@segmentstream/agent 0.18.3 → 0.19.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 (93) hide show
  1. package/README.md +4 -4
  2. package/dist/_chunks/{build-metadata-DZ9Nb8Q2.mjs → build-metadata-CZ245Pl3.mjs} +1 -1
  3. package/dist/_chunks/{inbound-request-8xhK7EaW.mjs → inbound-request-Dx1B6Y5r.mjs} +1 -1
  4. package/dist/_chunks/{principal-qyR3jKAr.mjs → principal-BnJuWJtk.mjs} +1 -1
  5. package/dist/extension/_manifest.json +3 -15
  6. package/dist/extension/connections/ontology.d.ts +1 -1
  7. package/dist/extension/connections/ontology.mjs +2 -2
  8. package/dist/extension/hooks/authorization.d.ts +1 -1
  9. package/dist/extension/hooks/authorization.mjs +3 -3
  10. package/dist/extension/hooks/ontology-files.d.ts +1 -1
  11. package/dist/extension/hooks/ontology-files.mjs +3 -1
  12. package/dist/extension/hooks/sandbox.d.ts +2 -2
  13. package/dist/extension/hooks/sandbox.mjs +2 -2
  14. package/dist/extension/instructions/conversations.d.ts +1 -1
  15. package/dist/extension/instructions/conversations.mjs +3 -3
  16. package/dist/extension/instructions/sandbox.d.ts +1 -1
  17. package/dist/extension/instructions/sandbox.mjs +2 -2
  18. package/dist/extension/instructions.md +13 -12
  19. package/dist/extension/lib/attachment-tools.mjs +1 -1
  20. package/dist/extension/lib/build-metadata.mjs +1 -1
  21. package/dist/extension/lib/confirmations.mjs +3 -3
  22. package/dist/extension/lib/conversation-runtime.d.ts +2 -2
  23. package/dist/extension/lib/conversation-runtime.mjs +40 -55
  24. package/dist/extension/lib/conversations.mjs +1 -1
  25. package/dist/extension/lib/group-routing/conversation-router.d.ts +1 -1
  26. package/dist/extension/lib/group-routing/conversation-router.mjs +2 -2
  27. package/dist/extension/lib/group-routing/dequeue.mjs +2 -2
  28. package/dist/extension/lib/group-routing/record.mjs +1 -1
  29. package/dist/extension/lib/group-routing/replay.mjs +1 -1
  30. package/dist/extension/lib/group-routing/router.d.ts +1 -1
  31. package/dist/extension/lib/group-routing/router.mjs +3 -3
  32. package/dist/extension/lib/ontology-connection.mjs +2 -2
  33. package/dist/extension/lib/ontology-file-call.mjs +2 -2
  34. package/dist/extension/lib/ontology-tools.mjs +1 -1
  35. package/dist/extension/lib/runtime-envelope.mjs +1 -1
  36. package/dist/extension/lib/sandbox.d.ts +3 -2
  37. package/dist/extension/lib/sandbox.mjs +1 -1
  38. package/dist/extension/lib/stored-files.mjs +1 -1
  39. package/dist/extension/lib/telegram/adapter.mjs +43 -28
  40. package/dist/extension/lib/telegram/archive-message.d.ts +4 -0
  41. package/dist/extension/lib/telegram/archive-message.mjs +85 -0
  42. package/dist/extension/lib/telegram/attachment-description.mjs +1 -1
  43. package/dist/extension/lib/telegram/attachments-send.mjs +2 -2
  44. package/dist/extension/lib/telegram/callbacks.mjs +2 -2
  45. package/dist/extension/lib/telegram/confirmation-expiry.mjs +20 -9
  46. package/dist/extension/lib/telegram/confirmations.d.ts +2 -2
  47. package/dist/extension/lib/telegram/confirmations.mjs +206 -181
  48. package/dist/extension/lib/telegram/conversations.mjs +5 -6
  49. package/dist/extension/lib/telegram/customer-text.mjs +1 -1
  50. package/dist/extension/lib/telegram/deferred-confirmations.mjs +2 -2
  51. package/dist/extension/lib/telegram/delivery-diagnostics.mjs +1 -1
  52. package/dist/extension/lib/telegram/durable-typing.d.ts +11 -0
  53. package/dist/extension/lib/telegram/durable-typing.mjs +10 -10
  54. package/dist/extension/lib/telegram/files.mjs +2 -2
  55. package/dist/extension/lib/telegram/health.mjs +1 -1
  56. package/dist/extension/lib/telegram/held-approvals.d.ts +3 -3
  57. package/dist/extension/lib/telegram/held-approvals.mjs +23 -19
  58. package/dist/extension/lib/telegram/images.d.ts +1 -1
  59. package/dist/extension/lib/telegram/images.mjs +1 -1
  60. package/dist/extension/lib/telegram/inbound-request.d.ts +2 -2
  61. package/dist/extension/lib/telegram/inbound-request.mjs +1 -1
  62. package/dist/extension/lib/telegram/inbound.mjs +5 -6
  63. package/dist/extension/lib/telegram/lifecycle.d.ts +2 -2
  64. package/dist/extension/lib/telegram/lifecycle.mjs +23 -27
  65. package/dist/extension/lib/telegram/media-policy.mjs +1 -1
  66. package/dist/extension/lib/telegram/principal.mjs +1 -1
  67. package/dist/extension/lib/telegram/routing-context.mjs +4 -4
  68. package/dist/extension/lib/telegram/session-recovery.d.ts +1 -1
  69. package/dist/extension/lib/telegram/session-recovery.mjs +2 -1
  70. package/dist/extension/lib/telegram/sessions.d.ts +7 -4
  71. package/dist/extension/lib/telegram/sessions.mjs +6 -3
  72. package/dist/extension/lib/telegram/silent.d.ts +1 -1
  73. package/dist/extension/lib/telegram/silent.mjs +11 -8
  74. package/dist/extension/lib/telegram/structured.mjs +1 -1
  75. package/dist/extension/lib/telegram/turn-errors.d.ts +1 -1
  76. package/dist/extension/lib/telegram/turn-errors.mjs +47 -31
  77. package/dist/extension/lib/telegram/voice.mjs +1 -1
  78. package/dist/extension/lib/workflow-serializable.mjs +1 -1
  79. package/dist/extension/model.mjs +7 -4
  80. package/dist/extension/tools/attachments_discard.mjs +1 -1
  81. package/dist/extension/tools/attachments_list.mjs +1 -1
  82. package/dist/extension/tools/attachments_promote.mjs +2 -2
  83. package/dist/extension/tools/attachments_read.mjs +1 -1
  84. package/dist/extension/tools/attachments_send.mjs +1 -1
  85. package/dist/extension/tools/attachments_table.mjs +1 -1
  86. package/dist/extension/tools/ontology_call_file.d.ts +1 -1
  87. package/dist/extension/tools/ontology_call_file.mjs +1 -1
  88. package/dist/extension/tools/questions_ask.mjs +2 -2
  89. package/dist/extension/tools/sandbox.d.ts +1 -8
  90. package/dist/extension/tools/sandbox.mjs +1 -1
  91. package/package.json +5 -5
  92. /package/dist/_chunks/{content-TRaZitQZ.mjs → content-cDtVnr8Y.mjs} +0 -0
  93. /package/dist/_chunks/{workflow-serializable-_g4JRau5.mjs → workflow-serializable-DU7WeCIW.mjs} +0 -0
