@segmentstream/agent 0.31.8 → 0.31.10

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.
@@ -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.8";
7
+ var version = "0.31.10";
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-DSc4ASfK.mjs";
7
+ export { t as agentBuild } from "../../_chunks/build-metadata-CPNo_iGJ.mjs";
@@ -23,6 +23,11 @@ export declare class UnsafeConfirmationTarget extends Error {
23
23
  }
24
24
  export declare function object(value: unknown): Record<string, unknown>;
25
25
  export declare function humanize(value: string): string;
26
+ /**
27
+ * Why a value cannot be shown as plain text on a confirmation card, or nothing when it can. An
28
+ * email address is a fact a member must see, so its domain is not read as a link or a file name.
29
+ */
30
+ export declare function humanTextIssue(value: unknown, maximum?: number): string | undefined;
26
31
  /** Reject machine identifiers and structured data even in authored labels or resolved titles. */
27
32
  export declare function humanText(value: unknown, maximum?: number): string | undefined;
28
33
  /** Resolve local schema references and wrappers without following remote references. */
@@ -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 { isTechnicalText } from "./customer-text-safety.mjs";
7
+ import { isTechnicalText, withoutEmailAddresses } from "./customer-text-safety.mjs";
8
8
  var UnsafeConfirmationTarget = class extends Error {
9
9
  label;
10
10
  constructor(label) {
@@ -19,18 +19,20 @@ function object(value) {
19
19
  function humanize(value) {
20
20
  return value.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").trim();
21
21
  }
22
- function humanText(value, maximum = 180) {
23
- if (typeof value !== "string") return;
22
+ function humanTextIssue(value, maximum = 180) {
23
+ if (typeof value !== "string") return "is not text";
24
24
  const text = value.trim();
25
- if (text === "" || text.length > maximum || isTechnicalText(text) || [
26
- /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}<>`*_~|\\\[\]{}]|^(?:#{1,6}|[-+])\s/u,
27
- /[a-z][a-z0-9+.-]*:\/\/|www\.|\b[a-z][a-z0-9]*\.[a-z][a-z_0-9]+\b/iu,
28
- /&(?:#\d+|#x[0-9a-f]+|[a-z]+);/iu,
29
- /\bBearer\s+|\b(?:password|secret|token|credential|api[ _-]?key)\s*[:=]/iu,
30
- /\b(?:sk|ssw|ghp)[_-][a-z0-9]+/iu,
31
- /\b[0-9a-f]{8}-[0-9a-f-]{27,}\b|\b[0-9A-HJKMNP-TV-Z]{26}\b|\b[a-z0-9]{24,}\b/iu
32
- ].some((pattern) => pattern.test(text))) return;
33
- return text;
25
+ if (text === "") return "is empty";
26
+ if (text.length > maximum) return `is longer than ${maximum} characters`;
27
+ const prose = withoutEmailAddresses(text);
28
+ if (/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u.test(prose)) return "has a line break or an invisible character";
29
+ if (/[<>`*_~|\\\[\]{}]|^(?:#{1,6}|[-+])\s/u.test(prose) || /&(?:#\d+|#x[0-9a-f]+|[a-z]+);/iu.test(prose)) return "has markup";
30
+ if (/[a-z][a-z0-9+.-]*:\/\/|www\.|\b[a-z][a-z0-9]*\.[a-z][a-z_0-9]+\b/iu.test(prose)) return "has a link, a web address or a file name (an email address is fine)";
31
+ if (/\bBearer\s+|\b(?:password|secret|token|credential|api[ _-]?key)\s*[:=]/iu.test(text) || /\b(?:sk|ssw|ghp)[_-][a-z0-9]+/iu.test(text)) return "looks like a credential";
32
+ if (isTechnicalText(text) || /\b[0-9a-f]{8}-[0-9a-f-]{27,}\b|\b[0-9A-HJKMNP-TV-Z]{26}\b|\b[a-z0-9]{24,}\b/iu.test(text)) return "has an identifier, a tool name or technical text";
33
+ }
34
+ function humanText(value, maximum = 180) {
35
+ return humanTextIssue(value, maximum) === void 0 ? value.trim() : void 0;
34
36
  }
35
37
  function factText(value, maximum = 180) {
36
38
  if (typeof value === "string" && value.trim().length > maximum) throw new Error("The complete confirmation facts cannot fit in one Telegram message.");
@@ -149,4 +151,4 @@ async function describeConfirmation(input) {
149
151
  ...targets.length === 0 ? {} : { targets }
150
152
  };
151
153
  }
152
- export { CONFIRMATION_FACTS, UnsafeConfirmationTarget, describeConfirmation, factsConfirmation, fieldSchema, humanText, humanize, object };
154
+ export { CONFIRMATION_FACTS, UnsafeConfirmationTarget, describeConfirmation, factsConfirmation, fieldSchema, humanText, humanTextIssue, humanize, object };
@@ -8,7 +8,7 @@ import { actorOf, member } from "./actor.mjs";
8
8
  import { i as memberIdOf } from "../../_chunks/principal-CPOCTHBa.mjs";
9
9
  import { UnsafeConfirmationTarget } from "./confirmation-description.mjs";
10
10
  import { chatPostDigest, isChatPost } from "./chat-post-confirmation.mjs";
11
- import { confirmationCopy, confirmationLocale, renderConfirmation } from "./telegram/confirmation-text.mjs";
11
+ import { confirmationCopy, confirmationCopyIssue, confirmationLocale, renderConfirmation } from "./telegram/confirmation-text.mjs";
12
12
  import { chatPostCard } from "./telegram/chat-post-card.mjs";
13
13
  import { withTelegramTexts } from "./telegram/texts.mjs";
14
14
  import { createHash } from "node:crypto";
@@ -77,7 +77,7 @@ function actionApproval(options) {
77
77
  const businessInput = Object.fromEntries(Object.entries(ctx.toolInput ?? {}).filter(([key]) => key !== "_confirmation"));
78
78
  const posting = isChatPost(ctx.toolName);
79
79
  let description;
80
- const missingCopy = () => denied((offered === void 0 ? "This action needs a confirmation card and the call has no _confirmation. " : "The call's _confirmation is invalid. ") + "Make the call again with _confirmation (for a file call, in its arguments file) in the chat's language: a plain single-line question naming the action and its key records and amounts (at most 300 characters), and short confirm, cancel, done, cancelled and failed labels without emoji.");
80
+ const missingCopy = () => denied((offered === void 0 ? "This action needs a confirmation card and the call has no _confirmation. " : `The call's _confirmation is invalid: ${confirmationCopyIssue(offered) ?? "it cannot be shown"}. `) + "Make the call again with _confirmation (for a file call, in its arguments file) in the chat's language: a plain single-line question naming the action and its key records and amounts (at most 300 characters), and short confirm, cancel, done, cancelled and failed labels without emoji.");
81
81
  if (posting && saved === void 0 && labels.confirmation === true && copy === void 0) return missingCopy();
82
82
  if (posting) try {
83
83
  description = await options.describe?.(member(memberId), ctx.toolName, businessInput, hints);
@@ -1 +1,3 @@
1
+ /** The text with each email address read as a word, for checks that would mistake one for a link. */
2
+ export declare function withoutEmailAddresses(text: string): string;
1
3
  export declare function isTechnicalText(text: string): boolean;
@@ -4,6 +4,10 @@ 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
+ const EMAIL_ADDRESS = new RegExp(String.raw`(?<![\p{L}\p{N}._%+-])[\p{L}\p{N}._%+-]+@` + String.raw`(?:[\p{L}\p{N}](?:[\p{L}\p{N}-]*[\p{L}\p{N}])?\.)+\p{L}{2,}` + String.raw`(?![\p{L}\p{N}-]|\.[\p{L}\p{N}])`, "gu");
8
+ function withoutEmailAddresses(text) {
9
+ return text.replace(EMAIL_ADDRESS, "address");
10
+ }
7
11
  const TECHNICAL_PATTERNS = [
8
12
  /^\s*(?=[0-9a-f]*[a-f])[0-9a-f]{8}\s*$/iu,
9
13
  /[{}]|```/u,
@@ -19,7 +23,7 @@ const TECHNICAL_PATTERNS = [
19
23
  function isTechnicalText(text) {
20
24
  if (/\bhq:[0-9a-f]{64}\b/iu.test(text) || /https?:\/\/[^\s/@]+:[^\s/@]+@|[?&](?:token|access_token|api_key|secret|password)=/iu.test(text)) return true;
21
25
  const visible = text.replace(/https?:\/\/[^\s)<>]+/giu, "link");
22
- const prose = visible.replace(/(?<![\w@])@[a-z][a-z0-9_]{4,31}(?!\w)/giu, "recipient");
26
+ const prose = withoutEmailAddresses(visible.replace(/(?<![\w@])@[a-z][a-z0-9_]{4,31}(?!\w)/giu, "recipient"));
23
27
  return TECHNICAL_PATTERNS.some((pattern) => pattern.test(visible)) || /\b[a-z][a-z0-9]*_[a-z][a-z0-9_]*\b(?!\.[a-z0-9])/iu.test(prose);
24
28
  }
25
- export { isTechnicalText };
29
+ export { isTechnicalText, withoutEmailAddresses };
@@ -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-DSc4ASfK.mjs";
13
+ import { t as agentBuild } from "../../../_chunks/build-metadata-CPNo_iGJ.mjs";
14
14
  import { attachmentLifecycle } from "./lifecycle.mjs";
15
15
  import { manifestOf } from "../../config.mjs";
16
16
  import { gatewayAttachmentDescriber } from "./attachment-description.mjs";
@@ -28,6 +28,11 @@ export interface ConfirmationText {
28
28
  readonly edit: string;
29
29
  }
30
30
  export declare function confirmationLocale(principal: SessionAuthContext | null, fallback?: string): string;
31
+ /**
32
+ * Why the agent's presentation cannot be used, in words the agent can act on, or nothing when it
33
+ * can. The whole object is judged; no part of malformed copy is trusted.
34
+ */
35
+ export declare function confirmationCopyIssue(value: unknown): string | undefined;
31
36
  /** Reject the entire presentation object; never partially trust malformed model copy. */
32
37
  export declare function confirmationCopy(value?: unknown): ConfirmationCopy | undefined;
33
38
  /** Button positions retain callback meaning; workspace copy supplies every label and status. */
@@ -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 { humanText, object } from "../confirmation-description.mjs";
7
+ import { humanText, humanTextIssue, object } from "../confirmation-description.mjs";
8
8
  import { isTechnicalText } from "../customer-text-safety.mjs";
9
9
  import { telegramText } from "./texts.mjs";
10
10
  import { AsyncLocalStorage } from "node:async_hooks";
@@ -28,31 +28,45 @@ function confirmationLocale(principal, fallback = "en") {
28
28
  }
29
29
  return fallback;
30
30
  }
31
- function confirmationCopy(value) {
32
- if (value === void 0) return;
31
+ const REQUIRED_COPY = [
32
+ "question",
33
+ "confirm",
34
+ "cancel",
35
+ "done",
36
+ "cancelled",
37
+ "failed"
38
+ ];
39
+ const OPTIONAL_COPY = [
40
+ "expired",
41
+ "interrupted",
42
+ "edit"
43
+ ];
44
+ function confirmationCopyIssue(value) {
45
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return "it is not an object";
33
46
  const copy = object(value);
34
- const required = [
35
- "question",
36
- "confirm",
37
- "cancel",
38
- "done",
39
- "cancelled",
40
- "failed"
41
- ];
42
- const optional = [
43
- "expired",
44
- "interrupted",
45
- "edit"
46
- ];
47
- const valid = (key) => {
47
+ const unknown = Object.keys(copy).find((key) => ![...REQUIRED_COPY, ...OPTIONAL_COPY].includes(key));
48
+ if (unknown !== void 0) return `it has an unknown key ${JSON.stringify(unknown)}`;
49
+ for (const key of [...REQUIRED_COPY, ...OPTIONAL_COPY]) {
48
50
  const text = copy[key];
49
- return typeof text === "string" && text === text.trim() && (key === "question" || !/[✅❌⌛⚠❓✏]/u.test(text)) && humanText(text, key === "question" ? 300 : 24) === text;
50
- };
51
- if (required.some((key) => !valid(key)) || optional.some((key) => copy[key] !== void 0 && !valid(key)) || copy.confirm === copy.cancel || Object.keys(copy).some((key) => ![...required, ...optional].includes(key))) {
51
+ if (text === void 0) {
52
+ if (REQUIRED_COPY.includes(key)) return `it has no ${key}`;
53
+ continue;
54
+ }
55
+ if (typeof text !== "string") return `its ${key} is not text`;
56
+ if (text !== text.trim()) return `its ${key} has leading or trailing spaces`;
57
+ if (key !== "question" && /[✅❌⌛⚠❓✏]/u.test(text)) return `its ${key} has an emoji`;
58
+ const issue = humanTextIssue(text, key === "question" ? 300 : 24);
59
+ if (issue !== void 0) return `its ${key} ${issue}`;
60
+ }
61
+ if (copy.confirm === copy.cancel) return "its confirm and cancel are the same";
62
+ }
63
+ function confirmationCopy(value) {
64
+ if (value === void 0) return;
65
+ if (confirmationCopyIssue(value) !== void 0) {
52
66
  console.warn("Invalid confirmation presentation; using workspace presentation.");
53
67
  return;
54
68
  }
55
- return { ...copy };
69
+ return { ...object(value) };
56
70
  }
57
71
  function renderConfirmation(description, copy) {
58
72
  copy = confirmationCopy(copy);
@@ -86,4 +100,4 @@ function renderConfirmation(description, copy) {
86
100
  edit: copy?.edit ?? configured("edit")
87
101
  };
88
102
  }
89
- export { confirmationCopy, confirmationLocale, isConfirmationText, renderConfirmation, withConfirmationText };
103
+ export { confirmationCopy, confirmationCopyIssue, confirmationLocale, isConfirmationText, renderConfirmation, withConfirmationText };
@@ -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-DSc4ASfK.mjs";
7
+ import { t as agentBuild } from "../../../_chunks/build-metadata-CPNo_iGJ.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";
@@ -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-DSc4ASfK.mjs";
8
+ import { t as agentBuild } from "../../../_chunks/build-metadata-CPNo_iGJ.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.8",
3
+ "version": "0.31.10",
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.86.0",
77
+ "@segmentstream-cloud/ontology": "0.87.0",
78
78
  "@vercel/oidc": "^3.8.4",
79
79
  "ai": "^7.0.137",
80
80
  "csv-parse": "^7.0.3",