@eduardorenani/atlasjs 0.1.0-alpha.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/LICENSE +201 -0
- package/README.md +113 -0
- package/dist/actorName.d.ts +2 -0
- package/dist/actorName.d.ts.map +1 -0
- package/dist/actorName.js +24 -0
- package/dist/actorName.js.map +1 -0
- package/dist/buildActions.d.ts +11 -0
- package/dist/buildActions.d.ts.map +1 -0
- package/dist/buildActions.js +23 -0
- package/dist/buildActions.js.map +1 -0
- package/dist/buildActiveState.d.ts +43 -0
- package/dist/buildActiveState.d.ts.map +1 -0
- package/dist/buildActiveState.js +194 -0
- package/dist/buildActiveState.js.map +1 -0
- package/dist/buildActors.d.ts +4 -0
- package/dist/buildActors.d.ts.map +1 -0
- package/dist/buildActors.js +40 -0
- package/dist/buildActors.js.map +1 -0
- package/dist/buildPassiveState.d.ts +19 -0
- package/dist/buildPassiveState.d.ts.map +1 -0
- package/dist/buildPassiveState.js +59 -0
- package/dist/buildPassiveState.js.map +1 -0
- package/dist/compile.d.ts +6 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +164 -0
- package/dist/compile.js.map +1 -0
- package/dist/contextLift.d.ts +35 -0
- package/dist/contextLift.d.ts.map +1 -0
- package/dist/contextLift.js +172 -0
- package/dist/contextLift.js.map +1 -0
- package/dist/defineAgent.d.ts +60 -0
- package/dist/defineAgent.d.ts.map +1 -0
- package/dist/defineAgent.js +79 -0
- package/dist/defineAgent.js.map +1 -0
- package/dist/defineCompoundMode.d.ts +77 -0
- package/dist/defineCompoundMode.d.ts.map +1 -0
- package/dist/defineCompoundMode.js +79 -0
- package/dist/defineCompoundMode.js.map +1 -0
- package/dist/defineMode.d.ts +89 -0
- package/dist/defineMode.d.ts.map +1 -0
- package/dist/defineMode.js +95 -0
- package/dist/defineMode.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/injectEnd.d.ts +10 -0
- package/dist/injectEnd.d.ts.map +1 -0
- package/dist/injectEnd.js +106 -0
- package/dist/injectEnd.js.map +1 -0
- package/dist/types.d.ts +539 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +51 -0
- package/dist/types.js.map +1 -0
- package/dist/validateRoutes.d.ts +2 -0
- package/dist/validateRoutes.d.ts.map +1 -0
- package/dist/validateRoutes.js +107 -0
- package/dist/validateRoutes.js.map +1 -0
- package/dist/validateTargets.d.ts +2 -0
- package/dist/validateTargets.d.ts.map +1 -0
- package/dist/validateTargets.js +132 -0
- package/dist/validateTargets.js.map +1 -0
- package/dist/walk.d.ts +20 -0
- package/dist/walk.d.ts.map +1 -0
- package/dist/walk.js +35 -0
- package/dist/walk.js.map +1 -0
- package/package.json +63 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The primitive leaves that survive a `JSON.stringify` / `JSON.parse` round
|
|
3
|
+
* trip without lossy encoding. `undefined` is admitted so optional fields
|
|
4
|
+
* (`field?: T` → `T | undefined`) typecheck; at runtime `JSON.stringify`
|
|
5
|
+
* silently drops keys whose value is `undefined`, which matches what every
|
|
6
|
+
* persistence layer round-trips and avoids forcing `T | null` boilerplate.
|
|
7
|
+
*/
|
|
8
|
+
export type JsonPrimitive = string | number | boolean | null | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Any JSON-compatible value: a primitive, an array of JSON values, or an
|
|
11
|
+
* object whose values are JSON values. Exported as a building block for users
|
|
12
|
+
* who want an open index-signature shape (e.g. `meta: JsonObject`).
|
|
13
|
+
*/
|
|
14
|
+
export type JsonValue = JsonPrimitive | JsonValue[] | {
|
|
15
|
+
[k: string]: JsonValue;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* An open object whose values are `JsonValue`. Useful inside `TContext` when
|
|
19
|
+
* the user wants a discriminated bag of arbitrary serializable telemetry.
|
|
20
|
+
*/
|
|
21
|
+
export type JsonObject = {
|
|
22
|
+
[k: string]: JsonValue;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* An array of JSON values.
|
|
26
|
+
*/
|
|
27
|
+
export type JsonArray = JsonValue[];
|
|
28
|
+
/**
|
|
29
|
+
* Recursive structural constraint — walks `T` and forces every leaf to be a
|
|
30
|
+
* `JsonPrimitive`. Used at parameter-position rather than as a generic bound
|
|
31
|
+
* (a `T extends JsonCompatible<T>` bound trips TypeScript's circular-
|
|
32
|
+
* constraint detector). The wrapper applies it at the user-facing fields
|
|
33
|
+
* that *receive* the data — `AgentConfig.context` and `CompoundContext.local`:
|
|
34
|
+
*
|
|
35
|
+
* context: JsonCompatible<TContext>
|
|
36
|
+
*
|
|
37
|
+
* For a JSON-compatible `T`, `JsonCompatible<T>` is structurally equal to
|
|
38
|
+
* `T`; the user's literal type-checks unchanged. For a `T` carrying a `Date`,
|
|
39
|
+
* `Map`, function, etc., `JsonCompatible<T>` substitutes `never` at the
|
|
40
|
+
* offending position — the user's literal then fails to assign with a
|
|
41
|
+
* pinpoint error (`Type 'Date' is not assignable to type 'never'`).
|
|
42
|
+
*
|
|
43
|
+
* Distinct from `T extends JsonObject` because TypeScript does not treat a
|
|
44
|
+
* closed object type (no index signature) as structurally assignable to
|
|
45
|
+
* `{ [k: string]: JsonValue }`. Walking the declared shape directly lets
|
|
46
|
+
* `{ messages: Message[] }` and
|
|
47
|
+
* `interface AgentContext { messages: Message[] }` both pass.
|
|
48
|
+
*
|
|
49
|
+
* Rejected at compile time: `bigint`, `Date`, `Map`, `Set`, functions,
|
|
50
|
+
* symbols, and any object or class type whose declared shape includes
|
|
51
|
+
* methods/getters/setters (those members map through the function branch).
|
|
52
|
+
* Data-only classes pass — the type system cannot distinguish them from
|
|
53
|
+
* plain object literals, and `JSON.stringify` round-trips them identically.
|
|
54
|
+
*/
|
|
55
|
+
export type JsonCompatible<T> = T extends JsonPrimitive ? T : T extends ReadonlyArray<infer U> ? ReadonlyArray<JsonCompatible<U>> : T extends ReadonlyMap<unknown, unknown> | ReadonlySet<unknown> ? never : T extends (...args: never[]) => unknown ? never : T extends object ? {
|
|
56
|
+
[K in keyof T]: JsonCompatible<T[K]>;
|
|
57
|
+
} : never;
|
|
58
|
+
/**
|
|
59
|
+
* The three intentional outcomes a Mode's `behavior` can return:
|
|
60
|
+
*
|
|
61
|
+
* - **`"achieved"`** — the Mode's work succeeded. Dispatch via `routes.achieved`.
|
|
62
|
+
* - **`"retry"`** — the Mode should run again on the same state (self-loop).
|
|
63
|
+
* Dispatch via `routes.retry`.
|
|
64
|
+
* - **`"abandoned"`** — the Mode's work failed in an *expected* way (give up,
|
|
65
|
+
* not crash). Dispatch via `routes.abandoned`.
|
|
66
|
+
*
|
|
67
|
+
* A fourth outcome (`error`) exists, but it is **synthesized by the wrapper**
|
|
68
|
+
* when `behavior` rejects — users never return it, and it is intentionally
|
|
69
|
+
* absent from this union.
|
|
70
|
+
*/
|
|
71
|
+
export type Outcome = "achieved" | "retry" | "abandoned";
|
|
72
|
+
/**
|
|
73
|
+
* The return type of an active Mode's `behavior`. The wrapper inspects
|
|
74
|
+
* `outcome` to pick the right route bucket and threads `payload` into the
|
|
75
|
+
* matched route's `when` / `assign` callbacks.
|
|
76
|
+
*
|
|
77
|
+
* @template TPayload Shape of the payload. Constrains the inputs of all
|
|
78
|
+
* `routes.*.when` and `routes.*.assign` callbacks on the
|
|
79
|
+
* same Mode, so payload-driven dispatch stays type-safe.
|
|
80
|
+
*/
|
|
81
|
+
export type ModeOutput<TPayload = unknown> = {
|
|
82
|
+
outcome: Outcome;
|
|
83
|
+
payload: TPayload;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* `END` — the only way for a route to leave a `CompoundMode`. Implemented as
|
|
87
|
+
* a unique symbol so it cannot collide with state names (DD-015).
|
|
88
|
+
*
|
|
89
|
+
* Use as a `target` on `achieved` / `abandoned` route entries when you want
|
|
90
|
+
* the enclosing compound's `onDone` transition to fire.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* routes: {
|
|
95
|
+
* achieved: { target: END }, // leave the compound on success
|
|
96
|
+
* retry: [],
|
|
97
|
+
* abandoned: { target: END }, // leave the compound on giving up
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export declare const END: unique symbol;
|
|
102
|
+
export type END = typeof END;
|
|
103
|
+
/**
|
|
104
|
+
* `RE_THROW` — an error-only `target` that re-propagates the caught rejection
|
|
105
|
+
* above the actor instead of transitioning. Lets `routes.error` filter out
|
|
106
|
+
* programmer errors (TypeError, etc.) without putting `throw` inside `assign`.
|
|
107
|
+
*
|
|
108
|
+
* Valid **only** on `ErrorEntry.target`. Using it on `achieved` / `abandoned`
|
|
109
|
+
* entries is a compile error.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* routes: {
|
|
114
|
+
* error: [
|
|
115
|
+
* { when: (e) => e instanceof TypeError, target: RE_THROW },
|
|
116
|
+
* { target: "fallback" },
|
|
117
|
+
* ],
|
|
118
|
+
* }
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export declare const RE_THROW: unique symbol;
|
|
122
|
+
export type RE_THROW = typeof RE_THROW;
|
|
123
|
+
/**
|
|
124
|
+
* Target type for `achieved` / `abandoned` entries — a sibling state name or
|
|
125
|
+
* `END`. The `string` half names a sibling in the **immediate enclosing**
|
|
126
|
+
* `modes` map; dotted paths, XState absolute paths (`#agent.foo`), and
|
|
127
|
+
* descendant paths are NOT accepted (DD-016 / spec §"Target resolution").
|
|
128
|
+
*
|
|
129
|
+
* The type stays plain `string` because a Mode doesn't know its enclosing
|
|
130
|
+
* siblings at definition time — the wrapper's compile step validates against
|
|
131
|
+
* the actual sibling set and throws on machine creation.
|
|
132
|
+
*/
|
|
133
|
+
export type RouteTarget = string | END;
|
|
134
|
+
/**
|
|
135
|
+
* Target type for `error` entries — additionally accepts `RE_THROW`, which
|
|
136
|
+
* re-propagates the caught rejection above the actor instead of transitioning.
|
|
137
|
+
*/
|
|
138
|
+
export type ErrorRouteTarget = string | END | RE_THROW;
|
|
139
|
+
/**
|
|
140
|
+
* A single entry in `routes.achieved` or `routes.abandoned`. Carries a
|
|
141
|
+
* required `target` and optional `when` / `assign`.
|
|
142
|
+
*
|
|
143
|
+
* - `when(payload)` — guard. Deps-free by design: routing decisions that need
|
|
144
|
+
* a dependency belong in `behavior`, not the routing layer (spec 005
|
|
145
|
+
* §Routes / EventHandlers).
|
|
146
|
+
* - `target` — the destination state (sibling name or `END`).
|
|
147
|
+
* - `assign({ context, payload, deps })` — return a `Partial<TContext>` to merge
|
|
148
|
+
* into context before the transition fires.
|
|
149
|
+
*
|
|
150
|
+
* @template TContext Context shape visible to `assign`. Constrained to
|
|
151
|
+
* `JsonCompatible<TContext>` for storage round-trip.
|
|
152
|
+
* @template TPayload Payload shape from `ModeOutput<TPayload>`.
|
|
153
|
+
* @template TDeps Frozen container of external resources, forwarded
|
|
154
|
+
* verbatim from `defineAgent.deps`.
|
|
155
|
+
*/
|
|
156
|
+
export type ExitEntry<TContext, TPayload, TDeps extends Record<string, unknown> = Record<string, never>> = {
|
|
157
|
+
when?: (payload: TPayload) => boolean;
|
|
158
|
+
target: RouteTarget;
|
|
159
|
+
assign?: (args: {
|
|
160
|
+
context: TContext;
|
|
161
|
+
payload: TPayload;
|
|
162
|
+
deps: TDeps;
|
|
163
|
+
}) => Partial<TContext>;
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* A single entry in `routes.retry`. **Has no `target`** — retry is always a
|
|
167
|
+
* structural self-loop on the same Mode (DD-014). Supplying `target` here is
|
|
168
|
+
* a compile error.
|
|
169
|
+
*
|
|
170
|
+
* - `when(payload)` — guard. Deps-free.
|
|
171
|
+
* - `assign({ context, payload, deps })` — return a `Partial<TContext>` to merge
|
|
172
|
+
* into context before the self-transition fires.
|
|
173
|
+
*
|
|
174
|
+
* @template TContext Context shape visible to `assign`.
|
|
175
|
+
* @template TPayload Payload shape from `ModeOutput<TPayload>`.
|
|
176
|
+
* @template TDeps Frozen deps container.
|
|
177
|
+
*/
|
|
178
|
+
export type RetryEntry<TContext, TPayload, TDeps extends Record<string, unknown> = Record<string, never>> = {
|
|
179
|
+
when?: (payload: TPayload) => boolean;
|
|
180
|
+
assign?: (args: {
|
|
181
|
+
context: TContext;
|
|
182
|
+
payload: TPayload;
|
|
183
|
+
deps: TDeps;
|
|
184
|
+
}) => Partial<TContext>;
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* A single entry in `routes.error`. Fired when `behavior` throws or its
|
|
188
|
+
* Promise rejects. The wrapper catches the rejection, synthesizes the
|
|
189
|
+
* outcome, and routes through these entries. `when` and `assign` receive the
|
|
190
|
+
* **raw error**, not a payload.
|
|
191
|
+
*
|
|
192
|
+
* Setting `target: RE_THROW` re-propagates the caught error above the actor;
|
|
193
|
+
* `assign` is ignored on RE_THROW entries (re-throwing is the side effect).
|
|
194
|
+
*
|
|
195
|
+
* @template TContext Context shape visible to `assign`.
|
|
196
|
+
* @template TDeps Frozen deps container.
|
|
197
|
+
*/
|
|
198
|
+
export type ErrorEntry<TContext, TDeps extends Record<string, unknown> = Record<string, never>> = {
|
|
199
|
+
when?: (error: unknown) => boolean;
|
|
200
|
+
target: ErrorRouteTarget;
|
|
201
|
+
assign?: (args: {
|
|
202
|
+
context: TContext;
|
|
203
|
+
error: unknown;
|
|
204
|
+
deps: TDeps;
|
|
205
|
+
}) => Partial<TContext>;
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* Helper: take an entry type `E` and **require** its `when` field.
|
|
209
|
+
* Used by `RouteList` to enforce that every non-last entry carries a guard.
|
|
210
|
+
*
|
|
211
|
+
* @template E An entry type (`ExitEntry` / `RetryEntry` / `ErrorEntry`) whose
|
|
212
|
+
* `when` is optional.
|
|
213
|
+
*/
|
|
214
|
+
export type WithWhen<E> = E extends {
|
|
215
|
+
when?: infer W;
|
|
216
|
+
} ? Omit<E, "when"> & {
|
|
217
|
+
when: NonNullable<W>;
|
|
218
|
+
} : E;
|
|
219
|
+
/**
|
|
220
|
+
* Helper: take an entry type `E` and **strip** its `when` field. Used by
|
|
221
|
+
* `RouteList` for the trailing default entry — its `when` must not be
|
|
222
|
+
* present, even as `undefined`.
|
|
223
|
+
*
|
|
224
|
+
* @template E An entry type whose `when` should be removed.
|
|
225
|
+
*/
|
|
226
|
+
export type NoWhen<E> = Omit<E, "when">;
|
|
227
|
+
/**
|
|
228
|
+
* Encodes the array-form rule "**first match wins, last entry is the
|
|
229
|
+
* default**" at the type level. Non-last entries are required to carry
|
|
230
|
+
* `when`; the last entry must omit it. This makes the misplacement of
|
|
231
|
+
* `when` (an unguarded entry shadowing later entries — dead code at runtime)
|
|
232
|
+
* a compile error rather than a silent routing bug.
|
|
233
|
+
*
|
|
234
|
+
* Two valid shapes:
|
|
235
|
+
* - Single-entry: just the default — `readonly [NoWhen<E>]`.
|
|
236
|
+
* - Multi-entry: one or more guarded entries followed by the default.
|
|
237
|
+
*
|
|
238
|
+
* `readonly []` is unrepresentable here — the type system rejects it for
|
|
239
|
+
* `achieved` / `abandoned` / `error`. `retry` permits `readonly []`
|
|
240
|
+
* separately as the "no special handling" shorthand.
|
|
241
|
+
*
|
|
242
|
+
* @template E The entry type (`ExitEntry` / `RetryEntry` / `ErrorEntry`).
|
|
243
|
+
*/
|
|
244
|
+
export type RouteList<E> = readonly [NoWhen<E>] | readonly [WithWhen<E>, ...readonly WithWhen<E>[], NoWhen<E>];
|
|
245
|
+
/**
|
|
246
|
+
* The full route table for an active Mode — one bucket per `Outcome`, plus an
|
|
247
|
+
* optional `error` bucket for synthesized errors.
|
|
248
|
+
*
|
|
249
|
+
* - **`achieved`** (required) — fired when `behavior` returns `outcome: "achieved"`.
|
|
250
|
+
* - **`retry`** (required) — fired when `behavior` returns `outcome: "retry"`.
|
|
251
|
+
* Pass `readonly []` for "no special handling" (the wrapper just re-enters
|
|
252
|
+
* the same Mode).
|
|
253
|
+
* - **`abandoned`** (required) — fired when `behavior` returns `outcome: "abandoned"`.
|
|
254
|
+
* - **`error`** (optional) — fired when `behavior` throws / its Promise
|
|
255
|
+
* rejects. **When omitted, the wrapper re-throws the rejection above the
|
|
256
|
+
* actor.** This is the only safe default — silently swallowing failures is
|
|
257
|
+
* not allowed.
|
|
258
|
+
*
|
|
259
|
+
* Each bucket accepts either a single entry or a `RouteList` (first-match-wins
|
|
260
|
+
* array). See `RouteList` for the array-form rules.
|
|
261
|
+
*
|
|
262
|
+
* @template TContext Context shape visible to `when` / `assign` callbacks.
|
|
263
|
+
* @template TPayload Payload type returned by `behavior`.
|
|
264
|
+
* @template TDeps Frozen deps container, forwarded to every `assign`.
|
|
265
|
+
*/
|
|
266
|
+
export type Routes<TContext, TPayload, TDeps extends Record<string, unknown> = Record<string, never>> = {
|
|
267
|
+
achieved: ExitEntry<TContext, TPayload, TDeps> | RouteList<ExitEntry<TContext, TPayload, TDeps>>;
|
|
268
|
+
retry: RetryEntry<TContext, TPayload, TDeps> | readonly [] | RouteList<RetryEntry<TContext, TPayload, TDeps>>;
|
|
269
|
+
abandoned: ExitEntry<TContext, TPayload, TDeps> | RouteList<ExitEntry<TContext, TPayload, TDeps>>;
|
|
270
|
+
error?: ErrorEntry<TContext, TDeps> | RouteList<ErrorEntry<TContext, TDeps>>;
|
|
271
|
+
};
|
|
272
|
+
/**
|
|
273
|
+
* A single passive transition. Fired when the matching event arrives while
|
|
274
|
+
* the Mode is active. For array-form handlers, first match wins (XState
|
|
275
|
+
* semantics).
|
|
276
|
+
*
|
|
277
|
+
* - `target` — sibling name or `END`. Passive Modes CAN leave a compound on
|
|
278
|
+
* a particular event.
|
|
279
|
+
* - `actions` — a name (or list of names) referencing entries declared in
|
|
280
|
+
* `defineAgent.actions`. **Inline callbacks are NOT accepted here** —
|
|
281
|
+
* that would re-introduce DD-004 churn.
|
|
282
|
+
* - `guard({ context, event, deps })` — optional. The transition only fires
|
|
283
|
+
* when it returns true. `guard` already had access to mutable context;
|
|
284
|
+
* adding `deps` does not change what the callback can observe.
|
|
285
|
+
*
|
|
286
|
+
* @template TContext Context shape visible to `guard`.
|
|
287
|
+
* @template TEventVariant The specific event variant this transition handles
|
|
288
|
+
* (narrowed from `TEvents` by the discriminant key).
|
|
289
|
+
* @template TDeps Frozen deps container.
|
|
290
|
+
*/
|
|
291
|
+
export type EventTransition<TContext, TEventVariant, TDeps extends Record<string, unknown> = Record<string, never>> = {
|
|
292
|
+
target?: RouteTarget;
|
|
293
|
+
actions?: string | readonly string[];
|
|
294
|
+
guard?: (args: {
|
|
295
|
+
context: TContext;
|
|
296
|
+
event: TEventVariant;
|
|
297
|
+
deps: TDeps;
|
|
298
|
+
}) => boolean;
|
|
299
|
+
};
|
|
300
|
+
/**
|
|
301
|
+
* The full `on` map for a passive Mode. Keys are event discriminants
|
|
302
|
+
* (`event.type`); values are one transition or an ordered list of them. The
|
|
303
|
+
* transition's `event` callback argument is automatically narrowed to the
|
|
304
|
+
* matching event variant via `Extract<TEvents, { type: K }>`.
|
|
305
|
+
*
|
|
306
|
+
* @template TContext Context shape visible to `guard`.
|
|
307
|
+
* @template TEvents The agent's full event union (each variant has a `type`).
|
|
308
|
+
* @template TDeps Frozen deps container.
|
|
309
|
+
*/
|
|
310
|
+
export type EventHandlers<TContext, TEvents extends {
|
|
311
|
+
type: string;
|
|
312
|
+
}, TDeps extends Record<string, unknown> = Record<string, never>> = {
|
|
313
|
+
[K in TEvents["type"]]?: EventTransition<TContext, Extract<TEvents, {
|
|
314
|
+
type: K;
|
|
315
|
+
}>, TDeps> | readonly EventTransition<TContext, Extract<TEvents, {
|
|
316
|
+
type: K;
|
|
317
|
+
}>, TDeps>[];
|
|
318
|
+
};
|
|
319
|
+
/**
|
|
320
|
+
* Active Mode shape — runs an async `behavior` and dispatches on its
|
|
321
|
+
* `ModeOutput`. Mutually exclusive with `PassiveModeConfig`; mixing
|
|
322
|
+
* `behavior` and `on` in the same config is a compile error (DD-019).
|
|
323
|
+
*
|
|
324
|
+
* @template TContext Context shape visible to `input` / `routes.*.assign`.
|
|
325
|
+
* @template TEvents Phantom — kept for symmetry with the passive variant.
|
|
326
|
+
* Active Modes don't observe events directly.
|
|
327
|
+
* @template TPayload Payload type returned by `behavior` and threaded into
|
|
328
|
+
* `routes.*.when` / `routes.*.assign`.
|
|
329
|
+
* @template TDeps Frozen deps container, available in `input` / `behavior`
|
|
330
|
+
* / every `routes.*.assign`.
|
|
331
|
+
*/
|
|
332
|
+
export type ActiveModeConfig<TContext, TEvents extends {
|
|
333
|
+
type: string;
|
|
334
|
+
}, TPayload, TDeps extends Record<string, unknown> = Record<string, never>> = {
|
|
335
|
+
input: (args: {
|
|
336
|
+
context: TContext;
|
|
337
|
+
deps: TDeps;
|
|
338
|
+
}) => unknown;
|
|
339
|
+
behavior: (args: {
|
|
340
|
+
input: unknown;
|
|
341
|
+
deps: TDeps;
|
|
342
|
+
}) => Promise<ModeOutput<TPayload>>;
|
|
343
|
+
routes: Routes<TContext, TPayload, TDeps>;
|
|
344
|
+
};
|
|
345
|
+
/**
|
|
346
|
+
* Passive Mode shape — waits for external events. Mutually exclusive with
|
|
347
|
+
* `ActiveModeConfig`.
|
|
348
|
+
*
|
|
349
|
+
* @template TContext Context shape visible to `on[event].guard`.
|
|
350
|
+
* @template TEvents The agent's full event union.
|
|
351
|
+
* @template TDeps Frozen deps container, forwarded to every `on[*].guard`.
|
|
352
|
+
*/
|
|
353
|
+
export type PassiveModeConfig<TContext, TEvents extends {
|
|
354
|
+
type: string;
|
|
355
|
+
}, TDeps extends Record<string, unknown> = Record<string, never>> = {
|
|
356
|
+
on: EventHandlers<TContext, TEvents, TDeps>;
|
|
357
|
+
};
|
|
358
|
+
/**
|
|
359
|
+
* The discriminated union of Mode config shapes. TypeScript picks the variant
|
|
360
|
+
* structurally — by which keys you supply.
|
|
361
|
+
*
|
|
362
|
+
* @template TContext Context shape this Mode observes.
|
|
363
|
+
* @template TEvents The agent's full event union.
|
|
364
|
+
* @template TPayload Payload type for the active variant. Ignored by passive.
|
|
365
|
+
* @template TDeps Frozen deps container.
|
|
366
|
+
*/
|
|
367
|
+
export type ModeConfig<TContext, TEvents extends {
|
|
368
|
+
type: string;
|
|
369
|
+
}, TPayload, TDeps extends Record<string, unknown> = Record<string, never>> = ActiveModeConfig<TContext, TEvents, TPayload, TDeps> | PassiveModeConfig<TContext, TEvents, TDeps>;
|
|
370
|
+
declare const __modeBrand: unique symbol;
|
|
371
|
+
declare const __compoundBrand: unique symbol;
|
|
372
|
+
/**
|
|
373
|
+
* Opaque brand returned by `defineMode`. User code cannot inspect the
|
|
374
|
+
* inside — the brand exists only so that `modes` slots reject anything
|
|
375
|
+
* other than the output of `defineMode` / `defineCompoundMode`. The phantom
|
|
376
|
+
* `__phantomMode` field preserves the covariant generic parameters; the
|
|
377
|
+
* separate `__phantomDeps` field puts `TDeps` in function-argument position
|
|
378
|
+
* so the brand is **contravariant** in `TDeps`. That gives the slot-time
|
|
379
|
+
* variance check the right direction at no syntactic cost: a `Mode<…, A>`
|
|
380
|
+
* is assignable to `Mode<…, B>` iff `B` is assignable to `A` — i.e. "the
|
|
381
|
+
* agent provides at least every key the Mode asks for".
|
|
382
|
+
*
|
|
383
|
+
* @template TContext Context shape this Mode observes.
|
|
384
|
+
* @template TEvents The agent's full event union.
|
|
385
|
+
* @template TPayload Payload type returned by the active variant's `behavior`.
|
|
386
|
+
* @template TDeps Frozen deps container the Mode demands.
|
|
387
|
+
*/
|
|
388
|
+
export interface Mode<TContext, TEvents extends {
|
|
389
|
+
type: string;
|
|
390
|
+
}, TPayload = unknown, TDeps extends Record<string, unknown> = Record<string, never>> {
|
|
391
|
+
readonly [__modeBrand]: true;
|
|
392
|
+
readonly __phantomMode?: {
|
|
393
|
+
context: TContext;
|
|
394
|
+
events: TEvents;
|
|
395
|
+
payload: TPayload;
|
|
396
|
+
};
|
|
397
|
+
readonly __phantomDeps?: (deps: TDeps) => void;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Opaque brand returned by `defineCompoundMode`. Same split-brand
|
|
401
|
+
* contravariance for `TDeps` as `Mode`. User code cannot inspect the inside;
|
|
402
|
+
* the brand only exists to constrain what `modes` slots accept.
|
|
403
|
+
*
|
|
404
|
+
* @template TContext Context shape provided by the enclosing scope.
|
|
405
|
+
* @template TEvents The agent's full event union.
|
|
406
|
+
* @template TDeps Frozen deps container the compound demands.
|
|
407
|
+
*/
|
|
408
|
+
export interface CompoundMode<TContext, TEvents extends {
|
|
409
|
+
type: string;
|
|
410
|
+
}, TDeps extends Record<string, unknown> = Record<string, never>> {
|
|
411
|
+
readonly [__compoundBrand]: true;
|
|
412
|
+
readonly __phantomCompound?: {
|
|
413
|
+
context: TContext;
|
|
414
|
+
events: TEvents;
|
|
415
|
+
};
|
|
416
|
+
readonly __phantomDeps?: (deps: TDeps) => void;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* A `modes` map — used at the agent root and inside every `CompoundMode`.
|
|
420
|
+
* Each slot is a `Mode` (leaf) or a nested `CompoundMode`. **Raw XState
|
|
421
|
+
* configs are not accepted** — `defineMode` / `defineCompoundMode` are the
|
|
422
|
+
* only way in.
|
|
423
|
+
*
|
|
424
|
+
* `TDeps` flows through to every slot, so a single `TDeps` declared at
|
|
425
|
+
* `defineAgent` propagates down through every nested compound's slot map
|
|
426
|
+
* without manual threading at the slot type level.
|
|
427
|
+
*
|
|
428
|
+
* @template TContext Context shape visible to every slot in this map.
|
|
429
|
+
* @template TEvents The agent's full event union.
|
|
430
|
+
* @template TDeps Frozen deps container the enclosing scope provides.
|
|
431
|
+
*/
|
|
432
|
+
export type ModesMap<TContext, TEvents extends {
|
|
433
|
+
type: string;
|
|
434
|
+
}, TDeps extends Record<string, unknown> = Record<string, never>> = Readonly<Record<string, Mode<TContext, TEvents, unknown, TDeps> | CompoundMode<TContext, TEvents, TDeps>>>;
|
|
435
|
+
/**
|
|
436
|
+
* Compound-local context declaration. Used as the optional `context` field on
|
|
437
|
+
* `CompoundModeConfig` to narrow what children see.
|
|
438
|
+
*
|
|
439
|
+
* - **`inherit`** — list of keys from the enclosing context that are
|
|
440
|
+
* **live-mirrored** into this compound. Keys NOT in `inherit` are invisible
|
|
441
|
+
* to children at the type level.
|
|
442
|
+
* - **`local`** — own variables declared at this compound. Initialized on
|
|
443
|
+
* entry and **reset on re-entry** (DD-018). Constrained to
|
|
444
|
+
* `JsonCompatible<TLocal>` because the slot is persisted as part of the
|
|
445
|
+
* root context.
|
|
446
|
+
*
|
|
447
|
+
* Children see `Pick<TParent, inherit[number]> & typeof local` as their
|
|
448
|
+
* context.
|
|
449
|
+
*
|
|
450
|
+
* @template TParent The enclosing context shape.
|
|
451
|
+
* @template TInherit A `readonly` tuple of string keys of `TParent`. Must be
|
|
452
|
+
* literal (e.g. `["messages"] as const`) so the element
|
|
453
|
+
* type is preserved exactly.
|
|
454
|
+
* @template TLocal The shape of declared local variables. Constrained to
|
|
455
|
+
* `JsonCompatible<TLocal>` so persisted snapshots remain
|
|
456
|
+
* JSON-safe.
|
|
457
|
+
*/
|
|
458
|
+
export type CompoundContext<TParent, TInherit extends ReadonlyArray<keyof TParent & string>, TLocal> = {
|
|
459
|
+
inherit: TInherit;
|
|
460
|
+
local: JsonCompatible<TLocal>;
|
|
461
|
+
};
|
|
462
|
+
/**
|
|
463
|
+
* Compute the effective context a compound's children see, given the
|
|
464
|
+
* enclosing `TParent` and the compound's `TCtx`. When `TCtx` is `undefined`
|
|
465
|
+
* the children see the full enclosing context (no narrowing, no locals).
|
|
466
|
+
*
|
|
467
|
+
* @template TParent The enclosing context shape.
|
|
468
|
+
* @template TCtx Either a `CompoundContext` literal or `undefined`.
|
|
469
|
+
*/
|
|
470
|
+
export type LocalContextOf<TParent, TCtx> = TCtx extends CompoundContext<TParent, infer I, infer L> ? Pick<TParent, I[number] & keyof TParent> & L : TParent;
|
|
471
|
+
/**
|
|
472
|
+
* The config passed to `defineCompoundMode`. `initial` is typed as
|
|
473
|
+
* `keyof TModes` so a typo here is a compile error. `onDone` is the parent-
|
|
474
|
+
* level transition target fired when any child routes to `END`; it accepts a
|
|
475
|
+
* sibling name OR `END` (when the compound itself is nested inside another).
|
|
476
|
+
*
|
|
477
|
+
* `context` is OPTIONAL. When present, children see only
|
|
478
|
+
* `Pick<TParentContext, inherit[number]> & typeof local`; when omitted they
|
|
479
|
+
* see the full `TParentContext`. See `defineCompoundMode` §"Lexical scoping".
|
|
480
|
+
*
|
|
481
|
+
* @template TParentContext Context shape the enclosing scope provides.
|
|
482
|
+
* @template TEvents The agent's full event union.
|
|
483
|
+
* @template TCtx Either a `CompoundContext` literal or `undefined`.
|
|
484
|
+
* @template TModes The compound's `modes` map, typed against the
|
|
485
|
+
* compound-local context view.
|
|
486
|
+
* @template TDeps Frozen deps container. Flows to every slot.
|
|
487
|
+
*/
|
|
488
|
+
export type CompoundModeConfig<TParentContext, TEvents extends {
|
|
489
|
+
type: string;
|
|
490
|
+
}, TCtx extends {
|
|
491
|
+
inherit: ReadonlyArray<keyof TParentContext & string>;
|
|
492
|
+
local: object;
|
|
493
|
+
} | undefined, TModes extends ModesMap<LocalContextOf<TParentContext, TCtx>, TEvents, TDeps>, TDeps extends Record<string, unknown> = Record<string, never>> = {
|
|
494
|
+
context?: TCtx;
|
|
495
|
+
initial: keyof TModes & string;
|
|
496
|
+
modes: TModes;
|
|
497
|
+
onDone: RouteTarget;
|
|
498
|
+
};
|
|
499
|
+
/**
|
|
500
|
+
* The config passed to `defineAgent`. The root of the entire Mode tree.
|
|
501
|
+
*
|
|
502
|
+
* - **`id`** — XState machine id.
|
|
503
|
+
* - **`initial`** — keyed against `TModes`; typo = compile error.
|
|
504
|
+
* - **`context`** — the agent's root context literal. Constrained to
|
|
505
|
+
* `JsonCompatible<TContext>` so the snapshot round-trips through arbitrary
|
|
506
|
+
* storage without custom encoding (spec 005 §P5).
|
|
507
|
+
* - **`events`** — phantom field; only its type matters. Pass `{} as TEvents`.
|
|
508
|
+
* - **`deps`** (optional) — frozen container of external resources (DB
|
|
509
|
+
* driver, logger, LLM client). When omitted, `TDeps` defaults to
|
|
510
|
+
* `Record<string, never>` and callbacks see a frozen `{}`. Spec 005 §P6.
|
|
511
|
+
* - **`actions`** (optional) — registers reusable, pure callbacks referenced
|
|
512
|
+
* by name from passive `on[event].actions`. Each callback returns
|
|
513
|
+
* `Partial<TContext>`; the wrapper applies `assign(...)` at compile time so
|
|
514
|
+
* user code never imports from `xstate`. The callback's `event` is typed
|
|
515
|
+
* as the full `TEvents` union — narrowing is the action body's job.
|
|
516
|
+
* - **`modes`** — the root `modes` map.
|
|
517
|
+
*
|
|
518
|
+
* @template TContext The agent's root context shape. JSON-constrained.
|
|
519
|
+
* @template TEvents The agent's full event union.
|
|
520
|
+
* @template TModes The root `modes` map.
|
|
521
|
+
* @template TDeps Frozen deps container.
|
|
522
|
+
*/
|
|
523
|
+
export type AgentConfig<TContext, TEvents extends {
|
|
524
|
+
type: string;
|
|
525
|
+
}, TModes extends ModesMap<TContext, TEvents, TDeps>, TDeps extends Record<string, unknown> = Record<string, never>> = {
|
|
526
|
+
id: string;
|
|
527
|
+
initial: keyof TModes & string;
|
|
528
|
+
context: JsonCompatible<TContext>;
|
|
529
|
+
events: TEvents;
|
|
530
|
+
deps?: Readonly<TDeps>;
|
|
531
|
+
actions?: Readonly<Record<string, (args: {
|
|
532
|
+
context: TContext;
|
|
533
|
+
event: TEvents;
|
|
534
|
+
deps: TDeps;
|
|
535
|
+
}) => Partial<TContext>>>;
|
|
536
|
+
modes: TModes;
|
|
537
|
+
};
|
|
538
|
+
export {};
|
|
539
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAgBA;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,M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types.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Atlas — type contract for the XState agent wrapper.
|
|
2
|
+
//
|
|
3
|
+
// Spec: docs/specs/004-xstate-agent-wrapper.md §"Type contract"
|
|
4
|
+
// + docs/specs/005-agent-deps-and-stringifiable-context.md
|
|
5
|
+
// + docs/specs/006-modes-not-states.md
|
|
6
|
+
//
|
|
7
|
+
// This file is pure types + symbol declarations. Runtime construction lives in
|
|
8
|
+
// defineMode.ts / defineCompoundMode.ts / defineAgent.ts / compile.ts.
|
|
9
|
+
//
|
|
10
|
+
// Vocabulary (DD-024): a `Mode` is a leaf — one node in the agent's state tree
|
|
11
|
+
// with no sub-states; a `CompoundMode` is a Mode that contains sub-Modes.
|
|
12
|
+
// `defineMode` constructs the leaf; `defineCompoundMode` constructs the
|
|
13
|
+
// compound.
|
|
14
|
+
// ── Exit & re-throw tokens ───────────────────────────────────────────
|
|
15
|
+
/**
|
|
16
|
+
* `END` — the only way for a route to leave a `CompoundMode`. Implemented as
|
|
17
|
+
* a unique symbol so it cannot collide with state names (DD-015).
|
|
18
|
+
*
|
|
19
|
+
* Use as a `target` on `achieved` / `abandoned` route entries when you want
|
|
20
|
+
* the enclosing compound's `onDone` transition to fire.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* routes: {
|
|
25
|
+
* achieved: { target: END }, // leave the compound on success
|
|
26
|
+
* retry: [],
|
|
27
|
+
* abandoned: { target: END }, // leave the compound on giving up
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export const END = Symbol("atlas.END");
|
|
32
|
+
/**
|
|
33
|
+
* `RE_THROW` — an error-only `target` that re-propagates the caught rejection
|
|
34
|
+
* above the actor instead of transitioning. Lets `routes.error` filter out
|
|
35
|
+
* programmer errors (TypeError, etc.) without putting `throw` inside `assign`.
|
|
36
|
+
*
|
|
37
|
+
* Valid **only** on `ErrorEntry.target`. Using it on `achieved` / `abandoned`
|
|
38
|
+
* entries is a compile error.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* routes: {
|
|
43
|
+
* error: [
|
|
44
|
+
* { when: (e) => e instanceof TypeError, target: RE_THROW },
|
|
45
|
+
* { target: "fallback" },
|
|
46
|
+
* ],
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export const RE_THROW = Symbol("atlas.RE_THROW");
|
|
51
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,EAAE;AACF,gEAAgE;AAChE,kEAAkE;AAClE,8CAA8C;AAC9C,EAAE;AACF,+EAA+E;AAC/E,uEAAuE;AACvE,EAAE;AACF,+EAA+E;AAC/E,0EAA0E;AAC1E,wEAAwE;AACxE,YAAY;AAiGZ,wEAAwE;AAExE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,GAAG,GAAkB,MAAM,CAAC,WAAW,CAAC,CAAC;AAGtD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAkB,MAAM,CAAC,gBAAgB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateRoutes.d.ts","sourceRoot":"","sources":["../src/validateRoutes.ts"],"names":[],"mappings":"AAoJA,wBAAgB,cAAc,CAC1B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,UAAU,GAAE,MAAW,GACxB,IAAI,CAYN"}
|