@autp/protocol 0.0.0-stage → 0.1.0-alpha.2

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 CHANGED
@@ -1,3 +1,32 @@
1
- # Temporary Holding Version
1
+ # @autp/protocol
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Zero-dependency core implementation of **Agent UI Tree Protocol (AUTP) v0.1**:
4
+
5
+ - Canonical TypeScript types (`UiTreeNode`, `UiActionDescriptor`, `UiInspectResponse`, `UiActRequest`, `UiTreeDiff`, `UiTreeError`)
6
+ - Token-efficient **Compact DSL** serializer (`renderUiTreeCompact`)
7
+ - Strict tree validator, cycle detector, depth pruner, and short-ref assigner (`indexAndPruneUiTree`)
8
+ - Action argument validator (`validateActionArgs`) & risk policy evaluator (`evaluateUiActionPolicy`)
9
+ - Minimal tree diff calculator (`computeUiTreeDiff`)
10
+ - Official JSON Schema (`@autp/protocol/schema`)
11
+
12
+ ## Usage
13
+
14
+ ```ts
15
+ import {
16
+ indexAndPruneUiTree,
17
+ renderUiTreeCompact,
18
+ evaluateUiActionPolicy,
19
+ } from '@autp/protocol';
20
+
21
+ const indexed = indexAndPruneUiTree({
22
+ id: 'app',
23
+ kind: 'app',
24
+ label: 'Demo',
25
+ actions: [{ name: 'toggle_sidebar', description: 'Toggle sidebar', risk: 'reversible' }],
26
+ });
27
+
28
+ const { text } = renderUiTreeCompact(indexed.root, { revision: 1 });
29
+ console.log(text);
30
+ ```
31
+
32
+ See the [AUTP repository](https://github.com/autp-protocol/autp) for the full v0.1 specification.
@@ -0,0 +1,18 @@
1
+ import { type UiTreeNode } from './types.ts';
2
+ export interface CompactRenderOptions {
3
+ revision: number;
4
+ focusedNodeId?: string;
5
+ includeActionSchemas?: boolean;
6
+ maxBytes?: number;
7
+ }
8
+ export interface CompactRenderResult {
9
+ text: string;
10
+ truncated: boolean;
11
+ }
12
+ /**
13
+ * Renders a UiTreeNode into AUTP's deterministic token-efficient compact DSL:
14
+ * # AUTP/0.1 rev=42 focus=tab:doc:f01abc
15
+ * [n1] app#workbench (context=workspace) [switch_context, toggle_sidebar]
16
+ */
17
+ export declare function renderUiTreeCompact(root: UiTreeNode, options: CompactRenderOptions): CompactRenderResult;
18
+ //# sourceMappingURL=compact.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compact.d.ts","sourceRoot":"","sources":["../src/compact.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,UAAU,EAChB,MAAM,YAAY,CAAC;AA+CpB,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,OAAO,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,oBAAoB,GAC5B,mBAAmB,CAuDrB"}
@@ -0,0 +1,108 @@
1
+ // SPDX-License-Identifier: MIT
2
+ import { AUTP_PROTOCOL_VERSION, } from "./types.js";
3
+ const DEFAULT_MAX_COMPACT_BYTES = 24_000;
4
+ const MAX_LABEL_CHARS = 120;
5
+ const MAX_STATE_VALUE_CHARS = 80;
6
+ function sanitizeInlineText(value, maxChars) {
7
+ const singleLine = value.replace(/[\r\n\t]+/g, ' ').replace(/\s{2,}/g, ' ').trim();
8
+ const clipped = singleLine.length > maxChars ? `${singleLine.slice(0, maxChars - 1)}…` : singleLine;
9
+ return clipped.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
10
+ }
11
+ function formatStateValue(value) {
12
+ if (value === null)
13
+ return 'null';
14
+ if (typeof value === 'boolean' || typeof value === 'number')
15
+ return String(value);
16
+ const clean = value.replace(/[\r\n\t]+/g, ' ').trim();
17
+ const clipped = clean.length > MAX_STATE_VALUE_CHARS ? `${clean.slice(0, MAX_STATE_VALUE_CHARS - 1)}…` : clean;
18
+ if (/^[a-zA-Z0-9._:/-]+$/.test(clipped))
19
+ return clipped;
20
+ return `"${sanitizeInlineText(clipped, MAX_STATE_VALUE_CHARS)}"`;
21
+ }
22
+ function formatActionToken(action, includeSchema) {
23
+ const suffix = action.risk === 'confirm'
24
+ ? '!confirm'
25
+ : action.risk === 'destructive'
26
+ ? '!destructive'
27
+ : '';
28
+ if (!includeSchema || !action.paramsSchema) {
29
+ return `${action.name}${suffix}`;
30
+ }
31
+ const props = action.paramsSchema &&
32
+ typeof action.paramsSchema === 'object' &&
33
+ 'properties' in action.paramsSchema &&
34
+ action.paramsSchema.properties &&
35
+ typeof action.paramsSchema.properties === 'object'
36
+ ? Object.keys(action.paramsSchema.properties)
37
+ : [];
38
+ const req = Array.isArray(action.paramsSchema.required)
39
+ ? new Set(action.paramsSchema.required.filter((item) => typeof item === 'string'))
40
+ : new Set();
41
+ if (!props.length)
42
+ return `${action.name}${suffix}`;
43
+ const sig = props.map(key => (req.has(key) ? key : `${key}?`)).join(',');
44
+ return `${action.name}(${sig})${suffix}`;
45
+ }
46
+ /**
47
+ * Renders a UiTreeNode into AUTP's deterministic token-efficient compact DSL:
48
+ * # AUTP/0.1 rev=42 focus=tab:doc:f01abc
49
+ * [n1] app#workbench (context=workspace) [switch_context, toggle_sidebar]
50
+ */
51
+ export function renderUiTreeCompact(root, options) {
52
+ const maxBytes = Math.max(1024, Math.min(options.maxBytes ?? DEFAULT_MAX_COMPACT_BYTES, 128_000));
53
+ const includeSchemas = !!options.includeActionSchemas;
54
+ const encoder = new TextEncoder();
55
+ const headerParts = [`# AUTP/${AUTP_PROTOCOL_VERSION}`, `rev=${options.revision}`];
56
+ if (options.focusedNodeId) {
57
+ headerParts.push(`focus=${options.focusedNodeId}`);
58
+ }
59
+ const lines = [headerParts.join(' ')];
60
+ let byteCount = encoder.encode(lines[0]).length + 1;
61
+ let truncated = false;
62
+ const visit = (node, depth) => {
63
+ if (truncated)
64
+ return;
65
+ const indent = ' '.repeat(depth);
66
+ const parts = [];
67
+ if (node.ref)
68
+ parts.push(`[${node.ref}]`);
69
+ parts.push(`${node.kind}#${node.id}`);
70
+ if (node.label !== undefined && node.label !== '') {
71
+ parts.push(`"${sanitizeInlineText(node.label, MAX_LABEL_CHARS)}"`);
72
+ }
73
+ if (node.state) {
74
+ const entries = Object.entries(node.state).filter(([, value]) => value !== undefined);
75
+ if (entries.length) {
76
+ parts.push(`(${entries.map(([key, value]) => `${key}=${formatStateValue(value)}`).join(', ')})`);
77
+ }
78
+ }
79
+ if (node.actions?.length) {
80
+ parts.push(`[${node.actions.map(action => formatActionToken(action, includeSchemas)).join(', ')}]`);
81
+ }
82
+ if (node.hasMore)
83
+ parts.push('*hasMore');
84
+ if (node.visualFallback)
85
+ parts.push('*visual');
86
+ if (node.untrustedSource)
87
+ parts.push(`*untrusted:${sanitizeInlineText(node.untrustedSource, 40)}`);
88
+ const line = `${indent}${parts.join(' ')}`;
89
+ const lineBytes = encoder.encode(line).length + 1;
90
+ if (byteCount + lineBytes > maxBytes) {
91
+ truncated = true;
92
+ lines.push(`${indent}... [truncated: compact byte budget (${maxBytes}B) reached; call ui.inspect with a narrower nodeId or smaller depth]`);
93
+ return;
94
+ }
95
+ lines.push(line);
96
+ byteCount += lineBytes;
97
+ if (node.children?.length) {
98
+ for (const child of node.children) {
99
+ visit(child, depth + 1);
100
+ if (truncated)
101
+ return;
102
+ }
103
+ }
104
+ };
105
+ visit(root, 0);
106
+ return { text: lines.join('\n'), truncated };
107
+ }
108
+ //# sourceMappingURL=compact.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compact.js","sourceRoot":"","sources":["../src/compact.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,OAAO,EACL,qBAAqB,GAItB,MAAM,YAAY,CAAC;AAEpB,MAAM,yB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C,cAAc,kBAAkB,CAAC,IAAI,CAAC,eAAe,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;QAEnG,MAAM,IAAI,GAAG,GAAG,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAC3C,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;QAClD,IAAI,SAAS,GAAG,SAAS,GAAG,QAAQ,EAAE,CAAC;YACrC,SAAS,GAAG,IAAI,CAAC;YACjB,KAAK,CAAC,IAAI,CAAC,GAAG,MAAM,wCAAwC,QAAQ,sEAAsE,CAAC,CAAC;YAC5I,OAAO;QACT,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjB,SAAS,IAAI,SAAS,CAAC;QAEvB,IAAI,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;YAC1B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAClC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;gBACxB,IAAI,SAAS;oBAAE,OAAO;YACxB,CAAC;QACH,CAAC;IACH,CAAC,CAAC;IAEF,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IACf,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './types.ts';
2
+ export * from './compact.ts';
3
+ export * from './validate.ts';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ // SPDX-License-Identifier: MIT
2
+ export * from "./types.js";
3
+ export * from "./compact.js";
4
+ export * from "./validate.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Agent UI Tree Protocol (AUTP) v0.1 — Core Protocol Types.
3
+ *
4
+ * Framework-agnostic, transport-agnostic semantic UI tree and action contract
5
+ * allowing pure-text LLM agents and external harnesses to perceive live application
6
+ * state and invoke node-scoped semantic actions safely.
7
+ */
8
+ export declare const AUTP_PROTOCOL_VERSION: "0.1";
9
+ export type UiActionRisk = 'read' | 'reversible' | 'confirm' | 'destructive';
10
+ export type UiTreeFormat = 'compact' | 'json';
11
+ export type UiAccessLevel = 'read' | 'review' | 'write';
12
+ export type UiTreeErrorCode = 'node_not_found' | 'action_not_supported' | 'invalid_args' | 'stale_revision' | 'confirmation_required' | 'access_denied' | 'provider_error' | 'host_unavailable' | 'capture_unavailable';
13
+ /** Core well-known semantic node kinds. Vendors and plugins may use `<namespace>:<kind>`. */
14
+ export declare const CORE_UI_NODE_KINDS: readonly ["app", "sidebar", "nav_item", "window", "split", "pane", "document_tab", "table_tab", "view_tab", "plugin_tab", "modal_layer", "modal", "commands", "command", "section", "heading", "item", "status", "error"];
15
+ export type CoreUiNodeKind = (typeof CORE_UI_NODE_KINDS)[number];
16
+ export type UiStatePrimitive = string | number | boolean | null;
17
+ export interface UiActionDescriptor {
18
+ /** Action identifier unique within the node (snake_case, e.g. `activate`, `split_right`). */
19
+ name: string;
20
+ /** Concise human/LLM-readable explanation of what this action does. */
21
+ description: string;
22
+ /** Risk classification enforced by the host policy engine. */
23
+ risk: UiActionRisk;
24
+ /** Optional JSON Schema (object) describing action arguments. */
25
+ paramsSchema?: Record<string, unknown>;
26
+ }
27
+ export interface UiTreeNode {
28
+ /** Stable hierarchical node ID (e.g. `pane:main:left`, `tab:doc:f01abc`, `plugin:kanban:board`). */
29
+ id: string;
30
+ /** Ephemeral short handle scoped to a specific `revision` (e.g. `n1`, `n2`). */
31
+ ref?: string;
32
+ /** Semantic kind: core kind or `<vendor>:<kind>`. */
33
+ kind: string;
34
+ /** Human-readable label. Hosts should sanitize/escape untrusted text. */
35
+ label?: string;
36
+ /** Concise key/value state (primitives only; never large document bodies). */
37
+ state?: Record<string, UiStatePrimitive>;
38
+ /** Actions currently legal on this node given live application state. */
39
+ actions?: UiActionDescriptor[];
40
+ /** Child nodes (omitted when truncated by depth or lazily loaded). */
41
+ children?: UiTreeNode[];
42
+ /** True when additional children exist and can be expanded via `ui.inspect({ nodeId })`. */
43
+ hasMore?: boolean;
44
+ /** Optional visual escape hatch: true when this node supports visual snapshot capture. */
45
+ visualFallback?: boolean;
46
+ /** Identifies untrusted provider origin (e.g. third-party plugin ID) for boundary wrapping. */
47
+ untrustedSource?: string;
48
+ }
49
+ export interface UiTreeCapabilities {
50
+ protocol: 'autp';
51
+ protocolVersion: typeof AUTP_PROTOCOL_VERSION;
52
+ formats: readonly UiTreeFormat[];
53
+ supportsRefs: boolean;
54
+ supportsDiff: boolean;
55
+ supportsVisualFallback: boolean;
56
+ supportsPlugins: boolean;
57
+ hostName?: string;
58
+ hostVersion?: string;
59
+ }
60
+ export interface UiInspectRequest {
61
+ /** Root node ID or short ref to inspect; defaults to tree root. */
62
+ nodeId?: string;
63
+ /** Maximum depth to expand (default 4, max 8). */
64
+ depth?: number;
65
+ /** Output representation: `compact` (default, token-efficient) or `json`. */
66
+ format?: UiTreeFormat;
67
+ /** Include full `paramsSchema` on actions (default false in compact mode). */
68
+ includeActionSchemas?: boolean;
69
+ /** Optional maximum serialized byte budget for compact output (default 24_000). */
70
+ maxBytes?: number;
71
+ }
72
+ export interface UiInspectResponse {
73
+ protocol: 'autp';
74
+ protocolVersion: typeof AUTP_PROTOCOL_VERSION;
75
+ revision: number;
76
+ focusedNodeId?: string;
77
+ truncated?: boolean;
78
+ root?: UiTreeNode;
79
+ compact?: string;
80
+ }
81
+ export interface UiQueryRequest {
82
+ /** Exact match on node `kind`. */
83
+ kind?: string;
84
+ /** Case-insensitive substring match on `label` or `id`. */
85
+ labelContains?: string;
86
+ /** Match nodes exposing an action with this name. */
87
+ hasAction?: string;
88
+ /** Maximum matches returned (default 20, max 100). */
89
+ limit?: number;
90
+ }
91
+ export interface UiQueryMatch {
92
+ id: string;
93
+ ref?: string;
94
+ kind: string;
95
+ label?: string;
96
+ parentId?: string;
97
+ state?: Record<string, UiStatePrimitive>;
98
+ actions?: string[];
99
+ hasMore?: boolean;
100
+ untrustedSource?: string;
101
+ }
102
+ export interface UiQueryResponse {
103
+ protocol: 'autp';
104
+ protocolVersion: typeof AUTP_PROTOCOL_VERSION;
105
+ revision: number;
106
+ matches: UiQueryMatch[];
107
+ totalMatched: number;
108
+ truncated: boolean;
109
+ }
110
+ export interface UiActRequest {
111
+ /** Target node stable `id` or snapshot `ref` (using `ref` requires `expectedRevision`). */
112
+ nodeId: string;
113
+ /** Action name declared on the target node. */
114
+ action: string;
115
+ /** Optional structured arguments matching the action's `paramsSchema`. */
116
+ args?: Record<string, unknown>;
117
+ /** Optimistic concurrency check: fails with `stale_revision` if host revision moved. */
118
+ expectedRevision?: number;
119
+ /** Optional rationale displayed on confirmation cards and audit trails. */
120
+ reason?: string;
121
+ }
122
+ export interface UiTreeDiff {
123
+ fromRevision: number;
124
+ toRevision: number;
125
+ addedIds: string[];
126
+ removedIds: string[];
127
+ updatedIds: string[];
128
+ focusChanged?: {
129
+ from?: string;
130
+ to?: string;
131
+ };
132
+ }
133
+ export interface UiActResponse {
134
+ protocol: 'autp';
135
+ protocolVersion: typeof AUTP_PROTOCOL_VERSION;
136
+ ok: boolean;
137
+ revision: number;
138
+ status: 'executed' | 'confirmation_required' | 'denied';
139
+ code?: UiTreeErrorCode;
140
+ message?: string;
141
+ /** Resolved stable node ID and action executed or requested. */
142
+ nodeId?: string;
143
+ action?: string;
144
+ risk?: UiActionRisk;
145
+ /** Structured tree diff so callers avoid a mandatory follow-up `ui.inspect`. */
146
+ diff?: UiTreeDiff;
147
+ /** Updated subtree for the affected node (or its parent if removed). */
148
+ updatedNode?: UiTreeNode;
149
+ updatedCompact?: string;
150
+ }
151
+ /** Optional visual escape-hatch request for nodes declaring `visualFallback: true`. */
152
+ export interface UiCaptureRequest {
153
+ /** Target node stable `id` or snapshot `ref` (using `ref` requires `expectedRevision`). */
154
+ nodeId: string;
155
+ /** Optimistic concurrency check matching the latest `ui.inspect` revision. */
156
+ expectedRevision?: number;
157
+ /** Optional pixel padding around the node's bounding box (0–48). */
158
+ padding?: number;
159
+ /** Optional max output dimension in pixels (320–1600). */
160
+ maxDimension?: number;
161
+ }
162
+ export interface UiCaptureResponse {
163
+ protocol: 'autp';
164
+ protocolVersion: typeof AUTP_PROTOCOL_VERSION;
165
+ ok: boolean;
166
+ revision: number;
167
+ nodeId?: string;
168
+ kind?: string;
169
+ mime?: 'image/png' | 'image/jpeg';
170
+ base64?: string;
171
+ width?: number;
172
+ height?: number;
173
+ redacted?: boolean;
174
+ code?: UiTreeErrorCode;
175
+ message?: string;
176
+ }
177
+ export declare class UiTreeError extends Error {
178
+ readonly code: UiTreeErrorCode;
179
+ readonly details?: Record<string, unknown> | undefined;
180
+ constructor(code: UiTreeErrorCode, message: string, details?: Record<string, unknown> | undefined);
181
+ }
182
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AAEH,eAAO,MAAM,qBAAqB,EAAG,KAAc,CAAC;AAEpD,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,YAAY,GAAG,SAAS,GAAG,aAAa,CAAC;AAE7E,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,MAAM,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C;CAClB;AAED,qBAAa,WAAY,SAAQ,KAAK;aAElB,IAAI,EAAE,eAAe;aAErB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBAFjC,IAAI,EAAE,eAAe,EACrC,OAAO,EAAE,MAAM,EACC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAA;CAKpD"}
package/dist/types.js ADDED
@@ -0,0 +1,42 @@
1
+ // SPDX-License-Identifier: MIT
2
+ /**
3
+ * Agent UI Tree Protocol (AUTP) v0.1 — Core Protocol Types.
4
+ *
5
+ * Framework-agnostic, transport-agnostic semantic UI tree and action contract
6
+ * allowing pure-text LLM agents and external harnesses to perceive live application
7
+ * state and invoke node-scoped semantic actions safely.
8
+ */
9
+ export const AUTP_PROTOCOL_VERSION = '0.1';
10
+ /** Core well-known semantic node kinds. Vendors and plugins may use `<namespace>:<kind>`. */
11
+ export const CORE_UI_NODE_KINDS = [
12
+ 'app',
13
+ 'sidebar',
14
+ 'nav_item',
15
+ 'window',
16
+ 'split',
17
+ 'pane',
18
+ 'document_tab',
19
+ 'table_tab',
20
+ 'view_tab',
21
+ 'plugin_tab',
22
+ 'modal_layer',
23
+ 'modal',
24
+ 'commands',
25
+ 'command',
26
+ 'section',
27
+ 'heading',
28
+ 'item',
29
+ 'status',
30
+ 'error',
31
+ ];
32
+ export class UiTreeError extends Error {
33
+ code;
34
+ details;
35
+ constructor(code, message, details) {
36
+ super(message);
37
+ this.code = code;
38
+ this.details = details;
39
+ this.name = 'UiTreeError';
40
+ }
41
+ }
42
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B;;;;;;GAMG;AAEH,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAc,CAAC;AAmBpD,6FAA6F;AAC7F,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,KAAK;IACL,SAAS;IACT,UAAU;IACV,QAAQ;IACR,OAAO;IACP,MAAM;IACN,cAAc;IACd,WAAW;IACX,UAAU;IACV,YAAY;IACZ,aAAa;IACb,OAAO;IACP,UAAU;IACV,SAAS;IACT,SAAS;IACT,SAAS;IACT,MAAM;IACN,QAAQ;IACR,OAAO;CACC,CAAC;AAgLX,MAAM,OAAO,WAAY,SAAQ,KAAK;IAElB;IAEA;IAHlB,YACkB,IAAqB,EACrC,OAAe,EACC,OAAiC;QAEjD,KAAK,CAAC,OAAO,CAAC,CAAC;QAJC,SAAI,GAAJ,IAAI,CAAiB;QAErB,YAAO,GAAP,OAAO,CAA0B;QAGjD,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF"}
@@ -0,0 +1,47 @@
1
+ import { type UiAccessLevel, type UiActionDescriptor, type UiActionRisk, type UiTreeDiff, type UiTreeNode } from './types.ts';
2
+ export declare const UI_TREE_LIMITS: {
3
+ readonly maxDepth: 8;
4
+ readonly defaultDepth: 4;
5
+ readonly maxNodes: 500;
6
+ readonly maxQueryLimit: 100;
7
+ readonly defaultQueryLimit: 20;
8
+ };
9
+ export interface IndexedUiTree {
10
+ root: UiTreeNode;
11
+ byId: Map<string, UiTreeNode>;
12
+ byRef: Map<string, UiTreeNode>;
13
+ parentById: Map<string, string>;
14
+ truncated: boolean;
15
+ }
16
+ /**
17
+ * Validates, depth-prunes, assigns sequential ephemeral refs (`n1`, `n2`, ...),
18
+ * and indexes a UiTreeNode hierarchy. Rejects cycles and malformed IDs.
19
+ */
20
+ export declare function indexAndPruneUiTree(rawRoot: UiTreeNode, options?: {
21
+ maxDepth?: number;
22
+ maxNodes?: number;
23
+ }): IndexedUiTree;
24
+ /**
25
+ * Evaluates whether an action of a given risk level may auto-execute, requires
26
+ * human confirmation, or is denied under the caller's access level.
27
+ */
28
+ export declare function evaluateUiActionPolicy(risk: UiActionRisk, access: UiAccessLevel): 'allow' | 'confirm' | 'deny';
29
+ /**
30
+ * Lightweight validation of action arguments against a JSON Schema subset
31
+ * (`required` + primitive `type` checks on declared `properties`).
32
+ */
33
+ export declare function validateActionArgs(action: UiActionDescriptor, args: Record<string, unknown> | undefined): void;
34
+ /**
35
+ * Computes a concise structural diff between two indexed snapshots so `ui.act`
36
+ * receipts tell the agent exactly what changed without a second `ui.inspect`.
37
+ */
38
+ export declare function computeUiTreeDiff(before: {
39
+ revision: number;
40
+ focusedNodeId?: string;
41
+ byId: Map<string, UiTreeNode>;
42
+ }, after: {
43
+ revision: number;
44
+ focusedNodeId?: string;
45
+ byId: Map<string, UiTreeNode>;
46
+ }): UiTreeDiff;
47
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,UAAU,EAEf,KAAK,UAAU,EAChB,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,cAAc;;;;;;CAMjB,CAAC;AAKX,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAC9B,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAC/B,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,SAAS,EAAE,OAAO,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,UAAU,EACnB,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAO,GACrD,aAAa,CAyEf;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,YAAY,EAClB,MAAM,EAAE,aAAa,GACpB,OAAO,GAAG,SAAS,GAAG,MAAM,CAS9B;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,kBAAkB,EAC1B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GACxC,IAAI,CAiDN;AAYD;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;CAAE,EACnF,KAAK,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;CAAE,GACjF,UAAU,CAgCZ"}
@@ -0,0 +1,196 @@
1
+ // SPDX-License-Identifier: MIT
2
+ import { UiTreeError, } from "./types.js";
3
+ export const UI_TREE_LIMITS = {
4
+ maxDepth: 8,
5
+ defaultDepth: 4,
6
+ maxNodes: 500,
7
+ maxQueryLimit: 100,
8
+ defaultQueryLimit: 20,
9
+ };
10
+ const VALID_ID_RE = /^[a-zA-Z0-9][a-zA-Z0-9._:/-]{0,160}$/;
11
+ const VALID_ACTION_RE = /^[a-z][a-z0-9_]{0,63}$/;
12
+ /**
13
+ * Validates, depth-prunes, assigns sequential ephemeral refs (`n1`, `n2`, ...),
14
+ * and indexes a UiTreeNode hierarchy. Rejects cycles and malformed IDs.
15
+ */
16
+ export function indexAndPruneUiTree(rawRoot, options = {}) {
17
+ const maxDepth = Math.max(0, Math.min(options.maxDepth ?? UI_TREE_LIMITS.defaultDepth, UI_TREE_LIMITS.maxDepth));
18
+ const maxNodes = Math.max(1, Math.min(options.maxNodes ?? UI_TREE_LIMITS.maxNodes, UI_TREE_LIMITS.maxNodes));
19
+ const byId = new Map();
20
+ const byRef = new Map();
21
+ const parentById = new Map();
22
+ const activeStack = new Set();
23
+ let refCounter = 0;
24
+ let truncated = false;
25
+ const cloneNode = (node, depth, parentId) => {
26
+ if (activeStack.has(node)) {
27
+ throw new UiTreeError('provider_error', `UI tree contains a cyclic reference: ${node.id}`);
28
+ }
29
+ if (!node.id || !VALID_ID_RE.test(node.id)) {
30
+ throw new UiTreeError('provider_error', `Invalid UI node ID: ${String(node.id)}`);
31
+ }
32
+ if (byId.has(node.id)) {
33
+ throw new UiTreeError('provider_error', `Duplicate UI node ID: ${node.id}`);
34
+ }
35
+ if (!node.kind || typeof node.kind !== 'string') {
36
+ throw new UiTreeError('provider_error', `UI node is missing a valid kind: ${node.id}`);
37
+ }
38
+ if (node.actions) {
39
+ for (const action of node.actions) {
40
+ if (!VALID_ACTION_RE.test(action.name)) {
41
+ throw new UiTreeError('provider_error', `Invalid action name: ${action.name} (node ${node.id})`);
42
+ }
43
+ }
44
+ }
45
+ activeStack.add(node);
46
+ const ref = `n${++refCounter}`;
47
+ const cloned = {
48
+ id: node.id,
49
+ ref,
50
+ kind: node.kind,
51
+ ...(node.label !== undefined ? { label: node.label } : {}),
52
+ ...(node.state ? { state: { ...node.state } } : {}),
53
+ ...(node.actions?.length ? { actions: node.actions.map(a => ({ ...a })) } : {}),
54
+ ...(node.visualFallback ? { visualFallback: true } : {}),
55
+ ...(node.hasMore ? { hasMore: true } : {}),
56
+ ...(node.untrustedSource ? { untrustedSource: node.untrustedSource } : {}),
57
+ };
58
+ byId.set(cloned.id, cloned);
59
+ byRef.set(ref, cloned);
60
+ if (parentId)
61
+ parentById.set(cloned.id, parentId);
62
+ if (node.children?.length) {
63
+ if (depth >= maxDepth) {
64
+ cloned.hasMore = true;
65
+ }
66
+ else {
67
+ const children = [];
68
+ for (const child of node.children) {
69
+ if (refCounter >= maxNodes) {
70
+ cloned.hasMore = true;
71
+ truncated = true;
72
+ break;
73
+ }
74
+ children.push(cloneNode(child, depth + 1, cloned.id));
75
+ }
76
+ if (children.length)
77
+ cloned.children = children;
78
+ }
79
+ }
80
+ activeStack.delete(node);
81
+ return cloned;
82
+ };
83
+ const root = cloneNode(rawRoot, 0);
84
+ return { root, byId, byRef, parentById, truncated };
85
+ }
86
+ /**
87
+ * Evaluates whether an action of a given risk level may auto-execute, requires
88
+ * human confirmation, or is denied under the caller's access level.
89
+ */
90
+ export function evaluateUiActionPolicy(risk, access) {
91
+ if (access === 'read') {
92
+ return risk === 'read' ? 'allow' : 'deny';
93
+ }
94
+ if (risk === 'read' || risk === 'reversible') {
95
+ return 'allow';
96
+ }
97
+ // Both `confirm` and `destructive` actions never auto-execute silently.
98
+ return 'confirm';
99
+ }
100
+ /**
101
+ * Lightweight validation of action arguments against a JSON Schema subset
102
+ * (`required` + primitive `type` checks on declared `properties`).
103
+ */
104
+ export function validateActionArgs(action, args) {
105
+ const payload = args ?? {};
106
+ const schema = action.paramsSchema;
107
+ if (!schema || typeof schema !== 'object')
108
+ return;
109
+ const required = Array.isArray(schema.required)
110
+ ? schema.required.filter((item) => typeof item === 'string')
111
+ : [];
112
+ for (const key of required) {
113
+ if (payload[key] === undefined || payload[key] === null) {
114
+ throw new UiTreeError('invalid_args', `Action ${action.name} is missing required parameter: ${key}`);
115
+ }
116
+ }
117
+ const properties = schema.properties && typeof schema.properties === 'object'
118
+ ? schema.properties
119
+ : undefined;
120
+ if (schema.additionalProperties === false && properties) {
121
+ for (const key of Object.keys(payload)) {
122
+ if (!Object.prototype.hasOwnProperty.call(properties, key)) {
123
+ throw new UiTreeError('invalid_args', `Action ${action.name} does not accept unknown parameter: ${key}`);
124
+ }
125
+ }
126
+ }
127
+ if (!properties)
128
+ return;
129
+ for (const [key, value] of Object.entries(payload)) {
130
+ if (value === undefined)
131
+ continue;
132
+ const propSchema = properties[key];
133
+ if (!propSchema)
134
+ continue;
135
+ const expectedType = propSchema.type;
136
+ if (expectedType === 'string' && typeof value !== 'string') {
137
+ throw new UiTreeError('invalid_args', `Parameter ${key} must be a string`);
138
+ }
139
+ if (expectedType === 'boolean' && typeof value !== 'boolean') {
140
+ throw new UiTreeError('invalid_args', `Parameter ${key} must be a boolean`);
141
+ }
142
+ if (expectedType === 'number' && (typeof value !== 'number' || !Number.isFinite(value))) {
143
+ throw new UiTreeError('invalid_args', `Parameter ${key} must be a finite number`);
144
+ }
145
+ if (expectedType === 'integer' && (typeof value !== 'number' || !Number.isInteger(value))) {
146
+ throw new UiTreeError('invalid_args', `Parameter ${key} must be an integer`);
147
+ }
148
+ if (Array.isArray(propSchema.enum) && !propSchema.enum.includes(value)) {
149
+ throw new UiTreeError('invalid_args', `Parameter ${key} must be one of the allowed values`);
150
+ }
151
+ }
152
+ }
153
+ function nodeFingerprint(node) {
154
+ return JSON.stringify({
155
+ kind: node.kind,
156
+ label: node.label ?? null,
157
+ state: node.state ?? null,
158
+ actions: (node.actions ?? []).map(a => `${a.name}:${a.risk}`),
159
+ hasMore: !!node.hasMore,
160
+ });
161
+ }
162
+ /**
163
+ * Computes a concise structural diff between two indexed snapshots so `ui.act`
164
+ * receipts tell the agent exactly what changed without a second `ui.inspect`.
165
+ */
166
+ export function computeUiTreeDiff(before, after) {
167
+ const addedIds = [];
168
+ const removedIds = [];
169
+ const updatedIds = [];
170
+ for (const [id, afterNode] of after.byId.entries()) {
171
+ const beforeNode = before.byId.get(id);
172
+ if (!beforeNode) {
173
+ addedIds.push(id);
174
+ }
175
+ else if (nodeFingerprint(beforeNode) !== nodeFingerprint(afterNode)) {
176
+ updatedIds.push(id);
177
+ }
178
+ }
179
+ for (const id of before.byId.keys()) {
180
+ if (!after.byId.has(id)) {
181
+ removedIds.push(id);
182
+ }
183
+ }
184
+ const focusChanged = before.focusedNodeId !== after.focusedNodeId
185
+ ? { from: before.focusedNodeId, to: after.focusedNodeId }
186
+ : undefined;
187
+ return {
188
+ fromRevision: before.revision,
189
+ toRevision: after.revision,
190
+ addedIds,
191
+ removedIds,
192
+ updatedIds,
193
+ ...(focusChanged ? { focusChanged } : {}),
194
+ };
195
+ }
196
+ //# sourceMappingURL=validate.js.map
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AI,CAAC,EAAE,CAAC,CAAC;QACtB,CAAC;IACH,CAAC;IAED,MAAM,YAAY,GAChB,MAAM,CAAC,aAAa,KAAK,KAAK,CAAC,aAAa;QAC1C,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,aAAa,EAAE,EAAE,EAAE,KAAK,CAAC,aAAa,EAAE;QACzD,CAAC,CAAC,SAAS,CAAC;IAEhB,OAAO;QACL,YAAY,EAAE,MAAM,CAAC,QAAQ;QAC7B,UAAU,EAAE,KAAK,CAAC,QAAQ;QAC1B,QAAQ;QACR,UAAU;QACV,UAAU;QACV,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC1C,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "@autp/protocol",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0-alpha.2",
4
+ "description": "Agent UI Tree Protocol (AUTP) v0.1 — Core types, JSON Schema, Compact DSL serializer, validator, diff, and risk policy engine.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "keywords": [
9
+ "autp",
10
+ "agent",
11
+ "llm",
12
+ "ui-tree",
13
+ "accessibility",
14
+ "protocol",
15
+ "mcp"
16
+ ],
17
+ "homepage": "https://github.com/autp-protocol/autp#readme",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/autp-protocol/autp.git",
21
+ "directory": "packages/protocol"
22
+ },
23
+ "bugs": {
24
+ "url": "https://github.com/autp-protocol/autp/issues"
25
+ },
26
+ "main": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "import": "./dist/index.js"
32
+ },
33
+ "./schema": "./ui-tree.schema.json"
34
+ },
35
+ "files": [
36
+ "dist",
37
+ "ui-tree.schema.json",
38
+ "README.md"
39
+ ],
40
+ "scripts": {
41
+ "build": "tsc -p tsconfig.json"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ }
46
+ }
@@ -0,0 +1,263 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://raw.githubusercontent.com/autp-protocol/autp/main/schema/ui-tree.schema.json",
4
+ "title": "Agent UI Tree Protocol (AUTP) v0.1",
5
+ "description": "Open, transport-agnostic semantic UI tree and node-scoped action protocol for LLM agents and external harnesses.",
6
+ "type": "object",
7
+ "$defs": {
8
+ "UiActionRisk": {
9
+ "type": "string",
10
+ "enum": ["read", "reversible", "confirm", "destructive"]
11
+ },
12
+ "UiTreeErrorCode": {
13
+ "type": "string",
14
+ "enum": [
15
+ "node_not_found",
16
+ "action_not_supported",
17
+ "invalid_args",
18
+ "stale_revision",
19
+ "confirmation_required",
20
+ "access_denied",
21
+ "provider_error",
22
+ "host_unavailable",
23
+ "capture_unavailable"
24
+ ]
25
+ },
26
+ "UiStatePrimitive": {
27
+ "type": ["string", "number", "boolean", "null"]
28
+ },
29
+ "UiActionDescriptor": {
30
+ "type": "object",
31
+ "additionalProperties": false,
32
+ "required": ["name", "description", "risk"],
33
+ "properties": {
34
+ "name": {
35
+ "type": "string",
36
+ "pattern": "^[a-z][a-z0-9_]{0,63}$"
37
+ },
38
+ "description": {
39
+ "type": "string",
40
+ "minLength": 1
41
+ },
42
+ "risk": { "$ref": "#/$defs/UiActionRisk" },
43
+ "paramsSchema": {
44
+ "type": "object"
45
+ }
46
+ }
47
+ },
48
+ "UiTreeNode": {
49
+ "type": "object",
50
+ "additionalProperties": false,
51
+ "required": ["id", "kind"],
52
+ "properties": {
53
+ "id": {
54
+ "type": "string",
55
+ "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._:/-]{0,160}$"
56
+ },
57
+ "ref": {
58
+ "type": "string",
59
+ "pattern": "^n[1-9][0-9]*$"
60
+ },
61
+ "kind": {
62
+ "type": "string",
63
+ "minLength": 1
64
+ },
65
+ "label": {
66
+ "type": "string"
67
+ },
68
+ "state": {
69
+ "type": "object",
70
+ "additionalProperties": { "$ref": "#/$defs/UiStatePrimitive" }
71
+ },
72
+ "actions": {
73
+ "type": "array",
74
+ "items": { "$ref": "#/$defs/UiActionDescriptor" }
75
+ },
76
+ "children": {
77
+ "type": "array",
78
+ "items": { "$ref": "#/$defs/UiTreeNode" }
79
+ },
80
+ "hasMore": { "type": "boolean" },
81
+ "visualFallback": { "type": "boolean" },
82
+ "untrustedSource": { "type": "string" }
83
+ }
84
+ },
85
+ "UiTreeDiff": {
86
+ "type": "object",
87
+ "additionalProperties": false,
88
+ "required": ["fromRevision", "toRevision", "addedIds", "removedIds", "updatedIds"],
89
+ "properties": {
90
+ "fromRevision": { "type": "integer", "minimum": 0 },
91
+ "toRevision": { "type": "integer", "minimum": 0 },
92
+ "addedIds": { "type": "array", "items": { "type": "string" } },
93
+ "removedIds": { "type": "array", "items": { "type": "string" } },
94
+ "updatedIds": { "type": "array", "items": { "type": "string" } },
95
+ "focusChanged": {
96
+ "type": "object",
97
+ "additionalProperties": false,
98
+ "properties": {
99
+ "from": { "type": "string" },
100
+ "to": { "type": "string" }
101
+ }
102
+ }
103
+ }
104
+ },
105
+ "UiTreeCapabilities": {
106
+ "type": "object",
107
+ "additionalProperties": false,
108
+ "required": [
109
+ "protocol",
110
+ "protocolVersion",
111
+ "formats",
112
+ "supportsRefs",
113
+ "supportsDiff",
114
+ "supportsVisualFallback",
115
+ "supportsPlugins"
116
+ ],
117
+ "properties": {
118
+ "protocol": { "const": "autp" },
119
+ "protocolVersion": { "const": "0.1" },
120
+ "formats": {
121
+ "type": "array",
122
+ "items": { "type": "string", "enum": ["compact", "json"] }
123
+ },
124
+ "supportsRefs": { "type": "boolean" },
125
+ "supportsDiff": { "type": "boolean" },
126
+ "supportsVisualFallback": { "type": "boolean" },
127
+ "supportsPlugins": { "type": "boolean" },
128
+ "hostName": { "type": "string" },
129
+ "hostVersion": { "type": "string" }
130
+ }
131
+ },
132
+ "UiInspectRequest": {
133
+ "type": "object",
134
+ "additionalProperties": false,
135
+ "properties": {
136
+ "nodeId": { "type": "string" },
137
+ "depth": { "type": "integer", "minimum": 0, "maximum": 8 },
138
+ "format": { "type": "string", "enum": ["compact", "json"] },
139
+ "includeActionSchemas": { "type": "boolean" },
140
+ "maxBytes": { "type": "integer", "minimum": 1024, "maximum": 128000 }
141
+ }
142
+ },
143
+ "UiInspectResponse": {
144
+ "type": "object",
145
+ "additionalProperties": false,
146
+ "required": ["protocol", "protocolVersion", "revision"],
147
+ "properties": {
148
+ "protocol": { "const": "autp" },
149
+ "protocolVersion": { "const": "0.1" },
150
+ "revision": { "type": "integer", "minimum": 0 },
151
+ "focusedNodeId": { "type": "string" },
152
+ "truncated": { "type": "boolean" },
153
+ "root": { "$ref": "#/$defs/UiTreeNode" },
154
+ "compact": { "type": "string" }
155
+ }
156
+ },
157
+ "UiQueryRequest": {
158
+ "type": "object",
159
+ "additionalProperties": false,
160
+ "properties": {
161
+ "kind": { "type": "string" },
162
+ "labelContains": { "type": "string" },
163
+ "hasAction": { "type": "string" },
164
+ "limit": { "type": "integer", "minimum": 1, "maximum": 100 }
165
+ }
166
+ },
167
+ "UiQueryMatch": {
168
+ "type": "object",
169
+ "additionalProperties": false,
170
+ "required": ["id", "kind"],
171
+ "properties": {
172
+ "id": { "type": "string" },
173
+ "ref": { "type": "string", "pattern": "^n[1-9][0-9]*$" },
174
+ "kind": { "type": "string" },
175
+ "label": { "type": "string" },
176
+ "parentId": { "type": "string" },
177
+ "state": {
178
+ "type": "object",
179
+ "additionalProperties": { "$ref": "#/$defs/UiStatePrimitive" }
180
+ },
181
+ "actions": { "type": "array", "items": { "type": "string" } },
182
+ "hasMore": { "type": "boolean" },
183
+ "untrustedSource": { "type": "string" }
184
+ }
185
+ },
186
+ "UiQueryResponse": {
187
+ "type": "object",
188
+ "additionalProperties": false,
189
+ "required": ["protocol", "protocolVersion", "revision", "matches", "totalMatched", "truncated"],
190
+ "properties": {
191
+ "protocol": { "const": "autp" },
192
+ "protocolVersion": { "const": "0.1" },
193
+ "revision": { "type": "integer", "minimum": 0 },
194
+ "matches": { "type": "array", "items": { "$ref": "#/$defs/UiQueryMatch" } },
195
+ "totalMatched": { "type": "integer", "minimum": 0 },
196
+ "truncated": { "type": "boolean" }
197
+ }
198
+ },
199
+ "UiActRequest": {
200
+ "type": "object",
201
+ "additionalProperties": false,
202
+ "required": ["nodeId", "action"],
203
+ "properties": {
204
+ "nodeId": { "type": "string", "minLength": 1 },
205
+ "action": { "type": "string", "pattern": "^[a-z][a-z0-9_]{0,63}$" },
206
+ "args": { "type": "object" },
207
+ "expectedRevision": { "type": "integer", "minimum": 0 },
208
+ "reason": { "type": "string", "maxLength": 1000 }
209
+ }
210
+ },
211
+ "UiActResponse": {
212
+ "type": "object",
213
+ "additionalProperties": false,
214
+ "required": ["protocol", "protocolVersion", "ok", "revision", "status"],
215
+ "properties": {
216
+ "protocol": { "const": "autp" },
217
+ "protocolVersion": { "const": "0.1" },
218
+ "ok": { "type": "boolean" },
219
+ "revision": { "type": "integer", "minimum": 0 },
220
+ "status": { "type": "string", "enum": ["executed", "confirmation_required", "denied"] },
221
+ "code": { "$ref": "#/$defs/UiTreeErrorCode" },
222
+ "message": { "type": "string" },
223
+ "nodeId": { "type": "string" },
224
+ "action": { "type": "string" },
225
+ "risk": { "$ref": "#/$defs/UiActionRisk" },
226
+ "diff": { "$ref": "#/$defs/UiTreeDiff" },
227
+ "updatedNode": { "$ref": "#/$defs/UiTreeNode" },
228
+ "updatedCompact": { "type": "string" }
229
+ }
230
+ },
231
+ "UiCaptureRequest": {
232
+ "type": "object",
233
+ "additionalProperties": false,
234
+ "required": ["nodeId"],
235
+ "properties": {
236
+ "nodeId": { "type": "string", "minLength": 1 },
237
+ "expectedRevision": { "type": "integer", "minimum": 0 },
238
+ "padding": { "type": "integer", "minimum": 0, "maximum": 48 },
239
+ "maxDimension": { "type": "integer", "minimum": 320, "maximum": 1600 }
240
+ }
241
+ },
242
+ "UiCaptureResponse": {
243
+ "type": "object",
244
+ "additionalProperties": false,
245
+ "required": ["protocol", "protocolVersion", "ok", "revision"],
246
+ "properties": {
247
+ "protocol": { "const": "autp" },
248
+ "protocolVersion": { "const": "0.1" },
249
+ "ok": { "type": "boolean" },
250
+ "revision": { "type": "integer", "minimum": 0 },
251
+ "nodeId": { "type": "string" },
252
+ "kind": { "type": "string" },
253
+ "mime": { "type": "string", "enum": ["image/png", "image/jpeg"] },
254
+ "base64": { "type": "string" },
255
+ "width": { "type": "integer", "minimum": 1 },
256
+ "height": { "type": "integer", "minimum": 1 },
257
+ "redacted": { "type": "boolean" },
258
+ "code": { "$ref": "#/$defs/UiTreeErrorCode" },
259
+ "message": { "type": "string" }
260
+ }
261
+ }
262
+ }
263
+ }