@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.
- package/README.md +92 -0
- package/dist/a2ui/agent-to-renderer.d.ts +36 -2
- package/dist/a2ui/agent-to-renderer.d.ts.map +1 -1
- package/dist/a2ui/agent-to-renderer.js +23 -1
- package/dist/a2ui/agent-to-renderer.js.map +1 -1
- package/dist/a2ui/interpreter.d.ts +24 -1
- package/dist/a2ui/interpreter.d.ts.map +1 -1
- package/dist/a2ui/interpreter.js +115 -65
- package/dist/a2ui/interpreter.js.map +1 -1
- package/dist/a2ui/json-pointer.d.ts.map +1 -1
- package/dist/a2ui/json-pointer.js +28 -3
- package/dist/a2ui/json-pointer.js.map +1 -1
- package/dist/a2ui/renderer-to-agent.d.ts +35 -11
- package/dist/a2ui/renderer-to-agent.d.ts.map +1 -1
- package/dist/a2ui/renderer-to-agent.js +15 -2
- package/dist/a2ui/renderer-to-agent.js.map +1 -1
- package/dist/a2ui/resolve.d.ts +1 -1
- package/dist/a2ui/resolve.d.ts.map +1 -1
- package/dist/a2ui/resolve.js +29 -3
- package/dist/a2ui/resolve.js.map +1 -1
- package/dist/a2ui/tree.d.ts +27 -2
- package/dist/a2ui/tree.d.ts.map +1 -1
- package/dist/a2ui/tree.js +48 -9
- package/dist/a2ui/tree.js.map +1 -1
- package/dist/ag-ui.d.ts.map +1 -1
- package/dist/ag-ui.js +30 -1
- package/dist/ag-ui.js.map +1 -1
- package/dist/core/a2ui/agent-to-renderer.d.ts +613 -0
- package/dist/core/a2ui/agent-to-renderer.d.ts.map +1 -0
- package/dist/core/a2ui/agent-to-renderer.js +191 -0
- package/dist/core/a2ui/agent-to-renderer.js.map +1 -0
- package/dist/core/a2ui/catalog.d.ts +73 -0
- package/dist/core/a2ui/catalog.d.ts.map +1 -0
- package/dist/core/a2ui/catalog.js +304 -0
- package/dist/core/a2ui/catalog.js.map +1 -0
- package/dist/core/a2ui/common-types.d.ts +401 -0
- package/dist/core/a2ui/common-types.d.ts.map +1 -0
- package/dist/core/a2ui/common-types.js +130 -0
- package/dist/core/a2ui/common-types.js.map +1 -0
- package/dist/core/a2ui/index.d.ts +16 -0
- package/dist/core/a2ui/index.d.ts.map +1 -0
- package/dist/core/a2ui/index.js +16 -0
- package/dist/core/a2ui/index.js.map +1 -0
- package/dist/core/a2ui/interpreter.d.ts +71 -0
- package/dist/core/a2ui/interpreter.d.ts.map +1 -0
- package/dist/core/a2ui/interpreter.js +341 -0
- package/dist/core/a2ui/interpreter.js.map +1 -0
- package/dist/core/a2ui/json-pointer.d.ts +48 -0
- package/dist/core/a2ui/json-pointer.d.ts.map +1 -0
- package/dist/core/a2ui/json-pointer.js +174 -0
- package/dist/core/a2ui/json-pointer.js.map +1 -0
- package/dist/core/a2ui/renderer-to-agent.d.ts +342 -0
- package/dist/core/a2ui/renderer-to-agent.d.ts.map +1 -0
- package/dist/core/a2ui/renderer-to-agent.js +111 -0
- package/dist/core/a2ui/renderer-to-agent.js.map +1 -0
- package/dist/core/a2ui/resolve.d.ts +28 -0
- package/dist/core/a2ui/resolve.d.ts.map +1 -0
- package/dist/core/a2ui/resolve.js +144 -0
- package/dist/core/a2ui/resolve.js.map +1 -0
- package/dist/core/a2ui/tree.d.ts +66 -0
- package/dist/core/a2ui/tree.d.ts.map +1 -0
- package/dist/core/a2ui/tree.js +74 -0
- package/dist/core/a2ui/tree.js.map +1 -0
- package/dist/core/ag-ui.d.ts +82 -0
- package/dist/core/ag-ui.d.ts.map +1 -0
- package/dist/core/ag-ui.js +85 -0
- package/dist/core/ag-ui.js.map +1 -0
- package/dist/core/capability.d.ts +81 -0
- package/dist/core/capability.d.ts.map +1 -0
- package/dist/core/capability.js +79 -0
- package/dist/core/capability.js.map +1 -0
- package/dist/core/dom/dom-page-driver.d.ts +36 -0
- package/dist/core/dom/dom-page-driver.d.ts.map +1 -0
- package/dist/core/dom/dom-page-driver.js +601 -0
- package/dist/core/dom/dom-page-driver.js.map +1 -0
- package/dist/core/dom/index.d.ts +17 -0
- package/dist/core/dom/index.d.ts.map +1 -0
- package/dist/core/dom/index.js +17 -0
- package/dist/core/dom/index.js.map +1 -0
- package/dist/core/dom/model-context.d.ts +69 -0
- package/dist/core/dom/model-context.d.ts.map +1 -0
- package/dist/core/dom/model-context.js +44 -0
- package/dist/core/dom/model-context.js.map +1 -0
- package/dist/core/element-handles.d.ts +120 -0
- package/dist/core/element-handles.d.ts.map +1 -0
- package/dist/core/element-handles.js +39 -0
- package/dist/core/element-handles.js.map +1 -0
- package/dist/core/gen-ui/encoder.d.ts +50 -0
- package/dist/core/gen-ui/encoder.d.ts.map +1 -0
- package/dist/core/gen-ui/encoder.js +97 -0
- package/dist/core/gen-ui/encoder.js.map +1 -0
- package/dist/core/gen-ui/events.d.ts +59 -0
- package/dist/core/gen-ui/events.d.ts.map +1 -0
- package/dist/core/gen-ui/events.js +15 -0
- package/dist/core/gen-ui/events.js.map +1 -0
- package/dist/core/gen-ui/index.d.ts +18 -0
- package/dist/core/gen-ui/index.d.ts.map +1 -0
- package/dist/core/gen-ui/index.js +17 -0
- package/dist/core/gen-ui/index.js.map +1 -0
- package/dist/core/guards.d.ts +96 -0
- package/dist/core/guards.d.ts.map +1 -0
- package/dist/core/guards.js +186 -0
- package/dist/core/guards.js.map +1 -0
- package/dist/core/handle.d.ts +89 -0
- package/dist/core/handle.d.ts.map +1 -0
- package/dist/core/handle.js +88 -0
- package/dist/core/handle.js.map +1 -0
- package/dist/core/index.d.ts +75 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +74 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/list-handles.d.ts +43 -0
- package/dist/core/list-handles.d.ts.map +1 -0
- package/dist/core/list-handles.js +57 -0
- package/dist/core/list-handles.js.map +1 -0
- package/dist/core/mcp-ui-apps.d.ts +223 -0
- package/dist/core/mcp-ui-apps.d.ts.map +1 -0
- package/dist/core/mcp-ui-apps.js +252 -0
- package/dist/core/mcp-ui-apps.js.map +1 -0
- package/dist/core/page-capabilities.d.ts +14 -0
- package/dist/core/page-capabilities.d.ts.map +1 -0
- package/dist/core/page-capabilities.js +129 -0
- package/dist/core/page-capabilities.js.map +1 -0
- package/dist/core/page-driver.d.ts +120 -0
- package/dist/core/page-driver.d.ts.map +1 -0
- package/dist/core/page-driver.js +2 -0
- package/dist/core/page-driver.js.map +1 -0
- package/dist/core/page-executor.d.ts +94 -0
- package/dist/core/page-executor.d.ts.map +1 -0
- package/dist/core/page-executor.js +320 -0
- package/dist/core/page-executor.js.map +1 -0
- package/dist/core/webmcp.d.ts +202 -0
- package/dist/core/webmcp.d.ts.map +1 -0
- package/dist/core/webmcp.js +173 -0
- package/dist/core/webmcp.js.map +1 -0
- package/dist/dom/dom-page-driver.d.ts +9 -2
- package/dist/dom/dom-page-driver.d.ts.map +1 -1
- package/dist/dom/dom-page-driver.js +84 -40
- package/dist/dom/dom-page-driver.js.map +1 -1
- package/dist/dom/index.d.ts +1 -1
- package/dist/dom/index.d.ts.map +1 -1
- package/dist/dom/index.js +1 -1
- package/dist/dom/index.js.map +1 -1
- package/dist/element-handles.d.ts +22 -1
- package/dist/element-handles.d.ts.map +1 -1
- package/dist/gen-ui/encoder.d.ts +8 -8
- package/dist/gen-ui/encoder.d.ts.map +1 -1
- package/dist/gen-ui/encoder.js +2 -2
- package/dist/gen-ui/encoder.js.map +1 -1
- package/dist/gen-ui/events.d.ts +10 -10
- package/dist/gen-ui/events.d.ts.map +1 -1
- package/dist/gen-ui/index.d.ts +3 -3
- package/dist/gen-ui/index.d.ts.map +1 -1
- package/dist/gen-ui/index.js +2 -2
- package/dist/gen-ui/index.js.map +1 -1
- package/dist/guards.d.ts +8 -3
- package/dist/guards.d.ts.map +1 -1
- package/dist/guards.js +6 -1
- package/dist/guards.js.map +1 -1
- package/dist/index.d.ts +4 -62
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -61
- package/dist/index.js.map +1 -1
- package/dist/mcp-ui-apps.d.ts +19 -0
- package/dist/mcp-ui-apps.d.ts.map +1 -1
- package/dist/mcp-ui-apps.js +50 -5
- package/dist/mcp-ui-apps.js.map +1 -1
- package/dist/page-capabilities.js +6 -6
- package/dist/page-capabilities.js.map +1 -1
- package/dist/page-driver.d.ts +15 -2
- package/dist/page-driver.d.ts.map +1 -1
- package/dist/page-executor.d.ts +11 -4
- package/dist/page-executor.d.ts.map +1 -1
- package/dist/page-executor.js +47 -15
- package/dist/page-executor.js.map +1 -1
- package/package.json +16 -9
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module tree
|
|
3
|
+
*
|
|
4
|
+
* Flattens the component adjacency list (`id -> ComponentInstance`, each instance's `children`
|
|
5
|
+
* being an array of other ids) into an ordered, depth-first render list — the two adversarial
|
|
6
|
+
* cases this exists to answer sanely: **a child id that doesn't exist** in the map, and **a
|
|
7
|
+
* circular reference** (A -> B -> A). Neither may crash or infinite-loop a renderer; both must
|
|
8
|
+
* degrade to a visible, inert placeholder node instead.
|
|
9
|
+
*
|
|
10
|
+
* Scope: only the *static array* form of `ChildList` (`common_types.json#/$defs/ChildList`'s
|
|
11
|
+
* first `oneOf` branch) is walked here. The *template* form (`{componentId, path}`, generating N
|
|
12
|
+
* children from a data-model list) is accepted by the wire schema (`ChildListSchema`) but not
|
|
13
|
+
* expanded by this port — see `../source-map.md` for why (a distinct, substantially larger
|
|
14
|
+
* rendering feature: item-scoped relative-path resolution, `@index`, per-item React keys for one
|
|
15
|
+
* shared component definition rendered N times). A `getChildIds` callback that always returns
|
|
16
|
+
* `[]` for a template-shaped `children` value is a safe, honest way to consume this module without
|
|
17
|
+
* pretending template lists render.
|
|
18
|
+
*/
|
|
19
|
+
export interface ComponentLike {
|
|
20
|
+
readonly id: string;
|
|
21
|
+
}
|
|
22
|
+
export type RenderNodeStatus = 'ok' | 'missing' | 'cycle' | 'truncated';
|
|
23
|
+
export interface RenderNode {
|
|
24
|
+
readonly id: string;
|
|
25
|
+
readonly depth: number;
|
|
26
|
+
readonly status: RenderNodeStatus;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Ceiling on how many nodes one flattening may produce.
|
|
30
|
+
*
|
|
31
|
+
* The cycle check bounds *repetition along one path*; it does not bound the tree's size, and a
|
|
32
|
+
* component map is an adjacency list, so a valid acyclic message can name the same child twice per
|
|
33
|
+
* level and double the output at every step. Measured before this cap existed: 24 components —
|
|
34
|
+
* a few hundred bytes of wire data — expanded to 16,777,215 render nodes in ~15 seconds. Nothing
|
|
35
|
+
* crashed; the renderer was simply consumed.
|
|
36
|
+
*
|
|
37
|
+
* Far above any real UI (the largest component tree a catalog of 18 types could sensibly produce
|
|
38
|
+
* is orders of magnitude smaller), so this is a fail-safe, not a design budget.
|
|
39
|
+
*/
|
|
40
|
+
export declare const MAX_RENDER_NODES = 50000;
|
|
41
|
+
/**
|
|
42
|
+
* @param components The full component map (id -> instance).
|
|
43
|
+
* @param rootId The id to start walking from (typically `'root'`, but not assumed — a surface
|
|
44
|
+
* with no `root` component yet is the caller's concern, not this function's; see
|
|
45
|
+
* `interpreter.ts`'s `getRoot()`).
|
|
46
|
+
* @param getChildIds Given a present component, returns its child ids in render order (`[]` for
|
|
47
|
+
* a leaf, or a template-shaped `ChildList` this port doesn't expand — see module doc).
|
|
48
|
+
* @returns A depth-first, pre-order flattening. A `missing` node is a leaf in the output (its own
|
|
49
|
+
* children are never visited — there is nothing to look up). A `cycle` node is also a leaf: the
|
|
50
|
+
* id is emitted once more so a renderer can show *where* the cycle closes, but its children are
|
|
51
|
+
* not walked again (that walk already happened higher up the same path). A `truncated` node is the
|
|
52
|
+
* third such marker and always the last entry: the tree exceeded {@link MAX_RENDER_NODES} and the
|
|
53
|
+
* rest was not walked.
|
|
54
|
+
*
|
|
55
|
+
* The walk is iterative — an explicit stack rather than recursion — because the component map is
|
|
56
|
+
* agent-authored: a straight chain of components is a legal, acyclic message, and a recursive walk
|
|
57
|
+
* died on one with `RangeError: Maximum call stack size exceeded` somewhere past 6,000 links.
|
|
58
|
+
* Degrading sanely on hostile input is this module's whole purpose, and "deep" belongs on that
|
|
59
|
+
* list next to "missing" and "circular".
|
|
60
|
+
*
|
|
61
|
+
* The ancestor set is maintained by push/pop along the current path rather than copied per node,
|
|
62
|
+
* which is both what makes the iterative form equivalent (an ancestor set IS the path from the
|
|
63
|
+
* root) and what removes the old walk's quadratic set-copying cost.
|
|
64
|
+
*/
|
|
65
|
+
export declare function flattenRenderTree<C extends ComponentLike>(components: ReadonlyMap<string, C>, rootId: string, getChildIds: (component: C) => readonly string[]): RenderNode[];
|
|
66
|
+
//# sourceMappingURL=tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["../../../src/core/a2ui/tree.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,MAAM,gBAAgB,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,GAAG,WAAW,CAAC;AAExE,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;CACnC;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gBAAgB,QAAS,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,aAAa,EACvD,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,EAClC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,CAAC,SAAS,EAAE,CAAC,KAAK,SAAS,MAAM,EAAE,GAC/C,UAAU,EAAE,CAuCd"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ceiling on how many nodes one flattening may produce.
|
|
3
|
+
*
|
|
4
|
+
* The cycle check bounds *repetition along one path*; it does not bound the tree's size, and a
|
|
5
|
+
* component map is an adjacency list, so a valid acyclic message can name the same child twice per
|
|
6
|
+
* level and double the output at every step. Measured before this cap existed: 24 components —
|
|
7
|
+
* a few hundred bytes of wire data — expanded to 16,777,215 render nodes in ~15 seconds. Nothing
|
|
8
|
+
* crashed; the renderer was simply consumed.
|
|
9
|
+
*
|
|
10
|
+
* Far above any real UI (the largest component tree a catalog of 18 types could sensibly produce
|
|
11
|
+
* is orders of magnitude smaller), so this is a fail-safe, not a design budget.
|
|
12
|
+
*/
|
|
13
|
+
export const MAX_RENDER_NODES = 50_000;
|
|
14
|
+
/**
|
|
15
|
+
* @param components The full component map (id -> instance).
|
|
16
|
+
* @param rootId The id to start walking from (typically `'root'`, but not assumed — a surface
|
|
17
|
+
* with no `root` component yet is the caller's concern, not this function's; see
|
|
18
|
+
* `interpreter.ts`'s `getRoot()`).
|
|
19
|
+
* @param getChildIds Given a present component, returns its child ids in render order (`[]` for
|
|
20
|
+
* a leaf, or a template-shaped `ChildList` this port doesn't expand — see module doc).
|
|
21
|
+
* @returns A depth-first, pre-order flattening. A `missing` node is a leaf in the output (its own
|
|
22
|
+
* children are never visited — there is nothing to look up). A `cycle` node is also a leaf: the
|
|
23
|
+
* id is emitted once more so a renderer can show *where* the cycle closes, but its children are
|
|
24
|
+
* not walked again (that walk already happened higher up the same path). A `truncated` node is the
|
|
25
|
+
* third such marker and always the last entry: the tree exceeded {@link MAX_RENDER_NODES} and the
|
|
26
|
+
* rest was not walked.
|
|
27
|
+
*
|
|
28
|
+
* The walk is iterative — an explicit stack rather than recursion — because the component map is
|
|
29
|
+
* agent-authored: a straight chain of components is a legal, acyclic message, and a recursive walk
|
|
30
|
+
* died on one with `RangeError: Maximum call stack size exceeded` somewhere past 6,000 links.
|
|
31
|
+
* Degrading sanely on hostile input is this module's whole purpose, and "deep" belongs on that
|
|
32
|
+
* list next to "missing" and "circular".
|
|
33
|
+
*
|
|
34
|
+
* The ancestor set is maintained by push/pop along the current path rather than copied per node,
|
|
35
|
+
* which is both what makes the iterative form equivalent (an ancestor set IS the path from the
|
|
36
|
+
* root) and what removes the old walk's quadratic set-copying cost.
|
|
37
|
+
*/
|
|
38
|
+
export function flattenRenderTree(components, rootId, getChildIds) {
|
|
39
|
+
const output = [];
|
|
40
|
+
/** Ids on the path from the root to the node being visited — the recursive walk's `ancestors`. */
|
|
41
|
+
const ancestors = new Set();
|
|
42
|
+
const stack = [{ id: rootId, depth: 0 }];
|
|
43
|
+
while (stack.length > 0) {
|
|
44
|
+
const frame = stack.pop();
|
|
45
|
+
if ('leave' in frame) {
|
|
46
|
+
ancestors.delete(frame.leave);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (output.length >= MAX_RENDER_NODES) {
|
|
50
|
+
output.push({ id: frame.id, depth: frame.depth, status: 'truncated' });
|
|
51
|
+
return output;
|
|
52
|
+
}
|
|
53
|
+
const { id, depth } = frame;
|
|
54
|
+
if (ancestors.has(id)) {
|
|
55
|
+
output.push({ id, depth, status: 'cycle' });
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const component = components.get(id);
|
|
59
|
+
if (!component) {
|
|
60
|
+
output.push({ id, depth, status: 'missing' });
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
output.push({ id, depth, status: 'ok' });
|
|
64
|
+
ancestors.add(id);
|
|
65
|
+
stack.push({ leave: id });
|
|
66
|
+
// Pushed in reverse so the first child is popped first, preserving pre-order.
|
|
67
|
+
const childIds = getChildIds(component);
|
|
68
|
+
for (let index = childIds.length - 1; index >= 0; index -= 1) {
|
|
69
|
+
stack.push({ id: childIds[index], depth: depth + 1 });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return output;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=tree.js.map
|
|
@@ -0,0 +1 @@
|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CAAC;QACrC,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;YAC9C,SAAS;QACX,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;QACzC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAClB,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;QAC1B,8EAA8E;QAC9E,MAAM,QAAQ,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC;QACxC,KAAK,IAAI,KAAK,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;YAC7D,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,QAAQ,CAAC,KAAK,CAAE,EAAE,KAAK,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module ag-ui
|
|
3
|
+
*
|
|
4
|
+
* Projection: {@link CapabilityDef} → an AG-UI frontend tool.
|
|
5
|
+
*
|
|
6
|
+
* AG-UI (the Agent-User Interaction Protocol) streams typed events between an agent backend and
|
|
7
|
+
* a frontend. The relevant half here is its **frontend tool calls**: the frontend passes its
|
|
8
|
+
* tools in `RunAgentInput.tools`, the agent emits a tool call, the frontend executes it, and the
|
|
9
|
+
* frontend returns a `role: "tool"` message referencing the call id. That is the same handoff
|
|
10
|
+
* Jini's capabilities describe, which is why this projection is a rename rather than a redesign.
|
|
11
|
+
*
|
|
12
|
+
* One shape difference this file exists to absorb: **AG-UI names the JSON Schema field
|
|
13
|
+
* `parameters`**, where WebMCP and MCP both name it `inputSchema`. Anything reading a manifest
|
|
14
|
+
* through the wrong name silently sends a tool with no arguments.
|
|
15
|
+
*
|
|
16
|
+
* Transport is not here — AG-UI runs over SSE or WebSocket, and this package opens no
|
|
17
|
+
* connections. This is the vocabulary translation only.
|
|
18
|
+
*/
|
|
19
|
+
import type { CapabilityDef, CapabilityInputSchema } from './capability.js';
|
|
20
|
+
/** An AG-UI tool as passed in `RunAgentInput.tools`. */
|
|
21
|
+
export interface AgUiTool {
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly description: string;
|
|
24
|
+
/** JSON Schema. Note the field name: AG-UI says `parameters`, not `inputSchema`. */
|
|
25
|
+
readonly parameters: CapabilityInputSchema;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The tool-call event names AG-UI emits, agent → frontend.
|
|
29
|
+
*
|
|
30
|
+
* Arguments stream: `TOOL_CALL_ARGS` carries a `delta` fragment and may arrive many times for
|
|
31
|
+
* one call, so a consumer must accumulate by `toolCallId` and only execute after
|
|
32
|
+
* `TOOL_CALL_END`. Acting on a partial argument object is the obvious failure here.
|
|
33
|
+
*/
|
|
34
|
+
export declare const AG_UI_TOOL_CALL_EVENTS: {
|
|
35
|
+
/** Fields: `toolCallId`, `toolCallName`, optional `parentMessageId`. */
|
|
36
|
+
readonly start: "TOOL_CALL_START";
|
|
37
|
+
/** Fields: `toolCallId`, `delta` — a JSON fragment, not a complete object. */
|
|
38
|
+
readonly args: "TOOL_CALL_ARGS";
|
|
39
|
+
/** Fields: `toolCallId`. Arguments are complete only once this arrives. */
|
|
40
|
+
readonly end: "TOOL_CALL_END";
|
|
41
|
+
};
|
|
42
|
+
/** The message a frontend returns after executing a tool call. */
|
|
43
|
+
export interface AgUiToolResultMessage {
|
|
44
|
+
readonly id: string;
|
|
45
|
+
readonly role: 'tool';
|
|
46
|
+
readonly content: string;
|
|
47
|
+
readonly toolCallId: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Projects one capability into an AG-UI tool.
|
|
51
|
+
*
|
|
52
|
+
* @param capability - The capability to expose.
|
|
53
|
+
* @returns The tool entry for `RunAgentInput.tools`.
|
|
54
|
+
*/
|
|
55
|
+
export declare function toAgUiTool(capability: CapabilityDef): AgUiTool;
|
|
56
|
+
/**
|
|
57
|
+
* Projects a whole manifest.
|
|
58
|
+
*
|
|
59
|
+
* @param capabilities - Capabilities to expose, already filtered by whatever policy applies.
|
|
60
|
+
* @returns One tool per capability, in manifest order.
|
|
61
|
+
*/
|
|
62
|
+
export declare function toAgUiTools(capabilities: readonly CapabilityDef[]): readonly AgUiTool[];
|
|
63
|
+
/**
|
|
64
|
+
* Builds the result message for a completed frontend tool call.
|
|
65
|
+
*
|
|
66
|
+
* AG-UI carries the result as a string, so structured output is JSON-encoded. Errors are
|
|
67
|
+
* returned through this same channel rather than thrown — the agent needs to see the refusal
|
|
68
|
+
* (a fill guard saying no, an unavailable capability) as a result it can reason about.
|
|
69
|
+
*
|
|
70
|
+
* @param messageId - Id for the result message itself.
|
|
71
|
+
* @param toolCallId - The `toolCallId` from `TOOL_CALL_START`.
|
|
72
|
+
* @param outcome - What happened.
|
|
73
|
+
* @returns The `role: "tool"` message to send back.
|
|
74
|
+
*/
|
|
75
|
+
export declare function createAgUiToolResult(messageId: string, toolCallId: string, outcome: {
|
|
76
|
+
ok: true;
|
|
77
|
+
output: unknown;
|
|
78
|
+
} | {
|
|
79
|
+
ok: false;
|
|
80
|
+
error: string;
|
|
81
|
+
}): AgUiToolResultMessage;
|
|
82
|
+
//# sourceMappingURL=ag-ui.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ag-ui.d.ts","sourceRoot":"","sources":["../../src/core/ag-ui.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE5E,wDAAwD;AACxD,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,oFAAoF;IACpF,QAAQ,CAAC,UAAU,EAAE,qBAAqB,CAAC;CAC5C;AAED;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB;IACjC,wEAAwE;;IAExE,8EAA8E;;IAE9E,2EAA2E;;CAEnE,CAAC;AAEX,kEAAkE;AAClE,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,aAAa,GAAG,QAAQ,CAM9D;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,YAAY,EAAE,SAAS,aAAa,EAAE,GAAG,SAAS,QAAQ,EAAE,CAEvF;AA+BD;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACpE,qBAAqB,CAKvB"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tool-call event names AG-UI emits, agent → frontend.
|
|
3
|
+
*
|
|
4
|
+
* Arguments stream: `TOOL_CALL_ARGS` carries a `delta` fragment and may arrive many times for
|
|
5
|
+
* one call, so a consumer must accumulate by `toolCallId` and only execute after
|
|
6
|
+
* `TOOL_CALL_END`. Acting on a partial argument object is the obvious failure here.
|
|
7
|
+
*/
|
|
8
|
+
export const AG_UI_TOOL_CALL_EVENTS = {
|
|
9
|
+
/** Fields: `toolCallId`, `toolCallName`, optional `parentMessageId`. */
|
|
10
|
+
start: 'TOOL_CALL_START',
|
|
11
|
+
/** Fields: `toolCallId`, `delta` — a JSON fragment, not a complete object. */
|
|
12
|
+
args: 'TOOL_CALL_ARGS',
|
|
13
|
+
/** Fields: `toolCallId`. Arguments are complete only once this arrives. */
|
|
14
|
+
end: 'TOOL_CALL_END',
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Projects one capability into an AG-UI tool.
|
|
18
|
+
*
|
|
19
|
+
* @param capability - The capability to expose.
|
|
20
|
+
* @returns The tool entry for `RunAgentInput.tools`.
|
|
21
|
+
*/
|
|
22
|
+
export function toAgUiTool(capability) {
|
|
23
|
+
return {
|
|
24
|
+
name: capability.id,
|
|
25
|
+
description: capability.description,
|
|
26
|
+
parameters: capability.inputSchema,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Projects a whole manifest.
|
|
31
|
+
*
|
|
32
|
+
* @param capabilities - Capabilities to expose, already filtered by whatever policy applies.
|
|
33
|
+
* @returns One tool per capability, in manifest order.
|
|
34
|
+
*/
|
|
35
|
+
export function toAgUiTools(capabilities) {
|
|
36
|
+
return capabilities.map(toAgUiTool);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* JSON, or a description of why there is none — always a string, which `JSON.stringify` alone is
|
|
40
|
+
* not.
|
|
41
|
+
*
|
|
42
|
+
* `output` is `unknown`: whatever a host's capability actually returned. `JSON.stringify` is not
|
|
43
|
+
* total over that domain, in two different ways, and `content` is declared `string`:
|
|
44
|
+
*
|
|
45
|
+
* - it **throws** for a BigInt or a circular structure — landing on the transport, where the
|
|
46
|
+
* agent never learns its tool call produced anything at all;
|
|
47
|
+
* - it **returns `undefined`** (not a string) for a function or a symbol, so `content` was
|
|
48
|
+
* genuinely `undefined` despite its type, and whatever serialized the message downstream
|
|
49
|
+
* dropped the field or wrote `undefined` into the wire.
|
|
50
|
+
*
|
|
51
|
+
* Both become a result the agent can read, because that is this channel's whole premise: a
|
|
52
|
+
* failure it can see and reason about beats one that disappears.
|
|
53
|
+
*/
|
|
54
|
+
function encodeToolContent(output) {
|
|
55
|
+
let encoded;
|
|
56
|
+
try {
|
|
57
|
+
encoded = JSON.stringify(output ?? null);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
61
|
+
return JSON.stringify({ error: `tool output could not be encoded as JSON: ${detail}` });
|
|
62
|
+
}
|
|
63
|
+
// `undefined` here means "not representable in JSON" (a function, a symbol), which is what
|
|
64
|
+
// `null` means in every other JSON position — an array element, an object property.
|
|
65
|
+
return encoded ?? 'null';
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Builds the result message for a completed frontend tool call.
|
|
69
|
+
*
|
|
70
|
+
* AG-UI carries the result as a string, so structured output is JSON-encoded. Errors are
|
|
71
|
+
* returned through this same channel rather than thrown — the agent needs to see the refusal
|
|
72
|
+
* (a fill guard saying no, an unavailable capability) as a result it can reason about.
|
|
73
|
+
*
|
|
74
|
+
* @param messageId - Id for the result message itself.
|
|
75
|
+
* @param toolCallId - The `toolCallId` from `TOOL_CALL_START`.
|
|
76
|
+
* @param outcome - What happened.
|
|
77
|
+
* @returns The `role: "tool"` message to send back.
|
|
78
|
+
*/
|
|
79
|
+
export function createAgUiToolResult(messageId, toolCallId, outcome) {
|
|
80
|
+
const content = outcome.ok
|
|
81
|
+
? typeof outcome.output === 'string' ? outcome.output : encodeToolContent(outcome.output)
|
|
82
|
+
: JSON.stringify({ error: outcome.error });
|
|
83
|
+
return { id: messageId, role: 'tool', content, toolCallId };
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=ag-ui.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ag-ui.js","sourceRoot":"","sources":["../../src/core/ag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QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,iBAAiB,CAAC,OAAO,CAAC,MAAM,CAAC;QACzF,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;IAC7C,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module capability
|
|
3
|
+
*
|
|
4
|
+
* The vocabulary every agent-drivable surface shares: what an outside caller may ask a
|
|
5
|
+
* frontend to do, described as pure data with no transport, DOM, or framework attached.
|
|
6
|
+
*
|
|
7
|
+
* One noun, deliberately: **capability**. The chat pane's first draft used `tool` in its
|
|
8
|
+
* type names and `capability` in its ids, which forked the vocabulary across four files.
|
|
9
|
+
* `tool` stays reserved for the engine's own `ToolRegistry`/`ToolExecutor` nouns; anything
|
|
10
|
+
* an outside caller asks a *frontend* to do is a capability. Transports may of course
|
|
11
|
+
* present capabilities as MCP tools — that is a projection, not a rename.
|
|
12
|
+
*/
|
|
13
|
+
/** How much damage a capability can do. `requiresConfirmation` is the enforcement; this is the label. */
|
|
14
|
+
export type CapabilityRisk = 'read' | 'write';
|
|
15
|
+
/**
|
|
16
|
+
* Whether a capability means anything without a live UI session attached.
|
|
17
|
+
*
|
|
18
|
+
* - `session` — needs a connected frontend. "Highlight this field" is meaningless with no
|
|
19
|
+
* tab open, and must fail closed with a distinct error rather than hanging on a timeout.
|
|
20
|
+
* - `server` — a product outcome the backend can satisfy headlessly. Sending a chat message
|
|
21
|
+
* is the same outcome whether a tab is open or not.
|
|
22
|
+
*
|
|
23
|
+
* This decides *availability*, so a caller can be told "no eligible frontend is connected"
|
|
24
|
+
* instead of waiting for a timeout that will never resolve.
|
|
25
|
+
*/
|
|
26
|
+
export type CapabilitySurface = 'session' | 'server';
|
|
27
|
+
export interface CapabilityInputSchema {
|
|
28
|
+
readonly type: 'object';
|
|
29
|
+
readonly properties: Record<string, {
|
|
30
|
+
type: string;
|
|
31
|
+
description?: string;
|
|
32
|
+
enum?: readonly string[];
|
|
33
|
+
}>;
|
|
34
|
+
readonly required?: readonly string[];
|
|
35
|
+
readonly additionalProperties?: boolean;
|
|
36
|
+
}
|
|
37
|
+
export interface CapabilityDef {
|
|
38
|
+
readonly id: string;
|
|
39
|
+
readonly description: string;
|
|
40
|
+
readonly inputSchema: CapabilityInputSchema;
|
|
41
|
+
readonly risk: CapabilityRisk;
|
|
42
|
+
readonly surface: CapabilitySurface;
|
|
43
|
+
/**
|
|
44
|
+
* Destructive or otherwise irreversible — the caller must acknowledge before it runs. A host
|
|
45
|
+
* with a real confirmation gate (`@jini-ai/daemon`'s `ToolExecutor` has a resumable one) should
|
|
46
|
+
* enforce it there; surfaces without one enforce it in-band by requiring `confirm: true`, so
|
|
47
|
+
* no transport can execute it by accident.
|
|
48
|
+
*/
|
|
49
|
+
readonly requiresConfirmation?: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Looks a capability up by id.
|
|
53
|
+
*
|
|
54
|
+
* @param capabilities - The manifest to search.
|
|
55
|
+
* @param id - Capability id to resolve.
|
|
56
|
+
* @returns The definition, or `undefined` when the id is not in the manifest.
|
|
57
|
+
*/
|
|
58
|
+
export declare function findCapability(capabilities: readonly CapabilityDef[], id: string): CapabilityDef | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Checks caller input against a capability's declared schema.
|
|
61
|
+
*
|
|
62
|
+
* Manifests advertise `additionalProperties: false` and a `required` list, but nothing was
|
|
63
|
+
* enforcing either — handlers read the fields they knew about and ignored the rest, so a
|
|
64
|
+
* misnamed argument silently became a missing one. This closes that for any surface that calls
|
|
65
|
+
* it. Intentionally a shallow check, not a JSON Schema engine: these schemas are flat by
|
|
66
|
+
* construction, and a real validator is a dependency this package will not take.
|
|
67
|
+
*
|
|
68
|
+
* @param capability - The capability being invoked.
|
|
69
|
+
* @param input - Raw caller-supplied arguments.
|
|
70
|
+
* @returns An error message, or `null` when the input is acceptable.
|
|
71
|
+
*/
|
|
72
|
+
export declare function findCapabilityInputError(capability: CapabilityDef, input: Record<string, unknown>): string | null;
|
|
73
|
+
/**
|
|
74
|
+
* The capabilities a caller may use given what is currently connected.
|
|
75
|
+
*
|
|
76
|
+
* @param capabilities - The full manifest.
|
|
77
|
+
* @param hasSession - Whether a live frontend session is attached.
|
|
78
|
+
* @returns Only the capabilities that can actually be satisfied right now.
|
|
79
|
+
*/
|
|
80
|
+
export declare function availableCapabilities(capabilities: readonly CapabilityDef[], hasSession: boolean): readonly CapabilityDef[];
|
|
81
|
+
//# sourceMappingURL=capability.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../../src/core/capability.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,yGAAyG;AACzG,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,OAAO,CAAC;AAE9C;;;;;;;;;;GAUG;AACH,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,QAAQ,CAAC;AAErD,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;IACtG,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC;CACzC;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,qBAAqB,CAAC;IAC5C,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC;IACpC;;;;;OAKG;IACH,QAAQ,CAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC;CACzC;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,YAAY,EAAE,SAAS,aAAa,EAAE,EACtC,EAAE,EAAE,MAAM,GACT,aAAa,GAAG,SAAS,CAE3B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CACtC,UAAU,EAAE,aAAa,EACzB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,MAAM,GAAG,IAAI,CAiCf;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,SAAS,aAAa,EAAE,EACtC,UAAU,EAAE,OAAO,GAClB,SAAS,aAAa,EAAE,CAE1B"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module capability
|
|
3
|
+
*
|
|
4
|
+
* The vocabulary every agent-drivable surface shares: what an outside caller may ask a
|
|
5
|
+
* frontend to do, described as pure data with no transport, DOM, or framework attached.
|
|
6
|
+
*
|
|
7
|
+
* One noun, deliberately: **capability**. The chat pane's first draft used `tool` in its
|
|
8
|
+
* type names and `capability` in its ids, which forked the vocabulary across four files.
|
|
9
|
+
* `tool` stays reserved for the engine's own `ToolRegistry`/`ToolExecutor` nouns; anything
|
|
10
|
+
* an outside caller asks a *frontend* to do is a capability. Transports may of course
|
|
11
|
+
* present capabilities as MCP tools — that is a projection, not a rename.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Looks a capability up by id.
|
|
15
|
+
*
|
|
16
|
+
* @param capabilities - The manifest to search.
|
|
17
|
+
* @param id - Capability id to resolve.
|
|
18
|
+
* @returns The definition, or `undefined` when the id is not in the manifest.
|
|
19
|
+
*/
|
|
20
|
+
export function findCapability(capabilities, id) {
|
|
21
|
+
return capabilities.find((capability) => capability.id === id);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Checks caller input against a capability's declared schema.
|
|
25
|
+
*
|
|
26
|
+
* Manifests advertise `additionalProperties: false` and a `required` list, but nothing was
|
|
27
|
+
* enforcing either — handlers read the fields they knew about and ignored the rest, so a
|
|
28
|
+
* misnamed argument silently became a missing one. This closes that for any surface that calls
|
|
29
|
+
* it. Intentionally a shallow check, not a JSON Schema engine: these schemas are flat by
|
|
30
|
+
* construction, and a real validator is a dependency this package will not take.
|
|
31
|
+
*
|
|
32
|
+
* @param capability - The capability being invoked.
|
|
33
|
+
* @param input - Raw caller-supplied arguments.
|
|
34
|
+
* @returns An error message, or `null` when the input is acceptable.
|
|
35
|
+
*/
|
|
36
|
+
export function findCapabilityInputError(capability, input) {
|
|
37
|
+
const { properties, required, additionalProperties } = capability.inputSchema;
|
|
38
|
+
for (const name of required ?? []) {
|
|
39
|
+
if (input[name] === undefined)
|
|
40
|
+
return `"${name}" is required`;
|
|
41
|
+
}
|
|
42
|
+
if (additionalProperties === false) {
|
|
43
|
+
// `key in properties` walks the whole prototype chain, so a key that happens to be inherited
|
|
44
|
+
// from Object.prototype (`__proto__`, `constructor`, `toString`, `valueOf`, …) reads as
|
|
45
|
+
// "known" regardless of whether the schema actually lists it — `'constructor' in {}` is
|
|
46
|
+
// true even on an empty object. `JSON.parse('{"__proto__":...}')` creates a real own data
|
|
47
|
+
// property (not the accessor), so this was a live way for such a key to escape the
|
|
48
|
+
// "unknown argument" refusal entirely. hasOwnProperty ignores the prototype chain, so only
|
|
49
|
+
// keys the schema actually declares count as known.
|
|
50
|
+
const unknown = Object.keys(input)
|
|
51
|
+
.filter((key) => !Object.prototype.hasOwnProperty.call(properties, key));
|
|
52
|
+
if (unknown.length > 0) {
|
|
53
|
+
return `unknown ${unknown.length === 1 ? 'argument' : 'arguments'}: ${unknown.sort().join(', ')}`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
for (const [name, schema] of Object.entries(properties)) {
|
|
57
|
+
const value = input[name];
|
|
58
|
+
if (value === undefined)
|
|
59
|
+
continue;
|
|
60
|
+
const actual = Array.isArray(value) ? 'array' : typeof value;
|
|
61
|
+
if (actual !== schema.type)
|
|
62
|
+
return `"${name}" must be a ${schema.type}, received ${actual}`;
|
|
63
|
+
if (schema.enum !== undefined && !schema.enum.includes(value)) {
|
|
64
|
+
return `"${name}" must be one of: ${schema.enum.join(', ')}`;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The capabilities a caller may use given what is currently connected.
|
|
71
|
+
*
|
|
72
|
+
* @param capabilities - The full manifest.
|
|
73
|
+
* @param hasSession - Whether a live frontend session is attached.
|
|
74
|
+
* @returns Only the capabilities that can actually be satisfied right now.
|
|
75
|
+
*/
|
|
76
|
+
export function availableCapabilities(capabilities, hasSession) {
|
|
77
|
+
return hasSession ? capabilities : capabilities.filter((c) => c.surface === 'server');
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=capability.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capability.js","sourceRoot":"","sources":["../../src/core/capability.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAwCH;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAC5B,YAAsC,EACtC,EAAU;IAEV,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;AACjE,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,wBAAwB,CACtC,UAAyB,EACzB,KAA8B;IAE9B,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,oBAAoB,EAAE,GAAG,UAAU,CAAC,WA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K,SAAS,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAe,CAAC,EAAE,CAAC;YACxE,OAAO,IAAI,IAAI,qBAAqB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/D,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CACnC,YAAsC,EACtC,UAAmB;IAEnB,OAAO,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC;AACxF,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { PageDriver } from '../page-driver.js';
|
|
2
|
+
/** One page a host allows navigation to: its human label, and how to actually get there. */
|
|
3
|
+
export interface DomPageDriverPage {
|
|
4
|
+
/** Shown to a caller by `page.find_elements`/`page.navigate`'s refusal message — see
|
|
5
|
+
* `PageSummary.label` for why this exists at all. */
|
|
6
|
+
readonly label: string;
|
|
7
|
+
readonly navigate: () => void;
|
|
8
|
+
}
|
|
9
|
+
export interface DomPageDriverOptions {
|
|
10
|
+
/** The subtree to expose. Never pass `document`. */
|
|
11
|
+
readonly root: ParentNode & {
|
|
12
|
+
querySelector: Element['querySelector'];
|
|
13
|
+
};
|
|
14
|
+
/** Page ids this driver may navigate to, each with its label and how to get there. */
|
|
15
|
+
readonly pages: Readonly<Record<string, DomPageDriverPage>>;
|
|
16
|
+
/**
|
|
17
|
+
* The id of the page currently shown, reported on every element.
|
|
18
|
+
*
|
|
19
|
+
* Omit it in a single-page app that swaps views: the driver then reads `data-agent-page` from
|
|
20
|
+
* the live DOM on every call, so navigating actually changes what elements report. A value
|
|
21
|
+
* captured here is fixed for the driver's whole lifetime, which is right only for a surface that
|
|
22
|
+
* never changes view — and silently wrong for one that does, since the driver outlives any one
|
|
23
|
+
* view (it is bound to the connection, not the render).
|
|
24
|
+
*/
|
|
25
|
+
readonly currentPage?: string | undefined;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Builds a driver over `root`.
|
|
29
|
+
*
|
|
30
|
+
* @param options - The subtree, the navigable pages, and the current page id.
|
|
31
|
+
* @returns A driver ready to hand to `executePageCapability`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function createDomPageDriver(options: DomPageDriverOptions): PageDriver;
|
|
34
|
+
/** Reads the current page's `data-agent-page`, for hosts that tag the body. */
|
|
35
|
+
export declare function currentAgentPage(root: ParentNode): string | undefined;
|
|
36
|
+
//# sourceMappingURL=dom-page-driver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom-page-driver.d.ts","sourceRoot":"","sources":["../../../src/core/dom/dom-page-driver.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAsB,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAgNxE,4FAA4F;AAC5F,MAAM,WAAW,iBAAiB;IAChC;0DACsD;IACtD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,IAAI,CAAC;CAC/B;AAED,MAAM,WAAW,oBAAoB;IACnC,oDAAoD;IACpD,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG;QAAE,aAAa,EAAE,OAAO,CAAC,eAAe,CAAC,CAAA;KAAE,CAAC;IACxE,sFAAsF;IACtF,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAC5D;;;;;;;;OAQG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3C;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,UAAU,CA2V7E;AAgDD,+EAA+E;AAC/E,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAGrE"}
|