@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.
- package/README.md +69 -0
- package/bin/agentkit.mjs +23 -0
- package/docs/guides/add-channel.md +114 -0
- package/docs/guides/add-knowledge.md +134 -0
- package/docs/guides/add-tool.md +342 -0
- package/docs/guides/agentkit-skills-architecture.md +471 -0
- package/docs/guides/channel-security.md +81 -0
- package/docs/guides/channels-implementation-map.md +243 -0
- package/docs/guides/channels-production-handoff.md +102 -0
- package/docs/guides/connect-telegram.md +110 -0
- package/docs/guides/connect-whatsapp-zapster.md +119 -0
- package/docs/guides/create-agent.md +220 -0
- package/docs/guides/prepare-deploy.md +209 -0
- package/docs/guides/run-evals.md +179 -0
- package/docs/guides/security-rules.md +156 -0
- package/docs/guides/use-provider.md +140 -0
- package/docs/llms-full.txt +876 -0
- package/docs/llms.txt +83 -0
- package/docs/portable-deploy-release-checklist.md +41 -0
- package/package.json +47 -0
- package/src/cli/args.ts +36 -0
- package/src/cli/cloud-client.ts +265 -0
- package/src/cli/commands/channels.ts +810 -0
- package/src/cli/commands/knowledge.ts +136 -0
- package/src/cli/constants.ts +4 -0
- package/src/cli/deploy-chat-ui.ts +392 -0
- package/src/cli/deploy-readiness.ts +348 -0
- package/src/cli/flags.ts +162 -0
- package/src/cli/help.ts +184 -0
- package/src/cli/index.ts +1276 -0
- package/src/cli/process.ts +31 -0
- package/src/cloud/artifact.ts +139 -0
- package/src/cloud/client.ts +79 -0
- package/src/cloud/contracts.ts +63 -0
- package/src/cloud/index.ts +3 -0
- package/src/create-project.ts +177 -0
- package/src/index.ts +408 -0
- package/src/providers/index.ts +25 -0
- package/src/providers/pi.ts +286 -0
- package/src/providers/test.ts +133 -0
- package/src/providers/types.ts +34 -0
- package/src/runtime/build.ts +43 -0
- package/src/runtime/channel-buffer.ts +30 -0
- package/src/runtime/channel-test-harness.ts +112 -0
- package/src/runtime/channels/telegram.ts +360 -0
- package/src/runtime/channels/website.ts +132 -0
- package/src/runtime/channels/whatsapp-meta.ts +71 -0
- package/src/runtime/channels/whatsapp-zapster.ts +278 -0
- package/src/runtime/channels.ts +138 -0
- package/src/runtime/chat.ts +218 -0
- package/src/runtime/config.ts +684 -0
- package/src/runtime/conversations.ts +38 -0
- package/src/runtime/core/deploy-state.ts +54 -0
- package/src/runtime/core/manifest.ts +213 -0
- package/src/runtime/core/targets.ts +133 -0
- package/src/runtime/database.ts +256 -0
- package/src/runtime/db-commands.ts +167 -0
- package/src/runtime/deploy-readiness.ts +105 -0
- package/src/runtime/deploy.ts +1 -0
- package/src/runtime/dev-server.ts +1247 -0
- package/src/runtime/docs.ts +36 -0
- package/src/runtime/env.ts +152 -0
- package/src/runtime/errors.ts +13 -0
- package/src/runtime/evals.ts +509 -0
- package/src/runtime/inspect.ts +203 -0
- package/src/runtime/knowledge/chunk.ts +333 -0
- package/src/runtime/knowledge/config.ts +135 -0
- package/src/runtime/knowledge/embeddings.ts +133 -0
- package/src/runtime/knowledge/ingest.ts +521 -0
- package/src/runtime/knowledge/prompt-policy.ts +30 -0
- package/src/runtime/knowledge/retrieve.ts +283 -0
- package/src/runtime/knowledge/schema.ts +56 -0
- package/src/runtime/knowledge/tool.ts +64 -0
- package/src/runtime/knowledge/vector.ts +258 -0
- package/src/runtime/runtime-contract.ts +93 -0
- package/src/runtime/spec.ts +152 -0
- package/src/runtime/sync.ts +144 -0
- package/src/runtime/targets/cloudflare/build.ts +2517 -0
- package/src/runtime/targets/container/build.ts +146 -0
- package/src/runtime/targets/container/server.ts +33 -0
- package/src/runtime/targets/vps/deploy.ts +206 -0
- package/src/runtime/tool-runner.ts +65 -0
- package/src/runtime/tools.ts +470 -0
- package/src/runtime/traces.ts +41 -0
- package/src/storage/sqlite.ts +1118 -0
- package/src/templates/blank.ts +394 -0
- package/src/templates/dentista.ts +1003 -0
- package/src/templates/index.ts +33 -0
- package/src/templates/skills/agentkit-build-agent/SKILL.md +51 -0
- package/src/templates/skills/agentkit-build-agent/templates/appointment-intake.instructions.md +20 -0
- package/src/templates/skills/agentkit-build-agent/templates/sales-qualifier.instructions.md +17 -0
- package/src/templates/skills/agentkit-build-agent/templates/support-agent.instructions.md +16 -0
- package/src/templates/skills/agentkit-capsule/SKILL.md +62 -0
- package/src/templates/skills/agentkit-capsule/references/docs-router.md +15 -0
- package/src/templates/skills/agentkit-channels/SKILL.md +62 -0
- package/src/templates/skills/agentkit-channels/references/channel-buffering.md +58 -0
- package/src/templates/skills/agentkit-channels/references/channel-debugging.md +41 -0
- package/src/templates/skills/agentkit-channels/references/telegram.md +38 -0
- package/src/templates/skills/agentkit-channels/references/whatsapp-zapster.md +44 -0
- package/src/templates/skills/agentkit-database/SKILL.md +45 -0
- package/src/templates/skills/agentkit-database/templates/appointments.schema.sql +15 -0
- package/src/templates/skills/agentkit-database/templates/leads.schema.sql +17 -0
- package/src/templates/skills/agentkit-deploy/SKILL.md +44 -0
- package/src/templates/skills/agentkit-evals/SKILL.md +60 -0
- package/src/templates/skills/agentkit-evals/templates/multi-turn.eval.md +22 -0
- package/src/templates/skills/agentkit-evals/templates/no-leak.eval.md +14 -0
- package/src/templates/skills/agentkit-evals/templates/smoke.eval.md +14 -0
- package/src/templates/skills/agentkit-evals/templates/tool-call.eval.md +18 -0
- package/src/templates/skills/agentkit-knowledge/SKILL.md +40 -0
- package/src/templates/skills/agentkit-knowledge/templates/faq.md +14 -0
- package/src/templates/skills/agentkit-knowledge/templates/policies.md +14 -0
- package/src/templates/skills/agentkit-knowledge/templates/prices.csv +3 -0
- package/src/templates/skills/agentkit-prompts/SKILL.md +45 -0
- package/src/templates/skills/agentkit-prompts/templates/knowledge-grounded-faq.instructions.md +11 -0
- package/src/templates/skills/agentkit-provider/SKILL.md +57 -0
- package/src/templates/skills/agentkit-security/SKILL.md +55 -0
- package/src/templates/skills/agentkit-tools/SKILL.md +36 -0
- package/src/templates/skills/agentkit-tools/examples/database-write.tool.md +35 -0
- package/src/templates/skills/agentkit-tools/examples/eval-safe-external-action.tool.md +37 -0
- package/src/templates/skills/agentkit-tools/examples/lookup-order.tool.md +46 -0
- package/src/templates/skills/agentkit-troubleshooting/SKILL.md +52 -0
- package/src/templates/support.ts +401 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# Channels Implementation Map
|
|
2
|
+
|
|
3
|
+
Source of truth: [`../../CHANNELS_PRD.md`](../../CHANNELS_PRD.md).
|
|
4
|
+
|
|
5
|
+
Use this map before implementing Channels. It identifies the current AgentKit files that should absorb the Channels contract and the blocker order from `TASKS.md`.
|
|
6
|
+
|
|
7
|
+
## Current State
|
|
8
|
+
|
|
9
|
+
AgentKit already has the hosted deploy spine that Channels should extend:
|
|
10
|
+
|
|
11
|
+
- Public config and exports live in `packages/agentkit/src/index.ts`.
|
|
12
|
+
- Config loading and validation live in `packages/agentkit/src/runtime/config.ts`.
|
|
13
|
+
- `agentkit inspect` state lives in `packages/agentkit/src/runtime/inspect.ts`.
|
|
14
|
+
- Cloudflare artifact generation lives in `packages/agentkit/src/runtime/targets/cloudflare/build.ts`.
|
|
15
|
+
- The CLI command switch lives in `packages/agentkit/src/cli/index.ts`.
|
|
16
|
+
- Local AgentKit Cloud control-plane routes live in `packages/agentkit/src/runtime/deploy.ts`.
|
|
17
|
+
- Local runtime conversation storage lives in `packages/agentkit/src/storage/sqlite.ts`.
|
|
18
|
+
|
|
19
|
+
Channels should not start inside provider-specific code. The obvious implementation path is contract-first, fixture-first, then hosted ingress.
|
|
20
|
+
|
|
21
|
+
## First Files To Edit
|
|
22
|
+
|
|
23
|
+
### Config Contract
|
|
24
|
+
|
|
25
|
+
Edit `packages/agentkit/src/index.ts` first.
|
|
26
|
+
|
|
27
|
+
Add:
|
|
28
|
+
|
|
29
|
+
- `AgentChannel`;
|
|
30
|
+
- `WebsiteChannelConfig`;
|
|
31
|
+
- `TelegramChannelConfig`;
|
|
32
|
+
- `WhatsappChannelConfig`;
|
|
33
|
+
- `ChannelType`;
|
|
34
|
+
- `ChannelProvider`;
|
|
35
|
+
- `websiteChannel(...)`;
|
|
36
|
+
- `telegramChannel(...)`;
|
|
37
|
+
- `whatsappChannel(...)`;
|
|
38
|
+
- optional `channels?: AgentChannel[]` on `AgentConfig`.
|
|
39
|
+
|
|
40
|
+
Reason: generated capsules import public helpers from `@andreprado/agentkit`, so the public contract must exist before config validation, templates, docs, or CLI commands can rely on it.
|
|
41
|
+
|
|
42
|
+
### Config Validation
|
|
43
|
+
|
|
44
|
+
Edit `packages/agentkit/src/runtime/config.ts` after the public types exist.
|
|
45
|
+
|
|
46
|
+
Add validation for:
|
|
47
|
+
|
|
48
|
+
- lowercase stable channel names;
|
|
49
|
+
- unique names within a capsule;
|
|
50
|
+
- supported type/provider combinations;
|
|
51
|
+
- required channel secret name arrays;
|
|
52
|
+
- `runtime: "edge"` when channels are configured for hosted use;
|
|
53
|
+
- no secret values in channel config.
|
|
54
|
+
|
|
55
|
+
Tests belong in `packages/agentkit/src/runtime/config.test.ts`.
|
|
56
|
+
|
|
57
|
+
### Inspect State
|
|
58
|
+
|
|
59
|
+
Edit `packages/agentkit/src/runtime/inspect.ts` after validation.
|
|
60
|
+
|
|
61
|
+
Add:
|
|
62
|
+
|
|
63
|
+
- channel summaries;
|
|
64
|
+
- channel required secrets merged into the existing `secrets` status map;
|
|
65
|
+
- no provider API values or webhook secret values.
|
|
66
|
+
|
|
67
|
+
Tests belong in `packages/agentkit/src/runtime/config.test.ts` or a new focused inspect test if the file grows too large.
|
|
68
|
+
|
|
69
|
+
### Build Manifest
|
|
70
|
+
|
|
71
|
+
Edit `packages/agentkit/src/runtime/targets/cloudflare/build.ts` after inspect.
|
|
72
|
+
|
|
73
|
+
Add channels to:
|
|
74
|
+
|
|
75
|
+
- `AgentManifest`;
|
|
76
|
+
- `buildManifest(...)`;
|
|
77
|
+
- generated Worker manifest JSON;
|
|
78
|
+
- warning text if a channel needs hosted bindings that the current artifact cannot run yet.
|
|
79
|
+
|
|
80
|
+
The generated Worker should not perform real channel processing until ingress/queue tasks land, but the manifest must carry enough metadata for the control plane to create resources.
|
|
81
|
+
|
|
82
|
+
Tests belong in `packages/agentkit/src/runtime/build.test.ts`.
|
|
83
|
+
|
|
84
|
+
## New Runtime Modules
|
|
85
|
+
|
|
86
|
+
Add `packages/agentkit/src/runtime/channels.ts` for normalized types and registry-level helpers.
|
|
87
|
+
|
|
88
|
+
It should own:
|
|
89
|
+
|
|
90
|
+
- `RawWebhookEvent`;
|
|
91
|
+
- `NormalizedChannelEvent`;
|
|
92
|
+
- `NormalizedChannelMessage`;
|
|
93
|
+
- `ChannelAdapter`;
|
|
94
|
+
- `ChannelSendInput`;
|
|
95
|
+
- `ChannelSendResult`;
|
|
96
|
+
- `WebhookVerificationInput`;
|
|
97
|
+
- `WebhookVerificationResult`;
|
|
98
|
+
- `ChannelStatusInput`;
|
|
99
|
+
- `ChannelStatusResult`;
|
|
100
|
+
- adapter lookup by channel type/provider;
|
|
101
|
+
- shared secret redaction helpers if they are not already generic.
|
|
102
|
+
|
|
103
|
+
Add adapter modules under `packages/agentkit/src/runtime/channels/`:
|
|
104
|
+
|
|
105
|
+
- `website.ts`;
|
|
106
|
+
- `telegram.ts`;
|
|
107
|
+
- `whatsapp-zapster.ts`;
|
|
108
|
+
- `whatsapp-meta.ts` as a compatibility stub.
|
|
109
|
+
|
|
110
|
+
Add fixtures under `packages/agentkit/src/runtime/fixtures/channels/`:
|
|
111
|
+
|
|
112
|
+
- `website-message.json`;
|
|
113
|
+
- `telegram-message.json`;
|
|
114
|
+
- `telegram-unsupported-update.json`;
|
|
115
|
+
- `zapster-message.json`;
|
|
116
|
+
- `zapster-unsupported-media.json`;
|
|
117
|
+
- duplicate-event variants where useful.
|
|
118
|
+
|
|
119
|
+
Default tests must use these fixtures and fake fetchers only.
|
|
120
|
+
|
|
121
|
+
## CLI Entry Points
|
|
122
|
+
|
|
123
|
+
Edit `packages/agentkit/src/cli/index.ts` only after config/build/control-plane basics exist.
|
|
124
|
+
|
|
125
|
+
Add a `channels` command with subcommands:
|
|
126
|
+
|
|
127
|
+
- `list`;
|
|
128
|
+
- `add`;
|
|
129
|
+
- `setup`;
|
|
130
|
+
- `status`;
|
|
131
|
+
- `test`;
|
|
132
|
+
- `deliveries list`;
|
|
133
|
+
- `deliveries show`.
|
|
134
|
+
|
|
135
|
+
Keep command behavior split:
|
|
136
|
+
|
|
137
|
+
- Before deploy: read local capsule config and explain missing deploy/setup state.
|
|
138
|
+
- After deploy: read `.agentkit/deploy.json` and call the AgentKit Cloud API.
|
|
139
|
+
|
|
140
|
+
Do not make the CLI mutate real Telegram/Zapster settings in default tests. Provider mutations need explicit credentials and opt-in smoke gates.
|
|
141
|
+
|
|
142
|
+
## Control Plane
|
|
143
|
+
|
|
144
|
+
Edit `packages/agentkit/src/runtime/deploy.ts` after manifest and CLI contracts are clear.
|
|
145
|
+
|
|
146
|
+
Current control-plane API only serves:
|
|
147
|
+
|
|
148
|
+
- `GET /health`;
|
|
149
|
+
- `POST /v1/deploys`.
|
|
150
|
+
|
|
151
|
+
Add:
|
|
152
|
+
|
|
153
|
+
- `POST /v1/deploys/{deploy_id}/channels`;
|
|
154
|
+
- `GET /v1/deploys/{deploy_id}/channels`;
|
|
155
|
+
- `GET /v1/channels/{channel_id}`;
|
|
156
|
+
- `DELETE /v1/channels/{channel_id}`;
|
|
157
|
+
- public webhook routes for `/channels/{channel_id}/{type}/{provider}/webhook`;
|
|
158
|
+
- delivery inspection routes for CLI use.
|
|
159
|
+
|
|
160
|
+
The local `npm run agentkit:operator -- serve` path can use an in-memory or local SQLite fake store first. Production Postgres support can follow once the contract is tested. In both stores, persist only secret names and statuses, never secret values.
|
|
161
|
+
|
|
162
|
+
## Hosted Worker And Cloudflare Bindings
|
|
163
|
+
|
|
164
|
+
Edit `packages/agentkit/src/runtime/targets/cloudflare/build.ts` when adding real hosted ingress.
|
|
165
|
+
|
|
166
|
+
The Worker currently handles:
|
|
167
|
+
|
|
168
|
+
- `GET /_agentkit`;
|
|
169
|
+
- `GET /`;
|
|
170
|
+
- `POST /chat`;
|
|
171
|
+
- Turso health/query helpers;
|
|
172
|
+
- R2 file routes.
|
|
173
|
+
|
|
174
|
+
Channels will need:
|
|
175
|
+
|
|
176
|
+
- a channel ingress route;
|
|
177
|
+
- raw body preservation for verification;
|
|
178
|
+
- a channel coordination Durable Object for dedupe and identity mapping;
|
|
179
|
+
- Cloudflare Queue producer and consumer bindings;
|
|
180
|
+
- delivery state persistence or calls back to AgentKit Cloud;
|
|
181
|
+
- redaction-aware logs.
|
|
182
|
+
|
|
183
|
+
Do not put AgentKit channel plumbing in the user's Turso database. Turso remains only for the user's agent application tables.
|
|
184
|
+
|
|
185
|
+
## Storage Boundary Decision
|
|
186
|
+
|
|
187
|
+
For local tests, use the AgentKit Cloud fake/control-plane store for channel resource metadata and delivery records.
|
|
188
|
+
|
|
189
|
+
Use this boundary for V1 local cloud tests:
|
|
190
|
+
|
|
191
|
+
| Record | Local `npm run agentkit:operator -- serve` store | Generated Worker / Durable Object / Queue contract |
|
|
192
|
+
| --- | --- | --- |
|
|
193
|
+
| Channel resource metadata | Yes: `channels` table or equivalent fake store keyed by `chn_...`. | Read-only manifest input after deploy. |
|
|
194
|
+
| Channel secret references | Yes: names and `set`/`missing` status only. | Runtime receives injected secret values by name; no readback. |
|
|
195
|
+
| Channel endpoint URL | Yes: generated from deploy URL plus stable channel ID. | Worker routes requests by channel ID, type, and provider. |
|
|
196
|
+
| Channel delivery records | Yes: `deliveries` table keyed by `del_...` for CLI inspection. | Worker/consumer reports state transitions back to control plane or durable storage. |
|
|
197
|
+
| Channel event audit records | Yes: compact event records keyed by `chevt_...`, with redacted provider metadata. | Ingress creates or reports event records after provider validation. |
|
|
198
|
+
| External identity mappings | Fake DO-compatible store for local tests, keyed by `chid_...`. | Durable Object owns strongly consistent identity to conversation mapping. |
|
|
199
|
+
| Dedupe keys | Fake DO-compatible store with default 14-day retention. | Durable Object owns deterministic dedupe keys and retention. |
|
|
200
|
+
| Per-conversation ordering/backpressure | Fake DO-compatible store only when tests need it. | Durable Object owns locks and short-lived backpressure state. |
|
|
201
|
+
| Queue payloads | In-memory fake queue drained by tests. | Cloudflare Queue owns async ingress to consumer handoff. |
|
|
202
|
+
| Raw payload/media blobs | Do not persist by default in local tests; use fixtures. | R2 stores large raw payloads, media, exports, and debug bundles. |
|
|
203
|
+
| User application data | Never. | Never. User application tables stay in Turso. |
|
|
204
|
+
|
|
205
|
+
Use Durable Object-compatible abstractions for:
|
|
206
|
+
|
|
207
|
+
- dedupe keys;
|
|
208
|
+
- external identity to conversation ID mappings;
|
|
209
|
+
- ordering/backpressure state.
|
|
210
|
+
|
|
211
|
+
This keeps the implementation aligned with the production architecture while allowing deterministic tests without real Cloudflare bindings.
|
|
212
|
+
|
|
213
|
+
The first implementation should prefer an in-memory fake store for tests unless persistence across local control-plane restarts is being tested. Production Postgres can mirror the same resource/delivery tables later, after API behavior is stable.
|
|
214
|
+
|
|
215
|
+
## Implementation Order
|
|
216
|
+
|
|
217
|
+
Start with the unblocked tasks from `TASKS.md`:
|
|
218
|
+
|
|
219
|
+
1. CH-01: decide the final local fake store shape.
|
|
220
|
+
2. CH-02: add public channel config helpers.
|
|
221
|
+
3. CH-03: validate `channels` config.
|
|
222
|
+
4. CH-04: include channels in inspect/build manifests.
|
|
223
|
+
5. CH-05 and CH-06: add normalized runtime types and fixture-first adapter tests.
|
|
224
|
+
|
|
225
|
+
Do not begin channel CRUD or ingress until CH-04 exists. The control plane needs channel metadata in the build manifest, otherwise hosted resources are disconnected from the deploy artifact.
|
|
226
|
+
|
|
227
|
+
## Test Strategy
|
|
228
|
+
|
|
229
|
+
Default verification should stay offline:
|
|
230
|
+
|
|
231
|
+
```sh
|
|
232
|
+
bun test
|
|
233
|
+
npm run typecheck
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Provider tests should be opt-in:
|
|
237
|
+
|
|
238
|
+
```sh
|
|
239
|
+
AGENTKIT_RUN_TELEGRAM_CHANNEL_TESTS=1 bun test
|
|
240
|
+
AGENTKIT_RUN_ZAPSTER_CHANNEL_TESTS=1 bun test
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Real-provider smoke tests must document required secret names and must never print secret values.
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# Channels Production Handoff
|
|
2
|
+
|
|
3
|
+
## Goal
|
|
4
|
+
|
|
5
|
+
Move Channels from local fake control-plane tests to production safely.
|
|
6
|
+
|
|
7
|
+
## Deployment Order
|
|
8
|
+
|
|
9
|
+
1. Build and typecheck:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm run typecheck
|
|
13
|
+
bun test
|
|
14
|
+
agentkit build --target cloudflare
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
2. Deploy AgentKit Cloud/control plane with:
|
|
18
|
+
|
|
19
|
+
```txt
|
|
20
|
+
Cloudflare Worker
|
|
21
|
+
Cloudflare Queue for channel jobs
|
|
22
|
+
Durable Object namespace for channel coordination
|
|
23
|
+
R2 bucket for large/raw payload handoff when enabled
|
|
24
|
+
Turso/Postgres control-plane tables for deploys, channels, deliveries, events, and identities
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
3. Set managed secrets:
|
|
28
|
+
|
|
29
|
+
```txt
|
|
30
|
+
OPENAI_API_KEY or another model provider key
|
|
31
|
+
TELEGRAM_BOT_TOKEN
|
|
32
|
+
TELEGRAM_WEBHOOK_SECRET
|
|
33
|
+
ZAPSTER_API_KEY
|
|
34
|
+
ZAPSTER_INSTANCE_ID
|
|
35
|
+
ZAPSTER_WEBHOOK_ID
|
|
36
|
+
META_WHATSAPP_ACCESS_TOKEN
|
|
37
|
+
META_WHATSAPP_APP_SECRET
|
|
38
|
+
META_WHATSAPP_VERIFY_TOKEN
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
4. Create channels:
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
agentkit channels add telegram support-telegram
|
|
45
|
+
agentkit channels add whatsapp support-whatsapp --provider zapster
|
|
46
|
+
agentkit channels setup support-telegram --apply
|
|
47
|
+
agentkit channels setup support-whatsapp
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
5. Run smoke checks:
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
agentkit channels status support-telegram
|
|
54
|
+
agentkit channels test support-telegram --message "hello"
|
|
55
|
+
agentkit channels status support-whatsapp
|
|
56
|
+
agentkit channels test support-whatsapp --message "hello"
|
|
57
|
+
agentkit channels deliveries list support-telegram --since 1h
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Local Fake Versus Real Provider Gates
|
|
61
|
+
|
|
62
|
+
Default tests are offline and must pass without provider credentials:
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
bun test
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Real-provider smoke tests are opt-in:
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
AGENTKIT_RUN_TELEGRAM_CHANNEL_TESTS=1 bun test
|
|
72
|
+
AGENTKIT_RUN_ZAPSTER_CHANNEL_TESTS=1 bun test
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Telegram smoke requires `TELEGRAM_BOT_TOKEN`, `TELEGRAM_WEBHOOK_SECRET`, and `AGENTKIT_TELEGRAM_WEBHOOK_URL`.
|
|
76
|
+
|
|
77
|
+
Zapster smoke requires `ZAPSTER_API_KEY`, `AGENTKIT_ZAPSTER_SEND_URL`, and `AGENTKIT_ZAPSTER_TO`.
|
|
78
|
+
|
|
79
|
+
## Smoke Checks
|
|
80
|
+
|
|
81
|
+
- Unknown channel ID returns `404` and creates no tenant record.
|
|
82
|
+
- Invalid Telegram signature or Zapster origin headers return `401` and create a failed delivery.
|
|
83
|
+
- Duplicate provider event returns `200` with `duplicate` and creates no second queue job.
|
|
84
|
+
- Accepted inbound text creates one queue job and one outbound delivery.
|
|
85
|
+
- Buffered inbound bursts stay in `buffered` state, then flush into one queue job and one outbound delivery.
|
|
86
|
+
- Retryable failures dead-letter after the configured retry ceiling.
|
|
87
|
+
- `channel_limit_exceeded` does not create queue backlog.
|
|
88
|
+
|
|
89
|
+
## Rollback
|
|
90
|
+
|
|
91
|
+
- Disable the channel resource first; do not delete delivery history.
|
|
92
|
+
- Remove provider webhook registration if the provider keeps retrying.
|
|
93
|
+
- Roll back the Worker only after queue drain or pause.
|
|
94
|
+
- Keep managed secrets; rotate only if a secret may have leaked.
|
|
95
|
+
|
|
96
|
+
## Production Defaults
|
|
97
|
+
|
|
98
|
+
- Start with conservative per-channel daily message and cost limits.
|
|
99
|
+
- For WhatsApp and Telegram agents that receive rapid client message bursts, start with `buffer.mode: "debounce"`, `quietWindowMs` between `1500` and `2500`, `maxWaitMs` between `8000` and `12000`, and strict `maxMessages`/`maxChars`.
|
|
100
|
+
- Keep raw body storage disabled unless there is an explicit encrypted R2 retention policy.
|
|
101
|
+
- Delivery APIs return hashes and redacted metadata, not payload bodies.
|
|
102
|
+
- Turso remains reserved for the user's agent application data, not AgentKit channel plumbing.
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Connect Telegram
|
|
2
|
+
|
|
3
|
+
## Goal
|
|
4
|
+
|
|
5
|
+
Connect a Telegram bot to a hosted AgentKit channel with a stable AgentKit webhook URL.
|
|
6
|
+
|
|
7
|
+
## When To Use It
|
|
8
|
+
|
|
9
|
+
Use this after `telegramChannel({ name: "support-telegram" })` exists in `agentkit.config.ts` and the capsule has been deployed.
|
|
10
|
+
|
|
11
|
+
## Commands
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
agentkit deploy
|
|
15
|
+
agentkit channels add telegram support-telegram
|
|
16
|
+
agentkit channels setup support-telegram
|
|
17
|
+
agentkit channels setup support-telegram --apply
|
|
18
|
+
agentkit channels status support-telegram
|
|
19
|
+
agentkit channels test support-telegram --message "hello"
|
|
20
|
+
agentkit channels deliveries list support-telegram
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Required secrets:
|
|
24
|
+
|
|
25
|
+
```txt
|
|
26
|
+
TELEGRAM_BOT_TOKEN
|
|
27
|
+
TELEGRAM_WEBHOOK_SECRET
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Files Created Or Edited
|
|
31
|
+
|
|
32
|
+
- `agentkit.config.ts`: `telegramChannel({ name: "support-telegram" })`.
|
|
33
|
+
- `.agentkit/deploy.json`: deploy state for resolving the hosted deploy.
|
|
34
|
+
- No local webhook server files.
|
|
35
|
+
|
|
36
|
+
## Minimal Working Example
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { defineAgent, telegramChannel } from "@andreprado/agentkit";
|
|
40
|
+
|
|
41
|
+
export default defineAgent({
|
|
42
|
+
name: "support-agent",
|
|
43
|
+
runtime: "edge",
|
|
44
|
+
provider: { name: "test", model: "fake" },
|
|
45
|
+
instructions: "./prompts/instructions.md",
|
|
46
|
+
secrets: [],
|
|
47
|
+
tools: [],
|
|
48
|
+
channels: [telegramChannel({ name: "support-telegram" })],
|
|
49
|
+
access: { mode: "public" },
|
|
50
|
+
storage: { driver: "agentkit" },
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
To answer once after a burst of Telegram messages, enable channel buffering:
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
telegramChannel({
|
|
58
|
+
name: "support-telegram",
|
|
59
|
+
buffer: {
|
|
60
|
+
mode: "debounce",
|
|
61
|
+
quietWindowMs: 1500,
|
|
62
|
+
maxWaitMs: 8000,
|
|
63
|
+
maxMessages: 20,
|
|
64
|
+
maxChars: 8000,
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Setup Behavior
|
|
70
|
+
|
|
71
|
+
`agentkit channels setup support-telegram` is read-only and prints the webhook URL.
|
|
72
|
+
|
|
73
|
+
`agentkit channels setup support-telegram --apply` calls Telegram `setWebhook` with:
|
|
74
|
+
|
|
75
|
+
- `url`: the AgentKit webhook URL;
|
|
76
|
+
- `secret_token`: `TELEGRAM_WEBHOOK_SECRET`;
|
|
77
|
+
- `allowed_updates`: `["message"]`.
|
|
78
|
+
|
|
79
|
+
Against AgentKit Cloud, `--apply` runs through the Cloud API and uses managed hosted secrets. The legacy local fallback only uses `TELEGRAM_BOT_TOKEN` and `TELEGRAM_WEBHOOK_SECRET` from the shell when the Cloud API does not expose channel setup.
|
|
80
|
+
|
|
81
|
+
## Safety Rules
|
|
82
|
+
|
|
83
|
+
- Use `--apply` only when real Telegram secrets are present.
|
|
84
|
+
- Do not paste the bot token into code, docs, test fixtures, or delivery logs.
|
|
85
|
+
- Telegram webhook validation uses `X-Telegram-Bot-Api-Secret-Token`.
|
|
86
|
+
|
|
87
|
+
## Verification
|
|
88
|
+
|
|
89
|
+
```sh
|
|
90
|
+
agentkit channels status support-telegram
|
|
91
|
+
agentkit channels test support-telegram --message "hello"
|
|
92
|
+
agentkit channels deliveries show <delivery-id>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Expected webhook URL shape:
|
|
96
|
+
|
|
97
|
+
```txt
|
|
98
|
+
https://<deploy-host>/channels/chn_<id>/telegram/webhook
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Troubleshooting
|
|
102
|
+
|
|
103
|
+
`TELEGRAM_BOT_TOKEN and TELEGRAM_WEBHOOK_SECRET must be set`:
|
|
104
|
+
Set both secrets before using `--apply`.
|
|
105
|
+
|
|
106
|
+
`channel_signature_invalid`:
|
|
107
|
+
The incoming Telegram secret token does not match `TELEGRAM_WEBHOOK_SECRET`.
|
|
108
|
+
|
|
109
|
+
`channel_payload_invalid`:
|
|
110
|
+
The update is malformed or is not a supported private text message.
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Connect WhatsApp Through Zapster
|
|
2
|
+
|
|
3
|
+
## Goal
|
|
4
|
+
|
|
5
|
+
Connect a Zapster WhatsApp account to a hosted AgentKit WhatsApp channel.
|
|
6
|
+
|
|
7
|
+
## When To Use It
|
|
8
|
+
|
|
9
|
+
Use this after `whatsappChannel({ name: "support-whatsapp", provider: "zapster" })` exists in `agentkit.config.ts` and the capsule has been deployed.
|
|
10
|
+
|
|
11
|
+
## Commands
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
agentkit deploy
|
|
15
|
+
agentkit channels add whatsapp support-whatsapp --provider zapster
|
|
16
|
+
agentkit channels setup support-whatsapp
|
|
17
|
+
agentkit channels status support-whatsapp
|
|
18
|
+
agentkit channels test support-whatsapp --message "hello"
|
|
19
|
+
agentkit channels deliveries list support-whatsapp --since 24h
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Required secrets:
|
|
23
|
+
|
|
24
|
+
```txt
|
|
25
|
+
ZAPSTER_API_KEY
|
|
26
|
+
ZAPSTER_INSTANCE_ID
|
|
27
|
+
ZAPSTER_WEBHOOK_ID
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Optional hardening secret:
|
|
31
|
+
|
|
32
|
+
```txt
|
|
33
|
+
ZAPSTER_WEBHOOK_TOKEN
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Files Created Or Edited
|
|
37
|
+
|
|
38
|
+
- `agentkit.config.ts`: `whatsappChannel({ name: "support-whatsapp", provider: "zapster" })`.
|
|
39
|
+
- `.agentkit/deploy.json`: deploy state for resolving the hosted deploy.
|
|
40
|
+
- No user-managed webhook server.
|
|
41
|
+
|
|
42
|
+
## Minimal Working Example
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { defineAgent, whatsappChannel } from "@andreprado/agentkit";
|
|
46
|
+
|
|
47
|
+
export default defineAgent({
|
|
48
|
+
name: "support-agent",
|
|
49
|
+
runtime: "edge",
|
|
50
|
+
provider: { name: "test", model: "fake" },
|
|
51
|
+
instructions: "./prompts/instructions.md",
|
|
52
|
+
secrets: [],
|
|
53
|
+
tools: [],
|
|
54
|
+
channels: [whatsappChannel({ name: "support-whatsapp", provider: "zapster" })],
|
|
55
|
+
access: { mode: "public" },
|
|
56
|
+
storage: { driver: "agentkit" },
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
To handle clients who send several WhatsApp messages before waiting, enable channel buffering:
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
whatsappChannel({
|
|
64
|
+
name: "support-whatsapp",
|
|
65
|
+
provider: "zapster",
|
|
66
|
+
buffer: {
|
|
67
|
+
mode: "debounce",
|
|
68
|
+
quietWindowMs: 2500,
|
|
69
|
+
maxWaitMs: 12000,
|
|
70
|
+
maxMessages: 20,
|
|
71
|
+
maxChars: 8000,
|
|
72
|
+
},
|
|
73
|
+
})
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Setup Behavior
|
|
77
|
+
|
|
78
|
+
`agentkit channels setup support-whatsapp` prints the stable AgentKit webhook URL. Paste it into Zapster webhook settings.
|
|
79
|
+
|
|
80
|
+
Expected webhook URL shape:
|
|
81
|
+
|
|
82
|
+
```txt
|
|
83
|
+
https://<deploy-host>/channels/chn_<id>/whatsapp/zapster/webhook
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
If the channel declares `ZAPSTER_WEBHOOK_TOKEN`, register the Zapster URL with the token as a query parameter:
|
|
87
|
+
|
|
88
|
+
```txt
|
|
89
|
+
https://<deploy-host>/channels/chn_<id>/whatsapp/zapster/webhook?token=<ZAPSTER_WEBHOOK_TOKEN>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Safety Rules
|
|
93
|
+
|
|
94
|
+
- Keep phone numbers redacted in logs by default.
|
|
95
|
+
- Do not store Zapster API keys in `agentkit.config.ts`.
|
|
96
|
+
- Inbound validation uses Zapster's `X-Instance-ID`, `X-Webhook-ID`, `X-Message-ID`, `X-Attempt-Count`, and `User-Agent: Zapsterapi/...` headers.
|
|
97
|
+
- Zapster webhook headers are origin validation, not a cryptographic body signature.
|
|
98
|
+
- Use optional `ZAPSTER_WEBHOOK_TOKEN` in the webhook URL when the endpoint should require an extra secret known only to AgentKit and Zapster.
|
|
99
|
+
- Unsupported media should be logged as skipped/unsupported without creating an agent run.
|
|
100
|
+
|
|
101
|
+
## Verification
|
|
102
|
+
|
|
103
|
+
```sh
|
|
104
|
+
agentkit channels status support-whatsapp
|
|
105
|
+
agentkit channels test support-whatsapp --message "hello"
|
|
106
|
+
agentkit channels deliveries list support-whatsapp
|
|
107
|
+
agentkit channels deliveries show <delivery-id>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Troubleshooting
|
|
111
|
+
|
|
112
|
+
`channel_secret_missing`:
|
|
113
|
+
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.
|
|
114
|
+
|
|
115
|
+
`channel_signature_invalid`:
|
|
116
|
+
Zapster is not sending the expected instance/webhook IDs, or the optional query token does not match.
|
|
117
|
+
|
|
118
|
+
`channel_unsupported_message_type` or skipped delivery:
|
|
119
|
+
The inbound WhatsApp event was not supported text. Inspect the delivery record for provider metadata.
|