@segmentstream/agent 0.31.14 → 0.33.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/dist/_chunks/{build-metadata-frH1WOMT.mjs → build-metadata-DpwHNeNL.mjs} +1 -1
- package/dist/_chunks/{inbound-request-Dy7q3T23.mjs → inbound-request-BQQWCrWl.mjs} +7 -3
- package/dist/_chunks/{principal-CPOCTHBa.mjs → principal-VsmaJp1x.mjs} +1 -1
- package/dist/extension/channels/whatsapp.d.ts +7 -0
- package/dist/extension/channels/whatsapp.mjs +13 -0
- package/dist/extension/config.d.ts +12 -0
- package/dist/extension/config.mjs +31 -5
- package/dist/extension/hooks/authorization.mjs +1 -1
- package/dist/extension/instructions.md +6 -2
- package/dist/extension/lib/actor.mjs +1 -1
- package/dist/extension/lib/attachment-tools.mjs +1 -1
- package/dist/extension/lib/build-metadata.mjs +1 -1
- package/dist/extension/lib/chat-context.mjs +1 -1
- package/dist/extension/lib/confirmation-description.d.ts +45 -0
- package/dist/extension/lib/confirmation-description.mjs +60 -1
- package/dist/extension/lib/confirmations.d.ts +7 -1
- package/dist/extension/lib/confirmations.mjs +5 -4
- package/dist/extension/lib/conversation-runtime.mjs +1 -1
- package/dist/extension/lib/ontology-connection.mjs +1 -1
- package/dist/extension/lib/ontology-file-call.mjs +3 -3
- package/dist/extension/lib/ontology-tools.d.ts +2 -1
- package/dist/extension/lib/ontology-tools.mjs +48 -4
- package/dist/extension/lib/runtime-envelope.mjs +1 -1
- package/dist/extension/lib/stored-files.mjs +1 -1
- package/dist/extension/lib/telegram/adapter.mjs +3 -3
- package/dist/extension/lib/telegram/attachment-description.mjs +1 -1
- package/dist/extension/lib/telegram/attachments-send.mjs +2 -2
- package/dist/extension/lib/telegram/callbacks.mjs +2 -2
- package/dist/extension/lib/telegram/confirmation-text.d.ts +52 -4
- package/dist/extension/lib/telegram/confirmation-text.mjs +84 -15
- package/dist/extension/lib/telegram/confirmations.d.ts +9 -0
- package/dist/extension/lib/telegram/confirmations.mjs +46 -14
- package/dist/extension/lib/telegram/conversations.mjs +1 -1
- package/dist/extension/lib/telegram/customer-text.mjs +1 -1
- package/dist/extension/lib/telegram/files.mjs +2 -2
- package/dist/extension/lib/telegram/format.d.ts +4 -0
- package/dist/extension/lib/telegram/health.mjs +1 -1
- package/dist/extension/lib/telegram/images.mjs +1 -1
- package/dist/extension/lib/telegram/inbound-request.mjs +1 -1
- package/dist/extension/lib/telegram/inbound.mjs +2 -2
- package/dist/extension/lib/telegram/lifecycle.mjs +3 -3
- package/dist/extension/lib/telegram/media-policy.mjs +1 -1
- 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 +2 -2
- package/dist/extension/lib/telegram/voice.mjs +1 -1
- package/dist/extension/lib/whatsapp/adapter.d.ts +81 -0
- package/dist/extension/lib/whatsapp/adapter.mjs +237 -0
- package/dist/extension/model.mjs +1 -1
- package/dist/extension/tools/attachments_promote.mjs +3 -3
- package/dist/extension/tools/questions_ask.mjs +1 -1
- package/package.json +7 -4
|
@@ -12,10 +12,10 @@ import { fetchFileGrant, transientFileStatus } from "../file-grant.mjs";
|
|
|
12
12
|
import { appOrigin, channelsEnabled, proxyEnvironment } from "../environment.mjs";
|
|
13
13
|
import { ACT_AS_HEADER } from "../actor.mjs";
|
|
14
14
|
import { runtimeToken } from "../runtime-token.mjs";
|
|
15
|
-
import "../../../_chunks/principal-
|
|
15
|
+
import "../../../_chunks/principal-VsmaJp1x.mjs";
|
|
16
16
|
import { confirmationLocale } from "./confirmation-text.mjs";
|
|
17
17
|
import { inTelegramSendQueue, telegramSendScope } from "./send-queue.mjs";
|
|
18
|
-
import { d as failureText, f as formattingRefused, l as customerMessage, p as reportTelegramError } from "../../../_chunks/inbound-request-
|
|
18
|
+
import { d as failureText, f as formattingRefused, l as customerMessage, p as reportTelegramError } from "../../../_chunks/inbound-request-BQQWCrWl.mjs";
|
|
19
19
|
import { TELEGRAM_PLACEHOLDER_TOKEN, TELEGRAM_PROXY_ORIGIN, telegramProxyFetch } from "./proxy-fetch.mjs";
|
|
20
20
|
const MAXIMUM_PHOTO_BYTES = 10485760;
|
|
21
21
|
const MAXIMUM_DOCUMENT_BYTES = 52428800;
|
|
@@ -5,8 +5,8 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { object } from "../confirmation-description.mjs";
|
|
8
|
-
import { d as telegramRuntimeSource, i as memberIdOf, o as telegramPrincipal, u as runtimeEnvelope } from "../../../_chunks/principal-
|
|
9
|
-
import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-
|
|
8
|
+
import { d as telegramRuntimeSource, i as memberIdOf, o as telegramPrincipal, u as runtimeEnvelope } from "../../../_chunks/principal-VsmaJp1x.mjs";
|
|
9
|
+
import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-BQQWCrWl.mjs";
|
|
10
10
|
import { formatAddress, parseAddress, scopedAddress } from "./sessions.mjs";
|
|
11
11
|
import { telegramText } from "./texts.mjs";
|
|
12
12
|
import { workspaceAction } from "./workspace-action.mjs";
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import type { SessionAuthContext } from "eve/context";
|
|
2
2
|
import { type ConfirmationDescription } from "../confirmation-description.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
3
|
+
import type { TelegramEntity } from "./format.js";
|
|
4
|
+
/** A confirmation card's text with its formatting, as Telegram entities. */
|
|
5
|
+
export interface ConfirmationMessageText {
|
|
6
|
+
readonly text: string;
|
|
7
|
+
readonly entities?: readonly TelegramEntity[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Confirmation facts and statuses are literal text, sent with exactly the formatting the card was
|
|
11
|
+
* built with; delivery still applies the shared validator to the text.
|
|
12
|
+
*/
|
|
13
|
+
export declare function withConfirmationText<T>(message: string | ConfirmationMessageText, run: () => T): T;
|
|
14
|
+
/** The formatting of the confirmation being delivered, when `text` is its text. */
|
|
15
|
+
export declare function confirmationEntities(text: string): readonly TelegramEntity[] | undefined;
|
|
6
16
|
export interface ConfirmationCopy {
|
|
7
17
|
readonly question: string;
|
|
8
18
|
readonly confirm: string;
|
|
@@ -17,6 +27,13 @@ export interface ConfirmationCopy {
|
|
|
17
27
|
export interface ConfirmationText {
|
|
18
28
|
readonly previewLinks?: readonly string[];
|
|
19
29
|
readonly text: string;
|
|
30
|
+
/** The formatting of `text`; a chat post card formats its own. */
|
|
31
|
+
readonly entities?: readonly TelegramEntity[];
|
|
32
|
+
/** A page about what the action concerns, as a button under the decision. */
|
|
33
|
+
readonly link?: {
|
|
34
|
+
readonly text: string;
|
|
35
|
+
readonly url: string;
|
|
36
|
+
};
|
|
20
37
|
readonly confirm: string;
|
|
21
38
|
readonly cancel: string;
|
|
22
39
|
readonly executing: string;
|
|
@@ -35,5 +52,36 @@ export declare function confirmationLocale(principal: SessionAuthContext | null,
|
|
|
35
52
|
export declare function confirmationCopyIssue(value: unknown): string | undefined;
|
|
36
53
|
/** Reject the entire presentation object; never partially trust malformed model copy. */
|
|
37
54
|
export declare function confirmationCopy(value?: unknown): ConfirmationCopy | undefined;
|
|
38
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* Button positions retain callback meaning; workspace copy supplies every label and status. An
|
|
57
|
+
* action that describes its own confirmation gives the card its title, facts and details; any
|
|
58
|
+
* other card asks the agent's question above the action's trusted facts.
|
|
59
|
+
*/
|
|
39
60
|
export declare function renderConfirmation(description?: ConfirmationDescription, copy?: ConfirmationCopy): ConfirmationText;
|
|
61
|
+
/** The marker of each outcome, used when the workspace's word for it has none of its own. */
|
|
62
|
+
declare const STATUS_MARKERS: {
|
|
63
|
+
readonly executing: "⌛";
|
|
64
|
+
readonly completed: "✅";
|
|
65
|
+
readonly cancelled: "✖️";
|
|
66
|
+
readonly failed: "⚠️";
|
|
67
|
+
readonly expired: "⏰";
|
|
68
|
+
readonly interrupted: "⏸";
|
|
69
|
+
};
|
|
70
|
+
export type ConfirmationOutcome = keyof typeof STATUS_MARKERS;
|
|
71
|
+
/**
|
|
72
|
+
* The card with its outcome under it: a marker and the workspace's word for the outcome, who
|
|
73
|
+
* decided, when (in each reader's own time zone), and why it failed when the action said so.
|
|
74
|
+
* A failure without the action's reason carries its diagnostic reference instead.
|
|
75
|
+
*/
|
|
76
|
+
export declare function confirmationStatus(card: ConfirmationMessageText, status: {
|
|
77
|
+
readonly outcome: ConfirmationOutcome;
|
|
78
|
+
readonly label: string;
|
|
79
|
+
readonly actor?: string | null;
|
|
80
|
+
readonly at: number;
|
|
81
|
+
readonly reason?: string;
|
|
82
|
+
readonly reference?: string;
|
|
83
|
+
}): {
|
|
84
|
+
text: string;
|
|
85
|
+
entities: TelegramEntity[];
|
|
86
|
+
};
|
|
87
|
+
export {};
|
|
@@ -4,17 +4,38 @@ 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 { humanText, humanTextIssue, object } from "../confirmation-description.mjs";
|
|
7
|
+
import { confirmationCard, humanText, humanTextIssue, object } from "../confirmation-description.mjs";
|
|
8
8
|
import { isTechnicalText } from "../customer-text-safety.mjs";
|
|
9
9
|
import { telegramText } from "./texts.mjs";
|
|
10
10
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
11
11
|
const plainConfirmation = new AsyncLocalStorage();
|
|
12
|
-
function withConfirmationText(
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
function withConfirmationText(message, run) {
|
|
13
|
+
const card = typeof message === "string" ? { text: message } : message;
|
|
14
|
+
if (card.text.length > 4096 || isTechnicalText(card.text)) throw new Error("The complete confirmation cannot pass the delivery safety check.");
|
|
15
|
+
return plainConfirmation.run(card, run);
|
|
15
16
|
}
|
|
16
|
-
function
|
|
17
|
-
|
|
17
|
+
function confirmationEntities(text) {
|
|
18
|
+
const card = plainConfirmation.getStore();
|
|
19
|
+
return card?.text === text ? card.entities ?? [] : void 0;
|
|
20
|
+
}
|
|
21
|
+
function composer(text = "", entities = []) {
|
|
22
|
+
const out = {
|
|
23
|
+
text,
|
|
24
|
+
entities: [...entities]
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
add(value, entity) {
|
|
28
|
+
if (entity !== void 0 && value.length > 0) out.entities.push({
|
|
29
|
+
...entity,
|
|
30
|
+
offset: out.text.length,
|
|
31
|
+
length: value.length
|
|
32
|
+
});
|
|
33
|
+
out.text += value;
|
|
34
|
+
},
|
|
35
|
+
get message() {
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
18
39
|
}
|
|
19
40
|
function confirmationLocale(principal, fallback = "en") {
|
|
20
41
|
for (const key of [
|
|
@@ -72,23 +93,44 @@ function renderConfirmation(description, copy) {
|
|
|
72
93
|
copy = confirmationCopy(copy);
|
|
73
94
|
const action = humanText(description?.action);
|
|
74
95
|
if (description === void 0 || action === void 0 || action === "❓") throw new Error("A confirmation requires a safe declared action title.");
|
|
75
|
-
const facts = [action, ...(description?.fields ?? []).map(({ label, value }) => {
|
|
76
|
-
if (value.length > 3584) throw new Error("The complete confirmation facts cannot fit in one Telegram message.");
|
|
77
|
-
const safeLabel = humanText(label);
|
|
78
|
-
const safeValue = humanText(value, 3584);
|
|
79
|
-
if (safeLabel === void 0 || safeValue === void 0) throw new Error("The complete confirmation facts contain an unsafe field.");
|
|
80
|
-
return `${safeLabel}: ${safeValue}`;
|
|
81
|
-
})].filter(Boolean).join("\n");
|
|
82
96
|
const configured = (key) => {
|
|
83
97
|
const value = telegramText("confirmation", key);
|
|
84
98
|
if (value === void 0) throw new Error(`texts.confirmation.${key} is required for Telegram confirmations.`);
|
|
85
99
|
return value;
|
|
86
100
|
};
|
|
87
|
-
const
|
|
101
|
+
const card = description.card === void 0 ? void 0 : confirmationCard(description.card);
|
|
102
|
+
const body = composer();
|
|
103
|
+
if (card !== void 0) {
|
|
104
|
+
body.add(card.icon === void 0 ? card.title : `${card.icon} ${card.title}`, { type: "bold" });
|
|
105
|
+
for (const fact of card.facts) {
|
|
106
|
+
body.add(fact.icon === void 0 ? "\n" : `\n${fact.icon} `);
|
|
107
|
+
body.add(fact.text, fact.url === void 0 ? void 0 : {
|
|
108
|
+
type: "text_link",
|
|
109
|
+
url: fact.url
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
if (card.details.length > 0) {
|
|
113
|
+
body.add("\n");
|
|
114
|
+
body.add(card.details.join("\n"), { type: "expandable_blockquote" });
|
|
115
|
+
}
|
|
116
|
+
} else {
|
|
117
|
+
const facts = [action, ...(description.fields ?? []).map(({ label, value }) => {
|
|
118
|
+
if (value.length > 3584) throw new Error("The complete confirmation facts cannot fit in one Telegram message.");
|
|
119
|
+
const safeLabel = humanText(label);
|
|
120
|
+
const safeValue = humanText(value, 3584);
|
|
121
|
+
if (safeLabel === void 0 || safeValue === void 0) throw new Error("The complete confirmation facts contain an unsafe field.");
|
|
122
|
+
return `${safeLabel}: ${safeValue}`;
|
|
123
|
+
})].join("\n");
|
|
124
|
+
body.add(copy?.question ?? configured("question"), { type: "bold" });
|
|
125
|
+
body.add(`\n\n${facts}`);
|
|
126
|
+
}
|
|
127
|
+
const { text, entities } = body.message;
|
|
88
128
|
if (text.length > 3584) throw new Error("The complete confirmation facts cannot fit in one Telegram message.");
|
|
89
129
|
if (isTechnicalText(text)) throw new Error("The complete confirmation cannot pass the delivery safety check.");
|
|
90
130
|
return {
|
|
91
131
|
text,
|
|
132
|
+
entities,
|
|
133
|
+
...card?.link === void 0 ? {} : { link: card.link },
|
|
92
134
|
confirm: copy?.confirm ?? configured("confirm"),
|
|
93
135
|
cancel: copy?.cancel ?? configured("cancel"),
|
|
94
136
|
executing: configured("executing"),
|
|
@@ -100,4 +142,31 @@ function renderConfirmation(description, copy) {
|
|
|
100
142
|
edit: copy?.edit ?? configured("edit")
|
|
101
143
|
};
|
|
102
144
|
}
|
|
103
|
-
|
|
145
|
+
const STATUS_MARKERS = {
|
|
146
|
+
executing: "⌛",
|
|
147
|
+
completed: "✅",
|
|
148
|
+
cancelled: "✖️",
|
|
149
|
+
failed: "⚠️",
|
|
150
|
+
expired: "⏰",
|
|
151
|
+
interrupted: "⏸"
|
|
152
|
+
};
|
|
153
|
+
function clock(at) {
|
|
154
|
+
return `${new Date(at).toISOString().slice(11, 16)} UTC`;
|
|
155
|
+
}
|
|
156
|
+
function confirmationStatus(card, status) {
|
|
157
|
+
const out = composer(card.text, card.entities);
|
|
158
|
+
const actor = humanText(status.actor, 80);
|
|
159
|
+
out.add("\n\n");
|
|
160
|
+
out.add(/^\p{Extended_Pictographic}/u.test(status.label) ? status.label : `${STATUS_MARKERS[status.outcome]} ${status.label}`);
|
|
161
|
+
if (actor !== void 0) out.add(` · ${actor}`);
|
|
162
|
+
out.add(" · ");
|
|
163
|
+
out.add(clock(status.at), {
|
|
164
|
+
type: "date_time",
|
|
165
|
+
unix_time: Math.floor(status.at / 1e3),
|
|
166
|
+
date_time_format: "t"
|
|
167
|
+
});
|
|
168
|
+
if (status.reason !== void 0) out.add(`\n${status.reason}`);
|
|
169
|
+
else if (status.reference !== void 0) out.add(` · ${status.reference}`);
|
|
170
|
+
return out.message;
|
|
171
|
+
}
|
|
172
|
+
export { confirmationCopy, confirmationCopyIssue, confirmationEntities, confirmationLocale, confirmationStatus, renderConfirmation, withConfirmationText };
|
|
@@ -23,5 +23,14 @@ export declare function handleConfirmationCallback(input: {
|
|
|
23
23
|
readonly scope: "chat" | "thread";
|
|
24
24
|
readonly now?: number;
|
|
25
25
|
}): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Why the action refused a confirmed call, in its own words, when it said: an ontology refusal
|
|
28
|
+
* (`action_rejected`) whose message is plain text a member can read. Anything else is not a reason
|
|
29
|
+
* to show; its diagnostic reference stays.
|
|
30
|
+
*/
|
|
31
|
+
export declare function refusalReason(data: {
|
|
32
|
+
readonly output?: unknown;
|
|
33
|
+
readonly error?: unknown;
|
|
34
|
+
}): string | undefined;
|
|
26
35
|
export declare function telegramConfirmationEvents(archive?: Conversations, scope?: () => "chat" | "thread"): TelegramChannelEvents & Pick<ChannelEvents<TelegramEventContext>, "context.settled">;
|
|
27
36
|
export declare const confirmationEvents: TelegramChannelEvents & Pick<ChannelEvents<TelegramEventContext>, "context.settled">;
|
|
@@ -12,9 +12,9 @@ import { chatPostOperationId, isChatPost } from "../chat-post-confirmation.mjs";
|
|
|
12
12
|
import { conversationEvent } from "../conversations.mjs";
|
|
13
13
|
import { chatPostCard, chatPostCardStatus, chatPostReceipt, withChatPostCard } from "./chat-post-card.mjs";
|
|
14
14
|
import { answerMarker, isPendingQuestion, pendingQuestions, questionKey } from "../questions.mjs";
|
|
15
|
-
import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-
|
|
16
|
-
import { renderConfirmation, withConfirmationText } from "./confirmation-text.mjs";
|
|
17
|
-
import { i as memberIdOf, o as telegramPrincipal } from "../../../_chunks/principal-
|
|
15
|
+
import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-BQQWCrWl.mjs";
|
|
16
|
+
import { confirmationStatus, renderConfirmation, withConfirmationText } from "./confirmation-text.mjs";
|
|
17
|
+
import { i as memberIdOf, o as telegramPrincipal } from "../../../_chunks/principal-VsmaJp1x.mjs";
|
|
18
18
|
import { formatAddress, scopedAddress } from "./sessions.mjs";
|
|
19
19
|
import { call } from "eve/events";
|
|
20
20
|
import { createHash } from "node:crypto";
|
|
@@ -201,6 +201,17 @@ function messagePrompt(message) {
|
|
|
201
201
|
at: new Date().toISOString()
|
|
202
202
|
};
|
|
203
203
|
}
|
|
204
|
+
function group(channel) {
|
|
205
|
+
const type = channel.telegram.chatType;
|
|
206
|
+
return type === void 0 ? String(channel.telegram.chatId).startsWith("-") : type !== "private";
|
|
207
|
+
}
|
|
208
|
+
function refusalReason(data) {
|
|
209
|
+
const output = object(data.output);
|
|
210
|
+
const structured = object(output.structuredContent ?? output);
|
|
211
|
+
const message = String(object(data.error).message ?? "");
|
|
212
|
+
const detail = structured.error === "action_rejected" && typeof structured.detail === "string" ? structured.detail : /^([^\n]+?) \(action_rejected, request [^)\n]+\)/u.exec(message)?.[1];
|
|
213
|
+
return humanText(detail, 300);
|
|
214
|
+
}
|
|
204
215
|
function telegramConfirmationEvents(archive, scope) {
|
|
205
216
|
const record = async (callId, phase, text, status, ctx) => {
|
|
206
217
|
const saved = confirmations.get()[callId];
|
|
@@ -292,6 +303,7 @@ function telegramConfirmationEvents(archive, scope) {
|
|
|
292
303
|
reply_markup: { inline_keyboard: [[
|
|
293
304
|
{
|
|
294
305
|
text: copy.confirm,
|
|
306
|
+
style: "success",
|
|
295
307
|
callback_data: confirmationCallback(requestId, memberId, "approve")
|
|
296
308
|
},
|
|
297
309
|
...exactPost ? [{
|
|
@@ -302,7 +314,10 @@ function telegramConfirmationEvents(archive, scope) {
|
|
|
302
314
|
text: copy.cancel,
|
|
303
315
|
callback_data: confirmationCallback(requestId, memberId, "cancel")
|
|
304
316
|
}
|
|
305
|
-
]]
|
|
317
|
+
], ...copy.link === void 0 ? [] : [[{
|
|
318
|
+
text: copy.link.text,
|
|
319
|
+
url: copy.link.url
|
|
320
|
+
}]]] }
|
|
306
321
|
});
|
|
307
322
|
const prompt = {
|
|
308
323
|
requestId,
|
|
@@ -321,7 +336,10 @@ function telegramConfirmationEvents(archive, scope) {
|
|
|
321
336
|
author: humanText(ctx.session.auth.current.attributes.memberName) ?? "the requester"
|
|
322
337
|
} }
|
|
323
338
|
};
|
|
324
|
-
const sent = await withConfirmationPrompt(prompt, () => exactPost ? withChatPostCard(text, send, copy.previewLinks) : withConfirmationText(
|
|
339
|
+
const sent = await withConfirmationPrompt(prompt, () => exactPost ? withChatPostCard(text, send, copy.previewLinks) : withConfirmationText({
|
|
340
|
+
text,
|
|
341
|
+
...copy.entities ? { entities: copy.entities } : {}
|
|
342
|
+
}, send));
|
|
325
343
|
if (aliasesPendingTopic(scope?.(), channel.continuation?.token)) channel.continuation?.alias(formatAddress({
|
|
326
344
|
chatId: channel.telegram.chatId,
|
|
327
345
|
messageThreadId: String(channel.telegram.messageThreadId ?? ""),
|
|
@@ -334,6 +352,7 @@ function telegramConfirmationEvents(archive, scope) {
|
|
|
334
352
|
requestId,
|
|
335
353
|
messageId: sent.id,
|
|
336
354
|
text,
|
|
355
|
+
...copy.entities === void 0 ? {} : { entities: copy.entities },
|
|
337
356
|
copy,
|
|
338
357
|
exactPost,
|
|
339
358
|
prompt,
|
|
@@ -363,12 +382,19 @@ function telegramConfirmationEvents(archive, scope) {
|
|
|
363
382
|
const [callId, message] = entry;
|
|
364
383
|
const copy = message.copy ?? renderConfirmation();
|
|
365
384
|
const reason = confirmations.get()[callId]?.cancellationReason;
|
|
366
|
-
const
|
|
385
|
+
const outcome = resolution.outcome === "accepted" ? "executing" : reason === "expired" ? "expired" : [
|
|
367
386
|
"withdrawn",
|
|
368
387
|
"interrupted",
|
|
369
388
|
"abandoned"
|
|
370
|
-
].includes(resolution.outcome) ?
|
|
371
|
-
const
|
|
389
|
+
].includes(resolution.outcome) ? "interrupted" : "cancelled";
|
|
390
|
+
const status = copy[outcome];
|
|
391
|
+
const card = message.exactPost ? { text: chatPostCardStatus(message.text, status) } : confirmationStatus(message, {
|
|
392
|
+
outcome,
|
|
393
|
+
label: status,
|
|
394
|
+
actor: (outcome === "executing" || outcome === "cancelled") && group(channel) ? messagePrompt(message).requestedBy : void 0,
|
|
395
|
+
at: Date.now()
|
|
396
|
+
});
|
|
397
|
+
const text = card.text;
|
|
372
398
|
const edit = () => channel.telegram.editMessageText({
|
|
373
399
|
messageId: message.messageId,
|
|
374
400
|
replyMarkup: { inline_keyboard: [] },
|
|
@@ -383,7 +409,7 @@ function telegramConfirmationEvents(archive, scope) {
|
|
|
383
409
|
].includes(resolution.outcome) ? "interrupted" : "cancelled"
|
|
384
410
|
};
|
|
385
411
|
message.prompt = prompt;
|
|
386
|
-
await withConfirmationPrompt(prompt, () => message.exactPost ? withChatPostCard(text, edit, [...message.previewLinks ?? [], ...telegramTextLinks(status)]) : withConfirmationText(
|
|
412
|
+
await withConfirmationPrompt(prompt, () => message.exactPost ? withChatPostCard(text, edit, [...message.previewLinks ?? [], ...telegramTextLinks(status)]) : withConfirmationText(card, edit));
|
|
387
413
|
await record(callId, reason ?? (resolution.outcome === "accepted" ? "approved" : resolution.outcome === "declined" ? "cancelled" : "ignored"), text, resolution.outcome === "accepted" ? "requested" : "cancelled", ctx);
|
|
388
414
|
if (resolution.outcome !== "accepted") {
|
|
389
415
|
delete state.confirmationMessages?.[callId];
|
|
@@ -460,16 +486,22 @@ function telegramConfirmationEvents(archive, scope) {
|
|
|
460
486
|
} else {
|
|
461
487
|
const copy = message.copy ?? renderConfirmation();
|
|
462
488
|
const errorId = failed ? reportTelegramError("confirmed_action_failed", data, { callId: data.callId }) : void 0;
|
|
463
|
-
const
|
|
464
|
-
const
|
|
489
|
+
const reason = failed ? refusalReason(data) : void 0;
|
|
490
|
+
const card = confirmationStatus(message, {
|
|
491
|
+
outcome: failed ? "failed" : "completed",
|
|
492
|
+
label: failed ? copy.failed : copy.completed,
|
|
493
|
+
actor: group(channel) ? messagePrompt(message).requestedBy : void 0,
|
|
494
|
+
at: Date.now(),
|
|
495
|
+
...reason !== void 0 ? { reason } : errorId === void 0 ? {} : { reference: errorId }
|
|
496
|
+
});
|
|
465
497
|
const prompt = {
|
|
466
498
|
...messagePrompt(message),
|
|
467
499
|
state: failed ? "failed" : "completed"
|
|
468
500
|
};
|
|
469
|
-
await withConfirmationPrompt(prompt, () => withConfirmationText(
|
|
501
|
+
await withConfirmationPrompt(prompt, () => withConfirmationText(card, () => channel.telegram.editMessageText({
|
|
470
502
|
messageId: message.messageId,
|
|
471
503
|
replyMarkup: { inline_keyboard: [] },
|
|
472
|
-
text
|
|
504
|
+
text: card.text
|
|
473
505
|
})));
|
|
474
506
|
}
|
|
475
507
|
delete state.confirmationMessages?.[data.callId];
|
|
@@ -493,4 +525,4 @@ function telegramConfirmationEvents(archive, scope) {
|
|
|
493
525
|
};
|
|
494
526
|
}
|
|
495
527
|
const confirmationEvents = telegramConfirmationEvents();
|
|
496
|
-
export { confirmationCallback, confirmationEvents, handleConfirmationCallback, questionAddress, questionFromHistory, questionsFromHistory, routingConfirmationState, routingConfirmations, telegramConfirmationEvents };
|
|
528
|
+
export { confirmationCallback, confirmationEvents, handleConfirmationCallback, questionAddress, questionFromHistory, questionsFromHistory, refusalReason, routingConfirmationState, routingConfirmations, telegramConfirmationEvents };
|
|
@@ -9,7 +9,7 @@ import { n as contentText, t as CONTENT_CAPS } from "../../../_chunks/content-cD
|
|
|
9
9
|
import { conversationEvent, sessionFailureEventId } from "../conversations.mjs";
|
|
10
10
|
import { currentConfirmationPrompt } from "../group-routing/messages.mjs";
|
|
11
11
|
import { messageMetadata } from "./message-metadata.mjs";
|
|
12
|
-
import { n as currentInboundRequest, p as reportTelegramError, s as currentThreadId } from "../../../_chunks/inbound-request-
|
|
12
|
+
import { n as currentInboundRequest, p as reportTelegramError, s as currentThreadId } from "../../../_chunks/inbound-request-BQQWCrWl.mjs";
|
|
13
13
|
import { reportMembership } from "./membership.mjs";
|
|
14
14
|
import { currentDeliveryScope } from "./delivery-diagnostics.mjs";
|
|
15
15
|
import { contentShape, messageContent } from "./content.mjs";
|
|
@@ -5,5 +5,5 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { isTechnicalText } from "../customer-text-safety.mjs";
|
|
8
|
-
import { a as TelegramDeliveryError, c as customerCopy, d as failureText, f as formattingRefused, h as withDeliveryLocale, l as customerMessage, m as safeTelegramFetch, o as currentLocale, p as reportTelegramError, s as currentThreadId, u as customerText } from "../../../_chunks/inbound-request-
|
|
8
|
+
import { a as TelegramDeliveryError, c as customerCopy, d as failureText, f as formattingRefused, h as withDeliveryLocale, l as customerMessage, m as safeTelegramFetch, o as currentLocale, p as reportTelegramError, s as currentThreadId, u as customerText } from "../../../_chunks/inbound-request-BQQWCrWl.mjs";
|
|
9
9
|
export { TelegramDeliveryError, currentLocale, currentThreadId, customerCopy, customerMessage, customerText, failureText, formattingRefused, isTechnicalText, reportTelegramError, safeTelegramFetch, withDeliveryLocale };
|
|
@@ -5,8 +5,8 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { MAXIMUM_ATTACHMENT_BYTES, attachmentUrl } from "../attachments.mjs";
|
|
8
|
-
import { d as failureText, p as reportTelegramError } from "../../../_chunks/inbound-request-
|
|
9
|
-
import { n as conversationLanguage } from "../../../_chunks/principal-
|
|
8
|
+
import { d as failureText, p as reportTelegramError } from "../../../_chunks/inbound-request-BQQWCrWl.mjs";
|
|
9
|
+
import { n as conversationLanguage } from "../../../_chunks/principal-VsmaJp1x.mjs";
|
|
10
10
|
import { describableImage, describeReceivedImage } from "./images.mjs";
|
|
11
11
|
function telegramConversation(chatId) {
|
|
12
12
|
return `telegram:${chatId}`;
|
|
@@ -4,6 +4,10 @@ export interface TelegramEntity {
|
|
|
4
4
|
readonly length: number;
|
|
5
5
|
readonly url?: string;
|
|
6
6
|
readonly language?: string;
|
|
7
|
+
/** A `date_time` entity's moment: Telegram shows it in each reader's time zone. */
|
|
8
|
+
readonly unix_time?: number;
|
|
9
|
+
/** A `date_time` entity's format, such as `t` for the short time. */
|
|
10
|
+
readonly date_time_format?: string;
|
|
7
11
|
}
|
|
8
12
|
export interface TelegramText {
|
|
9
13
|
readonly text: string;
|
|
@@ -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-DpwHNeNL.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 { p as reportTelegramError } from "../../../_chunks/inbound-request-
|
|
7
|
+
import { p as reportTelegramError } from "../../../_chunks/inbound-request-BQQWCrWl.mjs";
|
|
8
8
|
import { gateway, generateText } from "ai";
|
|
9
9
|
const MAXIMUM_IMAGE_DESCRIPTION_BYTES = 5242880;
|
|
10
10
|
const MAXIMUM_NATIVE_IMAGE_BYTES = 3145728;
|
|
@@ -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-
|
|
7
|
+
export { t as InboundRequest, n as currentInboundRequest, r as runInboundRequest, i as withReplacedText } from "../../../_chunks/inbound-request-BQQWCrWl.mjs";
|
|
@@ -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 conversationLanguage, o as telegramPrincipal, u as runtimeEnvelope } from "../../../_chunks/principal-
|
|
9
|
+
import { d as telegramRuntimeSource, n as conversationLanguage, o as telegramPrincipal, u as runtimeEnvelope } from "../../../_chunks/principal-VsmaJp1x.mjs";
|
|
10
10
|
import { routingBurst } from "../group-routing/burst.mjs";
|
|
11
11
|
import { telegramSignals } from "./signals.mjs";
|
|
12
12
|
import { addressingReason, conversationKey, otherRecipient } from "../group-routing/signals.mjs";
|
|
@@ -30,7 +30,7 @@ import { MAXIMUM_ROUTING_ATTACHMENT_BYTES, describeRoutingAttachment, routingAtt
|
|
|
30
30
|
import { recordGateDecision, recordInboundContent, recordRouteDecision } from "./conversations.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-
|
|
33
|
+
import { p as reportTelegramError } from "../../../_chunks/inbound-request-BQQWCrWl.mjs";
|
|
34
34
|
const MAXIMUM_QUOTE_LENGTH = 500;
|
|
35
35
|
function buttonTo(text, url) {
|
|
36
36
|
return { inline_keyboard: [[{
|
|
@@ -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-
|
|
8
|
-
import { t as agentBuild } from "../../../_chunks/build-metadata-
|
|
9
|
-
import { n as currentInboundRequest } from "../../../_chunks/inbound-request-
|
|
7
|
+
import { d as telegramRuntimeSource, l as principalRuntimeSource, u as runtimeEnvelope } from "../../../_chunks/principal-VsmaJp1x.mjs";
|
|
8
|
+
import { t as agentBuild } from "../../../_chunks/build-metadata-DpwHNeNL.mjs";
|
|
9
|
+
import { n as currentInboundRequest } from "../../../_chunks/inbound-request-BQQWCrWl.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";
|
|
@@ -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-
|
|
8
|
+
import { p as reportTelegramError } from "../../../_chunks/inbound-request-BQQWCrWl.mjs";
|
|
9
9
|
function planMedia(capabilities, descriptionModel = null) {
|
|
10
10
|
if (typeof descriptionModel === "string") return {
|
|
11
11
|
images: "describe",
|
|
@@ -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-
|
|
7
|
+
export { t as TELEGRAM_AUTHENTICATOR, n as conversationLanguage, r as identityProviderOf, i as memberIdOf, a as rolesOf, o as telegramPrincipal } from "../../../_chunks/principal-VsmaJp1x.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-
|
|
7
|
+
import { p as reportTelegramError } from "../../../_chunks/inbound-request-BQQWCrWl.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-
|
|
8
|
+
import { a as TelegramDeliveryError, l as customerMessage, o as currentLocale, p as reportTelegramError } from "../../../_chunks/inbound-request-BQQWCrWl.mjs";
|
|
9
9
|
import { splitTelegramText } from "./format.mjs";
|
|
10
10
|
import { inTelegramSendQueue } from "./send-queue.mjs";
|
|
11
11
|
const SILENT_MARKERS = new Set(["[silent]", "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-
|
|
7
|
+
import { d as telegramRuntimeSource, u as runtimeEnvelope } from "../../../_chunks/principal-VsmaJp1x.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,8 @@ __eveCreateRequire(import.meta.url);
|
|
|
7
7
|
import { telegramText } from "./texts.mjs";
|
|
8
8
|
import { confirmationLocale } from "./confirmation-text.mjs";
|
|
9
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-
|
|
11
|
-
import { i as memberIdOf } from "../../../_chunks/principal-
|
|
10
|
+
import { c as customerCopy, d as failureText, o as currentLocale, p as reportTelegramError, s as currentThreadId } from "../../../_chunks/inbound-request-BQQWCrWl.mjs";
|
|
11
|
+
import { i as memberIdOf } from "../../../_chunks/principal-VsmaJp1x.mjs";
|
|
12
12
|
import { modelServiceFailure } from "../model-service-failure.mjs";
|
|
13
13
|
function telegramFailureEvents(input) {
|
|
14
14
|
return {
|
|
@@ -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-
|
|
8
|
+
import { p as reportTelegramError } from "../../../_chunks/inbound-request-BQQWCrWl.mjs";
|
|
9
9
|
import { gateway, transcribe } from "ai";
|
|
10
10
|
const LABELS = {
|
|
11
11
|
voice: "voice message",
|