@swirls/looms 0.23.0 → 0.25.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 +22 -0
- package/dist/agent/threads.js +4 -1
- package/dist/approval/effects.d.ts +26 -26
- package/dist/approval/module.d.ts +52 -52
- package/dist/debugger/app/assets/index-GLtrulmj.js +23 -0
- package/dist/debugger/app/assets/{routes-Ch30UGik.js → routes-CECZJJob.js} +1 -1
- package/dist/debugger/app/index.html +1 -1
- package/dist/evaluator/effects.d.ts +33 -33
- package/dist/evaluator/module.d.ts +66 -66
- package/dist/nats/index.d.ts +1 -1
- package/dist/nats/index.js +1 -1
- package/dist/nats/projector.d.ts +17 -0
- package/dist/nats/projector.js +29 -8
- package/dist/nats/subjects.d.ts +8 -0
- package/dist/nats/subjects.js +10 -0
- package/dist/nats/transport.d.ts +10 -0
- package/dist/nats/transport.js +13 -4
- package/dist/swarm/board.d.ts +292 -0
- package/dist/swarm/board.js +123 -0
- package/dist/swarm/conformance.d.ts +15 -0
- package/dist/swarm/conformance.js +225 -0
- package/dist/swarm/definitions.d.ts +94 -0
- package/dist/swarm/definitions.js +51 -0
- package/dist/swarm/effects.d.ts +4720 -0
- package/dist/swarm/effects.js +296 -0
- package/dist/swarm/ensure.d.ts +16 -0
- package/dist/swarm/ensure.js +24 -0
- package/dist/swarm/events.d.ts +240 -0
- package/dist/swarm/events.js +49 -0
- package/dist/swarm/index.d.ts +15 -0
- package/dist/swarm/index.js +15 -0
- package/dist/swarm/memory-board.d.ts +10 -0
- package/dist/swarm/memory-board.js +344 -0
- package/dist/swarm/module.d.ts +9593 -0
- package/dist/swarm/module.js +94 -0
- package/dist/swarm/projections.d.ts +60 -0
- package/dist/swarm/projections.js +102 -0
- package/dist/swarm/prompt.d.ts +4 -0
- package/dist/swarm/prompt.js +35 -0
- package/dist/swarm/scope.d.ts +357 -0
- package/dist/swarm/scope.js +8 -0
- package/dist/swarm/services.d.ts +29 -0
- package/dist/swarm/services.js +40 -0
- package/dist/swarm/signals.d.ts +14 -0
- package/dist/swarm/signals.js +15 -0
- package/dist/swarm/steps.d.ts +15 -0
- package/dist/swarm/steps.js +27 -0
- package/dist/swarm/threads.d.ts +41 -0
- package/dist/swarm/threads.js +244 -0
- package/dist/swarm/tools.d.ts +19 -0
- package/dist/swarm/tools.js +100 -0
- package/package.json +7 -2
- package/dist/debugger/app/assets/index-CxbIGkpY.js +0 -22
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { Clock, Effect, Schema } from 'effect';
|
|
2
|
+
import { DEFAULT_DEFINITION_VERSION, RunLauncherTag, cleanUndefined, failEffect, } from '@swirls/looms/core';
|
|
3
|
+
import { BoardEventSchema, BoardLabelsSchema, TaskStateSchema } from './board.js';
|
|
4
|
+
import { activationPrompt } from './prompt.js';
|
|
5
|
+
import { swarmModule } from './scope.js';
|
|
6
|
+
import { BoardsTag, SwarmDefinitionsTag } from './services.js';
|
|
7
|
+
const RETRY = { maxAttempts: 5, backoffMs: 1_000, maxBackoffMs: 60_000 };
|
|
8
|
+
/** Board events read per pull. A fuller board is read over several pulls. */
|
|
9
|
+
export const PULL_LIMIT = 50;
|
|
10
|
+
const DefinitionFields = {
|
|
11
|
+
definitionName: Schema.String,
|
|
12
|
+
definitionVersion: Schema.String,
|
|
13
|
+
};
|
|
14
|
+
const PullInputSchema = Schema.Struct({
|
|
15
|
+
...DefinitionFields,
|
|
16
|
+
board: Schema.String,
|
|
17
|
+
after: Schema.NullOr(Schema.String),
|
|
18
|
+
pull: Schema.Finite,
|
|
19
|
+
});
|
|
20
|
+
const ActivateInputSchema = Schema.Struct({
|
|
21
|
+
...DefinitionFields,
|
|
22
|
+
board: Schema.String,
|
|
23
|
+
member: Schema.String,
|
|
24
|
+
activation: Schema.Finite,
|
|
25
|
+
events: Schema.Array(BoardEventSchema),
|
|
26
|
+
});
|
|
27
|
+
export const pullEffect = swarmModule.effect({
|
|
28
|
+
type: 'swarm.pull',
|
|
29
|
+
placement: 'local',
|
|
30
|
+
input: PullInputSchema,
|
|
31
|
+
retry: RETRY,
|
|
32
|
+
execute: (input, ctx) => Effect.gen(function* () {
|
|
33
|
+
const boards = yield* BoardsTag;
|
|
34
|
+
const definitions = yield* SwarmDefinitionsTag;
|
|
35
|
+
const now = yield* Clock.currentTimeMillis;
|
|
36
|
+
const definition = yield* definitions.resolve(input.definitionName, input.definitionVersion);
|
|
37
|
+
const page = yield* boards.call(input.board, (board) => board.events({ after: input.after ?? undefined, limit: PULL_LIMIT }));
|
|
38
|
+
const interval = definition?.pollIntervalMs ?? null;
|
|
39
|
+
return [
|
|
40
|
+
swarmModule.input('board.pulled', {
|
|
41
|
+
board: input.board,
|
|
42
|
+
pull: input.pull,
|
|
43
|
+
cursor: page.cursor,
|
|
44
|
+
events: page.events,
|
|
45
|
+
more: page.more,
|
|
46
|
+
nextPullAt: interval === null ? null : now + interval,
|
|
47
|
+
}, { threadId: ctx.threadId }),
|
|
48
|
+
];
|
|
49
|
+
}),
|
|
50
|
+
});
|
|
51
|
+
/** The run id of a member's activation. Derived, so a retried activation starts the same run. */
|
|
52
|
+
export function activationRunId(swarmRunId, member, activation) {
|
|
53
|
+
return `${swarmRunId}:${member}:${activation}`;
|
|
54
|
+
}
|
|
55
|
+
export const activateEffect = swarmModule.effect({
|
|
56
|
+
type: 'swarm.activate',
|
|
57
|
+
placement: 'local',
|
|
58
|
+
input: ActivateInputSchema,
|
|
59
|
+
retry: RETRY,
|
|
60
|
+
execute: (input, ctx) => Effect.gen(function* () {
|
|
61
|
+
const definitions = yield* SwarmDefinitionsTag;
|
|
62
|
+
const launcher = yield* RunLauncherTag;
|
|
63
|
+
const now = yield* Clock.currentTimeMillis;
|
|
64
|
+
const definition = yield* definitions.resolve(input.definitionName, input.definitionVersion);
|
|
65
|
+
const member = definition?.members.find((item) => item.name === input.member);
|
|
66
|
+
if (!definition || !member) {
|
|
67
|
+
return yield* failEffect({
|
|
68
|
+
error: `Swarm "${input.definitionName}@${input.definitionVersion}" has no member "${input.member}"`,
|
|
69
|
+
nonRetryable: true,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
const runId = activationRunId(ctx.runId, member.name, input.activation);
|
|
73
|
+
const activation = {
|
|
74
|
+
prompt: activationPrompt(definition, member, input.events),
|
|
75
|
+
swarm: {
|
|
76
|
+
name: definition.name,
|
|
77
|
+
runId: ctx.runId,
|
|
78
|
+
board: input.board,
|
|
79
|
+
member: member.name,
|
|
80
|
+
activation: input.activation,
|
|
81
|
+
},
|
|
82
|
+
events: input.events,
|
|
83
|
+
};
|
|
84
|
+
yield* launcher.launch({
|
|
85
|
+
runId,
|
|
86
|
+
kind: member.agent.kind,
|
|
87
|
+
definitionName: member.agent.name,
|
|
88
|
+
definitionVersion: member.agent.version ?? DEFAULT_DEFINITION_VERSION,
|
|
89
|
+
input: cleanUndefined(activation),
|
|
90
|
+
idempotencyKey: runId,
|
|
91
|
+
});
|
|
92
|
+
return [
|
|
93
|
+
swarmModule.input('member.activated', {
|
|
94
|
+
board: input.board,
|
|
95
|
+
member: member.name,
|
|
96
|
+
activation: input.activation,
|
|
97
|
+
runId,
|
|
98
|
+
events: input.events.length,
|
|
99
|
+
at: now,
|
|
100
|
+
}, { threadId: ctx.threadId }),
|
|
101
|
+
];
|
|
102
|
+
}),
|
|
103
|
+
});
|
|
104
|
+
/** Who is calling which board. `callId` pairs the resulting event with the caller's wait. */
|
|
105
|
+
const CallerFields = {
|
|
106
|
+
callId: Schema.String,
|
|
107
|
+
board: Schema.String,
|
|
108
|
+
as: Schema.String,
|
|
109
|
+
};
|
|
110
|
+
export const PostArgsSchema = Schema.Struct({
|
|
111
|
+
channel: Schema.String,
|
|
112
|
+
text: Schema.String,
|
|
113
|
+
labels: Schema.optional(BoardLabelsSchema),
|
|
114
|
+
});
|
|
115
|
+
export const ReplyArgsSchema = Schema.Struct({
|
|
116
|
+
/** Any message of the thread to reply in. */
|
|
117
|
+
to: Schema.String,
|
|
118
|
+
text: Schema.String,
|
|
119
|
+
});
|
|
120
|
+
export const ReadArgsSchema = Schema.Struct({
|
|
121
|
+
channel: Schema.optional(Schema.String),
|
|
122
|
+
thread: Schema.optional(Schema.String),
|
|
123
|
+
by: Schema.optional(Schema.String),
|
|
124
|
+
/** Only messages that mention the caller. */
|
|
125
|
+
mentionsMe: Schema.optional(Schema.Boolean),
|
|
126
|
+
after: Schema.optional(Schema.String),
|
|
127
|
+
limit: Schema.optional(Schema.Finite),
|
|
128
|
+
});
|
|
129
|
+
export const LabelArgsSchema = Schema.Struct({
|
|
130
|
+
message: Schema.String,
|
|
131
|
+
set: Schema.optional(BoardLabelsSchema),
|
|
132
|
+
unset: Schema.optional(Schema.Array(Schema.String)),
|
|
133
|
+
if: Schema.optional(Schema.Record(Schema.String, Schema.NullOr(Schema.String))),
|
|
134
|
+
});
|
|
135
|
+
export const CreateTaskArgsSchema = Schema.Struct({
|
|
136
|
+
channel: Schema.String,
|
|
137
|
+
text: Schema.String,
|
|
138
|
+
for: Schema.optional(Schema.String),
|
|
139
|
+
needs: Schema.optional(Schema.Array(Schema.String)),
|
|
140
|
+
});
|
|
141
|
+
export const ListTasksArgsSchema = Schema.Struct({
|
|
142
|
+
channel: Schema.optional(Schema.String),
|
|
143
|
+
state: Schema.optional(TaskStateSchema),
|
|
144
|
+
for: Schema.optional(Schema.String),
|
|
145
|
+
});
|
|
146
|
+
export const ClaimTaskArgsSchema = Schema.Struct({
|
|
147
|
+
task: Schema.optional(Schema.String),
|
|
148
|
+
channel: Schema.optional(Schema.String),
|
|
149
|
+
leaseMs: Schema.optional(Schema.Finite),
|
|
150
|
+
});
|
|
151
|
+
export const SettleTaskArgsSchema = Schema.Struct({
|
|
152
|
+
task: Schema.String,
|
|
153
|
+
token: Schema.String,
|
|
154
|
+
outcome: Schema.Union([
|
|
155
|
+
Schema.Literal('completed'),
|
|
156
|
+
Schema.Literal('failed'),
|
|
157
|
+
Schema.Literal('blocked'),
|
|
158
|
+
Schema.Literal('released'),
|
|
159
|
+
]),
|
|
160
|
+
note: Schema.optional(Schema.String),
|
|
161
|
+
});
|
|
162
|
+
/** A refusal is an answer, not a fault: record it so the caller's wait resolves with the error. */
|
|
163
|
+
function rejected(caller, threadId, error) {
|
|
164
|
+
return swarmModule.input('call.rejected', { callId: caller.callId, board: caller.board, code: error.code, error: error.message }, { threadId });
|
|
165
|
+
}
|
|
166
|
+
function answered(caller, threadId, call) {
|
|
167
|
+
return call.pipe(Effect.map((event) => [event]), Effect.catchTag('BoardError', (error) => Effect.succeed([rejected(caller, threadId, error)])));
|
|
168
|
+
}
|
|
169
|
+
export const postEffect = swarmModule.effect({
|
|
170
|
+
type: 'swarm.post',
|
|
171
|
+
placement: 'local',
|
|
172
|
+
input: Schema.Struct({ ...CallerFields, ...PostArgsSchema.fields }),
|
|
173
|
+
retry: RETRY,
|
|
174
|
+
execute: (input, ctx) => answered(input, ctx.threadId, Effect.gen(function* () {
|
|
175
|
+
const boards = yield* BoardsTag;
|
|
176
|
+
const message = yield* boards.call(input.board, (board) => board.post({
|
|
177
|
+
by: input.as,
|
|
178
|
+
channel: input.channel,
|
|
179
|
+
text: input.text,
|
|
180
|
+
labels: input.labels,
|
|
181
|
+
key: ctx.effectId,
|
|
182
|
+
}));
|
|
183
|
+
return swarmModule.input('message.posted', { callId: input.callId, board: input.board, message }, { threadId: ctx.threadId });
|
|
184
|
+
})),
|
|
185
|
+
});
|
|
186
|
+
export const replyEffect = swarmModule.effect({
|
|
187
|
+
type: 'swarm.reply',
|
|
188
|
+
placement: 'local',
|
|
189
|
+
input: Schema.Struct({ ...CallerFields, ...ReplyArgsSchema.fields }),
|
|
190
|
+
retry: RETRY,
|
|
191
|
+
execute: (input, ctx) => answered(input, ctx.threadId, Effect.gen(function* () {
|
|
192
|
+
const boards = yield* BoardsTag;
|
|
193
|
+
const message = yield* boards.call(input.board, (board) => board.reply({ by: input.as, to: input.to, text: input.text, key: ctx.effectId }));
|
|
194
|
+
return swarmModule.input('message.posted', { callId: input.callId, board: input.board, message }, { threadId: ctx.threadId });
|
|
195
|
+
})),
|
|
196
|
+
});
|
|
197
|
+
export const readEffect = swarmModule.effect({
|
|
198
|
+
type: 'swarm.read',
|
|
199
|
+
placement: 'local',
|
|
200
|
+
input: Schema.Struct({ ...CallerFields, ...ReadArgsSchema.fields }),
|
|
201
|
+
retry: RETRY,
|
|
202
|
+
execute: (input, ctx) => answered(input, ctx.threadId, Effect.gen(function* () {
|
|
203
|
+
const boards = yield* BoardsTag;
|
|
204
|
+
const messages = yield* boards.call(input.board, (board) => board.messages({
|
|
205
|
+
channel: input.channel,
|
|
206
|
+
thread: input.thread,
|
|
207
|
+
by: input.by,
|
|
208
|
+
mentions: input.mentionsMe ? input.as : undefined,
|
|
209
|
+
after: input.after,
|
|
210
|
+
limit: input.limit,
|
|
211
|
+
}));
|
|
212
|
+
return swarmModule.input('messages.read', { callId: input.callId, board: input.board, messages }, { threadId: ctx.threadId });
|
|
213
|
+
})),
|
|
214
|
+
});
|
|
215
|
+
export const labelEffect = swarmModule.effect({
|
|
216
|
+
type: 'swarm.label',
|
|
217
|
+
placement: 'local',
|
|
218
|
+
input: Schema.Struct({ ...CallerFields, ...LabelArgsSchema.fields }),
|
|
219
|
+
retry: RETRY,
|
|
220
|
+
execute: (input, ctx) => answered(input, ctx.threadId, Effect.gen(function* () {
|
|
221
|
+
const boards = yield* BoardsTag;
|
|
222
|
+
const message = yield* boards.call(input.board, (board) => board.label({
|
|
223
|
+
by: input.as,
|
|
224
|
+
message: input.message,
|
|
225
|
+
set: input.set,
|
|
226
|
+
unset: input.unset,
|
|
227
|
+
if: input.if,
|
|
228
|
+
}));
|
|
229
|
+
return swarmModule.input('message.labeled', { callId: input.callId, board: input.board, message }, { threadId: ctx.threadId });
|
|
230
|
+
})),
|
|
231
|
+
});
|
|
232
|
+
export const createTaskEffect = swarmModule.effect({
|
|
233
|
+
type: 'swarm.createTask',
|
|
234
|
+
placement: 'local',
|
|
235
|
+
input: Schema.Struct({ ...CallerFields, ...CreateTaskArgsSchema.fields }),
|
|
236
|
+
retry: RETRY,
|
|
237
|
+
execute: (input, ctx) => answered(input, ctx.threadId, Effect.gen(function* () {
|
|
238
|
+
const boards = yield* BoardsTag;
|
|
239
|
+
const task = yield* boards.call(input.board, (board) => board.createTask({
|
|
240
|
+
by: input.as,
|
|
241
|
+
channel: input.channel,
|
|
242
|
+
text: input.text,
|
|
243
|
+
for: input.for,
|
|
244
|
+
needs: input.needs,
|
|
245
|
+
key: ctx.effectId,
|
|
246
|
+
}));
|
|
247
|
+
return swarmModule.input('task.created', { callId: input.callId, board: input.board, task }, { threadId: ctx.threadId });
|
|
248
|
+
})),
|
|
249
|
+
});
|
|
250
|
+
export const listTasksEffect = swarmModule.effect({
|
|
251
|
+
type: 'swarm.listTasks',
|
|
252
|
+
placement: 'local',
|
|
253
|
+
input: Schema.Struct({ ...CallerFields, ...ListTasksArgsSchema.fields }),
|
|
254
|
+
retry: RETRY,
|
|
255
|
+
execute: (input, ctx) => answered(input, ctx.threadId, Effect.gen(function* () {
|
|
256
|
+
const boards = yield* BoardsTag;
|
|
257
|
+
const tasks = yield* boards.call(input.board, (board) => board.tasks({ channel: input.channel, state: input.state, for: input.for }));
|
|
258
|
+
return swarmModule.input('tasks.listed', { callId: input.callId, board: input.board, tasks }, { threadId: ctx.threadId });
|
|
259
|
+
})),
|
|
260
|
+
});
|
|
261
|
+
/**
|
|
262
|
+
* Not retried: a claim that took effect but whose answer was lost would be refused on a second
|
|
263
|
+
* attempt, and the lease returns the task to the queue on its own.
|
|
264
|
+
*/
|
|
265
|
+
export const claimTaskEffect = swarmModule.effect({
|
|
266
|
+
type: 'swarm.claimTask',
|
|
267
|
+
placement: 'local',
|
|
268
|
+
input: Schema.Struct({ ...CallerFields, ...ClaimTaskArgsSchema.fields }),
|
|
269
|
+
retry: { maxAttempts: 1 },
|
|
270
|
+
execute: (input, ctx) => answered(input, ctx.threadId, Effect.gen(function* () {
|
|
271
|
+
const boards = yield* BoardsTag;
|
|
272
|
+
const claim = yield* boards.call(input.board, (board) => board.claim({
|
|
273
|
+
by: input.as,
|
|
274
|
+
task: input.task,
|
|
275
|
+
channel: input.channel,
|
|
276
|
+
leaseMs: input.leaseMs,
|
|
277
|
+
}));
|
|
278
|
+
return swarmModule.input('task.claimed', { callId: input.callId, board: input.board, claim }, { threadId: ctx.threadId });
|
|
279
|
+
})),
|
|
280
|
+
});
|
|
281
|
+
export const settleTaskEffect = swarmModule.effect({
|
|
282
|
+
type: 'swarm.settleTask',
|
|
283
|
+
placement: 'local',
|
|
284
|
+
input: Schema.Struct({ ...CallerFields, ...SettleTaskArgsSchema.fields }),
|
|
285
|
+
retry: { maxAttempts: 1 },
|
|
286
|
+
execute: (input, ctx) => answered(input, ctx.threadId, Effect.gen(function* () {
|
|
287
|
+
const boards = yield* BoardsTag;
|
|
288
|
+
const task = yield* boards.call(input.board, (board) => board.settle({
|
|
289
|
+
task: input.task,
|
|
290
|
+
token: input.token,
|
|
291
|
+
outcome: input.outcome,
|
|
292
|
+
note: input.note,
|
|
293
|
+
}));
|
|
294
|
+
return swarmModule.input('task.settled', { callId: input.callId, board: input.board, task }, { threadId: ctx.threadId });
|
|
295
|
+
})),
|
|
296
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { LaunchRunArgs, RunState } from '@swirls/looms/core';
|
|
2
|
+
import type { SwarmDefinition, SwarmStart } from './definitions';
|
|
3
|
+
/** The two operations `ensureSwarm` needs. `createLooms` already has them. */
|
|
4
|
+
export interface SwarmHost {
|
|
5
|
+
startRun(args: LaunchRunArgs): Promise<{
|
|
6
|
+
readonly runId: string;
|
|
7
|
+
}>;
|
|
8
|
+
getRun(runId: string): Promise<RunState>;
|
|
9
|
+
}
|
|
10
|
+
export type SwarmEnsureResult = 'started' | 'running';
|
|
11
|
+
/**
|
|
12
|
+
* Start a swarm under a fixed run id unless that run already exists, so a host can call it on
|
|
13
|
+
* every boot or whenever a tenant is provisioned. A swarm that was stopped, failed or cancelled
|
|
14
|
+
* throws: its run id cannot be reused.
|
|
15
|
+
*/
|
|
16
|
+
export declare function ensureSwarm(host: SwarmHost, definition: SwarmDefinition, runId: string, config?: NonNullable<SwarmStart>): Promise<SwarmEnsureResult>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Start a swarm under a fixed run id unless that run already exists, so a host can call it on
|
|
3
|
+
* every boot or whenever a tenant is provisioned. A swarm that was stopped, failed or cancelled
|
|
4
|
+
* throws: its run id cannot be reused.
|
|
5
|
+
*/
|
|
6
|
+
export function ensureSwarm(host, definition, runId, config = {}) {
|
|
7
|
+
return host.getRun(runId).then((state) => {
|
|
8
|
+
if (state.rootThreadId === null) {
|
|
9
|
+
return host
|
|
10
|
+
.startRun({
|
|
11
|
+
runId,
|
|
12
|
+
kind: definition.kind,
|
|
13
|
+
definitionName: definition.name,
|
|
14
|
+
definitionVersion: definition.version,
|
|
15
|
+
input: config,
|
|
16
|
+
})
|
|
17
|
+
.then(() => 'started');
|
|
18
|
+
}
|
|
19
|
+
if (state.status !== 'running') {
|
|
20
|
+
throw new Error(`Swarm "${runId}" is ${state.status}; start it again under a new run id`);
|
|
21
|
+
}
|
|
22
|
+
return 'running';
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
|
+
export declare const BoardPulledPayloadSchema: Schema.Struct<{
|
|
3
|
+
readonly board: Schema.String;
|
|
4
|
+
/** The pull this answers. A swarm ignores a pull it is no longer waiting for. */
|
|
5
|
+
readonly pull: Schema.Finite;
|
|
6
|
+
readonly cursor: Schema.NullOr<Schema.String>;
|
|
7
|
+
readonly events: Schema.$Array<Schema.Struct<{
|
|
8
|
+
readonly cursor: Schema.String;
|
|
9
|
+
readonly type: Schema.Union<readonly [Schema.Literal<"message.posted">, Schema.Literal<"message.labeled">, Schema.Literal<"task.created">, Schema.Literal<"task.ready">, Schema.Literal<"task.claimed">, Schema.Literal<"task.blocked">, Schema.Literal<"task.completed">, Schema.Literal<"task.failed">, Schema.Literal<"task.canceled">, Schema.Literal<"task.reopened">]>;
|
|
10
|
+
readonly at: Schema.Finite;
|
|
11
|
+
readonly by: Schema.String;
|
|
12
|
+
readonly message: Schema.optional<Schema.Struct<{
|
|
13
|
+
readonly id: Schema.String;
|
|
14
|
+
readonly channel: Schema.String;
|
|
15
|
+
readonly text: Schema.String;
|
|
16
|
+
readonly by: Schema.String;
|
|
17
|
+
readonly re: Schema.NullOr<Schema.String>;
|
|
18
|
+
readonly mentions: Schema.$Array<Schema.String>;
|
|
19
|
+
readonly labels: Schema.$Record<Schema.String, Schema.String>;
|
|
20
|
+
readonly createdAt: Schema.Finite;
|
|
21
|
+
}>>;
|
|
22
|
+
readonly task: Schema.optional<Schema.Struct<{
|
|
23
|
+
readonly id: Schema.String;
|
|
24
|
+
readonly channel: Schema.String;
|
|
25
|
+
readonly text: Schema.String;
|
|
26
|
+
readonly by: Schema.String;
|
|
27
|
+
readonly for: Schema.NullOr<Schema.String>;
|
|
28
|
+
readonly needs: Schema.$Array<Schema.String>;
|
|
29
|
+
readonly state: Schema.Union<readonly [Schema.Literal<"waiting">, Schema.Literal<"ready">, Schema.Literal<"claimed">, Schema.Literal<"blocked">, Schema.Literal<"completed">, Schema.Literal<"failed">, Schema.Literal<"canceled">]>;
|
|
30
|
+
readonly holder: Schema.NullOr<Schema.String>;
|
|
31
|
+
readonly epoch: Schema.Finite;
|
|
32
|
+
readonly leaseUntil: Schema.NullOr<Schema.Finite>;
|
|
33
|
+
readonly note: Schema.NullOr<Schema.String>;
|
|
34
|
+
readonly createdAt: Schema.Finite;
|
|
35
|
+
readonly updatedAt: Schema.Finite;
|
|
36
|
+
}>>;
|
|
37
|
+
}>>;
|
|
38
|
+
/** The board had more events than fit in this page. */
|
|
39
|
+
readonly more: Schema.Boolean;
|
|
40
|
+
/** When to poll next, or null when the swarm only pulls on a nudge. */
|
|
41
|
+
readonly nextPullAt: Schema.NullOr<Schema.Finite>;
|
|
42
|
+
}>;
|
|
43
|
+
export declare const MemberActivatedPayloadSchema: Schema.Struct<{
|
|
44
|
+
readonly board: Schema.String;
|
|
45
|
+
readonly member: Schema.String;
|
|
46
|
+
/** Counts this member's activations, from 1. */
|
|
47
|
+
readonly activation: Schema.Finite;
|
|
48
|
+
/** The run that carries out the activation. */
|
|
49
|
+
readonly runId: Schema.String;
|
|
50
|
+
/** How many board events the member was woken for. */
|
|
51
|
+
readonly events: Schema.Finite;
|
|
52
|
+
readonly at: Schema.Finite;
|
|
53
|
+
}>;
|
|
54
|
+
export declare const SwarmEmptyPayloadSchema: Schema.Struct<{}>;
|
|
55
|
+
export declare const swarmCatalog: import("@swirls/looms/core").EventCatalog<"swarm", {
|
|
56
|
+
'board.pulled': Schema.Struct<{
|
|
57
|
+
readonly board: Schema.String;
|
|
58
|
+
/** The pull this answers. A swarm ignores a pull it is no longer waiting for. */
|
|
59
|
+
readonly pull: Schema.Finite;
|
|
60
|
+
readonly cursor: Schema.NullOr<Schema.String>;
|
|
61
|
+
readonly events: Schema.$Array<Schema.Struct<{
|
|
62
|
+
readonly cursor: Schema.String;
|
|
63
|
+
readonly type: Schema.Union<readonly [Schema.Literal<"message.posted">, Schema.Literal<"message.labeled">, Schema.Literal<"task.created">, Schema.Literal<"task.ready">, Schema.Literal<"task.claimed">, Schema.Literal<"task.blocked">, Schema.Literal<"task.completed">, Schema.Literal<"task.failed">, Schema.Literal<"task.canceled">, Schema.Literal<"task.reopened">]>;
|
|
64
|
+
readonly at: Schema.Finite;
|
|
65
|
+
readonly by: Schema.String;
|
|
66
|
+
readonly message: Schema.optional<Schema.Struct<{
|
|
67
|
+
readonly id: Schema.String;
|
|
68
|
+
readonly channel: Schema.String;
|
|
69
|
+
readonly text: Schema.String;
|
|
70
|
+
readonly by: Schema.String;
|
|
71
|
+
readonly re: Schema.NullOr<Schema.String>;
|
|
72
|
+
readonly mentions: Schema.$Array<Schema.String>;
|
|
73
|
+
readonly labels: Schema.$Record<Schema.String, Schema.String>;
|
|
74
|
+
readonly createdAt: Schema.Finite;
|
|
75
|
+
}>>;
|
|
76
|
+
readonly task: Schema.optional<Schema.Struct<{
|
|
77
|
+
readonly id: Schema.String;
|
|
78
|
+
readonly channel: Schema.String;
|
|
79
|
+
readonly text: Schema.String;
|
|
80
|
+
readonly by: Schema.String;
|
|
81
|
+
readonly for: Schema.NullOr<Schema.String>;
|
|
82
|
+
readonly needs: Schema.$Array<Schema.String>;
|
|
83
|
+
readonly state: Schema.Union<readonly [Schema.Literal<"waiting">, Schema.Literal<"ready">, Schema.Literal<"claimed">, Schema.Literal<"blocked">, Schema.Literal<"completed">, Schema.Literal<"failed">, Schema.Literal<"canceled">]>;
|
|
84
|
+
readonly holder: Schema.NullOr<Schema.String>;
|
|
85
|
+
readonly epoch: Schema.Finite;
|
|
86
|
+
readonly leaseUntil: Schema.NullOr<Schema.Finite>;
|
|
87
|
+
readonly note: Schema.NullOr<Schema.String>;
|
|
88
|
+
readonly createdAt: Schema.Finite;
|
|
89
|
+
readonly updatedAt: Schema.Finite;
|
|
90
|
+
}>>;
|
|
91
|
+
}>>;
|
|
92
|
+
/** The board had more events than fit in this page. */
|
|
93
|
+
readonly more: Schema.Boolean;
|
|
94
|
+
/** When to poll next, or null when the swarm only pulls on a nudge. */
|
|
95
|
+
readonly nextPullAt: Schema.NullOr<Schema.Finite>;
|
|
96
|
+
}>;
|
|
97
|
+
'member.activated': Schema.Struct<{
|
|
98
|
+
readonly board: Schema.String;
|
|
99
|
+
readonly member: Schema.String;
|
|
100
|
+
/** Counts this member's activations, from 1. */
|
|
101
|
+
readonly activation: Schema.Finite;
|
|
102
|
+
/** The run that carries out the activation. */
|
|
103
|
+
readonly runId: Schema.String;
|
|
104
|
+
/** How many board events the member was woken for. */
|
|
105
|
+
readonly events: Schema.Finite;
|
|
106
|
+
readonly at: Schema.Finite;
|
|
107
|
+
}>;
|
|
108
|
+
nudged: Schema.Struct<{}>;
|
|
109
|
+
stopped: Schema.Struct<{}>;
|
|
110
|
+
'message.posted': Schema.Struct<{
|
|
111
|
+
readonly callId: Schema.String;
|
|
112
|
+
readonly board: Schema.String;
|
|
113
|
+
readonly message: Schema.Struct<{
|
|
114
|
+
readonly id: Schema.String;
|
|
115
|
+
readonly channel: Schema.String;
|
|
116
|
+
readonly text: Schema.String;
|
|
117
|
+
readonly by: Schema.String;
|
|
118
|
+
readonly re: Schema.NullOr<Schema.String>;
|
|
119
|
+
readonly mentions: Schema.$Array<Schema.String>;
|
|
120
|
+
readonly labels: Schema.$Record<Schema.String, Schema.String>;
|
|
121
|
+
readonly createdAt: Schema.Finite;
|
|
122
|
+
}>;
|
|
123
|
+
}>;
|
|
124
|
+
'message.labeled': Schema.Struct<{
|
|
125
|
+
readonly callId: Schema.String;
|
|
126
|
+
readonly board: Schema.String;
|
|
127
|
+
readonly message: Schema.Struct<{
|
|
128
|
+
readonly id: Schema.String;
|
|
129
|
+
readonly channel: Schema.String;
|
|
130
|
+
readonly text: Schema.String;
|
|
131
|
+
readonly by: Schema.String;
|
|
132
|
+
readonly re: Schema.NullOr<Schema.String>;
|
|
133
|
+
readonly mentions: Schema.$Array<Schema.String>;
|
|
134
|
+
readonly labels: Schema.$Record<Schema.String, Schema.String>;
|
|
135
|
+
readonly createdAt: Schema.Finite;
|
|
136
|
+
}>;
|
|
137
|
+
}>;
|
|
138
|
+
'messages.read': Schema.Struct<{
|
|
139
|
+
readonly callId: Schema.String;
|
|
140
|
+
readonly board: Schema.String;
|
|
141
|
+
readonly messages: Schema.$Array<Schema.Struct<{
|
|
142
|
+
readonly id: Schema.String;
|
|
143
|
+
readonly channel: Schema.String;
|
|
144
|
+
readonly text: Schema.String;
|
|
145
|
+
readonly by: Schema.String;
|
|
146
|
+
readonly re: Schema.NullOr<Schema.String>;
|
|
147
|
+
readonly mentions: Schema.$Array<Schema.String>;
|
|
148
|
+
readonly labels: Schema.$Record<Schema.String, Schema.String>;
|
|
149
|
+
readonly createdAt: Schema.Finite;
|
|
150
|
+
}>>;
|
|
151
|
+
}>;
|
|
152
|
+
'task.created': Schema.Struct<{
|
|
153
|
+
readonly callId: Schema.String;
|
|
154
|
+
readonly board: Schema.String;
|
|
155
|
+
readonly task: Schema.Struct<{
|
|
156
|
+
readonly id: Schema.String;
|
|
157
|
+
readonly channel: Schema.String;
|
|
158
|
+
readonly text: Schema.String;
|
|
159
|
+
readonly by: Schema.String;
|
|
160
|
+
readonly for: Schema.NullOr<Schema.String>;
|
|
161
|
+
readonly needs: Schema.$Array<Schema.String>;
|
|
162
|
+
readonly state: Schema.Union<readonly [Schema.Literal<"waiting">, Schema.Literal<"ready">, Schema.Literal<"claimed">, Schema.Literal<"blocked">, Schema.Literal<"completed">, Schema.Literal<"failed">, Schema.Literal<"canceled">]>;
|
|
163
|
+
readonly holder: Schema.NullOr<Schema.String>;
|
|
164
|
+
readonly epoch: Schema.Finite;
|
|
165
|
+
readonly leaseUntil: Schema.NullOr<Schema.Finite>;
|
|
166
|
+
readonly note: Schema.NullOr<Schema.String>;
|
|
167
|
+
readonly createdAt: Schema.Finite;
|
|
168
|
+
readonly updatedAt: Schema.Finite;
|
|
169
|
+
}>;
|
|
170
|
+
}>;
|
|
171
|
+
'tasks.listed': Schema.Struct<{
|
|
172
|
+
readonly callId: Schema.String;
|
|
173
|
+
readonly board: Schema.String;
|
|
174
|
+
readonly tasks: Schema.$Array<Schema.Struct<{
|
|
175
|
+
readonly id: Schema.String;
|
|
176
|
+
readonly channel: Schema.String;
|
|
177
|
+
readonly text: Schema.String;
|
|
178
|
+
readonly by: Schema.String;
|
|
179
|
+
readonly for: Schema.NullOr<Schema.String>;
|
|
180
|
+
readonly needs: Schema.$Array<Schema.String>;
|
|
181
|
+
readonly state: Schema.Union<readonly [Schema.Literal<"waiting">, Schema.Literal<"ready">, Schema.Literal<"claimed">, Schema.Literal<"blocked">, Schema.Literal<"completed">, Schema.Literal<"failed">, Schema.Literal<"canceled">]>;
|
|
182
|
+
readonly holder: Schema.NullOr<Schema.String>;
|
|
183
|
+
readonly epoch: Schema.Finite;
|
|
184
|
+
readonly leaseUntil: Schema.NullOr<Schema.Finite>;
|
|
185
|
+
readonly note: Schema.NullOr<Schema.String>;
|
|
186
|
+
readonly createdAt: Schema.Finite;
|
|
187
|
+
readonly updatedAt: Schema.Finite;
|
|
188
|
+
}>>;
|
|
189
|
+
}>;
|
|
190
|
+
/** `claim` is null when the queue had nothing for the caller. */
|
|
191
|
+
'task.claimed': Schema.Struct<{
|
|
192
|
+
readonly callId: Schema.String;
|
|
193
|
+
readonly board: Schema.String;
|
|
194
|
+
readonly claim: Schema.NullOr<Schema.Struct<{
|
|
195
|
+
readonly task: Schema.Struct<{
|
|
196
|
+
readonly id: Schema.String;
|
|
197
|
+
readonly channel: Schema.String;
|
|
198
|
+
readonly text: Schema.String;
|
|
199
|
+
readonly by: Schema.String;
|
|
200
|
+
readonly for: Schema.NullOr<Schema.String>;
|
|
201
|
+
readonly needs: Schema.$Array<Schema.String>;
|
|
202
|
+
readonly state: Schema.Union<readonly [Schema.Literal<"waiting">, Schema.Literal<"ready">, Schema.Literal<"claimed">, Schema.Literal<"blocked">, Schema.Literal<"completed">, Schema.Literal<"failed">, Schema.Literal<"canceled">]>;
|
|
203
|
+
readonly holder: Schema.NullOr<Schema.String>;
|
|
204
|
+
readonly epoch: Schema.Finite;
|
|
205
|
+
readonly leaseUntil: Schema.NullOr<Schema.Finite>;
|
|
206
|
+
readonly note: Schema.NullOr<Schema.String>;
|
|
207
|
+
readonly createdAt: Schema.Finite;
|
|
208
|
+
readonly updatedAt: Schema.Finite;
|
|
209
|
+
}>;
|
|
210
|
+
readonly token: Schema.String;
|
|
211
|
+
readonly until: Schema.Finite;
|
|
212
|
+
}>>;
|
|
213
|
+
}>;
|
|
214
|
+
'task.settled': Schema.Struct<{
|
|
215
|
+
readonly callId: Schema.String;
|
|
216
|
+
readonly board: Schema.String;
|
|
217
|
+
readonly task: Schema.Struct<{
|
|
218
|
+
readonly id: Schema.String;
|
|
219
|
+
readonly channel: Schema.String;
|
|
220
|
+
readonly text: Schema.String;
|
|
221
|
+
readonly by: Schema.String;
|
|
222
|
+
readonly for: Schema.NullOr<Schema.String>;
|
|
223
|
+
readonly needs: Schema.$Array<Schema.String>;
|
|
224
|
+
readonly state: Schema.Union<readonly [Schema.Literal<"waiting">, Schema.Literal<"ready">, Schema.Literal<"claimed">, Schema.Literal<"blocked">, Schema.Literal<"completed">, Schema.Literal<"failed">, Schema.Literal<"canceled">]>;
|
|
225
|
+
readonly holder: Schema.NullOr<Schema.String>;
|
|
226
|
+
readonly epoch: Schema.Finite;
|
|
227
|
+
readonly leaseUntil: Schema.NullOr<Schema.Finite>;
|
|
228
|
+
readonly note: Schema.NullOr<Schema.String>;
|
|
229
|
+
readonly createdAt: Schema.Finite;
|
|
230
|
+
readonly updatedAt: Schema.Finite;
|
|
231
|
+
}>;
|
|
232
|
+
}>;
|
|
233
|
+
/** The board refused the call. `error` makes a waiting tool call fail with this message. */
|
|
234
|
+
'call.rejected': Schema.Struct<{
|
|
235
|
+
readonly callId: Schema.String;
|
|
236
|
+
readonly board: Schema.String;
|
|
237
|
+
readonly code: Schema.String;
|
|
238
|
+
readonly error: Schema.String;
|
|
239
|
+
}>;
|
|
240
|
+
}>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
|
+
import { defineEventCatalog } from '@swirls/looms/core';
|
|
3
|
+
import { BoardEventSchema, BoardMessageSchema, BoardTaskSchema, TaskClaimSchema } from './board.js';
|
|
4
|
+
/** Which board a member's call went to, and the id that pairs the result with its tool call. */
|
|
5
|
+
const CallFields = {
|
|
6
|
+
callId: Schema.String,
|
|
7
|
+
board: Schema.String,
|
|
8
|
+
};
|
|
9
|
+
export const BoardPulledPayloadSchema = Schema.Struct({
|
|
10
|
+
board: Schema.String,
|
|
11
|
+
/** The pull this answers. A swarm ignores a pull it is no longer waiting for. */
|
|
12
|
+
pull: Schema.Finite,
|
|
13
|
+
cursor: Schema.NullOr(Schema.String),
|
|
14
|
+
events: Schema.Array(BoardEventSchema),
|
|
15
|
+
/** The board had more events than fit in this page. */
|
|
16
|
+
more: Schema.Boolean,
|
|
17
|
+
/** When to poll next, or null when the swarm only pulls on a nudge. */
|
|
18
|
+
nextPullAt: Schema.NullOr(Schema.Finite),
|
|
19
|
+
});
|
|
20
|
+
export const MemberActivatedPayloadSchema = Schema.Struct({
|
|
21
|
+
board: Schema.String,
|
|
22
|
+
member: Schema.String,
|
|
23
|
+
/** Counts this member's activations, from 1. */
|
|
24
|
+
activation: Schema.Finite,
|
|
25
|
+
/** The run that carries out the activation. */
|
|
26
|
+
runId: Schema.String,
|
|
27
|
+
/** How many board events the member was woken for. */
|
|
28
|
+
events: Schema.Finite,
|
|
29
|
+
at: Schema.Finite,
|
|
30
|
+
});
|
|
31
|
+
export const SwarmEmptyPayloadSchema = Schema.Struct({});
|
|
32
|
+
export const swarmCatalog = defineEventCatalog('swarm', {
|
|
33
|
+
// On the swarm's run.
|
|
34
|
+
'board.pulled': BoardPulledPayloadSchema,
|
|
35
|
+
'member.activated': MemberActivatedPayloadSchema,
|
|
36
|
+
nudged: SwarmEmptyPayloadSchema,
|
|
37
|
+
stopped: SwarmEmptyPayloadSchema,
|
|
38
|
+
// On the run of whoever called the board: a member, or any thread that used a step.
|
|
39
|
+
'message.posted': Schema.Struct({ ...CallFields, message: BoardMessageSchema }),
|
|
40
|
+
'message.labeled': Schema.Struct({ ...CallFields, message: BoardMessageSchema }),
|
|
41
|
+
'messages.read': Schema.Struct({ ...CallFields, messages: Schema.Array(BoardMessageSchema) }),
|
|
42
|
+
'task.created': Schema.Struct({ ...CallFields, task: BoardTaskSchema }),
|
|
43
|
+
'tasks.listed': Schema.Struct({ ...CallFields, tasks: Schema.Array(BoardTaskSchema) }),
|
|
44
|
+
/** `claim` is null when the queue had nothing for the caller. */
|
|
45
|
+
'task.claimed': Schema.Struct({ ...CallFields, claim: Schema.NullOr(TaskClaimSchema) }),
|
|
46
|
+
'task.settled': Schema.Struct({ ...CallFields, task: BoardTaskSchema }),
|
|
47
|
+
/** The board refused the call. `error` makes a waiting tool call fail with this message. */
|
|
48
|
+
'call.rejected': Schema.Struct({ ...CallFields, code: Schema.String, error: Schema.String }),
|
|
49
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './board';
|
|
2
|
+
export * from './memory-board';
|
|
3
|
+
export * from './conformance';
|
|
4
|
+
export * from './events';
|
|
5
|
+
export * from './scope';
|
|
6
|
+
export * from './definitions';
|
|
7
|
+
export * from './services';
|
|
8
|
+
export * from './effects';
|
|
9
|
+
export * from './threads';
|
|
10
|
+
export * from './projections';
|
|
11
|
+
export * from './signals';
|
|
12
|
+
export * from './steps';
|
|
13
|
+
export * from './tools';
|
|
14
|
+
export * from './ensure';
|
|
15
|
+
export * from './module';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './board.js';
|
|
2
|
+
export * from './memory-board.js';
|
|
3
|
+
export * from './conformance.js';
|
|
4
|
+
export * from './events.js';
|
|
5
|
+
export * from './scope.js';
|
|
6
|
+
export * from './definitions.js';
|
|
7
|
+
export * from './services.js';
|
|
8
|
+
export * from './effects.js';
|
|
9
|
+
export * from './threads.js';
|
|
10
|
+
export * from './projections.js';
|
|
11
|
+
export * from './signals.js';
|
|
12
|
+
export * from './steps.js';
|
|
13
|
+
export * from './tools.js';
|
|
14
|
+
export * from './ensure.js';
|
|
15
|
+
export * from './module.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type MessageBoard } from './board';
|
|
2
|
+
export interface MemoryBoardOptions {
|
|
3
|
+
/** Epoch milliseconds. Tests pass a clock they control to expire leases. */
|
|
4
|
+
readonly now?: () => number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* A board held in process memory. It is the reference implementation of {@link MessageBoard}:
|
|
8
|
+
* use it in tests and single-process hosts, and read it when writing a durable board.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createMemoryBoard(options?: MemoryBoardOptions): MessageBoard;
|