@segmentstream/agent 0.53.0 → 0.55.0

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 +72 -0
  2. package/README.md +21 -8
  3. package/dist/_chunks/{build-metadata-Bc9qfC4D.mjs → build-metadata-CYSFZe6f.mjs} +1 -1
  4. package/dist/_chunks/{principal-JoaOmdFL.mjs → principal-DIgU-kPR.mjs} +71 -29
  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 +188 -67
  14. package/dist/extension/config.mjs +173 -36
  15. package/dist/extension/connections/ontology.mjs +1 -1
  16. package/dist/extension/hooks/authorization.mjs +1 -1
  17. package/dist/extension/hooks/guest-usage.d.ts +3 -0
  18. package/dist/extension/hooks/guest-usage.mjs +11 -0
  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 -2
  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 -1
  30. package/dist/extension/lib/chat-address.mjs +1 -1
  31. package/dist/extension/lib/chat-archive.d.ts +6 -0
  32. package/dist/extension/lib/chat-archive.mjs +7 -2
  33. package/dist/extension/lib/chat-context.mjs +3 -3
  34. package/dist/extension/lib/chat-post-confirmation.d.ts +13 -2
  35. package/dist/extension/lib/chat-post-confirmation.mjs +8 -3
  36. package/dist/extension/lib/chat-recorder.d.ts +17 -0
  37. package/dist/extension/lib/chat-recorder.mjs +18 -9
  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.d.ts +6 -1
  41. package/dist/extension/lib/confirmations.mjs +1 -1
  42. package/dist/extension/lib/email/attachments-send.d.ts +1 -1
  43. package/dist/extension/lib/email/attachments-send.mjs +1 -1
  44. package/dist/extension/lib/email/channel.d.ts +11 -3
  45. package/dist/extension/lib/email/channel.mjs +53 -42
  46. package/dist/extension/lib/guest-usage.d.ts +53 -0
  47. package/dist/extension/lib/guest-usage.mjs +52 -0
  48. package/dist/extension/lib/inbound-media/files.mjs +1 -1
  49. package/dist/extension/lib/inbound-media/index.mjs +1 -1
  50. package/dist/extension/lib/ontology-connection.mjs +1 -1
  51. package/dist/extension/lib/ontology-file-call.mjs +2 -1
  52. package/dist/extension/lib/ontology-tools.d.ts +2 -0
  53. package/dist/extension/lib/ontology-tools.mjs +1 -1
  54. package/dist/extension/lib/review/client.mjs +1 -0
  55. package/dist/extension/lib/review/hold.d.ts +7 -0
  56. package/dist/extension/lib/review/hold.mjs +2 -1
  57. package/dist/extension/lib/review/reply.mjs +3 -3
  58. package/dist/extension/lib/role-skill.mjs +1 -1
  59. package/dist/extension/lib/runtime-envelope.mjs +1 -1
  60. package/dist/extension/lib/sent-files.mjs +1 -1
  61. package/dist/extension/lib/slack/adapter.d.ts +5 -4
  62. package/dist/extension/lib/slack/adapter.mjs +19 -15
  63. package/dist/extension/lib/slack/attachments-send.d.ts +1 -1
  64. package/dist/extension/lib/slack/attachments-send.mjs +1 -1
  65. package/dist/extension/lib/stored-files.mjs +1 -1
  66. package/dist/extension/lib/telegram/adapter.d.ts +8 -2
  67. package/dist/extension/lib/telegram/adapter.mjs +43 -31
  68. package/dist/extension/lib/telegram/attachment-description.mjs +1 -1
  69. package/dist/extension/lib/telegram/attachments-send.mjs +1 -1
  70. package/dist/extension/lib/telegram/callbacks.mjs +1 -1
  71. package/dist/extension/lib/telegram/chat-archive.mjs +11 -10
  72. package/dist/extension/lib/telegram/chat-post-card.mjs +4 -3
  73. package/dist/extension/lib/telegram/confirmations.mjs +3 -3
  74. package/dist/extension/lib/telegram/customer-text.mjs +1 -1
  75. package/dist/extension/lib/telegram/delivery-diagnostics.mjs +2 -1
  76. package/dist/extension/lib/telegram/files.d.ts +4 -1
  77. package/dist/extension/lib/telegram/files.mjs +3 -2
  78. package/dist/extension/lib/telegram/health.mjs +1 -1
  79. package/dist/extension/lib/telegram/held-approvals.mjs +1 -1
  80. package/dist/extension/lib/telegram/inbound-request.mjs +1 -1
  81. package/dist/extension/lib/telegram/inbound.mjs +4 -4
  82. package/dist/extension/lib/telegram/lifecycle.mjs +2 -2
  83. package/dist/extension/lib/telegram/principal.mjs +1 -1
  84. package/dist/extension/lib/telegram/session-recovery.mjs +1 -1
  85. package/dist/extension/lib/telegram/signals.mjs +2 -1
  86. package/dist/extension/lib/telegram/silent.mjs +1 -1
  87. package/dist/extension/lib/telegram/structured.mjs +1 -1
  88. package/dist/extension/lib/telegram/turn-errors.mjs +1 -1
  89. package/dist/extension/lib/telegram/workspace-action.mjs +1 -1
  90. package/dist/extension/lib/web/auth.d.ts +18 -4
  91. package/dist/extension/lib/web/auth.mjs +1 -1
  92. package/dist/extension/lib/web/channel.mjs +1 -1
  93. package/dist/extension/lib/whatsapp/adapter.d.ts +12 -6
  94. package/dist/extension/lib/whatsapp/adapter.mjs +17 -10
  95. package/dist/extension/lib/whatsapp/attachments-send.d.ts +1 -1
  96. package/dist/extension/lib/whatsapp/attachments-send.mjs +1 -1
  97. package/dist/extension/lib/whatsapp/files.mjs +1 -1
  98. package/dist/extension/lib/workspace-source.d.ts +1 -1
  99. package/dist/extension/lib/workspace-source.mjs +3 -2
  100. package/dist/extension/model.mjs +1 -1
  101. package/dist/extension/tools/attachments_discard.mjs +1 -1
  102. package/dist/extension/tools/attachments_list.mjs +1 -1
  103. package/dist/extension/tools/attachments_promote.mjs +1 -1
  104. package/dist/extension/tools/attachments_read.mjs +1 -1
  105. package/dist/extension/tools/attachments_send.mjs +10 -6
  106. package/dist/extension/tools/attachments_stage.mjs +1 -1
  107. package/dist/extension/tools/attachments_table.mjs +1 -1
  108. package/dist/extension/tools/questions_ask.mjs +1 -1
  109. package/dist/extension/tools/unanswered.d.ts +2 -0
  110. package/dist/extension/tools/unanswered.mjs +39 -0
  111. package/dist/extension/tools/workspace_source.mjs +1 -1
  112. package/dist/tools/index.d.ts +1 -0
  113. package/dist/tools/index.mjs +2 -1
  114. package/package.json +2 -2
