@agentskit/cli 0.8.2 → 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/dist/bin.cjs +643 -2
- package/dist/bin.cjs.map +1 -1
- package/dist/bin.js +1 -1
- package/dist/{chunk-FLIR7BRS.js → chunk-ZEESHYST.js} +645 -4
- package/dist/chunk-ZEESHYST.js.map +1 -0
- package/dist/index.cjs +643 -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 +11 -11
- package/dist/chunk-FLIR7BRS.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -2079,6 +2079,635 @@ console.log(\`\\n\u2014 \${result.steps} steps \xB7 \${result.toolCalls.length}
|
|
|
2079
2079
|
"README.md": readmeFor(ctx)
|
|
2080
2080
|
};
|
|
2081
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
|
+
}
|
|
2082
2711
|
function readmeFor(ctx) {
|
|
2083
2712
|
const installCmd = ctx.pm === "npm" ? "npm install" : `${ctx.pm} install`;
|
|
2084
2713
|
const runCmd = ctx.pm === "npm" ? "npm run dev" : `${ctx.pm} dev`;
|
|
@@ -2116,9 +2745,15 @@ ISC
|
|
|
2116
2745
|
}
|
|
2117
2746
|
var TEMPLATE_FN = {
|
|
2118
2747
|
react: reactStarter,
|
|
2748
|
+
nextjs: nextjsStarter,
|
|
2119
2749
|
ink: inkStarter,
|
|
2120
2750
|
runtime: runtimeStarter,
|
|
2121
|
-
"multi-agent": multiAgentStarter
|
|
2751
|
+
"multi-agent": multiAgentStarter,
|
|
2752
|
+
sveltekit: sveltekitStarter,
|
|
2753
|
+
nuxt: nuxtStarter,
|
|
2754
|
+
"vite-ink": viteInkStarter,
|
|
2755
|
+
"cloudflare-workers": cloudflareWorkersStarter,
|
|
2756
|
+
bun: bunStarter
|
|
2122
2757
|
};
|
|
2123
2758
|
async function writeStarterProject(options) {
|
|
2124
2759
|
const ctx = {
|
|
@@ -2159,7 +2794,13 @@ ${kleur__default.default.bold().green("\u25B2")} ${kleur__default.default.bold("
|
|
|
2159
2794
|
default: defaults.template ?? "react",
|
|
2160
2795
|
choices: [
|
|
2161
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" },
|
|
2162
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" },
|
|
2163
2804
|
{ name: "Runtime (headless agent, no UI)", value: "runtime", description: "Autonomous task \u2192 result" },
|
|
2164
2805
|
{ name: "Multi-agent (planner + delegates)", value: "multi-agent", description: "Supervisor pattern, ready to extend" }
|
|
2165
2806
|
]
|
|
@@ -2268,7 +2909,7 @@ function printNextSteps(options) {
|
|
|
2268
2909
|
|
|
2269
2910
|
// src/commands/init.ts
|
|
2270
2911
|
function registerInitCommand(program) {
|
|
2271
|
-
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) => {
|
|
2272
2913
|
const isCi = !process.stdout.isTTY || rawOptions.yes || rawOptions.template;
|
|
2273
2914
|
let resolved;
|
|
2274
2915
|
if (isCi) {
|