@swirls/looms 0.18.0 → 0.19.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 +16 -0
- package/README.md +2 -0
- package/dist/agent/effects.d.ts +260 -260
- package/dist/cli/cli.js +1 -1
- package/dist/cli/commands.d.ts +2 -2
- package/dist/cli/commands.js +30 -29
- package/dist/cloudflare/r2-blob-store.js +1 -1
- package/dist/core/definition-resolver.d.ts +2 -2
- package/dist/core/definition-resolver.js +2 -3
- package/dist/core/definition-store.js +2 -3
- package/dist/debugger/app/assets/index-Et8_0gnF.js +22 -0
- package/dist/debugger/app/assets/routes-DcJehTYv.js +47 -0
- package/dist/debugger/app/index.html +1 -1
- package/dist/react/cache.js +5 -5
- package/dist/runtime/errors.d.ts +4 -0
- package/dist/runtime/errors.js +4 -0
- package/dist/runtime/types.d.ts +6 -0
- package/dist/runtime/wake-engine.js +24 -9
- package/dist/schedule/module.d.ts +36 -36
- package/package.json +4 -4
- package/dist/debugger/app/assets/index-BjZn1DuJ.js +0 -22
- package/dist/debugger/app/assets/routes-B90xnBF1.js +0 -47
package/dist/cli/commands.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Config, Console, Effect, FileSystem, Layer, Option, Path, Queue, Schema, Stdio, Stream, Terminal, } from 'effect';
|
|
2
|
-
import { Argument, CliError, Command, Flag } from 'effect/
|
|
3
|
-
import { ChildProcessSpawner } from 'effect/
|
|
2
|
+
import { Argument, CliError, Command, Flag } from 'effect/cli';
|
|
3
|
+
import { ChildProcessSpawner } from 'effect/process';
|
|
4
4
|
import { steer as steerEvent } from '@swirls/looms/agent';
|
|
5
5
|
import { decision } from '@swirls/looms/approval';
|
|
6
6
|
import { createLoomsClient } from '@swirls/looms/client';
|
|
@@ -11,7 +11,7 @@ import {} from '@swirls/looms/projectors/replica/sqlite';
|
|
|
11
11
|
import { openSqliteReplicaFile } from '@swirls/looms/projectors/replica/sqlite-bun';
|
|
12
12
|
import { createLooms } from '@swirls/looms/runtime';
|
|
13
13
|
const VERSION = '0.0.1';
|
|
14
|
-
const urlFlag = Flag.
|
|
14
|
+
const urlFlag = Flag.String('url').pipe(Flag.withDescription('Looms host base URL (env LOOMS_URL)'), Flag.withFallbackConfig(Config.String('LOOMS_URL')), Flag.withDefault('http://127.0.0.1:8787'), Flag.map((url) => url.replace(/\/$/, '')));
|
|
15
15
|
function parseJsonArg(raw) {
|
|
16
16
|
if (Option.isNone(raw) || raw.value === '') {
|
|
17
17
|
return null;
|
|
@@ -31,7 +31,7 @@ function tryClient(run) {
|
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
const serve = Command.make('serve', {
|
|
34
|
-
port: Flag.
|
|
34
|
+
port: Flag.Int('port').pipe(Flag.withDescription('Port to listen on (env PORT)'), Flag.withFallbackConfig(Config.Int('PORT')), Flag.withDefault(8787)),
|
|
35
35
|
}, Effect.fn('serve')(function* ({ port }) {
|
|
36
36
|
const looms = createLooms();
|
|
37
37
|
const server = looms.serve({ port });
|
|
@@ -40,33 +40,33 @@ const serve = Command.make('serve', {
|
|
|
40
40
|
})).pipe(Command.withDescription('Start the Looms runtime host'), Command.withShortDescription('Start the runtime'));
|
|
41
41
|
const loomsBase = Command.make('looms').pipe(Command.withDescription('Looms thread runtime'), Command.withSharedFlags({ url: urlFlag }));
|
|
42
42
|
const start = Command.make('start', {
|
|
43
|
-
kind: Argument.
|
|
44
|
-
name: Argument.
|
|
45
|
-
json: Argument.
|
|
43
|
+
kind: Argument.String('kind').pipe(Argument.withDescription('Thread kind (e.g. agent, workflow)')),
|
|
44
|
+
name: Argument.String('name').pipe(Argument.withDescription('Definition name')),
|
|
45
|
+
json: Argument.String('json').pipe(Argument.withDescription('Optional JSON input'), Argument.optional),
|
|
46
46
|
}, Effect.fn('start')(function* ({ kind, name, json }) {
|
|
47
47
|
const { url } = yield* loomsBase;
|
|
48
48
|
const result = yield* tryClient(() => clientFor(url).startRun({ kind, definitionName: name, input: parseJsonArg(json) }));
|
|
49
49
|
yield* Console.log(stringifyJsonPretty(result));
|
|
50
50
|
})).pipe(Command.withDescription('Start a run from a registered definition: looms start agent echo \'{"text":"hi"}\''), Command.withShortDescription('Start a run'));
|
|
51
51
|
const events = Command.make('events', {
|
|
52
|
-
runId: Argument.
|
|
52
|
+
runId: Argument.String('runId').pipe(Argument.withDescription('Run id')),
|
|
53
53
|
}, Effect.fn('events')(function* ({ runId }) {
|
|
54
54
|
const { url } = yield* loomsBase;
|
|
55
55
|
const result = yield* tryClient(() => clientFor(url).getEvents(runId));
|
|
56
56
|
yield* Console.log(stringifyJsonPretty(result));
|
|
57
57
|
})).pipe(Command.withDescription('List events for a run'), Command.withShortDescription('List run events'));
|
|
58
58
|
const state = Command.make('state', {
|
|
59
|
-
runId: Argument.
|
|
59
|
+
runId: Argument.String('runId').pipe(Argument.withDescription('Run id')),
|
|
60
60
|
}, Effect.fn('state')(function* ({ runId }) {
|
|
61
61
|
const { url } = yield* loomsBase;
|
|
62
62
|
const result = yield* tryClient(() => clientFor(url).getRun(runId));
|
|
63
63
|
yield* Console.log(stringifyJsonPretty(result));
|
|
64
64
|
})).pipe(Command.withDescription('Show run state'), Command.withShortDescription('Show run state'));
|
|
65
65
|
const approve = Command.make('approve', {
|
|
66
|
-
runId: Argument.
|
|
67
|
-
approvalId: Argument.
|
|
68
|
-
accept: Flag.
|
|
69
|
-
reject: Flag.
|
|
66
|
+
runId: Argument.String('runId').pipe(Argument.withDescription('Run id')),
|
|
67
|
+
approvalId: Argument.String('approvalId').pipe(Argument.withDescription('Pending approval id')),
|
|
68
|
+
accept: Flag.Boolean('approve').pipe(Flag.withAlias('a'), Flag.withDescription('Approve the request'), Flag.withDefault(false)),
|
|
69
|
+
reject: Flag.Boolean('reject').pipe(Flag.withAlias('r'), Flag.withDescription('Reject the request'), Flag.withDefault(false)),
|
|
70
70
|
}, Effect.fn('approve')(function* ({ runId, approvalId, accept, reject }) {
|
|
71
71
|
if (accept === reject) {
|
|
72
72
|
return yield* new CliError.UserError({
|
|
@@ -81,33 +81,33 @@ const approve = Command.make('approve', {
|
|
|
81
81
|
return undefined;
|
|
82
82
|
})).pipe(Command.withDescription('Approve or reject a pending approval'), Command.withShortDescription('Decide an approval'));
|
|
83
83
|
const replay = Command.make('replay', {
|
|
84
|
-
runId: Argument.
|
|
85
|
-
seq: Argument.
|
|
84
|
+
runId: Argument.String('runId').pipe(Argument.withDescription('Run id')),
|
|
85
|
+
seq: Argument.Int('seq').pipe(Argument.withDescription('Event sequence to replay through')),
|
|
86
86
|
}, Effect.fn('replay')(function* ({ runId, seq }) {
|
|
87
87
|
const { url } = yield* loomsBase;
|
|
88
88
|
const result = yield* tryClient(() => clientFor(url).replayTo(runId, seq));
|
|
89
89
|
yield* Console.log(stringifyJsonPretty(result));
|
|
90
90
|
})).pipe(Command.withDescription('Replay a run to a sequence'), Command.withShortDescription('Replay to seq'));
|
|
91
91
|
const signal = Command.make('signal', {
|
|
92
|
-
runId: Argument.
|
|
93
|
-
type: Argument.
|
|
94
|
-
json: Argument.
|
|
92
|
+
runId: Argument.String('runId').pipe(Argument.withDescription('Run id')),
|
|
93
|
+
type: Argument.String('type').pipe(Argument.withDescription('Event type')),
|
|
94
|
+
json: Argument.String('json').pipe(Argument.withDescription('Optional JSON payload'), Argument.optional),
|
|
95
95
|
}, Effect.fn('signal')(function* ({ runId, type, json }) {
|
|
96
96
|
const { url } = yield* loomsBase;
|
|
97
97
|
const result = yield* tryClient(() => clientFor(url).signal(runId, [{ type, payload: parseJsonArg(json) }]));
|
|
98
98
|
yield* Console.log(stringifyJsonPretty(result));
|
|
99
99
|
})).pipe(Command.withDescription('Append an external event and wake the run'), Command.withShortDescription('Signal a run'));
|
|
100
100
|
const steer = Command.make('steer', {
|
|
101
|
-
runId: Argument.
|
|
102
|
-
message: Argument.
|
|
103
|
-
interrupt: Flag.
|
|
101
|
+
runId: Argument.String('runId').pipe(Argument.withDescription('Run id')),
|
|
102
|
+
message: Argument.String('message').pipe(Argument.withDescription('Steering message'), Argument.variadic({ min: 1 })),
|
|
103
|
+
interrupt: Flag.Boolean('interrupt').pipe(Flag.withDescription('Interrupt the current turn (use --no-interrupt to disable)'), Flag.withDefault(true)),
|
|
104
104
|
}, Effect.fn('steer')(function* ({ runId, message, interrupt }) {
|
|
105
105
|
const { url } = yield* loomsBase;
|
|
106
106
|
const result = yield* tryClient(() => clientFor(url).signal(runId, [steerEvent({ content: message.join(' '), interrupt })]));
|
|
107
107
|
yield* Console.log(stringifyJsonPretty(result));
|
|
108
108
|
})).pipe(Command.withDescription('Send a steering message to a running agent'), Command.withShortDescription('Steer an agent'));
|
|
109
109
|
const tail = Command.make('tail', {
|
|
110
|
-
runId: Argument.
|
|
110
|
+
runId: Argument.String('runId').pipe(Argument.withDescription('Run id')),
|
|
111
111
|
}, Effect.fn('tail')(function* ({ runId }) {
|
|
112
112
|
const { url } = yield* loomsBase;
|
|
113
113
|
const client = clientFor(url);
|
|
@@ -120,9 +120,9 @@ const tail = Command.make('tail', {
|
|
|
120
120
|
yield* Stream.fromQueue(queue).pipe(Stream.runForEach((line) => Console.log(line)));
|
|
121
121
|
}));
|
|
122
122
|
})).pipe(Command.withDescription('Stream events for a run'), Command.withShortDescription('Tail run events'));
|
|
123
|
-
const databaseFlag = Flag.
|
|
124
|
-
const dialectFlag = Flag.
|
|
125
|
-
const configFlag = Flag.optional(Flag.
|
|
123
|
+
const databaseFlag = Flag.String('database').pipe(Flag.withDescription('Postgres connection string, or a SQLite file path with --dialect sqlite (env DATABASE_URL)'), Flag.withFallbackConfig(Config.String('DATABASE_URL')));
|
|
124
|
+
const dialectFlag = Flag.String('dialect').pipe(Flag.withDescription('Replica dialect: postgres (default) or sqlite'), Flag.withDefault('postgres'));
|
|
125
|
+
const configFlag = Flag.optional(Flag.String('config').pipe(Flag.withDescription('Module that exports the run attributes from defineRunAttributes, as `attributes` or default')));
|
|
126
126
|
const RunAttributeFieldsSchema = Schema.Record(Schema.String, Schema.Struct({
|
|
127
127
|
required: Schema.optional(Schema.Boolean),
|
|
128
128
|
index: Schema.optional(Schema.Boolean),
|
|
@@ -180,10 +180,10 @@ function openReplica(dialect, database, migrate, additionalFields) {
|
|
|
180
180
|
};
|
|
181
181
|
}
|
|
182
182
|
const generate = Command.make('generate', {
|
|
183
|
-
out: Flag.
|
|
183
|
+
out: Flag.String('out').pipe(Flag.withDescription('Directory of SQL migrations to write into')),
|
|
184
184
|
dialect: dialectFlag,
|
|
185
|
-
journal: Flag.optional(Flag.
|
|
186
|
-
check: Flag.
|
|
185
|
+
journal: Flag.optional(Flag.String('journal').pipe(Flag.withDescription('Also update a migration journal. Only `drizzle` is supported, and only for Postgres'))),
|
|
186
|
+
check: Flag.Boolean('check').pipe(Flag.withDescription('Exit non-zero when a migration is pending, and write nothing'), Flag.withDefault(false)),
|
|
187
187
|
config: configFlag,
|
|
188
188
|
}, Effect.fn('replica.generate')(function* ({ out, dialect, journal, check, config }) {
|
|
189
189
|
const parsed = asDialect(dialect);
|
|
@@ -246,7 +246,7 @@ const migrate = Command.make('migrate', { database: databaseFlag, dialect: diale
|
|
|
246
246
|
const status = Command.make('status', {
|
|
247
247
|
database: databaseFlag,
|
|
248
248
|
dialect: dialectFlag,
|
|
249
|
-
run: Flag.optional(Flag.
|
|
249
|
+
run: Flag.optional(Flag.String('run').pipe(Flag.withDescription('Also print freshness for this run id'))),
|
|
250
250
|
config: configFlag,
|
|
251
251
|
}, Effect.fn('replica.status')(function* ({ database, dialect, run, config }) {
|
|
252
252
|
const parsed = asDialect(dialect);
|
|
@@ -290,6 +290,7 @@ export const looms = loomsBase.pipe(Command.withSubcommands([
|
|
|
290
290
|
export const cliTestLayer = Layer.mergeAll(FileSystem.layerNoop({}), Path.layer, Stdio.layerTest({}), Layer.succeed(Terminal.Terminal, Terminal.make({
|
|
291
291
|
columns: Effect.succeed(80),
|
|
292
292
|
rows: Effect.succeed(24),
|
|
293
|
+
size: Effect.die('unused'),
|
|
293
294
|
readInput: Effect.die('unused'),
|
|
294
295
|
readLine: Effect.die('unused'),
|
|
295
296
|
display: () => Effect.void,
|
|
@@ -9,8 +9,8 @@ const PREFIX = 'looms/blobs/';
|
|
|
9
9
|
export function r2BlobStore(bucket) {
|
|
10
10
|
return blobStoreFromBytes(r2BlobBytes(bucket));
|
|
11
11
|
}
|
|
12
|
+
const keyFor = (key) => `${PREFIX}${key}`;
|
|
12
13
|
function r2BlobBytes(bucket) {
|
|
13
|
-
const keyFor = (key) => `${PREFIX}${key}`;
|
|
14
14
|
return {
|
|
15
15
|
read: (key) => Effect.tryPromise({
|
|
16
16
|
try: () => bucket.get(keyFor(key)),
|
|
@@ -6,11 +6,11 @@ declare const DefinitionResolveError_base: new <A extends Record<string, any> =
|
|
|
6
6
|
} & Readonly<A>;
|
|
7
7
|
export declare class DefinitionResolveError extends DefinitionResolveError_base<{
|
|
8
8
|
readonly kind: string;
|
|
9
|
-
readonly
|
|
9
|
+
readonly definitionName: string;
|
|
10
10
|
readonly version: string;
|
|
11
11
|
readonly message: string;
|
|
12
12
|
}> {
|
|
13
|
-
constructor(kind: string,
|
|
13
|
+
constructor(kind: string, definitionName: string, version: string, message: string);
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* Loads one definition by the identity pinned on a run.
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Data, Effect, Predicate } from 'effect';
|
|
2
2
|
import { DEFAULT_DEFINITION_VERSION, definitionKey } from './module.js';
|
|
3
3
|
export class DefinitionResolveError extends Data.TaggedError('DefinitionResolveError') {
|
|
4
|
-
constructor(kind,
|
|
5
|
-
super({ kind,
|
|
6
|
-
this.name = 'DefinitionResolveError';
|
|
4
|
+
constructor(kind, definitionName, version, message) {
|
|
5
|
+
super({ kind, definitionName, version, message });
|
|
7
6
|
}
|
|
8
7
|
}
|
|
9
8
|
export const DEFAULT_DEFINITION_CACHE_CAPACITY = 256;
|
|
@@ -26,9 +26,8 @@ export function makeDefinitionStore(kind, definitions) {
|
|
|
26
26
|
return Effect.succeed(stored);
|
|
27
27
|
}
|
|
28
28
|
if (!resolver) {
|
|
29
|
-
// Effect.
|
|
30
|
-
|
|
31
|
-
return Effect.succeed(undefined);
|
|
29
|
+
// Effect.undefined, not Effect.void: a missing definition is `undefined`, not `void`.
|
|
30
|
+
return Effect.undefined;
|
|
32
31
|
}
|
|
33
32
|
return resolver
|
|
34
33
|
.resolve(kind, name, version)
|