@swirls/looms 0.6.1 → 0.8.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 +26 -0
- package/dist/actor/cell.d.ts +1 -1
- package/dist/actor/routing.d.ts +5 -1
- package/dist/actor/routing.js +14 -3
- package/dist/agent/effects.d.ts +20 -2
- package/dist/agent/effects.js +2 -0
- package/dist/agent/module.d.ts +40 -4
- package/dist/approval/effects.d.ts +10 -1
- package/dist/approval/effects.js +1 -0
- package/dist/approval/module.d.ts +20 -2
- package/dist/cli/commands.js +65 -1
- package/dist/client/client.d.ts +38 -10
- package/dist/client/client.js +2 -1
- package/dist/cloudflare/durable-object.d.ts +1 -1
- package/dist/cloudflare/index.d.ts +1 -1
- package/dist/cloudflare/index.js +1 -1
- package/dist/cloudflare/queue-consumer.d.ts +17 -10
- package/dist/cloudflare/queue-consumer.js +63 -27
- package/dist/cloudflare/queue-message.d.ts +4 -1
- package/dist/cloudflare/queue-message.js +4 -1
- package/dist/cloudflare/queue-worker.d.ts +7 -3
- package/dist/cloudflare/queue-worker.js +7 -2
- package/dist/cloudflare/queues.d.ts +1 -1
- package/dist/cloudflare/queues.js +1 -1
- package/dist/core/compose.d.ts +2 -1
- package/dist/core/compose.js +5 -0
- package/dist/core/effects.d.ts +84 -39
- package/dist/core/effects.js +29 -8
- package/dist/core/fold.js +34 -0
- package/dist/core/module-scope.d.ts +22 -8
- package/dist/core/module-scope.js +3 -0
- package/dist/core/module.d.ts +40 -9
- package/dist/core/module.js +25 -6
- package/dist/core/protocol.d.ts +12 -1
- package/dist/core/protocol.js +12 -0
- package/dist/core/published.d.ts +52 -0
- package/dist/core/published.js +45 -0
- package/dist/core/replay.d.ts +4 -2
- package/dist/core/state.d.ts +8 -2
- package/dist/core/state.js +2 -0
- package/dist/debugger/app/assets/{index-CUO1xyYW.js → index-CMRl_aWQ.js} +2 -2
- package/dist/debugger/app/assets/routes-CfXxKG45.js +47 -0
- package/dist/debugger/app/index.html +1 -1
- package/dist/debugger/events/protocol-summarize.js +2 -0
- package/dist/evaluator/effects.d.ts +10 -1
- package/dist/evaluator/effects.js +1 -0
- package/dist/evaluator/module.d.ts +20 -2
- package/dist/projectors/delivery.d.ts +8 -3
- package/dist/projectors/delivery.js +29 -2
- package/dist/projectors/event-log.d.ts +8 -2
- package/dist/projectors/event-log.js +47 -61
- package/dist/projectors/index.d.ts +1 -0
- package/dist/projectors/index.js +1 -0
- package/dist/projectors/postgres.d.ts +4 -1
- package/dist/projectors/postgres.js +6 -4
- package/dist/projectors/projector.d.ts +16 -0
- package/dist/projectors/projector.js +3 -0
- package/dist/projectors/replica/drizzle.d.ts +1192 -0
- package/dist/projectors/replica/drizzle.js +119 -0
- package/dist/projectors/replica/migrations.d.ts +35 -0
- package/dist/projectors/replica/migrations.js +230 -0
- package/dist/projectors/replica/postgres.d.ts +57 -0
- package/dist/projectors/replica/postgres.js +356 -0
- package/dist/projectors/schema.d.ts +2 -1
- package/dist/projectors/schema.js +2 -31
- package/dist/projectors/sqlite-delivery.js +9 -0
- package/dist/runtime/cancellation.js +1 -1
- package/dist/runtime/dispatch-effect.d.ts +2 -2
- package/dist/runtime/dispatch-effect.js +12 -4
- package/dist/runtime/effect-admission.d.ts +45 -0
- package/dist/runtime/effect-admission.js +70 -0
- package/dist/runtime/helpers.d.ts +6 -1
- package/dist/runtime/helpers.js +14 -5
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.js +1 -0
- package/dist/runtime/local-effect-executor.js +25 -3
- package/dist/runtime/retry-policy.js +6 -1
- package/dist/runtime/runtime.js +7 -2
- package/dist/runtime/server/routes/definitions.js +8 -1
- package/dist/runtime/types.d.ts +20 -5
- package/dist/runtime/wake-engine.js +20 -0
- package/dist/runtime/worker-callbacks.js +2 -2
- package/dist/runtime/worker-effect-dispatch.d.ts +35 -9
- package/dist/runtime/worker-effect-dispatch.js +105 -26
- package/dist/schedule/effects.d.ts +20 -2
- package/dist/schedule/effects.js +2 -0
- package/dist/schedule/module.d.ts +76 -40
- package/dist/testing/corpus-module.d.ts +2 -2
- package/dist/testing/corpus-module.js +27 -19
- package/dist/testing/index.js +12 -23
- package/dist/workflow/effects.d.ts +20 -2
- package/dist/workflow/effects.js +2 -0
- package/dist/workflow/module.d.ts +40 -4
- package/package.json +29 -1
- package/dist/debugger/app/assets/routes-lt_6J025.js +0 -47
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Layer } from 'effect';
|
|
2
2
|
import { type CatalogEntries, type EventCatalog, type EventInputOf, type EventsOfCatalog, type InferPayload } from './catalog';
|
|
3
3
|
import type { EventsOf, ProtocolEvents } from './compose';
|
|
4
|
-
import { type EffectDefinition, type
|
|
4
|
+
import { type EffectDefinition, type EffectHandlerResult, type EffectPlacement, type EmitEffect, type LocalEffectDefinition, type PlacedEffectDefinition, type PlacementHandler, type RetryPolicy, type RuntimeEffect, type ScopedLocalEffectContext } from './effects';
|
|
5
5
|
import type { EventEnvelope, EventInput } from './envelope';
|
|
6
6
|
import type { RunLauncherTag } from './launcher';
|
|
7
|
-
import { type AnyRuntimeModule, type DefinitionHost, type EffectMiddleware, type RuntimeModule, type DefinitionRef, type RuntimeModuleDependency, type SignalInterruptRule } from './module';
|
|
7
|
+
import { type AnyRuntimeModule, type DefinitionHost, type EffectAdmission, type EffectMiddleware, type RuntimeModule, type DefinitionRef, type RuntimeModuleDependency, type SignalInterruptRule } from './module';
|
|
8
8
|
import { type ProjectionDefinition } from './projection';
|
|
9
9
|
import type { InferDefinedSchema, InferSchemaOutput, SchemaInput } from './schema';
|
|
10
10
|
import { type StartContext, type ThreadContext, type ThreadDefinition } from './thread';
|
|
@@ -20,8 +20,16 @@ export type ScopeUniverse<TEvents extends EventCatalog | undefined, TObserves ex
|
|
|
20
20
|
export type EffectRequirementsOf<TEffects> = TEffects extends {
|
|
21
21
|
readonly [key: string]: EffectDefinition<any, any, any>;
|
|
22
22
|
} ? Exclude<{
|
|
23
|
-
[K in keyof TEffects]: TEffects[K] extends
|
|
23
|
+
[K in keyof TEffects]: TEffects[K] extends LocalEffectDefinition<any, infer R, any> ? R : never;
|
|
24
24
|
}[keyof TEffects], RunLauncherTag> : never;
|
|
25
|
+
type EffectEventsOf<T> = T extends EffectDefinition<any, any, infer Ev> ? Ev : never;
|
|
26
|
+
/**
|
|
27
|
+
* Marks each effect whose events fall outside the module's catalogs, such as one built with
|
|
28
|
+
* another module's scope or the unscoped `defineEffect`.
|
|
29
|
+
*/
|
|
30
|
+
export type ForeignEffectsCheck<FX, TAllowed> = {
|
|
31
|
+
readonly [K in keyof FX as [EffectEventsOf<FX[K]>] extends [TAllowed] ? never : K]: 'Effect events are outside this module catalog; build it with this module scope';
|
|
32
|
+
};
|
|
25
33
|
export type ModuleServicesConfig<TR> = [TR] extends [never] ? {
|
|
26
34
|
readonly services?: () => Layer.Layer<any>;
|
|
27
35
|
} : {
|
|
@@ -63,14 +71,18 @@ export interface ModuleScope<TNamespace extends string, U extends EventEnvelope<
|
|
|
63
71
|
readonly initialState: InferSchemaOutput<TShape>;
|
|
64
72
|
reduce(state: NoInfer<InferSchemaOutput<TShape>>, event: U): InferSchemaOutput<TShape>;
|
|
65
73
|
}): ProjectionDefinition<InferSchemaOutput<TShape>>;
|
|
66
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Declare an effect for this module. `placement: 'local'` runs `execute` in the host actor cell
|
|
76
|
+
* with live `emit`. `placement: 'worker'` has no `execute`; implement it on the worker with
|
|
77
|
+
* `workerHandlers`. The type must start with the module namespace.
|
|
78
|
+
*/
|
|
79
|
+
effect<const P extends EffectPlacement, TSchema extends SchemaInput | undefined = undefined, TInput = InferDefinedSchema<TSchema>, R = never, HandlerError = never>(def: {
|
|
67
80
|
type: `${TNamespace}.${string}`;
|
|
81
|
+
placement: P;
|
|
68
82
|
input?: TSchema;
|
|
69
83
|
retry?: RetryPolicy;
|
|
70
|
-
execution?: EffectExecution;
|
|
71
84
|
deterministic?: boolean;
|
|
72
|
-
|
|
73
|
-
}): NoInfer<EffectDefinition<TInput, R, EventInputOf<U>>>;
|
|
85
|
+
} & PlacementHandler<P, (input: TInput, ctx: ScopedLocalEffectContext<EventInputOf<U>>) => EffectHandlerResult<R, EventInputOf<U>, HandlerError>>): NoInfer<PlacedEffectDefinition<P, TInput, R, EventInputOf<U>>>;
|
|
74
86
|
input<K extends keyof (TEvents extends EventCatalog<any, infer E> ? E : never) & string>(key: K, payload: InferPayload<(TEvents extends EventCatalog<any, infer E> ? E : never)[K]>, meta?: Omit<EventInput, 'type' | 'payload'>): Omit<EventInput, 'type' | 'payload'> & {
|
|
75
87
|
readonly type: `${TNamespace}.${K}`;
|
|
76
88
|
readonly payload: InferPayload<(TEvents extends EventCatalog<any, infer E> ? E : never)[K]>;
|
|
@@ -92,11 +104,12 @@ export declare function defineModule<const N extends string, E extends EventCata
|
|
|
92
104
|
} = {}>(options: Omit<DefineModuleOptions<N, ModuleCatalog<N, E>, O>, 'events'> & {
|
|
93
105
|
readonly events?: E;
|
|
94
106
|
}, setup: (scope: ModuleScope<N, ScopeUniverse<ModuleCatalog<N, E>, O>, ModuleCatalog<N, E>, O>) => {
|
|
95
|
-
readonly effects?: FX
|
|
107
|
+
readonly effects?: FX & ForeignEffectsCheck<FX, EventInputOf<ScopeUniverse<ModuleCatalog<N, E>, O>>>;
|
|
96
108
|
readonly threads?: TH;
|
|
97
109
|
readonly projections?: PR;
|
|
98
110
|
readonly definitions?: readonly DefinitionRef[];
|
|
99
111
|
readonly middleware?: readonly EffectMiddleware[];
|
|
112
|
+
readonly admission?: readonly EffectAdmission[];
|
|
100
113
|
readonly interruptsOnSignal?: SignalInterruptRule;
|
|
101
114
|
readonly bindHost?: (host: DefinitionHost) => void;
|
|
102
115
|
} & ModuleServicesConfig<EffectRequirementsOf<FX>>): RuntimeModule<N, Extract<ModuleCatalog<N, E>, EventCatalog>, FX, TH, PR> & {
|
|
@@ -104,3 +117,4 @@ export declare function defineModule<const N extends string, E extends EventCata
|
|
|
104
117
|
readonly threads: TH;
|
|
105
118
|
readonly projections: PR;
|
|
106
119
|
};
|
|
120
|
+
export {};
|
|
@@ -72,6 +72,9 @@ export function defineModule(options, setup) {
|
|
|
72
72
|
if (members.middleware) {
|
|
73
73
|
module.middleware = members.middleware;
|
|
74
74
|
}
|
|
75
|
+
if (members.admission) {
|
|
76
|
+
module.admission = members.admission;
|
|
77
|
+
}
|
|
75
78
|
if (members.services) {
|
|
76
79
|
module.services = members.services;
|
|
77
80
|
}
|
package/dist/core/module.d.ts
CHANGED
|
@@ -1,25 +1,51 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Effect, type Context, type Layer } from 'effect';
|
|
2
2
|
import type { EventCatalog } from './catalog';
|
|
3
3
|
import type { DefinitionResolver } from './definition-resolver';
|
|
4
|
-
import { type
|
|
4
|
+
import { type EffectDefinition, type LocalEffectContext, type LocalEffectDefinition, type RuntimeEffect } from './effects';
|
|
5
5
|
import type { EventInput } from './envelope';
|
|
6
6
|
import type { ProjectionDefinition } from './projection';
|
|
7
|
-
import type {
|
|
7
|
+
import type { RunAttributes, SecretContext } from './run-context';
|
|
8
|
+
import { type InferDefinedSchema, type SchemaInput } from './schema';
|
|
8
9
|
import type { ThreadDefinition } from './thread';
|
|
10
|
+
import type { TraceContext } from './trace';
|
|
9
11
|
import type { JsonValue } from './types';
|
|
10
12
|
export { DEFAULT_DEFINITION_VERSION, definitionKey } from './definition-version';
|
|
11
|
-
export type NextEffectHandler = (effect: RuntimeEffect, ctx:
|
|
12
|
-
export type EffectMiddleware = (effect: RuntimeEffect, ctx:
|
|
13
|
+
export type NextEffectHandler = (effect: RuntimeEffect, ctx: LocalEffectContext) => Effect.Effect<ReadonlyArray<EventInput>, Error>;
|
|
14
|
+
export type EffectMiddleware = (effect: RuntimeEffect, ctx: LocalEffectContext, next: NextEffectHandler) => Effect.Effect<ReadonlyArray<EventInput>, Error>;
|
|
13
15
|
/** Continues the middleware chain for the effect `onEffect` already matched. */
|
|
14
16
|
export type OnEffectNext = () => Effect.Effect<ReadonlyArray<EventInput>, Error>;
|
|
15
17
|
/**
|
|
16
|
-
* Middleware that runs only for one effect definition. The handler receives the effect's
|
|
18
|
+
* Middleware that runs only for one **local** effect definition. The handler receives the effect's
|
|
17
19
|
* decoded input type and must call `next()` to continue (or `failEffect` to reject the attempt).
|
|
18
20
|
*
|
|
19
|
-
* Middleware wraps local (in-process) effect dispatch only.
|
|
20
|
-
*
|
|
21
|
+
* Middleware wraps local (in-process) effect dispatch only. Worker-placed effects never see it —
|
|
22
|
+
* pass a {@link LocalEffectDefinition} so that is a type error rather than a silent no-op.
|
|
23
|
+
* Prefer {@link EffectAdmission} / {@link onAdmit} for gates that must apply on both paths.
|
|
21
24
|
*/
|
|
22
|
-
export declare function onEffect<TInput>(definition:
|
|
25
|
+
export declare function onEffect<TInput>(definition: LocalEffectDefinition<TInput>, handler: (input: TInput, ctx: LocalEffectContext, next: OnEffectNext) => Effect.Effect<ReadonlyArray<EventInput>, Error>): EffectMiddleware;
|
|
26
|
+
/**
|
|
27
|
+
* Identity of an effect attempt before it runs locally or is dispatched to a worker.
|
|
28
|
+
* Admission hooks see this on both paths; they cannot call `emit` or `heartbeat`.
|
|
29
|
+
*/
|
|
30
|
+
export interface EffectAdmissionContext {
|
|
31
|
+
readonly effectId: string;
|
|
32
|
+
readonly runId: string;
|
|
33
|
+
readonly threadId: string;
|
|
34
|
+
readonly causingEventId: string;
|
|
35
|
+
readonly attributes: RunAttributes;
|
|
36
|
+
readonly secrets: SecretContext;
|
|
37
|
+
readonly trace: TraceContext | null;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Runs in the host before a local attempt starts and before a worker attempt is queued.
|
|
41
|
+
* Fail with `failEffect` to reject the attempt under the retry policy on either path.
|
|
42
|
+
*/
|
|
43
|
+
export type EffectAdmission = (effect: RuntimeEffect, ctx: EffectAdmissionContext) => Effect.Effect<void, Error>;
|
|
44
|
+
/**
|
|
45
|
+
* Admission that runs only for one effect definition (local or worker). Prefer this over
|
|
46
|
+
* middleware when the gate must apply to worker-placed effects as well as local ones.
|
|
47
|
+
*/
|
|
48
|
+
export declare function onAdmit<TInput>(definition: EffectDefinition<TInput>, handler: (input: TInput, ctx: EffectAdmissionContext) => Effect.Effect<void, Error>): EffectAdmission;
|
|
23
49
|
/**
|
|
24
50
|
* Names the threads whose in-process effects an admitted signal event interrupts, so a running
|
|
25
51
|
* effect (such as a model call) can stop early. The runtime also interrupts each named thread's
|
|
@@ -81,6 +107,11 @@ export interface RuntimeModule<TNamespace extends string = string, TEvents exten
|
|
|
81
107
|
readonly definitions?: readonly DefinitionRef[];
|
|
82
108
|
readonly dependencies?: readonly RuntimeModuleDependency[];
|
|
83
109
|
readonly middleware?: readonly EffectMiddleware[];
|
|
110
|
+
/**
|
|
111
|
+
* Gates that run in the host before every local attempt and before every worker dispatch.
|
|
112
|
+
* Prefer this over middleware for credits, flags, and tenant checks that must cover worker effects.
|
|
113
|
+
*/
|
|
114
|
+
readonly admission?: readonly EffectAdmission[];
|
|
84
115
|
readonly interruptsOnSignal?: SignalInterruptRule;
|
|
85
116
|
/** Host-side services this module's effect handlers need (an LLM, a definition lookup, a DB pool). */
|
|
86
117
|
readonly services?: () => Layer.Layer<TServices>;
|
package/dist/core/module.js
CHANGED
|
@@ -1,20 +1,39 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
1
2
|
import { isPrimitiveEffect, } from './effects.js';
|
|
3
|
+
import { validateInputEffect, } from './schema.js';
|
|
2
4
|
export { DEFAULT_DEFINITION_VERSION, definitionKey } from './definition-version.js';
|
|
3
5
|
/**
|
|
4
|
-
* Middleware that runs only for one effect definition. The handler receives the effect's
|
|
6
|
+
* Middleware that runs only for one **local** effect definition. The handler receives the effect's
|
|
5
7
|
* decoded input type and must call `next()` to continue (or `failEffect` to reject the attempt).
|
|
6
8
|
*
|
|
7
|
-
* Middleware wraps local (in-process) effect dispatch only.
|
|
8
|
-
*
|
|
9
|
+
* Middleware wraps local (in-process) effect dispatch only. Worker-placed effects never see it —
|
|
10
|
+
* pass a {@link LocalEffectDefinition} so that is a type error rather than a silent no-op.
|
|
11
|
+
* Prefer {@link EffectAdmission} / {@link onAdmit} for gates that must apply on both paths.
|
|
9
12
|
*/
|
|
10
13
|
export function onEffect(definition, handler) {
|
|
11
14
|
return (effect, ctx, next) => {
|
|
12
15
|
if (isPrimitiveEffect(effect) || effect.type !== definition.type) {
|
|
13
16
|
return next(effect, ctx);
|
|
14
17
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
return decodeEffectInput(definition, effect.input).pipe(Effect.flatMap((input) => handler(input, ctx, () => next(effect, ctx))));
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function decodeEffectInput(definition, raw) {
|
|
22
|
+
return validateInputEffect(definition.input, raw).pipe(
|
|
23
|
+
// SAFETY: decoded with the definition's own schema, whose output is the phantom TInput.
|
|
24
|
+
// oxlint-disable-next-line typescript/no-unsafe-type-assertion
|
|
25
|
+
Effect.map((input) => input));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Admission that runs only for one effect definition (local or worker). Prefer this over
|
|
29
|
+
* middleware when the gate must apply to worker-placed effects as well as local ones.
|
|
30
|
+
*/
|
|
31
|
+
export function onAdmit(definition, handler) {
|
|
32
|
+
return (effect, ctx) => {
|
|
33
|
+
if (isPrimitiveEffect(effect) || effect.type !== definition.type) {
|
|
34
|
+
return Effect.void;
|
|
35
|
+
}
|
|
36
|
+
return decodeEffectInput(definition, effect.input).pipe(Effect.flatMap((input) => handler(input, ctx)));
|
|
18
37
|
};
|
|
19
38
|
}
|
|
20
39
|
export function defineRuntimeModule(module) {
|
package/dist/core/protocol.d.ts
CHANGED
|
@@ -164,6 +164,17 @@ export declare const protocolCatalog: import("./catalog").EventCatalog<"runtime"
|
|
|
164
164
|
readonly attempt: Schema.Finite;
|
|
165
165
|
readonly error: Schema.String;
|
|
166
166
|
}>;
|
|
167
|
+
/**
|
|
168
|
+
* Unacknowledged worker.dispatch rejected. The attempt enters `dispatch_wait` (same attempt,
|
|
169
|
+
* outbox backoff) until the host relays again or parks as ambiguous.
|
|
170
|
+
*/
|
|
171
|
+
'effect.dispatch.deferred': Schema.Struct<{
|
|
172
|
+
readonly effectId: Schema.String;
|
|
173
|
+
readonly attempt: Schema.Finite;
|
|
174
|
+
readonly retryAt: Schema.Finite;
|
|
175
|
+
readonly error: Schema.String;
|
|
176
|
+
readonly try: Schema.Finite;
|
|
177
|
+
}>;
|
|
167
178
|
'effect.retry.scheduled': Schema.Struct<{
|
|
168
179
|
readonly effectId: Schema.String;
|
|
169
180
|
readonly attempt: Schema.Finite;
|
|
@@ -181,7 +192,7 @@ export declare const protocolCatalog: import("./catalog").EventCatalog<"runtime"
|
|
|
181
192
|
}>;
|
|
182
193
|
export type ProtocolEvent = EventsOfCatalog<typeof protocolCatalog>;
|
|
183
194
|
export type ProtocolEventInput = EventInputOf<typeof protocolCatalog>;
|
|
184
|
-
export declare const PROTOCOL_TYPES: readonly ['runtime.run.started', 'runtime.run.completed', 'runtime.run.cancelled', 'runtime.run.launched', 'runtime.child.settled', 'runtime.child.close.requested', 'runtime.run.forked', 'runtime.fork.elided', 'runtime.thread.started', 'runtime.thread.completed', 'runtime.thread.failed', 'runtime.thread.cancelled', 'runtime.thread.cancel.requested', 'runtime.wait.registered', 'runtime.wait.satisfied', 'runtime.timer.set', 'runtime.timer.fired', 'runtime.effect.failed', 'runtime.effect.attempt.started', 'runtime.effect.queued', 'runtime.effect.dispatched', 'runtime.effect.worker.started', 'runtime.effect.heartbeat', 'runtime.effect.cancel.requested', 'runtime.effect.cancelled', 'runtime.effect.completed', 'runtime.effect.timed_out', 'runtime.effect.ambiguous', 'runtime.effect.retry.scheduled', 'runtime.snapshot.taken', 'runtime.signal.received'];
|
|
195
|
+
export declare const PROTOCOL_TYPES: readonly ['runtime.run.started', 'runtime.run.completed', 'runtime.run.cancelled', 'runtime.run.launched', 'runtime.child.settled', 'runtime.child.close.requested', 'runtime.run.forked', 'runtime.fork.elided', 'runtime.thread.started', 'runtime.thread.completed', 'runtime.thread.failed', 'runtime.thread.cancelled', 'runtime.thread.cancel.requested', 'runtime.wait.registered', 'runtime.wait.satisfied', 'runtime.timer.set', 'runtime.timer.fired', 'runtime.effect.failed', 'runtime.effect.attempt.started', 'runtime.effect.queued', 'runtime.effect.dispatched', 'runtime.effect.worker.started', 'runtime.effect.heartbeat', 'runtime.effect.cancel.requested', 'runtime.effect.cancelled', 'runtime.effect.completed', 'runtime.effect.timed_out', 'runtime.effect.ambiguous', 'runtime.effect.dispatch.deferred', 'runtime.effect.retry.scheduled', 'runtime.snapshot.taken', 'runtime.signal.received'];
|
|
185
196
|
export type ProtocolEventType = (typeof PROTOCOL_TYPES)[number];
|
|
186
197
|
export declare function isProtocolType(type: string): type is ProtocolEventType;
|
|
187
198
|
export type RunStartedPayload = Schema.Schema.Type<(typeof protocolCatalog.entries)['run.started']>;
|
package/dist/core/protocol.js
CHANGED
|
@@ -160,6 +160,17 @@ export const protocolCatalog = defineEventCatalog('runtime', {
|
|
|
160
160
|
attempt: Schema.Finite,
|
|
161
161
|
error: Schema.String,
|
|
162
162
|
}),
|
|
163
|
+
/**
|
|
164
|
+
* Unacknowledged worker.dispatch rejected. The attempt enters `dispatch_wait` (same attempt,
|
|
165
|
+
* outbox backoff) until the host relays again or parks as ambiguous.
|
|
166
|
+
*/
|
|
167
|
+
'effect.dispatch.deferred': Schema.Struct({
|
|
168
|
+
effectId: Schema.String,
|
|
169
|
+
attempt: Schema.Finite,
|
|
170
|
+
retryAt: Schema.Finite,
|
|
171
|
+
error: Schema.String,
|
|
172
|
+
try: Schema.Finite,
|
|
173
|
+
}),
|
|
163
174
|
'effect.retry.scheduled': Schema.Struct({
|
|
164
175
|
effectId: Schema.String,
|
|
165
176
|
attempt: Schema.Finite,
|
|
@@ -204,6 +215,7 @@ export const PROTOCOL_TYPES = [
|
|
|
204
215
|
'runtime.effect.completed',
|
|
205
216
|
'runtime.effect.timed_out',
|
|
206
217
|
'runtime.effect.ambiguous',
|
|
218
|
+
'runtime.effect.dispatch.deferred',
|
|
207
219
|
'runtime.effect.retry.scheduled',
|
|
208
220
|
'runtime.snapshot.taken',
|
|
209
221
|
'runtime.signal.received',
|
package/dist/core/published.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Schema } from 'effect';
|
|
2
|
+
import type { EffectPlacement, RetryPolicy } from './effects';
|
|
2
3
|
import type { RegisteredDefinition } from './module';
|
|
4
|
+
import { type SchemaInput } from './schema';
|
|
3
5
|
import { type RunState } from './state';
|
|
4
6
|
/** A registered definition as `GET /definitions` publishes it. */
|
|
5
7
|
export declare const PublishedDefinitionSchema: Schema.Struct<{
|
|
@@ -24,6 +26,55 @@ export declare const DefinitionCatalogSchema: Schema.Struct<{
|
|
|
24
26
|
}>;
|
|
25
27
|
export type DefinitionCatalog = Schema.Schema.Type<typeof DefinitionCatalogSchema>;
|
|
26
28
|
export declare function publishDefinition(definition: RegisteredDefinition): PublishedDefinition;
|
|
29
|
+
/** A declared effect as `GET /definitions/effects` publishes it. */
|
|
30
|
+
export declare const PublishedEffectSchema: Schema.Struct<{
|
|
31
|
+
readonly type: Schema.String;
|
|
32
|
+
readonly placement: Schema.Literals<readonly ["local", "worker"]>;
|
|
33
|
+
readonly deterministic: Schema.optional<Schema.Boolean>;
|
|
34
|
+
readonly retry: Schema.optional<Schema.Struct<{
|
|
35
|
+
readonly maxAttempts: Schema.Finite;
|
|
36
|
+
readonly backoffMs: Schema.optional<Schema.Finite>;
|
|
37
|
+
readonly maxBackoffMs: Schema.optional<Schema.Finite>;
|
|
38
|
+
readonly backoffMultiplier: Schema.optional<Schema.Finite>;
|
|
39
|
+
readonly scheduleToStartTimeoutMs: Schema.optional<Schema.Finite>;
|
|
40
|
+
readonly startToCloseTimeoutMs: Schema.optional<Schema.Finite>;
|
|
41
|
+
readonly heartbeatTimeoutMs: Schema.optional<Schema.Finite>;
|
|
42
|
+
readonly cancellationTimeoutMs: Schema.optional<Schema.Finite>;
|
|
43
|
+
}>>;
|
|
44
|
+
/** JSON Schema derived from the effect's `input`. */
|
|
45
|
+
readonly inputSchema: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
46
|
+
}>;
|
|
47
|
+
export type PublishedEffect = Schema.Schema.Type<typeof PublishedEffectSchema>;
|
|
48
|
+
export declare const EffectCatalogSchema: Schema.Struct<{
|
|
49
|
+
readonly effects: Schema.$Array<Schema.Struct<{
|
|
50
|
+
readonly type: Schema.String;
|
|
51
|
+
readonly placement: Schema.Literals<readonly ["local", "worker"]>;
|
|
52
|
+
readonly deterministic: Schema.optional<Schema.Boolean>;
|
|
53
|
+
readonly retry: Schema.optional<Schema.Struct<{
|
|
54
|
+
readonly maxAttempts: Schema.Finite;
|
|
55
|
+
readonly backoffMs: Schema.optional<Schema.Finite>;
|
|
56
|
+
readonly maxBackoffMs: Schema.optional<Schema.Finite>;
|
|
57
|
+
readonly backoffMultiplier: Schema.optional<Schema.Finite>;
|
|
58
|
+
readonly scheduleToStartTimeoutMs: Schema.optional<Schema.Finite>;
|
|
59
|
+
readonly startToCloseTimeoutMs: Schema.optional<Schema.Finite>;
|
|
60
|
+
readonly heartbeatTimeoutMs: Schema.optional<Schema.Finite>;
|
|
61
|
+
readonly cancellationTimeoutMs: Schema.optional<Schema.Finite>;
|
|
62
|
+
}>>;
|
|
63
|
+
/** JSON Schema derived from the effect's `input`. */
|
|
64
|
+
readonly inputSchema: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
65
|
+
}>>;
|
|
66
|
+
}>;
|
|
67
|
+
export type EffectCatalog = Schema.Schema.Type<typeof EffectCatalogSchema>;
|
|
68
|
+
interface PublishableEffect {
|
|
69
|
+
readonly type: string;
|
|
70
|
+
readonly placement: EffectPlacement;
|
|
71
|
+
readonly deterministic?: boolean;
|
|
72
|
+
readonly retry?: RetryPolicy;
|
|
73
|
+
readonly input?: SchemaInput;
|
|
74
|
+
}
|
|
75
|
+
export declare function publishEffect(definition: PublishableEffect): PublishedEffect;
|
|
76
|
+
/** Declared effects, sorted by type so the catalog is stable. */
|
|
77
|
+
export declare function publishEffects(effects: Iterable<PublishableEffect>): readonly PublishedEffect[];
|
|
27
78
|
/** A run as `GET /runs/summaries` lists it. */
|
|
28
79
|
export declare const RunSummarySchema: Schema.Struct<{
|
|
29
80
|
readonly runId: Schema.String;
|
|
@@ -43,3 +94,4 @@ export declare const RunSummariesSchema: Schema.Struct<{
|
|
|
43
94
|
readonly attributes: Schema.withDecodingDefaultKey<Schema.$Record<Schema.String, Schema.String>, never>;
|
|
44
95
|
}>>;
|
|
45
96
|
}>;
|
|
97
|
+
export {};
|
package/dist/core/published.js
CHANGED
|
@@ -25,6 +25,51 @@ export function publishDefinition(definition) {
|
|
|
25
25
|
inputSchema: jsonSchemaOfInput(definition.input),
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
+
const PublishedRetryPolicySchema = Schema.Struct({
|
|
29
|
+
maxAttempts: Schema.Finite,
|
|
30
|
+
backoffMs: Schema.optional(Schema.Finite),
|
|
31
|
+
maxBackoffMs: Schema.optional(Schema.Finite),
|
|
32
|
+
backoffMultiplier: Schema.optional(Schema.Finite),
|
|
33
|
+
scheduleToStartTimeoutMs: Schema.optional(Schema.Finite),
|
|
34
|
+
startToCloseTimeoutMs: Schema.optional(Schema.Finite),
|
|
35
|
+
heartbeatTimeoutMs: Schema.optional(Schema.Finite),
|
|
36
|
+
cancellationTimeoutMs: Schema.optional(Schema.Finite),
|
|
37
|
+
});
|
|
38
|
+
/** A declared effect as `GET /definitions/effects` publishes it. */
|
|
39
|
+
export const PublishedEffectSchema = Schema.Struct({
|
|
40
|
+
type: Schema.String,
|
|
41
|
+
placement: Schema.Literals(['local', 'worker']),
|
|
42
|
+
deterministic: Schema.optional(Schema.Boolean),
|
|
43
|
+
retry: Schema.optional(PublishedRetryPolicySchema),
|
|
44
|
+
/** JSON Schema derived from the effect's `input`. */
|
|
45
|
+
inputSchema: Schema.optional(JsonValueSchema),
|
|
46
|
+
});
|
|
47
|
+
export const EffectCatalogSchema = Schema.Struct({
|
|
48
|
+
effects: Schema.Array(PublishedEffectSchema),
|
|
49
|
+
});
|
|
50
|
+
export function publishEffect(definition) {
|
|
51
|
+
const published = {
|
|
52
|
+
type: definition.type,
|
|
53
|
+
placement: definition.placement,
|
|
54
|
+
};
|
|
55
|
+
if (definition.deterministic !== undefined) {
|
|
56
|
+
published.deterministic = definition.deterministic;
|
|
57
|
+
}
|
|
58
|
+
if (definition.retry !== undefined) {
|
|
59
|
+
published.retry = definition.retry;
|
|
60
|
+
}
|
|
61
|
+
const inputSchema = jsonSchemaOfInput(definition.input);
|
|
62
|
+
if (inputSchema !== undefined) {
|
|
63
|
+
published.inputSchema = inputSchema;
|
|
64
|
+
}
|
|
65
|
+
return published;
|
|
66
|
+
}
|
|
67
|
+
/** Declared effects, sorted by type so the catalog is stable. */
|
|
68
|
+
export function publishEffects(effects) {
|
|
69
|
+
return [...effects]
|
|
70
|
+
.map(publishEffect)
|
|
71
|
+
.toSorted((left, right) => left.type.localeCompare(right.type));
|
|
72
|
+
}
|
|
28
73
|
/** A run as `GET /runs/summaries` lists it. */
|
|
29
74
|
export const RunSummarySchema = Schema.Struct({
|
|
30
75
|
runId: Schema.String,
|
package/dist/core/replay.d.ts
CHANGED
|
@@ -176,13 +176,14 @@ export declare const ReplayStepSchema: Schema.Struct<{
|
|
|
176
176
|
readonly effectExecutions: Schema.withDecodingDefaultKey<Schema.$Record<Schema.String, Schema.Struct<{
|
|
177
177
|
readonly effectId: Schema.String;
|
|
178
178
|
readonly attempt: Schema.Finite;
|
|
179
|
-
readonly status: Schema.Union<readonly [Schema.Literal<"queued">, Schema.Literal<"dispatched">, Schema.Literal<"started">, Schema.Literal<"heartbeat">, Schema.Literal<"retry_wait">, Schema.Literal<"cancel_requested">, Schema.Literal<"timed_out">, Schema.Literal<"ambiguous">, Schema.Literal<"running">]>;
|
|
179
|
+
readonly status: Schema.Union<readonly [Schema.Literal<"queued">, Schema.Literal<"dispatch_wait">, Schema.Literal<"dispatched">, Schema.Literal<"started">, Schema.Literal<"heartbeat">, Schema.Literal<"retry_wait">, Schema.Literal<"cancel_requested">, Schema.Literal<"timed_out">, Schema.Literal<"ambiguous">, Schema.Literal<"running">]>;
|
|
180
180
|
readonly nextAttemptAt: Schema.NullOr<Schema.Finite>;
|
|
181
181
|
readonly deadlineAt: Schema.withDecodingDefaultKey<Schema.NullOr<Schema.Finite>, never>;
|
|
182
182
|
readonly startedAt: Schema.withDecodingDefaultKey<Schema.NullOr<Schema.Finite>, never>;
|
|
183
183
|
readonly lastHeartbeatAt: Schema.withDecodingDefaultKey<Schema.NullOr<Schema.Finite>, never>;
|
|
184
184
|
readonly heartbeatDetails: Schema.withDecodingDefaultKey<Schema.NullOr<Schema.Codec<Schema.Json, Schema.Json, never, never>>, never>;
|
|
185
185
|
readonly lastError: Schema.NullOr<Schema.String>;
|
|
186
|
+
readonly dispatchTry: Schema.withDecodingDefaultKey<Schema.Finite, never>;
|
|
186
187
|
}>>, never>;
|
|
187
188
|
readonly completedEffectIds: Schema.withDecodingDefaultKey<Schema.$Array<Schema.String>, never>;
|
|
188
189
|
readonly processedIdempotencyKeys: Schema.withDecodingDefaultKey<Schema.$Array<Schema.String>, never>;
|
|
@@ -330,13 +331,14 @@ export declare const ReplayStepSchema: Schema.Struct<{
|
|
|
330
331
|
readonly effectExecutions: Schema.withDecodingDefaultKey<Schema.$Record<Schema.String, Schema.Struct<{
|
|
331
332
|
readonly effectId: Schema.String;
|
|
332
333
|
readonly attempt: Schema.Finite;
|
|
333
|
-
readonly status: Schema.Union<readonly [Schema.Literal<"queued">, Schema.Literal<"dispatched">, Schema.Literal<"started">, Schema.Literal<"heartbeat">, Schema.Literal<"retry_wait">, Schema.Literal<"cancel_requested">, Schema.Literal<"timed_out">, Schema.Literal<"ambiguous">, Schema.Literal<"running">]>;
|
|
334
|
+
readonly status: Schema.Union<readonly [Schema.Literal<"queued">, Schema.Literal<"dispatch_wait">, Schema.Literal<"dispatched">, Schema.Literal<"started">, Schema.Literal<"heartbeat">, Schema.Literal<"retry_wait">, Schema.Literal<"cancel_requested">, Schema.Literal<"timed_out">, Schema.Literal<"ambiguous">, Schema.Literal<"running">]>;
|
|
334
335
|
readonly nextAttemptAt: Schema.NullOr<Schema.Finite>;
|
|
335
336
|
readonly deadlineAt: Schema.withDecodingDefaultKey<Schema.NullOr<Schema.Finite>, never>;
|
|
336
337
|
readonly startedAt: Schema.withDecodingDefaultKey<Schema.NullOr<Schema.Finite>, never>;
|
|
337
338
|
readonly lastHeartbeatAt: Schema.withDecodingDefaultKey<Schema.NullOr<Schema.Finite>, never>;
|
|
338
339
|
readonly heartbeatDetails: Schema.withDecodingDefaultKey<Schema.NullOr<Schema.Codec<Schema.Json, Schema.Json, never, never>>, never>;
|
|
339
340
|
readonly lastError: Schema.NullOr<Schema.String>;
|
|
341
|
+
readonly dispatchTry: Schema.withDecodingDefaultKey<Schema.Finite, never>;
|
|
340
342
|
}>>, never>;
|
|
341
343
|
readonly completedEffectIds: Schema.withDecodingDefaultKey<Schema.$Array<Schema.String>, never>;
|
|
342
344
|
readonly processedIdempotencyKeys: Schema.withDecodingDefaultKey<Schema.$Array<Schema.String>, never>;
|
package/dist/core/state.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export interface OutstandingEffect {
|
|
|
32
32
|
export interface EffectExecutionRecord {
|
|
33
33
|
effectId: string;
|
|
34
34
|
attempt: number;
|
|
35
|
-
status: 'queued' | 'dispatched' | 'started' | 'heartbeat' | 'retry_wait' | 'cancel_requested' | 'timed_out' | 'ambiguous' | 'running';
|
|
35
|
+
status: 'queued' | 'dispatch_wait' | 'dispatched' | 'started' | 'heartbeat' | 'retry_wait' | 'cancel_requested' | 'timed_out' | 'ambiguous' | 'running';
|
|
36
36
|
nextAttemptAt: number | null;
|
|
37
37
|
deadlineAt: number | null;
|
|
38
38
|
/** When the current attempt started executing, locally or on a worker. */
|
|
@@ -41,6 +41,11 @@ export interface EffectExecutionRecord {
|
|
|
41
41
|
/** Progress reported by the latest heartbeat. Survives retries so the next attempt can resume. */
|
|
42
42
|
heartbeatDetails: JsonValue | null;
|
|
43
43
|
lastError: string | null;
|
|
44
|
+
/**
|
|
45
|
+
* How many times the host deferred an unacknowledged worker.dispatch for this attempt.
|
|
46
|
+
* Used for outbox backoff; ignored for local and acknowledged-worker paths.
|
|
47
|
+
*/
|
|
48
|
+
dispatchTry: number;
|
|
44
49
|
}
|
|
45
50
|
export interface RunStartIdentity {
|
|
46
51
|
kind: string;
|
|
@@ -229,13 +234,14 @@ export declare const RunStateSchema: Schema.Struct<{
|
|
|
229
234
|
readonly effectExecutions: Schema.withDecodingDefaultKey<Schema.$Record<Schema.String, Schema.Struct<{
|
|
230
235
|
readonly effectId: Schema.String;
|
|
231
236
|
readonly attempt: Schema.Finite;
|
|
232
|
-
readonly status: Schema.Union<readonly [Schema.Literal<"queued">, Schema.Literal<"dispatched">, Schema.Literal<"started">, Schema.Literal<"heartbeat">, Schema.Literal<"retry_wait">, Schema.Literal<"cancel_requested">, Schema.Literal<"timed_out">, Schema.Literal<"ambiguous">, Schema.Literal<"running">]>;
|
|
237
|
+
readonly status: Schema.Union<readonly [Schema.Literal<"queued">, Schema.Literal<"dispatch_wait">, Schema.Literal<"dispatched">, Schema.Literal<"started">, Schema.Literal<"heartbeat">, Schema.Literal<"retry_wait">, Schema.Literal<"cancel_requested">, Schema.Literal<"timed_out">, Schema.Literal<"ambiguous">, Schema.Literal<"running">]>;
|
|
233
238
|
readonly nextAttemptAt: Schema.NullOr<Schema.Finite>;
|
|
234
239
|
readonly deadlineAt: Schema.withDecodingDefaultKey<Schema.NullOr<Schema.Finite>, never>;
|
|
235
240
|
readonly startedAt: Schema.withDecodingDefaultKey<Schema.NullOr<Schema.Finite>, never>;
|
|
236
241
|
readonly lastHeartbeatAt: Schema.withDecodingDefaultKey<Schema.NullOr<Schema.Finite>, never>;
|
|
237
242
|
readonly heartbeatDetails: Schema.withDecodingDefaultKey<Schema.NullOr<Schema.Codec<Schema.Json, Schema.Json, never, never>>, never>;
|
|
238
243
|
readonly lastError: Schema.NullOr<Schema.String>;
|
|
244
|
+
readonly dispatchTry: Schema.withDecodingDefaultKey<Schema.Finite, never>;
|
|
239
245
|
}>>, never>;
|
|
240
246
|
readonly completedEffectIds: Schema.withDecodingDefaultKey<Schema.$Array<Schema.String>, never>;
|
|
241
247
|
readonly processedIdempotencyKeys: Schema.withDecodingDefaultKey<Schema.$Array<Schema.String>, never>;
|
package/dist/core/state.js
CHANGED
|
@@ -66,6 +66,7 @@ export const RunStateSchema = Schema.Struct({
|
|
|
66
66
|
attempt: Schema.Finite,
|
|
67
67
|
status: Schema.Union([
|
|
68
68
|
Schema.Literal('queued'),
|
|
69
|
+
Schema.Literal('dispatch_wait'),
|
|
69
70
|
Schema.Literal('dispatched'),
|
|
70
71
|
Schema.Literal('started'),
|
|
71
72
|
Schema.Literal('heartbeat'),
|
|
@@ -81,6 +82,7 @@ export const RunStateSchema = Schema.Struct({
|
|
|
81
82
|
lastHeartbeatAt: Schema.NullOr(Schema.Finite).pipe(Schema.withDecodingDefaultKey(Effect.succeed(null))),
|
|
82
83
|
heartbeatDetails: Schema.NullOr(JsonValueSchema).pipe(Schema.withDecodingDefaultKey(Effect.succeed(null))),
|
|
83
84
|
lastError: Schema.NullOr(Schema.String),
|
|
85
|
+
dispatchTry: Schema.Finite.pipe(Schema.withDecodingDefaultKey(Effect.succeed(0))),
|
|
84
86
|
})).pipe(Schema.withDecodingDefaultKey(Effect.succeed({}))),
|
|
85
87
|
completedEffectIds: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
|
|
86
88
|
processedIdempotencyKeys: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
|