@segmentstream/agent 0.48.0 → 0.50.1

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 (91) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/dist/_chunks/{build-metadata-DjhDPTy-.mjs → build-metadata-CLYC7FWE.mjs} +1 -1
  3. package/dist/_chunks/principal-D5Tualrk.mjs +1836 -0
  4. package/dist/extension/channels/slack.mjs +2 -1
  5. package/dist/extension/channels/whatsapp.mjs +1 -0
  6. package/dist/extension/connections/ontology.mjs +1 -1
  7. package/dist/extension/hooks/authorization.mjs +1 -1
  8. package/dist/extension/instructions/persona.mjs +1 -1
  9. package/dist/extension/lib/actor.mjs +1 -46
  10. package/dist/extension/lib/attachment-tools.mjs +1 -3
  11. package/dist/extension/lib/attachments.d.ts +1 -1
  12. package/dist/extension/lib/attachments.mjs +1 -230
  13. package/dist/extension/lib/build-metadata.mjs +1 -1
  14. package/dist/extension/lib/chat-address.mjs +1 -50
  15. package/dist/extension/lib/chat-context.mjs +1 -1
  16. package/dist/extension/lib/chat-recorder.mjs +1 -2
  17. package/dist/extension/lib/confirmations.mjs +1 -179
  18. package/dist/extension/lib/inbound-media/files.d.ts +91 -0
  19. package/dist/extension/lib/inbound-media/files.mjs +7 -0
  20. package/dist/extension/lib/{telegram → inbound-media}/images.d.ts +2 -0
  21. package/dist/extension/lib/{telegram → inbound-media}/images.mjs +1 -2
  22. package/dist/extension/lib/inbound-media/index.d.ts +55 -0
  23. package/dist/extension/lib/inbound-media/index.mjs +7 -0
  24. package/dist/extension/lib/inbound-media/plan.d.ts +59 -0
  25. package/dist/extension/lib/{telegram/media-policy.mjs → inbound-media/plan.mjs} +56 -4
  26. package/dist/extension/lib/inbound-media/report.d.ts +5 -0
  27. package/dist/extension/lib/inbound-media/report.mjs +7 -0
  28. package/dist/extension/lib/inbound-media/speech.d.ts +52 -0
  29. package/dist/extension/lib/inbound-media/speech.mjs +73 -0
  30. package/dist/extension/lib/ontology-connection.mjs +1 -101
  31. package/dist/extension/lib/ontology-file-call.mjs +1 -4
  32. package/dist/extension/lib/ontology-tools.mjs +1 -377
  33. package/dist/extension/lib/review/hold.mjs +1 -2
  34. package/dist/extension/lib/review/reply.mjs +1 -2
  35. package/dist/extension/lib/role-skill.mjs +1 -1
  36. package/dist/extension/lib/runtime-envelope.mjs +1 -1
  37. package/dist/extension/lib/sent-files.mjs +1 -2
  38. package/dist/extension/lib/slack/adapter.d.ts +49 -7
  39. package/dist/extension/lib/slack/adapter.mjs +79 -21
  40. package/dist/extension/lib/slack/attachments-send.mjs +1 -3
  41. package/dist/extension/lib/slack/files.d.ts +12 -19
  42. package/dist/extension/lib/slack/files.mjs +26 -58
  43. package/dist/extension/lib/stored-files.mjs +1 -3
  44. package/dist/extension/lib/telegram/adapter.d.ts +3 -3
  45. package/dist/extension/lib/telegram/adapter.mjs +13 -17
  46. package/dist/extension/lib/telegram/attachment-description.d.ts +1 -1
  47. package/dist/extension/lib/telegram/attachment-description.mjs +2 -2
  48. package/dist/extension/lib/telegram/attachments-send.mjs +1 -3
  49. package/dist/extension/lib/telegram/callbacks.mjs +1 -2
  50. package/dist/extension/lib/telegram/chat-archive.mjs +1 -1
  51. package/dist/extension/lib/telegram/confirmations.mjs +1 -3
  52. package/dist/extension/lib/telegram/customer-text.mjs +1 -1
  53. package/dist/extension/lib/telegram/files.d.ts +8 -15
  54. package/dist/extension/lib/telegram/files.mjs +32 -107
  55. package/dist/extension/lib/telegram/health.mjs +1 -1
  56. package/dist/extension/lib/telegram/held-approvals.mjs +1 -1
  57. package/dist/extension/lib/telegram/inbound-request.d.ts +6 -12
  58. package/dist/extension/lib/telegram/inbound-request.mjs +1 -1
  59. package/dist/extension/lib/telegram/inbound.d.ts +3 -3
  60. package/dist/extension/lib/telegram/inbound.mjs +11 -11
  61. package/dist/extension/lib/telegram/lifecycle.mjs +2 -6
  62. package/dist/extension/lib/telegram/principal.mjs +1 -1
  63. package/dist/extension/lib/telegram/session-recovery.mjs +1 -1
  64. package/dist/extension/lib/telegram/silent.mjs +1 -1
  65. package/dist/extension/lib/telegram/structured.mjs +1 -1
  66. package/dist/extension/lib/telegram/turn-errors.mjs +1 -2
  67. package/dist/extension/lib/telegram/voice.d.ts +7 -38
  68. package/dist/extension/lib/telegram/voice.mjs +1 -64
  69. package/dist/extension/lib/telegram/workspace-action.mjs +1 -3
  70. package/dist/extension/lib/web/auth.mjs +1 -168
  71. package/dist/extension/lib/web/channel.d.ts +13 -4
  72. package/dist/extension/lib/web/channel.mjs +15 -8
  73. package/dist/extension/lib/whatsapp/adapter.d.ts +37 -1
  74. package/dist/extension/lib/whatsapp/adapter.mjs +118 -21
  75. package/dist/extension/lib/whatsapp/files.d.ts +40 -0
  76. package/dist/extension/lib/whatsapp/files.mjs +70 -0
  77. package/dist/extension/lib/workspace-source.mjs +1 -3
  78. package/dist/extension/model.mjs +1 -1
  79. package/dist/extension/tools/attachments_discard.mjs +1 -1
  80. package/dist/extension/tools/attachments_list.mjs +1 -1
  81. package/dist/extension/tools/attachments_promote.mjs +1 -5
  82. package/dist/extension/tools/attachments_read.mjs +1 -1
  83. package/dist/extension/tools/attachments_send.mjs +1 -2
  84. package/dist/extension/tools/attachments_stage.mjs +1 -1
  85. package/dist/extension/tools/attachments_table.mjs +1 -1
  86. package/dist/extension/tools/questions_ask.mjs +1 -2
  87. package/dist/extension/tools/workspace_source.mjs +1 -1
  88. package/package.json +2 -2
  89. package/dist/_chunks/inbound-request-B3RhCuOw.mjs +0 -413
  90. package/dist/_chunks/principal-Dzs8hUDB.mjs +0 -128
  91. package/dist/extension/lib/telegram/media-policy.d.ts +0 -15
