clay-server 3.8.1 → 4.0.0-beta.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/lib/ask-user-mcp-server.js +5 -119
- 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 +1 -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/mate-creation-mcp-server.js +55 -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 +4 -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 +1 -0
- package/lib/project-mate-creation-proposal.js +120 -0
- package/lib/project-memory.js +14 -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 +397 -0
- package/lib/project-worker-proposal.js +25 -25
- package/lib/project-workspace-query.js +144 -0
- package/lib/project.js +349 -102
- package/lib/public/app.js +85 -42
- 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/mates.css +7 -34
- package/lib/public/css/pane.css +1 -1
- package/lib/public/css/playbook.css +0 -80
- 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 +93 -74
- package/lib/public/modules/app-connection.js +10 -1
- 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 +102 -37
- package/lib/public/modules/app-notifications.js +8 -119
- 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/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 +158 -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-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-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/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 +7 -64
- package/lib/public/modules/sidebar-presence.js +37 -0
- 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 +7 -6
- 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-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 +13 -2
- package/lib/runtime-env.js +65 -0
- package/lib/sdk-bridge.js +120 -32
- package/lib/sdk-message-processor.js +10 -6
- 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 +111 -59
- package/lib/session-pair-mcp-server.js +6 -6
- package/lib/sessions.js +18 -3
- 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 +93 -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 +73 -43
- package/lib/yoke/adapters/codex.js +40 -10
- 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-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 +3 -2
- 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,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
|
+
}
|