@segmentstream/agent 0.6.11 → 0.6.13
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/README.md +10 -8
- package/dist/_chunks/{inbound-request-DRNPIIpb.mjs → inbound-request-CysnjMdw.mjs} +62 -62
- package/dist/extension/config.d.ts +7 -8
- package/dist/extension/config.mjs +20 -2
- package/dist/extension/instructions.md +8 -1
- package/dist/extension/lib/chat-post-confirmation.mjs +1 -1
- package/dist/extension/lib/confirmation-description.d.ts +1 -0
- package/dist/extension/lib/confirmation-description.mjs +29 -13
- package/dist/extension/lib/confirmations.d.ts +3 -0
- package/dist/extension/lib/confirmations.mjs +22 -5
- package/dist/extension/lib/customer-text-safety.d.ts +1 -0
- package/dist/extension/lib/customer-text-safety.mjs +23 -0
- package/dist/extension/lib/ontology-tools.mjs +13 -6
- package/dist/extension/lib/telegram/adapter.mjs +10 -6
- package/dist/extension/lib/telegram/attachments-send.mjs +6 -6
- package/dist/extension/lib/telegram/chat-post-card.d.ts +6 -13
- package/dist/extension/lib/telegram/chat-post-card.mjs +29 -37
- package/dist/extension/lib/telegram/confirmation-text.d.ts +20 -8
- package/dist/extension/lib/telegram/confirmation-text.mjs +55 -65
- package/dist/extension/lib/telegram/confirmations.d.ts +1 -2
- package/dist/extension/lib/telegram/confirmations.mjs +40 -96
- package/dist/extension/lib/telegram/content.d.ts +1 -1
- package/dist/extension/lib/telegram/conversations.mjs +1 -1
- package/dist/extension/lib/telegram/customer-text.d.ts +5 -5
- package/dist/extension/lib/telegram/customer-text.mjs +2 -1
- package/dist/extension/lib/telegram/files.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 +5 -5
- package/dist/extension/lib/telegram/media-policy.mjs +1 -1
- package/dist/extension/lib/telegram/principal.mjs +1 -1
- package/dist/extension/lib/telegram/silent.mjs +2 -2
- package/dist/extension/lib/telegram/turn-errors.mjs +2 -2
- package/dist/extension/lib/telegram/voice.mjs +1 -1
- package/package.json +2 -1
|
@@ -4,15 +4,16 @@ 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 { memberIdOf, telegramPrincipal } from "./principal.mjs";
|
|
8
8
|
import { chatPostOperationId, isChatPost } from "../chat-post-confirmation.mjs";
|
|
9
|
-
import {
|
|
9
|
+
import { renderConfirmation, withConfirmationText } from "./confirmation-text.mjs";
|
|
10
|
+
import { chatPostCard, chatPostCardStatus, chatPostReceipt, withChatPostCard } from "./chat-post-card.mjs";
|
|
10
11
|
import { confirmations } from "../confirmations.mjs";
|
|
11
12
|
import { conversationEvent } from "../conversations.mjs";
|
|
12
|
-
import {
|
|
13
|
+
import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-CysnjMdw.mjs";
|
|
13
14
|
import { answerMarker, isPendingQuestion, pendingQuestions, questionKey } from "../questions.mjs";
|
|
14
|
-
import { confirmationCopy, confirmationLocale, fallbackConfirmation } from "./confirmation-text.mjs";
|
|
15
15
|
import { formatAddress, scopedAddress } from "./sessions.mjs";
|
|
16
|
+
import { telegramTextLinks } from "@segmentstream-cloud/ontology/telegram";
|
|
16
17
|
import { registerTelegramFreeformPrompt, renderTelegramInputRequest } from "eve/channels/telegram";
|
|
17
18
|
import { createHash } from "node:crypto";
|
|
18
19
|
const PREFIX = "ss-confirm:";
|
|
@@ -54,10 +55,6 @@ function questionFromHistory(events, owner) {
|
|
|
54
55
|
for (const event of events) {
|
|
55
56
|
const data = object(event.data);
|
|
56
57
|
if (event.type === "context.cleared") pending.clear();
|
|
57
|
-
if (event.type === "input.resolved" && Array.isArray(data.resolutions)) for (const resolution of data.resolutions) {
|
|
58
|
-
const question = chatPostEditQuestion(object(resolution));
|
|
59
|
-
if (question !== void 0) pending.set(questionKey(question), question);
|
|
60
|
-
}
|
|
61
58
|
if (event.type === "action.result") {
|
|
62
59
|
const result = object(data.result);
|
|
63
60
|
const candidate = object(result.output).pendingQuestion;
|
|
@@ -69,16 +66,6 @@ function questionFromHistory(events, owner) {
|
|
|
69
66
|
}
|
|
70
67
|
return owner === void 0 ? [...pending.values()].at(-1) : pending.get(questionKey(owner));
|
|
71
68
|
}
|
|
72
|
-
function chatPostEditQuestion(resolution) {
|
|
73
|
-
const text = object(resolution.response).text;
|
|
74
|
-
if (resolution.outcome !== "cancelled" || typeof text !== "string") return;
|
|
75
|
-
try {
|
|
76
|
-
const question = object(JSON.parse(text)).pendingChatPostEdit;
|
|
77
|
-
return isPendingQuestion(question) ? question : void 0;
|
|
78
|
-
} catch {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
69
|
function questionAddress(owner) {
|
|
83
70
|
return formatAddress({
|
|
84
71
|
...owner,
|
|
@@ -87,27 +74,15 @@ function questionAddress(owner) {
|
|
|
87
74
|
}
|
|
88
75
|
async function handleConfirmationCallback(input) {
|
|
89
76
|
const { context, query } = input;
|
|
90
|
-
const chatLanguage = conversationLanguage([String(object(query.raw.message).text ?? "")]);
|
|
91
|
-
let language = chatLanguage ?? query.from.languageCode ?? "en";
|
|
92
77
|
const inbound = currentInboundRequest();
|
|
93
|
-
if (inbound !== void 0)
|
|
94
|
-
inbound.locale = language;
|
|
95
|
-
inbound.threadId = query.message?.messageThreadId === void 0 ? void 0 : String(query.message.messageThreadId);
|
|
96
|
-
}
|
|
97
|
-
const notices = {
|
|
98
|
-
"Unsupported action.": "Действие недоступно.",
|
|
99
|
-
"Only the requesting member can confirm or cancel this action.": "Подтвердить или отменить действие может только тот, кто его запросил.",
|
|
100
|
-
"This confirmation is no longer pending.": "Это подтверждение больше не ожидает ответа.",
|
|
101
|
-
"This confirmation expired; nothing executed.": "Срок подтверждения истёк. Действие не выполнено.",
|
|
102
|
-
"Cancellation received.": "Отменено.",
|
|
103
|
-
"Confirmation received.": "Подтверждено."
|
|
104
|
-
};
|
|
78
|
+
if (inbound !== void 0) inbound.threadId = query.message?.messageThreadId === void 0 ? void 0 : String(query.message.messageThreadId);
|
|
105
79
|
const notice = (text) => context.telegram.answerCallbackQuery({
|
|
106
80
|
callbackQueryId: query.id,
|
|
107
|
-
text
|
|
81
|
+
...text === void 0 ? {} : { text },
|
|
82
|
+
showAlert: false
|
|
108
83
|
});
|
|
109
84
|
if (!query.data?.startsWith(PREFIX) || query.message === void 0 || query.from.isBot) {
|
|
110
|
-
await notice("
|
|
85
|
+
await notice("⚠️");
|
|
111
86
|
return;
|
|
112
87
|
}
|
|
113
88
|
const [requestHash, memberHash, choice] = query.data.slice(11).split(":");
|
|
@@ -115,12 +90,8 @@ async function handleConfirmationCallback(input) {
|
|
|
115
90
|
provider: "telegram",
|
|
116
91
|
externalId: query.from.id
|
|
117
92
|
});
|
|
118
|
-
if (lookup.status === "paired" && chatLanguage === void 0) {
|
|
119
|
-
language = lookup.member.locale ?? language;
|
|
120
|
-
if (inbound !== void 0) inbound.locale = language;
|
|
121
|
-
}
|
|
122
93
|
if (lookup.status !== "paired" || shortHash(lookup.member.id) !== memberHash) {
|
|
123
|
-
await notice("
|
|
94
|
+
await notice("🔒");
|
|
124
95
|
return;
|
|
125
96
|
}
|
|
126
97
|
const address = scopedAddress(formatAddress({
|
|
@@ -135,7 +106,7 @@ async function handleConfirmationCallback(input) {
|
|
|
135
106
|
"n",
|
|
136
107
|
"e"
|
|
137
108
|
].includes(choice ?? "") || choice === "e" && !isChatPost(prompt.toolName)) {
|
|
138
|
-
await notice("
|
|
109
|
+
await notice("⌛");
|
|
139
110
|
return;
|
|
140
111
|
}
|
|
141
112
|
const expired = !Number.isFinite(prompt.at) || prompt.at + 6e5 <= (input.now ?? Date.now());
|
|
@@ -154,15 +125,6 @@ async function handleConfirmationCallback(input) {
|
|
|
154
125
|
});
|
|
155
126
|
const source = currentInboundRequest()?.respond;
|
|
156
127
|
if (source === void 0) throw new Error("Confirmation callback has no session continuation.");
|
|
157
|
-
const editQuestion = edit ? {
|
|
158
|
-
id: `edit-${prompt.callId}`,
|
|
159
|
-
memberId: lookup.member.id,
|
|
160
|
-
chatId: query.message.chat.id,
|
|
161
|
-
messageThreadId: String(query.message.messageThreadId ?? ""),
|
|
162
|
-
address,
|
|
163
|
-
question: chatPostCopy(language).changes,
|
|
164
|
-
task: `The previous chat post was cancelled for editing. Apply the member's changes to this draft, then make a NEW chat_post_message call and confirmation. Never reuse the cancelled call. Previous input: ${JSON.stringify(prompt.input)}`
|
|
165
|
-
} : void 0;
|
|
166
128
|
await source(address, prompt.requestId, decision, {
|
|
167
129
|
...principal,
|
|
168
130
|
attributes: {
|
|
@@ -171,10 +133,10 @@ async function handleConfirmationCallback(input) {
|
|
|
171
133
|
confirmationDecision: decision,
|
|
172
134
|
...expired ? { confirmationReason: "expired" } : edit ? { confirmationReason: "edit" } : {}
|
|
173
135
|
}
|
|
174
|
-
},
|
|
175
|
-
await notice(expired ? "
|
|
136
|
+
}, edit ? "The chat post was cancelled for editing. Ask the member what to change using questions_ask, then make a NEW chat_post_message call and confirmation. Never reuse the cancelled call." : void 0);
|
|
137
|
+
await notice(expired ? "⌛" : void 0);
|
|
176
138
|
}
|
|
177
|
-
function telegramConfirmationEvents(
|
|
139
|
+
function telegramConfirmationEvents(archive) {
|
|
178
140
|
const record = async (callId, phase, text, status, ctx) => {
|
|
179
141
|
const saved = confirmations.get()[callId];
|
|
180
142
|
if (archive === void 0 || saved?.description?.chatPost === void 0 || saved.source === void 0) return;
|
|
@@ -241,10 +203,12 @@ function telegramConfirmationEvents(render = async (description, locale) => fall
|
|
|
241
203
|
}
|
|
242
204
|
const memberId = confirmations.get()[request.action.callId]?.memberId ?? memberIdOf(ctx.session.auth.current);
|
|
243
205
|
if (memberId === void 0) throw new Error("Confirmation requires a member.");
|
|
244
|
-
const
|
|
206
|
+
const saved = confirmations.get()[request.action.callId];
|
|
207
|
+
const description = saved?.description;
|
|
245
208
|
const exactPost = isChatPost(request.action.toolName);
|
|
209
|
+
if (description === void 0) throw new Error("Approval buttons require trusted confirmation facts.");
|
|
246
210
|
if (exactPost && description?.chatPost === void 0) throw new Error("An exact chat post cannot show a generic confirmation.");
|
|
247
|
-
const copy = description?.chatPost === void 0 ?
|
|
211
|
+
const copy = description?.chatPost === void 0 ? renderConfirmation(description, saved?.copy) : chatPostCard(description, saved?.copy);
|
|
248
212
|
const text = copy.text;
|
|
249
213
|
await record(request.action.callId, "preview", text, "requested", ctx);
|
|
250
214
|
const send = () => channel.telegram.post({
|
|
@@ -255,7 +219,7 @@ function telegramConfirmationEvents(render = async (description, locale) => fall
|
|
|
255
219
|
callback_data: confirmationCallback(request.requestId, memberId, "approve")
|
|
256
220
|
},
|
|
257
221
|
...exactPost ? [{
|
|
258
|
-
text:
|
|
222
|
+
text: copy.edit,
|
|
259
223
|
callback_data: confirmationCallback(request.requestId, memberId, "edit")
|
|
260
224
|
}] : [],
|
|
261
225
|
{
|
|
@@ -264,7 +228,7 @@ function telegramConfirmationEvents(render = async (description, locale) => fall
|
|
|
264
228
|
}
|
|
265
229
|
]] }
|
|
266
230
|
});
|
|
267
|
-
const sent = await (exactPost ? withChatPostCard(text, send) : send
|
|
231
|
+
const sent = await (exactPost ? withChatPostCard(text, send, copy.previewLinks) : withConfirmationText(text, send));
|
|
268
232
|
const state = channel.state;
|
|
269
233
|
state.confirmationMessages = {
|
|
270
234
|
...state.confirmationMessages,
|
|
@@ -273,8 +237,8 @@ function telegramConfirmationEvents(render = async (description, locale) => fall
|
|
|
273
237
|
messageId: sent.id,
|
|
274
238
|
text,
|
|
275
239
|
copy,
|
|
276
|
-
|
|
277
|
-
|
|
240
|
+
exactPost,
|
|
241
|
+
previewLinks: copy.previewLinks
|
|
278
242
|
}
|
|
279
243
|
};
|
|
280
244
|
}
|
|
@@ -291,47 +255,24 @@ function telegramConfirmationEvents(render = async (description, locale) => fall
|
|
|
291
255
|
await channel.telegram.editMessageText({
|
|
292
256
|
messageId: prompt.messageId,
|
|
293
257
|
replyMarkup: { inline_keyboard: [] },
|
|
294
|
-
text: `${prompt.text}\n\n${label ??
|
|
258
|
+
text: `${prompt.text}\n\n${label ?? "✅"}`
|
|
295
259
|
});
|
|
296
260
|
delete channel.state.hitlPrompts?.[resolution.requestId];
|
|
297
261
|
}
|
|
298
262
|
continue;
|
|
299
263
|
}
|
|
300
264
|
const [callId, message] = entry;
|
|
301
|
-
const copy = message.copy ??
|
|
265
|
+
const copy = message.copy ?? renderConfirmation();
|
|
302
266
|
const reason = confirmations.get()[callId]?.cancellationReason;
|
|
303
|
-
const status = resolution.outcome === "approved" ? copy.executing : reason === "expired" ?
|
|
304
|
-
const text = message.exactPost ? chatPostCardStatus(message.text, status) : status
|
|
267
|
+
const status = resolution.outcome === "approved" ? copy.executing : reason === "expired" ? copy.expired : copy.cancelled;
|
|
268
|
+
const text = message.exactPost ? chatPostCardStatus(message.text, status) : `${message.text}\n\n${status}`;
|
|
305
269
|
const edit = () => channel.telegram.editMessageText({
|
|
306
270
|
messageId: message.messageId,
|
|
307
271
|
replyMarkup: { inline_keyboard: [] },
|
|
308
272
|
text
|
|
309
273
|
});
|
|
310
|
-
await (message.exactPost ? withChatPostCard(text, edit) : edit
|
|
311
|
-
await record(callId, reason ?? resolution.outcome, text, resolution.outcome === "approved" ? "
|
|
312
|
-
const question = chatPostEditQuestion(resolution);
|
|
313
|
-
if (message.exactPost && reason === "edit" && question !== void 0) {
|
|
314
|
-
pendingQuestions.update((all) => ({
|
|
315
|
-
...all,
|
|
316
|
-
[questionKey(question)]: question
|
|
317
|
-
}));
|
|
318
|
-
state.pendingQuestions = {
|
|
319
|
-
...state.pendingQuestions,
|
|
320
|
-
[questionKey(question)]: question
|
|
321
|
-
};
|
|
322
|
-
channel.continuation?.alias(questionAddress(question));
|
|
323
|
-
channel.continuation?.alias(formatAddress({
|
|
324
|
-
...question,
|
|
325
|
-
conversationId: ""
|
|
326
|
-
}));
|
|
327
|
-
await channel.telegram.post({
|
|
328
|
-
text: question.question,
|
|
329
|
-
reply_markup: {
|
|
330
|
-
force_reply: true,
|
|
331
|
-
selective: true
|
|
332
|
-
}
|
|
333
|
-
});
|
|
334
|
-
}
|
|
274
|
+
await (message.exactPost ? withChatPostCard(text, edit, [...message.previewLinks ?? [], ...telegramTextLinks(status)]) : withConfirmationText(text, edit));
|
|
275
|
+
await record(callId, reason ?? resolution.outcome, text, resolution.outcome === "approved" ? "requested" : "cancelled", ctx);
|
|
335
276
|
if (resolution.outcome !== "approved") {
|
|
336
277
|
delete state.confirmationMessages?.[callId];
|
|
337
278
|
confirmations.update((all) => ({
|
|
@@ -385,24 +326,27 @@ function telegramConfirmationEvents(render = async (description, locale) => fall
|
|
|
385
326
|
if (message === void 0) return;
|
|
386
327
|
const failed = data.status !== "completed" || data.result.kind === "tool-result" && (data.result.isError === true || object(data.result.output).isError === true || object(object(data.result.output).validation).ok === false);
|
|
387
328
|
if (message.exactPost) {
|
|
388
|
-
const
|
|
389
|
-
const receipt = !failed && data.result.kind === "tool-result" ? chatPostReceipt(data.result.output,
|
|
329
|
+
const copy = message.copy ?? renderConfirmation();
|
|
330
|
+
const receipt = !failed && data.result.kind === "tool-result" ? chatPostReceipt(data.result.output, copy.completed) : void 0;
|
|
390
331
|
const errorId = failed ? reportTelegramError("confirmed_chat_post_failed", data, { callId: data.result.callId }) : void 0;
|
|
391
|
-
const status = receipt ?? (failed ? `${
|
|
332
|
+
const status = receipt ?? (failed ? `${copy.failed} ${errorId}\n⚠️ ❓` : "⚠️ ❓");
|
|
392
333
|
const text = chatPostCardStatus(message.text, status);
|
|
393
334
|
await withChatPostCard(text, () => channel.telegram.editMessageText({
|
|
394
335
|
messageId: message.messageId,
|
|
395
336
|
replyMarkup: { inline_keyboard: [] },
|
|
396
337
|
text
|
|
397
|
-
}));
|
|
338
|
+
}), [...message.previewLinks ?? [], ...telegramTextLinks(status)]);
|
|
398
339
|
await record(data.result.callId, "receipt", text, failed ? "failed" : object(data.result.kind === "tool-result" ? data.result.output : void 0).status === "sent" ? "completed" : "unknown", ctx);
|
|
399
|
-
} else
|
|
400
|
-
const
|
|
401
|
-
|
|
340
|
+
} else {
|
|
341
|
+
const copy = message.copy ?? renderConfirmation();
|
|
342
|
+
const errorId = failed ? reportTelegramError("confirmed_action_failed", data, { callId: data.result.callId }) : void 0;
|
|
343
|
+
const status = failed ? `${copy.failed} ${errorId}` : copy.completed;
|
|
344
|
+
const text = `${message.text}\n\n${status}`;
|
|
345
|
+
await withConfirmationText(text, () => channel.telegram.editMessageText({
|
|
402
346
|
messageId: message.messageId,
|
|
403
347
|
replyMarkup: { inline_keyboard: [] },
|
|
404
|
-
text
|
|
405
|
-
});
|
|
348
|
+
text
|
|
349
|
+
}));
|
|
406
350
|
}
|
|
407
351
|
delete state.confirmationMessages?.[data.result.callId];
|
|
408
352
|
},
|
|
@@ -17,7 +17,7 @@ export declare function telegramRecord(value: unknown): Readonly<Record<string,
|
|
|
17
17
|
export declare function messageContent(raw: Readonly<Record<string, unknown>>): MessageContent;
|
|
18
18
|
/** Only shape/size diagnostics: do not retain/log raw webhook bodies, URLs or credential values. */
|
|
19
19
|
export declare function contentShape(raw: Readonly<Record<string, unknown>>, content?: MessageContent): {
|
|
20
|
-
contentSource: "
|
|
20
|
+
contentSource: "none" | "text" | "caption" | "rich_message";
|
|
21
21
|
textType: "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
|
|
22
22
|
captionType: "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
|
|
23
23
|
hasRichMessage: boolean;
|
|
@@ -6,7 +6,7 @@ __eveDirname(__filename);
|
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { collapseConversationEvents, conversationEvent } from "../conversations.mjs";
|
|
8
8
|
import { observedChatKey } from "./observed.mjs";
|
|
9
|
-
import { n as currentInboundRequest, s as currentThreadId } from "../../../_chunks/inbound-request-
|
|
9
|
+
import { n as currentInboundRequest, s as currentThreadId } from "../../../_chunks/inbound-request-CysnjMdw.mjs";
|
|
10
10
|
import { reportMembership } from "./membership.mjs";
|
|
11
11
|
import { contentShape, messageContent } from "./content.mjs";
|
|
12
12
|
import { parseTelegramUpdate } from "eve/channels/telegram";
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
+
import { type TelegramPreviewContext } from "@segmentstream-cloud/ontology/telegram";
|
|
1
2
|
import { type TelegramText } from "./format.js";
|
|
3
|
+
export { isTechnicalText } from "../customer-text-safety.js";
|
|
2
4
|
export declare function withDeliveryLocale<T>(locale: string, run: () => T, threadId?: string): T;
|
|
3
5
|
export declare function currentLocale(): string;
|
|
4
6
|
export declare function currentThreadId(): string | undefined;
|
|
5
|
-
export declare function customerCopy(
|
|
7
|
+
export declare function customerCopy(): {
|
|
6
8
|
failed: string;
|
|
7
9
|
recovery: string;
|
|
8
10
|
attachment: string;
|
|
9
11
|
authorization: string;
|
|
10
12
|
response: string;
|
|
11
|
-
reference: string;
|
|
12
13
|
connected: string;
|
|
13
14
|
disconnected: string;
|
|
14
15
|
};
|
|
15
|
-
export declare function isTechnicalText(text: string): boolean;
|
|
16
16
|
/** Original failures stay in operator diagnostics, joined to the public notice by a short reference. */
|
|
17
17
|
export declare function reportTelegramError(operation: string, error: unknown, metadata?: Record<string, unknown>, secrets?: ReadonlySet<string>): string;
|
|
18
|
-
export declare function failureText(errorId: string, kind?: "failed" | "cancelled" | "recovery" | "attachment" | "authorization" | "response",
|
|
18
|
+
export declare function failureText(errorId: string, kind?: "failed" | "cancelled" | "recovery" | "attachment" | "authorization" | "response", _locale?: string): string;
|
|
19
19
|
export declare function customerText(text: string, locale?: string): string;
|
|
20
20
|
/** Check what Telegram will display, including hidden link destinations, after removing markup. */
|
|
21
21
|
export declare function customerMessage(text: string, locale?: string): TelegramText;
|
|
@@ -29,4 +29,4 @@ export declare class TelegramDeliveryError extends Error {
|
|
|
29
29
|
constructor(reference: string, delivery: "failed" | "unknown", messageIds: readonly number[]);
|
|
30
30
|
}
|
|
31
31
|
/** Covers framework defaults, edits and callback notices as well as ordinary agent replies. */
|
|
32
|
-
export declare function safeTelegramFetch(fetchImpl: typeof fetch, scope?: string): typeof fetch;
|
|
32
|
+
export declare function safeTelegramFetch(fetchImpl: typeof fetch, scope?: string, previews?: TelegramPreviewContext): typeof fetch;
|
|
@@ -4,5 +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 {
|
|
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-CysnjMdw.mjs";
|
|
8
9
|
export { TelegramDeliveryError, currentLocale, currentThreadId, customerCopy, customerMessage, customerText, failureText, formattingRefused, isTechnicalText, reportTelegramError, safeTelegramFetch, withDeliveryLocale };
|
|
@@ -6,7 +6,7 @@ __eveDirname(__filename);
|
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { conversationLanguage } from "./principal.mjs";
|
|
8
8
|
import { MAXIMUM_ATTACHMENT_BYTES, attachmentUrl } from "../attachments.mjs";
|
|
9
|
-
import { d as failureText,
|
|
9
|
+
import { d as failureText, p as reportTelegramError } from "../../../_chunks/inbound-request-CysnjMdw.mjs";
|
|
10
10
|
import { describableImage, describeReceivedImage } from "./images.mjs";
|
|
11
11
|
function telegramConversation(chatId) {
|
|
12
12
|
return `telegram:${chatId}`;
|
|
@@ -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 { p as reportTelegramError } from "../../../_chunks/inbound-request-CysnjMdw.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,5 +4,5 @@ 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 { i as withReplacedText, n as currentInboundRequest, r as runInboundRequest, t as InboundRequest } from "../../../_chunks/inbound-request-
|
|
7
|
+
import { i as withReplacedText, n as currentInboundRequest, r as runInboundRequest, t as InboundRequest } from "../../../_chunks/inbound-request-CysnjMdw.mjs";
|
|
8
8
|
export { InboundRequest, currentInboundRequest, runInboundRequest, withReplacedText };
|
|
@@ -19,9 +19,9 @@ import { messageAudience } from "./audience.mjs";
|
|
|
19
19
|
import { addressingReason, routeMessage } from "./router.mjs";
|
|
20
20
|
import { routingContext } from "./routing-context.mjs";
|
|
21
21
|
import { voiceOf, voiceText } from "./voice.mjs";
|
|
22
|
-
const UNKNOWN_PRIVATE = "
|
|
23
|
-
const UNKNOWN_IN_GROUP = "
|
|
24
|
-
const REFUSED = "
|
|
22
|
+
const UNKNOWN_PRIVATE = "🔗";
|
|
23
|
+
const UNKNOWN_IN_GROUP = "🔒";
|
|
24
|
+
const REFUSED = "🔒";
|
|
25
25
|
const MAXIMUM_QUOTE_LENGTH = 500;
|
|
26
26
|
function buttonTo(text, url) {
|
|
27
27
|
return { inline_keyboard: [[{
|
|
@@ -80,7 +80,7 @@ function speakerBlock(input) {
|
|
|
80
80
|
function unknownInGroup(bot) {
|
|
81
81
|
return bot?.username === void 0 ? { text: UNKNOWN_IN_GROUP } : {
|
|
82
82
|
text: UNKNOWN_IN_GROUP,
|
|
83
|
-
reply_markup: buttonTo("
|
|
83
|
+
reply_markup: buttonTo("✉️", `https://t.me/${bot.username}`)
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
86
|
async function answerUnpaired(input) {
|
|
@@ -101,7 +101,7 @@ async function answerUnpaired(input) {
|
|
|
101
101
|
});
|
|
102
102
|
await context.telegram.post({
|
|
103
103
|
text: UNKNOWN_PRIVATE,
|
|
104
|
-
reply_markup: buttonTo("
|
|
104
|
+
reply_markup: buttonTo("🔗", dependencies.connectUrl(pairing.code))
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
107
|
function isGroupChat(message) {
|
|
@@ -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 {
|
|
8
|
+
import { p as reportTelegramError } from "../../../_chunks/inbound-request-CysnjMdw.mjs";
|
|
9
9
|
function planMedia(capabilities, descriptionModel = null) {
|
|
10
10
|
if (typeof descriptionModel === "string") return {
|
|
11
11
|
images: "describe",
|
|
@@ -35,7 +35,7 @@ function telegramPrincipal(input) {
|
|
|
35
35
|
}
|
|
36
36
|
function conversationLanguage(texts) {
|
|
37
37
|
for (const text of texts) {
|
|
38
|
-
if (/[
|
|
38
|
+
if (/[\u0430-\u044f\u0451]/iu.test(text)) return "ru";
|
|
39
39
|
if ((text.match(/\b[a-z]+\b/gi)?.length ?? 0) >= 3) return "en";
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -5,11 +5,11 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import "./principal.mjs";
|
|
8
|
+
import { confirmationLocale } from "./confirmation-text.mjs";
|
|
8
9
|
import { agentMessage, observedChatKey } from "./observed.mjs";
|
|
9
10
|
import { splitTelegramText } from "./format.mjs";
|
|
10
11
|
import { inTelegramSendQueue } from "./send-queue.mjs";
|
|
11
|
-
import { a as TelegramDeliveryError, l as customerMessage,
|
|
12
|
-
import { confirmationLocale } from "./confirmation-text.mjs";
|
|
12
|
+
import { a as TelegramDeliveryError, l as customerMessage, o as currentLocale, p as reportTelegramError } from "../../../_chunks/inbound-request-CysnjMdw.mjs";
|
|
13
13
|
const SILENT_MARKERS = new Set(["[silent]", "no_reply"]);
|
|
14
14
|
function isSilentReply(text) {
|
|
15
15
|
return SILENT_MARKERS.has(text.trim().toLowerCase());
|
|
@@ -5,8 +5,8 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { memberIdOf } from "./principal.mjs";
|
|
8
|
-
import { c as customerCopy, d as failureText, m as reportTelegramError, o as currentLocale } from "../../../_chunks/inbound-request-DRNPIIpb.mjs";
|
|
9
8
|
import { confirmationLocale } from "./confirmation-text.mjs";
|
|
9
|
+
import { c as customerCopy, d as failureText, o as currentLocale, p as reportTelegramError } from "../../../_chunks/inbound-request-CysnjMdw.mjs";
|
|
10
10
|
const telegramFailureEvents = {
|
|
11
11
|
async "turn.cancelled"(event, channel, context) {
|
|
12
12
|
const errorId = reportTelegramError("turn_cancelled", event, {
|
|
@@ -37,7 +37,7 @@ const telegramFailureEvents = {
|
|
|
37
37
|
const messageId = channel.state.pendingAuthMessageIds?.[event.name];
|
|
38
38
|
if (event.candidateId !== void 0 || messageId === void 0) return;
|
|
39
39
|
const locale = confirmationLocale(context.session.auth.current);
|
|
40
|
-
const copy = customerCopy(
|
|
40
|
+
const copy = customerCopy();
|
|
41
41
|
let text = event.outcome === "authorized" ? copy.connected : copy.disconnected;
|
|
42
42
|
if (event.reason !== void 0) {
|
|
43
43
|
const errorId = reportTelegramError("authorization_not_completed", event, { chatId: channel.state.chatId });
|
|
@@ -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 {
|
|
8
|
+
import { p as reportTelegramError } from "../../../_chunks/inbound-request-CysnjMdw.mjs";
|
|
9
9
|
import { gateway, transcribe } from "ai";
|
|
10
10
|
const LABELS = {
|
|
11
11
|
voice: "voice message",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/agent",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.13",
|
|
4
4
|
"description": "Mount a SegmentStream workspace's agent on eve: the ontology as tools, acting as the member who writes, and Telegram through the workspace's connection.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "SegmentStream",
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"@chat-adapter/telegram": "4.41.0",
|
|
64
|
+
"@segmentstream-cloud/ontology": "0.31.5",
|
|
64
65
|
"@vercel/oidc": "^3.8.4",
|
|
65
66
|
"ai": "^7.0.128",
|
|
66
67
|
"csv-parse": "^7.0.3",
|