@segmentstream/agent 0.42.1 → 0.44.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 (130) hide show
  1. package/CHANGELOG.md +1033 -0
  2. package/README.md +25 -24
  3. package/dist/_chunks/{build-metadata-BPEZ5XVM.mjs → build-metadata-BnufKOxq.mjs} +1 -1
  4. package/dist/_chunks/{inbound-request-DgQB4g1J.mjs → inbound-request-CK0QqEOP.mjs} +36 -1
  5. package/dist/_chunks/{principal-BIX7T6Hh.mjs → principal-BXvelsZk.mjs} +5 -5
  6. package/dist/extension/channels/telegram.mjs +1 -1
  7. package/dist/extension/channels/whatsapp.mjs +1 -1
  8. package/dist/extension/config.d.ts +26 -18
  9. package/dist/extension/config.mjs +65 -12
  10. package/dist/extension/conventions.d.ts +1 -1
  11. package/dist/extension/conventions.mjs +22 -19
  12. package/dist/extension/extension.d.ts +2 -2
  13. package/dist/extension/extension.mjs +3 -3
  14. package/dist/extension/hooks/authorization.mjs +1 -1
  15. package/dist/extension/hooks/{conversations.mjs → chat-recorder.mjs} +4 -4
  16. package/dist/extension/hooks/sandbox.d.ts +2 -2
  17. package/dist/extension/instructions/{conversations.mjs → chat-context.mjs} +2 -2
  18. package/dist/extension/instructions/persona.mjs +1 -1
  19. package/dist/extension/instructions/sandbox.mjs +2 -2
  20. package/dist/extension/instructions.md +10 -10
  21. package/dist/extension/lib/actor.mjs +1 -1
  22. package/dist/extension/lib/attachment-tools.d.ts +1 -1
  23. package/dist/extension/lib/attachment-tools.mjs +7 -7
  24. package/dist/extension/lib/attachments.d.ts +9 -4
  25. package/dist/extension/lib/attachments.mjs +9 -7
  26. package/dist/extension/lib/build-metadata.mjs +1 -1
  27. package/dist/extension/lib/chat-address.d.ts +33 -0
  28. package/dist/extension/lib/{conversation.mjs → chat-address.mjs} +13 -12
  29. package/dist/extension/lib/{conversations.d.ts → chat-archive.d.ts} +12 -12
  30. package/dist/extension/lib/{conversations.mjs → chat-archive.mjs} +9 -9
  31. package/dist/extension/lib/chat-context.d.ts +5 -5
  32. package/dist/extension/lib/chat-context.mjs +7 -7
  33. package/dist/extension/lib/{conversation-runtime.d.ts → chat-recorder.d.ts} +3 -3
  34. package/dist/extension/lib/{conversation-runtime.mjs → chat-recorder.mjs} +13 -13
  35. package/dist/extension/lib/confirmations.d.ts +3 -3
  36. package/dist/extension/lib/confirmations.mjs +8 -8
  37. package/dist/extension/lib/group-routing/addressing.d.ts +1 -1
  38. package/dist/extension/lib/group-routing/addressing.mjs +2 -2
  39. package/dist/extension/lib/group-routing/burst.mjs +2 -2
  40. package/dist/extension/lib/group-routing/{conversation-prompt.d.ts → chat-prompt.d.ts} +2 -2
  41. package/dist/extension/lib/group-routing/{conversation-prompt.mjs → chat-prompt.mjs} +3 -3
  42. package/dist/extension/lib/group-routing/{conversation-router.d.ts → chat-router.d.ts} +6 -6
  43. package/dist/extension/lib/group-routing/{conversation-router.mjs → chat-router.mjs} +9 -9
  44. package/dist/extension/lib/group-routing/engagement.mjs +2 -2
  45. package/dist/extension/lib/group-routing/messages.d.ts +1 -1
  46. package/dist/extension/lib/group-routing/policy.d.ts +6 -6
  47. package/dist/extension/lib/group-routing/policy.mjs +16 -16
  48. package/dist/extension/lib/group-routing/replay.mjs +36 -9
  49. package/dist/extension/lib/group-routing/router.d.ts +3 -3
  50. package/dist/extension/lib/group-routing/router.mjs +16 -16
  51. package/dist/extension/lib/group-routing/routing-context.d.ts +2 -2
  52. package/dist/extension/lib/group-routing/routing-context.mjs +2 -2
  53. package/dist/extension/lib/group-routing/signals.d.ts +3 -3
  54. package/dist/extension/lib/group-routing/signals.mjs +5 -5
  55. package/dist/extension/lib/model-service-alert.d.ts +2 -2
  56. package/dist/extension/lib/model-service-alert.mjs +2 -2
  57. package/dist/extension/lib/ontology-connection.mjs +1 -1
  58. package/dist/extension/lib/ontology-file-call.mjs +1 -1
  59. package/dist/extension/lib/ontology-tools.mjs +1 -1
  60. package/dist/extension/lib/review/hold.d.ts +7 -7
  61. package/dist/extension/lib/review/hold.mjs +12 -12
  62. package/dist/extension/lib/review/judge.d.ts +9 -9
  63. package/dist/extension/lib/review/judge.mjs +12 -12
  64. package/dist/extension/lib/review/reply.d.ts +13 -13
  65. package/dist/extension/lib/review/reply.mjs +20 -20
  66. package/dist/extension/lib/role-skill.mjs +1 -1
  67. package/dist/extension/lib/runtime-envelope.mjs +1 -1
  68. package/dist/extension/lib/sent-files.mjs +3 -2
  69. package/dist/extension/lib/slack/adapter.mjs +2 -2
  70. package/dist/extension/lib/slack/attachments-send.d.ts +2 -2
  71. package/dist/extension/lib/slack/attachments-send.mjs +6 -6
  72. package/dist/extension/lib/slack/files.mjs +4 -4
  73. package/dist/extension/lib/stored-files.mjs +1 -1
  74. package/dist/extension/lib/telegram/adapter.d.ts +4 -3
  75. package/dist/extension/lib/telegram/adapter.mjs +35 -15
  76. package/dist/extension/lib/telegram/app-links.d.ts +39 -0
  77. package/dist/extension/lib/telegram/app-links.mjs +53 -0
  78. package/dist/extension/lib/telegram/attachment-description.mjs +1 -1
  79. package/dist/extension/lib/telegram/attachments-send.mjs +2 -2
  80. package/dist/extension/lib/telegram/callbacks.mjs +2 -2
  81. package/dist/extension/lib/telegram/{conversations.d.ts → chat-archive.d.ts} +7 -7
  82. package/dist/extension/lib/telegram/{conversations.mjs → chat-archive.mjs} +11 -11
  83. package/dist/extension/lib/telegram/confirmation-text.mjs +1 -0
  84. package/dist/extension/lib/telegram/confirmations.d.ts +2 -2
  85. package/dist/extension/lib/telegram/confirmations.mjs +4 -4
  86. package/dist/extension/lib/telegram/customer-text.d.ts +2 -1
  87. package/dist/extension/lib/telegram/customer-text.mjs +1 -1
  88. package/dist/extension/lib/telegram/delivery-diagnostics.d.ts +3 -3
  89. package/dist/extension/lib/telegram/delivery-diagnostics.mjs +2 -2
  90. package/dist/extension/lib/telegram/files.d.ts +1 -1
  91. package/dist/extension/lib/telegram/files.mjs +9 -9
  92. package/dist/extension/lib/telegram/health.mjs +1 -1
  93. package/dist/extension/lib/telegram/images.mjs +1 -1
  94. package/dist/extension/lib/telegram/inbound-request.d.ts +1 -1
  95. package/dist/extension/lib/telegram/inbound-request.mjs +1 -1
  96. package/dist/extension/lib/telegram/inbound.d.ts +3 -3
  97. package/dist/extension/lib/telegram/inbound.mjs +37 -37
  98. package/dist/extension/lib/telegram/lifecycle.mjs +4 -4
  99. package/dist/extension/lib/telegram/media-policy.mjs +1 -1
  100. package/dist/extension/lib/telegram/principal.d.ts +2 -2
  101. package/dist/extension/lib/telegram/principal.mjs +1 -1
  102. package/dist/extension/lib/telegram/router.mjs +2 -2
  103. package/dist/extension/lib/telegram/session-recovery.mjs +1 -1
  104. package/dist/extension/lib/telegram/sessions.d.ts +1 -1
  105. package/dist/extension/lib/telegram/signals.mjs +1 -1
  106. package/dist/extension/lib/telegram/silent.d.ts +2 -2
  107. package/dist/extension/lib/telegram/silent.mjs +1 -1
  108. package/dist/extension/lib/telegram/structured.mjs +1 -1
  109. package/dist/extension/lib/telegram/turn-errors.d.ts +2 -2
  110. package/dist/extension/lib/telegram/turn-errors.mjs +3 -3
  111. package/dist/extension/lib/telegram/voice.d.ts +1 -1
  112. package/dist/extension/lib/telegram/voice.mjs +1 -1
  113. package/dist/extension/lib/whatsapp/adapter.d.ts +2 -2
  114. package/dist/extension/lib/whatsapp/adapter.mjs +4 -2
  115. package/dist/extension/lib/whatsapp/links.d.ts +12 -0
  116. package/dist/extension/lib/whatsapp/links.mjs +34 -0
  117. package/dist/extension/lib/workflow-serializable.d.ts +1 -1
  118. package/dist/extension/model.mjs +1 -1
  119. package/dist/extension/personas.d.ts +1 -1
  120. package/dist/extension/review.d.ts +23 -20
  121. package/dist/extension/review.mjs +21 -34
  122. package/dist/extension/tools/attachments_promote.mjs +1 -1
  123. package/dist/extension/tools/attachments_send.mjs +3 -3
  124. package/dist/extension/tools/no_reply.d.ts +1 -1
  125. package/dist/extension/tools/questions_ask.mjs +4 -4
  126. package/dist/extension/tools/sandbox.mjs +2 -2
  127. package/package.json +3 -2
  128. package/dist/extension/lib/conversation.d.ts +0 -33
  129. /package/dist/extension/hooks/{conversations.d.ts → chat-recorder.d.ts} +0 -0
  130. /package/dist/extension/instructions/{conversations.d.ts → chat-context.d.ts} +0 -0
