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

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 (142) hide show
  1. package/README.md +68 -6
  2. package/docs/guides/add-channel.md +189 -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 +128 -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-evolution.md +121 -0
  11. package/docs/guides/connect-whatsapp-uazapi.md +126 -0
  12. package/docs/guides/connect-whatsapp-zapster.md +112 -8
  13. package/docs/guides/create-agent.md +45 -4
  14. package/docs/guides/debug-channel.md +147 -0
  15. package/docs/guides/improve-from-production.md +151 -0
  16. package/docs/guides/prepare-deploy.md +47 -17
  17. package/docs/guides/replay-production-traces.md +72 -0
  18. package/docs/guides/run-evals.md +147 -20
  19. package/docs/guides/security-rules.md +7 -6
  20. package/docs/guides/send-feedback.md +135 -0
  21. package/docs/guides/use-provider.md +27 -3
  22. package/docs/llms-full.txt +348 -55
  23. package/docs/llms.txt +62 -7
  24. package/package.json +2 -5
  25. package/src/cli/args.ts +57 -0
  26. package/src/cli/cloud-client.ts +377 -0
  27. package/src/cli/commands/channels.ts +1586 -0
  28. package/src/cli/commands/feedback.ts +438 -0
  29. package/src/cli/commands/knowledge.ts +136 -0
  30. package/src/cli/commands/transcribe.ts +171 -0
  31. package/src/cli/constants.ts +4 -0
  32. package/src/cli/deploy-chat-ui.ts +535 -0
  33. package/src/cli/deploy-readiness.ts +481 -0
  34. package/src/cli/flags.ts +162 -0
  35. package/src/cli/help.ts +236 -0
  36. package/src/cli/index.ts +1167 -1005
  37. package/src/cli/process.ts +31 -0
  38. package/src/cloud/artifact.ts +139 -0
  39. package/src/cloud/client.ts +80 -0
  40. package/src/cloud/contracts.ts +63 -0
  41. package/src/cloud/index.ts +3 -0
  42. package/src/create-project.ts +21 -6
  43. package/src/index.ts +517 -8
  44. package/src/providers/pi.ts +70 -16
  45. package/src/providers/test.ts +88 -1
  46. package/src/providers/types.ts +7 -0
  47. package/src/runtime/channel-buffer.ts +30 -0
  48. package/src/runtime/channel-test-harness.ts +21 -1
  49. package/src/runtime/channels/discord.ts +896 -0
  50. package/src/runtime/channels/generic-webhook.ts +225 -0
  51. package/src/runtime/channels/slack.ts +646 -0
  52. package/src/runtime/channels/telegram.ts +466 -23
  53. package/src/runtime/channels/whatsapp-evolution.ts +1357 -0
  54. package/src/runtime/channels/whatsapp-meta.ts +9 -0
  55. package/src/runtime/channels/whatsapp-uazapi.ts +1327 -0
  56. package/src/runtime/channels/whatsapp-zapster.ts +677 -40
  57. package/src/runtime/channels.ts +87 -4
  58. package/src/runtime/chat.ts +130 -38
  59. package/src/runtime/config.ts +519 -19
  60. package/src/runtime/core/manifest.ts +103 -5
  61. package/src/runtime/core/targets.ts +5 -5
  62. package/src/runtime/database.ts +93 -2
  63. package/src/runtime/db-commands.ts +9 -0
  64. package/src/runtime/deploy-readiness.ts +46 -4
  65. package/src/runtime/deploy.ts +1 -1
  66. package/src/runtime/dev-server.ts +779 -45
  67. package/src/runtime/env.ts +8 -3
  68. package/src/runtime/evals.ts +589 -43
  69. package/src/runtime/improve.ts +868 -0
  70. package/src/runtime/inspect.ts +194 -4
  71. package/src/runtime/integrations/composio.ts +423 -0
  72. package/src/runtime/knowledge/chunk.ts +333 -0
  73. package/src/runtime/knowledge/config.ts +135 -0
  74. package/src/runtime/knowledge/embeddings.ts +133 -0
  75. package/src/runtime/knowledge/ingest.ts +521 -0
  76. package/src/runtime/knowledge/prompt-policy.ts +30 -0
  77. package/src/runtime/knowledge/retrieve.ts +303 -0
  78. package/src/runtime/knowledge/schema.ts +100 -0
  79. package/src/runtime/knowledge/tool.ts +64 -0
  80. package/src/runtime/knowledge/vector.ts +258 -0
  81. package/src/runtime/prompt-context.ts +141 -0
  82. package/src/runtime/runtime-contract.ts +86 -8
  83. package/src/runtime/skills.ts +95 -0
  84. package/src/runtime/spec.ts +152 -0
  85. package/src/runtime/sync.ts +144 -0
  86. package/src/runtime/targets/cloudflare/build.ts +1468 -203
  87. package/src/runtime/targets/container/server.ts +1 -1
  88. package/src/runtime/targets/vps/deploy.ts +26 -9
  89. package/src/runtime/tool-runner.ts +9 -1
  90. package/src/runtime/tools.ts +128 -2
  91. package/src/runtime/traces.ts +41 -0
  92. package/src/runtime/transcription.ts +483 -0
  93. package/src/storage/sqlite.ts +149 -3
  94. package/src/templates/blank.ts +76 -17
  95. package/src/templates/dentista.ts +1011 -0
  96. package/src/templates/index.ts +2 -0
  97. package/src/templates/skills/agentkit-build-agent/SKILL.md +52 -0
  98. package/src/templates/skills/agentkit-build-agent/templates/appointment-intake.instructions.md +21 -0
  99. package/src/templates/skills/agentkit-build-agent/templates/sales-qualifier.instructions.md +17 -0
  100. package/src/templates/skills/agentkit-build-agent/templates/support-agent.instructions.md +16 -0
  101. package/src/templates/skills/agentkit-capsule/SKILL.md +70 -0
  102. package/src/templates/skills/agentkit-capsule/references/docs-router.md +15 -0
  103. package/src/templates/skills/agentkit-channels/SKILL.md +127 -0
  104. package/src/templates/skills/agentkit-channels/references/channel-buffering.md +65 -0
  105. package/src/templates/skills/agentkit-channels/references/channel-debugging.md +66 -0
  106. package/src/templates/skills/agentkit-channels/references/discord.md +93 -0
  107. package/src/templates/skills/agentkit-channels/references/slack.md +56 -0
  108. package/src/templates/skills/agentkit-channels/references/telegram.md +72 -0
  109. package/src/templates/skills/agentkit-channels/references/whatsapp-evolution.md +57 -0
  110. package/src/templates/skills/agentkit-channels/references/whatsapp-uazapi.md +61 -0
  111. package/src/templates/skills/agentkit-channels/references/whatsapp-zapster.md +77 -0
  112. package/src/templates/skills/agentkit-database/SKILL.md +45 -0
  113. package/src/templates/skills/agentkit-database/templates/appointments.schema.sql +15 -0
  114. package/src/templates/skills/agentkit-database/templates/leads.schema.sql +17 -0
  115. package/src/templates/skills/agentkit-deploy/SKILL.md +50 -0
  116. package/src/templates/skills/agentkit-evals/SKILL.md +109 -0
  117. package/src/templates/skills/agentkit-evals/templates/multi-turn.eval.md +29 -0
  118. package/src/templates/skills/agentkit-evals/templates/no-leak.eval.md +18 -0
  119. package/src/templates/skills/agentkit-evals/templates/smoke.eval.md +18 -0
  120. package/src/templates/skills/agentkit-evals/templates/tool-call.eval.md +27 -0
  121. package/src/templates/skills/agentkit-improve/SKILL.md +86 -0
  122. package/src/templates/skills/agentkit-improve/references/replay-side-effects.md +18 -0
  123. package/src/templates/skills/agentkit-improve/references/trace-packets.md +22 -0
  124. package/src/templates/skills/agentkit-improve/templates/regression.eval.md +18 -0
  125. package/src/templates/skills/agentkit-integrations/SKILL.md +76 -0
  126. package/src/templates/skills/agentkit-knowledge/SKILL.md +43 -0
  127. package/src/templates/skills/agentkit-knowledge/templates/faq.md +14 -0
  128. package/src/templates/skills/agentkit-knowledge/templates/policies.md +14 -0
  129. package/src/templates/skills/agentkit-knowledge/templates/prices.csv +3 -0
  130. package/src/templates/skills/agentkit-prompts/SKILL.md +47 -0
  131. package/src/templates/skills/agentkit-prompts/templates/knowledge-grounded-faq.instructions.md +11 -0
  132. package/src/templates/skills/agentkit-provider/SKILL.md +60 -0
  133. package/src/templates/skills/agentkit-security/SKILL.md +56 -0
  134. package/src/templates/skills/agentkit-tools/SKILL.md +37 -0
  135. package/src/templates/skills/agentkit-tools/examples/database-write.tool.md +35 -0
  136. package/src/templates/skills/agentkit-tools/examples/eval-safe-external-action.tool.md +37 -0
  137. package/src/templates/skills/agentkit-tools/examples/lookup-order.tool.md +46 -0
  138. package/src/templates/skills/agentkit-troubleshooting/SKILL.md +76 -0
  139. package/src/templates/support.ts +77 -18
  140. package/docs/guides/channels-production-handoff.md +0 -99
  141. package/docs/portable-deploy-release-checklist.md +0 -41
  142. package/src/runtime/targets/cloudflare/deploy.ts +0 -5475
