@segmentstream/agent 0.69.2 → 0.71.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 (86) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/_chunks/{build-metadata-B1FvLdht.mjs → build-metadata-DliB5P2p.mjs} +1 -1
  3. package/dist/_chunks/{principal-DYl7vqOp.mjs → principal-BWTq_zuf.mjs} +106 -74
  4. package/dist/extension/channels/slack.mjs +1 -0
  5. package/dist/extension/channels/telegram.mjs +1 -0
  6. package/dist/extension/channels/whatsapp.mjs +1 -0
  7. package/dist/extension/config.d.ts +13 -5
  8. package/dist/extension/config.mjs +14 -0
  9. package/dist/extension/connections/ontology.mjs +1 -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.mjs +1 -1
  16. package/dist/extension/lib/build-metadata.mjs +1 -1
  17. package/dist/extension/lib/chat-address.d.ts +19 -2
  18. package/dist/extension/lib/chat-address.mjs +1 -1
  19. package/dist/extension/lib/chat-context.mjs +1 -1
  20. package/dist/extension/lib/chat-recorder.mjs +1 -1
  21. package/dist/extension/lib/confirmations.mjs +1 -1
  22. package/dist/extension/lib/email/attachments-send.mjs +1 -1
  23. package/dist/extension/lib/email/channel.mjs +1 -1
  24. package/dist/extension/lib/guest-usage.mjs +1 -1
  25. package/dist/extension/lib/inbound-media/files.mjs +1 -1
  26. package/dist/extension/lib/inbound-media/index.mjs +1 -1
  27. package/dist/extension/lib/ontology-connection.mjs +1 -1
  28. package/dist/extension/lib/ontology-file-call.mjs +1 -1
  29. package/dist/extension/lib/ontology-tools.d.ts +1 -0
  30. package/dist/extension/lib/ontology-tools.mjs +1 -1
  31. package/dist/extension/lib/review/hold.mjs +1 -1
  32. package/dist/extension/lib/review/reply.mjs +1 -1
  33. package/dist/extension/lib/role-skill.mjs +1 -1
  34. package/dist/extension/lib/runtime-envelope.d.ts +10 -1
  35. package/dist/extension/lib/runtime-envelope.mjs +1 -1
  36. package/dist/extension/lib/sent-files.mjs +1 -1
  37. package/dist/extension/lib/slack/adapter.d.ts +6 -0
  38. package/dist/extension/lib/slack/adapter.mjs +5 -2
  39. package/dist/extension/lib/slack/attachments-send.mjs +1 -1
  40. package/dist/extension/lib/slack/callbacks.d.ts +4 -4
  41. package/dist/extension/lib/slack/callbacks.mjs +21 -44
  42. package/dist/extension/lib/stored-files.mjs +1 -1
  43. package/dist/extension/lib/telegram/adapter.d.ts +6 -0
  44. package/dist/extension/lib/telegram/adapter.mjs +3 -3
  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 +43 -50
  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/web/auth.mjs +1 -1
  63. package/dist/extension/lib/web/channel.mjs +1 -1
  64. package/dist/extension/lib/whatsapp/adapter.d.ts +3 -0
  65. package/dist/extension/lib/whatsapp/adapter.mjs +48 -1
  66. package/dist/extension/lib/whatsapp/attachments-send.mjs +1 -1
  67. package/dist/extension/lib/whatsapp/callbacks.d.ts +55 -0
  68. package/dist/extension/lib/whatsapp/callbacks.mjs +132 -0
  69. package/dist/extension/lib/whatsapp/files.mjs +1 -1
  70. package/dist/extension/lib/workspace-action.d.ts +30 -0
  71. package/dist/extension/lib/workspace-action.mjs +36 -2
  72. package/dist/extension/lib/workspace-channel/attachments-send.mjs +1 -1
  73. package/dist/extension/lib/workspace-channel/channel.mjs +1 -1
  74. package/dist/extension/lib/workspace-source.mjs +1 -1
  75. package/dist/extension/model.mjs +1 -1
  76. package/dist/extension/tools/attachments_discard.mjs +1 -1
  77. package/dist/extension/tools/attachments_list.mjs +1 -1
  78. package/dist/extension/tools/attachments_promote.mjs +4 -3
  79. package/dist/extension/tools/attachments_read.mjs +1 -1
  80. package/dist/extension/tools/attachments_send.mjs +1 -1
  81. package/dist/extension/tools/attachments_stage.mjs +1 -1
  82. package/dist/extension/tools/attachments_table.mjs +1 -1
  83. package/dist/extension/tools/handoff.mjs +1 -1
  84. package/dist/extension/tools/questions_ask.mjs +1 -1
  85. package/dist/extension/tools/workspace_source.mjs +1 -1
  86. package/package.json +2 -2
@@ -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 { F as confirmations, H as actorOf, I as inputHash, It as runtimeEnvelope, P as actionApproval, V as actorKey, j as ontologyTools } from "../../_chunks/principal-DYl7vqOp.mjs";
7
+ import { F as confirmations, H as actorOf, I as inputHash, Ot as runtimeEnvelope, P as actionApproval, V as actorKey, j as ontologyTools } from "../../_chunks/principal-BWTq_zuf.mjs";
8
8
  import { isChatPost } from "./chat-post-confirmation.mjs";
