@segmentstream/agent 0.47.0 → 0.50.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.
Files changed (93) hide show
  1. package/CHANGELOG.md +75 -0
  2. package/README.md +14 -15
  3. package/dist/_chunks/{build-metadata-5S6uTvyu.mjs → build-metadata-DrQtDIMX.mjs} +1 -1
  4. package/dist/_chunks/principal-D5Tualrk.mjs +1836 -0
  5. package/dist/extension/channels/slack.mjs +2 -1
  6. package/dist/extension/channels/whatsapp.mjs +1 -0
  7. package/dist/extension/connections/ontology.mjs +1 -1
  8. package/dist/extension/hooks/authorization.mjs +1 -1
  9. package/dist/extension/instructions/persona.mjs +1 -1
  10. package/dist/extension/lib/actor.mjs +1 -46
  11. package/dist/extension/lib/attachment-tools.mjs +1 -3
  12. package/dist/extension/lib/attachments.d.ts +1 -1
  13. package/dist/extension/lib/attachments.mjs +1 -230
  14. package/dist/extension/lib/build-metadata.mjs +1 -1
  15. package/dist/extension/lib/chat-address.mjs +1 -50
  16. package/dist/extension/lib/chat-context.mjs +1 -1
  17. package/dist/extension/lib/chat-recorder.mjs +1 -2
  18. package/dist/extension/lib/confirmations.mjs +1 -179
  19. package/dist/extension/lib/inbound-media/files.d.ts +91 -0
  20. package/dist/extension/lib/inbound-media/files.mjs +7 -0
  21. package/dist/extension/lib/{telegram → inbound-media}/images.d.ts +2 -0
  22. package/dist/extension/lib/{telegram → inbound-media}/images.mjs +1 -2
  23. package/dist/extension/lib/inbound-media/index.d.ts +55 -0
  24. package/dist/extension/lib/inbound-media/index.mjs +7 -0
  25. package/dist/extension/lib/inbound-media/plan.d.ts +59 -0
  26. package/dist/extension/lib/{telegram/media-policy.mjs → inbound-media/plan.mjs} +56 -4
  27. package/dist/extension/lib/inbound-media/report.d.ts +5 -0
  28. package/dist/extension/lib/inbound-media/report.mjs +7 -0
  29. package/dist/extension/lib/inbound-media/speech.d.ts +52 -0
  30. package/dist/extension/lib/inbound-media/speech.mjs +73 -0
  31. package/dist/extension/lib/ontology-connection.mjs +1 -101
  32. package/dist/extension/lib/ontology-file-call.mjs +1 -4
  33. package/dist/extension/lib/ontology-tools.mjs +1 -377
  34. package/dist/extension/lib/review/hold.mjs +1 -2
  35. package/dist/extension/lib/review/reply.mjs +1 -2
  36. package/dist/extension/lib/role-skill.mjs +1 -1
  37. package/dist/extension/lib/runtime-envelope.mjs +1 -1
  38. package/dist/extension/lib/sent-files.mjs +1 -2
  39. package/dist/extension/lib/slack/adapter.d.ts +49 -7
  40. package/dist/extension/lib/slack/adapter.mjs +79 -21
  41. package/dist/extension/lib/slack/attachments-send.mjs +1 -3
  42. package/dist/extension/lib/slack/files.d.ts +12 -19
  43. package/dist/extension/lib/slack/files.mjs +26 -58
  44. package/dist/extension/lib/stored-files.mjs +1 -3
  45. package/dist/extension/lib/telegram/adapter.d.ts +3 -3
  46. package/dist/extension/lib/telegram/adapter.mjs +13 -17
  47. package/dist/extension/lib/telegram/attachment-description.d.ts +1 -1
  48. package/dist/extension/lib/telegram/attachment-description.mjs +2 -2
  49. package/dist/extension/lib/telegram/attachments-send.mjs +1 -3
  50. package/dist/extension/lib/telegram/callbacks.mjs +1 -2
  51. package/dist/extension/lib/telegram/chat-archive.mjs +1 -1
  52. package/dist/extension/lib/telegram/confirmations.mjs +1 -3
  53. package/dist/extension/lib/telegram/customer-text.mjs +1 -1
  54. package/dist/extension/lib/telegram/files.d.ts +8 -15
  55. package/dist/extension/lib/telegram/files.mjs +32 -107
  56. package/dist/extension/lib/telegram/health.mjs +1 -1
  57. package/dist/extension/lib/telegram/held-approvals.mjs +1 -1
  58. package/dist/extension/lib/telegram/inbound-request.d.ts +6 -12
  59. package/dist/extension/lib/telegram/inbound-request.mjs +1 -1
  60. package/dist/extension/lib/telegram/inbound.d.ts +3 -3
  61. package/dist/extension/lib/telegram/inbound.mjs +11 -11
  62. package/dist/extension/lib/telegram/lifecycle.mjs +2 -6
  63. package/dist/extension/lib/telegram/principal.mjs +1 -1
  64. package/dist/extension/lib/telegram/session-recovery.mjs +1 -1
  65. package/dist/extension/lib/telegram/silent.mjs +1 -1
  66. package/dist/extension/lib/telegram/structured.mjs +1 -1
  67. package/dist/extension/lib/telegram/turn-errors.mjs +1 -2
  68. package/dist/extension/lib/telegram/voice.d.ts +7 -38
  69. package/dist/extension/lib/telegram/voice.mjs +1 -64
  70. package/dist/extension/lib/telegram/workspace-action.mjs +1 -3
  71. package/dist/extension/lib/web/auth.d.ts +27 -4
  72. package/dist/extension/lib/web/auth.mjs +1 -124
  73. package/dist/extension/lib/web/channel.d.ts +13 -4
  74. package/dist/extension/lib/web/channel.mjs +15 -8
  75. package/dist/extension/lib/whatsapp/adapter.d.ts +37 -1
  76. package/dist/extension/lib/whatsapp/adapter.mjs +118 -21
  77. package/dist/extension/lib/whatsapp/files.d.ts +40 -0
  78. package/dist/extension/lib/whatsapp/files.mjs +70 -0
  79. package/dist/extension/lib/workspace-source.mjs +1 -3
  80. package/dist/extension/model.mjs +1 -1
  81. package/dist/extension/tools/attachments_discard.mjs +1 -1
  82. package/dist/extension/tools/attachments_list.mjs +1 -1
  83. package/dist/extension/tools/attachments_promote.mjs +1 -5
  84. package/dist/extension/tools/attachments_read.mjs +1 -1
  85. package/dist/extension/tools/attachments_send.mjs +1 -2
  86. package/dist/extension/tools/attachments_stage.mjs +1 -1
  87. package/dist/extension/tools/attachments_table.mjs +1 -1
  88. package/dist/extension/tools/questions_ask.mjs +1 -2
  89. package/dist/extension/tools/workspace_source.mjs +1 -1
  90. package/package.json +2 -2
  91. package/dist/_chunks/inbound-request-B3RhCuOw.mjs +0 -413
  92. package/dist/_chunks/principal-Dzs8hUDB.mjs +0 -128
  93. package/dist/extension/lib/telegram/media-policy.d.ts +0 -15
