@ouispec/agent-events 0.1.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.
Files changed (56) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +36 -0
  3. package/dist/catalog.d.ts +110 -0
  4. package/dist/catalog.d.ts.map +1 -0
  5. package/dist/catalog.js +289 -0
  6. package/dist/catalog.js.map +1 -0
  7. package/dist/cli.d.ts +3 -0
  8. package/dist/cli.d.ts.map +1 -0
  9. package/dist/cli.js +78 -0
  10. package/dist/cli.js.map +1 -0
  11. package/dist/codegen.d.ts +28 -0
  12. package/dist/codegen.d.ts.map +1 -0
  13. package/dist/codegen.js +99 -0
  14. package/dist/codegen.js.map +1 -0
  15. package/dist/event-declarations.v1.schema.json +316 -0
  16. package/dist/index.d.ts +27 -0
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +8 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/json-schema-lite.d.ts +15 -0
  21. package/dist/json-schema-lite.d.ts.map +1 -0
  22. package/dist/json-schema-lite.js +144 -0
  23. package/dist/json-schema-lite.js.map +1 -0
  24. package/dist/oui-wire.d.ts +8 -0
  25. package/dist/oui-wire.d.ts.map +1 -0
  26. package/dist/oui-wire.js +33 -0
  27. package/dist/oui-wire.js.map +1 -0
  28. package/dist/payload-shape.d.ts +21 -0
  29. package/dist/payload-shape.d.ts.map +1 -0
  30. package/dist/payload-shape.js +47 -0
  31. package/dist/payload-shape.js.map +1 -0
  32. package/dist/platform.d.ts +20 -0
  33. package/dist/platform.d.ts.map +1 -0
  34. package/dist/platform.js +109 -0
  35. package/dist/platform.js.map +1 -0
  36. package/dist/rooms.d.ts +21 -0
  37. package/dist/rooms.d.ts.map +1 -0
  38. package/dist/rooms.js +47 -0
  39. package/dist/rooms.js.map +1 -0
  40. package/dist/schema.d.ts +9 -0
  41. package/dist/schema.d.ts.map +1 -0
  42. package/dist/schema.js +26 -0
  43. package/dist/schema.js.map +1 -0
  44. package/dist/settlement.d.ts +43 -0
  45. package/dist/settlement.d.ts.map +1 -0
  46. package/dist/settlement.js +2 -0
  47. package/dist/settlement.js.map +1 -0
  48. package/dist/types.d.ts +23 -0
  49. package/dist/types.d.ts.map +1 -0
  50. package/dist/types.js +14 -0
  51. package/dist/types.js.map +1 -0
  52. package/dist/validate.d.ts +8 -0
  53. package/dist/validate.d.ts.map +1 -0
  54. package/dist/validate.js +38 -0
  55. package/dist/validate.js.map +1 -0
  56. package/package.json +65 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Closure Studio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # @ouispec/agent-events
