@swirls/looms 0.26.0 → 0.27.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.
@@ -4,7 +4,7 @@ import { STRUCTURED_OUTPUT_TOOL_NAME } from './definitions.js';
4
4
  import { callLlmEffect, executeToolEffect } from './effects.js';
5
5
  import { agentModule } from './scope.js';
6
6
  import { closeOpenToolCalls, insertToolResult } from './transcript.js';
7
- import { attachmentsFrom, userLine } from './types.js';
7
+ import { attachmentsField, attachmentsFrom, userLine } from './types.js';
8
8
  function inputToLine(input) {
9
9
  if (input === null) {
10
10
  return null;
@@ -170,11 +170,14 @@ export const agentThread = agentModule.thread({
170
170
  structuredOutput =
171
171
  isJsonObject(result) && 'output' in result ? (result.output ?? null) : result;
172
172
  }
173
+ // A result shaped `{ attachments }` shows those files to the model with the result.
174
+ const files = !error && isJsonObject(result) ? result.attachments : undefined;
173
175
  const lines = insertToolResult(state.lines, {
174
176
  role: 'tool',
175
177
  content,
176
178
  toolCallId,
177
179
  name: name ?? undefined,
180
+ ...attachmentsField(files),
178
181
  });
179
182
  return {
180
183
  ...state,
@@ -1,5 +1,5 @@
1
1
  import { type ModelMessage } from 'ai';
2
- import type { Attachment, Message, ToolCall } from '@swirls/looms/agent';
2
+ import type { AgentRunContext, Attachment, Message, ToolCall } from '@swirls/looms/agent';
3
3
  import type { JsonValue } from '@swirls/looms/core';
4
4
  /** An attachment's bytes (or base64 text), or a URL the model provider can fetch. */
5
5
  export type AttachmentData = Uint8Array | ArrayBuffer | string | URL;
@@ -8,7 +8,7 @@ export type AttachmentData = Uint8Array | ArrayBuffer | string | URL;
8
8
  * one that is gone, too large, or of a type the model cannot read. The message then names the
9
9
  * file in its text so the model knows it exists.
10
10
  */
11
- export type AttachmentResolver = (attachment: Attachment) => AttachmentData | null | Promise<AttachmentData | null>;
11
+ export type AttachmentResolver = (attachment: Attachment, run: AgentRunContext) => AttachmentData | null | Promise<AttachmentData | null>;
12
12
  export interface ToModelMessagesOptions {
13
13
  /**
14
14
  * Attachment contents by attachment id, from `resolveAttachments`. An attachment missing here
@@ -17,7 +17,7 @@ export interface ToModelMessagesOptions {
17
17
  readonly attachments?: ReadonlyMap<string, AttachmentData>;
18
18
  }
19
19
  /** Resolves every attachment in `messages` once, for `toModelMessages`. */
20
- export declare function resolveAttachments(messages: readonly Message[], resolve: AttachmentResolver): Promise<Map<string, AttachmentData>>;
20
+ export declare function resolveAttachments(messages: readonly Message[], resolve: AttachmentResolver, run: AgentRunContext): Promise<Map<string, AttachmentData>>;
21
21
  export declare function toModelMessages(messages: readonly Message[], options?: ToModelMessagesOptions): ModelMessage[];
22
22
  export declare function toLoomsToolCalls(calls: ReadonlyArray<{
23
23
  toolCallId: string;
@@ -18,13 +18,13 @@ function toAiJson(value) {
18
18
  return converted;
19
19
  }
20
20
  /** Resolves every attachment in `messages` once, for `toModelMessages`. */
21
- export function resolveAttachments(messages, resolve) {
21
+ export function resolveAttachments(messages, resolve, run) {
22
22
  const pending = new Map();
23
23
  for (const message of messages) {
24
24
  for (const attachment of message.attachments ?? []) {
25
25
  if (!pending.has(attachment.id)) {
26
26
  // Called inside a promise so a resolver that throws rejects instead of throwing here.
27
- pending.set(attachment.id, Promise.resolve().then(() => resolve(attachment)));
27
+ pending.set(attachment.id, Promise.resolve().then(() => resolve(attachment, run)));
28
28
  }
29
29
  }
30
30
  }
@@ -113,7 +113,7 @@ export function toModelMessages(messages, options = {}) {
113
113
  type: 'tool-result',
114
114
  toolCallId: message.toolCallId ?? message.name ?? 'unknown',
115
115
  toolName: message.name ?? 'unknown',
116
- output: parseToolOutput(message.content),
116
+ output: toolOutput(message, options.attachments),
117
117
  },
118
118
  ],
119
119
  });
@@ -126,9 +126,26 @@ export function toModelMessages(messages, options = {}) {
126
126
  }
127
127
  return converted;
128
128
  }
129
- function parseToolOutput(content) {
130
- return Option.match(decodeJson(content), {
131
- onNone: () => ({ type: 'text', value: content }),
129
+ /**
130
+ * A tool result as the model reads it. Files on the result are sent beside its text. A file
131
+ * that cannot be read is left out: the result's own text already names it.
132
+ */
133
+ function toolOutput(message, attachments) {
134
+ const files = [];
135
+ for (const attachment of message.attachments ?? []) {
136
+ const found = attachments?.get(attachment.id) ?? (attachment.url ? new URL(attachment.url) : null);
137
+ if (found !== null) {
138
+ const data = found instanceof URL ? { type: 'url', url: found } : { type: 'data', data: found };
139
+ files.push(attachment.name
140
+ ? { type: 'file', data, mediaType: attachment.mediaType, filename: attachment.name }
141
+ : { type: 'file', data, mediaType: attachment.mediaType });
142
+ }
143
+ }
144
+ if (files.length > 0) {
145
+ return { type: 'content', value: [{ type: 'text', text: message.content }, ...files] };
146
+ }
147
+ return Option.match(decodeJson(message.content), {
148
+ onNone: () => ({ type: 'text', value: message.content }),
132
149
  onSome: (value) => ({ type: 'json', value: toAiJson(value) }),
133
150
  });
134
151
  }
@@ -39,7 +39,7 @@ export function vercelLlm(options) {
39
39
  const { resolveAttachment } = options;
40
40
  const attachments = resolveAttachment
41
41
  ? yield* Effect.tryPromise({
42
- try: () => resolveAttachments(args.messages, resolveAttachment),
42
+ try: () => resolveAttachments(args.messages, resolveAttachment, args.run),
43
43
  catch: (cause) => new VercelLlmError(cause),
44
44
  })
45
45
  : undefined;
@@ -7,6 +7,39 @@ export declare const evaluateEffect: NoInfer<import("@swirls/looms/core").LocalE
7
7
  readonly definitionVersion?: string | undefined;
8
8
  readonly input?: Schema.Json | undefined;
9
9
  }, EvaluatorDefinitionsTag | EvaluatorTag, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
10
+ readonly type: "evaluator.evaluated";
11
+ readonly payload: {
12
+ readonly evaluationId: string;
13
+ readonly definitionName?: string | undefined;
14
+ readonly answers: {
15
+ readonly [x: string]: {
16
+ readonly type: "boolean";
17
+ readonly value: boolean;
18
+ readonly probability: number;
19
+ } | {
20
+ readonly type: "choice";
21
+ readonly value: string;
22
+ } | {
23
+ readonly type: "score";
24
+ readonly value: number;
25
+ };
26
+ };
27
+ readonly route: string;
28
+ readonly reason: "model" | "skipped" | "unavailable" | "uncertain";
29
+ readonly usage?: {
30
+ readonly input: number;
31
+ readonly output: number;
32
+ } | undefined;
33
+ };
34
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
35
+ readonly type: "evaluator.requested";
36
+ readonly payload: {
37
+ readonly evaluationId: string;
38
+ readonly definitionName?: string | undefined;
39
+ readonly state: string;
40
+ readonly model?: string | undefined;
41
+ };
42
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
10
43
  readonly type: "runtime.child.close.requested";
11
44
  readonly payload: {
12
45
  readonly policy: "terminate" | "wait";
@@ -252,37 +285,4 @@ export declare const evaluateEffect: NoInfer<import("@swirls/looms/core").LocalE
252
285
  readonly payload: Schema.Json;
253
286
  };
254
287
  };
255
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
256
- readonly type: "evaluator.evaluated";
257
- readonly payload: {
258
- readonly evaluationId: string;
259
- readonly definitionName?: string | undefined;
260
- readonly answers: {
261
- readonly [x: string]: {
262
- readonly type: "boolean";
263
- readonly value: boolean;
264
- readonly probability: number;
265
- } | {
266
- readonly type: "choice";
267
- readonly value: string;
268
- } | {
269
- readonly type: "score";
270
- readonly value: number;
271
- };
272
- };
273
- readonly route: string;
274
- readonly reason: "model" | "skipped" | "unavailable" | "uncertain";
275
- readonly usage?: {
276
- readonly input: number;
277
- readonly output: number;
278
- } | undefined;
279
- };
280
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
281
- readonly type: "evaluator.requested";
282
- readonly payload: {
283
- readonly evaluationId: string;
284
- readonly definitionName?: string | undefined;
285
- readonly state: string;
286
- readonly model?: string | undefined;
287
- };
288
288
  })>>;
@@ -43,6 +43,39 @@ export declare function evaluator(options?: EvaluatorModuleOptions): import("@sw
43
43
  readonly definitionVersion?: string | undefined;
44
44
  readonly input?: import("effect/Schema").Json | undefined;
45
45
  }, import("./definitions-store").EvaluatorDefinitionsTag | EvaluatorTag, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
46
+ readonly type: "evaluator.evaluated";
47
+ readonly payload: {
48
+ readonly evaluationId: string;
49
+ readonly definitionName?: string | undefined;
50
+ readonly answers: {
51
+ readonly [x: string]: {
52
+ readonly type: "boolean";
53
+ readonly value: boolean;
54
+ readonly probability: number;
55
+ } | {
56
+ readonly type: "choice";
57
+ readonly value: string;
58
+ } | {
59
+ readonly type: "score";
60
+ readonly value: number;
61
+ };
62
+ };
63
+ readonly route: string;
64
+ readonly reason: "model" | "skipped" | "unavailable" | "uncertain";
65
+ readonly usage?: {
66
+ readonly input: number;
67
+ readonly output: number;
68
+ } | undefined;
69
+ };
70
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
71
+ readonly type: "evaluator.requested";
72
+ readonly payload: {
73
+ readonly evaluationId: string;
74
+ readonly definitionName?: string | undefined;
75
+ readonly state: string;
76
+ readonly model?: string | undefined;
77
+ };
78
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
46
79
  readonly type: "runtime.child.close.requested";
47
80
  readonly payload: {
48
81
  readonly policy: "terminate" | "wait";
@@ -288,39 +321,6 @@ export declare function evaluator(options?: EvaluatorModuleOptions): import("@sw
288
321
  readonly payload: import("effect/Schema").Json;
289
322
  };
290
323
  };
291
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
292
- readonly type: "evaluator.evaluated";
293
- readonly payload: {
294
- readonly evaluationId: string;
295
- readonly definitionName?: string | undefined;
296
- readonly answers: {
297
- readonly [x: string]: {
298
- readonly type: "boolean";
299
- readonly value: boolean;
300
- readonly probability: number;
301
- } | {
302
- readonly type: "choice";
303
- readonly value: string;
304
- } | {
305
- readonly type: "score";
306
- readonly value: number;
307
- };
308
- };
309
- readonly route: string;
310
- readonly reason: "model" | "skipped" | "unavailable" | "uncertain";
311
- readonly usage?: {
312
- readonly input: number;
313
- readonly output: number;
314
- } | undefined;
315
- };
316
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
317
- readonly type: "evaluator.requested";
318
- readonly payload: {
319
- readonly evaluationId: string;
320
- readonly definitionName?: string | undefined;
321
- readonly state: string;
322
- readonly model?: string | undefined;
323
- };
324
324
  })>;
325
325
  }, {
326
326
  evaluator: import("@swirls/looms/core").ThreadDefinition<{
@@ -391,6 +391,39 @@ export declare function evaluator(options?: EvaluatorModuleOptions): import("@sw
391
391
  readonly definitionVersion?: string | undefined;
392
392
  readonly input?: import("effect/Schema").Json | undefined;
393
393
  }, import("./definitions-store").EvaluatorDefinitionsTag | EvaluatorTag, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
394
+ readonly type: "evaluator.evaluated";
395
+ readonly payload: {
396
+ readonly evaluationId: string;
397
+ readonly definitionName?: string | undefined;
398
+ readonly answers: {
399
+ readonly [x: string]: {
400
+ readonly type: "boolean";
401
+ readonly value: boolean;
402
+ readonly probability: number;
403
+ } | {
404
+ readonly type: "choice";
405
+ readonly value: string;
406
+ } | {
407
+ readonly type: "score";
408
+ readonly value: number;
409
+ };
410
+ };
411
+ readonly route: string;
412
+ readonly reason: "model" | "skipped" | "unavailable" | "uncertain";
413
+ readonly usage?: {
414
+ readonly input: number;
415
+ readonly output: number;
416
+ } | undefined;
417
+ };
418
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
419
+ readonly type: "evaluator.requested";
420
+ readonly payload: {
421
+ readonly evaluationId: string;
422
+ readonly definitionName?: string | undefined;
423
+ readonly state: string;
424
+ readonly model?: string | undefined;
425
+ };
426
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
394
427
  readonly type: "runtime.child.close.requested";
395
428
  readonly payload: {
396
429
  readonly policy: "terminate" | "wait";
@@ -636,39 +669,6 @@ export declare function evaluator(options?: EvaluatorModuleOptions): import("@sw
636
669
  readonly payload: import("effect/Schema").Json;
637
670
  };
638
671
  };
639
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
640
- readonly type: "evaluator.evaluated";
641
- readonly payload: {
642
- readonly evaluationId: string;
643
- readonly definitionName?: string | undefined;
644
- readonly answers: {
645
- readonly [x: string]: {
646
- readonly type: "boolean";
647
- readonly value: boolean;
648
- readonly probability: number;
649
- } | {
650
- readonly type: "choice";
651
- readonly value: string;
652
- } | {
653
- readonly type: "score";
654
- readonly value: number;
655
- };
656
- };
657
- readonly route: string;
658
- readonly reason: "model" | "skipped" | "unavailable" | "uncertain";
659
- readonly usage?: {
660
- readonly input: number;
661
- readonly output: number;
662
- } | undefined;
663
- };
664
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
665
- readonly type: "evaluator.requested";
666
- readonly payload: {
667
- readonly evaluationId: string;
668
- readonly definitionName?: string | undefined;
669
- readonly state: string;
670
- readonly model?: string | undefined;
671
- };
672
672
  })>;
673
673
  };
674
674
  readonly threads: {
@@ -342,6 +342,15 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
342
342
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
343
343
  readonly type: "schedule.paused";
344
344
  readonly payload: {};
345
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
346
+ readonly type: "schedule.resumed";
347
+ readonly payload: {};
348
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
349
+ readonly type: "schedule.retired";
350
+ readonly payload: {};
351
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
352
+ readonly type: "schedule.triggered";
353
+ readonly payload: {};
345
354
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
346
355
  readonly type: "schedule.planned";
347
356
  readonly payload: {
@@ -365,12 +374,6 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
365
374
  readonly payload: {
366
375
  readonly reason: string;
367
376
  };
368
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
369
- readonly type: "schedule.resumed";
370
- readonly payload: {};
371
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
372
- readonly type: "schedule.retired";
373
- readonly payload: {};
374
377
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
375
378
  readonly type: "schedule.skipped";
376
379
  readonly payload: {
@@ -381,9 +384,6 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
381
384
  readonly manual: boolean;
382
385
  readonly triggerId?: string | undefined;
383
386
  };
384
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
385
- readonly type: "schedule.triggered";
386
- readonly payload: {};
387
387
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
388
388
  readonly type: "schedule.updated";
389
389
  readonly payload: {
@@ -693,6 +693,15 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
693
693
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
694
694
  readonly type: "schedule.paused";
695
695
  readonly payload: {};
696
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
697
+ readonly type: "schedule.resumed";
698
+ readonly payload: {};
699
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
700
+ readonly type: "schedule.retired";
701
+ readonly payload: {};
702
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
703
+ readonly type: "schedule.triggered";
704
+ readonly payload: {};
696
705
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
697
706
  readonly type: "schedule.planned";
698
707
  readonly payload: {
@@ -716,12 +725,6 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
716
725
  readonly payload: {
717
726
  readonly reason: string;
718
727
  };
719
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
720
- readonly type: "schedule.resumed";
721
- readonly payload: {};
722
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
723
- readonly type: "schedule.retired";
724
- readonly payload: {};
725
728
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
726
729
  readonly type: "schedule.skipped";
727
730
  readonly payload: {
@@ -732,9 +735,6 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
732
735
  readonly manual: boolean;
733
736
  readonly triggerId?: string | undefined;
734
737
  };
735
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
736
- readonly type: "schedule.triggered";
737
- readonly payload: {};
738
738
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
739
739
  readonly type: "schedule.updated";
740
740
  readonly payload: {
@@ -1120,6 +1120,15 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
1120
1120
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1121
1121
  readonly type: "schedule.paused";
1122
1122
  readonly payload: {};
1123
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1124
+ readonly type: "schedule.resumed";
1125
+ readonly payload: {};
1126
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1127
+ readonly type: "schedule.retired";
1128
+ readonly payload: {};
1129
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1130
+ readonly type: "schedule.triggered";
1131
+ readonly payload: {};
1123
1132
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1124
1133
  readonly type: "schedule.planned";
1125
1134
  readonly payload: {
@@ -1143,12 +1152,6 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
1143
1152
  readonly payload: {
1144
1153
  readonly reason: string;
1145
1154
  };
1146
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1147
- readonly type: "schedule.resumed";
1148
- readonly payload: {};
1149
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1150
- readonly type: "schedule.retired";
1151
- readonly payload: {};
1152
1155
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1153
1156
  readonly type: "schedule.skipped";
1154
1157
  readonly payload: {
@@ -1159,9 +1162,6 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
1159
1162
  readonly manual: boolean;
1160
1163
  readonly triggerId?: string | undefined;
1161
1164
  };
1162
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1163
- readonly type: "schedule.triggered";
1164
- readonly payload: {};
1165
1165
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1166
1166
  readonly type: "schedule.updated";
1167
1167
  readonly payload: {
@@ -1471,6 +1471,15 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
1471
1471
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1472
1472
  readonly type: "schedule.paused";
1473
1473
  readonly payload: {};
1474
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1475
+ readonly type: "schedule.resumed";
1476
+ readonly payload: {};
1477
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1478
+ readonly type: "schedule.retired";
1479
+ readonly payload: {};
1480
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1481
+ readonly type: "schedule.triggered";
1482
+ readonly payload: {};
1474
1483
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1475
1484
  readonly type: "schedule.planned";
1476
1485
  readonly payload: {
@@ -1494,12 +1503,6 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
1494
1503
  readonly payload: {
1495
1504
  readonly reason: string;
1496
1505
  };
1497
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1498
- readonly type: "schedule.resumed";
1499
- readonly payload: {};
1500
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1501
- readonly type: "schedule.retired";
1502
- readonly payload: {};
1503
1506
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1504
1507
  readonly type: "schedule.skipped";
1505
1508
  readonly payload: {
@@ -1510,9 +1513,6 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
1510
1513
  readonly manual: boolean;
1511
1514
  readonly triggerId?: string | undefined;
1512
1515
  };
1513
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1514
- readonly type: "schedule.triggered";
1515
- readonly payload: {};
1516
1516
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1517
1517
  readonly type: "schedule.updated";
1518
1518
  readonly payload: {
@@ -1,4 +1,6 @@
1
1
  import { Schema } from 'effect';
2
+ import { type Attachment } from '@swirls/looms/agent';
3
+ import type { RunAttributes, SecretContext } from '@swirls/looms/core';
2
4
  /**
3
5
  * A message board is the only thing swarm members share. It holds channels of threaded messages,
4
6
  * tasks that members claim under a lease, and one ordered event log that a swarm follows.
@@ -20,6 +22,17 @@ export declare const BoardMessageSchema: Schema.Struct<{
20
22
  readonly mentions: Schema.$Array<Schema.String>;
21
23
  /** `key=value` state. Keys under `board.` belong to the board. */
22
24
  readonly labels: Schema.$Record<Schema.String, Schema.String>;
25
+ /**
26
+ * Files that travel with the message: screenshots, recordings, documents. The board holds
27
+ * these references and never the bytes, which stay wherever the application stored them.
28
+ */
29
+ readonly attachments: Schema.$Array<Schema.Struct<{
30
+ readonly id: Schema.String;
31
+ readonly mediaType: Schema.String;
32
+ readonly name: Schema.optional<Schema.String>;
33
+ readonly size: Schema.optional<Schema.Finite>;
34
+ readonly url: Schema.optional<Schema.String>;
35
+ }>>;
23
36
  readonly createdAt: Schema.Finite;
24
37
  }>;
25
38
  export type BoardMessage = Schema.Schema.Type<typeof BoardMessageSchema>;
@@ -96,6 +109,17 @@ export declare const BoardEventSchema: Schema.Struct<{
96
109
  readonly mentions: Schema.$Array<Schema.String>;
97
110
  /** `key=value` state. Keys under `board.` belong to the board. */
98
111
  readonly labels: Schema.$Record<Schema.String, Schema.String>;
112
+ /**
113
+ * Files that travel with the message: screenshots, recordings, documents. The board holds
114
+ * these references and never the bytes, which stay wherever the application stored them.
115
+ */
116
+ readonly attachments: Schema.$Array<Schema.Struct<{
117
+ readonly id: Schema.String;
118
+ readonly mediaType: Schema.String;
119
+ readonly name: Schema.optional<Schema.String>;
120
+ readonly size: Schema.optional<Schema.Finite>;
121
+ readonly url: Schema.optional<Schema.String>;
122
+ }>>;
99
123
  readonly createdAt: Schema.Finite;
100
124
  }>>;
101
125
  /** The task as it was after the event. Present on every task event. */
@@ -127,9 +151,11 @@ export declare const BOARD_ACTOR = "board";
127
151
  export declare const TASK_LABEL = "board.task";
128
152
  /** Label keys with this prefix are written only by the board. */
129
153
  export declare const RESERVED_LABEL_PREFIX = "board.";
154
+ /** The most files one message can carry. */
155
+ export declare const MAX_ATTACHMENTS = 10;
130
156
  export declare const DEFAULT_LEASE_MS: number;
131
157
  export declare const MAX_LEASE_MS: number;
132
- export type BoardErrorCode = 'invalid_input' | 'message_not_found' | 'task_not_found' | 'duplicate_key' | 'reserved_label' | 'label_conflict' | 'invalid_needs' | 'task_claimed' | 'task_assigned' | 'task_not_ready' | 'task_finished' | 'claim_lost';
158
+ export type BoardErrorCode = 'invalid_input' | 'board_denied' | 'message_not_found' | 'task_not_found' | 'duplicate_key' | 'reserved_label' | 'label_conflict' | 'invalid_needs' | 'task_claimed' | 'task_assigned' | 'task_not_ready' | 'task_finished' | 'claim_lost';
133
159
  declare const BoardError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
134
160
  readonly _tag: "BoardError";
135
161
  } & Readonly<A>;
@@ -148,6 +174,8 @@ export interface PostInput {
148
174
  readonly channel: string;
149
175
  readonly text: string;
150
176
  readonly labels?: BoardLabels;
177
+ /** At most {@link MAX_ATTACHMENTS}. Stored and returned as given. */
178
+ readonly attachments?: readonly Attachment[];
151
179
  /**
152
180
  * Idempotency key. Posting the same key again returns the first message and writes nothing.
153
181
  * The same key in a different channel or thread fails with `duplicate_key`.
@@ -160,6 +188,7 @@ export interface ReplyInput {
160
188
  readonly to: string;
161
189
  readonly text: string;
162
190
  readonly labels?: BoardLabels;
191
+ readonly attachments?: readonly Attachment[];
163
192
  readonly key?: string;
164
193
  }
165
194
  export interface LabelInput {
@@ -176,6 +205,8 @@ export interface LabelInput {
176
205
  };
177
206
  }
178
207
  export interface MessageQuery {
208
+ /** Only the message with this id. */
209
+ readonly id?: string;
179
210
  /** `support` matches that channel. `support/` matches it and every channel below it. */
180
211
  readonly channel?: string;
181
212
  /** Only the thread with this root: the root itself and its replies. */
@@ -196,6 +227,8 @@ export interface CreateTaskInput {
196
227
  readonly for?: string;
197
228
  readonly needs?: readonly string[];
198
229
  readonly labels?: BoardLabels;
230
+ /** Kept on the task's root message. */
231
+ readonly attachments?: readonly Attachment[];
199
232
  readonly key?: string;
200
233
  }
201
234
  export interface TaskQuery {
@@ -255,6 +288,8 @@ export interface EventPage {
255
288
  *
256
289
  * - Every write appends to one totally ordered event log, in the order the writes took effect.
257
290
  * - `post`, `reply` and `createTask` are idempotent on `key`.
291
+ * - A message returns the attachments it was written with, in order, and an empty list when it
292
+ * had none. More than {@link MAX_ATTACHMENTS} is refused with `invalid_input`.
258
293
  * - At most one claim holds a task. `claim` on a held task fails with `task_claimed`.
259
294
  * - A claim ends when it is settled, when its lease passes, or when the task is canceled. After
260
295
  * that its token fails with `claim_lost` and changes nothing, so a member that stalled cannot
@@ -281,8 +316,21 @@ export interface MessageBoard {
281
316
  cancel(input: TaskChangeInput): Promise<BoardTask>;
282
317
  events(query?: EventQuery): Promise<EventPage>;
283
318
  }
284
- /** Looks a board up by id, so one host can serve a board per tenant. */
285
- export type BoardResolver = (boardId: string) => MessageBoard | Promise<MessageBoard>;
319
+ /** The run a board call is made from: the swarm's run, a member's run, or a run that used a step. */
320
+ export interface BoardCaller {
321
+ readonly runId: string;
322
+ readonly threadId: string;
323
+ /** The labels the run was started with, such as its tenant. A swarm's members inherit them. */
324
+ readonly attributes: RunAttributes;
325
+ /** Bearer material for this attempt. */
326
+ readonly secrets: SecretContext;
327
+ }
328
+ /**
329
+ * Looks a board up by id, so one host can serve a board per tenant. A board id reaches the
330
+ * resolver from a run's input, so a host with tenants checks it against `caller.attributes` and
331
+ * throws {@link BoardError} with `board_denied` for a board the caller's tenant does not own.
332
+ */
333
+ export type BoardResolver = (boardId: string, caller: BoardCaller) => MessageBoard | Promise<MessageBoard>;
286
334
  /** The distinct `@name` handles in `text`, lowercased, in the order they first appear. */
287
335
  export declare function parseMentions(text: string): string[];
288
336
  /** Whether `channel` is selected by `filter`. A filter ending in `/` selects a whole subtree. */
@@ -1,4 +1,5 @@
1
1
  import { Data, Schema } from 'effect';
2
+ import { AttachmentSchema } from '@swirls/looms/agent';
2
3
  /**
3
4
  * A message board is the only thing swarm members share. It holds channels of threaded messages,
4
5
  * tasks that members claim under a lease, and one ordered event log that a swarm follows.
@@ -19,6 +20,11 @@ export const BoardMessageSchema = Schema.Struct({
19
20
  mentions: Schema.Array(Schema.String),
20
21
  /** `key=value` state. Keys under `board.` belong to the board. */
21
22
  labels: BoardLabelsSchema,
23
+ /**
24
+ * Files that travel with the message: screenshots, recordings, documents. The board holds
25
+ * these references and never the bytes, which stay wherever the application stored them.
26
+ */
27
+ attachments: Schema.Array(AttachmentSchema),
22
28
  createdAt: Schema.Finite,
23
29
  });
24
30
  export const TaskStateSchema = Schema.Union([
@@ -89,6 +95,8 @@ export const BOARD_ACTOR = 'board';
89
95
  export const TASK_LABEL = 'board.task';
90
96
  /** Label keys with this prefix are written only by the board. */
91
97
  export const RESERVED_LABEL_PREFIX = 'board.';
98
+ /** The most files one message can carry. */
99
+ export const MAX_ATTACHMENTS = 10;
92
100
  export const DEFAULT_LEASE_MS = 15 * 60_000;
93
101
  export const MAX_LEASE_MS = 60 * 60_000;
94
102
  /**