@@ -34,6 +34,14 @@ export declare const DEFAULT_ADMISSION_LIMITS: {
34
34
  readonly workspaceTurnsPerDay: 1000;
35
35
  };
36
36
  };
37
+ /**
38
+ * Ceilings of the guests' daily model cost, in US dollars. Unlike the turn limits, a cap the
39
+ * configuration leaves out does not apply: guests' spend is capped only where the workspace says.
40
+ */
41
+ export declare const GUEST_USD_CEILINGS: {
42
+ readonly usdPerDay: 100;
43
+ readonly workspaceUsdPerDay: 10000;
44
+ };
37
45
  export interface AdmissionLimits {
38
46
  readonly perSender: {
39
47
  readonly turnsPerMinute: number;
@@ -43,11 +51,15 @@ export interface AdmissionLimits {
43
51
  readonly workspaceTurnsPerDay: number;
44
52
  /**
45
53
  * Guests' turns, which the ontology counts apart from those of people who signed up: per guest
46
- * and for every guest together, each day. The agent's web channel sends them.
54
+ * and for every guest together, each day. The agent's web channel sends them. `usdPerDay` and
55
+ * `workspaceUsdPerDay` cap the model cost of each guest's turns and of every guest's together,
56
+ * each day, in US dollars, when set.
47
57
  */
48
58
  readonly guest: {
49
59
  readonly turnsPerDay: number;
50
60
  readonly workspaceTurnsPerDay: number;
61
+ readonly usdPerDay?: number;
62
+ readonly workspaceUsdPerDay?: number;
51
63
  };
52
64
  }
53
65
  export type AdmissionLimitsInput = Partial<Omit<AdmissionLimits, "perSender" | "guest">> & {
@@ -78,66 +90,12 @@ export interface SegmentStreamAgentConfigInput {
78
90
  readonly firstContact?: FirstContactSettings;
79
91
  readonly limits?: AdmissionLimitsInput;
80
92
  readonly replies?: AdmissionReplies;
81
- readonly channels?: {
82
- readonly telegram?: {
83
- /** The Connect key whose credential is the bot token, such as `telegram`. */
84
- readonly connection: string;
85
- /** @deprecated Use groups.mode; conflicting values are rejected. */
86
- readonly policy?: string;
87
- readonly groups?: {
88
- readonly replyEdgeIsAddress?: boolean;
89
- readonly topicScope?: boolean;
90
- readonly commandsAddress?: boolean;
91
- };
92
- /** External links only (default), Telegram's native first link, or no previews. */
93
- readonly linkPreviews?: string;
94
- /** Additional exact HTTP(S) origins belonging to this workspace. */
95
- readonly additionalOwnOrigins?: readonly string[];
96
- /**
97
- * How links to the workspace's own app open: `web` (default) leaves them as written,
98
- * `miniApp` opens their pages in the bot's Main Mini App.
99
- */
100
- readonly appLinks?: string;
101
- /**
102
- * Whether text the model writes before it calls tools reaches the chat as its own message,
103
- * like a reply. Off when absent: only final replies are delivered.
104
- */
105
- readonly interimMessages?: boolean;
106
- readonly inbound?: Omit<StructuredInbound, "contextVersion" | "kinds"> & {
107
- readonly kinds: ReadonlyArray<string>;
108
- readonly contextVersion: number;
109
- };
110
- readonly callbacks?: Omit<WorkspaceActionHook, "contextVersion"> & {
111
- readonly contextVersion: number;
112
- };
113
- readonly menuButton?: {
114
- readonly text: LocalizedText;
115
- };
116
- readonly attachmentLifecycle?: Omit<AttachmentLifecycle, "contextVersion"> & {
117
- readonly contextVersion?: number;
118
- };
119
- };
120
- readonly whatsapp?: {
121
- /** The key of the workspace's `WhatsAppConnection`, such as `whatsapp`. */
122
- readonly connection: string;
123
- };
124
- readonly slack?: {
125
- /** The key of the workspace's `SlackConnection`, such as `slack`. */
126
- readonly connection: string;
127
- };
128
- readonly email?: {
129
- /** The key of the workspace's `GmailConnection`: the mailbox the agent reads and answers. */
130
- readonly connection: string;
131
- /** Which mail reaches the agent, as Gmail's search; `in:inbox` when absent. */
132
- readonly query?: string;
133
- /** How long the mailbox may go unread, in minutes: 10 to 60, 10 when absent. */
134
- readonly checkAfterMinutes?: number;
135
- /** Gmail push to a Pub/Sub topic in the Google project of the connection's OAuth client. */
136
- readonly push?: {
137
- readonly topic: string;
138
- };
139
- };
140
- };
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;
141
99
  readonly models?: {
142
100
  /**
143
101
  * The chat model `segmentstream.model()` chooses per session: `default` for everyone, one per
@@ -172,6 +130,11 @@ export interface SegmentStreamAgentConfigInput {
172
130
  * deployed code into the sandbox, read as the member. Requires `sandbox`. Off when absent.
173
131
  */
174
132
  readonly workspaceSource?: boolean;
133
+ /**
134
+ * Whether the model gets `segmentstream__unanswered`, which records in the chat archive a
135
+ * question it could not answer, for the workspace's builders to read. Off when absent.
136
+ */
137
+ readonly unanswered?: boolean;
175
138
  /**
176
139
  * The web the agent may read: `segmentstream__web_fetch` fetches `https://` pages of these
177
140
  * domains, each also covering its subdomains, for callers who hold `agent_tool:web`. No web
@@ -234,6 +197,122 @@ export type ReviewInput = {
234
197
  readonly minConfidence: number;
235
198
  readonly criteria?: string;
236
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
+ /** A channel named other than its kind, as authored: its settings and its `kind`. */
263
+ export type NamedChannelInput = ({
264
+ readonly kind: "telegram";
265
+ } & TelegramChannelInput) | ({
266
+ readonly kind: "whatsapp";
267
+ } & WhatsAppChannelInput) | ({
268
+ readonly kind: "slack";
269
+ } & SlackChannelInput) | ({
270
+ readonly kind: "email";
271
+ } & EmailChannelInput);
272
+ /**
273
+ * `channels` as authored: the channel named after each kind, and any other channel with its kind.
274
+ * A JSON import widens `kind` to `string`, so the other names accept any object here; validation
275
+ * reads them.
276
+ */
277
+ export interface ChannelsInput {
278
+ readonly telegram?: TelegramChannelInput & {
279
+ readonly kind?: string;
280
+ };
281
+ readonly whatsapp?: WhatsAppChannelInput & {
282
+ readonly kind?: string;
283
+ };
284
+ readonly slack?: SlackChannelInput & {
285
+ readonly kind?: string;
286
+ };
287
+ readonly email?: EmailChannelInput & {
288
+ readonly kind?: string;
289
+ };
290
+ readonly [name: string]: (TelegramChannelInput & {
291
+ readonly kind?: string;
292
+ }) | (WhatsAppChannelInput & {
293
+ readonly kind?: string;
294
+ }) | (SlackChannelInput & {
295
+ readonly kind?: string;
296
+ }) | (EmailChannelInput & {
297
+ readonly kind?: string;
298
+ }) | undefined;
299
+ }
300
+ /** The kinds of channel the agent answers on: what a channel's name or `kind` says it is. */
301
+ export declare const CHANNEL_KINDS: readonly ["telegram", "whatsapp", "slack", "email"];
302
+ export type ChannelKind = (typeof CHANNEL_KINDS)[number];
303
+ /**
304
+ * A channel's name. It keys the channel's chats everywhere the platform keeps them, its wake-ups
305
+ * and its webhook, and names it to the ontology's `chat`.
306
+ */
307
+ export declare const CHANNEL_NAME: RegExp;
308
+ /**
309
+ * Names no channel may take: the platform keeps its own chats under them where a channel's chats
310
+ * carry its name, the browser's under `web` and workflow tasks' under `task`.
311
+ */
312
+ export declare const RESERVED_CHANNEL_NAMES: ReadonlyArray<string>;
313
+ /** The most channels one agent declares, of every kind together. */
314
+ export declare const MAXIMUM_CHANNELS = 20;
315
+ export declare function isChannelKind(value: unknown): value is ChannelKind;
237
316
  export interface TelegramSettings {
238
317
  readonly groups?: {
239
318
  readonly replyEdgeIsAddress?: boolean;
@@ -274,15 +353,52 @@ export type SessionScope = (typeof SESSION_SCOPES)[number];
274
353
  export interface SessionSettings {
275
354
  readonly scope: SessionScope;
276
355
  }
356
+ /** The settings of a channel of each kind, with defaults applied. */
357
+ export interface ChannelSettingsByKind {
358
+ readonly telegram: TelegramSettings;
359
+ readonly whatsapp: WhatsAppSettings;
360
+ readonly slack: SlackSettings;
361
+ readonly email: EmailSettings;
362
+ }
363
+ /** A channel named other than its kind: its settings, with its `kind`. */
364
+ export type NamedChannelSettings = {
365
+ readonly [K in ChannelKind]: {
366
+ readonly kind: K;
367
+ } & ChannelSettingsByKind[K];
368
+ }[ChannelKind];
369
+ /**
370
+ * The channels, by name. The channel named after each kind keeps that key, as it always had, and
371
+ * `null` when the agent has none; it carries no `kind`. Every other channel carries its `kind`.
372
+ * Read them with {@link declaredChannels} and {@link channelsOfKind}, which also read manifests
373
+ * stored before channels had names.
374
+ */
375
+ export interface ChannelsSettings {
376
+ readonly telegram: TelegramSettings | null;
377
+ readonly whatsapp: WhatsAppSettings | null;
378
+ readonly slack: SlackSettings | null;
379
+ readonly email: EmailSettings | null;
380
+ readonly [name: string]: ChannelSettingsByKind[ChannelKind] | NamedChannelSettings | null;
381
+ }
382
+ /** One channel the agent answers on: its name, its kind and its settings. */
383
+ export interface DeclaredChannel<K extends ChannelKind = ChannelKind> {
384
+ readonly name: string;
385
+ readonly kind: K;
386
+ readonly settings: ChannelSettingsByKind[K];
387
+ }
388
+ /**
389
+ * Every channel the settings declare, the channels named after their kinds first, then the others
390
+ * in the order written. A tolerant reader: an entry without `kind` is the kind its name names, and
391
+ * an entry that is neither, or `null`, is no channel.
392
+ */
393
+ export declare function declaredChannels(channels: Readonly<Record<string, unknown>> | null | undefined): ReadonlyArray<DeclaredChannel>;
394
+ /** The channels of one kind, the one named after the kind first. */
395
+ export declare function channelsOfKind<K extends ChannelKind>(channels: Readonly<Record<string, unknown>> | null | undefined, kind: K): ReadonlyArray<DeclaredChannel<K>>;
396
+ /** The settings of the channel `name` when it is of `kind`, else null. */
397
+ export declare function channelOf<K extends ChannelKind>(channels: Readonly<Record<string, unknown>> | null | undefined, kind: K, name: string): ChannelSettingsByKind[K] | null;
277
398
  /** The validated configuration with defaults applied. It stays JSON-serializable. */
278
399
  export interface SegmentStreamAgentConfig extends AdmissionSettings {
279
400
  readonly groups: GroupPolicy;
280
- readonly channels: {
281
- readonly telegram: TelegramSettings | null;
282
- readonly whatsapp: WhatsAppSettings | null;
283
- readonly slack: SlackSettings | null;
284
- readonly email: EmailSettings | null;
285
- };
401
+ readonly channels: ChannelsSettings;
286
402
  readonly models: {
287
403
  /**
288
404
  * `null` when the JSON sets none. The platform reads it at deploy; `agent.ts` passes the same
@@ -304,6 +420,11 @@ export interface SegmentStreamAgentConfig extends AdmissionSettings {
304
420
  * {@link SegmentStreamAgentConfigInput.workspaceSource}.
305
421
  */
306
422
  readonly workspaceSource?: boolean;
423
+ /**
424
+ * Whether the unanswered-question tool is on; validation sets it only when it is. See
425
+ * {@link SegmentStreamAgentConfigInput.unanswered}.
426
+ */
427
+ readonly unanswered?: boolean;
307
428
  /** The domains the web tools reach; absent without web tools. See {@link WebSettings}. */
308
429
  readonly web?: WebSettings;
309
430
  readonly sessions: SessionSettings;
@@ -34,6 +34,10 @@ const DEFAULT_ADMISSION_LIMITS = {
34
34
  workspaceTurnsPerDay: 1e3
35
35
  }
36
36
  };
37
+ const GUEST_USD_CEILINGS = {
38
+ usdPerDay: 100,
39
+ workspaceUsdPerDay: 1e4
40
+ };
37
41
  const ADMISSION_REPLY_KEYS = [
38
42
  "pairingRequired",
39
43
  "pairingButton",
@@ -45,7 +49,39 @@ const ADMISSION_REPLY_KEYS = [
45
49
  "groupPairingRequired",
46
50
  "refused"
47
51
  ];
52
+ const CHANNEL_KINDS = [
53
+ "telegram",
54
+ "whatsapp",
55
+ "slack",
56
+ "email"
57
+ ];
58
+ const CHANNEL_NAME = /^[a-z][a-z0-9_]{0,31}$/;
59
+ const RESERVED_CHANNEL_NAMES = ["web", "task"];
60
+ const MAXIMUM_CHANNELS = 20;
61
+ function isChannelKind(value) {
62
+ return CHANNEL_KINDS.some((kind) => kind === value);
63
+ }
48
64
  const SESSION_SCOPES = ["chat", "thread"];
65
+ function declaredChannels(channels) {
66
+ if (channels === null || channels === void 0 || typeof channels !== "object") return [];
67
+ const entries = Object.entries(channels).flatMap(([name, value]) => {
68
+ if (!isRecord(value) || typeof value.connection !== "string") return [];
69
+ const kind = value.kind ?? name;
70
+ if (!isChannelKind(kind) || isChannelKind(name) && name !== kind) return [];
71
+ return [{
72
+ name,
73
+ kind,
74
+ settings: Object.fromEntries(Object.entries(value).filter(([key]) => key !== "kind"))
75
+ }];
76
+ });
77
+ return [...CHANNEL_KINDS.flatMap((kind) => entries.filter((entry) => entry.name === kind)), ...entries.filter((entry) => !isChannelKind(entry.name))];
78
+ }
79
+ function channelsOfKind(channels, kind) {
80
+ return declaredChannels(channels).filter((channel) => channel.kind === kind);
81
+ }
82
+ function channelOf(channels, kind, name) {
83
+ return channelsOfKind(channels, kind).find((channel) => channel.name === name)?.settings ?? null;
84
+ }
49
85
  const IGNORED_SESSION_KEYS = [
50
86
  "compactAt",
51
87
  "timezone",
@@ -145,12 +181,11 @@ function section(input) {
145
181
  function isTelegramPolicy(value) {
146
182
  return TELEGRAM_POLICIES.some((policy) => policy === value);
147
183
  }
148
- function whatsappSettings(value, issues) {
149
- const path = ["channels", "whatsapp"];
184
+ function whatsappSettings(value, issues, path = ["channels", "whatsapp"]) {
150
185
  const whatsapp = section({
151
186
  value,
152
187
  path,
153
- allowed: ["connection"],
188
+ allowed: ["connection", "kind"],
154
189
  issues
155
190
  });
156
191
  if (whatsapp === void 0) return null;
@@ -163,12 +198,11 @@ function whatsappSettings(value, issues) {
163
198
  }
164
199
  return { connection: whatsapp.connection };
165
200
  }
166
- function slackSettings(value, issues) {
167
- const path = ["channels", "slack"];
201
+ function slackSettings(value, issues, path = ["channels", "slack"]) {
168
202
  const slack = section({
169
203
  value,
170
204
  path,
171
- allowed: ["connection"],
205
+ allowed: ["connection", "kind"],
172
206
  issues
173
207
  });
174
208
  if (slack === void 0) return null;
@@ -228,13 +262,13 @@ function webSettings(value, issues) {
228
262
  });
229
263
  return issues.length > before ? null : { domains };
230
264
  }
231
- function emailSettings(value, issues) {
232
- const path = ["channels", "email"];
265
+ function emailSettings(value, issues, path = ["channels", "email"]) {
233
266
  const email = section({
234
267
  value,
235
268
  path,
236
269
  allowed: [
237
270
  "connection",
271
+ "kind",
238
272
  "query",
239
273
  "checkAfterMinutes",
240
274
  "push"
@@ -279,14 +313,14 @@ function emailSettings(value, issues) {
279
313
  push: push === void 0 ? null : { topic: push.topic }
280
314
  };
281
315
  }
282
- function telegramSettings(value, issues) {
283
- const path = ["channels", "telegram"];
316
+ function telegramSettings(value, issues, path = ["channels", "telegram"]) {
284
317
  const telegram = section({
285
318
  value,
286
319
  path,
287
320
  allowed: [
288
321
  "connection",
289
- "policy",
322
+ "kind",
323
+ ...path.at(-1) === "telegram" ? ["policy"] : [],
290
324
  "groups",
291
325
  "linkPreviews",
292
326
  "additionalOwnOrigins",
@@ -339,10 +373,19 @@ function telegramSettings(value, issues) {
339
373
  path: [...path, "additionalOwnOrigins"]
340
374
  });
341
375
  const appLinks = telegram.appLinks === void 0 ? "web" : telegram.appLinks;
376
+ const miniApp = path.at(-1) === "telegram";
342
377
  if (!TELEGRAM_APP_LINKS.some((mode) => mode === appLinks)) issues.push({
343
378
  message: "must be \"web\" or \"miniApp\"",
344
379
  path: [...path, "appLinks"]
345
380
  });
381
+ else if (appLinks === "miniApp" && !miniApp) issues.push({
382
+ message: "must be \"web\": only the bot of channels.telegram opens the app as a Mini App",
383
+ path: [...path, "appLinks"]
384
+ });
385
+ if (telegram.menuButton !== void 0 && !miniApp) issues.push({
386
+ message: "is only for channels.telegram, whose bot opens the app as a Mini App",
387
+ path: [...path, "menuButton"]
388
+ });
346
389
  const interimMessages = telegram.interimMessages === void 0 ? false : telegram.interimMessages;
347
390
  if (typeof interimMessages !== "boolean") issues.push({
348
391
  message: "must be true or false",
@@ -427,6 +470,82 @@ function telegramSettings(value, issues) {
427
470
  } }
428
471
  } : null;
429
472
  }
473
+ function channelSettings(channels, issues) {
474
+ const result = {
475
+ telegram: telegramSettings(channels?.telegram, issues),
476
+ whatsapp: whatsappSettings(channels?.whatsapp, issues),
477
+ slack: slackSettings(channels?.slack, issues),
478
+ email: emailSettings(channels?.email, issues)
479
+ };
480
+ for (const kind of CHANNEL_KINDS) {
481
+ const value = channels?.[kind];
482
+ if (isRecord(value) && value.kind !== void 0 && value.kind !== kind) issues.push({
483
+ message: `must be "${kind}": a channel named after a kind is that kind; give another name to a channel of another kind`,
484
+ path: [
485
+ "channels",
486
+ kind,
487
+ "kind"
488
+ ]
489
+ });
490
+ }
491
+ for (const [name, value] of Object.entries(channels ?? {})) {
492
+ if (isChannelKind(name)) continue;
493
+ const path = ["channels", name];
494
+ if (!CHANNEL_NAME.test(name)) {
495
+ issues.push({
496
+ message: "must be a channel name: a lower-case letter, then up to 31 lower-case letters, digits or _",
497
+ path
498
+ });
499
+ continue;
500
+ }
501
+ if (RESERVED_CHANNEL_NAMES.includes(name)) {
502
+ issues.push({
503
+ message: "is a name the platform keeps its own chats under; choose another",
504
+ path
505
+ });
506
+ continue;
507
+ }
508
+ if (!isRecord(value)) {
509
+ issues.push({
510
+ message: "must be an object",
511
+ path
512
+ });
513
+ continue;
514
+ }
515
+ const kind = value.kind;
516
+ if (!isChannelKind(kind)) {
517
+ issues.push({
518
+ message: `must name the channel's kind: ${CHANNEL_KINDS.join(", ")}`,
519
+ path: [...path, "kind"]
520
+ });
521
+ continue;
522
+ }
523
+ const settings = kind === "telegram" ? telegramSettings(value, issues, path) : kind === "whatsapp" ? whatsappSettings(value, issues, path) : kind === "slack" ? slackSettings(value, issues, path) : emailSettings(value, issues, path);
524
+ if (settings !== null) result[name] = {
525
+ kind,
526
+ ...settings
527
+ };
528
+ }
529
+ const declared = declaredChannels(result);
530
+ if (declared.length > 20) issues.push({
531
+ message: `may declare at most 20 channels`,
532
+ path: ["channels"]
533
+ });
534
+ const named = new Map();
535
+ for (const channel of declared) {
536
+ const other = named.get(channel.settings.connection);
537
+ if (other === void 0) named.set(channel.settings.connection, channel.name);
538
+ else issues.push({
539
+ message: `is also the connection of channels.${other}; each channel needs a connection of its own`,
540
+ path: [
541
+ "channels",
542
+ channel.name,
543
+ "connection"
544
+ ]
545
+ });
546
+ }
547
+ return result;
548
+ }
430
549
  function workspaceHook(value, path, issues) {
431
550
  const configured = section({
432
551
  value,
@@ -617,9 +736,30 @@ function admissionLimits(value, issues) {
617
736
  const guest = section({
618
737
  value: limits?.guest,
619
738
  path: [...path, "guest"],
620
- allowed: Object.keys(DEFAULT_ADMISSION_LIMITS.guest),
739
+ allowed: [...Object.keys(DEFAULT_ADMISSION_LIMITS.guest), ...Object.keys(GUEST_USD_CEILINGS)],
621
740
  issues
622
741
  });
742
+ function usd(value, ceiling, path) {
743
+ if (value === void 0) return;
744
+ if (typeof value !== "number" || !Number.isFinite(value) || value <= 0 || value > ceiling) {
745
+ issues.push({
746
+ message: `must be a number of US dollars above 0 and at most ${ceiling}`,
747
+ path
748
+ });
749
+ return;
750
+ }
751
+ return value;
752
+ }
753
+ const usdPerDay = usd(guest?.usdPerDay, GUEST_USD_CEILINGS.usdPerDay, [
754
+ ...path,
755
+ "guest",
756
+ "usdPerDay"
757
+ ]);
758
+ const workspaceUsdPerDay = usd(guest?.workspaceUsdPerDay, GUEST_USD_CEILINGS.workspaceUsdPerDay, [
759
+ ...path,
760
+ "guest",
761
+ "workspaceUsdPerDay"
762
+ ]);
623
763
  function limit(value, ceiling, path) {
624
764
  if (value === void 0) return ceiling;
625
765
  if (typeof value !== "number" || !Number.isInteger(value) || value < 1 || value > ceiling) {
@@ -656,7 +796,9 @@ function admissionLimits(value, issues) {
656
796
  ...path,
657
797
  "guest",
658
798
  "workspaceTurnsPerDay"
659
- ])
799
+ ]),
800
+ ...usdPerDay === void 0 ? {} : { usdPerDay },
801
+ ...workspaceUsdPerDay === void 0 ? {} : { workspaceUsdPerDay }
660
802
  }
661
803
  };
662
804
  }
@@ -763,6 +905,7 @@ function validateConfig(input, options = {}) {
763
905
  "ontology",
764
906
  "sandbox",
765
907
  "workspaceSource",
908
+ "unanswered",
766
909
  "web",
767
910
  "sessions",
768
911
  "confirmations",
@@ -779,12 +922,7 @@ function validateConfig(input, options = {}) {
779
922
  const channels = section({
780
923
  value: root?.channels,
781
924
  path: ["channels"],
782
- allowed: [
783
- "telegram",
784
- "whatsapp",
785
- "slack",
786
- "email"
787
- ],
925
+ allowed: isRecord(root?.channels) ? Object.keys(root.channels) : [],
788
926
  issues
789
927
  });
790
928
  const models = section({
@@ -815,10 +953,8 @@ function validateConfig(input, options = {}) {
815
953
  message: "is retired; remove this setting (legacy \"deferred\" is accepted for compatibility)",
816
954
  path: ["confirmations", "mode"]
817
955
  });
818
- const telegram = telegramSettings(channels?.telegram, issues);
819
- const whatsapp = whatsappSettings(channels?.whatsapp, issues);
820
- const slack = slackSettings(channels?.slack, issues);
821
- const email = emailSettings(channels?.email, issues);
956
+ const declared = channelSettings(channels, issues);
957
+ const kinds = new Set(declaredChannels(declared).map((channel) => channel.kind));
822
958
  const authoredGroupsInput = currentGroupPolicyInput(root?.groups);
823
959
  for (const issue of groupPolicyIssues(authoredGroupsInput)) issues.push({
824
960
  ...issue,
@@ -925,7 +1061,7 @@ function validateConfig(input, options = {}) {
925
1061
  message: "is required when groupPairingButton is configured",
926
1062
  path: ["replies", "groupPairingRequired"]
927
1063
  });
928
- if (telegram !== null && !legacyArchive) {
1064
+ if (kinds.has("telegram") && !legacyArchive) {
929
1065
  for (const key of ["pairingRequired", "pairingButton"]) if (replies[key] === void 0) issues.push({
930
1066
  message: "is required for Telegram",
931
1067
  path: ["replies", key]
@@ -939,11 +1075,11 @@ function validateConfig(input, options = {}) {
939
1075
  ]
940
1076
  });
941
1077
  }
942
- if (whatsapp !== null && replies.pairingRequired === void 0) issues.push({
1078
+ if (kinds.has("whatsapp") && replies.pairingRequired === void 0) issues.push({
943
1079
  message: "is required for WhatsApp",
944
1080
  path: ["replies", "pairingRequired"]
945
1081
  });
946
- if (slack !== null && replies.pairingRequired === void 0) issues.push({
1082
+ if (kinds.has("slack") && replies.pairingRequired === void 0) issues.push({
947
1083
  message: "is required for Slack",
948
1084
  path: ["replies", "pairingRequired"]
949
1085
  });
@@ -965,6 +1101,11 @@ function validateConfig(input, options = {}) {
965
1101
  message: "requires sandbox to be true",
966
1102
  path: ["workspaceSource"]
967
1103
  });
1104
+ const unanswered = root?.unanswered ?? false;
1105
+ if (typeof unanswered !== "boolean") issues.push({
1106
+ message: "must be true or false",
1107
+ path: ["unanswered"]
1108
+ });
968
1109
  const web = webSettings(root?.web, issues);
969
1110
  const personas = personaSettings(root?.personas, issues, options.texts === "required");
970
1111
  if (root?.review !== void 0 && root.conversations !== void 0) issues.push({
@@ -975,15 +1116,10 @@ function validateConfig(input, options = {}) {
975
1116
  if (issues.length > 0) return { issues };
976
1117
  return { value: {
977
1118
  groups,
978
- channels: {
979
- telegram: telegram === null ? null : {
980
- ...telegram,
981
- policy: groups.mode
982
- },
983
- whatsapp,
984
- slack,
985
- email
986
- },
1119
+ channels: Object.fromEntries(Object.entries(declared).map(([name, channel]) => [name, channel !== null && (name === "telegram" || "kind" in channel && channel.kind === "telegram") ? {
1120
+ ...channel,
1121
+ policy: groups.mode
1122
+ } : channel])),
987
1123
  models: {
988
1124
  chat,
989
1125
  stt,
@@ -994,6 +1130,7 @@ function validateConfig(input, options = {}) {
994
1130
  ontology: { connection: connection === true },
995
1131
  sandbox: sandbox === true,
996
1132
  ...workspaceSource === true ? { workspaceSource: true } : {},
1133
+ ...unanswered === true ? { unanswered: true } : {},
997
1134
  ...web === null ? {} : { web },
998
1135
  sessions,
999
1136
  firstContact,
@@ -1025,4 +1162,4 @@ function manifestOf(config) {
1025
1162
  if (validation.issues !== void 0) throw new SegmentStreamAgentConfigError(validation.issues);
1026
1163
  return validation.value;
1027
1164
  }
1028
- 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, MAXIMUM_WEB_DOMAINS, PUBSUB_TOPIC, SESSION_SCOPES, SegmentStreamAgentConfigError, TELEGRAM_POLICIES, admissionLimitsOf, chatModelChoiceOf, configSchema, configWarnings, isLegacyAgentArchive, manifestOf, validateConfig };
1165
+ 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, admissionLimitsOf, channelOf, channelsOfKind, chatModelChoiceOf, configSchema, configWarnings, declaredChannels, 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 { D as ontologyConnection } from "../../_chunks/principal-JoaOmdFL.mjs";
8
+ import { T as ontologyConnection } from "../../_chunks/principal-DIgU-kPR.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;
@@ -7,7 +7,7 @@ __eveCreateRequire(import.meta.url);
7
7
  import segmentstream from "../extension.mjs";
8
8
  import { localizedText } from "../lib/admission.mjs";
9
9
  import { confirmationLocale } from "../lib/telegram/confirmation-text.mjs";
10
- import "../../_chunks/principal-JoaOmdFL.mjs";
10
+ import "../../_chunks/principal-DIgU-kPR.mjs";
11
11
  import { defineHook } from "eve/hooks";
12
12
  var authorization_default = defineHook({ events: { "interaction.opened": (event, context) => {
13
13
  const principal = context.session.auth.current;