@@ -4,380 +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
- import { c as compatibleRuntimeEnvelope, s as RUNTIME_SOURCE_PROTOCOL, u as runtimeEnvelope } from "../../_chunks/principal-Dzs8hUDB.mjs";
8
- import "./agent-task.mjs";
9
- import { actorHeaders, actorKey, actorOf } from "./actor.mjs";
10
- import { CONFIRMATION_FACTS, CONFIRMATION_PREVIEW_METHOD, ConfirmationRefused, confirmationCard, describeConfirmation, factsConfirmation, object } from "./confirmation-description.mjs";
11
- import { appOrigin } from "./environment.mjs";
12
- import { redactDiagnostic } from "./diagnostics.mjs";
13
- import { runtimeToken } from "./runtime-token.mjs";
14
- import { describeChatPost, isChatPost, supportsChatPost } from "./chat-post-confirmation.mjs";
15
- import { randomUUID } from "node:crypto";
16
- function rejection(error) {
17
- let cause = error.cause;
18
- for (let depth = 0; depth < 4 && cause !== void 0; depth++) {
19
- const code = object(object(cause).structuredContent).error;
20
- if (typeof code === "string") return code;
21
- cause = object(cause).cause;
22
- }
23
- return "";
24
- }
25
- const REFUSALS = new Set([
26
- "action_rejected",
27
- "not_found",
28
- "conflict",
29
- "forbidden"
30
- ]);
31
- var OntologyToolRejected = class extends Error {
32
- code = "ontology_tool_rejected";
33
- };
34
- var OntologyActionNotPermitted = class extends Error {
35
- code = "ontology_action_not_permitted";
36
- };
37
- var OntologyFileUnavailable = class extends Error {
38
- code;
39
- requestId;
40
- retryable = true;
41
- constructor(code, requestId, options) {
42
- super(`${code}${requestId === void 0 ? "" : ` (${requestId})`}`, options);
43
- this.code = code;
44
- this.requestId = requestId;
45
- }
46
- };
47
- function ontologyTools(options = {}) {
48
- const runtimeSources = options.runtimeSources ?? new Map();
49
- const initialized = new Map();
50
- const definitions = new Map();
51
- async function post(actor, method, params, credential, secrets, signal) {
52
- const key = actorKey(actor);
53
- const current = actorOf(options.principal);
54
- const own = current !== void 0 && actorKey(current) === key ? options.principal : null;
55
- const acting = actorHeaders({
56
- actor,
57
- principal: own,
58
- secret: options.secret
59
- });
60
- secrets.add(acting["X-SegmentStream-Agent-Task"] ?? "");
61
- const response = await (options.fetch ?? fetch)(`${appOrigin(options.environment ?? process.env)}/mcp`, {
62
- method: "POST",
63
- headers: {
64
- authorization: `Bearer ${credential}`,
65
- ...acting,
66
- "content-type": "application/json",
67
- accept: "application/json, text/event-stream",
68
- "mcp-protocol-version": "2025-11-25"
69
- },
70
- body: JSON.stringify({
71
- jsonrpc: "2.0",
72
- id: "approval-tools",
73
- method,
74
- params
75
- }),
76
- signal: signal ?? AbortSignal.timeout(15e3),
77
- redirect: "error"
78
- });
79
- if (!response.ok) throw Object.assign(new Error(`Cannot check action permission (HTTP ${response.status}).`, { cause: await response.text() }), { status: response.status });
80
- const body = object(await response.json());
81
- if (body.error !== void 0) throw new Error("Ontology metadata unavailable.", { cause: body.error });
82
- return object(body.result);
83
- }
84
- async function quiet(actor, method, params, signal) {
85
- const secrets = new Set();
86
- try {
87
- const credential = await (options.token ?? runtimeToken)();
88
- secrets.add(credential);
89
- return await post(actor, method, params, credential, secrets, signal);
90
- } catch (error) {
91
- console.warn("[segmentstream] ontology_metadata_fallback", {
92
- method,
93
- error: redactDiagnostic(error, secrets)
94
- });
95
- return;
96
- }
97
- }
98
- async function rpc(actor, method, params, signal) {
99
- const key = actorKey(actor);
100
- const current = actorOf(options.principal);
101
- const own = current !== void 0 && actorKey(current) === key ? options.principal : null;
102
- if (method === "tools/call") {
103
- const envelope = options.envelope ?? runtimeEnvelope({ principal: own });
104
- const extended = envelope.source !== void 0 && await runtimeSource(actor, signal);
105
- params = {
106
- ...params,
107
- arguments: {
108
- ...object(params.arguments),
109
- _segmentstream: compatibleRuntimeEnvelope(envelope, extended)
110
- }
111
- };
112
- }
113
- const credential = await (options.token ?? runtimeToken)();
114
- const secrets = new Set([credential]);
115
- if (method === "tools/call") await options.beforeCall?.(String(params.name));
116
- try {
117
- const result = await post(actor, method, params, credential, secrets, signal);
118
- if (method === "tools/list" && Array.isArray(result.tools)) runtimeSources.set(key, result.tools.map(object).some((tool) => object(tool._meta)[RUNTIME_SOURCE_PROTOCOL] === 1));
119
- if (result.isError === true) {
120
- const failure = object(result.structuredContent);
121
- if (method === "tools/call" && params.name === "files_download" && failure.retryable === true && ["ontology_updating", "storage_unavailable"].includes(String(failure.error))) throw new OntologyFileUnavailable(String(failure.error), typeof failure.request_id === "string" ? failure.request_id : void 0, { cause: result });
122
- const message = (Array.isArray(result.content) ? result.content : []).map(object).filter((part) => part.type === "text" && typeof part.text === "string").map((part) => part.text).join("\n");
123
- if ([
124
- "action_rejected",
125
- "invalid_input",
126
- "invalid_request",
127
- "invalid_json",
128
- "unsupported_media_type",
129
- "forbidden",
130
- "unauthorized",
131
- "not_invited",
132
- "not_found",
133
- "conflict",
134
- "invalid_cursor",
135
- "ontology_version_mismatch",
136
- "discovery_too_large"
137
- ].includes(String(object(result.structuredContent).error))) throw new OntologyToolRejected(message || "ontology_operation_rejected", { cause: result });
138
- throw new Error("ontology_action_outcome_uncertain", { cause: result });
139
- }
140
- return result;
141
- } catch (error) {
142
- const diagnostic = redactDiagnostic(error, secrets);
143
- const reference = randomUUID();
144
- console.error("[segmentstream] ontology_request_failed", {
145
- reference,
146
- error: diagnostic
147
- });
148
- if (error instanceof OntologyFileUnavailable) throw new OntologyFileUnavailable(error.code, error.requestId, { cause: diagnostic });
149
- if (error instanceof OntologyToolRejected) throw new OntologyToolRejected(String(object(diagnostic).message), { cause: diagnostic });
150
- throw new Error(`The ontology request failed (${reference}).`, { cause: diagnostic });
151
- }
152
- }
153
- function initialize(actor, signal) {
154
- const key = actorKey(actor);
155
- let pending = initialized.get(key);
156
- if (pending === void 0) {
157
- pending = quiet(actor, "initialize", {
158
- protocolVersion: "2025-11-25",
159
- capabilities: {},
160
- clientInfo: {
161
- name: "segmentstream-agent",
162
- version: "1"
163
- }
164
- }, signal);
165
- initialized.set(key, pending);
166
- }
167
- return pending;
168
- }
169
- async function advertises(actor, capability, signal) {
170
- const result = await initialize(actor, signal);
171
- return object(object(result?.capabilities).experimental)[capability] !== void 0;
172
- }
173
- async function runtimeSource(actor, signal) {
174
- const key = actorKey(actor);
175
- if (!runtimeSources.has(key)) {
176
- if (await advertises(actor, "segmentstream/runtime-source", signal)) runtimeSources.set(key, true);
177
- else await rpc(actor, "tools/list", {}, signal);
178
- }
179
- return runtimeSources.get(key) === true;
180
- }
181
- async function toolFor(actor, action, signal) {
182
- const result = await rpc(actor, "tools/list", {}, signal);
183
- const tools = Array.isArray(result.tools) ? result.tools.map(object) : [];
184
- const bareName = action.split("__").at(-1);
185
- let tool = tools.find((candidate) => candidate.name === bareName);
186
- if (tool === void 0 && tools.some((item) => item.name === "ontology_describe_tool")) {
187
- const inspected = await rpc(actor, "tools/call", {
188
- name: "ontology_describe_tool",
189
- arguments: { name: bareName }
190
- }, signal);
191
- const candidate = object(object(inspected.structuredContent).tool);
192
- if (candidate.name === bareName) tool = candidate;
193
- }
194
- if (tool === void 0) throw new OntologyActionNotPermitted("Action not permitted.");
195
- return {
196
- tool,
197
- tools
198
- };
199
- }
200
- async function listed(actor, name, signal) {
201
- const result = await quiet(actor, "resources/read", { uri: `ontology://tools/${encodeURIComponent(name)}` }, signal);
202
- const text = object(Array.isArray(result?.contents) ? result.contents[0] : void 0).text;
203
- try {
204
- const tool = object(typeof text === "string" ? JSON.parse(text) : void 0);
205
- return tool.name === name ? tool : void 0;
206
- } catch {
207
- return;
208
- }
209
- }
210
- function definition(actor, action, signal) {
211
- const bareName = action.split("__").at(-1) ?? action;
212
- const key = `${actorKey(actor)} ${bareName}`;
213
- let pending = definitions.get(key);
214
- if (pending === void 0) {
215
- pending = listed(actor, bareName, signal).then(async (tool) => tool === void 0 ? toolFor(actor, action, signal) : { tool });
216
- definitions.set(key, pending);
217
- pending.catch(() => definitions.delete(key));
218
- }
219
- return pending;
220
- }
221
- async function resolve(actor, action, input, signal, hints, depth = 0) {
222
- if (depth > 3) throw new Error("Too many nested ontology tools.");
223
- const bareName = action.split("__").at(-1);
224
- if (bareName === "attachments_promote") {
225
- const target = promotionTarget(input);
226
- return resolve(actor, target.action, target.input, signal, void 0, depth + 1);
227
- }
228
- const found = depth === 0 && hints?.["segmentstream/confirmation"] !== void 0 ? { tool: {
229
- name: bareName,
230
- annotations: hints
231
- } } : await definition(actor, action, signal);
232
- if (depth > 0 && isChatPost(String(found.tool.name))) throw new Error("Exact chat posting must use the direct chat_post_message tool.");
233
- if (found.tool.name === "ontology_call_tool") {
234
- if (typeof input.name !== "string") throw new Error("A target tool is required.");
235
- return resolve(actor, input.name, object(input.arguments), signal, void 0, depth + 1);
236
- }
237
- return {
238
- ...found,
239
- input
240
- };
241
- }
242
- async function preview(actor, name, input, locale, signal) {
243
- let result;
244
- try {
245
- result = await rpc(actor, CONFIRMATION_PREVIEW_METHOD, {
246
- name,
247
- arguments: input,
248
- locale
249
- }, signal);
250
- } catch (error) {
251
- if (error instanceof OntologyToolRejected && REFUSALS.has(rejection(error))) throw new ConfirmationRefused(error.message);
252
- console.warn("The action's confirmation could not be read; showing its fields.", error);
253
- return;
254
- }
255
- const structured = object(result.structuredContent);
256
- if (structured.confirmation === null || structured.confirmation === void 0) return;
257
- try {
258
- return confirmationCard(structured.confirmation);
259
- } catch (error) {
260
- console.warn("The action's confirmation cannot be shown; showing its fields.", error);
261
- return;
262
- }
263
- }
264
- async function catalogEntities(actor, signal) {
265
- try {
266
- const catalog = await rpc(actor, "resources/read", { uri: "ontology://catalog" }, signal);
267
- const text = object(Array.isArray(catalog.contents) ? catalog.contents[0] : void 0).text;
268
- const manifest = object(typeof text === "string" ? JSON.parse(text) : void 0);
269
- return Array.isArray(manifest.entities) ? manifest.entities.map(object) : [];
270
- } catch (error) {
271
- console.warn("The confirmation catalog could not be read.", error);
272
- return [];
273
- }
274
- }
275
- return {
276
- rpc,
277
- async supportsRuntimeSource(actor, signal) {
278
- return runtimeSource(actor, signal);
279
- },
280
- async labels(actor, action, input = {}, signal, hints) {
281
- const { tool } = await resolve(actor, action, input, signal, hints);
282
- const annotations = object(tool.annotations);
283
- return {
284
- ...Object.fromEntries(Object.entries(annotations).filter(([key]) => key !== CONFIRMATION_FACTS)),
285
- confirmation: annotations["segmentstream/confirmation"] !== void 0 || object(object(tool.inputSchema).properties)._confirmation !== void 0,
286
- ...object(annotations["segmentstream/confirmation"]).preview === true ? { preview: true } : {}
287
- };
288
- },
289
- async describe(actor, action, input, hints, locale = "en") {
290
- const signal = AbortSignal.timeout(15e3);
291
- const resolved = await resolve(actor, action, input, signal, hints);
292
- const { tool } = resolved;
293
- input = resolved.input;
294
- action = String(tool.name);
295
- if (isChatPost(action)) {
296
- if (!supportsChatPost(tool)) throw new Error("The ontology does not support exact chat confirmations.");
297
- const read = async (name, args) => {
298
- if (resolved.tools !== void 0 && !resolved.tools.some((candidate) => candidate.name === name && object(candidate.annotations).readOnlyHint === true)) throw new Error("The chat preview reads are unavailable.");
299
- const result = await rpc(actor, "tools/call", {
300
- name,
301
- arguments: args
302
- }, signal);
303
- if (result.isError === true) throw new Error("The chat preview could not be resolved.");
304
- return object(result.structuredContent);
305
- };
306
- const [caller, destinations] = await Promise.all([read("me", {}), read("chat_list", { chat: input.chat })]);
307
- return {
308
- ...describeChatPost({
309
- values: input,
310
- caller,
311
- destinations
312
- }),
313
- action: typeof tool.title === "string" ? tool.title : typeof tool.description === "string" ? tool.description.split("\n\n")[0] : ""
314
- };
315
- }
316
- async function read(entityName, id) {
317
- const name = actionToolName(entityName, "get");
318
- try {
319
- const result = await rpc(actor, "tools/call", {
320
- name,
321
- arguments: { id }
322
- }, signal);
323
- return result.isError === true ? void 0 : object(result.structuredContent);
324
- } catch (error) {
325
- console.warn("A confirmation record title could not be read.", error);
326
- return;
327
- }
328
- }
329
- const facts = object(tool.annotations)[CONFIRMATION_FACTS];
330
- const card = object(facts).preview === true ? await preview(actor, String(tool.name), input, locale, signal) : void 0;
331
- if (card !== void 0) return {
332
- card,
333
- action: card.title,
334
- fields: []
335
- };
336
- if (facts !== void 0) return describeConfirmation({
337
- ...factsConfirmation(object(facts)),
338
- values: input,
339
- read
340
- });
341
- const entities = await catalogEntities(actor, signal);
342
- const entity = entities.find((candidate) => {
343
- return [
344
- "create",
345
- "update",
346
- "delete",
347
- "link",
348
- "unlink",
349
- ...Array.isArray(candidate.actions) ? candidate.actions.map((item) => object(item).name) : []
350
- ].some((name) => typeof name === "string" && actionToolName(String(candidate.name), name) === tool.name);
351
- });
352
- return describeConfirmation({
353
- title: typeof tool.title === "string" ? tool.title : void 0,
354
- description: typeof tool.description === "string" ? tool.description : void 0,
355
- schema: object(tool.inputSchema),
356
- entity,
357
- entities,
358
- values: input,
359
- read
360
- });
361
- }
362
- };
363
- }
364
- function ontologyToolLabels(options = {}) {
365
- return ontologyTools(options).labels;
366
- }
367
- function actionToolName(entity, action) {
368
- const snake = (name) => name.replace(/([A-Z])([A-Z][a-z])/g, "$1_$2").replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase();
369
- return `${snake(entity)}_${snake(action)}`;
370
- }
371
- function promotionTarget(input) {
372
- const entity = input.entity;
373
- const action = input.action;
374
- if (typeof entity !== "string" || typeof action !== "string" || !/^(?:[a-z][a-zA-Z0-9]*|[a-z][a-z0-9]*(?:_[a-z0-9]+)*)$/.test(entity) || !/^(?:[a-z][a-zA-Z0-9]*|[a-z][a-z0-9]*(?:_[a-z0-9]+)*)$/.test(action)) throw new Error("A valid attachment target entity and action are required.");
375
- return {
376
- action: actionToolName(entity, action),
377
- input: {
378
- ...object(input.input),
379
- ...typeof input.record_id === "string" ? { id: input.record_id } : {}
380
- }
381
- };
382
- }
383
- export { OntologyActionNotPermitted, OntologyFileUnavailable, OntologyToolRejected, actionToolName, ontologyToolLabels, ontologyTools, promotionTarget };
7
+ export { D as OntologyActionNotPermitted, O as OntologyFileUnavailable, k as OntologyToolRejected, A as actionToolName, j as ontologyToolLabels, M as ontologyTools, N as promotionTarget } from "../../_chunks/principal-D5Tualrk.mjs";
@@ -5,8 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { reviewFor } from "../../review.mjs";
8
- import { chatAddressOf } from "../chat-address.mjs";
9
- import { a as rolesOf, i as memberIdOf } from "../../../_chunks/principal-Dzs8hUDB.mjs";
8
+ import { a as rolesOf, i as memberIdOf, ot as chatAddressOf } from "../../../_chunks/principal-D5Tualrk.mjs";
10
9
  function reviewOf(settings, principal) {
11
10
  return reviewFor(settings, rolesOf(principal));
12
11
  }
