@segmentstream/agent 0.42.1 → 0.43.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 (115) hide show
  1. package/README.md +24 -24
  2. package/dist/_chunks/{build-metadata-BPEZ5XVM.mjs → build-metadata-CkBdh-TE.mjs} +1 -1
  3. package/dist/_chunks/{principal-BIX7T6Hh.mjs → principal-nQ_gwLJs.mjs} +4 -4
  4. package/dist/extension/channels/telegram.mjs +1 -1
  5. package/dist/extension/channels/whatsapp.mjs +1 -1
  6. package/dist/extension/config.d.ts +14 -16
  7. package/dist/extension/config.mjs +57 -12
  8. package/dist/extension/conventions.d.ts +1 -1
  9. package/dist/extension/conventions.mjs +22 -19
  10. package/dist/extension/extension.d.ts +2 -2
  11. package/dist/extension/extension.mjs +3 -3
  12. package/dist/extension/hooks/authorization.mjs +1 -1
  13. package/dist/extension/hooks/{conversations.mjs → chat-recorder.mjs} +4 -4
  14. package/dist/extension/hooks/sandbox.d.ts +2 -2
  15. package/dist/extension/instructions/{conversations.mjs → chat-context.mjs} +2 -2
  16. package/dist/extension/instructions/persona.mjs +1 -1
  17. package/dist/extension/instructions/sandbox.mjs +2 -2
  18. package/dist/extension/instructions.md +10 -10
  19. package/dist/extension/lib/actor.mjs +1 -1
  20. package/dist/extension/lib/attachment-tools.d.ts +1 -1
  21. package/dist/extension/lib/attachment-tools.mjs +7 -7
  22. package/dist/extension/lib/attachments.d.ts +9 -4
  23. package/dist/extension/lib/attachments.mjs +9 -7
  24. package/dist/extension/lib/build-metadata.mjs +1 -1
  25. package/dist/extension/lib/chat-address.d.ts +33 -0
  26. package/dist/extension/lib/{conversation.mjs → chat-address.mjs} +13 -12
  27. package/dist/extension/lib/{conversations.d.ts → chat-archive.d.ts} +12 -12
  28. package/dist/extension/lib/{conversations.mjs → chat-archive.mjs} +9 -9
  29. package/dist/extension/lib/chat-context.d.ts +5 -5
  30. package/dist/extension/lib/chat-context.mjs +6 -6
  31. package/dist/extension/lib/{conversation-runtime.d.ts → chat-recorder.d.ts} +3 -3
  32. package/dist/extension/lib/{conversation-runtime.mjs → chat-recorder.mjs} +13 -13
  33. package/dist/extension/lib/confirmations.d.ts +3 -3
  34. package/dist/extension/lib/confirmations.mjs +8 -8
  35. package/dist/extension/lib/group-routing/addressing.d.ts +1 -1
  36. package/dist/extension/lib/group-routing/addressing.mjs +2 -2
  37. package/dist/extension/lib/group-routing/burst.mjs +2 -2
  38. package/dist/extension/lib/group-routing/{conversation-prompt.d.ts → chat-prompt.d.ts} +2 -2
  39. package/dist/extension/lib/group-routing/{conversation-prompt.mjs → chat-prompt.mjs} +3 -3
  40. package/dist/extension/lib/group-routing/{conversation-router.d.ts → chat-router.d.ts} +6 -6
  41. package/dist/extension/lib/group-routing/{conversation-router.mjs → chat-router.mjs} +9 -9
  42. package/dist/extension/lib/group-routing/engagement.mjs +2 -2
  43. package/dist/extension/lib/group-routing/messages.d.ts +1 -1
  44. package/dist/extension/lib/group-routing/policy.d.ts +6 -6
  45. package/dist/extension/lib/group-routing/policy.mjs +16 -16
  46. package/dist/extension/lib/group-routing/replay.mjs +36 -9
  47. package/dist/extension/lib/group-routing/router.d.ts +3 -3
  48. package/dist/extension/lib/group-routing/router.mjs +16 -16
  49. package/dist/extension/lib/group-routing/routing-context.d.ts +2 -2
  50. package/dist/extension/lib/group-routing/routing-context.mjs +2 -2
  51. package/dist/extension/lib/group-routing/signals.d.ts +3 -3
  52. package/dist/extension/lib/group-routing/signals.mjs +5 -5
  53. package/dist/extension/lib/model-service-alert.d.ts +2 -2
  54. package/dist/extension/lib/model-service-alert.mjs +2 -2
  55. package/dist/extension/lib/ontology-connection.mjs +1 -1
  56. package/dist/extension/lib/ontology-file-call.mjs +1 -1
  57. package/dist/extension/lib/ontology-tools.mjs +1 -1
  58. package/dist/extension/lib/review/hold.d.ts +7 -7
  59. package/dist/extension/lib/review/hold.mjs +12 -12
  60. package/dist/extension/lib/review/judge.d.ts +9 -9
  61. package/dist/extension/lib/review/judge.mjs +12 -12
  62. package/dist/extension/lib/review/reply.d.ts +13 -13
  63. package/dist/extension/lib/review/reply.mjs +20 -20
  64. package/dist/extension/lib/role-skill.mjs +1 -1
  65. package/dist/extension/lib/runtime-envelope.mjs +1 -1
  66. package/dist/extension/lib/sent-files.mjs +3 -2
  67. package/dist/extension/lib/slack/adapter.mjs +2 -2
  68. package/dist/extension/lib/slack/attachments-send.d.ts +2 -2
  69. package/dist/extension/lib/slack/attachments-send.mjs +5 -5
  70. package/dist/extension/lib/slack/files.mjs +4 -4
  71. package/dist/extension/lib/stored-files.mjs +1 -1
  72. package/dist/extension/lib/telegram/adapter.d.ts +4 -3
  73. package/dist/extension/lib/telegram/adapter.mjs +10 -10
  74. package/dist/extension/lib/telegram/attachments-send.mjs +1 -1
  75. package/dist/extension/lib/telegram/callbacks.mjs +1 -1
  76. package/dist/extension/lib/telegram/{conversations.d.ts → chat-archive.d.ts} +7 -7
  77. package/dist/extension/lib/telegram/{conversations.mjs → chat-archive.mjs} +10 -10
  78. package/dist/extension/lib/telegram/confirmation-text.mjs +1 -0
  79. package/dist/extension/lib/telegram/confirmations.d.ts +2 -2
  80. package/dist/extension/lib/telegram/confirmations.mjs +3 -3
  81. package/dist/extension/lib/telegram/delivery-diagnostics.d.ts +3 -3
  82. package/dist/extension/lib/telegram/delivery-diagnostics.mjs +2 -2
  83. package/dist/extension/lib/telegram/files.d.ts +1 -1
  84. package/dist/extension/lib/telegram/files.mjs +8 -8
  85. package/dist/extension/lib/telegram/health.mjs +1 -1
  86. package/dist/extension/lib/telegram/inbound-request.d.ts +1 -1
  87. package/dist/extension/lib/telegram/inbound.d.ts +3 -3
  88. package/dist/extension/lib/telegram/inbound.mjs +36 -36
  89. package/dist/extension/lib/telegram/lifecycle.mjs +3 -3
  90. package/dist/extension/lib/telegram/principal.d.ts +2 -2
  91. package/dist/extension/lib/telegram/principal.mjs +1 -1
  92. package/dist/extension/lib/telegram/router.mjs +2 -2
  93. package/dist/extension/lib/telegram/sessions.d.ts +1 -1
  94. package/dist/extension/lib/telegram/signals.mjs +1 -1
  95. package/dist/extension/lib/telegram/silent.d.ts +2 -2
  96. package/dist/extension/lib/telegram/structured.mjs +1 -1
  97. package/dist/extension/lib/telegram/turn-errors.d.ts +2 -2
  98. package/dist/extension/lib/telegram/turn-errors.mjs +2 -2
  99. package/dist/extension/lib/telegram/voice.d.ts +1 -1
  100. package/dist/extension/lib/whatsapp/adapter.d.ts +2 -2
  101. package/dist/extension/lib/whatsapp/adapter.mjs +2 -2
  102. package/dist/extension/lib/workflow-serializable.d.ts +1 -1
  103. package/dist/extension/model.mjs +1 -1
  104. package/dist/extension/personas.d.ts +1 -1
  105. package/dist/extension/review.d.ts +23 -20
  106. package/dist/extension/review.mjs +21 -34
  107. package/dist/extension/tools/attachments_promote.mjs +1 -1
  108. package/dist/extension/tools/attachments_send.mjs +3 -3
  109. package/dist/extension/tools/no_reply.d.ts +1 -1
  110. package/dist/extension/tools/questions_ask.mjs +4 -4
  111. package/dist/extension/tools/sandbox.mjs +2 -2
  112. package/package.json +2 -2
  113. package/dist/extension/lib/conversation.d.ts +0 -33
  114. /package/dist/extension/hooks/{conversations.d.ts → chat-recorder.d.ts} +0 -0
  115. /package/dist/extension/instructions/{conversations.d.ts → chat-context.d.ts} +0 -0