9
9
  import { sandboxFile } from "./sandbox-session.mjs";
10
10
  import { saveOntologyResult } from "./ontology-result-file.mjs";
@@ -51,6 +51,7 @@ export declare function ontologyTools(options?: {
51
51
  }): {
52
52
  rpc: (actor: OntologyActor, method: string, params: Record<string, unknown>, signal?: AbortSignal) => Promise<Record<string, unknown>>;
53
53
  supportsRuntimeSource(actor: OntologyActor, signal?: AbortSignal): Promise<boolean>;
54
+ sourceProviders: (actor: OntologyActor, signal?: AbortSignal) => Promise<ReadonlySet<string>>;
54
55
  labels(actor: OntologyActor, action: string, input?: Readonly<Record<string, unknown>>, signal?: AbortSignal, hints?: ToolHints): Promise<ActionAnnotations>;
55
56
  describe(actor: OntologyActor, action: string, input: Readonly<Record<string, unknown>>, hints?: ToolHints, locale?: string): Promise<ConfirmationDescription>;
56
57
  };
@@ -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 { E as OntologyActionNotPermitted, D as OntologyFileUnavailable, O as OntologyToolRejected, k as actionToolName, A as ontologyToolLabels, j as ontologyTools, M as promotionTarget } from "../../_chunks/principal-DYl7vqOp.mjs";
7
+ export { E as OntologyActionNotPermitted, D as OntologyFileUnavailable, O as OntologyToolRejected, k as actionToolName, A as ontologyToolLabels, j as ontologyTools, M as promotionTarget } from "../../_chunks/principal-BWTq_zuf.mjs";
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { reviewFor } from "../../review.mjs";
8
- import { a as rolesOf, gt as chatAddressOf, i as memberIdOf } from "../../../_chunks/principal-DYl7vqOp.mjs";
8
+ import { Pt as chatAddressOf, a as rolesOf, i as memberIdOf } from "../../../_chunks/principal-BWTq_zuf.mjs";
9
9
  function reviewOf(settings, principal) {
10
10
  return reviewFor(settings, rolesOf(principal));
11
11
  }
@@ -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, gt as chatAddressOf, i as memberIdOf } from "../../../_chunks/principal-DYl7vqOp.mjs";
7
+ import { Ft as chatChannel, Pt as chatAddressOf, i as memberIdOf } from "../../../_chunks/principal-BWTq_zuf.mjs";
8
8
  import { chatArchive, chatEvent } from "../chat-archive.mjs";
9
9
  import { stampedChat } from "../chat-recorder.mjs";
10
10
  import { appOrigin } from "../environment.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 { a as rolesOf } from "../../_chunks/principal-DYl7vqOp.mjs";
7
+ import { a as rolesOf } from "../../_chunks/principal-BWTq_zuf.mjs";
8
8
  import { defineDynamic, defineSkill } from "eve/skills";
