clay-server 3.8.1 → 4.0.0-beta.10
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/lib/ask-user-mcp-server.js +5 -119
- package/lib/background-task-timing.js +105 -0
- package/lib/builtin-mates.js +6 -6
- package/lib/claude-hook-installer.js +15 -0
- package/lib/clay-history-mcp-server.js +62 -297
- package/lib/daemon.js +23 -1
- package/lib/debate-model-selection.js +119 -0
- package/lib/home-debate-tool-policy.js +164 -0
- package/lib/home-response-notifications.js +26 -0
- package/lib/knowledge-import.js +436 -0
- package/lib/knowledge-record-store.js +188 -0
- package/lib/knowledge-search.js +224 -0
- package/lib/mate-creation-mcp-server.js +55 -0
- package/lib/mate-knowledge-mcp-server.js +151 -0
- package/lib/mate-knowledge-migration.js +283 -0
- package/lib/mate-knowledge-service.js +488 -0
- package/lib/mate-knowledge-sync.js +482 -0
- package/lib/mate-ready-creation.js +95 -0
- package/lib/mates.js +2 -0
- package/lib/notes.js +2 -1
- package/lib/project-ask-user.js +64 -0
- package/lib/project-capsule-catalog.js +101 -0
- package/lib/project-connection.js +17 -0
- package/lib/project-debate-proposal.js +133 -17
- package/lib/project-debate.js +214 -110
- package/lib/project-delegated-follow-up.js +84 -0
- package/lib/project-delegated-session.js +53 -0
- package/lib/project-filesystem.js +7 -9
- package/lib/project-knowledge.js +23 -0
- package/lib/project-logs-comments.js +137 -0
- package/lib/project-logs-mcp-server.js +290 -0
- package/lib/project-logs-query.js +167 -0
- package/lib/project-logs-root.js +67 -0
- package/lib/project-logs-schema.js +259 -0
- package/lib/project-logs-service.js +357 -0
- package/lib/project-logs-snapshot.js +202 -0
- package/lib/project-logs-store.js +498 -0
- package/lib/project-logs-versioning.js +128 -0
- package/lib/project-logs.js +347 -0
- package/lib/project-mate-creation-proposal.js +120 -0
- package/lib/project-mate-interaction.js +14 -0
- package/lib/project-mate-knowledge.js +110 -0
- package/lib/project-memory.js +36 -7
- package/lib/project-models.js +157 -32
- package/lib/project-session-notes.js +2 -2
- package/lib/project-session-pair.js +8 -8
- package/lib/project-sessions.js +66 -51
- package/lib/project-vendor-login.js +414 -0
- package/lib/project-worker-proposal.js +25 -25
- package/lib/project-workspace-query.js +144 -0
- package/lib/project.js +433 -102
- package/lib/public/app.js +109 -48
- package/lib/public/css/avatar-imprints.css +0 -1
- package/lib/public/css/base.css +4 -0
- package/lib/public/css/capsule-ui.css +389 -0
- package/lib/public/css/command-palette.css +306 -6
- package/lib/public/css/home-capsule-library.css +243 -0
- package/lib/public/css/home-capsule-source.css +192 -0
- package/lib/public/css/home-debate-live.css +146 -0
- package/lib/public/css/home-debate-planning.css +125 -0
- package/lib/public/css/home-debates-archive.css +281 -0
- package/lib/public/css/home-hub.css +896 -405
- package/lib/public/css/home-mate-creation.css +34 -0
- package/lib/public/css/home-mate-model-picker.css +131 -0
- package/lib/public/css/home-mate-settings.css +344 -0
- package/lib/public/css/home-session-actions.css +265 -0
- package/lib/public/css/home-sidebar.css +667 -0
- package/lib/public/css/icon-strip.css +1 -2
- package/lib/public/css/input.css +79 -25
- package/lib/public/css/mates.css +7 -34
- package/lib/public/css/pane.css +1 -1
- package/lib/public/css/playbook.css +0 -80
- package/lib/public/css/project-logs.css +234 -0
- package/lib/public/css/scheduler.css +1 -1
- package/lib/public/css/sticky-notes.css +53 -117
- package/lib/public/css/tui-attention.css +0 -44
- package/lib/public/css/workspace-assignment.css +45 -0
- package/lib/public/fonts/source-serif-4/LICENSE.md +93 -0
- package/lib/public/fonts/source-serif-4/SourceSerif4Caption-Semibold.ttf.woff2 +0 -0
- package/lib/public/index.html +96 -74
- package/lib/public/modules/app-connection.js +100 -5
- package/lib/public/modules/app-dm.js +43 -160
- package/lib/public/modules/app-home-hub.js +328 -585
- package/lib/public/modules/app-message-cards.js +242 -0
- package/lib/public/modules/app-message-router.js +84 -0
- package/lib/public/modules/app-messages.js +124 -38
- package/lib/public/modules/app-notifications.js +8 -119
- package/lib/public/modules/app-panels.js +43 -2
- package/lib/public/modules/app-projects.js +9 -1
- package/lib/public/modules/app-rendering.js +21 -602
- package/lib/public/modules/avatar-imprint.js +11 -8
- package/lib/public/modules/background-tasks-ui.js +139 -16
- package/lib/public/modules/chat-bubble-renderer.js +152 -0
- package/lib/public/modules/chat-render-runtime.js +198 -0
- package/lib/public/modules/command-palette.js +225 -436
- package/lib/public/modules/dm-render.js +82 -0
- package/lib/public/modules/home-capsule-creation-intent.js +31 -0
- package/lib/public/modules/home-capsule-library.js +146 -0
- package/lib/public/modules/home-capsule-source.js +383 -0
- package/lib/public/modules/home-chat-identity.js +35 -0
- package/lib/public/modules/home-chat-scroll.js +77 -0
- package/lib/public/modules/home-chat-stream-state.js +34 -0
- package/lib/public/modules/home-composer-focus.js +25 -0
- package/lib/public/modules/home-conversations-sheet.js +179 -0
- package/lib/public/modules/home-debate-activity.js +48 -0
- package/lib/public/modules/home-debate-controls.js +295 -0
- package/lib/public/modules/home-debate-launch.js +41 -0
- package/lib/public/modules/home-debate-live.js +284 -0
- package/lib/public/modules/home-debate-models.js +73 -0
- package/lib/public/modules/home-debate-planning.js +335 -0
- package/lib/public/modules/home-debates-archive.js +279 -0
- package/lib/public/modules/home-dock-resize.js +74 -0
- package/lib/public/modules/home-dock.js +446 -0
- package/lib/public/modules/home-mate-chat.js +496 -0
- package/lib/public/modules/home-mate-creation.js +109 -0
- package/lib/public/modules/home-mate-model-picker.js +281 -0
- package/lib/public/modules/home-mate-selection.js +38 -0
- package/lib/public/modules/home-mate-settings-menu.js +131 -0
- package/lib/public/modules/home-mate-settings.js +383 -0
- package/lib/public/modules/home-session-actions.js +373 -0
- package/lib/public/modules/home-session-model-confirmation.js +13 -0
- package/lib/public/modules/home-shell.js +9 -0
- package/lib/public/modules/home-sidebar-chat-list.js +63 -0
- package/lib/public/modules/home-sidebar.js +165 -0
- package/lib/public/modules/home-sub-surface.js +19 -0
- package/lib/public/modules/home-surface-boot.js +68 -0
- package/lib/public/modules/home-surface.js +141 -0
- package/lib/public/modules/home-tools.js +271 -0
- package/lib/public/modules/markdown.js +50 -2
- package/lib/public/modules/mate-management.js +86 -0
- package/lib/public/modules/mate-sidebar.js +0 -8
- package/lib/public/modules/mate-wizard.js +0 -7
- package/lib/public/modules/mention.js +17 -19
- package/lib/public/modules/pane-bridge.js +9 -0
- package/lib/public/modules/profile.js +4 -5
- package/lib/public/modules/project-logs-ambient.js +238 -0
- package/lib/public/modules/project-logs-render.js +359 -0
- package/lib/public/modules/project-logs.js +328 -0
- package/lib/public/modules/project-settings.js +34 -28
- package/lib/public/modules/project-switcher.js +11 -5
- package/lib/public/modules/project-workspace-assignment.js +23 -0
- package/lib/public/modules/scheduler.js +17 -3
- package/lib/public/modules/search-clay-chat.js +402 -0
- package/lib/public/modules/server-settings.js +14 -12
- package/lib/public/modules/session-actions.js +1 -1
- package/lib/public/modules/sidebar-mates.js +56 -552
- package/lib/public/modules/sidebar-mobile.js +12 -73
- package/lib/public/modules/sidebar-presence.js +37 -0
- package/lib/public/modules/sidebar-sessions.js +25 -1
- package/lib/public/modules/split-pair-ui.js +13 -13
- package/lib/public/modules/split-view.js +7 -0
- package/lib/public/modules/sticky-notes.js +106 -53
- package/lib/public/modules/tool-input-composition.js +48 -0
- package/lib/public/modules/tool-llm-status.js +167 -0
- package/lib/public/modules/tool-palette.js +76 -4
- package/lib/public/modules/tool-renderer-advanced.js +285 -0
- package/lib/public/modules/tool-renderer-chart.js +158 -0
- package/lib/public/modules/tool-renderer-semantics.js +35 -0
- package/lib/public/modules/tool-renderer.js +464 -0
- package/lib/public/modules/tool-runtime.js +309 -0
- package/lib/public/modules/tool-ui-evaluator.js +97 -0
- package/lib/public/modules/tool-ui-tree.js +21 -0
- package/lib/public/modules/tui-attention.js +10 -0
- package/lib/public/modules/user-settings.js +16 -23
- package/lib/public/modules/vendor-login.js +287 -0
- package/lib/public/modules/worker-proposal.js +2 -2
- package/lib/public/modules/workspace-assignment-card.js +149 -0
- package/lib/public/modules/workspace-assignment-routing.js +4 -0
- package/lib/public/style.css +14 -2
- package/lib/runtime-env.js +65 -0
- package/lib/sdk-bridge.js +120 -32
- package/lib/sdk-message-processor.js +34 -13
- package/lib/server-home-capsule-creation.js +36 -0
- package/lib/server-home-chat-events.js +287 -0
- package/lib/server-home-chat.js +518 -0
- package/lib/server-home-clay-entry.js +65 -0
- package/lib/server-home-clay-session-links.js +26 -0
- package/lib/server-home-debate-planning.js +214 -0
- package/lib/server-home-debates.js +137 -0
- package/lib/server-home-mate-creation.js +261 -0
- package/lib/server-home-models.js +241 -0
- package/lib/server-home-preferences.js +61 -0
- package/lib/server-mates.js +37 -0
- package/lib/server-tools.js +377 -0
- package/lib/server.js +166 -59
- package/lib/session-pair-mcp-server.js +6 -6
- package/lib/sessions.js +22 -4
- package/lib/tool-capsule-source.js +142 -0
- package/lib/tool-control-mcp-server.js +126 -0
- package/lib/tool-llm.js +48 -0
- package/lib/tool-storage.js +77 -0
- package/lib/tool-ui-spec-advanced.js +82 -0
- package/lib/tool-ui-spec.js +261 -0
- package/lib/tools-registry.js +286 -0
- package/lib/users-home-dock-preferences.js +77 -0
- package/lib/users-home-surface-preferences.js +99 -0
- package/lib/users-preferences.js +4 -7
- package/lib/users.js +12 -0
- package/lib/whats-new-content.js +3 -3
- package/lib/workspace-assignment-service.js +420 -0
- package/lib/workspace-query-mcp-server.js +154 -0
- package/lib/workspace-query-service.js +492 -0
- package/lib/ws-schema.js +107 -12
- package/lib/yoke/adapters/acp.js +2 -1
- package/lib/yoke/adapters/antigravity.js +2 -1
- package/lib/yoke/adapters/claude-worker.js +11 -4
- package/lib/yoke/adapters/claude.js +141 -46
- package/lib/yoke/adapters/codex.js +79 -11
- package/lib/yoke/adapters/kiro.js +2 -1
- package/lib/yoke/claude-user-input.js +38 -0
- package/lib/yoke/codex-app-server.js +20 -2
- package/lib/yoke/codex-background-tasks.js +8 -2
- package/lib/yoke/codex-user-input.js +64 -0
- package/lib/yoke/complete-once.js +164 -0
- package/lib/yoke/index.js +5 -1
- package/lib/yoke/interface.js +19 -0
- package/lib/yoke/mcp-bridge-server.js +2 -6
- package/lib/yoke/user-input.js +254 -0
- package/package.json +4 -3
- package/lib/public/css/home-chat.css +0 -380
- package/lib/public/modules/home-chat.js +0 -438
- package/lib/server-clay-home.js +0 -245
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// Truthful fixed-geometry charts for declarative Capsule UI.
|
|
2
|
+
|
|
3
|
+
import { collectionView, valueAtPath } from './tool-ui-evaluator.js';
|
|
4
|
+
|
|
5
|
+
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
6
|
+
|
|
7
|
+
function finiteNumber(value) {
|
|
8
|
+
var number = Number(value);
|
|
9
|
+
return Number.isFinite(number) ? number : 0;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function positiveNumber(value, fallback) {
|
|
13
|
+
var number = Number(value);
|
|
14
|
+
return Number.isFinite(number) && number > 0 ? number : fallback;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function chartData(state, bind, props, item) {
|
|
18
|
+
var limit = Math.max(1, Math.min(50, Number(props.maxItems) || 50));
|
|
19
|
+
var rows = collectionView(valueAtPath(state, bind, item), { pageSize: limit });
|
|
20
|
+
return rows.map(function (row, index) {
|
|
21
|
+
var category = props.categoryKey ? valueAtPath(row, props.categoryKey, null) : index + 1;
|
|
22
|
+
return {
|
|
23
|
+
label: String(category === undefined || category === null ? "Item " + (index + 1) : category).slice(0, 200),
|
|
24
|
+
value: Math.max(0, finiteNumber(valueAtPath(row, props.valueKey, null))),
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function lineGeometry(data) {
|
|
30
|
+
var max = data.reduce(function (result, entry) { return Math.max(result, entry.value); }, 0) || 1;
|
|
31
|
+
return data.map(function (entry, index) {
|
|
32
|
+
return {
|
|
33
|
+
x: data.length === 1 ? 50 : index / (data.length - 1) * 100,
|
|
34
|
+
y: 40 - entry.value / max * 38,
|
|
35
|
+
label: entry.label,
|
|
36
|
+
value: entry.value,
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function donutGeometry(data) {
|
|
42
|
+
var limited = data.slice(0, 12);
|
|
43
|
+
var total = limited.reduce(function (sum, entry) { return sum + entry.value; }, 0);
|
|
44
|
+
var offset = 0;
|
|
45
|
+
return limited.map(function (entry, index) {
|
|
46
|
+
var percent = total > 0 ? entry.value / total * 100 : 0;
|
|
47
|
+
var segment = { percent: percent, offset: offset, color: index % 8, label: entry.label, value: entry.value };
|
|
48
|
+
offset += percent;
|
|
49
|
+
return segment;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function createSvg(className, viewBox) {
|
|
54
|
+
var svg = document.createElementNS(SVG_NS, "svg");
|
|
55
|
+
svg.setAttribute("class", className);
|
|
56
|
+
svg.setAttribute("viewBox", viewBox);
|
|
57
|
+
svg.setAttribute("aria-hidden", "true");
|
|
58
|
+
svg.setAttribute("focusable", "false");
|
|
59
|
+
return svg;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function appendAccessibleData(figure, data) {
|
|
63
|
+
var list = document.createElement("ul");
|
|
64
|
+
list.className = "tool-chart-data";
|
|
65
|
+
for (var i = 0; i < data.length; i++) {
|
|
66
|
+
var entry = document.createElement("li");
|
|
67
|
+
entry.textContent = data[i].label + ": " + data[i].value;
|
|
68
|
+
list.appendChild(entry);
|
|
69
|
+
}
|
|
70
|
+
figure.appendChild(list);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function renderBar(figure, data) {
|
|
74
|
+
var svg = createSvg("tool-chart-svg tool-chart-bar", "0 0 100 50");
|
|
75
|
+
var max = data.reduce(function (result, entry) { return Math.max(result, entry.value); }, 0) || 1;
|
|
76
|
+
var width = data.length ? Math.max(1, 90 / data.length) : 1;
|
|
77
|
+
for (var i = 0; i < data.length; i++) {
|
|
78
|
+
var height = data[i].value / max * 46;
|
|
79
|
+
var rect = document.createElementNS(SVG_NS, "rect");
|
|
80
|
+
rect.setAttribute("class", "tool-chart-bar-mark");
|
|
81
|
+
rect.setAttribute("x", String(5 + i * width));
|
|
82
|
+
rect.setAttribute("y", String(48 - height));
|
|
83
|
+
rect.setAttribute("width", String(Math.max(1, width - 2)));
|
|
84
|
+
rect.setAttribute("height", String(height));
|
|
85
|
+
svg.appendChild(rect);
|
|
86
|
+
}
|
|
87
|
+
figure.appendChild(svg);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function renderLine(figure, data) {
|
|
91
|
+
var geometry = lineGeometry(data);
|
|
92
|
+
var svg = createSvg("tool-chart-svg tool-chart-line", "0 0 100 40");
|
|
93
|
+
if (geometry.length) {
|
|
94
|
+
var polyline = document.createElementNS(SVG_NS, "polyline");
|
|
95
|
+
polyline.setAttribute("class", "tool-chart-line-path");
|
|
96
|
+
polyline.setAttribute("points", geometry.map(function (point) { return point.x.toFixed(2) + "," + point.y.toFixed(2); }).join(" "));
|
|
97
|
+
svg.appendChild(polyline);
|
|
98
|
+
}
|
|
99
|
+
for (var i = 0; i < geometry.length; i++) {
|
|
100
|
+
var point = document.createElementNS(SVG_NS, "circle");
|
|
101
|
+
point.setAttribute("class", "tool-chart-line-point");
|
|
102
|
+
point.setAttribute("cx", geometry[i].x.toFixed(2));
|
|
103
|
+
point.setAttribute("cy", geometry[i].y.toFixed(2));
|
|
104
|
+
point.setAttribute("r", "1.8");
|
|
105
|
+
svg.appendChild(point);
|
|
106
|
+
}
|
|
107
|
+
figure.appendChild(svg);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function renderDonut(figure, data) {
|
|
111
|
+
var segments = donutGeometry(data);
|
|
112
|
+
var svg = createSvg("tool-chart-svg tool-chart-donut", "0 0 42 42");
|
|
113
|
+
var track = document.createElementNS(SVG_NS, "circle");
|
|
114
|
+
track.setAttribute("class", "tool-chart-donut-track");
|
|
115
|
+
track.setAttribute("cx", "21"); track.setAttribute("cy", "21"); track.setAttribute("r", "15.9155");
|
|
116
|
+
svg.appendChild(track);
|
|
117
|
+
for (var i = 0; i < segments.length; i++) {
|
|
118
|
+
if (segments[i].percent <= 0) continue;
|
|
119
|
+
var circle = document.createElementNS(SVG_NS, "circle");
|
|
120
|
+
circle.setAttribute("class", "tool-chart-donut-segment tool-chart-color-" + segments[i].color);
|
|
121
|
+
circle.setAttribute("cx", "21"); circle.setAttribute("cy", "21"); circle.setAttribute("r", "15.9155");
|
|
122
|
+
circle.setAttribute("stroke-dasharray", segments[i].percent.toFixed(4) + " " + (100 - segments[i].percent).toFixed(4));
|
|
123
|
+
circle.setAttribute("stroke-dashoffset", String(-segments[i].offset.toFixed(4)));
|
|
124
|
+
svg.appendChild(circle);
|
|
125
|
+
}
|
|
126
|
+
figure.appendChild(svg);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function renderChartNode(node, props, context) {
|
|
130
|
+
var figure = document.createElement("figure");
|
|
131
|
+
figure.className = "tool-chart tool-chart--" + props.kind;
|
|
132
|
+
figure.setAttribute("aria-label", String(props.label));
|
|
133
|
+
var caption = document.createElement("figcaption");
|
|
134
|
+
caption.textContent = String(props.label);
|
|
135
|
+
figure.appendChild(caption);
|
|
136
|
+
var data = chartData(context.state, node.bind, props, context.item);
|
|
137
|
+
if (props.kind === "donut") data = data.slice(0, 12);
|
|
138
|
+
if (props.kind === "metric") {
|
|
139
|
+
var metric = document.createElement("strong");
|
|
140
|
+
metric.className = "tool-chart-metric";
|
|
141
|
+
metric.textContent = data.length ? String(data[0].value) : "0";
|
|
142
|
+
figure.appendChild(metric);
|
|
143
|
+
} else if (props.kind === "progress") {
|
|
144
|
+
var maximum = positiveNumber(props.max, 1);
|
|
145
|
+
var current = Math.min(maximum, data.length ? data[0].value : 0);
|
|
146
|
+
var progress = document.createElement("progress");
|
|
147
|
+
progress.className = "tool-chart-progress";
|
|
148
|
+
progress.max = maximum;
|
|
149
|
+
progress.value = current;
|
|
150
|
+
progress.textContent = current + " of " + maximum;
|
|
151
|
+
figure.appendChild(progress);
|
|
152
|
+
data = [{ label: props.label, value: current }];
|
|
153
|
+
} else if (props.kind === "line") renderLine(figure, data);
|
|
154
|
+
else if (props.kind === "donut") renderDonut(figure, data);
|
|
155
|
+
else renderBar(figure, data);
|
|
156
|
+
appendAccessibleData(figure, data);
|
|
157
|
+
return figure;
|
|
158
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Fixed class mapping for the validated Capsule UI semantic grammar.
|
|
2
|
+
|
|
3
|
+
var TOKEN_KEYS = ["tone", "size", "emphasis", "gap", "variant", "align", "justify", "padding", "role"];
|
|
4
|
+
var SAFE_TOKENS = /^[a-z]+(?:-[a-z]+)*$/;
|
|
5
|
+
var TOKEN_VALUES = {
|
|
6
|
+
tone: ["neutral", "accent", "info", "success", "warning", "danger"],
|
|
7
|
+
size: ["xs", "sm", "md", "lg"], emphasis: ["subtle", "regular", "strong"],
|
|
8
|
+
gap: ["none", "xs", "sm", "md", "lg", "xl"],
|
|
9
|
+
variant: ["plain", "inset", "cards", "divided", "outlined", "raised", "callout", "output", "soft", "primary", "secondary", "ghost", "danger"],
|
|
10
|
+
align: ["start", "center", "end", "baseline", "stretch"], justify: ["start", "center", "end", "between"],
|
|
11
|
+
padding: ["none", "sm", "md", "lg"], role: ["body", "muted", "caption", "strong", "output", "display", "section"],
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function semanticClasses(base, props) {
|
|
15
|
+
var classes = [base];
|
|
16
|
+
props = props || {};
|
|
17
|
+
for (var i = 0; i < TOKEN_KEYS.length; i++) {
|
|
18
|
+
var key = TOKEN_KEYS[i];
|
|
19
|
+
var value = props[key];
|
|
20
|
+
if (typeof value === "string" && SAFE_TOKENS.test(value) && TOKEN_VALUES[key].indexOf(value) !== -1) classes.push(base + "--" + key + "-" + value);
|
|
21
|
+
}
|
|
22
|
+
if (props.wrap === true) classes.push(base + "--wrap");
|
|
23
|
+
return classes.join(" ");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function appendToolIcon(element, name, label) {
|
|
27
|
+
if (!name) return null;
|
|
28
|
+
var icon = document.createElement("i");
|
|
29
|
+
icon.className = "tool-icon";
|
|
30
|
+
icon.setAttribute("data-lucide", name);
|
|
31
|
+
if (label) icon.setAttribute("aria-label", label);
|
|
32
|
+
else icon.setAttribute("aria-hidden", "true");
|
|
33
|
+
element.appendChild(icon);
|
|
34
|
+
return icon;
|
|
35
|
+
}
|
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
// tool-renderer.js - Host-rendered declarative tool UI vocabulary.
|
|
2
|
+
|
|
3
|
+
import { bindToolTextInput, isToolTextInputComposing } from './tool-input-composition.js';
|
|
4
|
+
import { refreshIcons } from './icons.js';
|
|
5
|
+
import { semanticClasses, appendToolIcon } from './tool-renderer-semantics.js';
|
|
6
|
+
import { TOOL_LLM_ALIASES, getToolLlmConfiguration, requestAllToolLlmConfigurations, requestToolLlmConfiguration, subscribeToolLlmConfigurations } from './tool-llm-status.js';
|
|
7
|
+
import { collectionView, evaluateCondition, normalizeColumns, normalizeOptions, resolveProps, resolveValue, valueAtPath } from './tool-ui-evaluator.js';
|
|
8
|
+
import { renderAdvancedNode } from './tool-renderer-advanced.js';
|
|
9
|
+
|
|
10
|
+
var catalogs = Object.create(null);
|
|
11
|
+
var deferredRenders = new WeakMap();
|
|
12
|
+
var renderDisposers = new WeakMap();
|
|
13
|
+
var modelConfigurationRequested = new WeakSet();
|
|
14
|
+
|
|
15
|
+
function resolveTemplate(value, state, item) {
|
|
16
|
+
return resolveValue(value, state, item);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function appendChildren(element, node, context) {
|
|
20
|
+
var children = node.children || [];
|
|
21
|
+
for (var i = 0; i < children.length; i++) {
|
|
22
|
+
var child = renderNode(children[i], context);
|
|
23
|
+
if (child) element.appendChild(child);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function registerControl(node, props, context) {
|
|
28
|
+
if (!node.id) return;
|
|
29
|
+
context.catalog[node.id] = {
|
|
30
|
+
type: node.type,
|
|
31
|
+
label: props.label || props.text || node.id,
|
|
32
|
+
bind: node.bind || null,
|
|
33
|
+
action: node.action || null,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function emitNodeAction(node, props, context, extra) {
|
|
38
|
+
if (!node.action) return;
|
|
39
|
+
var args = resolveTemplate(props.args || {}, context.state, context.item);
|
|
40
|
+
var keys = Object.keys(extra || {});
|
|
41
|
+
for (var i = 0; i < keys.length; i++) args[keys[i]] = extra[keys[i]];
|
|
42
|
+
if (node.id) args.controlId = node.id;
|
|
43
|
+
if (node.bind) args.bind = node.bind;
|
|
44
|
+
context.emit(node.action, args);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function resolvedBoolean(value, context) {
|
|
48
|
+
if (typeof value === "string") return !!resolveTemplate(value, context.state, context.item);
|
|
49
|
+
return value === true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function appendFieldHeading(wrapper, node, props, control, context) {
|
|
53
|
+
if (props.label) {
|
|
54
|
+
var label = document.createElement("span");
|
|
55
|
+
label.className = "tool-field-label";
|
|
56
|
+
label.textContent = String(props.label);
|
|
57
|
+
wrapper.appendChild(label);
|
|
58
|
+
} else if (node.id) control.setAttribute("aria-label", node.id);
|
|
59
|
+
if (resolvedBoolean(props.required, context)) {
|
|
60
|
+
control.required = true;
|
|
61
|
+
control.setAttribute("aria-required", "true");
|
|
62
|
+
}
|
|
63
|
+
control.disabled = resolvedBoolean(props.disabled, context);
|
|
64
|
+
var descriptions = [];
|
|
65
|
+
if (props.hint) descriptions.push({ className: "tool-field-hint", text: props.hint });
|
|
66
|
+
if (props.error) {
|
|
67
|
+
descriptions.push({ className: "tool-field-error", text: props.error, alert: true });
|
|
68
|
+
control.setAttribute("aria-invalid", "true");
|
|
69
|
+
}
|
|
70
|
+
if (!descriptions.length) return false;
|
|
71
|
+
wrapper.appendChild(control);
|
|
72
|
+
var ids = [];
|
|
73
|
+
for (var i = 0; i < descriptions.length; i++) {
|
|
74
|
+
var copy = document.createElement("span");
|
|
75
|
+
copy.className = descriptions[i].className;
|
|
76
|
+
copy.textContent = String(descriptions[i].text);
|
|
77
|
+
copy.id = "tool-field-copy-" + context.toolId + "-" + context.hintIndex++;
|
|
78
|
+
if (descriptions[i].alert) copy.setAttribute("role", "alert");
|
|
79
|
+
ids.push(copy.id);
|
|
80
|
+
wrapper.appendChild(copy);
|
|
81
|
+
}
|
|
82
|
+
control.setAttribute("aria-describedby", ids.join(" "));
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function renderInput(node, props, context) {
|
|
87
|
+
var wrapper = document.createElement("label");
|
|
88
|
+
wrapper.className = semanticClasses("tool-field", props);
|
|
89
|
+
var input = document.createElement(node.type === "textarea" ? "textarea" : "input");
|
|
90
|
+
input.className = "tool-input";
|
|
91
|
+
var inputTypes = ["text", "search", "email", "url", "number", "range", "date", "time", "datetime-local", "tel"];
|
|
92
|
+
if (node.type === "input") input.type = inputTypes.indexOf(props.inputType) === -1 ? "text" : props.inputType;
|
|
93
|
+
if (node.type === "textarea" && props.rows) input.rows = Math.max(2, Math.min(16, Number(props.rows) || 2));
|
|
94
|
+
if (props.placeholder) input.placeholder = String(props.placeholder);
|
|
95
|
+
var validation = props.validation || {};
|
|
96
|
+
if (validation.minLength !== undefined) input.minLength = validation.minLength;
|
|
97
|
+
if (validation.maxLength !== undefined) input.maxLength = validation.maxLength;
|
|
98
|
+
if (validation.min !== undefined) input.min = validation.min;
|
|
99
|
+
if (validation.max !== undefined) input.max = validation.max;
|
|
100
|
+
if (validation.step !== undefined) input.step = validation.step;
|
|
101
|
+
if (validation.pattern === "integer") input.pattern = "-?[0-9]+";
|
|
102
|
+
else if (validation.pattern === "decimal") input.pattern = "-?[0-9]+(?:\\.[0-9]+)?";
|
|
103
|
+
else if (validation.pattern === "email") input.type = "email";
|
|
104
|
+
else if (validation.pattern === "url") input.type = "url";
|
|
105
|
+
input.addEventListener("invalid", function () { if (validation.message && typeof input.setCustomValidity === "function") input.setCustomValidity(validation.message); });
|
|
106
|
+
input.addEventListener("input", function () { if (typeof input.setCustomValidity === "function") input.setCustomValidity(""); });
|
|
107
|
+
var value = valueAtPath(context.state, node.bind, context.item);
|
|
108
|
+
input.value = value === undefined || value === null ? "" : String(value);
|
|
109
|
+
if (node.id) input.dataset.toolControlId = node.id;
|
|
110
|
+
bindToolTextInput(input, function (value) {
|
|
111
|
+
var typedValue = (input.type === "number" || input.type === "range") && value !== "" && Number.isFinite(Number(value)) ? Number(value) : value;
|
|
112
|
+
emitNodeAction(node, props, context, { value: typedValue });
|
|
113
|
+
}, {
|
|
114
|
+
isAlive: function (boundInput) { return context.container.contains(boundInput); },
|
|
115
|
+
onCompositionEnd: function (settledInput) {
|
|
116
|
+
var pending = deferredRenders.get(context.container);
|
|
117
|
+
deferredRenders.delete(context.container);
|
|
118
|
+
if (!pending || !context.container.contains(settledInput) || node.action) return;
|
|
119
|
+
renderToolUiNow(pending.toolId, pending.uiTree, pending.state, pending.emit, pending.container);
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
if (!appendFieldHeading(wrapper, node, props, input, context)) wrapper.appendChild(input);
|
|
123
|
+
registerControl(node, props, context);
|
|
124
|
+
return wrapper;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function renderSelect(node, props, context) {
|
|
128
|
+
var wrapper = document.createElement("label");
|
|
129
|
+
wrapper.className = semanticClasses("tool-field", props);
|
|
130
|
+
var select = document.createElement("select");
|
|
131
|
+
select.className = "tool-select";
|
|
132
|
+
if (node.id) select.dataset.toolControlId = node.id;
|
|
133
|
+
var options = normalizeOptions(props.options);
|
|
134
|
+
for (var i = 0; i < options.length; i++) {
|
|
135
|
+
var option = document.createElement("option");
|
|
136
|
+
var optionValue = options[i].value;
|
|
137
|
+
var optionLabel = options[i].label;
|
|
138
|
+
option.value = String(optionValue);
|
|
139
|
+
option.textContent = String(optionLabel);
|
|
140
|
+
option.disabled = options[i].disabled;
|
|
141
|
+
select.appendChild(option);
|
|
142
|
+
}
|
|
143
|
+
var value = valueAtPath(context.state, node.bind, context.item);
|
|
144
|
+
if (value !== undefined && value !== null) select.value = String(value);
|
|
145
|
+
select.addEventListener("change", function () { emitNodeAction(node, props, context, { value: select.value }); });
|
|
146
|
+
if (!appendFieldHeading(wrapper, node, props, select, context)) wrapper.appendChild(select);
|
|
147
|
+
registerControl(node, props, context);
|
|
148
|
+
return wrapper;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function modelAliasLabel(alias) {
|
|
152
|
+
return alias.charAt(0).toUpperCase() + alias.slice(1);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function modelOptionLabel(alias, state) {
|
|
156
|
+
var prefix = modelAliasLabel(alias);
|
|
157
|
+
if (state.status === "ready" && state.vendorName && state.modelName) return prefix + " · " + state.vendorName + " · " + state.modelName;
|
|
158
|
+
if (state.status === "error") return prefix + " · Unavailable";
|
|
159
|
+
return prefix + " · Checking model…";
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function renderModelSelect(node, props, context) {
|
|
163
|
+
var wrapper = document.createElement("div");
|
|
164
|
+
wrapper.className = "tool-model-select";
|
|
165
|
+
var field = document.createElement("label");
|
|
166
|
+
field.className = semanticClasses("tool-field", props);
|
|
167
|
+
var select = document.createElement("select");
|
|
168
|
+
select.className = "tool-select tool-model-select-control";
|
|
169
|
+
if (node.id) select.dataset.toolControlId = node.id;
|
|
170
|
+
var options = Object.create(null);
|
|
171
|
+
for (var i = 0; i < TOOL_LLM_ALIASES.length; i++) {
|
|
172
|
+
var alias = TOOL_LLM_ALIASES[i];
|
|
173
|
+
var option = document.createElement("option");
|
|
174
|
+
option.value = alias;
|
|
175
|
+
option.textContent = modelOptionLabel(alias, getToolLlmConfiguration(alias));
|
|
176
|
+
options[alias] = option;
|
|
177
|
+
select.appendChild(option);
|
|
178
|
+
}
|
|
179
|
+
var value = valueAtPath(context.state, node.bind, context.item);
|
|
180
|
+
select.value = TOOL_LLM_ALIASES.indexOf(value) !== -1 ? value : "fast";
|
|
181
|
+
select.addEventListener("change", function () {
|
|
182
|
+
emitNodeAction(node, props, context, { value: select.value });
|
|
183
|
+
updateAlias(select.value, getToolLlmConfiguration(select.value));
|
|
184
|
+
});
|
|
185
|
+
if (!appendFieldHeading(field, node, props, select, context)) field.appendChild(select);
|
|
186
|
+
wrapper.appendChild(field);
|
|
187
|
+
var feedback = document.createElement("span");
|
|
188
|
+
feedback.className = "tool-model-select-feedback hidden";
|
|
189
|
+
feedback.setAttribute("aria-live", "polite");
|
|
190
|
+
var retry = document.createElement("button");
|
|
191
|
+
retry.type = "button";
|
|
192
|
+
retry.className = "tool-model-select-retry hidden";
|
|
193
|
+
retry.textContent = "Retry";
|
|
194
|
+
retry.addEventListener("click", function () { requestToolLlmConfiguration(select.value); });
|
|
195
|
+
wrapper.appendChild(feedback);
|
|
196
|
+
wrapper.appendChild(retry);
|
|
197
|
+
function updateAlias(changedAlias, state) {
|
|
198
|
+
if (options[changedAlias]) options[changedAlias].textContent = modelOptionLabel(changedAlias, state);
|
|
199
|
+
var selectedState = getToolLlmConfiguration(select.value);
|
|
200
|
+
var failed = selectedState.status === "error";
|
|
201
|
+
feedback.textContent = failed ? selectedState.error || "This model is unavailable." : "";
|
|
202
|
+
feedback.classList.toggle("hidden", !failed);
|
|
203
|
+
retry.classList.toggle("hidden", !failed);
|
|
204
|
+
}
|
|
205
|
+
var unsubscribe = subscribeToolLlmConfigurations(updateAlias);
|
|
206
|
+
context.disposers.push(unsubscribe);
|
|
207
|
+
if (!modelConfigurationRequested.has(context.container)) {
|
|
208
|
+
modelConfigurationRequested.add(context.container);
|
|
209
|
+
requestAllToolLlmConfigurations();
|
|
210
|
+
}
|
|
211
|
+
registerControl(node, props, context);
|
|
212
|
+
return wrapper;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function renderCheckbox(node, props, context) {
|
|
216
|
+
var wrapper = document.createElement("label");
|
|
217
|
+
wrapper.className = semanticClasses("tool-checkbox-field", props);
|
|
218
|
+
var input = document.createElement("input");
|
|
219
|
+
input.type = "checkbox";
|
|
220
|
+
input.className = "tool-checkbox";
|
|
221
|
+
input.checked = !!valueAtPath(context.state, node.bind, context.item);
|
|
222
|
+
input.disabled = resolvedBoolean(props.disabled, context);
|
|
223
|
+
if (node.id) input.dataset.toolControlId = node.id;
|
|
224
|
+
input.addEventListener("change", function () { emitNodeAction(node, props, context, { value: input.checked }); });
|
|
225
|
+
wrapper.appendChild(input);
|
|
226
|
+
var copy = document.createElement("span");
|
|
227
|
+
copy.className = "tool-checkbox-copy";
|
|
228
|
+
var label = document.createElement("span");
|
|
229
|
+
label.className = "tool-field-label";
|
|
230
|
+
label.textContent = String(props.label || node.id || "Option");
|
|
231
|
+
copy.appendChild(label);
|
|
232
|
+
if (props.hint) {
|
|
233
|
+
var hint = document.createElement("span");
|
|
234
|
+
hint.className = "tool-field-hint";
|
|
235
|
+
hint.textContent = String(props.hint);
|
|
236
|
+
var hintId = "tool-hint-" + context.toolId + "-" + context.hintIndex++;
|
|
237
|
+
hint.id = hintId;
|
|
238
|
+
input.setAttribute("aria-describedby", hintId);
|
|
239
|
+
copy.appendChild(hint);
|
|
240
|
+
}
|
|
241
|
+
if (props.error) {
|
|
242
|
+
var error = document.createElement("span");
|
|
243
|
+
error.className = "tool-field-error";
|
|
244
|
+
error.textContent = String(props.error);
|
|
245
|
+
error.setAttribute("role", "alert");
|
|
246
|
+
var errorId = "tool-error-" + context.toolId + "-" + context.hintIndex++;
|
|
247
|
+
error.id = errorId;
|
|
248
|
+
var described = input.getAttribute("aria-describedby");
|
|
249
|
+
input.setAttribute("aria-describedby", described ? described + " " + errorId : errorId);
|
|
250
|
+
input.setAttribute("aria-invalid", "true");
|
|
251
|
+
copy.appendChild(error);
|
|
252
|
+
}
|
|
253
|
+
wrapper.appendChild(copy);
|
|
254
|
+
registerControl(node, props, context);
|
|
255
|
+
return wrapper;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function renderTable(node, props, context) {
|
|
259
|
+
var table = document.createElement("table");
|
|
260
|
+
table.className = "tool-table";
|
|
261
|
+
var columns = normalizeColumns(props.columns);
|
|
262
|
+
var head = document.createElement("thead");
|
|
263
|
+
var headRow = document.createElement("tr");
|
|
264
|
+
for (var i = 0; i < columns.length; i++) {
|
|
265
|
+
var th = document.createElement("th");
|
|
266
|
+
th.textContent = String(columns[i].label || columns[i].key || "");
|
|
267
|
+
headRow.appendChild(th);
|
|
268
|
+
}
|
|
269
|
+
head.appendChild(headRow);
|
|
270
|
+
table.appendChild(head);
|
|
271
|
+
var body = document.createElement("tbody");
|
|
272
|
+
var rows = collectionView(valueAtPath(context.state, node.bind, context.item), props);
|
|
273
|
+
for (var ri = 0; ri < rows.length; ri++) {
|
|
274
|
+
var tr = document.createElement("tr");
|
|
275
|
+
for (var ci = 0; ci < columns.length; ci++) {
|
|
276
|
+
var td = document.createElement("td");
|
|
277
|
+
var cell = valueAtPath(rows[ri], columns[ci].key, null);
|
|
278
|
+
td.textContent = cell === undefined || cell === null ? "" : String(cell);
|
|
279
|
+
tr.appendChild(td);
|
|
280
|
+
}
|
|
281
|
+
body.appendChild(tr);
|
|
282
|
+
}
|
|
283
|
+
table.appendChild(body);
|
|
284
|
+
return table;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function renderNode(node, context) {
|
|
288
|
+
if (node.when && !evaluateCondition(node.when, context.state, context.item)) return node.else ? renderNode(node.else, context) : null;
|
|
289
|
+
var props = resolveProps(node.props || {}, context.state, context.item);
|
|
290
|
+
var element;
|
|
291
|
+
var value;
|
|
292
|
+
if (node.type === "switch") {
|
|
293
|
+
var switchValue = valueAtPath(context.state, node.bind, context.item);
|
|
294
|
+
var switchChildren = node.children || [];
|
|
295
|
+
var fallback = null;
|
|
296
|
+
for (var si = 0; si < switchChildren.length; si++) {
|
|
297
|
+
if (switchChildren[si].props.default === true) fallback = switchChildren[si];
|
|
298
|
+
if (switchChildren[si].props.value === switchValue) return renderNode({ type: "stack", children: switchChildren[si].children || [] }, context);
|
|
299
|
+
}
|
|
300
|
+
return fallback ? renderNode({ type: "stack", children: fallback.children || [] }, context) : null;
|
|
301
|
+
}
|
|
302
|
+
if (["form", "tabs", "dialog", "menu", "pagination", "chart"].indexOf(node.type) !== -1) return renderAdvancedNode(node, props, context, renderNode);
|
|
303
|
+
if (["tab", "case", "menu-item"].indexOf(node.type) !== -1) return null;
|
|
304
|
+
if (node.type === "input" || node.type === "textarea") return renderInput(node, props, context);
|
|
305
|
+
if (node.type === "select") return renderSelect(node, props, context);
|
|
306
|
+
if (node.type === "model-select") return renderModelSelect(node, props, context);
|
|
307
|
+
if (node.type === "checkbox") return renderCheckbox(node, props, context);
|
|
308
|
+
if (node.type === "table") return renderTable(node, props, context);
|
|
309
|
+
if (node.type === "divider") {
|
|
310
|
+
element = document.createElement("hr");
|
|
311
|
+
element.className = "tool-divider";
|
|
312
|
+
return element;
|
|
313
|
+
}
|
|
314
|
+
if (node.type === "empty-state") {
|
|
315
|
+
value = valueAtPath(context.state, node.bind, context.item);
|
|
316
|
+
if (Array.isArray(value) && value.length > 0) return null;
|
|
317
|
+
element = document.createElement("div");
|
|
318
|
+
element.className = semanticClasses("tool-empty-state", props);
|
|
319
|
+
appendToolIcon(element, props.icon, null);
|
|
320
|
+
if (props.title) {
|
|
321
|
+
var emptyTitle = document.createElement("strong");
|
|
322
|
+
emptyTitle.className = "tool-empty-state-title";
|
|
323
|
+
emptyTitle.textContent = String(props.title);
|
|
324
|
+
element.appendChild(emptyTitle);
|
|
325
|
+
}
|
|
326
|
+
var emptyText = document.createElement("span");
|
|
327
|
+
emptyText.textContent = String(props.text || "Nothing here yet.");
|
|
328
|
+
element.appendChild(emptyText);
|
|
329
|
+
return element;
|
|
330
|
+
}
|
|
331
|
+
if (node.type === "list") {
|
|
332
|
+
element = document.createElement("ul");
|
|
333
|
+
element.className = semanticClasses("tool-list", props);
|
|
334
|
+
var items = collectionView(valueAtPath(context.state, node.bind, context.item), props);
|
|
335
|
+
for (var li = 0; li < items.length; li++) {
|
|
336
|
+
var listItem = document.createElement("li");
|
|
337
|
+
var itemContext = Object.assign({}, context, { item: items[li] });
|
|
338
|
+
if ((node.children || []).length) appendChildren(listItem, node, itemContext);
|
|
339
|
+
else listItem.textContent = String(items[li]);
|
|
340
|
+
element.appendChild(listItem);
|
|
341
|
+
}
|
|
342
|
+
return element;
|
|
343
|
+
}
|
|
344
|
+
if (node.type === "heading") {
|
|
345
|
+
var level = Math.max(1, Math.min(6, Number(props.level) || 2));
|
|
346
|
+
element = document.createElement("h" + level);
|
|
347
|
+
element.className = semanticClasses("tool-heading", props);
|
|
348
|
+
} else if (node.type === "text") {
|
|
349
|
+
element = document.createElement("span");
|
|
350
|
+
element.className = semanticClasses("tool-text", props);
|
|
351
|
+
} else if (node.type === "badge") {
|
|
352
|
+
element = document.createElement("span");
|
|
353
|
+
element.className = semanticClasses("tool-badge", props);
|
|
354
|
+
} else if (node.type === "button") {
|
|
355
|
+
element = document.createElement("button");
|
|
356
|
+
element.type = "button";
|
|
357
|
+
element.className = semanticClasses("tool-button", props);
|
|
358
|
+
element.disabled = resolvedBoolean(props.disabled, context);
|
|
359
|
+
if (props.accessibleLabel) element.setAttribute("aria-label", String(props.accessibleLabel));
|
|
360
|
+
element.dataset.toolControlId = node.id || "action-" + node.action + "-" + context.autoControlIndex++;
|
|
361
|
+
element.addEventListener("click", function () { emitNodeAction(node, props, context, {}); });
|
|
362
|
+
registerControl(node, props, context);
|
|
363
|
+
} else if (node.type === "icon") {
|
|
364
|
+
element = document.createElement("span");
|
|
365
|
+
element.className = semanticClasses("tool-icon-node", props);
|
|
366
|
+
appendToolIcon(element, props.icon, props.decorative ? null : props.label);
|
|
367
|
+
} else if (node.type === "callout") {
|
|
368
|
+
element = document.createElement("aside");
|
|
369
|
+
element.className = semanticClasses("tool-callout", props);
|
|
370
|
+
appendToolIcon(element, props.icon, null);
|
|
371
|
+
var calloutCopy = document.createElement("span");
|
|
372
|
+
calloutCopy.className = "tool-callout-copy";
|
|
373
|
+
if (props.title) {
|
|
374
|
+
var calloutTitle = document.createElement("strong");
|
|
375
|
+
calloutTitle.textContent = String(props.title);
|
|
376
|
+
calloutCopy.appendChild(calloutTitle);
|
|
377
|
+
}
|
|
378
|
+
if (props.text) {
|
|
379
|
+
var calloutText = document.createElement("span");
|
|
380
|
+
calloutText.textContent = String(props.text);
|
|
381
|
+
calloutCopy.appendChild(calloutText);
|
|
382
|
+
}
|
|
383
|
+
element.appendChild(calloutCopy);
|
|
384
|
+
} else {
|
|
385
|
+
element = document.createElement(node.type === "section" ? "section" : "div");
|
|
386
|
+
var base = node.type === "row" ? "tool-row" : node.type === "card" ? "tool-card" : node.type === "section" ? "tool-section" : "tool-stack";
|
|
387
|
+
element.className = semanticClasses(base, props);
|
|
388
|
+
if (node.type === "section" && props.accessibleLabel) element.setAttribute("aria-label", String(props.accessibleLabel));
|
|
389
|
+
if (node.type === "section" && props.label) {
|
|
390
|
+
var sectionLabel = document.createElement("span");
|
|
391
|
+
sectionLabel.className = "tool-section-label";
|
|
392
|
+
sectionLabel.textContent = String(props.label);
|
|
393
|
+
element.appendChild(sectionLabel);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
if (node.id) element.dataset.toolControlId = node.id;
|
|
397
|
+
value = node.bind ? valueAtPath(context.state, node.bind, context.item) : props.text || props.label;
|
|
398
|
+
if (node.type === "button") {
|
|
399
|
+
if (props.icon && props.iconPosition !== "end") appendToolIcon(element, props.icon, null);
|
|
400
|
+
var buttonLabel = document.createElement("span");
|
|
401
|
+
buttonLabel.textContent = String(props.label || props.accessibleLabel || "Action");
|
|
402
|
+
element.appendChild(buttonLabel);
|
|
403
|
+
if (props.icon && props.iconPosition === "end") appendToolIcon(element, props.icon, null);
|
|
404
|
+
} else if (node.type === "badge") {
|
|
405
|
+
appendToolIcon(element, props.icon, null);
|
|
406
|
+
var badgeText = document.createElement("span");
|
|
407
|
+
badgeText.textContent = String(value === undefined || value === null ? "" : value);
|
|
408
|
+
element.appendChild(badgeText);
|
|
409
|
+
} else if (value !== undefined && value !== null && node.type !== "icon" && node.type !== "callout" && node.type !== "section") {
|
|
410
|
+
element.textContent = String(value);
|
|
411
|
+
}
|
|
412
|
+
appendChildren(element, node, context);
|
|
413
|
+
return element;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function renderToolUiNow(toolId, uiTree, state, emit, container) {
|
|
417
|
+
var active = document.activeElement;
|
|
418
|
+
var activeControlId = active && container.contains(active) ? active.dataset.toolControlId : null;
|
|
419
|
+
var selectionStart = activeControlId && typeof active.selectionStart === "number" ? active.selectionStart : null;
|
|
420
|
+
var selectionEnd = activeControlId && typeof active.selectionEnd === "number" ? active.selectionEnd : null;
|
|
421
|
+
var catalog = Object.create(null);
|
|
422
|
+
var previousDisposers = renderDisposers.get(container) || [];
|
|
423
|
+
for (var di = 0; di < previousDisposers.length; di++) previousDisposers[di]();
|
|
424
|
+
var disposers = [];
|
|
425
|
+
catalogs[toolId] = catalog;
|
|
426
|
+
container.innerHTML = "";
|
|
427
|
+
var node = renderNode(uiTree, { toolId: toolId, state: state || {}, item: null, emit: emit, catalog: catalog, container: container, hintIndex: 1, autoControlIndex: 1, disposers: disposers, activeControlId: activeControlId });
|
|
428
|
+
renderDisposers.set(container, disposers);
|
|
429
|
+
if (node) container.appendChild(node);
|
|
430
|
+
if (typeof requestAnimationFrame === "function" && typeof lucide !== "undefined") refreshIcons();
|
|
431
|
+
if (activeControlId) {
|
|
432
|
+
var controls = container.querySelectorAll("[data-tool-control-id]");
|
|
433
|
+
for (var i = 0; i < controls.length; i++) {
|
|
434
|
+
if (controls[i].dataset.toolControlId !== activeControlId) continue;
|
|
435
|
+
controls[i].focus({ preventScroll: true });
|
|
436
|
+
if (selectionStart !== null && typeof controls[i].setSelectionRange === "function") {
|
|
437
|
+
controls[i].setSelectionRange(selectionStart, selectionEnd);
|
|
438
|
+
}
|
|
439
|
+
break;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
export function renderToolUi(toolId, uiTree, state, emit, container) {
|
|
445
|
+
var active = document.activeElement;
|
|
446
|
+
if (active && container.contains(active) && isToolTextInputComposing(active)) {
|
|
447
|
+
deferredRenders.set(container, { toolId: toolId, uiTree: uiTree, state: state, emit: emit, container: container });
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
deferredRenders.delete(container);
|
|
451
|
+
renderToolUiNow(toolId, uiTree, state, emit, container);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
export function disposeToolUi(container) {
|
|
455
|
+
var disposers = renderDisposers.get(container) || [];
|
|
456
|
+
for (var i = 0; i < disposers.length; i++) disposers[i]();
|
|
457
|
+
renderDisposers.delete(container);
|
|
458
|
+
modelConfigurationRequested.delete(container);
|
|
459
|
+
deferredRenders.delete(container);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
export function getControlCatalog(toolId) {
|
|
463
|
+
return Object.assign({}, catalogs[toolId] || {});
|
|
464
|
+
}
|