@@ -1,4 +1,5 @@
1
1
  import { blankTemplate } from "./blank";
2
+ import { dentistaTemplate } from "./dentista";
2
3
  import { supportTemplate } from "./support";
3
4
 
4
5
  export type TemplateFile = {
@@ -17,6 +18,7 @@ export type AgentTemplateContext = {
17
18
 
18
19
  const templates = new Map<string, AgentTemplate>([
19
20
  [blankTemplate.name, blankTemplate],
21
+ [dentistaTemplate.name, dentistaTemplate],
20
22
  [supportTemplate.name, supportTemplate],
21
23
  ]);
22
24
 
@@ -0,0 +1,52 @@
1
+ ---
2
+ name: agentkit-build-agent
3
+ description: Use when the owner gives a natural-language brief for a new or changed AgentKit agent and expects the coding agent to turn it into a working local capsule with prompts, tools, schema, evals, and verification.
4
+ ---
5
+
6
+ # Build An AgentKit Agent
7
+
8
+ Use this when the owner asks for an agent in plain language.
9
+
10
+ ## Workflow
11
+
12
+ 1. Read `agentkit.config.ts`, `prompts/instructions.md`, `schema.sql`, `evals/`, and existing `tools/`.
13
+ 2. If `AGENT_SPEC.md` does not exist, create it from the owner's plain-language request with `npm run agentkit -- spec init --brief "<owner request>"`. If it exists, update it directly before changing behavior.
14
+ 3. Infer the first useful local version from the owner's brief and the spec. Do not ask the owner to fill a form.
15
+ 4. Edit `prompts/instructions.md` for behavior, boundaries, intake questions, escalation rules, and tool-use policy.
16
+ 5. For scheduling, deadlines, reminders, or any relative-date behavior, set `timeZone` in `agentkit.config.ts` to the business/user timezone. AgentKit injects the current date, weekday, timestamp, and timezone dynamically at runtime; do not hardcode today's date in prompts.
17
+ 6. Add tools only when the agent needs action, live data, authorization-sensitive data, or durable writes.
18
+ 7. Add database tables to `schema.sql` or ordered `migrations/*.sql` when the agent owns records.
19
+ 8. Add `sync.ts` and `seed.sql` with `npm run agentkit -- sync init` when the agent depends on external catalogs or recurring imports.
20
+ 9. Add or update evals for the main flow. Prefer multi-turn `turns` evals for real conversations.
21
+ 10. Keep the capsule runnable on `test/fake` unless the owner has chosen a real provider.
22
+
23
+ ## Templates
24
+
25
+ Use these only when they match the brief:
26
+
27
+ - `templates/support-agent.instructions.md`
28
+ - `templates/appointment-intake.instructions.md`
29
+ - `templates/sales-qualifier.instructions.md`
30
+
31
+ For prompt-only work, use `skills/agentkit-prompts/SKILL.md`.
32
+ For database-backed tools, use `skills/agentkit-database/SKILL.md`.
33
+
34
+ ## Verification
35
+
36
+ ```sh
37
+ npm run typecheck
38
+ npm run agentkit -- inspect
39
+ npm run chat -- --message "hello"
40
+ npm run eval
41
+ npm run agentkit -- spec check
42
+ ```
43
+
44
+ If a tool was added:
45
+
46
+ ```sh
47
+ npm run agentkit -- tool <tool_name> --input '<json>'
48
+ ```
49
+
50
+ ## Final Response
51
+
52
+ Summarize the files changed, assumptions made, verification results, and whether the behavior was tested with `test/fake` or a real provider selected by the owner.
@@ -0,0 +1,21 @@
1
+ You are an appointment and intake agent.
2
+
3
+ Goal:
4
+ - Collect the information needed to understand the request.
5
+ - Offer available times only after checking availability through tools.
6
+ - Confirm the exact date, time, name, and contact details before saving.
7
+
8
+ Required intake:
9
+ - Full name
10
+ - Contact method
11
+ - Reason for visit
12
+ - Preferred date or time window
13
+ - Any urgency or special constraints
14
+
15
+ Rules:
16
+ - Interpret today, tomorrow, weekdays, and vague time windows using the AgentKit runtime date context.
17
+ - If the user's scheduling timezone may differ from the business timezone, confirm the timezone before booking.
18
+ - Do not diagnose, promise outcomes, or provide emergency guidance beyond directing urgent cases to appropriate human or emergency support.
19
+ - Do not create, change, or cancel an appointment without explicit user confirmation.
20
+ - Do not invent availability.
21
+ - Use the scheduling tools for availability and writes.
@@ -0,0 +1,17 @@
1
+ You are a sales qualification agent.
2
+
3
+ Goal:
4
+ - Understand the user's current situation, urgency, budget range, authority, and desired outcome.
5
+ - Identify whether the lead is a fit for the configured offer.
6
+ - Capture structured lead details through tools when available.
7
+
8
+ Behavior:
9
+ - Ask one focused question at a time.
10
+ - Avoid pressure and exaggerated claims.
11
+ - Be clear about what is known, unknown, and next.
12
+ - Escalate to a human when the user asks for pricing exceptions, legal terms, procurement details, or custom commitments.
13
+
14
+ Rules:
15
+ - Do not invent pricing, discounts, case studies, or availability.
16
+ - Do not expose internal lead scores or qualification labels.
17
+
@@ -0,0 +1,16 @@
1
+ You are a focused support agent.
2
+
3
+ Help users resolve the current issue clearly and efficiently.
4
+
5
+ Behavior:
6
+ - Ask for the minimum missing context needed to help.
7
+ - Use tools when order, account, booking, or case status is needed.
8
+ - Do not invent status, policy, price, or availability.
9
+ - Explain next steps in plain language.
10
+ - Escalate when the request involves billing disputes, safety, legal issues, account ownership, or anything outside the configured tools.
11
+
12
+ Boundaries:
13
+ - Do not claim to have changed anything unless a tool confirms it.
14
+ - Do not expose internal tool output, IDs, scores, secrets, or logs.
15
+ - If a tool fails, say what could not be verified and ask for a safe next step.
16
+
@@ -0,0 +1,70 @@
1
+ ---
2
+ name: agentkit-capsule
3
+ description: Use when working inside an AgentKit Agent Capsule, especially after detecting agentkit.config.ts or when the owner asks to build, change, test, or deploy an AgentKit agent. Routes to task-specific AgentKit skills while avoiding loading the full docs by default.
4
+ ---
5
+
6
+ # AgentKit Capsule
7
+
8
+ Use this first inside an AgentKit Agent Capsule.
9
+
10
+ ## Start
11
+
12
+ 1. Treat the directory containing `agentkit.config.ts` as the capsule root.
13
+ 2. Read `AGENTS.md` or `AGENTKIT.md` for capsule-specific rules.
14
+ 3. Run `npm run agentkit -- docs llms` for the lightweight docs router.
15
+ 4. Pick one task skill. Do not load `llms-full.txt` unless a task skill or ambiguous framework behavior requires the complete contract.
16
+
17
+ ## Task Routing
18
+
19
+ - Build or reshape the agent from the owner's brief: `skills/agentkit-build-agent/SKILL.md`
20
+ - Edit prompts: `skills/agentkit-prompts/SKILL.md`
21
+ - Add actions or external data: `skills/agentkit-tools/SKILL.md`
22
+ - Add AgentKit-managed integrations such as managed Composio: `skills/agentkit-integrations/SKILL.md`
23
+ - Add database tables or database-backed tools: `skills/agentkit-database/SKILL.md`
24
+ - Add docs, FAQs, prices, policies, or CSV facts: `skills/agentkit-knowledge/SKILL.md`
25
+ - Switch from `test/fake` to a real model provider: `skills/agentkit-provider/SKILL.md`
26
+ - Add or run evals: `skills/agentkit-evals/SKILL.md`
27
+ - Improve from hosted or local production evidence: `skills/agentkit-improve/SKILL.md`
28
+ - Prepare hosted deploy: `skills/agentkit-deploy/SKILL.md`
29
+ - Work with secrets, external APIs, public access, channels, or real data: `skills/agentkit-security/SKILL.md`
30
+ - Add or debug website, Telegram, WhatsApp, Discord, Slack, or generic webhook channels: `skills/agentkit-channels/SKILL.md`
31
+ - Investigate command failures: `skills/agentkit-troubleshooting/SKILL.md`
32
+
33
+ For a compact docs map, read `references/docs-router.md`.
34
+
35
+ ## Default Checks
36
+
37
+ Run these before finishing ordinary capsule work:
38
+
39
+ ```sh
40
+ npm run typecheck
41
+ npm run agentkit -- inspect
42
+ npm run chat -- --message "hello"
43
+ ```
44
+
45
+ If you add a tool, also run:
46
+
47
+ ```sh
48
+ npm run agentkit -- tool <tool_name> --input '{}'
49
+ ```
50
+
51
+ If you change behavior, add or update an eval and run:
52
+
53
+ ```sh
54
+ npm run eval
55
+ ```
56
+
57
+ If the change fixes production behavior, also collect or use an improve bundle and run:
58
+
59
+ ```sh
60
+ npm run agentkit -- replay .agentkit/improve/<run> --against local
61
+ ```
62
+
63
+ ## Rules
64
+
65
+ - Keep `.env`, `.agentkit/`, and `node_modules/` out of commits.
66
+ - Keep secret names in `.env.schema`; keep secret values in ignored `.env` or hosted managed secrets.
67
+ - Keep the first useful version runnable with `test/fake` unless the owner explicitly chooses a real provider.
68
+ - For scheduling or relative-date agents, set `timeZone` in `agentkit.config.ts`; AgentKit injects the current date, weekday, timestamp, and timezone dynamically at runtime.
69
+ - Ask follow-up questions only when missing information blocks a safe local implementation.
70
+ - Tell the owner when testing used `test/fake` instead of a real provider.
@@ -0,0 +1,15 @@
1
+ # AgentKit Docs Router
2
+
3
+ Prefer the narrowest source that covers the task.
4
+
5
+ - Capsule creation and scaffold verification: `docs/guides/create-agent.md`
6
+ - Tools, schemas, secrets, and direct tool tests: `docs/guides/add-tool.md`
7
+ - Knowledge sources, indexing, search, and hosted sync: `docs/guides/add-knowledge.md`
8
+ - Evals and deterministic side-effect guards: `docs/guides/run-evals.md`
9
+ - Safe AgentKit product feedback drafts/submission: `docs/guides/send-feedback.md`
10
+ - Real provider setup: `docs/guides/use-provider.md`
11
+ - Deploy readiness, managed secrets, smoke checks, hosted UI: `docs/guides/prepare-deploy.md`
12
+ - Channels: `docs/guides/add-channel.md`, `connect-discord.md`, `connect-slack.md`, `connect-telegram.md`, `connect-whatsapp-evolution.md`, `connect-whatsapp-uazapi.md`, `connect-whatsapp-zapster.md`, `debug-channel.md`
13
+ - Security: `docs/guides/security-rules.md`
14
+
15
+ Use `npm run agentkit -- docs full` only for a complete-contract audit, framework internals, or a behavior not covered by the task guide.
@@ -0,0 +1,127 @@
1
+ ---
2
+ name: agentkit-channels
3
+ description: Use when adding, connecting, testing, buffering, transcribing audio, or debugging AgentKit website, Telegram, WhatsApp, Discord, Slack, or generic webhook channels, including channel config helpers, provider secrets, webhook setup, channel tests, delivery logs, burst-message buffers, and transcription provider secrets.
4
+ ---
5
+
6
+ # AgentKit Channels
7
+
8
+ Channels receive user messages. Tools let the agent call external systems. Keep them separate.
9
+
10
+ ## Workflow
11
+
12
+ 1. Add channel helpers in `agentkit.config.ts`.
13
+ 2. Keep `runtime: "edge"` and `storage.driver: "agentkit"`.
14
+ 3. Deploy before hosted channel creation.
15
+ 4. Configure provider secrets as managed secrets.
16
+ 5. Connect channel resources through the CLI.
17
+ 6. Test, doctor, and inspect delivery logs.
18
+
19
+ ## Audio Transcription
20
+
21
+ Enable transcription at the agent level and opt in per channel with `audio.mode: "transcribe"`.
22
+
23
+ ```ts
24
+ export default defineAgent({
25
+ // ...
26
+ transcription: {
27
+ provider: "groq",
28
+ model: "whisper-large-v3-turbo",
29
+ secret: "GROQ_API_KEY",
30
+ language: "pt",
31
+ limits: {
32
+ maxDurationSeconds: 180,
33
+ maxBytes: 20_000_000,
34
+ },
35
+ },
36
+ channels: [
37
+ telegramChannel({
38
+ name: "support-telegram",
39
+ audio: { mode: "transcribe" },
40
+ }),
41
+ ],
42
+ });
43
+ ```
44
+
45
+ V1 providers:
46
+
47
+ - `openai`: `gpt-4o-mini-transcribe`, `gpt-4o-transcribe`, `whisper-1`; default secret `OPENAI_API_KEY`.
48
+ - `groq`: `whisper-large-v3-turbo`, `whisper-large-v3`, `distil-whisper-large-v3-en`; default secret `GROQ_API_KEY`.
49
+
50
+ Telegram voice notes are usually OGG/Opus, so use Groq for the default Telegram voice-note path in V1. Zapster audio needs a usable HTTPS Zapster media download URL in the webhook payload; arbitrary hosts are rejected before bearer auth is sent. UAZAPI audio downloads go through UAZAPI `/message/download` with base64 return enabled. Evolution audio downloads go through Evolution API `/chat/getBase64FromMediaMessage/{instance}` with base64 return enabled. Arbitrary UAZAPI and Evolution webhook media hosts are not fetched. Hosted channel creation requires the transcription secret automatically when the channel enables transcription. Webhooks only enqueue audio jobs; download and transcription run in the retryable channel worker before the agent run.
51
+
52
+ Discord channels do not support audio in V1.
53
+
54
+ ## Buffering
55
+
56
+ Enable `buffer.mode: "debounce"` when clients send several short messages in a row and the agent should answer once.
57
+
58
+ ```ts
59
+ whatsappChannel({
60
+ name: "support-whatsapp",
61
+ provider: "zapster",
62
+ buffer: {
63
+ mode: "debounce",
64
+ quietWindowMs: 2500,
65
+ maxWaitMs: 12000,
66
+ maxMessages: 20,
67
+ maxChars: 8000,
68
+ },
69
+ })
70
+ ```
71
+
72
+ Buffered deliveries show `buffered` until AgentKit flushes the conversation buffer into one queued run.
73
+
74
+ ## Commands
75
+
76
+ ```sh
77
+ npm run agentkit -- inspect
78
+ npm run agentkit -- deploy
79
+ npm run agentkit -- channels list
80
+ npm run agentkit -- channels add website website-chat
81
+ npm run agentkit -- channels connect telegram support-telegram
82
+ npm run agentkit -- channels add whatsapp support-whatsapp --provider zapster
83
+ npm run agentkit -- channels connect whatsapp support-whatsapp --provider uazapi
84
+ npm run agentkit -- channels connect whatsapp main-whatsapp --provider evolution
85
+ npm run agentkit -- channels connect discord support-discord
86
+ npm run agentkit -- channels connect discord server-discord --mode bot
87
+ npm run agentkit -- channels connect slack support-slack
88
+ npm run agentkit -- channels connect webhook n8n-webhook
89
+ npm run agentkit -- channels doctor support-telegram
90
+ npm run agentkit -- channels test support-telegram --message "hello"
91
+ npm run agentkit -- channels test-audio support-telegram --fixture voice-note
92
+ npm run agentkit -- transcribe smoke --provider groq
93
+ npm run agentkit -- channels deliveries list support-telegram
94
+ ```
95
+
96
+ ## References
97
+
98
+ - `references/discord.md`
99
+ - `references/slack.md`
100
+ - `references/telegram.md`
101
+ - `references/whatsapp-evolution.md`
102
+ - `references/whatsapp-uazapi.md`
103
+ - `references/whatsapp-zapster.md`
104
+ - `references/channel-buffering.md`
105
+ - `references/channel-debugging.md`
106
+
107
+ ## Safety
108
+
109
+ Do not paste provider tokens into code, docs, fixtures, prompts, evals, or delivery logs. Webhook URLs are public transport endpoints; authenticity comes from provider validation or channel tokens.
110
+
111
+ ## Generic Webhooks
112
+
113
+ Use `webhookChannel({ name: "n8n-webhook" })` for n8n, Make, Zapier, Pipedream, or custom server events.
114
+
115
+ Canonical JSON:
116
+
117
+ ```json
118
+ {
119
+ "event_id": "evt_123",
120
+ "external_id": "customer_123",
121
+ "message": "hello from n8n"
122
+ }
123
+ ```
124
+
125
+ `event_id` is required for dedupe. `external_id` is recommended for conversation continuity and is hashed before storage. Authenticate with `Authorization: Bearer <AGENTKIT_WEBHOOK_SECRET>`, `X-AgentKit-Webhook-Secret`, or `X-AgentKit-Webhook-Signature: sha256=<hmac of raw JSON body>`.
126
+
127
+ Generic webhooks are inbound-only in V1. Add a separate tool if the agent must call back into n8n after it runs.
@@ -0,0 +1,65 @@
1
+ # Channel Buffering
2
+
3
+ Use buffering when a client sends several messages in a burst and the agent should answer once.
4
+
5
+ Config:
6
+
7
+ ```ts
8
+ telegramChannel({
9
+ name: "support-telegram",
10
+ buffer: {
11
+ mode: "debounce",
12
+ quietWindowMs: 1500,
13
+ maxWaitMs: 8000,
14
+ maxMessages: 20,
15
+ maxChars: 8000,
16
+ },
17
+ })
18
+ ```
19
+
20
+ ```ts
21
+ whatsappChannel({
22
+ name: "support-whatsapp",
23
+ provider: "zapster",
24
+ buffer: {
25
+ mode: "debounce",
26
+ quietWindowMs: 2500,
27
+ maxWaitMs: 12000,
28
+ maxMessages: 20,
29
+ maxChars: 8000,
30
+ },
31
+ })
32
+ ```
33
+
34
+ Behavior:
35
+
36
+ - Buffer scope is one channel conversation.
37
+ - Provider validation and dedupe still run per webhook event.
38
+ - `quietWindowMs` flushes after the client stops sending messages.
39
+ - `maxWaitMs` guarantees a reply even if messages keep arriving.
40
+ - `maxMessages` and `maxChars` cap prompt size and cost.
41
+ - Omit `buffer` or set `buffer: { mode: "off" }` to run the agent once per inbound message.
42
+
43
+ Debug:
44
+
45
+ ```sh
46
+ agentkit channels buffers list <name>
47
+ agentkit channels buffers show <conversation-id>
48
+ agentkit channels buffers flush <conversation-id>
49
+ agentkit channels buffers clear <conversation-id>
50
+ agentkit channels buffers retry <conversation-id>
51
+ agentkit channels deliveries list <name>
52
+ agentkit channels deliveries show <delivery-id>
53
+ ```
54
+
55
+ Expected delivery states:
56
+
57
+ ```txt
58
+ buffered
59
+ queued
60
+ running
61
+ agent_completed
62
+ provider_request_built
63
+ provider_sent
64
+ adapter_stubbed
65
+ ```
@@ -0,0 +1,66 @@
1
+ # Channel Debugging
2
+
3
+ Start with:
4
+
5
+ ```sh
6
+ agentkit channels list
7
+ agentkit channels status <name>
8
+ agentkit channels doctor <name>
9
+ agentkit channels test <name> --message "hello"
10
+ agentkit channels test-audio <name> --fixture voice-note
11
+ agentkit transcribe smoke --provider groq
12
+ agentkit channels deliveries list <name> --since 24h
13
+ agentkit channels deliveries show <delivery-id>
14
+ agentkit channels buffers list <name>
15
+ agentkit channels buffers show <conversation-id>
16
+ agentkit channels buffers flush <conversation-id>
17
+ agentkit channels buffers clear <conversation-id>
18
+ agentkit channels buffers retry <conversation-id>
19
+ ```
20
+
21
+ Common states:
22
+
23
+ ```txt
24
+ webhook_received
25
+ validated
26
+ duplicate
27
+ audio_received
28
+ audio_downloaded
29
+ transcribing
30
+ transcribed
31
+ buffered
32
+ queued
33
+ running
34
+ agent_completed
35
+ provider_request_built
36
+ provider_sent
37
+ adapter_stubbed
38
+ delivered
39
+ provider_failed
40
+ synthetic_expected_failure
41
+ dead_lettered
42
+ skipped
43
+ ```
44
+
45
+ Common errors:
46
+
47
+ - `channel_not_found`: webhook URL points to an unknown channel. `channels test` is the official synthetic smoke and should resolve the current `.agentkit/deploy.json` channel.
48
+ - `channel_secret_missing`: required hosted secret is not set.
49
+ - `channel_signature_invalid`: webhook secret, token, origin header, or Discord public key mismatch.
50
+ - Discord bot mode with no deliveries: confirm `--mode bot`, `DISCORD_BOT_TOKEN`, Message Content Intent, server install, and channel permissions for View Channel, Read Message History, and Send Messages.
51
+ - `channel_payload_invalid`: malformed or unsupported provider payload.
52
+ - `channel_event_duplicate`: provider retry; do not create a second run.
53
+ - `audio_received`: audio message was accepted and normalized.
54
+ - `audio_downloaded`: retryable channel worker downloaded provider media into memory.
55
+ - `transcribing`: AgentKit is calling the configured transcription provider.
56
+ - `transcribed`: transcript text was queued for the agent.
57
+ - `channel_audio_download_unavailable`: provider audio payload did not include a usable download URL, or Zapster sent a non-HTTPS/non-Zapster media host.
58
+ - `transcription_secret_missing`: managed transcription secret is missing.
59
+ - `transcription_audio_too_large` or `transcription_audio_too_long`: audio exceeded configured limits.
60
+ - `transcription_audio_format_unsupported`: provider does not accept this audio MIME type or extension.
61
+ - `transcription_provider_unavailable`: retryable transcription provider failure.
62
+ - `channel_limit_exceeded`: backpressure skipped the message.
63
+ - `synthetic_expected_failure`: a synthetic test reached AgentKit, but the provider correctly rejected a fake test recipient.
64
+ - `buffered` delivery state: message is waiting for the channel quiet window or max wait before one coalesced agent run is queued.
65
+ - `adapter_stubbed`: adapter completed without calling an outbound provider, either because explicit dry-run mode is enabled or the channel is inbound-only.
66
+ - `provider_sent`: the provider accepted the outbound send and returned a provider message ID.
@@ -0,0 +1,93 @@
1
+ # Discord Channel
2
+
3
+ Discord supports two modes:
4
+
5
+ - `interactions`: slash commands through the Discord Interactions Endpoint URL.
6
+ - `bot`: normal server messages through a Discord Bot user and Gateway connection.
7
+
8
+ Use bot mode when the owner asks for the agent to answer without slash commands.
9
+
10
+ ## Slash Commands
11
+
12
+ Required secret:
13
+
14
+ ```txt
15
+ DISCORD_PUBLIC_KEY
16
+ ```
17
+
18
+ Config:
19
+
20
+ ```ts
21
+ discordChannel({ name: "support-discord" })
22
+ ```
23
+
24
+ Commands:
25
+
26
+ ```sh
27
+ agentkit deploy
28
+ agentkit secret set DISCORD_PUBLIC_KEY --stdin
29
+ agentkit channels connect discord support-discord
30
+ agentkit channels test support-discord --message "hello"
31
+ agentkit channels deliveries list support-discord
32
+ ```
33
+
34
+ Paste the printed webhook URL into the application's Interactions Endpoint URL. Register a slash command with a string option named `message`, `text`, `prompt`, `question`, `query`, or `input`.
35
+
36
+ ## Bot Server Messages
37
+
38
+ Required secret:
39
+
40
+ ```txt
41
+ DISCORD_BOT_TOKEN
42
+ ```
43
+
44
+ Config:
45
+
46
+ ```ts
47
+ discordChannel({
48
+ name: "server-discord",
49
+ mode: "bot",
50
+ })
51
+ ```
52
+
53
+ Commands:
54
+
55
+ ```sh
56
+ agentkit deploy
57
+ agentkit secret set DISCORD_BOT_TOKEN --stdin
58
+ agentkit channels connect discord server-discord --mode bot
59
+ agentkit channels test server-discord --message "hello"
60
+ agentkit channels deliveries list server-discord
61
+ ```
62
+
63
+ In the Discord Developer Portal, open the Bot page, enable Message Content Intent, install the app into the server, and grant the bot `View Channel`, `Read Message History`, and `Send Messages` in the channels it should answer.
64
+
65
+ Bot mode processes every readable non-bot text message Discord sends over the Gateway. Keep server permissions narrow if the agent should answer only in specific channels.
66
+
67
+ ## Buffering
68
+
69
+ Buffer rapid Discord messages:
70
+
71
+ ```ts
72
+ discordChannel({
73
+ name: "server-discord",
74
+ mode: "bot",
75
+ buffer: {
76
+ mode: "debounce",
77
+ quietWindowMs: 1500,
78
+ maxWaitMs: 8000,
79
+ maxMessages: 20,
80
+ maxChars: 8000,
81
+ },
82
+ })
83
+ ```
84
+
85
+ ## Runtime Behavior
86
+
87
+ Slash-command mode validates `X-Signature-Ed25519` and `X-Signature-Timestamp` against the raw body and `DISCORD_PUBLIC_KEY`, returns `type: 1` for Discord `PING`, acknowledges slash commands with a deferred response, then sends the final answer as an interaction follow-up.
88
+
89
+ Bot mode connects to Discord Gateway with `DISCORD_BOT_TOKEN`, requests guild message and message-content intents, ignores bot-authored messages, normalizes `MESSAGE_CREATE`, and sends the final answer through `/channels/<channel_id>/messages`.
90
+
91
+ All outbound Discord sends use `allowed_mentions: { parse: [] }`. Discord interaction tokens and bot tokens must not appear in delivery, queue, buffer, or doctor API responses.
92
+
93
+ Discord audio is not supported in V1; do not configure `audio` on `discordChannel`.
@@ -0,0 +1,56 @@
1
+ # Slack Channel
2
+
3
+ Slack uses Events API webhooks.
4
+
5
+ V1 supports:
6
+
7
+ - `app_mention` in channels.
8
+ - `message.im` direct messages.
9
+ - Outbound replies through `chat.postMessage`.
10
+
11
+ V1 does not support Socket Mode, files, audio transcription, app-management automation, or all-channel message listening.
12
+
13
+ ## Required Secrets
14
+
15
+ ```txt
16
+ SLACK_BOT_TOKEN
17
+ SLACK_SIGNING_SECRET
18
+ ```
19
+
20
+ ## Config
21
+
22
+ ```ts
23
+ slackChannel({
24
+ name: "support-slack",
25
+ })
26
+ ```
27
+
28
+ ## Commands
29
+
30
+ ```sh
31
+ agentkit deploy
32
+ agentkit secret set SLACK_BOT_TOKEN --stdin
33
+ agentkit secret set SLACK_SIGNING_SECRET --stdin
34
+ agentkit channels connect slack support-slack
35
+ agentkit channels test support-slack --message "hello"
36
+ agentkit channels deliveries list support-slack
37
+ ```
38
+
39
+ ## Slack Setup
40
+
41
+ In Slack app configuration:
42
+
43
+ 1. Basic Information: copy Signing Secret into `SLACK_SIGNING_SECRET`.
44
+ 2. OAuth & Permissions: add bot scopes `app_mentions:read`, `im:history`, and `chat:write`.
45
+ 3. Install or reinstall the app to the workspace.
46
+ 4. Copy the Bot User OAuth Token into `SLACK_BOT_TOKEN`.
47
+ 5. Event Subscriptions: enable events and paste the AgentKit webhook URL.
48
+ 6. Subscribe to bot events `app_mention` and `message.im`.
49
+
50
+ ## Runtime Behavior
51
+
52
+ AgentKit verifies `X-Slack-Signature` and `X-Slack-Request-Timestamp` against the raw body before processing events. It rejects stale timestamps, answers `url_verification` with the literal challenge, skips bot/subtype messages, maps channel mentions to Slack threads, maps DMs to the Slack DM channel and user, and replies with `chat.postMessage`.
53
+
54
+ Outbound Slack text escapes Slack control mentions and disables link-name expansion and unfurls.
55
+
56
+ Slack audio is not supported in V1; do not configure `audio` on `slackChannel`.