@segmentstream/agent 0.55.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 (87) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +2 -0
  3. package/dist/_chunks/{build-metadata-CYSFZe6f.mjs → build-metadata-DqDm9a2E.mjs} +1 -1
  4. package/dist/_chunks/{principal-DIgU-kPR.mjs → principal-TJ6zB2rF.mjs} +6 -2
  5. package/dist/extension/config.d.ts +54 -7
  6. package/dist/extension/config.mjs +65 -6
  7. package/dist/extension/connections/ontology.mjs +1 -1
  8. package/dist/extension/extension.d.ts +7 -1
  9. package/dist/extension/extension.mjs +2 -1
  10. package/dist/extension/hooks/authorization.mjs +1 -1
  11. package/dist/extension/instructions/persona.mjs +1 -1
  12. package/dist/extension/lib/actor.mjs +1 -1
  13. package/dist/extension/lib/attachment-tools.mjs +1 -1
  14. package/dist/extension/lib/attachments-send.mjs +1 -1
  15. package/dist/extension/lib/attachments.d.ts +1 -1
  16. package/dist/extension/lib/attachments.mjs +1 -1
  17. package/dist/extension/lib/build-metadata.mjs +1 -1
  18. package/dist/extension/lib/chat-address.d.ts +10 -2
  19. package/dist/extension/lib/chat-address.mjs +1 -1
  20. package/dist/extension/lib/chat-archive.d.ts +10 -0
  21. package/dist/extension/lib/chat-archive.mjs +15 -0
  22. package/dist/extension/lib/chat-context.mjs +1 -1
  23. package/dist/extension/lib/chat-post-confirmation.d.ts +1 -1
  24. package/dist/extension/lib/chat-post-confirmation.mjs +3 -2
  25. package/dist/extension/lib/chat-recorder.mjs +7 -3
  26. package/dist/extension/lib/confirmations.mjs +1 -1
  27. package/dist/extension/lib/email/attachments-send.mjs +1 -1
  28. package/dist/extension/lib/email/channel.mjs +1 -1
  29. package/dist/extension/lib/guest-usage.mjs +1 -1
  30. package/dist/extension/lib/inbound-media/files.mjs +1 -1
  31. package/dist/extension/lib/inbound-media/index.mjs +1 -1
  32. package/dist/extension/lib/ontology-connection.mjs +1 -1
  33. package/dist/extension/lib/ontology-file-call.mjs +1 -1
  34. package/dist/extension/lib/ontology-tools.mjs +1 -1
  35. package/dist/extension/lib/review/hold.d.ts +1 -1
  36. package/dist/extension/lib/review/hold.mjs +3 -2
  37. package/dist/extension/lib/review/reply.mjs +1 -1
  38. package/dist/extension/lib/role-skill.mjs +1 -1
  39. package/dist/extension/lib/runtime-envelope.mjs +1 -1
  40. package/dist/extension/lib/sent-files.mjs +1 -1
  41. package/dist/extension/lib/slack/adapter.mjs +1 -1
  42. package/dist/extension/lib/slack/attachments-send.mjs +1 -1
  43. package/dist/extension/lib/stored-files.mjs +1 -1
  44. package/dist/extension/lib/telegram/adapter.mjs +2 -2
  45. package/dist/extension/lib/telegram/attachment-description.mjs +1 -1
  46. package/dist/extension/lib/telegram/attachments-send.mjs +1 -1
  47. package/dist/extension/lib/telegram/callbacks.mjs +1 -1
  48. package/dist/extension/lib/telegram/chat-archive.mjs +1 -1
  49. package/dist/extension/lib/telegram/confirmations.mjs +1 -1
  50. package/dist/extension/lib/telegram/customer-text.mjs +1 -1
  51. package/dist/extension/lib/telegram/files.mjs +1 -1
  52. package/dist/extension/lib/telegram/health.mjs +1 -1
  53. package/dist/extension/lib/telegram/held-approvals.mjs +1 -1
  54. package/dist/extension/lib/telegram/inbound-request.mjs +1 -1
  55. package/dist/extension/lib/telegram/inbound.mjs +1 -1
  56. package/dist/extension/lib/telegram/lifecycle.mjs +2 -2
  57. package/dist/extension/lib/telegram/principal.mjs +1 -1
  58. package/dist/extension/lib/telegram/session-recovery.mjs +1 -1
  59. package/dist/extension/lib/telegram/silent.mjs +1 -1
  60. package/dist/extension/lib/telegram/structured.mjs +1 -1
  61. package/dist/extension/lib/telegram/turn-errors.mjs +1 -1
  62. package/dist/extension/lib/telegram/workspace-action.mjs +1 -1
  63. package/dist/extension/lib/web/auth.mjs +1 -1
  64. package/dist/extension/lib/web/channel.mjs +1 -1
  65. package/dist/extension/lib/whatsapp/adapter.mjs +1 -1
  66. package/dist/extension/lib/whatsapp/attachments-send.mjs +1 -1
  67. package/dist/extension/lib/whatsapp/files.mjs +1 -1
  68. package/dist/extension/lib/workspace-channel/attachments-send.d.ts +35 -0
  69. package/dist/extension/lib/workspace-channel/attachments-send.mjs +119 -0
  70. package/dist/extension/lib/workspace-channel/channel.d.ts +229 -0
  71. package/dist/extension/lib/workspace-channel/channel.mjs +525 -0
  72. package/dist/extension/lib/workspace-channel/connection.d.ts +55 -0
  73. package/dist/extension/lib/workspace-channel/connection.mjs +68 -0
  74. package/dist/extension/lib/workspace-channel/secrets.d.ts +32 -0
  75. package/dist/extension/lib/workspace-channel/secrets.mjs +55 -0
  76. package/dist/extension/lib/workspace-source.mjs +1 -1
  77. package/dist/extension/model.mjs +1 -1
  78. package/dist/extension/tools/attachments_discard.mjs +1 -1
  79. package/dist/extension/tools/attachments_list.mjs +1 -1
  80. package/dist/extension/tools/attachments_promote.mjs +1 -1
  81. package/dist/extension/tools/attachments_read.mjs +1 -1
  82. package/dist/extension/tools/attachments_send.mjs +6 -2
  83. package/dist/extension/tools/attachments_stage.mjs +1 -1
  84. package/dist/extension/tools/attachments_table.mjs +1 -1
  85. package/dist/extension/tools/questions_ask.mjs +1 -1
  86. package/dist/extension/tools/workspace_source.mjs +1 -1
  87. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.56.1
