@segmentstream/agent 0.75.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 (87) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +1 -0
  3. package/dist/_chunks/{build-metadata-CLenocka.mjs → build-metadata-DIf8SOej.mjs} +1 -1
  4. package/dist/_chunks/{chat-archive-DHYplDT5.mjs → chat-archive-BVngSwuB.mjs} +1 -1
  5. package/dist/extension/config.d.ts +15 -0
  6. package/dist/extension/config.mjs +25 -5
  7. package/dist/extension/connections/ontology.mjs +1 -1
  8. package/dist/extension/extension.d.ts +1 -1
  9. package/dist/extension/hooks/authorization.mjs +1 -1
  10. package/dist/extension/instructions/persona.mjs +1 -1
  11. package/dist/extension/lib/actor.mjs +1 -1
  12. package/dist/extension/lib/admission.d.ts +8 -3
  13. package/dist/extension/lib/admission.mjs +14 -2
  14. package/dist/extension/lib/attachment-tools.mjs +1 -1
  15. package/dist/extension/lib/attachments-send.mjs +1 -1
  16. package/dist/extension/lib/attachments.mjs +1 -1
  17. package/dist/extension/lib/build-metadata.mjs +1 -1
  18. package/dist/extension/lib/chat-address.mjs +1 -1
  19. package/dist/extension/lib/chat-context.mjs +1 -1
  20. package/dist/extension/lib/chat-messages.d.ts +37 -3
  21. package/dist/extension/lib/chat-messages.mjs +45 -7
  22. package/dist/extension/lib/chat-recorder.mjs +1 -1
  23. package/dist/extension/lib/confirmations.mjs +1 -1
  24. package/dist/extension/lib/email/attachments-send.mjs +1 -1
  25. package/dist/extension/lib/email/channel.mjs +1 -1
  26. package/dist/extension/lib/guest-usage.mjs +1 -1
  27. package/dist/extension/lib/inbound-media/files.mjs +1 -1
  28. package/dist/extension/lib/inbound-media/index.mjs +1 -1
  29. package/dist/extension/lib/ontology-connection.mjs +1 -1
  30. package/dist/extension/lib/ontology-file-call.mjs +1 -1
  31. package/dist/extension/lib/ontology-tools.mjs +1 -1
  32. package/dist/extension/lib/review/hold.mjs +1 -1
  33. package/dist/extension/lib/review/reply.mjs +1 -1
  34. package/dist/extension/lib/role-skill.mjs +1 -1
  35. package/dist/extension/lib/runtime-envelope.mjs +1 -1
  36. package/dist/extension/lib/sent-files.mjs +1 -1
  37. package/dist/extension/lib/slack/adapter.mjs +1 -1
  38. package/dist/extension/lib/slack/attachments-send.mjs +1 -1
  39. package/dist/extension/lib/slack/callbacks.mjs +1 -1
  40. package/dist/extension/lib/stored-files.mjs +1 -1
  41. package/dist/extension/lib/telegram/adapter.mjs +3 -3
  42. package/dist/extension/lib/telegram/attachment-description.mjs +1 -1
  43. package/dist/extension/lib/telegram/attachments-send.mjs +1 -1
  44. package/dist/extension/lib/telegram/callbacks.mjs +1 -1
  45. package/dist/extension/lib/telegram/chat-archive.mjs +1 -1
  46. package/dist/extension/lib/telegram/confirmations.mjs +1 -1
  47. package/dist/extension/lib/telegram/customer-text.mjs +1 -1
  48. package/dist/extension/lib/telegram/files.mjs +1 -1
  49. package/dist/extension/lib/telegram/health.mjs +1 -1
  50. package/dist/extension/lib/telegram/held-approvals.mjs +1 -1
  51. package/dist/extension/lib/telegram/inbound-request.mjs +1 -1
  52. package/dist/extension/lib/telegram/inbound.mjs +2 -2
  53. package/dist/extension/lib/telegram/lifecycle.mjs +2 -2
  54. package/dist/extension/lib/telegram/principal.mjs +1 -1
  55. package/dist/extension/lib/telegram/session-recovery.mjs +1 -1
  56. package/dist/extension/lib/telegram/silent.mjs +1 -1
  57. package/dist/extension/lib/telegram/store-capture.mjs +1 -1
  58. package/dist/extension/lib/telegram/structured.mjs +1 -1
  59. package/dist/extension/lib/telegram/turn-errors.mjs +2 -2
  60. package/dist/extension/lib/web/auth.mjs +1 -1
  61. package/dist/extension/lib/web/channel.mjs +1 -1
  62. package/dist/extension/lib/whatsapp/adapter.d.ts +6 -2
  63. package/dist/extension/lib/whatsapp/adapter.mjs +43 -9
  64. package/dist/extension/lib/whatsapp/attachments-send.mjs +1 -1
  65. package/dist/extension/lib/whatsapp/callbacks.mjs +1 -1
  66. package/dist/extension/lib/whatsapp/changes.d.ts +5 -4
  67. package/dist/extension/lib/whatsapp/changes.mjs +2 -2
  68. package/dist/extension/lib/whatsapp/echoes.d.ts +4 -3
  69. package/dist/extension/lib/whatsapp/echoes.mjs +2 -2
  70. package/dist/extension/lib/whatsapp/files.mjs +1 -1
  71. package/dist/extension/lib/workspace-action.mjs +1 -1
  72. package/dist/extension/lib/workspace-channel/attachments-send.mjs +1 -1
  73. package/dist/extension/lib/workspace-channel/channel.mjs +29 -15
  74. package/dist/extension/lib/workspace-source.mjs +1 -1
  75. package/dist/extension/model.mjs +1 -1
  76. package/dist/extension/tools/attachments_discard.mjs +1 -1
  77. package/dist/extension/tools/attachments_list.mjs +1 -1
  78. package/dist/extension/tools/attachments_promote.mjs +1 -1
  79. package/dist/extension/tools/attachments_read.mjs +1 -1
  80. package/dist/extension/tools/attachments_send.mjs +1 -1
  81. package/dist/extension/tools/attachments_stage.mjs +1 -1
  82. package/dist/extension/tools/attachments_table.mjs +1 -1
  83. package/dist/extension/tools/handoff.mjs +1 -1
  84. package/dist/extension/tools/questions_ask.mjs +1 -1
  85. package/dist/extension/tools/workspace_source.mjs +1 -1
  86. package/package.json +2 -2
  87. package/dist/_chunks/{principal-Zf42Yf4r.mjs → principal-C7aAjyt4.mjs} +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
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
+
3
28
  ## 0.75.0
