@segmentstream/agent 0.54.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 (103) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +10 -6
  3. package/dist/_chunks/{build-metadata-2TyBXJEt.mjs → build-metadata-CYSFZe6f.mjs} +1 -1
  4. package/dist/_chunks/{principal-DUla0Xge.mjs → principal-DIgU-kPR.mjs} +20 -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 +165 -66
  14. package/dist/extension/config.mjs +137 -34
  15. package/dist/extension/connections/ontology.mjs +1 -1
  16. package/dist/extension/hooks/authorization.mjs +1 -1
  17. package/dist/extension/instructions/persona.mjs +1 -1
  18. package/dist/extension/lib/actor.mjs +1 -1
  19. package/dist/extension/lib/attachment-tools.d.ts +1 -1
  20. package/dist/extension/lib/attachment-tools.mjs +2 -2
  21. package/dist/extension/lib/attachments-send.mjs +1 -1
  22. package/dist/extension/lib/attachments.mjs +1 -1
  23. package/dist/extension/lib/build-metadata.mjs +1 -1
  24. package/dist/extension/lib/channel-scope.d.ts +67 -0
  25. package/dist/extension/lib/channel-scope.mjs +104 -0
  26. package/dist/extension/lib/chat-address.d.ts +18 -3
  27. package/dist/extension/lib/chat-address.mjs +1 -1
  28. package/dist/extension/lib/chat-archive.d.ts +6 -0
  29. package/dist/extension/lib/chat-archive.mjs +7 -2
  30. package/dist/extension/lib/chat-context.mjs +3 -3
  31. package/dist/extension/lib/chat-post-confirmation.d.ts +13 -2
  32. package/dist/extension/lib/chat-post-confirmation.mjs +8 -3
  33. package/dist/extension/lib/chat-recorder.d.ts +17 -0
  34. package/dist/extension/lib/chat-recorder.mjs +18 -9
  35. package/dist/extension/lib/chats.d.ts +7 -0
  36. package/dist/extension/lib/chats.mjs +31 -1
  37. package/dist/extension/lib/confirmations.mjs +1 -1
  38. package/dist/extension/lib/email/attachments-send.d.ts +1 -1
  39. package/dist/extension/lib/email/attachments-send.mjs +1 -1
  40. package/dist/extension/lib/email/channel.d.ts +11 -3
  41. package/dist/extension/lib/email/channel.mjs +53 -42
  42. package/dist/extension/lib/guest-usage.mjs +1 -1
  43. package/dist/extension/lib/inbound-media/files.mjs +1 -1
  44. package/dist/extension/lib/inbound-media/index.mjs +1 -1
  45. package/dist/extension/lib/ontology-connection.mjs +1 -1
  46. package/dist/extension/lib/ontology-file-call.mjs +1 -1
  47. package/dist/extension/lib/ontology-tools.mjs +1 -1
  48. package/dist/extension/lib/review/client.mjs +1 -0
  49. package/dist/extension/lib/review/hold.d.ts +7 -0
  50. package/dist/extension/lib/review/hold.mjs +2 -1
  51. package/dist/extension/lib/review/reply.mjs +3 -3
  52. package/dist/extension/lib/role-skill.mjs +1 -1
  53. package/dist/extension/lib/runtime-envelope.mjs +1 -1
  54. package/dist/extension/lib/sent-files.mjs +1 -1
  55. package/dist/extension/lib/slack/adapter.d.ts +5 -4
  56. package/dist/extension/lib/slack/adapter.mjs +19 -15
  57. package/dist/extension/lib/slack/attachments-send.d.ts +1 -1
  58. package/dist/extension/lib/slack/attachments-send.mjs +1 -1
  59. package/dist/extension/lib/stored-files.mjs +1 -1
  60. package/dist/extension/lib/telegram/adapter.d.ts +8 -2
  61. package/dist/extension/lib/telegram/adapter.mjs +43 -31
  62. package/dist/extension/lib/telegram/attachment-description.mjs +1 -1
  63. package/dist/extension/lib/telegram/attachments-send.mjs +1 -1
  64. package/dist/extension/lib/telegram/callbacks.mjs +1 -1
  65. package/dist/extension/lib/telegram/chat-archive.mjs +11 -10
  66. package/dist/extension/lib/telegram/chat-post-card.mjs +4 -3
  67. package/dist/extension/lib/telegram/confirmations.mjs +2 -2
  68. package/dist/extension/lib/telegram/customer-text.mjs +1 -1
  69. package/dist/extension/lib/telegram/delivery-diagnostics.mjs +2 -1
  70. package/dist/extension/lib/telegram/files.d.ts +4 -1
  71. package/dist/extension/lib/telegram/files.mjs +3 -2
  72. package/dist/extension/lib/telegram/health.mjs +1 -1
  73. package/dist/extension/lib/telegram/held-approvals.mjs +1 -1
  74. package/dist/extension/lib/telegram/inbound-request.mjs +1 -1
  75. package/dist/extension/lib/telegram/inbound.mjs +4 -4
  76. package/dist/extension/lib/telegram/lifecycle.mjs +2 -2
  77. package/dist/extension/lib/telegram/principal.mjs +1 -1
  78. package/dist/extension/lib/telegram/session-recovery.mjs +1 -1
  79. package/dist/extension/lib/telegram/signals.mjs +2 -1
  80. package/dist/extension/lib/telegram/silent.mjs +1 -1
  81. package/dist/extension/lib/telegram/structured.mjs +1 -1
  82. package/dist/extension/lib/telegram/turn-errors.mjs +1 -1
  83. package/dist/extension/lib/telegram/workspace-action.mjs +1 -1
  84. package/dist/extension/lib/web/auth.mjs +1 -1
  85. package/dist/extension/lib/web/channel.mjs +1 -1
  86. package/dist/extension/lib/whatsapp/adapter.d.ts +12 -6
  87. package/dist/extension/lib/whatsapp/adapter.mjs +17 -10
  88. package/dist/extension/lib/whatsapp/attachments-send.d.ts +1 -1
  89. package/dist/extension/lib/whatsapp/attachments-send.mjs +1 -1
  90. package/dist/extension/lib/whatsapp/files.mjs +1 -1
  91. package/dist/extension/lib/workspace-source.d.ts +1 -1
  92. package/dist/extension/lib/workspace-source.mjs +3 -2
  93. package/dist/extension/model.mjs +1 -1
  94. package/dist/extension/tools/attachments_discard.mjs +1 -1
  95. package/dist/extension/tools/attachments_list.mjs +1 -1
  96. package/dist/extension/tools/attachments_promote.mjs +1 -1
  97. package/dist/extension/tools/attachments_read.mjs +1 -1
  98. package/dist/extension/tools/attachments_send.mjs +10 -6
  99. package/dist/extension/tools/attachments_stage.mjs +1 -1
  100. package/dist/extension/tools/attachments_table.mjs +1 -1
  101. package/dist/extension/tools/questions_ask.mjs +1 -1
  102. package/dist/extension/tools/workspace_source.mjs +1 -1
  103. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.55.0