@@ -6,10 +6,10 @@ __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { WorkspaceActionAlreadyDispatched } from "./workspace-action.mjs";
8
8
  import { structuredMessage } from "./structured.mjs";
9
- import { d as telegramRuntimeSource, n as conversationLanguage, o as telegramPrincipal, u as runtimeEnvelope } from "../../../_chunks/principal-BIX7T6Hh.mjs";
9
+ import { d as telegramRuntimeSource, n as chatLanguage, o as telegramPrincipal, u as runtimeEnvelope } from "../../../_chunks/principal-BXvelsZk.mjs";
10
10
  import { routingBurst } from "../group-routing/burst.mjs";
11
11
  import { telegramSignals } from "./signals.mjs";
12
- import { addressingReason, conversationKey, otherRecipient } from "../group-routing/signals.mjs";
12
+ import { addressingReason, chatKey, otherRecipient } from "../group-routing/signals.mjs";
13
13
  import { effectiveGroupPolicy, groupPolicy } from "../group-routing/policy.mjs";
14
14
  import { questionInvitation } from "../group-routing/engagement.mjs";
15
15
  import { AttachmentLifecycleNotPermitted } from "./lifecycle.mjs";
@@ -27,10 +27,10 @@ import { routingContext } from "./routing-context.mjs";
27
27
  import { formatAddress, messageAddress, scopedAddress } from "./sessions.mjs";
