@swirls/looms 0.24.0 → 0.26.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 +34 -0
- package/dist/actor/cell.d.ts +3 -1
- package/dist/actor/cell.js +1 -0
- package/dist/actor/host.d.ts +3 -1
- package/dist/actor/host.js +2 -1
- package/dist/actor/routing.d.ts +6 -3
- package/dist/actor/routing.js +6 -4
- package/dist/agent/agent-session.js +2 -2
- package/dist/agent/debugger/agent-chat.js +4 -3
- package/dist/agent/definitions.d.ts +3 -1
- package/dist/agent/effects.js +5 -3
- package/dist/agent/module.d.ts +730 -730
- 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/approval/steps.d.ts +3 -1
- package/dist/approval/steps.js +2 -2
- package/dist/client/client.d.ts +7 -1
- package/dist/client/client.js +5 -2
- package/dist/cloudflare/durable-object.d.ts +3 -1
- package/dist/cloudflare/durable-object.js +1 -0
- package/dist/cloudflare/queue-consumer.d.ts +3 -1
- package/dist/cloudflare/queue-consumer.js +2 -1
- package/dist/cloudflare/router.d.ts +3 -1
- package/dist/cloudflare/router.js +1 -1
- package/dist/core/compose.d.ts +8 -2
- package/dist/core/compose.js +6 -3
- package/dist/core/effects.d.ts +3 -0
- package/dist/core/envelope.d.ts +2 -0
- package/dist/core/envelope.js +2 -2
- package/dist/core/event-codec.d.ts +4 -3
- package/dist/core/event-codec.js +7 -7
- package/dist/core/fold.d.ts +3 -0
- package/dist/core/fold.js +3 -1
- package/dist/core/fork.js +1 -1
- package/dist/core/ids.d.ts +70 -5
- package/dist/core/ids.js +164 -41
- package/dist/core/snapshots.d.ts +2 -0
- package/dist/core/snapshots.js +2 -1
- package/dist/core/thread.d.ts +8 -0
- package/dist/debugger/app/assets/index-D_FKxPrN.js +23 -0
- package/dist/debugger/app/assets/routes-CkwzFejg.js +47 -0
- package/dist/debugger/app/index.html +1 -1
- package/dist/debugger/context.d.ts +4 -1
- package/dist/debugger/context.js +4 -4
- package/dist/debugger/shell/debugger-shell.d.ts +4 -1
- package/dist/debugger/shell/debugger-shell.js +2 -2
- package/dist/debugger/shell/use-start-run.d.ts +1 -1
- package/dist/debugger/shell/use-start-run.js +1 -2
- package/dist/evaluator/steps.d.ts +2 -2
- package/dist/evaluator/steps.js +3 -3
- package/dist/react/react.d.ts +8 -3
- package/dist/react/react.js +15 -2
- package/dist/react/store.d.ts +5 -1
- package/dist/react/store.js +5 -4
- package/dist/runtime/cancellation.js +5 -5
- package/dist/runtime/deadline-transition-planner.d.ts +1 -0
- package/dist/runtime/deadline-transition-planner.js +8 -7
- package/dist/runtime/effect-admission.js +1 -0
- package/dist/runtime/helpers.d.ts +6 -5
- package/dist/runtime/helpers.js +8 -8
- package/dist/runtime/local-effect-executor.js +15 -10
- package/dist/runtime/looms.d.ts +6 -1
- package/dist/runtime/looms.js +4 -1
- package/dist/runtime/retry-policy.d.ts +2 -1
- package/dist/runtime/retry-policy.js +2 -1
- package/dist/runtime/runtime.js +10 -10
- package/dist/runtime/server/routes/runs.js +5 -5
- package/dist/runtime/types.d.ts +7 -1
- package/dist/runtime/wake-engine.js +10 -9
- package/dist/runtime/worker-callbacks.js +9 -8
- package/dist/runtime/worker-effect-dispatch.d.ts +3 -2
- package/dist/runtime/worker-effect-dispatch.js +7 -5
- 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 +20 -0
- package/dist/swarm/tools.js +100 -0
- package/dist/workflow/effects.js +6 -5
- package/dist/workflow/graph.d.ts +3 -3
- package/dist/workflow/graph.js +5 -5
- package/dist/workflow/module.d.ts +8 -2
- package/dist/workflow/threads.d.ts +14 -2
- package/dist/workflow/threads.js +54 -44
- package/package.json +7 -2
- package/dist/debugger/app/assets/index-CxbIGkpY.js +0 -22
- package/dist/debugger/app/assets/routes-Ch30UGik.js +0 -47
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
|
+
import { type DefinitionRef, type JsonValue } from '@swirls/looms/core';
|
|
3
|
+
export declare const DEFAULT_POLL_INTERVAL_MS = 60000;
|
|
4
|
+
export declare const SwarmStartSchema: Schema.Union<readonly [Schema.Struct<{
|
|
5
|
+
/** The board this swarm follows. Defaults to the swarm's run id. */
|
|
6
|
+
readonly board: Schema.optional<Schema.String>;
|
|
7
|
+
/** Start after this board cursor. Omit to read the board's log from the start. */
|
|
8
|
+
readonly after: Schema.optional<Schema.String>;
|
|
9
|
+
}>, Schema.Null]>;
|
|
10
|
+
export type SwarmStart = Schema.Schema.Type<typeof SwarmStartSchema>;
|
|
11
|
+
/** One agent in a swarm. Its name is how it signs board messages and how others `@mention` it. */
|
|
12
|
+
export interface SwarmMember {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
/** What the swarm starts when the board has something for this member. */
|
|
15
|
+
readonly agent: DefinitionRef;
|
|
16
|
+
/** Told to the other members so they know what to hand over. */
|
|
17
|
+
readonly description?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Channel filters the member listens to: `support` for one channel, `support/` for a subtree.
|
|
20
|
+
* The member is woken for every message there and for unassigned tasks that become ready
|
|
21
|
+
* there. Without channels it is woken only when mentioned or assigned a task.
|
|
22
|
+
*/
|
|
23
|
+
readonly channels?: readonly string[];
|
|
24
|
+
}
|
|
25
|
+
export interface SwarmDefinition<TName extends string = string> extends DefinitionRef {
|
|
26
|
+
readonly kind: 'swarm';
|
|
27
|
+
readonly name: TName;
|
|
28
|
+
readonly version: string;
|
|
29
|
+
readonly description?: string;
|
|
30
|
+
readonly input: typeof SwarmStartSchema;
|
|
31
|
+
readonly members: readonly SwarmMember[];
|
|
32
|
+
/** Added to every member's activation prompt. */
|
|
33
|
+
readonly instructions?: string;
|
|
34
|
+
/**
|
|
35
|
+
* How often the swarm reads the board when nothing nudges it. `null` reads only on a nudge and
|
|
36
|
+
* after a member finishes, for hosts that signal `nudge()` on every outside write.
|
|
37
|
+
*/
|
|
38
|
+
readonly pollIntervalMs: number | null;
|
|
39
|
+
}
|
|
40
|
+
export type AnySwarmDefinition = SwarmDefinition;
|
|
41
|
+
export declare function defineSwarm<TName extends string>(def: {
|
|
42
|
+
readonly name: TName;
|
|
43
|
+
readonly version?: string;
|
|
44
|
+
readonly description?: string;
|
|
45
|
+
readonly members: readonly SwarmMember[];
|
|
46
|
+
readonly instructions?: string;
|
|
47
|
+
readonly pollIntervalMs?: number | null;
|
|
48
|
+
}): SwarmDefinition<TName>;
|
|
49
|
+
/** The input of a member's run: who it is, which board it is on, and why it was woken. */
|
|
50
|
+
export declare const ActivationSchema: Schema.Struct<{
|
|
51
|
+
/** Becomes the agent's first user message. */
|
|
52
|
+
readonly prompt: Schema.String;
|
|
53
|
+
readonly swarm: Schema.Struct<{
|
|
54
|
+
readonly name: Schema.String;
|
|
55
|
+
readonly runId: Schema.String;
|
|
56
|
+
readonly board: Schema.String;
|
|
57
|
+
readonly member: Schema.String;
|
|
58
|
+
readonly activation: Schema.Finite;
|
|
59
|
+
}>;
|
|
60
|
+
readonly events: Schema.$Array<Schema.Struct<{
|
|
61
|
+
readonly cursor: Schema.String;
|
|
62
|
+
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">]>;
|
|
63
|
+
readonly at: Schema.Finite;
|
|
64
|
+
readonly by: Schema.String;
|
|
65
|
+
readonly message: Schema.optional<Schema.Struct<{
|
|
66
|
+
readonly id: Schema.String;
|
|
67
|
+
readonly channel: Schema.String;
|
|
68
|
+
readonly text: Schema.String;
|
|
69
|
+
readonly by: Schema.String;
|
|
70
|
+
readonly re: Schema.NullOr<Schema.String>;
|
|
71
|
+
readonly mentions: Schema.$Array<Schema.String>;
|
|
72
|
+
readonly labels: Schema.$Record<Schema.String, Schema.String>;
|
|
73
|
+
readonly createdAt: Schema.Finite;
|
|
74
|
+
}>>;
|
|
75
|
+
readonly task: Schema.optional<Schema.Struct<{
|
|
76
|
+
readonly id: Schema.String;
|
|
77
|
+
readonly channel: Schema.String;
|
|
78
|
+
readonly text: Schema.String;
|
|
79
|
+
readonly by: Schema.String;
|
|
80
|
+
readonly for: Schema.NullOr<Schema.String>;
|
|
81
|
+
readonly needs: Schema.$Array<Schema.String>;
|
|
82
|
+
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">]>;
|
|
83
|
+
readonly holder: Schema.NullOr<Schema.String>;
|
|
84
|
+
readonly epoch: Schema.Finite;
|
|
85
|
+
readonly leaseUntil: Schema.NullOr<Schema.Finite>;
|
|
86
|
+
readonly note: Schema.NullOr<Schema.String>;
|
|
87
|
+
readonly createdAt: Schema.Finite;
|
|
88
|
+
readonly updatedAt: Schema.Finite;
|
|
89
|
+
}>>;
|
|
90
|
+
}>>;
|
|
91
|
+
}>;
|
|
92
|
+
export type Activation = Schema.Schema.Type<typeof ActivationSchema>;
|
|
93
|
+
/** The activation in a member run's input, or null when the run was not started by a swarm. */
|
|
94
|
+
export declare function readActivation(input: JsonValue | undefined): Activation | null;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Option, Schema } from 'effect';
|
|
2
|
+
import { DEFAULT_DEFINITION_VERSION, createKind, } from '@swirls/looms/core';
|
|
3
|
+
import { BoardEventSchema } from './board.js';
|
|
4
|
+
const swarmKind = createKind('swarm');
|
|
5
|
+
const MEMBER_NAME = /^[a-z][a-z0-9-]*$/;
|
|
6
|
+
export const DEFAULT_POLL_INTERVAL_MS = 60_000;
|
|
7
|
+
export const SwarmStartSchema = Schema.Union([
|
|
8
|
+
Schema.Struct({
|
|
9
|
+
/** The board this swarm follows. Defaults to the swarm's run id. */
|
|
10
|
+
board: Schema.optional(Schema.String),
|
|
11
|
+
/** Start after this board cursor. Omit to read the board's log from the start. */
|
|
12
|
+
after: Schema.optional(Schema.String),
|
|
13
|
+
}),
|
|
14
|
+
Schema.Null,
|
|
15
|
+
]);
|
|
16
|
+
export function defineSwarm(def) {
|
|
17
|
+
const names = new Set();
|
|
18
|
+
for (const member of def.members) {
|
|
19
|
+
if (!MEMBER_NAME.test(member.name)) {
|
|
20
|
+
throw new Error(`Swarm member name "${member.name}" must be lowercase letters, digits and hyphens`);
|
|
21
|
+
}
|
|
22
|
+
if (names.has(member.name)) {
|
|
23
|
+
throw new Error(`Swarm "${def.name}" lists member "${member.name}" twice`);
|
|
24
|
+
}
|
|
25
|
+
names.add(member.name);
|
|
26
|
+
}
|
|
27
|
+
return swarmKind.define({
|
|
28
|
+
...def,
|
|
29
|
+
version: def.version ?? DEFAULT_DEFINITION_VERSION,
|
|
30
|
+
input: SwarmStartSchema,
|
|
31
|
+
pollIntervalMs: def.pollIntervalMs === undefined ? DEFAULT_POLL_INTERVAL_MS : def.pollIntervalMs,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/** The input of a member's run: who it is, which board it is on, and why it was woken. */
|
|
35
|
+
export const ActivationSchema = Schema.Struct({
|
|
36
|
+
/** Becomes the agent's first user message. */
|
|
37
|
+
prompt: Schema.String,
|
|
38
|
+
swarm: Schema.Struct({
|
|
39
|
+
name: Schema.String,
|
|
40
|
+
runId: Schema.String,
|
|
41
|
+
board: Schema.String,
|
|
42
|
+
member: Schema.String,
|
|
43
|
+
activation: Schema.Finite,
|
|
44
|
+
}),
|
|
45
|
+
events: Schema.Array(BoardEventSchema),
|
|
46
|
+
});
|
|
47
|
+
const decodeActivation = Schema.decodeUnknownOption(ActivationSchema);
|
|
48
|
+
/** The activation in a member run's input, or null when the run was not started by a swarm. */
|
|
49
|
+
export function readActivation(input) {
|
|
50
|
+
return input === undefined ? null : Option.getOrNull(decodeActivation(input));
|
|
51
|
+
}
|