oui-spec 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -10
- package/dist/chunk-5TQ6AVQH.cjs +108 -0
- package/dist/chunk-5TQ6AVQH.cjs.map +1 -0
- package/dist/{chunk-LEXIU2MH.cjs → chunk-HK7OXB2W.cjs} +74 -7
- package/dist/chunk-HK7OXB2W.cjs.map +1 -0
- package/dist/{chunk-JO5LGOB6.js → chunk-ILUTAHUJ.js} +74 -8
- package/dist/chunk-ILUTAHUJ.js.map +1 -0
- package/dist/{chunk-WZXUKJ7E.cjs → chunk-MTMEW6MM.cjs} +2 -106
- package/dist/chunk-MTMEW6MM.cjs.map +1 -0
- package/dist/chunk-O6EI77LD.js +106 -0
- package/dist/chunk-O6EI77LD.js.map +1 -0
- package/dist/{chunk-7EXSMPGR.js → chunk-YDMGV72W.js} +3 -106
- package/dist/chunk-YDMGV72W.js.map +1 -0
- package/dist/core/index.cjs +7 -2
- package/dist/core/index.d.cts +116 -102
- package/dist/core/index.d.ts +116 -102
- package/dist/core/index.js +2 -1
- package/dist/define-surface-D6XPtoqu.d.cts +151 -0
- package/dist/define-surface-DXBop-uB.d.ts +151 -0
- package/dist/index.cjs +10 -5
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +3 -2
- package/dist/react/index.d.cts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/transport/index.cjs +4 -3
- package/dist/transport/index.d.cts +4 -77
- package/dist/transport/index.d.ts +4 -77
- package/dist/transport/index.js +2 -1
- package/dist/websocket-CiWvkaz_.d.ts +78 -0
- package/dist/websocket-CrI0yRNo.d.cts +78 -0
- package/package.json +4 -3
- package/dist/chunk-7EXSMPGR.js.map +0 -1
- package/dist/chunk-JO5LGOB6.js.map +0 -1
- package/dist/chunk-LEXIU2MH.cjs.map +0 -1
- package/dist/chunk-WZXUKJ7E.cjs.map +0 -1
|
@@ -101,110 +101,6 @@ function createWebSocketTransport(socket, config) {
|
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
// src/transport/direct.ts
|
|
105
|
-
function createDirectTransportPair() {
|
|
106
|
-
const actionHandlers = [];
|
|
107
|
-
const observationHandlers = [];
|
|
108
|
-
const surfaceRegisterHandlers = [];
|
|
109
|
-
const surfaceDeregisterHandlers = [];
|
|
110
|
-
const server = {
|
|
111
|
-
dispatch(surfaceId, actionId, params) {
|
|
112
|
-
actionHandlers.forEach((h) => h(surfaceId, actionId, params));
|
|
113
|
-
},
|
|
114
|
-
onAction() {
|
|
115
|
-
return () => {
|
|
116
|
-
};
|
|
117
|
-
},
|
|
118
|
-
// Server doesn't receive dispatches
|
|
119
|
-
pushObservation() {
|
|
120
|
-
},
|
|
121
|
-
// Server doesn't push observations
|
|
122
|
-
onObservation(handler) {
|
|
123
|
-
observationHandlers.push(handler);
|
|
124
|
-
return () => {
|
|
125
|
-
const i = observationHandlers.indexOf(handler);
|
|
126
|
-
if (i >= 0) observationHandlers.splice(i, 1);
|
|
127
|
-
};
|
|
128
|
-
},
|
|
129
|
-
registerSurface() {
|
|
130
|
-
},
|
|
131
|
-
deregisterSurface() {
|
|
132
|
-
},
|
|
133
|
-
onSurfaceRegister(handler) {
|
|
134
|
-
surfaceRegisterHandlers.push(handler);
|
|
135
|
-
return () => {
|
|
136
|
-
const i = surfaceRegisterHandlers.indexOf(handler);
|
|
137
|
-
if (i >= 0) surfaceRegisterHandlers.splice(i, 1);
|
|
138
|
-
};
|
|
139
|
-
},
|
|
140
|
-
onSurfaceDeregister(handler) {
|
|
141
|
-
surfaceDeregisterHandlers.push(handler);
|
|
142
|
-
return () => {
|
|
143
|
-
const i = surfaceDeregisterHandlers.indexOf(handler);
|
|
144
|
-
if (i >= 0) surfaceDeregisterHandlers.splice(i, 1);
|
|
145
|
-
};
|
|
146
|
-
},
|
|
147
|
-
get connected() {
|
|
148
|
-
return true;
|
|
149
|
-
},
|
|
150
|
-
async connect() {
|
|
151
|
-
},
|
|
152
|
-
disconnect() {
|
|
153
|
-
},
|
|
154
|
-
onConnectionChange() {
|
|
155
|
-
return () => {
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
const client = {
|
|
160
|
-
dispatch() {
|
|
161
|
-
},
|
|
162
|
-
// Client doesn't dispatch
|
|
163
|
-
onAction(handler) {
|
|
164
|
-
actionHandlers.push(handler);
|
|
165
|
-
return () => {
|
|
166
|
-
const i = actionHandlers.indexOf(handler);
|
|
167
|
-
if (i >= 0) actionHandlers.splice(i, 1);
|
|
168
|
-
};
|
|
169
|
-
},
|
|
170
|
-
pushObservation(update) {
|
|
171
|
-
observationHandlers.forEach((h) => h(update));
|
|
172
|
-
},
|
|
173
|
-
onObservation() {
|
|
174
|
-
return () => {
|
|
175
|
-
};
|
|
176
|
-
},
|
|
177
|
-
// Client doesn't receive observations
|
|
178
|
-
registerSurface(surface) {
|
|
179
|
-
surfaceRegisterHandlers.forEach((h) => h(surface));
|
|
180
|
-
},
|
|
181
|
-
deregisterSurface(surfaceId) {
|
|
182
|
-
surfaceDeregisterHandlers.forEach((h) => h(surfaceId));
|
|
183
|
-
},
|
|
184
|
-
onSurfaceRegister() {
|
|
185
|
-
return () => {
|
|
186
|
-
};
|
|
187
|
-
},
|
|
188
|
-
onSurfaceDeregister() {
|
|
189
|
-
return () => {
|
|
190
|
-
};
|
|
191
|
-
},
|
|
192
|
-
get connected() {
|
|
193
|
-
return true;
|
|
194
|
-
},
|
|
195
|
-
async connect() {
|
|
196
|
-
},
|
|
197
|
-
disconnect() {
|
|
198
|
-
},
|
|
199
|
-
onConnectionChange() {
|
|
200
|
-
return () => {
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
return { server, client };
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
exports.createDirectTransportPair = createDirectTransportPair;
|
|
208
104
|
exports.createWebSocketTransport = createWebSocketTransport;
|
|
209
|
-
//# sourceMappingURL=chunk-
|
|
210
|
-
//# sourceMappingURL=chunk-
|
|
105
|
+
//# sourceMappingURL=chunk-MTMEW6MM.cjs.map
|
|
106
|
+
//# sourceMappingURL=chunk-MTMEW6MM.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/transport/websocket.ts"],"names":[],"mappings":";;;AAaO,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,aAAA,IAAiB,GAAA;AAC3C,EAAA,MAAM,YAAA,GAAe,QAAQ,uBAAA,IAA2B,IAAA;AAExD,EAAA,IAAI,SAAA,GAAY,OAAO,SAAA,IAAa,KAAA;AACpC,EAAA,MAAM,qBAAkD,EAAC;AAGzD,EAAA,MAAA,CAAO,EAAA,CAAG,WAAW,MAAM;AACzB,IAAA,SAAA,GAAY,IAAA;AACZ,IAAA,kBAAA,CAAmB,OAAA,CAAQ,CAAA,CAAA,KAAK,CAAA,CAAE,IAAI,CAAC,CAAA;AAEvC,IAAA,IAAI,YAAA,EAAc;AAChB,MAAA,OAAO,MAAA,CAAO,SAAS,CAAA,EAAG;AACxB,QAAA,MAAM,GAAA,GAAM,OAAO,KAAA,EAAM;AACzB,QAAA,MAAA,CAAO,IAAA,CAAK,GAAA,CAAI,KAAA,EAAO,GAAA,CAAI,IAAI,CAAA;AAAA,MACjC;AAAA,IACF;AAAA,EACF,CAAC,CAAA;AAED,EAAA,MAAA,CAAO,EAAA,CAAG,cAAc,MAAM;AAC5B,IAAA,SAAA,GAAY,KAAA;AACZ,IAAA,kBAAA,CAAmB,OAAA,CAAQ,CAAA,CAAA,KAAK,CAAA,CAAE,KAAK,CAAC,CAAA;AAAA,EAC1C,CAAC,CAAA;AAED,EAAA,SAAS,IAAA,CAAK,OAAe,IAAA,EAAe;A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MAAA,IAAI,SAAA,EAAW;AACf,MAAA,OAAO,IAAI,OAAA,CAAc,CAAC,OAAA,EAAS,MAAA,KAAW;AAC5C,QAAA,MAAM,OAAA,GAAU,WAAW,MAAM;AAC/B,UAAA,MAAA,CAAO,IAAI,KAAA,CAAM,CAAA,+BAAA,EAAkC,QAAQ,gBAAA,IAAoB,GAAK,KAAK,CAAC,CAAA;AAAA,QAC5F,CAAA,EAAG,MAAA,EAAQ,gBAAA,IAAoB,GAAK,CAAA;AAEpC,QAAA,MAAA,CAAO,IAAA,CAAK,WAAW,MAAM;AAC3B,UAAA,YAAA,CAAa,OAAO,CAAA;AACpB,UAAA,OAAA,EAAQ;AAAA,QACV,CAAC,CAAA;AAED,QAAA,IAAI,OAAO,MAAA,CAAO,OAAA,KAAY,UAAA,EAAY;AACxC,UAAA,MAAA,CAAO,OAAA,EAAQ;AAAA,QACjB;AAAA,MACF,CAAC,CAAA;AAAA,IACH,CAAA;AAAA,IAEA,UAAA,GAAa;AACX,MAAA,IAAI,OAAO,MAAA,CAAO,UAAA,KAAe,UAAA,EAAY;AAC3C,QAAA,MAAA,CAAO,UAAA,EAAW;AAAA,MACpB;AAAA,IACF,CAAA;AAAA,IAEA,mBAAmB,OAAA,EAA+B;AAChD,MAAA,kBAAA,CAAmB,KAAK,OAAO,CAAA;AAC/B,MAAA,OAAO,MAAM;AACX,QAAA,MAAM,GAAA,GAAM,kBAAA,CAAmB,OAAA,CAAQ,OAAO,CAAA;AAC9C,QAAA,IAAI,GAAA,IAAO,CAAA,EAAG,kBAAA,CAAmB,MAAA,CAAO,KAAK,CAAC,CAAA;AAAA,MAChD,CAAA;AAAA,IACF;AAAA,GACF;AACF","file":"chunk-MTMEW6MM.cjs","sourcesContent":["import type { OUITransport, OUITransportConfig, OUIActionHandler, OUIObservationHandler } from './types.js';\nimport type { OUISurface, OUIObservationUpdate } 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 emitted:\n * {ns}:dispatch — action dispatch (server → client)\n * {ns}:observation — observation update (client → server)\n * {ns}:surface:register — surface registration (client → server)\n * {ns}:surface:deregister — surface deregistration (client → server)\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 // Track connection state\n socket.on('connect', () => {\n connected = true;\n connectionHandlers.forEach(h => h(true));\n // Flush buffer\n if (shouldBuffer) {\n while (buffer.length > 0) {\n const msg = buffer.shift()!;\n socket.emit(msg.event, msg.data);\n }\n }\n });\n\n socket.on('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 Channel ───────────────────────────────────────\n dispatch(surfaceId, actionId, params) {\n emit(`${ns}:dispatch`, { surfaceId, actionId, params, timestamp: Date.now() });\n },\n\n onAction(handler: OUIActionHandler) {\n const listener = (data: { surfaceId: string; actionId: string; params: Record<string, unknown> }) => {\n handler(data.surfaceId, data.actionId, data.params);\n };\n socket.on(`${ns}:dispatch`, listener);\n return () => socket.off(`${ns}:dispatch`, listener);\n },\n\n // ─── Observation Channel ────────────────────────────────────\n pushObservation(update: OUIObservationUpdate) {\n emit(`${ns}:observation`, update);\n },\n\n onObservation(handler: OUIObservationHandler) {\n const listener = (data: OUIObservationUpdate) => handler(data);\n socket.on(`${ns}:observation`, listener);\n return () => socket.off(`${ns}:observation`, listener);\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 const listener = (data: { surface: OUISurface }) => handler(data.surface);\n socket.on(`${ns}:surface:register`, listener);\n return () => socket.off(`${ns}:surface:register`, listener);\n },\n\n onSurfaceDeregister(handler: (surfaceId: string) => void) {\n const listener = (data: { surfaceId: string }) => handler(data.surfaceId);\n socket.on(`${ns}:surface:deregister`, listener);\n return () => socket.off(`${ns}:surface:deregister`, listener);\n },\n\n // ─── Connection ─────────────────────────────────────────────\n get connected() { return connected; },\n\n async connect() {\n if (connected) return;\n return new Promise<void>((resolve, reject) => {\n const timeout = setTimeout(() => {\n reject(new Error(`OUI transport connect timeout (${config?.connectTimeoutMs ?? 10000}ms)`));\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}\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"]}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// src/transport/direct.ts
|
|
2
|
+
function createDirectTransportPair() {
|
|
3
|
+
const actionHandlers = [];
|
|
4
|
+
const observationHandlers = [];
|
|
5
|
+
const surfaceRegisterHandlers = [];
|
|
6
|
+
const surfaceDeregisterHandlers = [];
|
|
7
|
+
const server = {
|
|
8
|
+
dispatch(surfaceId, actionId, params) {
|
|
9
|
+
actionHandlers.forEach((h) => h(surfaceId, actionId, params));
|
|
10
|
+
},
|
|
11
|
+
onAction() {
|
|
12
|
+
return () => {
|
|
13
|
+
};
|
|
14
|
+
},
|
|
15
|
+
// Server doesn't receive dispatches
|
|
16
|
+
pushObservation() {
|
|
17
|
+
},
|
|
18
|
+
// Server doesn't push observations
|
|
19
|
+
onObservation(handler) {
|
|
20
|
+
observationHandlers.push(handler);
|
|
21
|
+
return () => {
|
|
22
|
+
const i = observationHandlers.indexOf(handler);
|
|
23
|
+
if (i >= 0) observationHandlers.splice(i, 1);
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
registerSurface() {
|
|
27
|
+
},
|
|
28
|
+
deregisterSurface() {
|
|
29
|
+
},
|
|
30
|
+
onSurfaceRegister(handler) {
|
|
31
|
+
surfaceRegisterHandlers.push(handler);
|
|
32
|
+
return () => {
|
|
33
|
+
const i = surfaceRegisterHandlers.indexOf(handler);
|
|
34
|
+
if (i >= 0) surfaceRegisterHandlers.splice(i, 1);
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
onSurfaceDeregister(handler) {
|
|
38
|
+
surfaceDeregisterHandlers.push(handler);
|
|
39
|
+
return () => {
|
|
40
|
+
const i = surfaceDeregisterHandlers.indexOf(handler);
|
|
41
|
+
if (i >= 0) surfaceDeregisterHandlers.splice(i, 1);
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
get connected() {
|
|
45
|
+
return true;
|
|
46
|
+
},
|
|
47
|
+
async connect() {
|
|
48
|
+
},
|
|
49
|
+
disconnect() {
|
|
50
|
+
},
|
|
51
|
+
onConnectionChange() {
|
|
52
|
+
return () => {
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const client = {
|
|
57
|
+
dispatch() {
|
|
58
|
+
},
|
|
59
|
+
// Client doesn't dispatch
|
|
60
|
+
onAction(handler) {
|
|
61
|
+
actionHandlers.push(handler);
|
|
62
|
+
return () => {
|
|
63
|
+
const i = actionHandlers.indexOf(handler);
|
|
64
|
+
if (i >= 0) actionHandlers.splice(i, 1);
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
pushObservation(update) {
|
|
68
|
+
observationHandlers.forEach((h) => h(update));
|
|
69
|
+
},
|
|
70
|
+
onObservation() {
|
|
71
|
+
return () => {
|
|
72
|
+
};
|
|
73
|
+
},
|
|
74
|
+
// Client doesn't receive observations
|
|
75
|
+
registerSurface(surface) {
|
|
76
|
+
surfaceRegisterHandlers.forEach((h) => h(surface));
|
|
77
|
+
},
|
|
78
|
+
deregisterSurface(surfaceId) {
|
|
79
|
+
surfaceDeregisterHandlers.forEach((h) => h(surfaceId));
|
|
80
|
+
},
|
|
81
|
+
onSurfaceRegister() {
|
|
82
|
+
return () => {
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
onSurfaceDeregister() {
|
|
86
|
+
return () => {
|
|
87
|
+
};
|
|
88
|
+
},
|
|
89
|
+
get connected() {
|
|
90
|
+
return true;
|
|
91
|
+
},
|
|
92
|
+
async connect() {
|
|
93
|
+
},
|
|
94
|
+
disconnect() {
|
|
95
|
+
},
|
|
96
|
+
onConnectionChange() {
|
|
97
|
+
return () => {
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
return { server, client };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { createDirectTransportPair };
|
|
105
|
+
//# sourceMappingURL=chunk-O6EI77LD.js.map
|
|
106
|
+
//# sourceMappingURL=chunk-O6EI77LD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/transport/direct.ts"],"names":[],"mappings":";AAWO,SAAS,yBAAA,GAA4E;AAC1F,EAAA,MAAM,iBAAqC,EAAC;AAC5C,EAAA,MAAM,sBAA+C,EAAC;AACtD,EAAA,MAAM,0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SAAS,CAAC,CAAA;AAAA,IACrD,CAAA;AAAA,IACA,iBAAA,GAAoB;AAAE,MAAA,OAAO,MAAM;AAAA,MAAC,CAAA;AAAA,IAAG,CAAA;AAAA,IACvC,mBAAA,GAAsB;AAAE,MAAA,OAAO,MAAM;AAAA,MAAC,CAAA;AAAA,IAAG,CAAA;AAAA,IACzC,IAAI,SAAA,GAAY;AAAE,MAAA,OAAO,IAAA;AAAA,IAAM,CAAA;AAAA,IAC/B,MAAM,OAAA,GAAU;AAAA,IAAC,CAAA;AAAA,IACjB,UAAA,GAAa;AAAA,IAAC,CAAA;AAAA,IACd,kBAAA,GAAqB;AAAE,MAAA,OAAO,MAAM;AAAA,MAAC,CAAA;AAAA,IAAG;AAAA,GAC1C;AAEA,EAAA,OAAO,EAAE,QAAQ,MAAA,EAAO;AAC1B","file":"chunk-O6EI77LD.js","sourcesContent":["import type { OUITransport, OUIActionHandler, OUIObservationHandler } from './types.js';\nimport type { OUISurface, OUIObservationUpdate } from '../spec/index.js';\n\n/**\n * Direct transport — for same-process communication.\n * Used for API surfaces (where the agent runtime and surface are in the same Lambda)\n * and for testing (where you want synchronous, in-memory communication).\n *\n * Creates a paired (server, client) transport where messages sent on one\n * side are immediately received on the other.\n */\nexport function createDirectTransportPair(): { server: OUITransport; client: OUITransport } {\n const actionHandlers: OUIActionHandler[] = [];\n const observationHandlers: OUIObservationHandler[] = [];\n const surfaceRegisterHandlers: Array<(s: OUISurface) => void> = [];\n const surfaceDeregisterHandlers: Array<(id: string) => void> = [];\n\n const server: OUITransport = {\n dispatch(surfaceId, actionId, params) {\n // Server dispatches → client receives\n actionHandlers.forEach(h => h(surfaceId, actionId, params));\n },\n onAction() { return () => {}; }, // Server doesn't receive dispatches\n pushObservation() {}, // Server doesn't push observations\n onObservation(handler) {\n observationHandlers.push(handler);\n return () => { const i = observationHandlers.indexOf(handler); if (i >= 0) observationHandlers.splice(i, 1); };\n },\n registerSurface() {},\n deregisterSurface() {},\n onSurfaceRegister(handler) {\n surfaceRegisterHandlers.push(handler);\n return () => { const i = surfaceRegisterHandlers.indexOf(handler); if (i >= 0) surfaceRegisterHandlers.splice(i, 1); };\n },\n onSurfaceDeregister(handler) {\n surfaceDeregisterHandlers.push(handler);\n return () => { const i = surfaceDeregisterHandlers.indexOf(handler); if (i >= 0) surfaceDeregisterHandlers.splice(i, 1); };\n },\n get connected() { return true; },\n async connect() {},\n disconnect() {},\n onConnectionChange() { return () => {}; },\n };\n\n const client: OUITransport = {\n dispatch() {}, // Client doesn't dispatch\n onAction(handler) {\n actionHandlers.push(handler);\n return () => { const i = actionHandlers.indexOf(handler); if (i >= 0) actionHandlers.splice(i, 1); };\n },\n pushObservation(update: OUIObservationUpdate) {\n // Client pushes → server receives\n observationHandlers.forEach(h => h(update));\n },\n onObservation() { return () => {}; }, // Client doesn't receive observations\n registerSurface(surface) {\n surfaceRegisterHandlers.forEach(h => h(surface));\n },\n deregisterSurface(surfaceId) {\n surfaceDeregisterHandlers.forEach(h => h(surfaceId));\n },\n onSurfaceRegister() { return () => {}; },\n onSurfaceDeregister() { return () => {}; },\n get connected() { return true; },\n async connect() {},\n disconnect() {},\n onConnectionChange() { return () => {}; },\n };\n\n return { server, client };\n}\n"]}
|
|
@@ -99,109 +99,6 @@ function createWebSocketTransport(socket, config) {
|
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const observationHandlers = [];
|
|
106
|
-
const surfaceRegisterHandlers = [];
|
|
107
|
-
const surfaceDeregisterHandlers = [];
|
|
108
|
-
const server = {
|
|
109
|
-
dispatch(surfaceId, actionId, params) {
|
|
110
|
-
actionHandlers.forEach((h) => h(surfaceId, actionId, params));
|
|
111
|
-
},
|
|
112
|
-
onAction() {
|
|
113
|
-
return () => {
|
|
114
|
-
};
|
|
115
|
-
},
|
|
116
|
-
// Server doesn't receive dispatches
|
|
117
|
-
pushObservation() {
|
|
118
|
-
},
|
|
119
|
-
// Server doesn't push observations
|
|
120
|
-
onObservation(handler) {
|
|
121
|
-
observationHandlers.push(handler);
|
|
122
|
-
return () => {
|
|
123
|
-
const i = observationHandlers.indexOf(handler);
|
|
124
|
-
if (i >= 0) observationHandlers.splice(i, 1);
|
|
125
|
-
};
|
|
126
|
-
},
|
|
127
|
-
registerSurface() {
|
|
128
|
-
},
|
|
129
|
-
deregisterSurface() {
|
|
130
|
-
},
|
|
131
|
-
onSurfaceRegister(handler) {
|
|
132
|
-
surfaceRegisterHandlers.push(handler);
|
|
133
|
-
return () => {
|
|
134
|
-
const i = surfaceRegisterHandlers.indexOf(handler);
|
|
135
|
-
if (i >= 0) surfaceRegisterHandlers.splice(i, 1);
|
|
136
|
-
};
|
|
137
|
-
},
|
|
138
|
-
onSurfaceDeregister(handler) {
|
|
139
|
-
surfaceDeregisterHandlers.push(handler);
|
|
140
|
-
return () => {
|
|
141
|
-
const i = surfaceDeregisterHandlers.indexOf(handler);
|
|
142
|
-
if (i >= 0) surfaceDeregisterHandlers.splice(i, 1);
|
|
143
|
-
};
|
|
144
|
-
},
|
|
145
|
-
get connected() {
|
|
146
|
-
return true;
|
|
147
|
-
},
|
|
148
|
-
async connect() {
|
|
149
|
-
},
|
|
150
|
-
disconnect() {
|
|
151
|
-
},
|
|
152
|
-
onConnectionChange() {
|
|
153
|
-
return () => {
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
const client = {
|
|
158
|
-
dispatch() {
|
|
159
|
-
},
|
|
160
|
-
// Client doesn't dispatch
|
|
161
|
-
onAction(handler) {
|
|
162
|
-
actionHandlers.push(handler);
|
|
163
|
-
return () => {
|
|
164
|
-
const i = actionHandlers.indexOf(handler);
|
|
165
|
-
if (i >= 0) actionHandlers.splice(i, 1);
|
|
166
|
-
};
|
|
167
|
-
},
|
|
168
|
-
pushObservation(update) {
|
|
169
|
-
observationHandlers.forEach((h) => h(update));
|
|
170
|
-
},
|
|
171
|
-
onObservation() {
|
|
172
|
-
return () => {
|
|
173
|
-
};
|
|
174
|
-
},
|
|
175
|
-
// Client doesn't receive observations
|
|
176
|
-
registerSurface(surface) {
|
|
177
|
-
surfaceRegisterHandlers.forEach((h) => h(surface));
|
|
178
|
-
},
|
|
179
|
-
deregisterSurface(surfaceId) {
|
|
180
|
-
surfaceDeregisterHandlers.forEach((h) => h(surfaceId));
|
|
181
|
-
},
|
|
182
|
-
onSurfaceRegister() {
|
|
183
|
-
return () => {
|
|
184
|
-
};
|
|
185
|
-
},
|
|
186
|
-
onSurfaceDeregister() {
|
|
187
|
-
return () => {
|
|
188
|
-
};
|
|
189
|
-
},
|
|
190
|
-
get connected() {
|
|
191
|
-
return true;
|
|
192
|
-
},
|
|
193
|
-
async connect() {
|
|
194
|
-
},
|
|
195
|
-
disconnect() {
|
|
196
|
-
},
|
|
197
|
-
onConnectionChange() {
|
|
198
|
-
return () => {
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
return { server, client };
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
export { createDirectTransportPair, createWebSocketTransport };
|
|
206
|
-
//# sourceMappingURL=chunk-7EXSMPGR.js.map
|
|
207
|
-
//# sourceMappingURL=chunk-7EXSMPGR.js.map
|
|
102
|
+
export { createWebSocketTransport };
|
|
103
|
+
//# sourceMappingURL=chunk-YDMGV72W.js.map
|
|
104
|
+
//# sourceMappingURL=chunk-YDMGV72W.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/transport/websocket.ts"],"names":[],"mappings":";AAaO,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,aAAA,IAAiB,GAAA;AAC3C,EAAA,MAAM,YAAA,GAAe,QAAQ,uBAAA,IAA2B,IAAA;AAExD,EAAA,IAAI,SAAA,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,UAAA,MAAA,CAAO,OAAA,EAAQ;AAAA,QACjB;AAAA,MACF,CAAC,CAAA;AAAA,IACH,CAAA;AAAA,IAEA,UAAA,GAAa;AACX,MAAA,IAAI,OAAO,MAAA,CAAO,UAAA,KAAe,UAAA,EAAY;AAC3C,QAAA,MAAA,CAAO,UAAA,EAAW;AAAA,MACpB;AAAA,IACF,CAAA;AAAA,IAEA,mBAAmB,OAAA,EAA+B;AAChD,MAAA,kBAAA,CAAmB,KAAK,OAAO,CAAA;AAC/B,MAAA,OAAO,MAAM;AACX,QAAA,MAAM,GAAA,GAAM,kBAAA,CAAmB,OAAA,CAAQ,OAAO,CAAA;AAC9C,QAAA,IAAI,GAAA,IAAO,CAAA,EAAG,kBAAA,CAAmB,MAAA,CAAO,KAAK,CAAC,CAAA;AAAA,MAChD,CAAA;AAAA,IACF;AAAA,GACF;AACF","file":"chunk-YDMGV72W.js","sourcesContent":["import type { OUITransport, OUITransportConfig, OUIActionHandler, OUIObservationHandler } from './types.js';\nimport type { OUISurface, OUIObservationUpdate } 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 emitted:\n * {ns}:dispatch — action dispatch (server → client)\n * {ns}:observation — observation update (client → server)\n * {ns}:surface:register — surface registration (client → server)\n * {ns}:surface:deregister — surface deregistration (client → server)\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 // Track connection state\n socket.on('connect', () => {\n connected = true;\n connectionHandlers.forEach(h => h(true));\n // Flush buffer\n if (shouldBuffer) {\n while (buffer.length > 0) {\n const msg = buffer.shift()!;\n socket.emit(msg.event, msg.data);\n }\n }\n });\n\n socket.on('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 Channel ───────────────────────────────────────\n dispatch(surfaceId, actionId, params) {\n emit(`${ns}:dispatch`, { surfaceId, actionId, params, timestamp: Date.now() });\n },\n\n onAction(handler: OUIActionHandler) {\n const listener = (data: { surfaceId: string; actionId: string; params: Record<string, unknown> }) => {\n handler(data.surfaceId, data.actionId, data.params);\n };\n socket.on(`${ns}:dispatch`, listener);\n return () => socket.off(`${ns}:dispatch`, listener);\n },\n\n // ─── Observation Channel ────────────────────────────────────\n pushObservation(update: OUIObservationUpdate) {\n emit(`${ns}:observation`, update);\n },\n\n onObservation(handler: OUIObservationHandler) {\n const listener = (data: OUIObservationUpdate) => handler(data);\n socket.on(`${ns}:observation`, listener);\n return () => socket.off(`${ns}:observation`, listener);\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 const listener = (data: { surface: OUISurface }) => handler(data.surface);\n socket.on(`${ns}:surface:register`, listener);\n return () => socket.off(`${ns}:surface:register`, listener);\n },\n\n onSurfaceDeregister(handler: (surfaceId: string) => void) {\n const listener = (data: { surfaceId: string }) => handler(data.surfaceId);\n socket.on(`${ns}:surface:deregister`, listener);\n return () => socket.off(`${ns}:surface:deregister`, listener);\n },\n\n // ─── Connection ─────────────────────────────────────────────\n get connected() { return connected; },\n\n async connect() {\n if (connected) return;\n return new Promise<void>((resolve, reject) => {\n const timeout = setTimeout(() => {\n reject(new Error(`OUI transport connect timeout (${config?.connectTimeoutMs ?? 10000}ms)`));\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}\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"]}
|
package/dist/core/index.cjs
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkHK7OXB2W_cjs = require('../chunk-HK7OXB2W.cjs');
|
|
4
4
|
var chunk3DCIL4FV_cjs = require('../chunk-3DCIL4FV.cjs');
|
|
5
|
+
require('../chunk-MTMEW6MM.cjs');
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
|
|
9
|
+
Object.defineProperty(exports, "createOUI", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () { return chunkHK7OXB2W_cjs.createOUI; }
|
|
12
|
+
});
|
|
8
13
|
Object.defineProperty(exports, "defineSurface", {
|
|
9
14
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
15
|
+
get: function () { return chunkHK7OXB2W_cjs.defineSurface; }
|
|
11
16
|
});
|
|
12
17
|
Object.defineProperty(exports, "OUI_PROTOCOL_EVENTS", {
|
|
13
18
|
enumerable: true,
|
package/dist/core/index.d.cts
CHANGED
|
@@ -1,120 +1,134 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { OUIAction, OUIActionRequest, OUIActionResult, OUIObservation, OUIObservationUpdate, OUIProtocolEvent, OUISurfaceDeregistration, OUISurfaceRegistration, OUI_PROTOCOL_EVENTS } from '../spec/index.cjs';
|
|
1
|
+
import { OUISurface } from '../spec/index.cjs';
|
|
2
|
+
export { JSONSchema, OUIAction, OUIActionPolling, OUIActionRequest, OUIActionResult, OUIActivation, OUIObservation, OUIObservationUpdate, OUIProtocolEvent, OUISurfaceDeregistration, OUISurfaceRegistration, OUI_PROTOCOL_EVENTS } from '../spec/index.cjs';
|
|
3
|
+
import { D as DefinedSurface, O as OUIBranded } from '../define-surface-D6XPtoqu.cjs';
|
|
4
|
+
export { A as ActionDefinition, a as ActionHandlerResult, b as ActionPollingConfig, c as ObservationDefinition, S as SurfaceDefinition, d as defineSurface } from '../define-surface-D6XPtoqu.cjs';
|
|
5
|
+
import { S as SocketLike, c as OUITransportConfig, b as OUITransport } from '../websocket-CrI0yRNo.cjs';
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
+
* Compile-time validation for a createOUI configuration.
|
|
9
|
+
*
|
|
10
|
+
* These types resolve to a descriptive error type when a rule is broken, so the
|
|
11
|
+
* failure surfaces at the call site with a message naming the offending id —
|
|
12
|
+
* not as `Type 'X' is not assignable to type 'never'`.
|
|
13
|
+
*
|
|
14
|
+
* Everything here was previously a runtime `throw` inside defineSurface, or
|
|
15
|
+
* nothing at all. A duplicate action id threw when the surface was constructed,
|
|
16
|
+
* which in a React app means at render, in a browser, after a deploy. The same
|
|
17
|
+
* mistake is now a red squiggle.
|
|
8
18
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
+
/** A readable compile error. The message lands in the tooltip. */
|
|
20
|
+
type OUIConfigError<TMessage extends string> = {
|
|
21
|
+
readonly __ouiError: TMessage;
|
|
22
|
+
};
|
|
23
|
+
/** Ids appearing more than once in a tuple of string literals. */
|
|
24
|
+
type Duplicates<T extends readonly string[], Seen extends string = never> = T extends readonly [
|
|
25
|
+
infer Head extends string,
|
|
26
|
+
...infer Rest extends readonly string[]
|
|
27
|
+
] ? Head extends Seen ? Head | Duplicates<Rest, Seen | Head> : Duplicates<Rest, Seen | Head> : never;
|
|
19
28
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
29
|
+
* `never` when every id is unique, otherwise the duplicated ids.
|
|
30
|
+
* Exported for tests — a validation type nobody can assert against is a
|
|
31
|
+
* validation type nobody can trust.
|
|
23
32
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
* Called on each poll interval. Receives the dispatch result from the handler
|
|
27
|
-
* plus the current context. Return { done: true, data } to stop polling,
|
|
28
|
-
* or { done: false, data } to continue.
|
|
29
|
-
*/
|
|
30
|
-
resolve?: (dispatchResult: unknown, context: TContext) => Promise<{
|
|
31
|
-
done: boolean;
|
|
32
|
-
data: unknown;
|
|
33
|
-
}>;
|
|
34
|
-
}
|
|
33
|
+
type DuplicateIds<T extends readonly string[]> = Duplicates<T>;
|
|
34
|
+
type IsEmpty<T extends readonly unknown[]> = T extends readonly [] ? true : false;
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
36
|
+
* Validate the surface list, returning the config type when it passes and an
|
|
37
|
+
* OUIConfigError when it does not.
|
|
38
|
+
*
|
|
39
|
+
* The rules, and why each exists:
|
|
40
|
+
*
|
|
41
|
+
* Non-empty — an OUI instance with no surfaces registers nothing and
|
|
42
|
+
* dispatches nowhere. It looks connected and does nothing, which is the
|
|
43
|
+
* failure mode this whole design is trying to eliminate.
|
|
44
|
+
*
|
|
45
|
+
* Unique surface ids — registration is keyed by surface id, so a duplicate
|
|
46
|
+
* silently replaces the first surface's manifest. The agent then sees one
|
|
47
|
+
* surface's actions attributed to the other.
|
|
48
|
+
*/
|
|
49
|
+
type ValidateSurfaceIds<TIds extends readonly string[]> = IsEmpty<TIds> extends true ? OUIConfigError<"createOUI requires at least one surface. An instance with no surfaces registers nothing and dispatches nowhere."> : [DuplicateIds<TIds>] extends [never] ? unknown : OUIConfigError<`Duplicate surface id: "${DuplicateIds<TIds>}". Surface registration is keyed by id, so the second would silently replace the first.`>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* createOUI — the only supported way to instantiate OUI.
|
|
53
|
+
*
|
|
54
|
+
* WHY THIS EXISTS
|
|
55
|
+
*
|
|
56
|
+
* OUI shipped a correct protocol and a correct transport, and its first
|
|
57
|
+
* integrator used neither. studio-ui imported only the `SocketLike` TYPE from
|
|
58
|
+
* oui-spec and rebuilt the wire by hand: a literal map of protocol types to
|
|
59
|
+
* socket names, `oui:` hardcoded so the configurable namespace was unreachable,
|
|
60
|
+
* payload interfaces re-declared on the server, and an `action:result` channel
|
|
61
|
+
* mapped but never sent — duplicating the observation channel that already
|
|
62
|
+
* carries results.
|
|
63
|
+
*
|
|
64
|
+
* Nothing was wrong with the spec. Nothing enforced it. Structural typing meant
|
|
65
|
+
* every hand-rolled piece type-checked, and both ends agreed only by the
|
|
66
|
+
* coincidence of matching string literals. Rename one and the other keeps
|
|
67
|
+
* compiling and silently stops receiving.
|
|
68
|
+
*
|
|
69
|
+
* So the requirements are gated here:
|
|
70
|
+
*
|
|
71
|
+
* OUI owns the wire. The integrator provides a socket; it cannot provide a
|
|
72
|
+
* transport, because `OUITransport` values are branded and only this module
|
|
73
|
+
* brands them.
|
|
74
|
+
*
|
|
75
|
+
* OUI owns the result path. Results return through the observation channel,
|
|
76
|
+
* as `use-surface` already implements. An integrator cannot add a parallel
|
|
77
|
+
* channel because it cannot construct a transport to add one to.
|
|
78
|
+
*
|
|
79
|
+
* The integrator owns content. Surfaces, action schemas, observation schemas
|
|
80
|
+
* and handlers all arrive through `defineSurface`, whose output is branded —
|
|
81
|
+
* so a plain object shaped like a surface will not compile.
|
|
82
|
+
*
|
|
83
|
+
* Violations fail at compile time with a message naming the offending id.
|
|
39
84
|
*/
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
85
|
+
|
|
86
|
+
/** A transport OUI constructed. Integrators cannot produce one. */
|
|
87
|
+
type OwnedTransport = OUITransport & OUIBranded<"transport">;
|
|
88
|
+
/** Surface ids as literal types, for the duplicate check. */
|
|
89
|
+
type SurfaceIds<T extends readonly DefinedSurface<never>[]> = {
|
|
90
|
+
[K in keyof T]: T[K]["id"];
|
|
91
|
+
};
|
|
92
|
+
interface OUIConfig<TSurfaces extends readonly DefinedSurface<never>[]> {
|
|
47
93
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* and pushes observation updates until the operation completes.
|
|
51
|
-
* Extends the spec's OUIActionPolling with an optional resolve handler.
|
|
94
|
+
* The socket OUI will speak over. The integrator owns the connection —
|
|
95
|
+
* auth, reconnection, lifecycle — and OUI owns what travels on it.
|
|
52
96
|
*/
|
|
53
|
-
|
|
54
|
-
usage?: string;
|
|
55
|
-
preconditions?: string;
|
|
56
|
-
estimatedDuration?: string;
|
|
57
|
-
tags?: string[];
|
|
97
|
+
socket: SocketLike;
|
|
58
98
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* Returns a result that the agent sees as the tool output.
|
|
99
|
+
* Surfaces produced by `defineSurface`. A plain object with the same shape
|
|
100
|
+
* will not compile: DefinedSurface is branded.
|
|
62
101
|
*/
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
details?: unknown;
|
|
102
|
+
surfaces: TSurfaces;
|
|
103
|
+
/**
|
|
104
|
+
* Wire configuration. `namespace` defaults to 'oui' and is the supported way
|
|
105
|
+
* to change the event prefix — hardcoding it at the call site is what made
|
|
106
|
+
* this option unreachable in the first integration.
|
|
107
|
+
*/
|
|
108
|
+
transport?: Omit<OUITransportConfig, "namespace"> & {
|
|
109
|
+
namespace?: string;
|
|
72
110
|
};
|
|
73
|
-
/** For async actions: metadata passed to the polling resolver */
|
|
74
|
-
dispatchMeta?: Record<string, unknown>;
|
|
75
111
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
|
|
112
|
+
/** A live OUI instance. */
|
|
113
|
+
interface OUIInstance {
|
|
114
|
+
/** The transport OUI owns. Exposed for wiring, not for reimplementation. */
|
|
115
|
+
readonly transport: OwnedTransport;
|
|
116
|
+
/** Manifests for every registered surface, as the agent sees them. */
|
|
117
|
+
readonly manifests: readonly OUISurface[];
|
|
118
|
+
/** Register every surface and connect. */
|
|
119
|
+
start(): Promise<void>;
|
|
120
|
+
/** Deregister every surface and disconnect. */
|
|
121
|
+
stop(): void;
|
|
122
|
+
/** Look up a registered surface by id. */
|
|
123
|
+
getSurface(id: string): DefinedSurface<never> | undefined;
|
|
82
124
|
}
|
|
83
125
|
/**
|
|
84
|
-
*
|
|
85
|
-
* an application feature with the OUI protocol.
|
|
86
|
-
*
|
|
87
|
-
* This function validates the definition and returns a typed surface
|
|
88
|
-
* object that can be registered with an agent runtime or transport layer.
|
|
126
|
+
* Instantiate OUI.
|
|
89
127
|
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* id: 'my-feature',
|
|
94
|
-
* name: 'My Feature',
|
|
95
|
-
* description: 'Does something cool',
|
|
96
|
-
* actions: [
|
|
97
|
-
* {
|
|
98
|
-
* id: 'do_thing',
|
|
99
|
-
* description: 'Does the thing',
|
|
100
|
-
* input: { type: 'object', properties: { name: { type: 'string' } }, required: ['name'] },
|
|
101
|
-
* handler: async (params) => {
|
|
102
|
-
* const result = await doTheThing(params.name);
|
|
103
|
-
* return { success: true, data: result };
|
|
104
|
-
* },
|
|
105
|
-
* },
|
|
106
|
-
* ],
|
|
107
|
-
* });
|
|
108
|
-
* ```
|
|
128
|
+
* `const` on the type parameter captures surface ids as literal types, which is
|
|
129
|
+
* what allows duplicate detection to name the offending id rather than failing
|
|
130
|
+
* with an unassignable-to-never error.
|
|
109
131
|
*/
|
|
110
|
-
declare function
|
|
111
|
-
/** A fully defined surface with both manifest extraction and execution capabilities */
|
|
112
|
-
interface DefinedSurface<TContext = unknown> extends SurfaceDefinition<TContext> {
|
|
113
|
-
toManifest(): OUISurface;
|
|
114
|
-
executeAction(actionId: string, params: Record<string, unknown>, context: TContext): Promise<ActionHandlerResult>;
|
|
115
|
-
getActionIds(): string[];
|
|
116
|
-
/** Get the polling config for an action (if async) */
|
|
117
|
-
getPollingConfig(actionId: string): OUIActionPolling | undefined;
|
|
118
|
-
}
|
|
132
|
+
declare function createOUI<const TSurfaces extends readonly DefinedSurface<never>[]>(config: OUIConfig<TSurfaces> & ValidateSurfaceIds<SurfaceIds<TSurfaces>>): OUIInstance;
|
|
119
133
|
|
|
120
|
-
export {
|
|
134
|
+
export { DefinedSurface, type DuplicateIds, OUIBranded, type OUIConfig, type OUIConfigError, type OUIInstance, OUISurface, type OwnedTransport, type ValidateSurfaceIds, createOUI };
|