@jini-ai/agentic 0.4.3 → 0.4.5

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 (94) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/core/a2ui/json-pointer.js +94 -73
  3. package/dist/core/a2ui/resolve.js +45 -23
  4. package/dist/core/a2ui/tree.js +8 -5
  5. package/dist/core/capability.js +21 -12
  6. package/dist/core/dom/dom-page-driver.js +89 -74
  7. package/dist/core/gen-ui/encoder.js +31 -31
  8. package/dist/core/guards.js +13 -6
  9. package/dist/core/handle.d.ts +13 -0
  10. package/dist/core/handle.js +19 -0
  11. package/dist/core/index.d.ts +2 -1
  12. package/dist/core/index.js +2 -1
  13. package/dist/core/mcp-ui-apps.js +12 -6
  14. package/dist/core/page-executor.js +131 -111
  15. package/dist/core/site-guide/index.d.ts +4 -0
  16. package/dist/core/site-guide/index.js +4 -0
  17. package/dist/core/site-guide/site-guide.d.ts +18 -0
  18. package/dist/core/site-guide/site-guide.js +162 -0
  19. package/dist/core/site-guide/topic-schema.d.ts +16 -0
  20. package/dist/core/site-guide/topic-schema.js +68 -0
  21. package/dist/core/site-guide/types.d.ts +83 -0
  22. package/dist/core/site-guide/types.js +2 -0
  23. package/dist/skills/install/archive.js +42 -30
  24. package/dist/skills/install/github.js +102 -63
  25. package/dist/skills/install/index.d.ts +1 -0
  26. package/dist/skills/install/index.js +1 -0
  27. package/dist/skills/install/install-service.d.ts +20 -1
  28. package/dist/skills/install/install-service.js +23 -11
  29. package/dist/skills/install/layout.d.ts +8 -0
  30. package/dist/skills/install/layout.js +26 -1
  31. package/dist/skills/install/live-registration.js +1 -0
  32. package/dist/skills/install/node-filesystem.js +3 -1
  33. package/dist/skills/install/state.js +18 -7
  34. package/dist/skills/install/validation.d.ts +5 -1
  35. package/dist/skills/install/validation.js +85 -52
  36. package/dist/skills/install/yauzl-archive-reader.d.ts +29 -0
  37. package/dist/skills/install/yauzl-archive-reader.js +31 -0
  38. package/package.json +4 -4
  39. package/dist/a2ui/agent-to-renderer.d.ts +0 -613
  40. package/dist/a2ui/agent-to-renderer.js +0 -191
  41. package/dist/a2ui/catalog.d.ts +0 -73
  42. package/dist/a2ui/catalog.js +0 -304
  43. package/dist/a2ui/common-types.d.ts +0 -401
  44. package/dist/a2ui/common-types.js +0 -130
  45. package/dist/a2ui/index.d.ts +0 -16
  46. package/dist/a2ui/index.js +0 -16
  47. package/dist/a2ui/interpreter.d.ts +0 -71
  48. package/dist/a2ui/interpreter.js +0 -337
  49. package/dist/a2ui/json-pointer.d.ts +0 -48
  50. package/dist/a2ui/json-pointer.js +0 -174
  51. package/dist/a2ui/renderer-to-agent.d.ts +0 -342
  52. package/dist/a2ui/renderer-to-agent.js +0 -111
  53. package/dist/a2ui/resolve.d.ts +0 -28
  54. package/dist/a2ui/resolve.js +0 -144
  55. package/dist/a2ui/tree.d.ts +0 -66
  56. package/dist/a2ui/tree.js +0 -74
  57. package/dist/ag-ui.d.ts +0 -82
  58. package/dist/ag-ui.js +0 -85
  59. package/dist/agui/encoder.d.ts +0 -50
  60. package/dist/agui/encoder.js +0 -97
  61. package/dist/agui/events.d.ts +0 -59
  62. package/dist/agui/events.js +0 -15
  63. package/dist/capability.d.ts +0 -81
  64. package/dist/capability.js +0 -79
  65. package/dist/dom/dom-page-driver.d.ts +0 -36
  66. package/dist/dom/dom-page-driver.js +0 -601
  67. package/dist/dom/index.d.ts +0 -17
  68. package/dist/dom/index.js +0 -17
  69. package/dist/dom/model-context.d.ts +0 -69
  70. package/dist/dom/model-context.js +0 -44
  71. package/dist/element-handles.d.ts +0 -120
  72. package/dist/element-handles.js +0 -39
  73. package/dist/gen-ui/encoder.d.ts +0 -50
  74. package/dist/gen-ui/encoder.js +0 -97
  75. package/dist/gen-ui/events.d.ts +0 -59
  76. package/dist/gen-ui/events.js +0 -15
  77. package/dist/gen-ui/index.d.ts +0 -18
  78. package/dist/gen-ui/index.js +0 -17
  79. package/dist/guards.d.ts +0 -96
  80. package/dist/guards.js +0 -186
  81. package/dist/handle.d.ts +0 -41
  82. package/dist/handle.js +0 -41
  83. package/dist/mcp-ui-apps.d.ts +0 -223
  84. package/dist/mcp-ui-apps.js +0 -252
  85. package/dist/mcp-ui.d.ts +0 -133
  86. package/dist/mcp-ui.js +0 -134
  87. package/dist/page-capabilities.d.ts +0 -14
  88. package/dist/page-capabilities.js +0 -129
  89. package/dist/page-driver.d.ts +0 -120
  90. package/dist/page-driver.js +0 -2
  91. package/dist/page-executor.d.ts +0 -94
  92. package/dist/page-executor.js +0 -320
  93. package/dist/webmcp.d.ts +0 -202
  94. package/dist/webmcp.js +0 -173
