@segmentstream/agent 0.91.2 → 0.93.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 +18 -0
- package/README.md +3 -3
- package/dist/_chunks/{build-metadata-CsM7GfS1.mjs → build-metadata-CP0iLqzp.mjs} +1 -1
- package/dist/_chunks/{chat-archive-Btd3gajb.mjs → chat-archive-DmCXcI8G.mjs} +44 -10
- package/dist/_chunks/{chat-archive-DavfKJDI.mjs → chat-archive-_IBU0CXG.mjs} +7 -2
- package/dist/_chunks/{principal-CY72xYFi.mjs → principal-DL9NdRRP.mjs} +5 -1
- package/dist/_chunks/{silent-DK7m_iab.mjs → silent-xJcJ8SNJ.mjs} +1 -1
- package/dist/extension/_manifest.json +1 -1
- package/dist/extension/config.d.ts +9 -0
- package/dist/extension/config.mjs +25 -0
- package/dist/extension/connections/ontology.mjs +1 -1
- package/dist/extension/hooks/authorization.mjs +1 -1
- package/dist/extension/hooks/chat-context.mjs +1 -1
- package/dist/extension/hooks/chat-recorder.mjs +1 -1
- package/dist/extension/instructions/persona.mjs +1 -1
- package/dist/extension/lib/actor.mjs +1 -1
- package/dist/extension/lib/attachment-tools.mjs +1 -1
- package/dist/extension/lib/attachments-dispatch.mjs +2 -2
- package/dist/extension/lib/attachments-send.mjs +1 -1
- package/dist/extension/lib/attachments.mjs +1 -1
- package/dist/extension/lib/build-metadata.mjs +1 -1
- package/dist/extension/lib/chat-address.mjs +1 -1
- package/dist/extension/lib/chat-archive.d.ts +1 -0
- package/dist/extension/lib/chat-archive.mjs +1 -1
- package/dist/extension/lib/chat-context.mjs +6 -5
- package/dist/extension/lib/chat-messages.d.ts +1 -1
- package/dist/extension/lib/chat-messages.mjs +3 -2
- package/dist/extension/lib/chat-persona.d.ts +2 -0
- package/dist/extension/lib/chat-persona.mjs +6 -6
- package/dist/extension/lib/chat-recorder.mjs +13 -10
- package/dist/extension/lib/chat-store.d.ts +21 -10
- package/dist/extension/lib/chats.d.ts +2 -0
- package/dist/extension/lib/chats.mjs +4 -2
- package/dist/extension/lib/confirmations.mjs +1 -1
- package/dist/extension/lib/email/attachments-send.mjs +1 -1
- package/dist/extension/lib/email/channel.mjs +3 -3
- package/dist/extension/lib/group-routing/messages.d.ts +1 -0
- package/dist/extension/lib/group-routing/routing-context.mjs +6 -4
- package/dist/extension/lib/guest-usage.mjs +1 -1
- package/dist/extension/lib/inbound-media/files.mjs +1 -1
- package/dist/extension/lib/inbound-media/index.mjs +1 -1
- package/dist/extension/lib/model-service-alert.mjs +1 -1
- package/dist/extension/lib/ontology-connection.mjs +1 -1
- package/dist/extension/lib/ontology-file-call.mjs +1 -1
- package/dist/extension/lib/ontology-recall.mjs +1 -1
- package/dist/extension/lib/ontology-tools.mjs +1 -1
- package/dist/extension/lib/public-group.d.ts +19 -0
- package/dist/extension/lib/public-group.mjs +77 -0
- package/dist/extension/lib/review/files.mjs +1 -1
- package/dist/extension/lib/review/hold.mjs +1 -1
- package/dist/extension/lib/review/judge.mjs +1 -1
- package/dist/extension/lib/review/reply.mjs +3 -3
- package/dist/extension/lib/review/revision-channel.mjs +1 -1
- 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 -1
- package/dist/extension/lib/slack/adapter.d.ts +1 -0
- package/dist/extension/lib/slack/adapter.mjs +22 -6
- package/dist/extension/lib/slack/attachments-send.mjs +1 -1
- package/dist/extension/lib/slack/callbacks.mjs +1 -1
- package/dist/extension/lib/slack/changes.mjs +1 -1
- package/dist/extension/lib/slack/confirmation-card.mjs +1 -1
- package/dist/extension/lib/stored-files.mjs +1 -1
- package/dist/extension/lib/telegram/adapter.mjs +20 -8
- package/dist/extension/lib/telegram/attachment-description.mjs +1 -1
- package/dist/extension/lib/telegram/attachments-send.mjs +1 -1
- package/dist/extension/lib/telegram/bot.d.ts +1 -1
- package/dist/extension/lib/telegram/bot.mjs +2 -2
- package/dist/extension/lib/telegram/callbacks.mjs +1 -1
- package/dist/extension/lib/telegram/chat-archive.d.ts +3 -1
- package/dist/extension/lib/telegram/chat-archive.mjs +1 -1
- package/dist/extension/lib/telegram/confirmations.mjs +3 -3
- package/dist/extension/lib/telegram/customer-text.mjs +1 -1
- package/dist/extension/lib/telegram/delivery-diagnostics.mjs +1 -1
- package/dist/extension/lib/telegram/files.mjs +1 -1
- 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 +1 -0
- package/dist/extension/lib/telegram/inbound-request.mjs +1 -1
- package/dist/extension/lib/telegram/inbound.mjs +28 -3
- package/dist/extension/lib/telegram/lifecycle.mjs +2 -2
- package/dist/extension/lib/telegram/membership.mjs +8 -2
- package/dist/extension/lib/telegram/message-reference.d.ts +3 -0
- package/dist/extension/lib/telegram/message-reference.mjs +11 -0
- package/dist/extension/lib/telegram/principal.mjs +1 -1
- package/dist/extension/lib/telegram/routing-context.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/store-capture.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/web/auth.mjs +1 -1
- package/dist/extension/lib/web/channel.mjs +1 -1
- package/dist/extension/lib/web-search.d.ts +2 -0
- package/dist/extension/lib/web-search.mjs +1 -1
- package/dist/extension/lib/whatsapp/adapter.mjs +2 -2
- package/dist/extension/lib/whatsapp/attachments-send.mjs +2 -2
- package/dist/extension/lib/whatsapp/callbacks.mjs +1 -1
- package/dist/extension/lib/whatsapp/changes.mjs +1 -1
- package/dist/extension/lib/whatsapp/files.mjs +1 -1
- package/dist/extension/lib/whatsapp/sent.mjs +1 -1
- package/dist/extension/lib/workspace-action.mjs +1 -1
- package/dist/extension/lib/workspace-channel/attachments-send.mjs +1 -1
- package/dist/extension/lib/workspace-channel/channel.mjs +3 -3
- package/dist/extension/lib/workspace-chat-archive.mjs +1 -1
- package/dist/extension/lib/workspace-source.mjs +1 -1
- 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 -1
- package/dist/extension/tools/attachments_read.mjs +1 -1
- package/dist/extension/tools/attachments_send.mjs +2 -2
- package/dist/extension/tools/attachments_stage.mjs +1 -1
- package/dist/extension/tools/attachments_table.mjs +1 -1
- package/dist/extension/tools/handoff.mjs +1 -1
- package/dist/extension/tools/questions_ask.mjs +1 -1
- package/dist/extension/tools/workspace_source.mjs +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.93.0
|
|
4
|
+
|
|
5
|
+
Allow workspace operators to enable bounded, tool-free answers to unlinked senders in individual Telegram and Slack group chats. Dedicated connections can use a verified inviter's existing permission to open a newly joined group.
|
|
6
|
+
|
|
7
|
+
Pins @segmentstream/ontology 0.175.0.
|
|
8
|
+
|
|
9
|
+
## 0.92.0
|
|
10
|
+
|
|
11
|
+
Telegram messages, edits and delivery receipts keep the bot account that received or sent them.
|
|
12
|
+
Switching bots in a basic group preserves both messages when Telegram reuses a number. Older
|
|
13
|
+
messages keep their original history and a verified redelivery retains its dispatch state.
|
|
14
|
+
|
|
15
|
+
The workspace agent and web chat now use Eve 1.6.0.
|
|
16
|
+
|
|
17
|
+
Action required: pin `eve` to `1.6.0` in the agent, upgrade the Agent and App SDKs together, and upgrade the Ontology SDK before or alongside them.
|
|
18
|
+
|
|
19
|
+
Pins @segmentstream/ontology 0.174.1.
|
|
20
|
+
|
|
3
21
|
## 0.91.2
|
|
4
22
|
|
|
5
23
|
Pins @segmentstream/ontology 0.174.0.
|
package/README.md
CHANGED
|
@@ -10,13 +10,13 @@ something it does.
|
|
|
10
10
|
Guides named by path below, such as `docs/ontology.md`, are in every workspace project;
|
|
11
11
|
`segmentstream upgrade` keeps them current.
|
|
12
12
|
|
|
13
|
-
The package is built against one eve version, `1.
|
|
13
|
+
The package is built against one eve version, `1.6.0`, and the workspace's `agent/` pins the
|
|
14
14
|
same one. eve and the package move together.
|
|
15
15
|
|
|
16
16
|
## Install
|
|
17
17
|
|
|
18
18
|
```sh
|
|
19
|
-
npm install @segmentstream/agent eve@1.
|
|
19
|
+
npm install @segmentstream/agent eve@1.6.0
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
## Deploying workspace source
|
|
@@ -897,7 +897,7 @@ Eve resolution, so member/topic routing survives a cold start. No second provide
|
|
|
897
897
|
|
|
898
898
|
## Release and migration
|
|
899
899
|
|
|
900
|
-
The original exact-post release used Agent SDK 0.17.13, Eve 0.76.3, Ontology SDK 0.56.0 and App SDK 0.25.2. Current builds require eve 1.
|
|
900
|
+
The original exact-post release used Agent SDK 0.17.13, Eve 0.76.3, Ontology SDK 0.56.0 and App SDK 0.25.2. Current builds require eve 1.6.0 and a rebuilt Agent SDK extension.
|
|
901
901
|
In the next release, feedback file guidance follows the visible tools.
|
|
902
902
|
The compatible Cloud archive/API must be deployed first; migrations run only through its CI/CD gate.
|
|
903
903
|
Publish the ontology SDK before the agent SDK. Upgrade the workspace ontology before its agent,
|
|
@@ -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
|
-
var version = "0.
|
|
7
|
+
var version = "0.93.0";
|
|
8
8
|
function agentBuild(environment = process.env) {
|
|
9
9
|
return {
|
|
10
10
|
agent: version,
|
|
@@ -8,10 +8,10 @@ import { logConfirmationPress } from "../extension/lib/telegram/confirmation-pre
|
|
|
8
8
|
import { parseArchivedMessage } from "../extension/lib/telegram/archive-message.mjs";
|
|
9
9
|
import { currentChannel, currentKey } from "../extension/lib/channel-scope.mjs";
|
|
10
10
|
import { n as contentText, t as CONTENT_CAPS } from "./content-cDtVnr8Y.mjs";
|
|
11
|
-
import { C as sendFingerprint, S as reasonCode, _ as boundedMeta, a as chatEvent, b as messageInput, f as sessionFailureEventId, p as storeOf, v as cutText, w as storedFiles, x as metaOf } from "./chat-archive-
|
|
11
|
+
import { C as sendFingerprint, S as reasonCode, _ as boundedMeta, a as chatEvent, b as messageInput, f as sessionFailureEventId, p as storeOf, v as cutText, w as storedFiles, x as metaOf } from "./chat-archive-_IBU0CXG.mjs";
|
|
12
12
|
import { applyChatChange } from "../extension/lib/chat-messages.mjs";
|
|
13
13
|
import { ChatStoreError } from "../extension/lib/chat-store.mjs";
|
|
14
|
-
import { c as currentInboundRequest, ht as currentThreadId, xt as reportTelegramError } from "./principal-
|
|
14
|
+
import { c as currentInboundRequest, ht as currentThreadId, xt as reportTelegramError } from "./principal-DL9NdRRP.mjs";
|
|
15
15
|
import { telegramReaction } from "../extension/lib/telegram/reactions.mjs";
|
|
16
16
|
import { currentConfirmationPrompt } from "../extension/lib/group-routing/messages.mjs";
|
|
17
17
|
import { messageMetadata } from "../extension/lib/telegram/message-metadata.mjs";
|
|
@@ -19,6 +19,7 @@ import { reportMembership } from "../extension/lib/telegram/membership.mjs";
|
|
|
19
19
|
import { currentDeliveryScope } from "../extension/lib/telegram/delivery-diagnostics.mjs";
|
|
20
20
|
import { contentShape, messageContent } from "../extension/lib/telegram/content.mjs";
|
|
21
21
|
import { createHash, randomUUID } from "node:crypto";
|
|
22
|
+
import { telegramAccountMessageIds } from "@segmentstream/ontology/telegram";
|
|
22
23
|
const CLAIM_MS = 6e5;
|
|
23
24
|
const META_ATTEMPTS = 8;
|
|
24
25
|
const MESSAGE = "message";
|
|
@@ -39,11 +40,26 @@ function age(at) {
|
|
|
39
40
|
const time = at === null || at === void 0 ? NaN : Date.parse(at);
|
|
40
41
|
return Number.isNaN(time) ? Number.POSITIVE_INFINITY : Date.now() - time;
|
|
41
42
|
}
|
|
43
|
+
async function bindTelegramOriginal(store, target, raw, confirmationId) {
|
|
44
|
+
const message = object(raw);
|
|
45
|
+
const sender = object(message.sender_chat).id ?? object(message.from).id;
|
|
46
|
+
if (target.telegramBotId === void 0 || typeof message.date !== "number" || String(object(message.chat).id) !== target.chatId || String(message.message_id) !== target.messageId || typeof sender !== "number" && typeof sender !== "string") return;
|
|
47
|
+
const { applied } = await store.change({
|
|
48
|
+
...target,
|
|
49
|
+
change: "bind_telegram_bot",
|
|
50
|
+
telegramBotId: target.telegramBotId,
|
|
51
|
+
senderId: String(sender),
|
|
52
|
+
originalAt: new Date(message.date * 1e3).toISOString(),
|
|
53
|
+
...String(sender) === target.telegramBotId ? {
|
|
54
|
+
direction: "outbound",
|
|
55
|
+
...confirmationId === void 0 ? {} : { confirmationId }
|
|
56
|
+
} : {}
|
|
57
|
+
});
|
|
58
|
+
return applied;
|
|
59
|
+
}
|
|
42
60
|
async function readMessage(store, target) {
|
|
43
61
|
return (await store.read({
|
|
44
|
-
|
|
45
|
-
chatId: target.chatId,
|
|
46
|
-
messageId: target.messageId,
|
|
62
|
+
...target,
|
|
47
63
|
limit: 1
|
|
48
64
|
})).messages[0];
|
|
49
65
|
}
|
|
@@ -154,6 +170,7 @@ async function captureInStore(input) {
|
|
|
154
170
|
const edited = input.edited !== void 0;
|
|
155
171
|
const event = input.event;
|
|
156
172
|
const target = {
|
|
173
|
+
...event.telegramBotId === void 0 ? {} : { telegramBotId: event.telegramBotId },
|
|
157
174
|
channel: event.provider,
|
|
158
175
|
chatId: event.chatId,
|
|
159
176
|
messageId: event.messageId ?? ""
|
|
@@ -166,7 +183,12 @@ async function captureInStore(input) {
|
|
|
166
183
|
});
|
|
167
184
|
const fenceKey = structured === void 0 || !edited ? MESSAGE : digest;
|
|
168
185
|
const rowFence = fenceKey === MESSAGE;
|
|
169
|
-
|
|
186
|
+
let held = await readMessage(store, target);
|
|
187
|
+
if (event.telegramBotId !== void 0 && message.replyToMessage !== void 0) await bindTelegramOriginal(store, {
|
|
188
|
+
...target,
|
|
189
|
+
messageId: message.replyToMessage.messageId
|
|
190
|
+
}, message.raw.reply_to_message);
|
|
191
|
+
if (held === void 0 && await bindTelegramOriginal(store, target, message.raw)) held = await readMessage(store, target);
|
|
170
192
|
let known = held;
|
|
171
193
|
const heldMeta = object(held?.meta);
|
|
172
194
|
const heldRevision = object(heldMeta.held);
|
|
@@ -547,12 +569,17 @@ async function storeSend(input) {
|
|
|
547
569
|
const result = object(await response.clone().json().catch(() => null));
|
|
548
570
|
if (event.messageId !== null && response.ok && result.ok === true) {
|
|
549
571
|
const target = {
|
|
572
|
+
...event.telegramBotId === void 0 ? {} : { telegramBotId: event.telegramBotId },
|
|
550
573
|
channel: event.provider,
|
|
551
574
|
chatId: event.chatId,
|
|
552
575
|
messageId: event.messageId
|
|
553
576
|
};
|
|
554
577
|
const meta = metaOf(event);
|
|
555
578
|
const text = (event.text ?? "").slice(0, 1e5);
|
|
579
|
+
if (event.telegramBotId !== void 0 && String(object(object(result.result).from).id) === event.telegramBotId) {
|
|
580
|
+
const requestId = object(object(meta?.routing).confirmation).requestId;
|
|
581
|
+
await bindTelegramOriginal(store, target, result.result, typeof requestId === "string" ? requestId : void 0);
|
|
582
|
+
}
|
|
556
583
|
await (meta === void 0 ? store.change({
|
|
557
584
|
...target,
|
|
558
585
|
change: "edit",
|
|
@@ -581,6 +608,7 @@ async function storeSend(input) {
|
|
|
581
608
|
});
|
|
582
609
|
const receipt = async (status, providerMessageId) => {
|
|
583
610
|
await store.change({
|
|
611
|
+
...event.telegramBotId === void 0 ? {} : { telegramBotId: event.telegramBotId },
|
|
584
612
|
change: "sent",
|
|
585
613
|
channel: event.provider,
|
|
586
614
|
chatId: event.chatId,
|
|
@@ -707,7 +735,7 @@ async function captureTelegramWebhook(input) {
|
|
|
707
735
|
if (reaction !== void 0) await applyChatChange(input.archive, {
|
|
708
736
|
...reaction,
|
|
709
737
|
channel: currentChannel("telegram")
|
|
710
|
-
});
|
|
738
|
+
}, telegramAccountMessageIds(reaction.chatId) ? input.telegramBotId : void 0);
|
|
711
739
|
return new Response("ok");
|
|
712
740
|
}
|
|
713
741
|
if (input.chats !== void 0 && (update.my_chat_member !== void 0 || update.chat_member !== void 0)) {
|
|
@@ -772,7 +800,10 @@ async function captureTelegramWebhook(input) {
|
|
|
772
800
|
message,
|
|
773
801
|
content,
|
|
774
802
|
structured,
|
|
775
|
-
event
|
|
803
|
+
event: input.telegramBotId === void 0 || !telegramAccountMessageIds(event.chatId) ? event : {
|
|
804
|
+
...event,
|
|
805
|
+
telegramBotId: await input.telegramBotId()
|
|
806
|
+
},
|
|
776
807
|
lookup
|
|
777
808
|
});
|
|
778
809
|
let persisted;
|
|
@@ -1187,7 +1218,7 @@ async function recordSessionFailure(input) {
|
|
|
1187
1218
|
});
|
|
1188
1219
|
}
|
|
1189
1220
|
}
|
|
1190
|
-
function captureTelegramFetch(fetchImpl, archive, identities) {
|
|
1221
|
+
function captureTelegramFetch(fetchImpl, archive, identities, telegramBotId) {
|
|
1191
1222
|
return async (input, init) => {
|
|
1192
1223
|
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
1193
1224
|
const edit = /\/(?:editMessageText|editMessageCaption)$/u.test(url);
|
|
@@ -1245,7 +1276,10 @@ function captureTelegramFetch(fetchImpl, archive, identities) {
|
|
|
1245
1276
|
});
|
|
1246
1277
|
if (store !== void 0) return storeSend({
|
|
1247
1278
|
store,
|
|
1248
|
-
event
|
|
1279
|
+
event: telegramBotId === void 0 || !telegramAccountMessageIds(event.chatId) ? event : {
|
|
1280
|
+
...event,
|
|
1281
|
+
telegramBotId: await telegramBotId()
|
|
1282
|
+
},
|
|
1249
1283
|
edit,
|
|
1250
1284
|
send: () => fetchImpl(input, init)
|
|
1251
1285
|
});
|
|
@@ -4,6 +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 { telegramMessageKey } from "../extension/lib/telegram/message-reference.mjs";
|
|
7
8
|
import { channelKey } from "../extension/lib/channel-scope.mjs";
|
|
8
9
|
import { ChatStoreError, chatStore, storeAvailable } from "../extension/lib/chat-store.mjs";
|
|
9
10
|
import { appOrigin, proxyEnvironment } from "../extension/lib/environment.mjs";
|
|
@@ -112,6 +113,7 @@ function messageInput(event) {
|
|
|
112
113
|
const text = bounded(event.text, BOUNDS.text);
|
|
113
114
|
const meta = boundedMeta(metaOf(event));
|
|
114
115
|
return {
|
|
116
|
+
...event.telegramBotId === void 0 ? {} : { telegramBotId: event.telegramBotId },
|
|
115
117
|
channel: event.provider,
|
|
116
118
|
chatId: event.chatId.slice(0, BOUNDS.chat),
|
|
117
119
|
...threadId === void 0 ? {} : { threadId },
|
|
@@ -165,6 +167,7 @@ function eventOf(row) {
|
|
|
165
167
|
const agent = row.author === "agent";
|
|
166
168
|
const retained = object(meta?.routing)?.retainedText;
|
|
167
169
|
return {
|
|
170
|
+
...row.telegramBotId === void 0 ? {} : { telegramBotId: row.telegramBotId },
|
|
168
171
|
eventId: row.id,
|
|
169
172
|
provider: row.channel,
|
|
170
173
|
chatId: row.chatId,
|
|
@@ -230,6 +233,7 @@ function workspaceChatArchive(store) {
|
|
|
230
233
|
const status = storedStatus(event.status);
|
|
231
234
|
const failure = status === "failed" ? reasonCode(event.reason) : void 0;
|
|
232
235
|
const { applied } = await store.change({
|
|
236
|
+
...event.telegramBotId === void 0 ? {} : { telegramBotId: event.telegramBotId },
|
|
233
237
|
change: "sent",
|
|
234
238
|
channel: event.provider,
|
|
235
239
|
chatId: event.chatId,
|
|
@@ -246,7 +250,8 @@ function workspaceChatArchive(store) {
|
|
|
246
250
|
if (event.kind === "outbound" && event.operationId != null) return receipt(event, event.operationId);
|
|
247
251
|
if (event.kind !== "inbound" && event.kind !== "outbound") return false;
|
|
248
252
|
if (event.kind === "outbound" && chatAuthor(event) === "agent" && event.messageId !== null) {
|
|
249
|
-
const
|
|
253
|
+
const message = telegramMessageKey(event.messageId, event.telegramBotId);
|
|
254
|
+
const operation = `sent:${event.provider}:${event.chatId}:${message}`.slice(0, 512);
|
|
250
255
|
const sent = await receipt({
|
|
251
256
|
...event,
|
|
252
257
|
status: "requested"
|
|
@@ -427,7 +432,7 @@ function archiveSequence(value) {
|
|
|
427
432
|
function collapseChatEvents(events) {
|
|
428
433
|
const latest = new Map();
|
|
429
434
|
for (const event of events) {
|
|
430
|
-
const key = event.kind === "outbound" && event.operationId != null ? `chat-delivery:${event.operationId}` : event.kind === "inbound" && isTelegramMessage(event) && event.messageId !== null ? channelKey("telegram", event.provider, `telegram:${event.chatId}:${event.messageId}:message`) : event.kind === "outbound" && /^telegram:(send|edit):/u.test(event.eventId) ? event.eventId.replace(/:result$/u, "") : event.eventId;
|
|
435
|
+
const key = event.kind === "outbound" && event.operationId != null ? `chat-delivery:${event.operationId}` : event.kind === "inbound" && isTelegramMessage(event) && event.messageId !== null ? channelKey("telegram", event.provider, `telegram:${event.chatId}:${telegramMessageKey(event.messageId, event.telegramBotId)}:message`) : event.kind === "outbound" && /^telegram:(send|edit):/u.test(event.eventId) ? event.eventId.replace(/:result$/u, "") : event.eventId;
|
|
431
436
|
const previous = latest.get(key);
|
|
432
437
|
const current = archiveSequence(event.sequence);
|
|
433
438
|
const earlier = previous === void 0 ? void 0 : archiveSequence(previous.sequence);
|
|
@@ -1901,6 +1901,7 @@ var InboundRequest = class {
|
|
|
1901
1901
|
agentDescription;
|
|
1902
1902
|
agentName;
|
|
1903
1903
|
traceId = randomUUID();
|
|
1904
|
+
telegramBotId;
|
|
1904
1905
|
edited = false;
|
|
1905
1906
|
triggeringMessageId;
|
|
1906
1907
|
chatId;
|
|
@@ -1974,7 +1975,10 @@ function withReplacedText(source, request) {
|
|
|
1974
1975
|
async send(message, options) {
|
|
1975
1976
|
const typed = typeof message === "string" ? message : message.filter((part) => part.type === "text").map((part) => part.text).join("\n");
|
|
1976
1977
|
const answerText = options?.answerText ?? (typed.trim() === "" ? request.text : typed);
|
|
1977
|
-
const
|
|
1978
|
+
const botId = await request.telegramBotId;
|
|
1979
|
+
const botMarker = botId === void 0 ? "" : `;bot:${botId}`;
|
|
1980
|
+
const trigger = request.triggeringMessageId ?? request.replyTo;
|
|
1981
|
+
const marker = request.replyTo === void 0 ? void 0 : `[source-message:${request.replyTo};trigger:${trigger}${botMarker}]`;
|
|
1978
1982
|
const replacement = marker === void 0 ? request.text : `${marker}\n${request.text ?? (typeof message === "string" ? message : message.filter((part) => part.type === "text").map((part) => part.text).join("\n"))}`;
|
|
1979
1983
|
const text = replacement === void 0 ? message : replaceText(message, replacement);
|
|
1980
1984
|
const files = request.files === void 0 ? text : replaceFiles(text, request.files);
|
|
@@ -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 "../extension/lib/telegram/confirmation-text.mjs";
|
|
8
|
-
import { Ft as chatAddressOf, _t as customerMessage, i as memberIdOf, mt as currentLocale, pt as TelegramDeliveryError, xt as reportTelegramError, yt as failureText } from "./principal-
|
|
8
|
+
import { Ft as chatAddressOf, _t as customerMessage, i as memberIdOf, mt as currentLocale, pt as TelegramDeliveryError, xt as reportTelegramError, yt as failureText } from "./principal-DL9NdRRP.mjs";
|
|
9
9
|
import { splitTelegramText } from "../extension/lib/telegram/format.mjs";
|
|
10
10
|
import { inTelegramSendQueue } from "../extension/lib/telegram/send-queue.mjs";
|
|
11
11
|
import { redactDiagnostic } from "../extension/lib/diagnostics.mjs";
|
|
@@ -74,7 +74,15 @@ export interface FirstContactSettings {
|
|
|
74
74
|
}
|
|
75
75
|
export declare const ADMISSION_REPLY_KEYS: readonly ["pairingRequired", "pairingButton", "groupPairingButton", "limited", "perSenderLimited", "workspaceLimited", "registrationsLimited", "groupPairingRequired", "refused"];
|
|
76
76
|
export type AdmissionReplies = Partial<Record<(typeof ADMISSION_REPLY_KEYS)[number], LocalizedText>>;
|
|
77
|
+
export interface PublicGroupSettings {
|
|
78
|
+
readonly model: string;
|
|
79
|
+
/** Workspace-published material for an isolated, text-only answer. */
|
|
80
|
+
readonly instructions: string;
|
|
81
|
+
/** Dedicated group connections which may be opened by an authorized inviter. */
|
|
82
|
+
readonly trustedJoinChannels?: readonly string[];
|
|
83
|
+
}
|
|
77
84
|
export interface AdmissionSettings {
|
|
85
|
+
readonly publicGroups?: PublicGroupSettings;
|
|
78
86
|
readonly personas?: PersonaSettings;
|
|
79
87
|
readonly firstContact: FirstContactSettings | null;
|
|
80
88
|
readonly limits: AdmissionLimits;
|
|
@@ -87,6 +95,7 @@ export interface AdmissionSettings {
|
|
|
87
95
|
* the values validation allows.
|
|
88
96
|
*/
|
|
89
97
|
export interface SegmentStreamAgentConfigInput {
|
|
98
|
+
readonly publicGroups?: PublicGroupSettings;
|
|
90
99
|
readonly groups?: GroupPolicyInput;
|
|
91
100
|
readonly texts?: TelegramTexts;
|
|
92
101
|
readonly firstContact?: FirstContactSettings;
|
|
@@ -1114,6 +1114,7 @@ function validateConfig(input, options = {}) {
|
|
|
1114
1114
|
"sessions",
|
|
1115
1115
|
"confirmations",
|
|
1116
1116
|
"firstContact",
|
|
1117
|
+
"publicGroups",
|
|
1117
1118
|
"limits",
|
|
1118
1119
|
"replies",
|
|
1119
1120
|
"texts",
|
|
@@ -1259,6 +1260,29 @@ function validateConfig(input, options = {}) {
|
|
|
1259
1260
|
const sessions = sessionSettings(root?.sessions, issues);
|
|
1260
1261
|
const firstContact = firstContactSettings(root?.firstContact, issues, !legacyArchive);
|
|
1261
1262
|
const limits = admissionLimits(root?.limits, issues);
|
|
1263
|
+
const publicGroupInput = section({
|
|
1264
|
+
value: root?.publicGroups,
|
|
1265
|
+
path: ["publicGroups"],
|
|
1266
|
+
allowed: [
|
|
1267
|
+
"model",
|
|
1268
|
+
"instructions",
|
|
1269
|
+
"trustedJoinChannels"
|
|
1270
|
+
],
|
|
1271
|
+
issues
|
|
1272
|
+
});
|
|
1273
|
+
let publicGroups;
|
|
1274
|
+
if (publicGroupInput) {
|
|
1275
|
+
const { model, instructions, trustedJoinChannels } = publicGroupInput;
|
|
1276
|
+
if (typeof model !== "string" || !model.trim() || model.length > 256 || typeof instructions !== "string" || !instructions.trim() || instructions.length > 32e3 || trustedJoinChannels !== void 0 && (!Array.isArray(trustedJoinChannels) || !trustedJoinChannels.every((channel) => typeof channel === "string" && Object.hasOwn(channels ?? {}, channel)))) issues.push({
|
|
1277
|
+
path: ["publicGroups"],
|
|
1278
|
+
message: "Supply a model, public instructions and optional configured channel names."
|
|
1279
|
+
});
|
|
1280
|
+
else publicGroups = {
|
|
1281
|
+
model,
|
|
1282
|
+
instructions,
|
|
1283
|
+
...trustedJoinChannels ? { trustedJoinChannels } : {}
|
|
1284
|
+
};
|
|
1285
|
+
}
|
|
1262
1286
|
const replies = admissionReplies(root?.replies, issues, !legacyArchive);
|
|
1263
1287
|
const texts = telegramTexts(root?.texts, issues);
|
|
1264
1288
|
if (!legacyArchive && replies.groupPairingButton !== void 0 && replies.groupPairingRequired === void 0) issues.push({
|
|
@@ -1374,6 +1398,7 @@ function validateConfig(input, options = {}) {
|
|
|
1374
1398
|
...browser === null ? {} : { browser },
|
|
1375
1399
|
sessions,
|
|
1376
1400
|
firstContact,
|
|
1401
|
+
...publicGroups ? { publicGroups } : {},
|
|
1377
1402
|
limits,
|
|
1378
1403
|
replies,
|
|
1379
1404
|
texts,
|
|
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import segmentstream from "../extension.mjs";
|
|
8
|
-
import { T as ontologyConnection } from "../../_chunks/principal-
|
|
8
|
+
import { T as ontologyConnection } from "../../_chunks/principal-DL9NdRRP.mjs";
|
|
9
9
|
import { defineDynamic } from "eve/connections";
|
|
10
10
|
var ontology_default = defineDynamic(async (context) => {
|
|
11
11
|
if (!segmentstream.config.ontology.connection) return null;
|
|
@@ -7,7 +7,7 @@ __eveCreateRequire(import.meta.url);
|
|
|
7
7
|
import segmentstream from "../extension.mjs";
|
|
8
8
|
import { localizedText } from "../lib/admission.mjs";
|
|
9
9
|
import { confirmationLocale } from "../lib/telegram/confirmation-text.mjs";
|
|
10
|
-
import "../../_chunks/principal-
|
|
10
|
+
import "../../_chunks/principal-DL9NdRRP.mjs";
|
|
11
11
|
import { defineHook } from "eve/hooks";
|
|
12
12
|
var authorization_default = defineHook({ events: { "interaction.opened": (event, context) => {
|
|
13
13
|
const principal = context.session.auth.current;
|
|
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import segmentstream from "../extension.mjs";
|
|
8
|
-
import { r as chatArchive } from "../../_chunks/chat-archive-
|
|
8
|
+
import { r as chatArchive } from "../../_chunks/chat-archive-_IBU0CXG.mjs";
|
|
9
9
|
import { chatContextHook } from "../lib/chat-context.mjs";
|
|
10
10
|
import { appOrigin } from "../lib/environment.mjs";
|
|
11
11
|
import { agentSessionReviews } from "../lib/review/client.mjs";
|
|
@@ -6,7 +6,7 @@ __eveDirname(__filename);
|
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import segmentstream from "../extension.mjs";
|
|
8
8
|
import { chatRecorder } from "../lib/chat-recorder.mjs";
|
|
9
|
-
import { r as chatArchive } from "../../_chunks/chat-archive-
|
|
9
|
+
import { r as chatArchive } from "../../_chunks/chat-archive-_IBU0CXG.mjs";
|
|
10
10
|
import { repliesReviewed } from "../lib/review/hold.mjs";
|
|
11
11
|
import { defineHook } from "eve/hooks";
|
|
12
12
|
var chat_recorder_default = defineHook({ events: { "*": chatRecorder(chatArchive(), (principal) => repliesReviewed(segmentstream.config.review, principal)) } });
|
|
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import segmentstream from "../extension.mjs";
|
|
8
|
-
import { a as rolesOf } from "../../_chunks/principal-
|
|
8
|
+
import { a as rolesOf } from "../../_chunks/principal-DL9NdRRP.mjs";
|
|
9
9
|
import { resolveChatPersona } from "../lib/chat-persona.mjs";
|
|
10
10
|
import { personaFor } from "../personas.mjs";
|
|
11
11
|
import { defineDynamic, defineInstructions } from "eve/instructions";
|
|
@@ -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 { R as ACT_AS_HEADER, z as ActorRequiredError, B as actorHeaders, V as actorKey, H as actorOf, U as isGuestSession, W as member, G as memberTool, K as notForGuests } from "../../_chunks/principal-
|
|
7
|
+
export { R as ACT_AS_HEADER, z as ActorRequiredError, B as actorHeaders, V as actorKey, H as actorOf, U as isGuestSession, W as member, G as memberTool, K as notForGuests } from "../../_chunks/principal-DL9NdRRP.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 { Ft as chatAddressOf, It as chatChannel, b as agentAttachments, i as memberIdOf } from "../../_chunks/principal-
|
|
7
|
+
import { Ft as chatAddressOf, It as chatChannel, b as agentAttachments, i as memberIdOf } from "../../_chunks/principal-DL9NdRRP.mjs";
|
|
8
8
|
import { detectFile, documentText } from "./attachment-formats.mjs";
|
|
9
9
|
import { readSheets, typedTable } from "./attachment-tables.mjs";
|
|
10
10
|
import { appOrigin } from "./environment.mjs";
|
|
@@ -5,8 +5,8 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { channelOf } from "../config.mjs";
|
|
8
|
-
import { Ft as chatAddressOf, It as chatChannel } from "../../_chunks/principal-
|
|
9
|
-
import "../../_chunks/silent-
|
|
8
|
+
import { Ft as chatAddressOf, It as chatChannel } from "../../_chunks/principal-DL9NdRRP.mjs";
|
|
9
|
+
import "../../_chunks/silent-xJcJ8SNJ.mjs";
|
|
10
10
|
import { sendEmailAttachments } from "./email/attachments-send.mjs";
|
|
11
11
|
import { replyCopies } from "./email/channel.mjs";
|
|
12
12
|
import { sendSlackAttachments } from "./slack/attachments-send.mjs";
|
|
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { attachmentOwner } from "./attachment-tools.mjs";
|
|
8
|
-
import { Ft as chatAddressOf, _ as AttachmentError, yt as failureText } from "../../_chunks/principal-
|
|
8
|
+
import { Ft as chatAddressOf, _ as AttachmentError, yt as failureText } from "../../_chunks/principal-DL9NdRRP.mjs";
|
|
9
9
|
import { appOrigin, channelsEnabled } from "./environment.mjs";
|
|
10
10
|
import { transientFileStatus } from "./file-grant.mjs";
|
|
11
11
|
import { runtimeToken } from "./runtime-token.mjs";
|
|
@@ -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 { h as ATTACHMENT_TTL_HOURS, g as ATTACHMENT_URL_PROTOCOL, _ as AttachmentError, jt as CHAT_HEADER, v as EARLIER_CHAT_HEADER, y as MAXIMUM_ATTACHMENT_BYTES, Pt as SESSION_HEADER, b as agentAttachments, x as attachmentUrl, S as fetchStoredAttachment, C as parseAttachmentUrl } from "../../_chunks/principal-
|
|
7
|
+
export { h as ATTACHMENT_TTL_HOURS, g as ATTACHMENT_URL_PROTOCOL, _ as AttachmentError, jt as CHAT_HEADER, v as EARLIER_CHAT_HEADER, y as MAXIMUM_ATTACHMENT_BYTES, Pt as SESSION_HEADER, b as agentAttachments, x as attachmentUrl, S as fetchStoredAttachment, C as parseAttachmentUrl } from "../../_chunks/principal-DL9NdRRP.mjs";
|
|
@@ -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 agentBuild } from "../../_chunks/build-metadata-
|
|
7
|
+
export { t as agentBuild } from "../../_chunks/build-metadata-CP0iLqzp.mjs";
|
|
@@ -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 { At as CHAT_ATTRIBUTE, jt as CHAT_HEADER, Mt as PARTICIPANTS_ATTRIBUTE, Nt as RUNTIME_SOURCE_ATTRIBUTE, Pt as SESSION_HEADER, Ft as chatAddressOf, It as chatChannel, Lt as chatHeaders, Rt as chatRuntimeSource, zt as isSameChat, Bt as participantsOf, Vt as withChatAddress, Ht as workspaceIdentityProvider } from "../../_chunks/principal-
|
|
7
|
+
export { At as CHAT_ATTRIBUTE, jt as CHAT_HEADER, Mt as PARTICIPANTS_ATTRIBUTE, Nt as RUNTIME_SOURCE_ATTRIBUTE, Pt as SESSION_HEADER, Ft as chatAddressOf, It as chatChannel, Lt as chatHeaders, Rt as chatRuntimeSource, zt as isSameChat, Bt as participantsOf, Vt as withChatAddress, Ht as workspaceIdentityProvider } from "../../_chunks/principal-DL9NdRRP.mjs";
|
|
@@ -3,6 +3,7 @@ import { type Environment } from "./environment.js";
|
|
|
3
3
|
import { type RuntimeToken } from "./runtime-token.js";
|
|
4
4
|
/** Provider-neutral platform archive. Content uses the shared redaction and byte-limit policy. */
|
|
5
5
|
export interface ChatEvent {
|
|
6
|
+
readonly telegramBotId?: string;
|
|
6
7
|
readonly eventId: string;
|
|
7
8
|
readonly provider: string;
|
|
8
9
|
readonly chatId: string;
|
|
@@ -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 AGENT_SENDER, n as archiveSequence, r as chatArchive, i as chatAuthor, a as chatEvent, o as cloudChatArchive, s as collapseChatEvents, c as forgetChatStores, l as replyEvent, u as replyOperation, d as replyRecipients, f as sessionFailureEventId, p as storeOf, m as summarizeArguments, h as topicContext } from "../../_chunks/chat-archive-
|
|
7
|
+
export { t as AGENT_SENDER, n as archiveSequence, r as chatArchive, i as chatAuthor, a as chatEvent, o as cloudChatArchive, s as collapseChatEvents, c as forgetChatStores, l as replyEvent, u as replyOperation, d as replyRecipients, f as sessionFailureEventId, p as storeOf, m as summarizeArguments, h as topicContext } from "../../_chunks/chat-archive-_IBU0CXG.mjs";
|
|
@@ -6,8 +6,9 @@ __eveDirname(__filename);
|
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { agentTaskIdOf } from "./agent-task.mjs";
|
|
8
8
|
import { chatCoordinates, sessionKind } from "./chat-recorder.mjs";
|
|
9
|
-
import { h as topicContext, i as chatAuthor, n as archiveSequence, p as storeOf, r as chatArchive, s as collapseChatEvents } from "../../_chunks/chat-archive-
|
|
10
|
-
import {
|
|
9
|
+
import { h as topicContext, i as chatAuthor, n as archiveSequence, p as storeOf, r as chatArchive, s as collapseChatEvents } from "../../_chunks/chat-archive-_IBU0CXG.mjs";
|
|
10
|
+
import { TELEGRAM_SOURCE_MARKER, telegramMessageKey } from "./telegram/message-reference.mjs";
|
|
11
|
+
import { xt as reportTelegramError } from "../../_chunks/principal-DL9NdRRP.mjs";
|
|
11
12
|
import { createHash } from "node:crypto";
|
|
12
13
|
import { deliveries, runs, turns } from "eve/events";
|
|
13
14
|
import { defineState } from "eve/context";
|
|
@@ -55,10 +56,10 @@ const BOOTSTRAP_MESSAGES = 50;
|
|
|
55
56
|
const BOOTSTRAP_CHARACTERS = 2e4;
|
|
56
57
|
const TURN_CHARACTERS = 3e4;
|
|
57
58
|
const MAXIMUM_TEXT = 4e3;
|
|
58
|
-
const TRIGGER_MARKER = /^\[source-message:\d+;trigger:(\d+)\]/u;
|
|
59
59
|
function triggerOf(delivery) {
|
|
60
60
|
const first = delivery.parts?.find((part) => part.kind === "text");
|
|
61
|
-
|
|
61
|
+
const match = first?.kind === "text" ? TELEGRAM_SOURCE_MARKER.exec(first.text) : void 0;
|
|
62
|
+
return match?.[1] === void 0 ? void 0 : telegramMessageKey(match[1], match[2]);
|
|
62
63
|
}
|
|
63
64
|
function deliveredMessages(view, turnId) {
|
|
64
65
|
return deliveries(view, turnId === void 0 ? {} : { turnId }).flatMap((delivery) => delivery.turnId !== void 0 && delivery.outcome !== "refused" && delivery.outcome !== "ignored" && triggerOf(delivery) !== void 0 ? [triggerOf(delivery)] : []);
|
|
@@ -177,7 +178,7 @@ async function readChatContext(input) {
|
|
|
177
178
|
const messages = collapseChatEvents(unread.filter((event) => since === void 0 || Date.parse(event.storedAt) >= since)).filter((event) => {
|
|
178
179
|
const changed = event.kind === "inbound" && (edited(event) || event.deleted === true);
|
|
179
180
|
if (event.imported === true && !bootstrap && !changed) return false;
|
|
180
|
-
return (event.kind === "inbound" || event.kind === "outbound" && ["completed", "sent"].includes(event.status ?? "")) && !(event.kind === "inbound" && event.messageId !== null && delivering.has(event.messageId)) && (changed || !(event.kind === "inbound" && event.messageId !== null && delivered.has(event.messageId)) && !(event.kind === "inbound" && event.sessionId === input.sessionId && (event.turnId === null || turns.has(event.turnId))) && (bootstrap || event.sessionId !== input.sessionId));
|
|
181
|
+
return (event.kind === "inbound" || event.kind === "outbound" && ["completed", "sent"].includes(event.status ?? "")) && !(event.kind === "inbound" && event.messageId !== null && delivering.has(telegramMessageKey(event.messageId, event.telegramBotId))) && (changed || !(event.kind === "inbound" && event.messageId !== null && delivered.has(telegramMessageKey(event.messageId, event.telegramBotId))) && !(event.kind === "inbound" && event.sessionId === input.sessionId && (event.turnId === null || turns.has(event.turnId))) && (bootstrap || event.sessionId !== input.sessionId));
|
|
181
182
|
}).sort(workspace && bootstrap ? (first, second) => Date.parse(second.at) - Date.parse(first.at) || (sequence(first) < sequence(second) ? 1 : -1) : (first, second) => sequence(first) < sequence(second) ? 1 : -1);
|
|
182
183
|
const budget = bootstrap ? BOOTSTRAP_CHARACTERS : TURN_CHARACTERS;
|
|
183
184
|
const selected = [];
|
|
@@ -104,7 +104,7 @@ export type ChatChangeOutcome = "applied" | "unchanged" | "dropped";
|
|
|
104
104
|
* no such message, or the change changes nothing, such as a status older than the message's. On
|
|
105
105
|
* the chat archive in Cloud a change is dropped: it writes nothing new there.
|
|
106
106
|
*/
|
|
107
|
-
export declare function applyChatChange(archive: ChatArchive, change: ChatChange): Promise<ChatChangeOutcome>;
|
|
107
|
+
export declare function applyChatChange(archive: ChatArchive, change: ChatChange, telegramBotId?: () => Promise<string>): Promise<ChatChangeOutcome>;
|
|
108
108
|
/** A message the archive keeps without a turn. */
|
|
109
109
|
export interface RecordedMessage {
|
|
110
110
|
/** The channel's name, as the archive keys its chats. */
|
|
@@ -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 { a as chatEvent, g as UNVERIFIED, p as storeOf, w as storedFiles } from "../../_chunks/chat-archive-
|
|
7
|
+
import { a as chatEvent, g as UNVERIFIED, p as storeOf, w as storedFiles } from "../../_chunks/chat-archive-_IBU0CXG.mjs";
|
|
8
8
|
const MAXIMUM_PARTS = 20;
|
|
9
9
|
const PART_BOUNDS = {
|
|
10
10
|
text: 1024,
|
|
@@ -112,10 +112,11 @@ async function recordReceivedMessage(archive, message) {
|
|
|
112
112
|
return true;
|
|
113
113
|
}
|
|
114
114
|
const CODE = /^[a-z][a-z0-9_]{0,63}$/u;
|
|
115
|
-
async function applyChatChange(archive, change) {
|
|
115
|
+
async function applyChatChange(archive, change, telegramBotId) {
|
|
116
116
|
const store = await storeOf(archive);
|
|
117
117
|
if (store === void 0) return "dropped";
|
|
118
118
|
const target = {
|
|
119
|
+
...telegramBotId === void 0 ? {} : { telegramBotId: await telegramBotId() },
|
|
119
120
|
channel: change.channel,
|
|
120
121
|
chatId: change.chatId.slice(0, 256),
|
|
121
122
|
messageId: change.target.slice(0, 512)
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { SessionAuthContext } from "eve/context";
|
|
2
2
|
import { chatPersona, type PersonaSettings } from "../personas.js";
|
|
3
|
+
/** A production runtime lookup on the current chat. An outage must not silently change its persona. */
|
|
4
|
+
export declare function chatRuntimeRequest(operation: string, data: Record<string, unknown>): Promise<any>;
|
|
3
5
|
export declare function resolveChatPersona(settings: PersonaSettings, principal: SessionAuthContext | null | undefined, read?: (key: string) => Promise<string | null>): Promise<{
|
|
4
6
|
readonly name: string;
|
|
5
7
|
readonly source: "chat";
|
|
@@ -5,11 +5,11 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { chatPersona } from "../personas.mjs";
|
|
8
|
-
import { Ft as chatAddressOf, It as chatChannel, i as memberIdOf, ot as guestIdOf } from "../../_chunks/principal-
|
|
8
|
+
import { Ft as chatAddressOf, It as chatChannel, i as memberIdOf, ot as guestIdOf } from "../../_chunks/principal-DL9NdRRP.mjs";
|
|
9
9
|
import { appOrigin, ontologyDeploymentHeaders } from "./environment.mjs";
|
|
10
10
|
import { localizedText } from "./admission.mjs";
|
|
11
11
|
import { runtimeToken } from "./runtime-token.mjs";
|
|
12
|
-
async function
|
|
12
|
+
async function chatRuntimeRequest(operation, data) {
|
|
13
13
|
const response = await fetch(`${appOrigin()}/api/ontology/agent/chats/${operation}`, {
|
|
14
14
|
method: "POST",
|
|
15
15
|
redirect: "error",
|
|
@@ -21,11 +21,11 @@ async function request(operation, data) {
|
|
|
21
21
|
body: JSON.stringify(data),
|
|
22
22
|
signal: AbortSignal.timeout(5e3)
|
|
23
23
|
});
|
|
24
|
-
if (!response.ok) throw new Error(`
|
|
24
|
+
if (!response.ok) throw new Error(`The chat runtime request failed (HTTP ${response.status}).`);
|
|
25
25
|
return response.json();
|
|
26
26
|
}
|
|
27
27
|
async function readAssignment(key) {
|
|
28
|
-
const body = await
|
|
28
|
+
const body = await chatRuntimeRequest("persona", { key });
|
|
29
29
|
if (body?.persona !== null && typeof body?.persona !== "string") throw new Error("Invalid chat persona response.");
|
|
30
30
|
return body.persona;
|
|
31
31
|
}
|
|
@@ -47,7 +47,7 @@ async function offerPersona(settings, selection, principal, deliver, locale) {
|
|
|
47
47
|
const memberId = memberIdOf(principal);
|
|
48
48
|
if (!text || !chat || !memberId || selection?.source !== "default" || !selection.name) return;
|
|
49
49
|
try {
|
|
50
|
-
const receipt = await
|
|
50
|
+
const receipt = await chatRuntimeRequest("persona-notice", {
|
|
51
51
|
key: `${chatChannel(chat)}:${chat.chatId}`,
|
|
52
52
|
memberId,
|
|
53
53
|
provider: chat.provider
|
|
@@ -72,4 +72,4 @@ async function personaPrincipal(settings, principal, deliver) {
|
|
|
72
72
|
}
|
|
73
73
|
} : principal;
|
|
74
74
|
}
|
|
75
|
-
export { offerPersona, personaPrincipal, resolveChatPersona };
|
|
75
|
+
export { chatRuntimeRequest, offerPersona, personaPrincipal, resolveChatPersona };
|