@@ -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 { i as memberIdOf, u as runtimeEnvelope } from "../../_chunks/principal-qyR3jKAr.mjs";
7
+ import { i as memberIdOf, u as runtimeEnvelope } from "../../_chunks/principal-BnJuWJtk.mjs";
8
8
  import { isChatPost } from "./chat-post-confirmation.mjs";
9
9
  import { actionApproval, confirmations, inputHash } from "./confirmations.mjs";
10
10
  import { ontologyTools } from "./ontology-tools.mjs";
@@ -131,7 +131,7 @@ function ontologyFileCall(texts) {
131
131
  toolInput: request(ctx.request.callId, ctx.request.toolInput, memberIdOf(ctx.request.principal))
132
132
  }
133
133
  });
134
- if (decision.status === "allowed" && ctx.response.decision === "cancel") releasePayload(ctx.request.callId);
134
+ if (decision.status === "allowed" && ctx.response.decision === "deny") releasePayload(ctx.request.callId);
135
135
  return decision;
136
136
  } catch {
137
137
  return {
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { appOrigin } from "./environment.mjs";
8
- import { c as compatibleRuntimeEnvelope, i as memberIdOf, r as identityProviderOf, s as RUNTIME_SOURCE_PROTOCOL, u as runtimeEnvelope } from "../../_chunks/principal-qyR3jKAr.mjs";
8
+ import { c as compatibleRuntimeEnvelope, i as memberIdOf, r as identityProviderOf, s as RUNTIME_SOURCE_PROTOCOL, u as runtimeEnvelope } from "../../_chunks/principal-BnJuWJtk.mjs";
9
9
  import { redactDiagnostic } from "./diagnostics.mjs";
10
10
  import { describeConfirmation, object } from "./confirmation-description.mjs";
11
11
  import { runtimeToken } from "./runtime-token.mjs";
@@ -4,5 +4,5 @@ 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 { c as compatibleRuntimeEnvelope, d as telegramRuntimeSource, l as principalRuntimeSource, s as RUNTIME_SOURCE_PROTOCOL, u as runtimeEnvelope } from "../../_chunks/principal-qyR3jKAr.mjs";
7
+ import { c as compatibleRuntimeEnvelope, d as telegramRuntimeSource, l as principalRuntimeSource, s as RUNTIME_SOURCE_PROTOCOL, u as runtimeEnvelope } from "../../_chunks/principal-BnJuWJtk.mjs";
8
8
  export { RUNTIME_SOURCE_PROTOCOL, compatibleRuntimeEnvelope, principalRuntimeSource, runtimeEnvelope, telegramRuntimeSource };
@@ -16,9 +16,10 @@ import { type SandboxSession } from "eve/sandbox";
16
16
  * open. The Ubuntu packages exist in Ubuntu 26.04, the eve base image's release; a missing name
17
17
  * would fail preparation and so the deploy. pdfplumber, which Ubuntu does not ship, is pinned with
18
18
  * the two dependencies Ubuntu's are too old for, by version and hash, into the sandbox user's own
19
- * site-packages; its pdfminer.six 20260107 is Ubuntu's python3-pdfminer.
19
+ * site-packages. Install pip explicitly: Eve 0.84+ no longer includes it in the base image.
20
+ * Its pdfminer.six 20260107 is Ubuntu's python3-pdfminer.
20
21
  */
21
- export declare const SANDBOX_PREPARE_SCRIPT = "set -euo pipefail\nsudo apt-get update -q\nsudo env DEBIAN_FRONTEND=noninteractive apt-get install -y -q --no-install-recommends \\\n poppler-utils qpdf tesseract-ocr tesseract-ocr-eng tesseract-ocr-rus 7zip unar \\\n imagemagick ghostscript python3-pandas python3-openpyxl python3-pypdf python3-pdfminer\nsudo apt-get clean\nsudo rm -rf /var/lib/apt/lists/*\nrequirements=\"$(mktemp)\"\ncat > \"$requirements\" <<'REQUIREMENTS'\npdfplumber==0.11.10 \\\n --hash=sha256:7741ea81bf165b474b153e6789d10d18e06b6ddcf3ec84289c3ef2fed6802580\npillow==12.2.0 \\\n --hash=sha256:4bfd07bc812fbd20395212969e41931001fd59eb55a60658b0e5710872e95286 \\\n --hash=sha256:7b14cc0106cd9aecda615dd6903840a058b4700fcb817687d0ee4fc8b6e389be \\\n --hash=sha256:8cbeb542b2ebc6fcdacabf8aca8c1a97c9b3ad3927d46b8723f9d4f033288a0f \\\n --hash=sha256:22db17c68434de69d8ecfc2fe821569195c0c373b25cccb9cbdacf2c6e53c601\npypdfium2==5.9.0 \\\n --hash=sha256:7ce3a3dd23ec0adaa079d8be54565ba2aa2f6060e76a4989cd42dabc163d74ee \\\n --hash=sha256:1d902e03dff5efd51d93cd23d3e55bde53802fa6207bcd0e455239518859a069\nREQUIREMENTS\npython3 -m pip install --user --break-system-packages --no-cache-dir --no-deps \\\n --only-binary=:all: --require-hashes --disable-pip-version-check -r \"$requirements\"\nrm -f \"$requirements\"\nmkdir -p /workspace/work\nfor tool in pdftotext pdftoppm qpdf tesseract gs 7z unar unzip jq rg; do\n command -v \"$tool\" > /dev/null\ndone\nlanguages=\"$(tesseract --list-langs)\"\ngrep -qx eng <<< \"$languages\"\ngrep -qx rus <<< \"$languages\"\npython3 -c 'import openpyxl, pandas, pdfminer, pdfplumber, pypdf, pypdfium2'\n";
22
+ export declare const SANDBOX_PREPARE_SCRIPT = "set -euo pipefail\nsudo apt-get update -q\nsudo env DEBIAN_FRONTEND=noninteractive apt-get install -y -q --no-install-recommends \\\n poppler-utils qpdf tesseract-ocr tesseract-ocr-eng tesseract-ocr-rus 7zip unar \\\n imagemagick ghostscript python3-pip python3-pandas python3-openpyxl python3-pypdf python3-pdfminer\nsudo apt-get clean\nsudo rm -rf /var/lib/apt/lists/*\nrequirements=\"$(mktemp)\"\ncat > \"$requirements\" <<'REQUIREMENTS'\npdfplumber==0.11.10 \\\n --hash=sha256:7741ea81bf165b474b153e6789d10d18e06b6ddcf3ec84289c3ef2fed6802580\npillow==12.2.0 \\\n --hash=sha256:4bfd07bc812fbd20395212969e41931001fd59eb55a60658b0e5710872e95286 \\\n --hash=sha256:7b14cc0106cd9aecda615dd6903840a058b4700fcb817687d0ee4fc8b6e389be \\\n --hash=sha256:8cbeb542b2ebc6fcdacabf8aca8c1a97c9b3ad3927d46b8723f9d4f033288a0f \\\n --hash=sha256:22db17c68434de69d8ecfc2fe821569195c0c373b25cccb9cbdacf2c6e53c601\npypdfium2==5.9.0 \\\n --hash=sha256:7ce3a3dd23ec0adaa079d8be54565ba2aa2f6060e76a4989cd42dabc163d74ee \\\n --hash=sha256:1d902e03dff5efd51d93cd23d3e55bde53802fa6207bcd0e455239518859a069\nREQUIREMENTS\npython3 -m pip install --user --break-system-packages --no-cache-dir --no-deps \\\n --only-binary=:all: --require-hashes --disable-pip-version-check -r \"$requirements\"\nrm -f \"$requirements\"\nmkdir -p /workspace/work\nfor tool in pdftotext pdftoppm qpdf tesseract gs 7z unar unzip jq rg; do\n command -v \"$tool\" > /dev/null\ndone\nlanguages=\"$(tesseract --list-langs)\"\ngrep -qx eng <<< \"$languages\"\ngrep -qx rus <<< \"$languages\"\npython3 -c 'import openpyxl, pandas, pdfminer, pdfplumber, pypdf, pypdfium2'\n";
22
23
  /**
23
24
  * Identifies the toolset. eve keys a prepared snapshot on the authored `sandbox.ts` and the
24
25
  * environment's options, not on a `prepare` imported from a package, so the version travels as a
@@ -12,7 +12,7 @@ const SANDBOX_PREPARE_SCRIPT = `set -euo pipefail
12
12
  sudo apt-get update -q
13
13
  sudo env DEBIAN_FRONTEND=noninteractive apt-get install -y -q --no-install-recommends \\
14
14
  poppler-utils qpdf tesseract-ocr tesseract-ocr-eng tesseract-ocr-rus 7zip unar \\
15
- imagemagick ghostscript python3-pandas python3-openpyxl python3-pypdf python3-pdfminer
15
+ imagemagick ghostscript python3-pip python3-pandas python3-openpyxl python3-pypdf python3-pdfminer
16
16
  sudo apt-get clean
17
17
  sudo rm -rf /var/lib/apt/lists/*
18
18
  requirements="$(mktemp)"
@@ -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 { i as memberIdOf } from "../../_chunks/principal-qyR3jKAr.mjs";
7
+ import { i as memberIdOf } from "../../_chunks/principal-BnJuWJtk.mjs";
8
8
  import { redactDiagnostic } from "./diagnostics.mjs";
9
9
  import { object } from "./confirmation-description.mjs";
10
10
  import { OntologyFileUnavailable, ontologyTools } from "./ontology-tools.mjs";
@@ -7,13 +7,14 @@ __eveCreateRequire(import.meta.url);
7
7
  import { telegramText, withTelegramTexts } from "./texts.mjs";
8
8
  import { manifestOf } from "../../config.mjs";
9
9
  import { appOrigin, channelsEnabled, proxyEnvironment, runtimeIdentityEnvironment, webhookSecret } from "../environment.mjs";
10
- import { n as conversationLanguage, o as telegramPrincipal } from "../../../_chunks/principal-qyR3jKAr.mjs";
10
+ import { n as conversationLanguage, o as telegramPrincipal } from "../../../_chunks/principal-BnJuWJtk.mjs";
11
+ import { object } from "../confirmation-description.mjs";
11
12
  import { confirmationLocale } from "./confirmation-text.mjs";
12
13
  import { telegramSendScope } from "./send-queue.mjs";
13
14
  import { runtimeToken } from "../runtime-token.mjs";
14
15
  import { conversations } from "../conversations.mjs";
15
16
  import { withDeliveryDiagnostics } from "./delivery-diagnostics.mjs";
16
- import { d as failureText, h as withDeliveryLocale, i as withReplacedText, m as safeTelegramFetch, n as currentInboundRequest, o as currentLocale, p as reportTelegramError, r as runInboundRequest, t as InboundRequest } from "../../../_chunks/inbound-request-8xhK7EaW.mjs";
17
+ import { d as failureText, h as withDeliveryLocale, i as withReplacedText, m as safeTelegramFetch, n as currentInboundRequest, o as currentLocale, p as reportTelegramError, r as runInboundRequest, t as InboundRequest } from "../../../_chunks/inbound-request-Dx1B6Y5r.mjs";
17
18
  import { chooseModel } from "../../model.mjs";
18
19
  import { groupRoutingHealth } from "../group-routing/health.mjs";
19
20
  import { decisionRouter } from "../group-routing/router.mjs";
@@ -22,7 +23,7 @@ import { MAXIMUM_DOWNLOAD_BYTES, connectionProxy } from "../connection-proxy.mjs
22
23
  import { dispatchStructuredMessage, structuredMessage } from "./structured.mjs";
23
24
  import { scopedAddress, sessionPolicy } from "./sessions.mjs";
24
25
  import { handleWorkspaceCallback, isWorkspaceCallback } from "./callbacks.mjs";
25
- import { t as agentBuild } from "../../../_chunks/build-metadata-DZ9Nb8Q2.mjs";
26
+ import { t as agentBuild } from "../../../_chunks/build-metadata-CZ245Pl3.mjs";
26
27
  import { attachmentLifecycle } from "./lifecycle.mjs";
27
28
  import { observedMessages } from "./observed.mjs";
28
29
  import { expireDeferredCards, handleDeferredCallback, isDeferredCallback } from "./deferred-confirmations.mjs";
@@ -54,11 +55,9 @@ const eveHistory = async (sessionId) => {
54
55
  follow: false
55
56
  })) events.push({
56
57
  type: event.type,
57
- meta: { at: event.meta.at },
58
- ...event.type === "step.started" ? { data: { modelId: event.data.modelId } } : event.type === "message.completed" ? { data: {
59
- message: event.data.message,
60
- finishReason: event.data.finishReason
61
- } } : {}
58
+ meta: event.meta,
59
+ data: event.data,
60
+ scope: event.scope
62
61
  });
63
62
  return events;
64
63
  };
@@ -67,8 +66,9 @@ const eveInteractions = async (sessionId) => {
67
66
  const events = [];
68
67
  for await (const event of sessions.attach(sessionId).stream({ follow: false })) events.push({
69
68
  type: event.type,
70
- meta: { at: event.meta.at },
71
- data: event.data
69
+ meta: event.meta,
70
+ data: event.data,
71
+ scope: event.scope
72
72
  });
73
73
  return events;
74
74
  };
@@ -165,6 +165,15 @@ function segmentstreamTelegram(options) {
165
165
  });
166
166
  return store;
167
167
  }
168
+ const failureEvents = telegramFailureEvents({
169
+ archive,
170
+ identities: pairing
171
+ });
172
+ const approvalEvents = telegramConfirmationEvents(archive, observed, {
173
+ environment,
174
+ token,
175
+ ...options.fetch ? { fetch: options.fetch } : {}
176
+ });
168
177
  const channel = telegramChannel({
169
178
  turnPolicy: "queue",
170
179
  api: {
@@ -249,7 +258,7 @@ function segmentstreamTelegram(options) {
249
258
  if (sessionId !== void 0) try {
250
259
  for (const event of await readHistory(sessionId)) {
251
260
  const data = event.data;
252
- if (event.type === "step.started" && typeof data?.modelId === "string") selected = data.modelId;
261
+ if (event.type === "model.started" && typeof data?.modelId === "string") selected = data.modelId;
253
262
  }
254
263
  } catch (error) {
255
264
  reportTelegramError("media_session_model_lookup_failed", error, { sessionId });
@@ -379,20 +388,23 @@ function segmentstreamTelegram(options) {
379
388
  }
380
389
  },
381
390
  events: {
382
- ...telegramFailureEvents({
383
- archive,
384
- identities: pairing
385
- }),
386
- ...telegramConfirmationEvents(archive, observed, {
387
- environment,
388
- token,
389
- ...options.fetch ? { fetch: options.fetch } : {}
390
- }),
391
- async "message.completed"(event, channel, context) {
391
+ ...failureEvents,
392
+ ...approvalEvents,
393
+ async "interaction.opened"(event, ctx) {
394
+ await failureEvents["interaction.opened"]?.(event, ctx);
395
+ await approvalEvents["interaction.opened"]?.(event, ctx);
396
+ },
397
+ async "interaction.settled"(event, ctx) {
398
+ await failureEvents["interaction.settled"]?.(event, ctx);
399
+ await approvalEvents["interaction.settled"]?.(event, ctx);
400
+ },
401
+ async "content.completed"(event, context) {
402
+ const channel = context.channel;
403
+ const message = typeof event.data.value === "string" ? event.data.value : "";
392
404
  const principal = context.session.auth.current;
393
405
  const taskId = principal?.attributes.taskId;
394
406
  const configuration = settings().attachmentLifecycle;
395
- if (event.finishReason !== "tool-calls" && event.message && configuration && principal && typeof taskId === "string") try {
407
+ if (event.data.kind === "text" && event.data.phase === "reply" && !event.data.interrupted && message && configuration && principal && typeof taskId === "string") try {
396
408
  const memberId = principal.attributes.memberId;
397
409
  if (typeof memberId !== "string") throw new Error("A current member is required for completion.");
398
410
  const result = await attachmentLifecycle({
@@ -410,12 +422,15 @@ function segmentstreamTelegram(options) {
410
422
  }
411
423
  })("completed", {
412
424
  key: taskId,
413
- ...configuration.contextVersion === 2 ? { reply: event.message } : {},
425
+ ...configuration.contextVersion === 2 ? { reply: message } : {},
414
426
  ...typeof principal.attributes.attachmentDispatchToken === "string" ? { dispatch_token: principal.attributes.attachmentDispatchToken } : {}
415
427
  });
416
428
  if (result.message !== void 0 || result.complete === false) event = {
417
429
  ...event,
418
- message: result.message ?? ""
430
+ data: {
431
+ ...event.data,
432
+ value: result.message ?? ""
433
+ }
419
434
  };
420
435
  } catch (error) {
421
436
  const reference = reportTelegramError("intake_completion_failed", error, {
@@ -428,7 +443,7 @@ function segmentstreamTelegram(options) {
428
443
  await replyDelivery(observed, () => telegramSendScope(environment, settings().connection), {
429
444
  enabled: () => settings().interimMessages === true,
430
445
  delivered: interimDelivered
431
- })(event, channel, context);
446
+ })(event, context);
432
447
  }
433
448
  }
434
449
  });
@@ -484,7 +499,7 @@ function segmentstreamTelegram(options) {
484
499
  chatType: String(context.state.chatId).startsWith("-") ? "group" : "private",
485
500
  threadId: context.state.messageThreadId == null ? null : String(context.state.messageThreadId),
486
501
  sessionId: context.session?.id ?? null,
487
- turnId: typeof event === "object" && event !== null && "turnId" in event && typeof event.turnId === "string" ? event.turnId : null
502
+ turnId: typeof event === "object" && event !== null && "scope" in event && typeof object(event.scope).turnId === "string" ? String(object(event.scope).turnId) : null
488
503
  }, () => handler(event, context)), currentLocale);
489
504
  }, context.state.messageThreadId === null ? void 0 : String(context.state.messageThreadId), typeof principal?.attributes.replyToMessageId === "string" ? principal.attributes.replyToMessageId : void 0, typeof principal?.attributes.chatId === "string" ? principal.attributes.chatId : void 0);
490
505
  }]))
@@ -557,8 +572,8 @@ function gatedRoute(input) {
557
572
  });
558
573
  };
559
574
  inbound.respond = (address, requestId, decision, auth, text) => args.from(scoped(address)).respond([{
560
- requestId,
561
- optionId: decision,
575
+ interactionId: requestId,
576
+ optionId: decision === "cancel" ? "deny" : "approve",
562
577
  ...text === void 0 ? {} : { text }
563
578
  }], { auth });
564
579
  const tasks = [];
@@ -0,0 +1,4 @@
1
+ import type { TelegramMessage } from "eve/channels/telegram";
2
+ /** Archive-only projection before Eve dispatch: also covers edits and channel posts that Eve drops.
3
+ * Eve owns webhook parsing and dispatch. This projection cannot admit a message or authorize a turn. */
4
+ export declare function parseArchivedMessage(value: unknown): TelegramMessage | undefined;
@@ -0,0 +1,85 @@
1
+ import { fileURLToPath as __eveFileURLToPath } from "node:url";
2
+ import { dirname as __eveDirname } from "node:path";
3
+ import { createRequire as __eveCreateRequire } from "node:module";
4
+ const __filename = __eveFileURLToPath(import.meta.url);
5
+ __eveDirname(__filename);
6
+ __eveCreateRequire(import.meta.url);
7
+ const object = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
8
+ const text = (value) => typeof value === "string" ? value : void 0;
9
+ const number = (value) => typeof value === "number" && Number.isFinite(value) ? value : void 0;
10
+ const id = (value) => text(value) || (number(value) === void 0 ? void 0 : String(value));
11
+ function chat(value) {
12
+ const raw = object(value);
13
+ const chatId = id(raw.id);
14
+ const type = raw.type;
15
+ if (!chatId || type !== "private" && type !== "group" && type !== "supergroup" && type !== "channel") return;
16
+ return {
17
+ id: chatId,
18
+ type,
19
+ title: text(raw.title),
20
+ username: text(raw.username)
21
+ };
22
+ }
23
+ function user(value) {
24
+ const raw = object(value);
25
+ const userId = id(raw.id);
26
+ if (!userId) return;
27
+ return {
28
+ id: userId,
29
+ isBot: raw.is_bot === true,
30
+ firstName: text(raw.first_name),
31
+ lastName: text(raw.last_name),
32
+ username: text(raw.username),
33
+ languageCode: text(raw.language_code)
34
+ };
35
+ }
36
+ function reference(value) {
37
+ const raw = object(value);
38
+ const target = chat(raw.chat);
39
+ const messageId = id(raw.message_id);
40
+ if (!target || !messageId) return;
41
+ return {
42
+ chat: target,
43
+ messageId,
44
+ from: user(raw.from),
45
+ messageThreadId: number(raw.message_thread_id),
46
+ text: text(raw.text)
47
+ };
48
+ }
49
+ function parseArchivedMessage(value) {
50
+ const raw = object(value);
51
+ const message = reference(raw);
52
+ if (!message) return;
53
+ const attachments = [];
54
+ const photos = (Array.isArray(raw.photo) ? raw.photo : []).map(object).filter((photo) => text(photo.file_id));
55
+ const score = (photo) => number(photo.file_size) ?? (number(photo.width) ?? 0) * (number(photo.height) ?? 0);
56
+ const photo = photos.sort((a, b) => score(b) - score(a))[0];
57
+ if (photo) attachments.push({
58
+ kind: "photo",
59
+ fileId: String(photo.file_id),
60
+ fileName: "photo.jpg",
61
+ mediaType: "image/jpeg",
62
+ fileUniqueId: text(photo.file_unique_id),
63
+ size: number(photo.file_size),
64
+ width: number(photo.width),
65
+ height: number(photo.height)
66
+ });
67
+ const document = object(raw.document);
68
+ if (text(document.file_id)) attachments.push({
69
+ kind: "document",
70
+ fileId: String(document.file_id),
71
+ fileName: text(document.file_name),
72
+ mediaType: text(document.mime_type),
73
+ fileUniqueId: text(document.file_unique_id),
74
+ size: number(document.file_size)
75
+ });
76
+ return {
77
+ ...message,
78
+ text: text(raw.text) ?? "",
79
+ caption: text(raw.caption) ?? "",
80
+ replyToMessage: reference(raw.reply_to_message),
81
+ attachments,
82
+ raw
83
+ };
84
+ }
85
+ export { parseArchivedMessage };
@@ -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 { p as reportTelegramError } from "../../../_chunks/inbound-request-8xhK7EaW.mjs";
7
+ import { p as reportTelegramError } from "../../../_chunks/inbound-request-Dx1B6Y5r.mjs";
8
8
  import { describableImage } from "./images.mjs";
9
9
  import { MAXIMUM_ROUTING_PDF_CHARACTERS, extractRoutingPdf } from "./pdf-text.mjs";
10
10
  import { gateway, generateText } from "ai";
@@ -5,12 +5,12 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { appOrigin, channelsEnabled, proxyEnvironment } from "../environment.mjs";
8
- import "../../../_chunks/principal-qyR3jKAr.mjs";
8
+ import "../../../_chunks/principal-BnJuWJtk.mjs";
9
9
  import { redactDiagnostic } from "../diagnostics.mjs";
10
10
  import { confirmationLocale } from "./confirmation-text.mjs";
11
11
  import { inTelegramSendQueue, telegramSendScope } from "./send-queue.mjs";
12
12
  import { runtimeToken } from "../runtime-token.mjs";
13
- import { d as failureText, f as formattingRefused, l as customerMessage, p as reportTelegramError } from "../../../_chunks/inbound-request-8xhK7EaW.mjs";
13
+ import { d as failureText, f as formattingRefused, l as customerMessage, p as reportTelegramError } from "../../../_chunks/inbound-request-Dx1B6Y5r.mjs";
14
14
  import { MAXIMUM_PROXY_BODY_BYTES, connectionProxy } from "../connection-proxy.mjs";
15
15
  import { ACT_AS_HEADER } from "../ontology-connection.mjs";
16
16
  import { AttachmentError, CONVERSATION_HEADER, SESSION_HEADER } from "../attachments.mjs";
@@ -6,9 +6,9 @@ __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { admitMessage } from "../admission.mjs";
8
8
  import { telegramText } from "./texts.mjs";
9
- import { d as telegramRuntimeSource, i as memberIdOf, o as telegramPrincipal, u as runtimeEnvelope } from "../../../_chunks/principal-qyR3jKAr.mjs";
9
+ import { d as telegramRuntimeSource, i as memberIdOf, o as telegramPrincipal, u as runtimeEnvelope } from "../../../_chunks/principal-BnJuWJtk.mjs";
10
10
  import { object } from "../confirmation-description.mjs";
11
- import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-8xhK7EaW.mjs";
11
+ import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-Dx1B6Y5r.mjs";
12
12
  import { workspaceAction } from "./workspace-action.mjs";
13
13
  import { formatAddress, parseAddress, scopedAddress } from "./sessions.mjs";
14
14
  const isWorkspaceCallback = (data) => data?.startsWith("ws:") === true;
@@ -9,13 +9,12 @@ import { proxyEnvironment } from "../environment.mjs";
9
9
  import { telegramSendScope } from "./send-queue.mjs";
10
10
  import { runtimeToken } from "../runtime-token.mjs";
11
11
  import { conversations } from "../conversations.mjs";
12
- import { m as safeTelegramFetch, p as reportTelegramError } from "../../../_chunks/inbound-request-8xhK7EaW.mjs";
12
+ import { m as safeTelegramFetch, p as reportTelegramError } from "../../../_chunks/inbound-request-Dx1B6Y5r.mjs";
13
13
  import { connectionProxy } from "../connection-proxy.mjs";
14
14
  import { deferredConfirmations } from "../deferred-confirmations.mjs";
15
15
  import { expireDeferredRecord } from "./deferred-confirmations.mjs";
16
16
  import { TELEGRAM_PLACEHOLDER_TOKEN, TELEGRAM_PROXY_ORIGIN, telegramProxyFetch } from "./proxy-fetch.mjs";
17
17
  import { telegramPreviewEnvironment } from "@segmentstream-cloud/ontology/telegram";
18
- import { editTelegramMessageText } from "eve/channels/telegram";
19
18
  async function expireScheduledConfirmations(connection, notify, options = {}, settings, texts = {}) {
20
19
  const environment = options.environment ?? process.env;
21
20
  const token = options.token ?? runtimeToken;
@@ -37,13 +36,25 @@ async function expireScheduledConfirmations(connection, notify, options = {}, se
37
36
  });
38
37
  const records = await deferredConfirmations(options).command({ operation: "expired" });
39
38
  for (const record of records) try {
40
- await withTelegramTexts(texts, () => expireDeferredRecord(record, { telegram: { editMessageText: (input) => editTelegramMessageText({
41
- apiBaseUrl: TELEGRAM_PROXY_ORIGIN,
42
- credentials: { botToken: TELEGRAM_PLACEHOLDER_TOKEN },
43
- fetch: transport,
44
- chatId: record.data.chatId,
45
- ...input
46
- }) } }, options, archive, notify), () => record.data.locale ?? "en");
39
+ await withTelegramTexts(texts, () => expireDeferredRecord(record, { telegram: { editMessageText: async (input) => {
40
+ const response = await transport(`${TELEGRAM_PROXY_ORIGIN}/bot${TELEGRAM_PLACEHOLDER_TOKEN}/editMessageText`, {
41
+ method: "POST",
42
+ headers: { "content-type": "application/json" },
43
+ body: JSON.stringify({
44
+ chat_id: record.data.chatId,
45
+ message_id: input.messageId,
46
+ text: input.text,
47
+ reply_markup: input.replyMarkup
48
+ })
49
+ });
50
+ const result = await response.json();
51
+ if (!response.ok || result.ok !== true) throw new Error(`Telegram confirmation expiry failed: ${result.description ?? response.status}`);
52
+ return {
53
+ ok: true,
54
+ status: response.status,
55
+ body: result
56
+ };
57
+ } } }, options, archive, notify), () => record.data.locale ?? "en");
47
58
  } catch (error) {
48
59
  reportTelegramError("deferred_expiry_failed", error);
49
60
  }
@@ -24,5 +24,5 @@ export declare function handleConfirmationCallback(input: {
24
24
  readonly scope: "chat" | "thread";
25
25
  readonly now?: number;
26
26
  }): Promise<void>;
27
- export declare function telegramConfirmationEvents(archive?: Conversations, observed?: ObservedMessages, deferredOptions?: DeferredOptions): TelegramChannelEvents & Pick<ChannelEvents<TelegramEventContext>, "context.cleared">;
28
- export declare const confirmationEvents: TelegramChannelEvents & Pick<ChannelEvents<TelegramEventContext>, "context.cleared">;
27
+ export declare function telegramConfirmationEvents(archive?: Conversations, observed?: ObservedMessages, deferredOptions?: DeferredOptions): TelegramChannelEvents & Pick<ChannelEvents<TelegramEventContext>, "context.settled">;
28
+ export declare const confirmationEvents: TelegramChannelEvents & Pick<ChannelEvents<TelegramEventContext>, "context.settled">;