2
+
3
+ Event contracts the product declares. A product writes one declaration document: each event's payload schema, the rooms it goes to, its correlation fields and its role in a job. The platform follows it:
4
+
5
+ - the realtime server (`@ouispec/agent-realtime`) emits and relays declared events only;
6
+ - the worker's async tools (`@ouispec/agent-worker`) wait on a declared completion or failure;
7
+ - the UI's job tracker (`@ouispec/bindings/oui`) is built from it;
8
+ - a name the document doesn't hold fails the build.
9
+
10
+ ```sh
11
+ npm install @ouispec/agent-events
12
+ ```
13
+
14
+ ```ts
15
+ import { createEventCatalog, PLATFORM_EVENTS } from '@ouispec/agent-events';
16
+ import declarations from './events.json' with { type: 'json' };
17
+
18
+ // The platform's own turn events, with the product's.
19
+ export const catalog = createEventCatalog(PLATFORM_EVENTS, declarations);
20
+ ```
21
+
22
+ | Entry | What it has |
23
+ |---|---|
24
+ | `@ouispec/agent-events` | `createEventCatalog`, `validateEventDeclarations`, the room helpers, `PLATFORM_EVENTS`. Browser-safe. |
25
+ | `@ouispec/agent-events/validate` | Checks a payload against its declared schema. |
26
+ | `@ouispec/agent-events/codegen` | Generates the TypeScript for a declaration document. |
27
+ | `@ouispec/agent-events/schema.json` | The declaration document's JSON Schema, for editors and other languages. It is `@ouispec/contract`'s `event-declarations.json`. |
28
+
29
+ The `agent-sdk-events` CLI checks a document and generates its types:
30
+
31
+ ```sh
32
+ npx agent-sdk-events check events.json
33
+ npx agent-sdk-events types events.json --out src/generated/events.ts [--check]
34
+ ```
35
+
36
+ The declaration format is described in [the integrator guide](https://github.com/wesreid/oui/blob/main/packages/contract/INTEGRATOR-GUIDE.md).
@@ -0,0 +1,110 @@
1
+ import type { Settlement, SettlementOutcome } from './settlement.js';
2
+ import { type EventDeclarationDocument, type EventRole, type FailureReason, type JsonSchema } from './types.js';
3
+ export interface DeclaredRoom {
4
+ name: string;
5
+ /** Null for `turn`: the room of the agent turn, which each host names. */
6
+ pattern: string | null;
7
+ }
8
+ export interface DeclaredEvent {
9
+ name: string;
10
+ /** The product whose document declares it. */
11
+ product: string;
12
+ description: string;
13
+ role: EventRole;
14
+ /** The name generated code gives its payload type. */
15
+ typeName: string;
16
+ payload: JsonSchema;
17
+ /** The declaring document's `$defs`, which the payload's `$ref`s point into. */
18
+ defs: Readonly<Record<string, JsonSchema>>;
19
+ rooms: readonly DeclaredRoom[];
20
+ correlation: readonly string[];
21
+ /** The kind of job it settles; null unless it is a completion or failure. */
22
+ completes: string | null;
23
+ result: readonly string[];
24
+ reason: FailureReason | null;
25
+ }
26
+ /** A kind of job, as its settling events declare it. */
27
+ export interface JobKind {
28
+ kind: string;
29
+ product: string;
30
+ completion: DeclaredEvent;
31
+ /** Null when the product declares no failure: a failed job can then only time out. */
32
+ failure: DeclaredEvent | null;
33
+ /** The field both settling events carry the job's id in. */
34
+ correlation: string;
35
+ /**
36
+ * The room a follower joins to hear one job settle: a room of the
37
+ * completion whose only id is the correlation field. Null when there is
38
+ * none, and then a follower needs its own way in (an identity room).
39
+ */
40
+ followRoom: (DeclaredRoom & {
41
+ pattern: string;
42
+ }) | null;
43
+ }
44
+ export interface AsyncBindingSpec {
45
+ /** Who is binding, for errors: `intent 'generate-image'`, `operation POST /reports`. */
46
+ usedBy: string;
47
+ /** The completion event the work waits on. */
48
+ completion: string;
49
+ /** Its failure event. Default: the one the declarations pair with the completion. */
50
+ failure?: string;
51
+ /** The field the dispatch returns the job's id in. Default: the declared correlation field. */
52
+ correlation?: string;
53
+ }
54
+ /** A checked binding of async work to its declared settling events. */
55
+ export interface AsyncBinding {
56
+ usedBy: string;
57
+ kind: string;
58
+ completion: string;
59
+ failure: string | null;
60
+ correlation: string;
61
+ }
62
+ export interface EventCatalog {
63
+ /** The products whose documents make up the catalog, in order. */
64
+ readonly products: readonly string[];
65
+ /** Every declared name, in declaration order. */
66
+ names(): string[];
67
+ has(name: string): boolean;
68
+ get(name: string): DeclaredEvent | undefined;
69
+ /** The declaration of `name`, or an `UndeclaredEventError` naming `usedBy`. */
70
+ require(name: string, usedBy: string): DeclaredEvent;
71
+ jobKinds(): JobKind[];
72
+ jobKind(kind: string): JobKind | undefined;
73
+ /** Bind async work to its settling events, or throw saying what is wrong and who is wrong. */
74
+ asyncBinding(spec: AsyncBindingSpec): AsyncBinding;
75
+ /** The settlement `payload` makes, when `event` is a completion or failure carrying its job's id; else null. */
76
+ settlement(event: string, payload: unknown): Settlement | null;
77
+ /** The result a completion carries, or the reason a failure gives. */
78
+ outcome(settlement: Settlement): SettlementOutcome;
79
+ /** Whether `room` is one of the rooms `event` is declared to go to. A turn room is any room the host names. */
80
+ allowsRoom(event: string, room: string): boolean;
81
+ /** The room to join to follow one job of `kind`; throws when the kind has none. */
82
+ followRoom(kind: string, id: string): string;
83
+ }
84
+ /** A document breaks the schema or a rule of the catalog. Lists every problem found. */
85
+ export declare class EventDeclarationError extends Error {
86
+ readonly problems: readonly string[];
87
+ constructor(problems: readonly string[]);
88
+ }
89
+ /** Something names an event the declarations do not hold. */
90
+ export declare class UndeclaredEventError extends Error {
91
+ readonly event: string;
92
+ readonly usedBy: string;
93
+ constructor(event: string, usedBy: string, declared: readonly string[]);
94
+ }
95
+ /** A binding names declared events that cannot settle its work as asked. */
96
+ export declare class AsyncBindingError extends Error {
97
+ constructor(usedBy: string, problem: string);
98
+ }
99
+ /** `generation:completed` → `GenerationCompleted`, `asset:qc_passed` → `AssetQcPassed`, `avatar:frame-reselect` → `AvatarFrameReselect`. */
100
+ export declare function defaultTypeName(event: string): string;
101
+ /** Every problem with one document, or none. */
102
+ export declare function validateEventDeclarations(doc: unknown): string[];
103
+ /**
104
+ * Check and merge declaration documents: the platform's own
105
+ * (`PLATFORM_EVENTS`) and the product's. Throws an `EventDeclarationError`
106
+ * listing every problem when any document breaks the schema or a rule, or
107
+ * when two documents declare the same event.
108
+ */
109
+ export declare function createEventCatalog(...documents: readonly EventDeclarationDocument[]): EventCatalog;
110
+ //# sourceMappingURL=catalog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAGL,KAAK,wBAAwB,EAC7B,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AAa,qBAAsB,SAAQ,KAAK;IAClC,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE;gBAA3B,QAAQ,EAAE,SAAS,MAAM,EAAE;CAIjD;AAED,6DAA6D;AAC7D,qBAAa,oBAAqB,SAAQ,KAAK;IAE3C,QAAQ,CAAC,KAAK,EAAE,MAAM;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM;gBADd,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACvB,QAAQ,EAAE,SAAS,MAAM,EAAE;CAK9B;AAED,4EAA4E;AAC5E,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAI5C;AAID,4IAA4I;AAC5I,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMrD;AA0HD,gDAAgD;AAChD,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,EAAE,CAMhE;AAMD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,SAAS,EAAE,SAAS,wBAAwB,EAAE,GAAG,YAAY,CAkHlG"}
@@ -0,0 +1,289 @@
1
+ /**
2
+ * The event catalog: one or more declaration documents (the platform's own
3
+ * and the product's), checked, merged and looked up by name.
4
+ *
5
+ * Everything that names an event goes through it. A name it does not hold is
6
+ * an error that says who used it: the realtime server refuses the emit, the
7
+ * worker refuses to load the tool, the job tracker refuses to start.
8
+ */
9
+ import { EVENT_DECLARATIONS_SCHEMA } from './schema.js';
10
+ import { validateLite } from './json-schema-lite.js';
11
+ import { isObjectSchema, payloadShape } from './payload-shape.js';
12
+ import { formatRoom, roomPatternsRegExp, roomPlaceholders } from './rooms.js';
13
+ import { TURN_ROOM, } from './types.js';
14
+ // ─── Errors ─────────────────────────────────────────────────────────────────
15
+ /** A document breaks the schema or a rule of the catalog. Lists every problem found. */
16
+ export class EventDeclarationError extends Error {
17
+ problems;
18
+ constructor(problems) {
19
+ super(`[agent-sdk-events] Invalid event declarations:\n - ${problems.join('\n - ')}`);
20
+ this.problems = problems;
21
+ this.name = 'EventDeclarationError';
22
+ }
23
+ }
24
+ /** Something names an event the declarations do not hold. */
25
+ export class UndeclaredEventError extends Error {
26
+ event;
27
+ usedBy;
28
+ constructor(event, usedBy, declared) {
29
+ super(`[agent-sdk-events] ${usedBy} names the event '${event}', which is not declared. Declared: ${declared.join(', ') || '(none)'}.`);
30
+ this.event = event;
31
+ this.usedBy = usedBy;
32
+ this.name = 'UndeclaredEventError';
33
+ }
34
+ }
35
+ /** A binding names declared events that cannot settle its work as asked. */
36
+ export class AsyncBindingError extends Error {
37
+ constructor(usedBy, problem) {
38
+ super(`[agent-sdk-events] ${usedBy}: ${problem}`);
39
+ this.name = 'AsyncBindingError';
40
+ }
41
+ }
42
+ // ─── Checking a document ────────────────────────────────────────────────────
43
+ /** `generation:completed` → `GenerationCompleted`, `asset:qc_passed` → `AssetQcPassed`, `avatar:frame-reselect` → `AvatarFrameReselect`. */
44
+ export function defaultTypeName(event) {
45
+ return event
46
+ .split(/[:_-]/)
47
+ .filter(Boolean)
48
+ .map((part) => part[0].toUpperCase() + part.slice(1))
49
+ .join('');
50
+ }
51
+ function checkDocument(doc) {
52
+ const where = typeof doc?.product === 'string' && doc.product ? doc.product : '(document)';
53
+ const structural = validateLite(EVENT_DECLARATIONS_SCHEMA, doc);
54
+ if (structural.length > 0)
55
+ return { events: [], problems: structural.map((p) => `${where}: ${p || '/'}`) };
56
+ const problems = [];
57
+ const defs = doc.$defs ?? {};
58
+ if (TURN_ROOM in doc.rooms) {
59
+ problems.push(`${where}: rooms/${TURN_ROOM} is reserved for the agent turn's room, which each host names`);
60
+ }
61
+ const typeNames = new Map(Object.keys(defs).map((name) => [name, `$defs/${name}`]));
62
+ const events = [];
63
+ for (const [name, decl] of Object.entries(doc.events)) {
64
+ const at = `${where}: events/${name}`;
65
+ const typeName = decl.typeName ?? defaultTypeName(name);
66
+ const clash = typeNames.get(typeName);
67
+ if (clash)
68
+ problems.push(`${at}: its type name ${typeName} is also ${clash}; give it a typeName`);
69
+ typeNames.set(typeName, `events/${name}`);
70
+ const rooms = [];
71
+ for (const room of decl.rooms) {
72
+ if (room === TURN_ROOM)
73
+ rooms.push({ name: room, pattern: null });
74
+ else if (doc.rooms[room])
75
+ rooms.push({ name: room, pattern: doc.rooms[room].pattern });
76
+ else
77
+ problems.push(`${at}: room '${room}' is not declared in rooms (declared: ${Object.keys(doc.rooms).join(', ') || 'none'})`);
78
+ }
79
+ // A payload that does not resolve is reported once; its fields are not
80
+ // checked against a shape that could not be read.
81
+ let shape = null;
82
+ try {
83
+ shape = payloadShape(decl.payload, defs);
84
+ if (!isObjectSchema(decl.payload, defs))
85
+ problems.push(`${at}: payload must be an object schema`);
86
+ }
87
+ catch (err) {
88
+ problems.push(`${at}: payload ${err instanceof Error ? err.message : String(err)}`);
89
+ }
90
+ if (shape) {
91
+ const { properties, required } = shape;
92
+ for (const field of decl.correlation) {
93
+ if (!properties.has(field))
94
+ problems.push(`${at}: correlation field '${field}' is not a property of its payload`);
95
+ else if (!required.has(field))
96
+ problems.push(`${at}: correlation field '${field}' must be required: an event without it correlates to nothing`);
97
+ }
98
+ for (const field of decl.result ?? []) {
99
+ if (!properties.has(field))
100
+ problems.push(`${at}: result field '${field}' is not a property of its payload`);
101
+ }
102
+ if (decl.reason && !properties.has(decl.reason.field)) {
103
+ problems.push(`${at}: reason field '${decl.reason.field}' is not a property of its payload`);
104
+ }
105
+ }
106
+ events.push({
107
+ name,
108
+ product: doc.product,
109
+ description: decl.description,
110
+ role: decl.role,
111
+ typeName,
112
+ payload: decl.payload,
113
+ defs,
114
+ rooms,
115
+ correlation: decl.correlation,
116
+ completes: decl.completes ?? null,
117
+ result: decl.result ?? [],
118
+ reason: decl.reason ?? null,
119
+ });
120
+ }
121
+ return { events, problems };
122
+ }
123
+ function buildJobKinds(events, problems) {
124
+ const byKind = new Map();
125
+ for (const event of events) {
126
+ if (!event.completes || (event.role !== 'completion' && event.role !== 'failure'))
127
+ continue;
128
+ const entry = byKind.get(event.completes) ?? { completion: [], failure: [] };
129
+ entry[event.role].push(event);
130
+ byKind.set(event.completes, entry);
131
+ }
132
+ const kinds = new Map();
133
+ for (const [kind, { completion, failure }] of byKind) {
134
+ const at = `job kind '${kind}'`;
135
+ if (completion.length !== 1) {
136
+ problems.push(completion.length === 0
137
+ ? `${at}: settled by ${failure.map((e) => e.name).join(', ')} but no completion: a job of it could never finish`
138
+ : `${at}: has ${completion.length} completions (${completion.map((e) => e.name).join(', ')}); a job completes one way`);
139
+ continue;
140
+ }
141
+ if (failure.length > 1) {
142
+ problems.push(`${at}: has ${failure.length} failures (${failure.map((e) => e.name).join(', ')}); declare one`);
143
+ continue;
144
+ }
145
+ const done = completion[0];
146
+ const failed = failure[0] ?? null;
147
+ const products = new Set([done.product, failed?.product].filter(Boolean));
148
+ if (products.size > 1) {
149
+ problems.push(`${at}: declared by more than one product (${[...products].join(', ')})`);
150
+ continue;
151
+ }
152
+ const correlation = done.correlation[0];
153
+ if (failed && failed.correlation[0] !== correlation) {
154
+ problems.push(`${at}: ${done.name} correlates on '${correlation}' and ${failed.name} on '${failed.correlation[0]}'; a job has one id`);
155
+ continue;
156
+ }
157
+ const followRoom = done.rooms.find((r) => r.pattern !== null && roomPlaceholders(r.pattern).length === 1 && roomPlaceholders(r.pattern)[0] === correlation);
158
+ kinds.set(kind, { kind, product: done.product, completion: done, failure: failed, correlation, followRoom: followRoom ?? null });
159
+ }
160
+ return kinds;
161
+ }
162
+ /** Every problem with one document, or none. */
163
+ export function validateEventDeclarations(doc) {
164
+ const checked = checkDocument(doc);
165
+ if (checked.problems.length > 0)
166
+ return checked.problems;
167
+ const problems = [];
168
+ buildJobKinds(checked.events, problems);
169
+ return problems;
170
+ }
171
+ // ─── The catalog ────────────────────────────────────────────────────────────
172
+ const presentValue = (value) => value !== undefined && value !== null && value !== '';
173
+ /**
174
+ * Check and merge declaration documents: the platform's own
175
+ * (`PLATFORM_EVENTS`) and the product's. Throws an `EventDeclarationError`
176
+ * listing every problem when any document breaks the schema or a rule, or
177
+ * when two documents declare the same event.
178
+ */
179
+ export function createEventCatalog(...documents) {
180
+ if (documents.length === 0)
181
+ throw new EventDeclarationError(['no declaration documents were given']);
182
+ const problems = [];
183
+ const events = new Map();
184
+ const products = [];
185
+ for (const doc of documents) {
186
+ const checked = checkDocument(doc);
187
+ problems.push(...checked.problems);
188
+ if (products.includes(doc?.product))
189
+ problems.push(`${doc.product}: declared twice`);
190
+ products.push(doc?.product);
191
+ for (const event of checked.events) {
192
+ const earlier = events.get(event.name);
193
+ if (earlier)
194
+ problems.push(`${event.product}: events/${event.name} is already declared by ${earlier.product}`);
195
+ else
196
+ events.set(event.name, event);
197
+ }
198
+ }
199
+ const kinds = buildJobKinds([...events.values()], problems);
200
+ if (problems.length > 0)
201
+ throw new EventDeclarationError(problems);
202
+ const roomMatchers = new Map();
203
+ for (const event of events.values()) {
204
+ const turn = event.rooms.some((r) => r.pattern === null);
205
+ const patterns = event.rooms.flatMap((r) => (r.pattern ? [r.pattern] : []));
206
+ roomMatchers.set(event.name, turn ? null : roomPatternsRegExp(patterns));
207
+ }
208
+ const names = [...events.keys()];
209
+ const completionNames = () => [...kinds.values()].map((k) => k.completion.name);
210
+ const catalog = {
211
+ products,
212
+ names: () => [...names],
213
+ has: (name) => events.has(name),
214
+ get: (name) => events.get(name),
215
+ require(name, usedBy) {
216
+ const event = events.get(name);
217
+ if (!event)
218
+ throw new UndeclaredEventError(name, usedBy, names);
219
+ return event;
220
+ },
221
+ jobKinds: () => [...kinds.values()],
222
+ jobKind: (kind) => kinds.get(kind),
223
+ asyncBinding({ usedBy, completion, failure, correlation }) {
224
+ const done = events.get(completion);
225
+ if (!done)
226
+ throw new UndeclaredEventError(completion, usedBy, completionNames());
227
+ if (done.role !== 'completion' || !done.completes) {
228
+ const hint = done.role === 'progress' ? ': waiting on progress reports a running job as done' : '';
229
+ throw new AsyncBindingError(usedBy, `waits on '${completion}', a ${done.role} event${hint}. Wait on a completion: ${completionNames().join(', ')}.`);
230
+ }
231
+ const kind = kinds.get(done.completes);
232
+ if (failure !== undefined) {
233
+ if (!events.has(failure))
234
+ throw new UndeclaredEventError(failure, usedBy, names);
235
+ if (kind.failure?.name !== failure) {
236
+ throw new AsyncBindingError(usedBy, `names '${failure}' as the failure of '${completion}', but the declarations pair it with ${kind.failure ? `'${kind.failure.name}'` : 'no failure event'}`);
237
+ }
238
+ }
239
+ if (correlation !== undefined && correlation !== kind.correlation) {
240
+ throw new AsyncBindingError(usedBy, `correlates '${completion}' on '${correlation}', but it is declared to carry its job's id in '${kind.correlation}'; the wait would match nothing`);
241
+ }
242
+ return { usedBy, kind: kind.kind, completion, failure: kind.failure?.name ?? null, correlation: kind.correlation };
243
+ },
244
+ settlement(name, payload) {
245
+ const event = events.get(name);
246
+ if (!event?.completes || (event.role !== 'completion' && event.role !== 'failure'))
247
+ return null;
248
+ if (!payload || typeof payload !== 'object')
249
+ return null;
250
+ const kind = kinds.get(event.completes);
251
+ const id = payload[kind.correlation];
252
+ if (typeof id !== 'string' || id.length === 0)
253
+ return null;
254
+ return { kind: kind.kind, role: event.role, event: name, id, payload: payload };
255
+ },
256
+ outcome(settlement) {
257
+ const event = events.get(settlement.event);
258
+ if (!event)
259
+ throw new UndeclaredEventError(settlement.event, 'a settlement', names);
260
+ if (settlement.role === 'failure') {
261
+ const reason = event.reason ? settlement.payload[event.reason.field] : undefined;
262
+ return { status: 'failed', reason: typeof reason === 'string' ? reason : (event.reason?.fallback ?? `${settlement.kind} failed`) };
263
+ }
264
+ const result = {};
265
+ for (const field of event.result) {
266
+ if (presentValue(settlement.payload[field]))
267
+ result[field] = settlement.payload[field];
268
+ }
269
+ return { status: 'complete', result };
270
+ },
271
+ allowsRoom(name, room) {
272
+ if (!events.has(name))
273
+ return false;
274
+ const matcher = roomMatchers.get(name);
275
+ return matcher === null || !!matcher?.test(room);
276
+ },
277
+ followRoom(kind, id) {
278
+ const declared = kinds.get(kind);
279
+ if (!declared)
280
+ throw new UndeclaredEventError(kind, 'a job kind lookup', [...kinds.keys()]);
281
+ if (!declared.followRoom) {
282
+ throw new AsyncBindingError(`job kind '${kind}'`, `no room of ${declared.completion.name} is keyed by '${declared.correlation}' alone, so one job cannot be followed by joining a room`);
283
+ }
284
+ return formatRoom(declared.followRoom.pattern, { [declared.correlation]: id });
285
+ },
286
+ };
287
+ return catalog;
288
+ }
289
+ //# sourceMappingURL=catalog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.js","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9E,OAAO,EACL,SAAS,GAMV,MAAM,YAAY,CAAC;AAyFpB,+EAA+E;AAE/E,wFAAwF;AACxF,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IACzB;IAArB,YAAqB,QAA2B;QAC9C,KAAK,CAAC,uDAAuD,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QADrE,aAAQ,GAAR,QAAQ,CAAmB;QAE9C,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AAED,6DAA6D;AAC7D,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAElC;IACA;IAFX,YACW,KAAa,EACb,MAAc,EACvB,QAA2B;QAE3B,KAAK,CAAC,sBAAsB,MAAM,qBAAqB,KAAK,uCAAuC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,QAAQ,GAAG,CAAC,CAAC;QAJ9H,UAAK,GAAL,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,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QACjF,CAAC;KACF,CAAC;IACF,OAAO,OAAO,CAAC;AACjB,CAAC"}
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * agent-sdk-events — check a declaration document, and generate its TypeScript.
4
+ *
5
+ * agent-sdk-events check <document.json>...
6
+ * Exits 1, listing every problem, unless each document is valid on its own
7
+ * and all of them together (with the platform's events) make one catalog.
8
+ *
9
+ * agent-sdk-events types <document.json> --out <file.ts> [--names key=Name,...] [--source <text>] [--check]
10
+ * Writes the generated TypeScript. With --check, writes nothing and exits 1
11
+ * when <file.ts> is not what the document generates now.
12
+ */
13
+ import { readFileSync, writeFileSync } from 'node:fs';
14
+ import { createEventCatalog, EventDeclarationError } from './catalog.js';
15
+ import { PLATFORM_EVENTS } from './platform.js';
16
+ import { renderTypeScript } from './codegen.js';
17
+ function readDocument(path) {
18
+ try {
19
+ return JSON.parse(readFileSync(path, 'utf8'));
20
+ }
21
+ catch (err) {
22
+ throw new Error(`cannot read ${path}: ${err instanceof Error ? err.message : String(err)}`, { cause: err });
23
+ }
24
+ }
25
+ function option(args, name) {
26
+ const i = args.indexOf(name);
27
+ return i >= 0 ? args[i + 1] : undefined;
28
+ }
29
+ function run(args) {
30
+ const [command, ...rest] = args;
31
+ if (command === 'check') {
32
+ const files = rest.filter((a) => !a.startsWith('--'));
33
+ if (files.length === 0)
34
+ throw new Error('check needs at least one document');
35
+ createEventCatalog(PLATFORM_EVENTS, ...files.map(readDocument));
36
+ console.log(`event declarations valid: ${files.join(', ')}`);
37
+ return 0;
38
+ }
39
+ if (command === 'types') {
40
+ const file = rest[0];
41
+ const out = option(rest, '--out');
42
+ if (!file || !out)
43
+ throw new Error('types needs <document.json> --out <file.ts>');
44
+ const names = Object.fromEntries((option(rest, '--names') ?? '')
45
+ .split(',')
46
+ .filter(Boolean)
47
+ .map((pair) => pair.split('=')));
48
+ const source = option(rest, '--source') ?? `Generated from ${file} by agent-sdk-events. Edit the document, then regenerate.`;
49
+ const text = renderTypeScript(readDocument(file), { source, names });
50
+ if (rest.includes('--check')) {
51
+ let current = '';
52
+ try {
53
+ current = readFileSync(out, 'utf8');
54
+ }
55
+ catch {
56
+ // A missing file is as stale as a wrong one.
57
+ }
58
+ if (current !== text) {
59
+ console.error(`${out} is not what ${file} generates. Regenerate it: agent-sdk-events types ${file} --out ${out}`);
60
+ return 1;
61
+ }
62
+ console.log(`${out} is current`);
63
+ return 0;
64
+ }
65
+ writeFileSync(out, text);
66
+ console.log(`wrote ${out}`);
67
+ return 0;
68
+ }
69
+ throw new Error(`unknown command '${command ?? ''}'; use check or types`);
70
+ }
71
+ try {
72
+ process.exitCode = run(process.argv.slice(2));
73
+ }
74
+ catch (err) {
75
+ console.error(err instanceof EventDeclarationError ? err.message : `agent-sdk-events: ${err instanceof Error ? err.message : String(err)}`);
76
+ process.exitCode = 1;
77
+ }
78
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAwB,MAAM,cAAc,CAAC;AAGtE,SAAS,YAAY,CAAC,IAAY;IAChC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,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QAC5B,OAAO,CAAC,CAAC;IACX,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,oBAAoB,OAAO,IAAI,EAAE,uBAAuB,CAAC,CAAC;AAC5E,CAAC;AAED,IAAI,CAAC;IACH,OAAO,CAAC,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC;AAAC,OAAO,GAAG,EAAE,CAAC;IACb,OAAO,CAAC,KAAK,CAAC,GAAG,YAAY,qBAAqB,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,qBAAqB,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC5I,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC"}
@@ -0,0 +1,28 @@
1
+ import { defaultTypeName } from './catalog.js';
2
+ import type { EventDeclarationDocument } from './types.js';
3
+ export interface TypeScriptNames {
4
+ eventMap: string;
5
+ eventName: string;
6
+ eventPayload: string;
7
+ eventNames: string;
8
+ isEventName: string;
9
+ rooms: string;
10
+ roomPatterns: string;
11
+ roomRegex: string;
12
+ isValidRoom: string;
13
+ jobKinds: string;
14
+ declarations: string;
15
+ }
16
+ export declare const DEFAULT_TYPESCRIPT_NAMES: TypeScriptNames;
17
+ export interface TypeScriptOptions {
18
+ /** Text for the banner under the GENERATED line: where the document lives and how to regenerate. */
19
+ source: string;
20
+ /** Names for the generated declarations, beside the payload types. */
21
+ names?: Partial<TypeScriptNames>;
22
+ /** The module `EventDeclarationDocument` is imported from. */
23
+ typesFrom?: string;
24
+ }
25
+ /** Render the TypeScript for one declaration document. Throws when the document is invalid. */
26
+ export declare function renderTypeScript(document: EventDeclarationDocument, options: TypeScriptOptions): string;
27
+ export { defaultTypeName };
28
+ //# sourceMappingURL=codegen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../src/codegen.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAsB,eAAe,EAAE,MAAM,cAAc,CAAC;AAGnE,OAAO,KAAK,EAAE,wBAAwB,EAAc,MAAM,YAAY,CAAC;AAEvE,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,wBAAwB,EAAE,eAYtC,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC,oGAAoG;IACpG,MAAM,EAAE,MAAM,CAAC;IACf,sEAAsE;IACtE,KAAK,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IACjC,8DAA8D;IAC9D,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAiBD,+FAA+F;AAC/F,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,wBAAwB,EAAE,OAAO,EAAE,iBAAiB,GAAG,MAAM,CA+DvG;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}