@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
@@ -0,0 +1,121 @@
1
+ # Connect WhatsApp Through Evolution API
2
+
3
+ ## Goal
4
+
5
+ Connect a self-hosted Evolution API WhatsApp instance to a hosted AgentKit WhatsApp channel.
6
+
7
+ ## When To Use It
8
+
9
+ Use this after `whatsappChannel({ name: "main-whatsapp", provider: "evolution" })` exists in `agentkit.config.ts` and the capsule has been deployed.
10
+
11
+ ## Commands
12
+
13
+ ```sh
14
+ agentkit deploy
15
+ agentkit channels connect whatsapp main-whatsapp --provider evolution
16
+ agentkit channels status main-whatsapp
17
+ agentkit channels test main-whatsapp --message "hello"
18
+ agentkit channels deliveries list main-whatsapp
19
+ agentkit channels buffers list main-whatsapp
20
+ ```
21
+
22
+ Required secrets:
23
+
24
+ ```txt
25
+ EVOLUTION_API_BASE_URL
26
+ EVOLUTION_API_KEY
27
+ EVOLUTION_INSTANCE_NAME
28
+ EVOLUTION_WEBHOOK_TOKEN
29
+ ```
30
+
31
+ If WhatsApp audio transcription is enabled, also set the transcription provider secret declared by `agentkit inspect`, usually `OPENAI_API_KEY` or `GROQ_API_KEY`.
32
+
33
+ ## Minimal Working Example
34
+
35
+ ```ts
36
+ import { defineAgent, whatsappChannel } from "@andreprado/agentkit";
37
+
38
+ export default defineAgent({
39
+ name: "my-agent",
40
+ runtime: "edge",
41
+ provider: { name: "test", model: "fake" },
42
+ instructions: "./prompts/instructions.md",
43
+ secrets: [],
44
+ tools: [],
45
+ channels: [whatsappChannel({ name: "main-whatsapp", provider: "evolution" })],
46
+ access: { mode: "public" },
47
+ storage: { driver: "agentkit" },
48
+ });
49
+ ```
50
+
51
+ ## Setup Behavior
52
+
53
+ `agentkit channels connect whatsapp main-whatsapp --provider evolution` creates or updates the hosted channel, verifies managed secrets, calls Evolution API `POST /webhook/set/{instance}`, confirms the configured webhook through `GET /webhook/find/{instance}`, then runs a synthetic inbound smoke.
54
+
55
+ Expected webhook URL shape:
56
+
57
+ ```txt
58
+ https://<deploy-host>/channels/main-whatsapp/whatsapp/evolution/webhook
59
+ ```
60
+
61
+ AgentKit registers the webhook URL with the required token query parameter:
62
+
63
+ ```txt
64
+ https://<deploy-host>/channels/main-whatsapp/whatsapp/evolution/webhook?token=<EVOLUTION_WEBHOOK_TOKEN>
65
+ ```
66
+
67
+ `EVOLUTION_API_BASE_URL` must be the public HTTPS origin for the Evolution API server, for example `https://evolution.example.com`. AgentKit rejects HTTP, localhost, private-network, link-local, metadata, and credential-bearing base URLs before sending `EVOLUTION_API_KEY`.
68
+
69
+ ## Audio
70
+
71
+ Use `transcription` at the agent level and `audio.mode: "transcribe"` on the Evolution channel.
72
+
73
+ ```ts
74
+ whatsappChannel({
75
+ name: "main-whatsapp",
76
+ provider: "evolution",
77
+ audio: {
78
+ mode: "transcribe",
79
+ },
80
+ })
81
+ ```
82
+
83
+ Evolution audio webhooks become normalized audio messages. The retryable channel worker downloads media through Evolution API `POST /chat/getBase64FromMediaMessage/{instance}` and sends the bytes to AgentKit's configured transcription provider.
84
+
85
+ ## Safety Rules
86
+
87
+ - Keep phone numbers redacted in logs by default.
88
+ - Do not store Evolution API keys or webhook tokens in `agentkit.config.ts`.
89
+ - `EVOLUTION_WEBHOOK_TOKEN` is required because AgentKit V1 does not rely on an Evolution webhook body-signature contract.
90
+ - AgentKit ignores `fromMe` messages to avoid reply loops.
91
+ - Text replies call Evolution API `POST /message/sendText/{instance}` with the `apikey` header and a body containing `number` and `text`.
92
+ - Real provider success is recorded as `provider_sent` only when Evolution returns a provider message id.
93
+ - Only set `AGENTKIT_CHANNEL_SEND_DRY_RUN=1` in tests when Evolution should not receive a real message. Dry-run deliveries are recorded as `adapter_stubbed`, not sent.
94
+
95
+ ## Verification
96
+
97
+ ```sh
98
+ agentkit channels setup main-whatsapp --apply
99
+ agentkit channels status main-whatsapp
100
+ agentkit channels test main-whatsapp --message "hello"
101
+ agentkit channels test-audio main-whatsapp --fixture voice-note
102
+ agentkit channels deliveries list main-whatsapp
103
+ agentkit channels deliveries show <delivery-id>
104
+ ```
105
+
106
+ ## Troubleshooting
107
+
108
+ `channel_secret_missing`:
109
+ Set `EVOLUTION_API_BASE_URL`, `EVOLUTION_API_KEY`, `EVOLUTION_INSTANCE_NAME`, and `EVOLUTION_WEBHOOK_TOKEN` as hosted managed secrets.
110
+
111
+ `channel_signature_invalid`:
112
+ The Evolution webhook query token does not match.
113
+
114
+ `channel_provider_setup_invalid`:
115
+ `EVOLUTION_API_BASE_URL` is not an allowed public HTTPS base URL.
116
+
117
+ `channel_provider_setup_failed`:
118
+ AgentKit could not configure or verify the Evolution webhook through `/webhook/set/{instance}` and `/webhook/find/{instance}`.
119
+
120
+ `channel_audio_download_unavailable`:
121
+ Evolution did not return base64 media data from `/chat/getBase64FromMediaMessage/{instance}`, or the audio payload did not include a provider message id.
@@ -0,0 +1,126 @@
1
+ # Connect WhatsApp Through UAZAPI
2
+
3
+ ## Goal
4
+
5
+ Connect a UAZAPI WhatsApp instance to a hosted AgentKit WhatsApp channel.
6
+
7
+ ## When To Use It
8
+
9
+ Use this after `whatsappChannel({ name: "support-whatsapp", provider: "uazapi" })` exists in `agentkit.config.ts` and the capsule has been deployed.
10
+
11
+ ## Commands
12
+
13
+ ```sh
14
+ agentkit deploy
15
+ agentkit channels connect whatsapp support-whatsapp --provider uazapi
16
+ agentkit channels status support-whatsapp
17
+ agentkit channels test support-whatsapp --message "hello"
18
+ agentkit channels deliveries list support-whatsapp
19
+ agentkit channels buffers list support-whatsapp
20
+ ```
21
+
22
+ Required secrets:
23
+
24
+ ```txt
25
+ UAZAPI_BASE_URL
26
+ UAZAPI_TOKEN
27
+ ```
28
+
29
+ Optional hardening secret:
30
+
31
+ ```txt
32
+ UAZAPI_WEBHOOK_TOKEN
33
+ ```
34
+
35
+ If WhatsApp audio transcription is enabled, also set the transcription provider secret declared by `agentkit inspect`, usually `OPENAI_API_KEY` or `GROQ_API_KEY`.
36
+
37
+ ## Minimal Working Example
38
+
39
+ ```ts
40
+ import { defineAgent, whatsappChannel } from "@andreprado/agentkit";
41
+
42
+ export default defineAgent({
43
+ name: "support-agent",
44
+ runtime: "edge",
45
+ provider: { name: "test", model: "fake" },
46
+ instructions: "./prompts/instructions.md",
47
+ secrets: [],
48
+ tools: [],
49
+ channels: [whatsappChannel({ name: "support-whatsapp", provider: "uazapi" })],
50
+ access: { mode: "public" },
51
+ storage: { driver: "agentkit" },
52
+ });
53
+ ```
54
+
55
+ ## Setup Behavior
56
+
57
+ `agentkit channels connect whatsapp support-whatsapp --provider uazapi` creates or updates the hosted channel, verifies managed secrets, calls UAZAPI `/webhook`, confirms the configured webhook is listed by UAZAPI, then runs a synthetic inbound smoke.
58
+
59
+ Expected webhook URL shape:
60
+
61
+ ```txt
62
+ https://<deploy-host>/channels/support-whatsapp/whatsapp/uazapi/webhook
63
+ ```
64
+
65
+ If the channel declares `UAZAPI_WEBHOOK_TOKEN`, AgentKit registers the webhook URL with the token query parameter:
66
+
67
+ ```txt
68
+ https://<deploy-host>/channels/support-whatsapp/whatsapp/uazapi/webhook?token=<UAZAPI_WEBHOOK_TOKEN>
69
+ ```
70
+
71
+ `UAZAPI_BASE_URL` must be an HTTPS UAZAPI instance URL, for example `https://api.uazapi.com`. AgentKit rejects localhost, private-network, link-local, metadata, and credential-bearing base URLs before sending `UAZAPI_TOKEN`.
72
+
73
+ ## Audio
74
+
75
+ Use `transcription` at the agent level and `audio.mode: "transcribe"` on the UAZAPI channel.
76
+
77
+ ```ts
78
+ whatsappChannel({
79
+ name: "support-whatsapp",
80
+ provider: "uazapi",
81
+ audio: {
82
+ mode: "transcribe",
83
+ },
84
+ })
85
+ ```
86
+
87
+ UAZAPI audio webhooks become normalized audio messages. The retryable channel worker downloads media through UAZAPI `/message/download` using `return_base64: true`; AgentKit does not fetch arbitrary webhook-provided media URLs.
88
+
89
+ ## Safety Rules
90
+
91
+ - Keep phone numbers redacted in logs by default.
92
+ - Do not store UAZAPI tokens in `agentkit.config.ts`.
93
+ - Use optional `UAZAPI_WEBHOOK_TOKEN` when the endpoint should require a secret query token in addition to the public route.
94
+ - UAZAPI does not expose a documented webhook body-signature contract in AgentKit V1; treat the optional query token as the hardening layer.
95
+ - AgentKit ignores `fromMe` and `wasSentByApi` messages to avoid reply loops.
96
+ - Text replies call UAZAPI `POST /send/text` with the `token` header and a body containing `number`, `text`, `readchat`, `async`, `track_source`, and `track_id`.
97
+ - Real provider success is recorded as `provider_sent` only when UAZAPI returns a provider message id.
98
+ - Only set `AGENTKIT_CHANNEL_SEND_DRY_RUN=1` in tests when UAZAPI should not receive a real message. Dry-run deliveries are recorded as `adapter_stubbed`, not sent.
99
+
100
+ ## Verification
101
+
102
+ ```sh
103
+ agentkit channels setup support-whatsapp --apply
104
+ agentkit channels status support-whatsapp
105
+ agentkit channels test support-whatsapp --message "hello"
106
+ agentkit channels test-audio support-whatsapp --fixture voice-note
107
+ agentkit channels deliveries list support-whatsapp
108
+ agentkit channels deliveries show <delivery-id>
109
+ ```
110
+
111
+ ## Troubleshooting
112
+
113
+ `channel_secret_missing`:
114
+ Set `UAZAPI_BASE_URL` and `UAZAPI_TOKEN` as hosted managed secrets. If the channel declares `UAZAPI_WEBHOOK_TOKEN`, set that managed secret too.
115
+
116
+ `channel_signature_invalid`:
117
+ The optional UAZAPI webhook query token does not match.
118
+
119
+ `channel_provider_setup_invalid`:
120
+ `UAZAPI_BASE_URL` is not an allowed HTTPS public base URL.
121
+
122
+ `channel_provider_setup_failed`:
123
+ AgentKit could not configure or verify the UAZAPI webhook through `/webhook`.
124
+
125
+ `channel_audio_download_unavailable`:
126
+ UAZAPI did not return base64 media data from `/message/download`, or the audio payload did not include a provider message id.
@@ -12,18 +12,37 @@ Use this after `whatsappChannel({ name: "support-whatsapp", provider: "zapster"
12
12
 
13
13
  ```sh
