@segmentstream/agent 0.74.0 → 0.76.0

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.
Files changed (100) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/README.md +1 -0
  3. package/dist/_chunks/{build-metadata-Cq9R60V5.mjs → build-metadata-DIf8SOej.mjs} +1 -1
  4. package/dist/_chunks/{chat-archive-oJWmk8wm.mjs → chat-archive-BVngSwuB.mjs} +2 -2
  5. package/dist/_chunks/{chat-archive-BgxTGPKZ.mjs → chat-archive-CDk-FPLX.mjs} +7 -3
  6. package/dist/extension/config.d.ts +27 -0
  7. package/dist/extension/config.mjs +46 -7
  8. package/dist/extension/connections/ontology.mjs +1 -1
  9. package/dist/extension/extension.d.ts +1 -1
  10. package/dist/extension/hooks/authorization.mjs +1 -1
  11. package/dist/extension/hooks/chat-context.mjs +1 -1
  12. package/dist/extension/hooks/chat-recorder.mjs +1 -1
  13. package/dist/extension/instructions/persona.mjs +1 -1
  14. package/dist/extension/lib/actor.mjs +1 -1
  15. package/dist/extension/lib/admission.d.ts +8 -3
  16. package/dist/extension/lib/admission.mjs +14 -2
  17. package/dist/extension/lib/attachment-tools.mjs +1 -1
  18. package/dist/extension/lib/attachments-send.mjs +1 -1
  19. package/dist/extension/lib/attachments.mjs +1 -1
  20. package/dist/extension/lib/build-metadata.mjs +1 -1
  21. package/dist/extension/lib/chat-address.mjs +1 -1
  22. package/dist/extension/lib/chat-archive.mjs +1 -1
  23. package/dist/extension/lib/chat-context.mjs +2 -2
  24. package/dist/extension/lib/chat-messages.d.ts +43 -3
  25. package/dist/extension/lib/chat-messages.mjs +47 -8
  26. package/dist/extension/lib/chat-recorder.mjs +2 -2
  27. package/dist/extension/lib/confirmations.mjs +1 -1
  28. package/dist/extension/lib/email/attachments-send.mjs +1 -1
  29. package/dist/extension/lib/email/channel.d.ts +3 -0
  30. package/dist/extension/lib/email/channel.mjs +61 -15
  31. package/dist/extension/lib/group-routing/routing-context.mjs +1 -1
  32. package/dist/extension/lib/guest-usage.mjs +1 -1
  33. package/dist/extension/lib/inbound-media/files.mjs +1 -1
  34. package/dist/extension/lib/inbound-media/index.mjs +1 -1
  35. package/dist/extension/lib/model-service-alert.mjs +1 -1
  36. package/dist/extension/lib/ontology-connection.mjs +1 -1
  37. package/dist/extension/lib/ontology-file-call.mjs +1 -1
  38. package/dist/extension/lib/ontology-tools.mjs +1 -1
  39. package/dist/extension/lib/review/hold.mjs +1 -1
  40. package/dist/extension/lib/review/judge.mjs +1 -1
  41. package/dist/extension/lib/review/reply.mjs +2 -2
  42. package/dist/extension/lib/review/revision-channel.mjs +1 -1
  43. package/dist/extension/lib/role-skill.mjs +1 -1
  44. package/dist/extension/lib/runtime-envelope.mjs +1 -1
  45. package/dist/extension/lib/sent-files.mjs +1 -1
  46. package/dist/extension/lib/slack/adapter.mjs +2 -2
  47. package/dist/extension/lib/slack/attachments-send.mjs +1 -1
  48. package/dist/extension/lib/slack/callbacks.mjs +1 -1
  49. package/dist/extension/lib/stored-files.mjs +1 -1
  50. package/dist/extension/lib/telegram/adapter.mjs +4 -4
  51. package/dist/extension/lib/telegram/attachment-description.mjs +1 -1
  52. package/dist/extension/lib/telegram/attachments-send.mjs +1 -1
  53. package/dist/extension/lib/telegram/callbacks.mjs +1 -1
  54. package/dist/extension/lib/telegram/chat-archive.mjs +1 -1
  55. package/dist/extension/lib/telegram/confirmations.mjs +2 -2
  56. package/dist/extension/lib/telegram/customer-text.mjs +1 -1
  57. package/dist/extension/lib/telegram/delivery-diagnostics.mjs +1 -1
  58. package/dist/extension/lib/telegram/files.mjs +1 -1
  59. package/dist/extension/lib/telegram/health.mjs +1 -1
  60. package/dist/extension/lib/telegram/held-approvals.mjs +1 -1
  61. package/dist/extension/lib/telegram/inbound-request.mjs +1 -1
  62. package/dist/extension/lib/telegram/inbound.mjs +2 -2
  63. package/dist/extension/lib/telegram/lifecycle.mjs +2 -2
  64. package/dist/extension/lib/telegram/principal.mjs +1 -1
  65. package/dist/extension/lib/telegram/session-recovery.mjs +1 -1
  66. package/dist/extension/lib/telegram/silent.mjs +1 -1
  67. package/dist/extension/lib/telegram/store-capture.mjs +1 -1
  68. package/dist/extension/lib/telegram/structured.mjs +1 -1
  69. package/dist/extension/lib/telegram/turn-errors.mjs +2 -2
  70. package/dist/extension/lib/web/auth.mjs +1 -1
  71. package/dist/extension/lib/web/channel.mjs +1 -1
  72. package/dist/extension/lib/whatsapp/adapter.d.ts +6 -2
  73. package/dist/extension/lib/whatsapp/adapter.mjs +44 -10
  74. package/dist/extension/lib/whatsapp/attachments-send.mjs +2 -2
  75. package/dist/extension/lib/whatsapp/callbacks.mjs +1 -1
  76. package/dist/extension/lib/whatsapp/changes.d.ts +5 -4
  77. package/dist/extension/lib/whatsapp/changes.mjs +3 -3
  78. package/dist/extension/lib/whatsapp/echoes.d.ts +4 -3
  79. package/dist/extension/lib/whatsapp/echoes.mjs +2 -2
  80. package/dist/extension/lib/whatsapp/files.mjs +1 -1
  81. package/dist/extension/lib/whatsapp/sent.mjs +1 -1
  82. package/dist/extension/lib/workspace-action.mjs +1 -1
  83. package/dist/extension/lib/workspace-channel/attachments-send.mjs +1 -1
  84. package/dist/extension/lib/workspace-channel/channel.mjs +30 -16
  85. package/dist/extension/lib/workspace-chat-archive.d.ts +7 -0
  86. package/dist/extension/lib/workspace-chat-archive.mjs +1 -1
  87. package/dist/extension/lib/workspace-source.mjs +1 -1
  88. package/dist/extension/model.mjs +1 -1
  89. package/dist/extension/tools/attachments_discard.mjs +1 -1
  90. package/dist/extension/tools/attachments_list.mjs +1 -1
  91. package/dist/extension/tools/attachments_promote.mjs +1 -1
  92. package/dist/extension/tools/attachments_read.mjs +1 -1
  93. package/dist/extension/tools/attachments_send.mjs +1 -1
  94. package/dist/extension/tools/attachments_stage.mjs +1 -1
  95. package/dist/extension/tools/attachments_table.mjs +1 -1
  96. package/dist/extension/tools/handoff.mjs +1 -1
  97. package/dist/extension/tools/questions_ask.mjs +1 -1
  98. package/dist/extension/tools/workspace_source.mjs +1 -1
  99. package/package.json +2 -2
  100. package/dist/_chunks/{principal-Zf42Yf4r.mjs → principal-C7aAjyt4.mjs} +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,50 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.76.0
