oui-spec 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 (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +680 -0
  3. package/dist/chunk-2ON5IEXB.cjs +167 -0
  4. package/dist/chunk-2ON5IEXB.cjs.map +1 -0
  5. package/dist/chunk-3DCIL4FV.cjs +14 -0
  6. package/dist/chunk-3DCIL4FV.cjs.map +1 -0
  7. package/dist/chunk-7EXSMPGR.js +207 -0
  8. package/dist/chunk-7EXSMPGR.js.map +1 -0
  9. package/dist/chunk-CVUUSPF4.js +12 -0
  10. package/dist/chunk-CVUUSPF4.js.map +1 -0
  11. package/dist/chunk-JO5LGOB6.js +88 -0
  12. package/dist/chunk-JO5LGOB6.js.map +1 -0
  13. package/dist/chunk-LEXIU2MH.cjs +90 -0
  14. package/dist/chunk-LEXIU2MH.cjs.map +1 -0
  15. package/dist/chunk-UIGRLZOX.js +164 -0
  16. package/dist/chunk-UIGRLZOX.js.map +1 -0
  17. package/dist/chunk-WZXUKJ7E.cjs +210 -0
  18. package/dist/chunk-WZXUKJ7E.cjs.map +1 -0
  19. package/dist/core/index.cjs +17 -0
  20. package/dist/core/index.cjs.map +1 -0
  21. package/dist/core/index.d.cts +120 -0
  22. package/dist/core/index.d.ts +120 -0
  23. package/dist/core/index.js +4 -0
  24. package/dist/core/index.js.map +1 -0
  25. package/dist/index.cjs +35 -0
  26. package/dist/index.cjs.map +1 -0
  27. package/dist/index.d.cts +4 -0
  28. package/dist/index.d.ts +4 -0
  29. package/dist/index.js +6 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/react/index.cjs +16 -0
  32. package/dist/react/index.cjs.map +1 -0
  33. package/dist/react/index.d.cts +62 -0
  34. package/dist/react/index.d.ts +62 -0
  35. package/dist/react/index.js +3 -0
  36. package/dist/react/index.js.map +1 -0
  37. package/dist/spec/index.cjs +12 -0
  38. package/dist/spec/index.cjs.map +1 -0
  39. package/dist/spec/index.d.cts +249 -0
  40. package/dist/spec/index.d.ts +249 -0
  41. package/dist/spec/index.js +3 -0
  42. package/dist/spec/index.js.map +1 -0
  43. package/dist/transport/index.cjs +16 -0
  44. package/dist/transport/index.cjs.map +1 -0
  45. package/dist/transport/index.d.cts +91 -0
  46. package/dist/transport/index.d.ts +91 -0
  47. package/dist/transport/index.js +3 -0
  48. package/dist/transport/index.js.map +1 -0
  49. package/package.json +109 -0
  50. package/spec/OUI-SPEC-v0.1.md +1323 -0
@@ -0,0 +1,249 @@
1
+ /**
2
+ * OUI — Open UI Specification
3
+ *
4
+ * The machine-readable contract for agent-controllable user interfaces.
5
+ * Any UI application that implements this interface can be controlled by
6
+ * any OUI-compatible agent runtime.
7
+ */
8
+ /** JSON Schema type (subset used by OUI) */
9
+ type JSONSchema = {
10
+ type?: string | string[];
11
+ properties?: Record<string, JSONSchema>;
12
+ items?: JSONSchema;
13
+ required?: string[];
14
+ enum?: (string | number | boolean)[];
15
+ description?: string;
16
+ default?: unknown;
17
+ oneOf?: JSONSchema[];
18
+ anyOf?: JSONSchema[];
19
+ allOf?: JSONSchema[];
20
+ const?: unknown;
21
+ minimum?: number;
22
+ maximum?: number;
23
+ minLength?: number;
24
+ maxLength?: number;
25
+ pattern?: string;
26
+ format?: string;
27
+ additionalProperties?: boolean | JSONSchema;
28
+ };
29
+ /**
30
+ * A Surface is a controllable boundary within an application.
31
+ * It declares what an agent can do (actions), what it can observe (state),
32
+ * and when it's available (activation conditions).
33
+ *
34
+ * Think of it as "one page" or "one feature" of an application, described
35
+ * in a way that an agent can understand and operate.
36
+ */
37
+ interface OUISurface {
38
+ /** Unique identifier for this surface (e.g., 'dataviz-wizard', 'document-editor') */
39
+ id: string;
40
+ /** Human-readable name */
41
+ name: string;
42
+ /** Description of what this surface does — included in agent context */
43
+ description: string;
44
+ /** Version of this surface's contract (semver) */
45
+ version?: string;
46
+ /** Actions the agent can invoke on this surface */
47
+ actions: OUIAction[];
48
+ /** Observable state the agent can read */
49
+ observations?: OUIObservation[];
50
+ /** When this surface is active/available */
51
+ activation?: OUIActivation;
52
+ /** Additional metadata for agent context */
53
+ metadata?: Record<string, unknown>;
54
+ }
55
+ /**
56
+ * Declarative polling configuration for async actions.
57
+ * The OUI runtime in the browser manages the polling lifecycle automatically
58
+ * after the action handler returns its dispatch result.
59
+ */
60
+ interface OUIActionPolling {
61
+ /** How often to check (milliseconds) */
62
+ intervalMs: number;
63
+ /** Max poll attempts before giving up (optional) */
64
+ maxAttempts?: number;
65
+ /** Max total duration before giving up in ms (alternative to maxAttempts) */
66
+ maxDurationMs?: number;
67
+ /**
68
+ * Subscribe to a realtime event instead of polling.
69
+ * If provided, the runtime listens for this event instead of using setInterval.
70
+ * More efficient when realtime infrastructure exists.
71
+ */
72
+ subscribe?: {
73
+ /** Event name to listen for */
74
+ event: string;
75
+ /**
76
+ * Filter to match the event. Values prefixed with '$dispatchResult.'
77
+ * are resolved from the handler's return value.
78
+ * Example: { jobId: '$dispatchResult.jobId' }
79
+ */
80
+ filter?: Record<string, unknown>;
81
+ };
82
+ }
83
+ /**
84
+ * An Action is a single operation an agent can perform on a surface.
85
+ * Each action becomes a "tool" that the LLM can call.
86
+ *
87
+ * The action's handler executes in the UI (or API) and returns a result
88
+ * that the agent sees as the tool's output.
89
+ */
90
+ interface OUIAction {
91
+ /** Unique action identifier (becomes the tool name) */
92
+ id: string;
93
+ /** Human-readable description — this is what the LLM reads to decide when to use it */
94
+ description: string;
95
+ /** JSON Schema for the action's input parameters */
96
+ input: JSONSchema;
97
+ /** JSON Schema for the action's return value (optional — agent still gets the result) */
98
+ output?: JSONSchema;
99
+ /** If true, the agent runtime should confirm with the user before executing */
100
+ confirm?: boolean;
101
+ /** If true, the action is async — returns immediately with a job/tracking ID */
102
+ async?: boolean;
103
+ /** Declarative polling configuration — runtime manages the polling lifecycle after dispatch */
104
+ polling?: OUIActionPolling;
105
+ /** Human-readable hint about when this action is appropriate to use */
106
+ usage?: string;
107
+ /**
108
+ * Preconditions that should be met before this action is called.
109
+ * Expressed as a description (for the LLM) not as executable logic.
110
+ */
111
+ preconditions?: string;
112
+ /** Estimated duration hint (e.g., "instant", "2-5s", "30-120s") */
113
+ estimatedDuration?: string;
114
+ /** Tags for categorization */
115
+ tags?: string[];
116
+ }
117
+ /**
118
+ * An Observation is a piece of application state that the agent can read.
119
+ * Observations are pushed to the agent in real-time as the app state changes,
120
+ * giving it situational awareness without needing screenshots.
121
+ */
122
+ interface OUIObservation {
123
+ /** Unique identifier for this observation */
124
+ id: string;
125
+ /** Description of what this observation represents */
126
+ description: string;
127
+ /** JSON Schema for the observation's value */
128
+ schema: JSONSchema;
129
+ /** How frequently this observation updates */
130
+ updateFrequency?: 'realtime' | 'on-change' | 'polling';
131
+ }
132
+ /**
133
+ * Activation conditions — when a surface is available to the agent.
134
+ * A surface might only be active on a specific page, when certain
135
+ * entities are loaded, or under specific application states.
136
+ */
137
+ interface OUIActivation {
138
+ /** URL path(s) where this surface is active */
139
+ routes?: string | string[];
140
+ /** Entity type/ID that must be present for this surface to activate */
141
+ entity?: {
142
+ type: string;
143
+ id?: string;
144
+ };
145
+ /** Custom predicate description (for documentation, not execution) */
146
+ condition?: string;
147
+ }
148
+ /**
149
+ * A request from the agent runtime to execute an action on a surface.
150
+ */
151
+ interface OUIActionRequest {
152
+ /** Unique request ID for correlation */
153
+ requestId: string;
154
+ /** Which surface this request targets */
155
+ surfaceId: string;
156
+ /** Which action to invoke */
157
+ actionId: string;
158
+ /** The action's input parameters (validated against the action's input schema) */
159
+ params: Record<string, unknown>;
160
+ /** Timestamp of the request */
161
+ timestamp: number;
162
+ }
163
+ /**
164
+ * The result of an action execution, returned from the surface to the agent.
165
+ */
166
+ interface OUIActionResult {
167
+ /** Correlates to the request */
168
+ requestId: string;
169
+ /** Whether the action succeeded */
170
+ success: boolean;
171
+ /** The action's return data (if successful) */
172
+ data?: unknown;
173
+ /** Error information (if failed) */
174
+ error?: {
175
+ code: string;
176
+ message: string;
177
+ details?: unknown;
178
+ };
179
+ /** Progress indicator for interim polling results (0-100) */
180
+ progress?: number;
181
+ /** Whether this is an interim update (polling still in progress) or final */
182
+ interim?: boolean;
183
+ /** Duration of execution in milliseconds */
184
+ durationMs?: number;
185
+ /** Timestamp of the result */
186
+ timestamp: number;
187
+ }
188
+ /**
189
+ * An observation update pushed from the surface to the agent.
190
+ */
191
+ interface OUIObservationUpdate {
192
+ /** Which surface this observation belongs to */
193
+ surfaceId: string;
194
+ /** Which observation updated */
195
+ observationId: string;
196
+ /** The new value */
197
+ value: unknown;
198
+ /** Timestamp of the update */
199
+ timestamp: number;
200
+ }
201
+ /**
202
+ * Surface registration event — sent when a surface becomes active.
203
+ */
204
+ interface OUISurfaceRegistration {
205
+ /** The full surface manifest */
206
+ surface: OUISurface;
207
+ /** Timestamp of registration */
208
+ timestamp: number;
209
+ }
210
+ /**
211
+ * Surface deregistration event — sent when a surface becomes inactive.
212
+ */
213
+ interface OUISurfaceDeregistration {
214
+ /** Which surface is being deregistered */
215
+ surfaceId: string;
216
+ /** Timestamp */
217
+ timestamp: number;
218
+ }
219
+ /**
220
+ * All protocol events exchanged between agent runtime and surfaces.
221
+ */
222
+ type OUIProtocolEvent = {
223
+ type: 'surface:register';
224
+ payload: OUISurfaceRegistration;
225
+ } | {
226
+ type: 'surface:deregister';
227
+ payload: OUISurfaceDeregistration;
228
+ } | {
229
+ type: 'action:request';
230
+ payload: OUIActionRequest;
231
+ } | {
232
+ type: 'action:result';
233
+ payload: OUIActionResult;
234
+ } | {
235
+ type: 'observation:update';
236
+ payload: OUIObservationUpdate;
237
+ };
238
+ /**
239
+ * Protocol event type strings (for type guards and routing).
240
+ */
241
+ declare const OUI_PROTOCOL_EVENTS: {
242
+ readonly SURFACE_REGISTER: "surface:register";
243
+ readonly SURFACE_DEREGISTER: "surface:deregister";
244
+ readonly ACTION_REQUEST: "action:request";
245
+ readonly ACTION_RESULT: "action:result";
246
+ readonly OBSERVATION_UPDATE: "observation:update";
247
+ };
248
+
249
+ export { type JSONSchema, type OUIAction, type OUIActionPolling, type OUIActionRequest, type OUIActionResult, type OUIActivation, type OUIObservation, type OUIObservationUpdate, type OUIProtocolEvent, type OUISurface, type OUISurfaceDeregistration, type OUISurfaceRegistration, OUI_PROTOCOL_EVENTS };
@@ -0,0 +1,249 @@
1
+ /**
2
+ * OUI — Open UI Specification
3
+ *
4
+ * The machine-readable contract for agent-controllable user interfaces.
5
+ * Any UI application that implements this interface can be controlled by
6
+ * any OUI-compatible agent runtime.
7
+ */
8
+ /** JSON Schema type (subset used by OUI) */
9
+ type JSONSchema = {
10
+ type?: string | string[];
11
+ properties?: Record<string, JSONSchema>;
12
+ items?: JSONSchema;
13
+ required?: string[];
14
+ enum?: (string | number | boolean)[];
15
+ description?: string;
16
+ default?: unknown;
17
+ oneOf?: JSONSchema[];
18
+ anyOf?: JSONSchema[];
19
+ allOf?: JSONSchema[];
20
+ const?: unknown;
21
+ minimum?: number;
22
+ maximum?: number;
23
+ minLength?: number;
24
+ maxLength?: number;
25
+ pattern?: string;
26
+ format?: string;
27
+ additionalProperties?: boolean | JSONSchema;
28
+ };
29
+ /**
30
+ * A Surface is a controllable boundary within an application.
31
+ * It declares what an agent can do (actions), what it can observe (state),
32
+ * and when it's available (activation conditions).
33
+ *
34
+ * Think of it as "one page" or "one feature" of an application, described
35
+ * in a way that an agent can understand and operate.
36
+ */
37
+ interface OUISurface {
38
+ /** Unique identifier for this surface (e.g., 'dataviz-wizard', 'document-editor') */
39
+ id: string;
40
+ /** Human-readable name */
41
+ name: string;
42
+ /** Description of what this surface does — included in agent context */
43
+ description: string;
44
+ /** Version of this surface's contract (semver) */
45
+ version?: string;
46
+ /** Actions the agent can invoke on this surface */
47
+ actions: OUIAction[];
48
+ /** Observable state the agent can read */
49
+ observations?: OUIObservation[];
50
+ /** When this surface is active/available */
51
+ activation?: OUIActivation;
52
+ /** Additional metadata for agent context */
53
+ metadata?: Record<string, unknown>;
54
+ }
55
+ /**
56
+ * Declarative polling configuration for async actions.
57
+ * The OUI runtime in the browser manages the polling lifecycle automatically
58
+ * after the action handler returns its dispatch result.
59
+ */
60
+ interface OUIActionPolling {
61
+ /** How often to check (milliseconds) */
62
+ intervalMs: number;
63
+ /** Max poll attempts before giving up (optional) */
64
+ maxAttempts?: number;
65
+ /** Max total duration before giving up in ms (alternative to maxAttempts) */
66
+ maxDurationMs?: number;
67
+ /**
68
+ * Subscribe to a realtime event instead of polling.
69
+ * If provided, the runtime listens for this event instead of using setInterval.
70
+ * More efficient when realtime infrastructure exists.
71
+ */
72
+ subscribe?: {
73
+ /** Event name to listen for */
74
+ event: string;
75
+ /**
76
+ * Filter to match the event. Values prefixed with '$dispatchResult.'
77
+ * are resolved from the handler's return value.
78
+ * Example: { jobId: '$dispatchResult.jobId' }
79
+ */
80
+ filter?: Record<string, unknown>;
81
+ };
82
+ }
83
+ /**
84
+ * An Action is a single operation an agent can perform on a surface.
85
+ * Each action becomes a "tool" that the LLM can call.
86
+ *
87
+ * The action's handler executes in the UI (or API) and returns a result
88
+ * that the agent sees as the tool's output.
89
+ */
90
+ interface OUIAction {
91
+ /** Unique action identifier (becomes the tool name) */
92
+ id: string;
93
+ /** Human-readable description — this is what the LLM reads to decide when to use it */
94
+ description: string;
95
+ /** JSON Schema for the action's input parameters */
96
+ input: JSONSchema;
97
+ /** JSON Schema for the action's return value (optional — agent still gets the result) */
98
+ output?: JSONSchema;
99
+ /** If true, the agent runtime should confirm with the user before executing */
100
+ confirm?: boolean;
101
+ /** If true, the action is async — returns immediately with a job/tracking ID */
102
+ async?: boolean;
103
+ /** Declarative polling configuration — runtime manages the polling lifecycle after dispatch */
104
+ polling?: OUIActionPolling;
105
+ /** Human-readable hint about when this action is appropriate to use */
106
+ usage?: string;
107
+ /**
108
+ * Preconditions that should be met before this action is called.
109
+ * Expressed as a description (for the LLM) not as executable logic.
110
+ */
111
+ preconditions?: string;
112
+ /** Estimated duration hint (e.g., "instant", "2-5s", "30-120s") */
113
+ estimatedDuration?: string;
114
+ /** Tags for categorization */
115
+ tags?: string[];
116
+ }
117
+ /**
118
+ * An Observation is a piece of application state that the agent can read.
119
+ * Observations are pushed to the agent in real-time as the app state changes,
120
+ * giving it situational awareness without needing screenshots.
121
+ */
122
+ interface OUIObservation {
123
+ /** Unique identifier for this observation */
124
+ id: string;
125
+ /** Description of what this observation represents */
126
+ description: string;
127
+ /** JSON Schema for the observation's value */
128
+ schema: JSONSchema;
129
+ /** How frequently this observation updates */
130
+ updateFrequency?: 'realtime' | 'on-change' | 'polling';
131
+ }
132
+ /**
133
+ * Activation conditions — when a surface is available to the agent.
134
+ * A surface might only be active on a specific page, when certain
135
+ * entities are loaded, or under specific application states.
136
+ */
137
+ interface OUIActivation {
138
+ /** URL path(s) where this surface is active */
139
+ routes?: string | string[];
140
+ /** Entity type/ID that must be present for this surface to activate */
141
+ entity?: {
142
+ type: string;
143
+ id?: string;
144
+ };
145
+ /** Custom predicate description (for documentation, not execution) */
146
+ condition?: string;
147
+ }
148
+ /**
149
+ * A request from the agent runtime to execute an action on a surface.
150
+ */
151
+ interface OUIActionRequest {
152
+ /** Unique request ID for correlation */
153
+ requestId: string;
154
+ /** Which surface this request targets */
155
+ surfaceId: string;
156
+ /** Which action to invoke */
157
+ actionId: string;
158
+ /** The action's input parameters (validated against the action's input schema) */
159
+ params: Record<string, unknown>;
160
+ /** Timestamp of the request */
161
+ timestamp: number;
162
+ }
163
+ /**
164
+ * The result of an action execution, returned from the surface to the agent.
165
+ */
166
+ interface OUIActionResult {
167
+ /** Correlates to the request */
168
+ requestId: string;
169
+ /** Whether the action succeeded */
170
+ success: boolean;
171
+ /** The action's return data (if successful) */
172
+ data?: unknown;
173
+ /** Error information (if failed) */
174
+ error?: {
175
+ code: string;
176
+ message: string;
177
+ details?: unknown;
178
+ };
179
+ /** Progress indicator for interim polling results (0-100) */
180
+ progress?: number;
181
+ /** Whether this is an interim update (polling still in progress) or final */
182
+ interim?: boolean;
183
+ /** Duration of execution in milliseconds */
184
+ durationMs?: number;
185
+ /** Timestamp of the result */
186
+ timestamp: number;
187
+ }
188
+ /**
189
+ * An observation update pushed from the surface to the agent.
190
+ */
191
+ interface OUIObservationUpdate {
192
+ /** Which surface this observation belongs to */
193
+ surfaceId: string;
194
+ /** Which observation updated */
195
+ observationId: string;
196
+ /** The new value */
197
+ value: unknown;
198
+ /** Timestamp of the update */
199
+ timestamp: number;
200
+ }
201
+ /**
202
+ * Surface registration event — sent when a surface becomes active.
203
+ */
204
+ interface OUISurfaceRegistration {
205
+ /** The full surface manifest */
206
+ surface: OUISurface;
207
+ /** Timestamp of registration */
208
+ timestamp: number;
209
+ }
210
+ /**
211
+ * Surface deregistration event — sent when a surface becomes inactive.
212
+ */
213
+ interface OUISurfaceDeregistration {
214
+ /** Which surface is being deregistered */
215
+ surfaceId: string;
216
+ /** Timestamp */
217
+ timestamp: number;
218
+ }
219
+ /**
220
+ * All protocol events exchanged between agent runtime and surfaces.
221
+ */
222
+ type OUIProtocolEvent = {
223
+ type: 'surface:register';
224
+ payload: OUISurfaceRegistration;
225
+ } | {
226
+ type: 'surface:deregister';
227
+ payload: OUISurfaceDeregistration;
228
+ } | {
229
+ type: 'action:request';
230
+ payload: OUIActionRequest;
231
+ } | {
232
+ type: 'action:result';
233
+ payload: OUIActionResult;
234
+ } | {
235
+ type: 'observation:update';
236
+ payload: OUIObservationUpdate;
237
+ };
238
+ /**
239
+ * Protocol event type strings (for type guards and routing).
240
+ */
241
+ declare const OUI_PROTOCOL_EVENTS: {
242
+ readonly SURFACE_REGISTER: "surface:register";
243
+ readonly SURFACE_DEREGISTER: "surface:deregister";
244
+ readonly ACTION_REQUEST: "action:request";
245
+ readonly ACTION_RESULT: "action:result";
246
+ readonly OBSERVATION_UPDATE: "observation:update";
247
+ };
248
+
249
+ export { type JSONSchema, type OUIAction, type OUIActionPolling, type OUIActionRequest, type OUIActionResult, type OUIActivation, type OUIObservation, type OUIObservationUpdate, type OUIProtocolEvent, type OUISurface, type OUISurfaceDeregistration, type OUISurfaceRegistration, OUI_PROTOCOL_EVENTS };
@@ -0,0 +1,3 @@
1
+ export { OUI_PROTOCOL_EVENTS } from '../chunk-CVUUSPF4.js';
2
+ //# sourceMappingURL=index.js.map
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ var chunkWZXUKJ7E_cjs = require('../chunk-WZXUKJ7E.cjs');
4
+
5
+
6
+
7
+ Object.defineProperty(exports, "createDirectTransportPair", {
8
+ enumerable: true,
9
+ get: function () { return chunkWZXUKJ7E_cjs.createDirectTransportPair; }
10
+ });
11
+ Object.defineProperty(exports, "createWebSocketTransport", {
12
+ enumerable: true,
13
+ get: function () { return chunkWZXUKJ7E_cjs.createWebSocketTransport; }
14
+ });
15
+ //# sourceMappingURL=index.cjs.map
16
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
@@ -0,0 +1,91 @@
1
+ import { OUIObservationUpdate, OUISurface } from '../spec/index.cjs';
2
+
3
+ /**
4
+ * OUI Transport — the wire protocol between agent runtime and surfaces.
5
+ *
6
+ * Two one-way channels:
7
+ * - Dispatch channel (server → client): sends action instructions
8
+ * - Observation channel (client → server): pushes state updates
9
+ *
10
+ * NO request/response. NO correlation IDs. NO waiting.
11
+ * The Lambda dispatches and terminates. The browser processes and pushes state.
12
+ */
13
+ interface OUITransport {
14
+ /** Dispatch an action to a surface (one-way, fire-and-forget) */
15
+ dispatch(surfaceId: string, actionId: string, params: Record<string, unknown>): void;
16
+ /** Receive dispatched actions (surface/client side) */
17
+ onAction(handler: OUIActionHandler): () => void;
18
+ /** Push an observation update from the surface to the agent runtime */
19
+ pushObservation(update: OUIObservationUpdate): void;
20
+ /** Receive observation updates (runtime/server side) */
21
+ onObservation(handler: OUIObservationHandler): () => void;
22
+ /** Register a surface manifest (client → server) */
23
+ registerSurface(surface: OUISurface): void;
24
+ /** Deregister a surface (client → server) */
25
+ deregisterSurface(surfaceId: string): void;
26
+ /** Receive surface registrations (server side) */
27
+ onSurfaceRegister(handler: (surface: OUISurface) => void): () => void;
28
+ /** Receive surface deregistrations (server side) */
29
+ onSurfaceDeregister(handler: (surfaceId: string) => void): () => void;
30
+ readonly connected: boolean;
31
+ connect(): Promise<void>;
32
+ disconnect(): void;
33
+ onConnectionChange(handler: (connected: boolean) => void): () => void;
34
+ }
35
+ /** Handler for incoming action dispatches (client side) */
36
+ type OUIActionHandler = (surfaceId: string, actionId: string, params: Record<string, unknown>) => void;
37
+ /** Handler for incoming observation updates (server side) */
38
+ type OUIObservationHandler = (update: OUIObservationUpdate) => void;
39
+ /**
40
+ * Transport configuration options.
41
+ */
42
+ interface OUITransportConfig {
43
+ /** Namespace prefix for events (default: 'oui') */
44
+ namespace?: string;
45
+ /** Connection timeout in ms */
46
+ connectTimeoutMs?: number;
47
+ /** Whether to buffer dispatches while disconnected */
48
+ bufferWhileDisconnected?: boolean;
49
+ /** Max buffer size (messages dropped after this) */
50
+ maxBufferSize?: number;
51
+ }
52
+
53
+ /**
54
+ * WebSocket transport using Socket.IO.
55
+ * Maps OUI protocol events to socket events with a configurable namespace prefix.
56
+ *
57
+ * Events emitted:
58
+ * {ns}:dispatch — action dispatch (server → client)
59
+ * {ns}:observation — observation update (client → server)
60
+ * {ns}:surface:register — surface registration (client → server)
61
+ * {ns}:surface:deregister — surface deregistration (client → server)
62
+ */
63
+ declare function createWebSocketTransport(socket: SocketLike, config?: OUITransportConfig): OUITransport;
64
+ /**
65
+ * Minimal socket interface — compatible with Socket.IO client or server socket.
66
+ * Only the methods OUI actually uses.
67
+ */
68
+ interface SocketLike {
69
+ readonly connected?: boolean;
70
+ emit(event: string, data: unknown): void;
71
+ on(event: string, handler: (...args: any[]) => void): void;
72
+ off(event: string, handler: (...args: any[]) => void): void;
73
+ once(event: string, handler: (...args: any[]) => void): void;
74
+ connect?(): void;
75
+ disconnect?(): void;
76
+ }
77
+
78
+ /**
79
+ * Direct transport — for same-process communication.
80
+ * Used for API surfaces (where the agent runtime and surface are in the same Lambda)
81
+ * and for testing (where you want synchronous, in-memory communication).
82
+ *
83
+ * Creates a paired (server, client) transport where messages sent on one
84
+ * side are immediately received on the other.
85
+ */
86
+ declare function createDirectTransportPair(): {
87
+ server: OUITransport;
88
+ client: OUITransport;
89
+ };
90
+
91
+ export { type OUIActionHandler, type OUIObservationHandler, type OUITransport, type OUITransportConfig, type SocketLike, createDirectTransportPair, createWebSocketTransport };