@@ -1,69 +0,0 @@
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
@@ -1,44 +0,0 @@
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
@@ -1,120 +0,0 @@
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
@@ -1,39 +0,0 @@
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
@@ -1,50 +0,0 @@
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
@@ -1,97 +0,0 @@
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
@@ -1,59 +0,0 @@
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
@@ -1,15 +0,0 @@
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
@@ -1,18 +0,0 @@
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
@@ -1,17 +0,0 @@
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
package/dist/guards.d.ts DELETED
@@ -1,96 +0,0 @@
1
- /**
2
- * @module guards
3
- *
4
- * The refusals that must hold on every surface, expressed over plain descriptors rather than
5
- * DOM nodes so they are testable in Node and reusable from any framework binding.
6
- *
7
- * Both guards here answer review findings that an allowlist alone does not cover: a generic
8
- * filler will happily type into a password or card-number field even when that field carries a
9
- * legitimate handle, and `data-agent-label` is page-authored text that reaches a model as if
10
- * the host had written it.
11
- */
12
- /** The subset of an input element these guards need. Framework- and DOM-free by design. */
13
- export interface FieldDescriptor {
14
- /** The `type` attribute, lowercased. */
15
- readonly type?: string | undefined;
16
- /** The `autocomplete` attribute, lowercased. */
17
- readonly autocomplete?: string | undefined;
18
- readonly name?: string | undefined;
19
- readonly id?: string | undefined;
20
- /**
21
- * **Every** human-visible naming of the field the driver could resolve — `aria-label`,
22
- * `placeholder`, and the text of each associated `<label>`.
23
- *
24
- * Carried because `name`/`id` are the *machine* names, and a form builder or CMS that emits
25
- * `name="field_47"` leaves the guard nothing to judge while the page still plainly reads
26
- * "Card number" to the user. A field whose sensitivity is stated only in its label was
27
- * invisible to every refusal here until this existed.
28
- *
29
- * Plural, and required to be exhaustive, because the singular form this replaced took whichever
30
- * source resolved *first*: a page could then mask a sensitive field behind a benign one —
31
- * `<label for=f>Card number</label><input id=f name=field_47 placeholder="Enter value">` reached
32
- * the guard as the single label "Enter value", and its value was reported back in full.
33
- */
34
- readonly accessibleLabels?: readonly string[] | undefined;
35
- readonly readOnly?: boolean | undefined;
36
- readonly disabled?: boolean | undefined;
37
- }
38
- /**
39
- * The refusals that are about *secrecy* — the field's contents are not an agent's to know.
40
- *
41
- * Separated from the two writability refusals below because reading and writing are different
42
- * questions with different answers. A read-only field's value is perfectly safe to read back; a
43
- * password's is not safe to read even though it is, mechanically, just as readable. Folding both
44
- * into one list would either leak the password or hide the read-only field's value for no reason.
45
- */
46
- export type FieldReadRefusal = 'denied-type' | 'denied-autocomplete' | 'suspicious-name';
47
- export type FieldRefusal = FieldReadRefusal | 'not-text' | 'read-only' | 'disabled';
48
- /**
49
- * Why this field's current value must not be reported back to a caller, or `null` when reading
50
- * it is safe.
51
- *
52
- * Reading is the strictly more dangerous direction: writing into a password box gives an agent
53
- * nothing, whereas reading one out hands over the secret itself. So every secrecy signal the fill
54
- * guard uses applies here identically — type, autocomplete token, and a name or id that indicates
55
- * a credential or anti-forgery token — and none of them may be relaxed for reads.
56
- *
57
- * @param field - The field's attributes.
58
- * @returns The first secrecy refusal, or `null` when the value may be reported.
59
- */
60
- export declare function findFieldReadRefusal(field: FieldDescriptor): FieldReadRefusal | null;
61
- /**
62
- * Why an automated fill must be refused for this field, or `null` when it is safe to write.
63
- *
64
- * Fails closed on anything that looks like a credential, payment instrument, one-time code, or
65
- * anti-forgery token, independent of whether the field carries an agent handle. Tagging a
66
- * password box does not make it fillable. Every secrecy refusal is also a fill refusal — a field
67
- * whose contents an agent may not read is certainly not one it may overwrite — and two further
68
- * refusals cover fields that are simply not writable.
69
- *
70
- * @param field - The field's attributes.
71
- * @returns The first refusal reason, or `null` when the field may be filled.
72
- */
73
- export declare function findFieldFillRefusal(field: FieldDescriptor): FieldRefusal | null;
74
- /** Model-readable reason for a refusal, so a blocked fill explains itself instead of failing opaquely. */
75
- export declare function describeFieldRefusal(refusal: FieldRefusal): string;
76
- /** Model-readable reason a value was withheld, so a caller knows the field has contents it may not see rather than assuming it is empty. */
77
- export declare function describeFieldReadRefusal(refusal: FieldReadRefusal): string;
78
- /** Default cap on page-authored text handed to a model. */
79
- export declare const MAX_AGENT_LABEL_LENGTH = 200;
80
- export interface NormalizedLabel {
81
- readonly text: string;
82
- readonly truncated: boolean;
83
- }
84
- /**
85
- * Normalizes page-authored text before it reaches a model.
86
- *
87
- * Strips control characters (including the bidirectional overrides used to make text render
88
- * differently from how it reads), collapses whitespace, and caps the length. The result is still
89
- * untrusted *content* — this only bounds it; it does not make it safe to follow as instruction.
90
- *
91
- * @param raw - Text read off the page, e.g. a `data-agent-label`.
92
- * @param maxLength - Cap, defaulting to {@link MAX_AGENT_LABEL_LENGTH}.
93
- * @returns The bounded text and whether anything was cut.
94
- */
95
- export declare function normalizeAgentLabel(raw: string, maxLength?: number): NormalizedLabel;
96
- //# sourceMappingURL=guards.d.ts.map