@@ -4,13 +4,13 @@ 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 { conversationOf } from "../conversation.mjs";
8
- import { conversationEvent, conversations } from "../conversations.mjs";
7
+ import { chatAddressOf } from "../chat-address.mjs";
8
+ import { chatArchive, chatEvent } from "../chat-archive.mjs";
9
9
  import { appOrigin } from "../environment.mjs";
10
10
  import { agentReviews } from "./client.mjs";
11
- import { i as memberIdOf } from "../../../_chunks/principal-BIX7T6Hh.mjs";
11
+ import { i as memberIdOf } from "../../../_chunks/principal-nQ_gwLJs.mjs";
12
12
  import { heldReply, repliesReviewed, reviewOf, reviewOutcome } from "./hold.mjs";
13
- import { judgeReply, readConversation } from "./judge.mjs";
13
+ import { judgeReply, readChat } from "./judge.mjs";
14
14
  const VERDICTS_REMEMBERED = 512;
15
15
  function replyReview(options) {
16
16
  const verdicts = new Map();
@@ -28,17 +28,17 @@ function replyReview(options) {
28
28
  async sendOrHold(input) {
29
29
  const review = reviewOf(options.settings(), input.principal);
30
30
  if (!repliesReviewed(options.settings(), input.principal) || review.mode === "never") return true;
31
- const conversation = conversationOf(input.principal);
32
- const coordinates = conversation === void 0 ? void 0 : {
33
- provider: conversation.provider,
34
- chatId: conversation.chatId,
35
- threadId: conversation.threadId === "" ? null : conversation.threadId
31
+ const chat = chatAddressOf(input.principal);
32
+ const coordinates = chat === void 0 ? void 0 : {
33
+ provider: chat.provider,
34
+ chatId: chat.chatId,
35
+ threadId: chat.threadId === "" ? null : chat.threadId
36
36
  };
37
37
  const key = `${input.sessionId}:${input.partId}`;
38
38
  const outcome = verdicts.get(key) ?? remember(key, await reviewOutcome(review, async (criteria) => judgeReply({
39
39
  decide: options.decide,
40
40
  model: options.model(),
41
- conversation: coordinates === void 0 ? [] : await readConversation(options.archive, coordinates),
41
+ chat: coordinates === void 0 ? [] : await readChat(options.archive, coordinates),
42
42
  reply: input.text,
43
43
  ...criteria === void 0 ? {} : { criteria }
44
44
  }), (error) => console.error("[segmentstream] reply review judge failed; the reply is held", {
@@ -48,10 +48,10 @@ function replyReview(options) {
48
48
  const record = async (reason, summary) => {
49
49
  if (coordinates === void 0) return;
50
50
  const memberId = memberIdOf(input.principal);
51
- await options.archive.append(conversationEvent({
51
+ await options.archive.append(chatEvent({
52
52
  ...coordinates,
53
53
  eventId: `review:${input.sessionId}:${input.partId}`,
54
- chatType: conversation?.kind === "group" ? "group" : "private",
54
+ chatType: chat?.kind === "group" ? "group" : "private",
55
55
  participantIds: memberId === void 0 ? [] : [memberId],
56
56
  sessionId: input.sessionId,
57
57
  turnId: input.turnId,
@@ -73,7 +73,7 @@ function replyReview(options) {
73
73
  ...input,
74
74
  outcome
75
75
  });
76
- if (held === void 0) throw new Error("A reply under review has no conversation or member to be held for.");
76
+ if (held === void 0) throw new Error("A reply under review has no chat or member to be held for.");
77
77
  await options.hold(held);
78
78
  await record("review_held", {
79
79
  mode: outcome.mode,
@@ -107,14 +107,14 @@ function withReviewedReplies(channel, review, archive) {
107
107
  }
108
108
  }, context);
109
109
  await completed(event, context);
110
- const conversation = conversationOf(principal);
110
+ const chat = chatAddressOf(principal);
111
111
  const memberId = memberIdOf(principal);
112
- if (conversation !== void 0) await archive().append(conversationEvent({
112
+ if (chat !== void 0) await archive().append(chatEvent({
113
113
  eventId: `review:${context.session.id}:${event.data.partId}:outbound`,
114
- provider: conversation.provider,
115
- chatId: conversation.chatId,
116
- chatType: conversation.kind === "group" ? "group" : "private",
117
- threadId: conversation.threadId === "" ? null : conversation.threadId,
114
+ provider: chat.provider,
115
+ chatId: chat.chatId,
116
+ chatType: chat.kind === "group" ? "group" : "private",
117
+ threadId: chat.threadId === "" ? null : chat.threadId,
118
118
  participantIds: memberId === void 0 ? [] : [memberId],
119
119
  sessionId: context.session.id,
120
120
  turnId,
@@ -138,7 +138,7 @@ function channelReview(options, runtime) {
138
138
  token: runtime.token,
139
139
  ...runtime.fetch === void 0 ? {} : { fetch: runtime.fetch }
140
140
  };
141
- const archive = options.archive ?? conversations({
141
+ const archive = options.archive ?? chatArchive({
142
142
  environment: runtime.environment,
143
143
  ...transport
144
144
  });
@@ -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 { a as rolesOf } from "../../_chunks/principal-BIX7T6Hh.mjs";
7
+ import { a as rolesOf } from "../../_chunks/principal-nQ_gwLJs.mjs";
8
8
  import { defineDynamic, defineSkill } from "eve/skills";
9
9
  function forRoles(roles, skill) {
10
10
  if (!Array.isArray(roles) || roles.length === 0 || !roles.every((role) => typeof role === "string" && role.trim() !== "")) throw new TypeError("forRoles() needs at least one role name; a skill for everyone is an ordinary skill file.");
@@ -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 { s as RUNTIME_SOURCE_PROTOCOL, c as compatibleRuntimeEnvelope, l as principalRuntimeSource, u as runtimeEnvelope, d as telegramRuntimeSource } from "../../_chunks/principal-BIX7T6Hh.mjs";
7
+ export { s as RUNTIME_SOURCE_PROTOCOL, c as compatibleRuntimeEnvelope, l as principalRuntimeSource, u as runtimeEnvelope, d as telegramRuntimeSource } from "../../_chunks/principal-nQ_gwLJs.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 { AttachmentError, CONVERSATION_HEADER, SESSION_HEADER } from "./attachments.mjs";
7
+ import { AttachmentError, CHAT_HEADER, EARLIER_CHAT_HEADER, SESSION_HEADER } from "./attachments.mjs";
8
8
  import { fetchFileGrant, transientFileStatus } from "./file-grant.mjs";
9
9
  import { ACT_AS_HEADER } from "./actor.mjs";
10
10
  var StoredFileError = class extends AttachmentError {
@@ -54,7 +54,8 @@ async function fetchStoredFile(input) {
54
54
  headers: {
55
55
  authorization: `Bearer ${await input.token()}`,
56
56
  [ACT_AS_HEADER]: owner.memberId,
57
- [CONVERSATION_HEADER]: owner.conversation,
57
+ [CHAT_HEADER]: owner.chat,
58
+ [EARLIER_CHAT_HEADER]: owner.chat,
58
59
  ...owner.sessionId === void 0 ? {} : { [SESSION_HEADER]: owner.sessionId }
59
60
  },
60
61
  redirect: "error",
@@ -7,7 +7,7 @@ __eveCreateRequire(import.meta.url);
7
7
  import { admitMessage, localizedText } from "../admission.mjs";
8
8
  import { agentChats } from "../chats.mjs";
9
9
  import { withButtonDecision } from "../confirmation-buttons.mjs";
10
- import { withConversation } from "../conversation.mjs";
10
+ import { withChatAddress } from "../chat-address.mjs";
11
11
  import { redactDiagnostic } from "../diagnostics.mjs";
12
12
  import { MAXIMUM_DOWNLOAD_BYTES, connectionProxy } from "../connection-proxy.mjs";
13
13
  import { appOrigin, channelsEnabled, proxyEnvironment, webhookSecret } from "../environment.mjs";
@@ -359,7 +359,7 @@ async function receive(input) {
359
359
  else input.waitUntil(reported);
360
360
  }
361
361
  if (!turn) return null;
362
- const auth = withConversation(slackPrincipal(resolution.member, user), {
362
+ const auth = withChatAddress(slackPrincipal(resolution.member, user), {
363
363
  provider: "slack",
364
364
  chatId: ctx.slack.channelId,
365
365
  threadId: ctx.slack.threadTs,
@@ -3,10 +3,10 @@ import { type Environment } from "../environment.js";
3
3
  import { type RuntimeToken } from "../runtime-token.js";
4
4
  import type { SendAttachmentsInput } from "../telegram/attachments-send.js";
5
5
  /**
6
- * `attachments_send` in Slack: stored ontology files posted into the turn's Slack conversation,
6
+ * `attachments_send` in Slack: stored ontology files posted into the turn's Slack chat,
7
7
  * in its thread, with Slack's external upload: `files.getUploadURLExternal` for each file, its
8
8
  * bytes posted to the address Slack answers, then one `files.completeUploadExternal` that shares
9
- * them all in the conversation with the caption. Every call goes through the Slack connection,
9
+ * them all in the chat with the caption. Every call goes through the Slack connection,
10
10
  * which adds the bot token and needs `files:write`; each upload carries at most the connection
11
11
  * proxy's 2 MiB, as Telegram's do.
12
12
  */
@@ -7,7 +7,7 @@ __eveCreateRequire(import.meta.url);
7
7
  import { attachmentOwner } from "../attachment-tools.mjs";
8
8
  import { AttachmentError } from "../attachments.mjs";
9
9
  import { MAXIMUM_PROXY_BODY_BYTES, connectionProxy } from "../connection-proxy.mjs";
10
- import { conversationOf } from "../conversation.mjs";
10
+ import { chatAddressOf } from "../chat-address.mjs";
11
11
  import { redactDiagnostic } from "../diagnostics.mjs";
12
12
  import { appOrigin, channelsEnabled, proxyEnvironment } from "../environment.mjs";
13
13
  import { transientFileStatus } from "../file-grant.mjs";
@@ -53,10 +53,10 @@ async function sendSlackAttachments(options) {
53
53
  reference
54
54
  };
55
55
  };
56
- const conversation = conversationOf(principal);
56
+ const chat = chatAddressOf(principal);
57
57
  if (!channelsEnabled(environment)) return unavailable("channels_disabled", "Attachments can be sent only in production.");
58
58
  if (options.connection === void 0) return unavailable("unsupported", "The Slack channel is not configured.");
59
- if (conversation?.provider !== "slack") return unavailable("no_slack_conversation", "This turn has no Slack conversation.");
59
+ if (chat?.provider !== "slack") return unavailable("no_slack_chat", "This turn has no Slack chat.");
60
60
  let owner;
61
61
  try {
62
62
  owner = attachmentOwner({
@@ -185,8 +185,8 @@ async function sendSlackAttachments(options) {
185
185
  id: slackId,
186
186
  title: results[index].filename
187
187
  })),
188
- channel_id: conversation.chatId,
189
- ...conversation.threadId === "" ? {} : { thread_ts: conversation.threadId },
188
+ channel_id: chat.chatId,
189
+ ...chat.threadId === "" ? {} : { thread_ts: chat.threadId },
190
190
  ...options.input.caption === void 0 ? {} : { initial_comment: options.input.caption }
191
191
  })
192
192
  });
@@ -4,13 +4,13 @@ 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 { chatConversation } from "../attachment-tools.mjs";
7
+ import { providerChat } from "../attachment-tools.mjs";
8
8
  import { MAXIMUM_ATTACHMENT_BYTES, attachmentUrl } from "../attachments.mjs";
9
9
  function megabytes(bytes) {
10
10
  return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
11
11
  }
12
12
  async function stageSlackFiles(input) {
13
- const conversation = chatConversation("slack", input.channelId);
13
+ const chat = providerChat("slack", input.channelId);
14
14
  const staged = new Map();
15
15
  for (const [index, file] of input.files.entries()) {
16
16
  const key = file.id === "" ? `file-${index}` : file.id;
@@ -36,7 +36,7 @@ async function stageSlackFiles(input) {
36
36
  const bytes = await input.download(file.url, MAXIMUM_ATTACHMENT_BYTES, contentType);
37
37
  const attachment = await input.attachments.receive({
38
38
  memberId: input.memberId,
39
- conversation
39
+ chat
40
40
  }, {
41
41
  bytes,
42
42
  filename,
@@ -50,7 +50,7 @@ async function stageSlackFiles(input) {
50
50
  url: attachmentUrl({
51
51
  id: attachment.id,
52
52
  memberId: input.memberId,
53
- conversation
53
+ chat
54
54
  })
55
55
  });
56
56
  } catch (error) {
@@ -6,7 +6,7 @@ __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { object } from "./confirmation-description.mjs";
8
8
  import { OntologyFileUnavailable, ontologyTools } from "./ontology-tools.mjs";
9
- import { i as memberIdOf } from "../../_chunks/principal-BIX7T6Hh.mjs";
9
+ import { i as memberIdOf } from "../../_chunks/principal-nQ_gwLJs.mjs";
10
10
  import { member } from "./actor.mjs";
11
11
  import { redactDiagnostic } from "./diagnostics.mjs";
12
12
  import { createHash } from "node:crypto";
@@ -4,7 +4,7 @@ import { type TelegramChannel } from "eve/channels/telegram";
4
4
  import type { ChatModelChoice, AdmissionSettings, SessionSettings, TelegramSettings } from "../../config.js";
5
5
  import { type AgentAttachments } from "../attachments.js";
6
6
  import { type Environment } from "../environment.js";
7
- import { type Conversations } from "../conversations.js";
7
+ import { type ChatArchive } from "../chat-archive.js";
8
8
  import { type RuntimeTokenVerifier } from "../runtime-identity.js";
9
9
  import { type RuntimeToken } from "../runtime-token.js";
10
10
  import { type ImageDescriber } from "./images.js";
@@ -48,9 +48,10 @@ export interface TelegramAdapterOptions {
48
48
  readonly history?: HistoryReader;
49
49
  /** The attachment store; tests pass a fake. */
50
50
  readonly attachments?: AgentAttachments;
51
- readonly conversations?: Conversations;
51
+ /** The chat archive; tests pass a fake. */
52
+ readonly archive?: ChatArchive;
52
53
  /**
53
- * `conversations` of `agent/segmentstream.json`: who sends the agent's replies. Without it the
54
+ * `review` of `agent/segmentstream.json`: who sends the agent's replies. Without it the
54
55
  * agent sends every reply itself.
55
56
  */
56
57
  readonly review?: Omit<ChannelReviewOptions, "model" | "archive">;
@@ -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-BPEZ5XVM.mjs";
13
+ import { t as agentBuild } from "../../../_chunks/build-metadata-CkBdh-TE.mjs";
14
14
  import { attachmentLifecycle } from "./lifecycle.mjs";
15
15
  import { manifestOf } from "../../config.mjs";
16
16
  import { gatewayAttachmentDescriber } from "./attachment-description.mjs";
@@ -19,15 +19,15 @@ import { agentAttachments, parseAttachmentUrl } from "../attachments.mjs";
19
19
  import { MAXIMUM_DOWNLOAD_BYTES, connectionProxy } from "../connection-proxy.mjs";
20
20
  import { appOrigin, channelsEnabled, proxyEnvironment, runtimeIdentityEnvironment, webhookSecret } from "../environment.mjs";
21
21
  import { agentIdentities } from "../identities.mjs";
22
- import { conversations, topicContext } from "../conversations.mjs";
23
- import { captureRouteDecider, captureTelegramFetch, conversationIdentities, recordGateDecision, telegramConversationCapture } from "./conversations.mjs";
22
+ import { chatArchive, topicContext } from "../chat-archive.mjs";
23
+ import { captureRouteDecider, captureTelegramFetch, chatIdentities, recordGateDecision, telegramChatCapture } from "./chat-archive.mjs";
24
24
  import { runtimeTokenVerifier } from "../runtime-identity.mjs";
25
25
  import { runtimeToken } from "../runtime-token.mjs";
26
26
  import { botIdentityCache } from "./bot.mjs";
27
27
  import { handleConfirmationCallback, telegramConfirmationEvents } from "./confirmations.mjs";
28
28
  import { confirmationLocale } from "./confirmation-text.mjs";
29
29
  import { d as failureText, h as withDeliveryLocale, i as withReplacedText, m as safeTelegramFetch, n as currentInboundRequest, o as currentLocale, p as reportTelegramError, r as runInboundRequest, t as InboundRequest } from "../../../_chunks/inbound-request-DgQB4g1J.mjs";
30
- import { n as conversationLanguage, o as telegramPrincipal } from "../../../_chunks/principal-BIX7T6Hh.mjs";
30
+ import { n as chatLanguage, o as telegramPrincipal } from "../../../_chunks/principal-nQ_gwLJs.mjs";
31
31
  import { gatewayImageDescriber } from "./images.mjs";
32
32
  import { gatewayMediaCapabilities, planMedia } from "./media-policy.mjs";
33
33
  import { agentChats } from "../chats.mjs";
@@ -84,7 +84,7 @@ function segmentstreamTelegram(options) {
84
84
  const readHistory = options.history ?? eveHistory;
85
85
  const readInteractions = options.history ?? eveInteractions;
86
86
  const capabilities = options.modelCapabilities ?? gatewayMediaCapabilities(options.fetch);
87
- const archive = options.conversations ?? conversations({
87
+ const archive = options.archive ?? chatArchive({
88
88
  environment,
89
89
  token,
90
90
  fetch: options.fetch
@@ -134,7 +134,7 @@ function segmentstreamTelegram(options) {
134
134
  provider: "telegram",
135
135
  identities: pairing
136
136
  });
137
- const capture = telegramConversationCapture({
137
+ const capture = telegramChatCapture({
138
138
  archive,
139
139
  identities: pairing,
140
140
  chats,
@@ -200,7 +200,7 @@ function segmentstreamTelegram(options) {
200
200
  onMessage: async (context, message) => {
201
201
  const inbound = currentInboundRequest();
202
202
  if (inbound !== void 0) {
203
- inbound.locale = conversationLanguage([message.text || message.caption]) ?? message.from?.languageCode ?? "en";
203
+ inbound.locale = chatLanguage([message.text || message.caption]) ?? message.from?.languageCode ?? "en";
204
204
  inbound.threadId = message.messageThreadId === void 0 ? void 0 : String(message.messageThreadId);
205
205
  }
206
206
  try {
@@ -212,7 +212,7 @@ function segmentstreamTelegram(options) {
212
212
  policy: settings().policy,
213
213
  decisionModel: options.models().decision,
214
214
  groups: options.groups?.(),
215
- recentConversation: async (chatId, threadId) => archivedRoutingMessages((await topicContext(archive, {
215
+ recentChat: async (chatId, threadId) => archivedRoutingMessages((await topicContext(archive, {
216
216
  provider: "telegram",
217
217
  chatId,
218
218
  threadId: threadId ?? null,
@@ -279,7 +279,7 @@ function segmentstreamTelegram(options) {
279
279
  audio: false
280
280
  } : await capabilities(selected), options.models().imageDescription ?? null);
281
281
  },
282
- identities: conversationIdentities(pairing()),
282
+ identities: chatIdentities(pairing()),
283
283
  bot,
284
284
  decide: captureRouteDecider(decisionRouter({
285
285
  decide: options.decide,
@@ -446,7 +446,7 @@ function segmentstreamTelegram(options) {
446
446
  const sessionId = sessionIdOf(context);
447
447
  const { attachment, bytes } = await attachments().read({
448
448
  memberId: reference.memberId,
449
- conversation: reference.conversation,
449
+ chat: reference.chat,
450
450
  ...sessionId === void 0 ? {} : { sessionId }
451
451
  }, reference.id);
452
452
  return {
@@ -12,7 +12,7 @@ import { transientFileStatus } from "../file-grant.mjs";
12
12
  import { StoredFileError, fetchStoredFile } from "../sent-files.mjs";
13
13
  import { appOrigin, channelsEnabled, proxyEnvironment } from "../environment.mjs";
14
14
  import { runtimeToken } from "../runtime-token.mjs";
15
- import "../../../_chunks/principal-BIX7T6Hh.mjs";
15
+ import "../../../_chunks/principal-nQ_gwLJs.mjs";
16
16
  import { confirmationLocale } from "./confirmation-text.mjs";
17
17
  import { inTelegramSendQueue, telegramSendScope } from "./send-queue.mjs";
18
18
  import { d as failureText, f as formattingRefused, l as customerMessage, p as reportTelegramError } from "../../../_chunks/inbound-request-DgQB4g1J.mjs";
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { object } from "../confirmation-description.mjs";
8
- import { d as telegramRuntimeSource, i as memberIdOf, o as telegramPrincipal, u as runtimeEnvelope } from "../../../_chunks/principal-BIX7T6Hh.mjs";
8
+ import { d as telegramRuntimeSource, i as memberIdOf, o as telegramPrincipal, u as runtimeEnvelope } from "../../../_chunks/principal-nQ_gwLJs.mjs";
9
9
  import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-DgQB4g1J.mjs";
10
10
  import { formatAddress, parseAddress, scopedAddress } from "./sessions.mjs";
11
11
  import { telegramText } from "./texts.mjs";
@@ -1,6 +1,6 @@
1
1
  import type { StructuredMessage } from "./structured.js";
2
2
  import type { AgentIdentities } from "../identities.js";
3
- import { type Conversations } from "../conversations.js";
3
+ import { type ChatArchive } from "../chat-archive.js";
4
4
  import type { AgentChats } from "../chats.js";
5
5
  import type { DecodedAttachment } from "./attachment-description.js";
6
6
  import type { AddressingReason, RouteDecider, RouteDecision } from "./router.js";
@@ -11,7 +11,7 @@ export declare function captureTelegramWebhook(input: {
11
11
  readonly answerCallback?: (id: string, locale?: string) => Promise<unknown>;
12
12
  readonly structured?: (raw: Readonly<Record<string, unknown>>) => StructuredMessage | undefined;
13
13
  readonly request: Request;
14
- readonly archive: Conversations;
14
+ readonly archive: ChatArchive;
15
15
  readonly identities: AgentIdentities;
16
16
  readonly chats?: AgentChats;
17
17
  readonly next: (request?: Request) => Promise<Response>;
@@ -46,7 +46,7 @@ export declare function recordInboundContent(content: {
46
46
  * member's notice never depends on the archive.
47
47
  */
48
48
  export declare function recordSessionFailure(input: {
49
- readonly archive: Conversations;
49
+ readonly archive: ChatArchive;
50
50
  readonly identities: () => AgentIdentities;
51
51
  readonly chatId: string | null;
52
52
  readonly threadId: string | null;
@@ -57,14 +57,14 @@ export declare function recordSessionFailure(input: {
57
57
  };
58
58
  }): Promise<void>;
59
59
  /** Captures message sends and button/status edits, including pairing and proactive replies. */
60
- export declare function captureTelegramFetch(fetchImpl: typeof fetch, archive: Conversations, identities: () => AgentIdentities): typeof fetch;
60
+ export declare function captureTelegramFetch(fetchImpl: typeof fetch, archive: ChatArchive, identities: () => AgentIdentities): typeof fetch;
61
61
  /** Reuses the request's verified lookup; it never survives into another inbound request. */
62
- export declare function conversationIdentities(identities: AgentIdentities): AgentIdentities;
62
+ export declare function chatIdentities(identities: AgentIdentities): AgentIdentities;
63
63
  /** Verification and failure acknowledgement stay outside eve's swallowed onMessage failures. */
64
- export declare function telegramConversationCapture(input: {
64
+ export declare function telegramChatCapture(input: {
65
65
  readonly answerCallback?: (id: string, locale?: string) => Promise<unknown>;
66
66
  readonly structured?: (raw: Readonly<Record<string, unknown>>) => StructuredMessage | undefined;
67
- readonly archive: Conversations;
67
+ readonly archive: ChatArchive;
68
68
  readonly identities: () => AgentIdentities;
69
69
  readonly chats: AgentChats;
70
70
  readonly verify: (request: Request) => boolean;
@@ -6,7 +6,7 @@ __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { parseArchivedMessage } from "./archive-message.mjs";
8
8
  import { n as contentText, t as CONTENT_CAPS } from "../../../_chunks/content-cDtVnr8Y.mjs";
9
- import { conversationEvent, sessionFailureEventId } from "../conversations.mjs";
9
+ import { chatEvent, sessionFailureEventId } from "../chat-archive.mjs";
10
10
  import { currentConfirmationPrompt } from "../group-routing/messages.mjs";
11
11
  import { messageMetadata } from "./message-metadata.mjs";
12
12
  import { n as currentInboundRequest, p as reportTelegramError, s as currentThreadId } from "../../../_chunks/inbound-request-DgQB4g1J.mjs";
@@ -68,7 +68,7 @@ async function participants(message, identities, resolved) {
68
68
  resolved(lookup);
69
69
  return lookup.status === "paired" ? [lookup.member.id] : [];
70
70
  } catch (error) {
71
- console.error("[segmentstream] conversation participant lookup failed", { error });
71
+ console.error("[segmentstream] chat participant lookup failed", { error });
72
72
  return [];
73
73
  }
74
74
  }
@@ -114,7 +114,7 @@ async function captureTelegramWebhook(input) {
114
114
  const senderChat = record(message.raw.sender_chat);
115
115
  const attachments = attachmentRefs(message);
116
116
  let lookup;
117
- const event = conversationEvent({
117
+ const event = chatEvent({
118
118
  eventId: [
119
119
  "telegram",
120
120
  message.chat.id,
@@ -526,7 +526,7 @@ async function recordSessionFailure(input) {
526
526
  return;
527
527
  }
528
528
  const { chatType, participantIds } = await outboundAudience(input.chatId, input.identities);
529
- await input.archive.append(conversationEvent({
529
+ await input.archive.append(chatEvent({
530
530
  eventId: sessionId === null ? `eve:session.failed:${randomUUID()}` : sessionFailureEventId(sessionId),
531
531
  provider: "telegram",
532
532
  chatId: input.chatId,
@@ -558,7 +558,7 @@ function captureTelegramFetch(fetchImpl, archive, identities) {
558
558
  const { capture, chatType, participantIds } = await outboundAudience(chatId, identities);
559
559
  const delivery = currentDeliveryScope();
560
560
  const own = delivery?.chatId === chatId && delivery.sessionId !== null;
561
- const event = conversationEvent({
561
+ const event = chatEvent({
562
562
  eventId: `telegram:${edit ? "edit" : "send"}:${randomUUID()}`,
563
563
  provider: "telegram",
564
564
  chatId,
@@ -633,7 +633,7 @@ function captureTelegramFetch(fetchImpl, archive, identities) {
633
633
  return response;
634
634
  };
635
635
  }
636
- function conversationIdentities(identities) {
636
+ function chatIdentities(identities) {
637
637
  return {
638
638
  ...identities,
639
639
  resolve: async (account) => {
@@ -673,7 +673,7 @@ function conversationIdentities(identities) {
673
673
  }
674
674
  };
675
675
  }
676
- function telegramConversationCapture(input) {
676
+ function telegramChatCapture(input) {
677
677
  const processing = new Map();
678
678
  return async (request, next) => {
679
679
  if (!input.verify(request)) return next();
@@ -700,9 +700,9 @@ function telegramConversationCapture(input) {
700
700
  if (key !== void 0 && processing.get(key) === task) processing.delete(key);
701
701
  }
702
702
  } catch (error) {
703
- console.error("[segmentstream] conversation capture failed", { error });
704
- return new Response("conversation storage unavailable", { status: 503 });
703
+ console.error("[segmentstream] chat capture failed", { error });
704
+ return new Response("chat storage unavailable", { status: 503 });
705
705
  }
706
706
  };
707
707
  }
708
- export { REVISION_CLAIM_TTL_MS, captureRouteDecider, captureTelegramFetch, captureTelegramWebhook, conversationIdentities, recordGateDecision, recordInboundContent, recordRouteDecision, recordSessionFailure, telegramConversationCapture };
708
+ export { REVISION_CLAIM_TTL_MS, captureRouteDecider, captureTelegramFetch, captureTelegramWebhook, chatIdentities, recordGateDecision, recordInboundContent, recordRouteDecision, recordSessionFailure, telegramChatCapture };
@@ -39,6 +39,7 @@ function composer(text = "", entities = []) {
39
39
  }
40
40
  function confirmationLocale(principal, fallback = "en") {
41
41
  for (const key of [
42
+ "chatLanguage",
42
43
  "conversationLanguage",
43
44
  "locale",
44
45
  "language",
@@ -1,7 +1,7 @@
1
1
  import type { ChannelEvents } from "eve/channels";
2
2
  import type { TelegramCallbackQuery, TelegramChannelEvents, TelegramContext, TelegramEventContext } from "eve/channels/telegram";
3
3
  import { type ConfirmationPrompt, type PendingConfirmation, type RecentMessage } from "../group-routing/messages.js";
4
- import { type Conversations } from "../conversations.js";
4
+ import { type ChatArchive } from "../chat-archive.js";
5
5
  import type { AgentIdentities } from "../identities.js";
6
6
  import { type PendingQuestion } from "../questions.js";
7
7
  import { type HistoryReader, type RecordedEvent } from "./sessions.js";
@@ -32,5 +32,5 @@ export declare function refusalReason(data: {
32
32
  readonly output?: unknown;
33
33
  readonly error?: unknown;
34
34
  }): string | undefined;
35
- export declare function telegramConfirmationEvents(archive?: Conversations, scope?: () => "chat" | "thread"): TelegramChannelEvents & Pick<ChannelEvents<TelegramEventContext>, "context.settled">;
35
+ export declare function telegramConfirmationEvents(archive?: ChatArchive, scope?: () => "chat" | "thread"): TelegramChannelEvents & Pick<ChannelEvents<TelegramEventContext>, "context.settled">;
36
36
  export declare const confirmationEvents: TelegramChannelEvents & Pick<ChannelEvents<TelegramEventContext>, "context.settled">;
@@ -9,12 +9,12 @@ import { confirmations } from "../confirmations.mjs";
9
9
  import { humanText } from "../confirmation-description.mjs";
10
10
  import { withConfirmationPrompt } from "../group-routing/messages.mjs";
11
11
  import { chatPostOperationId, isChatPost } from "../chat-post-confirmation.mjs";
12
- import { conversationEvent } from "../conversations.mjs";
12
+ import { chatEvent } from "../chat-archive.mjs";
13
13
  import { chatPostCard, chatPostCardStatus, chatPostReceipt, withChatPostCard } from "./chat-post-card.mjs";
14
14
  import { answerMarker, isPendingQuestion, pendingQuestions, questionKey } from "../questions.mjs";
15
15
  import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-DgQB4g1J.mjs";
16
16
  import { confirmationStatus, renderConfirmation, withConfirmationText } from "./confirmation-text.mjs";
17
- import { i as memberIdOf, o as telegramPrincipal } from "../../../_chunks/principal-BIX7T6Hh.mjs";
17
+ import { i as memberIdOf, o as telegramPrincipal } from "../../../_chunks/principal-nQ_gwLJs.mjs";
18
18
  import { formatAddress, scopedAddress } from "./sessions.mjs";
19
19
  import { createHash } from "node:crypto";
20
20
  import { telegramTextLinks } from "@segmentstream/ontology/telegram";
@@ -218,7 +218,7 @@ function telegramConfirmationEvents(archive, scope) {
218
218
  if (archive === void 0 || saved?.description?.chatPost === void 0 || saved.source === void 0) return;
219
219
  const operationId = chatPostOperationId(ctx.session.id, callId);
220
220
  const source = saved.source;
221
- const append = () => archive.append(conversationEvent({
221
+ const append = () => archive.append(chatEvent({
222
222
  eventId: `chat-post:${operationId}:${phase}`,
223
223
  provider: "telegram",
224
224
  chatId: source.chatId,
@@ -1,15 +1,15 @@
1
- import { type ConversationEvent, type Conversations } from "../conversations.js";
1
+ import { type ChatEvent, type ChatArchive } from "../chat-archive.js";
2
2
  interface Diagnostic {
3
3
  readonly errorId: string;
4
4
  readonly operation: string;
5
5
  readonly error: unknown;
6
6
  readonly metadata: Record<string, unknown>;
7
7
  }
8
- type DeliveryScope = Pick<ConversationEvent, "chatId" | "chatType" | "threadId" | "sessionId" | "turnId">;
8
+ type DeliveryScope = Pick<ChatEvent, "chatId" | "chatType" | "threadId" | "sessionId" | "turnId">;
9
9
  /** Receives the same credential-redacted payload as operator logs, never raw provider errors. */
10
10
  export declare function retainDeliveryDiagnostic(diagnostic: Diagnostic): void;
11
11
  /** The session and turn a channel callback delivers for, so its sends are archived as its own. */
12
12
  export declare function currentDeliveryScope(): DeliveryScope | undefined;
13
13
  /** Await archive writes inside the channel callback, including failed or restored callbacks. */
14
- export declare function withDeliveryDiagnostics<T>(archive: Conversations, scope: DeliveryScope, run: () => T | Promise<T>): Promise<T>;
14
+ export declare function withDeliveryDiagnostics<T>(archive: ChatArchive, scope: DeliveryScope, run: () => T | Promise<T>): Promise<T>;
15
15
  export {};
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { n as contentText, t as CONTENT_CAPS } from "../../../_chunks/content-cDtVnr8Y.mjs";
8
- import { conversationEvent } from "../conversations.mjs";
8
+ import { chatEvent } from "../chat-archive.mjs";
9
9
  import { redactTelegramDiagnostic } from "./diagnostic-redaction.mjs";
10
10
  import { AsyncLocalStorage } from "node:async_hooks";
11
11
  const pending = new AsyncLocalStorage();
@@ -25,7 +25,7 @@ async function withDeliveryDiagnostics(archive, scope, run) {
25
25
  return await run();
26
26
  } finally {
27
27
  for (const diagnostic of diagnostics) try {
28
- await archive.append(conversationEvent({
28
+ await archive.append(chatEvent({
29
29
  ...scope,
30
30
  provider: "telegram",
31
31
  eventId: `telegram:diagnostic:${diagnostic.errorId}`,
@@ -12,7 +12,7 @@ import type { MediaPlan } from "./media-policy.js";
12
12
  * gets a note saying why.
13
13
  */
14
14
  /** The chat an attachment belongs to: `telegram:<chat id>`. */
15
- export declare function telegramConversation(chatId: string): string;
15
+ export declare function telegramChat(chatId: string): string;
16
16
  /** Eve normalizes photos/documents only. Keep other Telegram files available to attachment tools. */
17
17
  export declare function inboundAttachments(message: TelegramMessage): ReadonlyArray<TelegramAttachment>;
18
18
  /** Stores the message's files one after another, so that a large album holds one file at a time. */