@segmentstream/agent 0.23.16 → 0.24.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 (68) hide show
  1. package/README.md +11 -10
  2. package/dist/_chunks/{build-metadata-D471R-eU.mjs → build-metadata-C5051bJL.mjs} +1 -1
  3. package/dist/_chunks/{inbound-request-gJ5wpsBF.mjs → inbound-request-xmrm-49O.mjs} +0 -1
  4. package/dist/_chunks/{principal-69qoDdqy.mjs → principal-DMNXj4PX.mjs} +1 -1
  5. package/dist/extension/hooks/authorization.mjs +1 -1
  6. package/dist/extension/instructions.md +4 -19
  7. package/dist/extension/lib/actor.mjs +1 -1
  8. package/dist/extension/lib/attachment-tools.mjs +1 -1
  9. package/dist/extension/lib/build-metadata.mjs +1 -1
  10. package/dist/extension/lib/confirmation-description.d.ts +5 -0
  11. package/dist/extension/lib/confirmation-description.mjs +11 -3
  12. package/dist/extension/lib/confirmations.d.ts +1 -1
  13. package/dist/extension/lib/confirmations.mjs +3 -1
  14. package/dist/extension/lib/conversation-runtime.mjs +15 -2
  15. package/dist/extension/lib/group-routing/observed.mjs +1 -1
  16. package/dist/extension/lib/group-routing/router.d.ts +8 -2
  17. package/dist/extension/lib/group-routing/router.mjs +4 -2
  18. package/dist/extension/lib/ontology-connection.mjs +1 -1
  19. package/dist/extension/lib/ontology-file-call.mjs +1 -1
  20. package/dist/extension/lib/ontology-tools.d.ts +1 -1
  21. package/dist/extension/lib/ontology-tools.mjs +1 -1
  22. package/dist/extension/lib/runtime-envelope.mjs +1 -1
  23. package/dist/extension/lib/stored-files.d.ts +23 -8
  24. package/dist/extension/lib/stored-files.mjs +54 -43
  25. package/dist/extension/lib/telegram/adapter.mjs +11 -50
  26. package/dist/extension/lib/telegram/attachment-description.mjs +1 -1
  27. package/dist/extension/lib/telegram/attachments-send.mjs +2 -2
  28. package/dist/extension/lib/telegram/callbacks.mjs +2 -2
  29. package/dist/extension/lib/telegram/confirmations.d.ts +1 -2
  30. package/dist/extension/lib/telegram/confirmations.mjs +3 -11
  31. package/dist/extension/lib/telegram/conversations.mjs +2 -2
  32. package/dist/extension/lib/telegram/customer-text.mjs +1 -1
  33. package/dist/extension/lib/telegram/durable-typing.mjs +1 -1
  34. package/dist/extension/lib/telegram/files.mjs +2 -2
  35. package/dist/extension/lib/telegram/health.mjs +1 -1
  36. package/dist/extension/lib/telegram/held-approvals.d.ts +5 -2
  37. package/dist/extension/lib/telegram/held-approvals.mjs +1 -2
  38. package/dist/extension/lib/telegram/images.mjs +1 -1
  39. package/dist/extension/lib/telegram/inbound-request.d.ts +0 -2
  40. package/dist/extension/lib/telegram/inbound-request.mjs +1 -1
  41. package/dist/extension/lib/telegram/inbound.d.ts +0 -2
  42. package/dist/extension/lib/telegram/inbound.mjs +10 -9
  43. package/dist/extension/lib/telegram/lifecycle.mjs +3 -3
  44. package/dist/extension/lib/telegram/media-policy.mjs +1 -1
  45. package/dist/extension/lib/telegram/principal.mjs +1 -1
  46. package/dist/extension/lib/telegram/session-recovery.mjs +1 -1
  47. package/dist/extension/lib/telegram/sessions.d.ts +8 -0
  48. package/dist/extension/lib/telegram/sessions.mjs +21 -1
  49. package/dist/extension/lib/telegram/silent.mjs +2 -2
  50. package/dist/extension/lib/telegram/structured.mjs +1 -1
  51. package/dist/extension/lib/telegram/turn-errors.mjs +2 -2
  52. package/dist/extension/lib/telegram/voice.mjs +1 -1
  53. package/dist/extension/model.mjs +1 -1
  54. package/dist/extension/tools/attachments_promote.mjs +1 -1
  55. package/dist/extension/tools/attachments_stage.d.ts +2 -1
  56. package/dist/extension/tools/attachments_stage.mjs +53 -20
  57. package/dist/extension/tools/questions_ask.mjs +1 -1
  58. package/package.json +1 -1
  59. package/dist/extension/lib/confirmation-outcome.d.ts +0 -27
  60. package/dist/extension/lib/confirmation-outcome.mjs +0 -34
  61. package/dist/extension/lib/deferred-confirmations.d.ts +0 -41
  62. package/dist/extension/lib/deferred-confirmations.mjs +0 -77
  63. package/dist/extension/lib/telegram/confirmation-expiry.d.ts +0 -5
  64. package/dist/extension/lib/telegram/confirmation-expiry.mjs +0 -62
  65. package/dist/extension/lib/telegram/deferred-confirmations.d.ts +0 -26
  66. package/dist/extension/lib/telegram/deferred-confirmations.mjs +0 -295
  67. package/dist/extension/schedules/confirmations.d.ts +0 -6
  68. package/dist/extension/schedules/confirmations.mjs +0 -33
