@swirls/looms 0.11.3 → 0.12.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 +18 -4
- package/dist/actor/routing.d.ts +2 -2
- package/dist/actor/routing.js +9 -3
- package/dist/client/client.d.ts +352 -1
- package/dist/client/client.js +28 -12
- package/dist/debugger/app/assets/{index-D13zm4x1.js → index-B_KJqkH1.js} +2 -2
- package/dist/debugger/app/assets/{routes-BrDGfYv0.js → routes-oKOihm_o.js} +2 -2
- package/dist/debugger/app/index.html +1 -1
- package/dist/runtime/looms.d.ts +9 -1
- package/dist/runtime/looms.js +13 -0
- package/dist/runtime/server/fetch-handler.js +2 -1
- package/dist/runtime/server/routes/runs.js +38 -18
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>Looms debugger</title>
|
|
7
|
-
<script type="module" crossorigin src="./assets/index-
|
|
7
|
+
<script type="module" crossorigin src="./assets/index-B_KJqkH1.js"></script>
|
|
8
8
|
<link rel="modulepreload" crossorigin href="./assets/rolldown-runtime-CbXtAM7H.js">
|
|
9
9
|
<link rel="stylesheet" crossorigin href="./assets/index-CO5gIvV8.css">
|
|
10
10
|
</head>
|
package/dist/runtime/looms.d.ts
CHANGED
|
@@ -93,9 +93,17 @@ export interface Looms<Fields extends RunAttributeFields = RunAttributeFields> {
|
|
|
93
93
|
}>;
|
|
94
94
|
/** Start a run from a definition object; the input type follows the definition's schema. */
|
|
95
95
|
start<TDef extends DefinitionRef>(definition: TDef, ...args: LoomsStartArgs<TDef, Fields>): Promise<StartResult>;
|
|
96
|
+
/**
|
|
97
|
+
* Like `start`, but answers once the start is committed and leaves the first wake to the
|
|
98
|
+
* scheduler.
|
|
99
|
+
*/
|
|
100
|
+
launch<TDef extends DefinitionRef>(definition: TDef, ...args: LoomsStartArgs<TDef, Fields>): Promise<StartResult>;
|
|
96
101
|
/** Start a run by `{ kind, definitionName }` when you only have names (HTTP bodies, CLIs). */
|
|
97
102
|
startRun(args: LoomsStartRunArgs<Fields>): Promise<StartResult>;
|
|
98
|
-
/**
|
|
103
|
+
/**
|
|
104
|
+
* Like `startRun`, but answers once the start is committed and leaves the first wake to the
|
|
105
|
+
* scheduler.
|
|
106
|
+
*/
|
|
99
107
|
launchRun(args: LoomsStartRunArgs<Fields>): Promise<StartResult>;
|
|
100
108
|
getRun(runId: string): Promise<RunState>;
|
|
101
109
|
getEvents(runId: string, options?: {
|
package/dist/runtime/looms.js
CHANGED
|
@@ -101,6 +101,19 @@ export function createLooms(options = {}) {
|
|
|
101
101
|
secrets: startOpts?.secrets,
|
|
102
102
|
trace: startOpts?.trace,
|
|
103
103
|
})),
|
|
104
|
+
launch: (definition, input, startOpts) => runEffect((i) => i.runtime.launchRun({
|
|
105
|
+
kind: definition.kind,
|
|
106
|
+
definitionName: definition.name,
|
|
107
|
+
definitionVersion: definition.version,
|
|
108
|
+
// SAFETY: input is validated against the definition's schema inside launchRun.
|
|
109
|
+
input: input,
|
|
110
|
+
runId: startOpts?.runId,
|
|
111
|
+
threadId: startOpts?.threadId,
|
|
112
|
+
idempotencyKey: startOpts?.idempotencyKey,
|
|
113
|
+
attributes: startOpts?.attributes,
|
|
114
|
+
secrets: startOpts?.secrets,
|
|
115
|
+
trace: startOpts?.trace,
|
|
116
|
+
})),
|
|
104
117
|
getRun: (runId) => runEffect((i) => i.runtime.getRun(runId)),
|
|
105
118
|
getEvents: (runId, opts) => runEffect((i) => i.runtime.getEvents(runId, opts)),
|
|
106
119
|
signal: (runId, events, signalOpts) => runEffect((i) => i.runtime.signal(runId, events, signalOpts)),
|
|
@@ -23,6 +23,7 @@ const StartAttributesSchema = Schema.Struct({
|
|
|
23
23
|
class UnreadableStartBody extends Data.TaggedError('UnreadableStartBody') {
|
|
24
24
|
}
|
|
25
25
|
const noAttributes = {};
|
|
26
|
+
const START_ROUTES = new Set(['runs.start', 'runs.launch']);
|
|
26
27
|
function readRequestAttributes(req) {
|
|
27
28
|
return Effect.tryPromise({
|
|
28
29
|
try: () => req.clone().json(),
|
|
@@ -42,7 +43,7 @@ function authorizeRoute(req, matched, authorize, runtime, store) {
|
|
|
42
43
|
const stored = Predicate.isString(runId)
|
|
43
44
|
? yield* readStoredAttributes(runtime, store, runId)
|
|
44
45
|
: noAttributes;
|
|
45
|
-
const requested =
|
|
46
|
+
const requested = START_ROUTES.has(name) ? yield* readRequestAttributes(req) : noAttributes;
|
|
46
47
|
const attributes = hasEntries(stored) ? stored : requested;
|
|
47
48
|
const route = Predicate.isString(runId)
|
|
48
49
|
? hasEntries(attributes)
|
|
@@ -32,6 +32,27 @@ const CancelBodySchema = Schema.Struct({
|
|
|
32
32
|
const ForkBodySchema = Schema.Struct({
|
|
33
33
|
runId: Schema.optional(Schema.String),
|
|
34
34
|
});
|
|
35
|
+
function readStartRunArgs(req) {
|
|
36
|
+
return Effect.gen(function* () {
|
|
37
|
+
const body = yield* readJson(req).pipe(Effect.flatMap(Schema.decodeUnknownEffect(StartRunBodySchema)));
|
|
38
|
+
const definitionName = body.definitionName ?? body.name;
|
|
39
|
+
const kind = body.kind;
|
|
40
|
+
if (!definitionName || !kind) {
|
|
41
|
+
return Response.json({ error: 'kind and definitionName required' }, { status: 400 });
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
kind,
|
|
45
|
+
definitionName,
|
|
46
|
+
definitionVersion: body.definitionVersion,
|
|
47
|
+
input: body.input ?? null,
|
|
48
|
+
runId: body.runId ?? createRunId(),
|
|
49
|
+
idempotencyKey: extractIdempotencyKey(req, body.idempotencyKey),
|
|
50
|
+
attributes: body.attributes,
|
|
51
|
+
secrets: body.secrets,
|
|
52
|
+
trace: readTraceHeaders(req.headers),
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
}
|
|
35
56
|
function wantsRunStream(req, url) {
|
|
36
57
|
return url.searchParams.get('stream') === 'true' || acceptsEventStream(req);
|
|
37
58
|
}
|
|
@@ -94,25 +115,10 @@ export function runRoutes({ runtime, store }) {
|
|
|
94
115
|
name: 'runs.start',
|
|
95
116
|
access: 'write',
|
|
96
117
|
handle: ({ req, url }) => Effect.gen(function* () {
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (!definitionName || !kind) {
|
|
101
|
-
return Response.json({ error: 'kind and definitionName required' }, { status: 400 });
|
|
118
|
+
const args = yield* readStartRunArgs(req);
|
|
119
|
+
if (args instanceof Response) {
|
|
120
|
+
return args;
|
|
102
121
|
}
|
|
103
|
-
const runId = body.runId ?? createRunId();
|
|
104
|
-
const idempotencyKey = extractIdempotencyKey(req, body.idempotencyKey);
|
|
105
|
-
const args = {
|
|
106
|
-
kind,
|
|
107
|
-
definitionName,
|
|
108
|
-
definitionVersion: body.definitionVersion,
|
|
109
|
-
input: body.input ?? null,
|
|
110
|
-
runId,
|
|
111
|
-
idempotencyKey,
|
|
112
|
-
attributes: body.attributes,
|
|
113
|
-
secrets: body.secrets,
|
|
114
|
-
trace: readTraceHeaders(req.headers),
|
|
115
|
-
};
|
|
116
122
|
if (wantsRunStream(req, url)) {
|
|
117
123
|
return streamStartRun(req, runtime, store, args);
|
|
118
124
|
}
|
|
@@ -120,6 +126,20 @@ export function runRoutes({ runtime, store }) {
|
|
|
120
126
|
return Response.json(result);
|
|
121
127
|
}),
|
|
122
128
|
}),
|
|
129
|
+
route({
|
|
130
|
+
method: 'POST',
|
|
131
|
+
path: '/runs/launch',
|
|
132
|
+
name: 'runs.launch',
|
|
133
|
+
access: 'write',
|
|
134
|
+
handle: ({ req }) => Effect.gen(function* () {
|
|
135
|
+
const args = yield* readStartRunArgs(req);
|
|
136
|
+
if (args instanceof Response) {
|
|
137
|
+
return args;
|
|
138
|
+
}
|
|
139
|
+
const result = yield* provideStore(runtime.launchRun(args), store);
|
|
140
|
+
return Response.json(result);
|
|
141
|
+
}),
|
|
142
|
+
}),
|
|
123
143
|
route({
|
|
124
144
|
method: 'GET',
|
|
125
145
|
path: '/runs/:runId/replay',
|