@segmentstream/agent 0.84.0 → 0.86.1

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/_chunks/{build-metadata-CFe-5i6d.mjs → build-metadata-oZ48LO3j.mjs} +1 -1
  3. package/dist/_chunks/silent-C9x3GcMg.mjs +262 -0
  4. package/dist/extension/channels/email.mjs +3 -1
  5. package/dist/extension/channels/slack.mjs +3 -1
  6. package/dist/extension/channels/telegram.mjs +3 -1
  7. package/dist/extension/channels/whatsapp.mjs +3 -1
  8. package/dist/extension/lib/attachments-dispatch.d.ts +23 -0
  9. package/dist/extension/lib/attachments-dispatch.mjs +79 -0
  10. package/dist/extension/lib/build-metadata.mjs +1 -1
  11. package/dist/extension/lib/chat-recorder.mjs +1 -1
  12. package/dist/extension/lib/email/channel.d.ts +2 -0
  13. package/dist/extension/lib/email/channel.mjs +39 -5
  14. package/dist/extension/lib/evals.d.ts +3 -1
  15. package/dist/extension/lib/evals.mjs +3 -1
  16. package/dist/extension/lib/review/client.mjs +5 -0
  17. package/dist/extension/lib/review/files.d.ts +101 -0
  18. package/dist/extension/lib/review/files.mjs +7 -0
  19. package/dist/extension/lib/review/hold.d.ts +7 -0
  20. package/dist/extension/lib/review/hold.mjs +1 -0
  21. package/dist/extension/lib/review/judge.d.ts +2 -0
  22. package/dist/extension/lib/review/judge.mjs +1 -0
  23. package/dist/extension/lib/review/reply.d.ts +66 -0
  24. package/dist/extension/lib/review/reply.mjs +90 -8
  25. package/dist/extension/lib/telegram/adapter.mjs +9 -4
  26. package/dist/extension/lib/telegram/health.mjs +1 -1
  27. package/dist/extension/lib/telegram/lifecycle.mjs +1 -1
  28. package/dist/extension/lib/telegram/routing-context.mjs +1 -1
  29. package/dist/extension/lib/telegram/silent.mjs +1 -84
  30. package/dist/extension/lib/whatsapp/adapter.mjs +1 -1
  31. package/dist/extension/lib/workspace-channel/channel.mjs +23 -4
  32. package/dist/extension/tools/attachments_send.mjs +18 -38
  33. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.86.1
4
+
5
+ Pins @segmentstream/ontology 0.165.0.
6
+
7
+ ## 0.86.0
8
+
9
+ `@segmentstream/agent/evals` also offers eve's value assertions (`includes`, `equals`, `matches`,
10
+ `satisfies`, `similarity`) for `t.check`, so an eval imports nothing but this package.
11
+
12
+ ## 0.85.0
13
+
14
+ In a chat whose replies are reviewed, `segmentstream__attachments_send` no longer sends files
15
+ ahead of the reply. It asks the ontology (`POST /api/ontology/agent/drafts/files`) whether the
16
+ person may read each file and the chat's channel can send it, answers `{ attached: true }` or a
17
+ refusal, and the files join the turn's reply: the decision model reads their names with it, a reply
18
+ it passes goes out followed by its files, and a held reply carries them into its `agent_draft`,
19
+ which approval sends together. A call's caption joins the reply's text. Files no reply carries,
20
+ such as a reply of files alone, are held on their own and never sent unreviewed; a failed or
21
+ interrupted turn drops them. With an ontology SDK that holds no files with a draft, the call is
22
+ refused with `unsupported`: upgrade `@segmentstream/ontology` with the agent SDK to send files in
23
+ reviewed chats.
24
+
25
+ Pins @segmentstream/ontology 0.164.0.
26
+
3
27
  ## 0.84.0
4
28
 
5
29
  The agent runs in app previews. Where the platform sets `SEGMENTSTREAM_DEPLOYMENT_TARGET=preview`,
