@segmentstream/agent 0.8.3 → 0.8.4

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
@@ -592,3 +592,9 @@ honours the returned deadline within a 120-second processing budget; expiry fail
592
592
  closed without queueing an incomplete turn. Authenticated runtime health includes
593
593
  the built SDK version and deployment identity. Phase telemetry records webhook
594
594
  receipt, lifecycle/queue admission, model/tool events and typing API acceptance.
595
+
596
+ A configured hook failure, or a processing failure after it admits a task, returns
597
+ HTTP 503 with a correlation reference before durable queue admission. Telegram
598
+ can redeliver the same source; the hook and attachment reservation must preserve
599
+ idempotent source membership, storage results and the single acknowledgement.
600
+ Such a failure must not become an HTTP success with no queued work.
@@ -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.8.3";
7
+ var version = "0.8.4";
8
8
  function agentBuild(environment = process.env) {
9
9
  return {
10
10
  agent: version,
@@ -240,6 +240,7 @@ var InboundRequest = class {
240
240
  stopTyping;
241
241
  lifecycle;
242
242
  lifecycleKey;
243
+ retryReference;
243
244
  lifecycleContext;
244
245
  monitor;
245
246
  previousText;
@@ -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-BLyaHLJW.mjs";
7
+ import { t as agentBuild } from "../../_chunks/build-metadata-ByEgTqDs.mjs";
8
8
  export { agentBuild };
@@ -180,7 +180,7 @@ function actionToolName(entity, action) {
180
180
  function promotionTarget(input) {
181
181
  const entity = input.entity;
182
182
  const action = input.action;
183
- if (typeof entity !== "string" || typeof action !== "string" || !/^[a-z][a-zA-Z0-9_]*$/.test(entity) || !/^[a-z][a-zA-Z0-9_]*$/.test(action)) throw new Error("A valid attachment target entity and action are required.");
183
+ if (typeof entity !== "string" || typeof action !== "string" || !/^(?:[a-z][a-zA-Z0-9]*|[a-z][a-z0-9]*(?:_[a-z0-9]+)*)$/.test(entity) || !/^(?:[a-z][a-zA-Z0-9]*|[a-z][a-z0-9]*(?:_[a-z0-9]+)*)$/.test(action)) throw new Error("A valid attachment target entity and action are required.");
184
184
  return {
185
185
  action: actionToolName(entity, action),
186
186
  input: {
@@ -8,10 +8,10 @@ import { manifestOf } from "../../config.mjs";
8
8
  import { appOrigin, channelsEnabled, proxyEnvironment, runtimeIdentityEnvironment, webhookSecret } from "../environment.mjs";
9
9
  import { conversationLanguage, telegramPrincipal } from "./principal.mjs";
10
10
  import { chooseModel } from "../../model.mjs";
11
- import { t as agentBuild } from "../../../_chunks/build-metadata-BLyaHLJW.mjs";
11
+ import { t as agentBuild } from "../../../_chunks/build-metadata-ByEgTqDs.mjs";
12
12
  import { confirmationLocale } from "./confirmation-text.mjs";
13
13
  import { telegramSendScope } from "./send-queue.mjs";
14
- import { d as failureText, h as withDeliveryLocale, i as withReplacedText, m as safeTelegramFetch, n as currentInboundRequest, p as reportTelegramError, r as runInboundRequest, t as InboundRequest } from "../../../_chunks/inbound-request-CYSoY6pu.mjs";
14
+ import { d as failureText, h as withDeliveryLocale, i as withReplacedText, m as safeTelegramFetch, n as currentInboundRequest, p as reportTelegramError, r as runInboundRequest, t as InboundRequest } from "../../../_chunks/inbound-request-B98tr4Pd.mjs";
15
15
  import { runtimeToken } from "../runtime-token.mjs";
16
16
  import { attachmentLifecycle } from "./lifecycle.mjs";
17
17
  import { conversations } from "../conversations.mjs";
@@ -252,7 +252,8 @@ function segmentstreamTelegram(options) {
252
252
  } catch (error) {
253
253
  recordGateDecision("inbound_message_failed");
254
254
  const errorId = reportTelegramError("inbound_message_failed", error, { chatId: message.chat.id });
255
- await context.telegram.post(failureText(errorId));
255
+ if (inbound?.lifecycleKey !== void 0) inbound.retryReference = errorId;
256
+ else await context.telegram.post(failureText(errorId));
256
257
  return null;
257
258
  } finally {
258
259
  inbound?.stopTyping?.();
@@ -464,6 +465,13 @@ function gatedRoute(input) {
464
465
  completed = tasks.length;
465
466
  await Promise.all(pending);
466
467
  }
468
+ if (inbound.retryReference !== void 0) return Response.json({
469
+ error: "attachment_intake_retry",
470
+ reference: inbound.retryReference
471
+ }, {
472
+ status: 503,
473
+ headers: { "retry-after": "1" }
474
+ });
467
475
  return response;
468
476
  }));
469
477
  }
@@ -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-CYSoY6pu.mjs";
7
+ import { p as reportTelegramError } from "../../../_chunks/inbound-request-B98tr4Pd.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";
@@ -9,7 +9,7 @@ import "./principal.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
- import { c as customerCopy, f as formattingRefused, l as customerMessage, p as reportTelegramError } from "../../../_chunks/inbound-request-CYSoY6pu.mjs";
12
+ import { c as customerCopy, f as formattingRefused, l as customerMessage, p as reportTelegramError } from "../../../_chunks/inbound-request-B98tr4Pd.mjs";
13
13
  import { runtimeToken } from "../runtime-token.mjs";
14
14
  import { MAXIMUM_PROXY_BODY_BYTES, connectionProxy } from "../connection-proxy.mjs";
15
15
  import { ACT_AS_HEADER } from "../ontology-connection.mjs";
@@ -6,7 +6,7 @@ __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { proxyEnvironment } from "../environment.mjs";
8
8
  import { telegramSendScope } from "./send-queue.mjs";
9
- import { m as safeTelegramFetch, p as reportTelegramError } from "../../../_chunks/inbound-request-CYSoY6pu.mjs";
9
+ import { m as safeTelegramFetch, p as reportTelegramError } from "../../../_chunks/inbound-request-B98tr4Pd.mjs";
10
10
  import { runtimeToken } from "../runtime-token.mjs";
11
11
  import { deferredConfirmations } from "../deferred-confirmations.mjs";
12
12
  import { conversations } from "../conversations.mjs";
@@ -8,7 +8,7 @@ import { memberIdOf, telegramPrincipal } from "./principal.mjs";
8
8
  import { humanText } from "../confirmation-description.mjs";
9
9
  import { renderConfirmation, withConfirmationText } from "./confirmation-text.mjs";
10
10
  import { chatPostCard, chatPostCardStatus, chatPostReceipt, withChatPostCard } from "./chat-post-card.mjs";
11
- import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-CYSoY6pu.mjs";
11
+ import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-B98tr4Pd.mjs";
12
12
  import { chatPostOperationId, isChatPost } from "../chat-post-confirmation.mjs";
13
13
  import { confirmations } from "../confirmations.mjs";
14
14
  import { conversationEvent } from "../conversations.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 { n as currentInboundRequest, s as currentThreadId } from "../../../_chunks/inbound-request-CYSoY6pu.mjs";
7
+ import { n as currentInboundRequest, s as currentThreadId } from "../../../_chunks/inbound-request-B98tr4Pd.mjs";
8
8
  import { conversationEvent } from "../conversations.mjs";
9
9
  import { contentShape, messageContent } from "./content.mjs";
10
10
  import { currentConfirmationPrompt, messageMetadata, observedChatKey } from "./observed.mjs";
@@ -5,5 +5,5 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { isTechnicalText } from "../customer-text-safety.mjs";
8
- import { 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-CYSoY6pu.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-B98tr4Pd.mjs";
9
9
  export { TelegramDeliveryError, currentLocale, currentThreadId, customerCopy, customerMessage, customerText, failureText, formattingRefused, isTechnicalText, reportTelegramError, safeTelegramFetch, withDeliveryLocale };
@@ -8,7 +8,7 @@ import { telegramPrincipal } from "./principal.mjs";
8
8
  import { humanText } from "../confirmation-description.mjs";
9
9
  import { renderConfirmation, withConfirmationText } from "./confirmation-text.mjs";
10
10
  import { chatPostCard, chatPostCardStatus, chatPostReceipt, withChatPostCard } from "./chat-post-card.mjs";
11
- import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-CYSoY6pu.mjs";
11
+ import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-B98tr4Pd.mjs";
12
12
  import { CONFIRMATION_TTL_MS, inputHash } from "../confirmations.mjs";
13
13
  import { confirmationOutcome } from "../confirmation-outcome.mjs";
14
14
  import { deferredConfirmations, deferredKey, runDeferredAction } from "../deferred-confirmations.mjs";
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { conversationLanguage } from "./principal.mjs";
8
- import { d as failureText, p as reportTelegramError } from "../../../_chunks/inbound-request-CYSoY6pu.mjs";
8
+ import { d as failureText, p as reportTelegramError } from "../../../_chunks/inbound-request-B98tr4Pd.mjs";
9
9
  import { describableImage, describeReceivedImage } from "./images.mjs";
10
10
  import { MAXIMUM_ATTACHMENT_BYTES, attachmentUrl } from "../attachments.mjs";
11
11
  function telegramConversation(chatId) {
@@ -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-BLyaHLJW.mjs";
7
+ import { t as agentBuild } from "../../../_chunks/build-metadata-ByEgTqDs.mjs";
8
8
  import { runtimeRequestFailure } from "./runtime-request.mjs";
9
9
  import { GET } from "eve/channels";
10
10
  const HEALTH_ROUTE = "/eve/v1/telegram/health";
@@ -4,7 +4,7 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
- import { p as reportTelegramError } from "../../../_chunks/inbound-request-CYSoY6pu.mjs";
7
+ import { p as reportTelegramError } from "../../../_chunks/inbound-request-B98tr4Pd.mjs";
8
8
  import { gateway, generateText } from "ai";
9
9
  const MAXIMUM_IMAGE_DESCRIPTION_BYTES = 5242880;
10
10
  const MAXIMUM_NATIVE_IMAGE_BYTES = 3145728;
@@ -37,6 +37,8 @@ export declare class InboundRequest {
37
37
  stopTyping: (() => void) | undefined;
38
38
  lifecycle: ReturnType<typeof import("./lifecycle.js").attachmentLifecycle> | undefined;
39
39
  lifecycleKey: string | undefined;
40
+ /** An admitted task must be redelivered if processing did not reach durable queue admission. */
41
+ retryReference: string | undefined;
40
42
  lifecycleContext: string | undefined;
41
43
  monitor: ((session: Awaited<ReturnType<ChannelSource<unknown>["send"]>>, marker: string) => void) | undefined;
42
44
  previousText: string | undefined;
@@ -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-CYSoY6pu.mjs";
7
+ import { i as withReplacedText, n as currentInboundRequest, r as runInboundRequest, t as InboundRequest } from "../../../_chunks/inbound-request-B98tr4Pd.mjs";
8
8
  export { InboundRequest, currentInboundRequest, runInboundRequest, withReplacedText };
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { conversationLanguage, telegramPrincipal } from "./principal.mjs";
8
- import { p as reportTelegramError } from "../../../_chunks/inbound-request-CYSoY6pu.mjs";
8
+ import { p as reportTelegramError } from "../../../_chunks/inbound-request-B98tr4Pd.mjs";
9
9
  import { startTypingHeartbeat, typingUntilComplete } from "./lifecycle.mjs";
10
10
  import { formatAddress, messageAddress, scopedAddress } from "./sessions.mjs";
11
11
  import { contentShape, messageContent } from "./content.mjs";
@@ -401,11 +401,12 @@ async function handleInboundMessage(input) {
401
401
  });
402
402
  }
403
403
  } catch (error) {
404
- reportTelegramError("intake_admission_failed", error, {
404
+ input.request.retryReference = reportTelegramError("intake_admission_failed", error, {
405
405
  chatId: sent.chat.id,
406
406
  messageId: sent.messageId
407
407
  });
408
408
  input.request.lifecycle = void 0;
409
+ return null;
409
410
  }
410
411
  }
411
412
  if (input.request !== void 0) {
@@ -4,9 +4,9 @@ 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-BLyaHLJW.mjs";
7
+ import { t as agentBuild } from "../../../_chunks/build-metadata-ByEgTqDs.mjs";
8
8
  import { object } from "../confirmation-description.mjs";
9
- import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-CYSoY6pu.mjs";
9
+ import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-B98tr4Pd.mjs";
10
10
  import { needsConfirmation } from "../confirmations.mjs";
11
11
  import { actionToolName, ontologyTools } from "../ontology-tools.mjs";
12
12
  function attachmentLifecycle(options) {
@@ -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-CYSoY6pu.mjs";
8
+ import { p as reportTelegramError } from "../../../_chunks/inbound-request-B98tr4Pd.mjs";
9
9
  function planMedia(capabilities, descriptionModel = null) {
10
10
  if (typeof descriptionModel === "string") return {
11
11
  images: "describe",
@@ -8,7 +8,7 @@ import "./principal.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-CYSoY6pu.mjs";
11
+ import { a as TelegramDeliveryError, l as customerMessage, o as currentLocale, p as reportTelegramError } from "../../../_chunks/inbound-request-B98tr4Pd.mjs";
12
12
  import { agentMessage, observedChatKey } from "./observed.mjs";
13
13
  const SILENT_MARKERS = new Set(["[silent]", "no_reply"]);
14
14
  function isSilentReply(text) {
@@ -6,7 +6,7 @@ __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { memberIdOf } from "./principal.mjs";
8
8
  import { confirmationLocale } from "./confirmation-text.mjs";
9
- import { c as customerCopy, d as failureText, o as currentLocale, p as reportTelegramError } from "../../../_chunks/inbound-request-CYSoY6pu.mjs";
9
+ import { c as customerCopy, d as failureText, o as currentLocale, p as reportTelegramError } from "../../../_chunks/inbound-request-B98tr4Pd.mjs";
10
10
  const telegramFailureEvents = {
11
11
  async "turn.cancelled"(event, channel, context) {
12
12
  const errorId = reportTelegramError("turn_cancelled", event, {
@@ -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-CYSoY6pu.mjs";
7
+ import { p as reportTelegramError } from "../../../_chunks/inbound-request-B98tr4Pd.mjs";
8
8
  import "../connection-proxy.mjs";
9
9
  import { gateway, transcribe } from "ai";
10
10
  const LABELS = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segmentstream/agent",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
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",