9
9
  function forRoles(roles, skill) {
10
10
  if (!Array.isArray(roles) || roles.length === 0 || !roles.every((role) => typeof role === "string" && role.trim() !== "")) throw new TypeError("forRoles() needs at least one role name; a skill for everyone is an ordinary skill file.");
@@ -19,7 +19,10 @@ export type RuntimeEnvelope = {
19
19
  };
20
20
  /** The source comes from the verified Telegram message and admitted storage results. */
21
21
  export declare function telegramRuntimeSource(message: Pick<TelegramMessage, "chat" | "messageId" | "messageThreadId" | "replyToMessage" | "from" | "raw" | "attachments">, files?: ReadonlyMap<string, StagedFile>, callbackQueryId?: string): TelegramRuntimeSource;
22
- /** Session auth is SDK-owned; no tool argument is read while rebuilding provenance. */
22
+ /**
23
+ * The source of the message a channel's turn answers. Session auth is SDK-owned: each channel
24
+ * writes it from the verified message, and no tool argument is read while rebuilding provenance.
25
+ */
23
26
  export declare function principalRuntimeSource(principal?: SessionAuthContext | null): RuntimeSource | undefined;
24
27
  export declare function runtimeEnvelope(input?: {
25
28
  readonly principal?: SessionAuthContext | null;
@@ -27,6 +30,12 @@ export declare function runtimeEnvelope(input?: {
27
30
  readonly callId?: string;
28
31
  readonly source?: RuntimeSource;
29
32
  }): RuntimeEnvelope;
33
+ /**
34
+ * The envelope with its source only where the ontology reads it: from Telegram always, from another
35
+ * channel only where `initialize` lists it, since an ontology that cannot read a source refuses
36
+ * the whole call. The ontology is asked only for another channel's source.
37
+ */
38
+ export declare function readableRuntimeEnvelope(envelope: RuntimeEnvelope, providers: () => Promise<ReadonlySet<string>>): Promise<RuntimeEnvelope>;
30
39
  /** Older strict ontology schemas accept only the original chat identity fields. */
31
40
  export declare function compatibleRuntimeEnvelope(envelope: RuntimeEnvelope, extended: boolean): RuntimeEnvelope;
32
41
  export declare const RUNTIME_SOURCE_PROTOCOL = "segmentstream/runtime-source";
@@ -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 { Nt as RUNTIME_SOURCE_PROTOCOL, Pt as compatibleRuntimeEnvelope, Ft as principalRuntimeSource, It as runtimeEnvelope, Lt as telegramRuntimeSource } from "../../_chunks/principal-DYl7vqOp.mjs";
7
+ export { wt as RUNTIME_SOURCE_PROTOCOL, Tt as compatibleRuntimeEnvelope, Et as principalRuntimeSource, Dt as readableRuntimeEnvelope, Ot as runtimeEnvelope, kt as telegramRuntimeSource } from "../../_chunks/principal-BWTq_zuf.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 { R as ACT_AS_HEADER, _ as AttachmentError, ht as SESSION_HEADER, mt as CHAT_HEADER, v as EARLIER_CHAT_HEADER } from "../../_chunks/principal-DYl7vqOp.mjs";
7
+ import { Nt as SESSION_HEADER, R as ACT_AS_HEADER, _ as AttachmentError, jt as CHAT_HEADER, v as EARLIER_CHAT_HEADER } from "../../_chunks/principal-BWTq_zuf.mjs";
8
8
  import { fetchFileGrant, transientFileStatus } from "./file-grant.mjs";
9
9
  var StoredFileError = class extends AttachmentError {
10
10
  filename;
@@ -14,6 +14,7 @@ import { type ImageDescriber } from "../inbound-media/images.js";
14
14
  import { type CapabilityLookup, type MediaPlan } from "../inbound-media/plan.js";
15
15
  import { type Transcriber } from "../inbound-media/speech.js";
16
16
  import { type SlackFileDownload } from "./files.js";
17
+ import type { WorkspaceActionHook } from "../workspace-action.js";
17
18
  import { type ChannelReviewOptions } from "../review/reply.js";
18
19
  import { type RuntimeToken } from "../runtime-token.js";
19
20
  import { type ChatArchive } from "../chat-archive.js";
@@ -53,6 +54,11 @@ export interface SlackChannelOptions {
53
54
  /** The Slack channel `name` the mount declares, or `null` when it declares no such channel. */
54
55
  readonly settings: (name: string) => SlackSettings | null;
55
56
  readonly admission: () => AdmissionSettings;
57
+ /**
58
+ * The action a press of a workspace button calls, from `buttons` in `agent/segmentstream.json`:
59
+ * the same in every channel. Without it, a channel's own earlier `callbacks`.
60
+ */
61
+ readonly buttons?: () => WorkspaceActionHook | undefined;
56
62
  /**
57
63
  * The workspace's group routing. In `mention` mode a reply in a followed thread reaches the
58
64
  * agent only when it mentions the bot; in `smart` mode the model decides.
@@ -8,7 +8,7 @@ import { admitMessage, localizedText } from "../admission.mjs";
8
8
  import { agentToolsAttribute } from "../agent-tools.mjs";
9
9
  import { agentChats, channelChats } from "../chats.mjs";
10
10
  import { withButtonDecision } from "../confirmation-buttons.mjs";
11
- import { b as agentAttachments, bt as withChatAddress, d as prepareInboundMedia, m as turnContent } from "../../../_chunks/principal-DYl7vqOp.mjs";
11
+ import { b as agentAttachments, d as prepareInboundMedia, m as turnContent, zt as withChatAddress } from "../../../_chunks/principal-BWTq_zuf.mjs";
12
12
  import { channelAttributes, currentChannel, withNamedRoutes, withSessionChannels } from "../channel-scope.mjs";
13
13
  import { redactDiagnostic } from "../diagnostics.mjs";
14
14
  import { MAXIMUM_DOWNLOAD_BYTES, connectionProxy } from "../connection-proxy.mjs";
@@ -342,7 +342,7 @@ function segmentstreamSlack(options) {
342
342
  onInteraction: (action, ctx) => handleWorkspaceCallback({
343
343
  action,
344
344
  ctx,
345
- configuration: settings()?.callbacks,
345
+ configuration: options.buttons?.() ?? settings()?.callbacks,
346
346
  admission: options.admission(),
347
347
  identities: pairing(),
348
348
  environment,
@@ -472,6 +472,9 @@ async function receive(input) {
472
472
  threadId: ctx.slack.threadTs,
473
473
  kind: input.direct ? "private" : "group",
474
474
  ...input.direct ? { peer: user } : {}
475
+ }, {
476
+ id: message.ts,
477
+ sender: user
475
478
  });
476
479
  if (message.attachments.length === 0 || input.files === void 0) return { auth };
477
480
  const channelId = ctx.slack.channelId;
@@ -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 { _ as AttachmentError } from "../../../_chunks/principal-DYl7vqOp.mjs";
7
+ import { _ as AttachmentError } from "../../../_chunks/principal-BWTq_zuf.mjs";
8
8
  import { sendStoredAttachments } from "../attachments-send.mjs";
9
9
  import { MAXIMUM_PROXY_BODY_BYTES, connectionProxy } from "../connection-proxy.mjs";
10
10
  import { redactDiagnostic } from "../diagnostics.mjs";
@@ -7,10 +7,10 @@ import type { RuntimeToken } from "../runtime-token.js";
7
7
  import { type WorkspaceActionHook } from "../workspace-action.js";
8
8
  /**
9
9
  * A press of a button the workspace sent, whose `value` is `ws:<token>`: the routine action
10
- * `channels.slack.callbacks` names runs as the member paired with the Slack user who pressed it,
11
- * with the verified chat, thread, pressed message and presser as its runtime source. What the action
12
- * returns can acknowledge the press privately to the presser, edit the pressed message and queue
13
- * one turn in the thread's session. Anyone not paired gets the workspace's pairing reply, privately.
10
+ * `buttons` names runs as the member paired with the Slack user who pressed it, with the verified
11
+ * chat, thread, pressed message and presser as its runtime source. What the action returns can
12
+ * acknowledge the press privately to the presser, edit the pressed message and queue one turn in
13
+ * the thread's session. Anyone not paired gets the workspace's pairing reply, privately.
14
14
  *
15
15
  * There is no retry or token claim: expiry, audience checks, repeated presses and business
16
16
  * idempotency belong to the workspace's action. A button with another value is not the
@@ -4,16 +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 { admitMessage } from "../admission.mjs";
8
- import { It as runtimeEnvelope, bt as withChatAddress } from "../../../_chunks/principal-DYl7vqOp.mjs";
7
+ import { Lt as chatRuntimeSource, Ot as runtimeEnvelope, zt as withChatAddress } from "../../../_chunks/principal-BWTq_zuf.mjs";
9
8
  import { currentChannel } from "../channel-scope.mjs";
10
- import { object } from "../confirmation-description.mjs";
11
- import { workspaceAction, workspaceButtonToken } from "../workspace-action.mjs";
9
+ import { pressWorkspaceButton, queueWorkspaceButtonTurn, workspaceAction, workspaceButtonToken } from "../workspace-action.mjs";
12
10
  import { pairingNotice } from "./pairing.mjs";
13
11
  import { randomUUID } from "node:crypto";
14
- const DISPATCH_DEADLINE_MS = 1e4;
15
- const ACKNOWLEDGEMENT_LIMIT = 200;
16
- const CONTEXT_LIMIT = 16384;
17
12
  const EDIT_TEXT_LIMIT = 4e4;
18
13
  const EDIT_BLOCKS_LIMIT = 50;
19
14
  const EDIT_PAYLOAD_LIMIT = 32768;
@@ -23,7 +18,7 @@ async function handleWorkspaceCallback(input) {
23
18
  const messageTs = action.messageTs;
24
19
  if (token === void 0 || messageTs === void 0) return;
25
20
  if (input.configuration === void 0) {
26
- report("workspace_callback_unconfigured", new Error("A workspace button was pressed in Slack, but channels.slack.callbacks is absent."));
21
+ report("workspace_callback_unconfigured", new Error("A workspace button was pressed in Slack, but buttons names no action."));
27
22
  return;
28
23
  }
29
24
  const user = action.user.id;
@@ -65,50 +60,33 @@ async function handleWorkspaceCallback(input) {
65
60
  };
66
61
  const principal = withChatAddress(input.principal(lookup.member, user), address);
67
62
  const callId = action.triggerId ?? randomUUID();
68
- const controller = new AbortController();
69
- let timer;
70
- let result;
63
+ let answer;
71
64
  try {
72
- result = await Promise.race([workspaceAction({
65
+ answer = await pressWorkspaceButton((signal) => workspaceAction({
73
66
  configuration: input.configuration,
74
67
  principal,
75
68
  memberId: lookup.member.id,
76
69
  input: { token },
77
- signal: controller.signal,
70
+ signal,
78
71
  envelope: runtimeEnvelope({
79
- source: {
80
- provider: "slack",
81
- ...channel === "slack" ? {} : { channel },
82
- chat_id: channelId,
83
- thread_id: threadTs,
84
- kind: address.kind,
85
- ...direct ? { peer: user } : {},
86
- message_id: messageTs,
72
+ source: chatRuntimeSource(address, {
73
+ id: messageTs,
87
74
  sender: user
88
- },
75
+ }),
89
76
  sessionId: `slack:callback:${callId}`,
90
77
  callId
91
78
  }),
92
79
  environment: input.environment,
93
80
  ...input.token === void 0 ? {} : { token: input.token },
94
81
  ...input.fetch === void 0 ? {} : { fetch: input.fetch }
95
- }), new Promise((resolve) => {
96
- timer = setTimeout(() => {
97
- controller.abort();
98
- report("workspace_callback_timeout", new Error("A Slack workspace button's action took more than 10 seconds."));
99
- resolve(void 0);
100
- }, DISPATCH_DEADLINE_MS);
101
- })]);
82
+ }), (error) => report("workspace_callback_timeout", error));
102
83
  } catch (error) {
103
84
  report("workspace_callback_failed", error);
104
85
  return;
105
- } finally {
106
- if (timer !== void 0) clearTimeout(timer);
107
86
  }
108
- if (result === void 0) return;
109
- const acknowledgement = result.acknowledgement;
110
- if (typeof acknowledgement === "string" && acknowledgement.trim() !== "" && acknowledgement.length <= ACKNOWLEDGEMENT_LIMIT) await privately(acknowledgement).catch((error) => report("workspace_callback_ack_failed", error));
111
- const edit = object(result.edit);
87
+ if (answer === void 0) return;
88
+ const { acknowledgement, edit, context } = answer;
89
+ if (acknowledgement !== void 0) await privately(acknowledgement).catch((error) => report("workspace_callback_ack_failed", error));
112
90
  if (typeof edit.text === "string" || Array.isArray(edit.blocks)) try {
113
91
  const text = typeof edit.text === "string" && edit.text.length <= EDIT_TEXT_LIMIT ? edit.text : void 0;
114
92
  const blocks = Array.isArray(edit.blocks) && edit.blocks.length <= EDIT_BLOCKS_LIMIT ? edit.blocks : void 0;
@@ -124,10 +102,9 @@ async function handleWorkspaceCallback(input) {
124
102
  } catch (error) {
125
103
  report("workspace_callback_edit_failed", error);
126
104
  }
127
- const context = result.context;
128
- if (typeof context !== "string" || context.trim() === "" || context.length > CONTEXT_LIMIT) return;
105
+ if (context === void 0) return;
129
106
  try {
130
- const admitted = await admitMessage({
107
+ await queueWorkspaceButtonTurn({
131
108
  identity: {
132
109
  provider: "slack",
133
110
  externalId: user,
@@ -142,12 +119,12 @@ async function handleWorkspaceCallback(input) {
142
119
  channel,
143
120
  chatId: channelId,
144
121
  recipient: user
145
- } } : {}
146
- });
147
- if (admitted.status !== "existing" && admitted.status !== "created" || admitted.member.id !== lookup.member.id || admitted.handled === true) return;
148
- await ctx.send(context, {
149
- auth: principal,
150
- turnPolicy: "queue"
122
+ } } : {},
123
+ memberId: lookup.member.id,
124
+ queue: () => ctx.send(context, {
125
+ auth: principal,
126
+ turnPolicy: "queue"
127
+ })
151
128
  });
152
129
  } catch (error) {
153
130
  report("workspace_callback_turn_failed", error);
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { object } from "./confirmation-description.mjs";
8
- import { D as OntologyFileUnavailable, W as member, i as memberIdOf, j as ontologyTools } from "../../_chunks/principal-DYl7vqOp.mjs";
8
+ import { D as OntologyFileUnavailable, W as member, i as memberIdOf, j as ontologyTools } from "../../_chunks/principal-BWTq_zuf.mjs";
9
9
  import { redactDiagnostic } from "./diagnostics.mjs";
10
10
  import { createHash } from "node:crypto";
11
11
  async function readStoredFile(input, principal, options = {}) {
@@ -1,4 +1,5 @@
1
1
  import type { GroupPolicy } from "../group-routing/policy.js";
2
+ import type { WorkspaceActionHook } from "../workspace-action.js";
2
3
  import { type AttachmentDescriber } from "./attachment-description.js";
3
4
  import { type TelegramChannel } from "eve/channels/telegram";
4
5
  import type { ChatModelChoice, AdmissionSettings, SessionSettings, TelegramSettings } from "../../config.js";
@@ -27,6 +28,11 @@ import { type ChannelReviewOptions } from "../review/reply.js";
27
28
  export interface TelegramAdapterOptions {
28
29
  /** The Telegram channel `name` the mount declares, or `null` when it declares no such channel. */
29
30
  readonly settings: (name: string) => TelegramSettings | null;
31
+ /**
32
+ * The action a press of a workspace button calls, from `buttons` in `agent/segmentstream.json`:
33
+ * the same in every channel. Without it, a channel's own earlier `callbacks`.
34
+ */
35
+ readonly buttons?: () => WorkspaceActionHook | undefined;
30
36
  readonly groups?: () => GroupPolicy;
31
37
  readonly models: () => {
32
38
  readonly stt: string | false;
@@ -10,12 +10,12 @@ import { groupRoutingHealth } from "../group-routing/health.mjs";
10
10
  import { dispatchStructuredMessage, structuredMessage } from "./structured.mjs";
11
11
  import { handleWorkspaceCallback } from "./callbacks.mjs";
12
12
  import { telegramText, withTelegramTexts } from "./texts.mjs";
13
- import { t as agentBuild } from "../../../_chunks/build-metadata-B1FvLdht.mjs";
13
+ import { t as agentBuild } from "../../../_chunks/build-metadata-DliB5P2p.mjs";
14
14
  import { attachmentLifecycle } from "./lifecycle.mjs";
15
15
  import { manifestOf } from "../../config.mjs";
16
16
  import { gatewayAttachmentDescriber } from "./attachment-description.mjs";
17
17
  import { chooseModel } from "../../model.mjs";
18
- import { At as reportTelegramError, Ct as currentLocale, Mt as withDeliveryLocale, Ot as failureText, S as fetchStoredAttachment, b as agentAttachments, c as currentInboundRequest, jt as safeTelegramFetch, l as runInboundRequest, n as chatLanguage, o as telegramPrincipal, s as InboundRequest, u as withReplacedText } from "../../../_chunks/principal-DYl7vqOp.mjs";
18
+ import { Ct as withDeliveryLocale, S as fetchStoredAttachment, St as safeTelegramFetch, b as agentAttachments, c as currentInboundRequest, l as runInboundRequest, mt as currentLocale, n as chatLanguage, o as telegramPrincipal, s as InboundRequest, u as withReplacedText, xt as reportTelegramError, yt as failureText } from "../../../_chunks/principal-BWTq_zuf.mjs";
19
19
  import { MAXIMUM_DOWNLOAD_BYTES, connectionProxy } from "../connection-proxy.mjs";
20
20
  import { appOrigin, channelsEnabled, proxyEnvironment, runtimeIdentityEnvironment, webhookSecret } from "../environment.mjs";
21
21
  import { agentIdentities } from "../identities.mjs";
@@ -352,7 +352,7 @@ function segmentstreamTelegram(options) {
352
352
  await handleWorkspaceCallback({
353
353
  context,
354
354
  query,
355
- configuration: settings().callbacks,
355
+ configuration: options.buttons?.() ?? settings().callbacks,
356
356
  admission: options.admission?.() ?? manifestOf({}),
357
357
  scope: options.sessions().scope,
358
358
  identities: pairing(),
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { describableImage } from "../inbound-media/images.mjs";
8
- import { At as reportTelegramError } from "../../../_chunks/principal-DYl7vqOp.mjs";
8
+ import { xt as reportTelegramError } from "../../../_chunks/principal-BWTq_zuf.mjs";
9
9
  import { gateway, generateText } from "ai";
10
10
  const MAXIMUM_ROUTING_ATTACHMENT_BYTES = 5242880;
11
11
  const ROUTING_ATTACHMENT_TIMEOUT_MS = 15e3;
@@ -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 { At as reportTelegramError, Et as customerMessage, Ot as failureText, _ as AttachmentError, kt as formattingRefused } from "../../../_chunks/principal-DYl7vqOp.mjs";
8
+ import { _ as AttachmentError, _t as customerMessage, bt as formattingRefused, xt as reportTelegramError, yt as failureText } from "../../../_chunks/principal-BWTq_zuf.mjs";
9
9
  import { attachmentFailure } from "../attachments-send.mjs";
10
10
  import { MAXIMUM_PROXY_BODY_BYTES, connectionProxy } from "../connection-proxy.mjs";
11
11
  import { redactDiagnostic } from "../diagnostics.mjs";
@@ -4,22 +4,18 @@ 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 { object } from "../confirmation-description.mjs";
8
- import { At as reportTelegramError, It as runtimeEnvelope, Lt as telegramRuntimeSource, c as currentInboundRequest, i as memberIdOf, o as telegramPrincipal } from "../../../_chunks/principal-DYl7vqOp.mjs";
7
+ import { Ot as runtimeEnvelope, c as currentInboundRequest, i as memberIdOf, kt as telegramRuntimeSource, o as telegramPrincipal, xt as reportTelegramError } from "../../../_chunks/principal-BWTq_zuf.mjs";
9
8
  import { formatAddress, parseAddress, scopedAddress } from "./sessions.mjs";
10
9
  import { telegramText } from "./texts.mjs";
11
- import { isWorkspaceCallback, workspaceAction, workspaceButtonToken } from "../workspace-action.mjs";
12
- import { admitMessage } from "../admission.mjs";
10
+ import { isWorkspaceCallback, pressWorkspaceButton, queueWorkspaceButtonTurn, workspaceAction, workspaceButtonToken } from "../workspace-action.mjs";
13
11
  import { currentChannel } from "../channel-scope.mjs";
14
12
  async function handleWorkspaceCallback(input) {
15
13
  const { query, context } = input;
16
14
  const locale = query.from.languageCode;
17
15
  let acknowledgement;
18
16
  let showAlert = false;
19
- let result;
17
+ let answer;
20
18
  let principal;
21
- const controller = new AbortController();
22
- let timer;
23
19
  try {
24
20
  const token = workspaceButtonToken(query.data);
25
21
  if (!query.message || query.from.isBot || token === void 0) acknowledgement = telegramText("callback", "unknown", locale);
@@ -33,7 +29,7 @@ async function handleWorkspaceCallback(input) {
33
29
  caption: "",
34
30
  raw: {}
35
31
  };
36
- const dispatch = async () => {
32
+ answer = await pressWorkspaceButton(async (signal) => {
37
33
  const lookup = await input.identities.lookup({
38
34
  provider: "telegram",
39
35
  externalId: query.from.id
@@ -42,7 +38,7 @@ async function handleWorkspaceCallback(input) {
42
38
  acknowledgement = telegramText("callback", "forbidden", locale);
43
39
  return;
44
40
  }
45
- controller.signal.throwIfAborted();
41
+ signal.throwIfAborted();
46
42
  principal = telegramPrincipal({
47
43
  message,
48
44
  member: lookup.member,
@@ -54,32 +50,23 @@ async function handleWorkspaceCallback(input) {
54
50
  principal,
55
51
  memberId: lookup.member.id,
56
52
  input: { token },
57
- signal: controller.signal,
53
+ signal,
58
54
  envelope: runtimeEnvelope({
59
55
  source: telegramRuntimeSource(message, void 0, query.id),
60
56
  sessionId: `telegram:callback:${query.id}`,
61
57
  callId: query.id
62
58
  })
63
59
  });
64
- };
65
- const deadline = new Promise((resolve) => {
66
- timer = setTimeout(() => {
67
- controller.abort();
68
- reportTelegramError("workspace_callback_timeout", new Error("Telegram callback dispatch exceeded 10 seconds."), { callbackQueryId: query.id });
69
- resolve(void 0);
70
- }, 1e4);
71
- });
72
- result = await Promise.race([dispatch(), deadline]);
73
- if (result !== void 0) {
74
- acknowledgement = typeof result.acknowledgement === "string" && result.acknowledgement.length <= 200 ? result.acknowledgement : void 0;
75
- showAlert = result.show_alert === true;
60
+ }, (error) => reportTelegramError("workspace_callback_timeout", error, { callbackQueryId: query.id }));
61
+ if (answer !== void 0) {
62
+ acknowledgement = answer.acknowledgement;
63
+ showAlert = answer.result.show_alert === true;
76
64
  }
77
65
  }
78
66
  } catch (error) {
79
67
  reportTelegramError("workspace_callback_failed", error, { callbackQueryId: query.id });
80
- acknowledgement = controller.signal.aborted ? void 0 : telegramText("callback", "error", locale);
68
+ acknowledgement = telegramText("callback", "error", locale);
81
69
  } finally {
82
- if (timer !== void 0) clearTimeout(timer);
83
70
  try {
84
71
  await context.telegram.answerCallbackQuery({
85
72
  callbackQueryId: query.id,
@@ -90,8 +77,8 @@ async function handleWorkspaceCallback(input) {
90
77
  reportTelegramError("workspace_callback_ack_failed", error, { callbackQueryId: query.id });
91
78
  }
92
79
  }
93
- if (result === void 0 || query.message === void 0 || principal === void 0) return;
94
- const edit = object(result.edit);
80
+ if (answer === void 0 || query.message === void 0 || principal === void 0) return;
81
+ const { edit, context: queued } = answer;
95
82
  try {
96
83
  if (typeof edit.text === "string" || edit.reply_markup !== void 0) {
97
84
  const payload = {
@@ -113,12 +100,16 @@ async function handleWorkspaceCallback(input) {
113
100
  } catch (error) {
114
101
  reportTelegramError("workspace_callback_edit_failed", error, { callbackQueryId: query.id });
115
102
  }
116
- if (typeof result.context === "string" && result.context.trim() && result.context.length <= 16384) try {
117
- const admitted = await admitMessage({
103
+ const message = query.message;
104
+ const member = principal;
105
+ const memberId = memberIdOf(member);
106
+ if (queued === void 0 || memberId === void 0) return;
107
+ try {
108
+ await queueWorkspaceButtonTurn({
118
109
  identity: {
119
110
  provider: "telegram",
120
111
  externalId: query.from.id,
121
- chat: query.message.chat.type === "private" ? "private" : "group",
112
+ chat: message.chat.type === "private" ? "private" : "group",
122
113
  turn: true
123
114
  },
124
115
  identities: input.identities,
@@ -126,29 +117,31 @@ async function handleWorkspaceCallback(input) {
126
117
  languageCode: locale,
127
118
  sendNotice: (text) => context.telegram.post(text),
128
119
  noticeFailed: (error) => reportTelegramError("workspace_callback_notice_failed", error),
129
- ...query.message.chat.type === "private" ? { chat: {
120
+ ...message.chat.type === "private" ? { chat: {
130
121
  channel: currentChannel("telegram"),
131
122
  chatId: query.from.id
132
- } } : {}
133
- });
134
- if (admitted.status !== "existing" && admitted.status !== "created" || admitted.member.id !== memberIdOf(principal) || admitted.handled === true) return;
135
- const sessions = currentInboundRequest()?.sessions;
136
- if (sessions === void 0) throw new Error("The callback has no session transport.");
137
- const address = scopedAddress(formatAddress({
138
- chatId: query.message.chat.type === "private" ? query.from.id : query.message.chat.id,
139
- messageThreadId: String(query.message.messageThreadId ?? ""),
140
- conversationId: query.message.chat.type === "private" ? "" : query.message.messageId
141
- }), input.scope);
142
- const session = sessions.from(address);
143
- if (session.send === void 0) throw new Error("The callback session cannot enqueue turns.");
144
- await session.send(result.context, {
145
- auth: principal,
146
- turnPolicy: "queue",
147
- state: {
148
- chatId: query.message.chat.id,
149
- chatType: query.message.chat.type,
150
- messageThreadId: query.message.messageThreadId ?? null,
151
- conversationId: parseAddress(address).conversationId || null
123
+ } } : {},
124
+ memberId,
125
+ queue: async () => {
126
+ const sessions = currentInboundRequest()?.sessions;
127
+ if (sessions === void 0) throw new Error("The callback has no session transport.");
128
+ const address = scopedAddress(formatAddress({
129
+ chatId: message.chat.type === "private" ? query.from.id : message.chat.id,
130
+ messageThreadId: String(message.messageThreadId ?? ""),
131
+ conversationId: message.chat.type === "private" ? "" : message.messageId
132
+ }), input.scope);
133
+ const session = sessions.from(address);
134
+ if (session.send === void 0) throw new Error("The callback session cannot enqueue turns.");
135
+ await session.send(queued, {
136
+ auth: member,
137
+ turnPolicy: "queue",
138
+ state: {
139
+ chatId: message.chat.id,
140
+ chatType: message.chat.type,
141
+ messageThreadId: message.messageThreadId ?? null,
142
+ conversationId: parseAddress(address).conversationId || null
143
+ }
144
+ });
152
145
  }
153
146
  });
154
147
  } catch (error) {
@@ -10,7 +10,7 @@ import { n as contentText, t as CONTENT_CAPS } from "../../../_chunks/content-cD
10
10
  import { chatEvent, sessionFailureEventId } from "../chat-archive.mjs";
11
11
  import { currentConfirmationPrompt } from "../group-routing/messages.mjs";
12
12
  import { messageMetadata } from "./message-metadata.mjs";
13
- import { At as reportTelegramError, c as currentInboundRequest, wt as currentThreadId } from "../../../_chunks/principal-DYl7vqOp.mjs";
13
+ import { c as currentInboundRequest, ht as currentThreadId, xt as reportTelegramError } from "../../../_chunks/principal-BWTq_zuf.mjs";
14
14
  import { reportMembership } from "./membership.mjs";
15
15
  import { currentDeliveryScope } from "./delivery-diagnostics.mjs";
16
16
  import { contentShape, messageContent } from "./content.mjs";
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { telegramText } from "./texts.mjs";
8
- import { At as reportTelegramError, F as confirmations, _t as chatChannel, c as currentInboundRequest, i as memberIdOf, o as telegramPrincipal } from "../../../_chunks/principal-DYl7vqOp.mjs";
8
+ import { F as confirmations, Ft as chatChannel, c as currentInboundRequest, i as memberIdOf, o as telegramPrincipal, xt as reportTelegramError } from "../../../_chunks/principal-BWTq_zuf.mjs";
9
9
  import { humanText } from "../confirmation-description.mjs";
10
10
  import { withConfirmationPrompt } from "../group-routing/messages.mjs";
11
11
  import { chatPostOperationId, isChatPost } from "../chat-post-confirmation.mjs";
@@ -5,5 +5,5 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { isTechnicalText } from "../customer-text-safety.mjs";
8
- import { At as reportTelegramError, Ct as currentLocale, Dt as customerText, Et as customerMessage, Mt as withDeliveryLocale, Ot as failureText, St as TelegramDeliveryError, Tt as customerCopy, jt as safeTelegramFetch, kt as formattingRefused, wt as currentThreadId } from "../../../_chunks/principal-DYl7vqOp.mjs";
8
+ import { Ct as withDeliveryLocale, St as safeTelegramFetch, _t as customerMessage, bt as formattingRefused, gt as customerCopy, ht as currentThreadId, mt as currentLocale, pt as TelegramDeliveryError, vt as customerText, xt as reportTelegramError, yt as failureText } from "../../../_chunks/principal-BWTq_zuf.mjs";
9
9
  export { TelegramDeliveryError, currentLocale, currentThreadId, customerCopy, customerMessage, customerText, failureText, formattingRefused, isTechnicalText, reportTelegramError, safeTelegramFetch, withDeliveryLocale };
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { currentChannel } from "../channel-scope.mjs";
8
- import { At as reportTelegramError, p as storeFiles } from "../../../_chunks/principal-DYl7vqOp.mjs";
8
+ import { p as storeFiles, xt as reportTelegramError } from "../../../_chunks/principal-BWTq_zuf.mjs";
9
9
  function telegramChat(chatId) {
10
10
  return `${currentChannel("telegram")}:${chatId}`;
11
11
  }
@@ -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 agentBuild } from "../../../_chunks/build-metadata-B1FvLdht.mjs";
7
+ import { t as agentBuild } from "../../../_chunks/build-metadata-DliB5P2p.mjs";
8
8
  import { runtimeRequestFailure } from "./runtime-request.mjs";
9
9
  import { GET } from "eve/channels";
10
10
  const HEALTH_ROUTE = "/eve/v1/telegram/health";
@@ -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 { N as CONFIRMATION_TTL_MS } from "../../../_chunks/principal-DYl7vqOp.mjs";
7
+ import { N as CONFIRMATION_TTL_MS } from "../../../_chunks/principal-BWTq_zuf.mjs";
8
8
  import { object } from "../confirmation-description.mjs";
9
9
  import { SessionNotActiveError } from "eve/sessions";
10
10
  function heldApprovals(events) {
@@ -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 { s as InboundRequest, c as currentInboundRequest, l as runInboundRequest, u as withReplacedText } from "../../../_chunks/principal-DYl7vqOp.mjs";
7
+ export { s as InboundRequest, c as currentInboundRequest, l as runInboundRequest, u as withReplacedText } from "../../../_chunks/principal-BWTq_zuf.mjs";
@@ -7,7 +7,7 @@ __eveCreateRequire(import.meta.url);
7
7
  import { WorkspaceActionAlreadyDispatched } from "../workspace-action.mjs";
8
8
  import { structuredMessage } from "./structured.mjs";
9
9
  import { currentChannel } from "../channel-scope.mjs";
10
- import { At as reportTelegramError, It as runtimeEnvelope, Lt as telegramRuntimeSource, f as attachmentsContext, n as chatLanguage, o as telegramPrincipal, x as attachmentUrl } from "../../../_chunks/principal-DYl7vqOp.mjs";
10
+ import { Ot as runtimeEnvelope, f as attachmentsContext, kt as telegramRuntimeSource, n as chatLanguage, o as telegramPrincipal, x as attachmentUrl, xt as reportTelegramError } from "../../../_chunks/principal-BWTq_zuf.mjs";
11
11
  import { routingBurst } from "../group-routing/burst.mjs";
12
12
  import { telegramSignals } from "./signals.mjs";
13
13
  import { addressingReason, chatKey, otherRecipient } from "../group-routing/signals.mjs";