14
14
  agentkit deploy
15
- agentkit channels add whatsapp support-whatsapp --provider zapster
16
- agentkit channels setup support-whatsapp
15
+ agentkit channels connect whatsapp support-whatsapp --provider zapster
17
16
  agentkit channels status support-whatsapp
18
17
  agentkit channels test support-whatsapp --message "hello"
19
18
  agentkit channels deliveries list support-whatsapp --since 24h
19
+ agentkit channels buffers list support-whatsapp
20
20
  ```
21
21
 
22
22
  Required secrets:
23
23
 
24
24
  ```txt
25
25
  ZAPSTER_API_KEY
26
- ZAPSTER_WEBHOOK_SECRET
26
+ ZAPSTER_INSTANCE_ID
27
+ ZAPSTER_WEBHOOK_ID
28
+ ```
29
+
30
+ Optional hardening secret:
31
+
32
+ ```txt
33
+ ZAPSTER_WEBHOOK_TOKEN
34
+ ```
35
+
36
+ If WhatsApp audio transcription is enabled, also set the transcription provider secret declared by `agentkit inspect`, usually:
37
+
38
+ ```txt
39
+ OPENAI_API_KEY
40
+ ```
41
+
42
+ or:
43
+
44
+ ```txt
45
+ GROQ_API_KEY
27
46
  ```
28
47
 
29
48
  ## Files Created Or Edited
@@ -50,22 +69,97 @@ export default defineAgent({
50
69
  });
51
70
  ```
