@andreprado/agentkit 0.1.0-alpha.2 → 0.1.0-alpha.20

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 (135) hide show
  1. package/README.md +67 -6
  2. package/docs/guides/add-channel.md +118 -7
  3. package/docs/guides/add-knowledge.md +144 -0
  4. package/docs/guides/add-managed-composio.md +163 -0
  5. package/docs/guides/add-tool.md +1 -1
  6. package/docs/guides/channel-security.md +97 -32
  7. package/docs/guides/connect-discord.md +178 -0
  8. package/docs/guides/connect-slack.md +126 -0
  9. package/docs/guides/connect-telegram.md +78 -1
  10. package/docs/guides/connect-whatsapp-zapster.md +112 -8
  11. package/docs/guides/create-agent.md +45 -4
  12. package/docs/guides/debug-channel.md +147 -0
  13. package/docs/guides/improve-from-production.md +151 -0
  14. package/docs/guides/prepare-deploy.md +47 -17
  15. package/docs/guides/replay-production-traces.md +72 -0
  16. package/docs/guides/run-evals.md +147 -20
  17. package/docs/guides/security-rules.md +7 -6
  18. package/docs/guides/send-feedback.md +135 -0
  19. package/docs/guides/use-provider.md +27 -3
  20. package/docs/llms-full.txt +303 -55
  21. package/docs/llms.txt +57 -7
  22. package/package.json +2 -5
  23. package/src/cli/args.ts +57 -0
  24. package/src/cli/cloud-client.ts +377 -0
  25. package/src/cli/commands/channels.ts +1315 -0
  26. package/src/cli/commands/feedback.ts +438 -0
  27. package/src/cli/commands/knowledge.ts +136 -0
  28. package/src/cli/commands/transcribe.ts +171 -0
  29. package/src/cli/constants.ts +4 -0
  30. package/src/cli/deploy-chat-ui.ts +535 -0
  31. package/src/cli/deploy-readiness.ts +481 -0
  32. package/src/cli/flags.ts +162 -0
  33. package/src/cli/help.ts +236 -0
  34. package/src/cli/index.ts +1167 -1005
  35. package/src/cli/process.ts +31 -0
  36. package/src/cloud/artifact.ts +139 -0
  37. package/src/cloud/client.ts +80 -0
  38. package/src/cloud/contracts.ts +63 -0
  39. package/src/cloud/index.ts +3 -0
  40. package/src/create-project.ts +21 -6
  41. package/src/index.ts +479 -7
  42. package/src/providers/pi.ts +70 -16
  43. package/src/providers/test.ts +88 -1
  44. package/src/providers/types.ts +7 -0
  45. package/src/runtime/channel-buffer.ts +30 -0
  46. package/src/runtime/channel-test-harness.ts +8 -1
  47. package/src/runtime/channels/discord.ts +896 -0
  48. package/src/runtime/channels/slack.ts +646 -0
  49. package/src/runtime/channels/telegram.ts +466 -23
  50. package/src/runtime/channels/whatsapp-meta.ts +9 -0
  51. package/src/runtime/channels/whatsapp-zapster.ts +677 -40
  52. package/src/runtime/channels.ts +86 -3
  53. package/src/runtime/chat.ts +130 -38
  54. package/src/runtime/config.ts +483 -18
  55. package/src/runtime/core/manifest.ts +103 -5
  56. package/src/runtime/core/targets.ts +5 -5
  57. package/src/runtime/database.ts +93 -2
  58. package/src/runtime/db-commands.ts +9 -0
  59. package/src/runtime/deploy-readiness.ts +46 -4
  60. package/src/runtime/deploy.ts +1 -1
  61. package/src/runtime/dev-server.ts +759 -41
  62. package/src/runtime/env.ts +8 -3
  63. package/src/runtime/evals.ts +589 -43
  64. package/src/runtime/improve.ts +868 -0
  65. package/src/runtime/inspect.ts +194 -4
  66. package/src/runtime/integrations/composio.ts +423 -0
  67. package/src/runtime/knowledge/chunk.ts +333 -0
  68. package/src/runtime/knowledge/config.ts +135 -0
  69. package/src/runtime/knowledge/embeddings.ts +133 -0
  70. package/src/runtime/knowledge/ingest.ts +521 -0
  71. package/src/runtime/knowledge/prompt-policy.ts +30 -0
  72. package/src/runtime/knowledge/retrieve.ts +303 -0
  73. package/src/runtime/knowledge/schema.ts +100 -0
  74. package/src/runtime/knowledge/tool.ts +64 -0
  75. package/src/runtime/knowledge/vector.ts +258 -0
  76. package/src/runtime/prompt-context.ts +141 -0
  77. package/src/runtime/runtime-contract.ts +86 -8
  78. package/src/runtime/skills.ts +95 -0
  79. package/src/runtime/spec.ts +152 -0
  80. package/src/runtime/sync.ts +144 -0
  81. package/src/runtime/targets/cloudflare/build.ts +1430 -185
  82. package/src/runtime/targets/container/server.ts +1 -1
  83. package/src/runtime/targets/vps/deploy.ts +26 -9
  84. package/src/runtime/tool-runner.ts +9 -1
  85. package/src/runtime/tools.ts +128 -2
  86. package/src/runtime/traces.ts +41 -0
  87. package/src/runtime/transcription.ts +483 -0
  88. package/src/storage/sqlite.ts +149 -3
  89. package/src/templates/blank.ts +76 -17
  90. package/src/templates/dentista.ts +1011 -0
  91. package/src/templates/index.ts +2 -0
  92. package/src/templates/skills/agentkit-build-agent/SKILL.md +52 -0
  93. package/src/templates/skills/agentkit-build-agent/templates/appointment-intake.instructions.md +21 -0
  94. package/src/templates/skills/agentkit-build-agent/templates/sales-qualifier.instructions.md +17 -0
  95. package/src/templates/skills/agentkit-build-agent/templates/support-agent.instructions.md +16 -0
  96. package/src/templates/skills/agentkit-capsule/SKILL.md +70 -0
  97. package/src/templates/skills/agentkit-capsule/references/docs-router.md +15 -0
  98. package/src/templates/skills/agentkit-channels/SKILL.md +104 -0
  99. package/src/templates/skills/agentkit-channels/references/channel-buffering.md +65 -0
  100. package/src/templates/skills/agentkit-channels/references/channel-debugging.md +66 -0
  101. package/src/templates/skills/agentkit-channels/references/discord.md +93 -0
  102. package/src/templates/skills/agentkit-channels/references/slack.md +56 -0
  103. package/src/templates/skills/agentkit-channels/references/telegram.md +72 -0
  104. package/src/templates/skills/agentkit-channels/references/whatsapp-zapster.md +77 -0
  105. package/src/templates/skills/agentkit-database/SKILL.md +45 -0
  106. package/src/templates/skills/agentkit-database/templates/appointments.schema.sql +15 -0
  107. package/src/templates/skills/agentkit-database/templates/leads.schema.sql +17 -0
  108. package/src/templates/skills/agentkit-deploy/SKILL.md +50 -0
  109. package/src/templates/skills/agentkit-evals/SKILL.md +109 -0
  110. package/src/templates/skills/agentkit-evals/templates/multi-turn.eval.md +29 -0
  111. package/src/templates/skills/agentkit-evals/templates/no-leak.eval.md +18 -0
  112. package/src/templates/skills/agentkit-evals/templates/smoke.eval.md +18 -0
  113. package/src/templates/skills/agentkit-evals/templates/tool-call.eval.md +27 -0
  114. package/src/templates/skills/agentkit-improve/SKILL.md +86 -0
  115. package/src/templates/skills/agentkit-improve/references/replay-side-effects.md +18 -0
  116. package/src/templates/skills/agentkit-improve/references/trace-packets.md +22 -0
  117. package/src/templates/skills/agentkit-improve/templates/regression.eval.md +18 -0
  118. package/src/templates/skills/agentkit-integrations/SKILL.md +76 -0
  119. package/src/templates/skills/agentkit-knowledge/SKILL.md +43 -0
  120. package/src/templates/skills/agentkit-knowledge/templates/faq.md +14 -0
  121. package/src/templates/skills/agentkit-knowledge/templates/policies.md +14 -0
  122. package/src/templates/skills/agentkit-knowledge/templates/prices.csv +3 -0
  123. package/src/templates/skills/agentkit-prompts/SKILL.md +47 -0
  124. package/src/templates/skills/agentkit-prompts/templates/knowledge-grounded-faq.instructions.md +11 -0
  125. package/src/templates/skills/agentkit-provider/SKILL.md +60 -0
  126. package/src/templates/skills/agentkit-security/SKILL.md +56 -0
  127. package/src/templates/skills/agentkit-tools/SKILL.md +37 -0
  128. package/src/templates/skills/agentkit-tools/examples/database-write.tool.md +35 -0
  129. package/src/templates/skills/agentkit-tools/examples/eval-safe-external-action.tool.md +37 -0
  130. package/src/templates/skills/agentkit-tools/examples/lookup-order.tool.md +46 -0
  131. package/src/templates/skills/agentkit-troubleshooting/SKILL.md +76 -0
  132. package/src/templates/support.ts +77 -18
  133. package/docs/guides/channels-production-handoff.md +0 -99
  134. package/docs/portable-deploy-release-checklist.md +0 -41
  135. package/src/runtime/targets/cloudflare/deploy.ts +0 -5475
