@segmentstream/agent 0.77.1 → 0.79.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 +36 -0
- package/README.md +4 -3
- package/dist/_chunks/{build-metadata-DeFy9vS5.mjs → build-metadata-BrWGOlRd.mjs} +1 -1
- package/dist/_chunks/{chat-archive-pVRDSPL2.mjs → chat-archive-BEk40gWe.mjs} +11 -1
- package/dist/_chunks/{chat-archive-CUMEaSqy.mjs → chat-archive-DavfKJDI.mjs} +20 -2
- package/dist/extension/config.d.ts +7 -0
- package/dist/extension/config.mjs +9 -2
- package/dist/extension/hooks/chat-context.mjs +1 -1
- package/dist/extension/hooks/chat-recorder.mjs +1 -1
- package/dist/extension/lib/build-metadata.mjs +1 -1
- package/dist/extension/lib/chat-archive.d.ts +16 -0
- package/dist/extension/lib/chat-archive.mjs +1 -1
- package/dist/extension/lib/chat-context.d.ts +6 -0
- package/dist/extension/lib/chat-context.mjs +4 -2
- package/dist/extension/lib/chat-messages.d.ts +4 -0
- package/dist/extension/lib/chat-messages.mjs +3 -2
- package/dist/extension/lib/chat-recorder.mjs +6 -2
- package/dist/extension/lib/email/attachments-send.d.ts +6 -4
- package/dist/extension/lib/email/attachments-send.mjs +1 -0
- package/dist/extension/lib/email/channel.d.ts +16 -4
- package/dist/extension/lib/email/channel.mjs +29 -10
- package/dist/extension/lib/email/gmail.d.ts +7 -5
- package/dist/extension/lib/email/gmail.mjs +1 -0
- package/dist/extension/lib/email/message.d.ts +5 -0
- package/dist/extension/lib/email/message.mjs +10 -5
- package/dist/extension/lib/group-routing/routing-context.mjs +1 -1
- package/dist/extension/lib/model-service-alert.mjs +1 -1
- package/dist/extension/lib/review/client.mjs +57 -32
- package/dist/extension/lib/review/hold.d.ts +11 -0
- package/dist/extension/lib/review/hold.mjs +4 -0
- package/dist/extension/lib/review/judge.mjs +1 -1
- package/dist/extension/lib/review/reply.d.ts +5 -0
- package/dist/extension/lib/review/reply.mjs +1 -1
- package/dist/extension/lib/review/revision-channel.mjs +1 -1
- package/dist/extension/lib/slack/adapter.d.ts +16 -1
- package/dist/extension/lib/slack/adapter.mjs +64 -11
- 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 +3 -3
- package/dist/extension/lib/telegram/chat-archive.mjs +1 -1
- package/dist/extension/lib/telegram/confirmations.mjs +1 -1
- package/dist/extension/lib/telegram/delivery-diagnostics.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 +2 -2
- package/dist/extension/lib/whatsapp/attachments-send.mjs +1 -1
- package/dist/extension/lib/whatsapp/changes.d.ts +2 -1
- package/dist/extension/lib/whatsapp/changes.mjs +22 -11
- package/dist/extension/lib/whatsapp/sent.mjs +1 -1
- package/dist/extension/lib/workspace-channel/channel.mjs +1 -1
- package/dist/extension/lib/workspace-chat-archive.mjs +1 -1
- package/dist/extension/tools/attachments_send.mjs +3 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.79.0
|
|
4
|
+
|
|
5
|
+
An email channel can reply to all: with `"reply": "all"` in `agent/segmentstream.json`, a reply goes to the person who wrote, in `To`, and copies the other addresses of the `To` and `Cc` of the mail it answers, without the mailbox's own address; files `segmentstream__attachments_send` sends go to the same people. `"sender"`, the default, replies to the person alone, as before. Each state of a reply names whom it goes to in its channel state, so a reply a later wake sends goes to the same people.
|
|
6
|
+
|
|
7
|
+
A held reply to mail keeps whom it goes to: `agent_review` gains `to` and `cc`, and `agent_review.approve` takes `to` and `cc`, lists of plain addresses that replace them, refused on a reply that is not mail. The review records whom it was sent to, and approving again to other people is refused. A reply held before goes to its `recipient` alone. `POST /api/ontology/agent/reviews` takes `to` and `cc` for a reply to mail; an agent on this release whose ontology SDK predates them holds the reply for its person alone. `emailReplyMessage` of `@segmentstream/ontology/email` takes several addresses in `to` and `cc`.
|
|
8
|
+
|
|
9
|
+
In the app, `useInboxChat`'s held replies carry `to` and `cc`, and `approve(reply, text?, { to, cc })` replaces them.
|
|
10
|
+
|
|
11
|
+
Pins @segmentstream/ontology 0.154.0.
|
|
12
|
+
|
|
13
|
+
## 0.78.0
|
|
14
|
+
|
|
15
|
+
Telegram and Slack keep what people change of their messages, and WhatsApp keeps the business's
|
|
16
|
+
reactions, on an agent whose ontology keeps the workspace chat store. No reaction or deletion
|
|
17
|
+
starts a turn, and a change to a message the chat does not hold changes nothing.
|
|
18
|
+
|
|
19
|
+
- Telegram keeps a person's reaction on its message, the agent's replies included: of several,
|
|
20
|
+
the one they added last, and only an emoji, never a custom emoji or a paid reaction. The
|
|
21
|
+
platform registers the bot for Telegram's `message_reaction` at the next deploy; in a group,
|
|
22
|
+
Telegram reports reactions only to a bot that is an administrator there.
|
|
23
|
+
- Slack records each person's message by Slack's `ts`, with the files it stored, and keeps their
|
|
24
|
+
reactions (as the emoji, or as Slack's short name between colons, such as `:partyparrot:`, for
|
|
25
|
+
a workspace's own), edits and deletions on it. In a thread the agent serves, an edit still
|
|
26
|
+
reaches its session as before. The agent's own Slack replies are kept without Slack's `ts`, so a
|
|
27
|
+
reaction to one is not kept yet. A press of a workspace button that queues a turn is recorded as
|
|
28
|
+
the presser's message.
|
|
29
|
+
- WhatsApp keeps a reaction the business sends from the WhatsApp Business app on a number in
|
|
30
|
+
Coexistence, as the business number's beside the person's.
|
|
31
|
+
- A session's first turn no longer shows the message its channel recorded for it as chat beside
|
|
32
|
+
the message itself.
|
|
33
|
+
|
|
34
|
+
Slack sends reactions only to an app that asks for them. To keep them, add `reactions:read` to the
|
|
35
|
+
Slack connection's `scopes` beside the defaults, deploy, authorize again, and create the app from
|
|
36
|
+
Console again, or subscribe an existing app to `reaction_added` and `reaction_removed` under
|
|
37
|
+
Event Subscriptions in Slack. Edits and deletions need nothing new.
|
|
38
|
+
|
|
3
39
|
## 0.77.1
|
|
4
40
|
|
|
5
41
|
Pins @segmentstream/ontology 0.153.1.
|
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.79.0";
|
|
8
8
|
function agentBuild(environment = process.env) {
|
|
9
9
|
return {
|
|
10
10
|
agent: version,
|
|
@@ -7,9 +7,11 @@ __eveCreateRequire(import.meta.url);
|
|
|
7
7
|
import { parseArchivedMessage } from "../extension/lib/telegram/archive-message.mjs";
|
|
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
|
-
import { C as
|
|
10
|
+
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-DavfKJDI.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,
|
|
@@ -366,9 +366,27 @@ function replyEvent(input) {
|
|
|
366
366
|
senderIsBot: true,
|
|
367
367
|
status: input.status,
|
|
368
368
|
messageId: input.messageId ?? null,
|
|
369
|
-
...input.at === void 0 ? {} : { at: input.at }
|
|
369
|
+
...input.at === void 0 ? {} : { at: input.at },
|
|
370
|
+
...input.recipients === void 0 ? {} : { argsSummary: JSON.stringify({ recipients: {
|
|
371
|
+
to: input.recipients.to,
|
|
372
|
+
cc: input.recipients.cc
|
|
373
|
+
} }) }
|
|
370
374
|
});
|
|
371
375
|
}
|
|
376
|
+
function replyRecipients(event) {
|
|
377
|
+
try {
|
|
378
|
+
const value = JSON.parse(event.argsSummary ?? "null");
|
|
379
|
+
const addresses = (list) => Array.isArray(list) && list.every((item) => typeof item === "string") ? list : void 0;
|
|
380
|
+
const to = addresses(value?.recipients?.to);
|
|
381
|
+
const cc = addresses(value?.recipients?.cc ?? []);
|
|
382
|
+
return to === void 0 || cc === void 0 ? void 0 : {
|
|
383
|
+
to,
|
|
384
|
+
cc
|
|
385
|
+
};
|
|
386
|
+
} catch {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
372
390
|
const TOPIC_PAGES = 5;
|
|
373
391
|
const TOPIC_PAGE_SIZE = 100;
|
|
374
392
|
async function topicContext(archive, input) {
|
|
@@ -590,4 +608,4 @@ function summarizeArguments(value) {
|
|
|
590
608
|
};
|
|
591
609
|
return JSON.stringify(workflowValue(visit(value, 0), { boundary: "chat arguments" })).slice(0, 4e3);
|
|
592
610
|
}
|
|
593
|
-
export {
|
|
611
|
+
export { sendFingerprint as C, workspaceChatArchive as E, reasonCode as S, storedMessageId as T, boundedMeta as _, chatEvent as a, messageInput as b, forgetChatStores as c, replyRecipients as d, sessionFailureEventId as f, UNVERIFIED as g, topicContext as h, chatAuthor as i, replyEvent as l, summarizeArguments as m, archiveSequence as n, cloudChatArchive as o, storeOf as p, chatArchive as r, collapseChatEvents as s, AGENT_SENDER as t, replyOperation as u, cutText as v, storedFiles as w, metaOf as x, eventOf as y };
|
|
@@ -318,6 +318,11 @@ export interface EmailChannelInput {
|
|
|
318
318
|
readonly record?: "agent" | "all";
|
|
319
319
|
/** With `record: "all"`, which of that mail is recorded, as Gmail's search; all of it when absent. */
|
|
320
320
|
readonly recordQuery?: string;
|
|
321
|
+
/**
|
|
322
|
+
* Whom the agent's replies go to: `sender`, when absent, the person alone; or `all`, the person in
|
|
323
|
+
* `To` and the other people of the mail it answers in `Cc`, as a reply to all.
|
|
324
|
+
*/
|
|
325
|
+
readonly reply?: "all" | "sender";
|
|
321
326
|
}
|
|
322
327
|
/**
|
|
323
328
|
* A channel the workspace defines in its own code, `defineChannel` in `agent/agent/channels/`,
|
|
@@ -628,6 +633,8 @@ export interface EmailSettings {
|
|
|
628
633
|
readonly record?: "agent" | "all";
|
|
629
634
|
/** With `record: "all"`, the Gmail search that narrows what is recorded. */
|
|
630
635
|
readonly recordQuery?: string;
|
|
636
|
+
/** `all` when the agent's replies go to all the people of the mail; absent, to the person alone. */
|
|
637
|
+
readonly reply?: "all";
|
|
631
638
|
}
|
|
632
639
|
/**
|
|
633
640
|
* A channel the workspace defines in its own code (`defineChannel`): the connection its code calls
|
|
@@ -423,7 +423,8 @@ function emailSettings(value, issues, path = ["channels", "email"]) {
|
|
|
423
423
|
"checkAfterMinutes",
|
|
424
424
|
"push",
|
|
425
425
|
"record",
|
|
426
|
-
"recordQuery"
|
|
426
|
+
"recordQuery",
|
|
427
|
+
"reply"
|
|
427
428
|
],
|
|
428
429
|
issues
|
|
429
430
|
});
|
|
@@ -470,6 +471,11 @@ function emailSettings(value, issues, path = ["channels", "email"]) {
|
|
|
470
471
|
message: "must be a Gmail search of at most 1000 characters",
|
|
471
472
|
path: [...path, "recordQuery"]
|
|
472
473
|
});
|
|
474
|
+
const reply = email.reply ?? "sender";
|
|
475
|
+
if (reply !== "all" && reply !== "sender") issues.push({
|
|
476
|
+
message: "must be \"all\" or \"sender\"",
|
|
477
|
+
path: [...path, "reply"]
|
|
478
|
+
});
|
|
473
479
|
if (issues.length > before) return null;
|
|
474
480
|
return {
|
|
475
481
|
connection: email.connection,
|
|
@@ -479,7 +485,8 @@ function emailSettings(value, issues, path = ["channels", "email"]) {
|
|
|
479
485
|
...record === "all" ? {
|
|
480
486
|
record: "all",
|
|
481
487
|
...email.recordQuery === void 0 ? {} : { recordQuery: email.recordQuery.trim() }
|
|
482
|
-
} : {}
|
|
488
|
+
} : {},
|
|
489
|
+
...reply === "all" ? { reply: "all" } : {}
|
|
483
490
|
};
|
|
484
491
|
}
|
|
485
492
|
function telegramSettings(value, issues, path = ["channels", "telegram"]) {
|
|
@@ -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-DavfKJDI.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-DavfKJDI.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)) } });
|
|
@@ -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-BrWGOlRd.mjs";
|
|
@@ -163,7 +163,23 @@ export declare function replyEvent(input: {
|
|
|
163
163
|
readonly status: "requested" | "sent" | "failed";
|
|
164
164
|
readonly messageId?: string;
|
|
165
165
|
readonly at?: string;
|
|
166
|
+
/**
|
|
167
|
+
* Whom a reply to mail goes to, kept in the message's channel state: every state of the reply
|
|
168
|
+
* carries them, so the one still to deliver is sent to the same people.
|
|
169
|
+
*/
|
|
170
|
+
readonly recipients?: {
|
|
171
|
+
readonly to: ReadonlyArray<string>;
|
|
172
|
+
readonly cc: ReadonlyArray<string>;
|
|
173
|
+
};
|
|
166
174
|
}): ChatEvent;
|
|
175
|
+
/**
|
|
176
|
+
* Whom a reply to mail an archived event of {@link replyEvent} goes to, as its channel state keeps
|
|
177
|
+
* them; undefined for a reply that names no one.
|
|
178
|
+
*/
|
|
179
|
+
export declare function replyRecipients(event: Pick<ChatEvent, "argsSummary">): {
|
|
180
|
+
readonly to: ReadonlyArray<string>;
|
|
181
|
+
readonly cc: ReadonlyArray<string>;
|
|
182
|
+
} | undefined;
|
|
167
183
|
/**
|
|
168
184
|
* One chat or forum topic of the archive, newest first. The archive reads every topic when no topic
|
|
169
185
|
* is named, so a message without a topic, such as one in a forum's General topic, collects the rows
|
|
@@ -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
|
|
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-DavfKJDI.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>;
|
|
@@ -6,7 +6,7 @@ __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 {
|
|
9
|
+
import { h as topicContext, i as chatAuthor, n as archiveSequence, p as storeOf, r as chatArchive, s as collapseChatEvents } from "../../_chunks/chat-archive-DavfKJDI.mjs";
|
|
10
10
|
import { xt as reportTelegramError } from "../../_chunks/principal-C7aAjyt4.mjs";
|
|
11
11
|
import { createHash } from "node:crypto";
|
|
12
12
|
import { deliveries, runs, turns } from "eve/events";
|
|
@@ -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. */
|
|
@@ -4,7 +4,7 @@ import { createRequire as __eveCreateRequire } from "node:module";
|
|
|
4
4
|
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
|
-
import {
|
|
7
|
+
import { a as chatEvent, g as UNVERIFIED, p as storeOf, w as storedFiles } from "../../_chunks/chat-archive-DavfKJDI.mjs";
|
|
8
8
|
const MAXIMUM_PARTS = 20;
|
|
9
9
|
const PART_BOUNDS = {
|
|
10
10
|
text: 1024,
|
|
@@ -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",
|
|
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { n as contentText, t as CONTENT_CAPS } from "../../_chunks/content-cDtVnr8Y.mjs";
|
|
8
|
-
import { a as chatEvent,
|
|
8
|
+
import { a as chatEvent, f as sessionFailureEventId, m as summarizeArguments, p as storeOf, r as chatArchive } from "../../_chunks/chat-archive-DavfKJDI.mjs";
|
|
9
9
|
import { agentTaskIdOf } from "./agent-task.mjs";
|
|
10
10
|
import { revisionOf } from "./review/revision.mjs";
|
|
11
11
|
import { Ft as chatChannel, Pt as chatAddressOf, i as memberIdOf, ot as guestIdOf } from "../../_chunks/principal-C7aAjyt4.mjs";
|
|
@@ -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 [];
|
|
@@ -6,10 +6,10 @@ import type { SendAttachmentsInput } from "../telegram/attachments-send.js";
|
|
|
6
6
|
import { type Gmail } from "./gmail.js";
|
|
7
7
|
/**
|
|
8
8
|
* `attachments_send` in an email chat: the stored files go in one reply in the person's Gmail
|
|
9
|
-
* thread, from the channel's mailbox,
|
|
10
|
-
* message, marked `Auto-Submitted: auto-replied`, and named by a key of the session
|
|
11
|
-
* call, so a call run again finds the reply it sent rather than sending it twice. The
|
|
12
|
-
* the reply's text. The checks and failures are every channel's (`../attachments-send.ts`).
|
|
9
|
+
* thread, from the channel's mailbox, to the people the channel's text replies go to: under the
|
|
10
|
+
* thread's last message, marked `Auto-Submitted: auto-replied`, and named by a key of the session
|
|
11
|
+
* and the tool call, so a call run again finds the reply it sent rather than sending it twice. The
|
|
12
|
+
* caption is the reply's text. The checks and failures are every channel's (`../attachments-send.ts`).
|
|
13
13
|
*/
|
|
14
14
|
/**
|
|
15
15
|
* The most bytes of files one reply carries, together: below the 25 MB Gmail takes, with room for
|
|
@@ -34,6 +34,8 @@ export declare function sendEmailAttachments(options: {
|
|
|
34
34
|
readonly callId: string;
|
|
35
35
|
/** The connection of the email channel the chat is on, such as `channels.email.connection`. */
|
|
36
36
|
readonly connection: string | undefined;
|
|
37
|
+
/** The thread's other people the reply copies, as the channel's text replies do. */
|
|
38
|
+
readonly cc?: ReadonlyArray<string>;
|
|
37
39
|
readonly environment?: Environment;
|
|
38
40
|
readonly token?: RuntimeToken;
|
|
39
41
|
readonly fetch?: typeof fetch;
|
|
@@ -102,6 +102,7 @@ async function sendEmailAttachments(options) {
|
|
|
102
102
|
const id = await mailbox.reply({
|
|
103
103
|
threadId: chat.threadId,
|
|
104
104
|
to: chat.peer,
|
|
105
|
+
...options.cc === void 0 || options.cc.length === 0 ? {} : { cc: options.cc },
|
|
105
106
|
text: input.caption ?? "",
|
|
106
107
|
key: replyKeyOf(options.sessionId, options.callId, "files"),
|
|
107
108
|
attachments: read.map(({ file }) => ({
|
|
@@ -20,7 +20,8 @@ import { type Gmail } from "./gmail.js";
|
|
|
20
20
|
* project's agent webhook secret. A wake carries the cursor the last one answered; the channel
|
|
21
21
|
* reads what the mailbox received since, starts a turn per message in the person's thread, and
|
|
22
22
|
* answers the next cursor. One Gmail thread is one chat with one person. The reply leaves in the
|
|
23
|
-
* same thread,
|
|
23
|
+
* same thread, to the person and, as a reply to all, the other people of the mail it answers, or
|
|
24
|
+
* waits for a member when the person's review holds it.
|
|
24
25
|
*
|
|
25
26
|
* A reply is an operation of the chat archive, `requested` before it is sent, then `sent` or
|
|
26
27
|
* `failed`. One Gmail does not take for a while waits there, out of the 16 KiB cursor, and each
|
|
@@ -75,14 +76,25 @@ export interface EmailChannelOptions {
|
|
|
75
76
|
}
|
|
76
77
|
/**
|
|
77
78
|
* One person's private chat in a Gmail thread: the thread and the sender's address. Two people who
|
|
78
|
-
* write in the same thread have a chat and a session each
|
|
79
|
+
* write in the same thread have a chat and a session each.
|
|
79
80
|
*/
|
|
80
81
|
export declare function emailChatId(threadId: string, sender: string): string;
|
|
82
|
+
/**
|
|
83
|
+
* The principal's attribute that names the other people of the mail a turn answers, `To` and `Cc`
|
|
84
|
+
* without the sender and the mailbox: a reply to all copies them.
|
|
85
|
+
*/
|
|
86
|
+
export declare const EMAIL_OTHERS_ATTRIBUTE = "segmentstreamEmailOthers";
|
|
87
|
+
/**
|
|
88
|
+
* Whom a reply to `principal` copies: the other people of the mail it answers, when the channel
|
|
89
|
+
* replies to all (`reply: "all"`); none when it replies to the sender alone. The first of them, as
|
|
90
|
+
* many as a reply goes to beside its person.
|
|
91
|
+
*/
|
|
92
|
+
export declare function replyCopies(principal: SessionAuthContext | null | undefined, settings: Pick<EmailSettings, "reply"> | null | undefined): ReadonlyArray<string>;
|
|
81
93
|
/**
|
|
82
94
|
* The principal of an email session: the member who writes from the address, on the email channel
|
|
83
|
-
* the current wake runs for.
|
|
95
|
+
* the current wake runs for, with the other people of the mail it answers.
|
|
84
96
|
*/
|
|
85
|
-
export declare function emailPrincipal(member: PairedMember, sender: string, threadId: string): SessionAuthContext;
|
|
97
|
+
export declare function emailPrincipal(member: PairedMember, sender: string, threadId: string, others?: ReadonlyArray<string>): SessionAuthContext;
|
|
86
98
|
/** The email channel of the extension. */
|
|
87
99
|
export declare function segmentstreamEmail(options: EmailChannelOptions): Channel;
|
|
88
100
|
/** The email channel's route and events, which {@link segmentstreamEmail} defines as a channel. */
|
|
@@ -10,7 +10,7 @@ import { agentToolsAttribute } from "../agent-tools.mjs";
|
|
|
10
10
|
import { providerChat } from "../attachment-tools.mjs";
|
|
11
11
|
import { Pt as chatAddressOf, S as fetchStoredAttachment, b as agentAttachments, d as prepareInboundMedia, i as memberIdOf, m as turnContent, zt as withChatAddress } from "../../../_chunks/principal-C7aAjyt4.mjs";
|
|
12
12
|
import { channelAttributes, currentChannel, currentKey, inHandlerChannels, withNamedRoutes } from "../channel-scope.mjs";
|
|
13
|
-
import {
|
|
13
|
+
import { d as replyRecipients, g as UNVERIFIED, l as replyEvent, p as storeOf, r as chatArchive } from "../../../_chunks/chat-archive-DavfKJDI.mjs";
|
|
14
14
|
import { recordChatMessage, recordHandledMessage, recordSentOutside } from "../chat-messages.mjs";
|
|
15
15
|
import { ConnectionProxyError, connectionProxy } from "../connection-proxy.mjs";
|
|
16
16
|
import { redactDiagnostic } from "../diagnostics.mjs";
|
|
@@ -27,7 +27,7 @@ import { inboundMail, parseMail, sentMail } from "./message.mjs";
|
|
|
27
27
|
import { createHmac, randomUUID, timingSafeEqual } from "node:crypto";
|
|
28
28
|
import { reply } from "eve/events";
|
|
29
29
|
import { POST, defineChannel } from "eve/channels";
|
|
30
|
-
import { REPLY_KEY_HEADER } from "@segmentstream/ontology/email";
|
|
30
|
+
import { EMAIL_RECIPIENTS_LIMIT, REPLY_KEY_HEADER, isEmailAddress } from "@segmentstream/ontology/email";
|
|
31
31
|
const EMAIL_ROUTE = "/eve/segmentstream/v1/email";
|
|
32
32
|
const EMAIL_AUTHENTICATOR = "segmentstream-email";
|
|
33
33
|
const MESSAGES_PER_WAKE = 20;
|
|
@@ -58,12 +58,14 @@ const DISCARDED = new Set([
|
|
|
58
58
|
function waitingReply(event) {
|
|
59
59
|
const key = event.operationId?.startsWith("reply:") ? event.operationId.slice(6) : void 0;
|
|
60
60
|
const threadId = event.threadId;
|
|
61
|
-
const
|
|
62
|
-
|
|
61
|
+
const named = replyRecipients(event);
|
|
62
|
+
const to = named?.to.length === 1 ? named.to[0] : threadId !== null && event.chatId.startsWith(`${threadId}:`) ? event.chatId.slice(threadId.length + 1) : void 0;
|
|
63
|
+
return key === void 0 || threadId === null || !GMAIL_ID.test(threadId) || to === void 0 || !isEmailAddress(to) || event.text === null ? void 0 : {
|
|
63
64
|
key,
|
|
64
65
|
chatId: event.chatId,
|
|
65
66
|
threadId,
|
|
66
67
|
to,
|
|
68
|
+
cc: (named?.cc ?? []).filter(isEmailAddress).slice(0, EMAIL_RECIPIENTS_LIMIT - 1),
|
|
67
69
|
text: event.text,
|
|
68
70
|
participantIds: event.participantIds,
|
|
69
71
|
sessionId: event.sessionId,
|
|
@@ -131,7 +133,12 @@ function decodeCursor(value) {
|
|
|
131
133
|
function emailChatId(threadId, sender) {
|
|
132
134
|
return `${threadId}:${sender}`;
|
|
133
135
|
}
|
|
134
|
-
|
|
136
|
+
const EMAIL_OTHERS_ATTRIBUTE = "segmentstreamEmailOthers";
|
|
137
|
+
function replyCopies(principal, settings) {
|
|
138
|
+
const others = principal?.attributes[EMAIL_OTHERS_ATTRIBUTE];
|
|
139
|
+
return settings?.reply !== "all" || !Array.isArray(others) ? [] : others.filter(isEmailAddress).slice(0, EMAIL_RECIPIENTS_LIMIT - 1);
|
|
140
|
+
}
|
|
141
|
+
function emailPrincipal(member, sender, threadId, others = []) {
|
|
135
142
|
const channel = currentChannel("email");
|
|
136
143
|
return withChatAddress({
|
|
137
144
|
authenticator: EMAIL_AUTHENTICATOR,
|
|
@@ -146,7 +153,8 @@ function emailPrincipal(member, sender, threadId) {
|
|
|
146
153
|
...agentToolsAttribute(member.agentTools),
|
|
147
154
|
...member.name === null ? {} : { memberName: member.name },
|
|
148
155
|
...member.locale === void 0 ? {} : { locale: member.locale },
|
|
149
|
-
...channelAttributes("email", channel)
|
|
156
|
+
...channelAttributes("email", channel),
|
|
157
|
+
...others.length === 0 ? {} : { [EMAIL_OTHERS_ATTRIBUTE]: others.slice(0, EMAIL_RECIPIENTS_LIMIT - 1) }
|
|
150
158
|
}
|
|
151
159
|
}, {
|
|
152
160
|
provider: "email",
|
|
@@ -235,6 +243,7 @@ function emailChannelDefinition(options) {
|
|
|
235
243
|
return await mailbox().reply({
|
|
236
244
|
threadId: reply.threadId,
|
|
237
245
|
to: reply.to,
|
|
246
|
+
...reply.cc.length === 0 ? {} : { cc: reply.cc },
|
|
238
247
|
text: reply.text,
|
|
239
248
|
key: reply.key
|
|
240
249
|
});
|
|
@@ -257,7 +266,11 @@ function emailChannelDefinition(options) {
|
|
|
257
266
|
text: reply.text,
|
|
258
267
|
status,
|
|
259
268
|
...messageId === void 0 ? {} : { messageId },
|
|
260
|
-
...status === "requested" ? { at: reply.at } : {}
|
|
269
|
+
...status === "requested" ? { at: reply.at } : {},
|
|
270
|
+
recipients: {
|
|
271
|
+
to: [reply.to],
|
|
272
|
+
cc: reply.cc
|
|
273
|
+
}
|
|
261
274
|
}));
|
|
262
275
|
return true;
|
|
263
276
|
} catch (error) {
|
|
@@ -388,7 +401,7 @@ function emailChannelDefinition(options) {
|
|
|
388
401
|
});
|
|
389
402
|
return;
|
|
390
403
|
}
|
|
391
|
-
const auth = emailPrincipal(resolution.member, mail.from, added.threadId);
|
|
404
|
+
const auth = emailPrincipal(resolution.member, mail.from, added.threadId, mail.others);
|
|
392
405
|
const memberId = memberIdOf(auth);
|
|
393
406
|
const inbound = mail.attachments.map((file, index) => ({
|
|
394
407
|
key: `${added.id}:${index}`,
|
|
@@ -749,13 +762,18 @@ function emailChannelDefinition(options) {
|
|
|
749
762
|
if (outcome !== "completed" || chat?.provider !== "email" || chat.peer === void 0) return;
|
|
750
763
|
const text = replyText(ctx.view, turnId);
|
|
751
764
|
if (completionKind(text) !== "reply") return;
|
|
765
|
+
const cc = replyCopies(principal, settings());
|
|
752
766
|
const reviewing = review()?.review;
|
|
753
767
|
if (!(reviewing === void 0 ? true : await reviewing.sendOrHold({
|
|
754
768
|
principal,
|
|
755
769
|
sessionId: ctx.session.id,
|
|
756
770
|
turnId,
|
|
757
771
|
partId: turnId,
|
|
758
|
-
text
|
|
772
|
+
text,
|
|
773
|
+
recipients: {
|
|
774
|
+
to: [chat.peer],
|
|
775
|
+
cc
|
|
776
|
+
}
|
|
759
777
|
}))) return;
|
|
760
778
|
const memberId = memberIdOf(principal);
|
|
761
779
|
const reply = {
|
|
@@ -763,6 +781,7 @@ function emailChannelDefinition(options) {
|
|
|
763
781
|
chatId: chat.chatId,
|
|
764
782
|
threadId: chat.threadId,
|
|
765
783
|
to: chat.peer,
|
|
784
|
+
cc,
|
|
766
785
|
text,
|
|
767
786
|
participantIds: memberId === void 0 ? [] : [memberId],
|
|
768
787
|
sessionId: ctx.session.id,
|
|
@@ -780,4 +799,4 @@ function emailChannelDefinition(options) {
|
|
|
780
799
|
fetchFile: (url, context) => fetchStoredAttachment(files(), url, context)
|
|
781
800
|
};
|
|
782
801
|
}
|
|
783
|
-
export { EMAIL_AUTHENTICATOR, EMAIL_ROUTE, MAXIMUM_CURSOR_LENGTH, emailChannelDefinition, emailChatId, emailPrincipal, segmentstreamEmail };
|
|
802
|
+
export { EMAIL_AUTHENTICATOR, EMAIL_OTHERS_ATTRIBUTE, EMAIL_ROUTE, MAXIMUM_CURSOR_LENGTH, emailChannelDefinition, emailChatId, emailPrincipal, replyCopies, segmentstreamEmail };
|
|
@@ -67,15 +67,17 @@ export interface Gmail {
|
|
|
67
67
|
/** Asks Gmail to push the mailbox's changes to `topic`; resolves the watch's expiry. */
|
|
68
68
|
watch(topic: string): Promise<number>;
|
|
69
69
|
/**
|
|
70
|
-
* Replies in `threadId` to `to`, under the thread's last message, with the reply's
|
|
71
|
-
* HTML and as plain text and the files after it, marked
|
|
72
|
-
* Resolves the sent message's id. With `key`, a message in the
|
|
73
|
-
* is the reply, sent by an earlier attempt whose answer was lost:
|
|
74
|
-
* nothing is sent.
|
|
70
|
+
* Replies in `threadId` to `to`, copying `cc`, under the thread's last message, with the reply's
|
|
71
|
+
* Markdown as HTML and as plain text and the files after it, marked
|
|
72
|
+
* `Auto-Submitted: auto-replied`. Resolves the sent message's id. With `key`, a message in the
|
|
73
|
+
* thread that already carries it is the reply, sent by an earlier attempt whose answer was lost:
|
|
74
|
+
* its id is returned and nothing is sent.
|
|
75
75
|
*/
|
|
76
76
|
reply(input: {
|
|
77
77
|
readonly threadId: string;
|
|
78
78
|
readonly to: string;
|
|
79
|
+
/** The thread's other people the reply copies; none when absent. */
|
|
80
|
+
readonly cc?: ReadonlyArray<string>;
|
|
79
81
|
readonly text: string;
|
|
80
82
|
readonly key?: string;
|
|
81
83
|
readonly attachments?: ReadonlyArray<EmailAttachment>;
|
|
@@ -191,6 +191,7 @@ function gmail(proxy) {
|
|
|
191
191
|
}
|
|
192
192
|
const raw = emailReplyMessage({
|
|
193
193
|
to: input.to,
|
|
194
|
+
...input.cc === void 0 || input.cc.length === 0 ? {} : { cc: input.cc },
|
|
194
195
|
subject: header(messages[0], "Subject") ?? null,
|
|
195
196
|
inReplyTo: header(messages.at(-1), "Message-ID") ?? null,
|
|
196
197
|
references: header(messages.at(-1), "References") ?? null,
|
|
@@ -16,6 +16,11 @@ export interface InboundMail {
|
|
|
16
16
|
readonly messageId: string | undefined;
|
|
17
17
|
/** What the person wrote, without the history they quoted. */
|
|
18
18
|
readonly text: string;
|
|
19
|
+
/**
|
|
20
|
+
* Whom else the message went to, in `To` and `Cc`, in lower case: without the sender and the
|
|
21
|
+
* mailbox's own addresses. A reply to all copies them.
|
|
22
|
+
*/
|
|
23
|
+
readonly others: ReadonlyArray<string>;
|
|
19
24
|
readonly attachments: ReadonlyArray<MailAttachment>;
|
|
20
25
|
/**
|
|
21
26
|
* Whether Gmail's receiving server reported DMARC passing for the sender's own domain: the
|