52
71
 
72
+ To handle clients who send several WhatsApp messages before waiting, enable channel buffering:
73
+
74
+ ```ts
75
+ whatsappChannel({
76
+ name: "support-whatsapp",
77
+ provider: "zapster",
78
+ buffer: {
79
+ mode: "debounce",
80
+ quietWindowMs: 2500,
81
+ maxWaitMs: 12000,
82
+ maxMessages: 20,
83
+ maxChars: 8000,
84
+ },
85
+ })
86
+ ```
87
+
88
+ ## Auto Transcribe WhatsApp Audio
89
+
90
+ Use `transcription` at the agent level and `audio.mode: "transcribe"` on the Zapster channel.
91
+
92
+ ```ts
93
+ import { defineAgent, whatsappChannel } from "@andreprado/agentkit";
94
+
95
+ export default defineAgent({
96
+ name: "support-agent",
97
+ runtime: "edge",
98
+ provider: { name: "openai", model: "gpt-5.4-mini" },
99
+ instructions: "./prompts/instructions.md",
100
+ transcription: {
101
+ provider: "openai",
102
+ model: "gpt-4o-mini-transcribe",
103
+ secret: "OPENAI_API_KEY",
104
+ language: "pt",
105
+ limits: {
106
+ maxDurationSeconds: 180,
107
+ maxBytes: 20_000_000,
108
+ },
109
+ },
110
+ channels: [
111
+ whatsappChannel({
112
+ name: "support-whatsapp",
113
+ provider: "zapster",
114
+ audio: {
115
+ mode: "transcribe",
116
+ },
117
+ }),
118
+ ],
119
+ access: { mode: "public" },
120
+ storage: { driver: "agentkit" },
121
+ });
122
+ ```
123
+
124
+ Processing order:
125
+
126
+ 1. AgentKit validates Zapster origin headers and the optional webhook token.
127
+ 2. Zapster audio payloads become normalized audio messages.
128
+ 3. AgentKit records `audio_received` and enqueues a channel job before acknowledging Zapster.
129
+ 4. The retryable channel worker downloads the media URL from a trusted Zapster HTTPS host using `ZAPSTER_API_KEY`.
130
+ 5. AgentKit sends the audio bytes to the configured transcription provider using the user's managed secret.
131
+ 6. The agent run receives a text message with the transcript.
132
+
133
+ Zapster payloads must include a media download URL such as `audio.downloadUrl`, `audio.url`, `audio.mediaUrl`, or the snake_case equivalents. The URL must be HTTPS and hosted by Zapster; AgentKit rejects arbitrary webhook-provided hosts before sending `ZAPSTER_API_KEY`. If Zapster sends only a media ID without a download URL, AgentKit records `channel_audio_download_unavailable` and does not create an agent run for that audio in V1.
134
+
53
135
  ## Setup Behavior