4
+
5
+ A WhatsApp or workspace channel takes `"record": "all"` in `agent/segmentstream.json`: it keeps
6
+ every message it receives in its chats, answered or not, on an agent whose ontology keeps the
7
+ workspace chat store. `"agent"`, the default, records as before.
8
+
9
+ - A message from someone the agent does not admit joins their chat without a member and starts no
10
+ turn, `skipped` with `identity_unknown` (the account is no user's), `identity_refused` (a blocked
11
+ or inactive member) or `limited` (over a limit). Admission is unchanged: the person gets the
12
+ workspace's pairing, refusal or limit text as before, and nobody becomes a user by being
13
+ recorded. Their files are recorded by name, not stored.
14
+ - A member's message with nothing the agent reads is `skipped` with `no_text`.
15
+ - What the workspace's side writes outside the agent, and on WhatsApp a contact card, is recorded
16
+ even in a chat the agent has none of yet, without members.
17
+ - The private chat of someone who is no user is reported to the ontology without a person, which
18
+ registers it for the inbox where the ontology's `inbox.channels` lists the channel.
19
+
20
+ Recording every message stores what people the agent never answers wrote. Declare it only on a
21
+ channel whose every conversation the workspace works, scope `agent_chat:read` to the staff who
22
+ work them, and say in the workspace's privacy notice that those messages are kept and read by
23
+ staff. Telegram already records every message it receives; Slack, email and the web chat do not
24
+ take the setting.
25
+
26
+ Pins @segmentstream/ontology 0.151.0.
27
+
28
+ ## 0.75.0
29
+
30
+ An email channel can record its whole mailbox in the workspace chat store, beside the mail the agent
31
+ takes: `"record": "all"` in its settings, `"agent"` (the mail the agent takes) by default.
32
+
33
+ - Every message the mailbox receives joins its sender's chat in its thread, but drafts, spam and
34
+ trash, which are never recorded. Mail the agent takes is recorded with its turn, as before; the
35
+ rest starts no turn and is `skipped` with the reason the agent did not take it: `not_addressed`
36
+ for mail the channel's `query` does not find, `bulk`, `automated` or `bounce`, `identity_unknown`
37
+ for a sender the ontology admits no one for, `refused` and `limited`. Recording admits, signs up
38
+ and answers no one.
39
+ - `recordQuery`, a Gmail search allowed with `"record": "all"` only, narrows what is recorded
40
+ beyond the mail the agent takes.
41
+ - Mail that failed DMARC is recorded `skipped` with the reason `unverified`, as no one's. The
42
+ agent's reads of a chat never return a message skipped as `unverified`, so it reaches no session's
43
+ context and no reply's review.
44
+
45
+ An agent whose ontology keeps no chat store records what it always did, and so does an email
46
+ channel without `record`.
47
+
3
48
  ## 0.74.0
4
49
 
5
50
  A chat keeps what providers report of its messages beside new ones, on an agent whose ontology