@@ -9,13 +9,13 @@ import { runtimeToken } from "../runtime-token.mjs";
9
9
  import { runtimeTokenVerifier } from "../runtime-identity.mjs";
10
10
  import { telegramText, withTelegramTexts } from "./texts.mjs";
11
11
  import { manifestOf } from "../../config.mjs";
12
- import { n as conversationLanguage, o as telegramPrincipal } from "../../../_chunks/principal-69qoDdqy.mjs";
12
+ import { n as conversationLanguage, o as telegramPrincipal } from "../../../_chunks/principal-DMNXj4PX.mjs";
13
13
  import { object } from "../confirmation-description.mjs";
14
14
  import { confirmationLocale } from "./confirmation-text.mjs";
15
15
  import { telegramSendScope } from "./send-queue.mjs";
16
16
  import { conversations } from "../conversations.mjs";
17
17
  import { withDeliveryDiagnostics } from "./delivery-diagnostics.mjs";
18
- 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-gJ5wpsBF.mjs";
18
+ 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-xmrm-49O.mjs";
19
19
  import { chooseModel } from "../../model.mjs";
20
20
  import { groupRoutingHealth } from "../group-routing/health.mjs";
21
21
  import { decisionRouter } from "../group-routing/router.mjs";
@@ -24,14 +24,13 @@ import { MAXIMUM_DOWNLOAD_BYTES, connectionProxy } from "../connection-proxy.mjs
24
24
  import { dispatchStructuredMessage, structuredMessage } from "./structured.mjs";
25
25
  import { scopedAddress, sessionPolicy } from "./sessions.mjs";
26
26
  import { handleWorkspaceCallback, isWorkspaceCallback } from "./callbacks.mjs";
27
- import { t as agentBuild } from "../../../_chunks/build-metadata-D471R-eU.mjs";
27
+ import { t as agentBuild } from "../../../_chunks/build-metadata-C5051bJL.mjs";
28
28
  import { attachmentLifecycle } from "./lifecycle.mjs";
29
- import { observedMessages } from "./observed.mjs";
30
- import { expireDeferredCards, handleDeferredCallback, isDeferredCallback } from "./deferred-confirmations.mjs";
31
29
  import { gatewayImageDescriber } from "./images.mjs";
32
30
  import { gatewayAttachmentDescriber } from "./attachment-description.mjs";
33
31
  import { agentAttachments, parseAttachmentUrl } from "../attachments.mjs";
34
32
  import { agentIdentities } from "../identities.mjs";
33
+ import { observedMessages } from "./observed.mjs";
35
34
  import { interimTexts, replyDelivery } from "./silent.mjs";
36
35
  import { handleConfirmationCallback, telegramConfirmationEvents } from "./confirmations.mjs";
37
36
  import { captureRouteDecider, captureTelegramFetch, conversationIdentities, recordGateDecision, telegramConversationCapture } from "./conversations.mjs";
@@ -47,6 +46,7 @@ import { telegramFailureEvents } from "./turn-errors.mjs";
47
46
  import { telegramWebhookVerifier } from "./webhook.mjs";
48
47
  import { telegramPreviewEnvironment } from "@segmentstream-cloud/ontology/telegram";
49
48
  import { telegramChannel } from "eve/channels/telegram";
49
+ const LEGACY_DEFERRED_CALLBACK = "ss-confirm:d:";
50
50
  const eveHistory = async (sessionId) => {
51
51
  const { sessions } = await import("eve/server");
52
52
  const events = [];
@@ -169,11 +169,7 @@ function segmentstreamTelegram(options) {
169
169
  archive,
170
170
  identities: pairing
171
171
  });
