@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
package/dist/core/ids.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
export declare function createEventId(): string;
|
|
2
2
|
export declare function createRunId(): string;
|
|
3
3
|
export declare function createThreadId(): string;
|
|
4
|
+
/**
|
|
5
|
+
* A UUID-shaped id derived only from `parts`, so a reducer that replays the same events names the same
|
|
6
|
+
* child thread every time.
|
|
7
|
+
*/
|
|
8
|
+
export declare function deterministicThreadId(...parts: readonly (string | number)[]): string;
|
|
4
9
|
export declare function createWaitId(scope?: string, tag?: string | number): string;
|
|
5
10
|
export declare function createEffectId(threadId: string, causingSeqOrTag: number | string, index?: number): string;
|
|
6
11
|
export declare function parseEffectId(effectId: string): {
|
package/dist/core/ids.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import { Predicate } from 'effect';
|
|
1
|
+
import { DateTime, Predicate } from 'effect';
|
|
2
2
|
let counter = 0;
|
|
3
3
|
function token() {
|
|
4
4
|
counter += 1;
|
|
5
|
-
|
|
5
|
+
const timestamp = DateTime.toEpochMillis(DateTime.nowUnsafe());
|
|
6
|
+
// Synchronous ID factories need process-independent entropy without an Effect runtime.
|
|
7
|
+
// oxlint-disable-next-line effecttsgo/crypto-random-uuid
|
|
8
|
+
const entropy = globalThis.crypto.randomUUID().replaceAll('-', '');
|
|
9
|
+
return `${timestamp.toString(36)}_${counter.toString(36)}_${entropy}`;
|
|
6
10
|
}
|
|
7
11
|
export function createEventId() {
|
|
8
12
|
return `evt_${token()}`;
|
|
@@ -13,6 +17,35 @@ export function createRunId() {
|
|
|
13
17
|
export function createThreadId() {
|
|
14
18
|
return `thr_${token()}`;
|
|
15
19
|
}
|
|
20
|
+
function fnv1a32(value, seed) {
|
|
21
|
+
let hash = seed >>> 0;
|
|
22
|
+
for (let index = 0; index < value.length; index++) {
|
|
23
|
+
hash ^= value.charCodeAt(index);
|
|
24
|
+
hash = Math.imul(hash, 0x01000193);
|
|
25
|
+
}
|
|
26
|
+
return (hash >>> 0).toString(16).padStart(8, '0');
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A UUID-shaped id derived only from `parts`, so a reducer that replays the same events names the same
|
|
30
|
+
* child thread every time.
|
|
31
|
+
*/
|
|
32
|
+
export function deterministicThreadId(...parts) {
|
|
33
|
+
const source = parts.join(':');
|
|
34
|
+
let reversed = '';
|
|
35
|
+
for (let index = source.length - 1; index >= 0; index--) {
|
|
36
|
+
reversed += source.charAt(index);
|
|
37
|
+
}
|
|
38
|
+
const hex = [
|
|
39
|
+
fnv1a32(source, 0x811c9dc5),
|
|
40
|
+
fnv1a32(source, 0x9e3779b9),
|
|
41
|
+
fnv1a32(reversed, 0x85ebca6b),
|
|
42
|
+
fnv1a32(reversed, 0xc2b2ae35),
|
|
43
|
+
].join('');
|
|
44
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-5${hex.slice(13, 16)}-${((Number.parseInt(hex.slice(16, 18), 16) & 0x3f) |
|
|
45
|
+
0x80)
|
|
46
|
+
.toString(16)
|
|
47
|
+
.padStart(2, '0')}${hex.slice(18, 20)}-${hex.slice(20)}`;
|
|
48
|
+
}
|
|
16
49
|
export function createWaitId(scope, tag) {
|
|
17
50
|
if (scope !== undefined && tag !== undefined) {
|
|
18
51
|
return `wait_${scope}_${tag}`;
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export type * from './types';
|
|
2
|
-
export { asJson, cleanUndefined,
|
|
2
|
+
export { asJson, cleanUndefined, isJsonNumber, isJsonObject, isJsonString, stringifyJson, stringifyJsonPretty, } from './types';
|
|
3
3
|
export * from './ids';
|
|
4
|
+
export * from './worker-callback';
|
|
4
5
|
export * from './schema';
|
|
5
6
|
export * from './validate-event';
|
|
6
7
|
export * from './envelope';
|
|
@@ -14,6 +15,7 @@ export * from './fold';
|
|
|
14
15
|
export * from './replay';
|
|
15
16
|
export * from './projection';
|
|
16
17
|
export * from './module';
|
|
18
|
+
export * from './kind';
|
|
17
19
|
export * from './module-scope';
|
|
18
20
|
export * from './compose';
|
|
19
21
|
export * from './store';
|
|
@@ -24,3 +26,7 @@ export * from './event-codec';
|
|
|
24
26
|
export * from './serialize';
|
|
25
27
|
export * from './coalesce';
|
|
26
28
|
export * from './event-index';
|
|
29
|
+
export * from './limits';
|
|
30
|
+
export * from './definition-store';
|
|
31
|
+
export * from './published';
|
|
32
|
+
export type { DebuggerHost, DebuggerRequest } from './debugger-host';
|
package/dist/core/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { asJson, cleanUndefined,
|
|
1
|
+
export { asJson, cleanUndefined, isJsonNumber, isJsonObject, isJsonString, stringifyJson, stringifyJsonPretty, } from './types.js';
|
|
2
2
|
export * from './ids.js';
|
|
3
|
+
export * from './worker-callback.js';
|
|
3
4
|
export * from './schema.js';
|
|
4
5
|
export * from './validate-event.js';
|
|
5
6
|
export * from './envelope.js';
|
|
@@ -13,6 +14,7 @@ export * from './fold.js';
|
|
|
13
14
|
export * from './replay.js';
|
|
14
15
|
export * from './projection.js';
|
|
15
16
|
export * from './module.js';
|
|
17
|
+
export * from './kind.js';
|
|
16
18
|
export * from './module-scope.js';
|
|
17
19
|
export * from './compose.js';
|
|
18
20
|
export * from './store.js';
|
|
@@ -23,3 +25,6 @@ export * from './event-codec.js';
|
|
|
23
25
|
export * from './serialize.js';
|
|
24
26
|
export * from './coalesce.js';
|
|
25
27
|
export * from './event-index.js';
|
|
28
|
+
export * from './limits.js';
|
|
29
|
+
export * from './definition-store.js';
|
|
30
|
+
export * from './published.js';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stamp a startable `{ kind, name }` definition.
|
|
3
|
+
*
|
|
4
|
+
* `defineAgent` and `defineWorkflow` are specialized helpers for those kinds.
|
|
5
|
+
* Custom thread types should use `createKind` / `defineKind` instead of
|
|
6
|
+
* assembling the object by hand.
|
|
7
|
+
*/
|
|
8
|
+
export declare function defineKind<TKind extends string, TDef extends {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
}>(kind: TKind, def: TDef): TDef & {
|
|
11
|
+
readonly kind: TKind;
|
|
12
|
+
};
|
|
13
|
+
export interface KindBuilder<TKind extends string> {
|
|
14
|
+
readonly kind: TKind;
|
|
15
|
+
define<TDef extends {
|
|
16
|
+
readonly name: string;
|
|
17
|
+
}>(def: TDef): TDef & {
|
|
18
|
+
readonly kind: TKind;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** Bind `define` to one kind so each custom type has a builder, like `defineAgent`. */
|
|
22
|
+
export declare function createKind<TKind extends string>(kind: TKind): KindBuilder<TKind>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stamp a startable `{ kind, name }` definition.
|
|
3
|
+
*
|
|
4
|
+
* `defineAgent` and `defineWorkflow` are specialized helpers for those kinds.
|
|
5
|
+
* Custom thread types should use `createKind` / `defineKind` instead of
|
|
6
|
+
* assembling the object by hand.
|
|
7
|
+
*/
|
|
8
|
+
export function defineKind(kind, def) {
|
|
9
|
+
return { ...def, kind };
|
|
10
|
+
}
|
|
11
|
+
/** Bind `define` to one kind so each custom type has a builder, like `defineAgent`. */
|
|
12
|
+
export function createKind(kind) {
|
|
13
|
+
return {
|
|
14
|
+
kind,
|
|
15
|
+
define: (def) => defineKind(kind, def),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { AppendableEvent } from './envelope';
|
|
2
|
+
import type { RunSnapshot } from './snapshot-store';
|
|
3
|
+
import type { JsonValue } from './types';
|
|
4
|
+
export declare const DEFAULT_MAX_EVENT_BYTES: number;
|
|
5
|
+
export declare const DEFAULT_MAX_SNAPSHOT_BYTES: number;
|
|
6
|
+
declare const EventPayloadTooLargeError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
7
|
+
readonly _tag: "EventPayloadTooLargeError";
|
|
8
|
+
} & Readonly<A>;
|
|
9
|
+
export declare class EventPayloadTooLargeError extends EventPayloadTooLargeError_base<{
|
|
10
|
+
readonly runId: string;
|
|
11
|
+
readonly eventType: string;
|
|
12
|
+
readonly bytes: number;
|
|
13
|
+
readonly maxBytes: number;
|
|
14
|
+
readonly message: string;
|
|
15
|
+
}> {
|
|
16
|
+
constructor(runId: string, eventType: string, bytes: number, maxBytes: number);
|
|
17
|
+
}
|
|
18
|
+
declare const SnapshotPayloadTooLargeError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
19
|
+
readonly _tag: "SnapshotPayloadTooLargeError";
|
|
20
|
+
} & Readonly<A>;
|
|
21
|
+
export declare class SnapshotPayloadTooLargeError extends SnapshotPayloadTooLargeError_base<{
|
|
22
|
+
readonly runId: string;
|
|
23
|
+
readonly bytes: number;
|
|
24
|
+
readonly maxBytes: number;
|
|
25
|
+
readonly message: string;
|
|
26
|
+
}> {
|
|
27
|
+
constructor(runId: string, bytes: number, maxBytes: number);
|
|
28
|
+
}
|
|
29
|
+
/** Size of `value` as serialized JSON, in UTF-8 bytes. */
|
|
30
|
+
export declare function utf8JsonBytes(value: JsonValue | Readonly<object>): number;
|
|
31
|
+
/** Validate every event before any storage mutation begins. */
|
|
32
|
+
export declare function assertEventByteLimits(runId: string, events: ReadonlyArray<AppendableEvent>, maxBytes?: number): void;
|
|
33
|
+
export declare function assertSnapshotByteLimit(snapshot: RunSnapshot, maxBytes?: number): void;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Data } from 'effect';
|
|
2
|
+
export const DEFAULT_MAX_EVENT_BYTES = 1024 * 1024;
|
|
3
|
+
export const DEFAULT_MAX_SNAPSHOT_BYTES = 8 * 1024 * 1024;
|
|
4
|
+
const utf8 = new TextEncoder();
|
|
5
|
+
export class EventPayloadTooLargeError extends Data.TaggedError('EventPayloadTooLargeError') {
|
|
6
|
+
constructor(runId, eventType, bytes, maxBytes) {
|
|
7
|
+
super({
|
|
8
|
+
runId,
|
|
9
|
+
eventType,
|
|
10
|
+
bytes,
|
|
11
|
+
maxBytes,
|
|
12
|
+
message: `EventPayloadTooLarge: event "${eventType}" for run "${runId}" is ${bytes} UTF-8 bytes; limit is ${maxBytes}`,
|
|
13
|
+
});
|
|
14
|
+
this.name = 'EventPayloadTooLargeError';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export class SnapshotPayloadTooLargeError extends Data.TaggedError('SnapshotPayloadTooLargeError') {
|
|
18
|
+
constructor(runId, bytes, maxBytes) {
|
|
19
|
+
super({
|
|
20
|
+
runId,
|
|
21
|
+
bytes,
|
|
22
|
+
maxBytes,
|
|
23
|
+
message: `SnapshotPayloadTooLarge: snapshot for run "${runId}" is ${bytes} UTF-8 bytes; limit is ${maxBytes}`,
|
|
24
|
+
});
|
|
25
|
+
this.name = 'SnapshotPayloadTooLargeError';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Size of `value` as serialized JSON, in UTF-8 bytes. */
|
|
29
|
+
export function utf8JsonBytes(value) {
|
|
30
|
+
return utf8.encode(JSON.stringify(value)).byteLength;
|
|
31
|
+
}
|
|
32
|
+
/** Validate every event before any storage mutation begins. */
|
|
33
|
+
export function assertEventByteLimits(runId, events, maxBytes = DEFAULT_MAX_EVENT_BYTES) {
|
|
34
|
+
for (const event of events) {
|
|
35
|
+
const bytes = utf8JsonBytes({ ...event, runId, seq: event.seq ?? 0 });
|
|
36
|
+
if (bytes > maxBytes) {
|
|
37
|
+
throw new EventPayloadTooLargeError(runId, event.type, bytes, maxBytes);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export function assertSnapshotByteLimit(snapshot, maxBytes = DEFAULT_MAX_SNAPSHOT_BYTES) {
|
|
42
|
+
const bytes = utf8JsonBytes(snapshot);
|
|
43
|
+
if (bytes > maxBytes) {
|
|
44
|
+
throw new SnapshotPayloadTooLargeError(snapshot.runId, bytes, maxBytes);
|
|
45
|
+
}
|
|
46
|
+
}
|
package/dist/core/match.d.ts
CHANGED
|
@@ -4,5 +4,6 @@ import type { JsonValue } from './types';
|
|
|
4
4
|
export declare function isSubset(match: JsonValue, payload: JsonValue): boolean;
|
|
5
5
|
export declare function matchesWait(event: EventEnvelope, on: WaitCondition): boolean;
|
|
6
6
|
export declare function matchingWaits<T extends {
|
|
7
|
+
waitId: string;
|
|
7
8
|
on: WaitCondition;
|
|
8
9
|
}>(event: EventEnvelope, waits: readonly T[]): T[];
|
package/dist/core/match.js
CHANGED
|
@@ -54,5 +54,14 @@ export function matchesWait(event, on) {
|
|
|
54
54
|
return isSubset(on.match, event.payload);
|
|
55
55
|
}
|
|
56
56
|
export function matchingWaits(event, waits) {
|
|
57
|
-
return waits.filter((record) =>
|
|
57
|
+
return waits.filter((record) => {
|
|
58
|
+
if (isWaitOnTimer(record.on)) {
|
|
59
|
+
if (event.type !== 'runtime.timer.fired' || !Predicate.isObject(event.payload)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
const firedWaitId = event.payload.waitId;
|
|
63
|
+
return Predicate.isString(firedWaitId) && firedWaitId === record.waitId;
|
|
64
|
+
}
|
|
65
|
+
return matchesWait(event, record.on);
|
|
66
|
+
});
|
|
58
67
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
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 EffectHandlerResult, type EmitEffect, type RetryPolicy, type RuntimeEffect, type ScopedEffectContext } from './effects';
|
|
4
|
+
import { type EffectDefinition, type EffectExecution, type EffectHandlerResult, type EmitEffect, type RetryPolicy, type RuntimeEffect, type ScopedEffectContext } from './effects';
|
|
5
5
|
import type { EventEnvelope, EventInput } from './envelope';
|
|
6
|
-
import { type AnyRuntimeModule, type EffectMiddleware, type RuntimeModule, type DefinitionRef, type RuntimeModuleDependency } from './module';
|
|
6
|
+
import { type AnyRuntimeModule, type EffectMiddleware, type RuntimeModule, type DefinitionRef, type RuntimeModuleDependency, type SignalInterruptRule } from './module';
|
|
7
7
|
import { type ProjectionDefinition } from './projection';
|
|
8
8
|
import type { InferDefinedSchema, InferSchemaOutput, SchemaInput } from './schema';
|
|
9
9
|
import { type StartContext, type ThreadContext, type ThreadDefinition } from './thread';
|
|
@@ -32,40 +32,41 @@ export interface ModuleScope<TNamespace extends string, U extends EventEnvelope<
|
|
|
32
32
|
readonly events?: TEvents;
|
|
33
33
|
readonly observes?: TObserves;
|
|
34
34
|
readonly dependencies?: readonly RuntimeModuleDependency[];
|
|
35
|
-
thread<TShape, TInputSchema extends SchemaInput | undefined = undefined>(def: {
|
|
36
|
-
readonly kind: string;
|
|
37
|
-
readonly shape: TShape;
|
|
38
|
-
readonly input?: TInputSchema;
|
|
39
|
-
initialState(ctx: StartContext<InferDefinedSchema<TInputSchema>>): InferSchemaOutput<TShape>;
|
|
40
|
-
step(state: InferSchemaOutput<TShape>, event: U, ctx: ThreadContext): InferSchemaOutput<TShape>;
|
|
41
|
-
effects?(state: InferSchemaOutput<TShape>, ctx: ThreadContext): RuntimeEffect[];
|
|
42
|
-
}): ThreadDefinition<InferSchemaOutput<TShape>>;
|
|
43
35
|
thread<S = JsonValue, TInputSchema extends SchemaInput | undefined = undefined>(def: {
|
|
44
36
|
readonly kind: string;
|
|
45
|
-
readonly shape?:
|
|
37
|
+
readonly shape?: undefined;
|
|
46
38
|
readonly input?: TInputSchema;
|
|
47
39
|
initialState(ctx: StartContext<InferDefinedSchema<TInputSchema>>): S;
|
|
48
40
|
step(state: S, event: U, ctx: ThreadContext): S;
|
|
49
41
|
effects?(state: S, ctx: ThreadContext): RuntimeEffect[];
|
|
50
42
|
}): ThreadDefinition<S>;
|
|
51
|
-
|
|
52
|
-
readonly
|
|
43
|
+
thread<TShape extends SchemaInput, TInputSchema extends SchemaInput | undefined = undefined>(def: {
|
|
44
|
+
readonly kind: string;
|
|
53
45
|
readonly shape: TShape;
|
|
54
|
-
readonly
|
|
55
|
-
|
|
56
|
-
|
|
46
|
+
readonly input?: TInputSchema;
|
|
47
|
+
initialState(ctx: StartContext<InferDefinedSchema<TInputSchema>>): InferSchemaOutput<TShape>;
|
|
48
|
+
step(state: NoInfer<InferSchemaOutput<TShape>>, event: U, ctx: ThreadContext): InferSchemaOutput<TShape>;
|
|
49
|
+
effects?(state: NoInfer<InferSchemaOutput<TShape>>, ctx: ThreadContext): RuntimeEffect[];
|
|
50
|
+
}): ThreadDefinition<InferSchemaOutput<TShape>>;
|
|
57
51
|
projection<S>(def: {
|
|
58
52
|
readonly name: string;
|
|
59
|
-
readonly shape?:
|
|
53
|
+
readonly shape?: undefined;
|
|
60
54
|
readonly initialState: S;
|
|
61
55
|
reduce(state: S, event: U): S;
|
|
62
56
|
}): ProjectionDefinition<S>;
|
|
63
|
-
|
|
57
|
+
projection<TShape extends SchemaInput>(def: {
|
|
58
|
+
readonly name: string;
|
|
59
|
+
readonly shape: TShape;
|
|
60
|
+
readonly initialState: InferSchemaOutput<TShape>;
|
|
61
|
+
reduce(state: NoInfer<InferSchemaOutput<TShape>>, event: U): InferSchemaOutput<TShape>;
|
|
62
|
+
}): ProjectionDefinition<InferSchemaOutput<TShape>>;
|
|
63
|
+
effect<TSchema extends SchemaInput | undefined = undefined, TInput = InferDefinedSchema<TSchema>, R = never, HandlerError = never>(def: {
|
|
64
64
|
type: `${TNamespace}.${string}`;
|
|
65
65
|
input?: TSchema;
|
|
66
66
|
retry?: RetryPolicy;
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
execution?: EffectExecution;
|
|
68
|
+
execute?: (input: TInput, ctx: ScopedEffectContext<EventInputOf<U>>) => EffectHandlerResult<R, EventInputOf<U>, HandlerError>;
|
|
69
|
+
}): NoInfer<EffectDefinition<TInput, R, EventInputOf<U>>>;
|
|
69
70
|
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'> & {
|
|
70
71
|
readonly type: `${TNamespace}.${K}`;
|
|
71
72
|
readonly payload: InferPayload<(TEvents extends EventCatalog<any, infer E> ? E : never)[K]>;
|
|
@@ -92,6 +93,7 @@ export declare function defineModule<const N extends string, E extends EventCata
|
|
|
92
93
|
readonly projections?: PR;
|
|
93
94
|
readonly definitions?: readonly DefinitionRef[];
|
|
94
95
|
readonly middleware?: readonly EffectMiddleware[];
|
|
96
|
+
readonly interruptsOnSignal?: SignalInterruptRule;
|
|
95
97
|
} & ModuleServicesConfig<EffectRequirementsOf<FX>>): RuntimeModule<N, Extract<ModuleCatalog<N, E>, EventCatalog>, FX, TH, PR> & {
|
|
96
98
|
readonly effects: FX;
|
|
97
99
|
readonly threads: TH;
|
|
@@ -4,11 +4,7 @@ import {} from './module.js';
|
|
|
4
4
|
import { defineProjection } from './projection.js';
|
|
5
5
|
import { defineThread, } from './thread.js';
|
|
6
6
|
import { asJson } from './types.js';
|
|
7
|
-
function buildScopeInput(namespace,
|
|
8
|
-
if (events) {
|
|
9
|
-
// SAFETY: catalog input produces typed EventInput for the catalog entry.
|
|
10
|
-
return events.input(key, payload, meta);
|
|
11
|
-
}
|
|
7
|
+
function buildScopeInput(namespace, key, payload, meta) {
|
|
12
8
|
return {
|
|
13
9
|
...meta,
|
|
14
10
|
type: `${namespace}.${key}`,
|
|
@@ -33,40 +29,54 @@ export function createModuleScope(options) {
|
|
|
33
29
|
return defineEffect(def);
|
|
34
30
|
},
|
|
35
31
|
input(key, payload, meta) {
|
|
36
|
-
return buildScopeInput(namespace,
|
|
32
|
+
return buildScopeInput(namespace, key, payload, meta);
|
|
37
33
|
},
|
|
38
34
|
emit(key, payload, meta) {
|
|
39
|
-
return emit(buildScopeInput(namespace,
|
|
35
|
+
return emit(buildScopeInput(namespace, key, payload, meta));
|
|
40
36
|
},
|
|
41
37
|
};
|
|
42
38
|
return scope;
|
|
43
39
|
}
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
function isEventCatalog(source) {
|
|
41
|
+
return 'namespace' in source && 'entries' in source;
|
|
42
|
+
}
|
|
43
|
+
function isModuleScope(source) {
|
|
44
|
+
return 'thread' in source && 'effect' in source;
|
|
45
|
+
}
|
|
46
46
|
export function defineModule(options, setup) {
|
|
47
47
|
const source = options.events;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
(typeof source.input === 'function'
|
|
48
|
+
const events = source
|
|
49
|
+
? isEventCatalog(source)
|
|
51
50
|
? source
|
|
52
|
-
: defineEventCatalog(options.namespace, source)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
: createModuleScope({ ...options, events });
|
|
51
|
+
: defineEventCatalog(options.namespace, source)
|
|
52
|
+
: undefined;
|
|
53
|
+
const scope = isModuleScope(options) ? options : createModuleScope({ ...options, events });
|
|
56
54
|
const members = setup(scope);
|
|
57
|
-
|
|
55
|
+
const module = {
|
|
58
56
|
namespace: options.namespace,
|
|
59
57
|
protocolVersion: options.protocolVersion,
|
|
60
|
-
events
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
...(members.middleware ? { middleware: members.middleware } : {}),
|
|
65
|
-
...(members.services ? { services: members.services } : {}),
|
|
66
|
-
// SAFETY: absent member bags use the corresponding empty-object generic defaults.
|
|
67
|
-
effects: (members.effects ?? {}),
|
|
68
|
-
threads: (members.threads ?? {}),
|
|
69
|
-
projections: (members.projections ?? {}),
|
|
58
|
+
events,
|
|
59
|
+
effects: members.effects ?? {},
|
|
60
|
+
threads: members.threads ?? {},
|
|
61
|
+
projections: members.projections ?? {},
|
|
70
62
|
};
|
|
63
|
+
if (options.observes) {
|
|
64
|
+
module.observes = options.observes;
|
|
65
|
+
}
|
|
66
|
+
if (options.dependencies) {
|
|
67
|
+
module.dependencies = options.dependencies;
|
|
68
|
+
}
|
|
69
|
+
if (members.definitions) {
|
|
70
|
+
module.definitions = members.definitions;
|
|
71
|
+
}
|
|
72
|
+
if (members.middleware) {
|
|
73
|
+
module.middleware = members.middleware;
|
|
74
|
+
}
|
|
75
|
+
if (members.services) {
|
|
76
|
+
module.services = members.services;
|
|
77
|
+
}
|
|
78
|
+
if (members.interruptsOnSignal) {
|
|
79
|
+
module.interruptsOnSignal = members.interruptsOnSignal;
|
|
80
|
+
}
|
|
81
|
+
return module;
|
|
71
82
|
}
|
|
72
|
-
/* oxlint-enable anti-slop/no-runtime-typeof, anti-slop/no-chained-type-assertions, anti-slop/no-conditional-empty-object-spread, anti-slop/require-safety-comment-for-type-assertion */
|
package/dist/core/module.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Effect, Layer } from 'effect';
|
|
1
|
+
import type { Context, Effect, Layer } from 'effect';
|
|
2
2
|
import type { EventCatalog } from './catalog';
|
|
3
3
|
import type { EffectContext, EffectDefinition, RuntimeEffect } from './effects';
|
|
4
4
|
import type { EventInput } from './envelope';
|
|
@@ -8,6 +8,12 @@ import type { ThreadDefinition } from './thread';
|
|
|
8
8
|
import type { JsonValue } from './types';
|
|
9
9
|
export type NextEffectHandler = (effect: RuntimeEffect, ctx: EffectContext) => Effect.Effect<ReadonlyArray<EventInput>, Error>;
|
|
10
10
|
export type EffectMiddleware = (effect: RuntimeEffect, ctx: EffectContext, next: NextEffectHandler) => Effect.Effect<ReadonlyArray<EventInput>, Error>;
|
|
11
|
+
/**
|
|
12
|
+
* Names the threads whose in-process effects an admitted signal event interrupts, so a running
|
|
13
|
+
* effect (such as a model call) can stop early. Return an empty array when the event interrupts
|
|
14
|
+
* nothing.
|
|
15
|
+
*/
|
|
16
|
+
export type SignalInterruptRule = (event: EventInput) => readonly string[];
|
|
11
17
|
export interface RuntimeModuleDependency {
|
|
12
18
|
readonly namespace: string;
|
|
13
19
|
readonly protocolVersion?: string;
|
|
@@ -16,13 +22,19 @@ export interface RuntimeModuleDependency {
|
|
|
16
22
|
export interface DefinitionRef {
|
|
17
23
|
readonly kind: string;
|
|
18
24
|
readonly name: string;
|
|
25
|
+
readonly version?: string;
|
|
19
26
|
readonly input?: SchemaInput | undefined;
|
|
27
|
+
readonly description?: string | undefined;
|
|
20
28
|
}
|
|
21
|
-
|
|
29
|
+
export declare const DEFAULT_DEFINITION_VERSION = "v1";
|
|
30
|
+
export declare function definitionKey(kind: string, name: string, version: string): string;
|
|
31
|
+
/** A definition registered on a host, keyed by `${kind}:${name}@${version}`. */
|
|
22
32
|
export interface RegisteredDefinition {
|
|
23
33
|
readonly kind: string;
|
|
24
34
|
readonly name: string;
|
|
35
|
+
readonly version: string;
|
|
25
36
|
readonly input?: SchemaInput | undefined;
|
|
37
|
+
readonly description?: string | undefined;
|
|
26
38
|
readonly value: DefinitionRef;
|
|
27
39
|
}
|
|
28
40
|
/**
|
|
@@ -44,7 +56,7 @@ export interface RuntimeModule<TNamespace extends string = string, TEvents exten
|
|
|
44
56
|
readonly [key: string]: ProjectionDefinition;
|
|
45
57
|
} = {
|
|
46
58
|
readonly [key: string]: ProjectionDefinition;
|
|
47
|
-
}, TServices =
|
|
59
|
+
}, TServices = Context.Service.Any> {
|
|
48
60
|
readonly namespace: TNamespace;
|
|
49
61
|
readonly protocolVersion: string;
|
|
50
62
|
readonly events?: TEvents;
|
|
@@ -55,6 +67,7 @@ export interface RuntimeModule<TNamespace extends string = string, TEvents exten
|
|
|
55
67
|
readonly definitions?: readonly DefinitionRef[];
|
|
56
68
|
readonly dependencies?: readonly RuntimeModuleDependency[];
|
|
57
69
|
readonly middleware?: readonly EffectMiddleware[];
|
|
70
|
+
readonly interruptsOnSignal?: SignalInterruptRule;
|
|
58
71
|
/** Host-side services this module's effect handlers need (an LLM, a definition lookup, a DB pool). */
|
|
59
72
|
readonly services?: () => Layer.Layer<TServices>;
|
|
60
73
|
}
|
|
@@ -64,9 +77,9 @@ export declare function defineRuntimeModule<TNamespace extends string, TEvents e
|
|
|
64
77
|
readonly [key: string]: ThreadDefinition;
|
|
65
78
|
}, TProjections extends {
|
|
66
79
|
readonly [key: string]: ProjectionDefinition;
|
|
67
|
-
}, TServices =
|
|
80
|
+
}, TServices = Context.Service.Any>(module: RuntimeModule<TNamespace, TEvents, TEffects, TThreads, TProjections, TServices>): RuntimeModule<TNamespace, TEvents, TEffects, TThreads, TProjections, TServices>;
|
|
68
81
|
export type AnyRuntimeModule = RuntimeModule<string, EventCatalog, {
|
|
69
|
-
readonly [name: string]: EffectDefinition
|
|
82
|
+
readonly [name: string]: EffectDefinition<any, any, any>;
|
|
70
83
|
}, {
|
|
71
84
|
readonly [kind: string]: ThreadDefinition;
|
|
72
85
|
}, {
|
package/dist/core/module.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema, Stream, type Effect } from 'effect';
|
|
2
2
|
import type { EventEnvelope } from './envelope';
|
|
3
|
-
import type { InferSchemaOutput } from './schema';
|
|
3
|
+
import type { InferSchemaOutput, SchemaInput } from './schema';
|
|
4
4
|
import type { RunState, ThreadRecord } from './state';
|
|
5
5
|
export interface ProjectionDefinition<S = unknown> {
|
|
6
6
|
readonly name: string;
|
|
@@ -8,18 +8,18 @@ export interface ProjectionDefinition<S = unknown> {
|
|
|
8
8
|
initialState: S;
|
|
9
9
|
reduce(state: S, event: EventEnvelope): S;
|
|
10
10
|
}
|
|
11
|
-
export declare function defineProjection<TShape>(def: {
|
|
12
|
-
readonly name: string;
|
|
13
|
-
readonly shape: TShape;
|
|
14
|
-
readonly initialState: InferSchemaOutput<TShape>;
|
|
15
|
-
reduce(state: InferSchemaOutput<TShape>, event: EventEnvelope): InferSchemaOutput<TShape>;
|
|
16
|
-
}): ProjectionDefinition<InferSchemaOutput<TShape>>;
|
|
17
11
|
export declare function defineProjection<S = unknown>(def: {
|
|
18
12
|
readonly name: string;
|
|
19
|
-
readonly shape?:
|
|
13
|
+
readonly shape?: undefined;
|
|
20
14
|
readonly initialState: S;
|
|
21
15
|
reduce(state: S, event: EventEnvelope): S;
|
|
22
16
|
}): ProjectionDefinition<S>;
|
|
17
|
+
export declare function defineProjection<TShape extends SchemaInput>(def: {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly shape: TShape;
|
|
20
|
+
readonly initialState: InferSchemaOutput<TShape>;
|
|
21
|
+
reduce(state: NoInfer<InferSchemaOutput<TShape>>, event: EventEnvelope): InferSchemaOutput<TShape>;
|
|
22
|
+
}): ProjectionDefinition<InferSchemaOutput<TShape>>;
|
|
23
23
|
export declare function foldProjection<S>(projection: ProjectionDefinition<S>, events: readonly EventEnvelope[], initial?: S): S;
|
|
24
24
|
/** Fold a projection over events, skipping ephemeral ones. */
|
|
25
25
|
export declare function project<S>(definition: ProjectionDefinition<S>, events: readonly EventEnvelope[], from?: S): S;
|
|
@@ -29,6 +29,7 @@ export interface ThreadNode {
|
|
|
29
29
|
threadId: string;
|
|
30
30
|
kind: string;
|
|
31
31
|
definitionName: string;
|
|
32
|
+
definitionVersion: string;
|
|
32
33
|
status: ThreadRecord['status'];
|
|
33
34
|
parentThreadId: string | null;
|
|
34
35
|
children: ThreadNode[];
|
|
@@ -49,28 +50,27 @@ export interface TreeBuildState {
|
|
|
49
50
|
[threadId: string]: string[];
|
|
50
51
|
};
|
|
51
52
|
}
|
|
52
|
-
export declare const TreeBuildStateSchema: Schema.Schema<TreeBuildState>;
|
|
53
53
|
export declare const threadTree: ProjectionDefinition<TreeBuildState>;
|
|
54
54
|
export declare function toThreadTree(state: TreeBuildState): ThreadTree;
|
|
55
55
|
export declare function treeFromRun(state: RunState): ThreadTree;
|
|
56
56
|
export declare const TimelineEntrySchema: Schema.Struct<{
|
|
57
|
-
readonly seq: Schema.
|
|
57
|
+
readonly seq: Schema.Finite;
|
|
58
58
|
readonly id: Schema.String;
|
|
59
59
|
readonly type: Schema.String;
|
|
60
60
|
readonly threadId: Schema.NullOr<Schema.String>;
|
|
61
61
|
readonly causationId: Schema.NullOr<Schema.String>;
|
|
62
62
|
readonly effectId: Schema.NullOr<Schema.String>;
|
|
63
|
-
readonly ts: Schema.
|
|
63
|
+
readonly ts: Schema.Finite;
|
|
64
64
|
}>;
|
|
65
65
|
export type TimelineEntry = Schema.Schema.Type<typeof TimelineEntrySchema>;
|
|
66
66
|
export declare const TimelineSchema: Schema.mutable<Schema.$Array<Schema.Struct<{
|
|
67
|
-
readonly seq: Schema.
|
|
67
|
+
readonly seq: Schema.Finite;
|
|
68
68
|
readonly id: Schema.String;
|
|
69
69
|
readonly type: Schema.String;
|
|
70
70
|
readonly threadId: Schema.NullOr<Schema.String>;
|
|
71
71
|
readonly causationId: Schema.NullOr<Schema.String>;
|
|
72
72
|
readonly effectId: Schema.NullOr<Schema.String>;
|
|
73
|
-
readonly ts: Schema.
|
|
73
|
+
readonly ts: Schema.Finite;
|
|
74
74
|
}>>>;
|
|
75
75
|
export declare const timeline: ProjectionDefinition<{
|
|
76
76
|
readonly seq: number;
|