@@ -4,11 +4,10 @@ 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 { chatAddressOf } from "../chat-address.mjs";
7
+ import { i as memberIdOf, ot as chatAddressOf } from "../../../_chunks/principal-D5Tualrk.mjs";
8
8
  import { chatArchive, chatEvent } from "../chat-archive.mjs";
9
9
  import { appOrigin } from "../environment.mjs";
10
10
  import { agentReviews } from "./client.mjs";
11
- import { i as memberIdOf } from "../../../_chunks/principal-Dzs8hUDB.mjs";
12
11
  import { heldReply, repliesReviewed, reviewOf, reviewOutcome } from "./hold.mjs";
13
12
  import { judgeReply, readChat } from "./judge.mjs";
14
13
  const VERDICTS_REMEMBERED = 512;
@@ -4,7 +4,7 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
- import { a as rolesOf } from "../../_chunks/principal-Dzs8hUDB.mjs";
7
+ import { a as rolesOf } from "../../_chunks/principal-D5Tualrk.mjs";
8
8
  import { defineDynamic, defineSkill } from "eve/skills";
9
9
  function forRoles(roles, skill) {
10
10
  if (!Array.isArray(roles) || roles.length === 0 || !roles.every((role) => typeof role === "string" && role.trim() !== "")) throw new TypeError("forRoles() needs at least one role name; a skill for everyone is an ordinary skill file.");
@@ -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 { s as RUNTIME_SOURCE_PROTOCOL, c as compatibleRuntimeEnvelope, l as principalRuntimeSource, u as runtimeEnvelope, d as telegramRuntimeSource } from "../../_chunks/principal-Dzs8hUDB.mjs";
7
+ export { bt as RUNTIME_SOURCE_PROTOCOL, xt as compatibleRuntimeEnvelope, St as principalRuntimeSource, Ct as runtimeEnvelope, wt as telegramRuntimeSource } from "../../_chunks/principal-D5Tualrk.mjs";
@@ -4,9 +4,8 @@ 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 { AttachmentError, CHAT_HEADER, EARLIER_CHAT_HEADER, SESSION_HEADER } from "./attachments.mjs";
7
+ import { _ as AttachmentError, v as CHAT_HEADER, x as SESSION_HEADER, y as EARLIER_CHAT_HEADER, z as ACT_AS_HEADER } from "../../_chunks/principal-D5Tualrk.mjs";
8
8
  import { fetchFileGrant, transientFileStatus } from "./file-grant.mjs";
9
- import { ACT_AS_HEADER } from "./actor.mjs";
10
9
  var StoredFileError = class extends AttachmentError {
11
10
  filename;
12
11
  requestId;
@@ -1,12 +1,18 @@
1
+ import type { ChannelSource } from "eve/channels";
1
2
  import { type SlackChannel, type SlackInboundMessageContext, type SlackMentionResult, type SlackMessage } from "eve/channels/slack";
2
3
  import type { SessionAuthContext } from "eve/context";
3
- import type { AdmissionSettings, SlackSettings } from "../../config.js";
4
+ import type { SessionReader } from "eve/sessions";
5
+ import type { AdmissionSettings, ChatModelChoice, SlackSettings } from "../../config.js";
4
6
  import type { GroupPolicy } from "../group-routing/policy.js";
5
7
  import { type AgentChats } from "../chats.js";
6
8
  import { type ConnectionProxy } from "../connection-proxy.js";
7
9
  import { type Environment } from "../environment.js";
8
10
  import { type AgentAttachments } from "../attachments.js";
9
11
  import { type AgentIdentities, type PairedMember } from "../identities.js";
12
+ import { type PreparedMedia } from "../inbound-media/index.js";
13
+ import { type ImageDescriber } from "../inbound-media/images.js";
14
+ import { type CapabilityLookup, type MediaPlan } from "../inbound-media/plan.js";
15
+ import { type Transcriber } from "../inbound-media/speech.js";
10
16
  import { type SlackFileDownload } from "./files.js";
11
17
  import { type RuntimeToken } from "../runtime-token.js";
12
18
  /**
@@ -29,6 +35,11 @@ import { type RuntimeToken } from "../runtime-token.js";
29
35
  */
30
36
  /** The authenticator of a Slack session's principal. */
31
37
  export declare const SLACK_AUTHENTICATOR = "segmentstream-slack";
38
+ /** What the pipeline made of a message's files, and which Slack URL names each file's part. */
39
+ export interface SlackTurnMedia {
40
+ readonly media: PreparedMedia;
41
+ readonly keys: ReadonlyMap<string, string>;
42
+ }
32
43
  /** eve sent a request this channel does not route through the proxy. */
33
44
  export declare class SlackProxyRouteError extends Error {
34
45
  readonly name = "SlackProxyRouteError";
@@ -52,6 +63,18 @@ export interface SlackChannelOptions {
52
63
  readonly chats?: AgentChats;
53
64
  /** Where members' files are stored as attachments; tests pass their own. */
54
65
  readonly attachments?: AgentAttachments;
66
+ /**
67
+ * `models` of `agent/segmentstream.json`: `stt` transcribes voice clips, and `chat` with
68
+ * `imageDescription` decides how images reach the model. Without it voice is not transcribed.
69
+ */
70
+ readonly models?: () => {
71
+ readonly stt: string | false;
72
+ readonly chat?: ChatModelChoice | null;
73
+ readonly imageDescription?: string | false | null;
74
+ };
75
+ readonly transcribe?: Transcriber;
76
+ readonly describeImage?: ImageDescriber;
77
+ readonly modelCapabilities?: CapabilityLookup;
55
78
  /** Seconds since the epoch; tests pass a fixed clock. */
56
79
  readonly now?: () => number;
57
80
  }
@@ -109,13 +132,19 @@ export declare function followsThreadReply(input: {
109
132
  readonly message: Pick<SlackMessage, "author" | "ts" | "threadTs">;
110
133
  readonly mode: GroupPolicy["mode"] | undefined;
111
134
  }): Promise<boolean>;
135
+ /**
136
+ * A session source whose `send` delivers the message as the inbound media pipeline left its files:
137
+ * a voice clip's transcript in place of the clip, and an image the chat model does not read
138
+ * natively as its description. Every other file part stays eve's, which downloads it for the turn.
139
+ */
140
+ export declare function withTurnMedia<State>(source: ChannelSource<State>, turn: () => SlackTurnMedia | undefined): ChannelSource<State>;
112
141
  /**
113
142
  * Admits one inbound message: a turn as the paired member who wrote something, or `null` after
114
143
  * privately answering anyone else with the workspace's reply, if it has one.
115
144
  */
116
145
  export declare function receive(input: {
117
- readonly ctx: Pick<SlackInboundMessageContext, "thread" | "edit" | "slack">;
118
- readonly message: Pick<SlackMessage, "author" | "text" | "attachments" | "ts">;
146
+ readonly ctx: Pick<SlackInboundMessageContext, "thread" | "edit" | "slack"> & Partial<Pick<SlackInboundMessageContext, "resolveSession">>;
147
+ readonly message: Pick<SlackMessage, "author" | "text" | "attachments" | "ts"> & Partial<Pick<SlackMessage, "raw">>;
119
148
  readonly direct: boolean;
120
149
  readonly admission: AdmissionSettings;
121
150
  readonly identities: AgentIdentities;
@@ -125,8 +154,21 @@ export declare function receive(input: {
125
154
  /** Keeps the report alive after the turn starts; without it the report is awaited. */
126
155
  readonly waitUntil?: (task: Promise<unknown>) => void;
127
156
  /** Stores the message's files as the member's attachments; without it they are not stored. */
128
- readonly files?: {
129
- readonly attachments: () => AgentAttachments;
130
- readonly download: SlackFileDownload;
131
- };
157
+ readonly files?: SlackFiles;
158
+ /** Receives what the inbound media pipeline made of the files, for the turn's message. */
159
+ readonly turn?: (media: SlackTurnMedia) => void;
132
160
  }): Promise<SlackMentionResult>;
161
+ /** How the Slack channel stores and transcribes a message's files. */
162
+ export interface SlackFiles {
163
+ readonly attachments: () => AgentAttachments;
164
+ readonly download: SlackFileDownload;
165
+ /** `models.stt`; without it, or `false`, voice clips are not transcribed. */
166
+ readonly sttModel?: () => string | false;
167
+ readonly transcribe?: Transcriber;
168
+ /**
169
+ * How the turn's chat model takes images; without it they reach the model as files. The thread's
170
+ * session, when it has one, decides the model; otherwise the member starting it does.
171
+ */
172
+ readonly plan?: (principal: SessionAuthContext, session?: () => Promise<SessionReader | undefined>) => Promise<MediaPlan>;
173
+ readonly describeImage?: ImageDescriber;
174
+ }