@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
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
|
+
import { EvaluatorEvaluatedPayloadSchema } from './events.js';
|
|
3
|
+
import { evaluatorModule } from './scope.js';
|
|
4
|
+
export const EvaluationsSchema = Schema.Struct({
|
|
5
|
+
items: Schema.mutable(Schema.Array(EvaluatorEvaluatedPayloadSchema)),
|
|
6
|
+
});
|
|
7
|
+
export const evaluations = evaluatorModule.projection({
|
|
8
|
+
name: 'evaluations',
|
|
9
|
+
shape: EvaluationsSchema,
|
|
10
|
+
initialState: { items: [] },
|
|
11
|
+
reduce(state, event) {
|
|
12
|
+
if (event.type !== 'evaluator.evaluated') {
|
|
13
|
+
return state;
|
|
14
|
+
}
|
|
15
|
+
const next = event.payload;
|
|
16
|
+
return {
|
|
17
|
+
items: [...state.items.filter((item) => item.evaluationId !== next.evaluationId), next],
|
|
18
|
+
};
|
|
19
|
+
},
|
|
20
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type EventOf } from '@swirls/looms/core';
|
|
2
|
+
export declare const evaluatorModule: import("@swirls/looms/core").ModuleScope<"evaluator", import("@swirls/looms/core").ScopeUniverse<import("@swirls/looms/core").EventCatalog<"evaluator", {
|
|
3
|
+
requested: import("effect/Schema").Struct<{
|
|
4
|
+
readonly evaluationId: import("effect/Schema").String;
|
|
5
|
+
readonly definitionName: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
6
|
+
readonly state: import("effect/Schema").String;
|
|
7
|
+
readonly model: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
8
|
+
}>;
|
|
9
|
+
evaluated: import("effect/Schema").Struct<{
|
|
10
|
+
readonly evaluationId: import("effect/Schema").String;
|
|
11
|
+
readonly definitionName: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
12
|
+
readonly answers: import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").Union<readonly [import("effect/Schema").Struct<{
|
|
13
|
+
readonly type: import("effect/Schema").Literal<"boolean">;
|
|
14
|
+
readonly value: import("effect/Schema").Boolean;
|
|
15
|
+
readonly probability: import("effect/Schema").Finite;
|
|
16
|
+
}>, import("effect/Schema").Struct<{
|
|
17
|
+
readonly type: import("effect/Schema").Literal<"choice">;
|
|
18
|
+
readonly value: import("effect/Schema").String;
|
|
19
|
+
}>, import("effect/Schema").Struct<{
|
|
20
|
+
readonly type: import("effect/Schema").Literal<"score">;
|
|
21
|
+
readonly value: import("effect/Schema").Finite;
|
|
22
|
+
}>]>>;
|
|
23
|
+
readonly route: import("effect/Schema").String;
|
|
24
|
+
readonly reason: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"model">, import("effect/Schema").Literal<"uncertain">, import("effect/Schema").Literal<"skipped">, import("effect/Schema").Literal<"unavailable">]>;
|
|
25
|
+
readonly usage: import("effect/Schema").optional<import("effect/Schema").Struct<{
|
|
26
|
+
readonly input: import("effect/Schema").Finite;
|
|
27
|
+
readonly output: import("effect/Schema").Finite;
|
|
28
|
+
}>>;
|
|
29
|
+
}>;
|
|
30
|
+
}>, undefined>, import("@swirls/looms/core").EventCatalog<"evaluator", {
|
|
31
|
+
requested: import("effect/Schema").Struct<{
|
|
32
|
+
readonly evaluationId: import("effect/Schema").String;
|
|
33
|
+
readonly definitionName: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
34
|
+
readonly state: import("effect/Schema").String;
|
|
35
|
+
readonly model: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
36
|
+
}>;
|
|
37
|
+
evaluated: import("effect/Schema").Struct<{
|
|
38
|
+
readonly evaluationId: import("effect/Schema").String;
|
|
39
|
+
readonly definitionName: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
40
|
+
readonly answers: import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").Union<readonly [import("effect/Schema").Struct<{
|
|
41
|
+
readonly type: import("effect/Schema").Literal<"boolean">;
|
|
42
|
+
readonly value: import("effect/Schema").Boolean;
|
|
43
|
+
readonly probability: import("effect/Schema").Finite;
|
|
44
|
+
}>, import("effect/Schema").Struct<{
|
|
45
|
+
readonly type: import("effect/Schema").Literal<"choice">;
|
|
46
|
+
readonly value: import("effect/Schema").String;
|
|
47
|
+
}>, import("effect/Schema").Struct<{
|
|
48
|
+
readonly type: import("effect/Schema").Literal<"score">;
|
|
49
|
+
readonly value: import("effect/Schema").Finite;
|
|
50
|
+
}>]>>;
|
|
51
|
+
readonly route: import("effect/Schema").String;
|
|
52
|
+
readonly reason: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"model">, import("effect/Schema").Literal<"uncertain">, import("effect/Schema").Literal<"skipped">, import("effect/Schema").Literal<"unavailable">]>;
|
|
53
|
+
readonly usage: import("effect/Schema").optional<import("effect/Schema").Struct<{
|
|
54
|
+
readonly input: import("effect/Schema").Finite;
|
|
55
|
+
readonly output: import("effect/Schema").Finite;
|
|
56
|
+
}>>;
|
|
57
|
+
}>;
|
|
58
|
+
}>, undefined>;
|
|
59
|
+
export type EvaluatorEvent = EventOf<typeof evaluatorModule>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createWaitId, invoke, wait } from '@swirls/looms/core';
|
|
2
|
+
import { evaluateEffect } from './effects.js';
|
|
3
|
+
export function evaluate(definition, input) {
|
|
4
|
+
const evaluationId = createWaitId('evaluator');
|
|
5
|
+
return [
|
|
6
|
+
invoke(evaluateEffect, {
|
|
7
|
+
evaluationId,
|
|
8
|
+
definitionName: definition.name,
|
|
9
|
+
input,
|
|
10
|
+
}, `evaluate_${evaluationId}`),
|
|
11
|
+
wait({
|
|
12
|
+
waitId: createWaitId(evaluationId, 'result'),
|
|
13
|
+
on: { type: 'evaluator.evaluated', match: { evaluationId } },
|
|
14
|
+
tag: { evaluationId },
|
|
15
|
+
}),
|
|
16
|
+
];
|
|
17
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
|
+
export declare const EvaluatorThreadStateSchema: Schema.Struct<{
|
|
3
|
+
readonly definitionName: Schema.optional<Schema.String>;
|
|
4
|
+
readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
5
|
+
readonly evaluationId: Schema.String;
|
|
6
|
+
readonly dispatched: Schema.Boolean;
|
|
7
|
+
readonly status: Schema.Union<readonly [Schema.Literal<"pending">, Schema.Literal<"completed">, Schema.Literal<"failed">]>;
|
|
8
|
+
readonly output: Schema.NullOr<Schema.Struct<{
|
|
9
|
+
readonly evaluationId: Schema.String;
|
|
10
|
+
readonly definitionName: Schema.optional<Schema.String>;
|
|
11
|
+
readonly answers: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.Struct<{
|
|
12
|
+
readonly type: Schema.Literal<"boolean">;
|
|
13
|
+
readonly value: Schema.Boolean;
|
|
14
|
+
readonly probability: Schema.Finite;
|
|
15
|
+
}>, Schema.Struct<{
|
|
16
|
+
readonly type: Schema.Literal<"choice">;
|
|
17
|
+
readonly value: Schema.String;
|
|
18
|
+
}>, Schema.Struct<{
|
|
19
|
+
readonly type: Schema.Literal<"score">;
|
|
20
|
+
readonly value: Schema.Finite;
|
|
21
|
+
}>]>>;
|
|
22
|
+
readonly route: Schema.String;
|
|
23
|
+
readonly reason: Schema.Union<readonly [Schema.Literal<"model">, Schema.Literal<"uncertain">, Schema.Literal<"skipped">, Schema.Literal<"unavailable">]>;
|
|
24
|
+
readonly usage: Schema.optional<Schema.Struct<{
|
|
25
|
+
readonly input: Schema.Finite;
|
|
26
|
+
readonly output: Schema.Finite;
|
|
27
|
+
}>>;
|
|
28
|
+
}>>;
|
|
29
|
+
readonly error: Schema.NullOr<Schema.String>;
|
|
30
|
+
}>;
|
|
31
|
+
export type EvaluatorThreadState = Schema.Schema.Type<typeof EvaluatorThreadStateSchema>;
|
|
32
|
+
export declare const evaluatorThread: import("@swirls/looms/core").ThreadDefinition<{
|
|
33
|
+
readonly definitionName?: string | undefined;
|
|
34
|
+
readonly input: Schema.Json;
|
|
35
|
+
readonly evaluationId: string;
|
|
36
|
+
readonly dispatched: boolean;
|
|
37
|
+
readonly status: "completed" | "failed" | "pending";
|
|
38
|
+
readonly output: {
|
|
39
|
+
readonly evaluationId: string;
|
|
40
|
+
readonly definitionName?: string | undefined;
|
|
41
|
+
readonly answers: {
|
|
42
|
+
readonly [x: string]: {
|
|
43
|
+
readonly type: "boolean";
|
|
44
|
+
readonly value: boolean;
|
|
45
|
+
readonly probability: number;
|
|
46
|
+
} | {
|
|
47
|
+
readonly type: "choice";
|
|
48
|
+
readonly value: string;
|
|
49
|
+
} | {
|
|
50
|
+
readonly type: "score";
|
|
51
|
+
readonly value: number;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
readonly route: string;
|
|
55
|
+
readonly reason: "model" | "skipped" | "unavailable" | "uncertain";
|
|
56
|
+
readonly usage?: {
|
|
57
|
+
readonly input: number;
|
|
58
|
+
readonly output: number;
|
|
59
|
+
} | undefined;
|
|
60
|
+
} | null;
|
|
61
|
+
readonly error: string | null;
|
|
62
|
+
}>;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Option, Predicate, Schema } from 'effect';
|
|
2
|
+
import { asJson, complete, createWaitId, fail, invoke, wait, } from '@swirls/looms/core';
|
|
3
|
+
import { evaluateEffect } from './effects.js';
|
|
4
|
+
import { EvaluatorEvaluatedPayloadSchema } from './events.js';
|
|
5
|
+
import { evaluatorModule } from './scope.js';
|
|
6
|
+
export const EvaluatorThreadStateSchema = Schema.Struct({
|
|
7
|
+
definitionName: Schema.optional(Schema.String),
|
|
8
|
+
input: Schema.Json,
|
|
9
|
+
evaluationId: Schema.String,
|
|
10
|
+
dispatched: Schema.Boolean,
|
|
11
|
+
status: Schema.Union([
|
|
12
|
+
Schema.Literal('pending'),
|
|
13
|
+
Schema.Literal('completed'),
|
|
14
|
+
Schema.Literal('failed'),
|
|
15
|
+
]),
|
|
16
|
+
output: Schema.NullOr(EvaluatorEvaluatedPayloadSchema),
|
|
17
|
+
error: Schema.NullOr(Schema.String),
|
|
18
|
+
});
|
|
19
|
+
const decodeEvaluated = Schema.decodeUnknownOption(EvaluatorEvaluatedPayloadSchema);
|
|
20
|
+
function readEvaluated(payload) {
|
|
21
|
+
const decoded = decodeEvaluated(payload);
|
|
22
|
+
return Option.isSome(decoded) ? decoded.value : undefined;
|
|
23
|
+
}
|
|
24
|
+
export const evaluatorThread = evaluatorModule.thread({
|
|
25
|
+
kind: 'evaluator',
|
|
26
|
+
shape: EvaluatorThreadStateSchema,
|
|
27
|
+
initialState: (ctx) => ({
|
|
28
|
+
definitionName: ctx.definitionName,
|
|
29
|
+
input: ctx.input,
|
|
30
|
+
evaluationId: `eval_${ctx.threadId}`,
|
|
31
|
+
dispatched: false,
|
|
32
|
+
status: 'pending',
|
|
33
|
+
output: null,
|
|
34
|
+
error: null,
|
|
35
|
+
}),
|
|
36
|
+
step(state, event, ctx) {
|
|
37
|
+
if (state.status === 'completed' || state.status === 'failed') {
|
|
38
|
+
return state;
|
|
39
|
+
}
|
|
40
|
+
switch (event.type) {
|
|
41
|
+
case 'runtime.thread.started': {
|
|
42
|
+
return {
|
|
43
|
+
...state,
|
|
44
|
+
definitionName: event.payload.definitionName || state.definitionName,
|
|
45
|
+
input: event.payload.input ?? state.input,
|
|
46
|
+
evaluationId: `eval_${ctx.threadId}`,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
case 'evaluator.requested': {
|
|
50
|
+
if (event.payload.evaluationId !== state.evaluationId) {
|
|
51
|
+
return state;
|
|
52
|
+
}
|
|
53
|
+
return { ...state, dispatched: true };
|
|
54
|
+
}
|
|
55
|
+
case 'evaluator.evaluated': {
|
|
56
|
+
if (event.payload.evaluationId !== state.evaluationId) {
|
|
57
|
+
return state;
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
...state,
|
|
61
|
+
dispatched: true,
|
|
62
|
+
status: 'completed',
|
|
63
|
+
output: event.payload,
|
|
64
|
+
error: null,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
case 'runtime.effect.failed': {
|
|
68
|
+
const error = event.payload.error || 'Evaluation failed';
|
|
69
|
+
return {
|
|
70
|
+
...state,
|
|
71
|
+
status: 'failed',
|
|
72
|
+
error,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
case 'runtime.wait.satisfied': {
|
|
76
|
+
const embedded = event.payload.event;
|
|
77
|
+
if (!Predicate.isObject(embedded) || embedded.type !== 'evaluator.evaluated') {
|
|
78
|
+
return state;
|
|
79
|
+
}
|
|
80
|
+
const evaluated = readEvaluated(embedded.payload);
|
|
81
|
+
if (!evaluated || evaluated.evaluationId !== state.evaluationId) {
|
|
82
|
+
return state;
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
...state,
|
|
86
|
+
dispatched: true,
|
|
87
|
+
status: 'completed',
|
|
88
|
+
output: evaluated,
|
|
89
|
+
error: null,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
default:
|
|
93
|
+
return state;
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
effects(state) {
|
|
97
|
+
if (state.status === 'failed') {
|
|
98
|
+
return [fail(state.error ?? 'Evaluation failed')];
|
|
99
|
+
}
|
|
100
|
+
if (state.status === 'completed') {
|
|
101
|
+
return [complete(asJson(state.output ?? null))];
|
|
102
|
+
}
|
|
103
|
+
const effects = [];
|
|
104
|
+
if (!state.dispatched) {
|
|
105
|
+
effects.push(invoke(evaluateEffect, {
|
|
106
|
+
evaluationId: state.evaluationId,
|
|
107
|
+
definitionName: state.definitionName,
|
|
108
|
+
input: state.input,
|
|
109
|
+
}, `evaluate_${state.evaluationId}`));
|
|
110
|
+
}
|
|
111
|
+
effects.push(wait({
|
|
112
|
+
waitId: createWaitId(state.evaluationId, 'result'),
|
|
113
|
+
on: { type: 'evaluator.evaluated', match: { evaluationId: state.evaluationId } },
|
|
114
|
+
}));
|
|
115
|
+
return effects;
|
|
116
|
+
},
|
|
117
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
|
+
import type { JsonValue } from '@swirls/looms/core';
|
|
3
|
+
export declare const BooleanQuestionSchema: Schema.Struct<{
|
|
4
|
+
readonly type: Schema.Literal<"boolean">;
|
|
5
|
+
readonly instructions: Schema.String;
|
|
6
|
+
}>;
|
|
7
|
+
export type BooleanQuestion = Schema.Schema.Type<typeof BooleanQuestionSchema>;
|
|
8
|
+
export declare const ChoiceQuestionSchema: Schema.Struct<{
|
|
9
|
+
readonly type: Schema.Literal<"choice">;
|
|
10
|
+
readonly instructions: Schema.String;
|
|
11
|
+
readonly criteria: Schema.$Record<Schema.String, Schema.String>;
|
|
12
|
+
}>;
|
|
13
|
+
export type ChoiceQuestion = Schema.Schema.Type<typeof ChoiceQuestionSchema>;
|
|
14
|
+
export declare const ScoreQuestionSchema: Schema.Struct<{
|
|
15
|
+
readonly type: Schema.Literal<"score">;
|
|
16
|
+
readonly instructions: Schema.String;
|
|
17
|
+
readonly criteria: Schema.$Array<Schema.String>;
|
|
18
|
+
}>;
|
|
19
|
+
export type ScoreQuestion = Schema.Schema.Type<typeof ScoreQuestionSchema>;
|
|
20
|
+
export declare const EvaluatorQuestionSchema: Schema.Union<readonly [Schema.Struct<{
|
|
21
|
+
readonly type: Schema.Literal<"boolean">;
|
|
22
|
+
readonly instructions: Schema.String;
|
|
23
|
+
}>, Schema.Struct<{
|
|
24
|
+
readonly type: Schema.Literal<"choice">;
|
|
25
|
+
readonly instructions: Schema.String;
|
|
26
|
+
readonly criteria: Schema.$Record<Schema.String, Schema.String>;
|
|
27
|
+
}>, Schema.Struct<{
|
|
28
|
+
readonly type: Schema.Literal<"score">;
|
|
29
|
+
readonly instructions: Schema.String;
|
|
30
|
+
readonly criteria: Schema.$Array<Schema.String>;
|
|
31
|
+
}>]>;
|
|
32
|
+
export type EvaluatorQuestion = Schema.Schema.Type<typeof EvaluatorQuestionSchema>;
|
|
33
|
+
export declare const EvaluatorQuestionsSchema: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.Struct<{
|
|
34
|
+
readonly type: Schema.Literal<"boolean">;
|
|
35
|
+
readonly instructions: Schema.String;
|
|
36
|
+
}>, Schema.Struct<{
|
|
37
|
+
readonly type: Schema.Literal<"choice">;
|
|
38
|
+
readonly instructions: Schema.String;
|
|
39
|
+
readonly criteria: Schema.$Record<Schema.String, Schema.String>;
|
|
40
|
+
}>, Schema.Struct<{
|
|
41
|
+
readonly type: Schema.Literal<"score">;
|
|
42
|
+
readonly instructions: Schema.String;
|
|
43
|
+
readonly criteria: Schema.$Array<Schema.String>;
|
|
44
|
+
}>]>>;
|
|
45
|
+
export type EvaluatorQuestions = Schema.Schema.Type<typeof EvaluatorQuestionsSchema>;
|
|
46
|
+
export declare const BooleanAnswerSchema: Schema.Struct<{
|
|
47
|
+
readonly type: Schema.Literal<"boolean">;
|
|
48
|
+
readonly value: Schema.Boolean;
|
|
49
|
+
readonly probability: Schema.Finite;
|
|
50
|
+
}>;
|
|
51
|
+
export type BooleanAnswer = Schema.Schema.Type<typeof BooleanAnswerSchema>;
|
|
52
|
+
export declare const ChoiceAnswerSchema: Schema.Struct<{
|
|
53
|
+
readonly type: Schema.Literal<"choice">;
|
|
54
|
+
readonly value: Schema.String;
|
|
55
|
+
}>;
|
|
56
|
+
export type ChoiceAnswer = Schema.Schema.Type<typeof ChoiceAnswerSchema>;
|
|
57
|
+
export declare const ScoreAnswerSchema: Schema.Struct<{
|
|
58
|
+
readonly type: Schema.Literal<"score">;
|
|
59
|
+
readonly value: Schema.Finite;
|
|
60
|
+
}>;
|
|
61
|
+
export type ScoreAnswer = Schema.Schema.Type<typeof ScoreAnswerSchema>;
|
|
62
|
+
export declare const EvaluatorAnswerSchema: Schema.Union<readonly [Schema.Struct<{
|
|
63
|
+
readonly type: Schema.Literal<"boolean">;
|
|
64
|
+
readonly value: Schema.Boolean;
|
|
65
|
+
readonly probability: Schema.Finite;
|
|
66
|
+
}>, Schema.Struct<{
|
|
67
|
+
readonly type: Schema.Literal<"choice">;
|
|
68
|
+
readonly value: Schema.String;
|
|
69
|
+
}>, Schema.Struct<{
|
|
70
|
+
readonly type: Schema.Literal<"score">;
|
|
71
|
+
readonly value: Schema.Finite;
|
|
72
|
+
}>]>;
|
|
73
|
+
export type EvaluatorAnswer = Schema.Schema.Type<typeof EvaluatorAnswerSchema>;
|
|
74
|
+
export declare const EvaluatorAnswersSchema: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.Struct<{
|
|
75
|
+
readonly type: Schema.Literal<"boolean">;
|
|
76
|
+
readonly value: Schema.Boolean;
|
|
77
|
+
readonly probability: Schema.Finite;
|
|
78
|
+
}>, Schema.Struct<{
|
|
79
|
+
readonly type: Schema.Literal<"choice">;
|
|
80
|
+
readonly value: Schema.String;
|
|
81
|
+
}>, Schema.Struct<{
|
|
82
|
+
readonly type: Schema.Literal<"score">;
|
|
83
|
+
readonly value: Schema.Finite;
|
|
84
|
+
}>]>>;
|
|
85
|
+
export type EvaluatorAnswers = Schema.Schema.Type<typeof EvaluatorAnswersSchema>;
|
|
86
|
+
export declare const EvaluatorRouteSchema: Schema.String;
|
|
87
|
+
export type EvaluatorRoute = Schema.Schema.Type<typeof EvaluatorRouteSchema>;
|
|
88
|
+
export declare const EvaluatorReasonSchema: Schema.Union<readonly [Schema.Literal<"model">, Schema.Literal<"uncertain">, Schema.Literal<"skipped">, Schema.Literal<"unavailable">]>;
|
|
89
|
+
export type EvaluatorReason = Schema.Schema.Type<typeof EvaluatorReasonSchema>;
|
|
90
|
+
export declare const EvaluatorUsageSchema: Schema.Struct<{
|
|
91
|
+
readonly input: Schema.Finite;
|
|
92
|
+
readonly output: Schema.Finite;
|
|
93
|
+
}>;
|
|
94
|
+
export type EvaluatorUsage = Schema.Schema.Type<typeof EvaluatorUsageSchema>;
|
|
95
|
+
export interface EvaluatorEvaluateArgs {
|
|
96
|
+
readonly model?: string;
|
|
97
|
+
readonly state: string;
|
|
98
|
+
readonly questions: EvaluatorQuestions;
|
|
99
|
+
readonly signal?: AbortSignal;
|
|
100
|
+
}
|
|
101
|
+
export interface EvaluatorEvaluateResult {
|
|
102
|
+
readonly answers: EvaluatorAnswers;
|
|
103
|
+
readonly usage?: EvaluatorUsage;
|
|
104
|
+
readonly raw?: unknown;
|
|
105
|
+
}
|
|
106
|
+
export interface EvaluatorAdapter {
|
|
107
|
+
readonly evaluate: (args: EvaluatorEvaluateArgs) => Promise<EvaluatorEvaluateResult>;
|
|
108
|
+
}
|
|
109
|
+
export interface EvaluatorSkipResult {
|
|
110
|
+
readonly route: string;
|
|
111
|
+
readonly reason: 'skipped' | 'unavailable';
|
|
112
|
+
readonly answers?: EvaluatorAnswers;
|
|
113
|
+
}
|
|
114
|
+
export interface EvaluatorRouteDecision {
|
|
115
|
+
readonly route: string;
|
|
116
|
+
readonly reason?: EvaluatorReason;
|
|
117
|
+
}
|
|
118
|
+
export interface ResolvedEvaluatorDecision {
|
|
119
|
+
readonly route: string;
|
|
120
|
+
readonly reason: EvaluatorReason;
|
|
121
|
+
}
|
|
122
|
+
export interface EvaluatorRouteArgs {
|
|
123
|
+
readonly answers: EvaluatorAnswers;
|
|
124
|
+
readonly input: JsonValue;
|
|
125
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
|
+
export const BooleanQuestionSchema = Schema.Struct({
|
|
3
|
+
type: Schema.Literal('boolean'),
|
|
4
|
+
instructions: Schema.String,
|
|
5
|
+
});
|
|
6
|
+
export const ChoiceQuestionSchema = Schema.Struct({
|
|
7
|
+
type: Schema.Literal('choice'),
|
|
8
|
+
instructions: Schema.String,
|
|
9
|
+
criteria: Schema.Record(Schema.String, Schema.String),
|
|
10
|
+
});
|
|
11
|
+
export const ScoreQuestionSchema = Schema.Struct({
|
|
12
|
+
type: Schema.Literal('score'),
|
|
13
|
+
instructions: Schema.String,
|
|
14
|
+
criteria: Schema.Array(Schema.String),
|
|
15
|
+
});
|
|
16
|
+
export const EvaluatorQuestionSchema = Schema.Union([
|
|
17
|
+
BooleanQuestionSchema,
|
|
18
|
+
ChoiceQuestionSchema,
|
|
19
|
+
ScoreQuestionSchema,
|
|
20
|
+
]);
|
|
21
|
+
export const EvaluatorQuestionsSchema = Schema.Record(Schema.String, EvaluatorQuestionSchema);
|
|
22
|
+
export const BooleanAnswerSchema = Schema.Struct({
|
|
23
|
+
type: Schema.Literal('boolean'),
|
|
24
|
+
value: Schema.Boolean,
|
|
25
|
+
probability: Schema.Finite,
|
|
26
|
+
});
|
|
27
|
+
export const ChoiceAnswerSchema = Schema.Struct({
|
|
28
|
+
type: Schema.Literal('choice'),
|
|
29
|
+
value: Schema.String,
|
|
30
|
+
});
|
|
31
|
+
export const ScoreAnswerSchema = Schema.Struct({
|
|
32
|
+
type: Schema.Literal('score'),
|
|
33
|
+
value: Schema.Finite,
|
|
34
|
+
});
|
|
35
|
+
export const EvaluatorAnswerSchema = Schema.Union([
|
|
36
|
+
BooleanAnswerSchema,
|
|
37
|
+
ChoiceAnswerSchema,
|
|
38
|
+
ScoreAnswerSchema,
|
|
39
|
+
]);
|
|
40
|
+
export const EvaluatorAnswersSchema = Schema.Record(Schema.String, EvaluatorAnswerSchema);
|
|
41
|
+
export const EvaluatorRouteSchema = Schema.String;
|
|
42
|
+
export const EvaluatorReasonSchema = Schema.Union([
|
|
43
|
+
Schema.Literal('model'),
|
|
44
|
+
Schema.Literal('uncertain'),
|
|
45
|
+
Schema.Literal('skipped'),
|
|
46
|
+
Schema.Literal('unavailable'),
|
|
47
|
+
]);
|
|
48
|
+
export const EvaluatorUsageSchema = Schema.Struct({
|
|
49
|
+
input: Schema.Finite,
|
|
50
|
+
output: Schema.Finite,
|
|
51
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import type { EventStore, EventStoreError } from '@swirls/looms/core';
|
|
3
|
+
import { type Projector } from './projector';
|
|
4
|
+
export type ProjectorDeliveryState = 'idle' | 'retrying' | 'dead-letter';
|
|
5
|
+
export interface ProjectorDeliveryStatus {
|
|
6
|
+
readonly runId: string;
|
|
7
|
+
readonly projector: string;
|
|
8
|
+
readonly version: string;
|
|
9
|
+
readonly cursor: number;
|
|
10
|
+
readonly state: ProjectorDeliveryState;
|
|
11
|
+
readonly attempts: number;
|
|
12
|
+
readonly failedSeq: number | null;
|
|
13
|
+
readonly nextRetryAt: number | null;
|
|
14
|
+
readonly lastError: string | null;
|
|
15
|
+
readonly updatedAt: number;
|
|
16
|
+
}
|
|
17
|
+
declare const ProjectorCursorError_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 & {
|
|
18
|
+
readonly _tag: "ProjectorCursorError";
|
|
19
|
+
} & Readonly<A>;
|
|
20
|
+
export declare class ProjectorCursorError extends ProjectorCursorError_base<{
|
|
21
|
+
readonly message: string;
|
|
22
|
+
}> {
|
|
23
|
+
}
|
|
24
|
+
export interface ProjectorCursorStore {
|
|
25
|
+
get(runId: string, projector: Projector): Effect.Effect<ProjectorDeliveryStatus, ProjectorCursorError>;
|
|
26
|
+
advance(runId: string, projector: Projector, cursor: number, now: number): Effect.Effect<void, ProjectorCursorError>;
|
|
27
|
+
fail(runId: string, projector: Projector, failure: {
|
|
28
|
+
readonly attempts: number;
|
|
29
|
+
readonly failedSeq: number;
|
|
30
|
+
readonly nextRetryAt: number | null;
|
|
31
|
+
readonly error: string;
|
|
32
|
+
readonly now: number;
|
|
33
|
+
}): Effect.Effect<void, ProjectorCursorError>;
|
|
34
|
+
requeue(runId: string, projector: Projector, now: number): Effect.Effect<void, ProjectorCursorError>;
|
|
35
|
+
list(runId?: string): Effect.Effect<readonly ProjectorDeliveryStatus[], ProjectorCursorError>;
|
|
36
|
+
}
|
|
37
|
+
declare const UnknownProjectorError_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 & {
|
|
38
|
+
readonly _tag: "UnknownProjectorError";
|
|
39
|
+
} & Readonly<A>;
|
|
40
|
+
export declare class UnknownProjectorError extends UnknownProjectorError_base<{
|
|
41
|
+
readonly message: string;
|
|
42
|
+
}> {
|
|
43
|
+
}
|
|
44
|
+
export type ProjectorDeliveryFailure = ProjectorCursorError | EventStoreError;
|
|
45
|
+
export interface ProjectorDeliveryOptions {
|
|
46
|
+
readonly batchSize?: number;
|
|
47
|
+
readonly initialRetryMs?: number;
|
|
48
|
+
readonly maxRetryMs?: number;
|
|
49
|
+
readonly maxAttempts?: number;
|
|
50
|
+
readonly now?: () => number;
|
|
51
|
+
readonly scheduleRetry?: (at: number) => Effect.Effect<void>;
|
|
52
|
+
readonly observer?: ProjectorObserver;
|
|
53
|
+
}
|
|
54
|
+
export type ProjectorObservation = {
|
|
55
|
+
readonly type: 'projector.lag' | 'projector.retry' | 'projector.dead-letter';
|
|
56
|
+
readonly runId: string;
|
|
57
|
+
readonly projector: string;
|
|
58
|
+
readonly at: number;
|
|
59
|
+
readonly cursor: number;
|
|
60
|
+
readonly lag: number;
|
|
61
|
+
readonly attempts: number;
|
|
62
|
+
readonly error?: string;
|
|
63
|
+
};
|
|
64
|
+
export interface ProjectorObserver {
|
|
65
|
+
observe(event: ProjectorObservation): void | Promise<void>;
|
|
66
|
+
}
|
|
67
|
+
export interface ProjectorOperationalStatus extends ProjectorDeliveryStatus {
|
|
68
|
+
readonly sourceTail: number;
|
|
69
|
+
readonly lag: number;
|
|
70
|
+
}
|
|
71
|
+
export interface ProjectorDelivery {
|
|
72
|
+
deliver(runId: string, options?: {
|
|
73
|
+
readonly force?: boolean;
|
|
74
|
+
}): Effect.Effect<void, ProjectorDeliveryFailure>;
|
|
75
|
+
status(runId?: string): Effect.Effect<readonly ProjectorDeliveryStatus[], ProjectorCursorError>;
|
|
76
|
+
requeue(runId: string, projectorName: string, version?: string): Effect.Effect<void, ProjectorDeliveryFailure | UnknownProjectorError>;
|
|
77
|
+
nextRetryAt(runId?: string): Effect.Effect<number | null, ProjectorCursorError>;
|
|
78
|
+
inspect(runId?: string): Effect.Effect<readonly ProjectorOperationalStatus[], ProjectorDeliveryFailure>;
|
|
79
|
+
/** Re-register retry deadlines and resume due retryable projector work. */
|
|
80
|
+
recover(runId?: string): Effect.Effect<number, ProjectorDeliveryFailure>;
|
|
81
|
+
}
|
|
82
|
+
export declare function createProjectorDelivery(source: EventStore, projectors: readonly Projector[], cursors: ProjectorCursorStore, options?: ProjectorDeliveryOptions): ProjectorDelivery;
|
|
83
|
+
export {};
|