oui-spec 0.4.1 → 0.5.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 (41) hide show
  1. package/README.md +23 -0
  2. package/dist/{chunk-GDB56ZQZ.cjs → chunk-27CBVTA4.cjs} +53 -6
  3. package/dist/chunk-27CBVTA4.cjs.map +1 -0
  4. package/dist/chunk-2AISUNMW.cjs +131 -0
  5. package/dist/chunk-2AISUNMW.cjs.map +1 -0
  6. package/dist/{chunk-UQLG55ST.js → chunk-6ZIKO7MG.js} +51 -4
  7. package/dist/chunk-6ZIKO7MG.js.map +1 -0
  8. package/dist/chunk-BNGJJM3T.js +122 -0
  9. package/dist/chunk-BNGJJM3T.js.map +1 -0
  10. package/dist/{chunk-F3WKIRAU.js → chunk-UKKITNZK.js} +13 -3
  11. package/dist/chunk-UKKITNZK.js.map +1 -0
  12. package/dist/{chunk-DCVVTP3V.cjs → chunk-XUX4XVP3.cjs} +13 -3
  13. package/dist/chunk-XUX4XVP3.cjs.map +1 -0
  14. package/dist/core/index.cjs +7 -7
  15. package/dist/core/index.d.cts +2 -2
  16. package/dist/core/index.d.ts +2 -2
  17. package/dist/core/index.js +3 -3
  18. package/dist/index.cjs +36 -8
  19. package/dist/index.d.cts +2 -2
  20. package/dist/index.d.ts +2 -2
  21. package/dist/index.js +3 -3
  22. package/dist/react/index.d.cts +1 -1
  23. package/dist/react/index.d.ts +1 -1
  24. package/dist/spec/index.cjs +30 -2
  25. package/dist/spec/index.d.cts +91 -2
  26. package/dist/spec/index.d.ts +91 -2
  27. package/dist/spec/index.js +1 -1
  28. package/dist/{surface-runtime-DeByfbKg.d.ts → surface-runtime-CS0rByFQ.d.ts} +14 -1
  29. package/dist/{surface-runtime-BzIKgL_I.d.cts → surface-runtime-lqXn221P.d.cts} +14 -1
  30. package/dist/transport/index.cjs +2 -2
  31. package/dist/transport/index.js +1 -1
  32. package/package.json +4 -3
  33. package/spec/approval-vectors.json +88 -0
  34. package/dist/chunk-BMCL2K74.js +0 -12
  35. package/dist/chunk-BMCL2K74.js.map +0 -1
  36. package/dist/chunk-DCVVTP3V.cjs.map +0 -1
  37. package/dist/chunk-F3WKIRAU.js.map +0 -1
  38. package/dist/chunk-GDB56ZQZ.cjs.map +0 -1
  39. package/dist/chunk-UQLG55ST.js.map +0 -1
  40. package/dist/chunk-ZKM4XWAB.cjs +0 -14
  41. package/dist/chunk-ZKM4XWAB.cjs.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { JSONSchema, OUIAction, OUIActionPolling, OUIActionRequest, OUIActionResult, OUIActivation, OUIObservation, OUIObservationSnapshot, OUIObservationUpdate, OUIProtocolEvent, OUISurface, OUISurfaceDeregistration, OUISurfaceRegistration, OUISurfaceSnapshot, OUI_PROTOCOL_EVENTS } from './spec/index.js';
2
- export { A as ActionDefinition, a as ActionHandlerResult, b as ActionPollingConfig, D as DefinedSurface, M as MountedSurface, O as OUIBranded, c as ObservationDefinition, S as SettleOptions, d as SurfaceDefinition, e as SurfaceRuntime, f as SurfaceRuntimeOptions, g as createSurfaceRuntime, h as defineSurface } from './surface-runtime-DeByfbKg.js';
1
+ export { ARGS_HASH_PATTERN, JSONSchema, OUIAction, OUIActionApproval, OUIActionPolling, OUIActionRequest, OUIActionResult, OUIActivation, OUIApprovalGrant, OUIEffectKind, OUIObservation, OUIObservationSnapshot, OUIObservationUpdate, OUIProtocolEvent, OUISurface, OUISurfaceDeregistration, OUISurfaceRegistration, OUISurfaceSnapshot, OUI_EFFECT_ACCESS, OUI_EFFECT_KINDS, OUI_PROTOCOL_EVENTS, argsHash, canonicalJson, effectAccess, requiresApproval } from './spec/index.js';
2
+ export { A as ActionDefinition, a as ActionHandlerResult, b as ActionPollingConfig, D as DefinedSurface, M as MountedSurface, O as OUIBranded, c as ObservationDefinition, S as SettleOptions, d as SurfaceDefinition, e as SurfaceRuntime, f as SurfaceRuntimeOptions, g as createSurfaceRuntime, h as defineSurface } from './surface-runtime-CS0rByFQ.js';
3
3
  export { DuplicateIds, OUIConfig, OUIConfigError, OUIInstance, OwnedTransport, ValidateSurfaceIds, createOUI } from './core/index.js';
4
4
  export { SurfaceRuntimeProvider, SurfaceRuntimeProviderProps, UseSurfaceOptions, UseSurfaceResult, useObservation, useSurface, useSurfaceHold, useSurfaceRuntime } from './react/index.js';
5
5
  export { O as OUIActionHandler, a as OUIObservationHandler, b as OUIResultHandler, c as OUITransport, d as OUITransportConfig, S as SocketLike, e as createWebSocketTransport } from './websocket-c5tIUWY5.js';
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- export { createOUI, createSurfaceRuntime, defineSurface } from './chunk-UQLG55ST.js';
2
- export { OUI_PROTOCOL_EVENTS } from './chunk-BMCL2K74.js';
1
+ export { createOUI, createSurfaceRuntime, defineSurface } from './chunk-6ZIKO7MG.js';
2
+ export { ARGS_HASH_PATTERN, OUI_EFFECT_ACCESS, OUI_EFFECT_KINDS, OUI_PROTOCOL_EVENTS, argsHash, canonicalJson, effectAccess, requiresApproval } from './chunk-BNGJJM3T.js';
3
3
  export { SurfaceRuntimeProvider, useObservation, useSurface, useSurfaceHold, useSurfaceRuntime } from './chunk-NYCJZQSP.js';
4
4
  export { createDirectTransportPair } from './chunk-IIZ6HL2L.js';
5
- export { createWebSocketTransport } from './chunk-F3WKIRAU.js';
5
+ export { createWebSocketTransport } from './chunk-UKKITNZK.js';
6
6
  //# sourceMappingURL=index.js.map
7
7
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
3
  import { OUIActionResult } from '../spec/index.cjs';
4
- import { e as SurfaceRuntime, D as DefinedSurface } from '../surface-runtime-BzIKgL_I.cjs';
4
+ import { e as SurfaceRuntime, D as DefinedSurface } from '../surface-runtime-lqXn221P.cjs';
5
5
  import '../websocket-YfWILdZ4.cjs';
6
6
 
