@swirls/looms 0.0.2 → 0.2.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 +24 -2
- package/dist/actor/cell.d.ts +9 -4
- package/dist/actor/cell.js +7 -11
- package/dist/actor/host.d.ts +7 -3
- package/dist/actor/host.js +57 -33
- package/dist/actor/index.d.ts +1 -1
- package/dist/actor/index.js +1 -1
- package/dist/actor/routing.d.ts +12 -1
- package/dist/actor/routing.js +57 -51
- package/dist/agent/agent-session.d.ts +5 -0
- package/dist/agent/agent-session.js +270 -0
- package/dist/agent/debugger/agent-chat.d.ts +2 -0
- package/dist/agent/debugger/agent-chat.js +176 -0
- package/dist/agent/debugger/index.d.ts +5 -0
- package/dist/agent/debugger/index.js +19 -0
- package/dist/agent/debugger/summarize.d.ts +2 -0
- package/dist/agent/debugger/summarize.js +51 -0
- package/dist/agent/debugger/token-usage.d.ts +3 -0
- package/dist/agent/debugger/token-usage.js +11 -0
- package/dist/agent/definitions-store.d.ts +2 -3
- package/dist/agent/definitions-store.js +2 -4
- package/dist/agent/definitions.d.ts +47 -29
- package/dist/agent/definitions.js +39 -12
- package/dist/agent/effects.d.ts +359 -2
- package/dist/agent/effects.js +60 -34
- package/dist/agent/events.d.ts +175 -19
- package/dist/agent/events.js +45 -10
- package/dist/agent/index.d.ts +1 -0
- package/dist/agent/index.js +1 -0
- package/dist/agent/llm.d.ts +11 -2
- package/dist/agent/llm.js +13 -3
- package/dist/agent/module.d.ts +812 -78
- package/dist/agent/module.js +16 -4
- package/dist/agent/scope.d.ts +174 -18
- package/dist/agent/signals.d.ts +26 -1
- package/dist/agent/signals.js +79 -0
- package/dist/agent/threads.d.ts +3 -33
- package/dist/agent/threads.js +20 -25
- package/dist/agent/tool-schema.d.ts +1 -17
- package/dist/agent/tool-schema.js +3 -43
- package/dist/agent/types.d.ts +49 -4
- package/dist/agent/types.js +5 -5
- package/dist/ai-vercel/index.d.ts +1 -0
- package/dist/ai-vercel/index.js +1 -0
- package/dist/ai-vercel/messages.js +22 -7
- package/dist/ai-vercel/vercel-evaluator.d.ts +36 -0
- package/dist/ai-vercel/vercel-evaluator.js +73 -0
- package/dist/ai-vercel/vercel-llm.js +64 -44
- package/dist/approval/debugger/approvals-view.d.ts +3 -0
- package/dist/approval/debugger/approvals-view.js +16 -0
- package/dist/approval/debugger/index.d.ts +4 -0
- package/dist/approval/debugger/index.js +11 -0
- package/dist/approval/debugger/summarize.d.ts +2 -0
- package/dist/approval/debugger/summarize.js +17 -0
- package/dist/approval/effects.d.ts +89 -0
- package/dist/approval/module.d.ts +179 -29
- package/dist/approval/projections.d.ts +0 -14
- package/dist/approval/projections.js +20 -3
- package/dist/approval/signals.d.ts +2 -0
- package/dist/approval/signals.js +18 -2
- package/dist/cli/cli.js +2 -0
- package/dist/cli/commands.js +12 -16
- package/dist/client/client.d.ts +1213 -18
- package/dist/client/client.js +120 -120
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/sse.d.ts +13 -0
- package/dist/client/sse.js +38 -44
- package/dist/cloudflare/alarm-scheduler.d.ts +12 -2
- package/dist/cloudflare/alarm-scheduler.js +34 -7
- package/dist/cloudflare/durable-object.d.ts +10 -2
- package/dist/cloudflare/durable-object.js +59 -28
- package/dist/cloudflare/event-store.d.ts +7 -2
- package/dist/cloudflare/event-store.js +8 -7
- package/dist/cloudflare/index.d.ts +2 -2
- package/dist/cloudflare/index.js +2 -2
- package/dist/cloudflare/router.d.ts +1 -1
- package/dist/cloudflare/router.js +15 -16
- package/dist/core/catalog.d.ts +3 -3
- package/dist/core/catalog.js +2 -5
- package/dist/core/coalesce.js +5 -3
- package/dist/core/compose.d.ts +2 -1
- package/dist/core/compose.js +19 -2
- package/dist/core/debugger-host.d.ts +16 -0
- package/dist/core/debugger-host.js +1 -0
- package/dist/core/definition-store.d.ts +11 -0
- package/dist/core/definition-store.js +6 -0
- package/dist/core/effects.d.ts +127 -15
- package/dist/core/effects.js +89 -17
- package/dist/core/envelope.d.ts +27 -7
- package/dist/core/envelope.js +20 -6
- package/dist/core/event-codec.d.ts +4 -2
- package/dist/core/event-codec.js +10 -5
- package/dist/core/event-index.js +1 -3
- package/dist/core/fold.d.ts +3 -0
- package/dist/core/fold.js +171 -24
- package/dist/core/ids.d.ts +5 -0
- package/dist/core/ids.js +35 -2
- package/dist/core/index.d.ts +7 -1
- package/dist/core/index.js +6 -1
- package/dist/core/kind.d.ts +22 -0
- package/dist/core/kind.js +17 -0
- package/dist/core/limits.d.ts +34 -0
- package/dist/core/limits.js +46 -0
- package/dist/core/match.d.ts +1 -0
- package/dist/core/match.js +10 -1
- package/dist/core/module-scope.d.ts +22 -20
- package/dist/core/module-scope.js +38 -28
- package/dist/core/module.d.ts +18 -5
- package/dist/core/module.js +4 -0
- package/dist/core/projection.d.ts +13 -13
- package/dist/core/projection.js +9 -5
- package/dist/core/protocol.d.ts +68 -11
- package/dist/core/protocol.js +82 -11
- package/dist/core/published.d.ts +43 -0
- package/dist/core/published.js +44 -0
- package/dist/core/replay.d.ts +312 -3
- package/dist/core/replay.js +11 -1
- package/dist/core/schema.d.ts +11 -20
- package/dist/core/schema.js +63 -80
- package/dist/core/serialize.js +2 -4
- package/dist/core/snapshot-store.d.ts +6 -1
- package/dist/core/snapshot-store.js +15 -2
- package/dist/core/snapshots.d.ts +5 -1
- package/dist/core/snapshots.js +10 -15
- package/dist/core/sqlite-store.js +95 -11
- package/dist/core/state.d.ts +142 -4
- package/dist/core/state.js +78 -0
- package/dist/core/store.d.ts +38 -3
- package/dist/core/store.js +77 -22
- package/dist/core/thread.d.ts +10 -9
- package/dist/core/types.d.ts +5 -8
- package/dist/core/types.js +28 -24
- package/dist/core/validate-event.js +14 -4
- package/dist/core/worker-callback.d.ts +17 -0
- package/dist/core/worker-callback.js +1 -0
- package/dist/debugger/app/assets/index-B3Ah8WAE.css +2 -0
- package/dist/debugger/app/assets/index-Qb371t_O.js +22 -0
- package/dist/debugger/app/assets/rolldown-runtime-CbXtAM7H.js +1 -0
- package/dist/debugger/app/assets/routes-CjtEHgPQ.js +47 -0
- package/dist/debugger/app/index.html +14 -0
- package/dist/debugger/components/composer.d.ts +17 -0
- package/dist/debugger/components/composer.js +25 -0
- package/dist/debugger/components/debugger-split.d.ts +2 -1
- package/dist/debugger/components/debugger-split.js +2 -2
- package/dist/debugger/components/event-inspector.d.ts +2 -1
- package/dist/debugger/components/event-inspector.js +25 -16
- package/dist/debugger/components/event-stream.d.ts +2 -1
- package/dist/debugger/components/event-stream.js +14 -74
- package/dist/debugger/components/follow-list.d.ts +19 -0
- package/dist/debugger/components/follow-list.js +96 -0
- package/dist/debugger/components/json-tree.d.ts +11 -0
- package/dist/debugger/components/json-tree.js +120 -0
- package/dist/debugger/components/json-view.js +2 -2
- package/dist/debugger/components/run-tree.js +53 -20
- package/dist/debugger/components/status-dot.d.ts +4 -0
- package/dist/debugger/components/status-dot.js +6 -2
- package/dist/debugger/context.d.ts +14 -0
- package/dist/debugger/context.js +17 -0
- package/dist/debugger/contracts.d.ts +7 -4
- package/dist/debugger/events/builtin-families.d.ts +3 -0
- package/dist/debugger/events/builtin-families.js +9 -0
- package/dist/debugger/events/catalog.d.ts +3 -4
- package/dist/debugger/events/catalog.js +27 -17
- package/dist/debugger/events/protocol-summarize.d.ts +1 -2
- package/dist/debugger/events/protocol-summarize.js +42 -24
- package/dist/debugger/index.d.ts +20 -6
- package/dist/debugger/index.js +19 -5
- package/dist/debugger/lib/cn.d.ts +1 -0
- package/dist/debugger/lib/cn.js +3 -0
- package/dist/debugger/lib/event-meta.d.ts +2 -3
- package/dist/debugger/lib/event-meta.js +6 -12
- package/dist/debugger/lib/json.d.ts +25 -0
- package/dist/debugger/lib/json.js +87 -0
- package/dist/debugger/lib/payload.d.ts +7 -0
- package/dist/debugger/lib/payload.js +11 -0
- package/dist/debugger/lib/time.d.ts +3 -0
- package/dist/debugger/lib/time.js +24 -0
- package/dist/debugger/plugin.d.ts +36 -0
- package/dist/debugger/plugin.js +14 -0
- package/dist/debugger/server/index.d.ts +14 -0
- package/dist/debugger/server/index.js +114 -0
- package/dist/debugger/shell/debugger-shell.d.ts +15 -0
- package/dist/debugger/shell/debugger-shell.js +43 -0
- package/dist/debugger/shell/definition-key.d.ts +3 -0
- package/dist/debugger/shell/definition-key.js +4 -0
- package/dist/debugger/shell/events-pane.d.ts +12 -0
- package/dist/debugger/shell/events-pane.js +25 -0
- package/dist/debugger/shell/projections-panel.d.ts +4 -0
- package/dist/debugger/shell/projections-panel.js +59 -0
- package/dist/debugger/shell/run-controls.d.ts +4 -0
- package/dist/debugger/shell/run-controls.js +72 -0
- package/dist/debugger/shell/run-search.d.ts +6 -0
- package/dist/debugger/shell/run-search.js +102 -0
- package/dist/debugger/shell/run-type-menu.d.ts +6 -0
- package/dist/debugger/shell/run-type-menu.js +11 -0
- package/dist/debugger/shell/schema-form.d.ts +31 -0
- package/dist/debugger/shell/schema-form.js +117 -0
- package/dist/debugger/shell/start-form.d.ts +3 -0
- package/dist/debugger/shell/start-form.js +75 -0
- package/dist/debugger/shell/use-start-run.d.ts +14 -0
- package/dist/debugger/shell/use-start-run.js +32 -0
- package/dist/debugger/shell/workspace.d.ts +6 -0
- package/dist/debugger/shell/workspace.js +15 -0
- package/dist/debugger/styles.css +111 -27
- package/dist/debugger/ui/button.d.ts +24 -0
- package/dist/debugger/ui/button.js +24 -0
- package/dist/debugger/ui/command.d.ts +9 -0
- package/dist/debugger/ui/command.js +24 -0
- package/dist/debugger/ui/dropdown-menu.d.ts +13 -0
- package/dist/debugger/ui/dropdown-menu.js +37 -0
- package/dist/debugger/ui/panel.d.ts +14 -0
- package/dist/debugger/ui/panel.js +16 -0
- package/dist/debugger/ui/popover.d.ts +7 -0
- package/dist/debugger/ui/popover.js +17 -0
- package/dist/debugger/ui/resizable.d.ts +7 -0
- package/dist/debugger/ui/resizable.js +14 -0
- package/dist/debugger/ui/scroll-area.d.ts +2 -1
- package/dist/debugger/ui/scroll-area.js +5 -3
- package/dist/debugger/ui/select.d.ts +10 -0
- package/dist/debugger/ui/select.js +21 -0
- package/dist/debugger/ui/tabs.js +2 -2
- package/dist/debugger/ui/textarea.d.ts +3 -0
- package/dist/debugger/ui/textarea.js +7 -0
- package/dist/evaluator/definitions-store.d.ts +11 -0
- package/dist/evaluator/definitions-store.js +8 -0
- package/dist/evaluator/definitions.d.ts +18 -0
- package/dist/evaluator/definitions.js +4 -0
- package/dist/evaluator/effects.d.ts +226 -0
- package/dist/evaluator/effects.js +132 -0
- package/dist/evaluator/evaluator.d.ts +24 -0
- package/dist/evaluator/evaluator.js +67 -0
- package/dist/evaluator/events.d.ts +59 -0
- package/dist/evaluator/events.js +21 -0
- package/dist/evaluator/index.d.ts +11 -0
- package/dist/evaluator/index.js +11 -0
- package/dist/evaluator/module.d.ts +606 -0
- package/dist/evaluator/module.js +25 -0
- package/dist/evaluator/projections.d.ts +50 -0
- package/dist/evaluator/projections.js +20 -0
- package/dist/evaluator/scope.d.ts +59 -0
- package/dist/evaluator/scope.js +7 -0
- package/dist/evaluator/signals.d.ts +3 -0
- package/dist/evaluator/signals.js +17 -0
- package/dist/evaluator/threads.d.ts +62 -0
- package/dist/evaluator/threads.js +117 -0
- package/dist/evaluator/types.d.ts +125 -0
- package/dist/evaluator/types.js +51 -0
- package/dist/projectors/delivery.d.ts +83 -0
- package/dist/projectors/delivery.js +182 -0
- package/dist/projectors/index-model.d.ts +1 -1
- package/dist/projectors/index-model.js +4 -6
- package/dist/projectors/index.d.ts +2 -0
- package/dist/projectors/index.js +2 -0
- package/dist/projectors/memory.d.ts +1 -1
- package/dist/projectors/memory.js +10 -8
- package/dist/projectors/postgres.js +44 -58
- package/dist/projectors/projector.d.ts +17 -0
- package/dist/projectors/projector.js +26 -1
- package/dist/projectors/sqlite-delivery.d.ts +4 -0
- package/dist/projectors/sqlite-delivery.js +147 -0
- package/dist/projectors/sqlite.js +23 -23
- package/dist/projectors/with-projectors.d.ts +7 -2
- package/dist/projectors/with-projectors.js +27 -28
- package/dist/react/notify.js +11 -8
- package/dist/react/react.d.ts +2 -3
- package/dist/react/react.js +14 -30
- package/dist/react/sse.d.ts +1 -1
- package/dist/react/sse.js +1 -1
- package/dist/react/store.d.ts +3 -3
- package/dist/react/store.js +109 -119
- package/dist/runtime/cancellation.d.ts +16 -0
- package/dist/runtime/cancellation.js +129 -0
- package/dist/runtime/deadline-transition-planner.d.ts +31 -0
- package/dist/runtime/deadline-transition-planner.js +139 -0
- package/dist/runtime/dispatch-effect.d.ts +3 -2
- package/dist/runtime/dispatch-effect.js +7 -13
- package/dist/runtime/errors.d.ts +51 -0
- package/dist/runtime/errors.js +39 -0
- package/dist/runtime/{runtime-helpers.d.ts → helpers.d.ts} +24 -4
- package/dist/runtime/{runtime-helpers.js → helpers.js} +56 -19
- package/dist/runtime/index.d.ts +3 -3
- package/dist/runtime/index.js +3 -3
- package/dist/runtime/ingress.d.ts +15 -0
- package/dist/runtime/ingress.js +42 -0
- package/dist/runtime/local-effect-executor.d.ts +21 -0
- package/dist/runtime/local-effect-executor.js +137 -0
- package/dist/runtime/looms.d.ts +30 -4
- package/dist/runtime/looms.js +57 -37
- package/dist/runtime/observer.d.ts +45 -0
- package/dist/runtime/observer.js +11 -0
- package/dist/runtime/repository.d.ts +55 -0
- package/dist/runtime/repository.js +293 -0
- package/dist/runtime/retry-policy.d.ts +16 -0
- package/dist/runtime/retry-policy.js +29 -0
- package/dist/runtime/run-execution-context.d.ts +30 -0
- package/dist/runtime/run-execution-context.js +56 -0
- package/dist/runtime/run-start.d.ts +4 -0
- package/dist/runtime/run-start.js +44 -0
- package/dist/runtime/runtime.d.ts +6 -87
- package/dist/runtime/runtime.js +248 -470
- package/dist/runtime/server/auth.d.ts +41 -0
- package/dist/runtime/server/auth.js +45 -0
- package/dist/runtime/server/debugger-host.d.ts +11 -0
- package/dist/runtime/server/debugger-host.js +32 -0
- package/dist/runtime/server/fetch-handler.d.ts +18 -0
- package/dist/runtime/server/fetch-handler.js +62 -0
- package/dist/runtime/server/http.d.ts +38 -0
- package/dist/runtime/server/http.js +66 -0
- package/dist/runtime/server/route-table.d.ts +55 -0
- package/dist/runtime/server/route-table.js +74 -0
- package/dist/runtime/server/routes/definitions.d.ts +3 -0
- package/dist/runtime/server/routes/definitions.js +20 -0
- package/dist/runtime/server/routes/effects.d.ts +3 -0
- package/dist/runtime/server/routes/effects.js +59 -0
- package/dist/runtime/server/routes/operations.d.ts +3 -0
- package/dist/runtime/server/routes/operations.js +14 -0
- package/dist/runtime/server/routes/runs.d.ts +3 -0
- package/dist/runtime/server/routes/runs.js +199 -0
- package/dist/runtime/server.d.ts +4 -8
- package/dist/runtime/server.js +6 -211
- package/dist/runtime/sse.d.ts +2 -1
- package/dist/runtime/sse.js +24 -17
- package/dist/runtime/types.d.ts +117 -0
- package/dist/runtime/types.js +1 -0
- package/dist/runtime/wake-engine.d.ts +20 -0
- package/dist/runtime/wake-engine.js +311 -0
- package/dist/runtime/wake-scheduler.d.ts +3 -4
- package/dist/runtime/wake-scheduler.js +25 -31
- package/dist/runtime/worker-callbacks.d.ts +16 -0
- package/dist/runtime/worker-callbacks.js +167 -0
- package/dist/runtime/worker-effect-dispatch.d.ts +36 -0
- package/dist/runtime/worker-effect-dispatch.js +126 -0
- package/dist/s2/config.d.ts +1 -1
- package/dist/s2/config.js +1 -1
- package/dist/s2/lite.js +70 -82
- package/dist/s2/pagination.d.ts +15 -0
- package/dist/s2/pagination.js +36 -0
- package/dist/s2/projector.js +6 -5
- package/dist/s2/snapshot-store.js +188 -161
- package/dist/s2/store.d.ts +3 -21
- package/dist/s2/store.js +71 -165
- package/dist/testing/index.d.ts +15 -0
- package/dist/testing/index.js +53 -16
- package/dist/workflow/debugger/index.d.ts +4 -0
- package/dist/workflow/debugger/index.js +11 -0
- package/dist/workflow/debugger/nodes-view.d.ts +3 -0
- package/dist/workflow/debugger/nodes-view.js +13 -0
- package/dist/workflow/debugger/summarize.d.ts +2 -0
- package/dist/workflow/debugger/summarize.js +30 -0
- package/dist/workflow/definitions-store.d.ts +2 -3
- package/dist/workflow/definitions-store.js +2 -2
- package/dist/workflow/definitions.d.ts +78 -22
- package/dist/workflow/definitions.js +80 -14
- package/dist/workflow/effects.d.ts +453 -107
- package/dist/workflow/effects.js +214 -115
- package/dist/workflow/events.d.ts +149 -5
- package/dist/workflow/events.js +27 -5
- package/dist/workflow/graph.d.ts +56 -0
- package/dist/workflow/graph.js +207 -0
- package/dist/workflow/index.d.ts +1 -0
- package/dist/workflow/index.js +1 -0
- package/dist/workflow/module.d.ts +1047 -266
- package/dist/workflow/projections.d.ts +14 -12
- package/dist/workflow/projections.js +30 -8
- package/dist/workflow/scope.d.ts +146 -4
- package/dist/workflow/threads.d.ts +383 -155
- package/dist/workflow/threads.js +308 -110
- package/package.json +26 -2
- package/dist/debugger/events/domain-summarize.d.ts +0 -3
- package/dist/debugger/events/domain-summarize.js +0 -107
- package/dist/debugger/events/family.d.ts +0 -8
- package/dist/debugger/events/family.js +0 -44
- package/dist/runtime/events-api.d.ts +0 -4
- package/dist/runtime/events-api.js +0 -84
|
@@ -1,14 +1,34 @@
|
|
|
1
1
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
2
|
import { Schema } from 'effect';
|
|
3
|
-
import
|
|
3
|
+
import { type JsonValue, type RuntimeEffect } from '@swirls/looms/core';
|
|
4
|
+
import { type WorkflowEdge } from './graph';
|
|
4
5
|
export declare const NodeStatusSchema: Schema.Union<readonly [Schema.Literal<"pending">, Schema.Literal<"running">, Schema.Literal<"completed">, Schema.Literal<"failed">, Schema.Literal<"skipped">]>;
|
|
5
6
|
export type NodeStatus = Schema.Schema.Type<typeof NodeStatusSchema>;
|
|
6
7
|
export declare const NodeStateSchema: Schema.Struct<{
|
|
7
8
|
readonly status: Schema.Union<readonly [Schema.Literal<"pending">, Schema.Literal<"running">, Schema.Literal<"completed">, Schema.Literal<"failed">, Schema.Literal<"skipped">]>;
|
|
8
9
|
readonly result: Schema.NullOr<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
9
10
|
readonly error: Schema.NullOr<Schema.String>;
|
|
11
|
+
readonly attempts: Schema.optional<Schema.Finite>;
|
|
12
|
+
readonly branch: Schema.optional<Schema.String>;
|
|
13
|
+
/** Policy skips (skip/fallback) still satisfy dependents; inactive skips propagate. */
|
|
14
|
+
readonly skipCause: Schema.optional<Schema.Union<readonly [Schema.Literal<"inactive">, Schema.Literal<"policy">]>>;
|
|
15
|
+
readonly iteration: Schema.optional<Schema.Struct<{
|
|
16
|
+
readonly index: Schema.Finite;
|
|
17
|
+
readonly previous: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
18
|
+
}>>;
|
|
10
19
|
}>;
|
|
11
20
|
export type NodeState = Schema.Schema.Type<typeof NodeStateSchema>;
|
|
21
|
+
export interface WorkflowChild {
|
|
22
|
+
readonly kind: string;
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly version?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface WorkflowIteration {
|
|
27
|
+
/** Zero-based index of the loop iteration about to run. */
|
|
28
|
+
readonly index: number;
|
|
29
|
+
/** Output of the previous iteration's child. */
|
|
30
|
+
readonly previous: JsonValue;
|
|
31
|
+
}
|
|
12
32
|
export interface WorkflowNodeContext<TInput = JsonValue> {
|
|
13
33
|
readonly threadId: string;
|
|
14
34
|
readonly nodeId: string;
|
|
@@ -16,12 +36,22 @@ export interface WorkflowNodeContext<TInput = JsonValue> {
|
|
|
16
36
|
readonly results: {
|
|
17
37
|
[nodeId: string]: JsonValue | null;
|
|
18
38
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}, input: JsonValue): NodeResult;
|
|
39
|
+
/** Set when a `loop` node is re-run after one of its iterations completed. */
|
|
40
|
+
readonly iteration: WorkflowIteration | undefined;
|
|
41
|
+
spawn(child: WorkflowChild, input: JsonValue): NodeResult;
|
|
23
42
|
sleep(ms: number): NodeResult;
|
|
24
43
|
effects(effects: RuntimeEffect[]): NodeResult;
|
|
44
|
+
/** Run one child per item, one at a time, and finish with the ordered outputs. */
|
|
45
|
+
map(child: WorkflowChild, items: readonly JsonValue[]): NodeResult;
|
|
46
|
+
/** Run one child per item with bounded concurrency and finish with the ordered outputs. */
|
|
47
|
+
fanout(child: WorkflowChild, items: readonly JsonValue[], concurrency?: number): NodeResult;
|
|
48
|
+
/**
|
|
49
|
+
* Run one child iteration, then re-run this node with `ctx.iteration`. Returning a value
|
|
50
|
+
* instead ends the loop; reaching `maxIterations` ends it with the last iteration's output.
|
|
51
|
+
*/
|
|
52
|
+
loop(child: WorkflowChild, input: JsonValue, options: {
|
|
53
|
+
maxIterations: number;
|
|
54
|
+
}): NodeResult;
|
|
25
55
|
}
|
|
26
56
|
export type NodeResult = {
|
|
27
57
|
type: 'value';
|
|
@@ -30,26 +60,64 @@ export type NodeResult = {
|
|
|
30
60
|
type: 'spawn';
|
|
31
61
|
kind: string;
|
|
32
62
|
name: string;
|
|
63
|
+
version: string;
|
|
33
64
|
input: JsonValue;
|
|
65
|
+
childThreadId?: string;
|
|
34
66
|
} | {
|
|
35
67
|
type: 'sleep';
|
|
36
68
|
ms: number;
|
|
37
69
|
} | {
|
|
38
70
|
type: 'effects';
|
|
39
71
|
effects: RuntimeEffect[];
|
|
72
|
+
} | {
|
|
73
|
+
type: 'switch';
|
|
74
|
+
branch: string;
|
|
75
|
+
value?: JsonValue;
|
|
76
|
+
} | {
|
|
77
|
+
type: 'map';
|
|
78
|
+
kind: string;
|
|
79
|
+
name: string;
|
|
80
|
+
version: string;
|
|
81
|
+
items: readonly JsonValue[];
|
|
82
|
+
concurrency: number;
|
|
83
|
+
} | {
|
|
84
|
+
type: 'loop';
|
|
85
|
+
kind: string;
|
|
86
|
+
name: string;
|
|
87
|
+
version: string;
|
|
88
|
+
input: JsonValue;
|
|
89
|
+
maxIterations: number;
|
|
90
|
+
};
|
|
91
|
+
export type WorkflowFailurePolicy = {
|
|
92
|
+
readonly type: 'fail';
|
|
93
|
+
} | {
|
|
94
|
+
readonly type: 'skip';
|
|
95
|
+
} | {
|
|
96
|
+
readonly type: 'retry';
|
|
97
|
+
readonly maxAttempts: number;
|
|
98
|
+
} | {
|
|
99
|
+
readonly type: 'fallback';
|
|
100
|
+
readonly nodeId: string;
|
|
40
101
|
};
|
|
41
102
|
export interface WorkflowNodeDefinition<TInput = JsonValue> {
|
|
42
103
|
id: string;
|
|
43
104
|
deps?: string[];
|
|
105
|
+
type?: 'task' | 'switch' | 'workflow';
|
|
106
|
+
failure?: WorkflowFailurePolicy;
|
|
44
107
|
run(ctx: WorkflowNodeContext<TInput>): Promise<JsonValue | NodeResult> | JsonValue | NodeResult;
|
|
45
108
|
}
|
|
46
109
|
export interface WorkflowDefinition<TName extends string = string, TInput = JsonValue, TOutput extends JsonValue = JsonValue> {
|
|
47
110
|
readonly kind: 'workflow';
|
|
48
111
|
readonly name: TName;
|
|
112
|
+
readonly version: string;
|
|
49
113
|
readonly description?: string;
|
|
50
|
-
readonly input?: StandardSchemaV1<any, TInput> | Schema.
|
|
114
|
+
readonly input?: StandardSchemaV1<any, TInput> | Schema.ConstraintDecoder<TInput>;
|
|
51
115
|
readonly nodes: WorkflowNodeDefinition<TInput>[];
|
|
116
|
+
readonly edges?: readonly WorkflowEdge[];
|
|
52
117
|
readonly concurrency?: number;
|
|
118
|
+
readonly inputLimitBytes?: number;
|
|
119
|
+
readonly outputLimitBytes?: number;
|
|
120
|
+
readonly checkpointLimitBytes?: number;
|
|
53
121
|
output?(ctx: {
|
|
54
122
|
input: TInput;
|
|
55
123
|
results: {
|
|
@@ -58,25 +126,13 @@ export interface WorkflowDefinition<TName extends string = string, TInput = Json
|
|
|
58
126
|
}): TOutput;
|
|
59
127
|
}
|
|
60
128
|
export type AnyWorkflowDefinition = WorkflowDefinition;
|
|
61
|
-
export declare function defineWorkflow<TName extends string,
|
|
62
|
-
|
|
63
|
-
description?: string;
|
|
64
|
-
input?: TSchema;
|
|
65
|
-
nodes: Array<{
|
|
66
|
-
id: string;
|
|
67
|
-
deps?: string[];
|
|
68
|
-
run: (ctx: WorkflowNodeContext<TInput>) => Promise<JsonValue | NodeResult> | JsonValue | NodeResult;
|
|
69
|
-
}>;
|
|
70
|
-
concurrency?: number;
|
|
71
|
-
output?: (ctx: {
|
|
72
|
-
input: TInput;
|
|
73
|
-
results: {
|
|
74
|
-
[nodeId: string]: JsonValue | null;
|
|
75
|
-
};
|
|
76
|
-
}) => TOutput;
|
|
129
|
+
export declare function defineWorkflow<TName extends string, TInput = JsonValue, TOutput extends JsonValue = JsonValue>(def: Omit<WorkflowDefinition<TName, TInput, TOutput>, 'kind' | 'version'> & {
|
|
130
|
+
readonly version?: string;
|
|
77
131
|
}): WorkflowDefinition<TName, TInput, TOutput>;
|
|
78
132
|
export declare function readyNodes(workflow: WorkflowDefinition, nodeStates: {
|
|
79
133
|
[nodeId: string]: {
|
|
80
134
|
status: string;
|
|
81
135
|
};
|
|
82
136
|
}): string[];
|
|
137
|
+
/** Builds the helpers a node's `run` uses to describe durable work. */
|
|
138
|
+
export declare function nodeResultBuilders(): Pick<WorkflowNodeContext, 'spawn' | 'sleep' | 'effects' | 'map' | 'fanout' | 'loop'>;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Schema } from 'effect';
|
|
2
|
+
import { DEFAULT_DEFINITION_VERSION } from '@swirls/looms/core';
|
|
3
|
+
import { DEFAULT_GRAPH_CONCURRENCY, getReadyNodeIds, resolveGraphConcurrency, topologicalSort, workflowEdges, } from './graph.js';
|
|
2
4
|
export const NodeStatusSchema = Schema.Union([
|
|
3
5
|
Schema.Literal('pending'),
|
|
4
6
|
Schema.Literal('running'),
|
|
@@ -10,23 +12,87 @@ export const NodeStateSchema = Schema.Struct({
|
|
|
10
12
|
status: NodeStatusSchema,
|
|
11
13
|
result: Schema.NullOr(Schema.Json),
|
|
12
14
|
error: Schema.NullOr(Schema.String),
|
|
15
|
+
attempts: Schema.optional(Schema.Finite),
|
|
16
|
+
branch: Schema.optional(Schema.String),
|
|
17
|
+
/** Policy skips (skip/fallback) still satisfy dependents; inactive skips propagate. */
|
|
18
|
+
skipCause: Schema.optional(Schema.Union([Schema.Literal('inactive'), Schema.Literal('policy')])),
|
|
19
|
+
iteration: Schema.optional(Schema.Struct({ index: Schema.Finite, previous: Schema.Json })),
|
|
13
20
|
});
|
|
21
|
+
function compatibleNodeStatus(status) {
|
|
22
|
+
switch (status) {
|
|
23
|
+
case 'pending':
|
|
24
|
+
case 'running':
|
|
25
|
+
case 'completed':
|
|
26
|
+
case 'failed':
|
|
27
|
+
case 'skipped':
|
|
28
|
+
return status;
|
|
29
|
+
default:
|
|
30
|
+
return 'pending';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
14
33
|
export function defineWorkflow(def) {
|
|
15
|
-
|
|
16
|
-
|
|
34
|
+
const definition = {
|
|
35
|
+
kind: 'workflow',
|
|
36
|
+
...def,
|
|
37
|
+
version: def.version ?? DEFAULT_DEFINITION_VERSION,
|
|
38
|
+
concurrency: resolveGraphConcurrency(def.concurrency),
|
|
39
|
+
};
|
|
40
|
+
topologicalSort(definition.nodes, workflowEdges(definition));
|
|
41
|
+
for (const node of definition.nodes) {
|
|
42
|
+
const failure = node.failure;
|
|
43
|
+
if (failure?.type === 'retry' &&
|
|
44
|
+
(!Number.isInteger(failure.maxAttempts) ||
|
|
45
|
+
failure.maxAttempts < 1 ||
|
|
46
|
+
failure.maxAttempts > 64)) {
|
|
47
|
+
throw new Error(`Node "${node.id}" retry maxAttempts must be between 1 and 64`);
|
|
48
|
+
}
|
|
49
|
+
if (failure?.type === 'fallback' &&
|
|
50
|
+
!definition.nodes.some((candidate) => candidate.id === failure.nodeId)) {
|
|
51
|
+
throw new Error(`Node "${node.id}" references unknown fallback "${failure.nodeId}"`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return definition;
|
|
17
55
|
}
|
|
18
56
|
export function readyNodes(workflow, nodeStates) {
|
|
19
|
-
|
|
20
|
-
|
|
57
|
+
const states = {};
|
|
58
|
+
for (const node of workflow.nodes) {
|
|
21
59
|
const state = nodeStates[node.id];
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
60
|
+
states[node.id] = {
|
|
61
|
+
status: compatibleNodeStatus(state?.status),
|
|
62
|
+
result: null,
|
|
63
|
+
error: null,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return getReadyNodeIds(workflow, states);
|
|
67
|
+
}
|
|
68
|
+
function childRef(child) {
|
|
69
|
+
return {
|
|
70
|
+
kind: child.kind,
|
|
71
|
+
name: child.name,
|
|
72
|
+
version: child.version ?? DEFAULT_DEFINITION_VERSION,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function iterations(child, items, concurrency) {
|
|
76
|
+
return {
|
|
77
|
+
type: 'map',
|
|
78
|
+
...childRef(child),
|
|
79
|
+
items,
|
|
80
|
+
concurrency: resolveGraphConcurrency(concurrency),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/** Builds the helpers a node's `run` uses to describe durable work. */
|
|
84
|
+
export function nodeResultBuilders() {
|
|
85
|
+
return {
|
|
86
|
+
spawn: (child, input) => ({ type: 'spawn', ...childRef(child), input }),
|
|
87
|
+
sleep: (ms) => ({ type: 'sleep', ms }),
|
|
88
|
+
effects: (effects) => ({ type: 'effects', effects }),
|
|
89
|
+
map: (child, items) => iterations(child, items, 1),
|
|
90
|
+
fanout: (child, items, concurrency = DEFAULT_GRAPH_CONCURRENCY) => iterations(child, items, concurrency),
|
|
91
|
+
loop: (child, input, { maxIterations }) => {
|
|
92
|
+
if (!Number.isInteger(maxIterations) || maxIterations < 0) {
|
|
93
|
+
throw new Error('loop maxIterations must be a non-negative integer');
|
|
94
|
+
}
|
|
95
|
+
return { type: 'loop', ...childRef(child), input, maxIterations };
|
|
96
|
+
},
|
|
97
|
+
};
|
|
32
98
|
}
|