4
+
5
+ An agent answers on several channels of one kind: two WhatsApp numbers, a few Telegram bots,
6
+ several mailboxes or Slack apps. `channels` names each one; a channel named after its kind
7
+ (`telegram`, `whatsapp`, `slack`, `email`) is that kind and stays valid as written, and any other
8
+ name, such as `sales_whatsapp`, says its `kind`. Each channel needs a connection of its own.
9
+
10
+ The channel named after its kind keeps every key its chats had: sessions, archive, review and
11
+ attachments are unchanged. Any other channel carries its name in its chats' keys, so two bots'
12
+ private chats with the same person never meet, and receives at its own route:
13
+ `/eve/segmentstream/v1/<kind>/<name>`, where SegmentStream points each bot's webhook, relays each
14
+ number's and app's events, and wakes each mailbox. Each channel's replies leave through its own
15
+ connection, and a reply held for review names its channel, so approving it sends it through that
16
+ channel. People are not per channel: one Telegram account, number or address is one person on
17
+ every channel of its kind. Only the bot of `channels.telegram` opens the app as a Mini App.
18
+
19
+ `attachments_send` sends through the connection of the channel the chat is on, and each email
20
+ channel keeps, retries and drains its own replies. The chat an ontology request comes from
21
+ (`X-SegmentStream-Agent-Chat`) names the channel by its name, as the archive does, so history
22
+ and chat figures show `sales_whatsapp` where a chat of `channels.whatsapp` shows `whatsapp`. A
23
+ post to another chat renders as the kind `chat_list` names for its channel; an ontology that names
24
+ none lists only channels named after their kind, as before.
25
+
26
+ Action required: before naming a channel other than its kind, upgrade the ontology SDK and declare
27
+ the channel in `defineOntology({ chat })` under the same name with its `kind`, such as
28
+ `chat: { sales_whatsapp: { kind: "whatsapp", connection: waSales } }`; an older ontology refuses
29
+ the replies held on it.
30
+
31
+ Pins @segmentstream/ontology 0.111.0.
32
+
3
33
  ## 0.54.0
