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