@segmentstream/agent 0.54.0 → 0.56.1

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 (114) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/README.md +12 -6
  3. package/dist/_chunks/{build-metadata-2TyBXJEt.mjs → build-metadata-DqDm9a2E.mjs} +1 -1
  4. package/dist/_chunks/{principal-DUla0Xge.mjs → principal-TJ6zB2rF.mjs} +24 -8
  5. package/dist/extension/channels/email.d.ts +4 -3
  6. package/dist/extension/channels/email.mjs +2 -1
  7. package/dist/extension/channels/slack.d.ts +4 -3
  8. package/dist/extension/channels/slack.mjs +2 -1
  9. package/dist/extension/channels/telegram.d.ts +3 -1
  10. package/dist/extension/channels/telegram.mjs +2 -1
  11. package/dist/extension/channels/whatsapp.d.ts +3 -2
  12. package/dist/extension/channels/whatsapp.mjs +2 -1
  13. package/dist/extension/config.d.ts +212 -66
  14. package/dist/extension/config.mjs +196 -34
  15. package/dist/extension/connections/ontology.mjs +1 -1
  16. package/dist/extension/extension.d.ts +7 -1
  17. package/dist/extension/extension.mjs +2 -1
  18. package/dist/extension/hooks/authorization.mjs +1 -1
  19. package/dist/extension/instructions/persona.mjs +1 -1
  20. package/dist/extension/lib/actor.mjs +1 -1
  21. package/dist/extension/lib/attachment-tools.d.ts +1 -1
  22. package/dist/extension/lib/attachment-tools.mjs +2 -2
  23. package/dist/extension/lib/attachments-send.mjs +1 -1
  24. package/dist/extension/lib/attachments.d.ts +1 -1
  25. package/dist/extension/lib/attachments.mjs +1 -1
  26. package/dist/extension/lib/build-metadata.mjs +1 -1
  27. package/dist/extension/lib/channel-scope.d.ts +67 -0
  28. package/dist/extension/lib/channel-scope.mjs +104 -0
  29. package/dist/extension/lib/chat-address.d.ts +27 -4
  30. package/dist/extension/lib/chat-address.mjs +1 -1
  31. package/dist/extension/lib/chat-archive.d.ts +16 -0
  32. package/dist/extension/lib/chat-archive.mjs +22 -2
  33. package/dist/extension/lib/chat-context.mjs +3 -3
  34. package/dist/extension/lib/chat-post-confirmation.d.ts +14 -3
  35. package/dist/extension/lib/chat-post-confirmation.mjs +9 -3
  36. package/dist/extension/lib/chat-recorder.d.ts +17 -0
  37. package/dist/extension/lib/chat-recorder.mjs +24 -11
  38. package/dist/extension/lib/chats.d.ts +7 -0
  39. package/dist/extension/lib/chats.mjs +31 -1
  40. package/dist/extension/lib/confirmations.mjs +1 -1
  41. package/dist/extension/lib/email/attachments-send.d.ts +1 -1
  42. package/dist/extension/lib/email/attachments-send.mjs +1 -1
  43. package/dist/extension/lib/email/channel.d.ts +11 -3
  44. package/dist/extension/lib/email/channel.mjs +53 -42
  45. package/dist/extension/lib/guest-usage.mjs +1 -1
  46. package/dist/extension/lib/inbound-media/files.mjs +1 -1
  47. package/dist/extension/lib/inbound-media/index.mjs +1 -1
  48. package/dist/extension/lib/ontology-connection.mjs +1 -1
  49. package/dist/extension/lib/ontology-file-call.mjs +1 -1
  50. package/dist/extension/lib/ontology-tools.mjs +1 -1
  51. package/dist/extension/lib/review/client.mjs +1 -0
  52. package/dist/extension/lib/review/hold.d.ts +8 -1
  53. package/dist/extension/lib/review/hold.mjs +4 -2
  54. package/dist/extension/lib/review/reply.mjs +3 -3
  55. package/dist/extension/lib/role-skill.mjs +1 -1
  56. package/dist/extension/lib/runtime-envelope.mjs +1 -1
  57. package/dist/extension/lib/sent-files.mjs +1 -1
  58. package/dist/extension/lib/slack/adapter.d.ts +5 -4
  59. package/dist/extension/lib/slack/adapter.mjs +19 -15
  60. package/dist/extension/lib/slack/attachments-send.d.ts +1 -1
  61. package/dist/extension/lib/slack/attachments-send.mjs +1 -1
  62. package/dist/extension/lib/stored-files.mjs +1 -1
  63. package/dist/extension/lib/telegram/adapter.d.ts +8 -2
  64. package/dist/extension/lib/telegram/adapter.mjs +43 -31
  65. package/dist/extension/lib/telegram/attachment-description.mjs +1 -1
  66. package/dist/extension/lib/telegram/attachments-send.mjs +1 -1
  67. package/dist/extension/lib/telegram/callbacks.mjs +1 -1
  68. package/dist/extension/lib/telegram/chat-archive.mjs +11 -10
  69. package/dist/extension/lib/telegram/chat-post-card.mjs +4 -3
  70. package/dist/extension/lib/telegram/confirmations.mjs +2 -2
  71. package/dist/extension/lib/telegram/customer-text.mjs +1 -1
  72. package/dist/extension/lib/telegram/delivery-diagnostics.mjs +2 -1
  73. package/dist/extension/lib/telegram/files.d.ts +4 -1
  74. package/dist/extension/lib/telegram/files.mjs +3 -2
  75. package/dist/extension/lib/telegram/health.mjs +1 -1
  76. package/dist/extension/lib/telegram/held-approvals.mjs +1 -1
  77. package/dist/extension/lib/telegram/inbound-request.mjs +1 -1
  78. package/dist/extension/lib/telegram/inbound.mjs +4 -4
  79. package/dist/extension/lib/telegram/lifecycle.mjs +2 -2
  80. package/dist/extension/lib/telegram/principal.mjs +1 -1
  81. package/dist/extension/lib/telegram/session-recovery.mjs +1 -1
  82. package/dist/extension/lib/telegram/signals.mjs +2 -1
  83. package/dist/extension/lib/telegram/silent.mjs +1 -1
  84. package/dist/extension/lib/telegram/structured.mjs +1 -1
  85. package/dist/extension/lib/telegram/turn-errors.mjs +1 -1
  86. package/dist/extension/lib/telegram/workspace-action.mjs +1 -1
  87. package/dist/extension/lib/web/auth.mjs +1 -1
  88. package/dist/extension/lib/web/channel.mjs +1 -1
  89. package/dist/extension/lib/whatsapp/adapter.d.ts +12 -6
  90. package/dist/extension/lib/whatsapp/adapter.mjs +17 -10
  91. package/dist/extension/lib/whatsapp/attachments-send.d.ts +1 -1
  92. package/dist/extension/lib/whatsapp/attachments-send.mjs +1 -1
  93. package/dist/extension/lib/whatsapp/files.mjs +1 -1
  94. package/dist/extension/lib/workspace-channel/attachments-send.d.ts +35 -0
  95. package/dist/extension/lib/workspace-channel/attachments-send.mjs +119 -0
  96. package/dist/extension/lib/workspace-channel/channel.d.ts +229 -0
  97. package/dist/extension/lib/workspace-channel/channel.mjs +525 -0
  98. package/dist/extension/lib/workspace-channel/connection.d.ts +55 -0
  99. package/dist/extension/lib/workspace-channel/connection.mjs +68 -0
  100. package/dist/extension/lib/workspace-channel/secrets.d.ts +32 -0
  101. package/dist/extension/lib/workspace-channel/secrets.mjs +55 -0
  102. package/dist/extension/lib/workspace-source.d.ts +1 -1
  103. package/dist/extension/lib/workspace-source.mjs +3 -2
  104. package/dist/extension/model.mjs +1 -1
  105. package/dist/extension/tools/attachments_discard.mjs +1 -1
  106. package/dist/extension/tools/attachments_list.mjs +1 -1
  107. package/dist/extension/tools/attachments_promote.mjs +1 -1
  108. package/dist/extension/tools/attachments_read.mjs +1 -1
  109. package/dist/extension/tools/attachments_send.mjs +15 -7
  110. package/dist/extension/tools/attachments_stage.mjs +1 -1
  111. package/dist/extension/tools/attachments_table.mjs +1 -1
  112. package/dist/extension/tools/questions_ask.mjs +1 -1
  113. package/dist/extension/tools/workspace_source.mjs +1 -1
  114. package/package.json +2 -2
