@swirls/looms 0.17.0 → 0.18.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 +15 -0
- package/dist/actor/cell.d.ts +5 -1
- package/dist/actor/cell.js +2 -0
- package/dist/actor/host.d.ts +5 -1
- package/dist/actor/host.js +2 -0
- package/dist/agent/effects.d.ts +266 -266
- package/dist/client/client.d.ts +1 -0
- package/dist/client/client.js +10 -4
- package/dist/cloudflare/durable-object.d.ts +5 -1
- package/dist/cloudflare/durable-object.js +2 -0
- package/dist/cloudflare/queue-consumer.js +11 -3
- package/dist/core/effects.d.ts +1 -1
- package/dist/core/module.d.ts +1 -0
- package/dist/core/run-context.d.ts +6 -2
- package/dist/core/sqlite-store.js +6 -0
- package/dist/core/store.js +5 -0
- package/dist/core/worker-callback.d.ts +5 -2
- package/dist/debugger/app/assets/{index-Br9tGbPI.js → index-BjZn1DuJ.js} +2 -2
- package/dist/debugger/app/assets/{routes-CZ0buqO7.js → routes-B90xnBF1.js} +2 -2
- package/dist/debugger/app/index.html +1 -1
- package/dist/runtime/effect-admission.d.ts +8 -3
- package/dist/runtime/effect-admission.js +23 -4
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.js +2 -0
- package/dist/runtime/local-effect-executor.d.ts +8 -2
- package/dist/runtime/local-effect-executor.js +21 -8
- package/dist/runtime/looms.d.ts +6 -0
- package/dist/runtime/looms.js +2 -0
- package/dist/runtime/observer.d.ts +15 -0
- package/dist/runtime/run-secrets.d.ts +132 -0
- package/dist/runtime/run-secrets.js +154 -0
- package/dist/runtime/runtime.js +27 -25
- package/dist/runtime/secret-sealer.d.ts +24 -0
- package/dist/runtime/secret-sealer.js +120 -0
- package/dist/runtime/server/routes/runs.js +2 -1
- package/dist/runtime/types.d.ts +20 -7
- package/dist/runtime/wake-engine.d.ts +2 -0
- package/dist/runtime/wake-engine.js +23 -9
- package/dist/runtime/worker-callbacks.d.ts +4 -2
- package/dist/runtime/worker-callbacks.js +15 -2
- package/dist/runtime/worker-effect-dispatch.d.ts +1 -2
- package/dist/runtime/worker-effect-dispatch.js +0 -1
- package/dist/schedule/module.d.ts +36 -36
- package/dist/workflow/module.d.ts +32 -32
- package/package.json +1 -1
package/dist/client/client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Data, Effect, Option, Predicate, Schema, Stream } from 'effect';
|
|
2
|
-
import { createRunId, DefinitionCatalogSchema, EffectCatalogSchema, EventEnvelopeSchema, EventTypeCatalogSchema, JsonValueSchema, readSubscriptionData, ReplayStepSchema, RunStateSchema, RunSummariesSchema, SecretContextSchema, SignalCatalogSchema, stringifyJson, traceHeaders, } from '@swirls/looms/core';
|
|
2
|
+
import { createRunId, DefinitionCatalogSchema, EffectCatalogSchema, EventEnvelopeSchema, cleanUndefined, EventTypeCatalogSchema, JsonValueSchema, readSubscriptionData, ReplayStepSchema, RunStateSchema, RunSummariesSchema, SecretContextSchema, SignalCatalogSchema, stringifyJson, traceHeaders, } from '@swirls/looms/core';
|
|
3
3
|
import { consumeSseStreamEffect, eventsFromSseData, sseFrames } from './sse.js';
|
|
4
4
|
class LoomsClientError extends Data.TaggedError('LoomsClientError') {
|
|
5
5
|
constructor(message, cause) {
|
|
@@ -52,7 +52,13 @@ const WorkerCallbackResultSchema = Schema.Struct({
|
|
|
52
52
|
});
|
|
53
53
|
const WorkerSecretsResultSchema = Schema.Union([
|
|
54
54
|
Schema.Struct({ status: Schema.Literal('accepted'), secrets: SecretContextSchema }),
|
|
55
|
-
Schema.Struct({
|
|
55
|
+
Schema.Struct({
|
|
56
|
+
status: Schema.Union([
|
|
57
|
+
Schema.Literal('stale'),
|
|
58
|
+
Schema.Literal('cancelled'),
|
|
59
|
+
Schema.Literal('unavailable'),
|
|
60
|
+
]),
|
|
61
|
+
}),
|
|
56
62
|
]);
|
|
57
63
|
/** `appended` counts the events the run gained while the wake ran. */
|
|
58
64
|
const WakeResultSchema = Schema.Struct({
|
|
@@ -197,7 +203,7 @@ export function createLoomsClient(options = {}) {
|
|
|
197
203
|
body: stringifyJson(body),
|
|
198
204
|
});
|
|
199
205
|
};
|
|
200
|
-
/** Read the
|
|
206
|
+
/** Read the secrets for one attempt. Only the attempt that is currently running gets them. */
|
|
201
207
|
const workerSecrets = (runId, attempt) => request(`${attemptPath(runId, attempt)}/secrets`, WorkerSecretsResultSchema, {
|
|
202
208
|
method: 'POST',
|
|
203
209
|
headers: workerHeaders,
|
|
@@ -274,7 +280,7 @@ export function createLoomsClient(options = {}) {
|
|
|
274
280
|
/** Start a new run that continues where a finished run ended. */
|
|
275
281
|
fork: (sourceRunId, forkOptions) => request(`/runs/${encodeURIComponent(sourceRunId)}/fork`, StartResultSchema, {
|
|
276
282
|
method: 'POST',
|
|
277
|
-
body: stringifyJson(
|
|
283
|
+
body: stringifyJson(cleanUndefined({ runId: forkOptions?.runId, secrets: forkOptions?.secrets })),
|
|
278
284
|
}),
|
|
279
285
|
workerCallback,
|
|
280
286
|
workerSecrets,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DurableObject } from 'cloudflare:workers';
|
|
2
2
|
import { type AnyRuntimeModule, type DefinitionResolver, type EventInput, type BlobStore, type EventStoreTrimCoverage, type LaunchRunArgs, type RunAttributeFields, type RunLauncher, type RunState, type RunStatusSnapshot } from '@swirls/looms/core';
|
|
3
3
|
import type { Projector } from '@swirls/looms/projectors';
|
|
4
|
-
import { type Authorize, type EffectWorker, type RunSignalOptions, type StartResult, type StartRunArgs, type RuntimeObserver } from '@swirls/looms/runtime';
|
|
4
|
+
import { type Authorize, type EffectWorker, type RunSignalOptions, type StartResult, type StartRunArgs, type RuntimeObserver, type SecretProvider, type SecretSealer } from '@swirls/looms/runtime';
|
|
5
5
|
import { type DeleteTerminalRunStorageOptions } from './delete-terminal-run-storage';
|
|
6
6
|
export interface LoomsDurableObjectConfig {
|
|
7
7
|
readonly modules: readonly AnyRuntimeModule[];
|
|
@@ -11,6 +11,10 @@ export interface LoomsDurableObjectConfig {
|
|
|
11
11
|
readonly attributes?: RunAttributeFields;
|
|
12
12
|
/** Told about wakes, appends, snapshots and effect attempts. See `CreateRuntimeOptions`. */
|
|
13
13
|
readonly observer?: RuntimeObserver;
|
|
14
|
+
/** Decides what a run holds and what each attempt receives. See `CreateRuntimeOptions`. */
|
|
15
|
+
readonly secretProvider?: SecretProvider;
|
|
16
|
+
/** Encrypts what a run holds before it is stored. See `secretSealer`. */
|
|
17
|
+
readonly secretSealer?: SecretSealer;
|
|
14
18
|
readonly projectors?: readonly Projector[];
|
|
15
19
|
/** Content-addressed store for event and snapshot JSON over the inline byte limits. */
|
|
16
20
|
readonly blobs?: BlobStore;
|
|
@@ -55,6 +55,8 @@ export class LoomsDurableObject extends DurableObject {
|
|
|
55
55
|
definitionResolver: config.definitionResolver,
|
|
56
56
|
attributes: config.attributes,
|
|
57
57
|
observer: config.observer,
|
|
58
|
+
secretProvider: config.secretProvider,
|
|
59
|
+
secretSealer: config.secretSealer,
|
|
58
60
|
snapshotEvery: config.snapshotEvery,
|
|
59
61
|
maxWakeIterations: config.maxWakeIterations,
|
|
60
62
|
livenessLeaseMs: config.livenessLeaseMs,
|
|
@@ -71,10 +71,18 @@ function runAttempt(task, attempt, handler, cancelRequested, options) {
|
|
|
71
71
|
if (result.status === 'accepted') {
|
|
72
72
|
return Effect.succeed(result.secrets);
|
|
73
73
|
}
|
|
74
|
+
// The host could not produce the secrets this time. The attempt fails under its retry
|
|
75
|
+
// policy, so a later attempt can ask again.
|
|
76
|
+
if (result.status === 'unavailable') {
|
|
77
|
+
return Effect.fail(new QueueTaskError({ message: 'secrets are unavailable for this attempt' }));
|
|
78
|
+
}
|
|
74
79
|
controller.abort();
|
|
75
|
-
return Effect.fail(new
|
|
76
|
-
|
|
77
|
-
|
|
80
|
+
return Effect.fail(new QueueTaskError({
|
|
81
|
+
message: `the attempt is ${result.status}`,
|
|
82
|
+
nonRetryable: true,
|
|
83
|
+
}));
|
|
84
|
+
}), Effect.catchTag('CallbackError', (error) => Effect.fail(new QueueTaskError({ message: error.message, nonRetryable: true }))));
|
|
85
|
+
return taskInput(task, options.blobs).pipe(Effect.flatMap((input) => loadSecrets().pipe(Effect.flatMap((secrets) => {
|
|
78
86
|
const ctx = {
|
|
79
87
|
placement: 'worker',
|
|
80
88
|
effectId: task.effectId,
|
package/dist/core/effects.d.ts
CHANGED
|
@@ -177,7 +177,7 @@ export interface EffectContextBase {
|
|
|
177
177
|
/** Labels safe for every reader of the run. */
|
|
178
178
|
readonly attributes: RunAttributes;
|
|
179
179
|
/**
|
|
180
|
-
* Bearer material for this
|
|
180
|
+
* Bearer material for this attempt. Never copy it into an emitted event.
|
|
181
181
|
* On a durable worker transport this is loaded before the handler runs (same shape as local).
|
|
182
182
|
*/
|
|
183
183
|
readonly secrets: SecretContext;
|
package/dist/core/module.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export interface EffectAdmissionContext {
|
|
|
37
37
|
readonly threadId: string;
|
|
38
38
|
readonly causingEventId: string;
|
|
39
39
|
readonly attributes: RunAttributes;
|
|
40
|
+
/** The secrets this attempt will receive. */
|
|
40
41
|
readonly secrets: SecretContext;
|
|
41
42
|
readonly trace: TraceContext | null;
|
|
42
43
|
}
|
|
@@ -8,8 +8,9 @@ export type RunAttributes = {
|
|
|
8
8
|
readonly [key: string]: string;
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
|
-
* Bearer material
|
|
12
|
-
*
|
|
11
|
+
* Bearer material, such as an attenuated macaroon. For a run it is stored beside the log, and it
|
|
12
|
+
* is never written to an event, snapshot, or HTTP response. For an attempt it is what the
|
|
13
|
+
* attempt's handler receives as `ctx.secrets`.
|
|
13
14
|
*/
|
|
14
15
|
export type SecretContext = {
|
|
15
16
|
readonly [key: string]: string;
|
|
@@ -67,7 +68,10 @@ export declare const RunAttributesSchema: Schema.$Record<Schema.String, Schema.S
|
|
|
67
68
|
export declare const SecretContextSchema: Schema.$Record<Schema.String, Schema.String>;
|
|
68
69
|
export interface RunSecretStore {
|
|
69
70
|
readonly get: (runId: string) => Effect.Effect<SecretContext, Error>;
|
|
71
|
+
/** Replaces what is stored for the run. */
|
|
70
72
|
readonly put: (runId: string, secrets: SecretContext) => Effect.Effect<void, Error>;
|
|
73
|
+
/** Removes what is stored for the run. Deleting a run that has nothing stored succeeds. */
|
|
74
|
+
readonly delete: (runId: string) => Effect.Effect<void, Error>;
|
|
71
75
|
}
|
|
72
76
|
export declare function hasEntries(record: {
|
|
73
77
|
readonly [key: string]: string;
|
|
@@ -265,6 +265,12 @@ function createSqliteSecrets(exec) {
|
|
|
265
265
|
},
|
|
266
266
|
catch: (cause) => new EventStoreError(`Failed to store secret context for ${runId}`, cause),
|
|
267
267
|
}),
|
|
268
|
+
delete: (runId) => Effect.try({
|
|
269
|
+
try: () => {
|
|
270
|
+
exec.run('DELETE FROM looms_run_secrets WHERE run_id = ?', [runId]);
|
|
271
|
+
},
|
|
272
|
+
catch: (cause) => new EventStoreError(`Failed to delete secret context for ${runId}`, cause),
|
|
273
|
+
}),
|
|
268
274
|
};
|
|
269
275
|
}
|
|
270
276
|
function createSqliteEventStore(exec) {
|
package/dist/core/store.js
CHANGED
|
@@ -122,6 +122,11 @@ export const makeMemoryEventStore = Effect.gen(function* () {
|
|
|
122
122
|
const runSecrets = {
|
|
123
123
|
get: (runId) => Ref.get(secrets).pipe(Effect.map((map) => readSecretContext(map.get(runId) ?? {}))),
|
|
124
124
|
put: (runId, value) => Ref.update(secrets, (map) => new Map(map).set(runId, value)),
|
|
125
|
+
delete: (runId) => Ref.update(secrets, (map) => {
|
|
126
|
+
const next = new Map(map);
|
|
127
|
+
next.delete(runId);
|
|
128
|
+
return next;
|
|
129
|
+
}),
|
|
125
130
|
};
|
|
126
131
|
const getOrCreate = (map, runId) => {
|
|
127
132
|
const existing = map.get(runId);
|
|
@@ -32,10 +32,13 @@ export interface WorkerCallbackResult {
|
|
|
32
32
|
readonly status: 'accepted' | 'stale' | 'cancelled';
|
|
33
33
|
readonly cancelRequested: boolean;
|
|
34
34
|
}
|
|
35
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* The secrets for one attempt, released only to the attempt that is currently running.
|
|
37
|
+
* `unavailable` means the host could not produce them this time; the attempt can be retried.
|
|
38
|
+
*/
|
|
36
39
|
export type WorkerSecretsResult = {
|
|
37
40
|
readonly status: 'accepted';
|
|
38
41
|
readonly secrets: SecretContext;
|
|
39
42
|
} | {
|
|
40
|
-
readonly status: 'stale' | 'cancelled';
|
|
43
|
+
readonly status: 'stale' | 'cancelled' | 'unavailable';
|
|
41
44
|
};
|