@clagentic/console 1.9.0-beta.3 → 1.10.0-beta.1
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/LICENSE +117 -12
- package/LICENSES/MIT-legacy.txt +22 -0
- package/LICENSES/README.md +15 -0
- package/README.md +8 -2
- package/bin/cli.js +30 -5
- package/deploy/clagentic-console.service +10 -6
- package/lib/audit.js +3 -2
- package/lib/build-sha.json +2 -2
- package/lib/build-update-check.js +138 -0
- package/lib/cli/daemon-launch.js +17 -17
- package/lib/config.js +32 -20
- package/lib/daemon-env-settings.js +84 -0
- package/lib/daemon-projects.js +38 -0
- package/lib/daemon.js +202 -158
- package/lib/drain.js +74 -17
- package/lib/env-compat.js +61 -0
- package/lib/extension-commands.js +45 -0
- package/lib/history-visibility.js +4 -0
- package/lib/idle-adapter-reaper.js +71 -0
- package/lib/link-trap.js +78 -0
- package/lib/lore-attestation.js +73 -0
- package/lib/mcp-local.js +8 -6
- package/lib/mcp-tool-input.js +116 -0
- package/lib/mcp-tool-schema.js +179 -0
- package/lib/memory-limits.js +61 -5
- package/lib/memory-setting-validate.js +65 -0
- package/lib/new-work-gate.js +47 -0
- package/lib/os-users.js +5 -3
- package/lib/project-access.js +139 -0
- package/lib/project-connection.js +23 -22
- package/lib/project-external-trigger.js +103 -10
- package/lib/project-file-scope.js +172 -0
- package/lib/project-file-watch.js +86 -61
- package/lib/project-filesystem.js +144 -128
- package/lib/project-git.js +119 -0
- package/lib/project-http.js +44 -28
- package/lib/project-loop.js +12 -5
- package/lib/project-mcp.js +53 -72
- package/lib/project-message-gate.js +70 -0
- package/lib/project-notifications.js +31 -4
- package/lib/project-prompt-responses.js +216 -0
- package/lib/project-sessions.js +164 -302
- package/lib/project-user-message.js +36 -11
- package/lib/project.js +189 -142
- package/lib/projects-dir.js +90 -0
- package/lib/prompt-access.js +22 -0
- package/lib/prompt-kinds/answer-limits.js +15 -0
- package/lib/prompt-kinds/ask-user.js +58 -0
- package/lib/prompt-kinds/codecs.js +97 -0
- package/lib/prompt-kinds/elicitation.js +77 -0
- package/lib/prompt-kinds/extension.js +39 -0
- package/lib/prompt-kinds/index.js +68 -0
- package/lib/prompt-kinds/permission.js +114 -0
- package/lib/prompt-kinds/plan.js +79 -0
- package/lib/prompt-kinds/tool-call.js +38 -0
- package/lib/prompt-registry.js +673 -0
- package/lib/public/app.js +1 -1
- package/lib/public/css/diagnostics.css +50 -0
- package/lib/public/css/input.css +17 -3
- package/lib/public/css/menus.css +10 -0
- package/lib/public/css/messages.css +5 -0
- package/lib/public/css/rewind.css +22 -0
- package/lib/public/index.html +4 -12
- package/lib/public/modules/app-connection.js +7 -0
- package/lib/public/modules/app-cursors.js +7 -5
- package/lib/public/modules/app-messages.js +45 -45
- package/lib/public/modules/app-notifications.js +47 -71
- package/lib/public/modules/app-panels.js +61 -58
- package/lib/public/modules/app-projects.js +2 -1
- package/lib/public/modules/app-rendering.js +4 -10
- package/lib/public/modules/diagnostics.js +60 -16
- package/lib/public/modules/filebrowser.js +18 -16
- package/lib/public/modules/history-visibility.js +4 -0
- package/lib/public/modules/mention.js +3 -2
- package/lib/public/modules/mode-options.js +38 -0
- package/lib/public/modules/project-settings.js +19 -8
- package/lib/public/modules/prompt-banner.js +78 -0
- package/lib/public/modules/prompt-card.js +201 -0
- package/lib/public/modules/prompt-kinds/ask-user-codec.js +131 -0
- package/lib/public/modules/prompt-kinds/ask-user.js +213 -0
- package/lib/public/modules/prompt-kinds/elicitation-codec.js +343 -0
- package/lib/public/modules/prompt-kinds/elicitation.js +176 -0
- package/lib/public/modules/prompt-kinds/index.js +18 -0
- package/lib/public/modules/prompt-kinds/own-key.js +29 -0
- package/lib/public/modules/prompt-kinds/package.json +3 -0
- package/lib/public/modules/prompt-kinds/permission-choices.js +31 -0
- package/lib/public/modules/prompt-kinds/permission.js +209 -0
- package/lib/public/modules/prompt-kinds/plan.js +102 -0
- package/lib/public/modules/prompt-state.js +142 -0
- package/lib/public/modules/prompts.js +134 -0
- package/lib/public/modules/rewind.js +4 -1
- package/lib/public/modules/server-settings.js +2 -4
- package/lib/public/modules/sidebar-mobile.js +19 -9
- package/lib/public/modules/sidebar-sessions.js +21 -14
- package/lib/public/modules/sticky-notes.js +3 -2
- package/lib/public/modules/team-panel.js +5 -4
- package/lib/public/modules/tools.js +67 -904
- package/lib/public/modules/vendor-picker.js +53 -0
- package/lib/public/modules/vendor-registry.js +133 -0
- package/lib/public/sw.js +3 -1
- package/lib/rc-migrate.js +44 -0
- package/lib/runtime-env-keys.js +109 -0
- package/lib/runtime-env.js +236 -0
- package/lib/sdk-bridge.js +290 -273
- package/lib/sdk-message-processor.js +125 -145
- package/lib/server-hub-sessions.js +13 -10
- package/lib/server-palette.js +28 -19
- package/lib/server.js +141 -113
- package/lib/service-install.js +96 -0
- package/lib/session-capabilities.js +76 -0
- package/lib/sessions.js +45 -28
- package/lib/users-permissions.js +9 -6
- package/lib/users.js +9 -0
- package/lib/utils.js +4 -2
- package/lib/vendor-auth.js +22 -0
- package/lib/vendor-registry-message.js +65 -0
- package/lib/ws-origin.js +99 -0
- package/lib/ws-schema.js +33 -22
- package/lib/yoke/adapters/claude-capabilities.js +38 -0
- package/lib/yoke/adapters/claude-vendor.js +35 -0
- package/lib/yoke/adapters/claude-worker.js +55 -87
- package/lib/yoke/adapters/claude.js +156 -62
- package/lib/yoke/adapters/codex-capabilities.js +37 -0
- package/lib/yoke/adapters/codex-vendor.js +46 -0
- package/lib/yoke/adapters/codex.js +347 -156
- package/lib/yoke/adapters/effort-control.js +34 -0
- package/lib/yoke/adapters/permission-relay.js +58 -0
- package/lib/yoke/adapters/worker-mcp-servers.js +81 -0
- package/lib/yoke/auth-checks.js +104 -0
- package/lib/yoke/capabilities.js +49 -0
- package/lib/yoke/codex-app-server.js +23 -5
- package/lib/yoke/env-ownership.js +40 -0
- package/lib/yoke/index.js +67 -173
- package/lib/yoke/install-probe.js +121 -0
- package/lib/yoke/instructions.js +7 -11
- package/lib/yoke/interface.js +199 -3
- package/lib/yoke/package.json +1 -1
- package/lib/yoke/provider-credentials.js +96 -0
- package/lib/yoke/registry.js +340 -0
- package/package.json +12 -8
- package/scripts/check-sdk-lock-drift.js +160 -0
- package/scripts/check-test-count.js +76 -1
- package/scripts/postinstall.js +218 -136
- package/scripts/prompt-harness-history.js +202 -0
- package/scripts/verify-installed.js +67 -0
- package/lib/sdk-permission-ownership.js +0 -136
|
@@ -6,6 +6,7 @@ import { openFile } from './filebrowser.js';
|
|
|
6
6
|
import { getChatLayout } from './theme.js';
|
|
7
7
|
import { store } from './store.js';
|
|
8
8
|
import { VENDOR_NAMES } from './app-rendering.js';
|
|
9
|
+
import { createPromptController } from './prompts.js';
|
|
9
10
|
|
|
10
11
|
var ctx;
|
|
11
12
|
|
|
@@ -57,7 +58,6 @@ var todoMeta = {
|
|
|
57
58
|
var tools = {};
|
|
58
59
|
var currentThinking = null;
|
|
59
60
|
var thinkingGroup = null; // { el, count, totalDuration }
|
|
60
|
-
var pendingPermissions = {};
|
|
61
61
|
|
|
62
62
|
// --- Tool group tracking ---
|
|
63
63
|
var currentToolGroup = null;
|
|
@@ -206,158 +206,6 @@ function shortPath(p) {
|
|
|
206
206
|
return parts.length > 3 ? ".../" + parts.slice(-3).join("/") : p;
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
-
// --- AskUserQuestion ---
|
|
210
|
-
export function renderAskUserQuestion(toolId, input) {
|
|
211
|
-
ctx.finalizeAssistantBlock();
|
|
212
|
-
stopThinking();
|
|
213
|
-
closeToolGroup();
|
|
214
|
-
|
|
215
|
-
var questions = input.questions || [];
|
|
216
|
-
if (questions.length === 0) return;
|
|
217
|
-
|
|
218
|
-
var container = document.createElement("div");
|
|
219
|
-
container.className = "ask-user-container";
|
|
220
|
-
container.dataset.toolId = toolId;
|
|
221
|
-
|
|
222
|
-
var mateContentWrap = null;
|
|
223
|
-
|
|
224
|
-
var answers = {};
|
|
225
|
-
var multiSelections = {};
|
|
226
|
-
|
|
227
|
-
questions.forEach(function (q, qIdx) {
|
|
228
|
-
var qDiv = document.createElement("div");
|
|
229
|
-
qDiv.className = "ask-user-question";
|
|
230
|
-
|
|
231
|
-
if (q.header) {
|
|
232
|
-
var qHeader = document.createElement("div");
|
|
233
|
-
qHeader.className = "ask-user-question-header";
|
|
234
|
-
qHeader.textContent = q.header;
|
|
235
|
-
qDiv.appendChild(qHeader);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
var qText = document.createElement("div");
|
|
239
|
-
qText.className = "ask-user-question-text";
|
|
240
|
-
qText.textContent = q.question || "";
|
|
241
|
-
qDiv.appendChild(qText);
|
|
242
|
-
|
|
243
|
-
var optionsDiv = document.createElement("div");
|
|
244
|
-
optionsDiv.className = "ask-user-options";
|
|
245
|
-
|
|
246
|
-
var isMulti = q.multiSelect || false;
|
|
247
|
-
if (isMulti) multiSelections[qIdx] = new Set();
|
|
248
|
-
|
|
249
|
-
(q.options || []).forEach(function (opt) {
|
|
250
|
-
var btn = document.createElement("button");
|
|
251
|
-
btn.className = "ask-user-option";
|
|
252
|
-
btn.innerHTML =
|
|
253
|
-
'<div class="option-label"></div>' +
|
|
254
|
-
(opt.description ? '<div class="option-desc"></div>' : '');
|
|
255
|
-
btn.querySelector(".option-label").textContent = opt.label;
|
|
256
|
-
if (opt.description) btn.querySelector(".option-desc").textContent = opt.description;
|
|
257
|
-
if (opt.markdown) {
|
|
258
|
-
var pre = document.createElement("pre");
|
|
259
|
-
pre.className = "option-markdown";
|
|
260
|
-
pre.textContent = opt.markdown;
|
|
261
|
-
btn.appendChild(pre);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
btn.addEventListener("click", function () {
|
|
265
|
-
if (container.classList.contains("answered")) return;
|
|
266
|
-
|
|
267
|
-
if (isMulti) {
|
|
268
|
-
var set = multiSelections[qIdx];
|
|
269
|
-
if (set.has(opt.label)) {
|
|
270
|
-
set.delete(opt.label);
|
|
271
|
-
btn.classList.remove("selected");
|
|
272
|
-
} else {
|
|
273
|
-
set.add(opt.label);
|
|
274
|
-
btn.classList.add("selected");
|
|
275
|
-
}
|
|
276
|
-
} else {
|
|
277
|
-
optionsDiv.querySelectorAll(".ask-user-option").forEach(function (b) {
|
|
278
|
-
b.classList.remove("selected");
|
|
279
|
-
});
|
|
280
|
-
btn.classList.add("selected");
|
|
281
|
-
answers[qIdx] = opt.label;
|
|
282
|
-
var otherInput = qDiv.querySelector(".ask-user-other input");
|
|
283
|
-
if (otherInput) otherInput.value = "";
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
optionsDiv.appendChild(btn);
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
qDiv.appendChild(optionsDiv);
|
|
291
|
-
|
|
292
|
-
// "Other" text input
|
|
293
|
-
var otherDiv = document.createElement("div");
|
|
294
|
-
otherDiv.className = "ask-user-other";
|
|
295
|
-
var otherInput = document.createElement("input");
|
|
296
|
-
otherInput.type = "text";
|
|
297
|
-
otherInput.placeholder = "Other...";
|
|
298
|
-
otherInput.addEventListener("input", function () {
|
|
299
|
-
if (container.classList.contains("answered")) return;
|
|
300
|
-
if (otherInput.value.trim()) {
|
|
301
|
-
optionsDiv.querySelectorAll(".ask-user-option").forEach(function (b) {
|
|
302
|
-
b.classList.remove("selected");
|
|
303
|
-
});
|
|
304
|
-
if (isMulti) multiSelections[qIdx] = new Set();
|
|
305
|
-
answers[qIdx] = otherInput.value.trim();
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
otherInput.addEventListener("keydown", function (e) {
|
|
309
|
-
if (e.key === "Enter" && !e.shiftKey) {
|
|
310
|
-
e.preventDefault();
|
|
311
|
-
submitAskUserAnswer(container, toolId, questions, answers, multiSelections);
|
|
312
|
-
}
|
|
313
|
-
});
|
|
314
|
-
otherDiv.appendChild(otherInput);
|
|
315
|
-
qDiv.appendChild(otherDiv);
|
|
316
|
-
container.appendChild(qDiv);
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
// Submit button: always show
|
|
320
|
-
var submitBtn = document.createElement("button");
|
|
321
|
-
submitBtn.className = "ask-user-submit";
|
|
322
|
-
submitBtn.textContent = "Submit";
|
|
323
|
-
submitBtn.addEventListener("click", function () {
|
|
324
|
-
submitAskUserAnswer(container, toolId, questions, answers, multiSelections);
|
|
325
|
-
});
|
|
326
|
-
container.appendChild(submitBtn);
|
|
327
|
-
|
|
328
|
-
// Skip button
|
|
329
|
-
var skipBtn = document.createElement("button");
|
|
330
|
-
skipBtn.className = "ask-user-skip";
|
|
331
|
-
skipBtn.textContent = "Skip";
|
|
332
|
-
skipBtn.addEventListener("click", function () {
|
|
333
|
-
if (container.classList.contains("answered")) return;
|
|
334
|
-
container.classList.add("answered");
|
|
335
|
-
enableMainInput();
|
|
336
|
-
if (ctx.ws && ctx.connected) {
|
|
337
|
-
ctx.ws.send(JSON.stringify({ type: "stop" }));
|
|
338
|
-
}
|
|
339
|
-
});
|
|
340
|
-
container.appendChild(skipBtn);
|
|
341
|
-
|
|
342
|
-
// Mate DM: move all content into the bubble content wrapper
|
|
343
|
-
if (mateContentWrap) {
|
|
344
|
-
var children = [];
|
|
345
|
-
for (var ci = 0; ci < container.childNodes.length; ci++) {
|
|
346
|
-
if (container.childNodes[ci] !== container.querySelector(".dm-bubble-avatar")) {
|
|
347
|
-
children.push(container.childNodes[ci]);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
for (var cj = 0; cj < children.length; cj++) {
|
|
351
|
-
mateContentWrap.appendChild(children[cj]);
|
|
352
|
-
}
|
|
353
|
-
container.appendChild(mateContentWrap);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
ctx.addToMessages(container);
|
|
357
|
-
disableMainInput();
|
|
358
|
-
maybeScrollToBottom();
|
|
359
|
-
}
|
|
360
|
-
|
|
361
209
|
export function disableMainInput() {
|
|
362
210
|
ctx.inputEl.disabled = true;
|
|
363
211
|
ctx.inputEl.placeholder = "Answer the question above to continue...";
|
|
@@ -369,764 +217,81 @@ export function enableMainInput() {
|
|
|
369
217
|
ctx.inputEl.placeholder = "Message " + (VENDOR_NAMES[_v] || VENDOR_NAMES.claude) + "...";
|
|
370
218
|
}
|
|
371
219
|
|
|
372
|
-
|
|
373
|
-
if (container.classList.contains("answered")) return;
|
|
374
|
-
|
|
375
|
-
var result = {};
|
|
376
|
-
for (var i = 0; i < questions.length; i++) {
|
|
377
|
-
var q = questions[i];
|
|
378
|
-
if (q.multiSelect && multiSelections[i] && multiSelections[i].size > 0) {
|
|
379
|
-
result[i] = Array.from(multiSelections[i]).join(", ");
|
|
380
|
-
} else if (answers[i]) {
|
|
381
|
-
result[i] = answers[i];
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
if (Object.keys(result).length === 0) return;
|
|
386
|
-
|
|
387
|
-
container.classList.add("answered");
|
|
388
|
-
enableMainInput();
|
|
389
|
-
if (ctx.stopUrgentBlink) ctx.stopUrgentBlink();
|
|
390
|
-
|
|
391
|
-
// Show user's answers inline
|
|
392
|
-
showAnswerSummary(container, questions, result);
|
|
393
|
-
|
|
394
|
-
if (ctx.ws && ctx.connected) {
|
|
395
|
-
ctx.ws.send(JSON.stringify({
|
|
396
|
-
type: "ask_user_response",
|
|
397
|
-
toolId: toolId,
|
|
398
|
-
answers: result,
|
|
399
|
-
}));
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
function showAnswerSummary(container, questions, answers) {
|
|
404
|
-
if (!answers || Object.keys(answers).length === 0) return;
|
|
405
|
-
var existing = container.querySelector(".ask-user-answer-summary");
|
|
406
|
-
if (existing) return;
|
|
407
|
-
var summary = document.createElement("div");
|
|
408
|
-
summary.className = "ask-user-answer-summary";
|
|
409
|
-
for (var key in answers) {
|
|
410
|
-
if (!answers.hasOwnProperty(key)) continue;
|
|
411
|
-
var row = document.createElement("div");
|
|
412
|
-
row.className = "ask-user-answer-row";
|
|
413
|
-
var qi = parseInt(key, 10);
|
|
414
|
-
var label = (questions && questions[qi] && questions[qi].question) ? questions[qi].question : "Answer";
|
|
415
|
-
row.innerHTML = '<span class="ask-user-answer-label">' + escapeHtml(label) + '</span>' +
|
|
416
|
-
'<span class="ask-user-answer-value">' + escapeHtml(String(answers[key])) + '</span>';
|
|
417
|
-
summary.appendChild(row);
|
|
418
|
-
}
|
|
419
|
-
// Insert before submit button
|
|
420
|
-
var submitBtn = container.querySelector(".ask-user-submit");
|
|
421
|
-
if (submitBtn) {
|
|
422
|
-
submitBtn.parentNode.insertBefore(summary, submitBtn);
|
|
423
|
-
} else {
|
|
424
|
-
container.appendChild(summary);
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
export function markAskUserAnswered(toolId, answers) {
|
|
429
|
-
var container = document.querySelector('.ask-user-container[data-tool-id="' + toolId + '"]');
|
|
430
|
-
if (container && !container.classList.contains("answered")) {
|
|
431
|
-
container.classList.add("answered");
|
|
432
|
-
enableMainInput();
|
|
433
|
-
// Restore answers from history replay
|
|
434
|
-
if (answers && Object.keys(answers).length > 0) {
|
|
435
|
-
// Find matching questions from the tool_executing input
|
|
436
|
-
var questions = null;
|
|
437
|
-
var askQuestions = container.querySelectorAll(".ask-user-question");
|
|
438
|
-
if (askQuestions.length > 0) {
|
|
439
|
-
questions = [];
|
|
440
|
-
for (var qi = 0; qi < askQuestions.length; qi++) {
|
|
441
|
-
var qTextEl = askQuestions[qi].querySelector(".ask-user-question-text");
|
|
442
|
-
questions.push({ question: qTextEl ? qTextEl.textContent : "" });
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
showAnswerSummary(container, questions, answers);
|
|
446
|
-
// Also mark selected options to match the answers
|
|
447
|
-
for (var key in answers) {
|
|
448
|
-
if (!answers.hasOwnProperty(key)) continue;
|
|
449
|
-
var idx = parseInt(key, 10);
|
|
450
|
-
if (askQuestions[idx]) {
|
|
451
|
-
var answerVal = String(answers[key]);
|
|
452
|
-
var options = askQuestions[idx].querySelectorAll(".ask-user-option");
|
|
453
|
-
var matched = false;
|
|
454
|
-
for (var oi = 0; oi < options.length; oi++) {
|
|
455
|
-
var labelEl = options[oi].querySelector(".option-label");
|
|
456
|
-
if (labelEl && labelEl.textContent === answerVal) {
|
|
457
|
-
options[oi].classList.add("selected");
|
|
458
|
-
matched = true;
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
// If not matched to an option, fill the "Other" input
|
|
462
|
-
if (!matched) {
|
|
463
|
-
var otherInput = askQuestions[idx].querySelector(".ask-user-other input");
|
|
464
|
-
if (otherInput) otherInput.value = answerVal;
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
// --- Permission request ---
|
|
473
|
-
function permissionInputSummary(toolName, input) {
|
|
474
|
-
if (!input || typeof input !== "object") return "";
|
|
475
|
-
switch (toolName) {
|
|
476
|
-
case "Bash": return input.command || input.description || "";
|
|
477
|
-
case "Edit": return shortPath(input.file_path);
|
|
478
|
-
case "Write": return shortPath(input.file_path);
|
|
479
|
-
case "Read": return shortPath(input.file_path);
|
|
480
|
-
case "Glob": return input.pattern || "";
|
|
481
|
-
case "Grep": return (input.pattern || "") + (input.path ? " in " + shortPath(input.path) : "");
|
|
482
|
-
default: return toolSummary(toolName, input);
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
export function renderPermissionRequest(requestId, toolName, toolInput, decisionReason, mateId, vendor) {
|
|
487
|
-
if (pendingPermissions[requestId]) return;
|
|
488
|
-
// On WS reconnect the DOM node may survive a pendingPermissions reset.
|
|
489
|
-
// Guard against duplicating the card in that case.
|
|
490
|
-
if (ctx && ctx.messagesEl && ctx.messagesEl.querySelector('[data-request-id="' + requestId + '"]')) return;
|
|
491
|
-
ctx.finalizeAssistantBlock();
|
|
492
|
-
stopThinking();
|
|
493
|
-
closeToolGroup();
|
|
494
|
-
|
|
495
|
-
// ExitPlanMode: render as plan confirmation instead of generic permission
|
|
496
|
-
if (toolName === "ExitPlanMode") {
|
|
497
|
-
renderPlanPermission(requestId);
|
|
498
|
-
return;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
// Channel layout: conversational "Can I ...?" style
|
|
502
|
-
if (getChatLayout() === "channel") {
|
|
503
|
-
renderConversationalPermission(requestId, toolName, toolInput, mateId, vendor);
|
|
504
|
-
return;
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
// Bubble layout: formal "Permission Required" dialog
|
|
508
|
-
renderFormalPermission(requestId, toolName, toolInput, decisionReason);
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
function renderFormalPermission(requestId, toolName, toolInput, decisionReason) {
|
|
512
|
-
var container = document.createElement("div");
|
|
513
|
-
container.className = "permission-container";
|
|
514
|
-
container.dataset.requestId = requestId;
|
|
515
|
-
|
|
516
|
-
// Header
|
|
517
|
-
var header = document.createElement("div");
|
|
518
|
-
header.className = "permission-header";
|
|
519
|
-
header.innerHTML =
|
|
520
|
-
'<span class="permission-icon">' + iconHtml("shield") + '</span>' +
|
|
521
|
-
'<span class="permission-title">Permission Required</span>';
|
|
522
|
-
|
|
523
|
-
// Body
|
|
524
|
-
var body = document.createElement("div");
|
|
525
|
-
body.className = "permission-body";
|
|
526
|
-
|
|
527
|
-
var summary = document.createElement("div");
|
|
528
|
-
summary.className = "permission-summary";
|
|
529
|
-
var summaryText = permissionInputSummary(toolName, toolInput);
|
|
530
|
-
summary.innerHTML =
|
|
531
|
-
'<span class="permission-tool-name"></span>' +
|
|
532
|
-
(summaryText ? '<span class="permission-tool-desc"></span>' : '');
|
|
533
|
-
summary.querySelector(".permission-tool-name").textContent = toolName;
|
|
534
|
-
if (summaryText) {
|
|
535
|
-
summary.querySelector(".permission-tool-desc").textContent = summaryText;
|
|
536
|
-
}
|
|
537
|
-
body.appendChild(summary);
|
|
538
|
-
|
|
539
|
-
if (decisionReason) {
|
|
540
|
-
var reason = document.createElement("div");
|
|
541
|
-
reason.className = "permission-reason";
|
|
542
|
-
reason.textContent = decisionReason;
|
|
543
|
-
body.appendChild(reason);
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
// Collapsible details
|
|
547
|
-
var details = document.createElement("details");
|
|
548
|
-
details.className = "permission-details";
|
|
549
|
-
var detailsSummary = document.createElement("summary");
|
|
550
|
-
detailsSummary.textContent = "Details";
|
|
551
|
-
var detailsPre = document.createElement("pre");
|
|
552
|
-
detailsPre.textContent = JSON.stringify(toolInput, null, 2);
|
|
553
|
-
details.appendChild(detailsSummary);
|
|
554
|
-
details.appendChild(detailsPre);
|
|
555
|
-
body.appendChild(details);
|
|
556
|
-
|
|
557
|
-
// Actions
|
|
558
|
-
var actions = document.createElement("div");
|
|
559
|
-
actions.className = "permission-actions";
|
|
560
|
-
|
|
561
|
-
var allowBtn = document.createElement("button");
|
|
562
|
-
allowBtn.className = "permission-btn permission-allow";
|
|
563
|
-
allowBtn.textContent = "Allow Once";
|
|
564
|
-
allowBtn.addEventListener("click", function () {
|
|
565
|
-
sendPermissionResponse(container, requestId, "allow");
|
|
566
|
-
});
|
|
567
|
-
|
|
568
|
-
var allowAlwaysBtn = document.createElement("button");
|
|
569
|
-
allowAlwaysBtn.className = "permission-btn permission-allow-session";
|
|
570
|
-
allowAlwaysBtn.textContent = "Allow for Session";
|
|
571
|
-
allowAlwaysBtn.addEventListener("click", function () {
|
|
572
|
-
sendPermissionResponse(container, requestId, "allow_always");
|
|
573
|
-
});
|
|
574
|
-
|
|
575
|
-
var denyBtn = document.createElement("button");
|
|
576
|
-
denyBtn.className = "permission-btn permission-deny";
|
|
577
|
-
denyBtn.textContent = "Deny";
|
|
578
|
-
denyBtn.addEventListener("click", function () {
|
|
579
|
-
sendPermissionResponse(container, requestId, "deny");
|
|
580
|
-
});
|
|
581
|
-
|
|
582
|
-
actions.appendChild(allowBtn);
|
|
583
|
-
actions.appendChild(allowAlwaysBtn);
|
|
584
|
-
actions.appendChild(denyBtn);
|
|
585
|
-
|
|
586
|
-
container.appendChild(header);
|
|
587
|
-
container.appendChild(body);
|
|
588
|
-
container.appendChild(actions);
|
|
589
|
-
ctx.addToMessages(container);
|
|
590
|
-
|
|
591
|
-
pendingPermissions[requestId] = container;
|
|
592
|
-
refreshIcons(container);
|
|
593
|
-
maybeScrollToBottom();
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
function renderPlanPermission(requestId) {
|
|
597
|
-
if (pendingPermissions[requestId]) return;
|
|
598
|
-
var container = document.createElement("div");
|
|
599
|
-
container.className = "permission-container plan-permission";
|
|
600
|
-
container.dataset.requestId = requestId;
|
|
601
|
-
|
|
602
|
-
// Header
|
|
603
|
-
var header = document.createElement("div");
|
|
604
|
-
header.className = "permission-header plan-permission-header";
|
|
605
|
-
header.innerHTML =
|
|
606
|
-
'<span class="permission-icon">' + iconHtml("check-circle") + '</span>' +
|
|
607
|
-
'<span class="permission-title">Plan Approval</span>';
|
|
608
|
-
|
|
609
|
-
// Body (plan content already visible above, no need to repeat)
|
|
610
|
-
var body = document.createElement("div");
|
|
611
|
-
body.className = "permission-body";
|
|
612
|
-
|
|
613
|
-
// Actions row 1: main buttons
|
|
614
|
-
var actions = document.createElement("div");
|
|
615
|
-
actions.className = "permission-actions plan-permission-actions";
|
|
616
|
-
|
|
617
|
-
// Option 1: Clear context & auto-accept
|
|
618
|
-
var clearBtn = document.createElement("button");
|
|
619
|
-
clearBtn.className = "permission-btn plan-btn-clear";
|
|
620
|
-
var contextPct = ctx.getContextPercent ? ctx.getContextPercent() : 0;
|
|
621
|
-
clearBtn.innerHTML = iconHtml("refresh-cw") + ' <span>Clear context' +
|
|
622
|
-
(contextPct > 0 ? ' <span class="plan-ctx-pct">(' + contextPct + '% used)</span>' : '') +
|
|
623
|
-
' & auto-accept</span>';
|
|
624
|
-
clearBtn.addEventListener("click", function () {
|
|
625
|
-
sendPlanResponse(container, requestId, "allow_clear_context");
|
|
626
|
-
});
|
|
627
|
-
|
|
628
|
-
// Option 2: Auto-accept edits
|
|
629
|
-
var approveBtn = document.createElement("button");
|
|
630
|
-
approveBtn.className = "permission-btn permission-allow";
|
|
631
|
-
approveBtn.textContent = "Auto-accept edits";
|
|
632
|
-
approveBtn.addEventListener("click", function () {
|
|
633
|
-
sendPlanResponse(container, requestId, "allow_accept_edits");
|
|
634
|
-
});
|
|
220
|
+
// --- Operator prompts (permission, plan, AskUserQuestion, elicitation) ---
|
|
635
221
|
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
actions.appendChild(approveBtn);
|
|
654
|
-
actions.appendChild(manualBtn);
|
|
655
|
-
actions.appendChild(rejectBtn);
|
|
656
|
-
|
|
657
|
-
// Feedback input row (Option 4: tell Claude what to change)
|
|
658
|
-
var feedbackRow = document.createElement("div");
|
|
659
|
-
feedbackRow.className = "plan-feedback-row";
|
|
660
|
-
var feedbackInput = document.createElement("input");
|
|
661
|
-
feedbackInput.type = "text";
|
|
662
|
-
feedbackInput.className = "plan-feedback-input";
|
|
663
|
-
feedbackInput.placeholder = "Tell Claude what to change...";
|
|
664
|
-
var feedbackSendBtn = document.createElement("button");
|
|
665
|
-
feedbackSendBtn.className = "plan-feedback-send";
|
|
666
|
-
feedbackSendBtn.innerHTML = iconHtml("arrow-up");
|
|
667
|
-
feedbackSendBtn.disabled = true;
|
|
668
|
-
|
|
669
|
-
feedbackInput.addEventListener("input", function () {
|
|
670
|
-
feedbackSendBtn.disabled = !feedbackInput.value.trim();
|
|
671
|
-
});
|
|
672
|
-
feedbackInput.addEventListener("keydown", function (e) {
|
|
673
|
-
if (e.key === "Enter" && !e.shiftKey && feedbackInput.value.trim()) {
|
|
674
|
-
e.preventDefault();
|
|
675
|
-
submitPlanFeedback();
|
|
676
|
-
}
|
|
677
|
-
});
|
|
678
|
-
feedbackSendBtn.addEventListener("click", function () {
|
|
679
|
-
if (feedbackInput.value.trim()) submitPlanFeedback();
|
|
680
|
-
});
|
|
681
|
-
|
|
682
|
-
function submitPlanFeedback() {
|
|
683
|
-
var text = feedbackInput.value.trim();
|
|
684
|
-
if (!text) return;
|
|
685
|
-
sendPlanResponse(container, requestId, "deny_with_feedback", text);
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
feedbackRow.appendChild(feedbackInput);
|
|
689
|
-
feedbackRow.appendChild(feedbackSendBtn);
|
|
690
|
-
|
|
691
|
-
container.appendChild(header);
|
|
692
|
-
container.appendChild(body);
|
|
693
|
-
container.appendChild(actions);
|
|
694
|
-
container.appendChild(feedbackRow);
|
|
695
|
-
ctx.addToMessages(container);
|
|
696
|
-
|
|
697
|
-
pendingPermissions[requestId] = container;
|
|
698
|
-
refreshIcons(container);
|
|
699
|
-
maybeScrollToBottom();
|
|
700
|
-
// Focus the feedback input after render
|
|
701
|
-
setTimeout(function () { feedbackInput.focus(); }, 50);
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
function sendPlanResponse(container, requestId, decision, feedback) {
|
|
705
|
-
if (container.classList.contains("resolved")) return;
|
|
706
|
-
container.classList.add("resolved");
|
|
707
|
-
if (ctx.stopUrgentBlink) ctx.stopUrgentBlink();
|
|
708
|
-
|
|
709
|
-
var labelMap = {
|
|
710
|
-
"allow": "Approved (manual)",
|
|
711
|
-
"allow_accept_edits": "Approved (auto-accept)",
|
|
712
|
-
"allow_clear_context": "Approved (clear + auto-accept)",
|
|
713
|
-
"deny": "Rejected",
|
|
714
|
-
"deny_with_feedback": "Feedback sent",
|
|
715
|
-
};
|
|
716
|
-
var label = labelMap[decision] || decision;
|
|
717
|
-
var isDeny = decision === "deny" || decision === "deny_with_feedback";
|
|
718
|
-
var resolvedClass = isDeny ? "resolved-denied" : "resolved-allowed";
|
|
719
|
-
container.classList.add(resolvedClass);
|
|
720
|
-
|
|
721
|
-
// Replace actions + feedback with decision label
|
|
722
|
-
var actionsEl = container.querySelector(".plan-permission-actions");
|
|
723
|
-
if (actionsEl) {
|
|
724
|
-
actionsEl.innerHTML = '<span class="permission-decision-label">' + label + '</span>';
|
|
725
|
-
}
|
|
726
|
-
var feedbackRowEl = container.querySelector(".plan-feedback-row");
|
|
727
|
-
if (feedbackRowEl) feedbackRowEl.remove();
|
|
728
|
-
|
|
729
|
-
if (ctx.ws && ctx.connected) {
|
|
730
|
-
var payload = {
|
|
731
|
-
type: "permission_response",
|
|
732
|
-
requestId: requestId,
|
|
733
|
-
decision: decision,
|
|
734
|
-
};
|
|
735
|
-
if (feedback) payload.feedback = feedback;
|
|
736
|
-
if (decision === "allow_clear_context" && planContent) {
|
|
737
|
-
payload.planContent = planContent;
|
|
222
|
+
// Cards are drawn and kept in line with the server's state by one
|
|
223
|
+
// controller (prompts.js). Its state is not cleared by resetToolState: an
|
|
224
|
+
// older-history page resets tool state after newer pages already delivered
|
|
225
|
+
// the outcomes it needs. Cleared on session switch.
|
|
226
|
+
var prompts = createPromptController({
|
|
227
|
+
place: function (container, focusSelector) {
|
|
228
|
+
ctx.finalizeAssistantBlock();
|
|
229
|
+
stopThinking();
|
|
230
|
+
closeToolGroup();
|
|
231
|
+
ctx.addToMessages(container);
|
|
232
|
+
refreshIcons(container);
|
|
233
|
+
maybeScrollToBottom();
|
|
234
|
+
if (focusSelector) {
|
|
235
|
+
setTimeout(function () {
|
|
236
|
+
var target = container.querySelector(focusSelector);
|
|
237
|
+
if (target) target.focus();
|
|
238
|
+
}, 50);
|
|
738
239
|
}
|
|
240
|
+
},
|
|
241
|
+
send: function (payload) {
|
|
242
|
+
if (!(ctx.ws && ctx.connected)) return false;
|
|
739
243
|
ctx.ws.send(JSON.stringify(payload));
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
function
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
244
|
+
return true;
|
|
245
|
+
},
|
|
246
|
+
layout: function () { return getChatLayout(); },
|
|
247
|
+
toolSummary: toolSummary,
|
|
248
|
+
vendorIdentity: vendorIdentity,
|
|
249
|
+
getContextPercent: function () { return ctx.getContextPercent ? ctx.getContextPercent() : 0; },
|
|
250
|
+
getPlanContent: function () { return planContent; },
|
|
251
|
+
setMainInputDisabled: function (disabled) {
|
|
252
|
+
if (!ctx.inputEl) return;
|
|
253
|
+
if (disabled) disableMainInput();
|
|
254
|
+
else enableMainInput();
|
|
255
|
+
},
|
|
256
|
+
contains: function (el) {
|
|
257
|
+
return !(ctx.messagesEl && typeof ctx.messagesEl.contains === "function") || ctx.messagesEl.contains(el);
|
|
258
|
+
},
|
|
259
|
+
findInTranscript: function (requestId) {
|
|
260
|
+
return ctx && ctx.messagesEl ? ctx.messagesEl.querySelector('[data-request-id="' + requestId + '"]') : null;
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Apply one prompt message of any kind, live or replayed (including the
|
|
266
|
+
* per-kind messages of older history). Returns the prompt's effective state,
|
|
267
|
+
* or null for a message that is not about a prompt.
|
|
268
|
+
*/
|
|
269
|
+
export function applyPromptMessage(msg) {
|
|
270
|
+
return prompts.apply(msg);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export function clearPromptStates() {
|
|
274
|
+
prompts.clear();
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** Whether any prompt, of any kind, is still awaiting the operator. */
|
|
278
|
+
export function hasPendingPrompts() {
|
|
279
|
+
return prompts.hasPending();
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** Return every card awaiting a server confirmation to its answerable state. */
|
|
283
|
+
export function restoreUnconfirmedPrompts(message) {
|
|
284
|
+
prompts.restoreUnconfirmed(message);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function vendorIdentity(vendor) {
|
|
765
288
|
var vendorAvatars = { claude: "/claude-code-avatar.png", codex: "/codex-avatar.png" };
|
|
766
|
-
var vendorName = (vendor && VENDOR_NAMES[vendor]) || VENDOR_NAMES.claude;
|
|
767
289
|
return {
|
|
768
|
-
name:
|
|
290
|
+
name: (vendor && VENDOR_NAMES[vendor]) || VENDOR_NAMES.claude,
|
|
769
291
|
avatar: (vendor && vendorAvatars[vendor]) || vendorAvatars.claude,
|
|
770
292
|
};
|
|
771
293
|
}
|
|
772
294
|
|
|
773
|
-
function renderConversationalPermission(requestId, toolName, toolInput, mateId, vendor) {
|
|
774
|
-
var identity = resolvePermissionIdentity(mateId, vendor);
|
|
775
|
-
var info = matePermissionInfo(toolName, toolInput);
|
|
776
|
-
var askMsg = "Can I " + info.verb + (info.target ? " " + info.target : "") + "?";
|
|
777
|
-
|
|
778
|
-
var container = document.createElement("div");
|
|
779
|
-
container.className = "permission-container";
|
|
780
|
-
container.dataset.requestId = requestId;
|
|
781
|
-
|
|
782
|
-
// Avatar (left column)
|
|
783
|
-
var avi = document.createElement("img");
|
|
784
|
-
avi.className = "dm-bubble-avatar dm-bubble-avatar-agent";
|
|
785
|
-
avi.src = identity.avatar;
|
|
786
|
-
avi.alt = "";
|
|
787
|
-
container.appendChild(avi);
|
|
788
|
-
|
|
789
|
-
// Content (right column)
|
|
790
|
-
var content = document.createElement("div");
|
|
791
|
-
content.className = "dm-bubble-content";
|
|
792
|
-
|
|
793
|
-
// Name + time header
|
|
794
|
-
var headerRow = document.createElement("div");
|
|
795
|
-
headerRow.className = "dm-bubble-header";
|
|
796
|
-
headerRow.innerHTML =
|
|
797
|
-
'<span class="dm-bubble-name">' + escapeHtml(identity.name) + '</span>' +
|
|
798
|
-
'<span class="dm-bubble-time">' + String(new Date().getHours()).padStart(2, "0") + ":" + String(new Date().getMinutes()).padStart(2, "0") + '</span>';
|
|
799
|
-
content.appendChild(headerRow);
|
|
800
|
-
|
|
801
|
-
// Ask text
|
|
802
|
-
var askEl = document.createElement("div");
|
|
803
|
-
askEl.className = "perm-ask";
|
|
804
|
-
askEl.textContent = askMsg;
|
|
805
|
-
content.appendChild(askEl);
|
|
806
|
-
|
|
807
|
-
// Collapsible details
|
|
808
|
-
var details = document.createElement("details");
|
|
809
|
-
details.className = "perm-details";
|
|
810
|
-
var summary = document.createElement("summary");
|
|
811
|
-
summary.textContent = "Details";
|
|
812
|
-
var pre = document.createElement("pre");
|
|
813
|
-
pre.textContent = JSON.stringify(toolInput, null, 2);
|
|
814
|
-
details.appendChild(summary);
|
|
815
|
-
details.appendChild(pre);
|
|
816
|
-
content.appendChild(details);
|
|
817
|
-
|
|
818
|
-
// Buttons
|
|
819
|
-
var actions = document.createElement("div");
|
|
820
|
-
actions.className = "permission-actions";
|
|
821
|
-
|
|
822
|
-
var allowBtn = document.createElement("button");
|
|
823
|
-
allowBtn.className = "perm-reply perm-allow";
|
|
824
|
-
allowBtn.textContent = "Sure";
|
|
825
|
-
allowBtn.addEventListener("click", function () {
|
|
826
|
-
sendPermissionResponse(container, requestId, "allow");
|
|
827
|
-
});
|
|
828
|
-
|
|
829
|
-
var alwaysBtn = document.createElement("button");
|
|
830
|
-
alwaysBtn.className = "perm-reply perm-always";
|
|
831
|
-
alwaysBtn.textContent = "Allow for session";
|
|
832
|
-
alwaysBtn.addEventListener("click", function () {
|
|
833
|
-
sendPermissionResponse(container, requestId, "allow_always");
|
|
834
|
-
});
|
|
835
|
-
|
|
836
|
-
var denyBtn = document.createElement("button");
|
|
837
|
-
denyBtn.className = "perm-reply perm-deny";
|
|
838
|
-
denyBtn.textContent = "No";
|
|
839
|
-
denyBtn.addEventListener("click", function () {
|
|
840
|
-
sendPermissionResponse(container, requestId, "deny");
|
|
841
|
-
});
|
|
842
|
-
|
|
843
|
-
actions.appendChild(allowBtn);
|
|
844
|
-
actions.appendChild(alwaysBtn);
|
|
845
|
-
actions.appendChild(denyBtn);
|
|
846
|
-
content.appendChild(actions);
|
|
847
|
-
|
|
848
|
-
container.appendChild(content);
|
|
849
|
-
|
|
850
|
-
ctx.addToMessages(container);
|
|
851
|
-
pendingPermissions[requestId] = container;
|
|
852
|
-
refreshIcons(container);
|
|
853
|
-
maybeScrollToBottom();
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
function sendPermissionResponse(container, requestId, decision) {
|
|
857
|
-
if (container.classList.contains("resolved")) return;
|
|
858
|
-
container.classList.add("resolved");
|
|
859
|
-
if (ctx.stopUrgentBlink) ctx.stopUrgentBlink();
|
|
860
|
-
|
|
861
|
-
var label = decision === "deny" ? "Denied" : decision === "allow_always" ? "Allowed for session" : "Allowed";
|
|
862
|
-
var resolvedClass = decision === "deny" ? "resolved-denied" : "resolved-allowed";
|
|
863
|
-
container.classList.add(resolvedClass);
|
|
864
|
-
|
|
865
|
-
// Replace actions with decision label
|
|
866
|
-
var actions = container.querySelector(".permission-actions");
|
|
867
|
-
if (actions) {
|
|
868
|
-
actions.innerHTML = '<span class="permission-decision-label">' + label + '</span>';
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
if (ctx.ws && ctx.connected) {
|
|
872
|
-
ctx.ws.send(JSON.stringify({
|
|
873
|
-
type: "permission_response",
|
|
874
|
-
requestId: requestId,
|
|
875
|
-
decision: decision,
|
|
876
|
-
}));
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
delete pendingPermissions[requestId];
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
export function markPermissionResolved(requestId, decision) {
|
|
883
|
-
var container = pendingPermissions[requestId];
|
|
884
|
-
if (!container) {
|
|
885
|
-
// Find by data attribute (history replay)
|
|
886
|
-
container = ctx.messagesEl.querySelector('[data-request-id="' + requestId + '"]');
|
|
887
|
-
}
|
|
888
|
-
if (!container || container.classList.contains("resolved")) return;
|
|
889
|
-
|
|
890
|
-
container.classList.add("resolved");
|
|
891
|
-
|
|
892
|
-
// Plan-specific decisions
|
|
893
|
-
var planLabelMap = {
|
|
894
|
-
"allow_accept_edits": "Approved (auto-accept)",
|
|
895
|
-
"allow_clear_context": "Approved (clear + auto-accept)",
|
|
896
|
-
"deny_with_feedback": "Feedback sent",
|
|
897
|
-
};
|
|
898
|
-
var isDeny = decision === "deny" || decision === "deny_with_feedback";
|
|
899
|
-
var resolvedClass = isDeny ? "resolved-denied" : "resolved-allowed";
|
|
900
|
-
container.classList.add(resolvedClass);
|
|
901
|
-
|
|
902
|
-
var label = planLabelMap[decision] || (decision === "deny" ? "Denied" : decision === "allow_always" ? "Allowed for session" : "Allowed");
|
|
903
|
-
var actions = container.querySelector(".permission-actions") || container.querySelector(".plan-permission-actions");
|
|
904
|
-
if (actions) {
|
|
905
|
-
actions.innerHTML = '<span class="permission-decision-label">' + label + '</span>';
|
|
906
|
-
}
|
|
907
|
-
// Remove feedback row if present (plan permission)
|
|
908
|
-
var feedbackRow = container.querySelector(".plan-feedback-row");
|
|
909
|
-
if (feedbackRow) feedbackRow.remove();
|
|
910
|
-
|
|
911
|
-
delete pendingPermissions[requestId];
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
export function markPermissionCancelled(requestId) {
|
|
915
|
-
var container = pendingPermissions[requestId];
|
|
916
|
-
if (!container) {
|
|
917
|
-
container = ctx.messagesEl.querySelector('[data-request-id="' + requestId + '"]');
|
|
918
|
-
}
|
|
919
|
-
if (!container || container.classList.contains("resolved")) return;
|
|
920
|
-
|
|
921
|
-
container.classList.add("resolved", "resolved-cancelled");
|
|
922
|
-
var actions = container.querySelector(".permission-actions");
|
|
923
|
-
if (actions) {
|
|
924
|
-
actions.innerHTML = '<span class="permission-decision-label">Cancelled</span>';
|
|
925
|
-
}
|
|
926
|
-
|
|
927
|
-
delete pendingPermissions[requestId];
|
|
928
|
-
}
|
|
929
|
-
|
|
930
|
-
// --- MCP elicitation rendering ---
|
|
931
|
-
|
|
932
|
-
var pendingElicitations = {};
|
|
933
|
-
|
|
934
|
-
export function renderElicitationRequest(msg) {
|
|
935
|
-
if (pendingElicitations[msg.requestId]) return;
|
|
936
|
-
ctx.finalizeAssistantBlock();
|
|
937
|
-
stopThinking();
|
|
938
|
-
closeToolGroup();
|
|
939
|
-
|
|
940
|
-
var container = document.createElement("div");
|
|
941
|
-
container.className = "permission-container elicitation-container";
|
|
942
|
-
container.dataset.requestId = msg.requestId;
|
|
943
|
-
|
|
944
|
-
// Header
|
|
945
|
-
var header = document.createElement("div");
|
|
946
|
-
header.className = "permission-header";
|
|
947
|
-
header.innerHTML =
|
|
948
|
-
'<span class="permission-icon">' + iconHtml("key") + '</span>' +
|
|
949
|
-
'<span class="permission-title">' + escapeHtml(msg.serverName || "MCP Server") + ' requests input</span>';
|
|
950
|
-
|
|
951
|
-
// Body
|
|
952
|
-
var body = document.createElement("div");
|
|
953
|
-
body.className = "permission-body";
|
|
954
|
-
|
|
955
|
-
if (msg.message) {
|
|
956
|
-
var messageEl = document.createElement("div");
|
|
957
|
-
messageEl.className = "permission-reason";
|
|
958
|
-
messageEl.textContent = msg.message;
|
|
959
|
-
body.appendChild(messageEl);
|
|
960
|
-
}
|
|
961
|
-
|
|
962
|
-
// Form fields (form mode) or URL button (url mode)
|
|
963
|
-
var formData = {};
|
|
964
|
-
|
|
965
|
-
if (msg.mode === "url" && msg.url) {
|
|
966
|
-
var urlInfo = document.createElement("div");
|
|
967
|
-
urlInfo.className = "elicitation-url-info";
|
|
968
|
-
urlInfo.style.cssText = "margin-top: 8px; font-size: 12px; color: var(--text-muted);";
|
|
969
|
-
urlInfo.textContent = "Opens: " + msg.url;
|
|
970
|
-
body.appendChild(urlInfo);
|
|
971
|
-
} else if (msg.requestedSchema && msg.requestedSchema.properties) {
|
|
972
|
-
var formEl = document.createElement("div");
|
|
973
|
-
formEl.className = "elicitation-form";
|
|
974
|
-
formEl.style.cssText = "margin-top: 8px; display: flex; flex-direction: column; gap: 8px;";
|
|
975
|
-
|
|
976
|
-
var props = msg.requestedSchema.properties;
|
|
977
|
-
var required = msg.requestedSchema.required || [];
|
|
978
|
-
var propNames = Object.keys(props);
|
|
979
|
-
for (var i = 0; i < propNames.length; i++) {
|
|
980
|
-
var propName = propNames[i];
|
|
981
|
-
var prop = props[propName];
|
|
982
|
-
var isRequired = required.indexOf(propName) !== -1;
|
|
983
|
-
|
|
984
|
-
var fieldWrapper = document.createElement("div");
|
|
985
|
-
fieldWrapper.style.cssText = "display: flex; flex-direction: column; gap: 2px;";
|
|
986
|
-
|
|
987
|
-
var label = document.createElement("label");
|
|
988
|
-
label.style.cssText = "font-size: 12px; font-weight: 500; color: var(--text-secondary);";
|
|
989
|
-
label.textContent = propName + (isRequired ? " *" : "");
|
|
990
|
-
if (prop.description) {
|
|
991
|
-
label.title = prop.description;
|
|
992
|
-
}
|
|
993
|
-
|
|
994
|
-
var input;
|
|
995
|
-
if (prop.type === "boolean") {
|
|
996
|
-
input = document.createElement("input");
|
|
997
|
-
input.type = "checkbox";
|
|
998
|
-
input.dataset.propName = propName;
|
|
999
|
-
input.dataset.propType = "boolean";
|
|
1000
|
-
} else if (prop.enum) {
|
|
1001
|
-
input = document.createElement("select");
|
|
1002
|
-
input.dataset.propName = propName;
|
|
1003
|
-
input.dataset.propType = "enum";
|
|
1004
|
-
input.style.cssText = "padding: 4px 8px; border-radius: 4px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text-primary); font-size: 13px;";
|
|
1005
|
-
for (var ei = 0; ei < prop.enum.length; ei++) {
|
|
1006
|
-
var opt = document.createElement("option");
|
|
1007
|
-
opt.value = prop.enum[ei];
|
|
1008
|
-
opt.textContent = prop.enum[ei];
|
|
1009
|
-
input.appendChild(opt);
|
|
1010
|
-
}
|
|
1011
|
-
} else {
|
|
1012
|
-
input = document.createElement("input");
|
|
1013
|
-
input.type = prop.type === "number" || prop.type === "integer" ? "number" : "text";
|
|
1014
|
-
input.dataset.propName = propName;
|
|
1015
|
-
input.dataset.propType = prop.type || "string";
|
|
1016
|
-
input.placeholder = prop.description || propName;
|
|
1017
|
-
input.style.cssText = "padding: 4px 8px; border-radius: 4px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text-primary); font-size: 13px;";
|
|
1018
|
-
}
|
|
1019
|
-
|
|
1020
|
-
fieldWrapper.appendChild(label);
|
|
1021
|
-
fieldWrapper.appendChild(input);
|
|
1022
|
-
formEl.appendChild(fieldWrapper);
|
|
1023
|
-
}
|
|
1024
|
-
body.appendChild(formEl);
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
// Actions
|
|
1028
|
-
var actions = document.createElement("div");
|
|
1029
|
-
actions.className = "permission-actions";
|
|
1030
|
-
|
|
1031
|
-
var acceptBtn = document.createElement("button");
|
|
1032
|
-
acceptBtn.className = "permission-btn permission-allow";
|
|
1033
|
-
|
|
1034
|
-
if (msg.mode === "url" && msg.url) {
|
|
1035
|
-
acceptBtn.textContent = "Open & Approve";
|
|
1036
|
-
acceptBtn.addEventListener("click", function () {
|
|
1037
|
-
window.open(msg.url, "_blank");
|
|
1038
|
-
sendElicitationResponse(container, msg.requestId, "accept", {});
|
|
1039
|
-
});
|
|
1040
|
-
} else {
|
|
1041
|
-
acceptBtn.textContent = "Submit";
|
|
1042
|
-
acceptBtn.addEventListener("click", function () {
|
|
1043
|
-
// Collect form values
|
|
1044
|
-
var content = {};
|
|
1045
|
-
var inputs = container.querySelectorAll("[data-prop-name]");
|
|
1046
|
-
for (var j = 0; j < inputs.length; j++) {
|
|
1047
|
-
var inp = inputs[j];
|
|
1048
|
-
var name = inp.dataset.propName;
|
|
1049
|
-
var pType = inp.dataset.propType;
|
|
1050
|
-
if (pType === "boolean") {
|
|
1051
|
-
content[name] = inp.checked;
|
|
1052
|
-
} else if (pType === "number" || pType === "integer") {
|
|
1053
|
-
content[name] = Number(inp.value);
|
|
1054
|
-
} else {
|
|
1055
|
-
content[name] = inp.value;
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
sendElicitationResponse(container, msg.requestId, "accept", content);
|
|
1059
|
-
});
|
|
1060
|
-
}
|
|
1061
|
-
|
|
1062
|
-
var denyBtn = document.createElement("button");
|
|
1063
|
-
denyBtn.className = "permission-btn permission-deny";
|
|
1064
|
-
denyBtn.textContent = "Deny";
|
|
1065
|
-
denyBtn.addEventListener("click", function () {
|
|
1066
|
-
sendElicitationResponse(container, msg.requestId, "reject", null);
|
|
1067
|
-
});
|
|
1068
|
-
|
|
1069
|
-
actions.appendChild(acceptBtn);
|
|
1070
|
-
actions.appendChild(denyBtn);
|
|
1071
|
-
|
|
1072
|
-
container.appendChild(header);
|
|
1073
|
-
container.appendChild(body);
|
|
1074
|
-
container.appendChild(actions);
|
|
1075
|
-
ctx.addToMessages(container);
|
|
1076
|
-
|
|
1077
|
-
pendingElicitations[msg.requestId] = container;
|
|
1078
|
-
refreshIcons(container);
|
|
1079
|
-
maybeScrollToBottom();
|
|
1080
|
-
}
|
|
1081
|
-
|
|
1082
|
-
function sendElicitationResponse(container, requestId, action, content) {
|
|
1083
|
-
if (container.classList.contains("resolved")) return;
|
|
1084
|
-
container.classList.add("resolved");
|
|
1085
|
-
if (ctx.stopUrgentBlink) ctx.stopUrgentBlink();
|
|
1086
|
-
|
|
1087
|
-
var label = action === "reject" ? "Denied" : "Submitted";
|
|
1088
|
-
var resolvedClass = action === "reject" ? "resolved-denied" : "resolved-allowed";
|
|
1089
|
-
container.classList.add(resolvedClass);
|
|
1090
|
-
|
|
1091
|
-
var actions = container.querySelector(".permission-actions");
|
|
1092
|
-
if (actions) {
|
|
1093
|
-
actions.innerHTML = '<span class="permission-decision-label">' + label + '</span>';
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
if (ctx.ws && ctx.connected) {
|
|
1097
|
-
var msg = {
|
|
1098
|
-
type: "elicitation_response",
|
|
1099
|
-
requestId: requestId,
|
|
1100
|
-
action: action,
|
|
1101
|
-
};
|
|
1102
|
-
if (action === "accept" && content) {
|
|
1103
|
-
msg.content = content;
|
|
1104
|
-
}
|
|
1105
|
-
ctx.ws.send(JSON.stringify(msg));
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
delete pendingElicitations[requestId];
|
|
1109
|
-
}
|
|
1110
|
-
|
|
1111
|
-
export function markElicitationResolved(requestId, action) {
|
|
1112
|
-
var container = pendingElicitations[requestId];
|
|
1113
|
-
if (!container) {
|
|
1114
|
-
container = ctx.messagesEl.querySelector('.elicitation-container[data-request-id="' + requestId + '"]');
|
|
1115
|
-
}
|
|
1116
|
-
if (!container || container.classList.contains("resolved")) return;
|
|
1117
|
-
|
|
1118
|
-
container.classList.add("resolved");
|
|
1119
|
-
var isDeny = action === "reject";
|
|
1120
|
-
container.classList.add(isDeny ? "resolved-denied" : "resolved-allowed");
|
|
1121
|
-
|
|
1122
|
-
var label = isDeny ? "Denied" : "Submitted";
|
|
1123
|
-
var actionsEl = container.querySelector(".permission-actions");
|
|
1124
|
-
if (actionsEl) {
|
|
1125
|
-
actionsEl.innerHTML = '<span class="permission-decision-label">' + label + '</span>';
|
|
1126
|
-
}
|
|
1127
|
-
delete pendingElicitations[requestId];
|
|
1128
|
-
}
|
|
1129
|
-
|
|
1130
295
|
// --- Plan mode rendering ---
|
|
1131
296
|
export function renderPlanBanner(type) {
|
|
1132
297
|
ctx.finalizeAssistantBlock();
|
|
@@ -2276,8 +1441,6 @@ export function resetToolState() {
|
|
|
2276
1441
|
todoWidgetEl = null;
|
|
2277
1442
|
todoWidgetVisible = true;
|
|
2278
1443
|
if (todoObserver) { todoObserver.disconnect(); todoObserver = null; }
|
|
2279
|
-
pendingPermissions = {};
|
|
2280
|
-
pendingElicitations = {};
|
|
2281
1444
|
currentToolGroup = null;
|
|
2282
1445
|
toolGroupCounter = 0;
|
|
2283
1446
|
toolGroups = {};
|