7
7
  interface SurfaceRuntimeProviderProps {
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
3
  import { OUIActionResult } from '../spec/index.js';
4
- import { e as SurfaceRuntime, D as DefinedSurface } from '../surface-runtime-DeByfbKg.js';
4
+ import { e as SurfaceRuntime, D as DefinedSurface } from '../surface-runtime-CS0rByFQ.js';
5
5
  import '../websocket-c5tIUWY5.js';
6
6
 
7
7
  interface SurfaceRuntimeProviderProps {
@@ -1,12 +1,40 @@
1
1
  'use strict';
2
2
 
3
- var chunkZKM4XWAB_cjs = require('../chunk-ZKM4XWAB.cjs');
3
+ var chunk2AISUNMW_cjs = require('../chunk-2AISUNMW.cjs');
4
4
 
5
5
 
6
6
 
7
+ Object.defineProperty(exports, "ARGS_HASH_PATTERN", {
8
+ enumerable: true,
9
+ get: function () { return chunk2AISUNMW_cjs.ARGS_HASH_PATTERN; }
10
+ });
11
+ Object.defineProperty(exports, "OUI_EFFECT_ACCESS", {
12
+ enumerable: true,
13
+ get: function () { return chunk2AISUNMW_cjs.OUI_EFFECT_ACCESS; }
14
+ });
15
+ Object.defineProperty(exports, "OUI_EFFECT_KINDS", {
16
+ enumerable: true,
17
+ get: function () { return chunk2AISUNMW_cjs.OUI_EFFECT_KINDS; }
18
+ });
7
19
  Object.defineProperty(exports, "OUI_PROTOCOL_EVENTS", {
8
20
  enumerable: true,
9
- get: function () { return chunkZKM4XWAB_cjs.OUI_PROTOCOL_EVENTS; }
21
+ get: function () { return chunk2AISUNMW_cjs.OUI_PROTOCOL_EVENTS; }
22
+ });
23
+ Object.defineProperty(exports, "argsHash", {
24
+ enumerable: true,
25
+ get: function () { return chunk2AISUNMW_cjs.argsHash; }
26
+ });
27
+ Object.defineProperty(exports, "canonicalJson", {
28
+ enumerable: true,
29
+ get: function () { return chunk2AISUNMW_cjs.canonicalJson; }
30
+ });
31
+ Object.defineProperty(exports, "effectAccess", {
32
+ enumerable: true,
33
+ get: function () { return chunk2AISUNMW_cjs.effectAccess; }
34
+ });
35
+ Object.defineProperty(exports, "requiresApproval", {
36
+ enumerable: true,
37
+ get: function () { return chunk2AISUNMW_cjs.requiresApproval; }
10
38
  });
11
39
  //# sourceMappingURL=index.cjs.map
12
40
  //# sourceMappingURL=index.cjs.map
@@ -1,3 +1,74 @@
1
+ /**
2
+ * Approvals: an irreversible action runs only on an approval the user gave,
3
+ * bound to the exact request.
4
+ *
5
+ * An agent runtime stops at an action that needs approval and shows the user
6
+ * a confirmation. Its approval store issues a single-use grant when the user
7
+ * confirms, and the request that then reaches the tab carries `approval:
8
+ * { approvalId, argsHash }`. The surface runtime runs the action only when
9
+ * that matches a grant this tab received from the user's own confirmation.
10
+ *
11
+ * Everything that checks a request computes the same args hash: SHA-256 over
12
+ * the RFC 8785 (JCS) canonical JSON of its params, lowercase hex. The
13
+ * published vectors (`oui-spec/approval-vectors.json`) hold every
14
+ * implementation, in any language, to it.
15
+ */
16
+ /**
17
+ * What using an action does. One vocabulary for every kind of action, so an
18
+ * action is told apart by what it changes:
19
+ *
20
+ * | Effect | What it changes | Access |
21
+ * |---|---|---|
22
+ * | `view`, `selection`, `navigate`, `open` | What is shown | read |
23
+ * | `edit` | The document, one undo step | write |
24
+ * | `file` | Imports or exports a file | write |
25
+ * | `mutate` | Backend data, through an API operation | write |
26
+ * | `job` | Starts work that outlives the call | write |
27
+ * | `transaction` | An irreversible external act: an order, a payment, a send, a publish | write, approved |
28
+ */
29
+ type OUIEffectKind = "view" | "selection" | "navigate" | "open" | "edit" | "file" | "mutate" | "job" | "transaction";
30
+ /** Every effect, in the order of the table above. */
31
+ declare const OUI_EFFECT_KINDS: readonly OUIEffectKind[];
32
+ /** Whether an effect only changes what is shown, or changes something. */
33
+ declare const OUI_EFFECT_ACCESS: Readonly<Record<OUIEffectKind, "read" | "write">>;
34
+ /** `read` or `write`. An action that declares no effect is a `write`: nothing says it only shows. */
35
+ declare function effectAccess(effect: OUIEffectKind | undefined): "read" | "write";
36
+ /**
37
+ * Whether running an action needs the user's approval of the exact request: a
38
+ * `transaction` always, and a `write` declared destructive. An agent
39
+ * runtime's policy may require it of more; nothing waives these.
40
+ */
41
+ declare function requiresApproval(effect: OUIEffectKind | undefined, destructive?: boolean): boolean;
42
+ /** What a request for an approved action carries. */
43
+ interface OUIActionApproval {
44
+ approvalId: string;
45
+ /** `argsHash(params)` of the request the user approved. */
46
+ argsHash: string;
47
+ }
48
+ /** A grant this tab holds: the user approved this request here. */
49
+ interface OUIApprovalGrant extends OUIActionApproval {
50
+ /** Epoch ms after which the grant no longer admits anything. */
51
+ expiresAt: number;
52
+ }
53
+ /** An args hash: 64 lowercase hex digits. */
54
+ declare const ARGS_HASH_PATTERN: RegExp;
55
+ /**
56
+ * The RFC 8785 canonical form of a JSON value:
57
+ * - object members sorted by their names' UTF-16 code units, with no
58
+ * whitespace;
59
+ * - numbers in ECMAScript's shortest round-trip form (`-0` is `0`);
60
+ * - strings escaped as ECMAScript's `JSON.stringify` escapes them.
61
+ *
62
+ * The value must be I-JSON (RFC 7493): anything JSON cannot carry — `NaN`,
63
+ * infinities, `undefined` outside an object member, a bigint, a function, a
64
+ * symbol, a class instance, or a string with a lone surrogate — is refused
65
+ * rather than hashed as something the other end never receives. An object
66
+ * member whose value is `undefined` is left out, as it is on the wire.
67
+ */
68
+ declare function canonicalJson(value: unknown): string;
69
+ /** SHA-256 of the canonical JSON of a request's params, lowercase hex. Runs wherever WebCrypto does. */
70
+ declare function argsHash(params: unknown): Promise<string>;
71
+
1
72
  /**
2
73
  * OUI — Open UI Specification
3
74
  *
@@ -92,11 +163,23 @@ interface OUIAction {
92
163
  id: string;
93
164
  /** Human-readable description — this is what the LLM reads to decide when to use it */
94
165
  description: string;
166
+ /** The action's name as a person reads it, for a confirmation the user approves. */
167
+ title?: string;
168
+ /**
169
+ * What using the action does. A `transaction` runs only on the user's
170
+ * approval of the exact request (see `requiresApproval`). Undeclared counts
171
+ * as a write.
172
+ */
173
+ effect?: OUIEffectKind;
95
174
  /** JSON Schema for the action's input parameters */
96
175
  input: JSONSchema;
97
176
  /** JSON Schema for the action's return value (optional — agent still gets the result) */
98
177
  output?: JSONSchema;
99
- /** If true, the agent runtime should confirm with the user before executing */
178
+ /**
179
+ * Destructive: the action removes or replaces something the person made.
180
+ * Unless its effect only reads, it runs only on the user's approval of the
181
+ * exact request, which the surface runtime checks before it runs.
182
+ */
100
183
  confirm?: boolean;
101
184
  /** If true, the action is async — returns immediately with a job/tracking ID */
102
185
  async?: boolean;
@@ -159,6 +242,12 @@ interface OUIActionRequest {
159
242
  params: Record<string, unknown>;
160
243
  /** Timestamp of the request */
161
244
  timestamp: number;
245
+ /**
246
+ * The user's approval this request runs on, for an action that needs one.
247
+ * The surface runtime runs such an action only when this matches a grant
248
+ * the tab received from the user's own confirmation, for exactly `params`.
249
+ */
250
+ approval?: OUIActionApproval;
162
251
  }
163
252
  /**
164
253
  * The result of an action execution, returned from the surface to the agent.
@@ -274,4 +363,4 @@ declare const OUI_PROTOCOL_EVENTS: {
274
363
  readonly OBSERVATION_UPDATE: "observation:update";
275
364
  };
276
365
 
277
- export { type JSONSchema, type OUIAction, type OUIActionPolling, type OUIActionRequest, type OUIActionResult, type OUIActivation, type OUIObservation, type OUIObservationSnapshot, type OUIObservationUpdate, type OUIProtocolEvent, type OUISurface, type OUISurfaceDeregistration, type OUISurfaceRegistration, type OUISurfaceSnapshot, OUI_PROTOCOL_EVENTS };
366
+ export { ARGS_HASH_PATTERN, type JSONSchema, type OUIAction, type OUIActionApproval, type OUIActionPolling, type OUIActionRequest, type OUIActionResult, type OUIActivation, type OUIApprovalGrant, type OUIEffectKind, type OUIObservation, type OUIObservationSnapshot, type OUIObservationUpdate, type OUIProtocolEvent, type OUISurface, type OUISurfaceDeregistration, type OUISurfaceRegistration, type OUISurfaceSnapshot, OUI_EFFECT_ACCESS, OUI_EFFECT_KINDS, OUI_PROTOCOL_EVENTS, argsHash, canonicalJson, effectAccess, requiresApproval };
@@ -1,3 +1,74 @@
1
+ /**
2
+ * Approvals: an irreversible action runs only on an approval the user gave,
3
+ * bound to the exact request.
4
+ *
5
+ * An agent runtime stops at an action that needs approval and shows the user
6
+ * a confirmation. Its approval store issues a single-use grant when the user
7
+ * confirms, and the request that then reaches the tab carries `approval:
8
+ * { approvalId, argsHash }`. The surface runtime runs the action only when
9
+ * that matches a grant this tab received from the user's own confirmation.
10
+ *
11
+ * Everything that checks a request computes the same args hash: SHA-256 over
12
+ * the RFC 8785 (JCS) canonical JSON of its params, lowercase hex. The
13
+ * published vectors (`oui-spec/approval-vectors.json`) hold every
14
+ * implementation, in any language, to it.
15
+ */
16
+ /**
17
+ * What using an action does. One vocabulary for every kind of action, so an
18
+ * action is told apart by what it changes:
19
+ *
20
+ * | Effect | What it changes | Access |
21
+ * |---|---|---|
22
+ * | `view`, `selection`, `navigate`, `open` | What is shown | read |
23
+ * | `edit` | The document, one undo step | write |
24
+ * | `file` | Imports or exports a file | write |
25
+ * | `mutate` | Backend data, through an API operation | write |
26
+ * | `job` | Starts work that outlives the call | write |
27
+ * | `transaction` | An irreversible external act: an order, a payment, a send, a publish | write, approved |
28
+ */
29
+ type OUIEffectKind = "view" | "selection" | "navigate" | "open" | "edit" | "file" | "mutate" | "job" | "transaction";
30
+ /** Every effect, in the order of the table above. */
31
+ declare const OUI_EFFECT_KINDS: readonly OUIEffectKind[];
32
+ /** Whether an effect only changes what is shown, or changes something. */
33
+ declare const OUI_EFFECT_ACCESS: Readonly<Record<OUIEffectKind, "read" | "write">>;
34
+ /** `read` or `write`. An action that declares no effect is a `write`: nothing says it only shows. */
35
+ declare function effectAccess(effect: OUIEffectKind | undefined): "read" | "write";
36
+ /**
37
+ * Whether running an action needs the user's approval of the exact request: a
38
+ * `transaction` always, and a `write` declared destructive. An agent
39
+ * runtime's policy may require it of more; nothing waives these.
40
+ */
41
+ declare function requiresApproval(effect: OUIEffectKind | undefined, destructive?: boolean): boolean;
42
+ /** What a request for an approved action carries. */
43
+ interface OUIActionApproval {
44
+ approvalId: string;
45
+ /** `argsHash(params)` of the request the user approved. */
46
+ argsHash: string;
47
+ }
48
+ /** A grant this tab holds: the user approved this request here. */
49
+ interface OUIApprovalGrant extends OUIActionApproval {
50
+ /** Epoch ms after which the grant no longer admits anything. */
51
+ expiresAt: number;
52
+ }
53
+ /** An args hash: 64 lowercase hex digits. */
54
+ declare const ARGS_HASH_PATTERN: RegExp;
55
+ /**
56
+ * The RFC 8785 canonical form of a JSON value:
57
+ * - object members sorted by their names' UTF-16 code units, with no
58
+ * whitespace;
59
+ * - numbers in ECMAScript's shortest round-trip form (`-0` is `0`);
60
+ * - strings escaped as ECMAScript's `JSON.stringify` escapes them.
61
+ *
62
+ * The value must be I-JSON (RFC 7493): anything JSON cannot carry — `NaN`,
63
+ * infinities, `undefined` outside an object member, a bigint, a function, a
64
+ * symbol, a class instance, or a string with a lone surrogate — is refused
65
+ * rather than hashed as something the other end never receives. An object
66
+ * member whose value is `undefined` is left out, as it is on the wire.
67
+ */
68
+ declare function canonicalJson(value: unknown): string;
69
+ /** SHA-256 of the canonical JSON of a request's params, lowercase hex. Runs wherever WebCrypto does. */
70
+ declare function argsHash(params: unknown): Promise<string>;
71
+
1
72
  /**
2
73
  * OUI — Open UI Specification
3
74
  *
@@ -92,11 +163,23 @@ interface OUIAction {
92
163
  id: string;
93
164
  /** Human-readable description — this is what the LLM reads to decide when to use it */
94
165
  description: string;
166
+ /** The action's name as a person reads it, for a confirmation the user approves. */
167
+ title?: string;
168
+ /**
169
+ * What using the action does. A `transaction` runs only on the user's
170
+ * approval of the exact request (see `requiresApproval`). Undeclared counts
171
+ * as a write.
172
+ */
173
+ effect?: OUIEffectKind;
95
174
  /** JSON Schema for the action's input parameters */
96
175
  input: JSONSchema;
97
176
  /** JSON Schema for the action's return value (optional — agent still gets the result) */
98
177
  output?: JSONSchema;
99
- /** If true, the agent runtime should confirm with the user before executing */
178
+ /**
179
+ * Destructive: the action removes or replaces something the person made.
180
+ * Unless its effect only reads, it runs only on the user's approval of the
181
+ * exact request, which the surface runtime checks before it runs.
182
+ */
100
183
  confirm?: boolean;
101
184
  /** If true, the action is async — returns immediately with a job/tracking ID */
102
185
  async?: boolean;
@@ -159,6 +242,12 @@ interface OUIActionRequest {
159
242
  params: Record<string, unknown>;
160
243
  /** Timestamp of the request */
161
244
  timestamp: number;
245
+ /**
246
+ * The user's approval this request runs on, for an action that needs one.
247
+ * The surface runtime runs such an action only when this matches a grant
248
+ * the tab received from the user's own confirmation, for exactly `params`.
249
+ */
250
+ approval?: OUIActionApproval;
162
251
  }
163
252
  /**
164
253
  * The result of an action execution, returned from the surface to the agent.
@@ -274,4 +363,4 @@ declare const OUI_PROTOCOL_EVENTS: {
274
363
  readonly OBSERVATION_UPDATE: "observation:update";
275
364
  };
276
365
 
277
- export { type JSONSchema, type OUIAction, type OUIActionPolling, type OUIActionRequest, type OUIActionResult, type OUIActivation, type OUIObservation, type OUIObservationSnapshot, type OUIObservationUpdate, type OUIProtocolEvent, type OUISurface, type OUISurfaceDeregistration, type OUISurfaceRegistration, type OUISurfaceSnapshot, OUI_PROTOCOL_EVENTS };
366
+ export { ARGS_HASH_PATTERN, type JSONSchema, type OUIAction, type OUIActionApproval, type OUIActionPolling, type OUIActionRequest, type OUIActionResult, type OUIActivation, type OUIApprovalGrant, type OUIEffectKind, type OUIObservation, type OUIObservationSnapshot, type OUIObservationUpdate, type OUIProtocolEvent, type OUISurface, type OUISurfaceDeregistration, type OUISurfaceRegistration, type OUISurfaceSnapshot, OUI_EFFECT_ACCESS, OUI_EFFECT_KINDS, OUI_PROTOCOL_EVENTS, argsHash, canonicalJson, effectAccess, requiresApproval };
@@ -1,3 +1,3 @@
1
- export { OUI_PROTOCOL_EVENTS } from '../chunk-BMCL2K74.js';
1
+ export { ARGS_HASH_PATTERN, OUI_EFFECT_ACCESS, OUI_EFFECT_KINDS, OUI_PROTOCOL_EVENTS, argsHash, canonicalJson, effectAccess, requiresApproval } from '../chunk-BNGJJM3T.js';
2
2
  //# sourceMappingURL=index.js.map
3
3
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- import { JSONSchema, OUIActionPolling, OUIActivation, OUISurface, OUISurfaceSnapshot, OUIActionRequest, OUIActionResult } from './spec/index.js';
1
+ import { OUIEffectKind, JSONSchema, OUIActionPolling, OUIActivation, OUISurface, OUISurfaceSnapshot, OUIActionRequest, OUIActionResult, OUIApprovalGrant } from './spec/index.js';
2
2
  import { S as SocketLike, d as OUITransportConfig } from './websocket-c5tIUWY5.js';
3
3
 
4
4
  /**
@@ -61,8 +61,13 @@ interface ActionPollingConfig<TContext = unknown> extends OUIActionPolling {
61
61
  interface ActionDefinition<TContext = unknown> {
62
62
  id: string;
63
63
  description: string;
64
+ /** Its name as a person reads it, for a confirmation the user approves. */
65
+ title?: string;
66
+ /** What using it does; a `transaction` runs only on the user's approval of the exact request. */
67
+ effect?: OUIEffectKind;
64
68
  input: JSONSchema;
65
69
  output?: JSONSchema;
70
+ /** Destructive: it runs only on the user's approval of the exact request, unless it only reads. */
66
71
  confirm?: boolean;
67
72
  async?: boolean;
68
73
  /**
@@ -241,6 +246,14 @@ interface SurfaceRuntime {
241
246
  * code still loading or a page fetching the data it will display.
242
247
  */
243
248
  hold(): () => void;
249
+ /**
250
+ * Record that the user approved one request, here, through their own
251
+ * confirmation (the agent runtime's approval store answered it to this tab).
252
+ * An action that needs approval — a `transaction`, or a destructive write —
253
+ * runs only on a request whose `approval` matches an unused, unexpired grant
254
+ * for exactly its params. Each grant admits one request.
255
+ */
256
+ grantApproval(grant: OUIApprovalGrant): void;
244
257
  /** Called whenever the snapshot changes. */
245
258
  subscribe(listener: () => void): () => void;
246
259
  /** Stop polling, detach from the socket and forget every mount. */
@@ -1,4 +1,4 @@
1
- import { JSONSchema, OUIActionPolling, OUIActivation, OUISurface, OUISurfaceSnapshot, OUIActionRequest, OUIActionResult } from './spec/index.cjs';
1
+ import { OUIEffectKind, JSONSchema, OUIActionPolling, OUIActivation, OUISurface, OUISurfaceSnapshot, OUIActionRequest, OUIActionResult, OUIApprovalGrant } from './spec/index.cjs';
2
2
  import { S as SocketLike, d as OUITransportConfig } from './websocket-YfWILdZ4.cjs';
3
3
 
4
4
  /**
@@ -61,8 +61,13 @@ interface ActionPollingConfig<TContext = unknown> extends OUIActionPolling {
61
61
  interface ActionDefinition<TContext = unknown> {
62
62
  id: string;
63
63
  description: string;
64
+ /** Its name as a person reads it, for a confirmation the user approves. */
65
+ title?: string;
66
+ /** What using it does; a `transaction` runs only on the user's approval of the exact request. */
67
+ effect?: OUIEffectKind;
64
68
  input: JSONSchema;
65
69
  output?: JSONSchema;
70
+ /** Destructive: it runs only on the user's approval of the exact request, unless it only reads. */
66
71
  confirm?: boolean;
67
72
  async?: boolean;
68
73
  /**
@@ -241,6 +246,14 @@ interface SurfaceRuntime {
241
246
  * code still loading or a page fetching the data it will display.
242
247
  */
243
248
  hold(): () => void;
249
+ /**
250
+ * Record that the user approved one request, here, through their own
251
+ * confirmation (the agent runtime's approval store answered it to this tab).
252
+ * An action that needs approval — a `transaction`, or a destructive write —
253
+ * runs only on a request whose `approval` matches an unused, unexpired grant
254
+ * for exactly its params. Each grant admits one request.
255
+ */
256
+ grantApproval(grant: OUIApprovalGrant): void;
244
257
  /** Called whenever the snapshot changes. */
245
258
  subscribe(listener: () => void): () => void;
246
259
  /** Stop polling, detach from the socket and forget every mount. */
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkROGKEMLL_cjs = require('../chunk-ROGKEMLL.cjs');
4
- var chunkDCVVTP3V_cjs = require('../chunk-DCVVTP3V.cjs');
4
+ var chunkXUX4XVP3_cjs = require('../chunk-XUX4XVP3.cjs');
5
5
 
6
6
 
7
7
 
@@ -11,7 +11,7 @@ Object.defineProperty(exports, "createDirectTransportPair", {
11
11
  });
12
12
  Object.defineProperty(exports, "createWebSocketTransport", {
13
13
  enumerable: true,
14
- get: function () { return chunkDCVVTP3V_cjs.createWebSocketTransport; }
14
+ get: function () { return chunkXUX4XVP3_cjs.createWebSocketTransport; }
15
15
  });
16
16
  //# sourceMappingURL=index.cjs.map
17
17
  //# sourceMappingURL=index.cjs.map
@@ -1,4 +1,4 @@
1
1
  export { createDirectTransportPair } from '../chunk-IIZ6HL2L.js';
2
- export { createWebSocketTransport } from '../chunk-F3WKIRAU.js';
2
+ export { createWebSocketTransport } from '../chunk-UKKITNZK.js';
3
3
  //# sourceMappingURL=index.js.map
4
4
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "oui-spec",
3
- "version": "0.4.1",
4
- "description": "OUI — The OpenUI Specification. A machine-readable contract for agent-controllable user interfaces.",
3
+ "version": "0.5.0",
4
+ "description": "OUI \u2014 The OpenUI Specification. A machine-readable contract for agent-controllable user interfaces.",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -30,7 +30,8 @@
30
30
  "types": "./dist/transport/index.d.ts",
31
31
  "import": "./dist/transport/index.js",
32
32
  "require": "./dist/transport/index.cjs"
33
- }
33
+ },
34
+ "./approval-vectors.json": "./spec/approval-vectors.json"
34
35
  },