172
- const approvalEvents = telegramConfirmationEvents(archive, observed, {
173
- environment,
174
- token,
175
- ...options.fetch ? { fetch: options.fetch } : {}
176
- }, () => options.sessions().scope);
172
+ const approvalEvents = telegramConfirmationEvents(archive, observed, () => options.sessions().scope);
177
173
  const channel = telegramChannel({
178
174
  turnPolicy: "queue",
179
175
  api: {
@@ -190,15 +186,6 @@ function segmentstreamTelegram(options) {
190
186
  },
191
187
  uploadPolicy: { maxBytes: MAXIMUM_DOWNLOAD_BYTES },
192
188
  onMessage: async (context, message) => {
193
- try {
194
- await expireDeferredCards(context, {
195
- environment,
196
- token,
197
- ...options.fetch ? { fetch: options.fetch } : {}
198
- }, archive, observed);
199
- } catch (error) {
200
- reportTelegramError("deferred_expiry_failed", error);
201
- }
202
189
  const inbound = currentInboundRequest();
203
190
  if (inbound !== void 0) {
204
191
  inbound.locale = conversationLanguage([message.text || message.caption]) ?? message.from?.languageCode ?? "en";
@@ -235,7 +222,6 @@ function segmentstreamTelegram(options) {
235
222
  ...options.fetch ? { fetch: options.fetch } : {}
236
223
  })
237
224
  } },
238
- recoverHeldApprovals: options.confirmationMode?.() === "deferred",
239
225
  ...settings().attachmentLifecycle === void 0 ? {} : { lifecycle: (principal, memberId, message) => attachmentLifecycle({
240
226
  configuration: settings().attachmentLifecycle,
241
227
  principal,
@@ -357,18 +343,11 @@ function segmentstreamTelegram(options) {
357
343
  });
358
344
  return;
359
345
  }
360
- if (isDeferredCallback(query.data)) {
361
- await handleDeferredCallback({
362
- context,
363
- query,
364
- identities: pairing(),
365
- archive,
366
- options: {
367
- environment,
368
- token,
369
- ...options.fetch ? { fetch: options.fetch } : {}
370
- },
371
- observed
346
+ if (query.data?.startsWith(LEGACY_DEFERRED_CALLBACK) === true) {
347
+ const expired = telegramText("callback", "expired");
348
+ await context.telegram.answerCallbackQuery({
349
+ callbackQueryId: query.id,
350
+ ...expired === void 0 ? {} : { text: expired }
372
351
  });
373
352
  return;
374
353
  }
@@ -553,24 +532,6 @@ function gatedRoute(input) {
553
532
  resolveSession: args.resolveSession,
554
533
  from: args.from
555
534
  };
556
- inbound.confirmationEvent = async (record, result, auth) => {
557
- const address = record.data.address;
558
- if (address === void 0) throw new Error("Confirmation has no owning session address.");
559
- if ((await args.resolveSession(address))?.id !== record.data.sessionId) throw new Error("The confirmation session was replaced.");
560
- return args.from(address).send(JSON.stringify({
561
- type: "confirmation_result",
562
- ...result
563
- }), {
564
- auth,
565
- turnPolicy: "queue",
566
- state: {
567
- chatId: record.data.chatId,
568
- chatType: record.data.chatId.startsWith("-") ? "supergroup" : "private",
569
- messageThreadId: record.data.threadId ? Number(record.data.threadId) : null,
570
- conversationId: null
571
- }
572
- });
573
- };
574
535
  inbound.respond = (address, requestId, decision, auth, text) => args.from(scoped(address)).respond([{
575
536
  interactionId: requestId,
576
537
  optionId: decision === "cancel" ? "deny" : "approve",
@@ -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-gJ5wpsBF.mjs";
7
+ import { p as reportTelegramError } from "../../../_chunks/inbound-request-xmrm-49O.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";
@@ -7,10 +7,10 @@ __eveCreateRequire(import.meta.url);
7
7
  import { redactDiagnostic } from "../diagnostics.mjs";
8
8
  import { appOrigin, channelsEnabled, proxyEnvironment } from "../environment.mjs";
9
9
  import { runtimeToken } from "../runtime-token.mjs";
10
- import "../../../_chunks/principal-69qoDdqy.mjs";
10
+ import "../../../_chunks/principal-DMNXj4PX.mjs";
11
11
  import { confirmationLocale } from "./confirmation-text.mjs";
12
12
  import { inTelegramSendQueue, telegramSendScope } from "./send-queue.mjs";
13
- import { d as failureText, f as formattingRefused, l as customerMessage, p as reportTelegramError } from "../../../_chunks/inbound-request-gJ5wpsBF.mjs";
13
+ import { d as failureText, f as formattingRefused, l as customerMessage, p as reportTelegramError } from "../../../_chunks/inbound-request-xmrm-49O.mjs";
14
14
  import { MAXIMUM_PROXY_BODY_BYTES, connectionProxy } from "../connection-proxy.mjs";
15
15
  import { ACT_AS_HEADER } from "../actor.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-69qoDdqy.mjs";
9
+ import { d as telegramRuntimeSource, i as memberIdOf, o as telegramPrincipal, u as runtimeEnvelope } from "../../../_chunks/principal-DMNXj4PX.mjs";
10
10
  import { object } from "../confirmation-description.mjs";
11
- import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-gJ5wpsBF.mjs";
11
+ import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-xmrm-49O.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;
@@ -1,4 +1,3 @@
1
- import type { DeferredOptions } from "../deferred-confirmations.js";
2
1
  import type { ChannelEvents } from "eve/channels";
3
2
  import type { TelegramCallbackQuery, TelegramChannelEvents, TelegramContext, TelegramEventContext } from "eve/channels/telegram";
4
3
  import { type ObservedMessages, type PendingConfirmation, type RecentMessage } from "./observed.js";
@@ -24,5 +23,5 @@ export declare function handleConfirmationCallback(input: {
24
23
  readonly scope: "chat" | "thread";
25
24
  readonly now?: number;
26
25
  }): Promise<void>;
27
- export declare function telegramConfirmationEvents(archive?: Conversations, observed?: ObservedMessages, deferredOptions?: DeferredOptions, scope?: () => "chat" | "thread"): TelegramChannelEvents & Pick<ChannelEvents<TelegramEventContext>, "context.settled">;
26
+ export declare function telegramConfirmationEvents(archive?: Conversations, observed?: ObservedMessages, scope?: () => "chat" | "thread"): TelegramChannelEvents & Pick<ChannelEvents<TelegramEventContext>, "context.settled">;
28
27
  export declare const confirmationEvents: TelegramChannelEvents & Pick<ChannelEvents<TelegramEventContext>, "context.settled">;
@@ -5,17 +5,16 @@ 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 { i as memberIdOf, o as telegramPrincipal } from "../../../_chunks/principal-69qoDdqy.mjs";
8
+ import { i as memberIdOf, o as telegramPrincipal } from "../../../_chunks/principal-DMNXj4PX.mjs";
9
9
  import { humanText } from "../confirmation-description.mjs";
10
10
  import { renderConfirmation, withConfirmationText } from "./confirmation-text.mjs";
11
11
  import { chatPostCard, chatPostCardStatus, chatPostReceipt, withChatPostCard } from "./chat-post-card.mjs";
12
12
  import { conversationEvent } from "../conversations.mjs";
13
- import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-gJ5wpsBF.mjs";
13
+ import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-xmrm-49O.mjs";
14
14
  import { agentMessage, observedChatKey, withConfirmationPrompt } from "../group-routing/observed.mjs";
15
15
  import { chatPostOperationId, isChatPost } from "../chat-post-confirmation.mjs";
16
16
  import { confirmations } from "../confirmations.mjs";
17
17
  import { formatAddress, scopedAddress } from "./sessions.mjs";
18
- import { postDeferredCard } from "./deferred-confirmations.mjs";
19
18
  import { answerMarker, isPendingQuestion, pendingQuestions, questionKey } from "../questions.mjs";
20
19
  import { call } from "eve/events";
21
20
  import { createHash } from "node:crypto";
@@ -202,7 +201,7 @@ function messagePrompt(message) {
202
201
  at: new Date().toISOString()
203
202
  };
204
203
  }
205
- function telegramConfirmationEvents(archive, observed, deferredOptions, scope) {
204
+ function telegramConfirmationEvents(archive, observed, scope) {
206
205
  const remember = (channel, ctx, messageId, text, confirmation) => {
207
206
  const principal = ctx.session.auth.current;
208
207
  const name = humanText(principal?.attributes.memberName);
@@ -424,13 +423,6 @@ function telegramConfirmationEvents(archive, observed, deferredOptions, scope) {
424
423
  const state = channel.state;
425
424
  const data = event.data;
426
425
  const action = call(ctx.view, data.callId);
427
- if (action?.kind === "tool" && deferredOptions !== void 0 && archive !== void 0) {
428
- const output = object(data.output);
429
- if (output.status === "awaiting_confirmation" && typeof output.confirmation === "string") {
430
- await postDeferredCard(output.confirmation, channel, ctx, deferredOptions, archive, observed);
431
- return;
432
- }
433
- }
434
426
  if (action?.kind === "tool") {
435
427
  const question = object(data.output).pendingQuestion;
436
428
  if (action.name.endsWith("__questions_ask") && isPendingQuestion(question)) {
@@ -6,12 +6,12 @@ __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { n as contentText, t as CONTENT_CAPS } from "../../../_chunks/content-cDtVnr8Y.mjs";
8
8
  import { conversationEvent, sessionFailureEventId } from "../conversations.mjs";
9
- import { n as currentInboundRequest, p as reportTelegramError, s as currentThreadId } from "../../../_chunks/inbound-request-gJ5wpsBF.mjs";
9
+ import { n as currentInboundRequest, p as reportTelegramError, s as currentThreadId } from "../../../_chunks/inbound-request-xmrm-49O.mjs";
10
10
  import { currentConfirmationPrompt, observedChatKey } from "../group-routing/observed.mjs";
11
11
  import { archivedRoutingMessages } from "../group-routing/routing-context.mjs";
12
+ import { parseArchivedMessage } from "./archive-message.mjs";
12
13
  import { contentShape, messageContent } from "./content.mjs";
13
14
  import { messageMetadata } from "./observed.mjs";
14
- import { parseArchivedMessage } from "./archive-message.mjs";
15
15
  import { reportMembership } from "./membership.mjs";
16
16
  import { createHash, randomUUID } from "node:crypto";
17
17
  const captures = new WeakMap();
@@ -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 { a as TelegramDeliveryError, c as customerCopy, d as failureText, f as formattingRefused, h as withDeliveryLocale, l as customerMessage, m as safeTelegramFetch, o as currentLocale, p as reportTelegramError, s as currentThreadId, u as customerText } from "../../../_chunks/inbound-request-gJ5wpsBF.mjs";
8
+ import { a as TelegramDeliveryError, c as customerCopy, d as failureText, f as formattingRefused, h as withDeliveryLocale, l as customerMessage, m as safeTelegramFetch, o as currentLocale, p as reportTelegramError, s as currentThreadId, u as customerText } from "../../../_chunks/inbound-request-xmrm-49O.mjs";
9
9
  export { TelegramDeliveryError, currentLocale, currentThreadId, customerCopy, customerMessage, customerText, failureText, formattingRefused, isTechnicalText, reportTelegramError, safeTelegramFetch, withDeliveryLocale };
@@ -8,7 +8,7 @@ import { channelsEnabled, proxyEnvironment } from "../environment.mjs";
8
8
  import { runtimeToken } from "../runtime-token.mjs";
9
9
  import { redactTelegramDiagnostic } from "./diagnostic-redaction.mjs";
10
10
  import { conversationEvent, conversations } from "../conversations.mjs";
11
- import { p as reportTelegramError } from "../../../_chunks/inbound-request-gJ5wpsBF.mjs";
11
+ import { p as reportTelegramError } from "../../../_chunks/inbound-request-xmrm-49O.mjs";
12
12
  import { connectionProxy } from "../connection-proxy.mjs";
13
13
  import { sessions } from "eve/server";
14
14
  const object = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
@@ -4,8 +4,8 @@ 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 conversationLanguage } from "../../../_chunks/principal-69qoDdqy.mjs";
8
- import { d as failureText, p as reportTelegramError } from "../../../_chunks/inbound-request-gJ5wpsBF.mjs";
7
+ import { n as conversationLanguage } from "../../../_chunks/principal-DMNXj4PX.mjs";
8
+ import { d as failureText, p as reportTelegramError } from "../../../_chunks/inbound-request-xmrm-49O.mjs";
9
9
  import { describableImage, describeReceivedImage } from "./images.mjs";
10
10
  import { MAXIMUM_ATTACHMENT_BYTES, attachmentUrl } from "../attachments.mjs";
11
11
  function telegramConversation(chatId) {
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { runtimeRequestFailure } from "./runtime-request.mjs";
8
- import { t as agentBuild } from "../../../_chunks/build-metadata-D471R-eU.mjs";
8
+ import { t as agentBuild } from "../../../_chunks/build-metadata-C5051bJL.mjs";
9
9
  import { GET } from "eve/channels";
10
10
  const HEALTH_ROUTE = "/eve/v1/telegram/health";
11
11
  function healthRoute(input) {
@@ -8,10 +8,13 @@ export declare function heldApprovals(events: readonly RecordedEvent[]): {
8
8
  turnId: string;
9
9
  at: string;
10
10
  }[];
11
- /** Cancel the exact parked turn; never steer a new member into its permissions or old task. */
11
+ /**
12
+ * Cancel the exact parked turn; never steer a new member into its permissions or old task. Eve
13
+ * holds every other caller's message until a turn waiting on a person ends, so the caller runs
14
+ * this for each message the agent is about to answer: a pending card never holds the chat.
15
+ */
12
16
  export declare function releaseHeldApproval(input: {
13
17
  readonly events: readonly RecordedEvent[];
14
- readonly addressed: boolean;
15
18
  readonly now: number;
16
19
  readonly cancel: (options: {
17
20
  readonly turnId: string;
@@ -31,7 +31,6 @@ async function releaseHeldApproval(input) {
31
31
  const pending = heldApprovals(input.events);
32
32
  if (new Set(pending.map((approval) => approval.turnId)).size !== 1) return;
33
33
  const expired = pending.some((approval) => input.now - Date.parse(approval.at) >= CONFIRMATION_TTL_MS);
34
- if (!input.addressed && !expired) return;
35
34
  const turnId = pending[0].turnId;
36
35
  let delivery;
37
36
  try {
@@ -44,7 +43,7 @@ async function releaseHeldApproval(input) {
44
43
  if (result.outcome === "ignored" || result.outcome === "refused") return;
45
44
  return {
46
45
  status: "cancellation_requested",
47
- reason: expired ? "expired" : "addressed",
46
+ reason: expired ? "expired" : "superseded",
48
47
  turnId,
49
48
  startedAt: pending[0].at,
50
49
  actions: pending.map((approval) => approval.action),
@@ -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-gJ5wpsBF.mjs";
7
+ import { p as reportTelegramError } from "../../../_chunks/inbound-request-xmrm-49O.mjs";
8
8
  import { gateway, generateText } from "ai";
9
9
  const MAXIMUM_IMAGE_DESCRIPTION_BYTES = 5242880;
10
10
  const MAXIMUM_NATIVE_IMAGE_BYTES = 3145728;
@@ -1,4 +1,3 @@
1
- import type { DeferredConfirmation } from "../deferred-confirmations.js";
2
1
  import type { MessageContent } from "eve/channels";
3
2
  import type { ChannelSource } from "eve/channels";
4
3
  import type { SessionAuthContext } from "eve/context";
@@ -88,7 +87,6 @@ export declare class InboundRequest {
88
87
  waitUntil: ((task: Promise<unknown>) => void) | undefined;
89
88
  /** Continues the exact pending question's session, including under thread scope. */
90
89
  address: string | undefined;
91
- confirmationEvent: ((record: DeferredConfirmation, result: Readonly<Record<string, unknown>>, auth: SessionAuthContext | null) => Promise<unknown>) | undefined;
92
90
  respond: ((address: string, requestId: string, decision: "approve" | "cancel", principal: SessionAuthContext, text?: string) => Promise<unknown>) | undefined;
93
91
  constructor(
94
92
  /** The agent's description from the compiled manifest, for the routing decision. */
@@ -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 { i as withReplacedText, n as currentInboundRequest, r as runInboundRequest, t as InboundRequest } from "../../../_chunks/inbound-request-gJ5wpsBF.mjs";
7
+ import { i as withReplacedText, n as currentInboundRequest, r as runInboundRequest, t as InboundRequest } from "../../../_chunks/inbound-request-xmrm-49O.mjs";
8
8
  export { InboundRequest, currentInboundRequest, runInboundRequest, withReplacedText };
@@ -51,8 +51,6 @@ export interface InboundDependencies {
51
51
  readonly groups?: GroupPolicy;
52
52
  readonly recentConversation?: (chatId: string, threadId?: string) => Promise<ReadonlyArray<RecentMessage>>;
53
53
  readonly signalSettings?: TelegramSettings["groups"];
54
- /** Recover old held sessions only when the workspace has chosen non-blocking confirmations. */
55
- readonly recoverHeldApprovals?: boolean;
56
54
  readonly lifecycle?: (principal: import("eve/context").SessionAuthContext, memberId: string, message: TelegramMessage) => ReturnType<typeof attachmentLifecycle>;
57
55
  readonly admission: () => AdmissionSettings;
58
56
  readonly sessions: () => SessionSettings;
@@ -6,8 +6,8 @@ __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { effectiveGroupPolicy, groupPolicy } from "../group-routing/policy.mjs";
8
8
  import { admitMessage, localizedText } from "../admission.mjs";
9
- import { d as telegramRuntimeSource, n as conversationLanguage, o as telegramPrincipal, u as runtimeEnvelope } from "../../../_chunks/principal-69qoDdqy.mjs";
10
- import { p as reportTelegramError } from "../../../_chunks/inbound-request-gJ5wpsBF.mjs";
9
+ import { d as telegramRuntimeSource, n as conversationLanguage, o as telegramPrincipal, u as runtimeEnvelope } from "../../../_chunks/principal-DMNXj4PX.mjs";
10
+ import { p as reportTelegramError } from "../../../_chunks/inbound-request-xmrm-49O.mjs";
11
11
  import { addressingReason, conversationKey, otherRecipient } from "../group-routing/signals.mjs";
12
12
  import { conversationAddressing, conversationState } from "../group-routing/conversation.mjs";
13
13
  import { questionInvitation } from "../group-routing/engagement.mjs";
@@ -16,14 +16,14 @@ import { observedContext } from "../group-routing/observed.mjs";
16
16
  import { debounceBurst, routingBurst } from "../group-routing/burst.mjs";
17
17
  import { WorkspaceActionAlreadyDispatched } from "./workspace-action.mjs";
18
18
  import { structuredMessage } from "./structured.mjs";
19
- import { formatAddress, messageAddress, scopedAddress } from "./sessions.mjs";
19
+ import { evidenceSince, formatAddress, messageAddress, scopedAddress } from "./sessions.mjs";
20
20
  import { AttachmentLifecycleNotPermitted, startTypingHeartbeat, typingUntilComplete } from "./lifecycle.mjs";
21
- import { contentShape, messageContent } from "./content.mjs";
22
- import { messageAudience } from "./audience.mjs";
23
- import { attachmentKind, messageMetadata } from "./observed.mjs";
24
21
  import { MAXIMUM_NATIVE_IMAGE_BYTES } from "./images.mjs";
25
22
  import { MAXIMUM_ROUTING_ATTACHMENT_BYTES, describeRoutingAttachment, routingAttachmentDeadline } from "./attachment-description.mjs";
26
23
  import { attachmentUrl } from "../attachments.mjs";
24
+ import { contentShape, messageContent } from "./content.mjs";
25
+ import { messageAudience } from "./audience.mjs";
26
+ import { attachmentKind, messageMetadata } from "./observed.mjs";
27
27
  import { telegramSignals } from "./signals.mjs";
28
28
  import { answerMarker } from "../questions.mjs";
29
29
  import { questionAddress, questionFromHistory } from "./confirmations.mjs";
@@ -966,16 +966,17 @@ async function handleInboundMessage(input) {
966
966
  recordGateDecision("message_already_handled");
967
967
  return null;
968
968
  }
969
- if (dependencies.recoverHeldApprovals === true && operations !== void 0 && dependencies.history !== void 0) {
969
+ let receivingHistory;
970
+ if (operations !== void 0 && dependencies.history !== void 0) {
970
971
  let recoverySessionId;
971
972
  try {
972
973
  const session = await operations.resolveSession(address);
973
974
  if (session !== void 0) {
974
975
  recoverySessionId = session.id;
975
976
  const previous = session.id === owner?.id ? questionHistory : await dependencies.history(session.id);
977
+ receivingHistory = previous;
976
978
  const recovery = heldApprovals(previous).length === 0 ? void 0 : await releaseHeldApproval({
977
979
  events: await dependencies.history(session.id),
978
- addressed: addressed !== void 0,
979
980
  now: Date.now(),
980
981
  cancel: (options) => {
981
982
  if (session.cancel === void 0) throw new Error("The parked session does not support turn cancellation.");
@@ -1052,7 +1053,7 @@ async function handleInboundMessage(input) {
1052
1053
  }));
1053
1054
  }
1054
1055
  const language = conversationLanguage([text, ...dependencies.observed.recent(chat).map((message) => message.text).reverse()]);
1055
- const sharedContext = group ? conversationContext(await conversation()) : void 0;
1056
+ const sharedContext = group ? conversationContext(await conversation(), { since: receivingHistory === void 0 ? void 0 : evidenceSince(receivingHistory) }) : void 0;
1056
1057
  const beginTurnDispatch = structuredDispatched ? input.request?.beginStructuredContinuation : input.request?.beginDispatch;
1057
1058
  if (beginTurnDispatch !== void 0 && !await beginTurnDispatch()) {
1058
1059
  recordGateDecision("message_already_handled");
@@ -4,13 +4,13 @@ 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 { d as telegramRuntimeSource, l as principalRuntimeSource, u as runtimeEnvelope } from "../../../_chunks/principal-69qoDdqy.mjs";
7
+ import { d as telegramRuntimeSource, l as principalRuntimeSource, u as runtimeEnvelope } from "../../../_chunks/principal-DMNXj4PX.mjs";
8
8
  import { object } from "../confirmation-description.mjs";
9
- import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-gJ5wpsBF.mjs";
9
+ import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-xmrm-49O.mjs";
10
10
  import { member } from "../actor.mjs";
11
11
  import { needsConfirmation } from "../confirmations.mjs";
12
12
  import { OntologyActionNotPermitted, actionToolName, ontologyTools } from "../ontology-tools.mjs";
13
- import { t as agentBuild } from "../../../_chunks/build-metadata-D471R-eU.mjs";
13
+ import { t as agentBuild } from "../../../_chunks/build-metadata-C5051bJL.mjs";
14
14
  var AttachmentLifecycleNotPermitted = class extends Error {
15
15
  code = "attachment_lifecycle_not_permitted";
16
16
  };
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { DEFAULT_IMAGE_DESCRIPTION_MODEL } from "../../config.mjs";
8
- import { p as reportTelegramError } from "../../../_chunks/inbound-request-gJ5wpsBF.mjs";
8
+ import { p as reportTelegramError } from "../../../_chunks/inbound-request-xmrm-49O.mjs";
9
9
  function planMedia(capabilities, descriptionModel = null) {
10
10
  if (typeof descriptionModel === "string") return {
11
11
  images: "describe",
@@ -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 { a as rolesOf, i as memberIdOf, n as conversationLanguage, o as telegramPrincipal, r as identityProviderOf, t as TELEGRAM_AUTHENTICATOR } from "../../../_chunks/principal-69qoDdqy.mjs";
7
+ import { a as rolesOf, i as memberIdOf, n as conversationLanguage, o as telegramPrincipal, r as identityProviderOf, t as TELEGRAM_AUTHENTICATOR } from "../../../_chunks/principal-DMNXj4PX.mjs";
8
8
  export { TELEGRAM_AUTHENTICATOR, conversationLanguage, identityProviderOf, memberIdOf, rolesOf, telegramPrincipal };
@@ -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-gJ5wpsBF.mjs";
7
+ import { p as reportTelegramError } from "../../../_chunks/inbound-request-xmrm-49O.mjs";
8
8
  import { createHash } from "node:crypto";
9
9
  function missingDeployment(error) {
10
10
  if (!(error instanceof Error) || error.name !== "RunKeyFetchError" || !("status" in error) || error.status !== 404) return false;
@@ -57,6 +57,14 @@ export type HistoryReader = (sessionId: string) => Promise<ReadonlyArray<Recorde
57
57
  export declare const HISTORY_TAIL = 400;
58
58
  /** Folds a tail into a history; with no reset marker in it, `resetAt` is its earliest event. */
59
59
  export declare function historyOf(events: ReadonlyArray<RecordedEvent>): SessionHistory;
60
+ /**
61
+ * The earliest message time a group turn's conversation evidence still needs: each member
62
+ * message the session took in carried the chat's evidence up to then, and its history keeps it
63
+ * until a compaction or clear. Undefined when the session has none since its last reset, so the
64
+ * turn carries the whole window. Schedule sends and button answers carry no evidence and are
65
+ * skipped; a workspace callback turn is indistinguishable and may hide earlier unseen chatter.
66
+ */
67
+ export declare function evidenceSince(events: ReadonlyArray<RecordedEvent>): number | undefined;
60
68
  /** The route's operations on a continuation address, as eve gives them to the handler. */
61
69
  export interface SessionOperations {
62
70
  readonly resolveSession: (address: string) => Promise<{
@@ -108,6 +108,26 @@ function historyOf(events) {
108
108
  turnsSinceReset
109
109
  };
110
110
  }
111
+ const EVIDENCE_OVERLAP_MS = 6e4;
112
+ function evidenceSince(events) {
113
+ const members = new Set();
114
+ let since;
115
+ for (const event of events) {
116
+ const data = typeof event.data === "object" && event.data !== null ? event.data : {};
117
+ if (event.type === "session.started" || event.type === "context.settled" && data.outcome === "completed") {
118
+ members.clear();
119
+ since = void 0;
120
+ }
121
+ if (event.type === "delivery.admitted" && typeof data.deliveryId === "string") {
122
+ const principal = data.principal;
123
+ const source = data.source;
124
+ if (typeof principal?.id === "string" && principal.id.startsWith("telegram:") && source?.scheduleId === void 0) members.add(data.deliveryId);
125
+ }
126
+ const at = Date.parse(event.meta.at);
127
+ if (event.type === "delivery.consumed" && members.has(String(data.deliveryId)) && Array.isArray(data.parts) && data.parts.length > 0 && !Number.isNaN(at)) since = at - EVIDENCE_OVERLAP_MS;
128
+ }
129
+ return since;
130
+ }
111
131
  const MAXIMUM_REMEMBERED = 500;
112
132
  function sessionPolicy(input) {
113
133
  const remembered = new Map();
@@ -200,4 +220,4 @@ function sessionPolicy(input) {
200
220
  }
201
221
  };
202
222
  }
203
- export { HISTORY_TAIL, compactBoundary, formatAddress, historyOf, messageAddress, parseAddress, scopedAddress, sessionPolicy };
223
+ export { HISTORY_TAIL, compactBoundary, evidenceSince, formatAddress, historyOf, messageAddress, parseAddress, scopedAddress, sessionPolicy };
@@ -4,11 +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 "../../../_chunks/principal-69qoDdqy.mjs";
7
+ import "../../../_chunks/principal-DMNXj4PX.mjs";
8
8
  import { confirmationLocale } from "./confirmation-text.mjs";
9
9
  import { splitTelegramText } from "./format.mjs";
10
10
  import { inTelegramSendQueue } from "./send-queue.mjs";
11
- import { a as TelegramDeliveryError, l as customerMessage, o as currentLocale, p as reportTelegramError } from "../../../_chunks/inbound-request-gJ5wpsBF.mjs";
11
+ import { a as TelegramDeliveryError, l as customerMessage, o as currentLocale, p as reportTelegramError } from "../../../_chunks/inbound-request-xmrm-49O.mjs";
12
12
  import { agentMessage, observedChatKey } from "../group-routing/observed.mjs";
13
13
  const SILENT_MARKERS = new Set(["[silent]", "no_reply"]);
14
14
  function isSilentReply(text) {
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { STRUCTURED_KINDS } from "./structured-settings.mjs";
8
- import { d as telegramRuntimeSource, u as runtimeEnvelope } from "../../../_chunks/principal-69qoDdqy.mjs";
8
+ import { d as telegramRuntimeSource, u as runtimeEnvelope } from "../../../_chunks/principal-DMNXj4PX.mjs";
9
9
  import { workspaceAction } from "./workspace-action.mjs";
10
10
  const record = (value) => {
11
11
  if (value === null || typeof value !== "object" || Array.isArray(value)) throw new Error("Invalid structured Telegram object.");
@@ -5,9 +5,9 @@ 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 { i as memberIdOf } from "../../../_chunks/principal-69qoDdqy.mjs";
8
+ import { i as memberIdOf } from "../../../_chunks/principal-DMNXj4PX.mjs";
9
9
  import { confirmationLocale } from "./confirmation-text.mjs";
10
- import { c as customerCopy, d as failureText, o as currentLocale, p as reportTelegramError, s as currentThreadId } from "../../../_chunks/inbound-request-gJ5wpsBF.mjs";
10
+ import { c as customerCopy, d as failureText, o as currentLocale, p as reportTelegramError, s as currentThreadId } from "../../../_chunks/inbound-request-xmrm-49O.mjs";
11
11
  import { recordSessionFailure } from "./conversations.mjs";
12
12
  import { isSilentRoutingCancellation } from "../group-routing/cancellation.mjs";
13
13
  import { modelServiceFailure } from "../model-service-failure.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 { p as reportTelegramError } from "../../../_chunks/inbound-request-gJ5wpsBF.mjs";
7
+ import { p as reportTelegramError } from "../../../_chunks/inbound-request-xmrm-49O.mjs";
8
8
  import "../connection-proxy.mjs";
9
9
  import { gateway, transcribe } from "ai";
10
10
  const LABELS = {
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { isPreview } from "./lib/environment.mjs";
8
- import { a as rolesOf } from "../_chunks/principal-69qoDdqy.mjs";
8
+ import { a as rolesOf } from "../_chunks/principal-DMNXj4PX.mjs";
9
9
  import { runs } from "eve/events";
10
10
  import { defineDynamic } from "eve";
11
11
  function chooseModel(input) {
@@ -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 { u as runtimeEnvelope } from "../../_chunks/principal-69qoDdqy.mjs";
7
+ import { u as runtimeEnvelope } from "../../_chunks/principal-DMNXj4PX.mjs";
8
8
  import { n as workflowToolResult } from "../../_chunks/workflow-serializable-DU7WeCIW.mjs";
9
9
  import segmentstream from "../extension.mjs";
10
10
  import { memberTool } from "../lib/actor.mjs";
@@ -3,7 +3,8 @@
3
3
  * so scripts can work on its bytes: a chat attachment by id, or a permanent record's file by entity
4
4
  * and record id. The runtime reads it as the member, through the same grants as
5
5
  * `attachments_read`, checks its SHA-256 and writes it under `/workspace/.segmentstream/files/`.
6
- * No URL, header or credential enters the sandbox. The way back is `attachments_promote` with a
6
+ * A stored file is granted on every call, but its bytes are not transferred again while its digest
7
+ * path in the sandbox holds the same SHA-256. No URL, header or credential enters the sandbox. The way back is `attachments_promote` with a
7
8
  * path. Offered only when the sandbox is on, and never to a task session, which has no member
8
9
  * files.
9
10
  */