@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.
- package/CHANGELOG.md +24 -0
- package/dist/agent/definitions.d.ts +14 -4
- package/dist/agent/effects.js +16 -7
- package/dist/agent/llm.d.ts +3 -1
- package/dist/agent/module.d.ts +727 -727
- package/dist/agent/threads.js +4 -1
- package/dist/ai-vercel/messages.d.ts +3 -3
- package/dist/ai-vercel/messages.js +23 -6
- package/dist/ai-vercel/vercel-llm.js +1 -1
- package/dist/evaluator/effects.d.ts +33 -33
- package/dist/evaluator/module.d.ts +66 -66
- package/dist/schedule/module.d.ts +36 -36
- package/dist/swarm/board.d.ts +51 -3
- package/dist/swarm/board.js +8 -0
- package/dist/swarm/conformance.js +54 -1
- package/dist/swarm/definitions.d.ts +15 -0
- package/dist/swarm/definitions.js +3 -0
- package/dist/swarm/effects.d.ts +1009 -31
- package/dist/swarm/effects.js +73 -18
- package/dist/swarm/ensure.d.ts +9 -2
- package/dist/swarm/ensure.js +2 -1
- package/dist/swarm/events.d.ts +51 -0
- package/dist/swarm/events.js +10 -0
- package/dist/swarm/index.d.ts +1 -0
- package/dist/swarm/index.js +1 -0
- package/dist/swarm/memory-board.js +18 -2
- package/dist/swarm/module.d.ts +2055 -115
- package/dist/swarm/module.js +3 -1
- package/dist/swarm/prompt.d.ts +5 -0
- package/dist/swarm/prompt.js +27 -2
- package/dist/swarm/scope.d.ts +80 -0
- package/dist/swarm/services.d.ts +2 -2
- package/dist/swarm/services.js +5 -2
- package/dist/swarm/threads.d.ts +4 -0
- package/dist/swarm/threads.js +24 -2
- package/dist/swarm/tools.js +12 -5
- package/package.json +1 -1
package/dist/swarm/effects.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Clock, Effect, Schema } from 'effect';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { AttachmentSchema } from '@swirls/looms/agent';
|
|
3
|
+
import { DEFAULT_DEFINITION_VERSION, RunLauncherTag, cleanUndefined, failEffect, typeIds, } from '@swirls/looms/core';
|
|
4
|
+
import { BoardError, BoardEventSchema, BoardLabelsSchema, TaskStateSchema } from './board.js';
|
|
5
|
+
import { activationAttachments, activationPrompt } from './prompt.js';
|
|
5
6
|
import { swarmModule } from './scope.js';
|
|
6
7
|
import { BoardsTag, SwarmDefinitionsTag } from './services.js';
|
|
7
8
|
const RETRY = { maxAttempts: 5, backoffMs: 1_000, maxBackoffMs: 60_000 };
|
|
@@ -34,7 +35,11 @@ export const pullEffect = swarmModule.effect({
|
|
|
34
35
|
const definitions = yield* SwarmDefinitionsTag;
|
|
35
36
|
const now = yield* Clock.currentTimeMillis;
|
|
36
37
|
const definition = yield* definitions.resolve(input.definitionName, input.definitionVersion);
|
|
37
|
-
const page = yield* boards
|
|
38
|
+
const page = yield* boards
|
|
39
|
+
.call(input.board, ctx, (board) => board.events({ after: input.after ?? undefined, limit: PULL_LIMIT }))
|
|
40
|
+
.pipe(
|
|
41
|
+
// The board will refuse the next attempt too, so fail now and let the swarm fail.
|
|
42
|
+
Effect.catchTag('BoardError', (refusal) => failEffect({ error: `${refusal.code}: ${refusal.message}`, nonRetryable: true })));
|
|
38
43
|
const interval = definition?.pollIntervalMs ?? null;
|
|
39
44
|
return [
|
|
40
45
|
swarmModule.input('board.pulled', {
|
|
@@ -48,9 +53,12 @@ export const pullEffect = swarmModule.effect({
|
|
|
48
53
|
];
|
|
49
54
|
}),
|
|
50
55
|
});
|
|
51
|
-
/**
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
/**
|
|
57
|
+
* The run id of a member's activation, in the host's id format. Derived from the swarm's run id,
|
|
58
|
+
* so a retried activation starts the same run and a host can find a member's run.
|
|
59
|
+
*/
|
|
60
|
+
export function activationRunId(swarmRunId, member, activation, ids = typeIds) {
|
|
61
|
+
return ids.derive('run', [swarmRunId, member, activation]);
|
|
54
62
|
}
|
|
55
63
|
export const activateEffect = swarmModule.effect({
|
|
56
64
|
type: 'swarm.activate',
|
|
@@ -69,9 +77,11 @@ export const activateEffect = swarmModule.effect({
|
|
|
69
77
|
nonRetryable: true,
|
|
70
78
|
});
|
|
71
79
|
}
|
|
72
|
-
const runId = activationRunId(ctx.runId, member.name, input.activation);
|
|
80
|
+
const runId = activationRunId(ctx.runId, member.name, input.activation, ctx.ids);
|
|
81
|
+
const attachments = activationAttachments(input.events);
|
|
73
82
|
const activation = {
|
|
74
83
|
prompt: activationPrompt(definition, member, input.events),
|
|
84
|
+
attachments: attachments.length > 0 ? attachments : undefined,
|
|
75
85
|
swarm: {
|
|
76
86
|
name: definition.name,
|
|
77
87
|
runId: ctx.runId,
|
|
@@ -111,11 +121,17 @@ export const PostArgsSchema = Schema.Struct({
|
|
|
111
121
|
channel: Schema.String,
|
|
112
122
|
text: Schema.String,
|
|
113
123
|
labels: Schema.optional(BoardLabelsSchema),
|
|
124
|
+
attachments: Schema.optional(Schema.Array(AttachmentSchema)),
|
|
114
125
|
});
|
|
115
126
|
export const ReplyArgsSchema = Schema.Struct({
|
|
116
127
|
/** Any message of the thread to reply in. */
|
|
117
128
|
to: Schema.String,
|
|
118
129
|
text: Schema.String,
|
|
130
|
+
attachments: Schema.optional(Schema.Array(AttachmentSchema)),
|
|
131
|
+
});
|
|
132
|
+
export const ViewArgsSchema = Schema.Struct({
|
|
133
|
+
/** The message whose files to look at. A task's id is the id of its root message. */
|
|
134
|
+
message: Schema.String,
|
|
119
135
|
});
|
|
120
136
|
export const ReadArgsSchema = Schema.Struct({
|
|
121
137
|
channel: Schema.optional(Schema.String),
|
|
@@ -137,6 +153,7 @@ export const CreateTaskArgsSchema = Schema.Struct({
|
|
|
137
153
|
text: Schema.String,
|
|
138
154
|
for: Schema.optional(Schema.String),
|
|
139
155
|
needs: Schema.optional(Schema.Array(Schema.String)),
|
|
156
|
+
attachments: Schema.optional(Schema.Array(AttachmentSchema)),
|
|
140
157
|
});
|
|
141
158
|
export const ListTasksArgsSchema = Schema.Struct({
|
|
142
159
|
channel: Schema.optional(Schema.String),
|
|
@@ -159,6 +176,13 @@ export const SettleTaskArgsSchema = Schema.Struct({
|
|
|
159
176
|
]),
|
|
160
177
|
note: Schema.optional(Schema.String),
|
|
161
178
|
});
|
|
179
|
+
/**
|
|
180
|
+
* The idempotency key of a board write. An effect id is only unique within its run, and one
|
|
181
|
+
* board serves many runs, so the key names the run too.
|
|
182
|
+
*/
|
|
183
|
+
function writeKey(ctx) {
|
|
184
|
+
return `${ctx.runId}:${ctx.effectId}`;
|
|
185
|
+
}
|
|
162
186
|
/** A refusal is an answer, not a fault: record it so the caller's wait resolves with the error. */
|
|
163
187
|
function rejected(caller, threadId, error) {
|
|
164
188
|
return swarmModule.input('call.rejected', { callId: caller.callId, board: caller.board, code: error.code, error: error.message }, { threadId });
|
|
@@ -173,12 +197,13 @@ export const postEffect = swarmModule.effect({
|
|
|
173
197
|
retry: RETRY,
|
|
174
198
|
execute: (input, ctx) => answered(input, ctx.threadId, Effect.gen(function* () {
|
|
175
199
|
const boards = yield* BoardsTag;
|
|
176
|
-
const message = yield* boards.call(input.board, (board) => board.post({
|
|
200
|
+
const message = yield* boards.call(input.board, ctx, (board) => board.post({
|
|
177
201
|
by: input.as,
|
|
178
202
|
channel: input.channel,
|
|
179
203
|
text: input.text,
|
|
180
204
|
labels: input.labels,
|
|
181
|
-
|
|
205
|
+
attachments: input.attachments,
|
|
206
|
+
key: writeKey(ctx),
|
|
182
207
|
}));
|
|
183
208
|
return swarmModule.input('message.posted', { callId: input.callId, board: input.board, message }, { threadId: ctx.threadId });
|
|
184
209
|
})),
|
|
@@ -190,7 +215,13 @@ export const replyEffect = swarmModule.effect({
|
|
|
190
215
|
retry: RETRY,
|
|
191
216
|
execute: (input, ctx) => answered(input, ctx.threadId, Effect.gen(function* () {
|
|
192
217
|
const boards = yield* BoardsTag;
|
|
193
|
-
const message = yield* boards.call(input.board, (board) => board.reply({
|
|
218
|
+
const message = yield* boards.call(input.board, ctx, (board) => board.reply({
|
|
219
|
+
by: input.as,
|
|
220
|
+
to: input.to,
|
|
221
|
+
text: input.text,
|
|
222
|
+
attachments: input.attachments,
|
|
223
|
+
key: writeKey(ctx),
|
|
224
|
+
}));
|
|
194
225
|
return swarmModule.input('message.posted', { callId: input.callId, board: input.board, message }, { threadId: ctx.threadId });
|
|
195
226
|
})),
|
|
196
227
|
});
|
|
@@ -201,7 +232,7 @@ export const readEffect = swarmModule.effect({
|
|
|
201
232
|
retry: RETRY,
|
|
202
233
|
execute: (input, ctx) => answered(input, ctx.threadId, Effect.gen(function* () {
|
|
203
234
|
const boards = yield* BoardsTag;
|
|
204
|
-
const messages = yield* boards.call(input.board, (board) => board.messages({
|
|
235
|
+
const messages = yield* boards.call(input.board, ctx, (board) => board.messages({
|
|
205
236
|
channel: input.channel,
|
|
206
237
|
thread: input.thread,
|
|
207
238
|
by: input.by,
|
|
@@ -212,6 +243,29 @@ export const readEffect = swarmModule.effect({
|
|
|
212
243
|
return swarmModule.input('messages.read', { callId: input.callId, board: input.board, messages }, { threadId: ctx.threadId });
|
|
213
244
|
})),
|
|
214
245
|
});
|
|
246
|
+
export const viewEffect = swarmModule.effect({
|
|
247
|
+
type: 'swarm.view',
|
|
248
|
+
placement: 'local',
|
|
249
|
+
input: Schema.Struct({ ...CallerFields, ...ViewArgsSchema.fields }),
|
|
250
|
+
retry: RETRY,
|
|
251
|
+
execute: (input, ctx) => answered(input, ctx.threadId, Effect.gen(function* () {
|
|
252
|
+
const boards = yield* BoardsTag;
|
|
253
|
+
const found = yield* boards.call(input.board, ctx, (board) => board.messages({ id: input.message }));
|
|
254
|
+
const message = found[0];
|
|
255
|
+
if (!message) {
|
|
256
|
+
return yield* new BoardError({
|
|
257
|
+
code: 'message_not_found',
|
|
258
|
+
message: `No message "${input.message}"`,
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
return swarmModule.input('attachments.viewed', {
|
|
262
|
+
callId: input.callId,
|
|
263
|
+
board: input.board,
|
|
264
|
+
message: message.id,
|
|
265
|
+
attachments: message.attachments,
|
|
266
|
+
}, { threadId: ctx.threadId });
|
|
267
|
+
})),
|
|
268
|
+
});
|
|
215
269
|
export const labelEffect = swarmModule.effect({
|
|
216
270
|
type: 'swarm.label',
|
|
217
271
|
placement: 'local',
|
|
@@ -219,7 +273,7 @@ export const labelEffect = swarmModule.effect({
|
|
|
219
273
|
retry: RETRY,
|
|
220
274
|
execute: (input, ctx) => answered(input, ctx.threadId, Effect.gen(function* () {
|
|
221
275
|
const boards = yield* BoardsTag;
|
|
222
|
-
const message = yield* boards.call(input.board, (board) => board.label({
|
|
276
|
+
const message = yield* boards.call(input.board, ctx, (board) => board.label({
|
|
223
277
|
by: input.as,
|
|
224
278
|
message: input.message,
|
|
225
279
|
set: input.set,
|
|
@@ -236,13 +290,14 @@ export const createTaskEffect = swarmModule.effect({
|
|
|
236
290
|
retry: RETRY,
|
|
237
291
|
execute: (input, ctx) => answered(input, ctx.threadId, Effect.gen(function* () {
|
|
238
292
|
const boards = yield* BoardsTag;
|
|
239
|
-
const task = yield* boards.call(input.board, (board) => board.createTask({
|
|
293
|
+
const task = yield* boards.call(input.board, ctx, (board) => board.createTask({
|
|
240
294
|
by: input.as,
|
|
241
295
|
channel: input.channel,
|
|
242
296
|
text: input.text,
|
|
243
297
|
for: input.for,
|
|
244
298
|
needs: input.needs,
|
|
245
|
-
|
|
299
|
+
attachments: input.attachments,
|
|
300
|
+
key: writeKey(ctx),
|
|
246
301
|
}));
|
|
247
302
|
return swarmModule.input('task.created', { callId: input.callId, board: input.board, task }, { threadId: ctx.threadId });
|
|
248
303
|
})),
|
|
@@ -254,7 +309,7 @@ export const listTasksEffect = swarmModule.effect({
|
|
|
254
309
|
retry: RETRY,
|
|
255
310
|
execute: (input, ctx) => answered(input, ctx.threadId, Effect.gen(function* () {
|
|
256
311
|
const boards = yield* BoardsTag;
|
|
257
|
-
const tasks = yield* boards.call(input.board, (board) => board.tasks({ channel: input.channel, state: input.state, for: input.for }));
|
|
312
|
+
const tasks = yield* boards.call(input.board, ctx, (board) => board.tasks({ channel: input.channel, state: input.state, for: input.for }));
|
|
258
313
|
return swarmModule.input('tasks.listed', { callId: input.callId, board: input.board, tasks }, { threadId: ctx.threadId });
|
|
259
314
|
})),
|
|
260
315
|
});
|
|
@@ -269,7 +324,7 @@ export const claimTaskEffect = swarmModule.effect({
|
|
|
269
324
|
retry: { maxAttempts: 1 },
|
|
270
325
|
execute: (input, ctx) => answered(input, ctx.threadId, Effect.gen(function* () {
|
|
271
326
|
const boards = yield* BoardsTag;
|
|
272
|
-
const claim = yield* boards.call(input.board, (board) => board.claim({
|
|
327
|
+
const claim = yield* boards.call(input.board, ctx, (board) => board.claim({
|
|
273
328
|
by: input.as,
|
|
274
329
|
task: input.task,
|
|
275
330
|
channel: input.channel,
|
|
@@ -285,7 +340,7 @@ export const settleTaskEffect = swarmModule.effect({
|
|
|
285
340
|
retry: { maxAttempts: 1 },
|
|
286
341
|
execute: (input, ctx) => answered(input, ctx.threadId, Effect.gen(function* () {
|
|
287
342
|
const boards = yield* BoardsTag;
|
|
288
|
-
const task = yield* boards.call(input.board, (board) => board.settle({
|
|
343
|
+
const task = yield* boards.call(input.board, ctx, (board) => board.settle({
|
|
289
344
|
task: input.task,
|
|
290
345
|
token: input.token,
|
|
291
346
|
outcome: input.outcome,
|
package/dist/swarm/ensure.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LaunchRunArgs, RunState } from '@swirls/looms/core';
|
|
1
|
+
import type { LaunchRunArgs, RunAttributes, RunState } from '@swirls/looms/core';
|
|
2
2
|
import type { SwarmDefinition, SwarmStart } from './definitions';
|
|
3
3
|
/** The two operations `ensureSwarm` needs. `createLooms` already has them. */
|
|
4
4
|
export interface SwarmHost {
|
|
@@ -8,9 +8,16 @@ export interface SwarmHost {
|
|
|
8
8
|
getRun(runId: string): Promise<RunState>;
|
|
9
9
|
}
|
|
10
10
|
export type SwarmEnsureResult = 'started' | 'running';
|
|
11
|
+
export interface SwarmEnsureOptions {
|
|
12
|
+
/**
|
|
13
|
+
* The labels the swarm's run starts with, such as its tenant. Every member run inherits them,
|
|
14
|
+
* so the board resolver, the members' tools and the model adapter all see the same tenant.
|
|
15
|
+
*/
|
|
16
|
+
readonly attributes?: RunAttributes;
|
|
17
|
+
}
|
|
11
18
|
/**
|
|
12
19
|
* Start a swarm under a fixed run id unless that run already exists, so a host can call it on
|
|
13
20
|
* every boot or whenever a tenant is provisioned. A swarm that was stopped, failed or cancelled
|
|
14
21
|
* throws: its run id cannot be reused.
|
|
15
22
|
*/
|
|
16
|
-
export declare function ensureSwarm(host: SwarmHost, definition: SwarmDefinition, runId: string, config?: NonNullable<SwarmStart
|
|
23
|
+
export declare function ensureSwarm(host: SwarmHost, definition: SwarmDefinition, runId: string, config?: NonNullable<SwarmStart>, options?: SwarmEnsureOptions): Promise<SwarmEnsureResult>;
|
package/dist/swarm/ensure.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* every boot or whenever a tenant is provisioned. A swarm that was stopped, failed or cancelled
|
|
4
4
|
* throws: its run id cannot be reused.
|
|
5
5
|
*/
|
|
6
|
-
export function ensureSwarm(host, definition, runId, config = {}) {
|
|
6
|
+
export function ensureSwarm(host, definition, runId, config = {}, options = {}) {
|
|
7
7
|
return host.getRun(runId).then((state) => {
|
|
8
8
|
if (state.rootThreadId === null) {
|
|
9
9
|
return host
|
|
@@ -13,6 +13,7 @@ export function ensureSwarm(host, definition, runId, config = {}) {
|
|
|
13
13
|
definitionName: definition.name,
|
|
14
14
|
definitionVersion: definition.version,
|
|
15
15
|
input: config,
|
|
16
|
+
attributes: options.attributes,
|
|
16
17
|
})
|
|
17
18
|
.then(() => 'started');
|
|
18
19
|
}
|
package/dist/swarm/events.d.ts
CHANGED
|
@@ -17,6 +17,13 @@ export declare const BoardPulledPayloadSchema: Schema.Struct<{
|
|
|
17
17
|
readonly re: Schema.NullOr<Schema.String>;
|
|
18
18
|
readonly mentions: Schema.$Array<Schema.String>;
|
|
19
19
|
readonly labels: Schema.$Record<Schema.String, Schema.String>;
|
|
20
|
+
readonly attachments: Schema.$Array<Schema.Struct<{
|
|
21
|
+
readonly id: Schema.String;
|
|
22
|
+
readonly mediaType: Schema.String;
|
|
23
|
+
readonly name: Schema.optional<Schema.String>;
|
|
24
|
+
readonly size: Schema.optional<Schema.Finite>;
|
|
25
|
+
readonly url: Schema.optional<Schema.String>;
|
|
26
|
+
}>>;
|
|
20
27
|
readonly createdAt: Schema.Finite;
|
|
21
28
|
}>>;
|
|
22
29
|
readonly task: Schema.optional<Schema.Struct<{
|
|
@@ -71,6 +78,13 @@ export declare const swarmCatalog: import("@swirls/looms/core").EventCatalog<"sw
|
|
|
71
78
|
readonly re: Schema.NullOr<Schema.String>;
|
|
72
79
|
readonly mentions: Schema.$Array<Schema.String>;
|
|
73
80
|
readonly labels: Schema.$Record<Schema.String, Schema.String>;
|
|
81
|
+
readonly attachments: Schema.$Array<Schema.Struct<{
|
|
82
|
+
readonly id: Schema.String;
|
|
83
|
+
readonly mediaType: Schema.String;
|
|
84
|
+
readonly name: Schema.optional<Schema.String>;
|
|
85
|
+
readonly size: Schema.optional<Schema.Finite>;
|
|
86
|
+
readonly url: Schema.optional<Schema.String>;
|
|
87
|
+
}>>;
|
|
74
88
|
readonly createdAt: Schema.Finite;
|
|
75
89
|
}>>;
|
|
76
90
|
readonly task: Schema.optional<Schema.Struct<{
|
|
@@ -118,6 +132,13 @@ export declare const swarmCatalog: import("@swirls/looms/core").EventCatalog<"sw
|
|
|
118
132
|
readonly re: Schema.NullOr<Schema.String>;
|
|
119
133
|
readonly mentions: Schema.$Array<Schema.String>;
|
|
120
134
|
readonly labels: Schema.$Record<Schema.String, Schema.String>;
|
|
135
|
+
readonly attachments: Schema.$Array<Schema.Struct<{
|
|
136
|
+
readonly id: Schema.String;
|
|
137
|
+
readonly mediaType: Schema.String;
|
|
138
|
+
readonly name: Schema.optional<Schema.String>;
|
|
139
|
+
readonly size: Schema.optional<Schema.Finite>;
|
|
140
|
+
readonly url: Schema.optional<Schema.String>;
|
|
141
|
+
}>>;
|
|
121
142
|
readonly createdAt: Schema.Finite;
|
|
122
143
|
}>;
|
|
123
144
|
}>;
|
|
@@ -132,6 +153,13 @@ export declare const swarmCatalog: import("@swirls/looms/core").EventCatalog<"sw
|
|
|
132
153
|
readonly re: Schema.NullOr<Schema.String>;
|
|
133
154
|
readonly mentions: Schema.$Array<Schema.String>;
|
|
134
155
|
readonly labels: Schema.$Record<Schema.String, Schema.String>;
|
|
156
|
+
readonly attachments: Schema.$Array<Schema.Struct<{
|
|
157
|
+
readonly id: Schema.String;
|
|
158
|
+
readonly mediaType: Schema.String;
|
|
159
|
+
readonly name: Schema.optional<Schema.String>;
|
|
160
|
+
readonly size: Schema.optional<Schema.Finite>;
|
|
161
|
+
readonly url: Schema.optional<Schema.String>;
|
|
162
|
+
}>>;
|
|
135
163
|
readonly createdAt: Schema.Finite;
|
|
136
164
|
}>;
|
|
137
165
|
}>;
|
|
@@ -146,9 +174,32 @@ export declare const swarmCatalog: import("@swirls/looms/core").EventCatalog<"sw
|
|
|
146
174
|
readonly re: Schema.NullOr<Schema.String>;
|
|
147
175
|
readonly mentions: Schema.$Array<Schema.String>;
|
|
148
176
|
readonly labels: Schema.$Record<Schema.String, Schema.String>;
|
|
177
|
+
readonly attachments: Schema.$Array<Schema.Struct<{
|
|
178
|
+
readonly id: Schema.String;
|
|
179
|
+
readonly mediaType: Schema.String;
|
|
180
|
+
readonly name: Schema.optional<Schema.String>;
|
|
181
|
+
readonly size: Schema.optional<Schema.Finite>;
|
|
182
|
+
readonly url: Schema.optional<Schema.String>;
|
|
183
|
+
}>>;
|
|
149
184
|
readonly createdAt: Schema.Finite;
|
|
150
185
|
}>>;
|
|
151
186
|
}>;
|
|
187
|
+
/**
|
|
188
|
+
* The files on one message. `attachments` is at the top of the payload so that an agent's
|
|
189
|
+
* tool result shows them to the model.
|
|
190
|
+
*/
|
|
191
|
+
'attachments.viewed': Schema.Struct<{
|
|
192
|
+
readonly callId: Schema.String;
|
|
193
|
+
readonly board: Schema.String;
|
|
194
|
+
readonly message: Schema.String;
|
|
195
|
+
readonly attachments: Schema.$Array<Schema.Struct<{
|
|
196
|
+
readonly id: Schema.String;
|
|
197
|
+
readonly mediaType: Schema.String;
|
|
198
|
+
readonly name: Schema.optional<Schema.String>;
|
|
199
|
+
readonly size: Schema.optional<Schema.Finite>;
|
|
200
|
+
readonly url: Schema.optional<Schema.String>;
|
|
201
|
+
}>>;
|
|
202
|
+
}>;
|
|
152
203
|
'task.created': Schema.Struct<{
|
|
153
204
|
readonly callId: Schema.String;
|
|
154
205
|
readonly board: Schema.String;
|
package/dist/swarm/events.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Schema } from 'effect';
|
|
2
|
+
import { AttachmentSchema } from '@swirls/looms/agent';
|
|
2
3
|
import { defineEventCatalog } from '@swirls/looms/core';
|
|
3
4
|
import { BoardEventSchema, BoardMessageSchema, BoardTaskSchema, TaskClaimSchema } from './board.js';
|
|
4
5
|
/** Which board a member's call went to, and the id that pairs the result with its tool call. */
|
|
@@ -39,6 +40,15 @@ export const swarmCatalog = defineEventCatalog('swarm', {
|
|
|
39
40
|
'message.posted': Schema.Struct({ ...CallFields, message: BoardMessageSchema }),
|
|
40
41
|
'message.labeled': Schema.Struct({ ...CallFields, message: BoardMessageSchema }),
|
|
41
42
|
'messages.read': Schema.Struct({ ...CallFields, messages: Schema.Array(BoardMessageSchema) }),
|
|
43
|
+
/**
|
|
44
|
+
* The files on one message. `attachments` is at the top of the payload so that an agent's
|
|
45
|
+
* tool result shows them to the model.
|
|
46
|
+
*/
|
|
47
|
+
'attachments.viewed': Schema.Struct({
|
|
48
|
+
...CallFields,
|
|
49
|
+
message: Schema.String,
|
|
50
|
+
attachments: Schema.Array(AttachmentSchema),
|
|
51
|
+
}),
|
|
42
52
|
'task.created': Schema.Struct({ ...CallFields, task: BoardTaskSchema }),
|
|
43
53
|
'tasks.listed': Schema.Struct({ ...CallFields, tasks: Schema.Array(BoardTaskSchema) }),
|
|
44
54
|
/** `claim` is null when the queue had nothing for the caller. */
|
package/dist/swarm/index.d.ts
CHANGED
package/dist/swarm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BOARD_ACTOR, BoardError, DEFAULT_LEASE_MS, MAX_LEASE_MS, RESERVED_LABEL_PREFIX, TASK_LABEL, channelMatches, isFinishedTask, parseMentions, } from './board.js';
|
|
1
|
+
import { BOARD_ACTOR, BoardError, DEFAULT_LEASE_MS, MAX_ATTACHMENTS, MAX_LEASE_MS, RESERVED_LABEL_PREFIX, TASK_LABEL, channelMatches, isFinishedTask, parseMentions, } from './board.js';
|
|
2
2
|
const DEFAULT_MESSAGE_LIMIT = 50;
|
|
3
3
|
const DEFAULT_TASK_LIMIT = 100;
|
|
4
4
|
const DEFAULT_EVENT_LIMIT = 100;
|
|
@@ -15,8 +15,19 @@ function checkLabels(labels) {
|
|
|
15
15
|
}
|
|
16
16
|
return labels ?? {};
|
|
17
17
|
}
|
|
18
|
+
function checkAttachments(attachments) {
|
|
19
|
+
const files = attachments ?? [];
|
|
20
|
+
if (files.length > MAX_ATTACHMENTS) {
|
|
21
|
+
refuse('invalid_input', `A message carries at most ${MAX_ATTACHMENTS} attachments`);
|
|
22
|
+
}
|
|
23
|
+
if (files.some((file) => file.id === '' || file.mediaType === '')) {
|
|
24
|
+
refuse('invalid_input', 'An attachment needs an id and a media type');
|
|
25
|
+
}
|
|
26
|
+
return [...files];
|
|
27
|
+
}
|
|
18
28
|
function matchesMessage(message, query) {
|
|
19
|
-
return ((query.
|
|
29
|
+
return ((query.id === undefined || message.id === query.id) &&
|
|
30
|
+
(query.channel === undefined || channelMatches(query.channel, message.channel)) &&
|
|
20
31
|
(query.thread === undefined || message.id === query.thread || message.re === query.thread) &&
|
|
21
32
|
(query.by === undefined || message.by === query.by) &&
|
|
22
33
|
(query.mentions === undefined || message.mentions.includes(query.mentions)) &&
|
|
@@ -89,6 +100,7 @@ export function createMemoryBoard(options = {}) {
|
|
|
89
100
|
refuse('invalid_input', `"${input.channel}" is not a channel path`);
|
|
90
101
|
}
|
|
91
102
|
const labels = checkLabels(input.labels);
|
|
103
|
+
const attachments = checkAttachments(input.attachments);
|
|
92
104
|
const existing = input.key === undefined ? undefined : messages.get(keys.get(input.key) ?? '');
|
|
93
105
|
if (existing) {
|
|
94
106
|
if (existing.channel !== input.channel || existing.re !== input.re) {
|
|
@@ -105,6 +117,7 @@ export function createMemoryBoard(options = {}) {
|
|
|
105
117
|
re: input.re,
|
|
106
118
|
mentions: parseMentions(input.text),
|
|
107
119
|
labels,
|
|
120
|
+
attachments,
|
|
108
121
|
createdAt: now(),
|
|
109
122
|
};
|
|
110
123
|
messages.set(message.id, message);
|
|
@@ -159,6 +172,7 @@ export function createMemoryBoard(options = {}) {
|
|
|
159
172
|
text: input.text,
|
|
160
173
|
re: null,
|
|
161
174
|
labels: input.labels,
|
|
175
|
+
attachments: input.attachments,
|
|
162
176
|
key: input.key,
|
|
163
177
|
});
|
|
164
178
|
if (created) {
|
|
@@ -174,6 +188,7 @@ export function createMemoryBoard(options = {}) {
|
|
|
174
188
|
text: input.text,
|
|
175
189
|
re: target.re ?? target.id,
|
|
176
190
|
labels: input.labels,
|
|
191
|
+
attachments: input.attachments,
|
|
177
192
|
key: input.key,
|
|
178
193
|
});
|
|
179
194
|
if (created) {
|
|
@@ -219,6 +234,7 @@ export function createMemoryBoard(options = {}) {
|
|
|
219
234
|
text: input.text,
|
|
220
235
|
re: null,
|
|
221
236
|
labels: input.labels,
|
|
237
|
+
attachments: input.attachments,
|
|
222
238
|
key: input.key,
|
|
223
239
|
});
|
|
224
240
|
if (!created) {
|