@andreprado/agentkit 0.1.0-alpha.15 → 0.1.0-alpha.16
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/docs/guides/add-channel.md +63 -0
- package/docs/guides/channel-security.md +32 -0
- package/docs/guides/connect-telegram.md +58 -0
- package/docs/guides/connect-whatsapp-zapster.md +65 -0
- package/package.json +1 -1
- package/src/cli/commands/channels.ts +2 -0
- package/src/index.ts +86 -0
- package/src/runtime/channel-test-harness.ts +2 -0
- package/src/runtime/channels/telegram.ts +326 -10
- package/src/runtime/channels/whatsapp-zapster.ts +319 -0
- package/src/runtime/channels.ts +47 -1
- package/src/runtime/config.ts +85 -4
- package/src/runtime/core/manifest.ts +32 -0
- package/src/runtime/dev-server.ts +72 -4
- package/src/runtime/inspect.ts +34 -0
- package/src/runtime/targets/cloudflare/build.ts +2 -0
- package/src/runtime/transcription.ts +483 -0
- package/src/templates/skills/agentkit-channels/SKILL.md +34 -1
- package/src/templates/skills/agentkit-channels/references/channel-debugging.md +13 -0
- package/src/templates/skills/agentkit-channels/references/telegram.md +32 -0
- package/src/templates/skills/agentkit-channels/references/whatsapp-zapster.md +29 -0
|
@@ -87,6 +87,62 @@ agentkit channels buffers clear support-whatsapp <conversation-id>
|
|
|
87
87
|
agentkit channels buffers retry support-whatsapp <conversation-id>
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
+
## Auto Transcribe Audio
|
|
91
|
+
|
|
92
|
+
Use `transcription` at the agent level and `audio.mode: "transcribe"` on each channel that should accept voice notes or audio files.
|
|
93
|
+
|
|
94
|
+
```ts
|
|
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: "groq",
|
|
102
|
+
model: "whisper-large-v3-turbo",
|
|
103
|
+
secret: "GROQ_API_KEY",
|
|
104
|
+
language: "pt",
|
|
105
|
+
limits: {
|
|
106
|
+
maxDurationSeconds: 180,
|
|
107
|
+
maxBytes: 20_000_000,
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
channels: [
|
|
111
|
+
telegramChannel({
|
|
112
|
+
name: "support-telegram",
|
|
113
|
+
audio: { mode: "transcribe" },
|
|
114
|
+
}),
|
|
115
|
+
whatsappChannel({
|
|
116
|
+
name: "support-whatsapp",
|
|
117
|
+
provider: "zapster",
|
|
118
|
+
audio: { mode: "transcribe" },
|
|
119
|
+
}),
|
|
120
|
+
],
|
|
121
|
+
access: { mode: "public" },
|
|
122
|
+
storage: { driver: "agentkit" },
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Supported transcription providers in V1:
|
|
127
|
+
|
|
128
|
+
| Provider | Default secret | Supported models |
|
|
129
|
+
| --- | --- | --- |
|
|
130
|
+
| `openai` | `OPENAI_API_KEY` | `gpt-4o-mini-transcribe`, `gpt-4o-transcribe`, `whisper-1` |
|
|
131
|
+
| `groq` | `GROQ_API_KEY` | `whisper-large-v3-turbo`, `whisper-large-v3`, `distil-whisper-large-v3-en` |
|
|
132
|
+
|
|
133
|
+
Audio transcription is paid by the capsule owner because AgentKit only passes through the configured provider secret. Hosted channel creation automatically requires the transcription secret when a channel enables `audio.mode: "transcribe"`.
|
|
134
|
+
|
|
135
|
+
Processing order:
|
|
136
|
+
|
|
137
|
+
1. Provider webhook is validated and deduped.
|
|
138
|
+
2. Channel adapter normalizes the audio metadata.
|
|
139
|
+
3. AgentKit records `audio_received` and enqueues a channel job before acknowledging the webhook.
|
|
140
|
+
4. The retryable channel worker downloads the audio using the channel provider secret.
|
|
141
|
+
5. The transcription adapter sends the file to the configured transcription provider.
|
|
142
|
+
6. The agent receives a text message containing the transcript.
|
|
143
|
+
|
|
144
|
+
V1 keeps the raw audio in memory for the request path and delivery metadata only records redacted status/error fields. `rawAudioTtlSeconds` is part of the manifest contract for future object-storage retention, but V1 does not persist raw audio by default.
|
|
145
|
+
|
|
90
146
|
## Safety Rules
|
|
91
147
|
|
|
92
148
|
- Never put provider token values in `agentkit.config.ts`.
|
|
@@ -94,6 +150,7 @@ agentkit channels buffers retry support-whatsapp <conversation-id>
|
|
|
94
150
|
- Treat channel webhook URLs as public transport endpoints. Provider validation or the AgentKit website channel token controls authenticity.
|
|
95
151
|
- Keep channels separate from tools. Channels deliver user messages; tools let the agent call external systems.
|
|
96
152
|
- Keep `maxMessages` and `maxChars` bounded so one burst cannot create an oversized prompt or unexpected model spend.
|
|
153
|
+
- Keep `audio.limits` bounded so one voice note cannot create unexpected transcription spend.
|
|
97
154
|
|
|
98
155
|
## Verification
|
|
99
156
|
|
|
@@ -124,4 +181,10 @@ The provider webhook secret, token, or origin header does not match the managed
|
|
|
124
181
|
`channel_limit_exceeded`:
|
|
125
182
|
The channel daily message limit was reached. Website requests return `429`; Telegram and WhatsApp are acknowledged and skipped to avoid provider retry storms.
|
|
126
183
|
|
|
184
|
+
`transcription_secret_missing`:
|
|
185
|
+
Set the managed transcription secret declared by `agentkit inspect`, for example `OPENAI_API_KEY` or `GROQ_API_KEY`.
|
|
186
|
+
|
|
187
|
+
`transcription_audio_format_unsupported`:
|
|
188
|
+
The channel delivered an audio format the configured transcription provider does not accept. Telegram voice notes are OGG/Opus and work with Groq in V1; OpenAI accepts MP3, MP4, MPEG, MPGA, M4A, WAV, and WEBM in the AgentKit adapter.
|
|
189
|
+
|
|
127
190
|
Buffered messages stay in `buffered` delivery state until the quiet window or max wait flushes them into one queued run.
|
|
@@ -15,6 +15,7 @@ agentkit inspect
|
|
|
15
15
|
agentkit channels status <name>
|
|
16
16
|
agentkit channels deliveries show <delivery-id>
|
|
17
17
|
bun test packages/agentkit/src/runtime/channels/adapters.test.ts
|
|
18
|
+
bun test packages/agentkit/src/runtime/transcription.test.ts
|
|
18
19
|
bun test packages/agentkit/src/runtime/deploy.test.ts
|
|
19
20
|
```
|
|
20
21
|
|
|
@@ -41,9 +42,12 @@ Zapster smoke also requires `ZAPSTER_API_KEY`, `ZAPSTER_INSTANCE_ID`, and `AGENT
|
|
|
41
42
|
- Validate provider authenticity when the provider supports it.
|
|
42
43
|
- Do not store channel plumbing in the user's Turso database.
|
|
43
44
|
- Do not store raw webhook bodies in delivery records; store a SHA-256 hash.
|
|
45
|
+
- Do not store raw audio in delivery records. V1 audio transcription downloads provider media into memory and stores only redacted metadata and state transitions.
|
|
44
46
|
- Redact bearer tokens, bot tokens, signing secrets, provider API tokens, and phone numbers.
|
|
45
47
|
- Inject only channel-declared secrets into adapter code.
|
|
48
|
+
- Inject transcription secrets only when the deploy manifest declares transcription and the channel uses `audio.mode: "transcribe"`.
|
|
46
49
|
- Prefer acknowledging Telegram/WhatsApp over retry storms when a channel-level limit is exceeded.
|
|
50
|
+
- Keep audio duration and byte limits bounded before provider calls to avoid uncontrolled transcription spend.
|
|
47
51
|
|
|
48
52
|
## Minimal Working Example
|
|
49
53
|
|
|
@@ -54,17 +58,42 @@ telegramChannel({
|
|
|
54
58
|
});
|
|
55
59
|
```
|
|
56
60
|
|
|
61
|
+
With audio transcription:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
export default defineAgent({
|
|
65
|
+
// ...
|
|
66
|
+
transcription: {
|
|
67
|
+
provider: "groq",
|
|
68
|
+
model: "whisper-large-v3-turbo",
|
|
69
|
+
secret: "GROQ_API_KEY",
|
|
70
|
+
limits: {
|
|
71
|
+
maxDurationSeconds: 180,
|
|
72
|
+
maxBytes: 20_000_000,
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
channels: [
|
|
76
|
+
telegramChannel({
|
|
77
|
+
name: "support-telegram",
|
|
78
|
+
audio: { mode: "transcribe" },
|
|
79
|
+
}),
|
|
80
|
+
],
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
57
84
|
The config contains secret names only. Hosted responses report:
|
|
58
85
|
|
|
59
86
|
```txt
|
|
60
87
|
TELEGRAM_BOT_TOKEN: set
|
|
61
88
|
TELEGRAM_WEBHOOK_SECRET: missing
|
|
89
|
+
GROQ_API_KEY: set
|
|
62
90
|
```
|
|
63
91
|
|
|
64
92
|
## Verification
|
|
65
93
|
|
|
66
94
|
```sh
|
|
67
95
|
bun test packages/agentkit/src/runtime/channels/adapters.test.ts
|
|
96
|
+
bun test packages/agentkit/src/runtime/transcription.test.ts
|
|
68
97
|
bun test packages/agentkit/src/runtime/deploy.test.ts
|
|
69
98
|
npm run typecheck
|
|
70
99
|
```
|
|
@@ -79,3 +108,6 @@ Redact it to a stable partial form such as `5511******9999`.
|
|
|
79
108
|
|
|
80
109
|
Webhook accepts invalid signatures or origin headers:
|
|
81
110
|
Fix `verifyWebhook` for the adapter before enabling provider setup docs.
|
|
111
|
+
|
|
112
|
+
Raw audio or transcript provider secret appears in output:
|
|
113
|
+
Stop and add a regression test before changing behavior. Delivery APIs may include transcript text in normalized agent messages after successful transcription, but must never include raw bytes or provider secret values.
|
|
@@ -27,6 +27,12 @@ TELEGRAM_BOT_TOKEN
|
|
|
27
27
|
TELEGRAM_WEBHOOK_SECRET
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
If Telegram audio transcription is enabled, also set the transcription provider secret declared by `agentkit inspect`, usually:
|
|
31
|
+
|
|
32
|
+
```txt
|
|
33
|
+
GROQ_API_KEY
|
|
34
|
+
```
|
|
35
|
+
|
|
30
36
|
## Files Created Or Edited
|
|
31
37
|
|
|
32
38
|
- `agentkit.config.ts`: `telegramChannel({ name: "support-telegram" })`.
|
|
@@ -66,6 +72,52 @@ telegramChannel({
|
|
|
66
72
|
})
|
|
67
73
|
```
|
|
68
74
|
|
|
75
|
+
## Auto Transcribe Telegram Audio
|
|
76
|
+
|
|
77
|
+
Telegram voice notes arrive as OGG/Opus. In V1, use Groq for the most obvious Telegram voice-note path because the AgentKit Groq adapter accepts `audio/ogg`.
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
import { defineAgent, telegramChannel } from "@andreprado/agentkit";
|
|
81
|
+
|
|
82
|
+
export default defineAgent({
|
|
83
|
+
name: "support-agent",
|
|
84
|
+
runtime: "edge",
|
|
85
|
+
provider: { name: "openai", model: "gpt-5.4-mini" },
|
|
86
|
+
instructions: "./prompts/instructions.md",
|
|
87
|
+
transcription: {
|
|
88
|
+
provider: "groq",
|
|
89
|
+
model: "whisper-large-v3-turbo",
|
|
90
|
+
secret: "GROQ_API_KEY",
|
|
91
|
+
language: "pt",
|
|
92
|
+
limits: {
|
|
93
|
+
maxDurationSeconds: 180,
|
|
94
|
+
maxBytes: 20_000_000,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
channels: [
|
|
98
|
+
telegramChannel({
|
|
99
|
+
name: "support-telegram",
|
|
100
|
+
audio: {
|
|
101
|
+
mode: "transcribe",
|
|
102
|
+
},
|
|
103
|
+
}),
|
|
104
|
+
],
|
|
105
|
+
access: { mode: "public" },
|
|
106
|
+
storage: { driver: "agentkit" },
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Processing order:
|
|
111
|
+
|
|
112
|
+
1. AgentKit validates `X-Telegram-Bot-Api-Secret-Token`.
|
|
113
|
+
2. Telegram `voice` or `audio` payloads become normalized audio messages.
|
|
114
|
+
3. AgentKit records `audio_received` and enqueues a channel job before acknowledging Telegram.
|
|
115
|
+
4. The retryable channel worker calls Telegram `getFile`, downloads the file with `TELEGRAM_BOT_TOKEN`, and does not log the token.
|
|
116
|
+
5. AgentKit sends the audio bytes to the configured transcription provider using the user's managed secret.
|
|
117
|
+
6. The agent run receives a text message with the transcript.
|
|
118
|
+
|
|
119
|
+
OpenAI transcription can be used for Telegram files that arrive as MP3, MP4, MPEG, MPGA, M4A, WAV, or WEBM. Telegram voice notes are usually OGG/Opus, so they should use Groq in V1 unless the provider payload is converted before it reaches AgentKit.
|
|
120
|
+
|
|
69
121
|
## Setup Behavior
|
|
70
122
|
|
|
71
123
|
`agentkit channels setup support-telegram` is read-only and prints the webhook URL.
|
|
@@ -108,3 +160,9 @@ The incoming Telegram secret token does not match `TELEGRAM_WEBHOOK_SECRET`.
|
|
|
108
160
|
|
|
109
161
|
`channel_payload_invalid`:
|
|
110
162
|
The update is malformed or is not a supported private text message.
|
|
163
|
+
|
|
164
|
+
`transcription_secret_missing`:
|
|
165
|
+
Set `GROQ_API_KEY` or the custom secret named in `transcription.secret` as a managed hosted secret.
|
|
166
|
+
|
|
167
|
+
`transcription_audio_format_unsupported`:
|
|
168
|
+
The configured transcription provider does not accept the Telegram file format. Use Groq for OGG/Opus voice notes in V1.
|
|
@@ -33,6 +33,18 @@ Optional hardening secret:
|
|
|
33
33
|
ZAPSTER_WEBHOOK_TOKEN
|
|
34
34
|
```
|
|
35
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
|
|
46
|
+
```
|
|
47
|
+
|
|
36
48
|
## Files Created Or Edited
|
|
37
49
|
|
|
38
50
|
- `agentkit.config.ts`: `whatsappChannel({ name: "support-whatsapp", provider: "zapster" })`.
|
|
@@ -73,6 +85,53 @@ whatsappChannel({
|
|
|
73
85
|
})
|
|
74
86
|
```
|
|
75
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
|
+
|
|
76
135
|
## Setup Behavior
|
|
77
136
|
|
|
78
137
|
`agentkit channels setup support-whatsapp` prints the stable AgentKit webhook URL. Paste it into Zapster webhook settings.
|
|
@@ -125,3 +184,9 @@ Zapster is not sending the expected instance/webhook IDs, or the optional query
|
|
|
125
184
|
|
|
126
185
|
`channel_unsupported_message_type` or skipped delivery:
|
|
127
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.
|
package/package.json
CHANGED
|
@@ -20,6 +20,7 @@ type CloudChannel = {
|
|
|
20
20
|
webhook_url: string;
|
|
21
21
|
required_secrets: Array<{ name: string; status: string }>;
|
|
22
22
|
buffer?: AgentChannel["buffer"];
|
|
23
|
+
audio?: AgentChannel["audio"];
|
|
23
24
|
};
|
|
24
25
|
|
|
25
26
|
type CloudDelivery = {
|
|
@@ -386,6 +387,7 @@ async function createHostedChannel(
|
|
|
386
387
|
secrets: localChannel?.secrets ?? defaultChannelSecretsForCli(type, provider),
|
|
387
388
|
...(localChannel?.limits ? { limits: channelLimitsForApi(localChannel.limits) } : {}),
|
|
388
389
|
...(localChannel?.buffer ? { buffer: localChannel.buffer } : {}),
|
|
390
|
+
...(localChannel?.audio ? { audio: localChannel.audio } : {}),
|
|
389
391
|
};
|
|
390
392
|
|
|
391
393
|
return cloudPost<{ channel: CloudChannel }>(
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,8 @@ export type ChannelType = "website" | "telegram" | "whatsapp";
|
|
|
6
6
|
export type ChannelProvider = "agentkit" | "telegram" | "zapster" | "meta";
|
|
7
7
|
export type WhatsappChannelProvider = "zapster" | "meta";
|
|
8
8
|
export type TelegramAllowedUpdate = "message";
|
|
9
|
+
export type ChannelAudioMode = "off" | "reject" | "transcribe";
|
|
10
|
+
export type TranscriptionProviderName = "test" | "openai" | "groq";
|
|
9
11
|
|
|
10
12
|
export type AgentProvider = {
|
|
11
13
|
name: AgentProviderName;
|
|
@@ -39,6 +41,45 @@ export type ChannelBufferConfig =
|
|
|
39
41
|
maxChars: number;
|
|
40
42
|
};
|
|
41
43
|
|
|
44
|
+
export type ChannelAudioInput = {
|
|
45
|
+
mode?: ChannelAudioMode;
|
|
46
|
+
fallbackMessage?: string;
|
|
47
|
+
maxDurationSeconds?: number;
|
|
48
|
+
maxBytes?: number;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type ChannelAudioConfig =
|
|
52
|
+
| {
|
|
53
|
+
mode: "off";
|
|
54
|
+
}
|
|
55
|
+
| {
|
|
56
|
+
mode: "reject";
|
|
57
|
+
fallbackMessage: string;
|
|
58
|
+
maxDurationSeconds?: number;
|
|
59
|
+
maxBytes?: number;
|
|
60
|
+
}
|
|
61
|
+
| {
|
|
62
|
+
mode: "transcribe";
|
|
63
|
+
fallbackMessage: string;
|
|
64
|
+
maxDurationSeconds?: number;
|
|
65
|
+
maxBytes?: number;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export type AgentTranscriptionLimits = {
|
|
69
|
+
maxDurationSeconds?: number;
|
|
70
|
+
maxBytes?: number;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export type AgentTranscriptionConfig = {
|
|
74
|
+
provider: TranscriptionProviderName;
|
|
75
|
+
model: string;
|
|
76
|
+
secret?: string;
|
|
77
|
+
language?: string;
|
|
78
|
+
prompt?: string;
|
|
79
|
+
limits?: AgentTranscriptionLimits;
|
|
80
|
+
rawAudioTtlSeconds?: number;
|
|
81
|
+
};
|
|
82
|
+
|
|
42
83
|
export type WebsiteChannelAccess = {
|
|
43
84
|
mode: "token";
|
|
44
85
|
};
|
|
@@ -49,6 +90,7 @@ export type WebsiteChannelInput = {
|
|
|
49
90
|
secrets?: string[];
|
|
50
91
|
limits?: ChannelLimits;
|
|
51
92
|
buffer?: ChannelBufferInput;
|
|
93
|
+
audio?: ChannelAudioInput;
|
|
52
94
|
};
|
|
53
95
|
|
|
54
96
|
export type WebsiteChannelConfig = {
|
|
@@ -59,6 +101,7 @@ export type WebsiteChannelConfig = {
|
|
|
59
101
|
secrets: string[];
|
|
60
102
|
limits?: ChannelLimits;
|
|
61
103
|
buffer?: ChannelBufferConfig;
|
|
104
|
+
audio?: ChannelAudioConfig;
|
|
62
105
|
};
|
|
63
106
|
|
|
64
107
|
export type TelegramChannelInput = {
|
|
@@ -67,6 +110,7 @@ export type TelegramChannelInput = {
|
|
|
67
110
|
allowedUpdates?: TelegramAllowedUpdate[];
|
|
68
111
|
limits?: ChannelLimits;
|
|
69
112
|
buffer?: ChannelBufferInput;
|
|
113
|
+
audio?: ChannelAudioInput;
|
|
70
114
|
};
|
|
71
115
|
|
|
72
116
|
export type TelegramChannelConfig = {
|
|
@@ -77,6 +121,7 @@ export type TelegramChannelConfig = {
|
|
|
77
121
|
allowedUpdates: TelegramAllowedUpdate[];
|
|
78
122
|
limits?: ChannelLimits;
|
|
79
123
|
buffer?: ChannelBufferConfig;
|
|
124
|
+
audio?: ChannelAudioConfig;
|
|
80
125
|
};
|
|
81
126
|
|
|
82
127
|
export type WhatsappChannelInput = {
|
|
@@ -85,6 +130,7 @@ export type WhatsappChannelInput = {
|
|
|
85
130
|
secrets?: string[];
|
|
86
131
|
limits?: ChannelLimits;
|
|
87
132
|
buffer?: ChannelBufferInput;
|
|
133
|
+
audio?: ChannelAudioInput;
|
|
88
134
|
};
|
|
89
135
|
|
|
90
136
|
export type WhatsappChannelConfig = {
|
|
@@ -94,6 +140,7 @@ export type WhatsappChannelConfig = {
|
|
|
94
140
|
secrets: string[];
|
|
95
141
|
limits?: ChannelLimits;
|
|
96
142
|
buffer?: ChannelBufferConfig;
|
|
143
|
+
audio?: ChannelAudioConfig;
|
|
97
144
|
};
|
|
98
145
|
|
|
99
146
|
export type AgentChannel = WebsiteChannelConfig | TelegramChannelConfig | WhatsappChannelConfig;
|
|
@@ -270,6 +317,7 @@ export type AgentConfig = {
|
|
|
270
317
|
secrets: string[];
|
|
271
318
|
tools?: AgentTool[];
|
|
272
319
|
channels?: AgentChannel[];
|
|
320
|
+
transcription?: AgentTranscriptionConfig;
|
|
273
321
|
knowledge?: AgentKnowledgeConfig;
|
|
274
322
|
access: {
|
|
275
323
|
mode: AccessMode;
|
|
@@ -299,6 +347,7 @@ export function websiteChannel(input: WebsiteChannelInput): WebsiteChannelConfig
|
|
|
299
347
|
secrets: normalizeChannelSecrets(input.secrets ?? ["AGENTKIT_WEBSITE_CHANNEL_TOKEN"], "website channel"),
|
|
300
348
|
...(input.limits ? { limits: input.limits } : {}),
|
|
301
349
|
...(input.buffer ? { buffer: normalizeChannelBuffer(input.buffer, "website channel") } : {}),
|
|
350
|
+
...(input.audio ? { audio: normalizeChannelAudio(input.audio, "website channel") } : {}),
|
|
302
351
|
};
|
|
303
352
|
}
|
|
304
353
|
|
|
@@ -314,6 +363,7 @@ export function telegramChannel(input: TelegramChannelInput): TelegramChannelCon
|
|
|
314
363
|
allowedUpdates: input.allowedUpdates ?? ["message"],
|
|
315
364
|
...(input.limits ? { limits: input.limits } : {}),
|
|
316
365
|
...(input.buffer ? { buffer: normalizeChannelBuffer(input.buffer, "telegram channel") } : {}),
|
|
366
|
+
...(input.audio ? { audio: normalizeChannelAudio(input.audio, "telegram channel") } : {}),
|
|
317
367
|
};
|
|
318
368
|
}
|
|
319
369
|
|
|
@@ -328,6 +378,7 @@ export function whatsappChannel(input: WhatsappChannelInput): WhatsappChannelCon
|
|
|
328
378
|
),
|
|
329
379
|
...(input.limits ? { limits: input.limits } : {}),
|
|
330
380
|
...(input.buffer ? { buffer: normalizeChannelBuffer(input.buffer, `${input.provider} whatsapp channel`) } : {}),
|
|
381
|
+
...(input.audio ? { audio: normalizeChannelAudio(input.audio, `${input.provider} whatsapp channel`) } : {}),
|
|
331
382
|
};
|
|
332
383
|
}
|
|
333
384
|
|
|
@@ -382,6 +433,33 @@ function normalizeChannelBuffer(input: ChannelBufferInput, context: string): Cha
|
|
|
382
433
|
return buffer;
|
|
383
434
|
}
|
|
384
435
|
|
|
436
|
+
function normalizeChannelAudio(input: ChannelAudioInput, context: string): ChannelAudioConfig {
|
|
437
|
+
const mode = input.mode ?? "transcribe";
|
|
438
|
+
|
|
439
|
+
if (mode !== "off" && mode !== "reject" && mode !== "transcribe") {
|
|
440
|
+
throw new Error(`${context} audio.mode must be "off", "reject", or "transcribe".`);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
if (mode === "off") {
|
|
444
|
+
return { mode: "off" };
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
if (input.maxDurationSeconds !== undefined) {
|
|
448
|
+
validatePositiveInteger(input.maxDurationSeconds, `${context} audio.maxDurationSeconds`);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
if (input.maxBytes !== undefined) {
|
|
452
|
+
validatePositiveInteger(input.maxBytes, `${context} audio.maxBytes`);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
return {
|
|
456
|
+
mode,
|
|
457
|
+
fallbackMessage: input.fallbackMessage ?? "I received an audio message, but I could not transcribe it. Please send the message as text.",
|
|
458
|
+
...(input.maxDurationSeconds !== undefined ? { maxDurationSeconds: input.maxDurationSeconds } : {}),
|
|
459
|
+
...(input.maxBytes !== undefined ? { maxBytes: input.maxBytes } : {}),
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
|
|
385
463
|
function validatePositiveInteger(value: number, field: string): void {
|
|
386
464
|
if (!Number.isInteger(value) || value <= 0) {
|
|
387
465
|
throw new Error(`${field} must be a positive integer.`);
|
|
@@ -413,10 +491,13 @@ export { AgentKitError } from "./runtime/errors";
|
|
|
413
491
|
export type {
|
|
414
492
|
ChannelAdapter,
|
|
415
493
|
ChannelAdapterId,
|
|
494
|
+
ChannelAudioAttachment,
|
|
416
495
|
ChannelDeliveryDirection,
|
|
417
496
|
ChannelDeliveryState,
|
|
418
497
|
ChannelEventKind,
|
|
419
498
|
ChannelExternalIdentity,
|
|
499
|
+
ChannelMediaDownloadInput,
|
|
500
|
+
ChannelMediaDownloadResult,
|
|
420
501
|
ChannelMessageContentType,
|
|
421
502
|
ChannelMessageRole,
|
|
422
503
|
ChannelSendInput,
|
|
@@ -429,3 +510,8 @@ export type {
|
|
|
429
510
|
WebhookVerificationInput,
|
|
430
511
|
WebhookVerificationResult,
|
|
431
512
|
} from "./runtime/channels";
|
|
513
|
+
export type {
|
|
514
|
+
TranscriptionAdapter,
|
|
515
|
+
TranscriptionInput,
|
|
516
|
+
TranscriptionResult,
|
|
517
|
+
} from "./runtime/transcription";
|
|
@@ -8,9 +8,11 @@ import type { NormalizedChannelEvent, RawWebhookEvent } from "./channels";
|
|
|
8
8
|
export type ChannelFixtureName =
|
|
9
9
|
| "website-message"
|
|
10
10
|
| "telegram-message"
|
|
11
|
+
| "telegram-audio-message"
|
|
11
12
|
| "telegram-duplicate-message"
|
|
12
13
|
| "telegram-malformed-payload"
|
|
13
14
|
| "zapster-message"
|
|
15
|
+
| "zapster-audio-message"
|
|
14
16
|
| "zapster-duplicate-message"
|
|
15
17
|
| "zapster-unsupported-media";
|
|
16
18
|
|