4
+
5
+ Pins @segmentstream/ontology 0.113.0.
6
+
7
+ ## 0.56.0
8
+
9
+ A workspace can define a channel in its own code for any provider with an API, such as a CRM
10
+ inbox or a marketplace's buyer chat. `defineChannel({ name, config, receive, parse, send, limits })`
11
+ in `agent/agent/channels/<name>.ts` supplies the provider's part: a webhook `verify`, or a
12
+ `poll.read` the platform wakes with a cursor; `parse`, which maps an event to
13
+ `{ id, chatId, sender, text, files }`; and `send`, which sends through the channel's connection.
14
+ The platform does the rest as on its own channels: admission and sign-up, limits, sessions and
15
+ chat keys, the archive, review holds, attachments both ways with `limits.files`, chat provenance
16
+ and figures. `agent/segmentstream.json` declares it as
17
+ `channels.<name>: { kind: "custom", connection, receive?: "webhook" | "poll", checkAfterMinutes?,
18
+ secret? }`. `verify(request, { signedWith, matches })` checks a delivery against the workspace
19
+ secret `secret` names, which only the platform reads, as the ontology's webhooks are checked.
20
+
21
+ Its people's accounts are its own, `channel:<name>`: it can claim no Telegram, WhatsApp or email
22
+ account. Its chats are private, and the channel shows no confirmation buttons. A reply a member
23
+ approves, or a chat post to one of its chats, reaches the person through the channel's
24
+ `/eve/segmentstream/v1/custom/<name>/send`, which only the deployment's own functions may call;
25
+ a chat post goes to the chat the person last wrote from there. The agent previews a chat post to a
26
+ workspace channel with the text as written. The archive shows a reply once `send` returned. A
27
+ delivery or a read holding more than 50 messages is refused whole, before any starts a turn.
28
+ `custom` is a kind, never a channel's name.
29
+
30
+ Action required: before deploying a workspace channel, upgrade the ontology SDK and declare it in
31
+ `defineOntology({ chat: { <name>: { kind: "custom" } } })`, so approved replies and chat posts
32
+ reach it; list `channel:<name>` in `signUp.channels` for its strangers to sign up.
33
+
34
+ Pins @segmentstream/ontology 0.112.0.
35
+
3
36
  ## 0.55.0
4
37
 
5
38
  An agent answers on several channels of one kind: two WhatsApp numbers, a few Telegram bots,