28
28
  import { voiceOf, voiceText } from "./voice.mjs";
29
29
  import { MAXIMUM_ROUTING_ATTACHMENT_BYTES, describeRoutingAttachment, routingAttachmentDeadline } from "./attachment-description.mjs";
30
- import { recordGateDecision, recordInboundContent, recordRouteDecision } from "./conversations.mjs";
30
+ import { recordGateDecision, recordInboundContent, recordRouteDecision } from "./chat-archive.mjs";
31
31
  import { contentShape, messageContent } from "./content.mjs";
32
32
  import { messageAudience } from "./audience.mjs";
33
- import { p as reportTelegramError } from "../../../_chunks/inbound-request-DgQB4g1J.mjs";
33
+ import { p as reportTelegramError } from "../../../_chunks/inbound-request-CK0QqEOP.mjs";
34
34
  const MAXIMUM_QUOTE_LENGTH = 500;
35
35
  function buttonTo(text, url) {
36
36
  return { inline_keyboard: [[{
@@ -91,7 +91,7 @@ function speakerBlock(input) {
91
91
  if (isRecord(raw)) {
92
92
  const from = isRecord(raw.from) ? raw.from : {};
93
93
  const author = from.is_bot === true && bot !== void 0 && String(from.id) === bot.id ? "the agent" : typeof from.username === "string" ? `@${from.username}` : typeof from.first_name === "string" ? from.first_name : "unknown sender";
94
- const text = input.omitQuote ? "[confirmation; see conversation context]" : messageContent(raw).text;
94
+ const text = input.omitQuote ? "[confirmation; see chat context]" : messageContent(raw).text;
95
95
  const quoted = text.length > MAXIMUM_QUOTE_LENGTH ? `${text.slice(0, MAXIMUM_QUOTE_LENGTH)}…` : text;
96
96
  lines.push(`reply_to: ${author}: ${JSON.stringify(quoted)}`);
97
97
  }
@@ -298,16 +298,16 @@ async function handleInboundMessage(input) {
298
298
  const turn = structured === void 0 && input.request?.structuredContext === void 0 && addressed !== void 0 && hasContent && (addressed !== "reply-to-bot" || elsewhere === void 0);
299
299
  const lookup = await resolve(turn);
300
300
  const group = isGroupChat(sent);
301
- const freshConversation = async () => await dependencies.recentConversation?.(sent.chat.id, sent.messageThreadId === void 0 ? void 0 : String(sent.messageThreadId)) ?? [];
301
+ const freshChat = async () => await dependencies.recentChat?.(sent.chat.id, sent.messageThreadId === void 0 ? void 0 : String(sent.messageThreadId)) ?? [];
302
302
  let archived;
303
- const recentConversation = () => archived ??= freshConversation();
303
+ const recentChat = () => archived ??= freshChat();
304
304
  const languageOf = async (current) => {
305
- const own = conversationLanguage([current]);
305
+ const own = chatLanguage([current]);
306
306
  if (own !== void 0) return own;
307
307
  try {
308
- return conversationLanguage((await recentConversation()).map((message) => message.text).reverse());
308
+ return chatLanguage((await recentChat()).map((message) => message.text).reverse());
309
309
  } catch (error) {
310
- reportTelegramError("conversation_language_unavailable", error, { chatId: sent.chat.id });
310
+ reportTelegramError("chat_language_unavailable", error, { chatId: sent.chat.id });
311
311
  return;
312
312
  }
313
313
  };
@@ -439,7 +439,7 @@ async function handleInboundMessage(input) {
439
439
  const principal = telegramPrincipal({
440
440
  message: sent,
441
441
  member,
442
- conversationLanguage: await languageOf(sent.text || sent.caption)
442
+ chatLanguage: await languageOf(sent.text || sent.caption)
443
443
  });
444
444
  input.request.lifecycle = dependencies.lifecycle(principal, member.id, sent);
445
445
  await context.telegram.startTyping();
@@ -520,10 +520,10 @@ async function handleInboundMessage(input) {
520
520
  const groups = effectiveGroupPolicy(dependencies.groups ?? groupPolicy({}, {
521
521
  mode: dependencies.policy,
522
522
  model: dependencies.decisionModel
523
- }), conversationKey(policySignals));
524
- const conversationPolicy = group && groups.smart.engagement.policy === "conversation";
525
- let conversationRecent = conversationPolicy ? await recentConversation() : [];
526
- if (conversationPolicy && input.request && input.request.lifecycleKey === void 0 && input.request.structuredContext === void 0) {
523
+ }), chatKey(policySignals));
524
+ const chatPolicy = group && groups.smart.engagement.policy === "chat";
525
+ let chatRecent = chatPolicy ? await recentChat() : [];
526
+ if (chatPolicy && input.request && input.request.lifecycleKey === void 0 && input.request.structuredContext === void 0) {
527
527
  address = topicAddress;
528
528
  input.request.address = topicAddress;
529
529
  input.request.turnPolicy = "steer";
@@ -537,12 +537,12 @@ async function handleInboundMessage(input) {
537
537
  });
538
538
  const questionAge = Date.parse(sentAt(sent)) - Date.parse(asked?.meta.at ?? "");
539
539
  if (answering && addressed === void 0 && !questionInvitation(asked?.meta.at, sentAt(sent), groups.smart.engagement.openQuestionMinutes)) answering = false;
540
- const recipientAnswer = !conversationPolicy && answering && (groups.smart.engagement.policy === "engaged" || questionAge >= 0 && questionAge <= groups.smart.engagement.followUpMinutes * 6e4) && audience.replyTo?.kind === "bot" && isRecipientAnswer(audience);
541
- if (!conversationPolicy && answering && pending !== void 0 && input.request !== void 0) {
540
+ const recipientAnswer = !chatPolicy && answering && (groups.smart.engagement.policy === "engaged" || questionAge >= 0 && questionAge <= groups.smart.engagement.followUpMinutes * 6e4) && audience.replyTo?.kind === "bot" && isRecipientAnswer(audience);
541
+ if (!chatPolicy && answering && pending !== void 0 && input.request !== void 0) {
542
542
  address = pending.address || (questionSession === void 0 ? topicAddress : memberQuestionAddress);
543
543
  input.request.address = address;
544
544
  }
545
- if (input.request?.lifecycleKey === void 0 && input.request?.structuredContext === void 0 && group && (addressed === void 0 && !answering && groups.mode === "mention" || !conversationPolicy && elsewhere !== void 0 && (addressed === void 0 || addressed === "reply-to-bot" && !recipientAnswer))) {
545
+ if (input.request?.lifecycleKey === void 0 && input.request?.structuredContext === void 0 && group && (addressed === void 0 && !answering && groups.mode === "mention" || !chatPolicy && elsewhere !== void 0 && (addressed === void 0 || addressed === "reply-to-bot" && !recipientAnswer))) {
546
546
  await recordContent({
547
547
  text: text || (structured === void 0 ? text : `[${structured.kind}]`),
548
548
  decoded
@@ -553,7 +553,7 @@ async function handleInboundMessage(input) {
553
553
  });
554
554
  return null;
555
555
  }
556
- if (!conversationPolicy && hasContent && answering && !await admitTurn(true)) {
556
+ if (!chatPolicy && hasContent && answering && !await admitTurn(true)) {
557
557
  await observeRaw();
558
558
  return null;
559
559
  }
@@ -561,11 +561,11 @@ async function handleInboundMessage(input) {
561
561
  await observeRaw();
562
562
  return null;
563
563
  }
564
- if (group && !conversationPolicy) conversationRecent = (await recentConversation()).filter((message) => message.messageId !== sent.messageId).map(({ signedAuthor, ...message }) => signedAuthor === void 0 ? message : {
564
+ if (group && !chatPolicy) chatRecent = (await recentChat()).filter((message) => message.messageId !== sent.messageId).map(({ signedAuthor, ...message }) => signedAuthor === void 0 ? message : {
565
565
  ...message,
566
566
  author: signedAuthor
567
567
  });
568
- const carried = observedImages(conversationRecent, sent.messageId);
568
+ const carried = observedImages(chatRecent, sent.messageId);
569
569
  const mediaPlan = voice !== void 0 || sent.attachments.length > 0 || carried.length > 0 ? await dependencies.mediaPlan?.(member, owner?.id) : void 0;
570
570
  if (voice !== void 0 && !group) await transcribeVoice(false);
571
571
  if (voice !== void 0 && mediaPlan?.audio) notes.push("[The chat model supports audio, but this host cannot deliver native audio. The configured speech-to-text fallback was used if enabled.]");
@@ -602,7 +602,7 @@ async function handleInboundMessage(input) {
602
602
  let classified = false;
603
603
  let uncertain = false;
604
604
  let question;
605
- const conversation = async () => {
605
+ const routeQuestion = async () => {
606
606
  if (question !== void 0) return question;
607
607
  await report;
608
608
  const context = await routingContext({
@@ -611,7 +611,7 @@ async function handleInboundMessage(input) {
611
611
  address,
612
612
  operations,
613
613
  read: dependencies.history ?? dependencies.readHistory,
614
- remembered: conversationRecent,
614
+ remembered: chatRecent,
615
615
  at: sentAt(sent),
616
616
  questionHistory,
617
617
  questionSessionId: owner?.id
@@ -640,7 +640,7 @@ async function handleInboundMessage(input) {
640
640
  aliases
641
641
  },
642
642
  chat: group ? chatContext(dependencies.chats.chat(sent.chat.id)) : [],
643
- recent: conversationPolicy ? conversationRecent : context.recent,
643
+ recent: chatPolicy ? chatRecent : context.recent,
644
644
  pendingConfirmations: context.pendingConfirmations,
645
645
  pendingQuestions: context.pendingQuestions.filter((question) => question.chatId === sent.chat.id && question.messageThreadId === String(sent.messageThreadId ?? "")),
646
646
  message: observedMessage(sent, text, member, media, bot),
@@ -649,7 +649,7 @@ async function handleInboundMessage(input) {
649
649
  };
650
650
  return question;
651
651
  };
652
- if (conversationPolicy && input.request?.lifecycleKey === void 0 && input.request?.structuredContext === void 0) {
652
+ if (chatPolicy && input.request?.lifecycleKey === void 0 && input.request?.structuredContext === void 0) {
653
653
  if (voice !== void 0) await transcribeVoice(true);
654
654
  const routingSignals = {
655
655
  ...policySignals,
@@ -658,8 +658,8 @@ async function handleInboundMessage(input) {
658
658
  text
659
659
  }
660
660
  };
661
- const burst = routingBurst(routingSignals, conversationRecent, groups);
662
- const q = await conversation();
661
+ const burst = routingBurst(routingSignals, chatRecent, groups);
662
+ const q = await routeQuestion();
663
663
  question = {
664
664
  ...q,
665
665
  signals: routingSignals,
@@ -739,8 +739,8 @@ async function handleInboundMessage(input) {
739
739
  decoded,
740
740
  ...processedMedia === void 0 ? {} : { media: processedMedia }
741
741
  });
742
- if (conversationPolicy) {
743
- const current = await conversation();
742
+ if (chatPolicy) {
743
+ const current = await routeQuestion();
744
744
  const message = {
745
745
  ...current.message,
746
746
  text,
@@ -752,7 +752,7 @@ async function handleInboundMessage(input) {
752
752
  messagesToClassify: current.messagesToClassify?.map((m) => m.messageId === message.messageId ? message : m)
753
753
  };
754
754
  }
755
- return conversation();
755
+ return routeQuestion();
756
756
  }
757
757
  });
758
758
  if (route === "reply" && input.request !== void 0) input.request.engaged = true;
@@ -799,7 +799,7 @@ async function handleInboundMessage(input) {
799
799
  memberId: member.id
800
800
  };
801
801
  try {
802
- if (input.request?.recordStructuredContext === void 0) throw new Error("A structured continuation requires durable conversation capture.");
802
+ if (input.request?.recordStructuredContext === void 0) throw new Error("A structured continuation requires durable chat capture.");
803
803
  await input.request.recordStructuredContext(result.context, member.id);
804
804
  } catch (error) {
805
805
  reportTelegramError("workspace_structured_context_recording_failed", error);
@@ -880,7 +880,7 @@ async function handleInboundMessage(input) {
880
880
  try {
881
881
  outcome = { result: (await dependencies.attachments.promote({
882
882
  memberId: member.id,
883
- conversation: `telegram:${sent.chat.id}`
883
+ chat: `telegram:${sent.chat.id}`
884
884
  }, file.attachment.id, {
885
885
  ...stored.retain,
886
886
  runtime: runtimeEnvelope({ source: telegramRuntimeSource(sent, files) })
@@ -1001,7 +1001,7 @@ async function handleInboundMessage(input) {
1001
1001
  }
1002
1002
  if (voice !== void 0 && input.request !== void 0) input.request.text = text;
1003
1003
  else if (voice !== void 0) notes.push(text);
1004
- if (!conversationPolicy && answering && pending !== void 0 && input.request !== void 0) {
1004
+ if (!chatPolicy && answering && pending !== void 0 && input.request !== void 0) {
1005
1005
  input.request.replyTo = pending.replyToMessageId ?? input.request.replyTo;
1006
1006
  input.request.lifecycleKey = pending.taskId ?? input.request.lifecycleKey;
1007
1007
  input.request.text = `${answerMarker(pending.id)}\n${text}`;
@@ -1027,7 +1027,7 @@ async function handleInboundMessage(input) {
1027
1027
  data: attachmentUrl({
1028
1028
  id: image.id,
1029
1029
  memberId: member.id,
1030
- conversation: `telegram:${sent.chat.id}`
1030
+ chat: `telegram:${sent.chat.id}`
1031
1031
  }),
1032
1032
  mediaType: image.contentType,
1033
1033
  filename: image.filename
@@ -1035,7 +1035,7 @@ async function handleInboundMessage(input) {
1035
1035
  });
1036
1036
  }
1037
1037
  const language = await languageOf(text);
1038
- const confirmationReply = (group ? await conversation() : void 0)?.recent.some((entry) => "role" in entry && entry.confirmation !== void 0 && entry.messageId === audience.replyTo?.messageId) === true;
1038
+ const confirmationReply = (group ? await routeQuestion() : void 0)?.recent.some((entry) => "role" in entry && entry.confirmation !== void 0 && entry.messageId === audience.replyTo?.messageId) === true;
1039
1039
  const beginTurnDispatch = structuredDispatched ? input.request?.beginStructuredContinuation : input.request?.beginDispatch;
1040
1040
  if (beginTurnDispatch !== void 0 && !await beginTurnDispatch()) {
1041
1041
  recordGateDecision("message_already_handled");
@@ -1047,7 +1047,7 @@ async function handleInboundMessage(input) {
1047
1047
  text
1048
1048
  },
1049
1049
  member,
1050
- conversationLanguage: language
1050
+ chatLanguage: language
1051
1051
  });
1052
1052
  const [guidance] = group ? chatContext(dependencies.chats.chat(sent.chat.id)) : [];
1053
1053
  if (guidance !== void 0) principal = {
@@ -1095,7 +1095,7 @@ async function handleInboundMessage(input) {
1095
1095
  bot_tagged: audience.botTagged,
1096
1096
  reply_target: confirmationReply && audience.replyTo !== null ? Object.fromEntries(Object.entries(audience.replyTo).filter(([key]) => key !== "text")) : audience.replyTo,
1097
1097
  tagged_users: audience.mentions,
1098
- ...conversationPolicy ? { engagement_policy: "conversation" } : {},
1098
+ ...chatPolicy ? { engagement_policy: "chat" } : {},
1099
1099
  ...uncertain ? { routing: "uncertain" } : {}
1100
1100
  }) + "\n</message_audience>",
1101
1101
  ...attachmentsContext({
@@ -4,9 +4,9 @@ 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 { d as telegramRuntimeSource, l as principalRuntimeSource, u as runtimeEnvelope } from "../../../_chunks/principal-BIX7T6Hh.mjs";
8
- import { t as agentBuild } from "../../../_chunks/build-metadata-BPEZ5XVM.mjs";
9
- import { n as currentInboundRequest } from "../../../_chunks/inbound-request-DgQB4g1J.mjs";
7
+ import { d as telegramRuntimeSource, l as principalRuntimeSource, u as runtimeEnvelope } from "../../../_chunks/principal-BXvelsZk.mjs";
8
+ import { t as agentBuild } from "../../../_chunks/build-metadata-BnufKOxq.mjs";
9
+ import { n as currentInboundRequest } from "../../../_chunks/inbound-request-CK0QqEOP.mjs";
10
10
  import { object } from "../confirmation-description.mjs";
11
11
  import { needsConfirmation } from "../confirmations.mjs";
12
12
  import { OntologyActionNotPermitted, actionToolName, ontologyTools } from "../ontology-tools.mjs";
@@ -39,7 +39,7 @@ function attachmentLifecycle(options) {
39
39
  topic: String(options.message.messageThreadId ?? ""),
40
40
  message: options.message.messageId,
41
41
  sender: options.message.from.id,
42
- locale: String(options.principal.attributes.conversationLanguage ?? options.principal.attributes.locale ?? "en")
42
+ locale: String(options.principal.attributes.chatLanguage ?? options.principal.attributes.conversationLanguage ?? options.principal.attributes.locale ?? "en")
43
43
  },
44
44
  data: {
45
45
  ...data,
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { DEFAULT_IMAGE_DESCRIPTION_MODEL } from "../../config.mjs";
8
- import { p as reportTelegramError } from "../../../_chunks/inbound-request-DgQB4g1J.mjs";
8
+ import { p as reportTelegramError } from "../../../_chunks/inbound-request-CK0QqEOP.mjs";
9
9
  function planMedia(capabilities, descriptionModel = null) {
10
10
  if (typeof descriptionModel === "string") return {
11
11
  images: "describe",
@@ -13,11 +13,11 @@ export declare function telegramPrincipal(input: {
13
13
  readonly from: NonNullable<TelegramMessage["from"]>;
14
14
  };
15
15
  readonly member: PairedMember;
16
- readonly conversationLanguage?: string;
16
+ readonly chatLanguage?: string;
17
17
  readonly callbackQueryId?: string;
18
18
  }): SessionAuthContext;
19
19
  /** Short answers and attachment-only turns retain the recent chat language when known. */
20
- export declare function conversationLanguage(texts: readonly string[]): "ru" | "en" | undefined;
20
+ export declare function chatLanguage(texts: readonly string[]): "ru" | "en" | undefined;
21
21
  /**
22
22
  * The member a session principal acts for: `memberId` stamped by a SegmentStream channel. A task
23
23
  * session acts for no member; `actorOf` in `lib/actor.ts` names whom any session acts for.
@@ -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 TELEGRAM_AUTHENTICATOR, n as conversationLanguage, r as identityProviderOf, i as memberIdOf, a as rolesOf, o as telegramPrincipal } from "../../../_chunks/principal-BIX7T6Hh.mjs";
7
+ export { t as TELEGRAM_AUTHENTICATOR, n as chatLanguage, r as identityProviderOf, i as memberIdOf, a as rolesOf, o as telegramPrincipal } from "../../../_chunks/principal-BXvelsZk.mjs";
@@ -6,11 +6,11 @@ __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { telegramSignals } from "./signals.mjs";
8
8
  import { addressingReason as addressingReason$1 } from "../group-routing/signals.mjs";
9
- import { FOLLOW_UP_WINDOW_MS, conversationContext, decisionRouter, routeMessage } from "../group-routing/router.mjs";
9
+ import { FOLLOW_UP_WINDOW_MS, decisionRouter, routeMessage, routingEvidence } from "../group-routing/router.mjs";
10
10
  function addressingReason(message, bot) {
11
11
  return addressingReason$1(telegramSignals(message, bot));
12
12
  }
13
13
  function isAddressed(message, bot) {
14
14
  return addressingReason(message, bot) !== void 0;
15
15
  }
16
- export { FOLLOW_UP_WINDOW_MS, addressingReason, conversationContext, decisionRouter, isAddressed, routeMessage };
16
+ export { FOLLOW_UP_WINDOW_MS, addressingReason, decisionRouter, isAddressed, routeMessage, routingEvidence };
@@ -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 { p as reportTelegramError } from "../../../_chunks/inbound-request-DgQB4g1J.mjs";
7
+ import { p as reportTelegramError } from "../../../_chunks/inbound-request-CK0QqEOP.mjs";
8
8
  import { createHash } from "node:crypto";
9
9
  function strandedRun(error) {
10
10
  if (!(error instanceof Error) || error.name !== "RunKeyFetchError" || !("status" in error) || error.status !== 404) return;
@@ -7,7 +7,7 @@ import type { SessionSettings } from "../../config.js";
7
7
  * a group session spans. Compaction and idle expiry are eve's own: automatic compaction near the
8
8
  * context window and `limits.sessionTimeoutMs` in the workspace's `agent.ts`.
9
9
  */
10
- /** eve's Telegram continuation address: `chat:thread:conversation`, the last two possibly empty. */
10
+ /** eve's Telegram continuation address: `chat:thread:conversationId` (eve's names), the last two possibly empty. */
11
11
  export interface TelegramAddress {
12
12
  readonly chatId: string;
13
13
  readonly messageThreadId: string;
@@ -13,7 +13,7 @@ function telegramSignals(message, bot, settings) {
13
13
  const command = /^\/[A-Za-z0-9_]+(?:@(?<target>[A-Za-z0-9_]+))?(?:\s|$)/u.exec(message.text || message.caption);
14
14
  return {
15
15
  provider: "telegram",
16
- conversation: {
16
+ chat: {
17
17
  externalId: message.chat.id,
18
18
  kind: message.chat.type === "private" ? "direct" : "group",
19
19
  title: message.chat.title,
@@ -32,9 +32,9 @@ export interface InterimMessages {
32
32
  * The channel's final reply: formatted and split before Eve's plain-text splitter, with one
33
33
  * queue slot for the whole reply. Explicit silence markers have no delivery. Tool-call steps have
34
34
  * none either unless `interim` is enabled: then their text is delivered exactly like a reply. The
35
- * conversation archive records every delivery for routing and chat context. A text already
35
+ * chat archive records every delivery for routing and chat context. A text already
36
36
  * delivered as an interim message in the same turn, whether a repeat or the final reply, is not
37
- * delivered again. With `review`, a conversation whose replies are reviewed gets no interim
37
+ * delivered again. With `review`, a chat whose replies are reviewed gets no interim
38
38
  * messages, and its final reply is sent only when the review allows it.
39
39
  */
40
40
  export declare function replyDelivery(scope?: () => string, interim?: InterimMessages, review?: ReplyReview): MessageCompleted;
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { confirmationLocale } from "./confirmation-text.mjs";
8
- import { a as TelegramDeliveryError, l as customerMessage, o as currentLocale, p as reportTelegramError } from "../../../_chunks/inbound-request-DgQB4g1J.mjs";
8
+ import { a as TelegramDeliveryError, l as customerMessage, o as currentLocale, p as reportTelegramError } from "../../../_chunks/inbound-request-CK0QqEOP.mjs";
9
9
  import { splitTelegramText } from "./format.mjs";
10
10
  import { inTelegramSendQueue } from "./send-queue.mjs";
11
11
  const NO_REPLY_TOOL = "no_reply";
@@ -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 { d as telegramRuntimeSource, u as runtimeEnvelope } from "../../../_chunks/principal-BIX7T6Hh.mjs";
7
+ import { d as telegramRuntimeSource, u as runtimeEnvelope } from "../../../_chunks/principal-BXvelsZk.mjs";
8
8
  import { workspaceAction } from "./workspace-action.mjs";
9
9
  import { STRUCTURED_KINDS } from "./structured-settings.mjs";
10
10
  const record = (value) => {
@@ -1,8 +1,8 @@
1
1
  import type { TelegramChannelEvents } from "eve/channels/telegram";
2
- import type { Conversations } from "../conversations.js";
2
+ import type { ChatArchive } from "../chat-archive.js";
3
3
  import type { AgentIdentities } from "../identities.js";
4
4
  /** Failure notices for members; an unrecoverable session failure is also recorded to the archive. */
5
5
  export declare function telegramFailureEvents(input: {
6
- readonly archive: Conversations;
6
+ readonly archive: ChatArchive;
7
7
  readonly identities: () => AgentIdentities;
8
8
  }): Pick<TelegramChannelEvents, "turn.settled" | "session.ended" | "interaction.settled" | "interaction.opened">;
@@ -6,9 +6,9 @@ __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { telegramText } from "./texts.mjs";
8
8
  import { confirmationLocale } from "./confirmation-text.mjs";
9
- import { recordSessionFailure } from "./conversations.mjs";
10
- import { c as customerCopy, d as failureText, o as currentLocale, p as reportTelegramError, s as currentThreadId } from "../../../_chunks/inbound-request-DgQB4g1J.mjs";
11
- import { i as memberIdOf } from "../../../_chunks/principal-BIX7T6Hh.mjs";
9
+ import { recordSessionFailure } from "./chat-archive.mjs";
10
+ import { c as customerCopy, d as failureText, o as currentLocale, p as reportTelegramError, s as currentThreadId } from "../../../_chunks/inbound-request-CK0QqEOP.mjs";
11
+ import { i as memberIdOf } from "../../../_chunks/principal-BXvelsZk.mjs";
12
12
  import { modelServiceFailure } from "../model-service-failure.mjs";
13
13
  function telegramFailureEvents(input) {
14
14
  return {
@@ -3,7 +3,7 @@ import { type ConnectionProxy } from "../connection-proxy.js";
3
3
  * Voice, audio and video notes. eve's Telegram parser reads only photos and documents, so these
4
4
  * arrive as a message with no text; the adapter reads them from the raw update, downloads them
5
5
  * through the connection's `file` API and turns them into text with the configured speech-to-text
6
- * model before the conversation sees them, whatever the main model accepts.
6
+ * model before the session sees them, whatever the main model accepts.
7
7
  */
8
8
  export type VoiceKind = "voice" | "audio" | "video_note";
9
9
  export interface VoiceMessage {
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import "../connection-proxy.mjs";
8
- import { p as reportTelegramError } from "../../../_chunks/inbound-request-DgQB4g1J.mjs";
8
+ import { p as reportTelegramError } from "../../../_chunks/inbound-request-CK0QqEOP.mjs";
9
9
  import { gateway, transcribe } from "ai";
10
10
  const LABELS = {
11
11
  voice: "voice message",
@@ -37,7 +37,7 @@ export interface WhatsAppChannelOptions {
37
37
  readonly fetch?: typeof fetch;
38
38
  /** The ontology's pairing routes; tests pass a fake. */
39
39
  readonly identities?: AgentIdentities;
40
- /** Who sends the agent's replies, from `conversations`; without it every reply is sent. */
40
+ /** Who sends the agent's replies, from `review`; without it every reply is sent. */
41
41
  readonly review?: ChannelReviewOptions;
42
42
  }
43
43
  /** What the adapter reads per request: eve binds the mount after it loads the channel. */
@@ -74,7 +74,7 @@ export declare function segmentstreamWhatsApp(options: WhatsAppChannelOptions):
74
74
  * after answering anyone else with the workspace's reply, if it has one.
75
75
  */
76
76
  export declare function receive(input: {
77
- /** The Chat SDK thread: its id names the conversation, one person's chat with the number. */
77
+ /** The Chat SDK thread: its id names the chat, one person's chat with the number. */
78
78
  readonly thread: {
79
79
  readonly id: string;
80
80
  readonly post: (message: string | PostableCard) => Promise<unknown>;
@@ -6,13 +6,14 @@ __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { admitMessage, localizedText } from "../admission.mjs";
8
8
  import { chatSdkButtonAnswer, withButtonDecision } from "../confirmation-buttons.mjs";
9
- import { withConversation } from "../conversation.mjs";
9
+ import { withChatAddress } from "../chat-address.mjs";
10
10
  import { channelReview, withReviewedReplies } from "../review/reply.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";
14
14
  import { agentIdentities } from "../identities.mjs";
15
15
  import { runtimeToken } from "../runtime-token.mjs";
16
+ import { withPlainLinks } from "./links.mjs";
16
17
  import { createHash, createHmac, timingSafeEqual } from "node:crypto";
17
18
  import { createMemoryState } from "@chat-adapter/state-memory";
18
19
  import { WhatsAppAdapter, WhatsAppApiError } from "@chat-adapter/whatsapp";
@@ -41,6 +42,7 @@ var ProxiedWhatsAppAdapter = class extends WhatsAppAdapter {
41
42
  logger: new ConsoleLogger("warn", "whatsapp")
42
43
  });
43
44
  this.#runtime = runtime;
45
+ this.formatConverter = withPlainLinks(this.formatConverter);
44
46
  }
45
47
  async handleWebhook(request, options) {
46
48
  if (!this.#runtime.enabled()) return new Response(null, { status: 404 });
@@ -209,7 +211,7 @@ async function receive(input) {
209
211
  });
210
212
  switch (resolution.status) {
211
213
  case "existing":
212
- case "created": return turn ? withConversation(whatsappPrincipal(resolution.member, sender), {
214
+ case "created": return turn ? withChatAddress(whatsappPrincipal(resolution.member, sender), {
213
215
  provider: "whatsapp",
214
216
  chatId: thread.id,
215
217
  threadId: "",
@@ -0,0 +1,12 @@
1
+ import { type Root } from "chat";
2
+ /** What this module needs of the Chat SDK adapter's Markdown converter. */
3
+ export interface AstRenderer {
4
+ fromAst(ast: Root): string;
5
+ }
6
+ /**
7
+ * The converter with every link written as WhatsApp shows it. WhatsApp has no Markdown link, so a
8
+ * link written `[label](url)` reached the person as written, and a bare URL in angle brackets.
9
+ * Each link becomes `label: url`, or the URL alone when its label is the URL, which WhatsApp makes
10
+ * tappable. The links go in after the Markdown is written, so no character of a URL is escaped.
11
+ */
12
+ export declare function withPlainLinks<T extends AstRenderer>(converter: T): T;
@@ -0,0 +1,34 @@
1
+ import { fileURLToPath as __eveFileURLToPath } from "node:url";
2
+ import { dirname as __eveDirname } from "node:path";
3
+ import { createRequire as __eveCreateRequire } from "node:module";
4
+ const __filename = __eveFileURLToPath(import.meta.url);
5
+ __eveDirname(__filename);
6
+ __eveCreateRequire(import.meta.url);
7
+ import { isLinkNode, walkAst } from "chat";
8
+ const TOKEN = /(\d+)/gu;
9
+ function withPlainLinks(converter) {
10
+ const plain = Object.create(converter);
11
+ plain.fromAst = function fromAst(ast) {
12
+ const links = [];
13
+ const tokenized = walkAst(structuredClone(ast), (node) => {
14
+ if (!isLinkNode(node)) return node;
15
+ links.push(plainLink(textOf(node), node.url));
16
+ return {
17
+ type: "text",
18
+ value: `${links.length - 1}`
19
+ };
20
+ });
21
+ return converter.fromAst.call(this, tokenized).replace(TOKEN, (token, index) => links[Number(index)] ?? token);
22
+ };
23
+ return plain;
24
+ }
25
+ function plainLink(label, url) {
26
+ const text = label.trim();
27
+ const bare = url.replace(/^[a-z][a-z0-9+.-]*:(?:\/\/)?/iu, "");
28
+ return text === "" || text === url ? url : text === bare ? text : `${text}: ${url}`;
29
+ }
30
+ function textOf(node) {
31
+ if ("value" in node && typeof node.value === "string") return node.value;
32
+ return "children" in node && Array.isArray(node.children) ? node.children.map(textOf).join("") : "";
33
+ }
34
+ export { withPlainLinks };
@@ -1,4 +1,4 @@
1
- /** JSON data produced by SDK tools and conversation archive events. */
1
+ /** JSON data produced by SDK tools and chat archive events. */
2
2
  export type WorkflowSerializable = null | boolean | number | string | WorkflowSerializable[] | {
3
3
  [key: string]: WorkflowSerializable;
4
4
  };
@@ -6,7 +6,7 @@ __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { chatModelChoiceOf } from "./config.mjs";
8
8
  import { isPreview } from "./lib/environment.mjs";
9
- import { a as rolesOf } from "../_chunks/principal-BIX7T6Hh.mjs";
9
+ import { a as rolesOf } from "../_chunks/principal-BXvelsZk.mjs";
10
10
  import { defineDynamic } from "eve";
11
11
  import { runs } from "eve/events";
12
12
  function chooseModel(input) {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Personas: what the agent is to the person in a conversation. `agent/segmentstream.json` says
2
+ * Personas: what the agent is to the person in a chat. `agent/segmentstream.json` says
3
3
  * which roles get which persona; each persona's text is `agent/personas/<persona>.md`, which the
4
4
  * SDK reads when the agent is built and the platform puts inline (`personas.texts`) when it
5
5
  * deploys, so the running agent, which has no files, reads the same text. Selection reads only the