4
29
 
5
30
  An email channel can record its whole mailbox in the workspace chat store, beside the mail the agent
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.75.0";
7
+ var version = "0.76.0";
8
8
  function agentBuild(environment = process.env) {
9
9
  return {
10
10
  agent: version,
@@ -9,7 +9,7 @@ import { currentChannel, currentKey } from "../extension/lib/channel-scope.mjs";
9
9
  import { n as contentText, t as CONTENT_CAPS } from "./content-cDtVnr8Y.mjs";
10
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";
@@ -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 {
@@ -344,7 +346,16 @@ export interface WorkspaceChannelInput {
344
346
  * @deprecated Name a verification value of the channel's connection with `input`.
345
347
  */
346
348
  readonly secret?: string;
349
+ /** Which messages the channel records: {@link RecordSetting}. */
350
+ readonly record?: RecordSetting;
347
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";
348
359
  /** A channel named other than its kind, as authored: its settings and its `kind`. */
349
360
  export type NamedChannelInput = ({
350
361
  readonly kind: "telegram";
@@ -579,6 +590,8 @@ export declare class SegmentStreamAgentConfigError extends Error {
579
590
  */
580
591
  export interface WhatsAppSettings {
581
592
  readonly connection: string;
593
+ /** `all` when the channel records every message it receives; absent records the agent's. */
594
+ readonly record?: "all";
582
595
  }
583
596
  /**
584
597
  * The Slack channel: the bot of the workspace's `SlackConnection`, through the Slack app
@@ -633,6 +646,8 @@ export interface WorkspaceChannelSettings {
633
646
  readonly input?: string;
634
647
  /** The workspace secret they are checked against: the older form of `input`. */
635
648
  readonly secret?: string;
649
+ /** `all` when the channel records every message it receives; absent records the agent's. */
650
+ readonly record?: "all";
636
651
  }
637
652
  /**
638
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;
@@ -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 { 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-CLenocka.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";
@@ -7,7 +7,7 @@ __eveCreateRequire(import.meta.url);
7
7
  import { agentTaskIdOf } from "./agent-task.mjs";
8
8
  import { chatCoordinates, sessionKind } from "./chat-recorder.mjs";
9
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-Zf42Yf4r.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";
@@ -149,21 +150,54 @@ export type SentOutsideOutcome =
149
150
  | "no_chat"
150
151
  /** The archive holds the message already, such as the agent's own reply a provider echoes. */
151
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
+ }
152
157
  /**
153
158
  * Records what the workspace's side wrote in a person's chat outside the agent, such as a reply
154
159
  * from the provider's own app: an `outbound` message of a human, or of a program when the provider
155
160
  * says so, which starts no turn. Only a chat the agent already has with the person is recorded, its
156
161
  * members those of its latest message, so a number's or a mailbox's other conversations stay out of
157
- * 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.
158
165
  */
159
- 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>;
160
167
  /**
161
168
  * Records a person's message the agent cannot read, such as a contact card on a channel that
162
169
  * reads only text and files, in the chat the agent has with them, by the same rule as
163
170
  * {@link recordSentOutside}, with `reason` as what the agent did with it: it starts no turn. Only
164
171
  * the workspace chat store keeps it; nothing is written to the chat archive in Cloud.
165
172
  */
166
- 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>;
167
201
  /**
168
202
  * Records a person's message in a private chat a member of the workspace took over, which starts
169
203
  * no turn: the inbox shows it, and the agent reads it in its context once the chat is handed back.
@@ -170,20 +170,20 @@ async function recordChatMessage(archive, message) {
170
170
  }))
171
171
  }));
172
172
  }
173
- async function recordSentOutside(archive, message) {
173
+ async function recordSentOutside(archive, message, options = {}) {
174
174
  return recordInChat(archive, {
175
175
  ...message,
176
176
  direction: "outbound"
177
- });
177
+ }, options);
178
178
  }
179
- async function recordUnreadMessage(archive, message, reason) {
179
+ async function recordUnreadMessage(archive, message, reason, options = {}) {
180
180
  const store = await storeOf(archive);
181
181
  if (store === void 0) return "dropped";
182
182
  const outcome = await recordInChat(archive, {
183
183
  ...message,
184
184
  direction: "inbound",
185
185
  by: "human"
186
- });
186
+ }, options);
187
187
  if (outcome === "recorded") await store.change({
188
188
  channel: message.provider,
189
189
  chatId: message.chatId,
@@ -194,7 +194,7 @@ async function recordUnreadMessage(archive, message, reason) {
194
194
  });
195
195
  return outcome;
196
196
  }
197
- async function recordInChat(archive, message) {
197
+ async function recordInChat(archive, message, options) {
198
198
  const chat = {
199
199
  provider: message.provider,
200
200
  chatId: message.chatId,
@@ -204,7 +204,14 @@ async function recordInChat(archive, message) {
204
204
  ...chat,
205
205
  limit: 1
206
206
  })).events;
207
- if (latest === void 0) return "no_chat";
207
+ if (latest === void 0) {
208
+ if (options.record !== "all" || await storeOf(archive) === void 0) return "no_chat";
209
+ await recordChatMessage(archive, {
210
+ ...message,
211
+ participantIds: []
212
+ });
213
+ return "recorded";
214
+ }
208
215
  const [known] = (await archive.context({
209
216
  ...chat,
210
217
  messageId: message.messageId,
@@ -217,6 +224,37 @@ async function recordInChat(archive, message) {
217
224
  });
218
225
  return "recorded";
219
226
  }
227
+ async function recordUnadmittedMessage(archive, message, reason) {
228
+ const store = await storeOf(archive);
229
+ if (store === void 0) return false;
230
+ const chatId = message.chatId.slice(0, 256);
231
+ const messageId = message.messageId.slice(0, 512);
232
+ await recordChatMessage(archive, {
233
+ provider: message.channel,
234
+ chatId,
235
+ participantIds: [],
236
+ eventId: `unadmitted:${message.channel}:${chatId}:${messageId}`,
237
+ direction: "inbound",
238
+ by: "human",
239
+ senderId: message.senderId,
240
+ senderName: message.senderName ?? null,
241
+ messageId,
242
+ text: message.text,
243
+ ...message.files === void 0 ? {} : { files: message.files },
244
+ ...message.replyTo === void 0 ? {} : { replyTo: message.replyTo },
245
+ ...message.parts === void 0 ? {} : { parts: message.parts },
246
+ ...message.at === void 0 ? {} : { at: message.at }
247
+ });
248
+ await store.change({
249
+ channel: message.channel,
250
+ chatId,
251
+ messageId,
252
+ change: "disposition",
253
+ disposition: "skipped",
254
+ reason
255
+ });
256
+ return true;
257
+ }
220
258
  async function recordHandledMessage(archive, input) {
221
259
  const { chat } = input;
222
260
  const eventId = `handled:${chat.channel}:${chat.chatId}:${input.messageId}`;
@@ -264,4 +302,4 @@ async function recordHandledMessage(archive, input) {
264
302
  status: "completed"
265
303
  }));
266
304
  }
267
- export { MAXIMUM_PARTS, applyChatChange, chatPart, chatParts, recordChatMessage, recordHandledMessage, recordReceivedMessage, recordSentOutside, recordUnreadMessage, stagedFiles };
305
+ export { MAXIMUM_PARTS, applyChatChange, chatPart, chatParts, recordChatMessage, recordHandledMessage, recordReceivedMessage, recordSentOutside, recordUnadmittedMessage, recordUnreadMessage, stagedFiles };
@@ -8,7 +8,7 @@ import { n as contentText, t as CONTENT_CAPS } from "../../_chunks/content-cDtVn
8
8
  import { a as chatEvent, d as sessionFailureEventId, f as storeOf, p as summarizeArguments, r as chatArchive } from "../../_chunks/chat-archive-CDk-FPLX.mjs";
9
9
  import { agentTaskIdOf } from "./agent-task.mjs";
10
10
  import { revisionOf } from "./review/revision.mjs";
11
- import { Ft as chatChannel, Pt as chatAddressOf, i as memberIdOf, ot as guestIdOf } from "../../_chunks/principal-Zf42Yf4r.mjs";
11
+ import { Ft as chatChannel, Pt as chatAddressOf, i as memberIdOf, ot as guestIdOf } from "../../_chunks/principal-C7aAjyt4.mjs";
12
12
  import { keyChannel, principalChannel } from "./channel-scope.mjs";
13
13
  import { parseAddress } from "./telegram/sessions.mjs";
14
14
  import { completionKind } from "./telegram/silent.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 { N as CONFIRMATION_TTL_MS, P as actionApproval, F as confirmations, I as inputHash, L as needsConfirmation } from "../../_chunks/principal-Zf42Yf4r.mjs";
7
+ export { N as CONFIRMATION_TTL_MS, P as actionApproval, F as confirmations, I as inputHash, L as needsConfirmation } from "../../_chunks/principal-C7aAjyt4.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 { _ as AttachmentError } from "../../../_chunks/principal-Zf42Yf4r.mjs";
7
+ import { _ as AttachmentError } from "../../../_chunks/principal-C7aAjyt4.mjs";
8
8
  import { sendStoredAttachments } from "../attachments-send.mjs";
9
9
  import { ConnectionProxyError, connectionProxy } from "../connection-proxy.mjs";
10
10
  import { redactDiagnostic } from "../diagnostics.mjs";
@@ -8,7 +8,7 @@ import { PUBSUB_TOPIC } from "../../config.mjs";
8
8
  import { admitMessage, localizedText } from "../admission.mjs";
9
9
  import { agentToolsAttribute } from "../agent-tools.mjs";
10
10
  import { providerChat } from "../attachment-tools.mjs";
11
- import { Pt as chatAddressOf, S as fetchStoredAttachment, b as agentAttachments, d as prepareInboundMedia, i as memberIdOf, m as turnContent, zt as withChatAddress } from "../../../_chunks/principal-Zf42Yf4r.mjs";
11
+ import { Pt as chatAddressOf, S as fetchStoredAttachment, b as agentAttachments, d as prepareInboundMedia, i as memberIdOf, m as turnContent, zt as withChatAddress } from "../../../_chunks/principal-C7aAjyt4.mjs";
12
12
  import { channelAttributes, currentChannel, currentKey, inHandlerChannels, withNamedRoutes } from "../channel-scope.mjs";
13
13
  import { f as storeOf, h as UNVERIFIED, l as replyEvent, r as chatArchive } from "../../../_chunks/chat-archive-CDk-FPLX.mjs";
14
14
  import { recordChatMessage, recordHandledMessage, recordSentOutside } from "../chat-messages.mjs";
@@ -6,7 +6,7 @@ __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { appOrigin } from "./environment.mjs";
8
8
  import { runtimeToken } from "./runtime-token.mjs";
9
- import { ot as guestIdOf } from "../../_chunks/principal-Zf42Yf4r.mjs";
9
+ import { ot as guestIdOf } from "../../_chunks/principal-C7aAjyt4.mjs";
10
10
  const GUEST_USAGE_PATH = "/api/ontology/agent/guests/usage";
11
11
  const REPORT_TIMEOUT_MS = 5e3;
12
12
  function ontologyGuestUsage(options = {}) {
@@ -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 { f as attachmentsContext, p as storeFiles, m as turnContent } from "../../../_chunks/principal-Zf42Yf4r.mjs";
7
+ export { f as attachmentsContext, p as storeFiles, m as turnContent } 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 { f as attachmentsContext, d as prepareInboundMedia, p as storeFiles, m as turnContent } from "../../../_chunks/principal-Zf42Yf4r.mjs";
7
+ export { f as attachmentsContext, d as prepareInboundMedia, p as storeFiles, m as turnContent } 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 { R as ACT_AS_HEADER, w as actAsHeaders, T as ontologyConnection } from "../../_chunks/principal-Zf42Yf4r.mjs";
7
+ export { R as ACT_AS_HEADER, w as actAsHeaders, T as ontologyConnection } from "../../_chunks/principal-C7aAjyt4.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 { F as confirmations, H as actorOf, I as inputHash, Ot as runtimeEnvelope, P as actionApproval, V as actorKey, j as ontologyTools } from "../../_chunks/principal-Zf42Yf4r.mjs";
7
+ import { F as confirmations, H as actorOf, I as inputHash, Ot as runtimeEnvelope, P as actionApproval, V as actorKey, j as ontologyTools } from "../../_chunks/principal-C7aAjyt4.mjs";
8
8
  import { isChatPost } from "./chat-post-confirmation.mjs";
9
9
  import { sandboxFile } from "./sandbox-session.mjs";
10
10
  import { saveOntologyResult } from "./ontology-result-file.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 { E as OntologyActionNotPermitted, D as OntologyFileUnavailable, O as OntologyToolRejected, k as actionToolName, A as ontologyToolLabels, j as ontologyTools, M as promotionTarget } from "../../_chunks/principal-Zf42Yf4r.mjs";
7
+ export { E as OntologyActionNotPermitted, D as OntologyFileUnavailable, O as OntologyToolRejected, k as actionToolName, A as ontologyToolLabels, j as ontologyTools, M as promotionTarget } from "../../_chunks/principal-C7aAjyt4.mjs";
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { reviewFor } from "../../review.mjs";
8
- import { Pt as chatAddressOf, a as rolesOf, i as memberIdOf } from "../../../_chunks/principal-Zf42Yf4r.mjs";
8
+ import { Pt as chatAddressOf, a as rolesOf, i as memberIdOf } from "../../../_chunks/principal-C7aAjyt4.mjs";
9
9
  function reviewOf(settings, principal) {
10
10
  return reviewFor(settings, rolesOf(principal));
11
11
  }