54
136
 
55
- `agentkit channels setup support-whatsapp` prints the stable AgentKit webhook URL. Paste it into Zapster webhook settings and configure Zapster to send the same shared secret as `ZAPSTER_WEBHOOK_SECRET`.
137
+ `agentkit channels setup support-whatsapp` prints the stable AgentKit webhook URL. Paste it into Zapster webhook settings.
56
138
 
57
139
  Expected webhook URL shape:
58
140
 
59
141
  ```txt
60
- https://<deploy-host>/channels/chn_<id>/whatsapp/zapster/webhook
142
+ https://<deploy-host>/channels/support-whatsapp/whatsapp/zapster/webhook
143
+ ```
144
+
145
+ If the channel declares `ZAPSTER_WEBHOOK_TOKEN`, register the Zapster URL with the token as a query parameter:
146
+
147
+ ```txt
148
+ https://<deploy-host>/channels/support-whatsapp/whatsapp/zapster/webhook?token=<ZAPSTER_WEBHOOK_TOKEN>
61
149
  ```
62
150
 
63
151
  ## Safety Rules
64
152
 
65
153
  - Keep phone numbers redacted in logs by default.
66
154
  - Do not store Zapster API keys in `agentkit.config.ts`.
67
- - Inbound validation uses `X-Zapster-Webhook-Secret`.
155
+ - Inbound validation uses Zapster's `X-Instance-ID`, `X-Webhook-ID`, `X-Message-ID`, `X-Attempt-Count`, and `User-Agent: Zapsterapi/...` headers.
156
+ - Zapster webhook headers are origin validation, not a cryptographic body signature.
157
+ - Use optional `ZAPSTER_WEBHOOK_TOKEN` in the webhook URL when the endpoint should require an extra secret known only to AgentKit and Zapster.
68
158
  - Unsupported media should be logged as skipped/unsupported without creating an agent run.