package/README.md CHANGED
@@ -132,6 +132,7 @@ See [Sandbox](#sandbox).
132
132
  | `channels.<name>.kind` | the name | A channel not named after its kind, such as `sales_whatsapp`, says its kind and takes that kind's settings: several bots, numbers, apps or mailboxes on one agent; see `docs/agent.md`, "Channels by name" |
133
133
  | `channels.<name>.receive` | `"webhook"` | A workspace channel (`kind: "custom"`, defined with `defineChannel`): `webhook`, its provider calls it, or `poll`, the platform wakes it every `checkAfterMinutes`; see `docs/agent.md`, "Workspace channels" |
134
134
  | `channels.<name>.secret` | none | A workspace channel's workspace secret, which its `verify` checks deliveries against with `signedWith` or `matches`; only the platform reads it |
135
+ | `channels.<name>.record` | `"agent"` | A WhatsApp or workspace channel: `"all"` keeps every message it receives in its chats, those of people the agent does not admit among them, without a member; see `docs/agent.md`, "Recording every message" |
135
136
  | `models.stt` | `"spacexai/grok-stt"` | The AI Gateway transcription model for voice messages; `false` leaves them untranscribed |
136
137
  | `models.imageDescription` | `google/gemini-2.5-flash-lite` | Image evidence for group routing even with native vision; `false` disables descriptions |
137
138
  | `models.decision` | `"typesafe-ai/jev-1.14.0"` | The AI Gateway decision model of the inbound router |
@@ -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.74.0";
7
+ var version = "0.76.0";
8
8
  function agentBuild(environment = process.env) {
9
9
  return {
10
10
  agent: version,
@@ -7,9 +7,9 @@ __eveCreateRequire(import.meta.url);
7
7
  import { parseArchivedMessage } from "../extension/lib/telegram/archive-message.mjs";
8
8
  import { currentChannel, currentKey } from "../extension/lib/channel-scope.mjs";
9
9
  import { n as contentText, t as CONTENT_CAPS } from "./content-cDtVnr8Y.mjs";
10
- import { S as storedFiles, a as chatEvent, b as reasonCode, d as sessionFailureEventId, f as storeOf, g as cutText, h as boundedMeta, v as messageInput, x as sendFingerprint, y as metaOf } from "./chat-archive-BgxTGPKZ.mjs";
10
+ import { C as storedFiles, S as sendFingerprint, _ as cutText, a as chatEvent, b as metaOf, d as sessionFailureEventId, f as storeOf, g as boundedMeta, x as reasonCode, y as messageInput } from "./chat-archive-CDk-FPLX.mjs";
11
11
  import { ChatStoreError } from "../extension/lib/chat-store.mjs";
12
- import { c as currentInboundRequest, ht as currentThreadId, xt as reportTelegramError } from "./principal-Zf42Yf4r.mjs";
12
+ import { c as currentInboundRequest, ht as currentThreadId, xt as reportTelegramError } from "./principal-C7aAjyt4.mjs";
13
13
  import { currentConfirmationPrompt } from "../extension/lib/group-routing/messages.mjs";
14
14
  import { messageMetadata } from "../extension/lib/telegram/message-metadata.mjs";
15
15
  import { reportMembership } from "../extension/lib/telegram/membership.mjs";
@@ -198,6 +198,10 @@ function eventOf(row) {
198
198
  };
199
199
  }
200
200
  const CONTEXT_PAGES = 5;
201
+ const UNVERIFIED = "unverified";
202
+ function unverified(row) {
203
+ return row.direction === "inbound" && (object(row.meta)?.["unverified"] === true || row.disposition === "skipped" && row.reason === "unverified");
204
+ }
201
205
  function shown(row) {
202
206
  return row.direction === "inbound" || row.direction === "outbound" && (row.status === null || [
203
207
  "sent",
@@ -292,7 +296,7 @@ function workspaceChatArchive(store) {
292
296
  break;
293
297
  }
294
298
  examined = row;
295
- if (row.direction !== "internal" && (includeDecisions === true || shown(row)) && (search.senderId === void 0 || row.senderId === search.senderId) && (from === void 0 || Date.parse(row.at) >= from)) kept.push(row);
299
+ if (row.direction !== "internal" && !unverified(row) && (includeDecisions === true || shown(row)) && (search.senderId === void 0 || row.senderId === search.senderId) && (from === void 0 || Date.parse(row.at) >= from)) kept.push(row);
296
300
  }
297
301
  more = rest || read.nextCursor !== null;
298
302
  before = read.nextCursor ?? void 0;
@@ -311,7 +315,7 @@ function workspaceChatArchive(store) {
311
315
  limit: Math.min(limit ?? 100, 200)
312
316
  }, signal);
313
317
  return {
314
- events: page.messages.filter((row) => row.direction !== "internal" && (row.replacedBy ?? null) === null).map(eventOf),
318
+ events: page.messages.filter((row) => row.direction !== "internal" && !unverified(row) && (row.replacedBy ?? null) === null).map(eventOf),
315
319
  nextCursor: page.nextCursor
316
320
  };
317
321
  },
@@ -585,4 +589,4 @@ function summarizeArguments(value) {
585
589
  };
586
590
  return JSON.stringify(workflowValue(visit(value, 0), { boundary: "chat arguments" })).slice(0, 4e3);
587
591
  }
588
- export { storedMessageId as C, storedFiles as S, eventOf as _, chatEvent as a, reasonCode as b, forgetChatStores as c, sessionFailureEventId as d, storeOf as f, cutText as g, boundedMeta as h, chatAuthor as i, replyEvent as l, topicContext as m, archiveSequence as n, cloudChatArchive as o, summarizeArguments as p, chatArchive as r, collapseChatEvents as s, AGENT_SENDER as t, replyOperation as u, messageInput as v, workspaceChatArchive as w, sendFingerprint as x, metaOf as y };
592
+ export { storedFiles as C, sendFingerprint as S, workspaceChatArchive as T, cutText as _, chatEvent as a, metaOf as b, forgetChatStores as c, sessionFailureEventId as d, storeOf as f, boundedMeta as g, UNVERIFIED as h, chatAuthor as i, replyEvent as l, topicContext as m, archiveSequence as n, cloudChatArchive as o, summarizeArguments as p, chatArchive as r, collapseChatEvents as s, AGENT_SENDER as t, replyOperation as u, eventOf as v, storedMessageId as w, reasonCode as x, messageInput as y };
@@ -286,6 +286,8 @@ export interface TelegramChannelInput {
286
286
  export interface WhatsAppChannelInput {
287
287
  /** The key of the workspace's `WhatsAppConnection`, such as `whatsapp`. */
288
288
  readonly connection: string;
289
+ /** Which messages the channel records: {@link RecordSetting}. */
290
+ readonly record?: RecordSetting;
289
291
  }
290
292
  /** `channels.slack`, or a channel of kind `slack`, as authored. */
291
293
  export interface SlackChannelInput {
@@ -308,6 +310,14 @@ export interface EmailChannelInput {
308
310
  readonly push?: {
309
311
  readonly topic: string;
310
312
  };
313
+ /**
314
+ * What the workspace chat store keeps of the mailbox: `agent`, the mail the agent takes, when
315
+ * absent; or `all`, every message it receives but drafts, spam and trash, with what the agent did
316
+ * with each.
317
+ */
318
+ readonly record?: "agent" | "all";
319
+ /** With `record: "all"`, which of that mail is recorded, as Gmail's search; all of it when absent. */
320
+ readonly recordQuery?: string;
311
321
  }
312
322
  /**
313
323
  * A channel the workspace defines in its own code, `defineChannel` in `agent/agent/channels/`,
@@ -336,7 +346,16 @@ export interface WorkspaceChannelInput {
336
346
  * @deprecated Name a verification value of the channel's connection with `input`.
337
347
  */
338
348
  readonly secret?: string;
349
+ /** Which messages the channel records: {@link RecordSetting}. */
350
+ readonly record?: RecordSetting;
339
351
  }
352
+ /**
353
+ * Which messages a WhatsApp or workspace channel records in the chat: `agent`, the default, those
354
+ * the agent takes, as every channel does; `all`, every message it receives, the messages of people
355
+ * the agent does not admit among them, recorded without a member and `skipped` with a reason code.
356
+ * Under `all` no turn starts that would not start under `agent`, and nobody becomes a user.
357
+ */
358
+ export type RecordSetting = "agent" | "all";
340
359
  /** A channel named other than its kind, as authored: its settings and its `kind`. */
341
360
  export type NamedChannelInput = ({
342
361
  readonly kind: "telegram";
@@ -571,6 +590,8 @@ export declare class SegmentStreamAgentConfigError extends Error {
571
590
  */
572
591
  export interface WhatsAppSettings {
573
592
  readonly connection: string;
593
+ /** `all` when the channel records every message it receives; absent records the agent's. */
594
+ readonly record?: "all";
574
595
  }
575
596
  /**
576
597
  * The Slack channel: the bot of the workspace's `SlackConnection`, through the Slack app
@@ -603,6 +624,10 @@ export interface EmailSettings {
603
624
  readonly push: {
604
625
  readonly topic: string;
605
626
  } | null;
627
+ /** `all` records every message the mailbox receives; absent, only the mail the agent takes. */
628
+ readonly record?: "agent" | "all";
629
+ /** With `record: "all"`, the Gmail search that narrows what is recorded. */
630
+ readonly recordQuery?: string;
606
631
  }
607
632
  /**
608
633
  * A channel the workspace defines in its own code (`defineChannel`): the connection its code calls
@@ -621,6 +646,8 @@ export interface WorkspaceChannelSettings {
621
646
  readonly input?: string;
622
647
  /** The workspace secret they are checked against: the older form of `input`. */
623
648
  readonly secret?: string;
649
+ /** `all` when the channel records every message it receives; absent records the agent's. */
650
+ readonly record?: "all";
624
651
  }
625
652
  /**
626
653
  * The web the agent may read. `domains` are bare lower-case host names, such as `example.com`;
@@ -193,14 +193,27 @@ function section(input) {
193
193
  function isTelegramPolicy(value) {
194
194
  return TELEGRAM_POLICIES.some((policy) => policy === value);
195
195
  }
196
+ function recordSetting(value, path, issues) {
197
+ if (value === void 0 || value === "agent") return {};
198
+ if (value === "all") return { record: "all" };
199
+ issues.push({
200
+ message: "must be \"agent\" or \"all\"",
201
+ path: [...path, "record"]
202
+ });
203
+ }
196
204
  function whatsappSettings(value, issues, path = ["channels", "whatsapp"]) {
197
205
  const whatsapp = section({
198
206
  value,
199
207
  path,
200
- allowed: ["connection", "kind"],
208
+ allowed: [
209
+ "connection",
210
+ "kind",
211
+ "record"
212
+ ],
201
213
  issues
202
214
  });
203
215
  if (whatsapp === void 0) return null;
216
+ const record = recordSetting(whatsapp.record, path, issues);
204
217
  if (typeof whatsapp.connection !== "string" || !CONNECTION_KEY.test(whatsapp.connection)) {
205
218
  issues.push({
206
219
  message: "must be a connection key such as whatsapp",
@@ -208,7 +221,10 @@ function whatsappSettings(value, issues, path = ["channels", "whatsapp"]) {
208
221
  });
209
222
  return null;
210
223
  }
211
- return { connection: whatsapp.connection };
224
+ return record === void 0 ? null : {
225
+ connection: whatsapp.connection,
226
+ ...record
227
+ };
212
228
  }
213
229
  function slackSettings(value, issues, path = ["channels", "slack"]) {
214
230
  const slack = section({
@@ -254,12 +270,14 @@ function workspaceChannelSettings(value, issues, path) {
254
270
  "receive",
255
271
  "checkAfterMinutes",
256
272
  "input",
257
- "secret"
273
+ "secret",
274
+ "record"
258
275
  ],
259
276
  issues
260
277
  });
261
278
  if (channel === void 0) return null;
262
279
  const before = issues.length;
280
+ const record = recordSetting(channel.record, path, issues);
263
281
  if (typeof channel.connection !== "string" || !CONNECTION_KEY.test(channel.connection)) issues.push({
264
282
  message: "must be the key of the connection the channel's code calls its provider through",
265
283
  path: [...path, "connection"]
@@ -296,11 +314,13 @@ function workspaceChannelSettings(value, issues, path) {
296
314
  connection: channel.connection,
297
315
  receive,
298
316
  checkAfterMinutes: minutes,
299
- ...secret
317
+ ...secret,
318
+ ...record
300
319
  } : {
301
320
  connection: channel.connection,
302
321
  receive: "webhook",
303
- ...secret
322
+ ...secret,
323
+ ...record
304
324
  };
305
325
  }
306
326
  const MAXIMUM_WEB_DOMAINS = 50;
@@ -401,7 +421,9 @@ function emailSettings(value, issues, path = ["channels", "email"]) {
401
421
  "kind",
402
422
  "query",
403
423
  "checkAfterMinutes",
404
- "push"
424
+ "push",
425
+ "record",
426
+ "recordQuery"
405
427
  ],
406
428
  issues
407
429
  });
@@ -435,12 +457,29 @@ function emailSettings(value, issues, path = ["channels", "email"]) {
435
457
  "topic"
436
458
  ]
437
459
  });
460
+ const record = email.record ?? "agent";
461
+ if (record !== "agent" && record !== "all") issues.push({
462
+ message: "must be \"agent\" or \"all\"",
463
+ path: [...path, "record"]
464
+ });
465
+ if (email.recordQuery !== void 0 && record !== "all") issues.push({
466
+ message: "applies only with record \"all\"",
467
+ path: [...path, "recordQuery"]
468
+ });
469
+ else if (email.recordQuery !== void 0 && (typeof email.recordQuery !== "string" || email.recordQuery.trim() === "" || email.recordQuery.length > 1e3)) issues.push({
470
+ message: "must be a Gmail search of at most 1000 characters",
471
+ path: [...path, "recordQuery"]
472
+ });
438
473
  if (issues.length > before) return null;
439
474
  return {
440
475
  connection: email.connection,
441
476
  query: query.trim(),
442
477
  checkAfterMinutes: minutes,
443
- push: push === void 0 ? null : { topic: push.topic }
478
+ push: push === void 0 ? null : { topic: push.topic },
479
+ ...record === "all" ? {
480
+ record: "all",
481
+ ...email.recordQuery === void 0 ? {} : { recordQuery: email.recordQuery.trim() }
482
+ } : {}
444
483
  };
445
484
  }
446
485
  function telegramSettings(value, issues, path = ["channels", "telegram"]) {
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import segmentstream from "../extension.mjs";
8
- import { T as ontologyConnection } from "../../_chunks/principal-Zf42Yf4r.mjs";
8
+ import { T as ontologyConnection } from "../../_chunks/principal-C7aAjyt4.mjs";
9
9
  import { defineDynamic } from "eve/connections";
10
10
  var ontology_default = defineDynamic(async (context) => {
11
11
  if (!segmentstream.config.ontology.connection) return null;
@@ -25,7 +25,7 @@ export default segmentstream;
25
25
  * runtime's own definition, offered here so that the agent's files import only this package.
26
26
  */
27
27
  export { defineAgent } from "eve";
28
- export { DEFAULT_DECISION_MODEL, DEFAULT_STT_MODEL, DEFAULT_ADMISSION_LIMITS, SegmentStreamAgentConfigError, manifestOf, type ChatModelChoice, type AdmissionLimits, type AdmissionLimitsInput, type AdmissionSettings, type AdmissionReplies, type FirstContactSettings, type LocalizedText, type SegmentStreamAgentConfig, type SegmentStreamAgentConfigInput, type SessionScope, type SessionSettings, type TelegramPolicy, type TelegramSettings, type WebSettings, type BrowserSettings, type BrowserSettingsInput, type BrowserProxySettings, type WorkspaceChannelInput, type WorkspaceChannelSettings, } from "./config.js";
28
+ export { DEFAULT_DECISION_MODEL, DEFAULT_STT_MODEL, DEFAULT_ADMISSION_LIMITS, SegmentStreamAgentConfigError, manifestOf, type ChatModelChoice, type AdmissionLimits, type AdmissionLimitsInput, type AdmissionSettings, type AdmissionReplies, type FirstContactSettings, type LocalizedText, type RecordSetting, type SegmentStreamAgentConfig, type SegmentStreamAgentConfigInput, type SessionScope, type SessionSettings, type TelegramPolicy, type TelegramSettings, type WebSettings, type BrowserSettings, type BrowserSettingsInput, type BrowserProxySettings, type WorkspaceChannelInput, type WorkspaceChannelSettings, } from "./config.js";
29
29
  /**
30
30
  * Defines a channel in the workspace's own code, `agent/agent/channels/<name>.ts`, for a provider
31
31
  * the platform has no channel for: the code receives, reads and sends, the platform does the rest.
@@ -7,7 +7,7 @@ __eveCreateRequire(import.meta.url);
7
7
  import segmentstream from "../extension.mjs";
8
8
  import { localizedText } from "../lib/admission.mjs";
9
9
  import { confirmationLocale } from "../lib/telegram/confirmation-text.mjs";
10
- import "../../_chunks/principal-Zf42Yf4r.mjs";
10
+ import "../../_chunks/principal-C7aAjyt4.mjs";
11
11
  import { defineHook } from "eve/hooks";
12
12
  var authorization_default = defineHook({ events: { "interaction.opened": (event, context) => {
13
13
  const principal = context.session.auth.current;
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import segmentstream from "../extension.mjs";
8
- import { r as chatArchive } from "../../_chunks/chat-archive-BgxTGPKZ.mjs";
8
+ import { r as chatArchive } from "../../_chunks/chat-archive-CDk-FPLX.mjs";
9
9
  import { chatContextHook } from "../lib/chat-context.mjs";
10
10
  import { appOrigin } from "../lib/environment.mjs";
11
11
  import { agentSessionReviews } from "../lib/review/client.mjs";
@@ -6,7 +6,7 @@ __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import segmentstream from "../extension.mjs";
8
8
  import { chatRecorder } from "../lib/chat-recorder.mjs";
9
- import { r as chatArchive } from "../../_chunks/chat-archive-BgxTGPKZ.mjs";
9
+ import { r as chatArchive } from "../../_chunks/chat-archive-CDk-FPLX.mjs";
10
10
  import { repliesReviewed } from "../lib/review/hold.mjs";
11
11
  import { defineHook } from "eve/hooks";
12
12
  var chat_recorder_default = defineHook({ events: { "*": chatRecorder(chatArchive(), (principal) => repliesReviewed(segmentstream.config.review, principal)) } });
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import segmentstream from "../extension.mjs";
8
- import { a as rolesOf } from "../../_chunks/principal-Zf42Yf4r.mjs";
8
+ import { a as rolesOf } from "../../_chunks/principal-C7aAjyt4.mjs";
9
9
  import { personaFor } from "../personas.mjs";
10
10
  import { defineDynamic, defineInstructions } from "eve/instructions";
11
11
  var persona_default = defineDynamic((context) => {
@@ -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 { R as ACT_AS_HEADER, z as ActorRequiredError, B as actorHeaders, V as actorKey, H as actorOf, U as isGuestSession, W as member, G as memberTool, K as notForGuests } from "../../_chunks/principal-Zf42Yf4r.mjs";
7
+ export { R as ACT_AS_HEADER, z as ActorRequiredError, B as actorHeaders, V as actorKey, H as actorOf, U as isGuestSession, W as member, G as memberTool, K as notForGuests } from "../../_chunks/principal-C7aAjyt4.mjs";
@@ -1,5 +1,5 @@
1
- import type { AdmissionSettings, LocalizedText } from "../config.js";
2
- import type { AgentIdentities, IdentityResolution, ResolveIdentityInput } from "./identities.js";
1
+ import type { AdmissionSettings, LocalizedText, RecordSetting } from "../config.js";
2
+ import { type AgentIdentities, type IdentityResolution, type ResolveIdentityInput } from "./identities.js";
3
3
  /** Sender language, then English, then the first configured entry. No platform copy. */
4
4
  export declare function localizedText(texts: LocalizedText | undefined, languageCode?: string): string | undefined;
5
5
  /** The private chat a message arrived in, as the chat archive keys it. */
@@ -14,7 +14,10 @@ export interface AdmittedChat {
14
14
  /**
15
15
  * Channel-independent admission and at-least-once versioned notice delivery. A private chat a
16
16
  * member of staff took over comes back `handled`: the channel records the message with
17
- * `recordHandledMessage`, or as it records every message, and starts no turn.
17
+ * `recordHandledMessage`, or as it records every message, and starts no turn. On a channel that
18
+ * records every message (`record: "all"`), the private chat of someone who is no user is reported
19
+ * without a member, so that the inbox registers it where the ontology's `inbox.channels` lists the
20
+ * channel; admission itself is the same, and makes nobody a user it would not make one.
18
21
  */
19
22
  export declare function admitMessage(input: {
20
23
  readonly identity: ResolveIdentityInput;
@@ -27,4 +30,6 @@ export declare function admitMessage(input: {
27
30
  readonly chat?: AdmittedChat;
28
31
  /** A failed inbox report; by default it is logged. */
29
32
  readonly inboxFailed?: (error: unknown) => void;
33
+ /** Which messages the channel records; `agent` by default. */
34
+ readonly record?: RecordSetting;
30
35
  }): Promise<IdentityResolution>;
@@ -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 { AgentIdentityError } from "./identities.mjs";
7
8
  import { createHash } from "node:crypto";
8
9
  function localizedText(texts, languageCode) {
9
10
  if (texts === void 0) return;
@@ -28,7 +29,7 @@ const INBOX_REPORTS_REMEMBERED = 1e3;
28
29
  const inboxReports = new Map();
29
30
  async function reportInboxChat(input) {
30
31
  const { chat, identity } = input;
31
- const key = `${chat.channel}:${chat.chatId}`;
32
+ const key = `${chat.channel}:${chat.chatId}:${input.memberId ?? ""}`;
32
33
  const now = Date.now();
33
34
  const last = inboxReports.get(key);
34
35
  if (!input.every && last !== void 0 && now - last < INBOX_REPORT_INTERVAL_MS) return;
@@ -43,17 +44,21 @@ async function reportInboxChat(input) {
43
44
  provider: chat.channel,
44
45
  externalId: chat.chatId,
45
46
  title: (identity.display?.trim() || identity.externalId).slice(0, 200),
46
- memberId: input.memberId,
47
+ ...input.memberId === void 0 ? {} : { memberId: input.memberId },
47
48
  kind: "private",
48
49
  ...chat.recipient === void 0 || chat.recipient === chat.chatId ? {} : { recipient: chat.recipient },
49
50
  ...chat.threadId === void 0 || chat.threadId === "" ? {} : { threadId: chat.threadId }
50
51
  });
51
52
  } catch (error) {
53
+ if (input.memberId === void 0 && error instanceof AgentIdentityError && error.status === 404) return;
52
54
  inboxReports.delete(key);
53
55
  input.failed?.(error);
54
56
  return;
55
57
  }
56
58
  }
59
+ function noUser(resolution) {
60
+ return resolution.status === "pairing_required" || resolution.status === "limited" && resolution.scope === "newUsersPerHour";
61
+ }
57
62
  async function admitMessage(input) {
58
63
  const firstContact = input.settings.firstContact;
59
64
  const notice = localizedText(firstContact?.notice, input.languageCode);
@@ -91,6 +96,13 @@ async function admitMessage(input) {
91
96
  handled: true
92
97
  };
93
98
  }
99
+ if (input.record === "all" && noUser(resolved) && input.identity.chat === "private" && input.chat !== void 0) await reportInboxChat({
100
+ identity: input.identity,
101
+ identities: input.identities,
102
+ chat: input.chat,
103
+ every: false,
104
+ failed: input.inboxFailed ?? ((error) => console.error("[segmentstream] inbox chat report failed", error))
105
+ });
94
106
  return resolved;
95
107
  }
96
108
  export { admitMessage, localizedText };
@@ -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 { Ft as chatChannel, Pt as chatAddressOf, b as agentAttachments, i as memberIdOf } from "../../_chunks/principal-Zf42Yf4r.mjs";
7
+ import { Ft as chatChannel, Pt as chatAddressOf, b as agentAttachments, i as memberIdOf } from "../../_chunks/principal-C7aAjyt4.mjs";
8
8
  import { detectFile, documentText } from "./attachment-formats.mjs";
9
9
  import { readSheets, typedTable } from "./attachment-tables.mjs";
10
10
  import { appOrigin } from "./environment.mjs";
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { attachmentOwner } from "./attachment-tools.mjs";
8
- import { Pt as chatAddressOf, _ as AttachmentError, yt as failureText } from "../../_chunks/principal-Zf42Yf4r.mjs";
8
+ import { Pt as chatAddressOf, _ as AttachmentError, yt as failureText } from "../../_chunks/principal-C7aAjyt4.mjs";
9
9
  import { appOrigin, channelsEnabled } from "./environment.mjs";
10
10
  import { transientFileStatus } from "./file-grant.mjs";
11
11
  import { runtimeToken } from "./runtime-token.mjs";
@@ -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 { h as ATTACHMENT_TTL_HOURS, g as ATTACHMENT_URL_PROTOCOL, _ as AttachmentError, jt as CHAT_HEADER, v as EARLIER_CHAT_HEADER, y as MAXIMUM_ATTACHMENT_BYTES, Nt as SESSION_HEADER, b as agentAttachments, x as attachmentUrl, S as fetchStoredAttachment, C as parseAttachmentUrl } from "../../_chunks/principal-Zf42Yf4r.mjs";
7
+ export { h as ATTACHMENT_TTL_HOURS, g as ATTACHMENT_URL_PROTOCOL, _ as AttachmentError, jt as CHAT_HEADER, v as EARLIER_CHAT_HEADER, y as MAXIMUM_ATTACHMENT_BYTES, Nt as SESSION_HEADER, b as agentAttachments, x as attachmentUrl, S as fetchStoredAttachment, C as parseAttachmentUrl } from "../../_chunks/principal-C7aAjyt4.mjs";
@@ -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-Cq9R60V5.mjs";
7
+ export { t as agentBuild } from "../../_chunks/build-metadata-DIf8SOej.mjs";
@@ -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 { At as CHAT_ATTRIBUTE, jt as CHAT_HEADER, Mt as RUNTIME_SOURCE_ATTRIBUTE, Nt as SESSION_HEADER, Pt as chatAddressOf, Ft as chatChannel, It as chatHeaders, Lt as chatRuntimeSource, Rt as isSameChat, zt as withChatAddress, Bt as workspaceIdentityProvider } from "../../_chunks/principal-Zf42Yf4r.mjs";
7
+ export { At as CHAT_ATTRIBUTE, jt as CHAT_HEADER, Mt as RUNTIME_SOURCE_ATTRIBUTE, Nt as SESSION_HEADER, Pt as chatAddressOf, Ft as chatChannel, It as chatHeaders, Lt as chatRuntimeSource, Rt as isSameChat, zt as withChatAddress, Bt as workspaceIdentityProvider } from "../../_chunks/principal-C7aAjyt4.mjs";
@@ -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 AGENT_SENDER, n as archiveSequence, r as chatArchive, i as chatAuthor, a as chatEvent, o as cloudChatArchive, s as collapseChatEvents, c as forgetChatStores, l as replyEvent, u as replyOperation, d as sessionFailureEventId, f as storeOf, p as summarizeArguments, m as topicContext } from "../../_chunks/chat-archive-BgxTGPKZ.mjs";
7
+ export { t as AGENT_SENDER, n as archiveSequence, r as chatArchive, i as chatAuthor, a as chatEvent, o as cloudChatArchive, s as collapseChatEvents, c as forgetChatStores, l as replyEvent, u as replyOperation, d as sessionFailureEventId, f as storeOf, p as summarizeArguments, m as topicContext } from "../../_chunks/chat-archive-CDk-FPLX.mjs";
@@ -6,8 +6,8 @@ __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { agentTaskIdOf } from "./agent-task.mjs";
8
8
  import { chatCoordinates, sessionKind } from "./chat-recorder.mjs";
9
- import { f as storeOf, i as chatAuthor, m as topicContext, n as archiveSequence, r as chatArchive, s as collapseChatEvents } from "../../_chunks/chat-archive-BgxTGPKZ.mjs";
10
- import { xt as reportTelegramError } from "../../_chunks/principal-Zf42Yf4r.mjs";
9
+ import { f as storeOf, i as chatAuthor, m as topicContext, n as archiveSequence, r as chatArchive, s as collapseChatEvents } from "../../_chunks/chat-archive-CDk-FPLX.mjs";
10
+ import { xt as reportTelegramError } from "../../_chunks/principal-C7aAjyt4.mjs";
11
11
  import { createHash } from "node:crypto";
12
12
  import { deliveries, runs, turns } from "eve/events";
13
13
  import { defineState } from "eve/context";
@@ -1,3 +1,4 @@
1
+ import type { RecordSetting } from "../config.js";
1
2
  import type { AdmittedChat } from "./admission.js";
2
3
  import { type ChatArchive, type ChatAuthor } from "./chat-archive.js";
3
4
  import type { ChatPart, StoredFile } from "./chat-store.js";
@@ -132,6 +133,12 @@ export interface RecordedMessage {
132
133
  readonly chatType?: "private" | "group";
133
134
  /** When the message was written, if not now. */
134
135
  readonly at?: string;
136
+ /**
137
+ * A person's message nothing proved the sender of, such as mail that failed DMARC: marked so in
138
+ * the same write that records it, so the agent's reads of the chat never return it, even before
139
+ * what the channel did with it is recorded. Only the workspace chat store keeps the mark.
140
+ */
141
+ readonly unverified?: boolean;
135
142
  }
136
143
  /** Records one message that starts no turn; true for its first record. */
137
144
  export declare function recordChatMessage(archive: ChatArchive, message: RecordedMessage): Promise<boolean | void>;
@@ -143,21 +150,54 @@ export type SentOutsideOutcome =
143
150
  | "no_chat"
144
151
  /** The archive holds the message already, such as the agent's own reply a provider echoes. */
145
152
  | "known";
153
+ /** How a channel records a message outside a turn: its `record` setting, `agent` by default. */
154
+ export interface RecordOptions {
155
+ readonly record?: RecordSetting;
156
+ }
146
157
  /**
147
158
  * Records what the workspace's side wrote in a person's chat outside the agent, such as a reply
148
159
  * from the provider's own app: an `outbound` message of a human, or of a program when the provider
149
160
  * says so, which starts no turn. Only a chat the agent already has with the person is recorded, its
150
161
  * members those of its latest message, so a number's or a mailbox's other conversations stay out of
151
- * the archive. A message the archive holds by its provider id is skipped.
162
+ * the archive. On a channel that records every message (`record: "all"`), a chat the agent has
163
+ * none of is recorded too, without members, in the workspace chat store. A message the archive
164
+ * holds by its provider id is skipped.
152
165
  */
153
- export declare function recordSentOutside(archive: ChatArchive, message: Omit<RecordedMessage, "participantIds" | "direction">): Promise<SentOutsideOutcome>;
166
+ export declare function recordSentOutside(archive: ChatArchive, message: Omit<RecordedMessage, "participantIds" | "direction">, options?: RecordOptions): Promise<SentOutsideOutcome>;
154
167
  /**
155
168
  * Records a person's message the agent cannot read, such as a contact card on a channel that
156
169
  * reads only text and files, in the chat the agent has with them, by the same rule as
157
170
  * {@link recordSentOutside}, with `reason` as what the agent did with it: it starts no turn. Only
158
171
  * the workspace chat store keeps it; nothing is written to the chat archive in Cloud.
159
172
  */
160
- export declare function recordUnreadMessage(archive: ChatArchive, message: Omit<RecordedMessage, "participantIds" | "direction" | "by">, reason: string): Promise<SentOutsideOutcome | "dropped">;
173
+ export declare function recordUnreadMessage(archive: ChatArchive, message: Omit<RecordedMessage, "participantIds" | "direction" | "by">, reason: string, options?: RecordOptions): Promise<SentOutsideOutcome | "dropped">;
174
+ /** Why the agent took no turn for a message whose sender it did not admit, as a code. */
175
+ export type UnadmittedReason = "identity_unknown" | "identity_refused" | "limited";
176
+ /**
177
+ * A person's message on a channel that records every message (`record: "all"`), whose sender the
178
+ * agent did not admit: someone who is no user, a refused account, or one over a limit.
179
+ */
180
+ export interface UnadmittedMessage {
181
+ readonly channel: string;
182
+ readonly chatId: string;
183
+ /** The person's account at the provider. */
184
+ readonly senderId: string;
185
+ readonly senderName?: string | null;
186
+ readonly messageId: string;
187
+ readonly text: string;
188
+ /** Its files, by what the provider says of them: nothing of them is stored. */
189
+ readonly files?: ReadonlyArray<RecordedFile>;
190
+ readonly replyTo?: string;
191
+ readonly parts?: ReadonlyArray<ChatPart>;
192
+ readonly at?: string;
193
+ }
194
+ /**
195
+ * Records the message of a sender the agent did not admit, on a channel that records every
196
+ * message, in the workspace chat store: by its provider id, with no member, so that only staff
197
+ * whose `agent_chat:read` holds the chat read it, and `skipped` with `reason`. It starts no turn
198
+ * and makes nobody a user. True when recorded; nothing is recorded on the chat archive in Cloud.
199
+ */
200
+ export declare function recordUnadmittedMessage(archive: ChatArchive, message: UnadmittedMessage, reason: UnadmittedReason): Promise<boolean>;
161
201
  /**
162
202
  * Records a person's message in a private chat a member of the workspace took over, which starts
163
203
  * no turn: the inbox shows it, and the agent reads it in its context once the chat is handed back.