@segmentstream/agent 0.31.1 → 0.31.3

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
@@ -492,9 +492,9 @@ main model when native ingestion is selected (the omitted/default setting). Expl
492
492
  overrides retain their existing fallback ingestion behavior. `false` disables image descriptions. On text-only models the same setting supplies
493
493
  fallback image context; unknown capabilities remain explicit.
494
494
 
495
- Routing decodes at most one file (5 MiB/15 seconds): images yield up to 1,000 characters;
496
- PDFs use plain extraction in a terminable worker for the first two pages and 2,000 characters.
497
- No-text PDFs report `no_extractable_text`; other documents supply metadata. Group voice/audio/
495
+ Routing decodes at most one image (5 MiB/15 seconds) into up to 1,000 characters. Documents,
496
+ PDFs included, are never downloaded or read for routing: the classifier sees their kind and
497
+ filename, as a person in the chat does before opening them. Group voice/audio/
498
498
  video-note transcripts use `models.stt` (60 seconds/5 MiB/15 seconds, 1,000 characters).
499
499
  Derived evidence is untrusted and retained with the message under `argsSummary.routing.decoded`,
500
500
  including kind, model, status and voice duration. It is read back from the archive and is visible
@@ -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.31.1";
7
+ var version = "0.31.3";
8
8
  function agentBuild(environment = process.env) {
9
9
  return {
10
10
  agent: version,
@@ -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-D9dQiZ6s.mjs";
7
+ export { t as agentBuild } from "../../_chunks/build-metadata-D8s4zo2A.mjs";
@@ -9,7 +9,6 @@ import { type RuntimeTokenVerifier } from "../runtime-identity.js";
9
9
  import { type RuntimeToken } from "../runtime-token.js";
10
10
  import { type ImageDescriber } from "./images.js";
11
11
  import { type CapabilityLookup } from "./media-policy.js";
12
- import type { PdfTextExtractor } from "./pdf-text.js";
13
12
  import { type DecideFunction } from "./router.js";
14
13
  import { type HistoryReader } from "./sessions.js";
15
14
  import { type Transcriber } from "./voice.js";
@@ -41,7 +40,6 @@ export interface TelegramAdapterOptions {
41
40
  readonly transcribe?: Transcriber;
42
41
  readonly describeImage?: ImageDescriber;
43
42
  readonly describeAttachment?: AttachmentDescriber;
44
- readonly extractPdf?: PdfTextExtractor;
45
43
  readonly modelCapabilities?: CapabilityLookup;
46
44
  /** Verifies callers of the health route; tests pass one on a local key set. */
47
45
  readonly verify?: RuntimeTokenVerifier;
@@ -10,7 +10,7 @@ import { groupRoutingHealth } from "../group-routing/health.mjs";
10
10
  import { dispatchStructuredMessage, structuredMessage } from "./structured.mjs";
11
11
  import { handleWorkspaceCallback, isWorkspaceCallback } from "./callbacks.mjs";
12
12
  import { telegramText, withTelegramTexts } from "./texts.mjs";
13
- import { t as agentBuild } from "../../../_chunks/build-metadata-D9dQiZ6s.mjs";
13
+ import { t as agentBuild } from "../../../_chunks/build-metadata-D8s4zo2A.mjs";
14
14
  import { attachmentLifecycle } from "./lifecycle.mjs";
15
15
  import { manifestOf } from "../../config.mjs";
16
16
  import { gatewayAttachmentDescriber } from "./attachment-description.mjs";
@@ -232,7 +232,6 @@ function segmentstreamTelegram(options) {
232
232
  sttModel: options.models().stt,
233
233
  attachmentsModel: options.models().imageDescription ?? options.models().attachments ?? "google/gemini-2.5-flash-lite",
234
234
  describeAttachment: options.describeAttachment ?? gatewayAttachmentDescriber,
235
- ...options.extractPdf === void 0 ? {} : { extractPdf: options.extractPdf },
236
235
  describeImage: options.describeImage ?? gatewayImageDescriber,
237
236
  mediaPlan: async (member, sessionId) => {
238
237
  let selected;
@@ -1,5 +1,4 @@
1
1
  import { type ImageDescriber } from "./images.js";
2
- import { type PdfTextExtractor } from "./pdf-text.js";
3
2
  /** Routing has a separate budget from storing the original or running a full agent turn. */
4
3
  export declare const MAXIMUM_ROUTING_ATTACHMENT_BYTES: number;
5
4
  export declare const ROUTING_ATTACHMENT_TIMEOUT_MS = 15000;
@@ -7,7 +6,7 @@ export declare const MAXIMUM_ROUTING_ATTACHMENT_CHARACTERS = 1000;
7
6
  export interface DecodedAttachment {
8
7
  readonly attachment_kind: string;
9
8
  readonly processed: boolean;
10
- readonly status: "processed" | "not_processed" | "no_extractable_text";
9
+ readonly status: "processed" | "not_processed";
11
10
  readonly model?: string;
12
11
  readonly content?: string;
13
12
  readonly duration_seconds?: number;
@@ -19,6 +18,11 @@ export type AttachmentDescriber = (input: Parameters<ImageDescriber>[0] & {
19
18
  export declare const gatewayAttachmentDescriber: AttachmentDescriber;
20
19
  /** Also fences injected providers that ignore AbortSignal. */
21
20
  export declare function routingAttachmentDeadline<T>(run: (signal: AbortSignal) => Promise<T>): Promise<T>;
21
+ /**
22
+ * Routing evidence for one file. Only images are described, because a person in the chat sees an
23
+ * image itself; any other file, PDFs included, reaches the classifier as its kind and name alone,
24
+ * as a person sees it before opening it, and is never downloaded for routing.
25
+ */
22
26
  export declare function describeRoutingAttachment(input: {
23
27
  readonly kind: string;
24
28
  readonly size?: number;
@@ -27,5 +31,4 @@ export declare function describeRoutingAttachment(input: {
27
31
  readonly model: string | false;
28
32
  readonly download: (abortSignal: AbortSignal) => Promise<Uint8Array>;
29
33
  readonly describe: AttachmentDescriber;
30
- readonly extractPdf?: PdfTextExtractor;
31
34
  }): Promise<string>;
@@ -5,7 +5,6 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { describableImage } from "./images.mjs";
8
- import { MAXIMUM_ROUTING_PDF_CHARACTERS, extractRoutingPdf } from "./pdf-text.mjs";
9
8
  import { p as reportTelegramError } from "../../../_chunks/inbound-request-Dy7q3T23.mjs";
10
9
  import { gateway, generateText } from "ai";
11
10
  const MAXIMUM_ROUTING_ATTACHMENT_BYTES = 5242880;
@@ -44,9 +43,7 @@ async function routingAttachmentDeadline(run) {
44
43
  }
45
44
  }
46
45
  async function describeRoutingAttachment(input) {
47
- const pdf = input.mediaType === "application/pdf" || /\.pdf$/iu.test(input.filename);
48
- const image = input.kind === "photo" || describableImage(input.mediaType);
49
- const model = pdf ? "plain-extraction" : image && input.model !== false ? input.model : void 0;
46
+ const model = (input.kind === "photo" || describableImage(input.mediaType)) && input.model !== false ? input.model : void 0;
50
47
  const evidence = {
51
48
  attachment_kind: input.kind,
52
49
  processed: false,
@@ -54,13 +51,12 @@ async function describeRoutingAttachment(input) {
54
51
  ...model === void 0 ? {} : { model }
55
52
  };
56
53
  const unavailable = JSON.stringify(evidence);
57
- if (!pdf && (!image || input.model === false) || (input.size ?? 0) > 5242880) return unavailable;
54
+ if (model === void 0 || (input.size ?? 0) > 5242880) return unavailable;
58
55
  try {
59
56
  const text = await routingAttachmentDeadline(async (abortSignal) => {
60
57
  const bytes = await input.download(abortSignal);
61
58
  abortSignal.throwIfAborted();
62
59
  if (bytes.byteLength > 5242880) return;
63
- if (pdf) return (input.extractPdf ?? extractRoutingPdf)(bytes, abortSignal);
64
60
  return input.describe({
65
61
  ...input,
66
62
  bytes,
@@ -71,8 +67,8 @@ async function describeRoutingAttachment(input) {
71
67
  return text === void 0 ? unavailable : JSON.stringify({
72
68
  ...evidence,
73
69
  processed: text.trim() !== "",
74
- status: text.trim() !== "" ? "processed" : pdf ? "no_extractable_text" : "not_processed",
75
- ...text.trim() === "" ? {} : { content: text.trim().slice(0, pdf ? MAXIMUM_ROUTING_PDF_CHARACTERS : MAXIMUM_ROUTING_ATTACHMENT_CHARACTERS) }
70
+ status: text.trim() !== "" ? "processed" : "not_processed",
71
+ ...text.trim() === "" ? {} : { content: text.trim().slice(0, MAXIMUM_ROUTING_ATTACHMENT_CHARACTERS) }
76
72
  });
77
73
  } catch (error) {
78
74
  reportTelegramError("routing_attachment_processing_failed", error, { kind: input.kind });
@@ -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-D9dQiZ6s.mjs";
7
+ import { t as agentBuild } from "../../../_chunks/build-metadata-D8s4zo2A.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";
@@ -16,7 +16,6 @@ import { type RouteDecider } from "./router.js";
16
16
  import { type HistoryReader } from "./sessions.js";
17
17
  import { type Transcriber } from "./voice.js";
18
18
  import { type AttachmentDescriber } from "./attachment-description.js";
19
- import type { PdfTextExtractor } from "./pdf-text.js";
20
19
  /**
21
20
  * eve's Telegram `onMessage` hook, in the order `agent-design.md` gives:
22
21
  *
@@ -59,7 +58,6 @@ export interface InboundDependencies {
59
58
  readonly sttModel: string | false;
60
59
  readonly attachmentsModel: string | false;
61
60
  readonly describeAttachment: AttachmentDescriber;
62
- readonly extractPdf?: PdfTextExtractor;
63
61
  readonly mediaPlan?: (member: PairedMember, sessionId?: string) => Promise<MediaPlan>;
64
62
  readonly describeImage?: ImageDescriber;
65
63
  readonly identities: AgentIdentities;
@@ -687,8 +687,7 @@ async function handleInboundMessage(input) {
687
687
  routingBytes = bytes;
688
688
  return bytes;
689
689
  },
690
- describe: dependencies.describeAttachment,
691
- ...dependencies.extractPdf === void 0 ? {} : { extractPdf: dependencies.extractPdf }
690
+ describe: dependencies.describeAttachment
692
691
  }) : JSON.stringify(retained);
693
692
  const evidence = JSON.parse(processedMedia);
694
693
  const previous = decoded.findIndex((item) => item.attachment_kind === evidence.attachment_kind);
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { d as telegramRuntimeSource, l as principalRuntimeSource, u as runtimeEnvelope } from "../../../_chunks/principal-CPOCTHBa.mjs";
8
- import { t as agentBuild } from "../../../_chunks/build-metadata-D9dQiZ6s.mjs";
8
+ import { t as agentBuild } from "../../../_chunks/build-metadata-D8s4zo2A.mjs";
9
9
  import { n as currentInboundRequest } from "../../../_chunks/inbound-request-Dy7q3T23.mjs";
10
10
  import { object } from "../confirmation-description.mjs";
11
11
  import { needsConfirmation } from "../confirmations.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segmentstream/agent",
3
- "version": "0.31.1",
3
+ "version": "0.31.3",
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",
@@ -74,7 +74,7 @@
74
74
  },
75
75
  "dependencies": {
76
76
  "@chat-adapter/telegram": "4.41.0",
77
- "@segmentstream-cloud/ontology": "0.82.0",
77
+ "@segmentstream-cloud/ontology": "0.83.0",
78
78
  "@vercel/oidc": "^3.8.4",
79
79
  "ai": "^7.0.137",
80
80
  "csv-parse": "^7.0.3",
@@ -85,7 +85,6 @@
85
85
  "mammoth": "^1.13.0",
86
86
  "marked": "15.0.12",
87
87
  "postal-mime": "^4.0.5",
88
- "unpdf": "^1.9.0",
89
88
  "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz"
90
89
  },
91
90
  "peerDependencies": {
@@ -1,5 +0,0 @@
1
- export declare const MAXIMUM_ROUTING_PDF_PAGES = 2;
2
- export declare const MAXIMUM_ROUTING_PDF_CHARACTERS = 2000;
3
- export type PdfTextExtractor = (bytes: Uint8Array, signal: AbortSignal) => Promise<string>;
4
- /** Byte limits and the shared download/processing deadline are enforced by the caller. */
5
- export declare const extractRoutingPdf: PdfTextExtractor;
@@ -1,82 +0,0 @@
1
- import { fileURLToPath as __eveFileURLToPath, pathToFileURL } from "node:url";
2
- import { dirname as __eveDirname } from "node:path";
3
- import { createRequire as __eveCreateRequire, createRequire } from "node:module";
4
- const __filename = __eveFileURLToPath(import.meta.url);
5
- __eveDirname(__filename);
6
- __eveCreateRequire(import.meta.url);
7
- import { Worker } from "node:worker_threads";
8
- const MAXIMUM_ROUTING_PDF_PAGES = 2;
9
- const MAXIMUM_ROUTING_PDF_CHARACTERS = 2e3;
10
- const workerSource = `
11
- const { parentPort, workerData } = require("node:worker_threads");
12
- (async () => {
13
- const { getDocumentProxy } = await import(workerData.module);
14
- const pdf = await getDocumentProxy(workerData.bytes, {
15
- isEvalSupported: false, useSystemFonts: false, verbosity: 0,
16
- });
17
- let text = "";
18
- for (let pageNumber = 1; pageNumber <= Math.min(pdf.numPages, workerData.pages); pageNumber++) {
19
- if (text.length >= workerData.characters) break;
20
- const page = await pdf.getPage(pageNumber);
21
- const reader = page.streamTextContent().getReader();
22
- while (text.length < workerData.characters) {
23
- const { done, value } = await reader.read();
24
- if (done) break;
25
- for (const item of value.items) {
26
- if (typeof item.str === "string") {
27
- text += item.str.slice(0, workerData.characters - text.length) + (item.hasEOL ? "\\n" : " ");
28
- }
29
- if (text.length >= workerData.characters) break;
30
- }
31
- }
32
- text += "\\n";
33
- }
34
- // The host terminates the isolate on success or failure, releasing the parser and streams.
35
- parentPort.postMessage({ text: text.trim().slice(0, workerData.characters) });
36
- })().catch((error) => parentPort.postMessage({ error: {
37
- name: error?.name ?? "Error", message: error?.message ?? String(error), stack: error?.stack,
38
- } }));
39
- `;
40
- const extractRoutingPdf = async (bytes, signal) => {
41
- signal.throwIfAborted();
42
- const worker = new Worker(workerSource, {
43
- eval: true,
44
- execArgv: [],
45
- workerData: {
46
- module: pathToFileURL(createRequire(import.meta.url).resolve("unpdf")).href,
47
- bytes: bytes.slice(),
48
- pages: 2,
49
- characters: MAXIMUM_ROUTING_PDF_CHARACTERS
50
- },
51
- resourceLimits: {
52
- maxOldGenerationSizeMb: 64,
53
- maxYoungGenerationSizeMb: 16
54
- },
55
- stdout: true,
56
- stderr: true
57
- });
58
- let removeAbortListener = () => {};
59
- worker.stdout?.resume();
60
- worker.stderr?.resume();
61
- try {
62
- return await new Promise((resolve, reject) => {
63
- const abort = () => reject(new Error("Routing PDF extraction aborted."));
64
- signal.addEventListener("abort", abort, { once: true });
65
- removeAbortListener = () => signal.removeEventListener("abort", abort);
66
- worker.once("message", (result) => {
67
- signal.removeEventListener("abort", abort);
68
- if (result.text === void 0) {
69
- const cause = result.error === void 0 ? void 0 : Object.assign(new Error(result.error.message), result.error);
70
- reject(new Error("Routing PDF extraction failed.", { cause }));
71
- } else resolve(result.text);
72
- });
73
- worker.once("error", reject);
74
- worker.once("exit", () => reject(new Error("Routing PDF extractor exited.")));
75
- if (signal.aborted) abort();
76
- });
77
- } finally {
78
- removeAbortListener();
79
- await worker.terminate();
80
- }
81
- };
82
- export { MAXIMUM_ROUTING_PDF_CHARACTERS, MAXIMUM_ROUTING_PDF_PAGES, extractRoutingPdf };