@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/module.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineModule, makeDefinitionStore } from '@swirls/looms/core';
|
|
2
|
-
import { activateEffect, claimTaskEffect, createTaskEffect, labelEffect, listTasksEffect, postEffect, pullEffect, readEffect, replyEffect, settleTaskEffect, } from './effects.js';
|
|
2
|
+
import { activateEffect, claimTaskEffect, createTaskEffect, labelEffect, listTasksEffect, postEffect, pullEffect, readEffect, replyEffect, settleTaskEffect, viewEffect, } from './effects.js';
|
|
3
3
|
import { swarmStatus } from './projections.js';
|
|
4
4
|
import { swarmModule } from './scope.js';
|
|
5
5
|
import { SwarmServicesLive, memoryBoards } from './services.js';
|
|
@@ -20,6 +20,7 @@ export function swarm(options = {}) {
|
|
|
20
20
|
post: postEffect,
|
|
21
21
|
reply: replyEffect,
|
|
22
22
|
read: readEffect,
|
|
23
|
+
view: viewEffect,
|
|
23
24
|
label: labelEffect,
|
|
24
25
|
createTask: createTaskEffect,
|
|
25
26
|
listTasks: listTasksEffect,
|
|
@@ -51,6 +52,7 @@ export function swarm(options = {}) {
|
|
|
51
52
|
re: null,
|
|
52
53
|
mentions: ['triage'],
|
|
53
54
|
labels: {},
|
|
55
|
+
attachments: [],
|
|
54
56
|
createdAt: 1_000,
|
|
55
57
|
},
|
|
56
58
|
},
|
package/dist/swarm/prompt.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import type { Attachment } from '@swirls/looms/agent';
|
|
1
2
|
import type { BoardEvent } from './board';
|
|
2
3
|
import type { SwarmDefinition, SwarmMember } from './definitions';
|
|
4
|
+
/** Files shown to a member when it is woken. It reads the rest with `board_view`. */
|
|
5
|
+
export declare const ACTIVATION_ATTACHMENT_LIMIT = 10;
|
|
6
|
+
/** The distinct files on the messages of `events`, oldest first, up to the activation limit. */
|
|
7
|
+
export declare function activationAttachments(events: readonly BoardEvent[]): Attachment[];
|
|
3
8
|
/** The first user message of a member's run: who it is, who else is here, and what happened. */
|
|
4
9
|
export declare function activationPrompt(definition: SwarmDefinition, member: SwarmMember, events: readonly BoardEvent[]): string;
|
package/dist/swarm/prompt.js
CHANGED
|
@@ -1,18 +1,42 @@
|
|
|
1
1
|
const TEXT_LIMIT = 600;
|
|
2
|
+
/** Files shown to a member when it is woken. It reads the rest with `board_view`. */
|
|
3
|
+
export const ACTIVATION_ATTACHMENT_LIMIT = 10;
|
|
4
|
+
/** The distinct files on the messages of `events`, oldest first, up to the activation limit. */
|
|
5
|
+
export function activationAttachments(events) {
|
|
6
|
+
const files = new Map();
|
|
7
|
+
for (const event of events) {
|
|
8
|
+
for (const file of event.message?.attachments ?? []) {
|
|
9
|
+
if (!files.has(file.id)) {
|
|
10
|
+
files.set(file.id, file);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return [...files.values()].slice(0, ACTIVATION_ATTACHMENT_LIMIT);
|
|
15
|
+
}
|
|
2
16
|
function clip(text) {
|
|
3
17
|
return text.length > TEXT_LIMIT ? `${text.slice(0, TEXT_LIMIT)}…` : text;
|
|
4
18
|
}
|
|
19
|
+
function describeFiles(event) {
|
|
20
|
+
const files = event.message?.attachments ?? [];
|
|
21
|
+
if (files.length === 0) {
|
|
22
|
+
return '';
|
|
23
|
+
}
|
|
24
|
+
const listed = files.map((file) => file.name
|
|
25
|
+
? `${file.name} (${file.mediaType}, id "${file.id}")`
|
|
26
|
+
: `"${file.id}" (${file.mediaType})`);
|
|
27
|
+
return ` [files: ${listed.join(', ')}]`;
|
|
28
|
+
}
|
|
5
29
|
function describeEvent(event, member) {
|
|
6
30
|
const { message, task } = event;
|
|
7
31
|
if (task) {
|
|
8
32
|
const assigned = task.for === member ? ' (assigned to you)' : '';
|
|
9
33
|
const what = event.type === 'task.created' ? `created by ${task.by}` : event.type.slice(5);
|
|
10
|
-
return `- task [${task.id}] in ${task.channel}, ${what}, now ${task.state}${assigned}: ${clip(task.text)}`;
|
|
34
|
+
return `- task [${task.id}] in ${task.channel}, ${what}, now ${task.state}${assigned}: ${clip(task.text)}${describeFiles(event)}`;
|
|
11
35
|
}
|
|
12
36
|
if (message) {
|
|
13
37
|
const where = message.re === null ? message.channel : `${message.channel}, thread [${message.re}]`;
|
|
14
38
|
const mentioned = message.mentions.includes(member) ? ' (mentions you)' : '';
|
|
15
|
-
return `- message [${message.id}] by ${message.by} in ${where}${mentioned}: ${clip(message.text)}`;
|
|
39
|
+
return `- message [${message.id}] by ${message.by} in ${where}${mentioned}: ${clip(message.text)}${describeFiles(event)}`;
|
|
16
40
|
}
|
|
17
41
|
return `- ${event.type} by ${event.by}`;
|
|
18
42
|
}
|
|
@@ -25,6 +49,7 @@ export function activationPrompt(definition, member, events) {
|
|
|
25
49
|
`You are "${member.name}", a member of the "${definition.name}" swarm.`,
|
|
26
50
|
'The swarm shares one message board, and it is the only way members coordinate. Nothing you write outside the board reaches anyone. You keep no memory between activations, so put anything worth keeping on the board.',
|
|
27
51
|
'Use the board tools to read threads, reply, hand work over by mentioning a member with @name or by creating a task, and claim a task before you work on it. Settle every task you claim.',
|
|
52
|
+
`Messages and tasks can carry files such as screenshots and recordings. The files on the activity below are attached to this message, up to ${ACTIVATION_ATTACHMENT_LIMIT} of them. Call board_view to look at the files on any other message. To share a file, pass its reference in \`attachments\` when you post, reply, or create a task.`,
|
|
28
53
|
definition.instructions,
|
|
29
54
|
others.length > 0 ? `Other members:\n${others.join('\n')}` : undefined,
|
|
30
55
|
`New on the board for you, oldest first:\n${events.map((event) => describeEvent(event, member.name)).join('\n')}`,
|
package/dist/swarm/scope.d.ts
CHANGED
|
@@ -17,6 +17,13 @@ export declare const swarmModule: import("@swirls/looms/core").ModuleScope<"swar
|
|
|
17
17
|
readonly re: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
18
18
|
readonly mentions: import("effect/Schema").$Array<import("effect/Schema").String>;
|
|
19
19
|
readonly labels: import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").String>;
|
|
20
|
+
readonly attachments: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
21
|
+
readonly id: import("effect/Schema").String;
|
|
22
|
+
readonly mediaType: import("effect/Schema").String;
|
|
23
|
+
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
24
|
+
readonly size: import("effect/Schema").optional<import("effect/Schema").Finite>;
|
|
25
|
+
readonly url: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
26
|
+
}>>;
|
|
20
27
|
readonly createdAt: import("effect/Schema").Finite;
|
|
21
28
|
}>>;
|
|
22
29
|
readonly task: import("effect/Schema").optional<import("effect/Schema").Struct<{
|
|
@@ -59,6 +66,13 @@ export declare const swarmModule: import("@swirls/looms/core").ModuleScope<"swar
|
|
|
59
66
|
readonly re: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
60
67
|
readonly mentions: import("effect/Schema").$Array<import("effect/Schema").String>;
|
|
61
68
|
readonly labels: import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").String>;
|
|
69
|
+
readonly attachments: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
70
|
+
readonly id: import("effect/Schema").String;
|
|
71
|
+
readonly mediaType: import("effect/Schema").String;
|
|
72
|
+
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
73
|
+
readonly size: import("effect/Schema").optional<import("effect/Schema").Finite>;
|
|
74
|
+
readonly url: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
75
|
+
}>>;
|
|
62
76
|
readonly createdAt: import("effect/Schema").Finite;
|
|
63
77
|
}>;
|
|
64
78
|
}>;
|
|
@@ -73,6 +87,13 @@ export declare const swarmModule: import("@swirls/looms/core").ModuleScope<"swar
|
|
|
73
87
|
readonly re: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
74
88
|
readonly mentions: import("effect/Schema").$Array<import("effect/Schema").String>;
|
|
75
89
|
readonly labels: import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").String>;
|
|
90
|
+
readonly attachments: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
91
|
+
readonly id: import("effect/Schema").String;
|
|
92
|
+
readonly mediaType: import("effect/Schema").String;
|
|
93
|
+
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
94
|
+
readonly size: import("effect/Schema").optional<import("effect/Schema").Finite>;
|
|
95
|
+
readonly url: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
96
|
+
}>>;
|
|
76
97
|
readonly createdAt: import("effect/Schema").Finite;
|
|
77
98
|
}>;
|
|
78
99
|
}>;
|
|
@@ -87,9 +108,28 @@ export declare const swarmModule: import("@swirls/looms/core").ModuleScope<"swar
|
|
|
87
108
|
readonly re: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
88
109
|
readonly mentions: import("effect/Schema").$Array<import("effect/Schema").String>;
|
|
89
110
|
readonly labels: import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").String>;
|
|
111
|
+
readonly attachments: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
112
|
+
readonly id: import("effect/Schema").String;
|
|
113
|
+
readonly mediaType: import("effect/Schema").String;
|
|
114
|
+
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
115
|
+
readonly size: import("effect/Schema").optional<import("effect/Schema").Finite>;
|
|
116
|
+
readonly url: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
117
|
+
}>>;
|
|
90
118
|
readonly createdAt: import("effect/Schema").Finite;
|
|
91
119
|
}>>;
|
|
92
120
|
}>;
|
|
121
|
+
'attachments.viewed': import("effect/Schema").Struct<{
|
|
122
|
+
readonly callId: import("effect/Schema").String;
|
|
123
|
+
readonly board: import("effect/Schema").String;
|
|
124
|
+
readonly message: import("effect/Schema").String;
|
|
125
|
+
readonly attachments: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
126
|
+
readonly id: import("effect/Schema").String;
|
|
127
|
+
readonly mediaType: import("effect/Schema").String;
|
|
128
|
+
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
129
|
+
readonly size: import("effect/Schema").optional<import("effect/Schema").Finite>;
|
|
130
|
+
readonly url: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
131
|
+
}>>;
|
|
132
|
+
}>;
|
|
93
133
|
'task.created': import("effect/Schema").Struct<{
|
|
94
134
|
readonly callId: import("effect/Schema").String;
|
|
95
135
|
readonly board: import("effect/Schema").String;
|
|
@@ -194,6 +234,13 @@ export declare const swarmModule: import("@swirls/looms/core").ModuleScope<"swar
|
|
|
194
234
|
readonly re: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
195
235
|
readonly mentions: import("effect/Schema").$Array<import("effect/Schema").String>;
|
|
196
236
|
readonly labels: import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").String>;
|
|
237
|
+
readonly attachments: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
238
|
+
readonly id: import("effect/Schema").String;
|
|
239
|
+
readonly mediaType: import("effect/Schema").String;
|
|
240
|
+
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
241
|
+
readonly size: import("effect/Schema").optional<import("effect/Schema").Finite>;
|
|
242
|
+
readonly url: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
243
|
+
}>>;
|
|
197
244
|
readonly createdAt: import("effect/Schema").Finite;
|
|
198
245
|
}>>;
|
|
199
246
|
readonly task: import("effect/Schema").optional<import("effect/Schema").Struct<{
|
|
@@ -236,6 +283,13 @@ export declare const swarmModule: import("@swirls/looms/core").ModuleScope<"swar
|
|
|
236
283
|
readonly re: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
237
284
|
readonly mentions: import("effect/Schema").$Array<import("effect/Schema").String>;
|
|
238
285
|
readonly labels: import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").String>;
|
|
286
|
+
readonly attachments: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
287
|
+
readonly id: import("effect/Schema").String;
|
|
288
|
+
readonly mediaType: import("effect/Schema").String;
|
|
289
|
+
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
290
|
+
readonly size: import("effect/Schema").optional<import("effect/Schema").Finite>;
|
|
291
|
+
readonly url: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
292
|
+
}>>;
|
|
239
293
|
readonly createdAt: import("effect/Schema").Finite;
|
|
240
294
|
}>;
|
|
241
295
|
}>;
|
|
@@ -250,6 +304,13 @@ export declare const swarmModule: import("@swirls/looms/core").ModuleScope<"swar
|
|
|
250
304
|
readonly re: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
251
305
|
readonly mentions: import("effect/Schema").$Array<import("effect/Schema").String>;
|
|
252
306
|
readonly labels: import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").String>;
|
|
307
|
+
readonly attachments: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
308
|
+
readonly id: import("effect/Schema").String;
|
|
309
|
+
readonly mediaType: import("effect/Schema").String;
|
|
310
|
+
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
311
|
+
readonly size: import("effect/Schema").optional<import("effect/Schema").Finite>;
|
|
312
|
+
readonly url: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
313
|
+
}>>;
|
|
253
314
|
readonly createdAt: import("effect/Schema").Finite;
|
|
254
315
|
}>;
|
|
255
316
|
}>;
|
|
@@ -264,9 +325,28 @@ export declare const swarmModule: import("@swirls/looms/core").ModuleScope<"swar
|
|
|
264
325
|
readonly re: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
265
326
|
readonly mentions: import("effect/Schema").$Array<import("effect/Schema").String>;
|
|
266
327
|
readonly labels: import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").String>;
|
|
328
|
+
readonly attachments: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
329
|
+
readonly id: import("effect/Schema").String;
|
|
330
|
+
readonly mediaType: import("effect/Schema").String;
|
|
331
|
+
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
332
|
+
readonly size: import("effect/Schema").optional<import("effect/Schema").Finite>;
|
|
333
|
+
readonly url: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
334
|
+
}>>;
|
|
267
335
|
readonly createdAt: import("effect/Schema").Finite;
|
|
268
336
|
}>>;
|
|
269
337
|
}>;
|
|
338
|
+
'attachments.viewed': import("effect/Schema").Struct<{
|
|
339
|
+
readonly callId: import("effect/Schema").String;
|
|
340
|
+
readonly board: import("effect/Schema").String;
|
|
341
|
+
readonly message: import("effect/Schema").String;
|
|
342
|
+
readonly attachments: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
343
|
+
readonly id: import("effect/Schema").String;
|
|
344
|
+
readonly mediaType: import("effect/Schema").String;
|
|
345
|
+
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
346
|
+
readonly size: import("effect/Schema").optional<import("effect/Schema").Finite>;
|
|
347
|
+
readonly url: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
348
|
+
}>>;
|
|
349
|
+
}>;
|
|
270
350
|
'task.created': import("effect/Schema").Struct<{
|
|
271
351
|
readonly callId: import("effect/Schema").String;
|
|
272
352
|
readonly board: import("effect/Schema").String;
|
package/dist/swarm/services.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Context, Effect, Layer } from 'effect';
|
|
2
2
|
import type { DefinitionStore } from '@swirls/looms/core';
|
|
3
|
-
import { BoardError, type BoardResolver, type MessageBoard } from './board';
|
|
3
|
+
import { BoardError, type BoardCaller, type BoardResolver, type MessageBoard } from './board';
|
|
4
4
|
import type { SwarmDefinition } from './definitions';
|
|
5
5
|
export type SwarmDefinitionStore = DefinitionStore<SwarmDefinition>;
|
|
6
6
|
declare const SwarmDefinitionsTag_base: Context.ServiceClass<SwarmDefinitionsTag, "looms/SwarmDefinitions", SwarmDefinitionStore>;
|
|
@@ -17,7 +17,7 @@ export declare class BoardFaultError extends BoardFaultError_base<{
|
|
|
17
17
|
}
|
|
18
18
|
export interface Boards {
|
|
19
19
|
/** Run one call against a board. Refusals fail with `BoardError`, faults with `BoardFaultError`. */
|
|
20
|
-
readonly call: <A>(boardId: string, run: (board: MessageBoard) => Promise<A>) => Effect.Effect<A, BoardError | BoardFaultError>;
|
|
20
|
+
readonly call: <A>(boardId: string, caller: BoardCaller, run: (board: MessageBoard) => Promise<A>) => Effect.Effect<A, BoardError | BoardFaultError>;
|
|
21
21
|
}
|
|
22
22
|
declare const BoardsTag_base: Context.ServiceClass<BoardsTag, "looms/SwarmBoards", Boards>;
|
|
23
23
|
export declare class BoardsTag extends BoardsTag_base {
|
package/dist/swarm/services.js
CHANGED
|
@@ -18,8 +18,11 @@ function fault(cause) {
|
|
|
18
18
|
}
|
|
19
19
|
export function makeBoards(resolve) {
|
|
20
20
|
return {
|
|
21
|
-
call: (boardId, run) => Effect.tryPromise({
|
|
22
|
-
|
|
21
|
+
call: (boardId, caller, run) => Effect.tryPromise({
|
|
22
|
+
// Inside the promise so a resolver that throws is a refusal or a fault, not a defect.
|
|
23
|
+
try: () => Promise.resolve()
|
|
24
|
+
.then(() => resolve(boardId, caller))
|
|
25
|
+
.then(run),
|
|
23
26
|
catch: fault,
|
|
24
27
|
}),
|
|
25
28
|
};
|
package/dist/swarm/threads.d.ts
CHANGED
|
@@ -24,6 +24,8 @@ export interface SwarmState {
|
|
|
24
24
|
readonly cursor: string | null;
|
|
25
25
|
/** Completed pulls. Names the next pull, so each pull effect has its own tag. */
|
|
26
26
|
readonly pulls: number;
|
|
27
|
+
/** Pulls that have failed in a row since the last one that worked. */
|
|
28
|
+
readonly pullFailures: number;
|
|
27
29
|
/** Read the board as soon as possible. */
|
|
28
30
|
readonly pullNow: boolean;
|
|
29
31
|
/** Otherwise read it at this time, or not until nudged when null. */
|
|
@@ -38,4 +40,6 @@ export interface SwarmState {
|
|
|
38
40
|
}
|
|
39
41
|
/** Whether a board event should wake `member`. A member is never woken by its own writes. */
|
|
40
42
|
export declare function concerns(member: SwarmMember, event: BoardEvent): boolean;
|
|
43
|
+
/** The longest a swarm waits before it tries an unreachable board again. */
|
|
44
|
+
export declare const MAX_PULL_BACKOFF_MS: number;
|
|
41
45
|
export declare function createSwarmThread(definitions: DefinitionStore<SwarmDefinition>): ThreadDefinition<SwarmState>;
|
package/dist/swarm/threads.js
CHANGED
|
@@ -86,6 +86,12 @@ function cutBatches(state) {
|
|
|
86
86
|
function requestPull(state) {
|
|
87
87
|
return state.pullNow ? { ...state, dirty: true } : { ...state, pullNow: true };
|
|
88
88
|
}
|
|
89
|
+
/** The longest a swarm waits before it tries an unreachable board again. */
|
|
90
|
+
export const MAX_PULL_BACKOFF_MS = 15 * 60_000;
|
|
91
|
+
const PULL_BACKOFF_MS = 30_000;
|
|
92
|
+
function pullTag(state, when) {
|
|
93
|
+
return `pull:${state.pulls}:${state.pullFailures}:${when}`;
|
|
94
|
+
}
|
|
89
95
|
function activationTag(member, activation) {
|
|
90
96
|
return `activate:${member}:${activation}`;
|
|
91
97
|
}
|
|
@@ -104,6 +110,7 @@ export function createSwarmThread(definitions) {
|
|
|
104
110
|
board: config.board ?? ctx.runId,
|
|
105
111
|
cursor: config.after ?? null,
|
|
106
112
|
pulls: 0,
|
|
113
|
+
pullFailures: 0,
|
|
107
114
|
pullNow: true,
|
|
108
115
|
nextPullAt: null,
|
|
109
116
|
dirty: false,
|
|
@@ -125,6 +132,7 @@ export function createSwarmThread(definitions) {
|
|
|
125
132
|
...state,
|
|
126
133
|
cursor: event.payload.cursor,
|
|
127
134
|
pulls: state.pulls + 1,
|
|
135
|
+
pullFailures: 0,
|
|
128
136
|
pullNow: state.dirty || event.payload.more,
|
|
129
137
|
nextPullAt: event.payload.nextPullAt,
|
|
130
138
|
dirty: false,
|
|
@@ -166,6 +174,20 @@ export function createSwarmThread(definitions) {
|
|
|
166
174
|
}
|
|
167
175
|
case 'runtime.effect.failed': {
|
|
168
176
|
const tag = event.effectId ? parseEffectId(event.effectId)?.tag : undefined;
|
|
177
|
+
if (event.threadId === ctx.threadId && tag?.startsWith(pullTag(state, ''))) {
|
|
178
|
+
// A board that refuses the swarm will refuse it again, so the swarm fails where
|
|
179
|
+
// someone will see it. An unreachable board is tried again, less and less often.
|
|
180
|
+
if (event.payload.nonRetryable) {
|
|
181
|
+
return { ...state, invalid: event.payload.error || 'the board refused the swarm' };
|
|
182
|
+
}
|
|
183
|
+
const backoff = Math.min(PULL_BACKOFF_MS * 2 ** state.pullFailures, MAX_PULL_BACKOFF_MS);
|
|
184
|
+
return {
|
|
185
|
+
...state,
|
|
186
|
+
pullFailures: state.pullFailures + 1,
|
|
187
|
+
pullNow: false,
|
|
188
|
+
nextPullAt: event.ts + backoff,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
169
191
|
const entry = Object.entries(state.members).find(([name, member]) => member.batch !== null && tag === activationTag(name, member.activations));
|
|
170
192
|
if (!entry || event.threadId !== ctx.threadId) {
|
|
171
193
|
return state;
|
|
@@ -220,10 +242,10 @@ export function createSwarmThread(definitions) {
|
|
|
220
242
|
const effects = [];
|
|
221
243
|
const pull = { ...definition, board: state.board, after: state.cursor, pull: state.pulls };
|
|
222
244
|
if (state.pullNow) {
|
|
223
|
-
effects.push(invoke(pullEffect, pull,
|
|
245
|
+
effects.push(invoke(pullEffect, pull, pullTag(state, 'now')));
|
|
224
246
|
}
|
|
225
247
|
else if (state.nextPullAt !== null) {
|
|
226
|
-
effects.push(invoke(pullEffect, pull,
|
|
248
|
+
effects.push(invoke(pullEffect, pull, pullTag(state, String(state.nextPullAt)), {
|
|
227
249
|
at: state.nextPullAt,
|
|
228
250
|
}));
|
|
229
251
|
}
|
package/dist/swarm/tools.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Predicate } from 'effect';
|
|
|
2
2
|
import { asEffectsTool } from '@swirls/looms/agent';
|
|
3
3
|
import { invoke, typeIds } from '@swirls/looms/core';
|
|
4
4
|
import { readActivation } from './definitions.js';
|
|
5
|
-
import { ClaimTaskArgsSchema, CreateTaskArgsSchema, LabelArgsSchema, ListTasksArgsSchema, PostArgsSchema, ReadArgsSchema, ReplyArgsSchema, SettleTaskArgsSchema, claimTaskEffect, createTaskEffect, labelEffect, listTasksEffect, postEffect, readEffect, replyEffect, settleTaskEffect, } from './effects.js';
|
|
5
|
+
import { ClaimTaskArgsSchema, CreateTaskArgsSchema, LabelArgsSchema, ListTasksArgsSchema, PostArgsSchema, ReadArgsSchema, ReplyArgsSchema, SettleTaskArgsSchema, ViewArgsSchema, claimTaskEffect, createTaskEffect, labelEffect, listTasksEffect, postEffect, readEffect, replyEffect, settleTaskEffect, viewEffect, } from './effects.js';
|
|
6
6
|
/**
|
|
7
7
|
* A tool whose call becomes one board effect. The agent waits for the event that carries the
|
|
8
8
|
* same `callId`: the board's answer, or `swarm.call.rejected` when the board refused.
|
|
@@ -28,21 +28,28 @@ export function boardTools(binding, ids = typeIds) {
|
|
|
28
28
|
return [
|
|
29
29
|
boardTool(binding, {
|
|
30
30
|
name: 'board_read',
|
|
31
|
-
description: 'Read messages from the board, oldest first. Pass `thread` with a message id to read a whole thread, `channel` to read a channel ("support") or a subtree ("support/"), or `mentionsMe` for messages that mention you. Without `after` you get the latest `limit` matches.',
|
|
31
|
+
description: 'Read messages from the board, oldest first. Pass `thread` with a message id to read a whole thread, `channel` to read a channel ("support") or a subtree ("support/"), or `mentionsMe` for messages that mention you. Without `after` you get the latest `limit` matches. A message lists its files under `attachments`. To look at them, call board_view.',
|
|
32
32
|
input: ReadArgsSchema,
|
|
33
33
|
effect: readEffect,
|
|
34
34
|
answer: 'swarm.messages.read',
|
|
35
35
|
}, ids),
|
|
36
|
+
boardTool(binding, {
|
|
37
|
+
name: 'board_view',
|
|
38
|
+
description: 'Look at the files attached to one message or task, such as a screenshot or a recording. The files are shown to you with the result.',
|
|
39
|
+
input: ViewArgsSchema,
|
|
40
|
+
effect: viewEffect,
|
|
41
|
+
answer: 'swarm.attachments.viewed',
|
|
42
|
+
}, ids),
|
|
36
43
|
boardTool(binding, {
|
|
37
44
|
name: 'board_post',
|
|
38
|
-
description: 'Start a new thread in a channel. Mention a member with @name to wake them. To continue an existing thread, use board_reply.',
|
|
45
|
+
description: 'Start a new thread in a channel. Mention a member with @name to wake them. To continue an existing thread, use board_reply. Pass `attachments` to share files: each is a reference `{ id, mediaType, name }` copied from a message or from the tool that produced the file.',
|
|
39
46
|
input: PostArgsSchema,
|
|
40
47
|
effect: postEffect,
|
|
41
48
|
answer: 'swarm.message.posted',
|
|
42
49
|
}, ids),
|
|
43
50
|
boardTool(binding, {
|
|
44
51
|
name: 'board_reply',
|
|
45
|
-
description: 'Reply in the thread of message `to`. Use it to answer, report progress on a task, or mention a member with @name.',
|
|
52
|
+
description: 'Reply in the thread of message `to`. Use it to answer, report progress on a task, or mention a member with @name. Pass `attachments` to share files.',
|
|
46
53
|
input: ReplyArgsSchema,
|
|
47
54
|
effect: replyEffect,
|
|
48
55
|
answer: 'swarm.message.posted',
|
|
@@ -56,7 +63,7 @@ export function boardTools(binding, ids = typeIds) {
|
|
|
56
63
|
}, ids),
|
|
57
64
|
boardTool(binding, {
|
|
58
65
|
name: 'board_create_task',
|
|
59
|
-
description: 'Put a unit of work on the board for a member to claim. Pass `for` to assign it to one member, and `needs` with task ids that must complete first. The text is the instructions for whoever claims it.',
|
|
66
|
+
description: 'Put a unit of work on the board for a member to claim. Pass `for` to assign it to one member, and `needs` with task ids that must complete first. The text is the instructions for whoever claims it. Pass `attachments` for files the work needs.',
|
|
60
67
|
input: CreateTaskArgsSchema,
|
|
61
68
|
effect: createTaskEffect,
|
|
62
69
|
answer: 'swarm.task.created',
|