package/README.md CHANGED
@@ -129,6 +129,8 @@ See [Sandbox](#sandbox).
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
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" |
132
+ | `channels.<name>.receive` | `"webhook"` | A workspace channel (`kind: "custom"`, defined with `defineChannel`): `webhook`, its provider calls it, or `poll`, the platform wakes it every `checkAfterMinutes`; see `docs/agent.md`, "Workspace channels" |
133
+ | `channels.<name>.secret` | none | A workspace channel's workspace secret, which its `verify` checks deliveries against with `signedWith` or `matches`; only the platform reads it |
132
134
  | `models.stt` | `"spacexai/grok-stt"` | The AI Gateway transcription model for voice messages; `false` leaves them untranscribed |
133
135
  | `models.imageDescription` | `google/gemini-2.5-flash-lite` | Image evidence for group routing even with native vision; `false` disables descriptions |
134
136
  | `models.decision` | `"typesafe-ai/jev-1.14.0"` | The AI Gateway decision model of the inbound router |
@@ -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.55.0";
7
+ var version = "0.56.1";
8
8
  function agentBuild(environment = process.env) {
9
9
  return {
10
10
  agent: version,
@@ -401,7 +401,7 @@ function parsedChatAddress(value, provider) {
401
401
  if (typeof value !== "object" || value === null || Array.isArray(value)) return;
402
402
  const item = value;
403
403
  const text = (field, empty = false) => typeof field === "string" && (empty || field !== "") && field.length <= 512;
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;
404
+ if (item.provider !== "slack" && item.provider !== "whatsapp" && item.provider !== "web" && item.provider !== "email" && item.provider !== "custom" || (item.provider === "custom" ? typeof item.channel !== "string" || provider !== workspaceIdentityProvider(item.channel) : 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;
405
405
  return {
406
406
  provider: item.provider,
407
407
  ...item.channel === void 0 ? {} : { channel: item.channel },
@@ -411,6 +411,9 @@ function parsedChatAddress(value, provider) {
411
411
  ...item.peer === void 0 ? {} : { peer: item.peer }
412
412
  };
413
413
  }
414
+ function workspaceIdentityProvider(channel) {
415
+ return `channel:${channel}`;
416
+ }
414
417
  function chatChannel(chat) {
415
418
  return chat.channel ?? chat.provider;
416
419
  }
@@ -841,6 +844,7 @@ function actionApproval(options) {
841
844
  if (saved !== void 0) return denied("The original call is waiting for its Confirm / Cancel buttons.");
842
845
  if (!posting && !needsConfirmation(labels)) return "approved";
843
846
  if (chat?.provider === "email") return denied("Email shows no confirmation buttons, so this action cannot run from mail. Say in your reply what you would do; a member can run it.");
847
+ if (chat?.provider === "custom") return denied("This chat shows no confirmation buttons, so this action cannot run from it. Say in your reply what you would do; a member can run it.");
844
848
  if (labels.confirmation === true && labels.preview !== true && copy === void 0) return missingCopy();
845
849
  try {
846
850
  if (!posting) description = await options.describe?.(confirmer, ctx.toolName, businessInput, hints, confirmationLocale(ctx.session.auth.current));
@@ -1995,4 +1999,4 @@ function identityProviderOf(principal) {
1995
1999
  const provider = principal?.attributes.identityProvider;
1996
2000
  return typeof provider === "string" && provider !== "" ? provider : void 0;
1997
2001
  }
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 };
2002
+ export { KIND_ATTRIBUTE as $, ontologyToolLabels as A, reportTelegramError as At, actorHeaders as B, parseAttachmentUrl as C, currentLocale as Ct, OntologyFileUnavailable as D, customerText as Dt, OntologyActionNotPermitted as E, customerMessage as Et, confirmations as F, principalRuntimeSource as Ft, memberTool as G, actorOf as H, inputHash as I, runtimeEnvelope as It, AGENT_GRANT_HEADER as J, notForGuests as K, needsConfirmation as L, telegramRuntimeSource as Lt, promotionTarget as M, withDeliveryLocale as Mt, CONFIRMATION_TTL_MS as N, RUNTIME_SOURCE_PROTOCOL as Nt, OntologyToolRejected as O, failureText as Ot, actionApproval as P, compatibleRuntimeEnvelope as Pt, INTROSPECTION_PATH as Q, ACT_AS_HEADER as R, fetchStoredAttachment as S, TelegramDeliveryError as St, ontologyConnection as T, customerCopy 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, safeTelegramFetch as jt, actionToolName as k, formattingRefused 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, currentThreadId as wt, attachmentUrl as x, workspaceIdentityProvider as xt, MAXIMUM_ATTACHMENT_BYTES as y, isSameChat as yt, ActorRequiredError as z };
@@ -259,6 +259,26 @@ export interface EmailChannelInput {
259
259
  readonly topic: string;
260
260
  };
261
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
+ }
262
282
  /** A channel named other than its kind, as authored: its settings and its `kind`. */
263
283
  export type NamedChannelInput = ({
264
284
  readonly kind: "telegram";
@@ -268,7 +288,9 @@ export type NamedChannelInput = ({
268
288
  readonly kind: "slack";
269
289
  } & SlackChannelInput) | ({
270
290
  readonly kind: "email";
271
- } & EmailChannelInput);
291
+ } & EmailChannelInput) | ({
292
+ readonly kind: "custom";
293
+ } & WorkspaceChannelInput);
272
294
  /**
273
295
  * `channels` as authored: the channel named after each kind, and any other channel with its kind.
274
296
  * A JSON import widens `kind` to `string`, so the other names accept any object here; validation
@@ -295,11 +317,21 @@ export interface ChannelsInput {
295
317
  readonly kind?: string;
296
318
  }) | (EmailChannelInput & {
297
319
  readonly kind?: string;
320
+ }) | (WorkspaceChannelInput & {
321
+ readonly kind?: string;
298
322
  }) | undefined;
299
323
  }
300
324
  /** The kinds of channel the agent answers on: what a channel's name or `kind` says it is. */
301
325
  export declare const CHANNEL_KINDS: readonly ["telegram", "whatsapp", "slack", "email"];
302
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;
303
335
  /**
304
336
  * A channel's name. It keys the channel's chats everywhere the platform keeps them, its wake-ups
305
337
  * and its webhook, and names it to the ontology's `chat`.
@@ -307,7 +339,8 @@ export type ChannelKind = (typeof CHANNEL_KINDS)[number];
307
339
  export declare const CHANNEL_NAME: RegExp;
308
340
  /**
309
341
  * 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`.
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.
311
344
  */
312
345
  export declare const RESERVED_CHANNEL_NAMES: ReadonlyArray<string>;
313
346
  /** The most channels one agent declares, of every kind together. */
@@ -359,13 +392,14 @@ export interface ChannelSettingsByKind {
359
392
  readonly whatsapp: WhatsAppSettings;
360
393
  readonly slack: SlackSettings;
361
394
  readonly email: EmailSettings;
395
+ readonly custom: WorkspaceChannelSettings;
362
396
  }
363
397
  /** A channel named other than its kind: its settings, with its `kind`. */
364
398
  export type NamedChannelSettings = {
365
- readonly [K in ChannelKind]: {
399
+ readonly [K in AgentChannelKind]: {
366
400
  readonly kind: K;
367
401
  } & ChannelSettingsByKind[K];
368
- }[ChannelKind];
402
+ }[AgentChannelKind];
369
403
  /**
370
404
  * The channels, by name. The channel named after each kind keeps that key, as it always had, and
371
405
  * `null` when the agent has none; it carries no `kind`. Every other channel carries its `kind`.
@@ -380,7 +414,7 @@ export interface ChannelsSettings {
380
414
  readonly [name: string]: ChannelSettingsByKind[ChannelKind] | NamedChannelSettings | null;
381
415
  }
382
416
  /** One channel the agent answers on: its name, its kind and its settings. */
383
- export interface DeclaredChannel<K extends ChannelKind = ChannelKind> {
417
+ export interface DeclaredChannel<K extends AgentChannelKind = AgentChannelKind> {
384
418
  readonly name: string;
385
419
  readonly kind: K;
386
420
  readonly settings: ChannelSettingsByKind[K];
@@ -392,9 +426,9 @@ export interface DeclaredChannel<K extends ChannelKind = ChannelKind> {
392
426
  */
393
427
  export declare function declaredChannels(channels: Readonly<Record<string, unknown>> | null | undefined): ReadonlyArray<DeclaredChannel>;
394
428
  /** 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>>;
429
+ export declare function channelsOfKind<K extends AgentChannelKind>(channels: Readonly<Record<string, unknown>> | null | undefined, kind: K): ReadonlyArray<DeclaredChannel<K>>;
396
430
  /** 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;
431
+ export declare function channelOf<K extends AgentChannelKind>(channels: Readonly<Record<string, unknown>> | null | undefined, kind: K, name: string): ChannelSettingsByKind[K] | null;
398
432
  /** The validated configuration with defaults applied. It stays JSON-serializable. */
399
433
  export interface SegmentStreamAgentConfig extends AdmissionSettings {
400
434
  readonly groups: GroupPolicy;
@@ -498,6 +532,19 @@ export interface EmailSettings {
498
532
  readonly topic: string;
499
533
  } | null;
500
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
+ }
501
548
  /**
502
549
  * The web the agent may read. `domains` are bare lower-case host names, such as `example.com`;
503
550
  * each covers itself and its subdomains. Only `https://` pages of them are fetched, and every
@@ -55,8 +55,16 @@ const CHANNEL_KINDS = [
55
55
  "slack",
56
56
  "email"
57
57
  ];
58
+ const WORKSPACE_CHANNEL_KIND = "custom";
59
+ function isAgentChannelKind(value) {
60
+ return isChannelKind(value) || value === "custom";
61
+ }
58
62
  const CHANNEL_NAME = /^[a-z][a-z0-9_]{0,31}$/;
59
- const RESERVED_CHANNEL_NAMES = ["web", "task"];
63
+ const RESERVED_CHANNEL_NAMES = [
64
+ "web",
65
+ "task",
66
+ WORKSPACE_CHANNEL_KIND
67
+ ];
60
68
  const MAXIMUM_CHANNELS = 20;
61
69
  function isChannelKind(value) {
62
70
  return CHANNEL_KINDS.some((kind) => kind === value);
@@ -67,7 +75,7 @@ function declaredChannels(channels) {
67
75
  const entries = Object.entries(channels).flatMap(([name, value]) => {
68
76
  if (!isRecord(value) || typeof value.connection !== "string") return [];
69
77
  const kind = value.kind ?? name;
70
- if (!isChannelKind(kind) || isChannelKind(name) && name !== kind) return [];
78
+ if (!isAgentChannelKind(kind) || isChannelKind(name) && name !== kind || name === "custom") return [];
71
79
  return [{
72
80
  name,
73
81
  kind,
@@ -222,6 +230,57 @@ const EMAIL_CHECK_MINUTES = {
222
230
  };
223
231
  const DEFAULT_EMAIL_QUERY = "in:inbox";
224
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
+ }
225
284
  const MAXIMUM_WEB_DOMAINS = 50;
226
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])?$/;
227
286
  function webSettings(value, issues) {
@@ -513,14 +572,14 @@ function channelSettings(channels, issues) {
513
572
  continue;
514
573
  }
515
574
  const kind = value.kind;
516
- if (!isChannelKind(kind)) {
575
+ if (!isAgentChannelKind(kind)) {
517
576
  issues.push({
518
- message: `must name the channel's kind: ${CHANNEL_KINDS.join(", ")}`,
577
+ message: `must name the channel's kind: ${[...CHANNEL_KINDS, WORKSPACE_CHANNEL_KIND].join(", ")}`,
519
578
  path: [...path, "kind"]
520
579
  });
521
580
  continue;
522
581
  }
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);
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);
524
583
  if (settings !== null) result[name] = {
525
584
  kind,
526
585
  ...settings
@@ -1162,4 +1221,4 @@ function manifestOf(config) {
1162
1221
  if (validation.issues !== void 0) throw new SegmentStreamAgentConfigError(validation.issues);
1163
1222
  return validation.value;
1164
1223
  }
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 };
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-DIgU-kPR.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";
@@ -6,6 +6,7 @@ __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { DEFAULT_ADMISSION_LIMITS, DEFAULT_DECISION_MODEL, DEFAULT_STT_MODEL, SegmentStreamAgentConfigError, configSchema, manifestOf } from "./config.mjs";
8
8
  import { chooseModel, model } from "./model.mjs";
9
+ import { defineChannel } from "./lib/workspace-channel/channel.mjs";
9
10
  import { forRoles } from "./lib/role-skill.mjs";
10
11
  import { DEFAULT_GROUP_POLICY, effectiveGroupPolicy, groupPolicy } from "./lib/group-routing/policy.mjs";
11
12
  import { addressingReason, chatKey } from "./lib/group-routing/signals.mjs";
@@ -22,4 +23,4 @@ const segmentstream = Object.assign(extension, {
22
23
  model,
23
24
  manifestOf
24
25
  });
25
- export { DEFAULT_ADMISSION_LIMITS, DEFAULT_DECISION_MODEL, DEFAULT_GROUP_POLICY, DEFAULT_STT_MODEL, SegmentStreamAgentConfigError, archivedRoutingMessages, chatKey, chooseModel, segmentstream as default, segmentstream, defineAgent, effectiveGroupPolicy, forRoles, addressingReason as groupAddressingReason, agentMessage as groupAgentMessage, chatAddressing as groupChatAddressing, decisionRouter as groupDecisionRouter, groupPolicy, manifestOf, model, replayRouterPayload, routeMessage as routeGroupMessage, routingBurst };
26
+ export { DEFAULT_ADMISSION_LIMITS, DEFAULT_DECISION_MODEL, DEFAULT_GROUP_POLICY, DEFAULT_STT_MODEL, SegmentStreamAgentConfigError, archivedRoutingMessages, chatKey, chooseModel, segmentstream as default, segmentstream, defineAgent, defineChannel, effectiveGroupPolicy, forRoles, addressingReason as groupAddressingReason, agentMessage as groupAgentMessage, chatAddressing as groupChatAddressing, decisionRouter as groupDecisionRouter, groupPolicy, manifestOf, model, replayRouterPayload, routeMessage as routeGroupMessage, routingBurst };
@@ -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-DIgU-kPR.mjs";
10
+ import "../../_chunks/principal-TJ6zB2rF.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;
@@ -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 { a as rolesOf } from "../../_chunks/principal-DIgU-kPR.mjs";
8
+ import { a as rolesOf } from "../../_chunks/principal-TJ6zB2rF.mjs";
9
9
  import { personaFor } from "../personas.mjs";
10
10
  import { defineDynamic, defineInstructions } from "eve/instructions";
11
11
  var persona_default = defineDynamic((context) => {
@@ -4,4 +4,4 @@ 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
- export { R as ACT_AS_HEADER, z as ActorRequiredError, B as actorHeaders, V as actorKey, H as actorOf, U as isGuestSession, W as member, G as memberTool, K as notForGuests } from "../../_chunks/principal-DIgU-kPR.mjs";
7
+ export { R as ACT_AS_HEADER, z as ActorRequiredError, B as actorHeaders, V as actorKey, H as actorOf, U as isGuestSession, W as member, G as memberTool, K as notForGuests } from "../../_chunks/principal-TJ6zB2rF.mjs";
@@ -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
- import { _t as chatChannel, b as agentAttachments, gt as chatAddressOf, i as memberIdOf } from "../../_chunks/principal-DIgU-kPR.mjs";
7
+ import { _t as chatChannel, b as agentAttachments, gt as chatAddressOf, i as memberIdOf } from "../../_chunks/principal-TJ6zB2rF.mjs";
8
8
  import { detectFile, documentText } from "./attachment-formats.mjs";
9
9
  import { readSheets, typedTable } from "./attachment-tables.mjs";
10
10
  import { appOrigin } from "./environment.mjs";
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { attachmentOwner } from "./attachment-tools.mjs";
8
- import { Dt as failureText, _ as AttachmentError, gt as chatAddressOf } from "../../_chunks/principal-DIgU-kPR.mjs";
8
+ import { Ot as failureText, _ as AttachmentError, gt as chatAddressOf } from "../../_chunks/principal-TJ6zB2rF.mjs";
9
9
  import { appOrigin, channelsEnabled } from "./environment.mjs";
10
10
  import { transientFileStatus } from "./file-grant.mjs";
11
11
  import { runtimeToken } from "./runtime-token.mjs";
@@ -20,7 +20,7 @@ export declare const EARLIER_CHAT_HEADER = "X-SegmentStream-Agent-Conversation";
20
20
  /** The URL protocol of a file part that names a stored attachment instead of a Telegram file. */
21
21
  export declare const ATTACHMENT_URL_PROTOCOL = "segmentstream-attachment:";
22
22
  /** Where an attachment comes from: a channel's message, or the agent's sandbox. */
23
- export type AttachmentSource = "telegram" | "slack" | "whatsapp" | "email" | "sandbox";
23
+ export type AttachmentSource = "telegram" | "slack" | "whatsapp" | "email" | "sandbox" | "channel";
24
24
  /** Who asks for attachment access, from the turn: the member, chat and agent session. */
25
25
  export interface AttachmentOwner {
26
26
  readonly memberId: string;
@@ -4,4 +4,4 @@ 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
- export { h as ATTACHMENT_TTL_HOURS, g as ATTACHMENT_URL_PROTOCOL, _ as AttachmentError, mt as CHAT_HEADER, v as EARLIER_CHAT_HEADER, y as MAXIMUM_ATTACHMENT_BYTES, ht as SESSION_HEADER, b as agentAttachments, x as attachmentUrl, S as fetchStoredAttachment, C as parseAttachmentUrl } from "../../_chunks/principal-DIgU-kPR.mjs";
7
+ export { h as ATTACHMENT_TTL_HOURS, g as ATTACHMENT_URL_PROTOCOL, _ as AttachmentError, mt as CHAT_HEADER, v as EARLIER_CHAT_HEADER, y as MAXIMUM_ATTACHMENT_BYTES, ht as SESSION_HEADER, b as agentAttachments, x as attachmentUrl, S as fetchStoredAttachment, C as parseAttachmentUrl } from "../../_chunks/principal-TJ6zB2rF.mjs";
@@ -4,4 +4,4 @@ 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
- export { t as agentBuild } from "../../_chunks/build-metadata-CYSFZe6f.mjs";
7
+ export { t as agentBuild } from "../../_chunks/build-metadata-DqDm9a2E.mjs";
@@ -5,8 +5,11 @@ import type { SessionAuthContext } from "eve/context";
5
5
  * there the member's id on the provider, which a private destination on that provider names.
6
6
  */
7
7
  export interface ChatAddress {
8
- /** The kind of channel the chat is on, which decides how it behaves. */
9
- readonly provider: "telegram" | "slack" | "whatsapp" | "web" | "email";
8
+ /**
9
+ * The kind of channel the chat is on, which decides how it behaves: `custom` for a channel the
10
+ * workspace defines in its own code, which always names its `channel`.
11
+ */
12
+ readonly provider: "telegram" | "slack" | "whatsapp" | "web" | "email" | "custom";
10
13
  /**
11
14
  * The channel's name when it is not named after its kind, such as `sales_whatsapp`; absent for
12
15
  * the channel named after its kind. Read it with {@link chatChannel}.
@@ -42,6 +45,11 @@ export declare function chatAddressOf(principal?: SessionAuthContext | null): Ch
42
45
  * chat counts only as the member's or guest's own. A task has no chat, and sends none.
43
46
  */
44
47
  export declare function chatHeaders(principal: SessionAuthContext | null | undefined, sessionId?: string): Record<string, string>;
48
+ /**
49
+ * The provider of the accounts people write from on a workspace channel: `channel:<name>`, its
50
+ * own, so it can claim no Telegram, WhatsApp or email account, nor another workspace channel's.
51
+ */
52
+ export declare function workspaceIdentityProvider(channel: string): string;
45
53
  /**
46
54
  * The channel a chat is on, by name: what the archive, the chat registry, attachments and the
47
55
  * ontology's chat destinations key it by. The channel named after its kind is the kind.
@@ -4,4 +4,4 @@ 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
- export { pt as CHAT_ATTRIBUTE, mt as CHAT_HEADER, ht as SESSION_HEADER, gt as chatAddressOf, _t as chatChannel, vt as chatHeaders, yt as isSameChat, bt as withChatAddress } from "../../_chunks/principal-DIgU-kPR.mjs";
7
+ export { pt as CHAT_ATTRIBUTE, mt as CHAT_HEADER, ht as SESSION_HEADER, gt as chatAddressOf, _t as chatChannel, vt as chatHeaders, yt as isSameChat, bt as withChatAddress, xt as workspaceIdentityProvider } from "../../_chunks/principal-TJ6zB2rF.mjs";
@@ -84,6 +84,16 @@ export interface ChatArchive {
84
84
  readonly limit: number;
85
85
  readonly requestedBefore?: string;
86
86
  }): Promise<ChatPage>;
87
+ /**
88
+ * The chat of `provider` the person whose account is `senderId` last wrote in, read as the
89
+ * member `participantId`; undefined when they never wrote there. Archives that predate it have
90
+ * none.
91
+ */
92
+ lastChat?(input: {
93
+ readonly provider: string;
94
+ readonly senderId: string;
95
+ readonly participantId: string;
96
+ }): Promise<string | undefined>;
87
97
  }
88
98
  /** The archive operation of a channel's reply, which its states share: see {@link replyEvent}. */
89
99
  export declare function replyOperation(key: string): string;
@@ -141,6 +141,21 @@ function chatArchive(input = {}) {
141
141
  admin: false
142
142
  }
143
143
  }),
144
+ lastChat: async ({ provider, senderId, participantId }) => {
145
+ return (await call("search", {
146
+ search: {
147
+ provider,
148
+ senderId,
149
+ messagesOnly: true,
150
+ limit: 1
151
+ },
152
+ reader: {
153
+ participantId,
154
+ groups: false,
155
+ admin: false
156
+ }
157
+ })).events[0]?.chatId;
158
+ },
144
159
  pendingReplies: async ({ provider, limit, requestedBefore }) => await call("search", {
145
160
  search: {
146
161
  provider,
@@ -7,7 +7,7 @@ __eveCreateRequire(import.meta.url);
7
7
  import { agentTaskIdOf } from "./agent-task.mjs";
8
8
  import { chatCoordinates, sessionKind } from "./chat-recorder.mjs";
9
9
  import { chatArchive, collapseChatEvents, topicContext } from "./chat-archive.mjs";
10
- import { kt as reportTelegramError } from "../../_chunks/principal-DIgU-kPR.mjs";
10
+ import { At as reportTelegramError } from "../../_chunks/principal-TJ6zB2rF.mjs";
11
11
  import { createHash } from "node:crypto";
12
12
  import { deliveries, runs, turns } from "eve/events";
13
13
  import { defineState } from "eve/context";
@@ -5,7 +5,7 @@ export declare const CHAT_POST_ENVELOPE = "_segmentstream";
5
5
  /** The ontology's chat posting tool, without the connection's namespace. */
6
6
  export declare const CHAT_POST_TOOL = "chat_post_message";
7
7
  /** The kinds of channel whose chats this agent describes posts to; it refuses one elsewhere. */
8
- export type ChatPostProvider = "telegram" | "slack" | "whatsapp";
8
+ export type ChatPostProvider = "telegram" | "slack" | "whatsapp" | "custom";
9
9
  export interface ChatPostPreview {
10
10
  readonly chatId: string;
11
11
  /**
@@ -9,6 +9,7 @@ import { createHash } from "node:crypto";
9
9
  import { TelegramFormatConverter, escapeMarkdownV2 } from "@chat-adapter/telegram";
10
10
  import { renderSlack } from "@segmentstream/ontology/slack";
11
11
  import { renderWhatsApp } from "@segmentstream/ontology/whatsapp";
12
+ import { renderWorkspaceChannelText } from "@segmentstream/ontology/workspace-channel";
12
13
  const CHAT_POST_PROTOCOL = "segmentstream/chat-post";
13
14
  const CHAT_POST_ENVELOPE = "_segmentstream";
14
15
  const CHAT_POST_TOOL = "chat_post_message";
@@ -52,10 +53,10 @@ function describeChatPost(input) {
52
53
  target.title,
53
54
  target.external_id,
54
55
  caller.attribution
55
- ].every((value) => typeof value === "string" && value.length > 0) || typeof target.provider !== "string" || !target.provider || kind !== "telegram" && kind !== "slack" && kind !== "whatsapp" || kind === "whatsapp" && values.reply_to !== void 0 || target.id !== values.chat && target.title !== values.chat) throw new Error("An unambiguous destination and a complete exact chat preview are required.");
56
+ ].every((value) => typeof value === "string" && value.length > 0) || typeof target.provider !== "string" || !target.provider || kind !== "telegram" && kind !== "slack" && kind !== "whatsapp" && kind !== "custom" || kind === "whatsapp" && values.reply_to !== void 0 || target.id !== values.chat && target.title !== values.chat) throw new Error("An unambiguous destination and a complete exact chat preview are required.");
56
57
  const attribution = caller.attribution;
57
58
  const separator = typeof caller.attribution_separator === "string" ? caller.attribution_separator : "\n\n";
58
- const finalText = kind === "telegram" ? `${converter.fromMarkdown(values.text)}${escapeMarkdownV2(separator)}_${escapeMarkdownV2(attribution)}_` : kind === "slack" ? renderSlack(values.text, attribution, separator) : renderWhatsApp(values.text, attribution, separator);
59
+ const finalText = kind === "telegram" ? `${converter.fromMarkdown(values.text)}${escapeMarkdownV2(separator)}_${escapeMarkdownV2(attribution)}_` : kind === "slack" ? renderSlack(values.text, attribution, separator) : kind === "custom" ? renderWorkspaceChannelText(values.text, attribution, separator) : renderWhatsApp(values.text, attribution, separator);
59
60
  return {
60
61
  action: "",
61
62
  fields: [],
@@ -7,7 +7,7 @@ __eveCreateRequire(import.meta.url);
7
7
  import { n as contentText, t as CONTENT_CAPS } from "../../_chunks/content-cDtVnr8Y.mjs";
8
8
  import { chatArchive, chatEvent, sessionFailureEventId, summarizeArguments } from "./chat-archive.mjs";
9
9
  import { agentTaskIdOf } from "./agent-task.mjs";
10
- import { _t as chatChannel, gt as chatAddressOf, i as memberIdOf, ot as guestIdOf } from "../../_chunks/principal-DIgU-kPR.mjs";
10
+ import { _t as chatChannel, gt as chatAddressOf, i as memberIdOf, ot as guestIdOf } from "../../_chunks/principal-TJ6zB2rF.mjs";
11
11
  import { keyChannel, principalChannel } from "./channel-scope.mjs";
12
12
  import { parseAddress } from "./telegram/sessions.mjs";
13
13
  import { completionKind } from "./telegram/silent.mjs";
@@ -49,7 +49,7 @@ function chatCoordinates(context) {
49
49
  participantIds: [],
50
50
  senderId: `guest:${guestId}`
51
51
  };
52
- if (chat?.provider === "email" && webMemberId !== void 0) return {
52
+ if ((chat?.provider === "email" || chat?.provider === "custom") && webMemberId !== void 0) return {
53
53
  provider: chatChannel(chat),
54
54
  chatId: chat.chatId,
55
55
  chatType: "private",
@@ -79,7 +79,11 @@ function chatCoordinates(context) {
79
79
  senderId: principal?.subject ?? null
80
80
  };
81
81
  }
82
- const RECORDS_REPLIES = new Set(["telegram", "email"]);
82
+ const RECORDS_REPLIES = new Set([
83
+ "telegram",
84
+ "email",
85
+ "custom"
86
+ ]);
83
87
  const UNADDRESSED_SESSIONS_REMEMBERED = 1e3;
84
88
  function reportUnaddressed(event, context, reported) {
85
89
  const sessionId = context.session.id;
@@ -4,4 +4,4 @@ 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
- export { N as CONFIRMATION_TTL_MS, P as actionApproval, F as confirmations, I as inputHash, L as needsConfirmation } from "../../_chunks/principal-DIgU-kPR.mjs";
7
+ export { N as CONFIRMATION_TTL_MS, P as actionApproval, F as confirmations, I as inputHash, L as needsConfirmation } from "../../_chunks/principal-TJ6zB2rF.mjs";