@segmentstream/agent 0.89.5 → 0.89.6

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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.89.6
4
+
5
+ Telegram confirmation presses can be traced from receipt to the decision submitted to the agent session. The agent runtime logs identify the card and report why a press did not advance; they omit the button payload and message text.
6
+
3
7
  ## 0.89.5
4
8
 
5
9
  Pins @segmentstream/ontology 0.170.2.
package/README.md CHANGED
@@ -720,6 +720,12 @@ current chat; group purpose and document restrictions still apply.
720
720
 
721
721
  ## Telegram answer delivery
722
722
 
723
+ For confirmation buttons, search the agent runtime logs for `telegram.confirmation_press` and
724
+ the card's chat and message IDs. Each press has its own `pressId`. `received` records the
725
+ verified webhook and `submitted` records a decision handed to the session. Match its `callId`
726
+ with the tool result to check whether the action ran. An unsuccessful press records the stage
727
+ it reached or the reason it stopped. The trace omits button data and message text.
728
+
723
729
  Agent replies render Markdown as visible text and Telegram entities. Headings, emphasis,
724
730
  links, lists, quotations and code are supported; decorative separator lines are removed.
725
731
  The customer-text guard checks the rendered prose and link destinations, and replaces a reply that
@@ -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.89.5";
7
+ var version = "0.89.6";
8
8
  function agentBuild(environment = process.env) {
9
9
  return {
10
10
  agent: version,
@@ -4,6 +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 { logConfirmationPress } from "../extension/lib/telegram/confirmation-press.mjs";
7
8
  import { parseArchivedMessage } from "../extension/lib/telegram/archive-message.mjs";
8
9
  import { currentChannel, currentKey } from "../extension/lib/channel-scope.mjs";
9
10
  import { n as contentText, t as CONTENT_CAPS } from "./content-cDtVnr8Y.mjs";
@@ -683,6 +684,13 @@ async function captureTelegramWebhook(input) {
683
684
  const update = record(raw);
684
685
  const callback = record(update.callback_query);
685
686
  const data = callback.data;
687
+ if (typeof callback.id === "string" && typeof data === "string" && data.startsWith("ss-confirm:")) {
688
+ const message = record(callback.message);
689
+ logConfirmationPress(callback.id, {
690
+ chatId: record(message.chat).id,
691
+ messageId: message.message_id
692
+ }, "received");
693
+ }
686
694
  if (typeof data === "string" && (data.startsWith("eve_auth:") || data.startsWith("eve:"))) {
687
695
  if (typeof callback.id === "string" && input.answerCallback !== void 0) {
688
696
  const locale = record(callback.from).language_code;
@@ -4,4 +4,4 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
- export { t as agentBuild } from "../../_chunks/build-metadata-WTPUPTo4.mjs";
7
+ export { t as agentBuild } from "../../_chunks/build-metadata-CHCqNGRE.mjs";
@@ -4,13 +4,14 @@ 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 { logConfirmationPress } from "./confirmation-press.mjs";
7
8
  import { object } from "../confirmation-description.mjs";
8
9
  import { archivedRoutingMessages } from "../group-routing/routing-context.mjs";
9
10
  import { groupRoutingHealth } from "../group-routing/health.mjs";
10
11
  import { dispatchStructuredMessage, structuredMessage } from "./structured.mjs";
11
12
  import { handleWorkspaceCallback } from "./callbacks.mjs";
12
13
  import { telegramText, withTelegramTexts } from "./texts.mjs";
13
- import { t as agentBuild } from "../../../_chunks/build-metadata-WTPUPTo4.mjs";
14
+ import { t as agentBuild } from "../../../_chunks/build-metadata-CHCqNGRE.mjs";
14
15
  import { attachmentLifecycle } from "./lifecycle.mjs";
15
16
  import { manifestOf } from "../../config.mjs";
16
17
  import { gatewayAttachmentDescriber } from "./attachment-description.mjs";
@@ -20,13 +21,13 @@ import { MAXIMUM_DOWNLOAD_BYTES, connectionProxy } from "../connection-proxy.mjs
20
21
  import { appOrigin, channelsEnabled, proxyEnvironment, runtimeIdentityEnvironment, webhookSecret } from "../environment.mjs";
21
22
  import { agentIdentities } from "../identities.mjs";
22
23
  import { h as topicContext, r as chatArchive } from "../../../_chunks/chat-archive-DavfKJDI.mjs";
23
- import { a as captureTelegramFetch, h as telegramChatCapture, i as captureRouteDecider, s as chatIdentities, u as recordGateDecision } from "../../../_chunks/chat-archive-DwSKmO-f.mjs";
24
+ import { a as captureTelegramFetch, h as telegramChatCapture, i as captureRouteDecider, s as chatIdentities, u as recordGateDecision } from "../../../_chunks/chat-archive-BhVy1Dbk.mjs";
24
25
  import { runtimeTokenVerifier } from "../runtime-identity.mjs";
25
26
  import { runtimeToken } from "../runtime-token.mjs";
26
27
  import { botIdentityCache, proxiedBotRequest, runtimeBotIdentity } from "./bot.mjs";
27
28
  import { handleConfirmationCallback, telegramConfirmationEvents } from "./confirmations.mjs";
28
- import { confirmationLocale } from "./confirmation-text.mjs";
29
29
  import { isWorkspaceCallback } from "../workspace-action.mjs";
30
+ import { confirmationLocale } from "./confirmation-text.mjs";
30
31
  import { telegramAppLinkContext } from "./app-links.mjs";
31
32
  import { gatewayImageDescriber } from "../inbound-media/images.mjs";
32
33
  import { chatMediaPlan, gatewayMediaCapabilities, sessionModel } from "../inbound-media/plan.mjs";
@@ -380,7 +381,11 @@ function segmentstreamTelegram(options) {
380
381
  scope: options.sessions().scope
381
382
  });
382
383
  } catch (error) {
383
- reportTelegramError("confirmation_callback_failed", error);
384
+ const errorId = reportTelegramError("confirmation_callback_failed", error);
385
+ if (query.data?.startsWith("ss-confirm:")) logConfirmationPress(query.id, {
386
+ chatId: query.message?.chat.id,
387
+ messageId: query.message?.messageId
388
+ }, "failed", { errorId });
384
389
  await context.telegram.answerCallbackQuery({
385
390
  callbackQueryId: query.id,
386
391
  ...telegramText("callback", "error") === void 0 ? {} : { text: telegramText("callback", "error") }
@@ -4,4 +4,4 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
- export { t as REVISION_CLAIM_TTL_MS, n as attachmentIdentity, r as attachmentRefs, i as captureRouteDecider, a as captureTelegramFetch, o as captureTelegramWebhook, s as chatIdentities, c as currentCapture, l as participants, u as recordGateDecision, d as recordInboundContent, f as recordRouteDecision, p as recordSessionFailure, m as registerCapture, h as telegramChatCapture } from "../../../_chunks/chat-archive-DwSKmO-f.mjs";
7
+ export { t as REVISION_CLAIM_TTL_MS, n as attachmentIdentity, r as attachmentRefs, i as captureRouteDecider, a as captureTelegramFetch, o as captureTelegramWebhook, s as chatIdentities, c as currentCapture, l as participants, u as recordGateDecision, d as recordInboundContent, f as recordRouteDecision, p as recordSessionFailure, m as registerCapture, h as telegramChatCapture } from "../../../_chunks/chat-archive-BhVy1Dbk.mjs";
@@ -0,0 +1,13 @@
1
+ export declare const CONFIRMATION_PREFIX = "ss-confirm:";
2
+ interface Card {
3
+ readonly chatId: unknown;
4
+ readonly messageId: unknown;
5
+ }
6
+ /** Correlate a verified webhook with its decision without retaining the callback payload. */
7
+ export declare function logConfirmationPress(callbackId: string, card: Card, stage: "received" | "handling" | "invalid_callback" | "requester_verified" | "session_resolved" | "not_requester" | "session_missing" | "request_not_pending" | "invalid_choice" | "continuation_missing" | "submitting" | "submitted" | "failed", detail?: {
8
+ readonly errorId?: string;
9
+ readonly sessionId?: string;
10
+ readonly callId?: string;
11
+ readonly decision?: "approve" | "cancel" | "edit" | "expired";
12
+ }): void;
13
+ export {};
@@ -0,0 +1,19 @@
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
+ import { createHash } from "node:crypto";
8
+ const CONFIRMATION_PREFIX = "ss-confirm:";
9
+ function logConfirmationPress(callbackId, card, stage, detail) {
10
+ const numericId = (value) => (typeof value === "number" || typeof value === "string") && /^-?\d{1,24}$/u.test(String(value)) ? String(value) : void 0;
11
+ console.info("[segmentstream] telegram.confirmation_press", {
12
+ pressId: createHash("sha256").update(callbackId).digest("hex").slice(0, 20),
13
+ chatId: numericId(card.chatId),
14
+ messageId: numericId(card.messageId),
15
+ stage,
16
+ ...detail
17
+ });
18
+ }
19
+ export { CONFIRMATION_PREFIX, logConfirmationPress };
@@ -4,6 +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 { CONFIRMATION_PREFIX, logConfirmationPress } from "./confirmation-press.mjs";
7
8
  import { telegramText } from "./texts.mjs";
8
9
  import { F as confirmations, It as chatChannel, c as currentInboundRequest, i as memberIdOf, o as telegramPrincipal, xt as reportTelegramError } from "../../../_chunks/principal-h5knGNwo.mjs";
9
10
  import { humanText } from "../confirmation-description.mjs";
@@ -17,7 +18,6 @@ import { formatAddress, scopedAddress } from "./sessions.mjs";
17
18
  import { createHash } from "node:crypto";
18
19
  import { telegramTextLinks } from "@segmentstream/ontology/telegram";
19
20
  import { call } from "eve/events";
20
- const PREFIX = "ss-confirm:";
21
21
  const LIMIT_PREFIX = "ss-limit:";
22
22
  const recoveredContinuation = (address) => address !== void 0 && /:recovery:[a-f0-9]{64}$/u.test(address);
23
23
  function aliasesPendingTopic(scope, token) {
@@ -28,7 +28,7 @@ function shortHash(value) {
28
28
  }
29
29
  function confirmationCallback(requestId, memberId, decision) {
30
30
  const choice = decision === "approve" ? "y" : decision === "edit" ? "e" : "n";
31
- return `${PREFIX}${shortHash(requestId)}:${shortHash(memberId)}:${choice}`;
31
+ return `${CONFIRMATION_PREFIX}${shortHash(requestId)}:${shortHash(memberId)}:${choice}`;
32
32
  }
33
33
  function usageLimitCallback(interactionId, decision) {
34
34
  return `${LIMIT_PREFIX}${shortHash(interactionId)}:${decision === "continue" ? "y" : "n"}`;
@@ -187,31 +187,48 @@ async function handleConfirmationCallback(input) {
187
187
  });
188
188
  return;
189
189
  }
190
- if (!query.data?.startsWith(PREFIX) || query.message === void 0 || query.from.isBot) {
190
+ if (!query.data?.startsWith("ss-confirm:")) {
191
191
  await notice(telegramText("callback", "unknown"));
192
192
  return;
193
193
  }
194
- const [requestHash, memberHash, choice] = query.data.slice(11).split(":");
194
+ const card = {
195
+ chatId: query.message?.chat.id,
196
+ messageId: query.message?.messageId
197
+ };
198
+ logConfirmationPress(query.id, card, "handling");
199
+ if (query.message === void 0 || query.from.isBot) {
200
+ logConfirmationPress(query.id, card, "invalid_callback");
201
+ await notice(telegramText("callback", "unknown"));
202
+ return;
203
+ }
204
+ const [requestHash, memberHash, choice] = query.data.slice(CONFIRMATION_PREFIX.length).split(":");
195
205
  const lookup = await input.identities.lookup({
196
206
  provider: "telegram",
197
207
  externalId: query.from.id
198
208
  });
199
209
  if (lookup.status !== "paired" || shortHash(lookup.member.id) !== memberHash) {
210
+ logConfirmationPress(query.id, card, "not_requester");
200
211
  await notice(telegramText("callback", "forbidden"));
201
212
  return;
202
213
  }
214
+ logConfirmationPress(query.id, card, "requester_verified");
203
215
  const address = scopedAddress(formatAddress({
204
216
  chatId: query.message.chat.id,
205
217
  messageThreadId: String(query.message.messageThreadId ?? ""),
206
218
  conversationId: query.message.chat.type === "private" ? "" : query.message.messageId
207
219
  }), input.scope);
208
220
  const session = await (currentInboundRequest()?.sessions)?.resolveSession(address);
221
+ if (session !== void 0) logConfirmationPress(query.id, card, "session_resolved", { sessionId: session.id });
209
222
  const prompt = session === void 0 ? void 0 : openConfirmations(await input.read(session.id)).find((candidate) => shortHash(candidate.requestId) === requestHash);
210
223
  if (prompt === void 0 || ![
211
224
  "y",
212
225
  "n",
213
226
  "e"
214
227
  ].includes(choice ?? "") || choice === "e" && !isChatPost(prompt.toolName)) {
228
+ logConfirmationPress(query.id, card, session === void 0 ? "session_missing" : prompt === void 0 ? "request_not_pending" : "invalid_choice", {
229
+ sessionId: session?.id,
230
+ callId: prompt?.callId
231
+ });
215
232
  await notice(telegramText("callback", "already"));
216
233
  return;
217
234
  }
@@ -230,7 +247,16 @@ async function handleConfirmationCallback(input) {
230
247
  }
231
248
  });
232
249
  const source = currentInboundRequest()?.respond;
233
- if (source === void 0) throw new Error("Confirmation callback has no session continuation.");
250
+ const trace = {
251
+ sessionId: session?.id,
252
+ callId: prompt.callId,
253
+ decision: expired ? "expired" : edit ? "edit" : decision
254
+ };
255
+ if (source === void 0) {
256
+ logConfirmationPress(query.id, card, "continuation_missing", trace);
257
+ throw new Error("Confirmation callback has no session continuation.");
258
+ }
259
+ logConfirmationPress(query.id, card, "submitting", trace);
234
260
  await source(address, prompt.requestId, decision, {
235
261
  ...principal,
236
262
  attributes: {
@@ -240,6 +266,7 @@ async function handleConfirmationCallback(input) {
240
266
  ...expired ? { confirmationReason: "expired" } : edit ? { confirmationReason: "edit" } : {}
241
267
  }
242
268
  }, edit ? "The chat post was cancelled for editing. Ask the member what to change using questions_ask, then make a NEW chat_post_message call and confirmation. Never reuse the cancelled call." : void 0);
269
+ logConfirmationPress(query.id, card, "submitted", trace);
243
270
  await notice(expired ? telegramText("callback", "expired") : void 0);
244
271
  }
245
272
  async function answerUsageLimit(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 { t as agentBuild } from "../../../_chunks/build-metadata-WTPUPTo4.mjs";
7
+ import { t as agentBuild } from "../../../_chunks/build-metadata-CHCqNGRE.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";
@@ -28,7 +28,7 @@ import { routingContext } from "./routing-context.mjs";
28
28
  import { formatAddress, messageAddress, scopedAddress } from "./sessions.mjs";
29
29
  import { voiceOf } from "./voice.mjs";
30
30
  import { MAXIMUM_ROUTING_ATTACHMENT_BYTES, describeRoutingAttachment, routingAttachmentDeadline } from "./attachment-description.mjs";
31
- import { d as recordInboundContent, f as recordRouteDecision, u as recordGateDecision } from "../../../_chunks/chat-archive-DwSKmO-f.mjs";
31
+ import { d as recordInboundContent, f as recordRouteDecision, u as recordGateDecision } from "../../../_chunks/chat-archive-BhVy1Dbk.mjs";
32
32
  import { contentShape, messageContent } from "./content.mjs";
33
33
  import { messageAudience } from "./audience.mjs";
34
34
  const MAXIMUM_QUOTE_LENGTH = 500;
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { E as OntologyActionNotPermitted, Et as principalRuntimeSource, L as needsConfirmation, Ot as runtimeEnvelope, W as member, c as currentInboundRequest, j as ontologyTools, k as actionToolName, kt as telegramRuntimeSource } from "../../../_chunks/principal-h5knGNwo.mjs";
8
- import { t as agentBuild } from "../../../_chunks/build-metadata-WTPUPTo4.mjs";
8
+ import { t as agentBuild } from "../../../_chunks/build-metadata-CHCqNGRE.mjs";
9
9
  import { object } from "../confirmation-description.mjs";
10
10
  var AttachmentLifecycleNotPermitted = class extends Error {
11
11
  code = "attachment_lifecycle_not_permitted";
@@ -4,4 +4,4 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
- export { g as captureInStore, _ as storeSend } from "../../../_chunks/chat-archive-DwSKmO-f.mjs";
7
+ export { g as captureInStore, _ as storeSend } from "../../../_chunks/chat-archive-BhVy1Dbk.mjs";
@@ -6,7 +6,7 @@ __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { telegramText } from "./texts.mjs";
8
8
  import { confirmationLocale } from "./confirmation-text.mjs";
9
- import { p as recordSessionFailure } from "../../../_chunks/chat-archive-DwSKmO-f.mjs";
9
+ import { p as recordSessionFailure } from "../../../_chunks/chat-archive-BhVy1Dbk.mjs";
10
10
  import { gt as customerCopy, ht as currentThreadId, i as memberIdOf, mt as currentLocale, xt as reportTelegramError, yt as failureText } from "../../../_chunks/principal-h5knGNwo.mjs";
11
11
  import { modelServiceFailure } from "../model-service-failure.mjs";
12
12
  function telegramFailureEvents(input) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segmentstream/agent",
3
- "version": "0.89.5",
3
+ "version": "0.89.6",
4
4
  "description": "The SegmentStream workspace agent: the ontology as tools, acting as the member who writes, and the browser, Telegram, WhatsApp and Slack through the workspace's connections.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "SegmentStream",