@@ -90,66 +90,12 @@ export interface SegmentStreamAgentConfigInput {
90
90
  readonly firstContact?: FirstContactSettings;
91
91
  readonly limits?: AdmissionLimitsInput;
92
92
  readonly replies?: AdmissionReplies;
93
- readonly channels?: {
94
- readonly telegram?: {
95
- /** The Connect key whose credential is the bot token, such as `telegram`. */
96
- readonly connection: string;
97
- /** @deprecated Use groups.mode; conflicting values are rejected. */
98
- readonly policy?: string;
99
- readonly groups?: {
100
- readonly replyEdgeIsAddress?: boolean;
101
- readonly topicScope?: boolean;
102
- readonly commandsAddress?: boolean;
103
- };
104
- /** External links only (default), Telegram's native first link, or no previews. */
105
- readonly linkPreviews?: string;
106
- /** Additional exact HTTP(S) origins belonging to this workspace. */
107
- readonly additionalOwnOrigins?: readonly string[];
108
- /**
109
- * How links to the workspace's own app open: `web` (default) leaves them as written,
110
- * `miniApp` opens their pages in the bot's Main Mini App.
111
- */
112
- readonly appLinks?: string;
113
- /**
114
- * Whether text the model writes before it calls tools reaches the chat as its own message,
115
- * like a reply. Off when absent: only final replies are delivered.
116
- */
117
- readonly interimMessages?: boolean;
118
- readonly inbound?: Omit<StructuredInbound, "contextVersion" | "kinds"> & {
119
- readonly kinds: ReadonlyArray<string>;
120
- readonly contextVersion: number;
121
- };
122
- readonly callbacks?: Omit<WorkspaceActionHook, "contextVersion"> & {
123
- readonly contextVersion: number;
124
- };
125
- readonly menuButton?: {
126
- readonly text: LocalizedText;
127
- };
128
- readonly attachmentLifecycle?: Omit<AttachmentLifecycle, "contextVersion"> & {
129
- readonly contextVersion?: number;
130
- };
131
- };
132
- readonly whatsapp?: {
133
- /** The key of the workspace's `WhatsAppConnection`, such as `whatsapp`. */
134
- readonly connection: string;
135
- };
136
- readonly slack?: {
137
- /** The key of the workspace's `SlackConnection`, such as `slack`. */
138
- readonly connection: string;
139
- };
140
- readonly email?: {
141
- /** The key of the workspace's `GmailConnection`: the mailbox the agent reads and answers. */
142
- readonly connection: string;
143
- /** Which mail reaches the agent, as Gmail's search; `in:inbox` when absent. */
144
- readonly query?: string;
145
- /** How long the mailbox may go unread, in minutes: 10 to 60, 10 when absent. */
146
- readonly checkAfterMinutes?: number;
147
- /** Gmail push to a Pub/Sub topic in the Google project of the connection's OAuth client. */
148
- readonly push?: {
149
- readonly topic: string;
150
- };
151
- };
152
- };
93
+ /**
94
+ * The channels the agent answers on, by name. A channel named after its kind (`telegram`,
95
+ * `whatsapp`, `slack`, `email`) is that kind; any other name, such as `sales_whatsapp`, says its
96
+ * `kind`. Names match {@link CHANNEL_NAME}.
97
+ */
98
+ readonly channels?: ChannelsInput;
153
99
  readonly models?: {
154
100
  /**
155
101
  * The chat model `segmentstream.model()` chooses per session: `default` for everyone, one per
@@ -251,6 +197,155 @@ export type ReviewInput = {
251
197
  readonly minConfidence: number;
252
198
  readonly criteria?: string;
253
199
  };
200
+ /** `channels.telegram`, or a channel of kind `telegram`, as authored. */
201
+ export interface TelegramChannelInput {
202
+ /** The Connect key whose credential is the bot token, such as `telegram`. */
203
+ readonly connection: string;
204
+ /** @deprecated Use groups.mode; conflicting values are rejected. Only `channels.telegram`. */
205
+ readonly policy?: string;
206
+ readonly groups?: {
207
+ readonly replyEdgeIsAddress?: boolean;
208
+ readonly topicScope?: boolean;
209
+ readonly commandsAddress?: boolean;
210
+ };
211
+ /** External links only (default), Telegram's native first link, or no previews. */
212
+ readonly linkPreviews?: string;
213
+ /** Additional exact HTTP(S) origins belonging to this workspace. */
214
+ readonly additionalOwnOrigins?: readonly string[];
215
+ /**
216
+ * How links to the workspace's own app open: `web` (default) leaves them as written,
217
+ * `miniApp` opens their pages in the bot's Main Mini App.
218
+ */
219
+ readonly appLinks?: string;
220
+ /**
221
+ * Whether text the model writes before it calls tools reaches the chat as its own message,
222
+ * like a reply. Off when absent: only final replies are delivered.
223
+ */
224
+ readonly interimMessages?: boolean;
225
+ readonly inbound?: Omit<StructuredInbound, "contextVersion" | "kinds"> & {
226
+ readonly kinds: ReadonlyArray<string>;
227
+ readonly contextVersion: number;
228
+ };
229
+ readonly callbacks?: Omit<WorkspaceActionHook, "contextVersion"> & {
230
+ readonly contextVersion: number;
231
+ };
232
+ readonly menuButton?: {
233
+ readonly text: LocalizedText;
234
+ };
235
+ readonly attachmentLifecycle?: Omit<AttachmentLifecycle, "contextVersion"> & {
236
+ readonly contextVersion?: number;
237
+ };
238
+ }
239
+ /** `channels.whatsapp`, or a channel of kind `whatsapp`, as authored. */
240
+ export interface WhatsAppChannelInput {
241
+ /** The key of the workspace's `WhatsAppConnection`, such as `whatsapp`. */
242
+ readonly connection: string;
243
+ }
244
+ /** `channels.slack`, or a channel of kind `slack`, as authored. */
245
+ export interface SlackChannelInput {
246
+ /** The key of the workspace's `SlackConnection`, such as `slack`. */
247
+ readonly connection: string;
248
+ }
249
+ /** `channels.email`, or a channel of kind `email`, as authored. */
250
+ export interface EmailChannelInput {
251
+ /** The key of the workspace's `GmailConnection`: the mailbox the agent reads and answers. */
252
+ readonly connection: string;
253
+ /** Which mail reaches the agent, as Gmail's search; `in:inbox` when absent. */
254
+ readonly query?: string;
255
+ /** How long the mailbox may go unread, in minutes: 10 to 60, 10 when absent. */
256
+ readonly checkAfterMinutes?: number;
257
+ /** Gmail push to a Pub/Sub topic in the Google project of the connection's OAuth client. */
258
+ readonly push?: {
259
+ readonly topic: string;
260
+ };
261
+ }
262
+ /**
263
+ * A channel the workspace defines in its own code, `defineChannel` in `agent/agent/channels/`,
264
+ * as authored: always under a name of its own, with `kind: "custom"`.
265
+ */
266
+ export interface WorkspaceChannelInput {
267
+ /** The key of the connection the channel's code calls its provider through. */
268
+ readonly connection: string;
269
+ /**
270
+ * How messages reach it: `webhook`, the provider calls the channel's route, by default; or
271
+ * `poll`, SegmentStream wakes the channel to read them.
272
+ */
273
+ readonly receive?: "webhook" | "poll";
274
+ /** With `poll`, how long the source may go unread, in minutes: 10 to 60, 10 when absent. */
275
+ readonly checkAfterMinutes?: number;
276
+ /**
277
+ * The workspace secret holding what the provider signs its deliveries with, or the token it
278
+ * sends, which the channel's code checks them against with `signedWith` or `matches`.
279
+ */
280
+ readonly secret?: string;
281
+ }
282
+ /** A channel named other than its kind, as authored: its settings and its `kind`. */
283
+ export type NamedChannelInput = ({
284
+ readonly kind: "telegram";
285
+ } & TelegramChannelInput) | ({
286
+ readonly kind: "whatsapp";
287
+ } & WhatsAppChannelInput) | ({
288
+ readonly kind: "slack";
289
+ } & SlackChannelInput) | ({
290
+ readonly kind: "email";
291
+ } & EmailChannelInput) | ({
292
+ readonly kind: "custom";
293
+ } & WorkspaceChannelInput);
294
+ /**
295
+ * `channels` as authored: the channel named after each kind, and any other channel with its kind.
296
+ * A JSON import widens `kind` to `string`, so the other names accept any object here; validation
297
+ * reads them.
298
+ */
299
+ export interface ChannelsInput {
300
+ readonly telegram?: TelegramChannelInput & {
301
+ readonly kind?: string;
302
+ };
303
+ readonly whatsapp?: WhatsAppChannelInput & {
304
+ readonly kind?: string;
305
+ };
306
+ readonly slack?: SlackChannelInput & {
307
+ readonly kind?: string;
308
+ };
309
+ readonly email?: EmailChannelInput & {
310
+ readonly kind?: string;
311
+ };
312
+ readonly [name: string]: (TelegramChannelInput & {
313
+ readonly kind?: string;
314
+ }) | (WhatsAppChannelInput & {
315
+ readonly kind?: string;
316
+ }) | (SlackChannelInput & {
317
+ readonly kind?: string;
318
+ }) | (EmailChannelInput & {
319
+ readonly kind?: string;
320
+ }) | (WorkspaceChannelInput & {
321
+ readonly kind?: string;
322
+ }) | undefined;
323
+ }
324
+ /** The kinds of channel the agent answers on: what a channel's name or `kind` says it is. */
325
+ export declare const CHANNEL_KINDS: readonly ["telegram", "whatsapp", "slack", "email"];
326
+ export type ChannelKind = (typeof CHANNEL_KINDS)[number];
327
+ /**
328
+ * The kind of a channel the workspace defines in its own code. No channel is named after it: each
329
+ * has a name of its own, and its people's accounts are its own (`channel:<name>`).
330
+ */
331
+ export declare const WORKSPACE_CHANNEL_KIND = "custom";
332
+ /** What a channel's `kind` may say: one the platform provides, or the workspace's own. */
333
+ export type AgentChannelKind = ChannelKind | typeof WORKSPACE_CHANNEL_KIND;
334
+ export declare function isAgentChannelKind(value: unknown): value is AgentChannelKind;
335
+ /**
336
+ * A channel's name. It keys the channel's chats everywhere the platform keeps them, its wake-ups
337
+ * and its webhook, and names it to the ontology's `chat`.
338
+ */
339
+ export declare const CHANNEL_NAME: RegExp;
340
+ /**
341
+ * Names no channel may take: the platform keeps its own chats under them where a channel's chats
342
+ * carry its name, the browser's under `web` and workflow tasks' under `task`; and `custom`, the
343
+ * kind of a workspace channel, which always has a name of its own.
344
+ */
345
+ export declare const RESERVED_CHANNEL_NAMES: ReadonlyArray<string>;
346
+ /** The most channels one agent declares, of every kind together. */
347
+ export declare const MAXIMUM_CHANNELS = 20;
348
+ export declare function isChannelKind(value: unknown): value is ChannelKind;
254
349
  export interface TelegramSettings {
255
350
  readonly groups?: {
256
351
  readonly replyEdgeIsAddress?: boolean;
@@ -291,15 +386,53 @@ export type SessionScope = (typeof SESSION_SCOPES)[number];
291
386
  export interface SessionSettings {
292
387
  readonly scope: SessionScope;
293
388
  }
389
+ /** The settings of a channel of each kind, with defaults applied. */
390
+ export interface ChannelSettingsByKind {
391
+ readonly telegram: TelegramSettings;
392
+ readonly whatsapp: WhatsAppSettings;
393
+ readonly slack: SlackSettings;
394
+ readonly email: EmailSettings;
395
+ readonly custom: WorkspaceChannelSettings;
396
+ }
397
+ /** A channel named other than its kind: its settings, with its `kind`. */
398
+ export type NamedChannelSettings = {
399
+ readonly [K in AgentChannelKind]: {
400
+ readonly kind: K;
401
+ } & ChannelSettingsByKind[K];
402
+ }[AgentChannelKind];
403
+ /**
404
+ * The channels, by name. The channel named after each kind keeps that key, as it always had, and
405
+ * `null` when the agent has none; it carries no `kind`. Every other channel carries its `kind`.
406
+ * Read them with {@link declaredChannels} and {@link channelsOfKind}, which also read manifests
407
+ * stored before channels had names.
408
+ */
409
+ export interface ChannelsSettings {
410
+ readonly telegram: TelegramSettings | null;
411
+ readonly whatsapp: WhatsAppSettings | null;
412
+ readonly slack: SlackSettings | null;
413
+ readonly email: EmailSettings | null;
414
+ readonly [name: string]: ChannelSettingsByKind[ChannelKind] | NamedChannelSettings | null;
415
+ }
416
+ /** One channel the agent answers on: its name, its kind and its settings. */
417
+ export interface DeclaredChannel<K extends AgentChannelKind = AgentChannelKind> {
418
+ readonly name: string;
419
+ readonly kind: K;
420
+ readonly settings: ChannelSettingsByKind[K];
421
+ }
422
+ /**
423
+ * Every channel the settings declare, the channels named after their kinds first, then the others
424
+ * in the order written. A tolerant reader: an entry without `kind` is the kind its name names, and
425
+ * an entry that is neither, or `null`, is no channel.
426
+ */
427
+ export declare function declaredChannels(channels: Readonly<Record<string, unknown>> | null | undefined): ReadonlyArray<DeclaredChannel>;
428
+ /** The channels of one kind, the one named after the kind first. */
429
+ export declare function channelsOfKind<K extends AgentChannelKind>(channels: Readonly<Record<string, unknown>> | null | undefined, kind: K): ReadonlyArray<DeclaredChannel<K>>;
430
+ /** The settings of the channel `name` when it is of `kind`, else null. */
431
+ export declare function channelOf<K extends AgentChannelKind>(channels: Readonly<Record<string, unknown>> | null | undefined, kind: K, name: string): ChannelSettingsByKind[K] | null;
294
432
  /** The validated configuration with defaults applied. It stays JSON-serializable. */
295
433
  export interface SegmentStreamAgentConfig extends AdmissionSettings {
296
434
  readonly groups: GroupPolicy;
297
- readonly channels: {
298
- readonly telegram: TelegramSettings | null;
299
- readonly whatsapp: WhatsAppSettings | null;
300
- readonly slack: SlackSettings | null;
301
- readonly email: EmailSettings | null;
302
- };
435
+ readonly channels: ChannelsSettings;
303
436
  readonly models: {
304
437
  /**
305
438
  * `null` when the JSON sets none. The platform reads it at deploy; `agent.ts` passes the same
@@ -399,6 +532,19 @@ export interface EmailSettings {
399
532
  readonly topic: string;
400
533
  } | null;
401
534
  }
535
+ /**
536
+ * A channel the workspace defines in its own code (`defineChannel`): the connection its code calls
537
+ * the provider through, and how messages reach it. With `poll`, SegmentStream wakes it at least
538
+ * every `checkAfterMinutes`, as it wakes a mailbox; with `webhook`, the provider calls its route.
539
+ */
540
+ export interface WorkspaceChannelSettings {
541
+ readonly connection: string;
542
+ readonly receive: "webhook" | "poll";
543
+ /** With `poll` only. */
544
+ readonly checkAfterMinutes?: number;
545
+ /** The workspace secret the provider's deliveries are checked against; the platform reads it. */
546
+ readonly secret?: string;
547
+ }
402
548
  /**
403
549
  * The web the agent may read. `domains` are bare lower-case host names, such as `example.com`;
404
550
  * each covers itself and its subdomains. Only `https://` pages of them are fetched, and every
@@ -49,7 +49,47 @@ const ADMISSION_REPLY_KEYS = [
49
49
  "groupPairingRequired",
50
50
  "refused"
51
51
  ];
52
+ const CHANNEL_KINDS = [
53
+ "telegram",
54
+ "whatsapp",
55
+ "slack",
56
+ "email"
57
+ ];
58
+ const WORKSPACE_CHANNEL_KIND = "custom";
59
+ function isAgentChannelKind(value) {
60
+ return isChannelKind(value) || value === "custom";
61
+ }
62
+ const CHANNEL_NAME = /^[a-z][a-z0-9_]{0,31}$/;
63
+ const RESERVED_CHANNEL_NAMES = [
64
+ "web",
65
+ "task",
66
+ WORKSPACE_CHANNEL_KIND
67
+ ];
68
+ const MAXIMUM_CHANNELS = 20;
69
+ function isChannelKind(value) {
70
+ return CHANNEL_KINDS.some((kind) => kind === value);
71
+ }
52
72
  const SESSION_SCOPES = ["chat", "thread"];
73
+ function declaredChannels(channels) {
74
+ if (channels === null || channels === void 0 || typeof channels !== "object") return [];
75
+ const entries = Object.entries(channels).flatMap(([name, value]) => {
76
+ if (!isRecord(value) || typeof value.connection !== "string") return [];
77
+ const kind = value.kind ?? name;
78
+ if (!isAgentChannelKind(kind) || isChannelKind(name) && name !== kind || name === "custom") return [];
79
+ return [{
80
+ name,
81
+ kind,
82
+ settings: Object.fromEntries(Object.entries(value).filter(([key]) => key !== "kind"))
83
+ }];
84
+ });
85
+ return [...CHANNEL_KINDS.flatMap((kind) => entries.filter((entry) => entry.name === kind)), ...entries.filter((entry) => !isChannelKind(entry.name))];
86
+ }
87
+ function channelsOfKind(channels, kind) {
88
+ return declaredChannels(channels).filter((channel) => channel.kind === kind);
89
+ }
90
+ function channelOf(channels, kind, name) {
91
+ return channelsOfKind(channels, kind).find((channel) => channel.name === name)?.settings ?? null;
92
+ }
53
93
  const IGNORED_SESSION_KEYS = [
54
94
  "compactAt",
55
95
  "timezone",
@@ -149,12 +189,11 @@ function section(input) {
149
189
  function isTelegramPolicy(value) {
150
190
  return TELEGRAM_POLICIES.some((policy) => policy === value);
151
191
  }
152
- function whatsappSettings(value, issues) {
153
- const path = ["channels", "whatsapp"];
192
+ function whatsappSettings(value, issues, path = ["channels", "whatsapp"]) {
154
193
  const whatsapp = section({
155
194
  value,
156
195
  path,
157
- allowed: ["connection"],
196
+ allowed: ["connection", "kind"],
158
197
  issues
159
198
  });
160
199
  if (whatsapp === void 0) return null;
@@ -167,12 +206,11 @@ function whatsappSettings(value, issues) {
167
206
  }
168
207
  return { connection: whatsapp.connection };
169
208
  }
170
- function slackSettings(value, issues) {
171
- const path = ["channels", "slack"];
209
+ function slackSettings(value, issues, path = ["channels", "slack"]) {
172
210
  const slack = section({
173
211
  value,
174
212
  path,
175
- allowed: ["connection"],
213
+ allowed: ["connection", "kind"],
176
214
  issues
177
215
  });
178
216
  if (slack === void 0) return null;
@@ -192,6 +230,57 @@ const EMAIL_CHECK_MINUTES = {
192
230
  };
193
231
  const DEFAULT_EMAIL_QUERY = "in:inbox";
194
232
  const PUBSUB_TOPIC = /^projects\/[a-z][a-z0-9-]{4,28}[a-z0-9]\/topics\/[A-Za-z][A-Za-z0-9._~%+-]{2,254}$/;
233
+ const WORKSPACE_SECRET_NAME = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
234
+ function workspaceChannelSettings(value, issues, path) {
235
+ const channel = section({
236
+ value,
237
+ path,
238
+ allowed: [
239
+ "connection",
240
+ "kind",
241
+ "receive",
242
+ "checkAfterMinutes",
243
+ "secret"
244
+ ],
245
+ issues
246
+ });
247
+ if (channel === void 0) return null;
248
+ const before = issues.length;
249
+ if (typeof channel.connection !== "string" || !CONNECTION_KEY.test(channel.connection)) issues.push({
250
+ message: "must be the key of the connection the channel's code calls its provider through",
251
+ path: [...path, "connection"]
252
+ });
253
+ const receive = channel.receive ?? "webhook";
254
+ if (receive !== "webhook" && receive !== "poll") issues.push({
255
+ message: "must be \"webhook\" or \"poll\"",
256
+ path: [...path, "receive"]
257
+ });
258
+ const minutes = channel.checkAfterMinutes ?? EMAIL_CHECK_MINUTES.default;
259
+ if (receive === "webhook" && channel.checkAfterMinutes !== void 0) issues.push({
260
+ message: "applies only to a channel that receives by \"poll\"",
261
+ path: [...path, "checkAfterMinutes"]
262
+ });
263
+ else if (typeof minutes !== "number" || !Number.isInteger(minutes) || minutes < EMAIL_CHECK_MINUTES.min || minutes > EMAIL_CHECK_MINUTES.max) issues.push({
264
+ message: `must be a whole number of minutes from ${EMAIL_CHECK_MINUTES.min} to ${EMAIL_CHECK_MINUTES.max}`,
265
+ path: [...path, "checkAfterMinutes"]
266
+ });
267
+ if (channel.secret !== void 0 && (typeof channel.secret !== "string" || !WORKSPACE_SECRET_NAME.test(channel.secret))) issues.push({
268
+ message: "must be a workspace secret's name, such as zernio-signing-secret",
269
+ path: [...path, "secret"]
270
+ });
271
+ if (issues.length > before) return null;
272
+ const secret = channel.secret === void 0 ? {} : { secret: channel.secret };
273
+ return receive === "poll" ? {
274
+ connection: channel.connection,
275
+ receive,
276
+ checkAfterMinutes: minutes,
277
+ ...secret
278
+ } : {
279
+ connection: channel.connection,
280
+ receive: "webhook",
281
+ ...secret
282
+ };
283
+ }
195
284
  const MAXIMUM_WEB_DOMAINS = 50;
196
285
  const WEB_DOMAIN = /^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
197
286
  function webSettings(value, issues) {
@@ -232,13 +321,13 @@ function webSettings(value, issues) {
232
321
  });
233
322
  return issues.length > before ? null : { domains };
234
323
  }
235
- function emailSettings(value, issues) {
236
- const path = ["channels", "email"];
324
+ function emailSettings(value, issues, path = ["channels", "email"]) {
237
325
  const email = section({
238
326
  value,
239
327
  path,
240
328
  allowed: [
241
329
  "connection",
330
+ "kind",
242
331
  "query",
243
332
  "checkAfterMinutes",
244
333
  "push"
@@ -283,14 +372,14 @@ function emailSettings(value, issues) {
283
372
  push: push === void 0 ? null : { topic: push.topic }
284
373
  };
285
374
  }
286
- function telegramSettings(value, issues) {
287
- const path = ["channels", "telegram"];
375
+ function telegramSettings(value, issues, path = ["channels", "telegram"]) {
288
376
  const telegram = section({
289
377
  value,
290
378
  path,
291
379
  allowed: [
292
380
  "connection",
293
- "policy",
381
+ "kind",
382
+ ...path.at(-1) === "telegram" ? ["policy"] : [],
294
383
  "groups",
295
384
  "linkPreviews",
296
385
  "additionalOwnOrigins",
@@ -343,10 +432,19 @@ function telegramSettings(value, issues) {
343
432
  path: [...path, "additionalOwnOrigins"]
344
433
  });
345
434
  const appLinks = telegram.appLinks === void 0 ? "web" : telegram.appLinks;
435
+ const miniApp = path.at(-1) === "telegram";
346
436
  if (!TELEGRAM_APP_LINKS.some((mode) => mode === appLinks)) issues.push({
347
437
  message: "must be \"web\" or \"miniApp\"",
348
438
  path: [...path, "appLinks"]
349
439
  });
440
+ else if (appLinks === "miniApp" && !miniApp) issues.push({
441
+ message: "must be \"web\": only the bot of channels.telegram opens the app as a Mini App",
442
+ path: [...path, "appLinks"]
443
+ });
444
+ if (telegram.menuButton !== void 0 && !miniApp) issues.push({
445
+ message: "is only for channels.telegram, whose bot opens the app as a Mini App",
446
+ path: [...path, "menuButton"]
447
+ });
350
448
  const interimMessages = telegram.interimMessages === void 0 ? false : telegram.interimMessages;
351
449
  if (typeof interimMessages !== "boolean") issues.push({
352
450
  message: "must be true or false",
@@ -431,6 +529,82 @@ function telegramSettings(value, issues) {
431
529
  } }
432
530
  } : null;
433
531
  }
532
+ function channelSettings(channels, issues) {
533
+ const result = {
534
+ telegram: telegramSettings(channels?.telegram, issues),
535
+ whatsapp: whatsappSettings(channels?.whatsapp, issues),
536
+ slack: slackSettings(channels?.slack, issues),
537
+ email: emailSettings(channels?.email, issues)
538
+ };
539
+ for (const kind of CHANNEL_KINDS) {
540
+ const value = channels?.[kind];
541
+ if (isRecord(value) && value.kind !== void 0 && value.kind !== kind) issues.push({
542
+ message: `must be "${kind}": a channel named after a kind is that kind; give another name to a channel of another kind`,
543
+ path: [
544
+ "channels",
545
+ kind,
546
+ "kind"
547
+ ]
548
+ });
549
+ }
550
+ for (const [name, value] of Object.entries(channels ?? {})) {
551
+ if (isChannelKind(name)) continue;
552
+ const path = ["channels", name];
553
+ if (!CHANNEL_NAME.test(name)) {
554
+ issues.push({
555
+ message: "must be a channel name: a lower-case letter, then up to 31 lower-case letters, digits or _",
556
+ path
557
+ });
558
+ continue;
559
+ }
560
+ if (RESERVED_CHANNEL_NAMES.includes(name)) {
561
+ issues.push({
562
+ message: "is a name the platform keeps its own chats under; choose another",
563
+ path
564
+ });
565
+ continue;
566
+ }
567
+ if (!isRecord(value)) {
568
+ issues.push({
569
+ message: "must be an object",
570
+ path
571
+ });
572
+ continue;
573
+ }
574
+ const kind = value.kind;
575
+ if (!isAgentChannelKind(kind)) {
576
+ issues.push({
577
+ message: `must name the channel's kind: ${[...CHANNEL_KINDS, WORKSPACE_CHANNEL_KIND].join(", ")}`,
578
+ path: [...path, "kind"]
579
+ });
580
+ continue;
581
+ }
582
+ const settings = kind === "telegram" ? telegramSettings(value, issues, path) : kind === "whatsapp" ? whatsappSettings(value, issues, path) : kind === "slack" ? slackSettings(value, issues, path) : kind === "email" ? emailSettings(value, issues, path) : workspaceChannelSettings(value, issues, path);
583
+ if (settings !== null) result[name] = {
584
+ kind,
585
+ ...settings
586
+ };
587
+ }
588
+ const declared = declaredChannels(result);
589
+ if (declared.length > 20) issues.push({
590
+ message: `may declare at most 20 channels`,
591
+ path: ["channels"]
592
+ });
593
+ const named = new Map();
594
+ for (const channel of declared) {
595
+ const other = named.get(channel.settings.connection);
596
+ if (other === void 0) named.set(channel.settings.connection, channel.name);
597
+ else issues.push({
598
+ message: `is also the connection of channels.${other}; each channel needs a connection of its own`,
599
+ path: [
600
+ "channels",
601
+ channel.name,
602
+ "connection"
603
+ ]
604
+ });
605
+ }
606
+ return result;
607
+ }
434
608
  function workspaceHook(value, path, issues) {
435
609
  const configured = section({
436
610
  value,
@@ -807,12 +981,7 @@ function validateConfig(input, options = {}) {
807
981
  const channels = section({
808
982
  value: root?.channels,
809
983
  path: ["channels"],
810
- allowed: [
811
- "telegram",
812
- "whatsapp",
813
- "slack",
814
- "email"
815
- ],
984
+ allowed: isRecord(root?.channels) ? Object.keys(root.channels) : [],
816
985
  issues
817
986
  });
818
987
  const models = section({
@@ -843,10 +1012,8 @@ function validateConfig(input, options = {}) {
843
1012
  message: "is retired; remove this setting (legacy \"deferred\" is accepted for compatibility)",
844
1013
  path: ["confirmations", "mode"]
845
1014
  });
846
- const telegram = telegramSettings(channels?.telegram, issues);
847
- const whatsapp = whatsappSettings(channels?.whatsapp, issues);
848
- const slack = slackSettings(channels?.slack, issues);
849
- const email = emailSettings(channels?.email, issues);
1015
+ const declared = channelSettings(channels, issues);
1016
+ const kinds = new Set(declaredChannels(declared).map((channel) => channel.kind));
850
1017
  const authoredGroupsInput = currentGroupPolicyInput(root?.groups);
851
1018
  for (const issue of groupPolicyIssues(authoredGroupsInput)) issues.push({
852
1019
  ...issue,
@@ -953,7 +1120,7 @@ function validateConfig(input, options = {}) {
953
1120
  message: "is required when groupPairingButton is configured",
954
1121
  path: ["replies", "groupPairingRequired"]
955
1122
  });
956
- if (telegram !== null && !legacyArchive) {
1123
+ if (kinds.has("telegram") && !legacyArchive) {
957
1124
  for (const key of ["pairingRequired", "pairingButton"]) if (replies[key] === void 0) issues.push({
958
1125
  message: "is required for Telegram",
959
1126
  path: ["replies", key]
@@ -967,11 +1134,11 @@ function validateConfig(input, options = {}) {
967
1134
  ]
968
1135
  });
969
1136
  }
970
- if (whatsapp !== null && replies.pairingRequired === void 0) issues.push({
1137
+ if (kinds.has("whatsapp") && replies.pairingRequired === void 0) issues.push({
971
1138
  message: "is required for WhatsApp",
972
1139
  path: ["replies", "pairingRequired"]
973
1140
  });
974
- if (slack !== null && replies.pairingRequired === void 0) issues.push({
1141
+ if (kinds.has("slack") && replies.pairingRequired === void 0) issues.push({
975
1142
  message: "is required for Slack",
976
1143
  path: ["replies", "pairingRequired"]
977
1144
  });
@@ -1008,15 +1175,10 @@ function validateConfig(input, options = {}) {
1008
1175
  if (issues.length > 0) return { issues };
1009
1176
  return { value: {
1010
1177
  groups,
1011
- channels: {
1012
- telegram: telegram === null ? null : {
1013
- ...telegram,
1014
- policy: groups.mode
1015
- },
1016
- whatsapp,
1017
- slack,
1018
- email
1019
- },
1178
+ channels: Object.fromEntries(Object.entries(declared).map(([name, channel]) => [name, channel !== null && (name === "telegram" || "kind" in channel && channel.kind === "telegram") ? {
1179
+ ...channel,
1180
+ policy: groups.mode
1181
+ } : channel])),
1020
1182
  models: {
1021
1183
  chat,
1022
1184
  stt,
@@ -1059,4 +1221,4 @@ function manifestOf(config) {
1059
1221
  if (validation.issues !== void 0) throw new SegmentStreamAgentConfigError(validation.issues);
1060
1222
  return validation.value;
1061
1223
  }
1062
- export { ADMISSION_REPLY_KEYS, DEFAULT_ADMISSION_LIMITS, DEFAULT_ATTACHMENTS_MODEL, DEFAULT_DECISION_MODEL, DEFAULT_EMAIL_QUERY, DEFAULT_IMAGE_DESCRIPTION_MODEL, DEFAULT_STT_MODEL, EMAIL_CHECK_MINUTES, GUEST_USD_CEILINGS, MAXIMUM_WEB_DOMAINS, PUBSUB_TOPIC, SESSION_SCOPES, SegmentStreamAgentConfigError, TELEGRAM_POLICIES, admissionLimitsOf, chatModelChoiceOf, configSchema, configWarnings, isLegacyAgentArchive, manifestOf, validateConfig };
1224
+ export { ADMISSION_REPLY_KEYS, CHANNEL_KINDS, CHANNEL_NAME, DEFAULT_ADMISSION_LIMITS, DEFAULT_ATTACHMENTS_MODEL, DEFAULT_DECISION_MODEL, DEFAULT_EMAIL_QUERY, DEFAULT_IMAGE_DESCRIPTION_MODEL, DEFAULT_STT_MODEL, EMAIL_CHECK_MINUTES, GUEST_USD_CEILINGS, MAXIMUM_CHANNELS, MAXIMUM_WEB_DOMAINS, PUBSUB_TOPIC, RESERVED_CHANNEL_NAMES, SESSION_SCOPES, SegmentStreamAgentConfigError, TELEGRAM_POLICIES, WORKSPACE_CHANNEL_KIND, admissionLimitsOf, channelOf, channelsOfKind, chatModelChoiceOf, configSchema, configWarnings, declaredChannels, isAgentChannelKind, isChannelKind, isLegacyAgentArchive, manifestOf, validateConfig };
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import segmentstream from "../extension.mjs";
8
- import { T as ontologyConnection } from "../../_chunks/principal-DUla0Xge.mjs";
8
+ import { T as ontologyConnection } from "../../_chunks/principal-TJ6zB2rF.mjs";
9
9
  import { defineDynamic } from "eve/connections";
10
10
  var ontology_default = defineDynamic(async (context) => {
11
11
  if (!segmentstream.config.ontology.connection) return null;
@@ -25,7 +25,13 @@ export default segmentstream;
25
25
  * runtime's own definition, offered here so that the agent's files import only this package.
26
26
  */
27
27
  export { defineAgent } from "eve";
28
- export { DEFAULT_DECISION_MODEL, DEFAULT_STT_MODEL, DEFAULT_ADMISSION_LIMITS, SegmentStreamAgentConfigError, manifestOf, type ChatModelChoice, type AdmissionLimits, type AdmissionLimitsInput, type AdmissionSettings, type AdmissionReplies, type FirstContactSettings, type LocalizedText, type SegmentStreamAgentConfig, type SegmentStreamAgentConfigInput, type SessionScope, type SessionSettings, type TelegramPolicy, type TelegramSettings, type WebSettings, } from "./config.js";
28
+ export { DEFAULT_DECISION_MODEL, DEFAULT_STT_MODEL, DEFAULT_ADMISSION_LIMITS, SegmentStreamAgentConfigError, manifestOf, type ChatModelChoice, type AdmissionLimits, type AdmissionLimitsInput, type AdmissionSettings, type AdmissionReplies, type FirstContactSettings, type LocalizedText, type SegmentStreamAgentConfig, type SegmentStreamAgentConfigInput, type SessionScope, type SessionSettings, type TelegramPolicy, type TelegramSettings, type WebSettings, type WorkspaceChannelInput, type WorkspaceChannelSettings, } from "./config.js";
29
+ /**
30
+ * Defines a channel in the workspace's own code, `agent/agent/channels/<name>.ts`, for a provider
31
+ * the platform has no channel for: the code receives, reads and sends, the platform does the rest.
32
+ */
33
+ export { defineChannel, type ChannelChecks, type ChannelContext, type ChannelDefinition, type ChannelFile, type ChannelMessage, type ChannelRead, type ChannelReply, type ChannelReplyFile, type ChannelRequest, type ChannelSender, } from "./lib/workspace-channel/channel.js";
34
+ export type { ChannelConnection, ChannelConnectionRequest, ChannelConnectionRequestOptions, ChannelConnectionResponse, } from "./lib/workspace-channel/connection.js";
29
35
  export { chooseModel, model, type DynamicModel, type ModelChoice } from "./model.js";
30
36
  export { forRoles } from "./lib/role-skill.js";
31
37
  export { groupPolicy, effectiveGroupPolicy, DEFAULT_GROUP_POLICY, type GroupPolicy, type GroupPolicyInput, type SmartPolicyInput, type ChatOverrideInput, } from "./lib/group-routing/policy.js";