@@ -0,0 +1,152 @@
1
+ import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
2
+ import { dirname, relative, resolve } from "node:path";
3
+
4
+ import { findAgentCapsuleRoot } from "./config";
5
+ import { AgentKitError } from "./errors";
6
+
7
+ export type AgentSpecInitResult = {
8
+ root: string;
9
+ file: string;
10
+ created: boolean;
11
+ };
12
+
13
+ const REQUIRED_SPEC_HEADINGS = [
14
+ "Objective",
15
+ "Primary Flows",
16
+ "Required Data",
17
+ "Tools And Integrations",
18
+ "Knowledge",
19
+ "Handoff And Escalation",
20
+ "Limits",
21
+ "Acceptance Criteria",
22
+ ] as const;
23
+
24
+ export async function initializeAgentSpec(
25
+ cwd: string,
26
+ input: {
27
+ brief: string;
28
+ out?: string;
29
+ force?: boolean;
30
+ },
31
+ ): Promise<AgentSpecInitResult> {
32
+ const root = await findAgentCapsuleRoot(cwd);
33
+ const brief = input.brief.trim();
34
+
35
+ if (!brief) {
36
+ throw new AgentKitError("validation_error", "agentkit spec init requires a non-empty --brief value.");
37
+ }
38
+
39
+ const file = resolve(root, input.out ?? "AGENT_SPEC.md");
40
+
41
+ if (!input.force && await pathExists(file)) {
42
+ throw new AgentKitError(
43
+ "validation_error",
44
+ `${relative(root, file)} already exists. Update it directly, re-run with --force, or choose --out <path>.`,
45
+ );
46
+ }
47
+
48
+ await mkdir(dirname(file), { recursive: true });
49
+ await writeFile(file, renderAgentSpec(brief));
50
+
51
+ return {
52
+ root,
53
+ file,
54
+ created: true,
55
+ };
56
+ }
57
+
58
+ export async function checkAgentSpec(cwd: string, fileName = "AGENT_SPEC.md"): Promise<{
59
+ root: string;
60
+ file: string;
61
+ ok: boolean;
62
+ missingHeadings: string[];
63
+ }> {
64
+ const root = await findAgentCapsuleRoot(cwd);
65
+ const file = resolve(root, fileName);
66
+ let source: string;
67
+
68
+ try {
69
+ source = await readFile(file, "utf8");
70
+ } catch (error) {
71
+ throw new AgentKitError(
72
+ "validation_error",
73
+ `${relative(root, file)} was not found. Run agentkit spec init --brief "<owner request>" after the owner gives the agent idea.`,
74
+ { cause: error },
75
+ );
76
+ }
77
+
78
+ const missingHeadings = REQUIRED_SPEC_HEADINGS.filter((heading) => !source.includes(`## ${heading}`));
79
+
80
+ return {
81
+ root,
82
+ file,
83
+ ok: missingHeadings.length === 0,
84
+ missingHeadings,
85
+ };
86
+ }
87
+
88
+ function renderAgentSpec(brief: string): string {
89
+ return `# Agent Spec
90
+
91
+ ## Owner Request
92
+
93
+ ${brief}
94
+
95
+ ## Objective
96
+
97
+ Define the agent's job in one or two concrete sentences before editing prompts or tools.
98
+
99
+ ## Primary Flows
100
+
101
+ - Flow 1:
102
+ - Flow 2:
103
+ - Flow 3:
104
+
105
+ ## Required Data
106
+
107
+ - User data to collect:
108
+ - Business data to read:
109
+ - Records to create or update:
110
+
111
+ ## Tools And Integrations
112
+
113
+ - Tools to add:
114
+ - External systems:
115
+ - Secrets needed:
116
+
117
+ ## Knowledge
118
+
119
+ - Documents, FAQs, catalogs, CSVs, or policies to add:
120
+ - Sync source, if any:
121
+
122
+ ## Handoff And Escalation
123
+
124
+ - When the agent should stop and hand off:
125
+ - What information the handoff must include:
126
+
127
+ ## Limits
128
+
129
+ - The agent must not:
130
+ - Safety, compliance, or authorization boundaries:
131
+
132
+ ## Acceptance Criteria
133
+
134
+ - [ ] Prompt updated for the domain and boundaries.
135
+ - [ ] Tools added for actions, live data, or durable writes.
136
+ - [ ] Knowledge or seed data added when the agent needs catalog facts.
137
+ - [ ] Multi-turn eval covers the main user flow.
138
+ - [ ] Direct tool checks pass for every new tool.
139
+ - [ ] \`npm run typecheck\` passes.
140
+ - [ ] \`npm run agentkit -- inspect\` passes.
141
+ - [ ] \`npm run eval\` passes.
142
+ `;
143
+ }
144
+
145
+ async function pathExists(path: string): Promise<boolean> {
146
+ try {
147
+ await stat(path);
148
+ return true;
149
+ } catch {
150
+ return false;
151
+ }
152
+ }
@@ -0,0 +1,144 @@
1
+ import { mkdir, stat, writeFile } from "node:fs/promises";
2
+ import { dirname, relative, resolve } from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+
5
+ import type { SyncContext } from "../index";
6
+ import { findAgentCapsuleRoot, loadAgentCapsule } from "./config";
7
+ import { createLocalDatabaseRunner, openPreparedCapsuleStore } from "./database";
8
+ import { loadCapsuleEnv } from "./env";
9
+ import { AgentKitError } from "./errors";
10
+
11
+ export type SyncRunResult = {
12
+ root: string;
13
+ file: string;
14
+ output: unknown;
15
+ };
16
+
17
+ export type SyncInitResult = {
18
+ root: string;
19
+ files: string[];
20
+ };
21
+
22
+ type SyncModule = {
23
+ default?: unknown;
24
+ sync?: unknown;
25
+ };
26
+
27
+ export async function runCapsuleSync(cwd: string, input: { file?: string } = {}): Promise<SyncRunResult> {
28
+ const capsule = await loadAgentCapsule(cwd);
29
+ const file = resolve(capsule.root, input.file ?? "sync.ts");
30
+ const sync = await loadSyncFunction(file);
31
+ const env = await loadCapsuleEnv(capsule.root);
32
+ const prepared = await openPreparedCapsuleStore(capsule);
33
+
34
+ try {
35
+ const db = createLocalDatabaseRunner(prepared.store);
36
+ const context: SyncContext = {
37
+ env,
38
+ database: db,
39
+ db,
40
+ runtime: {
41
+ environment: "local",
42
+ invocation: "sync",
43
+ target: "bun",
44
+ database: "sqlite",
45
+ },
46
+ };
47
+ const output = await sync(context);
48
+
49
+ return {
50
+ root: capsule.root,
51
+ file,
52
+ output: output ?? { ok: true },
53
+ };
54
+ } finally {
55
+ prepared.store.close();
56
+ }
57
+ }
58
+
59
+ export async function initializeSyncScaffold(cwd: string, input: { force?: boolean } = {}): Promise<SyncInitResult> {
60
+ const root = await findAgentCapsuleRoot(cwd);
61
+ const files = [
62
+ {
63
+ path: "sync.ts",
64
+ contents: `import type { SyncContext } from "@andreprado/agentkit";
65
+
66
+ export default async function sync(ctx: SyncContext) {
67
+ // Replace this with catalog/API import logic. Use ctx.db for durable writes.
68
+ await ctx.db.execute(
69
+ "INSERT OR IGNORE INTO agent_notes (id, content) VALUES (?, ?)",
70
+ ["seed-note", "Created by sync.ts"],
71
+ );
72
+
73
+ return {
74
+ ok: true,
75
+ recordsImported: 1,
76
+ };
77
+ }
78
+ `,
79
+ },
80
+ {
81
+ path: "seed.sql",
82
+ contents: `INSERT OR IGNORE INTO agent_notes (id, content)
83
+ VALUES ('seed-note', 'Created by seed.sql');
84
+ `,
85
+ },
86
+ {
87
+ path: "migrations/0001_initial.sql",
88
+ contents: `CREATE TABLE IF NOT EXISTS agent_notes (
89
+ id TEXT PRIMARY KEY,
90
+ content TEXT NOT NULL,
91
+ created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
92
+ );
93
+ `,
94
+ },
95
+ ];
96
+ const written: string[] = [];
97
+
98
+ for (const file of files) {
99
+ const absolutePath = resolve(root, file.path);
100
+
101
+ if (!input.force && await pathExists(absolutePath)) {
102
+ continue;
103
+ }
104
+
105
+ await mkdir(dirname(absolutePath), { recursive: true });
106
+ await writeFile(absolutePath, file.contents);
107
+ written.push(file.path);
108
+ }
109
+
110
+ return { root, files: written };
111
+ }
112
+
113
+ async function loadSyncFunction(file: string): Promise<(context: SyncContext) => Promise<unknown> | unknown> {
114
+ let module: SyncModule;
115
+
116
+ try {
117
+ const url = pathToFileURL(file);
118
+ url.searchParams.set("t", String(Date.now()));
119
+ module = (await import(url.href)) as SyncModule;
120
+ } catch (error) {
121
+ throw new AgentKitError(
122
+ "validation_error",
123
+ `Could not load sync file at ${relative(process.cwd(), file)}. Run agentkit sync init or pass --file <path>.`,
124
+ { cause: error },
125
+ );
126
+ }
127
+
128
+ const sync = module.default ?? module.sync;
129
+
130
+ if (typeof sync !== "function") {
131
+ throw new AgentKitError("validation_error", `${relative(process.cwd(), file)} must export a default sync function.`);
132
+ }
133
+
134
+ return sync as (context: SyncContext) => Promise<unknown> | unknown;
135
+ }
136
+
137
+ async function pathExists(path: string): Promise<boolean> {
138
+ try {
139
+ await stat(path);
140
+ return true;
141
+ } catch {
142
+ return false;
143
+ }
144
+ }