159
+ - AgentKit handles Zapster `message.received` envelopes with event id at `id`, message text at `data.content.text`, and contact identity at `data.sender.id`.
160
+ - Outbound replies call `POST https://api.zapsterapi.com/v1/wa/messages` with bearer auth and a JSON body containing `recipient`, `text`, and `instance_id`.
161
+ - Real provider success is recorded as `provider_sent` only when Zapster returns a provider message ID.
162
+ - Only set `AGENTKIT_CHANNEL_SEND_DRY_RUN=1` in tests when Zapster should not receive a real message. Dry-run deliveries are recorded as `adapter_stubbed`, not sent.
69
163
 
70
164
  ## Verification
71
165
 
@@ -74,15 +168,25 @@ agentkit channels status support-whatsapp
74
168
  agentkit channels test support-whatsapp --message "hello"
75
169
  agentkit channels deliveries list support-whatsapp
76
170
  agentkit channels deliveries show <delivery-id>
171
+ agentkit channels buffers list support-whatsapp
172
+ agentkit channels buffers flush support-whatsapp <conversation-id>
173
+ agentkit channels buffers clear support-whatsapp <conversation-id>
174
+ agentkit channels buffers retry support-whatsapp <conversation-id>
77
175
  ```
78
176
 
79
177
  ## Troubleshooting
80
178
 
81
179
  `channel_secret_missing`:
82
- Set `ZAPSTER_API_KEY` and `ZAPSTER_WEBHOOK_SECRET` as hosted managed secrets.
180
+ Set `ZAPSTER_API_KEY`, `ZAPSTER_INSTANCE_ID`, and `ZAPSTER_WEBHOOK_ID` as hosted managed secrets. If the channel declares `ZAPSTER_WEBHOOK_TOKEN`, set that managed secret too.
83
181
 
84
182
  `channel_signature_invalid`:
85
- Zapster is not sending the expected webhook secret.
183
+ Zapster is not sending the expected instance/webhook IDs, or the optional query token does not match.
86
184
 
87
185
  `channel_unsupported_message_type` or skipped delivery:
88
186
  The inbound WhatsApp event was not supported text. Inspect the delivery record for provider metadata.
187
+
188
+ `channel_audio_download_unavailable`:
189
+ Zapster sent an audio event without a usable media download URL, or the URL was not an HTTPS Zapster media host. Configure Zapster to include a trusted Zapster media URL in webhook payloads, or add a Zapster media lookup adapter before enabling `audio.mode: "transcribe"`.
190
+
191
+ `transcription_secret_missing`:
192
+ Set `OPENAI_API_KEY`, `GROQ_API_KEY`, or the custom secret named in `transcription.secret` as a managed hosted secret.
@@ -19,7 +19,6 @@ cd /tmp/agentkit-demo
19
19
 
20
20
  npx @andreprado/agentkit@alpha new demo --template blank
21
21
  cd demo
22
- npm install
23
22
  npm run typecheck
24
23
  npm run chat -- --message "hello"
25
24
  npm run agentkit -- conversations list
@@ -37,10 +36,22 @@ For the support template:
37
36
  ```sh