@@ -4,10 +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 { MAXIMUM_ATTACHMENT_BYTES, attachmentUrl } from "../attachments.mjs";
8
- import { d as failureText, p as reportTelegramError } from "../../../_chunks/inbound-request-B3RhCuOw.mjs";
9
- import { n as chatLanguage } from "../../../_chunks/principal-Dzs8hUDB.mjs";
10
- import { describableImage, describeReceivedImage } from "./images.mjs";
7
+ import { _t as reportTelegramError, p as storeFiles } from "../../../_chunks/principal-D5Tualrk.mjs";
11
8
  function telegramChat(chatId) {
12
9
  return `telegram:${chatId}`;
13
10
  }
@@ -42,110 +39,38 @@ function described(file, index) {
42
39
  contentType: file.mediaType ?? (file.kind === "photo" ? "image/jpeg" : "application/octet-stream")
43
40
  };
44
41
  }
45
- function megabytes(bytes) {
46
- return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
47
- }
48
42
  async function stageFiles(input) {
49
43
  const { message } = input;
50
- const chat = telegramChat(message.chat.id);
51
- const staged = new Map();
52
- let descriptions = 0;
53
- for (const [index, file] of message.attachments.entries()) {
54
- const { filename, contentType } = described(file, index);
55
- if (file.size !== void 0 && file.size > MAXIMUM_ATTACHMENT_BYTES) {
56
- staged.set(file.fileId, {
57
- status: "refused",
58
- filename,
59
- reason: `it is ${megabytes(file.size)}, over the ${megabytes(MAXIMUM_ATTACHMENT_BYTES)} a bot may download`
60
- });
61
- continue;
62
- }
63
- try {
64
- const bytes = await input.download(file.fileId);
65
- if (bytes.byteLength > MAXIMUM_ATTACHMENT_BYTES) {
66
- staged.set(file.fileId, {
67
- status: "refused",
68
- filename,
69
- reason: "download exceeds 20 MiB"
70
- });
71
- continue;
72
- }
73
- const attachment = await input.attachments.receive({
74
- memberId: input.memberId,
75
- chat
76
- }, {
77
- bytes,
78
- filename,
79
- contentType,
80
- sourceRef: `${message.chat.id}:${message.messageId}:${index}`
81
- });
82
- let description;
83
- let decoded;
84
- let imageInput;
85
- if (input.imagePlan !== void 0 && contentType.startsWith("image/")) {
86
- imageInput = "text";
87
- if (!describableImage(contentType)) description = "[unsupported image format; original remains stored]";
88
- else if (input.imagePlan.images === "native" && bytes.byteLength <= 3145728) imageInput = "native";
89
- else if (input.imagePlan.images === "describe" && input.imagePlan.descriptionModel && input.describeImage) {
90
- decoded = {
91
- attachment_kind: file.kind,
92
- model: input.imagePlan.descriptionModel,
93
- processed: false,
94
- status: "not_processed"
95
- };
96
- description = descriptions >= 1 ? "[image description skipped: per-message limit; original remains stored]" : await describeReceivedImage({
97
- bytes,
98
- mediaType: contentType,
99
- model: input.imagePlan.descriptionModel,
100
- describe: input.describeImage,
101
- retain: (content) => {
102
- decoded = {
103
- attachment_kind: file.kind,
104
- model: input.imagePlan.descriptionModel,
105
- processed: true,
106
- status: "processed",
107
- content
108
- };
109
- }
110
- });
111
- descriptions += 1;
112
- } else description = input.imagePlan.images === "native" ? "[image exceeds the native 3 MiB context limit; original remains stored]" : "[image analysis unavailable or disabled; original remains stored]";
44
+ const files = message.attachments.map((file, index) => ({
45
+ key: file.fileId,
46
+ kind: file.kind === "photo" ? "image" : "document",
47
+ ...described(file, index),
48
+ ...file.size === void 0 ? {} : { size: file.size },
49
+ download: () => input.download(file.fileId)
50
+ }));
51
+ const staged = await storeFiles({
52
+ files,
53
+ memberId: input.memberId,
54
+ chat: telegramChat(message.chat.id),
55
+ source: "telegram",
56
+ sourceRef: (index) => `${message.chat.id}:${message.messageId}:${index}`,
57
+ attachments: input.attachments,
58
+ report: reportTelegramError,
59
+ ...input.imagePlan === void 0 ? {} : { imagePlan: input.imagePlan },
60
+ ...input.describeImage === void 0 ? {} : { describeImage: input.describeImage }
61
+ });
62
+ return new Map([...staged].map(([fileId, file]) => {
63
+ const kind = message.attachments.find((each) => each.fileId === fileId)?.kind;
64
+ return file.status !== "stored" || file.described === void 0 || kind === void 0 ? [fileId, file] : [fileId, {
65
+ ...file,
66
+ decoded: {
67
+ attachment_kind: kind,
68
+ model: file.described.model,
69
+ processed: file.described.content !== void 0,
70
+ status: file.described.content === void 0 ? "not_processed" : "processed",
71
+ ...file.described.content === void 0 ? {} : { content: file.described.content }
113
72
  }
114
- staged.set(file.fileId, {
115
- status: "stored",
116
- attachment,
117
- url: attachmentUrl({
118
- id: attachment.id,
119
- memberId: input.memberId,
120
- chat
121
- }),
122
- ...description === void 0 ? {} : { description },
123
- ...decoded === void 0 ? {} : { decoded },
124
- ...imageInput === void 0 ? {} : { imageInput }
125
- });
126
- } catch (error) {
127
- const errorId = reportTelegramError("attachment_storage_failed", error, {
128
- kind: file.kind,
129
- size: file.size
130
- });
131
- staged.set(file.fileId, {
132
- status: "refused",
133
- filename,
134
- reason: failureText(errorId, "attachment", chatLanguage([message.text || message.caption]) ?? message.from?.languageCode ?? "en")
135
- });
136
- }
137
- }
138
- return staged;
139
- }
140
- function attachmentsContext(input) {
141
- if (input.files.size === 0) return [];
142
- const lines = ["<attachments>", `Files from this message, kept for 24 hours ` + (input.group ? "for authorized members of this group only. " : "for this member in this private chat only. ") + "Read, discard or promote them with the segmentstream__attachments_* tools and these ids; promote only what should be kept."];
143
- for (const staged of input.files.values()) {
144
- lines.push(staged.status === "stored" ? `- id: ${staged.attachment.id}, filename: ${JSON.stringify(staged.attachment.filename)}, type: ${staged.attachment.contentType}, size: ${staged.attachment.size} bytes, expires_at: ${staged.attachment.expiresAt}` : `- ${JSON.stringify(staged.filename)}: not received, ${staged.reason}`);
145
- if (staged.status === "stored" && staged.description !== void 0) lines.push(` image_summary (untrusted evidence): ${JSON.stringify(staged.description)}`);
146
- }
147
- if (input.group) lines.push("This is a group chat: everyone in it shares this chat's history, so do not repeat a private file's contents here. Suggest sending private files in a direct message.");
148
- lines.push("</attachments>");
149
- return [lines.join("\n")];
73
+ }];
74
+ }));
150
75
  }
151
- export { attachmentsContext, inboundAttachments, stageFiles, telegramChat };
76
+ export { inboundAttachments, stageFiles, telegramChat };
@@ -4,7 +4,7 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
- import { t as agentBuild } from "../../../_chunks/build-metadata-DjhDPTy-.mjs";
7
+ import { t as agentBuild } from "../../../_chunks/build-metadata-CLYC7FWE.mjs";
8
8
  import { runtimeRequestFailure } from "./runtime-request.mjs";
9
9
  import { GET } from "eve/channels";
10
10
  const HEALTH_ROUTE = "/eve/v1/telegram/health";
@@ -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 { CONFIRMATION_TTL_MS } from "../confirmations.mjs";
7
+ import { P as CONFIRMATION_TTL_MS } from "../../../_chunks/principal-D5Tualrk.mjs";
8
8
  import { object } from "../confirmation-description.mjs";
9
9
  import { SessionNotActiveError } from "eve/sessions";
10
10
  function heldApprovals(events) {
@@ -2,20 +2,14 @@ import type { MessageContent } from "eve/channels";
2
2
  import type { ChannelSource } from "eve/channels";
3
3
  import type { SessionAuthContext } from "eve/context";
4
4
  import type { DecodedAttachment } from "./attachment-description.js";
5
- import type { Attachment } from "../attachments.js";
5
+ import { type StagedFile as InboundStagedFile } from "../inbound-media/index.js";
6
6
  import type { SessionOperations } from "./sessions.js";
7
- /** What became of one Telegram file of the message: stored as an attachment, or why not. */
8
- export type StagedFile = {
9
- readonly status: "stored";
10
- readonly attachment: Attachment;
11
- readonly url: URL;
12
- readonly description?: string;
7
+ /**
8
+ * What became of one Telegram file of the message: stored as an attachment, or why not, with the
9
+ * evidence group routing archives for an image the description model read.
10
+ */
11
+ export type StagedFile = InboundStagedFile & {
13
12
  readonly decoded?: DecodedAttachment;
14
- readonly imageInput?: "native" | "text";
15
- } | {
16
- readonly status: "refused";
17
- readonly filename: string;
18
- readonly reason: string;
19
13
  };
20
14
  /**
21
15
  * What one webhook request shares between eve's `onMessage` hook and the route wrapper around it.
@@ -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 InboundRequest, n as currentInboundRequest, r as runInboundRequest, i as withReplacedText } from "../../../_chunks/inbound-request-B3RhCuOw.mjs";
7
+ export { s as InboundRequest, c as currentInboundRequest, l as runInboundRequest, u as withReplacedText } from "../../../_chunks/principal-D5Tualrk.mjs";
@@ -10,11 +10,11 @@ import type { AgentIdentities, PairedMember } from "../identities.js";
10
10
  import type { BotIdentityLookup } from "./bot.js";
11
11
  import { type AgentChats } from "../chats.js";
12
12
  import type { InboundRequest } from "./inbound-request.js";
13
- import type { ImageDescriber } from "./images.js";
14
- import type { MediaPlan } from "./media-policy.js";
13
+ import { type ImageDescriber } from "../inbound-media/images.js";
14
+ import type { MediaPlan } from "../inbound-media/plan.js";
15
+ import { type Transcriber } from "../inbound-media/speech.js";
15
16
  import { type RouteDecider } from "./router.js";
16
17
  import { type HistoryReader } from "./sessions.js";
17
- import { type Transcriber } from "./voice.js";
18
18
  import { type AttachmentDescriber } from "./attachment-description.js";
19
19
  /**
20
20
  * eve's Telegram `onMessage` hook, in the order `agent-design.md` gives:
@@ -6,7 +6,7 @@ __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 chatLanguage, o as telegramPrincipal, u as runtimeEnvelope } from "../../../_chunks/principal-Dzs8hUDB.mjs";
9
+ import { C as attachmentUrl, Ct as runtimeEnvelope, _t as reportTelegramError, f as attachmentsContext, n as chatLanguage, o as telegramPrincipal, wt as telegramRuntimeSource } from "../../../_chunks/principal-D5Tualrk.mjs";
10
10
  import { routingBurst } from "../group-routing/burst.mjs";
11
11
  import { telegramSignals } from "./signals.mjs";
12
12
  import { addressingReason, chatKey, otherRecipient } from "../group-routing/signals.mjs";
@@ -17,20 +17,19 @@ import { admitMessage, localizedText } from "../admission.mjs";
17
17
  import { chatContext } from "../chats.mjs";
18
18
  import { questionAddress, questionFromHistory } from "./confirmations.mjs";
19
19
  import { answerMarker } from "../questions.mjs";
20
- import { attachmentsContext, inboundAttachments, stageFiles } from "./files.mjs";
21
- import { attachmentUrl } from "../attachments.mjs";
22
- import { MAXIMUM_NATIVE_IMAGE_BYTES } from "./images.mjs";
20
+ import { inboundAttachments, stageFiles } from "./files.mjs";
21
+ import { MAXIMUM_NATIVE_IMAGE_BYTES } from "../inbound-media/images.mjs";
22
+ import { NATIVE_AUDIO_NOTE, transcribeSpeech } from "../inbound-media/speech.mjs";
23
23
  import { heldApprovals, releaseHeldApproval } from "./held-approvals.mjs";
24
24
  import { attachmentKind, messageMetadata } from "./message-metadata.mjs";
25
25
  import { routeMessage } from "../group-routing/router.mjs";
26
26
  import { routingContext } from "./routing-context.mjs";
27
27
  import { formatAddress, messageAddress, scopedAddress } from "./sessions.mjs";
28
- import { voiceOf, voiceText } from "./voice.mjs";
28
+ import { voiceOf } from "./voice.mjs";
29
29
  import { MAXIMUM_ROUTING_ATTACHMENT_BYTES, describeRoutingAttachment, routingAttachmentDeadline } from "./attachment-description.mjs";
30
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-B3RhCuOw.mjs";
34
33
  const MAXIMUM_QUOTE_LENGTH = 500;
35
34
  function buttonTo(text, url) {
36
35
  return { inline_keyboard: [[{
@@ -346,11 +345,12 @@ async function handleInboundMessage(input) {
346
345
  return;
347
346
  }
348
347
  try {
349
- const transcribe = (abortSignal) => voiceText({
350
- voice,
348
+ const transcribe = (abortSignal) => transcribeSpeech({
349
+ speech: voice,
351
350
  model: dependencies.sttModel,
352
- download: async (fileId) => {
353
- voiceBytes ??= await dependencies.download(fileId, {
351
+ report: reportTelegramError,
352
+ download: async () => {
353
+ voiceBytes ??= await dependencies.download(voice.fileId, {
354
354
  ...abortSignal === void 0 ? {} : { abortSignal },
355
355
  ...routing ? { maxBytes: MAXIMUM_ROUTING_ATTACHMENT_BYTES } : {}
356
356
  });
@@ -568,7 +568,7 @@ async function handleInboundMessage(input) {
568
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
- 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.]");
571
+ if (voice !== void 0 && mediaPlan?.audio) notes.push(NATIVE_AUDIO_NOTE);
572
572
  if (structured !== void 0) {
573
573
  if (text.trim() === "") text = `[${structured.kind}]`;
574
574
  }
@@ -4,13 +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-Dzs8hUDB.mjs";
8
- import { t as agentBuild } from "../../../_chunks/build-metadata-DjhDPTy-.mjs";
9
- import { n as currentInboundRequest } from "../../../_chunks/inbound-request-B3RhCuOw.mjs";
7
+ import { A as actionToolName, Ct as runtimeEnvelope, D as OntologyActionNotPermitted, M as ontologyTools, R as needsConfirmation, St as principalRuntimeSource, W as member, c as currentInboundRequest, wt as telegramRuntimeSource } from "../../../_chunks/principal-D5Tualrk.mjs";
8
+ import { t as agentBuild } from "../../../_chunks/build-metadata-CLYC7FWE.mjs";
10
9
  import { object } from "../confirmation-description.mjs";
11
- import { needsConfirmation } from "../confirmations.mjs";
12
- import { OntologyActionNotPermitted, actionToolName, ontologyTools } from "../ontology-tools.mjs";
13
- import { member } from "../actor.mjs";
14
10
  var AttachmentLifecycleNotPermitted = class extends Error {
15
11
  code = "attachment_lifecycle_not_permitted";
16
12
  };
@@ -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 chatLanguage, r as identityProviderOf, i as memberIdOf, a as rolesOf, o as telegramPrincipal } from "../../../_chunks/principal-Dzs8hUDB.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-D5Tualrk.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 { p as reportTelegramError } from "../../../_chunks/inbound-request-B3RhCuOw.mjs";
7
+ import { _t as reportTelegramError } from "../../../_chunks/principal-D5Tualrk.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;
@@ -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-B3RhCuOw.mjs";
8
+ import { _t as reportTelegramError, lt as TelegramDeliveryError, pt as customerMessage, ut as currentLocale } from "../../../_chunks/principal-D5Tualrk.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-Dzs8hUDB.mjs";
7
+ import { Ct as runtimeEnvelope, wt as telegramRuntimeSource } from "../../../_chunks/principal-D5Tualrk.mjs";
8
8
  import { workspaceAction } from "./workspace-action.mjs";
9
9
  import { STRUCTURED_KINDS } from "./structured-settings.mjs";
10
10
  const record = (value) => {
@@ -7,8 +7,7 @@ __eveCreateRequire(import.meta.url);
7
7
  import { telegramText } from "./texts.mjs";
8
8
  import { confirmationLocale } from "./confirmation-text.mjs";
9
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-B3RhCuOw.mjs";
11
- import { i as memberIdOf } from "../../../_chunks/principal-Dzs8hUDB.mjs";
10
+ import { _t as reportTelegramError, dt as currentThreadId, ft as customerCopy, ht as failureText, i as memberIdOf, ut as currentLocale } from "../../../_chunks/principal-D5Tualrk.mjs";
12
11
  import { modelServiceFailure } from "../model-service-failure.mjs";
13
12
  function telegramFailureEvents(input) {
14
13
  return {
@@ -1,32 +1,17 @@
1
- import { type ConnectionProxy } from "../connection-proxy.js";
1
+ import type { ConnectionProxy } from "../connection-proxy.js";
2
+ import type { Speech } from "../inbound-media/speech.js";
2
3
  /**
3
4
  * Voice, audio and video notes. eve's Telegram parser reads only photos and documents, so these
4
- * arrive as a message with no text; the adapter reads them from the raw update, downloads them
5
- * through the connection's `file` API and turns them into text with the configured speech-to-text
6
- * model before the session sees them, whatever the main model accepts.
5
+ * arrive as a message with no text; the adapter reads them from the raw update and downloads them
6
+ * through the connection's `file` API, and the inbound media pipeline turns them into text with
7
+ * the configured speech-to-text model before the session sees them.
7
8
  */
8
- export type VoiceKind = "voice" | "audio" | "video_note";
9
- export interface VoiceMessage {
10
- readonly kind: VoiceKind;
9
+ /** A spoken file of a Telegram message, by its file id. */
10
+ export interface VoiceMessage extends Speech {
11
11
  readonly fileId: string;
12
- readonly seconds: number | undefined;
13
- readonly size: number | undefined;
14
12
  }
15
13
  /** The voice, audio or video note a raw Telegram message carries, if any. */
16
14
  export declare function voiceOf(raw: Readonly<Record<string, unknown>>): VoiceMessage | undefined;
17
- /** The note that tells the model a message was spoken, such as `[voice message, 12 s]`. */
18
- export declare function voiceNote(voice: VoiceMessage, detail?: string): string;
19
- /** Speech to text: the audio bytes in, the transcript out. */
20
- export type Transcriber = (input: {
21
- readonly audio: Uint8Array;
22
- readonly model: string;
23
- readonly abortSignal?: AbortSignal;
24
- }) => Promise<string>;
25
- /**
26
- * Transcribes through AI Gateway. The Gateway provider authenticates with `AI_GATEWAY_API_KEY`
27
- * when set and otherwise with the deployment's Vercel OIDC token, so a deployment needs no key.
28
- */
29
- export declare const gatewayTranscriber: Transcriber;
30
15
  /** A Telegram file could not be downloaded through the connection. */
31
16
  export declare class TelegramFileError extends Error {
32
17
  readonly name = "TelegramFileError";
@@ -38,19 +23,3 @@ export declare function downloadTelegramFile(input: {
38
23
  readonly abortSignal?: AbortSignal;
39
24
  readonly maxBytes?: number;
40
25
  }): Promise<Uint8Array>;
41
- /** What a voice message becomes: the text of the turn and the note that goes with it. */
42
- export interface VoiceText {
43
- readonly text: string;
44
- readonly note: string;
45
- readonly processed?: boolean;
46
- }
47
- /**
48
- * Turns a voice message into text. When it cannot (transcription is off, the file exceeds what a
49
- * bot may download, or a call fails), the text says so, so the agent can ask for a typed message.
50
- */
51
- export declare function voiceText(input: {
52
- readonly voice: VoiceMessage;
53
- readonly model: string | false;
54
- readonly download: (fileId: string) => Promise<Uint8Array>;
55
- readonly transcribe: Transcriber;
56
- }): Promise<VoiceText>;
@@ -4,16 +4,6 @@ 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 "../connection-proxy.mjs";
8
- import { p as reportTelegramError } from "../../../_chunks/inbound-request-B3RhCuOw.mjs";
9
- import { gateway, transcribe } from "ai";
10
- const LABELS = {
11
- voice: "voice message",
12
- audio: "audio file",
13
- video_note: "video message"
14
- };
15
- const TRANSCRIPTION_TIMEOUT_MS = 6e4;
16
- const MAXIMUM_TRANSCRIPTION_SECONDS = 600;
17
7
  function isRecord(value) {
18
8
  return typeof value === "object" && value !== null && !Array.isArray(value);
19
9
  }
@@ -35,19 +25,6 @@ function voiceOf(raw) {
35
25
  };
36
26
  }
37
27
  }
38
- function voiceNote(voice, detail) {
39
- const parts = [LABELS[voice.kind]];
40
- if (voice.seconds !== void 0) parts.push(`${Math.round(voice.seconds)} s`);
41
- if (detail !== void 0) parts.push(detail);
42
- return `[${parts.join(", ")}]`;
43
- }
44
- const gatewayTranscriber = async ({ audio, model, abortSignal }) => {
45
- return (await transcribe({
46
- model: gateway.transcription(model),
47
- audio,
48
- abortSignal: abortSignal ?? AbortSignal.timeout(TRANSCRIPTION_TIMEOUT_MS)
49
- })).text.trim();
50
- };
51
28
  var TelegramFileError = class extends Error {
52
29
  name = "TelegramFileError";
53
30
  };
@@ -79,44 +56,4 @@ async function downloadTelegramFile(input) {
79
56
  if (file.status !== 200) throw new TelegramFileError(`Telegram refused the file download with HTTP ${file.status}.`);
80
57
  return file.body;
81
58
  }
82
- async function voiceText(input) {
83
- const { voice, model } = input;
84
- const note = voiceNote(voice);
85
- if (model === false) return {
86
- text: voiceNote(voice, "voice transcription is off"),
87
- note
88
- };
89
- if (voice.size !== void 0 && voice.size > 20971520) return {
90
- text: voiceNote(voice, "too long to transcribe"),
91
- note
92
- };
93
- if (voice.seconds !== void 0 && voice.seconds > MAXIMUM_TRANSCRIPTION_SECONDS) return {
94
- text: voiceNote(voice, "exceeds the 10 minute transcription limit"),
95
- note
96
- };
97
- try {
98
- const audio = await input.download(voice.fileId);
99
- if (audio.byteLength > 20971520) return {
100
- text: voiceNote(voice, "too long to transcribe"),
101
- note
102
- };
103
- const transcript = await input.transcribe({
104
- audio,
105
- model
106
- });
107
- return transcript === "" ? {
108
- text: voiceNote(voice, "no speech recognized"),
109
- note
110
- } : {
111
- text: transcript,
112
- note,
113
- processed: true
114
- };
115
- } catch (error) {
116
- return {
117
- text: voiceNote(voice, `could not be transcribed; error reference: ${reportTelegramError("voice_transcription_failed", error, { kind: voice.kind })}`),
118
- note
119
- };
120
- }
121
- }
122
- export { TelegramFileError, downloadTelegramFile, gatewayTranscriber, voiceNote, voiceOf, voiceText };
59
+ export { TelegramFileError, downloadTelegramFile, voiceOf };
@@ -4,10 +4,8 @@ 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 { needsConfirmation } from "../confirmations.mjs";
7
+ import { A as actionToolName, M as ontologyTools, R as needsConfirmation, W as member } from "../../../_chunks/principal-D5Tualrk.mjs";
8
8
  import { object } from "../confirmation-description.mjs";
9
- import { actionToolName, ontologyTools } from "../ontology-tools.mjs";
10
- import { member } from "../actor.mjs";
11
9
  var WorkspaceActionAlreadyDispatched = class extends Error {};
12
10
  async function workspaceAction(input) {
13
11
  const action = actionToolName(input.configuration.entity, input.configuration.action);