@@ -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.84.0";
7
+ var version = "0.86.1";
8
8
  function agentBuild(environment = process.env) {
9
9
  return {
10
10
  agent: version,
@@ -0,0 +1,262 @@
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 { 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-C1g8wCIg.mjs";
9
+ import { splitTelegramText } from "../extension/lib/telegram/format.mjs";
10
+ import { inTelegramSendQueue } from "../extension/lib/telegram/send-queue.mjs";
11
+ import { redactDiagnostic } from "../extension/lib/diagnostics.mjs";
12
+ import { appOrigin, channelsEnabled } from "../extension/lib/environment.mjs";
13
+ import { runtimeToken } from "../extension/lib/runtime-token.mjs";
14
+ import { randomUUID } from "node:crypto";
15
+ import { calls, reply } from "eve/events";
16
+ const ATTACH_TOOL = /(?:^|__)attachments_send$/u;
17
+ const NONE = {
18
+ files: [],
19
+ captions: []
20
+ };
21
+ function isRecord(value) {
22
+ return typeof value === "object" && value !== null && !Array.isArray(value);
23
+ }
24
+ function attachedOf(output) {
25
+ if (!isRecord(output) || output.attached !== true || !Array.isArray(output.files)) return;
26
+ return {
27
+ files: output.files.flatMap((file) => isRecord(file) && typeof file.entity === "string" && typeof file.id === "string" && typeof file.property === "string" && typeof file.filename === "string" && typeof file.contentType === "string" && typeof file.size === "number" ? [{
28
+ entity: file.entity,
29
+ id: file.id,
30
+ property: file.property,
31
+ filename: file.filename,
32
+ contentType: file.contentType,
33
+ size: file.size
34
+ }] : []),
35
+ captions: typeof output.caption === "string" && output.caption.trim() !== "" ? [output.caption] : []
36
+ };
37
+ }
38
+ function attachments(view, turnId) {
39
+ return calls(view, { turnId }).filter((call) => ATTACH_TOOL.test(call.name) && call.outcome !== void 0).flatMap((call) => {
40
+ const attached = attachedOf(call.output);
41
+ return attached === void 0 || attached.files.length === 0 ? [] : [{
42
+ ...attached,
43
+ endedAt: call.endedAt ?? ""
44
+ }];
45
+ }).sort((one, other) => one.endedAt < other.endedAt ? -1 : one.endedAt > other.endedAt ? 1 : 0);
46
+ }
47
+ function merged(list) {
48
+ return list.length === 0 ? NONE : {
49
+ files: list.flatMap((item) => item.files),
50
+ captions: list.flatMap((item) => item.captions)
51
+ };
52
+ }
53
+ function replyParts(view, turnId) {
54
+ return reply(view, turnId).filter((part) => part.kind === "text" && part.phase === "reply" && part.interrupted !== true && typeof part.value === "string" && completionKind(part.value) === "reply");
55
+ }
56
+ function turnFiles(view, turnId) {
57
+ return merged(attachments(view, turnId));
58
+ }
59
+ function partFiles(view, turnId, partId) {
60
+ const parts = replyParts(view, turnId);
61
+ const index = parts.findIndex((part) => part.partId === partId);
62
+ if (index < 0) return NONE;
63
+ const start = index > 0 ? parts[index - 1].startedAt ?? "" : "";
64
+ const end = index >= 0 ? parts[index].startedAt ?? "" : "";
65
+ return merged(attachments(view, turnId).filter((attached) => attached.endedAt > start && (end === "" || attached.endedAt <= end)));
66
+ }
67
+ function filesAfterReply(view, turnId) {
68
+ const last = replyParts(view, turnId).at(-1)?.startedAt;
69
+ return merged(attachments(view, turnId).filter((attached) => last === void 0 || attached.endedAt > last));
70
+ }
71
+ const DRAFT_FILES_LIMIT = 10;
72
+ const CAPTION_LIMIT = 1024;
73
+ function fileGroups(files) {
74
+ const groups = [];
75
+ for (let start = 0; start < files.files.length; start += 10) groups.push({
76
+ files: files.files.slice(start, start + 10),
77
+ captions: start === 0 ? files.captions : []
78
+ });
79
+ return groups;
80
+ }
81
+ function withCaptions(text, captions) {
82
+ return [text.trim(), ...captions.map((caption) => caption.trim())].filter((part) => part !== "").join("\n\n");
83
+ }
84
+ var ReplyFilesRefused = class extends Error {
85
+ code;
86
+ status;
87
+ index;
88
+ name = "ReplyFilesRefused";
89
+ constructor(code, status, index) {
90
+ super(`The ontology refused the reply's files: ${code}.`);
91
+ this.code = code;
92
+ this.status = status;
93
+ this.index = index;
94
+ }
95
+ };
96
+ async function checkReplyFiles(input) {
97
+ const chat = chatAddressOf(input.principal);
98
+ const memberId = memberIdOf(input.principal);
99
+ if (chat === void 0 || chat.provider === "web" || memberId === void 0) throw new ReplyFilesRefused("unsupported", 0);
100
+ const token = await input.token();
101
+ let response;
102
+ try {
103
+ response = await (input.fetch ?? fetch)(`${input.origin}/api/ontology/agent/drafts/files`, {
104
+ method: "POST",
105
+ headers: {
106
+ authorization: `Bearer ${token}`,
107
+ accept: "application/json",
108
+ "content-type": "application/json"
109
+ },
110
+ body: JSON.stringify({
111
+ provider: chat.provider,
112
+ ...chat.channel === void 0 ? {} : { channel: chat.channel },
113
+ member_id: memberId,
114
+ files: input.files.map((file) => ({
115
+ entity: file.entity,
116
+ id: file.id,
117
+ ...file.property === void 0 ? {} : { property: file.property }
118
+ }))
119
+ }),
120
+ redirect: "error",
121
+ signal: AbortSignal.timeout(1e4)
122
+ });
123
+ } catch (error) {
124
+ console.error("[segmentstream] the reply's files could not be checked", { error: redactDiagnostic(error, new Set([token])) });
125
+ throw new ReplyFilesRefused("unavailable", 0);
126
+ }
127
+ const body = await response.json().catch(() => void 0);
128
+ if (response.status === 404) throw new ReplyFilesRefused("unsupported", 404);
129
+ if (!response.ok) throw new ReplyFilesRefused(isRecord(body) && typeof body.error === "string" ? body.error : "unavailable", response.status, isRecord(body) && typeof body.index === "number" ? body.index : void 0);
130
+ return (isRecord(body) && Array.isArray(body.files) ? body.files : []).flatMap((file) => isRecord(file) && typeof file.entity === "string" && typeof file.id === "string" && typeof file.property === "string" && typeof file.filename === "string" && typeof file.content_type === "string" && typeof file.size === "number" ? [{
131
+ entity: file.entity,
132
+ id: file.id,
133
+ property: file.property,
134
+ filename: file.filename,
135
+ contentType: file.content_type,
136
+ size: file.size
137
+ }] : []);
138
+ }
139
+ async function attachToReply(input) {
140
+ const environment = input.environment ?? process.env;
141
+ const locale = confirmationLocale(input.principal);
142
+ const refuse = (error, diagnostic, index) => {
143
+ const reference = randomUUID();
144
+ console.error("[segmentstream] attachment refused for a reviewed reply", {
145
+ reference,
146
+ error,
147
+ diagnostic
148
+ });
149
+ return {
150
+ error,
151
+ detail: failureText(reference, "attachment", locale),
152
+ reference,
153
+ ...index === void 0 ? {} : { index }
154
+ };
155
+ };
156
+ if (!channelsEnabled(environment)) return refuse("channels_disabled", "Attachments can be sent only in production.");
157
+ try {
158
+ return {
159
+ attached: true,
160
+ files: await checkReplyFiles({
161
+ origin: appOrigin(environment),
162
+ token: input.token ?? runtimeToken,
163
+ ...input.fetch === void 0 ? {} : { fetch: input.fetch },
164
+ principal: input.principal,
165
+ files: input.files
166
+ }),
167
+ ...input.caption === void 0 || input.caption.trim() === "" ? {} : { caption: input.caption }
168
+ };
169
+ } catch (error) {
170
+ return error instanceof ReplyFilesRefused ? refuse(error.code, error.message, error.index) : refuse("unavailable", error);
171
+ }
172
+ }
173
+ const NO_REPLY_TOOL = "no_reply";
174
+ function isNoReplyCall(name) {
175
+ const parts = name?.split("__") ?? [];
176
+ return parts.length <= 2 && parts.at(-1) === NO_REPLY_TOOL;
177
+ }
178
+ const SILENT_MARKERS = new Set(["[silent]", "no_reply"]);
179
+ function isSilentReply(text) {
180
+ return SILENT_MARKERS.has(text.trim().toLowerCase());
181
+ }
182
+ function completionKind(message, finishReason) {
183
+ if (finishReason === "tool-calls") return "tool_calls";
184
+ if (message === void 0 || message === null || message === "") return "empty";
185
+ if (message.trim() === "") return "whitespace";
186
+ return isSilentReply(message) ? "silent_marker" : "reply";
187
+ }
188
+ const INTERIM_TURNS = 256;
189
+ function interimTexts(limit = 256) {
190
+ const turns = new Map();
191
+ return {
192
+ has: (turn, text) => turns.get(turn)?.has(text) ?? false,
193
+ add(turn, text) {
194
+ const texts = turns.get(turn) ?? new Set();
195
+ turns.delete(turn);
196
+ turns.set(turn, texts.add(text));
197
+ for (const oldest of turns.keys()) {
198
+ if (turns.size <= limit) break;
199
+ turns.delete(oldest);
200
+ }
201
+ }
202
+ };
203
+ }
204
+ function replyDelivery(scope = () => "telegram", interim, review, identifiers = () => "block") {
205
+ return async (event, context) => {
206
+ if (event.data.kind !== "text" || event.data.interrupted) return;
207
+ const channel = context.channel;
208
+ const textValue = typeof event.data.value === "string" ? event.data.value : "";
209
+ const kind = completionKind(textValue, event.data.phase === "reply" ? "stop" : "tool-calls");
210
+ const interimOn = interim?.enabled() === true;
211
+ const isInterim = kind === "tool_calls" && interimOn && completionKind(textValue) === "reply";
212
+ if (kind !== "reply" && !isInterim) return;
213
+ const reviewed = review?.reviewed(context.session?.auth.current) === true;
214
+ if (reviewed && isInterim) return;
215
+ const turn = interimOn && typeof event.scope?.turnId === "string" && event.scope?.turnId !== "" ? JSON.stringify([context.session?.id ?? "", event.scope?.turnId]) : void 0;
216
+ const key = textValue.trim();
217
+ if (turn !== void 0 && interim.delivered.has(turn, key)) return;
218
+ const turnId = event.scope?.turnId ?? null;
219
+ const files = reviewed && !isInterim && turnId !== null && context.view !== void 0 ? partFiles(context.view, turnId, event.data.partId) : void 0;
220
+ if (reviewed && !await review.sendOrHold({
221
+ principal: context.session?.auth.current,
222
+ sessionId: context.session?.id ?? "",
223
+ turnId,
224
+ partId: event.data.partId,
225
+ text: textValue,
226
+ ...files === void 0 || files.files.length === 0 ? {} : { files }
227
+ })) return;
228
+ const message = customerMessage(textValue, confirmationLocale(context.session?.auth.current ?? null, currentLocale()), identifiers());
229
+ const replyTo = (context.session?.auth.current)?.attributes.replyToMessageId;
230
+ const replyParameters = typeof replyTo === "string" && /^[1-9]\d*$/u.test(replyTo) ? { reply_parameters: {
231
+ message_id: Number(replyTo),
232
+ allow_sending_without_reply: true
233
+ } } : {};
234
+ await inTelegramSendQueue(scope(), channel.telegram.chatId, async () => {
235
+ const messageIds = [];
236
+ try {
237
+ for (const part of splitTelegramText(message)) {
238
+ const result = await channel.telegram.post({
239
+ ...part,
240
+ ...replyParameters
241
+ });
242
+ if (!/^[1-9]\d*$/u.test(result.id)) throw new Error("Telegram did not acknowledge the reply with a message id.");
243
+ messageIds.push(Number(result.id));
244
+ }
245
+ } catch (error) {
246
+ const reference = reportTelegramError(isInterim ? "telegram_interim_delivery_failed" : "telegram_reply_delivery_failed", error, { messageIds });
247
+ throw new TelegramDeliveryError(reference, error instanceof TelegramDeliveryError ? error.delivery : "unknown", messageIds);
248
+ }
249
+ return messageIds;
250
+ });
251
+ if (isInterim && turn !== void 0) interim.delivered.add(turn, key);
252
+ if (files !== void 0 && files.files.length > 0) await review.sendFiles({
253
+ principal: context.session?.auth.current,
254
+ sessionId: context.session?.id ?? "",
255
+ turnId,
256
+ partId: event.data.partId,
257
+ files
258
+ });
259
+ };
260
+ }
261
+ const deliverUnlessSilent = replyDelivery();
262
+ export { withCaptions as _, isNoReplyCall as a, CAPTION_LIMIT as c, attachToReply as d, checkReplyFiles as f, turnFiles as g, partFiles as h, interimTexts as i, DRAFT_FILES_LIMIT as l, filesAfterReply as m, completionKind as n, isSilentReply as o, fileGroups as p, deliverUnlessSilent as r, replyDelivery as s, INTERIM_TURNS as t, ReplyFilesRefused as u };
@@ -6,6 +6,7 @@ __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { channelOf } from "../config.mjs";
8
8
  import segmentstream from "../extension.mjs";
9
+ import { replyFilesSender } from "../lib/attachments-dispatch.mjs";
9
10
  import { segmentstreamEmail } from "../lib/email/channel.mjs";
10
11
  import { decide } from "eve/ai";
11
12
  var email_default = segmentstreamEmail({
@@ -15,7 +16,8 @@ var email_default = segmentstreamEmail({
15
16
  review: {
16
17
  settings: () => segmentstream.config.review,
17
18
  decide: (options) => decide(options),
18
- model: () => segmentstream.config.models.decision
19
+ model: () => segmentstream.config.models.decision,
20
+ sendFiles: replyFilesSender(() => segmentstream.config.channels)
19
21
  }
20
22
  });
21
23
  export { email_default as default };
@@ -6,6 +6,7 @@ __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { channelOf } from "../config.mjs";
8
8
  import segmentstream from "../extension.mjs";
9
+ import { replyFilesSender } from "../lib/attachments-dispatch.mjs";
9
10
  import { segmentstreamSlack } from "../lib/slack/adapter.mjs";
10
11
  import { decide } from "eve/ai";
11
12
  var slack_default = segmentstreamSlack({
@@ -17,7 +18,8 @@ var slack_default = segmentstreamSlack({
17
18
  review: {
18
19
  settings: () => segmentstream.config.review,
19
20
  decide: (options) => decide(options),
20
- model: () => segmentstream.config.models.decision
21
+ model: () => segmentstream.config.models.decision,
22
+ sendFiles: replyFilesSender(() => segmentstream.config.channels)
21
23
  }
22
24
  });
23
25
  export { slack_default as default };
@@ -6,6 +6,7 @@ __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { channelOf } from "../config.mjs";
8
8
  import segmentstream from "../extension.mjs";
9
+ import { replyFilesSender } from "../lib/attachments-dispatch.mjs";
9
10
  import { segmentstreamTelegram } from "../lib/telegram/adapter.mjs";
10
11
  import { decide } from "eve/ai";
11
12
  var telegram_default = segmentstreamTelegram({
@@ -19,7 +20,8 @@ var telegram_default = segmentstreamTelegram({
19
20
  decide: (options) => decide(options),
20
21
  review: {
21
22
  settings: () => segmentstream.config.review,
22
- decide: (options) => decide(options)
23
+ decide: (options) => decide(options),
24
+ sendFiles: replyFilesSender(() => segmentstream.config.channels)
23
25
  }
24
26
  });
25
27
  export { telegram_default as default };
@@ -6,6 +6,7 @@ __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { channelOf } from "../config.mjs";
8
8
  import segmentstream from "../extension.mjs";
9
+ import { replyFilesSender } from "../lib/attachments-dispatch.mjs";
9
10
  import { segmentstreamWhatsApp } from "../lib/whatsapp/adapter.mjs";
10
11
  import { decide } from "eve/ai";
11
12
  var whatsapp_default = segmentstreamWhatsApp({
@@ -16,7 +17,8 @@ var whatsapp_default = segmentstreamWhatsApp({
16
17
  review: {
17
18
  settings: () => segmentstream.config.review,
18
19
  decide: (options) => decide(options),
19
- model: () => segmentstream.config.models.decision
20
+ model: () => segmentstream.config.models.decision,
21
+ sendFiles: replyFilesSender(() => segmentstream.config.channels)
20
22
  }
21
23
  });
22
24
  export { whatsapp_default as default };
@@ -0,0 +1,23 @@
1
+ import type { SessionAuthContext } from "eve/context";
2
+ import type { SendReplyFiles } from "./review/reply.js";
3
+ import { type SendAttachmentsInput } from "./telegram/attachments-send.js";
4
+ /**
5
+ * Sends stored files in the turn's chat through the channel the chat is on: its bot, app, number
6
+ * or mailbox, by that channel's own sender. `attachments_send` sends this way outside reviewed
7
+ * chats, and a reviewed chat's reply sends its files this way once the judge passed it.
8
+ */
9
+ export declare function sendStoredFiles(input: {
10
+ readonly channels: Readonly<Record<string, unknown>> | null | undefined;
11
+ readonly files: SendAttachmentsInput;
12
+ readonly principal: SessionAuthContext | null;
13
+ readonly sessionId: string;
14
+ readonly turnId: string | null;
15
+ /** Names the send in an email thread, so one run again finds the reply it sent. */
16
+ readonly callId: string;
17
+ }): Promise<unknown>;
18
+ /**
19
+ * The sender of a reviewed chat's passed reply's files, through the channel the chat is on, with
20
+ * their calls' captions when they fit one caption: a failure is logged, as the reply's text was
21
+ * already sent.
22
+ */
23
+ export declare function replyFilesSender(channels: () => Readonly<Record<string, unknown>> | null | undefined): SendReplyFiles;
@@ -0,0 +1,79 @@
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 { channelOf } from "../config.mjs";
8
+ import { Ft as chatAddressOf, It as chatChannel } from "../../_chunks/principal-C1g8wCIg.mjs";
9
+ import "../../_chunks/silent-C9x3GcMg.mjs";
10
+ import { sendEmailAttachments } from "./email/attachments-send.mjs";
11
+ import { replyCopies } from "./email/channel.mjs";
12
+ import { sendSlackAttachments } from "./slack/attachments-send.mjs";
13
+ import { sendAttachments } from "./telegram/attachments-send.mjs";
14
+ import { sendWhatsAppAttachments } from "./whatsapp/attachments-send.mjs";
15
+ import { sendChannelAttachments } from "./workspace-channel/attachments-send.mjs";
16
+ async function sendStoredFiles(input) {
17
+ const { channels, principal } = input;
18
+ const chat = chatAddressOf(principal);
19
+ const provider = chat?.provider;
20
+ const name = chat === void 0 ? "telegram" : chatChannel(chat);
21
+ const options = {
22
+ input: input.files,
23
+ principal,
24
+ sessionId: input.sessionId
25
+ };
26
+ if (provider === "slack") return sendSlackAttachments({
27
+ ...options,
28
+ connection: channelOf(channels, "slack", name)?.connection
29
+ });
30
+ if (provider === "email") return sendEmailAttachments({
31
+ ...options,
32
+ callId: input.callId,
33
+ connection: channelOf(channels, "email", name)?.connection,
34
+ cc: replyCopies(principal, channelOf(channels, "email", name))
35
+ });
36
+ if (provider === "whatsapp") return sendWhatsAppAttachments({
37
+ ...options,
38
+ turnId: input.turnId,
39
+ connection: channelOf(channels, "whatsapp", name)?.connection
40
+ });
41
+ if (provider === "custom") return sendChannelAttachments({
42
+ ...options,
43
+ connection: channelOf(channels, "custom", name)?.connection
44
+ });
45
+ const telegram = channelOf(channels, "telegram", name);
46
+ return sendAttachments({
47
+ ...options,
48
+ connection: telegram?.connection,
49
+ appLinks: telegram,
50
+ identifiers: telegram?.identifiers ?? "block"
51
+ });
52
+ }
53
+ function replyFilesSender(channels) {
54
+ return async (input) => {
55
+ const caption = input.files.captions.join("\n\n");
56
+ const result = await sendStoredFiles({
57
+ channels: channels(),
58
+ files: {
59
+ documentIds: input.files.files.map((file) => ({
60
+ entity: file.entity,
61
+ id: file.id,
62
+ property: file.property
63
+ })),
64
+ ...caption === "" || caption.length > 1024 ? {} : { caption }
65
+ },
66
+ principal: input.principal ?? null,
67
+ sessionId: input.sessionId,
68
+ turnId: input.turnId,
69
+ callId: `${input.partId}:files`
70
+ });
71
+ const files = result.files;
72
+ if (typeof result.error === "string" || files?.some((file) => file.error !== void 0) === true) console.error("[segmentstream] a passed reply's files were not all sent", {
73
+ sessionId: input.sessionId,
74
+ result
75
+ });
76
+ return result;
77
+ };
78
+ }
79
+ export { replyFilesSender, sendStoredFiles };
@@ -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-CFe-5i6d.mjs";
7
+ export { t as agentBuild } from "../../_chunks/build-metadata-oZ48LO3j.mjs";
@@ -11,7 +11,7 @@ import { revisionOf } from "./review/revision.mjs";
11
11
  import { Bt as participantsOf, Ft as chatAddressOf, It as chatChannel, i as memberIdOf, ot as guestIdOf } from "../../_chunks/principal-C1g8wCIg.mjs";
12
12
  import { keyChannel, principalChannel } from "./channel-scope.mjs";
13
13
  import { parseAddress } from "./telegram/sessions.mjs";
14
- import { completionKind } from "./telegram/silent.mjs";
14
+ import { n as completionKind } from "../../_chunks/silent-C9x3GcMg.mjs";
15
15
  import { recordModelServiceAlert } from "./model-service-alert.mjs";
16
16
  import { call, deliveries } from "eve/events";
17
17
  function isTelegram(context) {
@@ -57,6 +57,8 @@ export interface EmailChannelOptions {
57
57
  /** Tests pass an archive and a hold in place of the ontology's. */
58
58
  readonly archive?: ChatArchive;
59
59
  readonly hold?: Parameters<typeof channelReview>[0]["hold"];
60
+ /** Sends a passed reply's files; without it such a reply is held. */
61
+ readonly sendFiles?: Parameters<typeof channelReview>[0]["sendFiles"];
60
62
  };
61
63
  readonly environment?: Environment;
62
64
  readonly token?: RuntimeToken;
@@ -21,7 +21,7 @@ import { gatewayMediaCapabilities, turnMediaPlan } from "../inbound-media/plan.m
21
21
  import { gatewayImageDescriber } from "../inbound-media/images.mjs";
22
22
  import { gatewayTranscriber } from "../inbound-media/speech.mjs";
23
23
  import { channelReview } from "../review/reply.mjs";
24
- import { completionKind } from "../telegram/silent.mjs";
24
+ import { g as turnFiles, n as completionKind } from "../../../_chunks/silent-C9x3GcMg.mjs";
25
25
  import { runtimeToken } from "../runtime-token.mjs";
26
26
  import { GMAIL_ID, GmailError, gmail, replyKeyOf } from "./gmail.mjs";
27
27
  import { inboundMail, parseMail, sentMail } from "./message.mjs";
@@ -231,7 +231,8 @@ function emailChannelDefinition(options) {
231
231
  decide: options.review.decide,
232
232
  model: options.review.model,
233
233
  ...options.review.archive === void 0 ? {} : { archive: options.review.archive },
234
- ...options.review.hold === void 0 ? {} : { hold: options.review.hold }
234
+ ...options.review.hold === void 0 ? {} : { hold: options.review.hold },
235
+ ...options.review.sendFiles === void 0 ? {} : { sendFiles: options.review.sendFiles }
235
236
  }, {
236
237
  environment,
237
238
  ...transport
@@ -947,9 +948,22 @@ function emailChannelDefinition(options) {
947
948
  const chat = chatAddressOf(principal);
948
949
  if (outcome !== "completed" || chat?.provider !== "email" || chat.peer === void 0) return;
949
950
  const text = replyText(ctx.view, turnId);
950
- if (completionKind(text) !== "reply") return;
951
951
  const cc = replyCopies(principal, settings());
952
952
  const reviewing = review()?.review;
953
+ const files = reviewing === void 0 ? void 0 : turnFiles(ctx.view, turnId);
954
+ if (completionKind(text) !== "reply") {
955
+ if (files !== void 0 && files.files.length > 0 && reviewing.reviewed(principal)) await reviewing.holdFiles({
956
+ principal,
957
+ sessionId: ctx.session.id,
958
+ turnId,
959
+ files,
960
+ recipients: {
961
+ to: [chat.peer],
962
+ cc
963
+ }
964
+ });
965
+ return;
966
+ }
953
967
  if (!(reviewing === void 0 ? true : await reviewing.sendOrHold({
954
968
  principal,
955
969
  sessionId: ctx.session.id,
@@ -959,7 +973,8 @@ function emailChannelDefinition(options) {
959
973
  recipients: {
960
974
  to: [chat.peer],
961
975
  cc
962
- }
976
+ },
977
+ ...files === void 0 || files.files.length === 0 ? {} : { files }
963
978
  }))) return;
964
979
  const memberId = memberIdOf(principal);
965
980
  const participantIds = participantsOf(principal) ?? (memberId === void 0 ? [] : [memberId]);
@@ -976,7 +991,26 @@ function emailChannelDefinition(options) {
976
991
  at: new Date(now()).toISOString()
977
992
  };
978
993
  await record(reply, "requested");
979
- await send(reply, REPLY_ATTEMPTS);
994
+ const sent = await send(reply, REPLY_ATTEMPTS);
995
+ if (files !== void 0 && files.files.length > 0) {
996
+ if (sent === "sent") await reviewing.sendFiles({
997
+ principal,
998
+ sessionId: ctx.session.id,
999
+ turnId,
1000
+ partId: turnId,
1001
+ files
1002
+ });
1003
+ else await reviewing.holdFiles({
1004
+ principal,
1005
+ sessionId: ctx.session.id,
1006
+ turnId,
1007
+ files,
1008
+ recipients: {
1009
+ to: [chat.peer],
1010
+ cc
1011
+ }
1012
+ });
1013
+ }
980
1014
  } });
981
1015
  return {
982
1016
  routes: withNamedRoutes("email", [POST(EMAIL_ROUTE, wake)], (name) => {
@@ -4,4 +4,6 @@
4
4
  * agent's own bundle never loads them.
5
5
  */
6
6
  export { defineEval, defineEvalConfig } from "eve/evals";
7
- export type { EveEval, EveEvalConfig, EveEvalContext, EveEvalDefinition } from "eve/evals";
7
+ export type { Assertion, EveEval, EveEvalConfig, EveEvalContext, EveEvalDefinition, } from "eve/evals";
8
+ /** The value assertions `t.check(value, assertion)` and `t.require` apply. */
9
+ export { equals, includes, matches, satisfies, similarity } from "eve/evals/expect";
@@ -4,4 +4,6 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
- export { defineEval, defineEvalConfig } from "eve/evals";
7
+ import { defineEval, defineEvalConfig } from "eve/evals";
8
+ import { equals, includes, matches, satisfies, similarity } from "eve/evals/expect";
9
+ export { defineEval, defineEvalConfig, equals, includes, matches, satisfies, similarity };
@@ -44,6 +44,11 @@ function agentReviews(input) {
44
44
  member_id: reply.memberId,
45
45
  session_id: reply.sessionId,
46
46
  text: reply.text,
47
+ ...reply.files === void 0 ? {} : { files: reply.files.map((file) => ({
48
+ entity: file.entity,
49
+ id: file.id,
50
+ property: file.property
51
+ })) },
47
52
  mode: reply.mode,
48
53
  confidence: reply.confidence,
49
54
  ...named.turnId === void 0 ? {} : { turn_id: named.turnId }