38
37
  npx @andreprado/agentkit@alpha new support-demo --template support
39
38
  cd support-demo
40
- npm install
41
39
  npm run agentkit -- tool lookup_order --input '{"orderId":"A100"}'
42
40
  ```
43
41
 
42
+ ## Windows PowerShell
43
+
44
+ If PowerShell blocks `npm.ps1` or `npx.ps1` with `PSSecurityException`, run the same commands through the Windows command shims:
45
+
46
+ ```sh
47
+ npx.cmd @andreprado/agentkit@alpha new demo --template blank
48
+ npm.cmd run typecheck
49
+ npm.cmd run chat -- --message "hello"
50
+ npm.cmd run agentkit -- inspect
51
+ ```
52
+
53
+ This keeps the capsule workflow the same without changing the machine-wide PowerShell execution policy.
54
+
44
55
  ## Files Created Or Edited
45
56
 
46
57
  Generated files:
@@ -86,7 +97,16 @@ Primary flow:
86
97
  Develop an appointment and intake agent for an ophthalmology office.
87
98
  ```
88
99
 
89
- The generated `AGENTS.md`, `AGENTKIT.md`, and `CLAUDE.md` tell the coding agent which files to edit and which verification commands to run.
100
+ The generated `AGENTS.md`, `AGENTKIT.md`, `CLAUDE.md`, and `skills/` pack tell the coding agent which files to edit, which task skill to load, and which verification commands to run. There is no wizard or recipe layer: the coding agent edits the capsule directly from the scaffold, contract, and owner request. The default router is `skills/agentkit-capsule/SKILL.md`; `llms-full.txt` is reserved for complete-contract checks.
101
+
102
+ After the owner gives the general idea, the coding agent should create or update the implementation contract itself:
103
+
104
+ ```sh
105
+ npm run agentkit -- spec init --brief "Develop an appointment and intake agent for an ophthalmology office."
106
+ npm run agentkit -- spec check
107
+ ```
108
+
109
+ `AGENT_SPEC.md` is an internal working contract for the coding agent. It is not a form the owner must fill before work starts.
90
110
 
91
111
  Optional shortcut when copying a prompt into another coding agent:
92
112
 
@@ -137,6 +157,27 @@ Expected chat output:
137
157
  Echo: hello
