@andreprado/agentkit 0.1.0-alpha.10

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.
Files changed (122) hide show
  1. package/README.md +69 -0
  2. package/bin/agentkit.mjs +23 -0
  3. package/docs/guides/add-channel.md +114 -0
  4. package/docs/guides/add-knowledge.md +134 -0
  5. package/docs/guides/add-tool.md +342 -0
  6. package/docs/guides/agentkit-skills-architecture.md +471 -0
  7. package/docs/guides/channel-security.md +81 -0
  8. package/docs/guides/channels-implementation-map.md +243 -0
  9. package/docs/guides/channels-production-handoff.md +102 -0
  10. package/docs/guides/connect-telegram.md +110 -0
  11. package/docs/guides/connect-whatsapp-zapster.md +119 -0
  12. package/docs/guides/create-agent.md +220 -0
  13. package/docs/guides/prepare-deploy.md +209 -0
  14. package/docs/guides/run-evals.md +179 -0
  15. package/docs/guides/security-rules.md +156 -0
  16. package/docs/guides/use-provider.md +140 -0
  17. package/docs/llms-full.txt +876 -0
  18. package/docs/llms.txt +83 -0
  19. package/docs/portable-deploy-release-checklist.md +41 -0
  20. package/package.json +47 -0
  21. package/src/cli/args.ts +36 -0
  22. package/src/cli/cloud-client.ts +265 -0
  23. package/src/cli/commands/channels.ts +810 -0
  24. package/src/cli/commands/knowledge.ts +136 -0
  25. package/src/cli/constants.ts +4 -0
  26. package/src/cli/deploy-chat-ui.ts +392 -0
  27. package/src/cli/deploy-readiness.ts +348 -0
  28. package/src/cli/flags.ts +162 -0
  29. package/src/cli/help.ts +184 -0
  30. package/src/cli/index.ts +1276 -0
  31. package/src/cli/process.ts +31 -0
  32. package/src/cloud/artifact.ts +139 -0
  33. package/src/cloud/client.ts +79 -0
  34. package/src/cloud/contracts.ts +63 -0
  35. package/src/cloud/index.ts +3 -0
  36. package/src/create-project.ts +177 -0
  37. package/src/index.ts +408 -0
  38. package/src/providers/index.ts +25 -0
  39. package/src/providers/pi.ts +286 -0
  40. package/src/providers/test.ts +133 -0
  41. package/src/providers/types.ts +34 -0
  42. package/src/runtime/build.ts +43 -0
  43. package/src/runtime/channel-buffer.ts +30 -0
  44. package/src/runtime/channel-test-harness.ts +112 -0
  45. package/src/runtime/channels/telegram.ts +360 -0
  46. package/src/runtime/channels/website.ts +132 -0
  47. package/src/runtime/channels/whatsapp-meta.ts +71 -0
  48. package/src/runtime/channels/whatsapp-zapster.ts +278 -0
  49. package/src/runtime/channels.ts +138 -0
  50. package/src/runtime/chat.ts +218 -0
  51. package/src/runtime/config.ts +684 -0
  52. package/src/runtime/conversations.ts +38 -0
  53. package/src/runtime/core/deploy-state.ts +54 -0
  54. package/src/runtime/core/manifest.ts +213 -0
  55. package/src/runtime/core/targets.ts +133 -0
  56. package/src/runtime/database.ts +256 -0
  57. package/src/runtime/db-commands.ts +167 -0
  58. package/src/runtime/deploy-readiness.ts +105 -0
  59. package/src/runtime/deploy.ts +1 -0
  60. package/src/runtime/dev-server.ts +1247 -0
  61. package/src/runtime/docs.ts +36 -0
  62. package/src/runtime/env.ts +152 -0
  63. package/src/runtime/errors.ts +13 -0
  64. package/src/runtime/evals.ts +509 -0
  65. package/src/runtime/inspect.ts +203 -0
  66. package/src/runtime/knowledge/chunk.ts +333 -0
  67. package/src/runtime/knowledge/config.ts +135 -0
  68. package/src/runtime/knowledge/embeddings.ts +133 -0
  69. package/src/runtime/knowledge/ingest.ts +521 -0
  70. package/src/runtime/knowledge/prompt-policy.ts +30 -0
  71. package/src/runtime/knowledge/retrieve.ts +283 -0
  72. package/src/runtime/knowledge/schema.ts +56 -0
  73. package/src/runtime/knowledge/tool.ts +64 -0
  74. package/src/runtime/knowledge/vector.ts +258 -0
  75. package/src/runtime/runtime-contract.ts +93 -0
  76. package/src/runtime/spec.ts +152 -0
  77. package/src/runtime/sync.ts +144 -0
  78. package/src/runtime/targets/cloudflare/build.ts +2517 -0
  79. package/src/runtime/targets/container/build.ts +146 -0
  80. package/src/runtime/targets/container/server.ts +33 -0
  81. package/src/runtime/targets/vps/deploy.ts +206 -0
  82. package/src/runtime/tool-runner.ts +65 -0
  83. package/src/runtime/tools.ts +470 -0
  84. package/src/runtime/traces.ts +41 -0
  85. package/src/storage/sqlite.ts +1118 -0
  86. package/src/templates/blank.ts +394 -0
  87. package/src/templates/dentista.ts +1003 -0
  88. package/src/templates/index.ts +33 -0
  89. package/src/templates/skills/agentkit-build-agent/SKILL.md +51 -0
  90. package/src/templates/skills/agentkit-build-agent/templates/appointment-intake.instructions.md +20 -0
  91. package/src/templates/skills/agentkit-build-agent/templates/sales-qualifier.instructions.md +17 -0
  92. package/src/templates/skills/agentkit-build-agent/templates/support-agent.instructions.md +16 -0
  93. package/src/templates/skills/agentkit-capsule/SKILL.md +62 -0
  94. package/src/templates/skills/agentkit-capsule/references/docs-router.md +15 -0
  95. package/src/templates/skills/agentkit-channels/SKILL.md +62 -0
  96. package/src/templates/skills/agentkit-channels/references/channel-buffering.md +58 -0
  97. package/src/templates/skills/agentkit-channels/references/channel-debugging.md +41 -0
  98. package/src/templates/skills/agentkit-channels/references/telegram.md +38 -0
  99. package/src/templates/skills/agentkit-channels/references/whatsapp-zapster.md +44 -0
  100. package/src/templates/skills/agentkit-database/SKILL.md +45 -0
  101. package/src/templates/skills/agentkit-database/templates/appointments.schema.sql +15 -0
  102. package/src/templates/skills/agentkit-database/templates/leads.schema.sql +17 -0
  103. package/src/templates/skills/agentkit-deploy/SKILL.md +44 -0
  104. package/src/templates/skills/agentkit-evals/SKILL.md +60 -0
  105. package/src/templates/skills/agentkit-evals/templates/multi-turn.eval.md +22 -0
  106. package/src/templates/skills/agentkit-evals/templates/no-leak.eval.md +14 -0
  107. package/src/templates/skills/agentkit-evals/templates/smoke.eval.md +14 -0
  108. package/src/templates/skills/agentkit-evals/templates/tool-call.eval.md +18 -0
  109. package/src/templates/skills/agentkit-knowledge/SKILL.md +40 -0
  110. package/src/templates/skills/agentkit-knowledge/templates/faq.md +14 -0
  111. package/src/templates/skills/agentkit-knowledge/templates/policies.md +14 -0
  112. package/src/templates/skills/agentkit-knowledge/templates/prices.csv +3 -0
  113. package/src/templates/skills/agentkit-prompts/SKILL.md +45 -0
  114. package/src/templates/skills/agentkit-prompts/templates/knowledge-grounded-faq.instructions.md +11 -0
  115. package/src/templates/skills/agentkit-provider/SKILL.md +57 -0
  116. package/src/templates/skills/agentkit-security/SKILL.md +55 -0
  117. package/src/templates/skills/agentkit-tools/SKILL.md +36 -0
  118. package/src/templates/skills/agentkit-tools/examples/database-write.tool.md +35 -0
  119. package/src/templates/skills/agentkit-tools/examples/eval-safe-external-action.tool.md +37 -0
  120. package/src/templates/skills/agentkit-tools/examples/lookup-order.tool.md +46 -0
  121. package/src/templates/skills/agentkit-troubleshooting/SKILL.md +52 -0
  122. package/src/templates/support.ts +401 -0
