Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ export * from './shared/lib/token/index.js'; // Token tracking (if index.ts exis

// Legacy exports for backward compatibility
export type { IAgent } from './shared/types/agents.types.js';

export type { AgentConfigSQL } from './agents/studio/studio-graph.js';
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@langchain/core": "^0.3.72",
"@langchain/community": "^0.3.34",
"@types/pg": "^8.11.11",
"file-type": "^19.0.0",
"file-type": "^16.5.4",
"pg": "^8.13.3",
"prom-client": "^15.1.3",
"winston": "^3.17.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/services/file-validation.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fileTypeFromBuffer } from 'file-type';
import { fromBuffer } from 'file-type';
import logger from '../logger/logger.js';

export type SupportedMimeType =
Expand Down Expand Up @@ -60,7 +60,7 @@ export class FileValidationService {
declaredMimeType?: string
): Promise<FileValidationResponse> {
try {
const detected = await fileTypeFromBuffer(buffer);
const detected = await fromBuffer(buffer);
const detectedMimeType = detected?.mime;

logger.debug(
Expand Down
4 changes: 2 additions & 2 deletions packages/database/initdb/03-agents.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ CREATE TABLE IF NOT EXISTS agents (

-- Human-readable name for the agent
-- Used in UI displays and logging
-- Must be unique within a group for clarity
name VARCHAR(255) NOT NULL,
-- Must be unique across the entire system for clarity
name VARCHAR(255) NOT NULL UNIQUE,

-- Reference to the user who owns this agent
-- Foreign key linking to the user who created and manages this agent
Expand Down
2 changes: 1 addition & 1 deletion packages/server/common/cleanup/cleanup.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ScheduleModule } from '@nestjs/schedule';
import { CleanupService } from './cleanup.service.js';

@Module({
imports: [ScheduleModule.forRoot()],
imports: [ScheduleModule],
providers: [CleanupService],
exports: [CleanupService],
})
Expand Down
3 changes: 2 additions & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
},
"devDependencies": {
"@types/pg": "^8.11.0",
"typescript": "^5.7.3"
"typescript": "^5.7.3",
"tsx": "^4.20.4"
}
}
39 changes: 22 additions & 17 deletions packages/server/src/agents.storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,23 +234,28 @@ export class AgentStorage implements OnModuleInit {
rag: this.parseRagConfig(q_res[0].rag),
};
this.agentConfigs.push(newAgentDbRecord);
this.createSnakAgentFromConfig(newAgentDbRecord)
.then((snakAgent) => {
const compositeKey = `${newAgentDbRecord.id}|${newAgentDbRecord.user_id}`;
this.agentInstances.set(compositeKey, snakAgent);
this.agentSelector.updateAvailableAgents(
[newAgentDbRecord.id, snakAgent],
newAgentDbRecord.user_id
);
})
.catch((error) => {
logger.error(
`Failed to create SnakAgent for new agent ${newAgentDbRecord.id}: ${error}`
);
throw error;
});
logger.debug(`Agent ${newAgentDbRecord.id} added to configuration`);
return newAgentDbRecord;
try {
const snakAgent =
await this.createSnakAgentFromConfig(newAgentDbRecord);
const compositeKey = `${newAgentDbRecord.id}|${newAgentDbRecord.user_id}`;
this.agentInstances.set(compositeKey, snakAgent);
this.agentSelector.updateAvailableAgents(
[newAgentDbRecord.id, snakAgent],
newAgentDbRecord.user_id
);
logger.debug(
`Agent ${newAgentDbRecord.id} added to configuration and instance created`
);
return newAgentDbRecord;
} catch (error) {
logger.error(
`Failed to create SnakAgent for new agent ${newAgentDbRecord.id}: ${error}`
);
this.agentConfigs = this.agentConfigs.filter(
(config) => config.id !== newAgentDbRecord.id
);
throw error;
}
} else {
logger.error('Failed to add agent to database, no record returned.');
throw new Error('Failed to add agent to database.');
Expand Down
55 changes: 6 additions & 49 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,24 @@
"dev": "tsx src/index.ts",
"test": "tsx src/main.ts",
"demo": "tsx src/demo.ts",
"test:agents": "tsx src/test-agents.ts",
"test:files": "tsx src/test-files.ts",
"test:chat": "tsx src/test-chat.ts",
"test:file-stress": "tsx src/file-test/file-upload-stress-v2.ts",
"test:file-stress": "tsx src/stress-test/file-upload-stress.ts",
"test:agent-stress": "tsx src/stress-test/agent-stress.ts",
"clean": "rm -rf dist"
},
"dependencies": {
"axios": "^1.7.9",
"dotenv": "^16.4.7",
"chalk": "^4.1.2",
"ora": "^8.1.1",
"form-data": "^4.0.0"
"form-data": "^4.0.0",
"@snakagent/core": "workspace:*",
"@snakagent/server": "workspace:*",
"@snakagent/agents": "workspace:*"
},
"devDependencies": {
"@types/node": "^22.13.5",
"tsup": "^8.4.0",
"tsx": "^4.19.3",
"tsx": "^4.20.4",
"typescript": "^5.7.3"
},
"engines": {
Expand Down
58 changes: 58 additions & 0 deletions tests/src/agents/cleanup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import chalk from "chalk";
import { TestRunner } from "../test-runner";

export interface CleanupAgent {
testRunner: TestRunner;
agentId: string;
userId?: string;
agentName?: string;
}

export interface CleanupResult {
success: boolean;
index?: number;
error?: string;
}

export async function cleanupAgents(
agents: CleanupAgent[],
context: string = 'Cleanup'
): Promise<{ successful: number; failed: number; results: CleanupResult[] }> {
if (agents.length === 0) {
console.log(chalk.blue(`\n${context}: No agents to cleanup`));
return { successful: 0, failed: 0, results: [] };
}

console.log(chalk.blue(`\n${context}: Cleaning up ${agents.length} agents...`));

const cleanupPromises = agents.map(async (agent, index) => {
try {
const testName = `${context} - Delete Agent ${agent.agentId}`;

await agent.testRunner.runTest(testName, () =>
agent.testRunner.client.deleteAgent(agent.agentId)
);

return { success: true, index };
} catch (error) {
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
console.log(chalk.red(` Error: Failed to cleanup agent ${index + 1}: ${errorMessage}`));
return { success: false, index, error: errorMessage };
}
});

const settledResults = await Promise.allSettled(cleanupPromises);
const results = settledResults.map((result, index) => {
if (result.status === 'fulfilled') {
return result.value;
} else {
return { success: false, index, error: result.reason?.message || 'Unknown error' };
}
});
const successful = results.filter(r => r.success).length;
const failed = results.filter(r => !r.success).length;

console.log(chalk.green(` Success: ${context} completed: ${successful} successful, ${failed} failed`));

return { successful, failed, results };
}
Loading