35
36
  "typesVersions": {
36
37
  "*": {
@@ -0,0 +1,88 @@
1
+ {
2
+ "version": 1,
3
+ "algorithm": "SHA-256 over the RFC 8785 (JCS) canonical JSON of the value, UTF-8 encoded; lowercase hex",
4
+ "use": "The approval args hash. Every implementation (an agent runtime, an approval store, the browser runtime, a gateway in another language) parses each `json`, canonicalizes it to exactly `canonical`, and hashes it to exactly `sha256`; it refuses every `invalid` input.",
5
+ "provenance": "Canonical forms derived by hand from RFC 8785 §3.2 and Appendix B; hashes computed with Python hashlib over those forms, independently of any implementation under test.",
6
+ "vectors": [
7
+ {
8
+ "name": "key order",
9
+ "json": "{\"b\":2,\"a\":1,\"c\":{\"z\":true,\"y\":null,\"x\":[3,2,1]}}",
10
+ "canonical": "{\"a\":1,\"b\":2,\"c\":{\"x\":[3,2,1],\"y\":null,\"z\":true}}",
11
+ "sha256": "a3e834099e840d9028fa0c005d117ffd5ae99f8275223ae3b64121241290958d"
12
+ },
13
+ {
14
+ "name": "key order by UTF-16 code units, not code points (RFC 8785 §3.2.3)",
15
+ "json": "{\"\\u20ac\":\"Euro Sign\",\"\\r\":\"Carriage Return\",\"\\ufb33\":\"Hebrew Letter Dalet With Dagesh\",\"1\":\"One\",\"\\ud83d\\ude00\":\"Emoji: Grinning Face\",\"\\u0080\":\"Control\",\"\\u00f6\":\"Latin Small Letter O With Diaeresis\"}",
16
+ "canonical": "{\"\\r\":\"Carriage Return\",\"1\":\"One\",\"€\":\"Control\",\"ö\":\"Latin Small Letter O With Diaeresis\",\"€\":\"Euro Sign\",\"😀\":\"Emoji: Grinning Face\",\"דּ\":\"Hebrew Letter Dalet With Dagesh\"}",
17
+ "sha256": "5e321556d22018a9656991a9e94f77ec175fa193e52a2429d312f8419ec8b08c"
18
+ },
19
+ {
20
+ "name": "key order with digits, capitals and underscore",
21
+ "json": "{\"aa\":1,\"a\":2,\"b\":3,\"A\":4,\"_\":5,\"10\":6,\"9\":7}",
22
+ "canonical": "{\"10\":6,\"9\":7,\"A\":4,\"_\":5,\"a\":2,\"aa\":1,\"b\":3}",
23
+ "sha256": "e395d6cbc8557fd7b4e4dd42af7c48c30fb4d5ec7da43567ccf39bc322ff9804"
24
+ },
25
+ {
26
+ "name": "RFC 8785 §3.2.2 example: numbers, string escapes, literals",
27
+ "json": "{\"numbers\":[333333333.33333329,1E30,4.50,2e-3,0.000000000000000000000000001],\"string\":\"\\u20ac$\\u000F\\u000aA'\\u0042\\u0022\\u005c\\\\\\\"\\/\",\"literals\":[null,true,false]}",
28
+ "canonical": "{\"literals\":[null,true,false],\"numbers\":[333333333.3333333,1e+30,4.5,0.002,1e-27],\"string\":\"€$\\u000f\\nA'B\\\"\\\\\\\\\\\"/\"}",
29
+ "sha256": "2d5e01a318d0f0879ab568c4be289c8b1f64ef8921a53c6277d5e069978baacb"
30
+ },
31
+ {
32
+ "name": "numbers: RFC 8785 Appendix B and ECMAScript formatting",
33
+ "json": "[0,-0,5e-324,-5e-324,1.7976931348623157e308,9007199254740992,1e21,999999999999999900000,0.000001,9.999999999999997e-7,1e-7,100,1.5,-1.5,123456789012345680000,1E2,0.1,-0.0000123]",
34
+ "canonical": "[0,0,5e-324,-5e-324,1.7976931348623157e+308,9007199254740992,1e+21,999999999999999900000,0.000001,9.999999999999997e-7,1e-7,100,1.5,-1.5,123456789012345680000,100,0.1,-0.0000123]",
35
+ "sha256": "6f4a14dff8d80f1da955de6c0dc2099dd8a65c8538b4cbcabf4dbf92323832d6"
36
+ },
37
+ {
38
+ "name": "nested arrays",
39
+ "json": "{\"a\":[[],[[]],[1,[2,[3,{}]]],[{\"b\":[],\"a\":{}}]]}",
40
+ "canonical": "{\"a\":[[],[[]],[1,[2,[3,{}]]],[{\"a\":{},\"b\":[]}]]}",
41
+ "sha256": "f5cb025d9d4301d5b460a2919d5d5c21856faef0fba5a987555d8be6e36cfc1a"
42
+ },
43
+ {
44
+ "name": "empty object",
45
+ "json": "{}",
46
+ "canonical": "{}",
47
+ "sha256": "44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a"
48
+ },
49
+ {
50
+ "name": "empty members",
51
+ "json": "{ \"c\" : \"\", \"b\" : [ ], \"a\" : { } }",
52
+ "canonical": "{\"a\":{},\"b\":[],\"c\":\"\"}",
53
+ "sha256": "e052004170cc85d084722ffe760c499548014bfdbdf5275548b688255770dfc2"
54
+ },
55
+ {
56
+ "name": "Unicode and control characters in strings",
57
+ "json": "{\"s\":\"line1\\nline2\\ttab \\u0000 \\u001f \\u007f \\u2028 \\b\\f\\r é 中文 \\ud83d\\ude00 \\\"q\\\" \\\\ \\/\"}",
58
+ "canonical": "{\"s\":\"line1\\nline2\\ttab \\u0000 \\u001f  
 \\b\\f\\r é 中文 😀 \\\"q\\\" \\\\ /\"}",
59
+ "sha256": "0704f4e91b2358f88126313e3d01b58887d0222527f54a365f7c47284701f77b"
60
+ },
61
+ {
62
+ "name": "a tool call's arguments",
63
+ "json": "{\"to\":\"cfo@desk.example\",\"reportId\":\"q3-2026\",\"amount\":1250.5,\"lines\":[{\"sku\":\"A-1\",\"qty\":2},{\"qty\":1,\"sku\":\"B-7\"}],\"note\":null,\"urgent\":false}",
64
+ "canonical": "{\"amount\":1250.5,\"lines\":[{\"qty\":2,\"sku\":\"A-1\"},{\"qty\":1,\"sku\":\"B-7\"}],\"note\":null,\"reportId\":\"q3-2026\",\"to\":\"cfo@desk.example\",\"urgent\":false}",
65
+ "sha256": "9fca331ee3441ff41fb72daf559bb93cb062624683e896fad0ba11f1ebfa39b3"
66
+ },
67
+ {
68
+ "name": "an order",
69
+ "json": "{\"side\":\"buy\",\"symbol\":\"ACME\",\"quantity\":100,\"limitPrice\":12.34,\"timeInForce\":\"day\"}",
70
+ "canonical": "{\"limitPrice\":12.34,\"quantity\":100,\"side\":\"buy\",\"symbol\":\"ACME\",\"timeInForce\":\"day\"}",
71
+ "sha256": "95d63838fb17517676ce7070891709fc5fdb1bc21bd378f44f20aa1e463d7024"
72
+ }
73
+ ],
74
+ "invalid": [
75
+ {
76
+ "name": "a lone high surrogate",
77
+ "json": "{\"s\":\"\\ud800\"}"
78
+ },
79
+ {
80
+ "name": "a lone low surrogate",
81
+ "json": "{\"s\":\"a\\udc00b\"}"
82
+ },
83
+ {
84
+ "name": "a lone surrogate in a key",
85
+ "json": "{\"\\udbff\":1}"
86
+ }
87
+ ]
88
+ }
@@ -1,12 +0,0 @@
1
- // src/spec/types.ts
2
- var OUI_PROTOCOL_EVENTS = {
3
- SURFACE_REGISTER: "surface:register",
4
- SURFACE_DEREGISTER: "surface:deregister",
5
- ACTION_REQUEST: "action:request",
6
- ACTION_RESULT: "action:result",
7
- OBSERVATION_UPDATE: "observation:update"
8
- };
9
-
10
- export { OUI_PROTOCOL_EVENTS };
11
- //# sourceMappingURL=chunk-BMCL2K74.js.map
12
- //# sourceMappingURL=chunk-BMCL2K74.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/spec/types.ts"],"names":[],"mappings":";AAiUO,IAAM,mBAAA,GAAsB;AAAA,EACjC,gBAAA,EAAkB,kBAAA;AAAA,EAClB,kBAAA,EAAoB,oBAAA;AAAA,EACpB,cAAA,EAAgB,gBAAA;AAAA,EAChB,aAAA,EAAe,eAAA;AAAA,EACf,kBAAA,EAAoB;AACtB","file":"chunk-BMCL2K74.js","sourcesContent":["/**\n * OUI — Open UI Specification\n *\n * The machine-readable contract for agent-controllable user interfaces.\n * Any UI application that implements this interface can be controlled by\n * any OUI-compatible agent runtime.\n */\n\n/** JSON Schema type (subset used by OUI) */\nexport type JSONSchema = {\n type?: string | string[];\n properties?: Record<string, JSONSchema>;\n items?: JSONSchema;\n required?: string[];\n enum?: (string | number | boolean)[];\n description?: string;\n default?: unknown;\n oneOf?: JSONSchema[];\n anyOf?: JSONSchema[];\n allOf?: JSONSchema[];\n const?: unknown;\n minimum?: number;\n maximum?: number;\n minLength?: number;\n maxLength?: number;\n pattern?: string;\n format?: string;\n additionalProperties?: boolean | JSONSchema;\n};\n\n/**\n * A Surface is a controllable boundary within an application.\n * It declares what an agent can do (actions), what it can observe (state),\n * and when it's available (activation conditions).\n *\n * Think of it as \"one page\" or \"one feature\" of an application, described\n * in a way that an agent can understand and operate.\n */\nexport interface OUISurface {\n /** Unique identifier for this surface (e.g., 'dataviz-wizard', 'document-editor') */\n id: string;\n\n /** Human-readable name */\n name: string;\n\n /** Description of what this surface does — included in agent context */\n description: string;\n\n /** Version of this surface's contract (semver) */\n version?: string;\n\n /** Actions the agent can invoke on this surface */\n actions: OUIAction[];\n\n /** Observable state the agent can read */\n observations?: OUIObservation[];\n\n /** When this surface is active/available */\n activation?: OUIActivation;\n\n /** Additional metadata for agent context */\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Declarative polling configuration for async actions.\n * The OUI runtime in the browser manages the polling lifecycle automatically\n * after the action handler returns its dispatch result.\n */\nexport interface OUIActionPolling {\n /** How often to check (milliseconds) */\n intervalMs: number;\n\n /** Max poll attempts before giving up (optional) */\n maxAttempts?: number;\n\n /** Max total duration before giving up in ms (alternative to maxAttempts) */\n maxDurationMs?: number;\n\n /**\n * Subscribe to a realtime event instead of polling.\n * If provided, the runtime listens for this event instead of using setInterval.\n * More efficient when realtime infrastructure exists.\n */\n subscribe?: {\n /** Event name to listen for */\n event: string;\n /**\n * Filter to match the event. Values prefixed with '$dispatchResult.'\n * are resolved from the handler's return value.\n * Example: { jobId: '$dispatchResult.jobId' }\n */\n filter?: Record<string, unknown>;\n };\n}\n\n/**\n * An Action is a single operation an agent can perform on a surface.\n * Each action becomes a \"tool\" that the LLM can call.\n *\n * The action's handler executes in the UI (or API) and returns a result\n * that the agent sees as the tool's output.\n */\nexport interface OUIAction {\n /** Unique action identifier (becomes the tool name) */\n id: string;\n\n /** Human-readable description — this is what the LLM reads to decide when to use it */\n description: string;\n\n /** JSON Schema for the action's input parameters */\n input: JSONSchema;\n\n /** JSON Schema for the action's return value (optional — agent still gets the result) */\n output?: JSONSchema;\n\n /** If true, the agent runtime should confirm with the user before executing */\n confirm?: boolean;\n\n /** If true, the action is async — returns immediately with a job/tracking ID */\n async?: boolean;\n\n /** Declarative polling configuration — runtime manages the polling lifecycle after dispatch */\n polling?: OUIActionPolling;\n\n /** Human-readable hint about when this action is appropriate to use */\n usage?: string;\n\n /**\n * Preconditions that should be met before this action is called.\n * Expressed as a description (for the LLM) not as executable logic.\n */\n preconditions?: string;\n\n /** Estimated duration hint (e.g., \"instant\", \"2-5s\", \"30-120s\") */\n estimatedDuration?: string;\n\n /** Tags for categorization */\n tags?: string[];\n}\n\n/**\n * An Observation is a piece of application state that the agent can read.\n * Observations are pushed to the agent in real-time as the app state changes,\n * giving it situational awareness without needing screenshots.\n */\nexport interface OUIObservation {\n /** Unique identifier for this observation */\n id: string;\n\n /** Description of what this observation represents */\n description: string;\n\n /** JSON Schema for the observation's value */\n schema: JSONSchema;\n\n /** How frequently this observation updates */\n updateFrequency?: \"realtime\" | \"on-change\" | \"polling\";\n}\n\n/**\n * Activation conditions — when a surface is available to the agent.\n * A surface might only be active on a specific page, when certain\n * entities are loaded, or under specific application states.\n */\nexport interface OUIActivation {\n /** URL path(s) where this surface is active */\n routes?: string | string[];\n\n /** Entity type/ID that must be present for this surface to activate */\n entity?: {\n type: string;\n id?: string;\n };\n\n /** Custom predicate description (for documentation, not execution) */\n condition?: string;\n}\n\n// ─── Protocol Types ──────────────────────────────────────────────────────────\n\n/**\n * A request from the agent runtime to execute an action on a surface.\n */\nexport interface OUIActionRequest {\n /** Unique request ID for correlation */\n requestId: string;\n\n /** Which surface this request targets */\n surfaceId: string;\n\n /** Which action to invoke */\n actionId: string;\n\n /** The action's input parameters (validated against the action's input schema) */\n params: Record<string, unknown>;\n\n /** Timestamp of the request */\n timestamp: number;\n}\n\n/**\n * The result of an action execution, returned from the surface to the agent.\n */\nexport interface OUIActionResult {\n /** Correlates to the request */\n requestId: string;\n\n /** Whether the action succeeded */\n success: boolean;\n\n /** The action's return data (if successful) */\n data?: unknown;\n\n /** Error information (if failed) */\n error?: {\n code: string;\n message: string;\n details?: unknown;\n };\n\n /** Progress indicator for interim polling results (0-100) */\n progress?: number;\n\n /** Whether this is an interim update (polling still in progress) or final */\n interim?: boolean;\n\n /** Duration of execution in milliseconds */\n durationMs?: number;\n\n /** Timestamp of the result */\n timestamp: number;\n\n /**\n * The surfaces active on the client once the action's effects settled.\n *\n * An action can change what the agent is able to do next: navigating\n * unmounts one page's surfaces and mounts another's. Without this, the agent\n * would act on the capability set it had before the action, which is the\n * set the action just replaced.\n */\n surfaces?: OUISurface[];\n\n /** Latest observation values per surface once the action's effects settled. */\n observations?: OUIObservationSnapshot;\n\n /**\n * False when the client's deadline passed before its UI settled, so\n * `surfaces` and `observations` may still be changing. Absent or true\n * otherwise.\n */\n settled?: boolean;\n}\n\n/** Latest observation values, keyed by surface id and then observation id. */\nexport type OUIObservationSnapshot = Record<string, Record<string, unknown>>;\n\n/**\n * What a client can do right now: the surfaces it has mounted and their latest\n * observation values. A client sends this to its agent runtime (for example,\n * with each turn), and returns it on every action result.\n */\nexport interface OUISurfaceSnapshot {\n surfaces: OUISurface[];\n observations: OUIObservationSnapshot;\n}\n\n/**\n * An observation update pushed from the surface to the agent.\n */\nexport interface OUIObservationUpdate {\n /** Which surface this observation belongs to */\n surfaceId: string;\n\n /** Which observation updated */\n observationId: string;\n\n /** The new value */\n value: unknown;\n\n /** Timestamp of the update */\n timestamp: number;\n}\n\n/**\n * Surface registration event — sent when a surface becomes active.\n */\nexport interface OUISurfaceRegistration {\n /** The full surface manifest */\n surface: OUISurface;\n\n /** Timestamp of registration */\n timestamp: number;\n}\n\n/**\n * Surface deregistration event — sent when a surface becomes inactive.\n */\nexport interface OUISurfaceDeregistration {\n /** Which surface is being deregistered */\n surfaceId: string;\n\n /** Timestamp */\n timestamp: number;\n}\n\n// ─── Transport Protocol Events ───────────────────────────────────────────────\n\n/**\n * All protocol events exchanged between agent runtime and surfaces.\n */\nexport type OUIProtocolEvent =\n | { type: \"surface:register\"; payload: OUISurfaceRegistration }\n | { type: \"surface:deregister\"; payload: OUISurfaceDeregistration }\n | { type: \"action:request\"; payload: OUIActionRequest }\n | { type: \"action:result\"; payload: OUIActionResult }\n | { type: \"observation:update\"; payload: OUIObservationUpdate };\n\n/**\n * Protocol event type strings (for type guards and routing).\n */\nexport const OUI_PROTOCOL_EVENTS = {\n SURFACE_REGISTER: \"surface:register\",\n SURFACE_DEREGISTER: \"surface:deregister\",\n ACTION_REQUEST: \"action:request\",\n ACTION_RESULT: \"action:result\",\n OBSERVATION_UPDATE: \"observation:update\",\n} as const;\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/transport/websocket.ts"],"names":[],"mappings":";;;AAyBO,SAAS,wBAAA,CACd,QACA,MAAA,EACc;AACd,EAAA,MAAM,EAAA,GAAK,QAAQ,SAAA,IAAa,KAAA;AAChC,EAAA,MAAM,SAAkD,EAAC;AACzD,EAAA,MAAM,SAAA,GAAY,QAAQ,a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CAAA;AAAA,IACF,CAAA;AAAA,IAEA,OAAA,GAAU;AACR,MAAA,KAAA,MAAW,EAAE,KAAA,EAAO,OAAA,MAAa,QAAA,CAAS,MAAA,CAAO,CAAC,CAAA,EAAG;AACnD,QAAA,MAAA,CAAO,GAAA,CAAI,OAAO,OAAO,CAAA;AAAA,MAC3B;AACA,MAAA,kBAAA,CAAmB,MAAA,GAAS,CAAA;AAC5B,MAAA,MAAA,CAAO,MAAA,GAAS,CAAA;AAAA,IAClB;AAAA,GACF;AACF","file":"chunk-DCVVTP3V.cjs","sourcesContent":["import type {\n OUITransport,\n OUITransportConfig,\n OUIActionHandler,\n OUIObservationHandler,\n OUIResultHandler,\n} from \"./types.js\";\nimport type {\n OUISurface,\n OUIObservationUpdate,\n OUIActionRequest,\n OUIActionResult,\n} from \"../spec/index.js\";\n\n/**\n * WebSocket transport using Socket.IO.\n * Maps OUI protocol events to socket events with a configurable namespace prefix.\n *\n * Events:\n * {ns}:dispatch — action request (runtime → client)\n * {ns}:action:result — action result (client → runtime)\n * {ns}:observation — observation (client → runtime)\n * {ns}:surface:register — registration (client → runtime)\n * {ns}:surface:deregister — deregistration (client → runtime)\n */\nexport function createWebSocketTransport(\n socket: SocketLike,\n config?: OUITransportConfig,\n): OUITransport {\n const ns = config?.namespace ?? \"oui\";\n const buffer: Array<{ event: string; data: unknown }> = [];\n const maxBuffer = config?.maxBufferSize ?? 100;\n const shouldBuffer = config?.bufferWhileDisconnected ?? true;\n\n let connected = socket.connected ?? false;\n const connectionHandlers: Array<(c: boolean) => void> = [];\n\n // Every listener this transport attaches, so dispose() can remove exactly\n // these and nothing the integrator attached to the same socket.\n const attached: Array<{ event: string; handler: (...args: any[]) => void }> =\n [];\n function listen(\n event: string,\n handler: (...args: any[]) => void,\n ): () => void {\n socket.on(event, handler);\n const entry = { event, handler };\n attached.push(entry);\n return () => {\n socket.off(event, handler);\n const i = attached.indexOf(entry);\n if (i >= 0) attached.splice(i, 1);\n };\n }\n\n listen(\"connect\", () => {\n connected = true;\n // Flush before announcing: anything queued while offline was sent earlier\n // than whatever a connection handler is about to send.\n if (shouldBuffer) {\n while (buffer.length > 0) {\n const msg = buffer.shift()!;\n socket.emit(msg.event, msg.data);\n }\n }\n connectionHandlers.forEach((h) => h(true));\n });\n\n listen(\"disconnect\", () => {\n connected = false;\n connectionHandlers.forEach((h) => h(false));\n });\n\n function emit(event: string, data: unknown) {\n if (connected) {\n socket.emit(event, data);\n } else if (shouldBuffer && buffer.length < maxBuffer) {\n buffer.push({ event, data });\n }\n }\n\n return {\n // ─── Dispatch ───────────────────────────────────────────────\n dispatch(request: OUIActionRequest) {\n emit(`${ns}:dispatch`, request);\n },\n\n onAction(handler: OUIActionHandler) {\n return listen(\n `${ns}:dispatch`,\n (data: Partial<OUIActionRequest> | undefined) => {\n // A request without a requestId cannot be answered, and answering is\n // the contract. Refuse it loudly rather than run an action whose\n // result has nowhere to go.\n if (\n !data ||\n typeof data.requestId !== \"string\" ||\n !data.requestId ||\n typeof data.surfaceId !== \"string\" ||\n typeof data.actionId !== \"string\"\n ) {\n console.warn(\n \"[OUI] Dropped a dispatch without requestId/surfaceId/actionId\",\n data,\n );\n return;\n }\n handler({\n requestId: data.requestId,\n surfaceId: data.surfaceId,\n actionId: data.actionId,\n params: data.params ?? {},\n timestamp: data.timestamp ?? Date.now(),\n });\n },\n );\n },\n\n // ─── Result ─────────────────────────────────────────────────\n sendResult(result: OUIActionResult) {\n emit(`${ns}:action:result`, result);\n },\n\n onResult(handler: OUIResultHandler) {\n return listen(`${ns}:action:result`, (data: OUIActionResult) =>\n handler(data),\n );\n },\n\n // ─── Observation Channel ────────────────────────────────────\n pushObservation(update: OUIObservationUpdate) {\n emit(`${ns}:observation`, update);\n },\n\n onObservation(handler: OUIObservationHandler) {\n return listen(`${ns}:observation`, (data: OUIObservationUpdate) =>\n handler(data),\n );\n },\n\n // ─── Surface Lifecycle ──────────────────────────────────────\n registerSurface(surface: OUISurface) {\n emit(`${ns}:surface:register`, { surface, timestamp: Date.now() });\n },\n\n deregisterSurface(surfaceId: string) {\n emit(`${ns}:surface:deregister`, { surfaceId, timestamp: Date.now() });\n },\n\n onSurfaceRegister(handler: (surface: OUISurface) => void) {\n return listen(`${ns}:surface:register`, (data: { surface: OUISurface }) =>\n handler(data.surface),\n );\n },\n\n onSurfaceDeregister(handler: (surfaceId: string) => void) {\n return listen(`${ns}:surface:deregister`, (data: { surfaceId: string }) =>\n handler(data.surfaceId),\n );\n },\n\n // ─── Connection ─────────────────────────────────────────────\n get connected() {\n return connected;\n },\n\n async connect() {\n if (connected) return;\n return new Promise<void>((resolve, reject) => {\n const timeout = setTimeout(() => {\n reject(\n new Error(\n `OUI transport connect timeout (${config?.connectTimeoutMs ?? 10000}ms)`,\n ),\n );\n }, config?.connectTimeoutMs ?? 10000);\n\n socket.once(\"connect\", () => {\n clearTimeout(timeout);\n resolve();\n });\n\n if (typeof socket.connect === \"function\") {\n socket.connect();\n }\n });\n },\n\n disconnect() {\n if (typeof socket.disconnect === \"function\") {\n socket.disconnect();\n }\n },\n\n onConnectionChange(handler: (c: boolean) => void) {\n connectionHandlers.push(handler);\n return () => {\n const idx = connectionHandlers.indexOf(handler);\n if (idx >= 0) connectionHandlers.splice(idx, 1);\n };\n },\n\n dispose() {\n for (const { event, handler } of attached.splice(0)) {\n socket.off(event, handler);\n }\n connectionHandlers.length = 0;\n buffer.length = 0;\n },\n };\n}\n\n/**\n * Minimal socket interface — compatible with Socket.IO client or server socket.\n * Only the methods OUI actually uses.\n */\nexport interface SocketLike {\n readonly connected?: boolean;\n emit(event: string, data: unknown): void;\n on(event: string, handler: (...args: any[]) => void): void;\n off(event: string, handler: (...args: any[]) => void): void;\n once(event: string, handler: (...args: any[]) => void): void;\n connect?(): void;\n disconnect?(): void;\n}\n"]}