@@ -0,0 +1,146 @@
1
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
2
+ import { join, resolve } from "node:path";
3
+
4
+ import { loadAgentCapsule } from "../../config";
5
+ import { buildSharedAgentManifest, type ManifestSchema, type SharedAgentManifest } from "../../core/manifest";
6
+
7
+ export type ContainerBuildResult = {
8
+ target: "container";
9
+ root: string;
10
+ buildDir: string;
11
+ manifestPath: string;
12
+ serverPath: string;
13
+ packageJsonPath: string;
14
+ dockerfilePath: string;
15
+ migrationsDir: string;
16
+ warnings: string[];
17
+ };
18
+
19
+ export type ContainerManifest = Omit<SharedAgentManifest, "runtime"> & {
20
+ target: "container";
21
+ runtime: "container";
22
+ container: {
23
+ runtime: "node";
24
+ entrypoint: "server.ts";
25
+ port: 4123;
26
+ };
27
+ };
28
+
29
+ const CONTAINER_BUILD_DIR = ".agentkit/build/container";
30
+
31
+ export async function buildContainerAgentCapsule(cwd = process.cwd()): Promise<ContainerBuildResult> {
32
+ const capsule = await loadAgentCapsule(cwd);
33
+ const databaseConfig = capsule.config.storage.database;
34
+ const databaseSchema = await loadApplicationSchema(
35
+ capsule.root,
36
+ databaseConfig?.driver === "turso" ? databaseConfig.schema : undefined,
37
+ );
38
+ const manifest = buildContainerManifest(buildSharedAgentManifest(capsule, { databaseSchema }));
39
+ const buildDir = join(capsule.root, CONTAINER_BUILD_DIR);
40
+ const migrationsDir = join(buildDir, "migrations");
41
+ const manifestPath = join(buildDir, "agent.manifest.json");
42
+ const serverPath = join(buildDir, "server.ts");
43
+ const packageJsonPath = join(buildDir, "package.json");
44
+ const dockerfilePath = join(buildDir, "Dockerfile");
45
+
46
+ await mkdir(migrationsDir, { recursive: true });
47
+ await writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
48
+ await writeFile(serverPath, renderContainerServer());
49
+ await writeFile(packageJsonPath, renderContainerPackageJson(capsule.config.name));
50
+ await writeFile(dockerfilePath, renderDockerfile());
51
+
52
+ if (databaseSchema) {
53
+ await writeFile(join(migrationsDir, "schema.sql"), databaseSchema.source);
54
+ }
55
+
56
+ return {
57
+ target: "container",
58
+ root: capsule.root,
59
+ buildDir,
60
+ manifestPath,
61
+ serverPath,
62
+ packageJsonPath,
63
+ dockerfilePath,
64
+ migrationsDir,
65
+ warnings: [],
66
+ };
67
+ }
68
+
69
+ function buildContainerManifest(shared: SharedAgentManifest): ContainerManifest {
70
+ return {
71
+ ...shared,
72
+ target: "container",
73
+ runtime: "container",
74
+ container: {
75
+ runtime: "node",
76
+ entrypoint: "server.ts",
77
+ port: 4123,
78
+ },
79
+ };
80
+ }
81
+
82
+ async function loadApplicationSchema(root: string, schemaPath: string | undefined): Promise<ManifestSchema | null> {
83
+ if (!schemaPath) {
84
+ return null;
85
+ }
86
+
87
+ const source = await readFile(resolve(root, schemaPath), "utf8");
88
+ const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(source));
89
+ return {
90
+ source,
91
+ sha256: Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join(""),
92
+ };
93
+ }
94
+
95
+ function renderContainerServer(): string {
96
+ return `import { startContainerRuntime } from "@andreprado/agentkit/runtime/container";
97
+
98
+ await startContainerRuntime();
99
+ `;
100
+ }
101
+
102
+ function renderContainerPackageJson(agentName: string): string {
103
+ return `${JSON.stringify(
104
+ {
105
+ name: `agentkit-${slugify(agentName)}-container`,
106
+ private: true,
107
+ type: "module",
108
+ scripts: {
109
+ start: "tsx server.ts",
110
+ },
111
+ dependencies: {
112
+ "@andreprado/agentkit": "latest",
113
+ "tsx": "^4.22.3",
114
+ },
115
+ },
116
+ null,
117
+ 2,
118
+ )}\n`;
119
+ }
120
+
121
+ function renderDockerfile(): string {
122
+ return `FROM node:24-slim
123
+
124
+ WORKDIR /app
125
+ COPY package.json server.ts agent.manifest.json ./
126
+ COPY migrations ./migrations
127
+ RUN npm install --omit=dev
128
+
129
+ ENV HOST=0.0.0.0
130
+ ENV PORT=4123
131
+ ENV AGENTKIT_CAPSULE_ROOT=/capsule
132
+
133
+ EXPOSE 4123
134
+ CMD ["npm", "start"]
135
+ `;
136
+ }
137
+
138
+ function slugify(value: string): string {
139
+ const slug = value
140
+ .toLowerCase()
141
+ .replace(/[^a-z0-9-]+/g, "-")
142
+ .replace(/^-+|-+$/g, "")
143
+ .slice(0, 48);
144
+
145
+ return slug || "agent";
146
+ }
@@ -0,0 +1,33 @@
1
+ import { resolve } from "node:path";
2
+
3
+ import { startAgentDevServer, type AgentDevServer } from "../../dev-server";
4
+
5
+ export type ContainerRuntimeOptions = {
6
+ capsuleRoot?: string;
7
+ hostname?: string;
8
+ port?: number;
9
+ };
10
+
11
+ export async function startContainerRuntime(options: ContainerRuntimeOptions = {}): Promise<AgentDevServer> {
12
+ const capsuleRoot = resolve(options.capsuleRoot ?? process.env.AGENTKIT_CAPSULE_ROOT ?? process.cwd());
13
+ const hostname = options.hostname ?? process.env.HOST ?? "0.0.0.0";
14
+ const port = options.port ?? parsePort(process.env.PORT) ?? 4123;
15
+ return startAgentDevServer(capsuleRoot, { hostname, port });
16
+ }
17
+
18
+ function parsePort(value: string | undefined): number | undefined {
19
+ if (!value) {
20
+ return undefined;
21
+ }
22
+
23
+ const port = Number(value);
24
+ return Number.isInteger(port) && port > 0 && port <= 65535 ? port : undefined;
25
+ }
26
+
27
+ if (import.meta.main) {
28
+ const runtime = await startContainerRuntime();
29
+
30
+ console.log("AgentKit container runtime running");
31
+ console.log(`API: http://${runtime.hostname}:${runtime.port}`);
32
+ console.log(`Inspect: http://${runtime.hostname}:${runtime.port}/_agentkit`);
33
+ }
@@ -0,0 +1,206 @@
1
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+
4
+ import type { LocalDeployState } from "../../core/deploy-state";
5
+ import type { ContainerBuildResult } from "../container/build";
6
+
7
+ export type VpsDeployOptions = {
8
+ host: string;
9
+ dryRun?: boolean;
10
+ };
11
+
12
+ export type VpsDeployPlan = {
13
+ target: "vps";
14
+ runtime: "container";
15
+ host: string;
16
+ buildDir: string;
17
+ composePath: string;
18
+ envExamplePath: string;
19
+ secretsPath: string;
20
+ handoffPath: string;
21
+ statePath: string;
22
+ commands: string[];
23
+ };
24
+
25
+ const VPS_BUILD_DIR = ".agentkit/build/vps";
26
+
27
+ export async function prepareVpsDeploy(
28
+ container: ContainerBuildResult,
29
+ options: VpsDeployOptions,
30
+ ): Promise<VpsDeployPlan> {
31
+ const buildDir = join(container.root, VPS_BUILD_DIR);
32
+ const composePath = join(buildDir, "compose.yaml");
33
+ const envExamplePath = join(buildDir, ".env.production.example");
34
+ const envPath = join(buildDir, ".env.production");
35
+ const secretsPath = join(buildDir, "SECRETS.md");
36
+ const handoffPath = join(buildDir, "PRODUCTION_HANDOFF.md");
37
+ const statePath = join(container.root, ".agentkit/deploy.json");
38
+ const manifest = JSON.parse(await readFile(container.manifestPath, "utf8")) as {
39
+ name: string;
40
+ secrets: string[];
41
+ };
42
+
43
+ await mkdir(buildDir, { recursive: true });
44
+ const envExample = renderEnvExample(manifest.secrets);
45
+ await writeFile(composePath, renderCompose(manifest.name));
46
+ await writeFile(envExamplePath, envExample);
47
+ await writeFile(envPath, envExample);
48
+ await writeFile(secretsPath, renderSecretsChecklist(manifest.secrets));
49
+ await writeFile(handoffPath, renderProductionHandoff(options.host, manifest.name));
50
+
51
+ const state: LocalDeployState = {
52
+ deploy_id: `vps_${slugify(manifest.name)}`,
53
+ project_id: `local_${slugify(manifest.name)}`,
54
+ url: `https://${options.host}`,
55
+ target: "vps",
56
+ runtime: "container",
57
+ resources: {
58
+ vps: {
59
+ host: options.host,
60
+ compose: composePath,
61
+ env_example: envExamplePath,
62
+ sqlite_path: "/data/agentkit.db",
63
+ files_path: "/capsule/.agentkit/files",
64
+ },
65
+ container: {
66
+ build_dir: container.buildDir,
67
+ },
68
+ },
69
+ access: {
70
+ mode: "operator-managed",
71
+ },
72
+ created_at: new Date().toISOString(),
73
+ };
74
+ await writeFile(statePath, `${JSON.stringify(state, null, 2)}\n`);
75
+
76
+ return {
77
+ target: "vps",
78
+ runtime: "container",
79
+ host: options.host,
80
+ buildDir,
81
+ composePath,
82
+ envExamplePath,
83
+ secretsPath,
84
+ handoffPath,
85
+ statePath,
86
+ commands: [
87
+ `cp ${envExamplePath} ${envPath}`,
88
+ `docker compose -f ${composePath} --env-file ${envPath} config`,
89
+ `docker compose -f ${composePath} --env-file ${envPath} up -d --build`,
90
+ `curl -fsS https://${options.host}/health`,
91
+ `curl -fsS https://${options.host}/_agentkit`,
92
+ ],
93
+ };
94
+ }
95
+
96
+ function renderCompose(agentName: string): string {
97
+ return `services:
98
+ agent:
99
+ build:
100
+ context: ../container
101
+ image: agentkit-${slugify(agentName)}:latest
102
+ restart: unless-stopped
103
+ env_file:
104
+ - .env.production
105
+ environment:
106
+ HOST: 0.0.0.0
107
+ PORT: 4123
108
+ AGENTKIT_SQLITE_PATH: /data/agentkit.db
109
+ ports:
110
+ - "\${AGENTKIT_PORT:-4123}:4123"
111
+ volumes:
112
+ - ../../..:/capsule
113
+ - agentkit_data:/data
114
+ - agentkit_files:/capsule/.agentkit/files
115
+ healthcheck:
116
+ test: ["CMD", "bun", "-e", "const r=await fetch('http://127.0.0.1:4123/health'); process.exit(r.ok?0:1)"]
117
+ interval: 30s
118
+ timeout: 5s
119
+ retries: 3
120
+ start_period: 10s
121
+
122
+ volumes:
123
+ agentkit_data:
124
+ agentkit_files:
125
+ `;
126
+ }
127
+
128
+ function renderEnvExample(secrets: string[]): string {
129
+ const secretLines = secrets.map((name) => `${name}=`).join("\n");
130
+ return `# Copy to .env.production on the VPS and fill values there.
131
+ AGENTKIT_PORT=4123
132
+ AGENTKIT_CAPSULE_ROOT=/capsule
133
+ AGENTKIT_SQLITE_PATH=/data/agentkit.db
134
+ ${secretLines ? `\n${secretLines}\n` : ""}
135
+ `;
136
+ }
137
+
138
+ function renderSecretsChecklist(secrets: string[]): string {
139
+ const lines = secrets.length > 0 ? secrets.map((name) => `- [ ] ${name}`).join("\n") : "- No production secrets required for the current manifest.";
140
+ return `# VPS Secret Checklist
141
+
142
+ Fill these names in .env.production on the host. Do not commit secret values.
143
+
144
+ ${lines}
145
+ `;
146
+ }
147
+
148
+ function renderProductionHandoff(host: string, agentName: string): string {
149
+ return `# VPS Production Handoff
150
+
151
+ ## Deploy
152
+
153
+ 1. Copy .agentkit/build/vps to the VPS or run these commands from the capsule root on the VPS.
154
+ 2. Copy .agentkit/build/vps/.env.production.example to .agentkit/build/vps/.env.production and fill secret values on the host.
155
+ 3. Run:
156
+
157
+ \`\`\`sh
158
+ docker compose -f .agentkit/build/vps/compose.yaml --env-file .agentkit/build/vps/.env.production config
159
+ docker compose -f .agentkit/build/vps/compose.yaml --env-file .agentkit/build/vps/.env.production up -d --build
160
+ \`\`\`
161
+
162
+ ## Ports And Reverse Proxy
163
+
164
+ - Container port: 4123.
165
+ - Host port: AGENTKIT_PORT, default 4123.
166
+ - Put nginx, Caddy, Traefik, or your VPS proxy in front of http://127.0.0.1:4123 for https://${host}.
167
+
168
+ ## Smoke
169
+
170
+ \`\`\`sh
171
+ curl -fsS https://${host}/health
172
+ curl -fsS https://${host}/_agentkit
173
+ curl -fsS -X POST https://${host}/chat \\
174
+ -H 'content-type: application/json' \\
175
+ -d '{"message":{"role":"user","content":"hello"}}'
176
+ \`\`\`
177
+
178
+ ## Database
179
+
180
+ - Default database: SQLite at /data/agentkit.db in the agentkit_data volume.
181
+ - Backup: snapshot the agentkit_data Docker volume or copy /data/agentkit.db after stopping the container.
182
+ - Postgres upgrade path: set a managed DATABASE_URL in .env.production after the container runtime grows the Postgres store.
183
+
184
+ ## Files
185
+
186
+ - Local files persist in the agentkit_files volume mounted at /capsule/.agentkit/files.
187
+
188
+ ## Rollback
189
+
190
+ \`\`\`sh
191
+ docker compose -f .agentkit/build/vps/compose.yaml --env-file .agentkit/build/vps/.env.production down
192
+ docker image ls 'agentkit-${slugify(agentName)}'
193
+ docker compose -f .agentkit/build/vps/compose.yaml --env-file .agentkit/build/vps/.env.production up -d --no-build
194
+ \`\`\`
195
+ `;
196
+ }
197
+
198
+ function slugify(value: string): string {
199
+ const slug = value
200
+ .toLowerCase()
201
+ .replace(/[^a-z0-9-]+/g, "-")
202
+ .replace(/^-+|-+$/g, "")
203
+ .slice(0, 48);
204
+
205
+ return slug || "agent";
206
+ }
@@ -0,0 +1,65 @@
1
+ import { loadAgentCapsule } from "./config";
2
+ import { openPreparedCapsuleStore } from "./database";
3
+ import { loadCapsuleEnv } from "./env";
4
+ import { isAgentKitError } from "./errors";
5
+ import { createToolRuntime, type ToolCallResult } from "./tools";
6
+
7
+ export type RunToolOptions = {
8
+ name: string;
9
+ input?: unknown;
10
+ signal?: AbortSignal;
11
+ };
12
+
13
+ export async function runToolFromCwd(cwd: string, options: RunToolOptions): Promise<ToolCallResult> {
14
+ const capsule = await loadAgentCapsule(cwd);
15
+ const env = await loadCapsuleEnv(capsule.root);
16
+ const { store } = await openPreparedCapsuleStore(capsule);
17
+ const conversation = store.createConversation({
18
+ agentName: capsule.config.name,
19
+ title: `tool ${options.name}`,
20
+ });
21
+ const run = store.createRun({
22
+ conversationId: conversation.id,
23
+ provider: capsule.config.provider.name,
24
+ model: capsule.config.provider.model,
25
+ });
26
+ const toolRuntime = createToolRuntime({
27
+ tools: capsule.config.tools ?? [],
28
+ store,
29
+ runId: run.id,
30
+ conversationId: conversation.id,
31
+ env,
32
+ signal: options.signal,
33
+ runtime: {
34
+ environment: "local",
35
+ invocation: "tool",
36
+ target: "bun",
37
+ database: "sqlite",
38
+ },
39
+ });
40
+
41
+ try {
42
+ const result = await toolRuntime.execute({
43
+ name: options.name,
44
+ input: options.input ?? {},
45
+ });
46
+
47
+ store.completeRun({
48
+ runId: run.id,
49
+ status: "completed",
50
+ });
51
+
52
+ return result;
53
+ } catch (error) {
54
+ store.completeRun({
55
+ runId: run.id,
56
+ status: "failed",
57
+ errorCode: isAgentKitError(error) ? error.code : "runtime_error",
58
+ errorMessage: error instanceof Error ? error.message : String(error),
59
+ });
60
+
61
+ throw error;
62
+ } finally {
63
+ store.close();
64
+ }
65
+ }