@segmentstream/agent 0.47.0 → 0.50.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.
- package/CHANGELOG.md +75 -0
- package/README.md +14 -15
- package/dist/_chunks/{build-metadata-5S6uTvyu.mjs → build-metadata-DrQtDIMX.mjs} +1 -1
- package/dist/_chunks/principal-D5Tualrk.mjs +1836 -0
- package/dist/extension/channels/slack.mjs +2 -1
- package/dist/extension/channels/whatsapp.mjs +1 -0
- package/dist/extension/connections/ontology.mjs +1 -1
- package/dist/extension/hooks/authorization.mjs +1 -1
- package/dist/extension/instructions/persona.mjs +1 -1
- package/dist/extension/lib/actor.mjs +1 -46
- package/dist/extension/lib/attachment-tools.mjs +1 -3
- package/dist/extension/lib/attachments.d.ts +1 -1
- package/dist/extension/lib/attachments.mjs +1 -230
- package/dist/extension/lib/build-metadata.mjs +1 -1
- package/dist/extension/lib/chat-address.mjs +1 -50
- package/dist/extension/lib/chat-context.mjs +1 -1
- package/dist/extension/lib/chat-recorder.mjs +1 -2
- package/dist/extension/lib/confirmations.mjs +1 -179
- package/dist/extension/lib/inbound-media/files.d.ts +91 -0
- package/dist/extension/lib/inbound-media/files.mjs +7 -0
- package/dist/extension/lib/{telegram → inbound-media}/images.d.ts +2 -0
- package/dist/extension/lib/{telegram → inbound-media}/images.mjs +1 -2
- package/dist/extension/lib/inbound-media/index.d.ts +55 -0
- package/dist/extension/lib/inbound-media/index.mjs +7 -0
- package/dist/extension/lib/inbound-media/plan.d.ts +59 -0
- package/dist/extension/lib/{telegram/media-policy.mjs → inbound-media/plan.mjs} +56 -4
- package/dist/extension/lib/inbound-media/report.d.ts +5 -0
- package/dist/extension/lib/inbound-media/report.mjs +7 -0
- package/dist/extension/lib/inbound-media/speech.d.ts +52 -0
- package/dist/extension/lib/inbound-media/speech.mjs +73 -0
- package/dist/extension/lib/ontology-connection.mjs +1 -101
- package/dist/extension/lib/ontology-file-call.mjs +1 -4
- package/dist/extension/lib/ontology-tools.mjs +1 -377
- package/dist/extension/lib/review/hold.mjs +1 -2
- package/dist/extension/lib/review/reply.mjs +1 -2
- package/dist/extension/lib/role-skill.mjs +1 -1
- package/dist/extension/lib/runtime-envelope.mjs +1 -1
- package/dist/extension/lib/sent-files.mjs +1 -2
- package/dist/extension/lib/slack/adapter.d.ts +49 -7
- package/dist/extension/lib/slack/adapter.mjs +79 -21
- package/dist/extension/lib/slack/attachments-send.mjs +1 -3
- package/dist/extension/lib/slack/files.d.ts +12 -19
- package/dist/extension/lib/slack/files.mjs +26 -58
- package/dist/extension/lib/stored-files.mjs +1 -3
- package/dist/extension/lib/telegram/adapter.d.ts +3 -3
- package/dist/extension/lib/telegram/adapter.mjs +13 -17
- package/dist/extension/lib/telegram/attachment-description.d.ts +1 -1
- package/dist/extension/lib/telegram/attachment-description.mjs +2 -2
- package/dist/extension/lib/telegram/attachments-send.mjs +1 -3
- package/dist/extension/lib/telegram/callbacks.mjs +1 -2
- package/dist/extension/lib/telegram/chat-archive.mjs +1 -1
- package/dist/extension/lib/telegram/confirmations.mjs +1 -3
- package/dist/extension/lib/telegram/customer-text.mjs +1 -1
- package/dist/extension/lib/telegram/files.d.ts +8 -15
- package/dist/extension/lib/telegram/files.mjs +32 -107
- package/dist/extension/lib/telegram/health.mjs +1 -1
- package/dist/extension/lib/telegram/held-approvals.mjs +1 -1
- package/dist/extension/lib/telegram/inbound-request.d.ts +6 -12
- package/dist/extension/lib/telegram/inbound-request.mjs +1 -1
- package/dist/extension/lib/telegram/inbound.d.ts +3 -3
- package/dist/extension/lib/telegram/inbound.mjs +11 -11
- package/dist/extension/lib/telegram/lifecycle.mjs +2 -6
- package/dist/extension/lib/telegram/principal.mjs +1 -1
- package/dist/extension/lib/telegram/session-recovery.mjs +1 -1
- package/dist/extension/lib/telegram/silent.mjs +1 -1
- package/dist/extension/lib/telegram/structured.mjs +1 -1
- package/dist/extension/lib/telegram/turn-errors.mjs +1 -2
- package/dist/extension/lib/telegram/voice.d.ts +7 -38
- package/dist/extension/lib/telegram/voice.mjs +1 -64
- package/dist/extension/lib/telegram/workspace-action.mjs +1 -3
- package/dist/extension/lib/web/auth.d.ts +27 -4
- package/dist/extension/lib/web/auth.mjs +1 -124
- package/dist/extension/lib/web/channel.d.ts +13 -4
- package/dist/extension/lib/web/channel.mjs +15 -8
- package/dist/extension/lib/whatsapp/adapter.d.ts +37 -1
- package/dist/extension/lib/whatsapp/adapter.mjs +118 -21
- package/dist/extension/lib/whatsapp/files.d.ts +40 -0
- package/dist/extension/lib/whatsapp/files.mjs +70 -0
- package/dist/extension/lib/workspace-source.mjs +1 -3
- package/dist/extension/model.mjs +1 -1
- package/dist/extension/tools/attachments_discard.mjs +1 -1
- package/dist/extension/tools/attachments_list.mjs +1 -1
- package/dist/extension/tools/attachments_promote.mjs +1 -5
- package/dist/extension/tools/attachments_read.mjs +1 -1
- package/dist/extension/tools/attachments_send.mjs +1 -2
- package/dist/extension/tools/attachments_stage.mjs +1 -1
- package/dist/extension/tools/attachments_table.mjs +1 -1
- package/dist/extension/tools/questions_ask.mjs +1 -2
- package/dist/extension/tools/workspace_source.mjs +1 -1
- package/package.json +2 -2
- package/dist/_chunks/inbound-request-B3RhCuOw.mjs +0 -413
- package/dist/_chunks/principal-Dzs8hUDB.mjs +0 -128
- 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 {
|
|
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
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
115
|
-
|
|
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 {
|
|
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-
|
|
7
|
+
import { t as agentBuild } from "../../../_chunks/build-metadata-DrQtDIMX.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 "
|
|
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
|
|
5
|
+
import { type StagedFile as InboundStagedFile } from "../inbound-media/index.js";
|
|
6
6
|
import type { SessionOperations } from "./sessions.js";
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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 {
|
|
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
|
|
14
|
-
import type { MediaPlan } from "
|
|
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 {
|
|
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 {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
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
|
|
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) =>
|
|
350
|
-
voice,
|
|
348
|
+
const transcribe = (abortSignal) => transcribeSpeech({
|
|
349
|
+
speech: voice,
|
|
351
350
|
model: dependencies.sttModel,
|
|
352
|
-
|
|
353
|
-
|
|
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(
|
|
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 {
|
|
8
|
-
import { t as agentBuild } from "../../../_chunks/build-metadata-
|
|
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-DrQtDIMX.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-
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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
|
|
5
|
-
* through the connection's `file` API and turns them into text with
|
|
6
|
-
* model before the session sees them
|
|
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
|
-
|
|
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
|
-
|
|
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 "
|
|
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);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SessionAuthContext } from "eve/context";
|
|
2
|
-
import { type AuthFn } from "eve/channels/auth";
|
|
2
|
+
import { ForbiddenError, type AuthFn } from "eve/channels/auth";
|
|
3
3
|
import { type Environment } from "../environment.js";
|
|
4
4
|
import { type RuntimeToken } from "../runtime-token.js";
|
|
5
5
|
/**
|
|
@@ -29,12 +29,33 @@ export interface WebMember {
|
|
|
29
29
|
readonly chat: string;
|
|
30
30
|
readonly roles: ReadonlyArray<string>;
|
|
31
31
|
readonly name?: string;
|
|
32
|
+
/**
|
|
33
|
+
* For a turn the member starts: the agent's limit for people who signed up that it exceeds, and
|
|
34
|
+
* when the next turn may run. Members invited or paired are never limited.
|
|
35
|
+
*/
|
|
36
|
+
readonly limited?: {
|
|
37
|
+
readonly scope: string;
|
|
38
|
+
readonly retryAfterSeconds: number;
|
|
39
|
+
};
|
|
32
40
|
}
|
|
33
41
|
/**
|
|
34
42
|
* Asks whom a token stands for, for the origin the member reached the agent on: the member, or
|
|
35
|
-
* `undefined` when it stands for nobody.
|
|
43
|
+
* `undefined` when it stands for nobody. With `turn`, the member is starting a turn, which the
|
|
44
|
+
* ontology counts against the agent's limits. Throws when the ontology cannot answer.
|
|
36
45
|
*/
|
|
37
|
-
export type WebIntrospection = (token: string, origin: string) => Promise<WebMember | undefined>;
|
|
46
|
+
export type WebIntrospection = (token: string, origin: string, turn?: boolean) => Promise<WebMember | undefined>;
|
|
47
|
+
/** The code of the answer to a turn the agent's limits refuse, as the ontology's own refusals. */
|
|
48
|
+
export declare const TURN_LIMITED_CODE = "rate_limited";
|
|
49
|
+
/**
|
|
50
|
+
* A turn the agent's limits for people who signed up refuse: answered `429 rate_limited` with
|
|
51
|
+
* `Retry-After`, before the turn reaches the model. The answer carries no words: the app's chat
|
|
52
|
+
* reports it by its code in the workspace's own.
|
|
53
|
+
*/
|
|
54
|
+
export declare class TurnLimitedError extends ForbiddenError {
|
|
55
|
+
readonly retryAfterSeconds: number;
|
|
56
|
+
readonly response: Response;
|
|
57
|
+
constructor(retryAfterSeconds: number);
|
|
58
|
+
}
|
|
38
59
|
/** The member an introspection answer names, when it is active and names their own chat. */
|
|
39
60
|
export declare function webMemberOf(body: unknown): WebMember | undefined;
|
|
40
61
|
/** The ontology's introspection, called with the deployment's runtime token. */
|
|
@@ -55,6 +76,8 @@ export interface WebAuthOptions {
|
|
|
55
76
|
* The route authenticator for the agent's own HTTP channel: a request with an agent token runs as
|
|
56
77
|
* the member it stands for, and any other request goes on to the next authenticator. An answer to
|
|
57
78
|
* one of the agent's confirmations through its own buttons is stamped with its decision, as a click
|
|
58
|
-
* on a Telegram card is, so that only a click, never a typed message, decides a confirmation.
|
|
79
|
+
* on a Telegram card is, so that only a click, never a typed message, decides a confirmation. A
|
|
80
|
+
* message starts a turn, which counts against the agent's limits for people who signed up, as their
|
|
81
|
+
* turns on a messenger do; one beyond them is refused with {@link TurnLimitedError}.
|
|
59
82
|
*/
|
|
60
83
|
export declare function webAuth(options?: WebAuthOptions): AuthFn<Request>;
|