@swirls/looms 0.9.0 → 0.11.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 +32 -0
- package/dist/actor/cell.d.ts +3 -1
- package/dist/actor/cell.js +1 -0
- package/dist/actor/host.d.ts +3 -1
- package/dist/actor/host.js +1 -0
- package/dist/actor/routing.js +2 -1
- package/dist/agent/debugger/agent-chat.js +6 -5
- package/dist/agent/debugger/index.js +2 -1
- package/dist/agent/module.d.ts +207 -1
- package/dist/agent/module.js +31 -0
- package/dist/agent/scope.js +1 -0
- package/dist/agent/signals.d.ts +108 -15
- package/dist/agent/signals.js +70 -47
- package/dist/approval/debugger/approvals-view.js +1 -1
- package/dist/approval/index.d.ts +1 -0
- package/dist/approval/index.js +1 -0
- package/dist/approval/module.d.ts +42 -1
- package/dist/approval/module.js +53 -0
- package/dist/approval/scope.js +1 -0
- package/dist/approval/signals.d.ts +19 -13
- package/dist/approval/signals.js +25 -45
- package/dist/approval/steps.d.ts +11 -0
- package/dist/approval/steps.js +39 -0
- package/dist/cli/commands.d.ts +1 -1
- package/dist/cli/commands.js +49 -14
- package/dist/client/client.d.ts +231 -21
- package/dist/client/client.js +20 -2
- package/dist/cloudflare/delete-terminal-run-storage.d.ts +39 -0
- package/dist/cloudflare/delete-terminal-run-storage.js +98 -0
- package/dist/cloudflare/durable-object.d.ts +11 -1
- package/dist/cloudflare/durable-object.js +23 -0
- package/dist/cloudflare/index.d.ts +1 -0
- package/dist/cloudflare/index.js +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +1 -0
- package/dist/core/module-scope.d.ts +50 -5
- package/dist/core/module-scope.js +22 -2
- package/dist/core/module.d.ts +29 -2
- package/dist/core/projection.d.ts +1 -0
- package/dist/core/published.d.ts +59 -1
- package/dist/core/published.js +97 -1
- package/dist/core/run-context.d.ts +50 -0
- package/dist/core/run-context.js +21 -1
- package/dist/core/signals.d.ts +56 -0
- package/dist/core/signals.js +93 -0
- package/dist/core/validate-event.d.ts +12 -1
- package/dist/core/validate-event.js +34 -11
- package/dist/debugger/app/assets/index-CO5gIvV8.css +2 -0
- package/dist/debugger/app/assets/{index-CMRl_aWQ.js → index-VTotlHcm.js} +2 -2
- package/dist/debugger/app/assets/routes-CEdsN9DO.js +47 -0
- package/dist/debugger/app/index.html +2 -2
- package/dist/debugger/index.d.ts +1 -1
- package/dist/debugger/index.js +1 -1
- package/dist/debugger/lib/cn.d.ts +1 -1
- package/dist/debugger/lib/cn.js +12 -1
- package/dist/debugger/plugin.d.ts +11 -1
- package/dist/debugger/plugin.js +41 -0
- package/dist/debugger/shell/debugger-shell.js +1 -1
- package/dist/debugger/shell/form-fields.d.ts +17 -0
- package/dist/debugger/shell/form-fields.js +38 -0
- package/dist/debugger/shell/run-action.d.ts +6 -0
- package/dist/debugger/shell/run-action.js +15 -0
- package/dist/debugger/shell/run-controls.js +3 -55
- package/dist/debugger/shell/schema-form.d.ts +10 -1
- package/dist/debugger/shell/schema-form.js +108 -10
- package/dist/debugger/shell/signal-form.d.ts +18 -0
- package/dist/debugger/shell/signal-form.js +185 -0
- package/dist/debugger/shell/start-form.js +2 -32
- package/dist/debugger/shell/use-debounced-preview.d.ts +22 -0
- package/dist/debugger/shell/use-debounced-preview.js +68 -0
- package/dist/evaluator/index.d.ts +1 -1
- package/dist/evaluator/index.js +1 -1
- package/dist/evaluator/module.d.ts +8 -1
- package/dist/evaluator/module.js +33 -0
- package/dist/evaluator/scope.js +1 -0
- package/dist/projectors/event-log-ops.d.ts +0 -6
- package/dist/projectors/event-log-ops.js +2 -12
- package/dist/projectors/event-log.d.ts +10 -5
- package/dist/projectors/event-log.js +26 -22
- package/dist/projectors/replica/columns.d.ts +41 -0
- package/dist/projectors/replica/columns.js +77 -0
- package/dist/projectors/replica/drizzle.d.ts +328 -57
- package/dist/projectors/replica/drizzle.js +18 -14
- package/dist/projectors/replica/migrations.d.ts +25 -5
- package/dist/projectors/replica/migrations.js +62 -14
- package/dist/projectors/replica/postgres.d.ts +12 -11
- package/dist/projectors/replica/postgres.js +12 -26
- package/dist/projectors/replica/sqlite-bun.d.ts +3 -1
- package/dist/projectors/replica/sqlite-bun.js +6 -2
- package/dist/projectors/replica/sqlite-migrations.d.ts +5 -5
- package/dist/projectors/replica/sqlite-migrations.js +22 -9
- package/dist/projectors/replica/sqlite.d.ts +12 -11
- package/dist/projectors/replica/sqlite.js +23 -16
- package/dist/runtime/looms.d.ts +27 -36
- package/dist/runtime/looms.js +1 -0
- package/dist/runtime/runtime.js +7 -1
- package/dist/runtime/server/http.js +4 -2
- package/dist/runtime/server/routes/definitions.d.ts +1 -1
- package/dist/runtime/server/routes/definitions.js +58 -2
- package/dist/runtime/server/routes/runs.js +25 -1
- package/dist/runtime/types.d.ts +6 -1
- package/dist/schedule/module.d.ts +117 -1
- package/dist/schedule/module.js +30 -0
- package/dist/schedule/scope.js +1 -0
- package/dist/schedule/signals.d.ts +59 -7
- package/dist/schedule/signals.js +35 -17
- package/dist/testing/corpus-module.d.ts +1 -1
- package/dist/testing/index.js +2 -1
- package/dist/testing/module-examples.d.ts +6 -0
- package/dist/testing/module-examples.js +66 -0
- package/dist/workflow/module.d.ts +3 -1
- package/dist/workflow/module.js +13 -0
- package/dist/workflow/scope.js +1 -0
- package/package.json +1 -1
- package/dist/debugger/app/assets/index-B7GdT1UA.css +0 -2
- package/dist/debugger/app/assets/routes-CfXxKG45.js +0 -47
- /package/dist/evaluator/{signals.d.ts → steps.d.ts} +0 -0
- /package/dist/evaluator/{signals.js → steps.js} +0 -0
|
@@ -1,17 +1,47 @@
|
|
|
1
|
-
import type { Layer } from 'effect';
|
|
1
|
+
import type { Context, 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
4
|
import { type EffectDefinition, type EffectHandlerResult, type EffectPlacement, type EmitEffect, type LocalEffectDefinition, type PlacedEffectDefinition, type PlacementHandler, type RetryPolicy, type RuntimeEffect, type ScopedLocalEffectContext } from './effects';
|
|
5
5
|
import type { EventEnvelope, EventInput } from './envelope';
|
|
6
6
|
import type { RunLauncherTag } from './launcher';
|
|
7
7
|
import { type AnyRuntimeModule, type DefinitionHost, type EffectAdmission, type EffectMiddleware, type RuntimeModule, type DefinitionRef, type RuntimeModuleDependency, type SignalInterruptRule } from './module';
|
|
8
|
-
import { type ProjectionDefinition } from './projection';
|
|
8
|
+
import { type ProjectionDefinition, type ProjectionStateOf } from './projection';
|
|
9
9
|
import type { InferDefinedSchema, InferSchemaOutput, SchemaInput } from './schema';
|
|
10
|
+
import { type AnySignalDefinition, type SignalDefinition } from './signals';
|
|
10
11
|
import { type StartContext, type ThreadContext, type ThreadDefinition } from './thread';
|
|
11
12
|
import { type JsonValue } from './types';
|
|
13
|
+
/** Schema-backed event builders returned on `signals`. Each is a {@link SignalDefinition}. */
|
|
14
|
+
export type ModuleSignals = {
|
|
15
|
+
readonly [key: string]: AnySignalDefinition;
|
|
16
|
+
};
|
|
17
|
+
type SignalBuiltOf<T> = T extends (...args: never[]) => infer R ? R : never;
|
|
18
|
+
type SignalEventOf<T> = SignalBuiltOf<T> extends readonly (infer E)[] ? E : SignalBuiltOf<T> extends infer E ? E : never;
|
|
19
|
+
/**
|
|
20
|
+
* Marks each signal whose built events fall outside the module's catalogs, such as one built with
|
|
21
|
+
* another module's scope or the unscoped `defineSignal`.
|
|
22
|
+
*/
|
|
23
|
+
export type ForeignSignalsCheck<SG, TAllowed> = {
|
|
24
|
+
readonly [K in keyof SG as [SignalEventOf<SG[K]>] extends [TAllowed] ? never : K]: 'Signal events are outside this module catalog; build it with this module scope';
|
|
25
|
+
};
|
|
26
|
+
/** Effect composers returned on `steps`. Each returns effects for threads and workflow nodes. */
|
|
27
|
+
export type ModuleSteps = {
|
|
28
|
+
readonly [key: string]: (...args: never[]) => readonly RuntimeEffect[];
|
|
29
|
+
};
|
|
30
|
+
type DeepReadonly<T> = T extends object ? {
|
|
31
|
+
readonly [K in keyof T]: DeepReadonly<T[K]>;
|
|
32
|
+
} : T;
|
|
33
|
+
/** Typed example trace. Projection keys are member keys from setup, not projection `.name` values. */
|
|
34
|
+
export interface ModuleExampleOf<U, PR> {
|
|
35
|
+
readonly name: string;
|
|
36
|
+
readonly events: readonly EventInputOf<U>[];
|
|
37
|
+
readonly projections: {
|
|
38
|
+
readonly [K in keyof PR]?: DeepReadonly<ProjectionStateOf<PR[K]>>;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
12
41
|
export interface DefineModuleOptions<TNamespace extends string, TEvents extends EventCatalog | undefined = undefined, TObserves extends readonly EventCatalog[] | undefined = undefined> {
|
|
13
42
|
readonly namespace: TNamespace;
|
|
14
43
|
readonly protocolVersion: string;
|
|
44
|
+
readonly description?: string;
|
|
15
45
|
readonly events?: TEvents;
|
|
16
46
|
readonly observes?: TObserves;
|
|
17
47
|
readonly dependencies?: readonly RuntimeModuleDependency[];
|
|
@@ -38,6 +68,7 @@ export type ModuleServicesConfig<TR> = [TR] extends [never] ? {
|
|
|
38
68
|
export interface ModuleScope<TNamespace extends string, U extends EventEnvelope<any, any>, TEvents extends EventCatalog | undefined, TObserves extends readonly EventCatalog[] | undefined = readonly EventCatalog[] | undefined> {
|
|
39
69
|
readonly namespace: TNamespace;
|
|
40
70
|
readonly protocolVersion: string;
|
|
71
|
+
readonly description?: string;
|
|
41
72
|
readonly events?: TEvents;
|
|
42
73
|
readonly observes?: TObserves;
|
|
43
74
|
readonly dependencies?: readonly RuntimeModuleDependency[];
|
|
@@ -83,6 +114,15 @@ export interface ModuleScope<TNamespace extends string, U extends EventEnvelope<
|
|
|
83
114
|
retry?: RetryPolicy;
|
|
84
115
|
deterministic?: boolean;
|
|
85
116
|
} & PlacementHandler<P, (input: TInput, ctx: ScopedLocalEffectContext<EventInputOf<U>>) => EffectHandlerResult<R, EventInputOf<U>, HandlerError>>): NoInfer<PlacedEffectDefinition<P, TInput, R, EventInputOf<U>>>;
|
|
117
|
+
/**
|
|
118
|
+
* Declare a signal for this module. Callers outside the run invoke it to build typed events.
|
|
119
|
+
* The host publishes its `input` schema and can run `build` over HTTP for the debugger.
|
|
120
|
+
*/
|
|
121
|
+
signal<TSchema extends SchemaInput | undefined = undefined, E extends EventInputOf<U> | readonly EventInputOf<U>[] = EventInputOf<U> | readonly EventInputOf<U>[]>(def: {
|
|
122
|
+
readonly description?: string;
|
|
123
|
+
readonly input?: TSchema;
|
|
124
|
+
readonly build: (input: InferDefinedSchema<TSchema, undefined>) => E;
|
|
125
|
+
}): SignalDefinition<InferDefinedSchema<TSchema, undefined>, E>;
|
|
86
126
|
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'> & {
|
|
87
127
|
readonly type: `${TNamespace}.${K}`;
|
|
88
128
|
readonly payload: InferPayload<(TEvents extends EventCatalog<any, infer E> ? E : never)[K]>;
|
|
@@ -94,27 +134,32 @@ export type ThreadStateOf<T> = T extends ThreadDefinition<infer S> ? S : never;
|
|
|
94
134
|
export declare function createModuleScope<TNamespace extends string, TEvents extends EventCatalog | undefined = undefined, TObserves extends readonly EventCatalog[] | undefined = undefined>(options: DefineModuleOptions<TNamespace, TEvents, TObserves>): ModuleScope<TNamespace, ScopeUniverse<TEvents, TObserves>, TEvents, TObserves>;
|
|
95
135
|
/** A catalog may be supplied directly, or created from inline event schemas. */
|
|
96
136
|
export type ModuleCatalog<N extends string, E> = E extends EventCatalog ? E : E extends CatalogEntries ? EventCatalog<N, E> : undefined;
|
|
97
|
-
/** Construct a complete module. Only members returned by setup are
|
|
137
|
+
/** Construct a complete module. Only members returned by setup are kept. */
|
|
98
138
|
export declare function defineModule<const N extends string, E extends EventCatalog | CatalogEntries | undefined = undefined, O extends readonly EventCatalog[] | undefined = undefined, FX extends {
|
|
99
139
|
readonly [key: string]: EffectDefinition<any, any, any>;
|
|
100
140
|
} = {}, TH extends {
|
|
101
141
|
readonly [key: string]: ThreadDefinition;
|
|
102
142
|
} = {}, PR extends {
|
|
103
143
|
readonly [key: string]: ProjectionDefinition;
|
|
104
|
-
} = {}>(options: Omit<DefineModuleOptions<N, ModuleCatalog<N, E>, O>, 'events'> & {
|
|
144
|
+
} = {}, SG extends ModuleSignals = {}, ST extends ModuleSteps = {}, const EX extends readonly ModuleExampleOf<ScopeUniverse<ModuleCatalog<N, E>, O>, PR>[] = []>(options: Omit<DefineModuleOptions<N, ModuleCatalog<N, E>, O>, 'events'> & {
|
|
105
145
|
readonly events?: E;
|
|
106
146
|
}, setup: (scope: ModuleScope<N, ScopeUniverse<ModuleCatalog<N, E>, O>, ModuleCatalog<N, E>, O>) => {
|
|
107
147
|
readonly effects?: FX & ForeignEffectsCheck<FX, EventInputOf<ScopeUniverse<ModuleCatalog<N, E>, O>>>;
|
|
108
148
|
readonly threads?: TH;
|
|
109
149
|
readonly projections?: PR;
|
|
150
|
+
readonly signals?: SG & ForeignSignalsCheck<SG, EventInputOf<ScopeUniverse<ModuleCatalog<N, E>, O>>>;
|
|
151
|
+
readonly steps?: ST;
|
|
152
|
+
readonly examples?: EX;
|
|
110
153
|
readonly definitions?: readonly DefinitionRef[];
|
|
111
154
|
readonly middleware?: readonly EffectMiddleware[];
|
|
112
155
|
readonly admission?: readonly EffectAdmission[];
|
|
113
156
|
readonly interruptsOnSignal?: SignalInterruptRule;
|
|
114
157
|
readonly bindHost?: (host: DefinitionHost) => void;
|
|
115
|
-
} & ModuleServicesConfig<EffectRequirementsOf<FX>>): RuntimeModule<N, Extract<ModuleCatalog<N, E>, EventCatalog>, FX, TH, PR> & {
|
|
158
|
+
} & ModuleServicesConfig<EffectRequirementsOf<FX>>): RuntimeModule<N, Extract<ModuleCatalog<N, E>, EventCatalog>, FX, TH, PR, Context.Service.Any, SG, ST> & {
|
|
116
159
|
readonly effects: FX;
|
|
117
160
|
readonly threads: TH;
|
|
118
161
|
readonly projections: PR;
|
|
162
|
+
readonly signals: SG;
|
|
163
|
+
readonly steps: ST;
|
|
119
164
|
};
|
|
120
165
|
export {};
|
|
@@ -2,8 +2,16 @@ import { defineEventCatalog, } from './catalog.js';
|
|
|
2
2
|
import { emit, defineEffect, } from './effects.js';
|
|
3
3
|
import {} from './module.js';
|
|
4
4
|
import { defineProjection } from './projection.js';
|
|
5
|
+
import { defineSignal } from './signals.js';
|
|
5
6
|
import { defineThread, } from './thread.js';
|
|
6
|
-
import { asJson } from './types.js';
|
|
7
|
+
import { asJson, cleanUndefined } from './types.js';
|
|
8
|
+
function storeExamples(examples) {
|
|
9
|
+
return examples.map(({ name, events, projections }) => ({
|
|
10
|
+
name,
|
|
11
|
+
events,
|
|
12
|
+
projections: Object.fromEntries(Object.entries(projections).map(([key, state]) => [key, cleanUndefined(state)])),
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
7
15
|
function buildScopeInput(namespace, key, payload, meta) {
|
|
8
16
|
return {
|
|
9
17
|
...meta,
|
|
@@ -12,10 +20,11 @@ function buildScopeInput(namespace, key, payload, meta) {
|
|
|
12
20
|
};
|
|
13
21
|
}
|
|
14
22
|
export function createModuleScope(options) {
|
|
15
|
-
const { namespace, protocolVersion, events, observes, dependencies } = options;
|
|
23
|
+
const { namespace, protocolVersion, description, events, observes, dependencies } = options;
|
|
16
24
|
const scope = {
|
|
17
25
|
namespace,
|
|
18
26
|
protocolVersion,
|
|
27
|
+
description,
|
|
19
28
|
events,
|
|
20
29
|
observes,
|
|
21
30
|
dependencies,
|
|
@@ -28,6 +37,9 @@ export function createModuleScope(options) {
|
|
|
28
37
|
effect(def) {
|
|
29
38
|
return defineEffect(def);
|
|
30
39
|
},
|
|
40
|
+
signal(def) {
|
|
41
|
+
return defineSignal(def);
|
|
42
|
+
},
|
|
31
43
|
input(key, payload, meta) {
|
|
32
44
|
return buildScopeInput(namespace, key, payload, meta);
|
|
33
45
|
},
|
|
@@ -59,13 +71,21 @@ export function defineModule(options, setup) {
|
|
|
59
71
|
effects: members.effects ?? {},
|
|
60
72
|
threads: members.threads ?? {},
|
|
61
73
|
projections: members.projections ?? {},
|
|
74
|
+
signals: members.signals ?? {},
|
|
75
|
+
steps: members.steps ?? {},
|
|
62
76
|
};
|
|
77
|
+
if (options.description) {
|
|
78
|
+
module.description = options.description;
|
|
79
|
+
}
|
|
63
80
|
if (options.observes) {
|
|
64
81
|
module.observes = options.observes;
|
|
65
82
|
}
|
|
66
83
|
if (options.dependencies) {
|
|
67
84
|
module.dependencies = options.dependencies;
|
|
68
85
|
}
|
|
86
|
+
if (members.examples) {
|
|
87
|
+
module.examples = storeExamples(members.examples);
|
|
88
|
+
}
|
|
69
89
|
if (members.definitions) {
|
|
70
90
|
module.definitions = members.definitions;
|
|
71
91
|
}
|
package/dist/core/module.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { EventInput } from './envelope';
|
|
|
6
6
|
import type { ProjectionDefinition } from './projection';
|
|
7
7
|
import type { RunAttributes, SecretContext } from './run-context';
|
|
8
8
|
import { type InferDefinedSchema, type SchemaInput } from './schema';
|
|
9
|
+
import type { AnySignalDefinition } from './signals';
|
|
9
10
|
import type { ThreadDefinition } from './thread';
|
|
10
11
|
import type { TraceContext } from './trace';
|
|
11
12
|
import type { JsonValue } from './types';
|
|
@@ -84,6 +85,17 @@ export interface RegisteredDefinition {
|
|
|
84
85
|
export type DefinitionInput<TDef> = TDef extends {
|
|
85
86
|
readonly input?: infer S;
|
|
86
87
|
} ? InferDefinedSchema<S> : JsonValue;
|
|
88
|
+
/**
|
|
89
|
+
* A trace `moduleConformance` folds. Events are catalog inputs in log order. `projections` maps a
|
|
90
|
+
* projection member key to the JSON state the fold must produce. The host does not read examples.
|
|
91
|
+
*/
|
|
92
|
+
export interface ModuleExample {
|
|
93
|
+
readonly name: string;
|
|
94
|
+
readonly events: readonly EventInput[];
|
|
95
|
+
readonly projections: {
|
|
96
|
+
readonly [memberKey: string]: JsonValue;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
87
99
|
export interface RuntimeModule<TNamespace extends string = string, TEvents extends EventCatalog = EventCatalog, TEffects extends {
|
|
88
100
|
readonly [key: string]: EffectDefinition;
|
|
89
101
|
} = {
|
|
@@ -96,14 +108,25 @@ export interface RuntimeModule<TNamespace extends string = string, TEvents exten
|
|
|
96
108
|
readonly [key: string]: ProjectionDefinition;
|
|
97
109
|
} = {
|
|
98
110
|
readonly [key: string]: ProjectionDefinition;
|
|
99
|
-
}, TServices = Context.Service.Any> {
|
|
111
|
+
}, TServices = Context.Service.Any, TSignals = {}, TSteps = {}> {
|
|
100
112
|
readonly namespace: TNamespace;
|
|
101
113
|
readonly protocolVersion: string;
|
|
114
|
+
/** Published on `GET /definitions` so a catalog can name the module. */
|
|
115
|
+
readonly description?: string;
|
|
102
116
|
readonly events?: TEvents;
|
|
103
117
|
readonly observes?: readonly EventCatalog[];
|
|
104
118
|
readonly threads?: TThreads;
|
|
105
119
|
readonly effects?: TEffects;
|
|
106
120
|
readonly projections?: TProjections;
|
|
121
|
+
/**
|
|
122
|
+
* Schema-backed event builders for callers outside a run. Callers import them, and the host
|
|
123
|
+
* publishes their input schemas and can run `build` for preview / named send over HTTP.
|
|
124
|
+
*/
|
|
125
|
+
readonly signals?: TSignals;
|
|
126
|
+
/** Effect composers for threads and workflow nodes. The host does not run them. */
|
|
127
|
+
readonly steps?: TSteps;
|
|
128
|
+
/** Sample traces. The host ignores them; conformance folds them. */
|
|
129
|
+
readonly examples?: readonly ModuleExample[];
|
|
107
130
|
readonly definitions?: readonly DefinitionRef[];
|
|
108
131
|
readonly dependencies?: readonly RuntimeModuleDependency[];
|
|
109
132
|
readonly middleware?: readonly EffectMiddleware[];
|
|
@@ -127,11 +150,15 @@ export declare function defineRuntimeModule<TNamespace extends string, TEvents e
|
|
|
127
150
|
readonly [key: string]: ThreadDefinition;
|
|
128
151
|
}, TProjections extends {
|
|
129
152
|
readonly [key: string]: ProjectionDefinition;
|
|
130
|
-
}, TServices = Context.Service.Any>(module: RuntimeModule<TNamespace, TEvents, TEffects, TThreads, TProjections, TServices>): RuntimeModule<TNamespace, TEvents, TEffects, TThreads, TProjections, TServices>;
|
|
153
|
+
}, TServices = Context.Service.Any, TSignals = {}, TSteps = {}>(module: RuntimeModule<TNamespace, TEvents, TEffects, TThreads, TProjections, TServices, TSignals, TSteps>): RuntimeModule<TNamespace, TEvents, TEffects, TThreads, TProjections, TServices, TSignals, TSteps>;
|
|
131
154
|
export type AnyRuntimeModule = RuntimeModule<string, EventCatalog, {
|
|
132
155
|
readonly [name: string]: EffectDefinition<any, any, any>;
|
|
133
156
|
}, {
|
|
134
157
|
readonly [kind: string]: ThreadDefinition;
|
|
135
158
|
}, {
|
|
136
159
|
readonly [name: string]: ProjectionDefinition;
|
|
160
|
+
}, Context.Service.Any, {
|
|
161
|
+
readonly [name: string]: AnySignalDefinition;
|
|
162
|
+
}, {
|
|
163
|
+
readonly [name: string]: (...args: never[]) => readonly RuntimeEffect[];
|
|
137
164
|
}>;
|
|
@@ -9,6 +9,7 @@ export interface ProjectionDefinition<S = unknown> {
|
|
|
9
9
|
initialState: S;
|
|
10
10
|
reduce(state: S, event: EventEnvelope): S;
|
|
11
11
|
}
|
|
12
|
+
export type ProjectionStateOf<T> = T extends ProjectionDefinition<infer S> ? S : never;
|
|
12
13
|
export declare function defineProjection<S = unknown, TEvent extends AnyEventEnvelope = RegisteredEvent>(def: {
|
|
13
14
|
readonly name: string;
|
|
14
15
|
readonly shape?: undefined;
|
package/dist/core/published.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema } from 'effect';
|
|
2
2
|
import type { EffectPlacement, RetryPolicy } from './effects';
|
|
3
|
-
import type { RegisteredDefinition } from './module';
|
|
3
|
+
import type { AnyRuntimeModule, RegisteredDefinition } from './module';
|
|
4
4
|
import { type SchemaInput } from './schema';
|
|
5
5
|
import { type RunState } from './state';
|
|
6
6
|
/** A registered definition as `GET /definitions` publishes it. */
|
|
@@ -13,6 +13,13 @@ export declare const PublishedDefinitionSchema: Schema.Struct<{
|
|
|
13
13
|
readonly inputSchema: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
14
14
|
}>;
|
|
15
15
|
export type PublishedDefinition = Schema.Schema.Type<typeof PublishedDefinitionSchema>;
|
|
16
|
+
/** A module as `GET /definitions` publishes it. */
|
|
17
|
+
export declare const PublishedModuleSchema: Schema.Struct<{
|
|
18
|
+
readonly namespace: Schema.String;
|
|
19
|
+
readonly protocolVersion: Schema.String;
|
|
20
|
+
readonly description: Schema.optional<Schema.String>;
|
|
21
|
+
}>;
|
|
22
|
+
export type PublishedModule = Schema.Schema.Type<typeof PublishedModuleSchema>;
|
|
16
23
|
export declare const DefinitionCatalogSchema: Schema.Struct<{
|
|
17
24
|
readonly definitions: Schema.$Array<Schema.Struct<{
|
|
18
25
|
readonly kind: Schema.String;
|
|
@@ -23,8 +30,15 @@ export declare const DefinitionCatalogSchema: Schema.Struct<{
|
|
|
23
30
|
readonly inputSchema: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
24
31
|
}>>;
|
|
25
32
|
readonly projections: Schema.$Array<Schema.String>;
|
|
33
|
+
readonly modules: Schema.withDecodingDefaultKey<Schema.$Array<Schema.Struct<{
|
|
34
|
+
readonly namespace: Schema.String;
|
|
35
|
+
readonly protocolVersion: Schema.String;
|
|
36
|
+
readonly description: Schema.optional<Schema.String>;
|
|
37
|
+
}>>, never>;
|
|
26
38
|
}>;
|
|
27
39
|
export type DefinitionCatalog = Schema.Schema.Type<typeof DefinitionCatalogSchema>;
|
|
40
|
+
/** Modules in registration order. */
|
|
41
|
+
export declare function publishModules(modules: readonly AnyRuntimeModule[]): readonly PublishedModule[];
|
|
28
42
|
export declare function publishDefinition(definition: RegisteredDefinition): PublishedDefinition;
|
|
29
43
|
/** A declared effect as `GET /definitions/effects` publishes it. */
|
|
30
44
|
export declare const PublishedEffectSchema: Schema.Struct<{
|
|
@@ -75,6 +89,50 @@ interface PublishableEffect {
|
|
|
75
89
|
export declare function publishEffect(definition: PublishableEffect): PublishedEffect;
|
|
76
90
|
/** Declared effects, sorted by type so the catalog is stable. */
|
|
77
91
|
export declare function publishEffects(effects: Iterable<PublishableEffect>): readonly PublishedEffect[];
|
|
92
|
+
/** A module signal as `GET /definitions/signals` publishes it. */
|
|
93
|
+
export declare const PublishedSignalSchema: Schema.Struct<{
|
|
94
|
+
readonly namespace: Schema.String;
|
|
95
|
+
readonly name: Schema.String;
|
|
96
|
+
readonly description: Schema.optional<Schema.String>;
|
|
97
|
+
/** JSON Schema derived from the signal's `input`. Omitted for no-arg signals. */
|
|
98
|
+
readonly inputSchema: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
99
|
+
}>;
|
|
100
|
+
export type PublishedSignal = Schema.Schema.Type<typeof PublishedSignalSchema>;
|
|
101
|
+
export declare const SignalCatalogSchema: Schema.Struct<{
|
|
102
|
+
readonly signals: Schema.$Array<Schema.Struct<{
|
|
103
|
+
readonly namespace: Schema.String;
|
|
104
|
+
readonly name: Schema.String;
|
|
105
|
+
readonly description: Schema.optional<Schema.String>;
|
|
106
|
+
/** JSON Schema derived from the signal's `input`. Omitted for no-arg signals. */
|
|
107
|
+
readonly inputSchema: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
108
|
+
}>>;
|
|
109
|
+
}>;
|
|
110
|
+
export type SignalCatalog = Schema.Schema.Type<typeof SignalCatalogSchema>;
|
|
111
|
+
export declare function publishSignal(namespace: string, name: string, definition: {
|
|
112
|
+
readonly description?: string;
|
|
113
|
+
readonly input?: SchemaInput;
|
|
114
|
+
}): PublishedSignal;
|
|
115
|
+
/** Declared signals across modules, sorted by namespace then name. */
|
|
116
|
+
export declare function publishSignals(modules: readonly AnyRuntimeModule[]): readonly PublishedSignal[];
|
|
117
|
+
/** A catalog event as `GET /definitions/events` publishes it. */
|
|
118
|
+
export declare const PublishedEventSchema: Schema.Struct<{
|
|
119
|
+
readonly type: Schema.String;
|
|
120
|
+
readonly namespace: Schema.String;
|
|
121
|
+
/** JSON Schema for the event payload, when the catalog entry has a runtime schema. */
|
|
122
|
+
readonly payloadSchema: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
123
|
+
}>;
|
|
124
|
+
export type PublishedEvent = Schema.Schema.Type<typeof PublishedEventSchema>;
|
|
125
|
+
export declare const EventTypeCatalogSchema: Schema.Struct<{
|
|
126
|
+
readonly events: Schema.$Array<Schema.Struct<{
|
|
127
|
+
readonly type: Schema.String;
|
|
128
|
+
readonly namespace: Schema.String;
|
|
129
|
+
/** JSON Schema for the event payload, when the catalog entry has a runtime schema. */
|
|
130
|
+
readonly payloadSchema: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
131
|
+
}>>;
|
|
132
|
+
}>;
|
|
133
|
+
export type EventTypeCatalog = Schema.Schema.Type<typeof EventTypeCatalogSchema>;
|
|
134
|
+
/** Catalog events across modules, sorted by type. */
|
|
135
|
+
export declare function publishEvents(modules: readonly AnyRuntimeModule[]): readonly PublishedEvent[];
|
|
78
136
|
/** A run as `GET /runs/summaries` lists it. */
|
|
79
137
|
export declare const RunSummarySchema: Schema.Struct<{
|
|
80
138
|
readonly runId: Schema.String;
|
package/dist/core/published.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Effect, Schema } from 'effect';
|
|
1
|
+
import { Effect, Predicate, Schema } from 'effect';
|
|
2
2
|
import { JsonValueSchema } from './envelope.js';
|
|
3
3
|
import { RunAttributesSchema } from './run-context.js';
|
|
4
4
|
import { jsonSchemaOfInput } from './schema.js';
|
|
5
|
+
import { isSignalDefinition } from './signals.js';
|
|
5
6
|
import { RunStateSchema } from './state.js';
|
|
6
7
|
/** A registered definition as `GET /definitions` publishes it. */
|
|
7
8
|
export const PublishedDefinitionSchema = Schema.Struct({
|
|
@@ -12,10 +13,25 @@ export const PublishedDefinitionSchema = Schema.Struct({
|
|
|
12
13
|
/** JSON Schema derived from the definition's `input`. */
|
|
13
14
|
inputSchema: Schema.optional(JsonValueSchema),
|
|
14
15
|
});
|
|
16
|
+
/** A module as `GET /definitions` publishes it. */
|
|
17
|
+
export const PublishedModuleSchema = Schema.Struct({
|
|
18
|
+
namespace: Schema.String,
|
|
19
|
+
protocolVersion: Schema.String,
|
|
20
|
+
description: Schema.optional(Schema.String),
|
|
21
|
+
});
|
|
15
22
|
export const DefinitionCatalogSchema = Schema.Struct({
|
|
16
23
|
definitions: Schema.Array(PublishedDefinitionSchema),
|
|
17
24
|
projections: Schema.Array(Schema.String),
|
|
25
|
+
modules: Schema.Array(PublishedModuleSchema).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
|
|
18
26
|
});
|
|
27
|
+
/** Modules in registration order. */
|
|
28
|
+
export function publishModules(modules) {
|
|
29
|
+
return modules.map(({ namespace, protocolVersion, description }) => ({
|
|
30
|
+
namespace,
|
|
31
|
+
protocolVersion,
|
|
32
|
+
...(description ? { description } : undefined),
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
19
35
|
export function publishDefinition(definition) {
|
|
20
36
|
return {
|
|
21
37
|
kind: definition.kind,
|
|
@@ -70,6 +86,86 @@ export function publishEffects(effects) {
|
|
|
70
86
|
.map(publishEffect)
|
|
71
87
|
.toSorted((left, right) => left.type.localeCompare(right.type));
|
|
72
88
|
}
|
|
89
|
+
/** A module signal as `GET /definitions/signals` publishes it. */
|
|
90
|
+
export const PublishedSignalSchema = Schema.Struct({
|
|
91
|
+
namespace: Schema.String,
|
|
92
|
+
name: Schema.String,
|
|
93
|
+
description: Schema.optional(Schema.String),
|
|
94
|
+
/** JSON Schema derived from the signal's `input`. Omitted for no-arg signals. */
|
|
95
|
+
inputSchema: Schema.optional(JsonValueSchema),
|
|
96
|
+
});
|
|
97
|
+
export const SignalCatalogSchema = Schema.Struct({
|
|
98
|
+
signals: Schema.Array(PublishedSignalSchema),
|
|
99
|
+
});
|
|
100
|
+
export function publishSignal(namespace, name, definition) {
|
|
101
|
+
const published = { namespace, name };
|
|
102
|
+
if (definition.description !== undefined) {
|
|
103
|
+
published.description = definition.description;
|
|
104
|
+
}
|
|
105
|
+
const inputSchema = jsonSchemaOfInput(definition.input);
|
|
106
|
+
if (inputSchema !== undefined) {
|
|
107
|
+
published.inputSchema = inputSchema;
|
|
108
|
+
}
|
|
109
|
+
return published;
|
|
110
|
+
}
|
|
111
|
+
/** Declared signals across modules, sorted by namespace then name. */
|
|
112
|
+
export function publishSignals(modules) {
|
|
113
|
+
const signals = [];
|
|
114
|
+
for (const module of modules) {
|
|
115
|
+
for (const [name, candidate] of Object.entries(module.signals ?? {})) {
|
|
116
|
+
if (!isSignalDefinition(candidate)) {
|
|
117
|
+
throw new TypeError(`Module "${module.namespace}" signals.${name} is not a SignalDefinition`);
|
|
118
|
+
}
|
|
119
|
+
signals.push(publishSignal(module.namespace, name, candidate));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return signals.toSorted((left, right) => left.namespace.localeCompare(right.namespace) || left.name.localeCompare(right.name));
|
|
123
|
+
}
|
|
124
|
+
/** A catalog event as `GET /definitions/events` publishes it. */
|
|
125
|
+
export const PublishedEventSchema = Schema.Struct({
|
|
126
|
+
type: Schema.String,
|
|
127
|
+
namespace: Schema.String,
|
|
128
|
+
/** JSON Schema for the event payload, when the catalog entry has a runtime schema. */
|
|
129
|
+
payloadSchema: Schema.optional(JsonValueSchema),
|
|
130
|
+
});
|
|
131
|
+
export const EventTypeCatalogSchema = Schema.Struct({
|
|
132
|
+
events: Schema.Array(PublishedEventSchema),
|
|
133
|
+
});
|
|
134
|
+
function payloadSchemaOfEntry(entry) {
|
|
135
|
+
if (Predicate.isReadonlyObject(entry) && '~standard' in entry) {
|
|
136
|
+
// SAFETY: CatalogEntry with ~standard is a Standard Schema; jsonSchemaOfInput expects SchemaInput.
|
|
137
|
+
// oxlint-disable-next-line typescript/no-unsafe-type-assertion
|
|
138
|
+
return jsonSchemaOfInput(entry);
|
|
139
|
+
}
|
|
140
|
+
if (Schema.isSchema(entry)) {
|
|
141
|
+
// SAFETY: Schema.isSchema narrows CatalogEntry to an Effect Schema, which is a valid SchemaInput.
|
|
142
|
+
// oxlint-disable-next-line typescript/no-unsafe-type-assertion
|
|
143
|
+
return jsonSchemaOfInput(entry);
|
|
144
|
+
}
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
/** Catalog events across modules, sorted by type. */
|
|
148
|
+
export function publishEvents(modules) {
|
|
149
|
+
const events = [];
|
|
150
|
+
for (const module of modules) {
|
|
151
|
+
const catalog = module.events;
|
|
152
|
+
if (!catalog) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
for (const [key, entry] of Object.entries(catalog.entries)) {
|
|
156
|
+
const published = {
|
|
157
|
+
type: `${catalog.namespace}.${key}`,
|
|
158
|
+
namespace: catalog.namespace,
|
|
159
|
+
};
|
|
160
|
+
const payloadSchema = payloadSchemaOfEntry(entry);
|
|
161
|
+
if (payloadSchema !== undefined) {
|
|
162
|
+
published.payloadSchema = payloadSchema;
|
|
163
|
+
}
|
|
164
|
+
events.push(published);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return events.toSorted((left, right) => left.type.localeCompare(right.type));
|
|
168
|
+
}
|
|
73
169
|
/** A run as `GET /runs/summaries` lists it. */
|
|
74
170
|
export const RunSummarySchema = Schema.Struct({
|
|
75
171
|
runId: Schema.String,
|
|
@@ -14,6 +14,55 @@ export type RunAttributes = {
|
|
|
14
14
|
export type SecretContext = {
|
|
15
15
|
readonly [key: string]: string;
|
|
16
16
|
};
|
|
17
|
+
/** One declared run attribute. A replica stores each declared attribute in its own column. */
|
|
18
|
+
export interface RunAttributeField {
|
|
19
|
+
/** A start without this attribute is rejected. */
|
|
20
|
+
readonly required?: boolean;
|
|
21
|
+
/** Index the replica column. */
|
|
22
|
+
readonly index?: boolean;
|
|
23
|
+
/** Replica column name. Defaults to the key in snake_case. */
|
|
24
|
+
readonly fieldName?: string;
|
|
25
|
+
}
|
|
26
|
+
/** Declared run attributes, keyed by attribute name. */
|
|
27
|
+
export type RunAttributeFields = {
|
|
28
|
+
readonly [name: string]: RunAttributeField;
|
|
29
|
+
};
|
|
30
|
+
type RequiredAttributeKeys<Fields extends RunAttributeFields> = {
|
|
31
|
+
[Key in keyof Fields & string]: Fields[Key] extends {
|
|
32
|
+
readonly required: true;
|
|
33
|
+
} ? Key : never;
|
|
34
|
+
}[keyof Fields & string];
|
|
35
|
+
/**
|
|
36
|
+
* The `attributes` a start accepts. Without a declaration this is any string map.
|
|
37
|
+
* With one, only declared keys are allowed and `required` keys must be present.
|
|
38
|
+
*/
|
|
39
|
+
export type RunAttributesInput<Fields extends RunAttributeFields = RunAttributeFields> = string extends keyof Fields ? RunAttributes : {
|
|
40
|
+
readonly [Key in RequiredAttributeKeys<Fields>]: string;
|
|
41
|
+
} & {
|
|
42
|
+
readonly [Key in Exclude<keyof Fields & string, RequiredAttributeKeys<Fields>>]?: string;
|
|
43
|
+
};
|
|
44
|
+
export type HasRequiredAttributes<Fields extends RunAttributeFields> = [
|
|
45
|
+
RequiredAttributeKeys<Fields>
|
|
46
|
+
] extends [never] ? false : true;
|
|
47
|
+
/** `{ attributes }` for a start: required when a declared attribute is. */
|
|
48
|
+
export type RunAttributesOption<Fields extends RunAttributeFields = RunAttributeFields> = HasRequiredAttributes<Fields> extends true ? {
|
|
49
|
+
readonly attributes: RunAttributesInput<Fields>;
|
|
50
|
+
} : {
|
|
51
|
+
readonly attributes?: RunAttributesInput<Fields>;
|
|
52
|
+
};
|
|
53
|
+
/** Declare run attributes once and pass the result to the runtime, the replica, and the client. */
|
|
54
|
+
export declare function defineRunAttributes<const Fields extends RunAttributeFields>(fields: Fields): Fields;
|
|
55
|
+
declare const InvalidRunAttributesError_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 & {
|
|
56
|
+
readonly _tag: "InvalidRunAttributesError";
|
|
57
|
+
} & Readonly<A>;
|
|
58
|
+
export declare class InvalidRunAttributesError extends InvalidRunAttributesError_base<{
|
|
59
|
+
readonly message: string;
|
|
60
|
+
readonly issues: readonly string[];
|
|
61
|
+
}> {
|
|
62
|
+
constructor(issues: readonly string[]);
|
|
63
|
+
}
|
|
64
|
+
/** Missing required and undeclared attributes, in declaration order then input order. */
|
|
65
|
+
export declare function runAttributeIssues(fields: RunAttributeFields, attributes: RunAttributes): readonly string[];
|
|
17
66
|
export declare const RunAttributesSchema: Schema.$Record<Schema.String, Schema.String>;
|
|
18
67
|
export declare const SecretContextSchema: Schema.$Record<Schema.String, Schema.String>;
|
|
19
68
|
export interface RunSecretStore {
|
|
@@ -31,3 +80,4 @@ export declare function sameStringRecord(left: {
|
|
|
31
80
|
/** Reads a string map from an event payload. Anything else becomes an empty map. */
|
|
32
81
|
export declare function readAttributes(value: JsonValue | undefined): RunAttributes;
|
|
33
82
|
export declare function readSecretContext(value: JsonValue): SecretContext;
|
|
83
|
+
export {};
|
package/dist/core/run-context.js
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
|
-
import { Option, Schema } from 'effect';
|
|
1
|
+
import { Data, Option, Schema } from 'effect';
|
|
2
|
+
/** Declare run attributes once and pass the result to the runtime, the replica, and the client. */
|
|
3
|
+
export function defineRunAttributes(fields) {
|
|
4
|
+
return fields;
|
|
5
|
+
}
|
|
6
|
+
export class InvalidRunAttributesError extends Data.TaggedError('InvalidRunAttributesError') {
|
|
7
|
+
constructor(issues) {
|
|
8
|
+
super({ message: `Invalid run attributes: ${issues.join('; ')}`, issues });
|
|
9
|
+
this.name = 'InvalidRunAttributesError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/** Missing required and undeclared attributes, in declaration order then input order. */
|
|
13
|
+
export function runAttributeIssues(fields, attributes) {
|
|
14
|
+
const missing = Object.entries(fields)
|
|
15
|
+
.filter(([name, field]) => field.required === true && attributes[name] === undefined)
|
|
16
|
+
.map(([name]) => `"${name}" is required`);
|
|
17
|
+
const undeclared = Object.keys(attributes)
|
|
18
|
+
.filter((name) => !Object.hasOwn(fields, name))
|
|
19
|
+
.map((name) => `"${name}" is not a declared attribute`);
|
|
20
|
+
return [...missing, ...undeclared];
|
|
21
|
+
}
|
|
2
22
|
export const RunAttributesSchema = Schema.Record(Schema.String, Schema.String);
|
|
3
23
|
export const SecretContextSchema = Schema.Record(Schema.String, Schema.String);
|
|
4
24
|
const decodeAttributes = Schema.decodeUnknownOption(RunAttributesSchema);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import type { EventInput } from './envelope';
|
|
3
|
+
import type { AnyRuntimeModule } from './module';
|
|
4
|
+
import { type InferDefinedSchema, type InvalidInputError, type SchemaInput } from './schema';
|
|
5
|
+
import { type JsonValue } from './types';
|
|
6
|
+
declare const signalBrand: unique symbol;
|
|
7
|
+
/** Options for a signal call. `threadId` stamps events that do not already set one. */
|
|
8
|
+
export interface SignalOptions {
|
|
9
|
+
readonly threadId?: string;
|
|
10
|
+
}
|
|
11
|
+
type SignalResult = EventInput | readonly EventInput[];
|
|
12
|
+
/**
|
|
13
|
+
* A named, schema-backed event builder. Callable as `(input, options?) => events`.
|
|
14
|
+
* When `input` is omitted on the definition, the first argument is options: `pause()` or
|
|
15
|
+
* `stopAgentTurn({ threadId })`.
|
|
16
|
+
*/
|
|
17
|
+
export type SignalDefinition<TInput = JsonValue | undefined, E extends SignalResult = EventInput> = {
|
|
18
|
+
readonly description?: string;
|
|
19
|
+
readonly input?: SchemaInput;
|
|
20
|
+
readonly [signalBrand]: true;
|
|
21
|
+
} & ([TInput] extends [undefined] ? {
|
|
22
|
+
(options?: SignalOptions): E;
|
|
23
|
+
} : {
|
|
24
|
+
(input: TInput, options?: SignalOptions): E;
|
|
25
|
+
});
|
|
26
|
+
/** Erased signal shape for registries, publishing, and `findSignal`. */
|
|
27
|
+
export type AnySignalDefinition = {
|
|
28
|
+
readonly description?: string;
|
|
29
|
+
readonly input?: SchemaInput;
|
|
30
|
+
readonly [signalBrand]: true;
|
|
31
|
+
(...args: any[]): SignalResult;
|
|
32
|
+
};
|
|
33
|
+
export declare function isSignalDefinition(value: unknown): value is AnySignalDefinition;
|
|
34
|
+
/** Stamp `threadId` onto events that do not already set one. Preserves single vs batch shape. */
|
|
35
|
+
export declare function stampSignalThread(built: SignalResult, threadId: string | undefined): SignalResult;
|
|
36
|
+
interface DefineSignalInput<TSchema, E extends SignalResult> {
|
|
37
|
+
readonly description?: string;
|
|
38
|
+
readonly input?: TSchema;
|
|
39
|
+
readonly build: (input: InferDefinedSchema<TSchema, undefined>) => E;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Low-level signal constructor. Inside a module, prefer `m.signal` / `scope.signal`, which type
|
|
43
|
+
* built events against the module's catalogs. `defineModule` also rejects foreign signals the
|
|
44
|
+
* same way it rejects foreign effects.
|
|
45
|
+
*/
|
|
46
|
+
export declare function defineSignal<TSchema extends SchemaInput | undefined = undefined, E extends SignalResult = EventInput>(def: DefineSignalInput<TSchema, E>): SignalDefinition<InferDefinedSchema<TSchema, undefined>, E>;
|
|
47
|
+
/** Look up a signal by module namespace and member key. */
|
|
48
|
+
export declare function findSignal(modules: readonly AnyRuntimeModule[], namespace: string, name: string): AnySignalDefinition | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Validate `rawInput` against the signal's schema and invoke the callable (which stamps
|
|
51
|
+
* `threadId`). Returns the events that `runtime.signal` would append.
|
|
52
|
+
*/
|
|
53
|
+
export declare function runSignal(definition: AnySignalDefinition, rawInput: JsonValue, threadId?: string): Effect.Effect<EventInput[], InvalidInputError>;
|
|
54
|
+
/** Sync form of {@link runSignal}. Throws {@link InvalidInputError} on bad input. */
|
|
55
|
+
export declare function runSignalSync(definition: AnySignalDefinition, rawInput: JsonValue, threadId?: string): EventInput[];
|
|
56
|
+
export {};
|