138
158
  ```
139
159
 
160
+ ## Testing With A UI
161
+
162
+ Local UI:
163
+
164
+ ```sh
165
+ npm run dev
166
+ ```
167
+
168
+ Open the printed `Chat:` URL and tell the owner the exact URL.
169
+
170
+ Hosted deploy UI:
171
+
172
+ ```sh
173
+ npm run agentkit -- deploy
174
+ npm run agentkit -- chat-ui --deploy
175
+ ```
176
+
177
+ Open the printed `Chat:` URL and tell the owner this local UI is connected to the hosted deploy.
178
+
179
+ `test/fake` is deterministic. It validates the scaffold, direct tool checks, and fake-provider evals, but it does not validate natural conversation quality. Before claiming real conversation behavior is tested, ask the owner which provider to use: OpenRouter, OpenAI, Anthropic, or another supported provider.
180
+
140
181
  ## Safety Rules
141
182
 
142
183
  - Do not commit `.env`.
@@ -173,7 +214,7 @@ npm install
173
214
  npm run typecheck
174
215
  ```
175
216
 
176
- Make sure `tsconfig.json` has `moduleResolution: "Bundler"`.
217
+ `agentkit new` installs dependencies by default. Run this if the scaffold was created with `--no-install`, the install failed, or `node_modules` was deleted. Make sure `tsconfig.json` has `moduleResolution: "Bundler"`.
177
218
 
178
219
  `No agentkit.config.ts found`:
179
220
 
