@agent-creator/cli 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/dist/package.json +36 -0
- package/dist/src/capabilities/agent-core/capability.config.d.ts +2 -0
- package/dist/src/capabilities/agent-core/capability.config.js +6 -0
- package/dist/src/capabilities/agent-core/fileLoader.d.ts +3 -0
- package/dist/src/capabilities/agent-core/fileLoader.js +40 -0
- package/dist/src/capabilities/agent-core/files/base/.env.example +4 -0
- package/dist/src/capabilities/agent-core/files/base/README.md +69 -0
- package/dist/src/capabilities/agent-core/files/base/agent.config.ts +31 -0
- package/dist/src/capabilities/agent-core/files/base/package.json +33 -0
- package/dist/src/capabilities/agent-core/files/base/src/cli.ts +46 -0
- package/dist/src/capabilities/agent-core/files/base/src/dev.ts +1 -0
- package/dist/src/capabilities/agent-core/files/base/src/env.ts +23 -0
- package/dist/src/capabilities/agent-core/files/base/src/index.ts +31 -0
- package/dist/src/capabilities/agent-core/files/base/src/skills/index.ts +9 -0
- package/dist/src/capabilities/agent-core/files/base/tests/agent.test.ts +25 -0
- package/dist/src/capabilities/agent-core/files/base/tsconfig.json +17 -0
- package/dist/src/capabilities/agent-core/files/service/next.config.ts +15 -0
- package/dist/src/capabilities/agent-core/files/service/package.json +30 -0
- package/dist/src/capabilities/agent-core/files/service/src/app/api/agent/route.ts +10 -0
- package/dist/src/capabilities/agent-core/files/service/src/app/api/agent/stream/route.ts +53 -0
- package/dist/src/capabilities/agent-core/files/service/src/app/globals.css +34 -0
- package/dist/src/capabilities/agent-core/files/service/src/app/layout.tsx +19 -0
- package/dist/src/capabilities/agent-core/files/service/src/app/page.tsx +7 -0
- package/dist/src/capabilities/agent-core/files/service/src/components/AgentChat.tsx +146 -0
- package/dist/src/capabilities/capabilityRegistry.d.ts +3 -0
- package/dist/src/capabilities/capabilityRegistry.js +16 -0
- package/dist/src/capabilities/index.d.ts +1 -0
- package/dist/src/capabilities/index.js +1 -0
- package/dist/src/cli/cli.d.ts +3 -0
- package/dist/src/cli/cli.js +63 -0
- package/dist/src/commands/addSkill.d.ts +2 -0
- package/dist/src/commands/addSkill.js +58 -0
- package/dist/src/commands/addTool.d.ts +3 -0
- package/dist/src/commands/addTool.js +7 -0
- package/dist/src/commands/create.d.ts +2 -0
- package/dist/src/commands/create.js +32 -0
- package/dist/src/commands/dev.d.ts +1 -0
- package/dist/src/commands/dev.js +11 -0
- package/dist/src/commands/trace.d.ts +7 -0
- package/dist/src/commands/trace.js +35 -0
- package/dist/src/commands/validate.d.ts +1 -0
- package/dist/src/commands/validate.js +166 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +3 -0
- package/dist/src/schemas/agentConfig.schema.d.ts +103 -0
- package/dist/src/schemas/agentConfig.schema.js +26 -0
- package/dist/src/schemas/capability.schema.d.ts +25 -0
- package/dist/src/schemas/capability.schema.js +11 -0
- package/dist/src/types/capability.d.ts +11 -0
- package/dist/src/types/capability.js +1 -0
- package/dist/src/types/cli.d.ts +10 -0
- package/dist/src/types/cli.js +1 -0
- package/dist/src/utils/fs.d.ts +4 -0
- package/dist/src/utils/fs.js +21 -0
- package/dist/src/utils/logger.d.ts +6 -0
- package/dist/src/utils/logger.js +14 -0
- package/dist/src/utils/packageManager.d.ts +1 -0
- package/dist/src/utils/packageManager.js +5 -0
- package/dist/src/utils/path.d.ts +2 -0
- package/dist/src/utils/path.js +7 -0
- package/dist/src/utils/string.d.ts +4 -0
- package/dist/src/utils/string.js +21 -0
- package/dist/src/version.d.ts +4 -0
- package/dist/src/version.js +5 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "agent-creator-cli",
|
|
3
|
+
"version": "0.4.2",
|
|
4
|
+
"description": "CLI for creating projects powered by @agent-creator/core.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"agent": "./dist/src/index.js"
|
|
8
|
+
},
|
|
9
|
+
"main": "./dist/src/index.js",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md",
|
|
13
|
+
"package.json"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "node ../../scripts/clean-cli.mjs && tsc -p tsconfig.json && node ../../scripts/copy-capabilities.mjs",
|
|
17
|
+
"dev": "tsx src/index.ts",
|
|
18
|
+
"test": "vitest run",
|
|
19
|
+
"validate": "tsx src/index.ts validate",
|
|
20
|
+
"check:package": "npm pack --dry-run --json"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@agent-creator/core": "file:../core",
|
|
24
|
+
"commander": "^12.1.0",
|
|
25
|
+
"typescript": "^5.9.3",
|
|
26
|
+
"zod": "^3.23.8"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "^20.14.12",
|
|
30
|
+
"tsx": "^4.16.2",
|
|
31
|
+
"vitest": "^2.0.5"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=18"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { normalizePath } from '../../utils/path.js';
|
|
5
|
+
import { AGENT_CORE_CAPABILITY_VERSION, CLI_VERSION, CURRENT_CONFIG_VERSION } from '../../version.js';
|
|
6
|
+
const capabilityDir = path.join(path.dirname(fileURLToPath(import.meta.url)), 'files');
|
|
7
|
+
export async function loadAgentCoreFiles(projectName, options = {}) {
|
|
8
|
+
const mode = options.mode === 'package' ? 'package' : 'service';
|
|
9
|
+
const baseFiles = await readCapabilityFiles(path.join(capabilityDir, 'base'));
|
|
10
|
+
const serviceFiles = mode === 'service' ? await readCapabilityFiles(path.join(capabilityDir, 'service')) : [];
|
|
11
|
+
const files = mergeFiles([...baseFiles, ...serviceFiles]);
|
|
12
|
+
return files.map((file) => ({
|
|
13
|
+
path: file.path,
|
|
14
|
+
content: file.content
|
|
15
|
+
.replaceAll('{{projectName}}', projectName)
|
|
16
|
+
.replaceAll('{{cliVersion}}', CLI_VERSION)
|
|
17
|
+
.replaceAll('{{configVersion}}', CURRENT_CONFIG_VERSION)
|
|
18
|
+
.replaceAll('{{capabilityVersion}}', AGENT_CORE_CAPABILITY_VERSION)
|
|
19
|
+
.replaceAll('{{coreVersion}}', AGENT_CORE_CAPABILITY_VERSION)
|
|
20
|
+
.replaceAll('{{serviceEnabled}}', mode === 'service' ? 'true' : 'false')
|
|
21
|
+
.replaceAll('{{serviceFramework}}', mode === 'service' ? "'next'" : 'undefined'),
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
function mergeFiles(files) {
|
|
25
|
+
const byPath = new Map();
|
|
26
|
+
for (const file of files)
|
|
27
|
+
byPath.set(file.path, file);
|
|
28
|
+
return [...byPath.values()];
|
|
29
|
+
}
|
|
30
|
+
async function readCapabilityFiles(directory, baseDir = directory) {
|
|
31
|
+
const entries = await fs.readdir(directory, { withFileTypes: true });
|
|
32
|
+
const files = await Promise.all(entries.map(async (entry) => {
|
|
33
|
+
const entryPath = path.join(directory, entry.name);
|
|
34
|
+
if (entry.isDirectory())
|
|
35
|
+
return readCapabilityFiles(entryPath, baseDir);
|
|
36
|
+
const relativePath = normalizePath(path.relative(baseDir, entryPath));
|
|
37
|
+
return [{ path: relativePath, content: await fs.readFile(entryPath, 'utf8') }];
|
|
38
|
+
}));
|
|
39
|
+
return files.flat();
|
|
40
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# {{projectName}}
|
|
2
|
+
|
|
3
|
+
Generated by Agent Creator v{{cliVersion}}.
|
|
4
|
+
|
|
5
|
+
Capability: `agent-core` v{{capabilityVersion}}
|
|
6
|
+
Core: `@agent-creator/core` v{{coreVersion}}
|
|
7
|
+
Config schema: `{{configVersion}}`
|
|
8
|
+
|
|
9
|
+
This is an independent runnable Agent project powered by `@agent-creator/core`.
|
|
10
|
+
|
|
11
|
+
## Configure The Agent
|
|
12
|
+
|
|
13
|
+
Open `agent.config.ts` and set the minimum model configuration:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
model: {
|
|
17
|
+
baseUrl: 'https://api.openai.com/v1',
|
|
18
|
+
apiKey: 'your-key',
|
|
19
|
+
model: 'gpt-4o-mini', // optional; defaults to gpt-4o-mini
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
You can also keep the generated environment-variable reads and set:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
export LLM_BASE_URL=https://api.openai.com/v1
|
|
27
|
+
export OPENAI_API_KEY=your-key
|
|
28
|
+
# Optional override. Defaults to gpt-4o-mini.
|
|
29
|
+
export LLM_MODEL=gpt-4o-mini
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Run
|
|
33
|
+
|
|
34
|
+
Package mode starts a command-line chat:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install
|
|
38
|
+
npm run dev
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
After build:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npm run build
|
|
45
|
+
npm start
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Service mode starts a Next.js web chat:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm install
|
|
52
|
+
npm run dev
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Then open the printed local URL and chat in the browser. Service mode also keeps a CLI debug entry:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npm run dev:agent
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Customize Capabilities
|
|
62
|
+
|
|
63
|
+
Add skills and compose the Agent in `src/index.ts`:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
agent add skill calendar
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`src/index.ts` creates the Builder, registers every Skill from `src/skills/index.ts`, and calls `build()`.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const config = {
|
|
2
|
+
name: '{{projectName}}',
|
|
3
|
+
capability: 'agent-core',
|
|
4
|
+
version: '{{capabilityVersion}}',
|
|
5
|
+
configVersion: '{{configVersion}}',
|
|
6
|
+
capabilityVersion: '{{capabilityVersion}}',
|
|
7
|
+
generatedBy: {
|
|
8
|
+
name: 'agent-creator',
|
|
9
|
+
version: '{{cliVersion}}',
|
|
10
|
+
},
|
|
11
|
+
service: {
|
|
12
|
+
enabled: {{serviceEnabled}},
|
|
13
|
+
framework: {{serviceFramework}},
|
|
14
|
+
},
|
|
15
|
+
model: {
|
|
16
|
+
// Minimum required configuration: baseUrl and apiKey.
|
|
17
|
+
// You can hardcode local values here, or keep reading from environment variables.
|
|
18
|
+
baseUrl: process.env.LLM_BASE_URL ?? '',
|
|
19
|
+
apiKey: process.env.OPENAI_API_KEY ?? '',
|
|
20
|
+
model: process.env.LLM_MODEL ?? 'gpt-4o-mini',
|
|
21
|
+
timeoutMs: 30000,
|
|
22
|
+
maxRetries: 1,
|
|
23
|
+
},
|
|
24
|
+
skills: {
|
|
25
|
+
enabled: [
|
|
26
|
+
// agent-creator:skills
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default config;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{projectName}}",
|
|
3
|
+
"version": "{{capabilityVersion}}",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/src/index.js",
|
|
6
|
+
"types": "./dist/src/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"{{projectName}}": "./dist/src/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/src/index.d.ts",
|
|
13
|
+
"import": "./dist/src/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"dev": "tsx src/cli.ts",
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"start": "node dist/src/cli.js",
|
|
20
|
+
"test": "vitest run",
|
|
21
|
+
"validate": "agent validate"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@agent-creator/core": "^{{coreVersion}}",
|
|
25
|
+
"zod": "^3.23.8"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^20.14.12",
|
|
29
|
+
"tsx": "^4.16.2",
|
|
30
|
+
"typescript": "^5.5.4",
|
|
31
|
+
"vitest": "^2.0.5"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import readline from 'node:readline/promises';
|
|
2
|
+
import { stdin as input, stdout as output } from 'node:process';
|
|
3
|
+
import type { AgentProgressEvent } from '@agent-creator/core';
|
|
4
|
+
import { loadDotEnv } from './env.js';
|
|
5
|
+
|
|
6
|
+
export async function runCli(): Promise<void> {
|
|
7
|
+
loadDotEnv();
|
|
8
|
+
const { default: config } = await import('../agent.config.js');
|
|
9
|
+
const { runAgent } = await import('./index.js');
|
|
10
|
+
const rl = readline.createInterface({ input, output });
|
|
11
|
+
const sessionId = `session_${Date.now()}`;
|
|
12
|
+
|
|
13
|
+
console.log(`${config.name} CLI started.`);
|
|
14
|
+
if (!config.model.baseUrl || !config.model.apiKey) {
|
|
15
|
+
console.error('Set model.baseUrl and model.apiKey in agent.config.ts before running the Agent.');
|
|
16
|
+
process.exitCode = 1;
|
|
17
|
+
rl.close();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
console.log('Type "exit" or "quit" to quit.\n');
|
|
21
|
+
|
|
22
|
+
while (true) {
|
|
23
|
+
const text = await rl.question('User: ');
|
|
24
|
+
if (['exit', 'quit'].includes(text.trim().toLowerCase())) break;
|
|
25
|
+
const result = await runAgent({
|
|
26
|
+
input: text,
|
|
27
|
+
sessionId,
|
|
28
|
+
metadata: {
|
|
29
|
+
onProgress(event: AgentProgressEvent) {
|
|
30
|
+
console.log(formatProgress(event));
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
console.log('Agent:');
|
|
35
|
+
console.log(JSON.stringify(result, null, 2));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
rl.close();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
await runCli();
|
|
42
|
+
|
|
43
|
+
function formatProgress(event: AgentProgressEvent): string {
|
|
44
|
+
const prefix = event.type.endsWith('.completed') ? '✓' : event.type.endsWith('.failed') ? '✗' : '…';
|
|
45
|
+
return `${prefix} ${event.message}`;
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './cli.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
export function loadDotEnv(filePath = path.resolve(process.cwd(), '.env')): void {
|
|
5
|
+
if (!fs.existsSync(filePath)) return;
|
|
6
|
+
const source = fs.readFileSync(filePath, 'utf8');
|
|
7
|
+
for (const line of source.split(/\r?\n/)) {
|
|
8
|
+
const trimmed = line.trim();
|
|
9
|
+
if (!trimmed || trimmed.startsWith('#')) continue;
|
|
10
|
+
const separator = trimmed.indexOf('=');
|
|
11
|
+
if (separator <= 0) continue;
|
|
12
|
+
const key = trimmed.slice(0, separator).trim();
|
|
13
|
+
const value = unquote(trimmed.slice(separator + 1).trim());
|
|
14
|
+
process.env[key] ??= value;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function unquote(value: string): string {
|
|
19
|
+
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
20
|
+
return value.slice(1, -1);
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createAgent, type Agent } from '@agent-creator/core';
|
|
2
|
+
import config from '../agent.config.js';
|
|
3
|
+
import { skills } from './skills/index.js';
|
|
4
|
+
|
|
5
|
+
let configuredAgent: Agent | undefined;
|
|
6
|
+
|
|
7
|
+
export function getAgent(): Agent {
|
|
8
|
+
if (configuredAgent) return configuredAgent;
|
|
9
|
+
const builder = createAgent({ model: config.model });
|
|
10
|
+
for (const skill of skills) builder.useSkill(skill);
|
|
11
|
+
configuredAgent = builder.build();
|
|
12
|
+
return configuredAgent;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function runAgent(input: Parameters<Agent['run']>[0]) {
|
|
16
|
+
return getAgent().run(input);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { createAgent } from '@agent-creator/core';
|
|
20
|
+
export type {
|
|
21
|
+
Agent,
|
|
22
|
+
AgentInput,
|
|
23
|
+
AgentOutput,
|
|
24
|
+
Executor,
|
|
25
|
+
Guard,
|
|
26
|
+
MemoryProvider,
|
|
27
|
+
ModelProvider,
|
|
28
|
+
Planner,
|
|
29
|
+
Skill,
|
|
30
|
+
TraceProvider,
|
|
31
|
+
} from '@agent-creator/core';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { createAgent } from '@agent-creator/core';
|
|
3
|
+
|
|
4
|
+
describe('generated agent', () => {
|
|
5
|
+
it('runs with a custom model provider', async () => {
|
|
6
|
+
const agent = createAgent({
|
|
7
|
+
model: {
|
|
8
|
+
baseUrl: 'https://example.test/v1/',
|
|
9
|
+
apiKey: 'test-key',
|
|
10
|
+
model: 'test-model',
|
|
11
|
+
},
|
|
12
|
+
})
|
|
13
|
+
.useModel({
|
|
14
|
+
async generate() {
|
|
15
|
+
return { text: 'hello from generated agent' };
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
.build();
|
|
19
|
+
|
|
20
|
+
await expect(agent.run({ input: 'hello' })).resolves.toMatchObject({
|
|
21
|
+
success: true,
|
|
22
|
+
message: 'hello from generated agent',
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Bundler",
|
|
6
|
+
"lib": ["ES2022"],
|
|
7
|
+
"strict": true,
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"outDir": "dist",
|
|
13
|
+
"rootDir": "."
|
|
14
|
+
},
|
|
15
|
+
"include": ["agent.config.ts", "src/**/*.ts", "tests/**/*.ts"],
|
|
16
|
+
"exclude": ["dist", "node_modules"]
|
|
17
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { NextConfig } from 'next';
|
|
2
|
+
|
|
3
|
+
const nextConfig: NextConfig = {
|
|
4
|
+
webpack(config) {
|
|
5
|
+
config.resolve ??= {};
|
|
6
|
+
config.resolve.extensionAlias = {
|
|
7
|
+
...config.resolve.extensionAlias,
|
|
8
|
+
'.js': ['.ts', '.tsx', '.js'],
|
|
9
|
+
'.mjs': ['.mts', '.mjs'],
|
|
10
|
+
};
|
|
11
|
+
return config;
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default nextConfig;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{projectName}}",
|
|
3
|
+
"version": "{{capabilityVersion}}",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "next dev",
|
|
7
|
+
"dev:agent": "tsx src/cli.ts",
|
|
8
|
+
"build": "next build",
|
|
9
|
+
"start": "next start",
|
|
10
|
+
"test": "vitest run",
|
|
11
|
+
"validate": "agent validate"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@agent-creator/core": "^{{coreVersion}}",
|
|
15
|
+
"@ant-design/nextjs-registry": "^1.0.2",
|
|
16
|
+
"antd": "^5.21.6",
|
|
17
|
+
"next": "^15.0.3",
|
|
18
|
+
"react": "^19.0.0",
|
|
19
|
+
"react-dom": "^19.0.0",
|
|
20
|
+
"zod": "^3.23.8"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/node": "^20.14.12",
|
|
24
|
+
"@types/react": "^19.0.0",
|
|
25
|
+
"@types/react-dom": "^19.0.0",
|
|
26
|
+
"tsx": "^4.16.2",
|
|
27
|
+
"typescript": "^5.5.4",
|
|
28
|
+
"vitest": "^2.0.5"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server';
|
|
2
|
+
import { runAgent } from '../../../index';
|
|
3
|
+
|
|
4
|
+
export async function POST(request: Request) {
|
|
5
|
+
const body = await request.json().catch(() => ({})) as Record<string, unknown>;
|
|
6
|
+
const input = typeof body.input === 'string' ? body.input : '';
|
|
7
|
+
const sessionId = typeof body.sessionId === 'string' ? body.sessionId : undefined;
|
|
8
|
+
const output = await runAgent({ input, sessionId });
|
|
9
|
+
return NextResponse.json(output);
|
|
10
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { AgentOutput, AgentProgressEvent } from '@agent-creator/core';
|
|
2
|
+
import { runAgent } from '../../../../index';
|
|
3
|
+
|
|
4
|
+
type StreamEvent =
|
|
5
|
+
| { type: 'progress'; event: AgentProgressEvent }
|
|
6
|
+
| { type: 'final'; output: AgentOutput };
|
|
7
|
+
|
|
8
|
+
export async function POST(request: Request) {
|
|
9
|
+
const body = await request.json().catch(() => ({})) as Record<string, unknown>;
|
|
10
|
+
const input = typeof body.input === 'string' ? body.input : '';
|
|
11
|
+
const sessionId = typeof body.sessionId === 'string' ? body.sessionId : undefined;
|
|
12
|
+
const encoder = new TextEncoder();
|
|
13
|
+
|
|
14
|
+
const stream = new ReadableStream<Uint8Array>({
|
|
15
|
+
async start(controller) {
|
|
16
|
+
function send(event: StreamEvent) {
|
|
17
|
+
controller.enqueue(encoder.encode(`${JSON.stringify(event)}\n`));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
const output = await runAgent({
|
|
22
|
+
input,
|
|
23
|
+
sessionId,
|
|
24
|
+
metadata: {
|
|
25
|
+
onProgress(event: AgentProgressEvent) {
|
|
26
|
+
send({ type: 'progress', event });
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
send({ type: 'final', output });
|
|
31
|
+
} catch (error) {
|
|
32
|
+
send({
|
|
33
|
+
type: 'final',
|
|
34
|
+
output: {
|
|
35
|
+
success: false,
|
|
36
|
+
intent: 'stream_error',
|
|
37
|
+
message: 'Agent stream failed.',
|
|
38
|
+
errors: [error instanceof Error ? error.message : String(error)],
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
} finally {
|
|
42
|
+
controller.close();
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return new Response(stream, {
|
|
48
|
+
headers: {
|
|
49
|
+
'content-type': 'application/x-ndjson; charset=utf-8',
|
|
50
|
+
'cache-control': 'no-cache',
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
* {
|
|
2
|
+
box-sizing: border-box;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
body {
|
|
6
|
+
margin: 0;
|
|
7
|
+
background: #f5f7fb;
|
|
8
|
+
color: #172033;
|
|
9
|
+
font-family: Arial, Helvetica, sans-serif;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
a {
|
|
13
|
+
color: inherit;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.appShell {
|
|
17
|
+
min-height: 100vh;
|
|
18
|
+
padding: 24px;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.content {
|
|
22
|
+
max-width: 1120px;
|
|
23
|
+
margin: 0 auto;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.jsonBlock {
|
|
27
|
+
max-height: 520px;
|
|
28
|
+
overflow: auto;
|
|
29
|
+
padding: 12px;
|
|
30
|
+
border-radius: 6px;
|
|
31
|
+
background: #0f172a;
|
|
32
|
+
color: #dbeafe;
|
|
33
|
+
font-size: 12px;
|
|
34
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Metadata } from 'next';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
import { AntdRegistry } from '@ant-design/nextjs-registry';
|
|
4
|
+
import './globals.css';
|
|
5
|
+
|
|
6
|
+
export const metadata: Metadata = {
|
|
7
|
+
title: '{{projectName}} Agent',
|
|
8
|
+
description: 'Agent Creator service example shell',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default function RootLayout({ children }: { children: ReactNode }) {
|
|
12
|
+
return (
|
|
13
|
+
<html lang="en">
|
|
14
|
+
<body>
|
|
15
|
+
<AntdRegistry>{children}</AntdRegistry>
|
|
16
|
+
</body>
|
|
17
|
+
</html>
|
|
18
|
+
);
|
|
19
|
+
}
|