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,91 @@
1
+ import { OUIObservationUpdate, OUISurface } from '../spec/index.js';
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 };
@@ -0,0 +1,3 @@
1
+ export { createDirectTransportPair, createWebSocketTransport } from '../chunk-7EXSMPGR.js';
2
+ //# sourceMappingURL=index.js.map
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
package/package.json ADDED
@@ -0,0 +1,109 @@
1
+ {
2
+ "name": "oui-spec",
3
+ "version": "0.1.0",
4
+ "description": "OUI — The OpenUI Specification. A machine-readable contract for agent-controllable user interfaces.",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ },
14
+ "./spec": {
15
+ "types": "./dist/spec/index.d.ts",
16
+ "import": "./dist/spec/index.js",
17
+ "require": "./dist/spec/index.cjs"
18
+ },
19
+ "./core": {
20
+ "types": "./dist/core/index.d.ts",
21
+ "import": "./dist/core/index.js",
22
+ "require": "./dist/core/index.cjs"
23
+ },
24
+ "./react": {
25
+ "types": "./dist/react/index.d.ts",
26
+ "import": "./dist/react/index.js",
27
+ "require": "./dist/react/index.cjs"
28
+ },
29
+ "./transport": {
30
+ "types": "./dist/transport/index.d.ts",
31
+ "import": "./dist/transport/index.js",
32
+ "require": "./dist/transport/index.cjs"
33
+ }
34
+ },
35
+ "typesVersions": {
36
+ "*": {
37
+ "spec": [
38
+ "dist/spec/index.d.ts"
39
+ ],
40
+ "core": [
41
+ "dist/core/index.d.ts"
42
+ ],
43
+ "react": [
44
+ "dist/react/index.d.ts"
45
+ ],
46
+ "transport": [
47
+ "dist/transport/index.d.ts"
48
+ ]
49
+ }
50
+ },
51
+ "files": [
52
+ "dist",
53
+ "spec"
54
+ ],
55
+ "license": "MIT",
56
+ "type": "module",
57
+ "repository": {
58
+ "type": "git",
59
+ "url": "https://github.com/wesreid/oui.git"
60
+ },
61
+ "keywords": [
62
+ "oui",
63
+ "openui",
64
+ "ai",
65
+ "agent",
66
+ "ui",
67
+ "specification",
68
+ "protocol"
69
+ ],
70
+ "scripts": {
71
+ "build": "tsup",
72
+ "typecheck": "tsc --noEmit",
73
+ "lint": "eslint src",
74
+ "test": "vitest run",
75
+ "test:watch": "vitest",
76
+ "prepare": "husky",
77
+ "prepublishOnly": "npm run build"
78
+ },
79
+ "peerDependencies": {
80
+ "react": ">=18.0.0"
81
+ },
82
+ "peerDependenciesMeta": {
83
+ "react": {
84
+ "optional": true
85
+ }
86
+ },
87
+ "devDependencies": {
88
+ "@types/react": "^19.0.0",
89
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
90
+ "@typescript-eslint/parser": "^8.0.0",
91
+ "eslint": "^9.0.0",
92
+ "husky": "^9.1.7",
93
+ "lint-staged": "^16.4.0",
94
+ "prettier": "^3.9.6",
95
+ "react": "^19.0.0",
96
+ "tsup": "^8.4.0",
97
+ "typescript": "^5.8.0",
98
+ "vitest": "^3.0.0"
99
+ },
100
+ "lint-staged": {
101
+ "src/**/*.{ts,tsx}": [
102
+ "eslint --fix",
103
+ "prettier --write"
104
+ ],
105
+ "*.{json,md}": [
106
+ "prettier --write"
107
+ ]
108
+ }
109
+ }