@@ -0,0 +1,147 @@
1
+ # Debug A Channel
2
+
3
+ ## Goal
4
+
5
+ Diagnose website, Telegram, WhatsApp, Discord, Slack, or generic webhook channel setup, webhook validation, dedupe, buffering, outbound sends, and delivery failures from the Agent Capsule CLI.
6
+
7
+ ## When To Use It
8
+
9
+ Use this when a hosted channel is not responding, a provider is retrying messages, audio transcription is failing, or delivery status does not match the user's expectation.
10
+
11
+ ## Commands
12
+
13
+ ```sh
14
+ agentkit channels list
15
+ agentkit channels status <name>
16
+ agentkit channels doctor <name>
17
+ agentkit channels test <name> --message "hello"
18
+ agentkit channels test-audio <name> --fixture voice-note
19
+ agentkit transcribe smoke --provider groq
20
+ agentkit channels test <name> --fixture ./fixtures/provider-event.json
21
+ agentkit channels deliveries list <name> --since 24h
22
+ agentkit channels deliveries show <delivery-id>
23
+ agentkit channels buffers list <name>
24
+ agentkit channels buffers show <conversation-id>
25
+ agentkit channels buffers flush <conversation-id>
26
+ agentkit channels buffers clear <conversation-id>
27
+ agentkit channels buffers retry <conversation-id>
28
+ ```
29
+
30
+ ## Files Created Or Edited
31
+
32
+ Debugging should not require source edits. Use fixtures only when reproducing provider payload shape, and never commit provider secrets, full phone numbers, raw audio, or private client data.
33
+
34
+ ## Delivery States
35
+
36
+ ```txt
37
+ received
38
+ validated
39
+ duplicate
40
+ audio_received
41
+ audio_downloaded
42
+ transcribing
43
+ transcribed
44
+ buffered
45
+ queued
46
+ running
47
+ agent_completed
48
+ provider_request_built
49
+ provider_sent
50
+ adapter_stubbed
51
+ delivered
52
+ provider_failed
53
+ failed
54
+ dead_lettered
55
+ skipped
56
+ ```
57
+
58
+ ## Minimal Working Example
59
+
60
+ ```sh
61
+ agentkit channels test support-telegram --message "hello"
62
+ agentkit channels deliveries list support-telegram --since 1h
63
+ agentkit channels deliveries show del_123
64
+ ```
65
+
66
+ Expected `show` output includes signature status, dedupe key, queue/run state, outbound provider request ID when available, and a normalized error envelope.
67
+
68
+ ## Safety Rules
69
+
70
+ - Inspect delivery IDs, hashes, statuses, and redacted metadata rather than raw provider payloads.
71
+ - Never paste provider secrets into fixtures or prompts.
72
+ - Treat `adapter_stubbed` as "no outbound provider call happened", not proof that a client received a message. It can mean explicit dry-run mode or an inbound-only channel such as a generic webhook.
73
+ - Before replaying or flushing buffered conversations, confirm the channel name and conversation ID.
74
+ - Keep local `.env` values ignored and upload hosted production values through AgentKit secret commands.
75
+
76
+ ## Troubleshooting By Error Code
77
+
78
+ `channel_not_found`:
79
+ The webhook URL points to an unknown or deleted channel. Stable hosted URLs use the channel name, for example `/channels/support-whatsapp/whatsapp/zapster/webhook`; old `chn_*` URLs are accepted only for compatibility.
80
+
81
+ `agentkit channels test <name>` is the official synthetic smoke. If it fails while `channels list`, `status`, or `doctor` find the channel, rerun against the current deploy state in `.agentkit/deploy.json`.
82
+
83
+ `channel_disabled`:
84
+ The channel was disabled. Re-add or recreate it.
85
+
86
+ `channel_secret_missing`:
87
+ The hosted secret metadata says a required channel secret is missing. Set it with `agentkit secret set <NAME> --from-local-env` or `agentkit secret sync --from-local`.
88
+
89
+ `channel_signature_invalid`:
90
+ Provider authenticity validation failed. Check the provider webhook secret, token, origin settings, or Discord public key.
91
+
92
+ `channel_payload_invalid`:
93
+ The provider payload is malformed or does not match the route provider.
94
+
95
+ Discord endpoint validation fails in the Developer Portal:
96
+ Confirm `DISCORD_PUBLIC_KEY` is set from the application's public key and the webhook URL is `/channels/<name>/discord/discord/webhook`. AgentKit must validate Discord's signature headers before returning the `PING` PONG.
97
+
98
+ Discord bot does not answer normal server messages:
99
+ Confirm the channel was created with `--mode bot`, `DISCORD_BOT_TOKEN` is set, Message Content Intent is enabled in the Discord Developer Portal, the app is installed into the server, and the bot has `View Channel`, `Read Message History`, and `Send Messages` permissions for the channel.
100
+
101
+ `audio_received`:
102
+ The webhook contained a supported audio message and the channel is entering the audio handling path.
103
+
104
+ `audio_downloaded`:
105
+ The retryable channel worker downloaded the provider media file into memory. The delivery metadata should include only redacted size, MIME, and provider IDs.
106
+
107
+ `transcribing`:
108
+ AgentKit is calling the configured transcription provider with the user's managed transcription secret.
109
+
110
+ `transcribed`:
111
+ Transcription succeeded and the queued agent message contains transcript text instead of raw audio.
112
+
113
+ `channel_event_duplicate` or `duplicate`:
114
+ The provider retried an already-processed event. No second agent run should be created.
115
+
116
+ `buffered`:
117
+ The message is accepted and waiting inside a per-conversation channel buffer. It should move to `queued` after the quiet window, max wait, max message count, or max character count.
118
+
119
+ `adapter_stubbed`:
120
+ The adapter completed without calling an outbound provider. This can happen in explicit dry-run mode or for an inbound-only channel such as a generic webhook.
121
+
122
+ `provider_sent`:
123
+ The provider API accepted the outbound request and returned a provider message ID.
124
+
125
+ `channel_limit_exceeded`:
126
+ Backpressure skipped the message before queueing.
127
+
128
+ `channel_audio_download_unavailable`:
129
+ The channel provider reported audio but did not include enough metadata for AgentKit to download it.
130
+
131
+ `transcription_secret_missing`:
132
+ The transcription provider secret declared in `agentkit inspect` is not set as a managed hosted secret.
133
+
134
+ `transcription_audio_too_large` or `transcription_audio_too_long`:
135
+ The audio exceeded `transcription.limits` or the channel-level `audio.limits`.
136
+
137
+ `transcription_audio_format_unsupported`:
138
+ The configured transcription provider does not accept this audio MIME type or file extension.
139
+
140
+ `transcription_provider_unavailable`:
141
+ The transcription provider returned a retryable error, usually HTTP 429 or a server-side failure.
142
+
143
+ `channel_provider_unavailable`:
144
+ The agent run or provider send path failed with a retryable provider condition.
145
+
146
+ `channel_delivery_dead_lettered`:
147
+ The queue exhausted retries. Inspect the delivery and replay manually only after fixing the cause.