@agentskit/cli 0.7.1 → 0.9.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 -2
- package/dist/bin.cjs +826 -2
- package/dist/bin.cjs.map +1 -1
- package/dist/bin.js +1 -1
- package/dist/{chunk-72XFU2X2.js → chunk-ZEESHYST.js} +828 -4
- package/dist/chunk-ZEESHYST.js.map +1 -0
- package/dist/index.cjs +826 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +22 -11
- package/dist/chunk-72XFU2X2.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -22,6 +22,7 @@ var prompts = require('@inquirer/prompts');
|
|
|
22
22
|
var kleur = require('kleur');
|
|
23
23
|
var chokidar = require('chokidar');
|
|
24
24
|
var rag = require('@agentskit/rag');
|
|
25
|
+
var agentSchema = require('@agentskit/core/agent-schema');
|
|
25
26
|
|
|
26
27
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
27
28
|
|
|
@@ -2078,6 +2079,635 @@ console.log(\`\\n\u2014 \${result.steps} steps \xB7 \${result.toolCalls.length}
|
|
|
2078
2079
|
"README.md": readmeFor(ctx)
|
|
2079
2080
|
};
|
|
2080
2081
|
}
|
|
2082
|
+
function buildAdapterServerImport(provider) {
|
|
2083
|
+
if (provider === "demo") return "";
|
|
2084
|
+
return `import { ${PROVIDER_IMPORT[provider]} } from '@agentskit/adapters'
|
|
2085
|
+
`;
|
|
2086
|
+
}
|
|
2087
|
+
function envExampleFor(provider) {
|
|
2088
|
+
const envKey = PROVIDER_ENV_KEY[provider];
|
|
2089
|
+
return envKey ? `${envKey}=
|
|
2090
|
+
` : "# No API key required for the demo provider\n";
|
|
2091
|
+
}
|
|
2092
|
+
function sveltekitStarter(ctx) {
|
|
2093
|
+
const deps = {
|
|
2094
|
+
"@agentskit/svelte": "^0.4.0",
|
|
2095
|
+
"@sveltejs/kit": "^2.0.0",
|
|
2096
|
+
svelte: "^5.0.0"
|
|
2097
|
+
};
|
|
2098
|
+
if (ctx.provider !== "demo") deps["@agentskit/adapters"] = "^0.4.0";
|
|
2099
|
+
const adapterCallStr = adapterCall(ctx.provider);
|
|
2100
|
+
const adapterImport2 = buildAdapterServerImport(ctx.provider);
|
|
2101
|
+
const demoSnippet = ctx.provider === "demo" ? demoAdapterSnippet() : "";
|
|
2102
|
+
return {
|
|
2103
|
+
"package.json": JSON.stringify(
|
|
2104
|
+
{
|
|
2105
|
+
name: "agentskit-sveltekit-app",
|
|
2106
|
+
private: true,
|
|
2107
|
+
type: "module",
|
|
2108
|
+
scripts: {
|
|
2109
|
+
dev: "vite dev",
|
|
2110
|
+
build: "vite build",
|
|
2111
|
+
preview: "vite preview",
|
|
2112
|
+
check: "svelte-check --tsconfig ./tsconfig.json"
|
|
2113
|
+
},
|
|
2114
|
+
dependencies: deps,
|
|
2115
|
+
devDependencies: {
|
|
2116
|
+
"@sveltejs/adapter-auto": "^4.0.0",
|
|
2117
|
+
"@sveltejs/vite-plugin-svelte": "^6.0.0",
|
|
2118
|
+
"svelte-check": "^4.0.0",
|
|
2119
|
+
typescript: "^5.5.0",
|
|
2120
|
+
vite: "^7.0.0"
|
|
2121
|
+
}
|
|
2122
|
+
},
|
|
2123
|
+
null,
|
|
2124
|
+
2
|
|
2125
|
+
) + "\n",
|
|
2126
|
+
"svelte.config.js": `import adapter from '@sveltejs/adapter-auto'
|
|
2127
|
+
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
|
|
2128
|
+
|
|
2129
|
+
export default {
|
|
2130
|
+
preprocess: vitePreprocess(),
|
|
2131
|
+
kit: { adapter: adapter() },
|
|
2132
|
+
}
|
|
2133
|
+
`,
|
|
2134
|
+
"vite.config.ts": `import { sveltekit } from '@sveltejs/kit/vite'
|
|
2135
|
+
import { defineConfig } from 'vite'
|
|
2136
|
+
export default defineConfig({ plugins: [sveltekit()] })
|
|
2137
|
+
`,
|
|
2138
|
+
"tsconfig.json": JSON.stringify(
|
|
2139
|
+
{
|
|
2140
|
+
extends: "./.svelte-kit/tsconfig.json",
|
|
2141
|
+
compilerOptions: {
|
|
2142
|
+
allowJs: true,
|
|
2143
|
+
checkJs: true,
|
|
2144
|
+
esModuleInterop: true,
|
|
2145
|
+
forceConsistentCasingInFileNames: true,
|
|
2146
|
+
resolveJsonModule: true,
|
|
2147
|
+
skipLibCheck: true,
|
|
2148
|
+
sourceMap: true,
|
|
2149
|
+
strict: true,
|
|
2150
|
+
moduleResolution: "bundler"
|
|
2151
|
+
}
|
|
2152
|
+
},
|
|
2153
|
+
null,
|
|
2154
|
+
2
|
|
2155
|
+
) + "\n",
|
|
2156
|
+
"src/app.html": `<!doctype html>
|
|
2157
|
+
<html lang="en">
|
|
2158
|
+
<head>
|
|
2159
|
+
<meta charset="utf-8" />
|
|
2160
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
2161
|
+
%sveltekit.head%
|
|
2162
|
+
</head>
|
|
2163
|
+
<body>%sveltekit.body%</body>
|
|
2164
|
+
</html>
|
|
2165
|
+
`,
|
|
2166
|
+
"src/routes/+page.svelte": `<script lang="ts">
|
|
2167
|
+
import { useChat } from '@agentskit/svelte'
|
|
2168
|
+
import '@agentskit/svelte/theme'
|
|
2169
|
+
|
|
2170
|
+
const chat = useChat({ endpoint: '/api/chat' })
|
|
2171
|
+
</script>
|
|
2172
|
+
|
|
2173
|
+
<main>
|
|
2174
|
+
{#each $chat.messages as message (message.id)}
|
|
2175
|
+
<article data-ak-message data-role={message.role}>{message.content}</article>
|
|
2176
|
+
{/each}
|
|
2177
|
+
<form on:submit|preventDefault={() => chat.send($chat.input)}>
|
|
2178
|
+
<input bind:value={$chat.input} />
|
|
2179
|
+
<button>Send</button>
|
|
2180
|
+
</form>
|
|
2181
|
+
</main>
|
|
2182
|
+
`,
|
|
2183
|
+
"src/routes/api/chat/+server.ts": `import type { RequestHandler } from './$types'
|
|
2184
|
+
${adapterImport2}${demoSnippet}export const POST: RequestHandler = async ({ request }) => {
|
|
2185
|
+
const { messages } = await request.json()
|
|
2186
|
+
const adapter = ${adapterCallStr}
|
|
2187
|
+
const source = adapter.createSource({ messages: messages.map((m: { role: string; content: string }, i: number) => ({
|
|
2188
|
+
id: String(i), role: m.role, content: m.content,
|
|
2189
|
+
status: 'complete' as const, createdAt: new Date(0),
|
|
2190
|
+
})) })
|
|
2191
|
+
|
|
2192
|
+
const stream = new ReadableStream<Uint8Array>({
|
|
2193
|
+
async start(controller) {
|
|
2194
|
+
const encoder = new TextEncoder()
|
|
2195
|
+
for await (const chunk of source.stream()) {
|
|
2196
|
+
if (chunk.type === 'text') controller.enqueue(encoder.encode(chunk.content))
|
|
2197
|
+
}
|
|
2198
|
+
controller.close()
|
|
2199
|
+
},
|
|
2200
|
+
})
|
|
2201
|
+
return new Response(stream, { headers: { 'content-type': 'text/plain; charset=utf-8' } })
|
|
2202
|
+
}
|
|
2203
|
+
`,
|
|
2204
|
+
".env.example": envExampleFor(ctx.provider),
|
|
2205
|
+
".gitignore": "node_modules\n.svelte-kit\nbuild\n.env\n.env.local\n",
|
|
2206
|
+
"README.md": readmeFor(ctx)
|
|
2207
|
+
};
|
|
2208
|
+
}
|
|
2209
|
+
function nuxtStarter(ctx) {
|
|
2210
|
+
const deps = {
|
|
2211
|
+
"@agentskit/vue": "^0.4.0",
|
|
2212
|
+
nuxt: "^4.0.0",
|
|
2213
|
+
vue: "^3.5.0"
|
|
2214
|
+
};
|
|
2215
|
+
if (ctx.provider !== "demo") deps["@agentskit/adapters"] = "^0.4.0";
|
|
2216
|
+
const adapterCallStr = adapterCall(ctx.provider);
|
|
2217
|
+
const adapterImport2 = buildAdapterServerImport(ctx.provider);
|
|
2218
|
+
const demoSnippet = ctx.provider === "demo" ? demoAdapterSnippet() : "";
|
|
2219
|
+
return {
|
|
2220
|
+
"package.json": JSON.stringify(
|
|
2221
|
+
{
|
|
2222
|
+
name: "agentskit-nuxt-app",
|
|
2223
|
+
private: true,
|
|
2224
|
+
type: "module",
|
|
2225
|
+
scripts: {
|
|
2226
|
+
dev: "nuxt dev",
|
|
2227
|
+
build: "nuxt build",
|
|
2228
|
+
preview: "nuxt preview",
|
|
2229
|
+
generate: "nuxt generate"
|
|
2230
|
+
},
|
|
2231
|
+
dependencies: deps,
|
|
2232
|
+
devDependencies: { typescript: "^5.5.0" }
|
|
2233
|
+
},
|
|
2234
|
+
null,
|
|
2235
|
+
2
|
|
2236
|
+
) + "\n",
|
|
2237
|
+
"nuxt.config.ts": `export default defineNuxtConfig({
|
|
2238
|
+
compatibilityDate: '2026-04-01',
|
|
2239
|
+
modules: [],
|
|
2240
|
+
typescript: { strict: true },
|
|
2241
|
+
})
|
|
2242
|
+
`,
|
|
2243
|
+
"tsconfig.json": JSON.stringify(
|
|
2244
|
+
{ extends: "./.nuxt/tsconfig.json" },
|
|
2245
|
+
null,
|
|
2246
|
+
2
|
|
2247
|
+
) + "\n",
|
|
2248
|
+
"app.vue": `<script setup lang="ts">
|
|
2249
|
+
import { useChat } from '@agentskit/vue'
|
|
2250
|
+
import '@agentskit/vue/theme'
|
|
2251
|
+
|
|
2252
|
+
const { messages, input, send } = useChat({ endpoint: '/api/chat' })
|
|
2253
|
+
</script>
|
|
2254
|
+
|
|
2255
|
+
<template>
|
|
2256
|
+
<main>
|
|
2257
|
+
<article v-for="message in messages" :key="message.id" :data-role="message.role">
|
|
2258
|
+
{{ message.content }}
|
|
2259
|
+
</article>
|
|
2260
|
+
<form @submit.prevent="send(input)">
|
|
2261
|
+
<input v-model="input" />
|
|
2262
|
+
<button>Send</button>
|
|
2263
|
+
</form>
|
|
2264
|
+
</main>
|
|
2265
|
+
</template>
|
|
2266
|
+
`,
|
|
2267
|
+
"server/api/chat.post.ts": `${adapterImport2}${demoSnippet}export default defineEventHandler(async (event) => {
|
|
2268
|
+
const { messages } = await readBody<{ messages: Array<{ role: string; content: string }> }>(event)
|
|
2269
|
+
const adapter = ${adapterCallStr}
|
|
2270
|
+
const source = adapter.createSource({ messages: messages.map((m, i) => ({
|
|
2271
|
+
id: String(i), role: m.role as 'user' | 'assistant' | 'system',
|
|
2272
|
+
content: m.content, status: 'complete' as const, createdAt: new Date(0),
|
|
2273
|
+
})) })
|
|
2274
|
+
|
|
2275
|
+
setHeader(event, 'content-type', 'text/plain; charset=utf-8')
|
|
2276
|
+
return sendStream(event, new ReadableStream<Uint8Array>({
|
|
2277
|
+
async start(controller) {
|
|
2278
|
+
const encoder = new TextEncoder()
|
|
2279
|
+
for await (const chunk of source.stream()) {
|
|
2280
|
+
if (chunk.type === 'text') controller.enqueue(encoder.encode(chunk.content))
|
|
2281
|
+
}
|
|
2282
|
+
controller.close()
|
|
2283
|
+
},
|
|
2284
|
+
}))
|
|
2285
|
+
})
|
|
2286
|
+
`,
|
|
2287
|
+
".env.example": envExampleFor(ctx.provider),
|
|
2288
|
+
".gitignore": "node_modules\n.nuxt\n.output\n.env\n.env.local\n",
|
|
2289
|
+
"README.md": readmeFor(ctx)
|
|
2290
|
+
};
|
|
2291
|
+
}
|
|
2292
|
+
function viteInkStarter(ctx) {
|
|
2293
|
+
const deps = {
|
|
2294
|
+
"@agentskit/ink": "^0.4.0",
|
|
2295
|
+
ink: "^7.0.0",
|
|
2296
|
+
react: "^19.0.0"
|
|
2297
|
+
};
|
|
2298
|
+
if (ctx.provider !== "demo") deps["@agentskit/adapters"] = "^0.4.0";
|
|
2299
|
+
if (ctx.tools.length > 0) deps["@agentskit/tools"] = "^0.4.0";
|
|
2300
|
+
return {
|
|
2301
|
+
"package.json": JSON.stringify(
|
|
2302
|
+
{
|
|
2303
|
+
name: "agentskit-vite-ink-app",
|
|
2304
|
+
private: true,
|
|
2305
|
+
type: "module",
|
|
2306
|
+
scripts: {
|
|
2307
|
+
dev: "vite-node --watch src/index.tsx",
|
|
2308
|
+
start: "vite-node src/index.tsx",
|
|
2309
|
+
build: "vite build"
|
|
2310
|
+
},
|
|
2311
|
+
dependencies: deps,
|
|
2312
|
+
devDependencies: {
|
|
2313
|
+
"@types/react": "^19.0.0",
|
|
2314
|
+
"vite-node": "^4.0.0",
|
|
2315
|
+
vite: "^7.0.0",
|
|
2316
|
+
typescript: "^5.5.0"
|
|
2317
|
+
}
|
|
2318
|
+
},
|
|
2319
|
+
null,
|
|
2320
|
+
2
|
|
2321
|
+
) + "\n",
|
|
2322
|
+
"vite.config.ts": `import { defineConfig } from 'vite'
|
|
2323
|
+
export default defineConfig({
|
|
2324
|
+
build: { ssr: true, target: 'node22', rollupOptions: { input: 'src/index.tsx' } },
|
|
2325
|
+
})
|
|
2326
|
+
`,
|
|
2327
|
+
"tsconfig.json": JSON.stringify(
|
|
2328
|
+
{
|
|
2329
|
+
compilerOptions: {
|
|
2330
|
+
target: "ES2022",
|
|
2331
|
+
module: "ESNext",
|
|
2332
|
+
moduleResolution: "bundler",
|
|
2333
|
+
jsx: "react-jsx",
|
|
2334
|
+
strict: true,
|
|
2335
|
+
noEmit: true,
|
|
2336
|
+
skipLibCheck: true
|
|
2337
|
+
},
|
|
2338
|
+
include: ["src"]
|
|
2339
|
+
},
|
|
2340
|
+
null,
|
|
2341
|
+
2
|
|
2342
|
+
) + "\n",
|
|
2343
|
+
"src/index.tsx": `import React from 'react'
|
|
2344
|
+
import { render } from 'ink'
|
|
2345
|
+
import { ChatContainer, InputBar, Message, useChat } from '@agentskit/ink'
|
|
2346
|
+
${adapterImport(ctx.provider)}${toolImports(ctx.tools)}
|
|
2347
|
+
${ctx.provider === "demo" ? demoAdapterSnippet() : ""}function App() {
|
|
2348
|
+
const chat = useChat({
|
|
2349
|
+
adapter: ${adapterCall(ctx.provider)},${ctx.tools.length > 0 ? `
|
|
2350
|
+
tools: ${toolList(ctx.tools)},` : ""}
|
|
2351
|
+
})
|
|
2352
|
+
|
|
2353
|
+
return (
|
|
2354
|
+
<ChatContainer>
|
|
2355
|
+
{chat.messages.map(message => (
|
|
2356
|
+
<Message key={message.id} message={message} />
|
|
2357
|
+
))}
|
|
2358
|
+
<InputBar chat={chat} />
|
|
2359
|
+
</ChatContainer>
|
|
2360
|
+
)
|
|
2361
|
+
}
|
|
2362
|
+
|
|
2363
|
+
render(<App />)
|
|
2364
|
+
`,
|
|
2365
|
+
".env.example": envExampleFor(ctx.provider),
|
|
2366
|
+
".gitignore": "node_modules\ndist\n.env\n.env.local\n.agentskit-history.*\n",
|
|
2367
|
+
"README.md": readmeFor(ctx)
|
|
2368
|
+
};
|
|
2369
|
+
}
|
|
2370
|
+
function cloudflareWorkersStarter(ctx) {
|
|
2371
|
+
const deps = {
|
|
2372
|
+
"itty-router": "^5.0.0"
|
|
2373
|
+
};
|
|
2374
|
+
if (ctx.provider !== "demo") deps["@agentskit/adapters"] = "^0.4.0";
|
|
2375
|
+
const adapterCallEdge = ctx.provider === "demo" ? "demoAdapter()" : ctx.provider === "ollama" ? `ollama({ model: '${PROVIDER_DEFAULT_MODEL[ctx.provider]}' })` : `${PROVIDER_IMPORT[ctx.provider]}({ apiKey: env.${PROVIDER_ENV_KEY[ctx.provider]} ?? '', model: '${PROVIDER_DEFAULT_MODEL[ctx.provider]}' })`;
|
|
2376
|
+
const adapterImport2 = buildAdapterServerImport(ctx.provider);
|
|
2377
|
+
const demoSnippet = ctx.provider === "demo" ? demoAdapterSnippet() : "";
|
|
2378
|
+
const envKey = PROVIDER_ENV_KEY[ctx.provider];
|
|
2379
|
+
return {
|
|
2380
|
+
"package.json": JSON.stringify(
|
|
2381
|
+
{
|
|
2382
|
+
name: "agentskit-cf-worker",
|
|
2383
|
+
private: true,
|
|
2384
|
+
type: "module",
|
|
2385
|
+
scripts: {
|
|
2386
|
+
dev: "wrangler dev",
|
|
2387
|
+
deploy: "wrangler deploy"
|
|
2388
|
+
},
|
|
2389
|
+
dependencies: deps,
|
|
2390
|
+
devDependencies: {
|
|
2391
|
+
"@cloudflare/workers-types": "^4.0.0",
|
|
2392
|
+
typescript: "^5.5.0",
|
|
2393
|
+
wrangler: "^3.0.0"
|
|
2394
|
+
}
|
|
2395
|
+
},
|
|
2396
|
+
null,
|
|
2397
|
+
2
|
|
2398
|
+
) + "\n",
|
|
2399
|
+
"wrangler.toml": `name = "agentskit-cf-worker"
|
|
2400
|
+
main = "src/worker.ts"
|
|
2401
|
+
compatibility_date = "2026-04-01"
|
|
2402
|
+
compatibility_flags = ["nodejs_compat"]
|
|
2403
|
+
|
|
2404
|
+
# Bind D1 + KV when you wire memory:
|
|
2405
|
+
# [[d1_databases]]
|
|
2406
|
+
# binding = "DB"
|
|
2407
|
+
# database_name = "agentskit"
|
|
2408
|
+
#
|
|
2409
|
+
# [[kv_namespaces]]
|
|
2410
|
+
# binding = "KV"
|
|
2411
|
+
# id = "..."
|
|
2412
|
+
|
|
2413
|
+
[vars]
|
|
2414
|
+
${envKey ? `# Set ${envKey} via 'wrangler secret put ${envKey}'` : "# No API key required for the demo provider"}
|
|
2415
|
+
`,
|
|
2416
|
+
"tsconfig.json": JSON.stringify(
|
|
2417
|
+
{
|
|
2418
|
+
compilerOptions: {
|
|
2419
|
+
target: "ES2022",
|
|
2420
|
+
module: "ESNext",
|
|
2421
|
+
moduleResolution: "bundler",
|
|
2422
|
+
lib: ["ES2022"],
|
|
2423
|
+
types: ["@cloudflare/workers-types"],
|
|
2424
|
+
strict: true,
|
|
2425
|
+
noEmit: true,
|
|
2426
|
+
skipLibCheck: true
|
|
2427
|
+
},
|
|
2428
|
+
include: ["src"]
|
|
2429
|
+
},
|
|
2430
|
+
null,
|
|
2431
|
+
2
|
|
2432
|
+
) + "\n",
|
|
2433
|
+
"src/worker.ts": `import { Router } from 'itty-router'
|
|
2434
|
+
${adapterImport2}
|
|
2435
|
+
${demoSnippet}interface Env {
|
|
2436
|
+
${envKey ? `${envKey}: string` : "/* no env vars */"}
|
|
2437
|
+
}
|
|
2438
|
+
|
|
2439
|
+
const router = Router()
|
|
2440
|
+
|
|
2441
|
+
router.post('/chat', async (request: Request, env: Env) => {
|
|
2442
|
+
const { messages } = await request.json() as { messages: Array<{ role: string; content: string }> }
|
|
2443
|
+
const adapter = ${adapterCallEdge}
|
|
2444
|
+
const source = adapter.createSource({ messages: messages.map((m, i) => ({
|
|
2445
|
+
id: String(i), role: m.role as 'user' | 'assistant' | 'system',
|
|
2446
|
+
content: m.content, status: 'complete' as const, createdAt: new Date(0),
|
|
2447
|
+
})) })
|
|
2448
|
+
|
|
2449
|
+
const stream = new ReadableStream<Uint8Array>({
|
|
2450
|
+
async start(controller) {
|
|
2451
|
+
const encoder = new TextEncoder()
|
|
2452
|
+
for await (const chunk of source.stream()) {
|
|
2453
|
+
if (chunk.type === 'text') controller.enqueue(encoder.encode(chunk.content))
|
|
2454
|
+
}
|
|
2455
|
+
controller.close()
|
|
2456
|
+
},
|
|
2457
|
+
})
|
|
2458
|
+
return new Response(stream, { headers: { 'content-type': 'text/plain; charset=utf-8' } })
|
|
2459
|
+
})
|
|
2460
|
+
|
|
2461
|
+
router.all('*', () => new Response('not found', { status: 404 }))
|
|
2462
|
+
|
|
2463
|
+
export default {
|
|
2464
|
+
fetch: (req: Request, env: Env, ctx: ExecutionContext) => router.handle(req, env, ctx),
|
|
2465
|
+
} satisfies ExportedHandler<Env>
|
|
2466
|
+
`,
|
|
2467
|
+
".env.example": envExampleFor(ctx.provider),
|
|
2468
|
+
".gitignore": "node_modules\n.wrangler\n.dev.vars\n.env\n.env.local\n",
|
|
2469
|
+
"README.md": readmeFor(ctx)
|
|
2470
|
+
};
|
|
2471
|
+
}
|
|
2472
|
+
function bunStarter(ctx) {
|
|
2473
|
+
const deps = {};
|
|
2474
|
+
if (ctx.provider !== "demo") deps["@agentskit/adapters"] = "^0.4.0";
|
|
2475
|
+
const adapterCallStr = adapterCall(ctx.provider);
|
|
2476
|
+
const adapterImport2 = buildAdapterServerImport(ctx.provider);
|
|
2477
|
+
const demoSnippet = ctx.provider === "demo" ? demoAdapterSnippet() : "";
|
|
2478
|
+
return {
|
|
2479
|
+
"package.json": JSON.stringify(
|
|
2480
|
+
{
|
|
2481
|
+
name: "agentskit-bun-server",
|
|
2482
|
+
private: true,
|
|
2483
|
+
type: "module",
|
|
2484
|
+
scripts: {
|
|
2485
|
+
dev: "bun --hot src/server.ts",
|
|
2486
|
+
start: "bun src/server.ts"
|
|
2487
|
+
},
|
|
2488
|
+
dependencies: deps,
|
|
2489
|
+
devDependencies: { typescript: "^5.5.0" }
|
|
2490
|
+
},
|
|
2491
|
+
null,
|
|
2492
|
+
2
|
|
2493
|
+
) + "\n",
|
|
2494
|
+
"tsconfig.json": JSON.stringify(
|
|
2495
|
+
{
|
|
2496
|
+
compilerOptions: {
|
|
2497
|
+
target: "ES2022",
|
|
2498
|
+
module: "ESNext",
|
|
2499
|
+
moduleResolution: "bundler",
|
|
2500
|
+
types: ["bun-types"],
|
|
2501
|
+
strict: true,
|
|
2502
|
+
noEmit: true,
|
|
2503
|
+
skipLibCheck: true
|
|
2504
|
+
},
|
|
2505
|
+
include: ["src"]
|
|
2506
|
+
},
|
|
2507
|
+
null,
|
|
2508
|
+
2
|
|
2509
|
+
) + "\n",
|
|
2510
|
+
"src/server.ts": `${adapterImport2}${demoSnippet}const adapter = ${adapterCallStr}
|
|
2511
|
+
|
|
2512
|
+
const server = Bun.serve({
|
|
2513
|
+
port: Number(process.env.PORT ?? 3000),
|
|
2514
|
+
async fetch(request) {
|
|
2515
|
+
const url = new URL(request.url)
|
|
2516
|
+
if (request.method === 'POST' && url.pathname === '/chat') {
|
|
2517
|
+
const { messages } = await request.json() as { messages: Array<{ role: string; content: string }> }
|
|
2518
|
+
const source = adapter.createSource({ messages: messages.map((m, i) => ({
|
|
2519
|
+
id: String(i), role: m.role as 'user' | 'assistant' | 'system',
|
|
2520
|
+
content: m.content, status: 'complete' as const, createdAt: new Date(0),
|
|
2521
|
+
})) })
|
|
2522
|
+
const stream = new ReadableStream<Uint8Array>({
|
|
2523
|
+
async start(controller) {
|
|
2524
|
+
const encoder = new TextEncoder()
|
|
2525
|
+
for await (const chunk of source.stream()) {
|
|
2526
|
+
if (chunk.type === 'text') controller.enqueue(encoder.encode(chunk.content))
|
|
2527
|
+
}
|
|
2528
|
+
controller.close()
|
|
2529
|
+
},
|
|
2530
|
+
})
|
|
2531
|
+
return new Response(stream, { headers: { 'content-type': 'text/plain; charset=utf-8' } })
|
|
2532
|
+
}
|
|
2533
|
+
if (url.pathname === '/') {
|
|
2534
|
+
return new Response(\`<!doctype html><title>AgentsKit Bun starter</title>
|
|
2535
|
+
<body><pre>POST /chat with { messages: [...] }</pre></body>\`, {
|
|
2536
|
+
headers: { 'content-type': 'text/html' },
|
|
2537
|
+
})
|
|
2538
|
+
}
|
|
2539
|
+
return new Response('not found', { status: 404 })
|
|
2540
|
+
},
|
|
2541
|
+
})
|
|
2542
|
+
|
|
2543
|
+
console.log(\`Listening on http://localhost:\${server.port}\`)
|
|
2544
|
+
`,
|
|
2545
|
+
".env.example": envExampleFor(ctx.provider),
|
|
2546
|
+
".gitignore": "node_modules\n.env\n.env.local\nbun.lockb\n",
|
|
2547
|
+
"README.md": readmeFor(ctx)
|
|
2548
|
+
};
|
|
2549
|
+
}
|
|
2550
|
+
function nextjsStarter(ctx) {
|
|
2551
|
+
const deps = {
|
|
2552
|
+
"@agentskit/react": "^0.4.0",
|
|
2553
|
+
next: "^15.0.0",
|
|
2554
|
+
react: "^19.0.0",
|
|
2555
|
+
"react-dom": "^19.0.0"
|
|
2556
|
+
};
|
|
2557
|
+
if (ctx.provider !== "demo") deps["@agentskit/adapters"] = "^0.4.0";
|
|
2558
|
+
if (ctx.tools.length > 0) deps["@agentskit/tools"] = "^0.4.0";
|
|
2559
|
+
const envKey = PROVIDER_ENV_KEY[ctx.provider];
|
|
2560
|
+
const adapter = adapterCall(ctx.provider);
|
|
2561
|
+
const apiAdapterImport = ctx.provider === "demo" ? "" : `import { ${PROVIDER_IMPORT[ctx.provider]} } from '@agentskit/adapters'
|
|
2562
|
+
`;
|
|
2563
|
+
const apiDemoSnippet = ctx.provider === "demo" ? demoAdapterSnippet() : "";
|
|
2564
|
+
return {
|
|
2565
|
+
"package.json": JSON.stringify(
|
|
2566
|
+
{
|
|
2567
|
+
name: "agentskit-nextjs-app",
|
|
2568
|
+
private: true,
|
|
2569
|
+
type: "module",
|
|
2570
|
+
scripts: {
|
|
2571
|
+
dev: "next dev",
|
|
2572
|
+
build: "next build",
|
|
2573
|
+
start: "next start",
|
|
2574
|
+
lint: "next lint"
|
|
2575
|
+
},
|
|
2576
|
+
dependencies: deps,
|
|
2577
|
+
devDependencies: {
|
|
2578
|
+
"@types/node": "^22.0.0",
|
|
2579
|
+
"@types/react": "^19.0.0",
|
|
2580
|
+
"@types/react-dom": "^19.0.0",
|
|
2581
|
+
typescript: "^5.5.0"
|
|
2582
|
+
}
|
|
2583
|
+
},
|
|
2584
|
+
null,
|
|
2585
|
+
2
|
|
2586
|
+
) + "\n",
|
|
2587
|
+
"next.config.mjs": `/** @type {import('next').NextConfig} */
|
|
2588
|
+
const nextConfig = {}
|
|
2589
|
+
export default nextConfig
|
|
2590
|
+
`,
|
|
2591
|
+
"tsconfig.json": JSON.stringify(
|
|
2592
|
+
{
|
|
2593
|
+
compilerOptions: {
|
|
2594
|
+
target: "ES2022",
|
|
2595
|
+
lib: ["dom", "dom.iterable", "ES2022"],
|
|
2596
|
+
allowJs: true,
|
|
2597
|
+
skipLibCheck: true,
|
|
2598
|
+
strict: true,
|
|
2599
|
+
noEmit: true,
|
|
2600
|
+
esModuleInterop: true,
|
|
2601
|
+
module: "ESNext",
|
|
2602
|
+
moduleResolution: "bundler",
|
|
2603
|
+
resolveJsonModule: true,
|
|
2604
|
+
isolatedModules: true,
|
|
2605
|
+
jsx: "preserve",
|
|
2606
|
+
incremental: true,
|
|
2607
|
+
plugins: [{ name: "next" }],
|
|
2608
|
+
paths: { "@/*": ["./*"] }
|
|
2609
|
+
},
|
|
2610
|
+
include: ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
|
2611
|
+
exclude: ["node_modules"]
|
|
2612
|
+
},
|
|
2613
|
+
null,
|
|
2614
|
+
2
|
|
2615
|
+
) + "\n",
|
|
2616
|
+
"app/layout.tsx": `import type { ReactNode } from 'react'
|
|
2617
|
+
import '@agentskit/react/theme'
|
|
2618
|
+
|
|
2619
|
+
export const metadata = { title: 'AgentsKit \xB7 Next.js Starter' }
|
|
2620
|
+
|
|
2621
|
+
export default function RootLayout({ children }: { children: ReactNode }) {
|
|
2622
|
+
return (
|
|
2623
|
+
<html lang="en">
|
|
2624
|
+
<body>{children}</body>
|
|
2625
|
+
</html>
|
|
2626
|
+
)
|
|
2627
|
+
}
|
|
2628
|
+
`,
|
|
2629
|
+
"app/page.tsx": `'use client'
|
|
2630
|
+
|
|
2631
|
+
import { ChatContainer, InputBar, Message, useChat } from '@agentskit/react'
|
|
2632
|
+
import { genericAdapter } from './chat-adapter'
|
|
2633
|
+
|
|
2634
|
+
export default function Page() {
|
|
2635
|
+
const chat = useChat({ adapter: genericAdapter('/api/chat') })
|
|
2636
|
+
|
|
2637
|
+
return (
|
|
2638
|
+
<main style={{ display: 'grid', placeItems: 'center', minHeight: '100dvh' }}>
|
|
2639
|
+
<ChatContainer>
|
|
2640
|
+
{chat.messages.map(message => (
|
|
2641
|
+
<Message key={message.id} message={message} />
|
|
2642
|
+
))}
|
|
2643
|
+
<InputBar chat={chat} />
|
|
2644
|
+
</ChatContainer>
|
|
2645
|
+
</main>
|
|
2646
|
+
)
|
|
2647
|
+
}
|
|
2648
|
+
`,
|
|
2649
|
+
"app/chat-adapter.ts": `import { generic } from '@agentskit/adapters'
|
|
2650
|
+
|
|
2651
|
+
export const genericAdapter = (route: string) => generic({
|
|
2652
|
+
fetch: async ({ messages, signal }) => {
|
|
2653
|
+
const response = await fetch(route, {
|
|
2654
|
+
method: 'POST',
|
|
2655
|
+
headers: { 'Content-Type': 'application/json' },
|
|
2656
|
+
body: JSON.stringify({ messages }),
|
|
2657
|
+
signal,
|
|
2658
|
+
})
|
|
2659
|
+
if (!response.body) throw new Error('No body returned from /api/chat')
|
|
2660
|
+
return response
|
|
2661
|
+
},
|
|
2662
|
+
})
|
|
2663
|
+
`,
|
|
2664
|
+
"app/api/chat/route.ts": `${apiAdapterImport}${apiDemoSnippet}export const runtime = 'edge'
|
|
2665
|
+
|
|
2666
|
+
export async function POST(request: Request) {
|
|
2667
|
+
const { messages } = await request.json() as { messages: Array<{ role: string; content: string }> }
|
|
2668
|
+
|
|
2669
|
+
const adapter = ${adapter}
|
|
2670
|
+
|
|
2671
|
+
const source = adapter.createSource({ messages: messages.map((message, index) => ({
|
|
2672
|
+
id: String(index),
|
|
2673
|
+
role: message.role as 'user' | 'assistant' | 'system',
|
|
2674
|
+
content: message.content,
|
|
2675
|
+
status: 'complete' as const,
|
|
2676
|
+
createdAt: new Date(0),
|
|
2677
|
+
})) })
|
|
2678
|
+
|
|
2679
|
+
const stream = new ReadableStream<Uint8Array>({
|
|
2680
|
+
async start(controller) {
|
|
2681
|
+
const encoder = new TextEncoder()
|
|
2682
|
+
try {
|
|
2683
|
+
for await (const chunk of source.stream()) {
|
|
2684
|
+
if (chunk.type === 'text') controller.enqueue(encoder.encode(chunk.content))
|
|
2685
|
+
}
|
|
2686
|
+
} catch (err) {
|
|
2687
|
+
controller.error(err)
|
|
2688
|
+
return
|
|
2689
|
+
}
|
|
2690
|
+
controller.close()
|
|
2691
|
+
},
|
|
2692
|
+
})
|
|
2693
|
+
|
|
2694
|
+
return new Response(stream, {
|
|
2695
|
+
headers: { 'Content-Type': 'text/plain; charset=utf-8', 'Cache-Control': 'no-cache' },
|
|
2696
|
+
})
|
|
2697
|
+
}
|
|
2698
|
+
`,
|
|
2699
|
+
".env.example": envKey ? `${envKey}=
|
|
2700
|
+
` : "# No API key required for the demo provider\n",
|
|
2701
|
+
".gitignore": `node_modules
|
|
2702
|
+
.next
|
|
2703
|
+
out
|
|
2704
|
+
.env
|
|
2705
|
+
.env.local
|
|
2706
|
+
.agentskit-history.*
|
|
2707
|
+
`,
|
|
2708
|
+
"README.md": readmeFor(ctx)
|
|
2709
|
+
};
|
|
2710
|
+
}
|
|
2081
2711
|
function readmeFor(ctx) {
|
|
2082
2712
|
const installCmd = ctx.pm === "npm" ? "npm install" : `${ctx.pm} install`;
|
|
2083
2713
|
const runCmd = ctx.pm === "npm" ? "npm run dev" : `${ctx.pm} dev`;
|
|
@@ -2115,9 +2745,15 @@ ISC
|
|
|
2115
2745
|
}
|
|
2116
2746
|
var TEMPLATE_FN = {
|
|
2117
2747
|
react: reactStarter,
|
|
2748
|
+
nextjs: nextjsStarter,
|
|
2118
2749
|
ink: inkStarter,
|
|
2119
2750
|
runtime: runtimeStarter,
|
|
2120
|
-
"multi-agent": multiAgentStarter
|
|
2751
|
+
"multi-agent": multiAgentStarter,
|
|
2752
|
+
sveltekit: sveltekitStarter,
|
|
2753
|
+
nuxt: nuxtStarter,
|
|
2754
|
+
"vite-ink": viteInkStarter,
|
|
2755
|
+
"cloudflare-workers": cloudflareWorkersStarter,
|
|
2756
|
+
bun: bunStarter
|
|
2121
2757
|
};
|
|
2122
2758
|
async function writeStarterProject(options) {
|
|
2123
2759
|
const ctx = {
|
|
@@ -2158,7 +2794,13 @@ ${kleur__default.default.bold().green("\u25B2")} ${kleur__default.default.bold("
|
|
|
2158
2794
|
default: defaults.template ?? "react",
|
|
2159
2795
|
choices: [
|
|
2160
2796
|
{ name: "React chat (Vite + browser)", value: "react", description: "Streaming UI with @agentskit/react" },
|
|
2797
|
+
{ name: "Next.js chat (App Router + Route Handler)", value: "nextjs", description: "app/api/chat streams to a useChat client" },
|
|
2798
|
+
{ name: "SvelteKit chat", value: "sveltekit", description: "@agentskit/svelte client + server route streaming" },
|
|
2799
|
+
{ name: "Nuxt chat", value: "nuxt", description: "@agentskit/vue composable + Nitro server route streaming" },
|
|
2161
2800
|
{ name: "Ink chat (terminal UI)", value: "ink", description: "Same chat but in your terminal" },
|
|
2801
|
+
{ name: "Vite + Ink (terminal, hot-reload)", value: "vite-ink", description: "Ink chat with vite-node hot reload" },
|
|
2802
|
+
{ name: "Cloudflare Workers (edge)", value: "cloudflare-workers", description: "Edge runtime with itty-router + streaming" },
|
|
2803
|
+
{ name: "Bun server", value: "bun", description: "Bun.serve with hot reload" },
|
|
2162
2804
|
{ name: "Runtime (headless agent, no UI)", value: "runtime", description: "Autonomous task \u2192 result" },
|
|
2163
2805
|
{ name: "Multi-agent (planner + delegates)", value: "multi-agent", description: "Supervisor pattern, ready to extend" }
|
|
2164
2806
|
]
|
|
@@ -2267,7 +2909,7 @@ function printNextSteps(options) {
|
|
|
2267
2909
|
|
|
2268
2910
|
// src/commands/init.ts
|
|
2269
2911
|
function registerInitCommand(program) {
|
|
2270
|
-
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) => {
|
|
2912
|
+
program.command("init").description("Generate a starter project. Run with no flags for interactive mode.").option("--template <template>", "Starter template (react|nextjs|sveltekit|nuxt|ink|vite-ink|cloudflare-workers|bun|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) => {
|
|
2271
2913
|
const isCi = !process.stdout.isTTY || rawOptions.yes || rawOptions.template;
|
|
2272
2914
|
let resolved;
|
|
2273
2915
|
if (isCi) {
|
|
@@ -2959,6 +3601,187 @@ function registerRagCommand(program) {
|
|
|
2959
3601
|
});
|
|
2960
3602
|
}
|
|
2961
3603
|
|
|
3604
|
+
// src/ai/scaffold.ts
|
|
3605
|
+
function snakeToCamel(name) {
|
|
3606
|
+
return name.replace(/[-_](\w)/g, (_, c) => c.toUpperCase());
|
|
3607
|
+
}
|
|
3608
|
+
function toolStub(tool) {
|
|
3609
|
+
const fnName = snakeToCamel(tool.name);
|
|
3610
|
+
const schema = tool.schema ? JSON.stringify(tool.schema, null, 2) : '{ type: "object", properties: {} }';
|
|
3611
|
+
return `import { defineTool } from '@agentskit/core'
|
|
3612
|
+
|
|
3613
|
+
/**
|
|
3614
|
+
* ${tool.description ?? tool.name}
|
|
3615
|
+
* ${tool.implementation ? `
|
|
3616
|
+
* Implementation hint: ${tool.implementation}` : ""}
|
|
3617
|
+
*/
|
|
3618
|
+
export const ${fnName} = defineTool({
|
|
3619
|
+
name: '${tool.name}',
|
|
3620
|
+
description: ${JSON.stringify(tool.description ?? "")},
|
|
3621
|
+
schema: ${schema} as const,
|
|
3622
|
+
${tool.requiresConfirmation ? "requiresConfirmation: true," : ""}
|
|
3623
|
+
async execute(args) {
|
|
3624
|
+
// TODO: implement ${tool.name}
|
|
3625
|
+
return { args }
|
|
3626
|
+
},
|
|
3627
|
+
})
|
|
3628
|
+
`;
|
|
3629
|
+
}
|
|
3630
|
+
function indexTs(schema) {
|
|
3631
|
+
const toolImports2 = (schema.tools ?? []).map((t) => `import { ${snakeToCamel(t.name)} } from './tools/${t.name}'`).join("\n");
|
|
3632
|
+
const toolList2 = (schema.tools ?? []).map((t) => snakeToCamel(t.name)).join(", ");
|
|
3633
|
+
return `import { createRuntime } from '@agentskit/runtime'
|
|
3634
|
+
${toolImports2}
|
|
3635
|
+
|
|
3636
|
+
export const agent = {
|
|
3637
|
+
name: '${schema.name}',
|
|
3638
|
+
systemPrompt: ${JSON.stringify(schema.systemPrompt ?? "")},
|
|
3639
|
+
tools: [${toolList2}],
|
|
3640
|
+
}
|
|
3641
|
+
|
|
3642
|
+
export function createAgent(adapter: Parameters<typeof createRuntime>[0]['adapter']) {
|
|
3643
|
+
return createRuntime({
|
|
3644
|
+
adapter,
|
|
3645
|
+
systemPrompt: agent.systemPrompt,
|
|
3646
|
+
tools: agent.tools,
|
|
3647
|
+
})
|
|
3648
|
+
}
|
|
3649
|
+
`;
|
|
3650
|
+
}
|
|
3651
|
+
function readme(schema) {
|
|
3652
|
+
const lines = [];
|
|
3653
|
+
lines.push(`# ${schema.name}`);
|
|
3654
|
+
lines.push("");
|
|
3655
|
+
if (schema.description) lines.push(schema.description, "");
|
|
3656
|
+
lines.push(`## Model`);
|
|
3657
|
+
lines.push("");
|
|
3658
|
+
lines.push(`- Provider: \`${schema.model.provider}\``);
|
|
3659
|
+
if (schema.model.model) lines.push(`- Model: \`${schema.model.model}\``);
|
|
3660
|
+
lines.push("");
|
|
3661
|
+
if (schema.tools && schema.tools.length > 0) {
|
|
3662
|
+
lines.push("## Tools");
|
|
3663
|
+
lines.push("");
|
|
3664
|
+
for (const t of schema.tools) {
|
|
3665
|
+
lines.push(`- \`${t.name}\` \u2014 ${t.description ?? ""}`);
|
|
3666
|
+
}
|
|
3667
|
+
lines.push("");
|
|
3668
|
+
}
|
|
3669
|
+
if (schema.skills && schema.skills.length > 0) {
|
|
3670
|
+
lines.push("## Skills");
|
|
3671
|
+
lines.push("");
|
|
3672
|
+
for (const s of schema.skills) lines.push(`- ${s}`);
|
|
3673
|
+
lines.push("");
|
|
3674
|
+
}
|
|
3675
|
+
lines.push("## Generated by");
|
|
3676
|
+
lines.push("");
|
|
3677
|
+
lines.push('`npx agentskit ai "<description>"`');
|
|
3678
|
+
lines.push("");
|
|
3679
|
+
return lines.join("\n");
|
|
3680
|
+
}
|
|
3681
|
+
function scaffoldAgent(schema) {
|
|
3682
|
+
const files = [
|
|
3683
|
+
{ path: "agent.json", content: JSON.stringify(schema, null, 2) + "\n" },
|
|
3684
|
+
{ path: "agent.ts", content: indexTs(schema) },
|
|
3685
|
+
{ path: "README.md", content: readme(schema) }
|
|
3686
|
+
];
|
|
3687
|
+
for (const tool of schema.tools ?? []) {
|
|
3688
|
+
files.push({ path: `tools/${tool.name}.ts`, content: toolStub(tool) });
|
|
3689
|
+
}
|
|
3690
|
+
return files;
|
|
3691
|
+
}
|
|
3692
|
+
async function writeScaffold(files, outDir, opts = {}) {
|
|
3693
|
+
const { writeFile: writeFile2, mkdir: mkdir2, access } = await import('fs/promises');
|
|
3694
|
+
const { dirname, join: join5 } = await import('path');
|
|
3695
|
+
const written = [];
|
|
3696
|
+
for (const f of files) {
|
|
3697
|
+
const full = join5(outDir, f.path);
|
|
3698
|
+
await mkdir2(dirname(full), { recursive: true });
|
|
3699
|
+
if (!opts.overwrite) {
|
|
3700
|
+
try {
|
|
3701
|
+
await access(full);
|
|
3702
|
+
continue;
|
|
3703
|
+
} catch {
|
|
3704
|
+
}
|
|
3705
|
+
}
|
|
3706
|
+
await writeFile2(full, f.content, "utf8");
|
|
3707
|
+
written.push(f.path);
|
|
3708
|
+
}
|
|
3709
|
+
return written;
|
|
3710
|
+
}
|
|
3711
|
+
var PLANNER_SYSTEM_PROMPT = `You design AI agents for the AgentsKit framework.
|
|
3712
|
+
Given a user's plain-language description, return a single JSON object
|
|
3713
|
+
matching the AgentsKit AgentSchema type. Do not include commentary or
|
|
3714
|
+
markdown fences \u2014 emit raw JSON only.
|
|
3715
|
+
|
|
3716
|
+
Schema:
|
|
3717
|
+
{
|
|
3718
|
+
"name": "kebab-or-snake-case",
|
|
3719
|
+
"description": "short summary",
|
|
3720
|
+
"systemPrompt": "you are...",
|
|
3721
|
+
"model": { "provider": "anthropic"|"openai"|"gemini"|..., "model": "..." },
|
|
3722
|
+
"tools": [{ "name": "search", "description": "...", "schema": {...}, "implementation": "fetch('/api/search?q=...')" }],
|
|
3723
|
+
"memory": { "kind": "inMemory"|"localStorage", "key": "..." },
|
|
3724
|
+
"skills": ["researcher", "critic"]
|
|
3725
|
+
}
|
|
3726
|
+
|
|
3727
|
+
Prefer fewer well-scoped tools over many overlapping ones. Name tools
|
|
3728
|
+
in snake_case.`;
|
|
3729
|
+
function extractJson(text) {
|
|
3730
|
+
const fenced = text.match(/```(?:json)?\s*([\s\S]+?)```/);
|
|
3731
|
+
const raw = fenced?.[1] ?? text;
|
|
3732
|
+
const start = raw.indexOf("{");
|
|
3733
|
+
const end = raw.lastIndexOf("}");
|
|
3734
|
+
if (start < 0 || end <= start) throw new Error("Planner response did not contain a JSON object");
|
|
3735
|
+
return raw.slice(start, end + 1);
|
|
3736
|
+
}
|
|
3737
|
+
function createAdapterPlanner(adapter) {
|
|
3738
|
+
return async (description) => {
|
|
3739
|
+
const messages = [
|
|
3740
|
+
{ id: "sys", role: "system", content: PLANNER_SYSTEM_PROMPT, status: "complete", createdAt: /* @__PURE__ */ new Date(0) },
|
|
3741
|
+
{ id: "user", role: "user", content: description, status: "complete", createdAt: /* @__PURE__ */ new Date(0) }
|
|
3742
|
+
];
|
|
3743
|
+
const request = { messages, context: { temperature: 0 } };
|
|
3744
|
+
const source = adapter.createSource(request);
|
|
3745
|
+
let text = "";
|
|
3746
|
+
for await (const chunk of source.stream()) {
|
|
3747
|
+
if (chunk.type === "text" && chunk.content) text += chunk.content;
|
|
3748
|
+
}
|
|
3749
|
+
const json = extractJson(text);
|
|
3750
|
+
return agentSchema.validateAgentSchema(JSON.parse(json));
|
|
3751
|
+
};
|
|
3752
|
+
}
|
|
3753
|
+
|
|
3754
|
+
// src/commands/ai.ts
|
|
3755
|
+
function registerAiCommand(program) {
|
|
3756
|
+
program.command("ai <description...>").description("Generate an agent (config + tools + skill wiring) from a natural-language description.").option("-o, --out <dir>", "Output directory", "./my-agent").option("--provider <provider>", "Planner provider (openai | anthropic | ...)", "anthropic").option("--model <model>", "Planner model id").option("--api-key <key>", "API key (falls back to env)").option("--base-url <url>", "Override base URL (for OpenAI-compatible endpoints)").option("--overwrite", "Overwrite existing files", false).option("--dry-run", "Print the plan + files without writing", false).action(async (descriptionWords, options) => {
|
|
3757
|
+
const description = descriptionWords.join(" ").trim();
|
|
3758
|
+
if (!description) {
|
|
3759
|
+
process.stderr.write("agentskit ai: missing description.\n");
|
|
3760
|
+
process.exit(1);
|
|
3761
|
+
}
|
|
3762
|
+
const resolved = resolveChatProvider({
|
|
3763
|
+
provider: options.provider,
|
|
3764
|
+
model: options.model,
|
|
3765
|
+
apiKey: options.apiKey,
|
|
3766
|
+
baseUrl: options.baseUrl
|
|
3767
|
+
});
|
|
3768
|
+
const planner2 = createAdapterPlanner(resolved.adapter);
|
|
3769
|
+
process.stderr.write(`Planning agent for: "${description}"
|
|
3770
|
+
`);
|
|
3771
|
+
const schema = await planner2(description);
|
|
3772
|
+
const files = scaffoldAgent(schema);
|
|
3773
|
+
if (options.dryRun) {
|
|
3774
|
+
process.stdout.write(JSON.stringify({ schema, files: files.map((f) => f.path) }, null, 2) + "\n");
|
|
3775
|
+
return;
|
|
3776
|
+
}
|
|
3777
|
+
const written = await writeScaffold(files, options.out, { overwrite: options.overwrite });
|
|
3778
|
+
process.stderr.write(`Wrote ${written.length} file(s) to ${options.out}
|
|
3779
|
+
`);
|
|
3780
|
+
for (const f of written) process.stderr.write(` + ${f}
|
|
3781
|
+
`);
|
|
3782
|
+
});
|
|
3783
|
+
}
|
|
3784
|
+
|
|
2962
3785
|
// src/commands/index.ts
|
|
2963
3786
|
function createCli() {
|
|
2964
3787
|
const program = new commander.Command();
|
|
@@ -2971,6 +3794,7 @@ function createCli() {
|
|
|
2971
3794
|
registerConfigCommand(program);
|
|
2972
3795
|
registerTunnelCommand(program);
|
|
2973
3796
|
registerRagCommand(program);
|
|
3797
|
+
registerAiCommand(program);
|
|
2974
3798
|
return program;
|
|
2975
3799
|
}
|
|
2976
3800
|
|