@agentskit/cli 0.4.2 → 0.5.1
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 +28 -4
- package/dist/bin.cjs +1089 -63
- package/dist/bin.cjs.map +1 -1
- package/dist/bin.js +1 -1
- package/dist/chunk-IMW4N7X2.js +1569 -0
- package/dist/chunk-IMW4N7X2.js.map +1 -0
- package/dist/index.cjs +1094 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +175 -3
- package/dist/index.d.ts +175 -3
- package/dist/index.js +1 -1
- package/package.json +32 -13
- package/dist/chunk-RHXN45FL.js +0 -545
- package/dist/chunk-RHXN45FL.js.map +0 -1
package/dist/bin.cjs
CHANGED
|
@@ -5,21 +5,65 @@ var React3 = require('react');
|
|
|
5
5
|
var ink = require('ink');
|
|
6
6
|
var commander = require('commander');
|
|
7
7
|
var path = require('path');
|
|
8
|
-
var
|
|
8
|
+
var promises = require('fs/promises');
|
|
9
9
|
var ink$1 = require('@agentskit/ink');
|
|
10
10
|
var adapters = require('@agentskit/adapters');
|
|
11
11
|
var tools = require('@agentskit/tools');
|
|
12
12
|
var skills = require('@agentskit/skills');
|
|
13
13
|
var memory = require('@agentskit/memory');
|
|
14
14
|
var jsxRuntime = require('react/jsx-runtime');
|
|
15
|
-
var
|
|
15
|
+
var prompts = require('@inquirer/prompts');
|
|
16
|
+
var kleur = require('kleur');
|
|
17
|
+
var fs = require('fs');
|
|
16
18
|
var runtime = require('@agentskit/runtime');
|
|
19
|
+
var child_process = require('child_process');
|
|
20
|
+
var chokidar = require('chokidar');
|
|
17
21
|
|
|
18
22
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
19
23
|
|
|
20
24
|
var React3__default = /*#__PURE__*/_interopDefault(React3);
|
|
21
25
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
26
|
+
var kleur__default = /*#__PURE__*/_interopDefault(kleur);
|
|
27
|
+
var chokidar__default = /*#__PURE__*/_interopDefault(chokidar);
|
|
22
28
|
|
|
29
|
+
async function loadJsonConfig(path4) {
|
|
30
|
+
try {
|
|
31
|
+
const raw = await promises.readFile(path4, "utf8");
|
|
32
|
+
return JSON.parse(raw);
|
|
33
|
+
} catch {
|
|
34
|
+
return void 0;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async function loadTsConfig(path4) {
|
|
38
|
+
try {
|
|
39
|
+
const mod = await import(path4);
|
|
40
|
+
return mod.default ?? mod;
|
|
41
|
+
} catch {
|
|
42
|
+
return void 0;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function loadPackageJsonConfig(dir) {
|
|
46
|
+
try {
|
|
47
|
+
const raw = await promises.readFile(path.join(dir, "package.json"), "utf8");
|
|
48
|
+
const pkg = JSON.parse(raw);
|
|
49
|
+
if (pkg.agentskit && typeof pkg.agentskit === "object") {
|
|
50
|
+
return pkg.agentskit;
|
|
51
|
+
}
|
|
52
|
+
return void 0;
|
|
53
|
+
} catch {
|
|
54
|
+
return void 0;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async function loadConfig(options) {
|
|
58
|
+
const cwd = path.resolve(process.cwd());
|
|
59
|
+
const tsPath = path.join(cwd, ".agentskit.config.ts");
|
|
60
|
+
const tsConfig = await loadTsConfig(tsPath);
|
|
61
|
+
if (tsConfig) return tsConfig;
|
|
62
|
+
const jsonPath = path.join(cwd, ".agentskit.config.json");
|
|
63
|
+
const jsonConfig = await loadJsonConfig(jsonPath);
|
|
64
|
+
if (jsonConfig) return jsonConfig;
|
|
65
|
+
return await loadPackageJsonConfig(cwd);
|
|
66
|
+
}
|
|
23
67
|
var providers = {
|
|
24
68
|
openai: {
|
|
25
69
|
label: "OpenAI",
|
|
@@ -79,7 +123,7 @@ function createDemoAdapter(provider, model) {
|
|
|
79
123
|
].join(" ");
|
|
80
124
|
for (const chunk of reply.match(/.{1,18}/g) ?? []) {
|
|
81
125
|
if (cancelled) return;
|
|
82
|
-
await new Promise((
|
|
126
|
+
await new Promise((resolve2) => setTimeout(resolve2, 35));
|
|
83
127
|
yield { type: "text", content: chunk };
|
|
84
128
|
}
|
|
85
129
|
yield { type: "done" };
|
|
@@ -186,7 +230,7 @@ function resolveMemory(backend, memoryPath) {
|
|
|
186
230
|
return memory.sqliteChatMemory({ path: memoryPath.replace(/\.json$/, ".db") });
|
|
187
231
|
case "file":
|
|
188
232
|
default:
|
|
189
|
-
return
|
|
233
|
+
return memory.fileChatMemory(memoryPath);
|
|
190
234
|
}
|
|
191
235
|
}
|
|
192
236
|
function ChatApp(options) {
|
|
@@ -234,92 +278,470 @@ function renderChatHeader(options) {
|
|
|
234
278
|
if (options.memoryBackend) parts.push(`memory=${options.memoryBackend}`);
|
|
235
279
|
return parts.join(" ");
|
|
236
280
|
}
|
|
237
|
-
|
|
281
|
+
var PROVIDER_IMPORT = {
|
|
282
|
+
openai: "openai",
|
|
283
|
+
anthropic: "anthropic",
|
|
284
|
+
gemini: "gemini",
|
|
285
|
+
ollama: "ollama"
|
|
286
|
+
};
|
|
287
|
+
var PROVIDER_DEFAULT_MODEL = {
|
|
288
|
+
openai: "gpt-4o-mini",
|
|
289
|
+
anthropic: "claude-sonnet-4-6",
|
|
290
|
+
gemini: "gemini-2.5-flash",
|
|
291
|
+
ollama: "llama3.1",
|
|
292
|
+
demo: "demo"
|
|
293
|
+
};
|
|
294
|
+
var PROVIDER_ENV_KEY = {
|
|
295
|
+
openai: "OPENAI_API_KEY",
|
|
296
|
+
anthropic: "ANTHROPIC_API_KEY",
|
|
297
|
+
gemini: "GEMINI_API_KEY",
|
|
298
|
+
ollama: null,
|
|
299
|
+
demo: null
|
|
300
|
+
};
|
|
301
|
+
function adapterCall(provider, prefix = "process.env") {
|
|
302
|
+
const model = PROVIDER_DEFAULT_MODEL[provider];
|
|
303
|
+
if (provider === "demo") return `demoAdapter()`;
|
|
304
|
+
if (provider === "ollama") return `ollama({ model: '${model}' })`;
|
|
305
|
+
const envKey = PROVIDER_ENV_KEY[provider];
|
|
306
|
+
return `${PROVIDER_IMPORT[provider]}({ apiKey: ${prefix}.${envKey} ?? '', model: '${model}' })`;
|
|
307
|
+
}
|
|
308
|
+
function viteAdapterCall(provider) {
|
|
309
|
+
if (provider === "demo") return `demoAdapter()`;
|
|
310
|
+
if (provider === "ollama") return `ollama({ model: '${PROVIDER_DEFAULT_MODEL[provider]}' })`;
|
|
311
|
+
const envKey = PROVIDER_ENV_KEY[provider];
|
|
312
|
+
return `${PROVIDER_IMPORT[provider]}({ apiKey: import.meta.env.VITE_${envKey} ?? '', model: '${PROVIDER_DEFAULT_MODEL[provider]}' })`;
|
|
313
|
+
}
|
|
314
|
+
function adapterImport(provider) {
|
|
315
|
+
if (provider === "demo") return "";
|
|
316
|
+
return `import { ${PROVIDER_IMPORT[provider]} } from '@agentskit/adapters'
|
|
317
|
+
`;
|
|
318
|
+
}
|
|
319
|
+
function toolImports(tools) {
|
|
320
|
+
if (tools.length === 0) return "";
|
|
321
|
+
return `import { ${tools.map((t) => t === "web_search" ? "webSearch" : t).join(", ")} } from '@agentskit/tools'
|
|
322
|
+
`;
|
|
323
|
+
}
|
|
324
|
+
function toolList(tools) {
|
|
325
|
+
if (tools.length === 0) return "[]";
|
|
326
|
+
const calls = tools.map((t) => {
|
|
327
|
+
if (t === "web_search") return "webSearch()";
|
|
328
|
+
if (t === "filesystem") return `...filesystem({ basePath: './workspace' })`;
|
|
329
|
+
if (t === "shell") return `shell({ allowedCommands: ['ls', 'cat'] })`;
|
|
330
|
+
return "";
|
|
331
|
+
});
|
|
332
|
+
return `[${calls.join(", ")}]`;
|
|
333
|
+
}
|
|
334
|
+
function memoryImport(memory) {
|
|
335
|
+
if (memory === "file") return `import { fileChatMemory } from '@agentskit/memory'
|
|
336
|
+
`;
|
|
337
|
+
if (memory === "sqlite") return `import { sqliteChatMemory } from '@agentskit/memory'
|
|
338
|
+
`;
|
|
339
|
+
return "";
|
|
340
|
+
}
|
|
341
|
+
function memoryCall(memory) {
|
|
342
|
+
if (memory === "file") return `fileChatMemory('./.agentskit-history.json')`;
|
|
343
|
+
if (memory === "sqlite") return `sqliteChatMemory({ path: './.agentskit-history.db' })`;
|
|
344
|
+
return "undefined";
|
|
345
|
+
}
|
|
346
|
+
function demoAdapterSnippet() {
|
|
347
|
+
return `function demoAdapter() {
|
|
238
348
|
return {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
dev: "vite"
|
|
349
|
+
createSource: () => ({
|
|
350
|
+
stream: async function* () {
|
|
351
|
+
yield { type: 'text' as const, content: 'Hello from your AgentsKit starter. ' }
|
|
352
|
+
yield { type: 'text' as const, content: 'Configure a real adapter to talk to a model.' }
|
|
353
|
+
yield { type: 'done' as const }
|
|
245
354
|
},
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
355
|
+
abort: () => {},
|
|
356
|
+
}),
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
`;
|
|
361
|
+
}
|
|
362
|
+
function reactStarter(ctx) {
|
|
363
|
+
const deps = {
|
|
364
|
+
"@agentskit/react": "^0.4.0",
|
|
365
|
+
react: "^19.0.0",
|
|
366
|
+
"react-dom": "^19.0.0"
|
|
367
|
+
};
|
|
368
|
+
if (ctx.provider !== "demo") deps["@agentskit/adapters"] = "^0.4.0";
|
|
369
|
+
if (ctx.tools.length > 0) deps["@agentskit/tools"] = "^0.4.0";
|
|
370
|
+
if (ctx.memory !== "none") deps["@agentskit/memory"] = "^0.4.0";
|
|
371
|
+
const includesDemo = ctx.provider === "demo";
|
|
372
|
+
const adapter = ctx.provider === "demo" ? viteAdapterCall(ctx.provider) : viteAdapterCall(ctx.provider);
|
|
373
|
+
const envKey = PROVIDER_ENV_KEY[ctx.provider];
|
|
374
|
+
const envContent = envKey ? `VITE_${envKey}=
|
|
375
|
+
` : "# No API key required for the local provider\n";
|
|
376
|
+
return {
|
|
377
|
+
"package.json": JSON.stringify(
|
|
378
|
+
{
|
|
379
|
+
name: path__default.default.basename(ctx.template === "react" ? "agentskit-react-app" : "agentskit-app"),
|
|
380
|
+
private: true,
|
|
381
|
+
type: "module",
|
|
382
|
+
scripts: {
|
|
383
|
+
dev: "vite",
|
|
384
|
+
build: "vite build",
|
|
385
|
+
preview: "vite preview"
|
|
386
|
+
},
|
|
387
|
+
dependencies: deps,
|
|
388
|
+
devDependencies: {
|
|
389
|
+
"@types/react": "^19.0.0",
|
|
390
|
+
"@types/react-dom": "^19.0.0",
|
|
391
|
+
"@vitejs/plugin-react": "^5.0.0",
|
|
392
|
+
typescript: "^5.5.0",
|
|
393
|
+
vite: "^7.0.0"
|
|
394
|
+
}
|
|
395
|
+
},
|
|
396
|
+
null,
|
|
397
|
+
2
|
|
398
|
+
) + "\n",
|
|
399
|
+
"index.html": `<!doctype html>
|
|
400
|
+
<html lang="en">
|
|
401
|
+
<head>
|
|
402
|
+
<meta charset="UTF-8" />
|
|
403
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
404
|
+
<title>AgentsKit React Starter</title>
|
|
405
|
+
</head>
|
|
406
|
+
<body>
|
|
407
|
+
<div id="root"></div>
|
|
408
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
409
|
+
</body>
|
|
410
|
+
</html>
|
|
411
|
+
`,
|
|
412
|
+
"vite.config.ts": `import { defineConfig } from 'vite'
|
|
413
|
+
import react from '@vitejs/plugin-react'
|
|
414
|
+
|
|
415
|
+
export default defineConfig({ plugins: [react()] })
|
|
416
|
+
`,
|
|
417
|
+
"tsconfig.json": JSON.stringify(
|
|
418
|
+
{
|
|
419
|
+
compilerOptions: {
|
|
420
|
+
target: "ES2022",
|
|
421
|
+
lib: ["ES2022", "DOM"],
|
|
422
|
+
module: "ESNext",
|
|
423
|
+
moduleResolution: "bundler",
|
|
424
|
+
jsx: "react-jsx",
|
|
425
|
+
strict: true,
|
|
426
|
+
noEmit: true,
|
|
427
|
+
skipLibCheck: true
|
|
428
|
+
},
|
|
429
|
+
include: ["src"]
|
|
430
|
+
},
|
|
431
|
+
null,
|
|
432
|
+
2
|
|
433
|
+
) + "\n",
|
|
253
434
|
"src/main.tsx": `import React from 'react'
|
|
254
435
|
import ReactDOM from 'react-dom/client'
|
|
255
|
-
import
|
|
256
|
-
import { openai } from '@agentskit/adapters'
|
|
257
|
-
import '@agentskit/react/theme'
|
|
436
|
+
import App from './App'
|
|
258
437
|
|
|
259
|
-
|
|
438
|
+
ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
439
|
+
<React.StrictMode>
|
|
440
|
+
<App />
|
|
441
|
+
</React.StrictMode>,
|
|
442
|
+
)
|
|
443
|
+
`,
|
|
444
|
+
"src/App.tsx": `import { ChatContainer, InputBar, Message, useChat } from '@agentskit/react'
|
|
445
|
+
${adapterImport(ctx.provider)}${toolImports(ctx.tools)}${memoryImport(ctx.memory)}import '@agentskit/react/theme'
|
|
446
|
+
|
|
447
|
+
${includesDemo ? demoAdapterSnippet() : ""}export default function App() {
|
|
260
448
|
const chat = useChat({
|
|
261
|
-
adapter:
|
|
449
|
+
adapter: ${adapter},${ctx.tools.length > 0 ? `
|
|
450
|
+
tools: ${toolList(ctx.tools)},` : ""}${ctx.memory !== "none" ? `
|
|
451
|
+
memory: ${memoryCall(ctx.memory)},` : ""}
|
|
262
452
|
})
|
|
263
453
|
|
|
264
454
|
return (
|
|
265
455
|
<ChatContainer>
|
|
266
|
-
{chat.messages.map(message =>
|
|
456
|
+
{chat.messages.map(message => (
|
|
457
|
+
<Message key={message.id} message={message} />
|
|
458
|
+
))}
|
|
267
459
|
<InputBar chat={chat} />
|
|
268
460
|
</ChatContainer>
|
|
269
461
|
)
|
|
270
462
|
}
|
|
271
|
-
|
|
272
|
-
ReactDOM.createRoot(document.getElementById('root')!).render(<App />)
|
|
273
463
|
`,
|
|
274
|
-
".env.example":
|
|
464
|
+
".env.example": envContent,
|
|
465
|
+
".gitignore": `node_modules
|
|
466
|
+
dist
|
|
467
|
+
.env
|
|
468
|
+
.env.local
|
|
469
|
+
.agentskit-history.*
|
|
470
|
+
`,
|
|
471
|
+
"README.md": readmeFor(ctx)
|
|
275
472
|
};
|
|
276
473
|
}
|
|
277
|
-
function inkStarter() {
|
|
474
|
+
function inkStarter(ctx) {
|
|
475
|
+
const deps = {
|
|
476
|
+
"@agentskit/ink": "^0.4.0",
|
|
477
|
+
ink: "^7.0.0",
|
|
478
|
+
react: "^19.0.0"
|
|
479
|
+
};
|
|
480
|
+
if (ctx.provider !== "demo") deps["@agentskit/adapters"] = "^0.4.0";
|
|
481
|
+
if (ctx.tools.length > 0) deps["@agentskit/tools"] = "^0.4.0";
|
|
482
|
+
if (ctx.memory !== "none") deps["@agentskit/memory"] = "^0.4.0";
|
|
278
483
|
return {
|
|
279
|
-
"package.json": JSON.stringify(
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
484
|
+
"package.json": JSON.stringify(
|
|
485
|
+
{
|
|
486
|
+
name: "agentskit-ink-app",
|
|
487
|
+
private: true,
|
|
488
|
+
type: "module",
|
|
489
|
+
scripts: {
|
|
490
|
+
dev: "tsx src/index.tsx",
|
|
491
|
+
start: "tsx src/index.tsx"
|
|
492
|
+
},
|
|
493
|
+
dependencies: deps,
|
|
494
|
+
devDependencies: {
|
|
495
|
+
"@types/react": "^19.0.0",
|
|
496
|
+
"@types/react-dom": "^19.0.0",
|
|
497
|
+
tsx: "^4.20.0",
|
|
498
|
+
typescript: "^5.5.0"
|
|
499
|
+
}
|
|
285
500
|
},
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
501
|
+
null,
|
|
502
|
+
2
|
|
503
|
+
) + "\n",
|
|
504
|
+
"tsconfig.json": JSON.stringify(
|
|
505
|
+
{
|
|
506
|
+
compilerOptions: {
|
|
507
|
+
target: "ES2022",
|
|
508
|
+
module: "ESNext",
|
|
509
|
+
moduleResolution: "bundler",
|
|
510
|
+
jsx: "react-jsx",
|
|
511
|
+
strict: true,
|
|
512
|
+
noEmit: true,
|
|
513
|
+
skipLibCheck: true
|
|
514
|
+
},
|
|
515
|
+
include: ["src"]
|
|
516
|
+
},
|
|
517
|
+
null,
|
|
518
|
+
2
|
|
519
|
+
) + "\n",
|
|
291
520
|
"src/index.tsx": `import React from 'react'
|
|
292
521
|
import { render } from 'ink'
|
|
293
522
|
import { ChatContainer, InputBar, Message, useChat } from '@agentskit/ink'
|
|
523
|
+
${adapterImport(ctx.provider)}${toolImports(ctx.tools)}${memoryImport(ctx.memory)}
|
|
524
|
+
${ctx.provider === "demo" ? demoAdapterSnippet() : ""}function App() {
|
|
525
|
+
const chat = useChat({
|
|
526
|
+
adapter: ${adapterCall(ctx.provider)},${ctx.tools.length > 0 ? `
|
|
527
|
+
tools: ${toolList(ctx.tools)},` : ""}${ctx.memory !== "none" ? `
|
|
528
|
+
memory: ${memoryCall(ctx.memory)},` : ""}
|
|
529
|
+
})
|
|
294
530
|
|
|
295
|
-
function DemoAdapter() {
|
|
296
|
-
return {
|
|
297
|
-
createSource: () => ({
|
|
298
|
-
async *stream() {
|
|
299
|
-
yield { type: 'text', content: 'Hello from AgentsKit Ink.' }
|
|
300
|
-
yield { type: 'done' }
|
|
301
|
-
},
|
|
302
|
-
abort() {},
|
|
303
|
-
}),
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
function App() {
|
|
308
|
-
const chat = useChat({ adapter: DemoAdapter() })
|
|
309
531
|
return (
|
|
310
532
|
<ChatContainer>
|
|
311
|
-
{chat.messages.map(message =>
|
|
533
|
+
{chat.messages.map(message => (
|
|
534
|
+
<Message key={message.id} message={message} />
|
|
535
|
+
))}
|
|
312
536
|
<InputBar chat={chat} />
|
|
313
537
|
</ChatContainer>
|
|
314
538
|
)
|
|
315
539
|
}
|
|
316
540
|
|
|
317
541
|
render(<App />)
|
|
318
|
-
|
|
542
|
+
`,
|
|
543
|
+
".env.example": PROVIDER_ENV_KEY[ctx.provider] ? `${PROVIDER_ENV_KEY[ctx.provider]}=
|
|
544
|
+
` : "# No API key required for the local provider\n",
|
|
545
|
+
".gitignore": `node_modules
|
|
546
|
+
.env
|
|
547
|
+
.env.local
|
|
548
|
+
.agentskit-history.*
|
|
549
|
+
`,
|
|
550
|
+
"README.md": readmeFor(ctx)
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
function runtimeStarter(ctx) {
|
|
554
|
+
const deps = {
|
|
555
|
+
"@agentskit/runtime": "^0.4.0"
|
|
556
|
+
};
|
|
557
|
+
if (ctx.provider !== "demo") deps["@agentskit/adapters"] = "^0.4.0";
|
|
558
|
+
if (ctx.tools.length > 0) deps["@agentskit/tools"] = "^0.4.0";
|
|
559
|
+
if (ctx.memory !== "none") deps["@agentskit/memory"] = "^0.4.0";
|
|
560
|
+
return {
|
|
561
|
+
"package.json": JSON.stringify(
|
|
562
|
+
{
|
|
563
|
+
name: "agentskit-runtime-app",
|
|
564
|
+
private: true,
|
|
565
|
+
type: "module",
|
|
566
|
+
scripts: {
|
|
567
|
+
start: "tsx src/index.ts",
|
|
568
|
+
dev: "tsx src/index.ts"
|
|
569
|
+
},
|
|
570
|
+
dependencies: deps,
|
|
571
|
+
devDependencies: {
|
|
572
|
+
tsx: "^4.20.0",
|
|
573
|
+
typescript: "^5.5.0"
|
|
574
|
+
}
|
|
575
|
+
},
|
|
576
|
+
null,
|
|
577
|
+
2
|
|
578
|
+
) + "\n",
|
|
579
|
+
"tsconfig.json": JSON.stringify(
|
|
580
|
+
{
|
|
581
|
+
compilerOptions: {
|
|
582
|
+
target: "ES2022",
|
|
583
|
+
module: "ESNext",
|
|
584
|
+
moduleResolution: "bundler",
|
|
585
|
+
strict: true,
|
|
586
|
+
noEmit: true,
|
|
587
|
+
skipLibCheck: true
|
|
588
|
+
},
|
|
589
|
+
include: ["src"]
|
|
590
|
+
},
|
|
591
|
+
null,
|
|
592
|
+
2
|
|
593
|
+
) + "\n",
|
|
594
|
+
"src/index.ts": `import { createRuntime } from '@agentskit/runtime'
|
|
595
|
+
${adapterImport(ctx.provider)}${toolImports(ctx.tools)}${memoryImport(ctx.memory)}
|
|
596
|
+
${ctx.provider === "demo" ? demoAdapterSnippet() : ""}const runtime = createRuntime({
|
|
597
|
+
adapter: ${adapterCall(ctx.provider)},${ctx.tools.length > 0 ? `
|
|
598
|
+
tools: ${toolList(ctx.tools)},` : ""}${ctx.memory !== "none" ? `
|
|
599
|
+
memory: ${memoryCall(ctx.memory)},` : ""}
|
|
600
|
+
maxSteps: 10,
|
|
601
|
+
})
|
|
602
|
+
|
|
603
|
+
const task = process.argv.slice(2).join(' ') || 'Say hello and tell me one fact about TypeScript.'
|
|
604
|
+
const result = await runtime.run(task)
|
|
605
|
+
|
|
606
|
+
console.log(result.content)
|
|
607
|
+
console.log(\`\\n\u2014 \${result.steps} steps \xB7 \${result.toolCalls.length} tool calls \xB7 \${result.durationMs}ms\`)
|
|
608
|
+
`,
|
|
609
|
+
".env.example": PROVIDER_ENV_KEY[ctx.provider] ? `${PROVIDER_ENV_KEY[ctx.provider]}=
|
|
610
|
+
` : "# No API key required for the local provider\n",
|
|
611
|
+
".gitignore": `node_modules
|
|
612
|
+
.env
|
|
613
|
+
.env.local
|
|
614
|
+
.agentskit-history.*
|
|
615
|
+
`,
|
|
616
|
+
"README.md": readmeFor(ctx)
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
function multiAgentStarter(ctx) {
|
|
620
|
+
const deps = {
|
|
621
|
+
"@agentskit/runtime": "^0.4.0",
|
|
622
|
+
"@agentskit/skills": "^0.4.0"
|
|
623
|
+
};
|
|
624
|
+
if (ctx.provider !== "demo") deps["@agentskit/adapters"] = "^0.4.0";
|
|
625
|
+
if (ctx.tools.length === 0) ctx.tools = ["web_search"];
|
|
626
|
+
deps["@agentskit/tools"] = "^0.4.0";
|
|
627
|
+
return {
|
|
628
|
+
"package.json": JSON.stringify(
|
|
629
|
+
{
|
|
630
|
+
name: "agentskit-multi-agent",
|
|
631
|
+
private: true,
|
|
632
|
+
type: "module",
|
|
633
|
+
scripts: {
|
|
634
|
+
start: "tsx src/index.ts",
|
|
635
|
+
dev: "tsx src/index.ts"
|
|
636
|
+
},
|
|
637
|
+
dependencies: deps,
|
|
638
|
+
devDependencies: {
|
|
639
|
+
tsx: "^4.20.0",
|
|
640
|
+
typescript: "^5.5.0"
|
|
641
|
+
}
|
|
642
|
+
},
|
|
643
|
+
null,
|
|
644
|
+
2
|
|
645
|
+
) + "\n",
|
|
646
|
+
"tsconfig.json": JSON.stringify(
|
|
647
|
+
{
|
|
648
|
+
compilerOptions: {
|
|
649
|
+
target: "ES2022",
|
|
650
|
+
module: "ESNext",
|
|
651
|
+
moduleResolution: "bundler",
|
|
652
|
+
strict: true,
|
|
653
|
+
noEmit: true,
|
|
654
|
+
skipLibCheck: true
|
|
655
|
+
},
|
|
656
|
+
include: ["src"]
|
|
657
|
+
},
|
|
658
|
+
null,
|
|
659
|
+
2
|
|
660
|
+
) + "\n",
|
|
661
|
+
"src/index.ts": `import { createRuntime } from '@agentskit/runtime'
|
|
662
|
+
import { planner, researcher } from '@agentskit/skills'
|
|
663
|
+
${adapterImport(ctx.provider)}${toolImports(ctx.tools)}
|
|
664
|
+
${ctx.provider === "demo" ? demoAdapterSnippet() : ""}const runtime = createRuntime({
|
|
665
|
+
adapter: ${adapterCall(ctx.provider)},
|
|
666
|
+
maxSteps: 10,
|
|
667
|
+
maxDelegationDepth: 2,
|
|
668
|
+
})
|
|
669
|
+
|
|
670
|
+
const task = process.argv.slice(2).join(' ') || 'Research the current state of WebGPU and summarize.'
|
|
671
|
+
|
|
672
|
+
const result = await runtime.run(task, {
|
|
673
|
+
skill: planner,
|
|
674
|
+
delegates: {
|
|
675
|
+
researcher: {
|
|
676
|
+
skill: researcher,
|
|
677
|
+
tools: ${toolList(ctx.tools)},
|
|
678
|
+
maxSteps: 5,
|
|
679
|
+
},
|
|
680
|
+
},
|
|
681
|
+
})
|
|
682
|
+
|
|
683
|
+
console.log(result.content)
|
|
684
|
+
console.log(\`\\n\u2014 \${result.steps} steps \xB7 \${result.toolCalls.length} tool calls\`)
|
|
685
|
+
`,
|
|
686
|
+
".env.example": PROVIDER_ENV_KEY[ctx.provider] ? `${PROVIDER_ENV_KEY[ctx.provider]}=
|
|
687
|
+
` : "# No API key required for the local provider\n",
|
|
688
|
+
".gitignore": `node_modules
|
|
689
|
+
.env
|
|
690
|
+
.env.local
|
|
691
|
+
`,
|
|
692
|
+
"README.md": readmeFor(ctx)
|
|
319
693
|
};
|
|
320
694
|
}
|
|
695
|
+
function readmeFor(ctx) {
|
|
696
|
+
const installCmd = ctx.pm === "npm" ? "npm install" : `${ctx.pm} install`;
|
|
697
|
+
const runCmd = ctx.pm === "npm" ? "npm run dev" : `${ctx.pm} dev`;
|
|
698
|
+
const envKey = PROVIDER_ENV_KEY[ctx.provider];
|
|
699
|
+
return `# AgentsKit ${ctx.template} starter
|
|
700
|
+
|
|
701
|
+
Generated by \`agentskit init\`.
|
|
702
|
+
|
|
703
|
+
## Stack
|
|
704
|
+
|
|
705
|
+
- **Template**: \`${ctx.template}\`
|
|
706
|
+
- **Provider**: \`${ctx.provider}\`${ctx.tools.length ? `
|
|
707
|
+
- **Tools**: ${ctx.tools.map((t) => `\`${t}\``).join(", ")}` : ""}${ctx.memory !== "none" ? `
|
|
708
|
+
- **Memory**: \`${ctx.memory}\`` : ""}
|
|
709
|
+
|
|
710
|
+
## Run
|
|
711
|
+
|
|
712
|
+
\`\`\`bash
|
|
713
|
+
${installCmd}
|
|
714
|
+
${envKey ? `cp .env.example .env
|
|
715
|
+
# add ${envKey}=...` : "# No API key required"}
|
|
716
|
+
${runCmd}
|
|
717
|
+
\`\`\`
|
|
718
|
+
|
|
719
|
+
## Next steps
|
|
720
|
+
|
|
721
|
+
- Open the AgentsKit docs at https://www.agentskit.io/docs
|
|
722
|
+
- Add a custom skill: https://www.agentskit.io/docs/concepts/skill
|
|
723
|
+
- Wire up RAG: https://www.agentskit.io/docs/recipes/rag-chat
|
|
724
|
+
|
|
725
|
+
## License
|
|
726
|
+
|
|
727
|
+
ISC
|
|
728
|
+
`;
|
|
729
|
+
}
|
|
730
|
+
var TEMPLATE_FN = {
|
|
731
|
+
react: reactStarter,
|
|
732
|
+
ink: inkStarter,
|
|
733
|
+
runtime: runtimeStarter,
|
|
734
|
+
"multi-agent": multiAgentStarter
|
|
735
|
+
};
|
|
321
736
|
async function writeStarterProject(options) {
|
|
322
|
-
const
|
|
737
|
+
const ctx = {
|
|
738
|
+
template: options.template,
|
|
739
|
+
provider: options.provider ?? "demo",
|
|
740
|
+
tools: options.tools ?? [],
|
|
741
|
+
memory: options.memory ?? "none",
|
|
742
|
+
pm: options.packageManager ?? "pnpm"
|
|
743
|
+
};
|
|
744
|
+
const files = TEMPLATE_FN[ctx.template](ctx);
|
|
323
745
|
await promises.mkdir(options.targetDir, { recursive: true });
|
|
324
746
|
await Promise.all(
|
|
325
747
|
Object.entries(files).map(async ([relativePath, content]) => {
|
|
@@ -329,6 +751,133 @@ async function writeStarterProject(options) {
|
|
|
329
751
|
})
|
|
330
752
|
);
|
|
331
753
|
}
|
|
754
|
+
async function runInteractiveInit(defaults = {}) {
|
|
755
|
+
process.stdout.write(`
|
|
756
|
+
${kleur__default.default.bold().green("\u25B2")} ${kleur__default.default.bold("agentskit init")}
|
|
757
|
+
`);
|
|
758
|
+
process.stdout.write(kleur__default.default.dim(" Generate a starter project \u2014 answer five questions.\n\n"));
|
|
759
|
+
try {
|
|
760
|
+
const targetDir = await prompts.input({
|
|
761
|
+
message: "Project directory:",
|
|
762
|
+
default: defaults.dir ?? "agentskit-app",
|
|
763
|
+
validate: (value) => {
|
|
764
|
+
if (!value.trim()) return "A directory name is required.";
|
|
765
|
+
const abs = path__default.default.resolve(process.cwd(), value);
|
|
766
|
+
if (fs.existsSync(abs)) return `${value} already exists. Pick a different name.`;
|
|
767
|
+
return true;
|
|
768
|
+
}
|
|
769
|
+
});
|
|
770
|
+
const template = await prompts.select({
|
|
771
|
+
message: "Template:",
|
|
772
|
+
default: defaults.template ?? "react",
|
|
773
|
+
choices: [
|
|
774
|
+
{ name: "React chat (Vite + browser)", value: "react", description: "Streaming UI with @agentskit/react" },
|
|
775
|
+
{ name: "Ink chat (terminal UI)", value: "ink", description: "Same chat but in your terminal" },
|
|
776
|
+
{ name: "Runtime (headless agent, no UI)", value: "runtime", description: "Autonomous task \u2192 result" },
|
|
777
|
+
{ name: "Multi-agent (planner + delegates)", value: "multi-agent", description: "Supervisor pattern, ready to extend" }
|
|
778
|
+
]
|
|
779
|
+
});
|
|
780
|
+
const provider = await prompts.select({
|
|
781
|
+
message: "LLM provider:",
|
|
782
|
+
default: "demo",
|
|
783
|
+
choices: [
|
|
784
|
+
{ name: "Demo (no API key \u2014 deterministic stub)", value: "demo" },
|
|
785
|
+
{ name: "OpenAI", value: "openai" },
|
|
786
|
+
{ name: "Anthropic", value: "anthropic" },
|
|
787
|
+
{ name: "Gemini", value: "gemini" },
|
|
788
|
+
{ name: "Ollama (local, no key)", value: "ollama" }
|
|
789
|
+
]
|
|
790
|
+
});
|
|
791
|
+
let tools = [];
|
|
792
|
+
if (template !== "react") {
|
|
793
|
+
tools = await prompts.checkbox({
|
|
794
|
+
message: "Tools (space to toggle, enter to confirm):",
|
|
795
|
+
choices: [
|
|
796
|
+
{ name: "web_search", value: "web_search" },
|
|
797
|
+
{ name: "filesystem", value: "filesystem" },
|
|
798
|
+
{ name: "shell", value: "shell" }
|
|
799
|
+
]
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
const memory = await prompts.select({
|
|
803
|
+
message: "Memory backend:",
|
|
804
|
+
default: "none",
|
|
805
|
+
choices: [
|
|
806
|
+
{ name: "None (stateless)", value: "none" },
|
|
807
|
+
{ name: "File (JSON on disk)", value: "file" },
|
|
808
|
+
{ name: "SQLite (better-sqlite3)", value: "sqlite" }
|
|
809
|
+
]
|
|
810
|
+
});
|
|
811
|
+
const packageManager = await prompts.select({
|
|
812
|
+
message: "Package manager:",
|
|
813
|
+
default: "pnpm",
|
|
814
|
+
choices: [
|
|
815
|
+
{ name: "pnpm", value: "pnpm" },
|
|
816
|
+
{ name: "npm", value: "npm" },
|
|
817
|
+
{ name: "yarn", value: "yarn" },
|
|
818
|
+
{ name: "bun", value: "bun" }
|
|
819
|
+
]
|
|
820
|
+
});
|
|
821
|
+
process.stdout.write("\n" + kleur__default.default.dim(" Summary:\n"));
|
|
822
|
+
process.stdout.write(kleur__default.default.dim(` dir ${targetDir}
|
|
823
|
+
`));
|
|
824
|
+
process.stdout.write(kleur__default.default.dim(` template ${template}
|
|
825
|
+
`));
|
|
826
|
+
process.stdout.write(kleur__default.default.dim(` provider ${provider}
|
|
827
|
+
`));
|
|
828
|
+
if (tools.length) process.stdout.write(kleur__default.default.dim(` tools ${tools.join(", ")}
|
|
829
|
+
`));
|
|
830
|
+
process.stdout.write(kleur__default.default.dim(` memory ${memory}
|
|
831
|
+
`));
|
|
832
|
+
process.stdout.write(kleur__default.default.dim(` pm ${packageManager}
|
|
833
|
+
|
|
834
|
+
`));
|
|
835
|
+
const proceed = await prompts.confirm({ message: "Generate?", default: true });
|
|
836
|
+
if (!proceed) {
|
|
837
|
+
process.stdout.write(kleur__default.default.yellow("Cancelled.\n"));
|
|
838
|
+
return { cancelled: true, options: { targetDir, template, provider, tools, memory, packageManager } };
|
|
839
|
+
}
|
|
840
|
+
return {
|
|
841
|
+
cancelled: false,
|
|
842
|
+
options: {
|
|
843
|
+
targetDir: path__default.default.resolve(process.cwd(), targetDir),
|
|
844
|
+
template,
|
|
845
|
+
provider,
|
|
846
|
+
tools,
|
|
847
|
+
memory,
|
|
848
|
+
packageManager
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
} catch (err) {
|
|
852
|
+
if (err.name === "ExitPromptError") {
|
|
853
|
+
process.stdout.write(kleur__default.default.yellow("\nCancelled.\n"));
|
|
854
|
+
return { cancelled: true, options: { targetDir: "", template: "react" } };
|
|
855
|
+
}
|
|
856
|
+
throw err;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
function printNextSteps(options) {
|
|
860
|
+
const dir = path__default.default.relative(process.cwd(), options.targetDir) || ".";
|
|
861
|
+
const pm = options.packageManager ?? "pnpm";
|
|
862
|
+
const installCmd = pm === "npm" ? "npm install" : `${pm} install`;
|
|
863
|
+
const runCmd = pm === "npm" ? "npm run dev" : `${pm} dev`;
|
|
864
|
+
process.stdout.write("\n" + kleur__default.default.green("\u2713 Created starter at ") + kleur__default.default.bold(dir) + "\n\n");
|
|
865
|
+
process.stdout.write(kleur__default.default.bold("Next steps:\n\n"));
|
|
866
|
+
process.stdout.write(` ${kleur__default.default.cyan("cd")} ${dir}
|
|
867
|
+
`);
|
|
868
|
+
process.stdout.write(` ${kleur__default.default.cyan(installCmd)}
|
|
869
|
+
`);
|
|
870
|
+
if (options.provider && options.provider !== "demo" && options.provider !== "ollama") {
|
|
871
|
+
process.stdout.write(
|
|
872
|
+
` ${kleur__default.default.cyan("cp")} .env.example .env ${kleur__default.default.dim("# add your API key")}
|
|
873
|
+
`
|
|
874
|
+
);
|
|
875
|
+
}
|
|
876
|
+
process.stdout.write(` ${kleur__default.default.cyan(runCmd)}
|
|
877
|
+
|
|
878
|
+
`);
|
|
879
|
+
process.stdout.write(kleur__default.default.dim(" Docs: https://www.agentskit.io/docs\n\n"));
|
|
880
|
+
}
|
|
332
881
|
function formatEvent(event) {
|
|
333
882
|
switch (event.type) {
|
|
334
883
|
case "agent:step":
|
|
@@ -483,6 +1032,404 @@ function RunApp({ task, options }) {
|
|
|
483
1032
|
] })
|
|
484
1033
|
] });
|
|
485
1034
|
}
|
|
1035
|
+
var PROVIDER_ENV_KEYS = {
|
|
1036
|
+
openai: "OPENAI_API_KEY",
|
|
1037
|
+
anthropic: "ANTHROPIC_API_KEY",
|
|
1038
|
+
gemini: "GEMINI_API_KEY",
|
|
1039
|
+
deepseek: "DEEPSEEK_API_KEY",
|
|
1040
|
+
grok: "XAI_API_KEY",
|
|
1041
|
+
kimi: "KIMI_API_KEY"
|
|
1042
|
+
};
|
|
1043
|
+
var PROVIDER_REACH_URLS = {
|
|
1044
|
+
openai: "https://api.openai.com/v1/models",
|
|
1045
|
+
anthropic: "https://api.anthropic.com",
|
|
1046
|
+
gemini: "https://generativelanguage.googleapis.com",
|
|
1047
|
+
ollama: "http://localhost:11434/api/tags"
|
|
1048
|
+
};
|
|
1049
|
+
async function checkNodeVersion() {
|
|
1050
|
+
const major = Number(process.versions.node.split(".")[0]);
|
|
1051
|
+
if (Number.isNaN(major)) {
|
|
1052
|
+
return { status: "fail", name: "Node version", detail: "Could not parse process.versions.node" };
|
|
1053
|
+
}
|
|
1054
|
+
if (major < 22) {
|
|
1055
|
+
return {
|
|
1056
|
+
status: "fail",
|
|
1057
|
+
name: "Node version",
|
|
1058
|
+
detail: `Node ${process.versions.node} (need 22+)`,
|
|
1059
|
+
fix: "Install Node 22 LTS or newer (https://nodejs.org)"
|
|
1060
|
+
};
|
|
1061
|
+
}
|
|
1062
|
+
if (major === 25) {
|
|
1063
|
+
return {
|
|
1064
|
+
status: "warn",
|
|
1065
|
+
name: "Node version",
|
|
1066
|
+
detail: `Node ${process.versions.node} \u2014 Docusaurus apps may break here`,
|
|
1067
|
+
fix: "Use Node 22 LTS for the legacy docs app, or stay on 25 for everything else"
|
|
1068
|
+
};
|
|
1069
|
+
}
|
|
1070
|
+
return { status: "pass", name: "Node version", detail: `Node ${process.versions.node}` };
|
|
1071
|
+
}
|
|
1072
|
+
async function checkPnpm() {
|
|
1073
|
+
const cwd = process.cwd();
|
|
1074
|
+
const hasPnpm = fs.existsSync(path.join(cwd, "pnpm-lock.yaml")) || fs.existsSync(path.join(cwd, "pnpm-workspace.yaml"));
|
|
1075
|
+
if (hasPnpm) {
|
|
1076
|
+
return { status: "pass", name: "Package manager", detail: "pnpm detected (lockfile)" };
|
|
1077
|
+
}
|
|
1078
|
+
if (fs.existsSync(path.join(cwd, "package-lock.json"))) {
|
|
1079
|
+
return { status: "warn", name: "Package manager", detail: "npm detected \u2014 pnpm recommended for monorepo workflows" };
|
|
1080
|
+
}
|
|
1081
|
+
if (fs.existsSync(path.join(cwd, "yarn.lock"))) {
|
|
1082
|
+
return { status: "pass", name: "Package manager", detail: "yarn detected" };
|
|
1083
|
+
}
|
|
1084
|
+
if (fs.existsSync(path.join(cwd, "bun.lock")) || fs.existsSync(path.join(cwd, "bun.lockb"))) {
|
|
1085
|
+
return { status: "pass", name: "Package manager", detail: "bun detected" };
|
|
1086
|
+
}
|
|
1087
|
+
return {
|
|
1088
|
+
status: "skip",
|
|
1089
|
+
name: "Package manager",
|
|
1090
|
+
detail: "No lockfile found in cwd"
|
|
1091
|
+
};
|
|
1092
|
+
}
|
|
1093
|
+
async function checkPackageJson() {
|
|
1094
|
+
const path4 = path.join(process.cwd(), "package.json");
|
|
1095
|
+
if (!fs.existsSync(path4)) {
|
|
1096
|
+
return {
|
|
1097
|
+
status: "warn",
|
|
1098
|
+
name: "package.json",
|
|
1099
|
+
detail: "No package.json in cwd",
|
|
1100
|
+
fix: "Run from a project directory (or use `agentskit init` to create one)"
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
try {
|
|
1104
|
+
const pkg = JSON.parse(await promises.readFile(path4, "utf8"));
|
|
1105
|
+
const deps = {
|
|
1106
|
+
...pkg.dependencies ?? {},
|
|
1107
|
+
...pkg.devDependencies ?? {}
|
|
1108
|
+
};
|
|
1109
|
+
const akDeps = Object.entries(deps).filter(([name]) => name.startsWith("@agentskit/"));
|
|
1110
|
+
if (akDeps.length === 0) {
|
|
1111
|
+
return { status: "skip", name: "AgentsKit packages", detail: "No @agentskit/* deps found in package.json" };
|
|
1112
|
+
}
|
|
1113
|
+
return {
|
|
1114
|
+
status: "pass",
|
|
1115
|
+
name: "AgentsKit packages",
|
|
1116
|
+
detail: `${akDeps.length} installed: ${akDeps.map(([n]) => n.replace("@agentskit/", "")).join(", ")}`
|
|
1117
|
+
};
|
|
1118
|
+
} catch (err) {
|
|
1119
|
+
return {
|
|
1120
|
+
status: "fail",
|
|
1121
|
+
name: "package.json",
|
|
1122
|
+
detail: `Could not parse: ${err.message}`
|
|
1123
|
+
};
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
async function checkProviderEnv(provider) {
|
|
1127
|
+
const envKey = PROVIDER_ENV_KEYS[provider];
|
|
1128
|
+
if (!envKey) {
|
|
1129
|
+
return { status: "skip", name: `${provider} API key`, detail: "No env-key requirement for this provider" };
|
|
1130
|
+
}
|
|
1131
|
+
const value = process.env[envKey];
|
|
1132
|
+
if (!value) {
|
|
1133
|
+
return {
|
|
1134
|
+
status: "fail",
|
|
1135
|
+
name: `${provider} API key`,
|
|
1136
|
+
detail: `${envKey} is not set`,
|
|
1137
|
+
fix: `export ${envKey}=...`
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
1140
|
+
if (value.length < 16) {
|
|
1141
|
+
return {
|
|
1142
|
+
status: "warn",
|
|
1143
|
+
name: `${provider} API key`,
|
|
1144
|
+
detail: `${envKey} looks too short (${value.length} chars)`,
|
|
1145
|
+
fix: "Verify the key is complete and not truncated"
|
|
1146
|
+
};
|
|
1147
|
+
}
|
|
1148
|
+
return { status: "pass", name: `${provider} API key`, detail: `${envKey} set (${value.length} chars)` };
|
|
1149
|
+
}
|
|
1150
|
+
async function checkProviderReachable(provider, fetchImpl = fetch, timeoutMs = 4e3) {
|
|
1151
|
+
const url = PROVIDER_REACH_URLS[provider];
|
|
1152
|
+
if (!url) {
|
|
1153
|
+
return { status: "skip", name: `${provider} reachable`, detail: "No reachability check for this provider" };
|
|
1154
|
+
}
|
|
1155
|
+
const controller = new AbortController();
|
|
1156
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
1157
|
+
try {
|
|
1158
|
+
const res = await fetchImpl(url, {
|
|
1159
|
+
method: "GET",
|
|
1160
|
+
signal: controller.signal
|
|
1161
|
+
// No auth — we just want to confirm DNS + network reach.
|
|
1162
|
+
});
|
|
1163
|
+
return {
|
|
1164
|
+
status: "pass",
|
|
1165
|
+
name: `${provider} reachable`,
|
|
1166
|
+
detail: `${url} \u2192 HTTP ${res.status}`
|
|
1167
|
+
};
|
|
1168
|
+
} catch (err) {
|
|
1169
|
+
const reason = err.name === "AbortError" ? `timeout after ${timeoutMs}ms` : err.message;
|
|
1170
|
+
return {
|
|
1171
|
+
status: "fail",
|
|
1172
|
+
name: `${provider} reachable`,
|
|
1173
|
+
detail: `${url} \u2192 ${reason}`,
|
|
1174
|
+
fix: provider === "ollama" ? "Start Ollama: `ollama serve` (or install from https://ollama.com)" : "Check network / firewall / VPN settings"
|
|
1175
|
+
};
|
|
1176
|
+
} finally {
|
|
1177
|
+
clearTimeout(timer);
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
async function checkConfig() {
|
|
1181
|
+
try {
|
|
1182
|
+
const config = await loadConfig();
|
|
1183
|
+
if (!config) {
|
|
1184
|
+
return { status: "skip", name: "AgentsKit config", detail: "No .agentskit.config or package.json#agentskit found" };
|
|
1185
|
+
}
|
|
1186
|
+
return {
|
|
1187
|
+
status: "pass",
|
|
1188
|
+
name: "AgentsKit config",
|
|
1189
|
+
detail: `loaded \u2014 defaults: ${JSON.stringify(config.defaults ?? {})}`
|
|
1190
|
+
};
|
|
1191
|
+
} catch (err) {
|
|
1192
|
+
return {
|
|
1193
|
+
status: "warn",
|
|
1194
|
+
name: "AgentsKit config",
|
|
1195
|
+
detail: `Could not load: ${err.message}`
|
|
1196
|
+
};
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
async function runDoctor(options = {}) {
|
|
1200
|
+
const providers2 = options.providers ?? ["openai", "anthropic", "gemini", "ollama"];
|
|
1201
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
1202
|
+
const checks = [
|
|
1203
|
+
checkNodeVersion(),
|
|
1204
|
+
checkPnpm(),
|
|
1205
|
+
checkPackageJson(),
|
|
1206
|
+
checkConfig()
|
|
1207
|
+
];
|
|
1208
|
+
for (const provider of providers2) {
|
|
1209
|
+
checks.push(checkProviderEnv(provider));
|
|
1210
|
+
if (!options.noNetwork) {
|
|
1211
|
+
checks.push(checkProviderReachable(provider, fetchImpl));
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
const results = await Promise.all(checks);
|
|
1215
|
+
return {
|
|
1216
|
+
results,
|
|
1217
|
+
pass: results.filter((r) => r.status === "pass").length,
|
|
1218
|
+
warn: results.filter((r) => r.status === "warn").length,
|
|
1219
|
+
fail: results.filter((r) => r.status === "fail").length,
|
|
1220
|
+
skip: results.filter((r) => r.status === "skip").length
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
1223
|
+
var ICON = {
|
|
1224
|
+
pass: "\u2713",
|
|
1225
|
+
warn: "!",
|
|
1226
|
+
fail: "\u2717",
|
|
1227
|
+
skip: "\xB7"
|
|
1228
|
+
};
|
|
1229
|
+
function renderReport(report, opts = {}) {
|
|
1230
|
+
const color = opts.color ?? true;
|
|
1231
|
+
const c = (code, text) => color ? `\x1B[${code}m${text}\x1B[0m` : text;
|
|
1232
|
+
const colorFor = {
|
|
1233
|
+
pass: (t) => c("32", t),
|
|
1234
|
+
warn: (t) => c("33", t),
|
|
1235
|
+
fail: (t) => c("31", t),
|
|
1236
|
+
skip: (t) => c("90", t)
|
|
1237
|
+
};
|
|
1238
|
+
const lines = [];
|
|
1239
|
+
lines.push("");
|
|
1240
|
+
lines.push(c("1", "agentskit doctor"));
|
|
1241
|
+
lines.push("");
|
|
1242
|
+
for (const r of report.results) {
|
|
1243
|
+
const icon = colorFor[r.status](ICON[r.status]);
|
|
1244
|
+
const name = r.name.padEnd(28);
|
|
1245
|
+
const detail = r.detail ? c("90", r.detail) : "";
|
|
1246
|
+
lines.push(` ${icon} ${name} ${detail}`);
|
|
1247
|
+
if (r.fix && (r.status === "fail" || r.status === "warn")) {
|
|
1248
|
+
lines.push(` ${c("90", "\u21B3 " + r.fix)}`);
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
lines.push("");
|
|
1252
|
+
const summary = [
|
|
1253
|
+
`${report.pass} pass`,
|
|
1254
|
+
report.warn > 0 ? colorFor.warn(`${report.warn} warn`) : `${report.warn} warn`,
|
|
1255
|
+
report.fail > 0 ? colorFor.fail(`${report.fail} fail`) : `${report.fail} fail`,
|
|
1256
|
+
`${report.skip} skip`
|
|
1257
|
+
].join(" \xB7 ");
|
|
1258
|
+
lines.push(` ${c("1", "Summary:")} ${summary}`);
|
|
1259
|
+
lines.push("");
|
|
1260
|
+
return lines.join("\n");
|
|
1261
|
+
}
|
|
1262
|
+
var DEFAULT_WATCH = [
|
|
1263
|
+
"**/*.ts",
|
|
1264
|
+
"**/*.tsx",
|
|
1265
|
+
"**/*.mjs",
|
|
1266
|
+
"**/*.json",
|
|
1267
|
+
".agentskit.config.*"
|
|
1268
|
+
];
|
|
1269
|
+
var DEFAULT_IGNORE = [
|
|
1270
|
+
"**/node_modules/**",
|
|
1271
|
+
"**/dist/**",
|
|
1272
|
+
"**/build/**",
|
|
1273
|
+
"**/.next/**",
|
|
1274
|
+
"**/.turbo/**",
|
|
1275
|
+
"**/.git/**",
|
|
1276
|
+
"**/coverage/**",
|
|
1277
|
+
"**/*.test.ts",
|
|
1278
|
+
"**/*.spec.ts"
|
|
1279
|
+
];
|
|
1280
|
+
function startDev(options) {
|
|
1281
|
+
const entry = path.resolve(process.cwd(), options.entry);
|
|
1282
|
+
if (!fs.existsSync(entry)) {
|
|
1283
|
+
throw new Error(`Entry file not found: ${entry}`);
|
|
1284
|
+
}
|
|
1285
|
+
const stdout = options.stdout ?? process.stdout;
|
|
1286
|
+
const stderr = options.stderr ?? process.stderr;
|
|
1287
|
+
const debounceMs = options.debounceMs ?? 200;
|
|
1288
|
+
const isTs = entry.endsWith(".ts") || entry.endsWith(".tsx");
|
|
1289
|
+
const cmd = isTs ? "tsx" : "node";
|
|
1290
|
+
const baseArgs = [entry, ...options.scriptArgs ?? []];
|
|
1291
|
+
const spawnFn = options.spawn ?? ((c, a) => child_process.spawn(c, a, {
|
|
1292
|
+
stdio: ["inherit", "pipe", "pipe"],
|
|
1293
|
+
env: { ...process.env, FORCE_COLOR: "1" }
|
|
1294
|
+
}));
|
|
1295
|
+
const watchPaths = options.watch ?? DEFAULT_WATCH;
|
|
1296
|
+
const ignorePaths = [...DEFAULT_IGNORE, ...options.ignore ?? []];
|
|
1297
|
+
const watcherFactory = options.watcher ?? ((paths, opts) => chokidar__default.default.watch(paths, { ignored: opts.ignored, ignoreInitial: true }));
|
|
1298
|
+
const watcher = watcherFactory(watchPaths, { ignored: ignorePaths });
|
|
1299
|
+
let child;
|
|
1300
|
+
let restartCount = 0;
|
|
1301
|
+
let restartTimer;
|
|
1302
|
+
let stopped = false;
|
|
1303
|
+
let resolveDone;
|
|
1304
|
+
const done = new Promise((r) => {
|
|
1305
|
+
resolveDone = r;
|
|
1306
|
+
});
|
|
1307
|
+
const banner = (msg, color = "green") => {
|
|
1308
|
+
const time = (/* @__PURE__ */ new Date()).toTimeString().slice(0, 8);
|
|
1309
|
+
stdout.write(kleur__default.default[color](`[agentskit dev ${time}] `) + msg + "\n");
|
|
1310
|
+
};
|
|
1311
|
+
const startChild = () => {
|
|
1312
|
+
restartCount++;
|
|
1313
|
+
banner(`\u25B8 starting ${kleur__default.default.bold(path.basename(entry))} (restart #${restartCount - 1})`, "cyan");
|
|
1314
|
+
const c = spawnFn(cmd, baseArgs);
|
|
1315
|
+
child = c;
|
|
1316
|
+
c.stdout?.on("data", (d) => stdout.write(d));
|
|
1317
|
+
c.stderr?.on("data", (d) => stderr.write(d));
|
|
1318
|
+
c.on("exit", (code, signal) => {
|
|
1319
|
+
if (stopped) return;
|
|
1320
|
+
if (signal === "SIGTERM" || signal === "SIGINT") return;
|
|
1321
|
+
if (code === 0) {
|
|
1322
|
+
banner(`\u2713 exited cleanly \u2014 waiting for changes`, "green");
|
|
1323
|
+
} else {
|
|
1324
|
+
banner(`\u2717 exited with code ${code} \u2014 waiting for changes`, "red");
|
|
1325
|
+
}
|
|
1326
|
+
});
|
|
1327
|
+
};
|
|
1328
|
+
const restart = (path4) => {
|
|
1329
|
+
if (restartTimer) clearTimeout(restartTimer);
|
|
1330
|
+
restartTimer = setTimeout(() => {
|
|
1331
|
+
restartTimer = void 0;
|
|
1332
|
+
banner(`\u21BB change detected \u2014 ${path4}`, "yellow");
|
|
1333
|
+
if (child && !child.killed && child.exitCode === null) {
|
|
1334
|
+
child.kill("SIGTERM");
|
|
1335
|
+
}
|
|
1336
|
+
setTimeout(startChild, 80);
|
|
1337
|
+
}, debounceMs);
|
|
1338
|
+
};
|
|
1339
|
+
watcher.on("change", restart);
|
|
1340
|
+
watcher.on("add", restart);
|
|
1341
|
+
watcher.on("unlink", restart);
|
|
1342
|
+
startChild();
|
|
1343
|
+
const stop = async () => {
|
|
1344
|
+
if (stopped) return;
|
|
1345
|
+
stopped = true;
|
|
1346
|
+
if (restartTimer) clearTimeout(restartTimer);
|
|
1347
|
+
if (child && !child.killed && child.exitCode === null) {
|
|
1348
|
+
child.kill("SIGTERM");
|
|
1349
|
+
}
|
|
1350
|
+
await watcher.close();
|
|
1351
|
+
banner(`stopped`, "cyan");
|
|
1352
|
+
resolveDone();
|
|
1353
|
+
};
|
|
1354
|
+
if (process.stdin.isTTY && process.stdin.setRawMode) {
|
|
1355
|
+
process.stdin.setRawMode(true);
|
|
1356
|
+
process.stdin.resume();
|
|
1357
|
+
process.stdin.on("data", (data) => {
|
|
1358
|
+
const key = data.toString();
|
|
1359
|
+
if (key === "r") restart("manual");
|
|
1360
|
+
if (key === "q" || key === "") void stop();
|
|
1361
|
+
});
|
|
1362
|
+
}
|
|
1363
|
+
return {
|
|
1364
|
+
done,
|
|
1365
|
+
stop,
|
|
1366
|
+
restarts: () => restartCount
|
|
1367
|
+
};
|
|
1368
|
+
}
|
|
1369
|
+
async function startTunnel(options) {
|
|
1370
|
+
const stdout = options.stdout ?? process.stdout;
|
|
1371
|
+
const open = options.open ?? (async (opts) => {
|
|
1372
|
+
const lt = (await import('localtunnel')).default;
|
|
1373
|
+
return await lt(opts);
|
|
1374
|
+
});
|
|
1375
|
+
const banner = (msg, color = "green") => {
|
|
1376
|
+
const time = (/* @__PURE__ */ new Date()).toTimeString().slice(0, 8);
|
|
1377
|
+
stdout.write(kleur__default.default[color](`[agentskit tunnel ${time}] `) + msg + "\n");
|
|
1378
|
+
};
|
|
1379
|
+
banner(`opening tunnel to ${options.host ?? "localhost"}:${options.port}...`, "cyan");
|
|
1380
|
+
const tunnel = await open({
|
|
1381
|
+
port: options.port,
|
|
1382
|
+
subdomain: options.subdomain,
|
|
1383
|
+
local_host: options.host
|
|
1384
|
+
});
|
|
1385
|
+
let requests = 0;
|
|
1386
|
+
let stopped = false;
|
|
1387
|
+
let resolveDone;
|
|
1388
|
+
const done = new Promise((r) => {
|
|
1389
|
+
resolveDone = r;
|
|
1390
|
+
});
|
|
1391
|
+
tunnel.on("request", () => {
|
|
1392
|
+
requests++;
|
|
1393
|
+
});
|
|
1394
|
+
tunnel.on("close", () => {
|
|
1395
|
+
if (stopped) return;
|
|
1396
|
+
banner(`tunnel closed by remote`, "yellow");
|
|
1397
|
+
resolveDone();
|
|
1398
|
+
});
|
|
1399
|
+
tunnel.on("error", (...args) => {
|
|
1400
|
+
const err = args[0];
|
|
1401
|
+
banner(`error: ${err?.message ?? "unknown"}`, "red");
|
|
1402
|
+
});
|
|
1403
|
+
banner(`\u2713 ready`, "green");
|
|
1404
|
+
stdout.write("\n");
|
|
1405
|
+
stdout.write(` ${kleur__default.default.bold("Public URL:")} ${kleur__default.default.cyan(tunnel.url)}
|
|
1406
|
+
`);
|
|
1407
|
+
stdout.write(` ${kleur__default.default.bold("Local:")} http://${options.host ?? "localhost"}:${options.port}
|
|
1408
|
+
`);
|
|
1409
|
+
stdout.write("\n");
|
|
1410
|
+
stdout.write(kleur__default.default.dim(` Forward webhooks here, then ${kleur__default.default.bold("Ctrl+C")} to stop.
|
|
1411
|
+
|
|
1412
|
+
`));
|
|
1413
|
+
options.onReady?.(tunnel.url);
|
|
1414
|
+
const stop = async () => {
|
|
1415
|
+
if (stopped) return;
|
|
1416
|
+
stopped = true;
|
|
1417
|
+
tunnel.close();
|
|
1418
|
+
banner(`stopped \u2014 proxied ${requests} request${requests === 1 ? "" : "s"}`, "cyan");
|
|
1419
|
+
resolveDone();
|
|
1420
|
+
};
|
|
1421
|
+
if (process.stdin.isTTY) {
|
|
1422
|
+
process.on("SIGINT", () => {
|
|
1423
|
+
void stop();
|
|
1424
|
+
});
|
|
1425
|
+
}
|
|
1426
|
+
return {
|
|
1427
|
+
url: tunnel.url,
|
|
1428
|
+
done,
|
|
1429
|
+
stop,
|
|
1430
|
+
requests: () => requests
|
|
1431
|
+
};
|
|
1432
|
+
}
|
|
486
1433
|
|
|
487
1434
|
// src/commands.ts
|
|
488
1435
|
function mergeWithConfig(options, config) {
|
|
@@ -498,7 +1445,7 @@ function createCli() {
|
|
|
498
1445
|
const program = new commander.Command();
|
|
499
1446
|
program.name("agentskit").description("AgentsKit CLI for chat demos and project bootstrapping.");
|
|
500
1447
|
program.command("chat").description("Start a terminal chat session.").option("--provider <provider>", "Provider to use", "demo").option("--model <model>", "Model name").option("--api-key <key>", "API key for the selected provider").option("--base-url <url>", "Override provider base URL").option("--system <prompt>", "System prompt").option("--memory <path>", "Path for file-based memory", ".agentskit-history.json").option("--tools <tools>", "Comma-separated tools: web_search,filesystem,shell").option("--skill <skills>", "Comma-separated skills: researcher,coder,planner,critic,summarizer").option("--memory-backend <backend>", "Memory backend: file (default), sqlite").option("--no-config", "Skip loading .agentskit.config.json").action(async (options) => {
|
|
501
|
-
const config = options.config !== false ? await
|
|
1448
|
+
const config = options.config !== false ? await loadConfig() : void 0;
|
|
502
1449
|
const merged = mergeWithConfig(options, config);
|
|
503
1450
|
const chatOptions = {
|
|
504
1451
|
apiKey: merged.apiKey ?? options.apiKey,
|
|
@@ -522,7 +1469,7 @@ function createCli() {
|
|
|
522
1469
|
process.stderr.write("Error: task is required. Pass as argument or use --task.\n");
|
|
523
1470
|
process.exit(1);
|
|
524
1471
|
}
|
|
525
|
-
const config = options.config !== false ? await
|
|
1472
|
+
const config = options.config !== false ? await loadConfig() : void 0;
|
|
526
1473
|
const merged = mergeWithConfig(options, config);
|
|
527
1474
|
if (options.pretty) {
|
|
528
1475
|
ink.render(React3__default.default.createElement(RunApp, { task, options }));
|
|
@@ -536,13 +1483,92 @@ function createCli() {
|
|
|
536
1483
|
}
|
|
537
1484
|
}
|
|
538
1485
|
});
|
|
539
|
-
program.command("init").description("Generate a starter project.").option("--template <template>", "Starter template (react|ink)"
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
1486
|
+
program.command("init").description("Generate a starter project. Run with no flags for interactive mode.").option("--template <template>", "Starter template (react|ink|runtime|multi-agent)").option("--dir <directory>", "Target directory", "agentskit-app").option("--provider <provider>", "LLM provider (openai|anthropic|gemini|ollama|demo)").option("--tools <tools>", "Comma-separated tools (web_search,filesystem,shell)").option("--memory <backend>", "Memory backend (none|file|sqlite)").option("--pm <packageManager>", "Package manager (pnpm|npm|yarn|bun)").option("-y, --yes", "Skip interactive prompts; use flag values + defaults").action(async (rawOptions) => {
|
|
1487
|
+
const isCi = !process.stdout.isTTY || rawOptions.yes || rawOptions.template;
|
|
1488
|
+
let resolved;
|
|
1489
|
+
if (isCi) {
|
|
1490
|
+
const template = rawOptions.template ?? "react";
|
|
1491
|
+
resolved = {
|
|
1492
|
+
targetDir: path__default.default.resolve(process.cwd(), rawOptions.dir),
|
|
1493
|
+
template,
|
|
1494
|
+
provider: rawOptions.provider ?? "demo",
|
|
1495
|
+
tools: rawOptions.tools ? rawOptions.tools.split(",").map((t) => t.trim()) : [],
|
|
1496
|
+
memory: rawOptions.memory ?? "none",
|
|
1497
|
+
packageManager: rawOptions.pm ?? "pnpm"
|
|
1498
|
+
};
|
|
1499
|
+
} else {
|
|
1500
|
+
const result = await runInteractiveInit({
|
|
1501
|
+
dir: rawOptions.dir,
|
|
1502
|
+
template: rawOptions.template
|
|
1503
|
+
});
|
|
1504
|
+
if (result.cancelled) {
|
|
1505
|
+
process.exit(0);
|
|
1506
|
+
}
|
|
1507
|
+
resolved = result.options;
|
|
1508
|
+
}
|
|
1509
|
+
await writeStarterProject(resolved);
|
|
1510
|
+
if (isCi) {
|
|
1511
|
+
process.stdout.write(
|
|
1512
|
+
`Created ${resolved.template} starter in ${path__default.default.relative(process.cwd(), resolved.targetDir) || "."}
|
|
1513
|
+
`
|
|
1514
|
+
);
|
|
1515
|
+
} else {
|
|
1516
|
+
printNextSteps(resolved);
|
|
1517
|
+
}
|
|
1518
|
+
});
|
|
1519
|
+
program.command("doctor").description("Diagnose your AgentsKit environment.").option("--no-network", "Skip provider reachability checks").option(
|
|
1520
|
+
"--providers <providers>",
|
|
1521
|
+
"Comma-separated providers to check (default: openai,anthropic,gemini,ollama)"
|
|
1522
|
+
).option("--json", "Emit JSON instead of formatted output").action(async (options) => {
|
|
1523
|
+
const providers2 = options.providers ? options.providers.split(",").map((p) => p.trim()).filter(Boolean) : void 0;
|
|
1524
|
+
const report = await runDoctor({
|
|
1525
|
+
providers: providers2,
|
|
1526
|
+
noNetwork: options.network === false
|
|
543
1527
|
});
|
|
544
|
-
|
|
1528
|
+
if (options.json) {
|
|
1529
|
+
process.stdout.write(JSON.stringify(report, null, 2) + "\n");
|
|
1530
|
+
} else {
|
|
1531
|
+
process.stdout.write(renderReport(report, { color: process.stdout.isTTY }));
|
|
1532
|
+
}
|
|
1533
|
+
if (report.fail > 0) process.exit(1);
|
|
1534
|
+
});
|
|
1535
|
+
program.command("dev [entry]").description("Run an entry file with hot-reload on file changes.").option("--watch <globs>", "Comma-separated glob patterns to watch").option("--ignore <globs>", "Comma-separated glob patterns to ignore").option("--debounce <ms>", "Debounce window before restart", "200").action(async (positional, options) => {
|
|
1536
|
+
const entry = positional ?? "src/index.ts";
|
|
1537
|
+
const watch = options.watch ? options.watch.split(",").map((s) => s.trim()).filter(Boolean) : void 0;
|
|
1538
|
+
const ignore = options.ignore ? options.ignore.split(",").map((s) => s.trim()).filter(Boolean) : void 0;
|
|
1539
|
+
try {
|
|
1540
|
+
const controller = startDev({
|
|
1541
|
+
entry,
|
|
1542
|
+
watch,
|
|
1543
|
+
ignore,
|
|
1544
|
+
debounceMs: Number(options.debounce) || 200
|
|
1545
|
+
});
|
|
1546
|
+
await controller.done;
|
|
1547
|
+
} catch (err) {
|
|
1548
|
+
process.stderr.write(`Error: ${err.message}
|
|
545
1549
|
`);
|
|
1550
|
+
process.exit(1);
|
|
1551
|
+
}
|
|
1552
|
+
});
|
|
1553
|
+
program.command("tunnel <port>").description("Open a public URL pointing to a local port (great for webhooks).").option("--subdomain <name>", "Hint for a stable subdomain (provider may decline)").option("--host <host>", "Local hostname", "localhost").action(async (port, options) => {
|
|
1554
|
+
const portNum = Number(port);
|
|
1555
|
+
if (Number.isNaN(portNum) || portNum < 1 || portNum > 65535) {
|
|
1556
|
+
process.stderr.write(`Error: invalid port: ${port}
|
|
1557
|
+
`);
|
|
1558
|
+
process.exit(2);
|
|
1559
|
+
}
|
|
1560
|
+
try {
|
|
1561
|
+
const controller = await startTunnel({
|
|
1562
|
+
port: portNum,
|
|
1563
|
+
subdomain: options.subdomain,
|
|
1564
|
+
host: options.host
|
|
1565
|
+
});
|
|
1566
|
+
await controller.done;
|
|
1567
|
+
} catch (err) {
|
|
1568
|
+
process.stderr.write(`Error: ${err.message}
|
|
1569
|
+
`);
|
|
1570
|
+
process.exit(1);
|
|
1571
|
+
}
|
|
546
1572
|
});
|
|
547
1573
|
return program;
|
|
548
1574
|
}
|