@segmentstream/agent 0.77.0 → 0.78.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 +30 -0
- package/README.md +4 -3
- package/dist/_chunks/{build-metadata-BkE742Ne.mjs → build-metadata-WG90Pemy.mjs} +1 -1
- package/dist/_chunks/{chat-archive-pVRDSPL2.mjs → chat-archive-CdumQXGM.mjs} +10 -0
- package/dist/extension/lib/build-metadata.mjs +1 -1
- package/dist/extension/lib/chat-context.d.ts +6 -0
- package/dist/extension/lib/chat-context.mjs +3 -1
- package/dist/extension/lib/chat-messages.d.ts +4 -0
- package/dist/extension/lib/chat-messages.mjs +2 -1
- package/dist/extension/lib/chat-recorder.mjs +5 -1
- package/dist/extension/lib/slack/adapter.d.ts +16 -1
- package/dist/extension/lib/slack/adapter.mjs +63 -10
- package/dist/extension/lib/slack/callbacks.d.ts +6 -0
- package/dist/extension/lib/slack/callbacks.mjs +18 -4
- package/dist/extension/lib/slack/changes.d.ts +47 -0
- package/dist/extension/lib/slack/changes.mjs +101 -0
- package/dist/extension/lib/slack/thread-history.mjs +1 -4
- package/dist/extension/lib/telegram/adapter.mjs +2 -2
- package/dist/extension/lib/telegram/chat-archive.mjs +1 -1
- package/dist/extension/lib/telegram/health.mjs +1 -1
- package/dist/extension/lib/telegram/inbound.mjs +1 -1
- package/dist/extension/lib/telegram/lifecycle.mjs +1 -1
- package/dist/extension/lib/telegram/reactions.d.ts +18 -0
- package/dist/extension/lib/telegram/reactions.mjs +35 -0
- package/dist/extension/lib/telegram/store-capture.mjs +1 -1
- package/dist/extension/lib/telegram/turn-errors.mjs +1 -1
- package/dist/extension/lib/whatsapp/adapter.mjs +1 -1
- package/dist/extension/lib/whatsapp/changes.d.ts +2 -1
- package/dist/extension/lib/whatsapp/changes.mjs +21 -10
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.78.0
|
|
4
|
+
|
|
5
|
+
Telegram and Slack keep what people change of their messages, and WhatsApp keeps the business's
|
|
6
|
+
reactions, on an agent whose ontology keeps the workspace chat store. No reaction or deletion
|
|
7
|
+
starts a turn, and a change to a message the chat does not hold changes nothing.
|
|
8
|
+
|
|
9
|
+
- Telegram keeps a person's reaction on its message, the agent's replies included: of several,
|
|
10
|
+
the one they added last, and only an emoji, never a custom emoji or a paid reaction. The
|
|
11
|
+
platform registers the bot for Telegram's `message_reaction` at the next deploy; in a group,
|
|
12
|
+
Telegram reports reactions only to a bot that is an administrator there.
|
|
13
|
+
- Slack records each person's message by Slack's `ts`, with the files it stored, and keeps their
|
|
14
|
+
reactions (as the emoji, or as Slack's short name between colons, such as `:partyparrot:`, for
|
|
15
|
+
a workspace's own), edits and deletions on it. In a thread the agent serves, an edit still
|
|
16
|
+
reaches its session as before. The agent's own Slack replies are kept without Slack's `ts`, so a
|
|
17
|
+
reaction to one is not kept yet. A press of a workspace button that queues a turn is recorded as
|
|
18
|
+
the presser's message.
|
|
19
|
+
- WhatsApp keeps a reaction the business sends from the WhatsApp Business app on a number in
|
|
20
|
+
Coexistence, as the business number's beside the person's.
|
|
21
|
+
- A session's first turn no longer shows the message its channel recorded for it as chat beside
|
|
22
|
+
the message itself.
|
|
23
|
+
|
|
24
|
+
Slack sends reactions only to an app that asks for them. To keep them, add `reactions:read` to the
|
|
25
|
+
Slack connection's `scopes` beside the defaults, deploy, authorize again, and create the app from
|
|
26
|
+
Console again, or subscribe an existing app to `reaction_added` and `reaction_removed` under
|
|
27
|
+
Event Subscriptions in Slack. Edits and deletions need nothing new.
|
|
28
|
+
|
|
29
|
+
## 0.77.1
|
|
30
|
+
|
|
31
|
+
Pins @segmentstream/ontology 0.153.1.
|
|
32
|
+
|
|
3
33
|
## 0.77.0
|
|
4
34
|
|
|
5
35
|
An email channel with `record: "all"` takes the mailbox's chats into the inbox. A verified sender's chat that has no member joins the inbox without members when the ontology's `inbox.channels` lists the channel, which may now name an email channel. Mail that failed DMARC never joins. Mail staff send from the mailbox is recorded in each recipient's chat, including a chat the agent has none of yet, when `recordQuery`, if any, finds it.
|
package/README.md
CHANGED
|
@@ -658,9 +658,10 @@ inputs, and the chat context names their stored ids. Already dispatched native i
|
|
|
658
658
|
sandbox/session history and may be omitted by compaction. Native audio is follow-up work, not a
|
|
659
659
|
guarantee of this adapter.
|
|
660
660
|
|
|
661
|
-
The webhook subscribes to `message`, `edited_message`, `callback_query`, `my_chat_member
|
|
662
|
-
and `
|
|
663
|
-
unpaired; membership updates do not start turns.
|
|
661
|
+
The webhook subscribes to `message`, `edited_message`, `callback_query`, `my_chat_member`,
|
|
662
|
+
`chat_member` and `message_reaction`. A bot join reports the group immediately, including when the
|
|
663
|
+
inviter is unpaired; membership updates do not start turns. A reaction is kept on its message in
|
|
664
|
+
the workspace chat store and starts no turn. Report tasks participate in the wrapper's
|
|
664
665
|
tracked promises and Eve's `waitUntil`, and concurrent callers await a pending report.
|
|
665
666
|
|
|
666
667
|
Registry failures carry structured `status`, body `code`, request id and counters in operator
|
|
@@ -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.78.0";
|
|
8
8
|
function agentBuild(environment = process.env) {
|
|
9
9
|
return {
|
|
10
10
|
agent: version,
|
|
@@ -8,8 +8,10 @@ import { parseArchivedMessage } from "../extension/lib/telegram/archive-message.
|
|
|
8
8
|
import { currentChannel, currentKey } from "../extension/lib/channel-scope.mjs";
|
|
9
9
|
import { n as contentText, t as CONTENT_CAPS } from "./content-cDtVnr8Y.mjs";
|
|
10
10
|
import { C as storedFiles, S as sendFingerprint, _ as cutText, a as chatEvent, b as metaOf, d as sessionFailureEventId, f as storeOf, g as boundedMeta, x as reasonCode, y as messageInput } from "./chat-archive-CUMEaSqy.mjs";
|
|
11
|
+
import { applyChatChange } from "../extension/lib/chat-messages.mjs";
|
|
11
12
|
import { ChatStoreError } from "../extension/lib/chat-store.mjs";
|
|
12
13
|
import { c as currentInboundRequest, ht as currentThreadId, xt as reportTelegramError } from "./principal-C7aAjyt4.mjs";
|
|
14
|
+
import { telegramReaction } from "../extension/lib/telegram/reactions.mjs";
|
|
13
15
|
import { currentConfirmationPrompt } from "../extension/lib/group-routing/messages.mjs";
|
|
14
16
|
import { messageMetadata } from "../extension/lib/telegram/message-metadata.mjs";
|
|
15
17
|
import { reportMembership } from "../extension/lib/telegram/membership.mjs";
|
|
@@ -692,6 +694,14 @@ async function captureTelegramWebhook(input) {
|
|
|
692
694
|
}
|
|
693
695
|
return new Response("ok");
|
|
694
696
|
}
|
|
697
|
+
if (update.message_reaction !== void 0) {
|
|
698
|
+
const reaction = telegramReaction(update);
|
|
699
|
+
if (reaction !== void 0) await applyChatChange(input.archive, {
|
|
700
|
+
...reaction,
|
|
701
|
+
channel: currentChannel("telegram")
|
|
702
|
+
});
|
|
703
|
+
return new Response("ok");
|
|
704
|
+
}
|
|
695
705
|
if (input.chats !== void 0 && (update.my_chat_member !== void 0 || update.chat_member !== void 0)) {
|
|
696
706
|
const task = reportMembership({
|
|
697
707
|
update,
|
|
@@ -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-WG90Pemy.mjs";
|
|
@@ -112,6 +112,12 @@ export declare function readChatContext(input: {
|
|
|
112
112
|
readonly delivered: ReadonlyArray<string>;
|
|
113
113
|
/** The messages this turn delivers, as they are now: never shown beside it. */
|
|
114
114
|
readonly delivering?: ReadonlyArray<string>;
|
|
115
|
+
/**
|
|
116
|
+
* The turns whose messages the session holds as they were delivered: this one, and one it starts
|
|
117
|
+
* again. A message its channel recorded for the session, which one of them took or none took
|
|
118
|
+
* yet, is never shown beside them, even in a history that holds no chat.
|
|
119
|
+
*/
|
|
120
|
+
readonly turns?: ReadonlyArray<string>;
|
|
115
121
|
readonly guidance?: string;
|
|
116
122
|
readonly now: Date;
|
|
117
123
|
}): Promise<ChatContextRead>;
|
|
@@ -170,10 +170,11 @@ async function readChatContext(input) {
|
|
|
170
170
|
const unread = [...latest.values()].filter((event) => cursor === void 0 || sequence(event) > cursor && !seen.has(event.sequence) || overlapSince !== void 0 && sequence(event) >= 0n && Date.parse(event.storedAt) >= overlapSince && !seen.has(event.sequence)).sort((first, second) => sequence(first) < sequence(second) ? -1 : sequence(first) > sequence(second) ? 1 : 0);
|
|
171
171
|
const delivered = new Set(input.delivered);
|
|
172
172
|
const delivering = new Set(input.delivering);
|
|
173
|
+
const turns = new Set(input.turns);
|
|
173
174
|
const messages = collapseChatEvents(unread.filter((event) => since === void 0 || Date.parse(event.storedAt) >= since)).filter((event) => {
|
|
174
175
|
const changed = event.kind === "inbound" && (edited(event) || event.deleted === true);
|
|
175
176
|
if (event.imported === true && !bootstrap && !changed) return false;
|
|
176
|
-
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)) && (bootstrap || event.sessionId !== input.sessionId));
|
|
177
|
+
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));
|
|
177
178
|
}).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);
|
|
178
179
|
const budget = bootstrap ? BOOTSTRAP_CHARACTERS : TURN_CHARACTERS;
|
|
179
180
|
const selected = [];
|
|
@@ -251,6 +252,7 @@ function chatContextHook(archive = chatArchive(), reviews, holding = () => true)
|
|
|
251
252
|
from,
|
|
252
253
|
sessionId: context.session.id,
|
|
253
254
|
delivering: deliveredMessages(context.view, turnId),
|
|
255
|
+
turns: restarted ? [turnId, pending.turnId] : [turnId],
|
|
254
256
|
delivered: [
|
|
255
257
|
...from.delivered,
|
|
256
258
|
...deliveredMessages(context.view, bootstrap ? turnId : void 0),
|
|
@@ -32,6 +32,10 @@ export declare function stagedFiles(files: ReadonlyMap<string, StagedFile>): Rea
|
|
|
32
32
|
export interface ReceivedMessage {
|
|
33
33
|
readonly channel: string;
|
|
34
34
|
readonly chatId: string;
|
|
35
|
+
/** A group's chat, such as a thread in a Slack channel; by default a person's private chat. */
|
|
36
|
+
readonly chatType?: "private" | "group";
|
|
37
|
+
/** The thread it is in, in a chat that keeps its threads apart. */
|
|
38
|
+
readonly threadId?: string;
|
|
35
39
|
/** The member who wrote it, who reads it. */
|
|
36
40
|
readonly memberId: string;
|
|
37
41
|
/** The person's account at the provider. */
|
|
@@ -80,7 +80,8 @@ async function recordReceivedMessage(archive, message) {
|
|
|
80
80
|
const turn = "turn" in message.outcome ? message.outcome.turn : void 0;
|
|
81
81
|
await store.record({
|
|
82
82
|
...target,
|
|
83
|
-
|
|
83
|
+
...message.threadId === void 0 || message.threadId === "" ? {} : { threadId: message.threadId.slice(0, 256) },
|
|
84
|
+
chatType: message.chatType ?? "private",
|
|
84
85
|
participants: UUID.test(message.memberId) ? [message.memberId] : [],
|
|
85
86
|
direction: "inbound",
|
|
86
87
|
author: "human",
|
|
@@ -262,7 +262,11 @@ function turnMessages(context, turnId, telegram) {
|
|
|
262
262
|
function turnDeliveries(context, turnId) {
|
|
263
263
|
return deliveries(context.view, { turnId }).filter((delivery) => delivery.outcome !== "refused" && delivery.outcome !== "ignored");
|
|
264
264
|
}
|
|
265
|
-
const RECORDS_MESSAGES = new Set([
|
|
265
|
+
const RECORDS_MESSAGES = new Set([
|
|
266
|
+
"custom",
|
|
267
|
+
"whatsapp",
|
|
268
|
+
"slack"
|
|
269
|
+
]);
|
|
266
270
|
const DELIVERED_WINDOW = 100;
|
|
267
271
|
async function deliveredMessages(store, chat, deliveryIds) {
|
|
268
272
|
if (deliveryIds.length === 0) return [];
|
|
@@ -18,6 +18,7 @@ import type { WorkspaceActionHook } from "../workspace-action.js";
|
|
|
18
18
|
import { type ChannelReviewOptions } from "../review/reply.js";
|
|
19
19
|
import { type RuntimeToken } from "../runtime-token.js";
|
|
20
20
|
import { type ChatArchive } from "../chat-archive.js";
|
|
21
|
+
import { type ReceivedMessage } from "../chat-messages.js";
|
|
21
22
|
/**
|
|
22
23
|
* The SegmentStream Slack channel (`agent-design.md`, "Channels"): eve's Slack channel at
|
|
23
24
|
* `POST /eve/v1/slack`, for the Slack app SegmentStream created for the workspace's
|
|
@@ -38,9 +39,15 @@ import { type ChatArchive } from "../chat-archive.js";
|
|
|
38
39
|
* The channels the agent is in are reported to the ontology's `agent_chat` registry, titled as
|
|
39
40
|
* Slack names them, when a paired member writes there and when the agent joins, leaves or sees one
|
|
40
41
|
* renamed. Direct and group direct messages are never reported.
|
|
42
|
+
*
|
|
43
|
+
* On the workspace chat store, a person's message that starts a turn is recorded by Slack's `ts`
|
|
44
|
+
* once eve's inbox took it, and the reactions, edits and deletions Slack reports change it and
|
|
45
|
+
* start no turn (`changes.ts`).
|
|
41
46
|
*/
|
|
42
47
|
/** The authenticator of a Slack session's principal. */
|
|
43
48
|
export declare const SLACK_AUTHENTICATOR = "segmentstream-slack";
|
|
49
|
+
/** A person's message that starts a turn, as the workspace chat store keeps it by Slack's `ts`. */
|
|
50
|
+
export type SlackReceivedMessage = Omit<ReceivedMessage, "outcome">;
|
|
44
51
|
/** What the pipeline made of a message's files, and which Slack URL names each file's part. */
|
|
45
52
|
export interface SlackTurnMedia {
|
|
46
53
|
readonly media: PreparedMedia;
|
|
@@ -76,6 +83,8 @@ export interface SlackChannelOptions {
|
|
|
76
83
|
readonly review?: ChannelReviewOptions;
|
|
77
84
|
/** Where members' files are stored as attachments; tests pass their own. */
|
|
78
85
|
readonly attachments?: AgentAttachments;
|
|
86
|
+
/** The chat archive; tests pass their own. */
|
|
87
|
+
readonly archive?: ChatArchive;
|
|
79
88
|
/**
|
|
80
89
|
* `models` of `agent/segmentstream.json`: `stt` transcribes voice clips, and `chat` with
|
|
81
90
|
* `imageDescription` decides how images reach the model. Without it voice is not transcribed.
|
|
@@ -149,8 +158,9 @@ export declare function followsThreadReply(input: {
|
|
|
149
158
|
* A session source whose `send` delivers the message as the inbound media pipeline left its files:
|
|
150
159
|
* a voice clip's transcript in place of the clip, and an image the chat model does not read
|
|
151
160
|
* natively as its description. Every other file part stays eve's, which downloads it for the turn.
|
|
161
|
+
* Each delivery eve's inbox took is passed to `delivered` before `send` answers.
|
|
152
162
|
*/
|
|
153
|
-
export declare function withTurnMedia<State>(source: ChannelSource<State>, turn: () => SlackTurnMedia | undefined): ChannelSource<State>;
|
|
163
|
+
export declare function withTurnMedia<State>(source: ChannelSource<State>, turn: () => SlackTurnMedia | undefined, delivered?: (delivery: unknown) => Promise<void>): ChannelSource<State>;
|
|
154
164
|
/**
|
|
155
165
|
* Admits one inbound message: a turn as the paired member who wrote something, or `null` after
|
|
156
166
|
* privately answering anyone else with the workspace's reply, if it has one.
|
|
@@ -175,6 +185,11 @@ export declare function receive(input: {
|
|
|
175
185
|
readonly files?: SlackFiles;
|
|
176
186
|
/** Receives what the inbound media pipeline made of the files, for the turn's message. */
|
|
177
187
|
readonly turn?: (media: SlackTurnMedia) => void;
|
|
188
|
+
/**
|
|
189
|
+
* Receives the person's message a new turn answers, to record by Slack's `ts` once eve's inbox
|
|
190
|
+
* took it; an edit, which changes the message recorded before, gives none.
|
|
191
|
+
*/
|
|
192
|
+
readonly received?: (message: SlackReceivedMessage) => void;
|
|
178
193
|
}): Promise<SlackMentionResult>;
|
|
179
194
|
/** How the Slack channel stores and transcribes a message's files. */
|
|
180
195
|
export interface SlackFiles {
|
|
@@ -25,7 +25,8 @@ import { recordThreadHistory } from "./thread-history.mjs";
|
|
|
25
25
|
import { channelReview, withReviewedReplies } from "../review/reply.mjs";
|
|
26
26
|
import { runtimeToken } from "../runtime-token.mjs";
|
|
27
27
|
import { r as chatArchive } from "../../../_chunks/chat-archive-CUMEaSqy.mjs";
|
|
28
|
-
import { recordHandledMessage } from "../chat-messages.mjs";
|
|
28
|
+
import { recordHandledMessage, recordReceivedMessage, stagedFiles } from "../chat-messages.mjs";
|
|
29
|
+
import { recordSlackChange, slackChange, slackTime } from "./changes.mjs";
|
|
29
30
|
import { createHash, createHmac, randomUUID, timingSafeEqual } from "node:crypto";
|
|
30
31
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
31
32
|
import { slackChannel } from "eve/channels/slack";
|
|
@@ -229,7 +230,7 @@ function segmentstreamSlack(options) {
|
|
|
229
230
|
identities: pairing
|
|
230
231
|
}));
|
|
231
232
|
const chats = () => registry;
|
|
232
|
-
let records;
|
|
233
|
+
let records = options.archive;
|
|
233
234
|
const archive = () => records ??= chatArchive({
|
|
234
235
|
environment,
|
|
235
236
|
token,
|
|
@@ -288,20 +289,29 @@ function segmentstreamSlack(options) {
|
|
|
288
289
|
waitUntil: work.waitUntil,
|
|
289
290
|
turn: (media) => {
|
|
290
291
|
work.turn = media;
|
|
292
|
+
},
|
|
293
|
+
received: (received) => {
|
|
294
|
+
work.received = received;
|
|
291
295
|
}
|
|
292
296
|
}
|
|
293
297
|
});
|
|
294
298
|
};
|
|
295
299
|
const observe = async (relayed, waitUntil) => {
|
|
296
300
|
let envelope;
|
|
301
|
+
let change;
|
|
297
302
|
try {
|
|
298
303
|
const body = await relayed.clone().text();
|
|
299
304
|
envelope = JSON.parse(body);
|
|
300
|
-
|
|
305
|
+
change = slackChange(envelope);
|
|
306
|
+
if (change === void 0 && !MEMBERSHIP_EVENTS.has(String(record(record(envelope).event).type))) return;
|
|
301
307
|
verify(relayed, body);
|
|
302
308
|
} catch {
|
|
303
309
|
return;
|
|
304
310
|
}
|
|
311
|
+
if (change !== void 0) {
|
|
312
|
+
waitUntil(recordSlackChange(archive(), change).catch((error) => report("change_record_failed", error)));
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
305
315
|
waitUntil(reportMembership({
|
|
306
316
|
envelope,
|
|
307
317
|
chats: chats(),
|
|
@@ -309,6 +319,19 @@ function segmentstreamSlack(options) {
|
|
|
309
319
|
request
|
|
310
320
|
}).catch((error) => report("membership_report_failed", error)));
|
|
311
321
|
};
|
|
322
|
+
const delivered = async (work, delivery) => {
|
|
323
|
+
const received = work.received;
|
|
324
|
+
const turn = record(delivery);
|
|
325
|
+
work.received = void 0;
|
|
326
|
+
if (received === void 0 || typeof turn.sessionId !== "string" || typeof turn.deliveryId !== "string") return;
|
|
327
|
+
await recordReceivedMessage(archive(), {
|
|
328
|
+
...received,
|
|
329
|
+
outcome: { turn: {
|
|
330
|
+
sessionId: turn.sessionId,
|
|
331
|
+
deliveryId: turn.deliveryId
|
|
332
|
+
} }
|
|
333
|
+
}).catch((error) => report("message_record_failed", error));
|
|
334
|
+
};
|
|
312
335
|
const channel = slackChannel({
|
|
313
336
|
credentials: {
|
|
314
337
|
botToken: PLACEHOLDER,
|
|
@@ -348,6 +371,10 @@ function segmentstreamSlack(options) {
|
|
|
348
371
|
environment,
|
|
349
372
|
principal: slackPrincipal,
|
|
350
373
|
report,
|
|
374
|
+
received: (message) => {
|
|
375
|
+
const work = requestWork.getStore();
|
|
376
|
+
if (work !== void 0) work.received = message;
|
|
377
|
+
},
|
|
351
378
|
token,
|
|
352
379
|
...options.fetch === void 0 ? {} : { fetch: options.fetch }
|
|
353
380
|
})
|
|
@@ -360,7 +387,7 @@ function segmentstreamSlack(options) {
|
|
|
360
387
|
const replying = reviewed === void 0 ? channel : withReviewedReplies(channel, () => reviewed.review, () => reviewed.archive);
|
|
361
388
|
return {
|
|
362
389
|
...withSessionChannels("slack", replying),
|
|
363
|
-
routes: withNamedRoutes("slack", replying.routes.flatMap((route) => route.transport === "websocket" ? [] : [gatedRoute(route, settings, environment, observe)]), (name) => options.settings(name) !== null)
|
|
390
|
+
routes: withNamedRoutes("slack", replying.routes.flatMap((route) => route.transport === "websocket" ? [] : [gatedRoute(route, settings, environment, observe, delivered)]), (name) => options.settings(name) !== null)
|
|
364
391
|
};
|
|
365
392
|
}
|
|
366
393
|
async function followsThreadReply(input) {
|
|
@@ -368,7 +395,7 @@ async function followsThreadReply(input) {
|
|
|
368
395
|
if (message.author?.isBot !== false || message.threadTs === message.ts || input.mode === "mention") return false;
|
|
369
396
|
return ctx.edit !== void 0 || await ctx.isSubscribed();
|
|
370
397
|
}
|
|
371
|
-
function gatedRoute(route, settings, environment, observe) {
|
|
398
|
+
function gatedRoute(route, settings, environment, observe, delivered) {
|
|
372
399
|
return {
|
|
373
400
|
...route,
|
|
374
401
|
handler: async (request, args) => {
|
|
@@ -378,17 +405,17 @@ function gatedRoute(route, settings, environment, observe) {
|
|
|
378
405
|
await observe(request, waitUntil);
|
|
379
406
|
return requestWork.run(work, () => route.handler(request, {
|
|
380
407
|
...args,
|
|
381
|
-
from: (address) => withTurnMedia(args.from(address), () => work.turn)
|
|
408
|
+
from: (address) => withTurnMedia(args.from(address), () => work.turn, (delivery) => delivered(work, delivery))
|
|
382
409
|
}));
|
|
383
410
|
}
|
|
384
411
|
};
|
|
385
412
|
}
|
|
386
|
-
function withTurnMedia(source, turn) {
|
|
413
|
+
function withTurnMedia(source, turn, delivered) {
|
|
387
414
|
return {
|
|
388
415
|
...source,
|
|
389
|
-
send(message, options) {
|
|
416
|
+
async send(message, options) {
|
|
390
417
|
const current = turn();
|
|
391
|
-
|
|
418
|
+
const delivery = await source.send(current === void 0 ? message : turnContent(message, {
|
|
392
419
|
files: current.media.files,
|
|
393
420
|
keyOf: (part) => {
|
|
394
421
|
const data = part.data;
|
|
@@ -397,6 +424,8 @@ function withTurnMedia(source, turn) {
|
|
|
397
424
|
},
|
|
398
425
|
spoken: current.media.spoken
|
|
399
426
|
}), options);
|
|
427
|
+
await delivered?.(delivery);
|
|
428
|
+
return delivery;
|
|
400
429
|
}
|
|
401
430
|
};
|
|
402
431
|
}
|
|
@@ -476,7 +505,30 @@ async function receive(input) {
|
|
|
476
505
|
id: message.ts,
|
|
477
506
|
sender: user
|
|
478
507
|
});
|
|
479
|
-
|
|
508
|
+
const received = (media) => {
|
|
509
|
+
if (ctx.edit === void 0) {
|
|
510
|
+
const at = slackTime(message.ts);
|
|
511
|
+
input.received?.({
|
|
512
|
+
channel: currentChannel("slack"),
|
|
513
|
+
chatId: ctx.slack.channelId,
|
|
514
|
+
...input.direct ? {} : {
|
|
515
|
+
chatType: "group",
|
|
516
|
+
threadId: ctx.slack.threadTs
|
|
517
|
+
},
|
|
518
|
+
memberId: resolution.member.id,
|
|
519
|
+
senderId: user,
|
|
520
|
+
...display === void 0 ? {} : { senderName: display },
|
|
521
|
+
messageId: message.ts,
|
|
522
|
+
text: media?.text ?? message.text,
|
|
523
|
+
...media === void 0 ? {} : { files: stagedFiles(media.files) },
|
|
524
|
+
...at === void 0 ? {} : { at }
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
if (message.attachments.length === 0 || input.files === void 0) {
|
|
529
|
+
received();
|
|
530
|
+
return { auth };
|
|
531
|
+
}
|
|
480
532
|
const channelId = ctx.slack.channelId;
|
|
481
533
|
const files = slackFiles({
|
|
482
534
|
files: message.attachments,
|
|
@@ -506,6 +558,7 @@ async function receive(input) {
|
|
|
506
558
|
media,
|
|
507
559
|
keys: new Map(files.flatMap((file) => file.url === void 0 ? [] : [[file.url, file.key]]))
|
|
508
560
|
});
|
|
561
|
+
received(media);
|
|
509
562
|
return {
|
|
510
563
|
auth,
|
|
511
564
|
context: [...media.context]
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { SlackInteractionAction, SlackInteractionContext } from "eve/channels/slack";
|
|
2
2
|
import type { SessionAuthContext } from "eve/context";
|
|
3
3
|
import type { AdmissionSettings } from "../../config.js";
|
|
4
|
+
import type { ReceivedMessage } from "../chat-messages.js";
|
|
4
5
|
import type { Environment } from "../environment.js";
|
|
5
6
|
import type { AgentIdentities, PairedMember } from "../identities.js";
|
|
6
7
|
import type { RuntimeToken } from "../runtime-token.js";
|
|
@@ -26,6 +27,11 @@ export declare function handleWorkspaceCallback(input: {
|
|
|
26
27
|
/** The session principal of a paired member's Slack account. */
|
|
27
28
|
readonly principal: (member: PairedMember, user: string) => SessionAuthContext;
|
|
28
29
|
readonly report: (operation: string, error: unknown) => void;
|
|
30
|
+
/**
|
|
31
|
+
* Receives the turn a press queues as the presser's message in the chat, to record once eve's
|
|
32
|
+
* inbox took it, by the press: it has no Slack message of its own.
|
|
33
|
+
*/
|
|
34
|
+
readonly received?: (message: Omit<ReceivedMessage, "outcome">) => void;
|
|
29
35
|
readonly token?: RuntimeToken;
|
|
30
36
|
readonly fetch?: typeof fetch;
|
|
31
37
|
}): Promise<void>;
|
|
@@ -121,10 +121,24 @@ async function handleWorkspaceCallback(input) {
|
|
|
121
121
|
recipient: user
|
|
122
122
|
} } : {},
|
|
123
123
|
memberId: lookup.member.id,
|
|
124
|
-
queue: () =>
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
124
|
+
queue: () => {
|
|
125
|
+
input.received?.({
|
|
126
|
+
channel,
|
|
127
|
+
chatId: channelId,
|
|
128
|
+
...direct ? {} : {
|
|
129
|
+
chatType: "group",
|
|
130
|
+
threadId: threadTs
|
|
131
|
+
},
|
|
132
|
+
memberId: lookup.member.id,
|
|
133
|
+
senderId: user,
|
|
134
|
+
messageId: `slack:press:${callId}`,
|
|
135
|
+
text: context
|
|
136
|
+
});
|
|
137
|
+
return ctx.send(context, {
|
|
138
|
+
auth: principal,
|
|
139
|
+
turnPolicy: "queue"
|
|
140
|
+
});
|
|
141
|
+
}
|
|
128
142
|
});
|
|
129
143
|
} catch (error) {
|
|
130
144
|
report("workspace_callback_turn_failed", error);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type ChatArchive } from "../chat-archive.js";
|
|
2
|
+
import { type ChatChange, type ChatChangeOutcome } from "../chat-messages.js";
|
|
3
|
+
/**
|
|
4
|
+
* What Slack reports of a message beside new ones (docs/agent.md, "Message changes"): a person's
|
|
5
|
+
* reaction added or removed (`reaction_added`, `reaction_removed`, delivered for the
|
|
6
|
+
* `reactions:read` scope), and an edit or a deletion of a message (`message` events of subtype
|
|
7
|
+
* `message_changed` and `message_deleted`, delivered with the messages of a conversation). Each
|
|
8
|
+
* changes its message in the workspace chat store, found by Slack's `ts` of it in its
|
|
9
|
+
* conversation, and starts no turn: eve still reads an edit of a message in a thread it serves.
|
|
10
|
+
*/
|
|
11
|
+
/** A change of the store, in the conversation it keys by Slack's id of it. */
|
|
12
|
+
type StoreChange = ChatChange extends infer Change ? Change extends unknown ? Omit<Change, "channel"> : never : never;
|
|
13
|
+
/**
|
|
14
|
+
* A change one event reports. The removal of a reaction names the emoji it takes away: Slack lets a
|
|
15
|
+
* person add several, and the store keeps one per person, so it clears theirs only while it is
|
|
16
|
+
* that one.
|
|
17
|
+
*/
|
|
18
|
+
export type SlackChange = Exclude<StoreChange, {
|
|
19
|
+
readonly change: "reaction";
|
|
20
|
+
}> | (Extract<StoreChange, {
|
|
21
|
+
readonly change: "reaction";
|
|
22
|
+
}> & {
|
|
23
|
+
readonly removed?: string;
|
|
24
|
+
});
|
|
25
|
+
/** A Slack `ts`, seconds since the epoch, as ISO 8601. */
|
|
26
|
+
export declare function slackTime(ts: unknown): string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* The emoji of a Slack reaction, which Slack names by its short name: the emoji itself where the
|
|
29
|
+
* Chat SDK knows it, else the short name between colons, as Slack writes it, such as a workspace's
|
|
30
|
+
* own emoji. A skin tone is left out.
|
|
31
|
+
*/
|
|
32
|
+
export declare function slackEmoji(name: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* The change a verified Events API callback reports, or undefined for any other event: a reaction
|
|
35
|
+
* to anything but a message, and a `message_changed` that leaves the text as it was, such as a link
|
|
36
|
+
* unfurled, change nothing. A thread's first message deleted under its replies stays as a
|
|
37
|
+
* placeholder, which Slack reports as a change to it: that is its deletion.
|
|
38
|
+
*/
|
|
39
|
+
export declare function slackChange(envelope: unknown): SlackChange | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Applies one change on the Slack channel the request runs for: `unchanged` for a message the
|
|
42
|
+
* store does not hold, such as the agent's own reply, which the store keeps without Slack's id,
|
|
43
|
+
* and for the removal of a reaction the person's is no longer; `dropped` on the chat archive in
|
|
44
|
+
* Cloud, which keeps no changes.
|
|
45
|
+
*/
|
|
46
|
+
export declare function recordSlackChange(archive: ChatArchive, change: SlackChange): Promise<ChatChangeOutcome>;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { fileURLToPath as __eveFileURLToPath } from "node:url";
|
|
2
|
+
import { dirname as __eveDirname } from "node:path";
|
|
3
|
+
import { createRequire as __eveCreateRequire } from "node:module";
|
|
4
|
+
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
|
+
__eveDirname(__filename);
|
|
6
|
+
__eveCreateRequire(import.meta.url);
|
|
7
|
+
import { currentChannel } from "../channel-scope.mjs";
|
|
8
|
+
import { f as storeOf } from "../../../_chunks/chat-archive-CUMEaSqy.mjs";
|
|
9
|
+
import { applyChatChange } from "../chat-messages.mjs";
|
|
10
|
+
import { defaultEmojiResolver } from "chat";
|
|
11
|
+
function record(value) {
|
|
12
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
13
|
+
}
|
|
14
|
+
function text(value) {
|
|
15
|
+
return typeof value === "string" && value !== "" ? value : void 0;
|
|
16
|
+
}
|
|
17
|
+
function slackTime(ts) {
|
|
18
|
+
const seconds = typeof ts === "string" && /^\d{1,12}(\.\d{1,9})?$/u.test(ts) ? Number(ts) : NaN;
|
|
19
|
+
return Number.isFinite(seconds) && seconds > 0 ? new Date(seconds * 1e3).toISOString() : void 0;
|
|
20
|
+
}
|
|
21
|
+
function slackEmoji(name) {
|
|
22
|
+
const base = name.replace(/^:|:$/gu, "").replace(/::skin-tone-\d$/u, "");
|
|
23
|
+
const value = defaultEmojiResolver.fromSlack(base);
|
|
24
|
+
const emoji = defaultEmojiResolver.toGChat(value);
|
|
25
|
+
return emoji === value.name ? `:${base}:` : emoji;
|
|
26
|
+
}
|
|
27
|
+
function slackChange(envelope) {
|
|
28
|
+
const callback = record(envelope);
|
|
29
|
+
const event = record(callback?.event);
|
|
30
|
+
if (callback?.type !== "event_callback" || event === void 0) return;
|
|
31
|
+
if (event.type === "reaction_added" || event.type === "reaction_removed") {
|
|
32
|
+
const item = record(event.item);
|
|
33
|
+
const chatId = text(item?.channel);
|
|
34
|
+
const target = text(item?.ts);
|
|
35
|
+
const senderId = text(event.user);
|
|
36
|
+
const reaction = text(event.reaction);
|
|
37
|
+
return item?.type !== "message" || chatId === void 0 || target === void 0 || senderId === void 0 || reaction === void 0 ? void 0 : {
|
|
38
|
+
chatId,
|
|
39
|
+
target,
|
|
40
|
+
change: "reaction",
|
|
41
|
+
senderId,
|
|
42
|
+
...event.type === "reaction_added" ? { emoji: slackEmoji(reaction) } : {
|
|
43
|
+
emoji: "",
|
|
44
|
+
removed: slackEmoji(reaction)
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const chatId = text(event.channel);
|
|
49
|
+
if (event.type !== "message" || chatId === void 0) return;
|
|
50
|
+
if (event.subtype === "message_deleted") {
|
|
51
|
+
const target = text(event.deleted_ts) ?? text(record(event.previous_message)?.ts);
|
|
52
|
+
const at = slackTime(event.ts);
|
|
53
|
+
return target === void 0 ? void 0 : {
|
|
54
|
+
chatId,
|
|
55
|
+
target,
|
|
56
|
+
change: "delete",
|
|
57
|
+
...at === void 0 ? {} : { at }
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (event.subtype !== "message_changed") return;
|
|
61
|
+
const message = record(event.message);
|
|
62
|
+
const target = text(message?.ts);
|
|
63
|
+
const at = slackTime(record(message?.edited)?.ts ?? event.ts);
|
|
64
|
+
if (message === void 0 || target === void 0) return;
|
|
65
|
+
if (message.subtype === "tombstone") return {
|
|
66
|
+
chatId,
|
|
67
|
+
target,
|
|
68
|
+
change: "delete",
|
|
69
|
+
...at === void 0 ? {} : { at }
|
|
70
|
+
};
|
|
71
|
+
const edited = typeof message.text === "string" ? message.text : "";
|
|
72
|
+
const previous = record(event.previous_message)?.text;
|
|
73
|
+
return typeof previous === "string" && previous === edited ? void 0 : {
|
|
74
|
+
chatId,
|
|
75
|
+
target,
|
|
76
|
+
change: "edit",
|
|
77
|
+
text: edited,
|
|
78
|
+
...at === void 0 ? {} : { at }
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
async function recordSlackChange(archive, change) {
|
|
82
|
+
const channel = currentChannel("slack");
|
|
83
|
+
if (change.change !== "reaction" || change.removed === void 0) return applyChatChange(archive, {
|
|
84
|
+
...change,
|
|
85
|
+
channel
|
|
86
|
+
});
|
|
87
|
+
const store = await storeOf(archive);
|
|
88
|
+
if (store === void 0) return "dropped";
|
|
89
|
+
const { removed, ...reaction } = change;
|
|
90
|
+
const [message] = (await store.read({
|
|
91
|
+
channel,
|
|
92
|
+
chatId: change.chatId.slice(0, 256),
|
|
93
|
+
messageId: change.target.slice(0, 512),
|
|
94
|
+
limit: 1
|
|
95
|
+
})).messages;
|
|
96
|
+
return message?.reactions.find((kept) => kept.senderId === change.senderId)?.emoji === removed ? applyChatChange(archive, {
|
|
97
|
+
...reaction,
|
|
98
|
+
channel
|
|
99
|
+
}) : "unchanged";
|
|
100
|
+
}
|
|
101
|
+
export { recordSlackChange, slackChange, slackEmoji, slackTime };
|
|
@@ -5,11 +5,8 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { recordChatMessage } from "../chat-messages.mjs";
|
|
8
|
+
import { slackTime } from "./changes.mjs";
|
|
8
9
|
import { loadThreadContextMessages } from "eve/channels/slack";
|
|
9
|
-
function slackTime(ts) {
|
|
10
|
-
const seconds = Number(ts);
|
|
11
|
-
return Number.isFinite(seconds) && seconds > 0 ? new Date(seconds * 1e3).toISOString() : void 0;
|
|
12
|
-
}
|
|
13
10
|
async function recordThreadHistory(input) {
|
|
14
11
|
if (input.threadTs === input.messageTs) return;
|
|
15
12
|
const chat = {
|
|
@@ -10,7 +10,7 @@ import { groupRoutingHealth } from "../group-routing/health.mjs";
|
|
|
10
10
|
import { dispatchStructuredMessage, structuredMessage } from "./structured.mjs";
|
|
11
11
|
import { handleWorkspaceCallback } from "./callbacks.mjs";
|
|
12
12
|
import { telegramText, withTelegramTexts } from "./texts.mjs";
|
|
13
|
-
import { t as agentBuild } from "../../../_chunks/build-metadata-
|
|
13
|
+
import { t as agentBuild } from "../../../_chunks/build-metadata-WG90Pemy.mjs";
|
|
14
14
|
import { attachmentLifecycle } from "./lifecycle.mjs";
|
|
15
15
|
import { manifestOf } from "../../config.mjs";
|
|
16
16
|
import { gatewayAttachmentDescriber } from "./attachment-description.mjs";
|
|
@@ -20,7 +20,7 @@ import { MAXIMUM_DOWNLOAD_BYTES, connectionProxy } from "../connection-proxy.mjs
|
|
|
20
20
|
import { appOrigin, channelsEnabled, proxyEnvironment, runtimeIdentityEnvironment, webhookSecret } from "../environment.mjs";
|
|
21
21
|
import { agentIdentities } from "../identities.mjs";
|
|
22
22
|
import { m as topicContext, r as chatArchive } from "../../../_chunks/chat-archive-CUMEaSqy.mjs";
|
|
23
|
-
import { a as captureTelegramFetch, h as telegramChatCapture, i as captureRouteDecider, s as chatIdentities, u as recordGateDecision } from "../../../_chunks/chat-archive-
|
|
23
|
+
import { a as captureTelegramFetch, h as telegramChatCapture, i as captureRouteDecider, s as chatIdentities, u as recordGateDecision } from "../../../_chunks/chat-archive-CdumQXGM.mjs";
|
|
24
24
|
import { runtimeTokenVerifier } from "../runtime-identity.mjs";
|
|
25
25
|
import { runtimeToken } from "../runtime-token.mjs";
|
|
26
26
|
import { botIdentityCache, proxiedBotRequest, runtimeBotIdentity } from "./bot.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 REVISION_CLAIM_TTL_MS, n as attachmentIdentity, r as attachmentRefs, i as captureRouteDecider, a as captureTelegramFetch, o as captureTelegramWebhook, s as chatIdentities, c as currentCapture, l as participants, u as recordGateDecision, d as recordInboundContent, f as recordRouteDecision, p as recordSessionFailure, m as registerCapture, h as telegramChatCapture } from "../../../_chunks/chat-archive-
|
|
7
|
+
export { t as REVISION_CLAIM_TTL_MS, n as attachmentIdentity, r as attachmentRefs, i as captureRouteDecider, a as captureTelegramFetch, o as captureTelegramWebhook, s as chatIdentities, c as currentCapture, l as participants, u as recordGateDecision, d as recordInboundContent, f as recordRouteDecision, p as recordSessionFailure, m as registerCapture, h as telegramChatCapture } from "../../../_chunks/chat-archive-CdumQXGM.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 { t as agentBuild } from "../../../_chunks/build-metadata-
|
|
7
|
+
import { t as agentBuild } from "../../../_chunks/build-metadata-WG90Pemy.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";
|
|
@@ -28,7 +28,7 @@ import { routingContext } from "./routing-context.mjs";
|
|
|
28
28
|
import { formatAddress, messageAddress, scopedAddress } from "./sessions.mjs";
|
|
29
29
|
import { voiceOf } from "./voice.mjs";
|
|
30
30
|
import { MAXIMUM_ROUTING_ATTACHMENT_BYTES, describeRoutingAttachment, routingAttachmentDeadline } from "./attachment-description.mjs";
|
|
31
|
-
import { d as recordInboundContent, f as recordRouteDecision, u as recordGateDecision } from "../../../_chunks/chat-archive-
|
|
31
|
+
import { d as recordInboundContent, f as recordRouteDecision, u as recordGateDecision } from "../../../_chunks/chat-archive-CdumQXGM.mjs";
|
|
32
32
|
import { contentShape, messageContent } from "./content.mjs";
|
|
33
33
|
import { messageAudience } from "./audience.mjs";
|
|
34
34
|
const MAXIMUM_QUOTE_LENGTH = 500;
|
|
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { E as OntologyActionNotPermitted, Et as principalRuntimeSource, L as needsConfirmation, Ot as runtimeEnvelope, W as member, c as currentInboundRequest, j as ontologyTools, k as actionToolName, kt as telegramRuntimeSource } from "../../../_chunks/principal-C7aAjyt4.mjs";
|
|
8
|
-
import { t as agentBuild } from "../../../_chunks/build-metadata-
|
|
8
|
+
import { t as agentBuild } from "../../../_chunks/build-metadata-WG90Pemy.mjs";
|
|
9
9
|
import { object } from "../confirmation-description.mjs";
|
|
10
10
|
var AttachmentLifecycleNotPermitted = class extends Error {
|
|
11
11
|
code = "attachment_lifecycle_not_permitted";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ChatChange } from "../chat-messages.js";
|
|
2
|
+
/**
|
|
3
|
+
* A person's reaction to a message in a Telegram chat (docs/agent.md, "Message changes"): Telegram
|
|
4
|
+
* reports it as a `message_reaction` update, which the bot receives only when its webhook lists
|
|
5
|
+
* that update, and in a group only while it is an administrator there. The update names the
|
|
6
|
+
* person's reactions before and after the change; the chat keeps one reaction per person, so the
|
|
7
|
+
* one the change added is kept, else the first the person still has, and none removes theirs.
|
|
8
|
+
* Only emoji reactions are kept: a custom emoji or a paid reaction has no emoji to show.
|
|
9
|
+
*/
|
|
10
|
+
/** A reaction the update reports, in the chat the store keys by Telegram's id of it. */
|
|
11
|
+
export type TelegramReaction = Omit<Extract<ChatChange, {
|
|
12
|
+
readonly change: "reaction";
|
|
13
|
+
}>, "channel">;
|
|
14
|
+
/**
|
|
15
|
+
* The reaction a `message_reaction` update reports, by the person who reacted, or by the chat
|
|
16
|
+
* they reacted on behalf of; undefined for an update that names no chat, message or sender.
|
|
17
|
+
*/
|
|
18
|
+
export declare function telegramReaction(update: unknown): TelegramReaction | undefined;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { fileURLToPath as __eveFileURLToPath } from "node:url";
|
|
2
|
+
import { dirname as __eveDirname } from "node:path";
|
|
3
|
+
import { createRequire as __eveCreateRequire } from "node:module";
|
|
4
|
+
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
|
+
__eveDirname(__filename);
|
|
6
|
+
__eveCreateRequire(import.meta.url);
|
|
7
|
+
function record(value) {
|
|
8
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
9
|
+
}
|
|
10
|
+
function id(value) {
|
|
11
|
+
return typeof value === "number" && Number.isSafeInteger(value) || typeof value === "string" && /^-?\d{1,20}$/u.test(value) ? String(value) : void 0;
|
|
12
|
+
}
|
|
13
|
+
function emoji(value) {
|
|
14
|
+
return (Array.isArray(value) ? value : []).flatMap((item) => {
|
|
15
|
+
const reaction = record(item);
|
|
16
|
+
return reaction?.type === "emoji" && typeof reaction.emoji === "string" && reaction.emoji !== "" ? [reaction.emoji] : [];
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function telegramReaction(update) {
|
|
20
|
+
const reaction = record(record(update)?.message_reaction);
|
|
21
|
+
const chatId = id(record(reaction?.chat)?.id);
|
|
22
|
+
const target = id(reaction?.message_id);
|
|
23
|
+
const senderId = id(record(reaction?.user)?.id) ?? id(record(reaction?.actor_chat)?.id);
|
|
24
|
+
if (chatId === void 0 || target === void 0 || senderId === void 0) return;
|
|
25
|
+
const before = emoji(reaction?.old_reaction);
|
|
26
|
+
const after = emoji(reaction?.new_reaction);
|
|
27
|
+
return {
|
|
28
|
+
chatId,
|
|
29
|
+
target,
|
|
30
|
+
change: "reaction",
|
|
31
|
+
senderId,
|
|
32
|
+
emoji: after.find((added) => !before.includes(added)) ?? after[0] ?? ""
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export { telegramReaction };
|
|
@@ -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 { g as captureInStore, _ as storeSend } from "../../../_chunks/chat-archive-
|
|
7
|
+
export { g as captureInStore, _ as storeSend } from "../../../_chunks/chat-archive-CdumQXGM.mjs";
|
|
@@ -6,7 +6,7 @@ __eveDirname(__filename);
|
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { telegramText } from "./texts.mjs";
|
|
8
8
|
import { confirmationLocale } from "./confirmation-text.mjs";
|
|
9
|
-
import { p as recordSessionFailure } from "../../../_chunks/chat-archive-
|
|
9
|
+
import { p as recordSessionFailure } from "../../../_chunks/chat-archive-CdumQXGM.mjs";
|
|
10
10
|
import { gt as customerCopy, ht as currentThreadId, i as memberIdOf, mt as currentLocale, xt as reportTelegramError, yt as failureText } from "../../../_chunks/principal-C7aAjyt4.mjs";
|
|
11
11
|
import { modelServiceFailure } from "../model-service-failure.mjs";
|
|
12
12
|
function telegramFailureEvents(input) {
|
|
@@ -30,9 +30,9 @@ import { collectSent, noteSent, recordSent } from "./sent.mjs";
|
|
|
30
30
|
import { STATUSES_HEADER, STATUSES_RECORDED } from "./statuses.mjs";
|
|
31
31
|
import { createHash, createHmac, randomUUID, timingSafeEqual } from "node:crypto";
|
|
32
32
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
33
|
+
import { Actions, Card, CardText, ConsoleLogger, LinkButton } from "chat";
|
|
33
34
|
import { createMemoryState } from "@chat-adapter/state-memory";
|
|
34
35
|
import { WhatsAppAdapter, WhatsAppApiError } from "@chat-adapter/whatsapp";
|
|
35
|
-
import { Actions, Card, CardText, ConsoleLogger, LinkButton } from "chat";
|
|
36
36
|
import { chatSdkChannel, messageContentOf } from "eve/channels/chat-sdk";
|
|
37
37
|
const WHATSAPP_AUTHENTICATOR = "segmentstream-whatsapp";
|
|
38
38
|
const WHATSAPP_PROXY_ORIGIN = "https://whatsapp.segmentstream.invalid";
|
|
@@ -9,7 +9,8 @@ export declare const FAILURE_RETRY_MS: ReadonlyArray<number>;
|
|
|
9
9
|
* What a relayed WhatsApp delivery says of messages beside the people's new ones, which the Chat
|
|
10
10
|
* SDK adapter reads (`docs/agent.md`, "Message changes"): the delivery statuses of messages the
|
|
11
11
|
* number sent, people's reactions, and on a number in Coexistence with the WhatsApp Business app,
|
|
12
|
-
* edits and deletions by the person or by the business in the app
|
|
12
|
+
* edits and deletions by the person or by the business in the app, and the business's reactions
|
|
13
|
+
* there. Each is a change of a message
|
|
13
14
|
* in the person's chat, found by Meta's id of it, and starts no turn. A contact card a person
|
|
14
15
|
* sends, which the adapter reads as no message, is recorded in their chat with its parts.
|
|
15
16
|
*/
|
|
@@ -93,6 +93,17 @@ function revision(chatId, message) {
|
|
|
93
93
|
};
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
+
function reaction(chatId, message, senderId) {
|
|
97
|
+
const reacted = record(message.reaction);
|
|
98
|
+
const target = text(reacted?.message_id);
|
|
99
|
+
return target === void 0 ? void 0 : {
|
|
100
|
+
chatId,
|
|
101
|
+
target,
|
|
102
|
+
change: "reaction",
|
|
103
|
+
senderId,
|
|
104
|
+
emoji: typeof reacted?.emoji === "string" ? reacted.emoji : ""
|
|
105
|
+
};
|
|
106
|
+
}
|
|
96
107
|
function whatsappChanges(payload) {
|
|
97
108
|
const changes = [];
|
|
98
109
|
const contacts = [];
|
|
@@ -103,6 +114,7 @@ function whatsappChanges(payload) {
|
|
|
103
114
|
const phoneNumberId = text(record(value?.metadata)?.phone_number_id);
|
|
104
115
|
if (value === void 0 || phoneNumberId === void 0) continue;
|
|
105
116
|
const chat = (person) => `whatsapp:${phoneNumberId}:${person}`;
|
|
117
|
+
const business = text(record(value.metadata)?.display_phone_number) ?? phoneNumberId;
|
|
106
118
|
if (field === "messages") {
|
|
107
119
|
for (const status of list(value.statuses).map(record)) {
|
|
108
120
|
const target = text(status?.id);
|
|
@@ -124,15 +136,8 @@ function whatsappChanges(payload) {
|
|
|
124
136
|
const id = text(message?.id);
|
|
125
137
|
if (message === void 0 || person === void 0 || id === void 0) continue;
|
|
126
138
|
if (message.type === "reaction") {
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
if (target !== void 0) changes.push({
|
|
130
|
-
chatId: chat(person),
|
|
131
|
-
target,
|
|
132
|
-
change: "reaction",
|
|
133
|
-
senderId: person,
|
|
134
|
-
emoji: typeof reaction?.emoji === "string" ? reaction.emoji : ""
|
|
135
|
-
});
|
|
139
|
+
const reacted = reaction(chat(person), message, person);
|
|
140
|
+
if (reacted !== void 0) changes.push(reacted);
|
|
136
141
|
continue;
|
|
137
142
|
}
|
|
138
143
|
const revised = revision(chat(person), message);
|
|
@@ -157,7 +162,13 @@ function whatsappChanges(payload) {
|
|
|
157
162
|
}
|
|
158
163
|
if (field === "smb_message_echoes") for (const echo of list(value.message_echoes).map(record)) {
|
|
159
164
|
const person = text(echo?.to) ?? text(echo?.to_user_id);
|
|
160
|
-
|
|
165
|
+
if (echo === void 0 || person === void 0) continue;
|
|
166
|
+
if (echo.type === "reaction") {
|
|
167
|
+
const reacted = reaction(chat(person), echo, text(echo.from) ?? business);
|
|
168
|
+
if (reacted !== void 0) changes.push(reacted);
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
const revised = revision(chat(person), echo);
|
|
161
172
|
if (revised !== void 0) changes.push(revised);
|
|
162
173
|
}
|
|
163
174
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.78.0",
|
|
4
4
|
"description": "The SegmentStream workspace agent: the ontology as tools, acting as the member who writes, and the browser, Telegram, WhatsApp and Slack through the workspace's connections.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "SegmentStream",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"@chat-adapter/state-memory": "4.42.0",
|
|
85
85
|
"@chat-adapter/telegram": "4.41.0",
|
|
86
86
|
"@chat-adapter/whatsapp": "4.42.0",
|
|
87
|
-
"@segmentstream/ontology": "0.153.
|
|
87
|
+
"@segmentstream/ontology": "0.153.1",
|
|
88
88
|
"@vercel/oidc": "^3.8.4",
|
|
89
89
|
"ai": "^7.0.172",
|
|
90
90
|
"chat": "4.42.0",
|