@segmentstream/agent 0.16.0 → 0.16.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.
package/README.md CHANGED
@@ -549,7 +549,7 @@ Eve resolution, so member/topic routing survives a cold start. No second provide
549
549
 
550
550
  ## Release and migration
551
551
 
552
- The coordinated release uses Agent SDK 0.16.0, Eve 0.76.3, Ontology SDK 0.52.0 and App SDK 0.25.0.
552
+ The coordinated release uses Agent SDK 0.16.1, Eve 0.76.3, Ontology SDK 0.52.0 and App SDK 0.25.0.
553
553
  The compatible Cloud archive/API must be deployed first; migrations run only through its CI/CD gate.
554
554
  Publish the ontology SDK before the agent SDK. Upgrade the workspace ontology before its agent,
555
555
  with the declared Telegram provider mapping and explicit `agent_chat:post_message` grant.
@@ -4,7 +4,7 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
- var version = "0.16.0";
7
+ var version = "0.16.1";
8
8
  function agentBuild(environment = process.env) {
9
9
  return {
10
10
  agent: version,
@@ -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 { t as agentBuild } from "../../_chunks/build-metadata-CIFPiRho.mjs";
7
+ import { t as agentBuild } from "../../_chunks/build-metadata-CsawQFEV.mjs";
8
8
  export { agentBuild };
@@ -14,6 +14,10 @@ export declare function conversationCoordinates(context: {
14
14
  participantIds: string[];
15
15
  senderId: string | null;
16
16
  } | undefined;
17
- /** eve event hooks run after its durable event write. IDs make platform writes replay-safe. */
17
+ /**
18
+ * eve event hooks run after its durable event write. IDs make platform writes replay-safe.
19
+ * eve 0.76.3 catches a throwing hook and logs it as `[eve:hooks] stream event hook failed`
20
+ * with the session, event type and full error, so archive failures propagate unwrapped.
21
+ */
18
22
  export declare function conversationRecorder(archive?: Conversations, closing?: (message: string, model: string) => Promise<number>): (event: HookEvent, context: HookContext) => Promise<void>;
19
23
  export {};
@@ -7,7 +7,7 @@ __eveCreateRequire(import.meta.url);
7
7
  import { ENDS_CONVERSATION_INSTRUCTIONS } from "./group-routing/conversation-prompt.mjs";
8
8
  import { i as memberIdOf } from "../../_chunks/principal-MEMlG3EG.mjs";
9
9
  import { n as contentText, t as CONTENT_CAPS } from "../../_chunks/content-CvFsrmSD.mjs";
10
- import { conversationEvent, conversations, summarizeArguments } from "./conversations.mjs";
10
+ import { conversationEvent, conversations, sessionFailureEventId, summarizeArguments } from "./conversations.mjs";
11
11
  import { parseAddress } from "./telegram/sessions.mjs";
12
12
  import { completionKind } from "./telegram/silent.mjs";
13
13
  import { decide } from "eve/ai";
@@ -33,6 +33,29 @@ function conversationCoordinates(context) {
33
33
  senderId: principal?.subject ?? null
34
34
  };
35
35
  }
36
+ const UNADDRESSED_SESSIONS_REMEMBERED = 1e3;
37
+ function reportUnaddressed(event, context, reported) {
38
+ const sessionId = context.session.id;
39
+ const fields = {
40
+ sessionId,
41
+ eventType: event.type,
42
+ channelKind: context.channel.kind ?? null,
43
+ hasContinuationToken: Boolean(context.channel.continuationToken),
44
+ authenticator: context.session.auth.current?.authenticator ?? null
45
+ };
46
+ if (event.type === "turn.failed" || event.type === "step.failed" || event.type === "session.failed") {
47
+ console.error("[segmentstream] agent log dropped unaddressed failure", {
48
+ ...fields,
49
+ code: event.data.code,
50
+ message: contentText(event.data.message, CONTENT_CAPS.error)
51
+ });
52
+ return;
53
+ }
54
+ if (reported.has(sessionId)) return;
55
+ if (reported.size >= UNADDRESSED_SESSIONS_REMEMBERED) reported.delete(reported.values().next().value);
56
+ reported.add(sessionId);
57
+ console.warn("[segmentstream] agent log dropped unaddressed session events", fields);
58
+ }
36
59
  function conversationRecorder(archive = conversations(), closing = async (message, model) => {
37
60
  return (await decide({
38
61
  model,
@@ -45,9 +68,13 @@ function conversationRecorder(archive = conversations(), closing = async (messag
45
68
  maxRetries: 0
46
69
  })).answers.ends_conversation.probability;
47
70
  }) {
71
+ const unaddressed = new Set();
48
72
  return async (event, context) => {
49
73
  const coordinates = conversationCoordinates(context);
50
- if (coordinates === void 0) return;
74
+ if (coordinates === void 0) {
75
+ reportUnaddressed(event, context, unaddressed);
76
+ return;
77
+ }
51
78
  const base = {
52
79
  ...coordinates,
53
80
  sessionId: context.session.id,
@@ -94,10 +121,9 @@ function conversationRecorder(archive = conversations(), closing = async (messag
94
121
  } : {},
95
122
  status: event.type === "task.started" ? "requested" : event.data.status === "cancelled" ? "cancelled" : event.data.status === "failed" ? "failed" : "completed"
96
123
  }));
97
- else if (event.type === "turn.failed" || event.type === "step.failed") await archive.append(conversationEvent({
124
+ else if (event.type === "turn.failed" || event.type === "step.failed" || event.type === "session.failed") await archive.append(conversationEvent({
98
125
  ...base,
99
- turnId: event.data.turnId,
100
- eventId,
126
+ eventId: event.type === "session.failed" ? sessionFailureEventId(context.session.id) : eventId,
101
127
  kind: "decision",
102
128
  decision: "silent",
103
129
  reason: event.type,
@@ -73,6 +73,12 @@ export interface Conversations {
73
73
  }
74
74
  /** Collapse delivery snapshots from older archives before building a user/model transcript. */
75
75
  export declare function collapseConversationEvents(events: ConversationPage["events"]): ConversationPage["events"];
76
+ /**
77
+ * eve's terminal session failure reaches the channel adapter unstamped, so its event ID is not
78
+ * available there; a session fails terminally once. The hook recorder and the channel both use
79
+ * this ID, and the archive's idempotent append keeps whichever arrives first.
80
+ */
81
+ export declare function sessionFailureEventId(sessionId: string): string;
76
82
  export declare function conversationEvent(input: Pick<ConversationEvent, "eventId" | "provider" | "chatId" | "chatType" | "kind"> & Partial<ConversationEvent>): ConversationEvent;
77
83
  export declare function conversations(input?: {
78
84
  readonly environment?: Environment;
@@ -20,6 +20,9 @@ function collapseConversationEvents(events) {
20
20
  }
21
21
  return [...latest.values()];
22
22
  }
23
+ function sessionFailureEventId(sessionId) {
24
+ return `eve:${sessionId}:session.failed`;
25
+ }
23
26
  function conversationEvent(input) {
24
27
  return workflowValue({
25
28
  threadId: null,
@@ -137,4 +140,4 @@ async function storedConversationContext(archive, coordinates) {
137
140
  JSON.stringify(selected.reverse())
138
141
  ].join("\n");
139
142
  }
140
- export { collapseConversationEvents, conversationEvent, conversations, storedConversationContext, summarizeArguments };
143
+ export { collapseConversationEvents, conversationEvent, conversations, sessionFailureEventId, storedConversationContext, summarizeArguments };
@@ -20,7 +20,7 @@ import { archivedRoutingMessages } from "../group-routing/routing-context.mjs";
20
20
  import { dispatchStructuredMessage, structuredMessage } from "./structured.mjs";
21
21
  import { scopedAddress, sessionPolicy } from "./sessions.mjs";
22
22
  import { handleWorkspaceCallback, isWorkspaceCallback } from "./callbacks.mjs";
23
- import { t as agentBuild } from "../../../_chunks/build-metadata-CIFPiRho.mjs";
23
+ import { t as agentBuild } from "../../../_chunks/build-metadata-CsawQFEV.mjs";
24
24
  import { attachmentLifecycle } from "./lifecycle.mjs";
25
25
  import { observedMessages } from "./observed.mjs";
26
26
  import { expireDeferredCards, handleDeferredCallback, isDeferredCallback } from "./deferred-confirmations.mjs";
@@ -372,7 +372,10 @@ function segmentstreamTelegram(options) {
372
372
  }
373
373
  },
374
374
  events: {
375
- ...telegramFailureEvents,
375
+ ...telegramFailureEvents({
376
+ archive,
377
+ identities: pairing
378
+ }),
376
379
  ...telegramConfirmationEvents(archive, observed, {
377
380
  environment,
378
381
  token,
@@ -28,6 +28,22 @@ export declare function recordInboundContent(content: {
28
28
  readonly media?: string;
29
29
  readonly decoded?: ReadonlyArray<DecodedAttachment>;
30
30
  }): Promise<void>;
31
+ /**
32
+ * Records eve's unrecoverable session failure from the channel. The channel receives it even when
33
+ * eve publishes it after its workflow loop throws, which runs no hooks. Never throws, so the
34
+ * member's notice never depends on the archive.
35
+ */
36
+ export declare function recordSessionFailure(input: {
37
+ readonly archive: Conversations;
38
+ readonly identities: () => AgentIdentities;
39
+ readonly chatId: string | null;
40
+ readonly threadId: string | null;
41
+ readonly failure: {
42
+ readonly code: string;
43
+ readonly message: string;
44
+ readonly sessionId: string;
45
+ };
46
+ }): Promise<void>;
31
47
  /** Captures message sends and button/status edits, including pairing and proactive replies. */
32
48
  export declare function captureTelegramFetch(fetchImpl: typeof fetch, archive: Conversations, identities: () => AgentIdentities): typeof fetch;
33
49
  /** Reuses the request's verified lookup; it never survives into another inbound request. */
@@ -5,8 +5,9 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { n as currentInboundRequest, p as reportTelegramError, s as currentThreadId } from "../../../_chunks/inbound-request-RIRNBxUC.mjs";
8
+ import { n as contentText, t as CONTENT_CAPS } from "../../../_chunks/content-CvFsrmSD.mjs";
8
9
  import { currentConfirmationPrompt, observedChatKey } from "../group-routing/observed.mjs";
9
- import { conversationEvent } from "../conversations.mjs";
10
+ import { conversationEvent, sessionFailureEventId } from "../conversations.mjs";
10
11
  import { archivedRoutingMessages } from "../group-routing/routing-context.mjs";
11
12
  import { contentShape, messageContent } from "./content.mjs";
12
13
  import { messageMetadata } from "./observed.mjs";
@@ -517,6 +518,62 @@ async function recordInboundContent(content) {
517
518
  await capture.archive.append(event);
518
519
  capture.event = event;
519
520
  }
521
+ async function outboundAudience(chatId, identities) {
522
+ const inbound = currentInboundRequest();
523
+ const capture = inbound === void 0 ? void 0 : captures.get(inbound);
524
+ let participantIds = capture?.event.participantIds ?? [];
525
+ const chatType = capture?.event.chatType ?? (chatId.startsWith("-") ? "group" : "private");
526
+ if (chatType === "private" && participantIds.length === 0 && capture === void 0) try {
527
+ const lookup = await identities().lookup({
528
+ provider: "telegram",
529
+ externalId: chatId
530
+ });
531
+ if (lookup.status === "paired") participantIds = [lookup.member.id];
532
+ } catch (error) {
533
+ console.error("[segmentstream] outbound participant lookup failed", { error });
534
+ }
535
+ return {
536
+ capture,
537
+ chatType,
538
+ participantIds
539
+ };
540
+ }
541
+ async function recordSessionFailure(input) {
542
+ const { failure } = input;
543
+ const sessionId = failure.sessionId === "" ? null : failure.sessionId;
544
+ try {
545
+ const errorText = contentText(failure.message, CONTENT_CAPS.error);
546
+ if (input.chatId === null) {
547
+ console.error("[segmentstream] agent log dropped unaddressed failure", {
548
+ sessionId,
549
+ eventType: "session.failed",
550
+ code: failure.code,
551
+ message: errorText
552
+ });
553
+ return;
554
+ }
555
+ const { chatType, participantIds } = await outboundAudience(input.chatId, input.identities);
556
+ await input.archive.append(conversationEvent({
557
+ eventId: sessionId === null ? `eve:session.failed:${randomUUID()}` : sessionFailureEventId(sessionId),
558
+ provider: "telegram",
559
+ chatId: input.chatId,
560
+ chatType,
561
+ threadId: input.threadId,
562
+ participantIds,
563
+ sessionId,
564
+ kind: "decision",
565
+ decision: "silent",
566
+ reason: "session.failed",
567
+ status: "failed",
568
+ errorText
569
+ }));
570
+ } catch (error) {
571
+ console.error("[segmentstream] recording session failure failed", {
572
+ sessionId,
573
+ error
574
+ });
575
+ }
576
+ }
520
577
  function captureTelegramFetch(fetchImpl, archive, identities) {
521
578
  return async (input, init) => {
522
579
  const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
@@ -525,19 +582,7 @@ function captureTelegramFetch(fetchImpl, archive, identities) {
525
582
  const body = record(JSON.parse(init.body));
526
583
  const chatId = id(body.chat_id);
527
584
  if (chatId === null) return fetchImpl(input, init);
528
- const inbound = currentInboundRequest();
529
- const capture = inbound === void 0 ? void 0 : captures.get(inbound);
530
- let participantIds = capture?.event.participantIds ?? [];
531
- const chatType = capture?.event.chatType ?? (chatId.startsWith("-") ? "group" : "private");
532
- if (chatType === "private" && participantIds.length === 0 && capture === void 0) try {
533
- const lookup = await identities().lookup({
534
- provider: "telegram",
535
- externalId: chatId
536
- });
537
- if (lookup.status === "paired") participantIds = [lookup.member.id];
538
- } catch (error) {
539
- console.error("[segmentstream] outbound participant lookup failed", { error });
540
- }
585
+ const { capture, chatType, participantIds } = await outboundAudience(chatId, identities);
541
586
  const event = conversationEvent({
542
587
  eventId: `telegram:${edit ? "edit" : "send"}:${randomUUID()}`,
543
588
  provider: "telegram",
@@ -681,4 +726,4 @@ function telegramConversationCapture(input) {
681
726
  }
682
727
  };
683
728
  }
684
- export { REVISION_CLAIM_TTL_MS, captureRouteDecider, captureTelegramFetch, captureTelegramWebhook, conversationIdentities, recordGateDecision, recordInboundContent, recordRouteDecision, telegramConversationCapture };
729
+ export { REVISION_CLAIM_TTL_MS, captureRouteDecider, captureTelegramFetch, captureTelegramWebhook, conversationIdentities, recordGateDecision, recordInboundContent, recordRouteDecision, recordSessionFailure, telegramConversationCapture };
@@ -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-CIFPiRho.mjs";
7
+ import { t as agentBuild } from "../../../_chunks/build-metadata-CsawQFEV.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";
@@ -9,7 +9,7 @@ import { object } from "../confirmation-description.mjs";
9
9
  import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-RIRNBxUC.mjs";
10
10
  import { needsConfirmation } from "../confirmations.mjs";
11
11
  import { OntologyActionNotPermitted, actionToolName, ontologyTools } from "../ontology-tools.mjs";
12
- import { t as agentBuild } from "../../../_chunks/build-metadata-CIFPiRho.mjs";
12
+ import { t as agentBuild } from "../../../_chunks/build-metadata-CsawQFEV.mjs";
13
13
  var AttachmentLifecycleNotPermitted = class extends Error {
14
14
  code = "attachment_lifecycle_not_permitted";
15
15
  };
@@ -1,2 +1,8 @@
1
1
  import type { TelegramChannelEvents } from "eve/channels/telegram";
2
- export declare const telegramFailureEvents: Pick<TelegramChannelEvents, "turn.failed" | "turn.cancelled" | "session.failed" | "authorization.completed" | "authorization.required">;
2
+ import type { Conversations } from "../conversations.js";
3
+ import type { AgentIdentities } from "../identities.js";
4
+ /** Failure notices for members; an unrecoverable session failure is also recorded to the archive. */
5
+ export declare function telegramFailureEvents(input: {
6
+ readonly archive: Conversations;
7
+ readonly identities: () => AgentIdentities;
8
+ }): Pick<TelegramChannelEvents, "turn.failed" | "turn.cancelled" | "session.failed" | "authorization.completed" | "authorization.required">;
@@ -7,82 +7,95 @@ __eveCreateRequire(import.meta.url);
7
7
  import { telegramText } from "./texts.mjs";
8
8
  import { i as memberIdOf } from "../../../_chunks/principal-MEMlG3EG.mjs";
9
9
  import { confirmationLocale } from "./confirmation-text.mjs";
10
- import { c as customerCopy, d as failureText, o as currentLocale, p as reportTelegramError } from "../../../_chunks/inbound-request-RIRNBxUC.mjs";
11
- const telegramFailureEvents = {
12
- async "authorization.required"(event, channel, context) {
13
- if (event.candidateId !== void 0) return;
14
- const locale = confirmationLocale(context.session.auth.current, currentLocale());
15
- const prompt = telegramText("authorization", "prompt", locale);
16
- const url = telegramText("authorization", "url", locale);
17
- const button = telegramText("authorization", "button", locale);
18
- if (prompt !== void 0) {
19
- const sent = await channel.telegram.post({
20
- text: prompt,
21
- ...url === void 0 || button === void 0 ? {} : { reply_markup: { inline_keyboard: [[{
22
- text: button,
23
- url
24
- }]] } }
10
+ import { c as customerCopy, d as failureText, o as currentLocale, p as reportTelegramError, s as currentThreadId } from "../../../_chunks/inbound-request-RIRNBxUC.mjs";
11
+ import { recordSessionFailure } from "./conversations.mjs";
12
+ function telegramFailureEvents(input) {
13
+ return {
14
+ async "authorization.required"(event, channel, context) {
15
+ if (event.candidateId !== void 0) return;
16
+ const locale = confirmationLocale(context.session.auth.current, currentLocale());
17
+ const prompt = telegramText("authorization", "prompt", locale);
18
+ const url = telegramText("authorization", "url", locale);
19
+ const button = telegramText("authorization", "button", locale);
20
+ if (prompt !== void 0) {
21
+ const sent = await channel.telegram.post({
22
+ text: prompt,
23
+ ...url === void 0 || button === void 0 ? {} : { reply_markup: { inline_keyboard: [[{
24
+ text: button,
25
+ url
26
+ }]] } }
27
+ });
28
+ if (sent.id) channel.state.pendingAuthMessageIds = {
29
+ ...channel.state.pendingAuthMessageIds,
30
+ [event.name]: sent.id
31
+ };
32
+ return;
33
+ }
34
+ const state = channel.state;
35
+ state.authorizationCancellationTurnId = event.turnId;
36
+ const errorId = reportTelegramError("authorization_prompt_unconfigured", new Error("texts.authorization.prompt is not configured."), { sessionId: context.session.id });
37
+ await channel.telegram.post(failureText(errorId, "authorization", locale));
38
+ },
39
+ async "turn.cancelled"(event, channel, context) {
40
+ const state = channel.state;
41
+ const authorizationTurn = state.authorizationCancellationTurnId;
42
+ delete state.authorizationCancellationTurnId;
43
+ if (typeof event.turnId === "string" && authorizationTurn === event.turnId) return;
44
+ const errorId = reportTelegramError("turn_cancelled", event, {
45
+ chatId: channel.state.chatId,
46
+ sessionId: context.session.id,
47
+ turnId: event.turnId
25
48
  });
26
- if (sent.id) channel.state.pendingAuthMessageIds = {
27
- ...channel.state.pendingAuthMessageIds,
28
- [event.name]: sent.id
29
- };
30
- return;
31
- }
32
- const state = channel.state;
33
- state.authorizationCancellationTurnId = event.turnId;
34
- const errorId = reportTelegramError("authorization_prompt_unconfigured", new Error("texts.authorization.prompt is not configured."), { sessionId: context.session.id });
35
- await channel.telegram.post(failureText(errorId, "authorization", locale));
36
- },
37
- async "turn.cancelled"(event, channel, context) {
38
- const state = channel.state;
39
- const authorizationTurn = state.authorizationCancellationTurnId;
40
- delete state.authorizationCancellationTurnId;
41
- if (typeof event.turnId === "string" && authorizationTurn === event.turnId) return;
42
- const errorId = reportTelegramError("turn_cancelled", event, {
43
- chatId: channel.state.chatId,
44
- sessionId: context.session.id,
45
- turnId: event.turnId
46
- });
47
- await channel.telegram.post(failureText(errorId, "cancelled", confirmationLocale(context.session.auth.current, currentLocale())));
48
- },
49
- async "turn.failed"(event, channel, context) {
50
- const errorId = reportTelegramError("turn_failed", event, {
51
- chatId: channel.state.chatId,
52
- memberId: memberIdOf(context.session.auth.current) ?? null,
53
- sessionId: context.session.id,
54
- turnId: event.turnId
55
- });
56
- await channel.telegram.post(failureText(errorId, "failed", confirmationLocale(context.session.auth.current, currentLocale())));
57
- },
58
- async "session.failed"(event, channel) {
59
- const errorId = reportTelegramError("session_recovery_failed", event, {
60
- chatId: channel.state.chatId,
61
- sessionId: event.sessionId
62
- });
63
- const locale = channel.state.customerLocale ?? "en";
64
- await channel.telegram.post(failureText(errorId, "recovery", locale));
65
- },
66
- async "authorization.completed"(event, channel, context) {
67
- const messageId = channel.state.pendingAuthMessageIds?.[event.name];
68
- if (event.candidateId !== void 0 || messageId === void 0) return;
69
- const locale = confirmationLocale(context.session.auth.current);
70
- const copy = customerCopy(locale);
71
- let text = event.outcome === "authorized" ? copy.connected : copy.disconnected;
72
- if (event.reason !== void 0) {
73
- const errorId = reportTelegramError("authorization_not_completed", event, { chatId: channel.state.chatId });
74
- text = failureText(errorId, "authorization", locale);
49
+ await channel.telegram.post(failureText(errorId, "cancelled", confirmationLocale(context.session.auth.current, currentLocale())));
50
+ },
51
+ async "turn.failed"(event, channel, context) {
52
+ const errorId = reportTelegramError("turn_failed", event, {
53
+ chatId: channel.state.chatId,
54
+ memberId: memberIdOf(context.session.auth.current) ?? null,
55
+ sessionId: context.session.id,
56
+ turnId: event.turnId
57
+ });
58
+ await channel.telegram.post(failureText(errorId, "failed", confirmationLocale(context.session.auth.current, currentLocale())));
59
+ },
60
+ async "session.failed"(event, channel) {
61
+ const errorId = reportTelegramError("session_recovery_failed", event, {
62
+ chatId: channel.state.chatId,
63
+ sessionId: event.sessionId
64
+ });
65
+ const locale = channel.state.customerLocale ?? "en";
66
+ const recorded = recordSessionFailure({
67
+ ...input,
68
+ chatId: channel.state.chatId,
69
+ threadId: typeof channel.state.messageThreadId === "number" ? String(channel.state.messageThreadId) : currentThreadId() ?? null,
70
+ failure: event
71
+ });
72
+ try {
73
+ await channel.telegram.post(failureText(errorId, "recovery", locale));
74
+ } finally {
75
+ await recorded;
76
+ }
77
+ },
78
+ async "authorization.completed"(event, channel, context) {
79
+ const messageId = channel.state.pendingAuthMessageIds?.[event.name];
80
+ if (event.candidateId !== void 0 || messageId === void 0) return;
81
+ const locale = confirmationLocale(context.session.auth.current);
82
+ const copy = customerCopy(locale);
83
+ let text = event.outcome === "authorized" ? copy.connected : copy.disconnected;
84
+ if (event.reason !== void 0) {
85
+ const errorId = reportTelegramError("authorization_not_completed", event, { chatId: channel.state.chatId });
86
+ text = failureText(errorId, "authorization", locale);
87
+ }
88
+ if (text !== void 0) await channel.telegram.editMessageText({
89
+ messageId,
90
+ text,
91
+ replyMarkup: { inline_keyboard: [] }
92
+ });
93
+ else await channel.telegram.editMessageReplyMarkup({
94
+ messageId,
95
+ replyMarkup: { inline_keyboard: [] }
96
+ });
97
+ delete channel.state.pendingAuthMessageIds?.[event.name];
75
98
  }
76
- if (text !== void 0) await channel.telegram.editMessageText({
77
- messageId,
78
- text,
79
- replyMarkup: { inline_keyboard: [] }
80
- });
81
- else await channel.telegram.editMessageReplyMarkup({
82
- messageId,
83
- replyMarkup: { inline_keyboard: [] }
84
- });
85
- delete channel.state.pendingAuthMessageIds?.[event.name];
86
- }
87
- };
99
+ };
100
+ }
88
101
  export { telegramFailureEvents };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segmentstream/agent",
3
- "version": "0.16.0",
3
+ "version": "0.16.1",
4
4
  "description": "Mount a SegmentStream workspace's agent on eve: the ontology as tools, acting as the member who writes, and Telegram through the workspace's connection.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "SegmentStream",