@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oui-wire.d.ts","sourceRoot":"","sources":["../src/oui-wire.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,OAAO;IACtB,gEAAgE;IAChE,QAAQ,EAAE,MAAM,CAAC;IACjB,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;CAChB;AA0BD,eAAO,MAAM,QAAQ,EAAE,OAAuB,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * OUI's own names for its wire events, read from OUI's transport rather than
3
+ * written here: OUI owns its wire, and a copy of a name is how two ends drift
4
+ * apart. The dispatch is declared among the platform's events; the result is
5
+ * a client event the realtime server receives.
6
+ */
7
+ import { createWebSocketTransport } from 'oui-spec/transport';
8
+ function captureWire() {
9
+ let dispatch = null;
10
+ let result = null;
11
+ const capture = {
12
+ connected: true,
13
+ emit(event) {
14
+ dispatch = event;
15
+ },
16
+ on(event) {
17
+ result = event;
18
+ },
19
+ off() { },
20
+ once() { },
21
+ };
22
+ const transport = createWebSocketTransport(capture);
23
+ transport.dispatch({ requestId: 'capture', surfaceId: 'capture', actionId: 'capture', params: {}, timestamp: 0 });
24
+ // The transport registers its connection listeners first; the last listener
25
+ // registered is the result listener added here.
26
+ transport.onResult(() => { });
27
+ transport.dispose();
28
+ if (!dispatch || !result)
29
+ throw new Error('[agent-sdk-events] oui-spec transport emitted no dispatch or registered no result listener');
30
+ return { dispatch, result };
31
+ }
32
+ export const OUI_WIRE = captureWire();
33
+ //# sourceMappingURL=oui-wire.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oui-wire.js","sourceRoot":"","sources":["../src/oui-wire.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,wBAAwB,EAAmB,MAAM,oBAAoB,CAAC;AAS/E,SAAS,WAAW;IAClB,IAAI,QAAQ,GAAkB,IAAI,CAAC;IACnC,IAAI,MAAM,GAAkB,IAAI,CAAC;IACjC,MAAM,OAAO,GAAe;QAC1B,SAAS,EAAE,IAAI;QACf,IAAI,CAAC,KAAK;YACR,QAAQ,GAAG,KAAK,CAAC;QACnB,CAAC;QACD,EAAE,CAAC,KAAK;YACN,MAAM,GAAG,KAAK,CAAC;QACjB,CAAC;QACD,GAAG,KAAI,CAAC;QACR,IAAI,KAAI,CAAC;KACV,CAAC;IACF,MAAM,SAAS,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAC;IACpD,SAAS,CAAC,QAAQ,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC;IAClH,4EAA4E;IAC5E,gDAAgD;IAChD,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAC7B,SAAS,CAAC,OAAO,EAAE,CAAC;IACpB,IAAI,CAAC,QAAQ,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,4FAA4F,CAAC,CAAC;IACxI,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC9B,CAAC;AAED,MAAM,CAAC,MAAM,QAAQ,GAAY,WAAW,EAAE,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The fields of a payload schema: what the platform reads to know that a
3
+ * correlation, result or reason field exists and is always sent.
4
+ */
5
+ import type { JsonSchema } from './types.js';
6
+ export interface PayloadShape {
7
+ /** Every declared property, through `$ref` and `allOf`. */
8
+ properties: ReadonlyMap<string, JsonSchema>;
9
+ /** The properties every payload carries. */
10
+ required: ReadonlySet<string>;
11
+ }
12
+ /** The `$defs` name a `$ref` points to, or null when it does not point into `$defs`. */
13
+ export declare function defName(ref: string): string | null;
14
+ /**
15
+ * Collect the object shape of `schema`, following `$ref`s into `defs` and
16
+ * merging `allOf`. Throws naming the reference when one does not resolve.
17
+ */
18
+ export declare function payloadShape(schema: JsonSchema, defs: Readonly<Record<string, JsonSchema>> | undefined): PayloadShape;
19
+ /** Whether `schema` describes an object: `type: 'object'`, or a `$ref`/`allOf` that does. */
20
+ export declare function isObjectSchema(schema: JsonSchema, defs: Readonly<Record<string, JsonSchema>> | undefined): boolean;
21
+ //# sourceMappingURL=payload-shape.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payload-shape.d.ts","sourceRoot":"","sources":["../src/payload-shape.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,WAAW,YAAY;IAC3B,2DAA2D;IAC3D,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAC5C,4CAA4C;IAC5C,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC/B;AAID,wFAAwF;AACxF,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAElD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,GAAG,SAAS,GAAG,YAAY,CAsBrH;AAED,6FAA6F;AAC7F,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,GAAG,SAAS,GAAG,OAAO,CAQlH"}
@@ -0,0 +1,47 @@
1
+ const DEF_REF = /^#\/\$defs\/([^/]+)$/;
2
+ /** The `$defs` name a `$ref` points to, or null when it does not point into `$defs`. */
3
+ export function defName(ref) {
4
+ return DEF_REF.exec(ref)?.[1] ?? null;
5
+ }
6
+ /**
7
+ * Collect the object shape of `schema`, following `$ref`s into `defs` and
8
+ * merging `allOf`. Throws naming the reference when one does not resolve.
9
+ */
10
+ export function payloadShape(schema, defs) {
11
+ const properties = new Map();
12
+ const required = new Set();
13
+ const seen = new Set();
14
+ function visit(s) {
15
+ if (typeof s.$ref === 'string') {
16
+ const name = defName(s.$ref);
17
+ const target = name ? defs?.[name] : undefined;
18
+ if (!name || !target)
19
+ throw new Error(`$ref '${s.$ref}' does not name an entry of $defs`);
20
+ if (seen.has(name))
21
+ throw new Error(`$ref '${s.$ref}' refers back to itself`);
22
+ seen.add(name);
23
+ visit(target);
24
+ seen.delete(name);
25
+ }
26
+ for (const [key, value] of Object.entries(s.properties ?? {}))
27
+ properties.set(key, value);
28
+ for (const key of s.required ?? [])
29
+ required.add(key);
30
+ for (const part of s.allOf ?? [])
31
+ visit(part);
32
+ }
33
+ visit(schema);
34
+ return { properties, required };
35
+ }
36
+ /** Whether `schema` describes an object: `type: 'object'`, or a `$ref`/`allOf` that does. */
37
+ export function isObjectSchema(schema, defs) {
38
+ if (schema.type === 'object')
39
+ return true;
40
+ if (typeof schema.$ref === 'string') {
41
+ const name = defName(schema.$ref);
42
+ const target = name ? defs?.[name] : undefined;
43
+ return !!target && isObjectSchema(target, defs);
44
+ }
45
+ return (schema.allOf ?? []).some((part) => isObjectSchema(part, defs));
46
+ }
47
+ //# sourceMappingURL=payload-shape.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payload-shape.js","sourceRoot":"","sources":["../src/payload-shape.ts"],"names":[],"mappings":"AAaA,MAAM,OAAO,GAAG,sBAAsB,CAAC;AAEvC,wFAAwF;AACxF,MAAM,UAAU,OAAO,CAAC,GAAW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CAAC,GAAG,CAAC,CAAC;QACtD,KAAK,MAAM,IAAI,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE;YAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,CAAC;IACd,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;AAClC,CAAC;AAED,6FAA6F;AAC7F,MAAM,UAAU,cAAc,CAAC,MAAkB,EAAE,IAAsD;IACvG,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC1C,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACpC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAClC,MAAM,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC/C,OAAO,CAAC,CAAC,MAAM,IAAI,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AACzE,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { type EventDeclarationDocument } from './types.js';
2
+ /**
3
+ * The agent's turn events on the wire. A client parses all of them
4
+ * (`parseSocketEvent` in agent-sdk-core); the worker emits the ones
5
+ * `PLATFORM_EVENTS` declares.
6
+ */
7
+ export declare const AGENT_TURN_EVENTS: {
8
+ readonly TURN_STARTED: "agent:turn_started";
9
+ readonly TOKEN: "agent:token";
10
+ readonly TOKEN_CLEAR: "agent:token_clear";
11
+ readonly TOOL_CALL_STARTED: "agent:tool_call_started";
12
+ readonly TOOL_CALL_COMPLETE: "agent:tool_call_complete";
13
+ readonly TURN_COMPLETE: "agent:turn_complete";
14
+ readonly TURN_ERROR: "agent:turn_error";
15
+ readonly ERROR: "agent:error";
16
+ /** The turn stopped at a call that needs the user's approval (ADR-0228); the payload is agent-sdk-core's `ApprovalRequiredEvent`. */
17
+ readonly APPROVAL_REQUIRED: "agent:approval_required";
18
+ };
19
+ export declare const PLATFORM_EVENTS: EventDeclarationDocument;
20
+ //# sourceMappingURL=platform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAUA,OAAO,EAAa,KAAK,wBAAwB,EAAmB,MAAM,YAAY,CAAC;AAEvF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;IAS5B,qIAAqI;;CAE7H,CAAC;AAiBX,eAAO,MAAM,eAAe,EAAE,wBA0F7B,CAAC"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * The platform's own events: what the agent worker emits to a turn's room,
3
+ * turn events and UI action dispatches.
4
+ * Declared like any product's, so the realtime server holds them to the same
5
+ * rule: a declared name, a valid payload, a declared room.
6
+ *
7
+ * Every catalog a realtime server or client uses includes this document
8
+ * beside the product's (`createEventCatalog(PLATFORM_EVENTS, productEvents)`).
9
+ */
10
+ import { OUI_WIRE } from './oui-wire.js';
11
+ import { TURN_ROOM } from './types.js';
12
+ /**
13
+ * The agent's turn events on the wire. A client parses all of them
14
+ * (`parseSocketEvent` in agent-sdk-core); the worker emits the ones
15
+ * `PLATFORM_EVENTS` declares.
16
+ */
17
+ export const AGENT_TURN_EVENTS = {
18
+ TURN_STARTED: 'agent:turn_started',
19
+ TOKEN: 'agent:token',
20
+ TOKEN_CLEAR: 'agent:token_clear',
21
+ TOOL_CALL_STARTED: 'agent:tool_call_started',
22
+ TOOL_CALL_COMPLETE: 'agent:tool_call_complete',
23
+ TURN_COMPLETE: 'agent:turn_complete',
24
+ TURN_ERROR: 'agent:turn_error',
25
+ ERROR: 'agent:error',
26
+ /** The turn stopped at a call that needs the user's approval (ADR-0228); the payload is agent-sdk-core's `ApprovalRequiredEvent`. */
27
+ APPROVAL_REQUIRED: 'agent:approval_required',
28
+ };
29
+ const turnId = { type: 'string', minLength: 1, description: 'The turn the event belongs to.' };
30
+ const timestamp = { type: 'number', description: 'When it happened, epoch ms.' };
31
+ const turnEvent = (description, properties, required) => ({
32
+ description,
33
+ payload: {
34
+ type: 'object',
35
+ properties: { turnId, ...properties, timestamp },
36
+ required: ['turnId', ...required, 'timestamp'],
37
+ },
38
+ rooms: [TURN_ROOM],
39
+ correlation: ['turnId'],
40
+ role: 'notice',
41
+ });
42
+ export const PLATFORM_EVENTS = {
43
+ version: 1,
44
+ product: 'agent-sdk',
45
+ description: "The agent worker's turn events and UI action dispatches, emitted to the room of the turn they belong to.",
46
+ rooms: {},
47
+ events: {
48
+ [AGENT_TURN_EVENTS.TOKEN]: turnEvent('Reply text as it streams: the next piece, not the whole reply.', { text: { type: 'string' } }, ['text']),
49
+ [AGENT_TURN_EVENTS.TOOL_CALL_STARTED]: turnEvent('A tool call began.', {
50
+ toolUseId: { type: 'string', description: 'The call id, which its completion repeats.' },
51
+ name: { type: 'string', description: 'The tool.' },
52
+ input: { type: 'object', description: 'The arguments.' },
53
+ }, ['toolUseId', 'name']),
54
+ [AGENT_TURN_EVENTS.TOOL_CALL_COMPLETE]: turnEvent('A tool call ended, with its result or error.', {
55
+ toolUseId: { type: 'string' },
56
+ name: { type: 'string' },
57
+ result: { description: 'What the model was given.' },
58
+ success: { type: 'boolean' },
59
+ durationMs: { type: 'number' },
60
+ }, ['toolUseId', 'name', 'success']),
61
+ [AGENT_TURN_EVENTS.TURN_COMPLETE]: turnEvent('The turn finished. The last event of a turn: everything before it has been sent.', {
62
+ rounds: { type: 'integer', description: 'Model calls the turn made.' },
63
+ usage: { type: 'object', description: 'Token usage.' },
64
+ }, []),
65
+ [AGENT_TURN_EVENTS.TURN_ERROR]: turnEvent('The turn failed.', {
66
+ error: {
67
+ type: 'object',
68
+ properties: { code: { type: 'string' }, message: { type: 'string' } },
69
+ required: ['code', 'message'],
70
+ },
71
+ }, ['error']),
72
+ [AGENT_TURN_EVENTS.APPROVAL_REQUIRED]: turnEvent("The turn stopped at a call that needs the user's approval (ADR-0228): the card the tab shows, and what the approval is bound to.", {
73
+ conversationId: { type: 'string' },
74
+ approvalId: { type: 'string', minLength: 1, description: 'Equals the tool call id.' },
75
+ tool: { type: 'string' },
76
+ effect: { type: 'string', description: "The action's declared effect kind, or `write`." },
77
+ destructive: { type: 'boolean' },
78
+ preview: {
79
+ type: 'object',
80
+ properties: {
81
+ title: { type: 'string' },
82
+ consequence: { type: 'string' },
83
+ arguments: { type: 'array', items: { type: 'object' } },
84
+ readback: { type: 'string' },
85
+ },
86
+ required: ['title', 'arguments', 'readback'],
87
+ },
88
+ expiresAt: { type: 'number', description: 'Epoch ms.' },
89
+ }, ['conversationId', 'approvalId', 'tool', 'effect', 'destructive', 'preview', 'expiresAt']),
90
+ [OUI_WIRE.dispatch]: {
91
+ description: "A UI action request for the tab that sent the turn (ADR-0209). The tab answers on OUI's result event.",
92
+ payload: {
93
+ type: 'object',
94
+ properties: {
95
+ requestId: { type: 'string', minLength: 1 },
96
+ surfaceId: { type: 'string', minLength: 1 },
97
+ actionId: { type: 'string', minLength: 1 },
98
+ params: { type: 'object' },
99
+ timestamp: { type: 'number' },
100
+ },
101
+ required: ['requestId', 'surfaceId', 'actionId'],
102
+ },
103
+ rooms: [TURN_ROOM],
104
+ correlation: ['requestId'],
105
+ role: 'notice',
106
+ },
107
+ },
108
+ };
109
+ //# sourceMappingURL=platform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,SAAS,EAAkD,MAAM,YAAY,CAAC;AAEvF;;;;GAIG;AACH,MAAM,CAAC,MAAM,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,QAAQ,EAAE,SAAS,EAAE,CAAC,EAAE;oBAC3C,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,EAAE;oBAC1C,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;oBAC1B,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;iBAC9B;gBACD,QAAQ,EAAE,CAAC,WAAW,EAAE,WAAW,EAAE,UAAU,CAAC;aACjD;YACD,KAAK,EAAE,CAAC,SAAS,CAAC;YAClB,WAAW,EAAE,CAAC,WAAW,CAAC;YAC1B,IAAI,EAAE,QAAQ;SACf;KACF;CACF,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Room patterns: `generation:{jobId}` names every room of that kind. One
3
+ * reading of a pattern, used to build a room, to recognise one, and to
4
+ * generate constructors, so the three cannot disagree.
5
+ */
6
+ /** What an id in a room may be. */
7
+ export declare const ROOM_ID_CHARS = "[a-zA-Z0-9_-]+";
8
+ /** The placeholders of a pattern, in order: `agent:turn:{turnId}` → `['turnId']`. */
9
+ export declare function roomPlaceholders(pattern: string): string[];
10
+ /** The pattern with `{name}`s replaced by `format(name)`, and the literal text by `literal(text)`. */
11
+ export declare function mapRoomPattern(pattern: string, literal: (text: string) => string, format: (name: string) => string): string;
12
+ /** A regular-expression source (unanchored) matching exactly the rooms of a pattern. */
13
+ export declare function roomPatternSource(pattern: string): string;
14
+ /** A regular expression matching exactly the rooms of any of the patterns. */
15
+ export declare function roomPatternsRegExp(patterns: readonly string[]): RegExp;
16
+ /**
17
+ * The room a pattern names for these values. Throws when a value is missing
18
+ * or is not a valid id: a room built from `undefined` is a room nobody is in.
19
+ */
20
+ export declare function formatRoom(pattern: string, values: Readonly<Record<string, unknown>>): string;
21
+ //# sourceMappingURL=rooms.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rooms.d.ts","sourceRoot":"","sources":["../src/rooms.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,mCAAmC;AACnC,eAAO,MAAM,aAAa,mBAAmB,CAAC;AAI9C,qFAAqF;AACrF,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAE1D;AAED,sGAAsG;AACtG,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAS3H;AAID,wFAAwF;AACxF,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED,8EAA8E;AAC9E,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAEtE;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAa7F"}
package/dist/rooms.js ADDED
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Room patterns: `generation:{jobId}` names every room of that kind. One
3
+ * reading of a pattern, used to build a room, to recognise one, and to
4
+ * generate constructors, so the three cannot disagree.
5
+ */
6
+ /** What an id in a room may be. */
7
+ export const ROOM_ID_CHARS = '[a-zA-Z0-9_-]+';
8
+ const PLACEHOLDER = /\{([a-zA-Z][a-zA-Z0-9]*)\}/g;
9
+ /** The placeholders of a pattern, in order: `agent:turn:{turnId}` → `['turnId']`. */
10
+ export function roomPlaceholders(pattern) {
11
+ return [...pattern.matchAll(PLACEHOLDER)].map((m) => m[1]);
12
+ }
13
+ /** The pattern with `{name}`s replaced by `format(name)`, and the literal text by `literal(text)`. */
14
+ export function mapRoomPattern(pattern, literal, format) {
15
+ let out = '';
16
+ let last = 0;
17
+ for (const m of pattern.matchAll(PLACEHOLDER)) {
18
+ out += literal(pattern.slice(last, m.index));
19
+ out += format(m[1]);
20
+ last = (m.index ?? 0) + m[0].length;
21
+ }
22
+ return out + literal(pattern.slice(last));
23
+ }
24
+ const escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
25
+ /** A regular-expression source (unanchored) matching exactly the rooms of a pattern. */
26
+ export function roomPatternSource(pattern) {
27
+ return mapRoomPattern(pattern, escapeRegExp, () => ROOM_ID_CHARS);
28
+ }
29
+ /** A regular expression matching exactly the rooms of any of the patterns. */
30
+ export function roomPatternsRegExp(patterns) {
31
+ return new RegExp(`^(?:${patterns.map(roomPatternSource).join('|')})$`);
32
+ }
33
+ /**
34
+ * The room a pattern names for these values. Throws when a value is missing
35
+ * or is not a valid id: a room built from `undefined` is a room nobody is in.
36
+ */
37
+ export function formatRoom(pattern, values) {
38
+ const idChars = new RegExp(`^${ROOM_ID_CHARS}$`);
39
+ return mapRoomPattern(pattern, (text) => text, (name) => {
40
+ const value = values[name];
41
+ if (typeof value !== 'string' || !idChars.test(value)) {
42
+ throw new Error(`[agent-sdk-events] room ${pattern} needs '${name}' to be an id, got ${JSON.stringify(value)}`);
43
+ }
44
+ return value;
45
+ });
46
+ }
47
+ //# sourceMappingURL=rooms.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rooms.js","sourceRoot":"","sources":["../src/rooms.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,mCAAmC;AACnC,MAAM,CAAC,MAAM,aAAa,GAAG,gBAAgB,CAAC;AAE9C,MAAM,WAAW,GAAG,6BAA6B,CAAC;AAElD,qFAAqF;AACrF,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC9C,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7D,CAAC;AAED,sGAAsG;AACtG,MAAM,UAAU,cAAc,CAAC,OAAe,EAAE,OAAiC,E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AE;QACP,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACtD,MAAM,IAAI,KAAK,CAAC,2BAA2B,OAAO,WAAW,IAAI,sBAAsB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAClH,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,9 @@
1
+ export declare const EVENT_DECLARATIONS_SCHEMA_ID = "https://schemas.closurestudio.ai/agent-sdk/event-declarations/v1.json";
2
+ export declare const EVENT_DECLARATIONS_SCHEMA: import("@ouispec/contract").ContractSchemaDocument;
3
+ /** An event name: lower-case segments, usually joined by `:` (`generation:completed`, `avatar:frame-reselect`). */
4
+ export declare const EVENT_NAME_PATTERN: string;
5
+ /** A room name in the document: `user`, `agentTurn`. */
6
+ export declare const ROOM_NAME_PATTERN: string;
7
+ /** A room pattern: literal `a-z 0-9 _ - :` with `{placeholder}`s. */
8
+ export declare const ROOM_PATTERN_PATTERN: string;
9
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,4BAA4B,0EAAsG,CAAC;AAQhJ,eAAO,MAAM,yBAAyB,oDAA8C,CAAC;AAMrF,mHAAmH;AACnH,eAAO,MAAM,kBAAkB,QAAgD,CAAC;AAChF,wDAAwD;AACxD,eAAO,MAAM,iBAAiB,QAA+C,CAAC;AAC9E,qEAAqE;AACrE,eAAO,MAAM,oBAAoB,QAAyD,CAAC"}
package/dist/schema.js ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The JSON Schema of an event declaration document, version 1.
3
+ *
4
+ * It is part of the OUI contract (`@ouispec/contract`,
5
+ * `schemas/event-declarations.json`) and published here too, as
6
+ * `@ouispec/agent-events/schema.json`: editors and other languages
7
+ * validate a document against it. The catalog validates every document
8
+ * against this same object (json-schema-lite.ts) before it checks what a
9
+ * schema cannot say: that a room, a `$ref` or a correlation field exists, and
10
+ * that each job kind has one completion.
11
+ */
12
+ import { CONTRACT_SCHEMAS } from '@ouispec/contract';
13
+ import { EVENT_DECLARATIONS_VERSION } from './types.js';
14
+ export const EVENT_DECLARATIONS_SCHEMA_ID = `https://schemas.closurestudio.ai/agent-sdk/event-declarations/v${EVENT_DECLARATIONS_VERSION}.json`;
15
+ export const EVENT_DECLARATIONS_SCHEMA = CONTRACT_SCHEMAS['event-declarations.json'];
16
+ const shape = EVENT_DECLARATIONS_SCHEMA;
17
+ if (shape.$id !== EVENT_DECLARATIONS_SCHEMA_ID) {
18
+ throw new Error(`[agent-sdk-events] the contract's event declaration schema is ${shape.$id}, not version ${EVENT_DECLARATIONS_VERSION}`);
19
+ }
20
+ /** An event name: lower-case segments, usually joined by `:` (`generation:completed`, `avatar:frame-reselect`). */
21
+ export const EVENT_NAME_PATTERN = shape.properties.events.propertyNames.pattern;
22
+ /** A room name in the document: `user`, `agentTurn`. */
23
+ export const ROOM_NAME_PATTERN = shape.properties.rooms.propertyNames.pattern;
24
+ /** A room pattern: literal `a-z 0-9 _ - :` with `{placeholder}`s. */
25
+ export const ROOM_PATTERN_PATTERN = shape.$defs.RoomDeclaration.properties.pattern.pattern;
26
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AAExD,MAAM,CAAC,MAAM,4BAA4B,GAAG,kEAAkE,0BAA0B,OAAO,CAAC;AAQhJ,MAAM,CAAC,MAAM,yBAAyB,GAAG,gBAAgB,CAAC,yBAAyB,CAAC,CAAC;AACrF,MAAM,KAAK,GAAG,yBAA8D,CAAC;AAC7E,IAAI,KAAK,CAAC,GAAG,KAAK,4BAA4B,EAAE,CAAC;IAC/C,MAAM,IAAI,KAAK,CAAC,iEAAiE,KAAK,CAAC,GAAG,iBAAiB,0BAA0B,EAAE,CAAC,CAAC;AAC3I,CAAC;AAED,mHAAmH;AACnH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC;AAChF,wDAAwD;AACxD,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC;AAC9E,qEAAqE;AACrE,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,CAAC,KAAK,CAAC,eAAe,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * How a job ends, as the platform sees it: the one completion or failure
3
+ * event that settles it. The worker's async tools wait for a settlement, the
4
+ * realtime server keeps one for each job, and the UI's job tracker records one
5
+ * as the job's outcome, so all three read an event the same way.
6
+ */
7
+ import type { AsyncBinding } from './catalog.js';
8
+ export interface Settlement {
9
+ /** The kind of job settled, as the declarations name it. */
10
+ kind: string;
11
+ role: 'completion' | 'failure';
12
+ /** The event that settled it. */
13
+ event: string;
14
+ /** The job: the value of the kind's correlation field. */
15
+ id: string;
16
+ payload: Readonly<Record<string, unknown>>;
17
+ }
18
+ /** What a settlement means: the job's result, or why there is none. */
19
+ export type SettlementOutcome = {
20
+ status: 'complete';
21
+ result: Readonly<Record<string, unknown>>;
22
+ } | {
23
+ status: 'failed';
24
+ reason: string;
25
+ };
26
+ export interface SettlementRequest {
27
+ /** What is waited on: the binding's completion or failure event, for this job. */
28
+ binding: AsyncBinding;
29
+ /** The job's correlation value (its `jobId`, say), from the dispatch. */
30
+ id: string;
31
+ timeoutMs: number;
32
+ signal?: AbortSignal;
33
+ }
34
+ /**
35
+ * How the worker waits for a job to settle. `createHttpEventWaiter` (in
36
+ * `@ouispec/agent-worker`) asks the SDK realtime server, which keeps
37
+ * every declared settlement; a host may supply its own.
38
+ */
39
+ export interface EventWaiter {
40
+ /** The job's settlement once it has one, or null when none arrives by `timeoutMs`. */
41
+ waitForSettlement(request: SettlementRequest): Promise<Settlement | null>;
42
+ }
43
+ //# sourceMappingURL=settlement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settlement.d.ts","sourceRoot":"","sources":["../src/settlement.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,WAAW,UAAU;IACzB,4DAA4D;IAC5D,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,YAAY,GAAG,SAAS,CAAC;IAC/B,iCAAiC;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,0DAA0D;IAC1D,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAC5C;AAED,uEAAuE;AACvE,MAAM,MAAM,iBAAiB,GACzB;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;CAAE,GACjE;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzC,MAAM,WAAW,iBAAiB;IAChC,kFAAkF;IAClF,OAAO,EAAE,YAAY,CAAC;IACtB,yEAAyE;IACzE,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,sFAAsF;IACtF,iBAAiB,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;CAC3E"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=settlement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settlement.js","sourceRoot":"","sources":["../src/settlement.ts"],"names":[],"mappings":""}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The event declaration document: what a product says about every event its
3
+ * backend emits over realtime (ADR-0227 §2.2, §2.4).
4
+ *
5
+ * The platform follows it: the realtime server emits and relays declared
6
+ * events only, the worker's async tools wait on a declared completion event,
7
+ * and the UI's job tracker is built from it. A name absent from it fails the
8
+ * build. The JSON Schema of this document is `EVENT_DECLARATIONS_SCHEMA`
9
+ * (published as `@ouispec/agent-events/schema.json`).
10
+ */
11
+ import type { EventPayloadSchema } from '@ouispec/contract';
12
+ export type { EventDeclaration, EventDeclarationDocument, EventRole, FailureReason, JsonType, RoomDeclaration, } from '@ouispec/contract';
13
+ /**
14
+ * A JSON Schema (draft 2020-12). A payload may use any keyword; the platform
15
+ * reads `$ref` (to the document's `$defs`), `allOf`, `type`, `properties` and
16
+ * `required` to find the fields it correlates and reports on, and validates
17
+ * the rest with a full validator.
18
+ */
19
+ export type JsonSchema = EventPayloadSchema;
20
+ export declare const EVENT_DECLARATIONS_VERSION = 1;
21
+ /** The room an agent turn's events go to; each host names it in the turn. */
22
+ export declare const TURN_ROOM = "turn";
23
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAI5D,YAAY,EACV,gBAAgB,EAChB,wBAAwB,EACxB,SAAS,EACT,aAAa,EACb,QAAQ,EACR,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAE3B;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,kBAAkB,CAAC;AAE5C,eAAO,MAAM,0BAA0B,IAAI,CAAC;AAE5C,6EAA6E;AAC7E,eAAO,MAAM,SAAS,SAAS,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The event declaration document: what a product says about every event its
3
+ * backend emits over realtime (ADR-0227 §2.2, §2.4).
4
+ *
5
+ * The platform follows it: the realtime server emits and relays declared
6
+ * events only, the worker's async tools wait on a declared completion event,
7
+ * and the UI's job tracker is built from it. A name absent from it fails the
8
+ * build. The JSON Schema of this document is `EVENT_DECLARATIONS_SCHEMA`
9
+ * (published as `@ouispec/agent-events/schema.json`).
10
+ */
11
+ export const EVENT_DECLARATIONS_VERSION = 1;
12
+ /** The room an agent turn's events go to; each host names it in the turn. */
13
+ export const TURN_ROOM = 'turn';
14
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAuBH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC;AAE5C,6EAA6E;AAC7E,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { EventCatalog } from './catalog.js';
2
+ export interface PayloadValidator {
3
+ /** Why `payload` is not a valid `event` payload; empty when it is. Throws for an undeclared event. */
4
+ problems(event: string, payload: unknown): string[];
5
+ }
6
+ /** Compile every declared payload schema of the catalog once. */
7
+ export declare function createPayloadValidator(catalog: EventCatalog): PayloadValidator;
8
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAOjD,MAAM,WAAW,gBAAgB;IAC/B,sGAAsG;IACtG,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,EAAE,CAAC;CACrD;AAED,iEAAiE;AACjE,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,YAAY,GAAG,gBAAgB,CA2B9E"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @ouispec/agent-events/validate — checks a payload against its
3
+ * declared schema, with a full JSON Schema (2020-12) validator. For servers
4
+ * and build checks; the catalog itself does not need it.
5
+ */
6
+ import { Ajv2020 } from 'ajv/dist/2020.js';
7
+ import formatsPlugin from 'ajv-formats';
8
+ // ajv-formats is CommonJS; under ESM interop its function is on `default`.
9
+ const addFormats = formatsPlugin.default ?? formatsPlugin;
10
+ /** Compile every declared payload schema of the catalog once. */
11
+ export function createPayloadValidator(catalog) {
12
+ const ajv = new Ajv2020({ allErrors: true, strict: true, strictRequired: false });
13
+ addFormats(ajv);
14
+ const compiled = new Map();
15
+ for (const name of catalog.names()) {
16
+ const event = catalog.get(name);
17
+ try {
18
+ compiled.set(name, ajv.compile({ ...event.payload, $defs: { ...event.defs, ...event.payload.$defs } }));
19
+ }
20
+ catch (err) {
21
+ throw new Error(`[agent-sdk-events] ${event.product}: events/${name} has a payload schema that cannot be compiled: ${err instanceof Error ? err.message : String(err)}`, { cause: err });
22
+ }
23
+ }
24
+ return {
25
+ problems(event, payload) {
26
+ const validate = compiled.get(event);
27
+ if (!validate) {
28
+ // Surface the same error every other lookup gives.
29
+ catalog.require(event, 'payload validation');
30
+ return [];
31
+ }
32
+ if (validate(payload))
33
+ return [];
34
+ return (validate.errors ?? []).map((e) => `${e.instancePath || '/'} ${e.message ?? 'is invalid'}`);
35
+ },
36
+ };
37
+ }
38
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.js","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,OAAO,EAAyB,MAAM,kBAAkB,CAAC;AACl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AAO,CAAC,KAAK,EAAE,oBAAoB,CAAC,CAAC;gBAC7C,OAAO,EAAE,CAAC;YACZ,CAAC;YACD,IAAI,QAAQ,CAAC,OAAO,CAAC;gBAAE,OAAO,EAAE,CAAC;YACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,YAAY,IAAI,GAAG,IAAI,CAAC,CAAC,OAAO,IAAI,YAAY,EAAE,CAAC,CAAC;QACrG,CAAC;KACF,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@ouispec/agent-events",
3
+ "version": "0.1.0",
4
+ "description": "Event contracts the product declares (ADR-0227 §2.4): each event's payload schema, rooms, correlation and job role; the catalog the realtime server, the worker's async tools and the UI's job tracker follow; the platform's own turn events; payload validation and TypeScript generation",
5
+ "homepage": "https://github.com/wesreid/oui/tree/main/packages/agent-events#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/wesreid/oui/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/wesreid/oui.git",
12
+ "directory": "packages/agent-events"
13
+ },
14
+ "license": "MIT",
15
+ "type": "module",
16
+ "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "bin": {
19
+ "agent-sdk-events": "./dist/cli.js"
20
+ },
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "import": "./dist/index.js",
25
+ "default": "./dist/index.js"
26
+ },
27
+ "./validate": {
28
+ "types": "./dist/validate.d.ts",
29
+ "import": "./dist/validate.js",
30
+ "default": "./dist/validate.js"
31
+ },
32
+ "./codegen": {
33
+ "types": "./dist/codegen.d.ts",
34
+ "import": "./dist/codegen.js",
35
+ "default": "./dist/codegen.js"
36
+ },
37
+ "./schema.json": "./dist/event-declarations.v1.schema.json"
38
+ },
39
+ "files": [
40
+ "dist",
41
+ "README.md"
42
+ ],
43
+ "sideEffects": false,
44
+ "dependencies": {
45
+ "ajv": "^8.17.0",
46
+ "ajv-formats": "^3.0.1",
47
+ "@ouispec/contract": "^0.1.0",
48
+ "oui-spec": "^0.6.1"
49
+ },
50
+ "devDependencies": {
51
+ "@types/node": "^22.0.0",
52
+ "typescript": "^5.8.0",
53
+ "vitest": "^3.2.0"
54
+ },
55
+ "publishConfig": {
56
+ "access": "public",
57
+ "provenance": true
58
+ },
59
+ "scripts": {
60
+ "build": "tsc -p tsconfig.build.json && node scripts/write-schema.mjs",
61
+ "typecheck": "tsc --noEmit",
62
+ "test": "vitest run",
63
+ "clean": "rm -rf dist"
64
+ }
65
+ }