@jini-ai/agentic 0.1.2 → 0.3.6

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 (176) hide show
  1. package/README.md +92 -0
  2. package/dist/a2ui/agent-to-renderer.d.ts +36 -2
  3. package/dist/a2ui/agent-to-renderer.d.ts.map +1 -1
  4. package/dist/a2ui/agent-to-renderer.js +23 -1
  5. package/dist/a2ui/agent-to-renderer.js.map +1 -1
  6. package/dist/a2ui/interpreter.d.ts +24 -1
  7. package/dist/a2ui/interpreter.d.ts.map +1 -1
  8. package/dist/a2ui/interpreter.js +115 -65
  9. package/dist/a2ui/interpreter.js.map +1 -1
  10. package/dist/a2ui/json-pointer.d.ts.map +1 -1
  11. package/dist/a2ui/json-pointer.js +28 -3
  12. package/dist/a2ui/json-pointer.js.map +1 -1
  13. package/dist/a2ui/renderer-to-agent.d.ts +35 -11
  14. package/dist/a2ui/renderer-to-agent.d.ts.map +1 -1
  15. package/dist/a2ui/renderer-to-agent.js +15 -2
  16. package/dist/a2ui/renderer-to-agent.js.map +1 -1
  17. package/dist/a2ui/resolve.d.ts +1 -1
  18. package/dist/a2ui/resolve.d.ts.map +1 -1
  19. package/dist/a2ui/resolve.js +29 -3
  20. package/dist/a2ui/resolve.js.map +1 -1
  21. package/dist/a2ui/tree.d.ts +27 -2
  22. package/dist/a2ui/tree.d.ts.map +1 -1
  23. package/dist/a2ui/tree.js +48 -9
  24. package/dist/a2ui/tree.js.map +1 -1
  25. package/dist/ag-ui.d.ts.map +1 -1
  26. package/dist/ag-ui.js +30 -1
  27. package/dist/ag-ui.js.map +1 -1
  28. package/dist/core/a2ui/agent-to-renderer.d.ts +613 -0
  29. package/dist/core/a2ui/agent-to-renderer.d.ts.map +1 -0
  30. package/dist/core/a2ui/agent-to-renderer.js +191 -0
  31. package/dist/core/a2ui/agent-to-renderer.js.map +1 -0
  32. package/dist/core/a2ui/catalog.d.ts +73 -0
  33. package/dist/core/a2ui/catalog.d.ts.map +1 -0
  34. package/dist/core/a2ui/catalog.js +304 -0
  35. package/dist/core/a2ui/catalog.js.map +1 -0
  36. package/dist/core/a2ui/common-types.d.ts +401 -0
  37. package/dist/core/a2ui/common-types.d.ts.map +1 -0
  38. package/dist/core/a2ui/common-types.js +130 -0
  39. package/dist/core/a2ui/common-types.js.map +1 -0
  40. package/dist/core/a2ui/index.d.ts +16 -0
  41. package/dist/core/a2ui/index.d.ts.map +1 -0
  42. package/dist/core/a2ui/index.js +16 -0
  43. package/dist/core/a2ui/index.js.map +1 -0
  44. package/dist/core/a2ui/interpreter.d.ts +71 -0
  45. package/dist/core/a2ui/interpreter.d.ts.map +1 -0
  46. package/dist/core/a2ui/interpreter.js +341 -0
  47. package/dist/core/a2ui/interpreter.js.map +1 -0
  48. package/dist/core/a2ui/json-pointer.d.ts +48 -0
  49. package/dist/core/a2ui/json-pointer.d.ts.map +1 -0
  50. package/dist/core/a2ui/json-pointer.js +174 -0
  51. package/dist/core/a2ui/json-pointer.js.map +1 -0
  52. package/dist/core/a2ui/renderer-to-agent.d.ts +342 -0
  53. package/dist/core/a2ui/renderer-to-agent.d.ts.map +1 -0
  54. package/dist/core/a2ui/renderer-to-agent.js +111 -0
  55. package/dist/core/a2ui/renderer-to-agent.js.map +1 -0
  56. package/dist/core/a2ui/resolve.d.ts +28 -0
  57. package/dist/core/a2ui/resolve.d.ts.map +1 -0
  58. package/dist/core/a2ui/resolve.js +144 -0
  59. package/dist/core/a2ui/resolve.js.map +1 -0
  60. package/dist/core/a2ui/tree.d.ts +66 -0
  61. package/dist/core/a2ui/tree.d.ts.map +1 -0
  62. package/dist/core/a2ui/tree.js +74 -0
  63. package/dist/core/a2ui/tree.js.map +1 -0
  64. package/dist/core/ag-ui.d.ts +82 -0
  65. package/dist/core/ag-ui.d.ts.map +1 -0
  66. package/dist/core/ag-ui.js +85 -0
  67. package/dist/core/ag-ui.js.map +1 -0
  68. package/dist/core/capability.d.ts +81 -0
  69. package/dist/core/capability.d.ts.map +1 -0
  70. package/dist/core/capability.js +79 -0
  71. package/dist/core/capability.js.map +1 -0
  72. package/dist/core/dom/dom-page-driver.d.ts +36 -0
  73. package/dist/core/dom/dom-page-driver.d.ts.map +1 -0
  74. package/dist/core/dom/dom-page-driver.js +601 -0
  75. package/dist/core/dom/dom-page-driver.js.map +1 -0
  76. package/dist/core/dom/index.d.ts +17 -0
  77. package/dist/core/dom/index.d.ts.map +1 -0
  78. package/dist/core/dom/index.js +17 -0
  79. package/dist/core/dom/index.js.map +1 -0
  80. package/dist/core/dom/model-context.d.ts +69 -0
  81. package/dist/core/dom/model-context.d.ts.map +1 -0
  82. package/dist/core/dom/model-context.js +44 -0
  83. package/dist/core/dom/model-context.js.map +1 -0
  84. package/dist/core/element-handles.d.ts +120 -0
  85. package/dist/core/element-handles.d.ts.map +1 -0
  86. package/dist/core/element-handles.js +39 -0
  87. package/dist/core/element-handles.js.map +1 -0
  88. package/dist/core/gen-ui/encoder.d.ts +50 -0
  89. package/dist/core/gen-ui/encoder.d.ts.map +1 -0
  90. package/dist/core/gen-ui/encoder.js +97 -0
  91. package/dist/core/gen-ui/encoder.js.map +1 -0
  92. package/dist/core/gen-ui/events.d.ts +59 -0
  93. package/dist/core/gen-ui/events.d.ts.map +1 -0
  94. package/dist/core/gen-ui/events.js +15 -0
  95. package/dist/core/gen-ui/events.js.map +1 -0
  96. package/dist/core/gen-ui/index.d.ts +18 -0
  97. package/dist/core/gen-ui/index.d.ts.map +1 -0
  98. package/dist/core/gen-ui/index.js +17 -0
  99. package/dist/core/gen-ui/index.js.map +1 -0
  100. package/dist/core/guards.d.ts +96 -0
  101. package/dist/core/guards.d.ts.map +1 -0
  102. package/dist/core/guards.js +186 -0
  103. package/dist/core/guards.js.map +1 -0
  104. package/dist/core/handle.d.ts +89 -0
  105. package/dist/core/handle.d.ts.map +1 -0
  106. package/dist/core/handle.js +88 -0
  107. package/dist/core/handle.js.map +1 -0
  108. package/dist/core/index.d.ts +75 -0
  109. package/dist/core/index.d.ts.map +1 -0
  110. package/dist/core/index.js +74 -0
  111. package/dist/core/index.js.map +1 -0
  112. package/dist/core/list-handles.d.ts +43 -0
  113. package/dist/core/list-handles.d.ts.map +1 -0
  114. package/dist/core/list-handles.js +57 -0
  115. package/dist/core/list-handles.js.map +1 -0
  116. package/dist/core/mcp-ui-apps.d.ts +223 -0
  117. package/dist/core/mcp-ui-apps.d.ts.map +1 -0
  118. package/dist/core/mcp-ui-apps.js +252 -0
  119. package/dist/core/mcp-ui-apps.js.map +1 -0
  120. package/dist/core/page-capabilities.d.ts +14 -0
  121. package/dist/core/page-capabilities.d.ts.map +1 -0
  122. package/dist/core/page-capabilities.js +129 -0
  123. package/dist/core/page-capabilities.js.map +1 -0
  124. package/dist/core/page-driver.d.ts +120 -0
  125. package/dist/core/page-driver.d.ts.map +1 -0
  126. package/dist/core/page-driver.js +2 -0
  127. package/dist/core/page-driver.js.map +1 -0
  128. package/dist/core/page-executor.d.ts +94 -0
  129. package/dist/core/page-executor.d.ts.map +1 -0
  130. package/dist/core/page-executor.js +320 -0
  131. package/dist/core/page-executor.js.map +1 -0
  132. package/dist/core/webmcp.d.ts +202 -0
  133. package/dist/core/webmcp.d.ts.map +1 -0
  134. package/dist/core/webmcp.js +173 -0
  135. package/dist/core/webmcp.js.map +1 -0
  136. package/dist/dom/dom-page-driver.d.ts +9 -2
  137. package/dist/dom/dom-page-driver.d.ts.map +1 -1
  138. package/dist/dom/dom-page-driver.js +84 -40
  139. package/dist/dom/dom-page-driver.js.map +1 -1
  140. package/dist/dom/index.d.ts +1 -1
  141. package/dist/dom/index.d.ts.map +1 -1
  142. package/dist/dom/index.js +1 -1
  143. package/dist/dom/index.js.map +1 -1
  144. package/dist/element-handles.d.ts +22 -1
  145. package/dist/element-handles.d.ts.map +1 -1
  146. package/dist/gen-ui/encoder.d.ts +8 -8
  147. package/dist/gen-ui/encoder.d.ts.map +1 -1
  148. package/dist/gen-ui/encoder.js +2 -2
  149. package/dist/gen-ui/encoder.js.map +1 -1
  150. package/dist/gen-ui/events.d.ts +10 -10
  151. package/dist/gen-ui/events.d.ts.map +1 -1
  152. package/dist/gen-ui/index.d.ts +3 -3
  153. package/dist/gen-ui/index.d.ts.map +1 -1
  154. package/dist/gen-ui/index.js +2 -2
  155. package/dist/gen-ui/index.js.map +1 -1
  156. package/dist/guards.d.ts +8 -3
  157. package/dist/guards.d.ts.map +1 -1
  158. package/dist/guards.js +6 -1
  159. package/dist/guards.js.map +1 -1
  160. package/dist/index.d.ts +4 -62
  161. package/dist/index.d.ts.map +1 -1
  162. package/dist/index.js +4 -61
  163. package/dist/index.js.map +1 -1
  164. package/dist/mcp-ui-apps.d.ts +19 -0
  165. package/dist/mcp-ui-apps.d.ts.map +1 -1
  166. package/dist/mcp-ui-apps.js +50 -5
  167. package/dist/mcp-ui-apps.js.map +1 -1
  168. package/dist/page-capabilities.js +6 -6
  169. package/dist/page-capabilities.js.map +1 -1
  170. package/dist/page-driver.d.ts +15 -2
  171. package/dist/page-driver.d.ts.map +1 -1
  172. package/dist/page-executor.d.ts +11 -4
  173. package/dist/page-executor.d.ts.map +1 -1
  174. package/dist/page-executor.js +47 -15
  175. package/dist/page-executor.js.map +1 -1
  176. package/package.json +16 -9
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @jini-ai/agentic/dom — the browser half of agent control.
3
+ *
4
+ * The one `PageDriver` (see `@jini-ai/agentic`'s `page-driver.ts`) that reads and writes a real DOM
5
+ * subtree. Split into its own entry point, compiled under its own `DOM`-lib `tsconfig.dom.json`,
6
+ * so the rest of this package can stay provably DOM-free — see source-map.md's "The DOM split".
7
+ *
8
+ * `@jini-ai/chat-react` is this package's one in-repo consumer today.
9
+ */
10
+ export { createDomPageDriver, currentAgentPage, type DomPageDriverOptions, type DomPageDriverPage, } from './dom-page-driver.js';
11
+ /**
12
+ * WebMCP feature detection — moved 2026-07-26 from `@jini-ai/ui`'s `agent-tools/model-context.ts`
13
+ * (plan §8 step 6). See `model-context.ts`'s module doc for why it lives here rather than
14
+ * alongside `../webmcp.ts`'s DOM-free projection.
15
+ */
16
+ export { getAgentModelContext, type AgentModelContextLike, type AgentModelContextToolRegistration, } from './model-context.js';
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/dom/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,GACvB,MAAM,sBAAsB,CAAC;AAE9B;;;;GAIG;AACH,OAAO,EACL,oBAAoB,EACpB,KAAK,qBAAqB,EAC1B,KAAK,iCAAiC,GACvC,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @jini-ai/agentic/dom — the browser half of agent control.
3
+ *
4
+ * The one `PageDriver` (see `@jini-ai/agentic`'s `page-driver.ts`) that reads and writes a real DOM
5
+ * subtree. Split into its own entry point, compiled under its own `DOM`-lib `tsconfig.dom.json`,
6
+ * so the rest of this package can stay provably DOM-free — see source-map.md's "The DOM split".
7
+ *
8
+ * `@jini-ai/chat-react` is this package's one in-repo consumer today.
9
+ */
10
+ export { createDomPageDriver, currentAgentPage, } from './dom-page-driver.js';
11
+ /**
12
+ * WebMCP feature detection — moved 2026-07-26 from `@jini-ai/ui`'s `agent-tools/model-context.ts`
13
+ * (plan §8 step 6). See `model-context.ts`'s module doc for why it lives here rather than
14
+ * alongside `../webmcp.ts`'s DOM-free projection.
15
+ */
16
+ export { getAgentModelContext, } from './model-context.js';
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/dom/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACL,mBAAmB,EACnB,gBAAgB,GAGjB,MAAM,sBAAsB,CAAC;AAE9B;;;;GAIG;AACH,OAAO,EACL,oBAAoB,GAGrB,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @module dom/model-context
3
+ *
4
+ * Feature-detected access to the browser's (draft) WebMCP surface —
5
+ * `document.modelContext`, falling back to the deprecated `navigator.modelContext`
6
+ * alias (the spec moved the getter from Navigator to Document in 2026;
7
+ * see the polyfill ecosystem's own back-compat posture). No `@mcp-b/*` or
8
+ * other WebMCP package dependency: this module only needs the shape, the
9
+ * same "typed global + validated getter + graceful unavailable path"
10
+ * pattern `@jini-ai/desktop-host`'s `bridge.ts` and other host-provided-global
11
+ * bridges already use.
12
+ * A page that wants `document.modelContext` to actually exist in a browser
13
+ * without native support must load a real polyfill itself (e.g.
14
+ * `@mcp-b/webmcp-polyfill`) — this module only ever reads what's there.
15
+ *
16
+ * Moved 2026-07-26 from `@jini-ai/ui/src/features/agent-tools/model-context.ts` (plan §4/§8 step 6).
17
+ * Lives under `src/dom/`, not alongside `../webmcp.ts`'s pure `CapabilityDef` → WebMCP-tool
18
+ * projection, because it reads `document`/`navigator` — `webmcp.ts`'s own module doc is explicit
19
+ * that "that detection is deliberately NOT here: it touches browser globals, and this package
20
+ * holds none," which is exactly the DOM-free guarantee `src/dom/` exists to carve an exception
21
+ * for. See `dom/index.ts`'s re-export of this module.
22
+ *
23
+ * `AgentModelContextToolRegistration` gained `title`/`annotations` 2026-07-28, matching the same
24
+ * `ModelContextTool` dict fields `../webmcp.ts`'s `WebMcpToolRegistration` closed the same day —
25
+ * this file models the identical spec dictionary independently (no shared import; see the module
26
+ * doc above for why the DOM/DOM-free split keeps them separate files), so the two had drifted out
27
+ * of sync on the exact same gap. Found while wiring `examples/reference-web`'s WebMCP stress-test
28
+ * fixture: a raw (non-`toWebMcpTool`) registration carrying a `title` failed TypeScript's
29
+ * excess-property check against the un-widened type here.
30
+ */
31
+ export interface AgentModelContextToolRegistration {
32
+ readonly name: string;
33
+ /** `ModelContextTool.title` — optional human-readable label, distinct from `name` and `description`. */
34
+ readonly title?: string;
35
+ readonly description: string;
36
+ readonly inputSchema: unknown;
37
+ readonly execute: (args: Record<string, unknown>) => Promise<unknown>;
38
+ /** `ModelContextTool.annotations` — `{ readOnlyHint?, untrustedContentHint? }` behavior hints. */
39
+ readonly annotations?: {
40
+ readonly readOnlyHint?: boolean;
41
+ readonly untrustedContentHint?: boolean;
42
+ };
43
+ }
44
+ /**
45
+ * Options `registerTool` accepts. Matches the draft's
46
+ * `ModelContextRegisterToolOptions`: an `AbortSignal` that unregisters the tool when aborted, and
47
+ * `exposedTo` to scope which consumers may see it.
48
+ */
49
+ export interface AgentModelContextRegisterToolOptions {
50
+ readonly signal?: AbortSignal;
51
+ readonly exposedTo?: readonly string[];
52
+ }
53
+ export interface AgentModelContextLike {
54
+ /**
55
+ * Draft IDL: `Promise<undefined> registerTool(ModelContextTool tool, optional
56
+ * ModelContextRegisterToolOptions options = {})` — it is **async**. Callers must not assume it
57
+ * has taken effect synchronously, and must not let a rejection escape.
58
+ */
59
+ registerTool(tool: AgentModelContextToolRegistration, options?: AgentModelContextRegisterToolOptions): Promise<void>;
60
+ /**
61
+ * NOT in the spec — the draft's only unregistration mechanism is aborting the `signal` passed to
62
+ * `registerTool`. Kept optional purely so a polyfill that happens to expose one can be used;
63
+ * never rely on its presence, and always pass a `signal` as the real cleanup path.
64
+ */
65
+ unregisterTool?(name: string): void;
66
+ }
67
+ /** Returns the page's WebMCP surface if one is installed (native or polyfilled), or `undefined`. */
68
+ export declare function getAgentModelContext(): AgentModelContextLike | undefined;
69
+ //# sourceMappingURL=model-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-context.d.ts","sourceRoot":"","sources":["../../../src/core/dom/model-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,MAAM,WAAW,iCAAiC;IAChD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,wGAAwG;IACxG,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACtE,kGAAkG;IAClG,QAAQ,CAAC,WAAW,CAAC,EAAE;QAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,oBAAoB,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;CACrG;AAED;;;;GAIG;AACH,MAAM,WAAW,oCAAoC;IACnD,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACxC;AAED,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,YAAY,CAAC,IAAI,EAAE,iCAAiC,EAAE,OAAO,CAAC,EAAE,oCAAoC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrH;;;;OAIG;IACH,cAAc,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrC;AAMD,oGAAoG;AACpG,wBAAgB,oBAAoB,IAAI,qBAAqB,GAAG,SAAS,CAMxE"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @module dom/model-context
3
+ *
4
+ * Feature-detected access to the browser's (draft) WebMCP surface —
5
+ * `document.modelContext`, falling back to the deprecated `navigator.modelContext`
6
+ * alias (the spec moved the getter from Navigator to Document in 2026;
7
+ * see the polyfill ecosystem's own back-compat posture). No `@mcp-b/*` or
8
+ * other WebMCP package dependency: this module only needs the shape, the
9
+ * same "typed global + validated getter + graceful unavailable path"
10
+ * pattern `@jini-ai/desktop-host`'s `bridge.ts` and other host-provided-global
11
+ * bridges already use.
12
+ * A page that wants `document.modelContext` to actually exist in a browser
13
+ * without native support must load a real polyfill itself (e.g.
14
+ * `@mcp-b/webmcp-polyfill`) — this module only ever reads what's there.
15
+ *
16
+ * Moved 2026-07-26 from `@jini-ai/ui/src/features/agent-tools/model-context.ts` (plan §4/§8 step 6).
17
+ * Lives under `src/dom/`, not alongside `../webmcp.ts`'s pure `CapabilityDef` → WebMCP-tool
18
+ * projection, because it reads `document`/`navigator` — `webmcp.ts`'s own module doc is explicit
19
+ * that "that detection is deliberately NOT here: it touches browser globals, and this package
20
+ * holds none," which is exactly the DOM-free guarantee `src/dom/` exists to carve an exception
21
+ * for. See `dom/index.ts`'s re-export of this module.
22
+ *
23
+ * `AgentModelContextToolRegistration` gained `title`/`annotations` 2026-07-28, matching the same
24
+ * `ModelContextTool` dict fields `../webmcp.ts`'s `WebMcpToolRegistration` closed the same day —
25
+ * this file models the identical spec dictionary independently (no shared import; see the module
26
+ * doc above for why the DOM/DOM-free split keeps them separate files), so the two had drifted out
27
+ * of sync on the exact same gap. Found while wiring `examples/reference-web`'s WebMCP stress-test
28
+ * fixture: a raw (non-`toWebMcpTool`) registration carrying a `title` failed TypeScript's
29
+ * excess-property check against the un-widened type here.
30
+ */
31
+ function isModelContext(value) {
32
+ return typeof value === 'object' && value !== null && typeof value.registerTool === 'function';
33
+ }
34
+ /** Returns the page's WebMCP surface if one is installed (native or polyfilled), or `undefined`. */
35
+ export function getAgentModelContext() {
36
+ const doc = globalThis.document;
37
+ if (isModelContext(doc?.modelContext))
38
+ return doc.modelContext;
39
+ const nav = globalThis.navigator;
40
+ if (isModelContext(nav?.modelContext))
41
+ return nav.modelContext;
42
+ return undefined;
43
+ }
44
+ //# sourceMappingURL=model-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-context.js","sourceRoot":"","sources":["../../../src/core/dom/model-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAsCH,SAAS,cAAc,CAAC,KAAc;IACpC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,OAAQ,KAA+B,CAAC,YAAY,KAAK,UAAU,CAAC;AAC5H,CAAC;AAED,oGAAoG;AACpG,MAAM,UAAU,oBAAoB;IAClC,MAAM,GAAG,GAAI,UAAwD,CAAC,QAAQ,CAAC;IAC/E,IAAI,cAAc,CAAC,GAAG,EAAE,YAAY,CAAC;QAAE,OAAO,GAAG,CAAC,YAAY,CAAC;IAC/D,MAAM,GAAG,GAAI,UAAyD,CAAC,SAAS,CAAC;IACjF,IAAI,cAAc,CAAC,GAAG,EAAE,YAAY,CAAC;QAAE,OAAO,GAAG,CAAC,YAAY,CAAC;IAC/D,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,120 @@
1
+ /**
2
+ * @module element-handles
3
+ *
4
+ * The `data-agent-*` markup convention: how a page names the things an agent may act on.
5
+ *
6
+ * Handles are an **allowlist**, not a query language. A caller names a handle the page
7
+ * already published; it never supplies a selector. That is the whole security property —
8
+ * `resolveHandleSelector` can only ever build `[data-agent-element="<validated-handle>"]`,
9
+ * so there is no path from caller input to an arbitrary `querySelector`.
10
+ */
11
+ import type { FieldDescriptor } from './guards.js';
12
+ export declare const AGENT_ELEMENT_ATTRIBUTE = "data-agent-element";
13
+ export declare const AGENT_ROLE_ATTRIBUTE = "data-agent-role";
14
+ export declare const AGENT_LABEL_ATTRIBUTE = "data-agent-label";
15
+ export declare const AGENT_PAGE_ATTRIBUTE = "data-agent-page";
16
+ /** What verb applies to a tagged element. Mirrors the convention documented in the sample markup. */
17
+ export type AgentElementRole = 'button' | 'checkbox' | 'field' | 'form' | 'list' | 'status' | 'region' | 'link';
18
+ export declare const AGENT_ELEMENT_ROLES: readonly AgentElementRole[];
19
+ /**
20
+ * Whether `handle` is a syntactically valid agent element handle.
21
+ *
22
+ * @param handle - Candidate handle, typically caller-supplied.
23
+ * @returns True when it is safe to interpolate into an attribute selector.
24
+ */
25
+ export declare function isValidElementHandle(handle: string): boolean;
26
+ /**
27
+ * Builds the one selector shape this system will ever resolve.
28
+ *
29
+ * @param handle - A handle published by the page.
30
+ * @returns The attribute selector for that handle.
31
+ * @throws If the handle is not valid — never fall back to treating it as a raw selector.
32
+ */
33
+ export declare function resolveHandleSelector(handle: string): string;
34
+ /** A tagged element as described back to a caller. `label` is page-authored, so it is untrusted. */
35
+ export interface AgentElementDescriptor {
36
+ readonly handle: string;
37
+ readonly role: AgentElementRole | undefined;
38
+ readonly label: string;
39
+ readonly labelTruncated: boolean;
40
+ readonly page: string | undefined;
41
+ }
42
+ /**
43
+ * What an element currently *is*, as opposed to what it is *for*.
44
+ *
45
+ * `label` answers "what is this control" and is stable page ontology — it stays `"Full name"`
46
+ * whether the box is empty or holds `"Ada Lovelace"`. That stability is the reason a caller can
47
+ * address the same element across a whole session, and the reason a driver must never overwrite a
48
+ * label with live text. But it leaves a caller unable to check its own work: after typing a name,
49
+ * after ticking a box, after navigating, the reply named the element and said nothing about
50
+ * whether anything had actually happened.
51
+ *
52
+ * This is the missing half — a separate channel, so observation is added rather than ontology
53
+ * traded away.
54
+ *
55
+ * `text` and any `value` are page-authored and therefore untrusted, exactly like `label`.
56
+ */
57
+ export interface AgentElementState {
58
+ /**
59
+ * Live text rendered inside the element, normalized and bounded. Empty for a bare input, and
60
+ * empty when withheld — see {@link AgentElementState.textWithheld}.
61
+ */
62
+ readonly text: string;
63
+ readonly textTruncated: boolean;
64
+ /**
65
+ * Why `text` is empty on an element that has some — so a caller reads "withheld", not "blank".
66
+ *
67
+ * Only ever set for an editable region (a `contenteditable`), whose text is the field's own
68
+ * contents rather than page-authored chrome. Every other element's text is what the page already
69
+ * renders openly to anyone looking at it.
70
+ */
71
+ readonly textWithheld?: string;
72
+ /** The field's current contents. Absent when the element is not a field, or when withheld. */
73
+ readonly value?: string;
74
+ readonly valueTruncated?: boolean;
75
+ /** Why `value` is absent on a field that has one — so a caller reads "withheld", not "empty". */
76
+ readonly valueWithheld?: string;
77
+ /** Checkbox/radio state. Absent when the element is neither. */
78
+ readonly checked?: boolean;
79
+ readonly disabled?: boolean;
80
+ /** False when the element is present in the DOM but not rendered. */
81
+ readonly visible?: boolean;
82
+ /**
83
+ * A dropdown's available option texts — what `page.select_option` will accept. Absent for
84
+ * everything else. Reported even when the current `value` is withheld: which options exist is
85
+ * page-authored ontology, not the user's data.
86
+ */
87
+ readonly options?: readonly string[];
88
+ }
89
+ /**
90
+ * What a driver reports for one element, before policy runs.
91
+ *
92
+ * Drivers stay mechanical: this carries the raw `value` and the `field` descriptor, and the
93
+ * executor decides whether the value may be reported at all (see `findFieldReadRefusal`). Putting
94
+ * that decision in the driver would place a secrecy rule in the one layer this design says must
95
+ * not hold policy — and would have to be re-derived correctly by every future driver.
96
+ */
97
+ export interface AgentElementRawState {
98
+ /** Raw text content. The executor normalizes and bounds it. */
99
+ readonly text: string;
100
+ /**
101
+ * True when this element's `text` IS the field's contents rather than page-authored chrome —
102
+ * i.e. it is an editable region (`contenteditable`), which has no `value` of its own.
103
+ *
104
+ * A mechanical fact about the element, which is why a driver reports it: only the driver can
105
+ * tell. What follows from it is policy and stays in `projectElementState`, which gates such text
106
+ * with the same read guard it applies to `value`. Without this, a `<div contenteditable
107
+ * name="password">` had no `value` to withhold and handed the secret back as `text` instead.
108
+ */
109
+ readonly textIsValue?: boolean | undefined;
110
+ /** Raw field contents, reported unconditionally; the executor applies the read guard. */
111
+ readonly value?: string | undefined;
112
+ readonly checked?: boolean | undefined;
113
+ readonly disabled?: boolean | undefined;
114
+ readonly visible?: boolean | undefined;
115
+ /** Present when the element resolves to a field, so the executor can apply the read guard. */
116
+ readonly field?: FieldDescriptor | undefined;
117
+ /** A dropdown's option texts. Page-authored, so it is bounded but never withheld. */
118
+ readonly options?: readonly string[] | undefined;
119
+ }
120
+ //# sourceMappingURL=element-handles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element-handles.d.ts","sourceRoot":"","sources":["../../src/core/element-handles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAC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CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,gEAAgE;IAChE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,qEAAqE;IACrE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAoB;IACnC,+DAA+D;IAC/D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;;;;;OAQG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC3C,yFAAyF;IACzF,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACvC,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACvC,8FAA8F;IAC9F,QAAQ,CAAC,KAAK,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC;IAC7C,qFAAqF;IACrF,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;CAClD"}
@@ -0,0 +1,39 @@
1
+ export const AGENT_ELEMENT_ATTRIBUTE = 'data-agent-element';
2
+ export const AGENT_ROLE_ATTRIBUTE = 'data-agent-role';
3
+ export const AGENT_LABEL_ATTRIBUTE = 'data-agent-label';
4
+ export const AGENT_PAGE_ATTRIBUTE = 'data-agent-page';
5
+ export const AGENT_ELEMENT_ROLES = [
6
+ 'button', 'checkbox', 'field', 'form', 'list', 'status', 'region', 'link',
7
+ ];
8
+ /**
9
+ * Lowercase, digits and single hyphens. Deliberately narrower than CSS allows: a handle that
10
+ * cannot contain a quote, bracket, backslash or whitespace cannot break out of the attribute
11
+ * selector it is interpolated into.
12
+ */
13
+ const HANDLE_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
14
+ /** Upper bound on a handle, so a hostile page cannot publish a megabyte-long name. */
15
+ const MAX_HANDLE_LENGTH = 128;
16
+ /**
17
+ * Whether `handle` is a syntactically valid agent element handle.
18
+ *
19
+ * @param handle - Candidate handle, typically caller-supplied.
20
+ * @returns True when it is safe to interpolate into an attribute selector.
21
+ */
22
+ export function isValidElementHandle(handle) {
23
+ return handle.length > 0 && handle.length <= MAX_HANDLE_LENGTH && HANDLE_PATTERN.test(handle);
24
+ }
25
+ /**
26
+ * Builds the one selector shape this system will ever resolve.
27
+ *
28
+ * @param handle - A handle published by the page.
29
+ * @returns The attribute selector for that handle.
30
+ * @throws If the handle is not valid — never fall back to treating it as a raw selector.
31
+ */
32
+ export function resolveHandleSelector(handle) {
33
+ if (!isValidElementHandle(handle)) {
34
+ throw new Error(`invalid element handle "${handle.slice(0, MAX_HANDLE_LENGTH)}": `
35
+ + 'handles are lowercase words joined by single hyphens, and are never CSS selectors');
36
+ }
37
+ return `[${AGENT_ELEMENT_ATTRIBUTE}="${handle}"]`;
38
+ }
39
+ //# sourceMappingURL=element-handles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element-handles.js","sourceRoot":"","sources":["../../src/core/element-handles.ts"],"names":[],"mappings":"AAYA,MAAM,CAAC,MAAM,uBAAuB,GAAG,oBAAoB,CAAC;AAC5D,MAAM,CAAC,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AACtD,MAAM,CAAC,MAAM,qBAAqB,GAAG,kBAAkB,CAAC;AACxD,MAAM,CAAC,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AAatD,MAAM,CAAC,MAAM,mBAAmB,GAAgC;IAC9D,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM;CAC1E,CAAC;AAEF;;;;GAIG;AACH,MAAM,cAAc,GAAG,4BAA4B,CAAC;AAEpD,sFAAsF;AACtF,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAE9B;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAAc;IACjD,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,MAAM,IAAI,iBAAiB,IAAI,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAChG,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAc;IAClD,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CACb,2BAA2B,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,iBAAiB,CAAC,KAAK;cAChE,mFAAmF,CACtF,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,uBAAuB,KAAK,MAAM,IAAI,CAAC;AACpD,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @module agui/encoder
3
+ *
4
+ * Encodes `@jini-ai/protocol`'s `RunProtocolEvent` stream into AG-UI wire events (see
5
+ * `./events.ts`'s module doc). Rewritten from scratch against `@jini-ai/protocol`'s actual
6
+ * current shape — the ported adapter's original encoder targeted a different, product-specific
7
+ * event union with no direct correspondence to `RunProtocolEvent`/`RunAgentPayload`; only the
8
+ * *shape* of the job (a big per-event-kind switch, unrecognized events silently dropped) carried
9
+ * over. See `source-map.md` for the full old→new field-mapping table and the generalization
10
+ * writeup for the six event kinds that had no generic equivalent before this task.
11
+ *
12
+ * Folded in 2026-07-26 from the standalone `@jini-ai/agui` package (plan §3a) into this `src/gen-ui/`
13
+ * subdirectory — kept out of the flat `ag-ui.ts` namespace because that file is a different
14
+ * projection ({@link CapabilityDef} → an AG-UI *frontend tool*); this one turns a run's event
15
+ * stream into AG-UI *wire* events. Same protocol, two unrelated halves of it.
16
+ */
17
+ import type { RunProtocolEvent } from '@jini-ai/protocol';
18
+ import type { GenUiEvent } from './events.js';
19
+ export interface GenUiEncodeContext {
20
+ /** The run this event belongs to — stamped onto every produced `GenUiEvent`. */
21
+ readonly runId: string;
22
+ /** Passed through onto the produced event's `seq`, when the caller tracks one (e.g. an SSE `Last-Event-ID`-shaped cursor). Omitted entirely (not set to `undefined`) when absent, matching the original adapter's own base-field construction. */
23
+ readonly seq?: number;
24
+ /** Injectable clock for the produced event's `ts`. Defaults to `Date.now`. Test-only hook. */
25
+ readonly now?: () => number;
26
+ }
27
+ /**
28
+ * A stateful AG-UI encoder for one run's event stream. Stateful because `tool_use`/`tool_result`
29
+ * correlation requires remembering each in-flight tool call's name/args between the two protocol
30
+ * events that describe its start and end — a pure per-event function cannot do this alone. Create
31
+ * one instance per run (e.g. one per `RunLifecycle.stream(runId, ...)` subscription); do not share
32
+ * an instance across multiple runs, since the correlation map has no per-run partitioning of its
33
+ * own (`ctx.runId` is only used to stamp the produced event, not to scope the map).
34
+ */
35
+ export interface GenUiEncoder {
36
+ /**
37
+ * Encodes one `RunProtocolEvent` into an `GenUiEvent`, or `null` if this event has no AG-UI
38
+ * equivalent (an unrecognized/not-yet-generalized event kind — silently dropped by the relay,
39
+ * matching the original adapter's own default behavior).
40
+ */
41
+ encode(event: RunProtocolEvent, ctx: GenUiEncodeContext): GenUiEvent | null;
42
+ }
43
+ /**
44
+ * Creates a fresh `GenUiEncoder` with its own, empty tool-call correlation map.
45
+ * @complexity `encode` is O(1) per call (one `Map` get/set/delete); memory is O(k) in the number
46
+ * of currently in-flight (not yet resolved) tool calls for the run this instance encodes.
47
+ * @overallScore 100/100
48
+ */
49
+ export declare function createGenUiEncoder(): GenUiEncoder;
50
+ //# sourceMappingURL=encoder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encoder.d.ts","sourceRoot":"","sources":["../../../src/core/gen-ui/encoder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAmB,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,WAAW,kBAAkB;IACjC,gFAAgF;IAChF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,kPAAkP;IAClP,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,8FAA8F;IAC9F,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CAC7B;AAOD;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,gBAAgB,EAAE,GAAG,EAAE,kBAAkB,GAAG,UAAU,GAAG,IAAI,CAAC;CAC7E;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,YAAY,CAqGjD"}
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Creates a fresh `GenUiEncoder` with its own, empty tool-call correlation map.
3
+ * @complexity `encode` is O(1) per call (one `Map` get/set/delete); memory is O(k) in the number
4
+ * of currently in-flight (not yet resolved) tool calls for the run this instance encodes.
5
+ * @overallScore 100/100
6
+ */
7
+ export function createGenUiEncoder() {
8
+ const pendingToolCalls = new Map();
9
+ function baseFields(ctx) {
10
+ const ts = ctx.now ? ctx.now() : Date.now();
11
+ return ctx.seq !== undefined ? { runId: ctx.runId, ts, seq: ctx.seq } : { runId: ctx.runId, ts };
12
+ }
13
+ function encodeAgentPayload(payload, ctx) {
14
+ const base = baseFields(ctx);
15
+ switch (payload.type) {
16
+ case 'text_delta':
17
+ return { ...base, kind: 'agent.message', text: payload.delta };
18
+ case 'tool_use':
19
+ // Overwrites any prior entry under the same id (a duplicate tool_use for one id) — the
20
+ // most recent call's name/args are what a matching tool_result should be attributed to,
21
+ // and there is no protocol-level guarantee ids are never reused within one run.
22
+ pendingToolCalls.set(payload.id, { toolName: payload.name, args: payload.input });
23
+ return { ...base, kind: 'tool_call', toolName: payload.name, args: payload.input, callId: payload.id, status: 'started' };
24
+ case 'tool_result': {
25
+ const pending = pendingToolCalls.get(payload.toolUseId);
26
+ pendingToolCalls.delete(payload.toolUseId);
27
+ return {
28
+ ...base,
29
+ kind: 'tool_call',
30
+ // A tool_result with no matching prior tool_use (never observed, or already resolved/
31
+ // cleared — e.g. after a run-ending 'end' event, see below) falls back to an 'unknown'
32
+ // name and null args rather than throwing: the result itself is still real and worth
33
+ // relaying even when its originating call wasn't captured.
34
+ toolName: pending?.toolName ?? 'unknown',
35
+ args: pending?.args ?? null,
36
+ callId: payload.toolUseId,
37
+ status: payload.isError ? 'failed' : 'completed',
38
+ result: payload.content,
39
+ };
40
+ }
41
+ // Generalization (see source-map.md): pipeline_stage_started/completed generalized into a
42
+ // named-stage boundary any multi-step driver can emit, flowing through the same 'agent'
43
+ // channel as tool_use/tool_result.
44
+ case 'stage_start':
45
+ return {
46
+ ...base,
47
+ kind: 'run.lifecycle',
48
+ status: 'pipeline_stage_started',
49
+ stageId: payload.stageId,
50
+ ...(payload.iteration !== undefined ? { iteration: payload.iteration } : {}),
51
+ };
52
+ case 'stage_end':
53
+ return {
54
+ ...base,
55
+ kind: 'run.lifecycle',
56
+ status: 'pipeline_stage_completed',
57
+ stageId: payload.stageId,
58
+ ...(payload.iteration !== undefined ? { iteration: payload.iteration } : {}),
59
+ };
60
+ // Generalization (see source-map.md): genui_surface_request/response generalized into a
61
+ // generic human-in-the-loop ask/answer pair.
62
+ case 'surface_request':
63
+ return { ...base, kind: 'ui.surface_requested', surfaceId: payload.surfaceId, surfaceKind: payload.surfaceKind, payload: payload.payload };
64
+ case 'surface_response':
65
+ return { ...base, kind: 'ui.surface_responded', surfaceId: payload.surfaceId, value: payload.value, respondedBy: payload.respondedBy };
66
+ // 'status' / 'thinking_start' / 'thinking_delta' / 'tool_input_delta' / 'usage' / 'raw':
67
+ // no AG-UI equivalent — silently dropped, matching the original adapter's default behavior.
68
+ default:
69
+ return null;
70
+ }
71
+ }
72
+ function encode(event, ctx) {
73
+ switch (event.kind) {
74
+ case 'start':
75
+ return { ...baseFields(ctx), kind: 'run.lifecycle', status: 'started' };
76
+ case 'end': {
77
+ const status = event.payload.status === 'failed' ? 'failed' : event.payload.status === 'canceled' ? 'cancelled' : 'completed';
78
+ // A run can legitimately end while a tool_use is still in flight (its tool_result never
79
+ // arrived, or arrived after 'end' and was already rejected by RunLifecycle — see
80
+ // run-lifecycle.ts's "cannot emit on terminal run" guard). Clearing here means any such
81
+ // stale entries never leak past this run's own lifetime, and a same-id tool_result that
82
+ // somehow still reaches this encoder afterward correctly falls back to 'unknown' rather
83
+ // than resolving against a call from a run that has already ended.
84
+ pendingToolCalls.clear();
85
+ return { ...baseFields(ctx), kind: 'run.lifecycle', status };
86
+ }
87
+ case 'agent':
88
+ return encodeAgentPayload(event.payload, ctx);
89
+ // 'stdout' / 'stderr' / 'error': no AG-UI equivalent — silently dropped, matching the
90
+ // original adapter's default behavior for unrecognized event kinds.
91
+ default:
92
+ return null;
93
+ }
94
+ }
95
+ return { encode };
96
+ }
97
+ //# sourceMappingURL=encoder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encoder.js","sourceRoot":"","sources":["../../../src/core/gen-ui/encoder.ts"],"names":[],"mappings":"AAkDA;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB;IAChC,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAA2B,CAAC;IAE5D,SAAS,UAAU,CAAC,GAAuB;QACzC,MAAM,EAAE,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;QAC5C,OAAO,GAAG,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,CAA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,IAAI,CAAC;QAChB,CAAC;IACH,CAAC;IAED,SAAS,MAAM,CAAC,KAAuB,EAAE,GAAuB;QAC9D,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;YACnB,KAAK,OAAO;gBACV,OAAO,EAAE,GAAG,UAAU,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;YAE1E,KAAK,KAAK,CAAC,CAAC,CAAC;gBACX,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC;gBAC9H,wFAAwF;gBACxF,iFAAiF;gBACjF,wFAAwF;gBACxF,wFAAwF;gBACxF,wFAAwF;gBACxF,mEAAmE;gBACnE,gBAAgB,CAAC,KAAK,EAAE,CAAC;gBACzB,OAAO,EAAE,GAAG,UAAU,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,CAAC;YAC/D,CAAC;YAED,KAAK,OAAO;gBACV,OAAO,kBAAkB,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YAEhD,sFAAsF;YACtF,oEAAoE;YACpE;gBACE,OAAO,IAAI,CAAC;QAChB,CAAC;IACH,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @module agui/events
3
+ *
4
+ * The AG-UI wire event shapes `./encoder.ts` produces. AG-UI (Agent-User Interaction
5
+ * Protocol) is CopilotKit's open, external wire protocol for streaming an agent's run over SSE to
6
+ * a UI client — see https://github.com/ag-ui-protocol/ag-ui. This module is a near-verbatim port
7
+ * of a 312-line adapter that encoded a product's own run-event stream into this shape; the types
8
+ * themselves are unchanged in kind, only de-branded (see `source-map.md` for the full
9
+ * field-mapping table and provenance).
10
+ *
11
+ * Folded in 2026-07-26 from the standalone `@jini-ai/agui` package (plan §3a) into this `src/gen-ui/`
12
+ * subdirectory — see `./encoder.ts` for why it is kept apart from the flat `ag-ui.ts`.
13
+ */
14
+ export type GenUiEventKind = 'agent.message' | 'tool_call' | 'state_update' | 'ui.surface_requested' | 'ui.surface_responded' | 'run.lifecycle';
15
+ export interface GenUiEventBase {
16
+ kind: GenUiEventKind;
17
+ runId: string;
18
+ seq?: number;
19
+ ts: number;
20
+ }
21
+ export interface GenUiAgentMessageEvent extends GenUiEventBase {
22
+ kind: 'agent.message';
23
+ text: string;
24
+ done?: boolean;
25
+ }
26
+ export interface GenUiToolCallEvent extends GenUiEventBase {
27
+ kind: 'tool_call';
28
+ toolName: string;
29
+ args: unknown;
30
+ callId?: string;
31
+ status?: 'started' | 'completed' | 'failed';
32
+ result?: unknown;
33
+ }
34
+ export interface GenUiStateUpdateEvent extends GenUiEventBase {
35
+ kind: 'state_update';
36
+ path: string;
37
+ value: unknown;
38
+ }
39
+ export interface GenUiSurfaceRequestedEvent extends GenUiEventBase {
40
+ kind: 'ui.surface_requested';
41
+ surfaceId: string;
42
+ surfaceKind: 'form' | 'choice' | 'confirmation' | 'oauth-prompt';
43
+ payload: unknown;
44
+ }
45
+ export interface GenUiSurfaceRespondedEvent extends GenUiEventBase {
46
+ kind: 'ui.surface_responded';
47
+ surfaceId: string;
48
+ value: unknown;
49
+ respondedBy: 'user' | 'agent' | 'auto' | 'cache';
50
+ }
51
+ export interface GenUiRunLifecycleEvent extends GenUiEventBase {
52
+ kind: 'run.lifecycle';
53
+ status: 'started' | 'pipeline_stage_started' | 'pipeline_stage_completed' | 'completed' | 'cancelled' | 'failed';
54
+ stageId?: string;
55
+ iteration?: number;
56
+ message?: string;
57
+ }
58
+ export type GenUiEvent = GenUiAgentMessageEvent | GenUiToolCallEvent | GenUiStateUpdateEvent | GenUiSurfaceRequestedEvent | GenUiSurfaceRespondedEvent | GenUiRunLifecycleEvent;
59
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/core/gen-ui/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,MAAM,cAAc,GACtB,eAAe,GACf,WAAW,GACX,cAAc,GACd,sBAAsB,GACtB,sBAAsB,GACtB,eAAe,CAAC;AAEpB,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,sBAAuB,SAAQ,cAAc;IAC5D,IAAI,EAAE,eAAe,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,kBAAmB,SAAQ,cAAc;IACxD,IAAI,EAAE,WAAW,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAC;IAC5C,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,qBAAsB,SAAQ,cAAc;IAC3D,IAAI,EAAE,cAAc,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,0BAA2B,SAAQ,cAAc;IAChE,IAAI,EAAE,sBAAsB,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,GAAG,QAAQ,GAAG,cAAc,GAAG,cAAc,CAAC;IACjE,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,0BAA2B,SAAQ,cAAc;IAChE,IAAI,EAAE,sBAAsB,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC;IACf,WAAW,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC;CAClD;AAED,MAAM,WAAW,sBAAuB,SAAQ,cAAc;IAC5D,IAAI,EAAE,eAAe,CAAC;IACtB,MAAM,EAAE,SAAS,GAAG,wBAAwB,GAAG,0BAA0B,GAAG,WAAW,GAAG,WAAW,GAAG,QAAQ,CAAC;IACjH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,UAAU,GAClB,sBAAsB,GACtB,kBAAkB,GAClB,qBAAqB,GACrB,0BAA0B,GAC1B,0BAA0B,GAC1B,sBAAsB,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @module agui/events
3
+ *
4
+ * The AG-UI wire event shapes `./encoder.ts` produces. AG-UI (Agent-User Interaction
5
+ * Protocol) is CopilotKit's open, external wire protocol for streaming an agent's run over SSE to
6
+ * a UI client — see https://github.com/ag-ui-protocol/ag-ui. This module is a near-verbatim port
7
+ * of a 312-line adapter that encoded a product's own run-event stream into this shape; the types
8
+ * themselves are unchanged in kind, only de-branded (see `source-map.md` for the full
9
+ * field-mapping table and provenance).
10
+ *
11
+ * Folded in 2026-07-26 from the standalone `@jini-ai/agui` package (plan §3a) into this `src/gen-ui/`
12
+ * subdirectory — see `./encoder.ts` for why it is kept apart from the flat `ag-ui.ts`.
13
+ */
14
+ export {};
15
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../../../src/core/gen-ui/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @module gen-ui
3
+ *
4
+ * Jini's **own** run-stream surface protocol — six event kinds (`agent.message`, `tool_call`,
5
+ * `state_update`, `ui.surface_requested`, `ui.surface_responded`, `run.lifecycle`) and the encoder
6
+ * that produces them from a `RunProtocolEvent` stream.
7
+ *
8
+ * **This is not AG-UI**, despite what this directory was called until 2026-07-27. The real
9
+ * Agent-User Interaction Protocol uses a 33-member `SCREAMING_SNAKE` event enum and shares zero
10
+ * event names with these six; `../ag-ui.ts` is the genuine AG-UI projection and lives at `src/`
11
+ * root, apart from this. See `source-map.md` for how the two came to be confused.
12
+ *
13
+ * Nothing here opens a connection or touches a browser global. Transport (SSE, WebSocket) belongs
14
+ * to a host — `@jini-ai/http-kit`'s run-stream route is the shipped consumer.
15
+ */
16
+ export { createGenUiEncoder, type GenUiEncodeContext, type GenUiEncoder, } from './encoder.js';
17
+ export type { GenUiAgentMessageEvent, GenUiEvent, GenUiEventBase, GenUiEventKind, GenUiRunLifecycleEvent, GenUiStateUpdateEvent, GenUiSurfaceRequestedEvent, GenUiSurfaceRespondedEvent, GenUiToolCallEvent, } from './events.js';
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/gen-ui/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,kBAAkB,EAClB,KAAK,kBAAkB,EACvB,KAAK,YAAY,GAClB,MAAM,cAAc,CAAC;AAEtB,YAAY,EACV,sBAAsB,EACtB,UAAU,EACV,cAAc,EACd,cAAc,EACd,sBAAsB,EACtB,qBAAqB,EACrB,0BAA0B,EAC1B,0BAA0B,EAC1B,kBAAkB,GACnB,MAAM,aAAa,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @module gen-ui
3
+ *
4
+ * Jini's **own** run-stream surface protocol — six event kinds (`agent.message`, `tool_call`,
5
+ * `state_update`, `ui.surface_requested`, `ui.surface_responded`, `run.lifecycle`) and the encoder
6
+ * that produces them from a `RunProtocolEvent` stream.
7
+ *
8
+ * **This is not AG-UI**, despite what this directory was called until 2026-07-27. The real
9
+ * Agent-User Interaction Protocol uses a 33-member `SCREAMING_SNAKE` event enum and shares zero
10
+ * event names with these six; `../ag-ui.ts` is the genuine AG-UI projection and lives at `src/`
11
+ * root, apart from this. See `source-map.md` for how the two came to be confused.
12
+ *
13
+ * Nothing here opens a connection or touches a browser global. Transport (SSE, WebSocket) belongs
14
+ * to a host — `@jini-ai/http-kit`'s run-stream route is the shipped consumer.
15
+ */
16
+ export { createGenUiEncoder, } from './encoder.js';
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/gen-ui/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,kBAAkB,GAGnB,MAAM,cAAc,CAAC"}