4
34
 
5
35
  History keeps the chat an action came from. The app's agent names the chat it acts in and its
package/README.md CHANGED
@@ -128,6 +128,7 @@ See [Sandbox](#sandbox).
128
128
  | `channels.telegram.additionalOwnOrigins` | `[]` | Additional exact HTTP(S) workspace origins, including local ports; no paths or credentials. |
129
129
  | `channels.telegram.appLinks` | `"web"` | `"miniApp"` opens links to the app's own pages in the bot's Main Mini App (`t.me/<bot>?startapp=…`) as messages are delivered; see `docs/agent.md` |
130
130
  | `channels.telegram.interimMessages` | `false` | `true` delivers the text the model writes before calling tools as its own message, like a reply; see [Telegram answer delivery](#telegram-answer-delivery) |
131
+ | `channels.<name>.kind` | the name | A channel not named after its kind, such as `sales_whatsapp`, says its kind and takes that kind's settings: several bots, numbers, apps or mailboxes on one agent; see `docs/agent.md`, "Channels by name" |
131
132
  | `models.stt` | `"spacexai/grok-stt"` | The AI Gateway transcription model for voice messages; `false` leaves them untranscribed |
132
133
  | `models.imageDescription` | `google/gemini-2.5-flash-lite` | Image evidence for group routing even with native vision; `false` disables descriptions |
133
134
  | `models.decision` | `"typesafe-ai/jev-1.14.0"` | The AI Gateway decision model of the inbound router |
@@ -808,14 +809,17 @@ ordinary tools use the compatible connection and no runtime arguments are added.
808
809
  missing/incomplete preview metadata is denied. The versioned connection has its own instance key.
809
810
 
810
811
  The runtime reads `me` for the server-derived `attribution`, and `chat_list({ chat })` for exactly
811
- one eligible destination: `{ items: [{ id, title, provider, external_id }], next_cursor: null }`.
812
- Provider is `telegram`, `slack` or `whatsapp`; the agent refuses a destination on any other
813
- provider when it describes the post, as agents before Slack and WhatsApp destinations refuse
814
- theirs, and refuses a `reply_to` for WhatsApp. The final text is computed as the ontology renders
812
+ one eligible destination: `{ items: [{ id, title, provider, kind?, external_id }], next_cursor:
813
+ null }`. `provider` is the destination's channel by its name and `kind` that channel's kind; an
814
+ ontology that sends no `kind` lists only channels named after their kind, whose name is the kind.
815
+ The kind is `telegram`, `slack` or `whatsapp`; the agent refuses a destination of any other kind
816
+ when it describes the post, as agents before Slack and WhatsApp destinations refuse theirs, and
817
+ refuses a `reply_to` for WhatsApp. The final text is computed as the ontology renders
815
818
  it: Telegram's MarkdownV2, `renderSlack` from `@segmentstream/ontology/slack`, or `renderWhatsApp`
816
819
  from `@segmentstream/ontology/whatsapp`. The final plain text is `text + separator + attribution`, with a blank line as the neutral separator;
817
- `reply_to` is optional. A preview digest is SHA-256 of the JSON array of chat ID, provider,
818
- external ID, title, attribution, text, final text and nullable reply target, in that order.
820
+ `reply_to` is optional. A preview digest is SHA-256 of the JSON array of chat ID, provider (the
821
+ channel's name), external ID, title, attribution, text, final text and nullable reply target, in
822
+ that order.
819
823
  The target/attribution are resolved again immediately before executing the frozen call.
820
824
 
821
825
  The SDK constructs model-hidden `_segmentstream` metadata for approved runtime posts.
@@ -4,7 +4,7 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
- var version = "0.54.0";
7
+ var version = "0.55.0";
8
8
  function agentBuild(environment = process.env) {
9
9
  return {
10
10
  agent: version,
@@ -7,12 +7,14 @@ __eveCreateRequire(import.meta.url);
7
7
  import { telegramText, withTelegramTexts } from "../extension/lib/telegram/texts.mjs";
8
8
  import { isTechnicalText } from "../extension/lib/customer-text-safety.mjs";
9
9
  import { miniAppLinks, originalLinkPreview, withMiniAppLinks } from "../extension/lib/telegram/app-links.mjs";
10
- import { admissionLimitsOf } from "../extension/config.mjs";
10
+ import { CHANNEL_NAME, admissionLimitsOf } from "../extension/config.mjs";
11
11
  import { appOrigin } from "../extension/lib/environment.mjs";
12
+ import { channelAttributes, currentChannel, principalChannel } from "../extension/lib/channel-scope.mjs";
12
13
  import { redactDiagnostic } from "../extension/lib/diagnostics.mjs";
13
14
  import { redactTelegramDiagnostic } from "../extension/lib/telegram/diagnostic-redaction.mjs";
14
15
  import { CONFIRMATION_FACTS, CONFIRMATION_PREVIEW_METHOD, ConfirmationRefused, UnsafeConfirmationTarget, confirmationCard, describeConfirmation, factsConfirmation, object } from "../extension/lib/confirmation-description.mjs";
15
16
  import { confirmationCopy, confirmationCopyIssue, confirmationEntities, confirmationLocale, renderConfirmation } from "../extension/lib/telegram/confirmation-text.mjs";
17
+ import { CHAT_POST_ENVELOPE, CHAT_POST_TOOL, chatPostDigest, chatPostOperationId, describeChatPost, isChatPost, supportsChatPost } from "../extension/lib/chat-post-confirmation.mjs";
16
18
  import { chatPostCard, chatPostCardLinks, chatPostPrompt, isExactChatPostCard } from "../extension/lib/telegram/chat-post-card.mjs";
17
19
  import { plainTelegramText, splitTelegramText, telegramMarkdown } from "../extension/lib/telegram/format.mjs";
18
20
  import { inTelegramSendQueue } from "../extension/lib/telegram/send-queue.mjs";
@@ -22,7 +24,6 @@ import { MAXIMUM_DOWNLOAD_BYTES } from "../extension/lib/connection-proxy.mjs";
22
24
  import { AGENT_TOOLS_ATTRIBUTE, SANDBOX_TOOL, agentToolsAnswer, agentToolsAttribute } from "../extension/lib/agent-tools.mjs";
23
25
  import { AGENT_TASK_HEADER, agentTaskIdOf, taskSecret } from "../extension/lib/agent-task.mjs";
24
26
  import { promptFits, withButtonDecision } from "../extension/lib/confirmation-buttons.mjs";
25
- import { CHAT_POST_ENVELOPE, CHAT_POST_TOOL, chatPostDigest, chatPostOperationId, describeChatPost, isChatPost, supportsChatPost } from "../extension/lib/chat-post-confirmation.mjs";
26
27
  import { describableImage, describeReceivedImage } from "../extension/lib/inbound-media/images.mjs";
27
28
  import { NATIVE_AUDIO_NOTE, isSpeech, transcribeSpeech } from "../extension/lib/inbound-media/speech.mjs";
28
29
  import { createHash, randomBytes, randomUUID } from "node:crypto";
@@ -57,8 +58,10 @@ function telegramRuntimeSource(message, files, callbackQueryId) {
57
58
  media_type: staged.attachment.contentType
58
59
  });
59
60
  }
61
+ const channel = currentChannel("telegram");
60
62
  return {
61
63
  provider: "telegram",
64
+ ...channel === "telegram" ? {} : { channel },
62
65
  chat_id: message.chat.id,
63
66
  thread_id: String(message.messageThreadId ?? ""),
64
67
  message_id: message.messageId,
@@ -93,6 +96,7 @@ function compatibleRuntimeEnvelope(envelope, extended) {
93
96
  ...envelope,
94
97
  source: {
95
98
  provider: source.provider,
99
+ ...source.channel === void 0 ? {} : { channel: source.channel },
96
100
  chat_id: source.chat_id,
97
101
  thread_id: source.thread_id
98
102
  }
@@ -372,6 +376,7 @@ function chatAddressOf(principal) {
372
376
  const chatId = attributes.chatId;
373
377
  return typeof chatId !== "string" || chatId === "" ? void 0 : {
374
378
  provider: "telegram",
379
+ ...principalChannel(principal) === void 0 ? {} : { channel: principalChannel(principal) },
375
380
  chatId,
376
381
  threadId: String(attributes.messageThreadId ?? ""),
377
382
  kind: chatId.startsWith("-") ? "group" : "private"
@@ -388,7 +393,7 @@ function chatAddressOf(principal) {
388
393
  function chatHeaders(principal, sessionId) {
389
394
  const chat = chatAddressOf(principal);
390
395
  return chat === void 0 ? {} : {
391
- [CHAT_HEADER]: `${chat.provider}:${chat.chatId}`,
396
+ [CHAT_HEADER]: `${chatChannel(chat)}:${chat.chatId}`,
392
397
  ...sessionId === void 0 || sessionId === "" ? {} : { [SESSION_HEADER]: sessionId }
393
398
  };
394
399
  }
@@ -396,17 +401,21 @@ function parsedChatAddress(value, provider) {
396
401
  if (typeof value !== "object" || value === null || Array.isArray(value)) return;
397
402
  const item = value;
398
403
  const text = (field, empty = false) => typeof field === "string" && (empty || field !== "") && field.length <= 512;
399
- if (item.provider !== "slack" && item.provider !== "whatsapp" && item.provider !== "web" && item.provider !== "email" || item.provider !== provider || !text(item.chatId) || !text(item.threadId, true) || item.kind !== "private" && item.kind !== "group" || item.peer !== void 0 && !text(item.peer)) return;
404
+ if (item.provider !== "slack" && item.provider !== "whatsapp" && item.provider !== "web" && item.provider !== "email" || item.provider !== provider || !text(item.chatId) || !text(item.threadId, true) || item.kind !== "private" && item.kind !== "group" || item.peer !== void 0 && !text(item.peer) || item.channel !== void 0 && (typeof item.channel !== "string" || !CHANNEL_NAME.test(item.channel) || item.channel === item.provider)) return;
400
405
  return {
401
406
  provider: item.provider,
407
+ ...item.channel === void 0 ? {} : { channel: item.channel },
402
408
  chatId: item.chatId,
403
409
  threadId: item.threadId,
404
410
  kind: item.kind,
405
411
  ...item.peer === void 0 ? {} : { peer: item.peer }
406
412
  };
407
413
  }
414
+ function chatChannel(chat) {
415
+ return chat.channel ?? chat.provider;
416
+ }
408
417
  function isSameChat(chat, destination) {
409
- if (chat.provider !== destination.provider) return false;
418
+ if (chatChannel(chat) !== destination.provider) return false;
410
419
  return chat.chatId === destination.externalId || chat.provider !== "telegram" && chat.kind === "private" && chat.peer === destination.externalId;
411
420
  }
412
421
  const WEB_AUTHENTICATOR = "segmentstream-web";
@@ -726,7 +735,7 @@ function ownedBy(saved, actor) {
726
735
  }
727
736
  }
728
737
  function isSameSource(saved, current) {
729
- return current !== void 0 && saved.provider === current.provider && saved.chatId === current.chatId && saved.threadId === current.threadId;
738
+ return current !== void 0 && chatChannel(saved) === chatChannel(current) && saved.chatId === current.chatId && saved.threadId === current.threadId;
730
739
  }
731
740
  const confirmations = defineState("segmentstream.confirmations", () => ({}));
732
741
  function connectionHints(ctx) {
@@ -1341,11 +1350,13 @@ function ontologyConnection(input) {
1341
1350
  operation_id: chatPostOperationId(ctx.session.id, ctx.callId),
1342
1351
  source: source.provider === "telegram" ? {
1343
1352
  provider: "telegram",
1353
+ ...source.channel === void 0 ? {} : { channel: source.channel },
1344
1354
  chat_id: source.chatId,
1345
1355
  thread_id: source.threadId,
1346
1356
  ...base.source
1347
1357
  } : {
1348
1358
  provider: source.provider,
1359
+ ...source.channel === void 0 ? {} : { channel: source.channel },
1349
1360
  chat_id: source.chatId,
1350
1361
  thread_id: source.threadId,
1351
1362
  kind: source.kind,
@@ -1945,7 +1956,8 @@ function telegramPrincipal(input) {
1945
1956
  roles: member.roles,
1946
1957
  ...agentToolsAttribute(member.agentTools),
1947
1958
  chatId: message.chat.id,
1948
- chatType: message.chat.type
1959
+ chatType: message.chat.type,
1960
+ ...channelAttributes("telegram")
1949
1961
  };
1950
1962
  if (member.name !== null) attributes.memberName = member.name;
1951
1963
  if (message.messageThreadId !== void 0) attributes.messageThreadId = String(message.messageThreadId);
@@ -1983,4 +1995,4 @@ function identityProviderOf(principal) {
1983
1995
  const provider = principal?.attributes.identityProvider;
1984
1996
  return typeof provider === "string" && provider !== "" ? provider : void 0;
1985
1997
  }
1986
- export { KIND_ATTRIBUTE as $, ontologyToolLabels as A, withDeliveryLocale as At, actorHeaders as B, parseAttachmentUrl as C, customerCopy as Ct, OntologyFileUnavailable as D, formattingRefused as Dt, OntologyActionNotPermitted as E, failureText as Et, confirmations as F, telegramRuntimeSource as Ft, memberTool as G, actorOf as H, inputHash as I, AGENT_GRANT_HEADER as J, notForGuests as K, needsConfirmation as L, promotionTarget as M, compatibleRuntimeEnvelope as Mt, CONFIRMATION_TTL_MS as N, principalRuntimeSource as Nt, OntologyToolRejected as O, reportTelegramError as Ot, actionApproval as P, runtimeEnvelope as Pt, INTROSPECTION_PATH as Q, ACT_AS_HEADER as R, fetchStoredAttachment as S, currentThreadId as St, ontologyConnection as T, customerText as Tt, isGuestSession as U, actorKey as V, member as W, GUEST_ID_ATTRIBUTE as X, GUEST_CONFIRMATIONS_ATTRIBUTE as Y, GUEST_ROLE as Z, AttachmentError as _, chatHeaders as _t, rolesOf as a, guestConfirms as at, agentAttachments as b, TelegramDeliveryError as bt, currentInboundRequest as c, ontologyIntrospection as ct, prepareInboundMedia as d, webMemberOf as dt, TURN_LIMITED_CODE as et, attachmentsContext as f, webPrincipal as ft, ATTACHMENT_URL_PROTOCOL as g, chatAddressOf as gt, ATTACHMENT_TTL_HOURS as h, SESSION_HEADER as ht, memberIdOf as i, WEB_PROVIDER as it, ontologyTools as j, RUNTIME_SOURCE_PROTOCOL as jt, actionToolName as k, safeTelegramFetch as kt, runInboundRequest as l, webAuth as lt, turnContent as m, CHAT_HEADER as mt, chatLanguage as n, WEB_AUTHENTICATOR as nt, telegramPrincipal as o, guestIdOf as ot, storeFiles as p, CHAT_ATTRIBUTE as pt, ACCESS_TOKEN_PREFIX as q, identityProviderOf as r, WEB_GRANT_ATTRIBUTE as rt, InboundRequest as s, guestPrincipal as st, TELEGRAM_AUTHENTICATOR as t, TurnLimitedError as tt, withReplacedText as u, webGrantOf as ut, EARLIER_CHAT_HEADER as v, isSameChat as vt, actAsHeaders as w, customerMessage as wt, attachmentUrl as x, currentLocale as xt, MAXIMUM_ATTACHMENT_BYTES as y, withChatAddress as yt, ActorRequiredError as z };
1998
+ export { KIND_ATTRIBUTE as $, ontologyToolLabels as A, safeTelegramFetch as At, actorHeaders as B, parseAttachmentUrl as C, currentThreadId as Ct, OntologyFileUnavailable as D, failureText as Dt, OntologyActionNotPermitted as E, customerText as Et, confirmations as F, runtimeEnvelope as Ft, memberTool as G, actorOf as H, inputHash as I, telegramRuntimeSource as It, AGENT_GRANT_HEADER as J, notForGuests as K, needsConfirmation as L, promotionTarget as M, RUNTIME_SOURCE_PROTOCOL as Mt, CONFIRMATION_TTL_MS as N, compatibleRuntimeEnvelope as Nt, OntologyToolRejected as O, formattingRefused as Ot, actionApproval as P, principalRuntimeSource as Pt, INTROSPECTION_PATH as Q, ACT_AS_HEADER as R, fetchStoredAttachment as S, currentLocale as St, ontologyConnection as T, customerMessage as Tt, isGuestSession as U, actorKey as V, member as W, GUEST_ID_ATTRIBUTE as X, GUEST_CONFIRMATIONS_ATTRIBUTE as Y, GUEST_ROLE as Z, AttachmentError as _, chatChannel as _t, rolesOf as a, guestConfirms as at, agentAttachments as b, withChatAddress as bt, currentInboundRequest as c, ontologyIntrospection as ct, prepareInboundMedia as d, webMemberOf as dt, TURN_LIMITED_CODE as et, attachmentsContext as f, webPrincipal as ft, ATTACHMENT_URL_PROTOCOL as g, chatAddressOf as gt, ATTACHMENT_TTL_HOURS as h, SESSION_HEADER as ht, memberIdOf as i, WEB_PROVIDER as it, ontologyTools as j, withDeliveryLocale as jt, actionToolName as k, reportTelegramError as kt, runInboundRequest as l, webAuth as lt, turnContent as m, CHAT_HEADER as mt, chatLanguage as n, WEB_AUTHENTICATOR as nt, telegramPrincipal as o, guestIdOf as ot, storeFiles as p, CHAT_ATTRIBUTE as pt, ACCESS_TOKEN_PREFIX as q, identityProviderOf as r, WEB_GRANT_ATTRIBUTE as rt, InboundRequest as s, guestPrincipal as st, TELEGRAM_AUTHENTICATOR as t, TurnLimitedError as tt, withReplacedText as u, webGrantOf as ut, EARLIER_CHAT_HEADER as v, chatHeaders as vt, actAsHeaders as w, customerCopy as wt, attachmentUrl as x, TelegramDeliveryError as xt, MAXIMUM_ATTACHMENT_BYTES as y, isSameChat as yt, ActorRequiredError as z };
@@ -1,7 +1,8 @@
1
1
  /**
2
- * `POST /eve/segmentstream/v1/email`: the mailbox of the connection named in `channels.email`.
3
- * SegmentStream wakes it when Gmail pushes a change and at least every `checkAfterMinutes`.
4
- * Without that setting, or outside production, the route answers 404.
2
+ * `POST /eve/segmentstream/v1/email`: the mailbox of the connection named in `channels.email`, and
3
+ * `POST /eve/segmentstream/v1/email/<name>` that of every other channel of kind `email`.
4
+ * SegmentStream wakes each when Gmail pushes a change and at least every `checkAfterMinutes`.
5
+ * Without such a channel, or outside production, the route answers 404.
5
6
  */
6
7
  declare const _default: import("eve/channels").Channel<undefined, Record<string, unknown>, Record<string, unknown>>;
7
8
  export default _default;
@@ -4,11 +4,12 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
+ import { channelOf } from "../config.mjs";
7
8
  import segmentstream from "../extension.mjs";
8
9
  import { segmentstreamEmail } from "../lib/email/channel.mjs";
9
10
  import { decide } from "eve/ai";
10
11
  var email_default = segmentstreamEmail({
11
- settings: () => segmentstream.config.channels.email,
12
+ settings: (name) => channelOf(segmentstream.config.channels, "email", name),
12
13
  admission: () => segmentstream.config,
13
14
  models: () => segmentstream.config.models,
14
15
  review: {
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * `POST /eve/v1/slack`: the bot of the workspace's `SlackConnection`, through the Slack app
3
- * SegmentStream created for it and named in `channels.slack`. SegmentStream relays the app's
4
- * events, interactions and slash commands here. Without that setting, or outside production, the
5
- * route answers 404.
3
+ * SegmentStream created for it and named in `channels.slack`, and
4
+ * `POST /eve/segmentstream/v1/slack/<name>` the app of every other channel of kind `slack`.
5
+ * SegmentStream relays each app's events, interactions and slash commands to its channel. Without
6
+ * such a channel, or outside production, the route answers 404.
6
7
  */
7
8
  declare const _default: import("eve/channels/slack").SlackChannel;
8
9
  export default _default;
@@ -4,10 +4,11 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
+ import { channelOf } from "../config.mjs";
7
8
  import segmentstream from "../extension.mjs";
8
9
  import { segmentstreamSlack } from "../lib/slack/adapter.mjs";
9
10
  var slack_default = segmentstreamSlack({
10
- settings: () => segmentstream.config.channels.slack,
11
+ settings: (name) => channelOf(segmentstream.config.channels, "slack", name),
11
12
  admission: () => segmentstream.config,
12
13
  groups: () => segmentstream.config.groups,
13
14
  models: () => segmentstream.config.models
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * `segmentstream__telegram` at `POST /eve/v1/telegram`: the workspace's Telegram bot, reached
3
- * through the connection named in `channels.telegram`. Without that setting the route answers 404.
3
+ * through the connection named in `channels.telegram`, and at
4
+ * `POST /eve/segmentstream/v1/telegram/<name>` the bot of every other channel of kind `telegram`.
5
+ * Without such a channel the route answers 404.
4
6
  */
5
7
  declare const _default: import("eve/channels/telegram").TelegramChannel;
6
8
  export default _default;
@@ -4,11 +4,12 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
+ import { channelOf } from "../config.mjs";
7
8
  import segmentstream from "../extension.mjs";
8
9
  import { segmentstreamTelegram } from "../lib/telegram/adapter.mjs";
9
10
  import { decide } from "eve/ai";
10
11
  var telegram_default = segmentstreamTelegram({
11
- settings: () => segmentstream.config.channels.telegram,
12
+ settings: (name) => channelOf(segmentstream.config.channels, "telegram", name),
12
13
  groups: () => segmentstream.config.groups,
13
14
  models: () => segmentstream.config.models,
14
15
  confirmationMode: () => "native",
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * `POST /eve/v1/whatsapp`: the workspace's WhatsApp number, through the connection named in
3
- * `channels.whatsapp`. SegmentStream relays the number's messages here. Without that setting, or
4
- * outside production, the route answers 404.
3
+ * `channels.whatsapp`, and `POST /eve/segmentstream/v1/whatsapp/<name>` the number of every other
4
+ * channel of kind `whatsapp`. SegmentStream relays each number's messages to its channel. Without
5
+ * such a channel, or outside production, the route answers 404.
5
6
  */
6
7
  declare const _default: import("eve/channels/chat-sdk").ChatSdkChannel;
7
8
  export default _default;
@@ -4,11 +4,12 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
+ import { channelOf } from "../config.mjs";
7
8
  import segmentstream from "../extension.mjs";
8
9
  import { segmentstreamWhatsApp } from "../lib/whatsapp/adapter.mjs";
9
10
  import { decide } from "eve/ai";
10
11
  var whatsapp_default = segmentstreamWhatsApp({
11
- settings: () => segmentstream.config.channels.whatsapp,
12
+ settings: (name) => channelOf(segmentstream.config.channels, "whatsapp", name),
12
13
  admission: () => segmentstream.config,
13
14
  models: () => segmentstream.config.models,
14
15
  review: {
@@ -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,122 @@ 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
+ /** 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;
254
316
  export interface TelegramSettings {
255
317
  readonly groups?: {
256
318
  readonly replyEdgeIsAddress?: boolean;
@@ -291,15 +353,52 @@ export type SessionScope = (typeof SESSION_SCOPES)[number];
291
353
  export interface SessionSettings {
292
354
  readonly scope: SessionScope;
293
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;
294
398
  /** The validated configuration with defaults applied. It stays JSON-serializable. */
295
399
  export interface SegmentStreamAgentConfig extends AdmissionSettings {
296
400
  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
- };
401
+ readonly channels: ChannelsSettings;
303
402
  readonly models: {
304
403
  /**
305
404
  * `null` when the JSON sets none. The platform reads it at deploy; `agent.ts` passes the same