openclacky 1.5.25 → 1.5.26
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +61 -0
- data/lib/clacky/agent/chunk_index.rb +2 -1
- data/lib/clacky/agent/message_compressor_helper.rb +20 -2
- data/lib/clacky/agent/session_serializer.rb +28 -1
- data/lib/clacky/agent/skill_manager.rb +2 -8
- data/lib/clacky/agent/time_machine.rb +108 -127
- data/lib/clacky/agent/tool_executor.rb +2 -11
- data/lib/clacky/agent.rb +15 -19
- data/lib/clacky/agent_config.rb +14 -4
- data/lib/clacky/billing/media_usage.rb +69 -0
- data/lib/clacky/billing/platform_billing.rb +5 -0
- data/lib/clacky/brand_config.rb +16 -215
- data/lib/clacky/default_extensions/ext-studio/agents/ext-developer/system_prompt.md +2 -80
- data/lib/clacky/default_extensions/ext-studio/panels/studio/view.js +1 -1
- data/lib/clacky/default_extensions/ext-studio/skills/ext-develop/SKILL.md +10 -96
- data/lib/clacky/default_extensions/git/panels/git/view.js +208 -69
- data/lib/clacky/default_extensions/knowledge/README.md +1 -1
- data/lib/clacky/default_extensions/knowledge/README.zh.md +1 -1
- data/lib/clacky/default_extensions/knowledge/lib/importer.rb +1 -1
- data/lib/clacky/default_extensions/knowledge/panels/kb/view.js +3 -3
- data/lib/clacky/default_extensions/meeting/api/handler.rb +23 -2
- data/lib/clacky/default_extensions/meeting/panels/meeting/view.js +194 -36
- data/lib/clacky/default_extensions/preview/icon.svg +3 -2
- data/lib/clacky/default_extensions/secretary/panels/work/view.js +108 -33
- data/lib/clacky/default_extensions/side-chat/README.md +40 -0
- data/lib/clacky/default_extensions/side-chat/README.zh.md +40 -0
- data/lib/clacky/default_extensions/side-chat/api/handler.rb +90 -0
- data/lib/clacky/default_extensions/side-chat/api/runtime.rb +411 -0
- data/lib/clacky/default_extensions/side-chat/ext.yml +16 -0
- data/lib/clacky/default_extensions/side-chat/icon.svg +14 -0
- data/lib/clacky/default_extensions/side-chat/panels/side-chat/view.js +779 -0
- data/lib/clacky/default_extensions/terminal/README.md +36 -0
- data/lib/clacky/default_extensions/terminal/README.zh.md +36 -0
- data/lib/clacky/default_extensions/terminal/api/handler.rb +121 -0
- data/lib/clacky/default_extensions/terminal/api/runtime.rb +397 -0
- data/lib/clacky/default_extensions/terminal/ext.yml +16 -0
- data/lib/clacky/default_extensions/terminal/icon.svg +13 -0
- data/lib/clacky/default_extensions/terminal/panels/terminal/view.js +351 -0
- data/lib/clacky/default_extensions/terminal/vendor/LICENSE +21 -0
- data/lib/clacky/default_extensions/terminal/vendor/addon-fit.js +2 -0
- data/lib/clacky/default_extensions/terminal/vendor/xterm.css +218 -0
- data/lib/clacky/default_extensions/terminal/vendor/xterm.js +2 -0
- data/lib/clacky/default_skills/media-gen/SKILL.md +30 -9
- data/lib/clacky/extension/api_extension.rb +12 -0
- data/lib/clacky/locales/en.rb +14 -11
- data/lib/clacky/locales/i18n.rb +25 -0
- data/lib/clacky/locales/zh.rb +14 -11
- data/lib/clacky/media/base.rb +11 -1
- data/lib/clacky/media/openai_compat.rb +271 -3
- data/lib/clacky/message_format/open_ai.rb +17 -0
- data/lib/clacky/prompts/base.md +3 -0
- data/lib/clacky/providers.rb +33 -20
- data/lib/clacky/reasoning_levels.rb +75 -0
- data/lib/clacky/server/channel/channel_ui_controller.rb +12 -5
- data/lib/clacky/server/git_panel.rb +40 -18
- data/lib/clacky/server/http_server.rb +62 -71
- data/lib/clacky/server/session_registry.rb +3 -0
- data/lib/clacky/ui2/markdown_renderer.rb +153 -0
- data/lib/clacky/ui2/strings_cjk_patch.rb +134 -124
- data/lib/clacky/utils/file_link_normalizer.rb +30 -3
- data/lib/clacky/utils/frontmatter.rb +63 -0
- data/lib/clacky/utils/model_pricing.rb +67 -9
- data/lib/clacky/version.rb +1 -1
- data/lib/clacky/web/app.css +722 -274
- data/lib/clacky/web/app.js +2 -0
- data/lib/clacky/web/components/chat-composer.js +504 -0
- data/lib/clacky/web/components/chat-navigator.js +1 -1
- data/lib/clacky/web/components/model-picker.js +319 -20
- data/lib/clacky/web/components/quote-select.js +97 -39
- data/lib/clacky/web/core/aside.js +137 -27
- data/lib/clacky/web/core/ext.js +658 -81
- data/lib/clacky/web/features/brand/store.js +0 -4
- data/lib/clacky/web/features/brand/view.js +2 -99
- data/lib/clacky/web/features/extensions/store.js +3 -1
- data/lib/clacky/web/features/extensions/view.js +14 -15
- data/lib/clacky/web/features/new-session/store.js +4 -0
- data/lib/clacky/web/features/new-session/view.js +27 -4
- data/lib/clacky/web/features/skills/store.js +7 -5
- data/lib/clacky/web/features/skills/view.js +65 -16
- data/lib/clacky/web/features/version/view.js +1 -1
- data/lib/clacky/web/features/workspace/store.js +7 -3
- data/lib/clacky/web/features/workspace/view.js +46 -5
- data/lib/clacky/web/i18n.js +104 -58
- data/lib/clacky/web/index.html +21 -22
- data/lib/clacky/web/lib/box-diagram.js +239 -0
- data/lib/clacky/web/sessions.js +117 -151
- data/lib/clacky/web/settings.js +23 -16
- data/lib/clacky/web/ws-dispatcher.js +4 -1
- data/lib/clacky.rb +2 -0
- metadata +24 -1
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
// ── BoxDiagram — cell-accurate repair for box-drawing diagrams ─────────────
|
|
2
|
+
//
|
|
3
|
+
// Models pad box rows by character count, so a row holding CJK comes out wider
|
|
4
|
+
// than the terminal-style cells it was aiming for. The TUI fixes this in Ruby
|
|
5
|
+
// (ui2/markdown_renderer.rb#align_box_diagrams); the browser needs its own copy
|
|
6
|
+
// because chat markdown is rendered here by marked.
|
|
7
|
+
//
|
|
8
|
+
// Two problems, both solved here:
|
|
9
|
+
// 1. Rows are padded by characters, not display cells. `align` re-pads every
|
|
10
|
+
// row of a diagram to one shared cell width.
|
|
11
|
+
// 2. A CJK glyph is 1.66 ASCII advances in a browser monospace font, not 2,
|
|
12
|
+
// so cell padding alone can never line up. `toHtml` wraps each wide glyph
|
|
13
|
+
// in a span pinned to `2ch`, which restores the 1:2 ratio.
|
|
14
|
+
(function (global) {
|
|
15
|
+
"use strict";
|
|
16
|
+
|
|
17
|
+
var BOX_CHARS = "│┌┐└┘├┤┬┴┼";
|
|
18
|
+
var BOX_CORNERS = "┌┐└┘";
|
|
19
|
+
var BOX_OPEN = /^\s*┌.*┐\s*$/;
|
|
20
|
+
var BOX_ROW_END = /[│┐┘┤]$/;
|
|
21
|
+
// Frame followed by a floating label, e.g. `│ + │ ← tab bar`.
|
|
22
|
+
var BOX_ANNOTATED = /^(.*│)(\s{2,}[^\s│┌┐└┘├┤┬┴┼][^│┌┐└┘├┤┬┴┼]*)$/;
|
|
23
|
+
// East Asian Wide / Fullwidth: two cells, everywhere.
|
|
24
|
+
var WIDE = /[\u1100-\u115F\u2E80-\uA4CF\uAC00-\uD7A3\uF900-\uFAFF\uFE30-\uFE6F\uFF00-\uFF60\uFFE0-\uFFE6]/;
|
|
25
|
+
|
|
26
|
+
function charWidth(ch) {
|
|
27
|
+
return WIDE.test(ch) ? 2 : 1;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function width(text) {
|
|
31
|
+
var w = 0;
|
|
32
|
+
for (var i = 0; i < text.length; i++) {
|
|
33
|
+
var code = text.charCodeAt(i);
|
|
34
|
+
if (code >= 0xd800 && code <= 0xdbff && i + 1 < text.length) {
|
|
35
|
+
w += 2; // astral plane: CJK ext B and friends
|
|
36
|
+
i++;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
w += charWidth(text.charAt(i));
|
|
40
|
+
}
|
|
41
|
+
return w;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function rstrip(text) {
|
|
45
|
+
return text.replace(/\s+$/, "");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function countChars(text, chars) {
|
|
49
|
+
var n = 0;
|
|
50
|
+
for (var i = 0; i < text.length; i++) {
|
|
51
|
+
if (chars.indexOf(text.charAt(i)) !== -1) n++;
|
|
52
|
+
}
|
|
53
|
+
return n;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function splitLabel(text) {
|
|
57
|
+
var match = text.match(BOX_ANNOTATED);
|
|
58
|
+
if (!match) return [text, null];
|
|
59
|
+
return [match[1], match[2].replace(/^\s+|\s+$/g, "")];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function boxWidth(body) {
|
|
63
|
+
var parts = splitLabel(rstrip(body));
|
|
64
|
+
var text = rstrip(parts[0]);
|
|
65
|
+
return BOX_ROW_END.test(text) ? width(text) : null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// A frame holding free-standing boxes (no ┬/┼ anywhere) is gridded by those
|
|
69
|
+
// boxes' own corners, e.g. `│ ┌──┐ ┌──┐ │`.
|
|
70
|
+
function gridRow(text) {
|
|
71
|
+
return /^\s*│/.test(text) && countChars(text, BOX_CORNERS) >= 2;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function barColumns(text, chars) {
|
|
75
|
+
var cols = [];
|
|
76
|
+
var offset = 0;
|
|
77
|
+
for (var i = 0; i < text.length; i++) {
|
|
78
|
+
var ch = text.charAt(i);
|
|
79
|
+
if (chars.indexOf(ch) !== -1) cols.push(offset);
|
|
80
|
+
offset += charWidth(ch);
|
|
81
|
+
}
|
|
82
|
+
return cols;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// A border row is the grid; a frame drawn without one falls back to its first
|
|
86
|
+
// content row, so the rest of the frame at least agrees with it.
|
|
87
|
+
function targetBars(ref, bars) {
|
|
88
|
+
if (!ref) return null;
|
|
89
|
+
var inner = bars.slice(1, -1);
|
|
90
|
+
var target = ref.length === inner.length ? ref : ref.slice(1, -1);
|
|
91
|
+
if (!inner.length || target.length !== inner.length) return null;
|
|
92
|
+
return [bars[0]].concat(target, [bars[bars.length - 1]]);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function fitCell(cell, cellWidth) {
|
|
96
|
+
var text = cell.replace(/^\s+|\s+$/g, "");
|
|
97
|
+
var pad = cellWidth - width(text);
|
|
98
|
+
if (pad < 0) return null;
|
|
99
|
+
if (pad === 0) return text;
|
|
100
|
+
return " " + text + new Array(pad).join(" ");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// A cell that cannot fit its column leaves the row alone rather than
|
|
104
|
+
// half-aligned; an exact fit closes the gap and keeps the bars lined up.
|
|
105
|
+
function rebuildRow(text, bars) {
|
|
106
|
+
var cells = text.split("│");
|
|
107
|
+
if (cells.length !== bars.length + 1) return null;
|
|
108
|
+
|
|
109
|
+
var fitted = [];
|
|
110
|
+
for (var i = 0; i < bars.length - 1; i++) {
|
|
111
|
+
var cellWidth = bars[i + 1] - bars[i] - 1;
|
|
112
|
+
var cell = fitCell(cells[i + 1], cellWidth);
|
|
113
|
+
if (cell === null) return null;
|
|
114
|
+
fitted.push(cell);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
var out = cells[0];
|
|
118
|
+
for (var j = 0; j < fitted.length; j++) out += "│" + fitted[j];
|
|
119
|
+
return out + "│" + cells[cells.length - 1];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function alignCells(rows) {
|
|
123
|
+
var ref = null;
|
|
124
|
+
return rows.map(function (row) {
|
|
125
|
+
var text = rstrip(row);
|
|
126
|
+
if (gridRow(text) || (/[┬┼]/.test(text) && /[┌├]/.test(text))) {
|
|
127
|
+
ref = barColumns(text, BOX_CHARS);
|
|
128
|
+
return row;
|
|
129
|
+
}
|
|
130
|
+
if (/^\s*[└┘]/.test(text)) {
|
|
131
|
+
ref = null;
|
|
132
|
+
return row;
|
|
133
|
+
}
|
|
134
|
+
if (/^\s*│/.test(text) && BOX_ROW_END.test(text)) {
|
|
135
|
+
var bars = barColumns(text, "│");
|
|
136
|
+
var target = targetBars(ref, bars);
|
|
137
|
+
var rebuilt = target && rebuildRow(text, target);
|
|
138
|
+
if (!ref && bars.length > 2) ref = bars;
|
|
139
|
+
return rebuilt || row;
|
|
140
|
+
}
|
|
141
|
+
return row;
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Frames grow to the widest row instead of cutting content.
|
|
146
|
+
function alignBlock(rows) {
|
|
147
|
+
var aligned = alignCells(rows);
|
|
148
|
+
var target = 0;
|
|
149
|
+
aligned.forEach(function (row) {
|
|
150
|
+
var w = boxWidth(row);
|
|
151
|
+
if (w !== null && w > target) target = w;
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
return aligned.map(function (row) {
|
|
155
|
+
var parts = splitLabel(rstrip(row));
|
|
156
|
+
var body = parts[0];
|
|
157
|
+
var label = parts[1];
|
|
158
|
+
// A connector carrying a label is not a frame row; padding it would shove
|
|
159
|
+
// the label past the frame it annotates.
|
|
160
|
+
var resized = label && countChars(body, BOX_CHARS) < 2 ? body : resize(body, target);
|
|
161
|
+
return label ? resized + " " + label : resized;
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function resize(body, target) {
|
|
166
|
+
var text = rstrip(body);
|
|
167
|
+
if (!BOX_ROW_END.test(text)) return body;
|
|
168
|
+
|
|
169
|
+
var diff = target - width(text);
|
|
170
|
+
if (diff <= 0) return text;
|
|
171
|
+
|
|
172
|
+
var filler = /^\s*[┌└├]/.test(text) ? "─" : " ";
|
|
173
|
+
var pad = new Array(diff + 1).join(filler);
|
|
174
|
+
return text.slice(0, -1) + pad + text.charAt(text.length - 1);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function hasFrame(text) {
|
|
178
|
+
if (!text || text.indexOf("┌") === -1) return false;
|
|
179
|
+
var lines = text.split("\n");
|
|
180
|
+
for (var i = 0; i < lines.length; i++) {
|
|
181
|
+
if (BOX_OPEN.test(lines[i])) return true;
|
|
182
|
+
}
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function align(content) {
|
|
187
|
+
if (!hasFrame(content)) return content;
|
|
188
|
+
|
|
189
|
+
var lines = content.split("\n");
|
|
190
|
+
var out = [];
|
|
191
|
+
var i = 0;
|
|
192
|
+
while (i < lines.length) {
|
|
193
|
+
if (BOX_OPEN.test(lines[i])) {
|
|
194
|
+
var stop = i;
|
|
195
|
+
while (stop + 1 < lines.length && blockLine(lines[stop + 1])) stop++;
|
|
196
|
+
out = out.concat(alignBlock(lines.slice(i, stop + 1)));
|
|
197
|
+
i = stop + 1;
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
out.push(lines[i]);
|
|
201
|
+
i++;
|
|
202
|
+
}
|
|
203
|
+
return out.join("\n");
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function blockLine(line) {
|
|
207
|
+
var text = rstrip(line);
|
|
208
|
+
if (!text.replace(/\s/g, "")) return false;
|
|
209
|
+
return BOX_ROW_END.test(text) || /^\s*│/.test(text);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Every wide glyph is pinned to 2ch, putting the browser font back on the 1:2
|
|
213
|
+
// grid the diagram was drawn for.
|
|
214
|
+
function toHtml(text) {
|
|
215
|
+
var out = "";
|
|
216
|
+
for (var i = 0; i < text.length; i++) {
|
|
217
|
+
var ch = text.charAt(i);
|
|
218
|
+
var code = text.charCodeAt(i);
|
|
219
|
+
if (code >= 0xd800 && code <= 0xdbff && i + 1 < text.length) {
|
|
220
|
+
out += '<span class="bd-c">' + text.substr(i, 2) + "</span>";
|
|
221
|
+
i++;
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
if (ch === "&") out += "&";
|
|
225
|
+
else if (ch === "<") out += "<";
|
|
226
|
+
else if (ch === ">") out += ">";
|
|
227
|
+
else if (WIDE.test(ch)) out += '<span class="bd-c">' + ch + "</span>";
|
|
228
|
+
else out += ch;
|
|
229
|
+
}
|
|
230
|
+
return out;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
global.BoxDiagram = {
|
|
234
|
+
align: align,
|
|
235
|
+
hasFrame: hasFrame,
|
|
236
|
+
toHtml: toHtml,
|
|
237
|
+
width: width
|
|
238
|
+
};
|
|
239
|
+
})(window);
|
data/lib/clacky/web/sessions.js
CHANGED
|
@@ -213,9 +213,13 @@ const Sessions = (() => {
|
|
|
213
213
|
// treats a space as the end of the URL, so links with spaces are never
|
|
214
214
|
// recognized. Re-encoding the path (decode then encode, idempotent) turns
|
|
215
215
|
// spaces into %20 and a literal % into %25 so marked sees a valid URL.
|
|
216
|
+
//
|
|
217
|
+
// A destination ends at the first unbalanced ")", so a paired "()" inside a
|
|
218
|
+
// file name (备份(旧).pdf) stays part of the path instead of ending it — the
|
|
219
|
+
// same rule the server-side FileLinkNormalizer uses.
|
|
216
220
|
function _encodeFileUrlsInMarkdown(text) {
|
|
217
221
|
return text.replace(
|
|
218
|
-
/(!?\[[^\]]*\]\()(file:\/{2,3})([^)]+)(\))/g,
|
|
222
|
+
/(!?\[[^\]]*\]\()(file:\/{2,3})((?:[^()\n]|\([^()\n]*\))+)(\))/g,
|
|
219
223
|
(_m, open, scheme, path, close) => {
|
|
220
224
|
try { path = decodeURI(path); } catch (_) { /* keep raw if malformed */ }
|
|
221
225
|
return open + scheme + encodeURI(path) + close;
|
|
@@ -271,7 +275,16 @@ const Sessions = (() => {
|
|
|
271
275
|
renderer.code = function({ text: code, lang }) {
|
|
272
276
|
code = restoreMathInCode(code);
|
|
273
277
|
const language = (lang || "").split(/\s+/)[0]; // strip extra info after lang
|
|
274
|
-
|
|
278
|
+
// Box-drawing diagrams are re-padded to display cells and their wide
|
|
279
|
+
// glyphs pinned to 2ch — hljs would split them into random tokens, so
|
|
280
|
+
// they skip highlighting entirely.
|
|
281
|
+
const diagram =
|
|
282
|
+
typeof BoxDiagram !== "undefined" && BoxDiagram.hasFrame(code)
|
|
283
|
+
? BoxDiagram.align(code)
|
|
284
|
+
: null;
|
|
285
|
+
const body = diagram
|
|
286
|
+
? `<pre class="box-diagram"><code>${BoxDiagram.toHtml(diagram)}</code></pre>`
|
|
287
|
+
: `<pre><code class="hljs${language ? ` language-${escapeHtml(language)}` : ""}">${_highlightCode(code, language)}</code></pre>`;
|
|
275
288
|
const displayLang = language || "text";
|
|
276
289
|
return (
|
|
277
290
|
`<div class="code-block">` +
|
|
@@ -286,7 +299,7 @@ const Sessions = (() => {
|
|
|
286
299
|
`</svg>` +
|
|
287
300
|
`</button>` +
|
|
288
301
|
`</div>` +
|
|
289
|
-
|
|
302
|
+
body +
|
|
290
303
|
`</div>`
|
|
291
304
|
);
|
|
292
305
|
};
|
|
@@ -3596,6 +3609,27 @@ const Sessions = (() => {
|
|
|
3596
3609
|
// (in app.js) when the user presses Enter without an active completion.
|
|
3597
3610
|
// Will be internalised once the Skill autocomplete moves into skills.js.
|
|
3598
3611
|
sendMessage: _sendMessage,
|
|
3612
|
+
// Markdown pipeline shared with panels that render agent text outside the
|
|
3613
|
+
// main conversation (the side chat). Same <think> extraction, same marked
|
|
3614
|
+
// config, so a message reads identically in both places.
|
|
3615
|
+
renderMarkdown: _renderMarkdown,
|
|
3616
|
+
// Reference badges (quote / mention chips) drawn on user bubbles, shared
|
|
3617
|
+
// with the side chat so a forwarded message keeps its provenance.
|
|
3618
|
+
renderReferenceBadge: _renderMentionBadge,
|
|
3619
|
+
// Tool rows: the exact elements the main conversation builds for a tool
|
|
3620
|
+
// run, exposed so a panel shows the same grouping, collapse, args pane,
|
|
3621
|
+
// diffs and stdout instead of growing a look-alike that drifts.
|
|
3622
|
+
toolView: {
|
|
3623
|
+
makeGroup: _makeToolGroup,
|
|
3624
|
+
addCall: _addToolCallToGroup,
|
|
3625
|
+
complete: _completeToolItem,
|
|
3626
|
+
collapse: _collapseToolGroup,
|
|
3627
|
+
toggleDetails: _toggleToolItemDetails,
|
|
3628
|
+
// Search hits and markdown documents leave the row and become their own
|
|
3629
|
+
// card below the group; a panel needs the same rule, not a copy of it.
|
|
3630
|
+
isPromoted: _isPromotedToolResult,
|
|
3631
|
+
promoteResult: _promoteToolResult,
|
|
3632
|
+
},
|
|
3599
3633
|
// Composer entry point for "add to chat" on a file in the Files tab: the
|
|
3600
3634
|
// caller passes an entry ({ name, path, size }) and gets it staged in the
|
|
3601
3635
|
// attachment strip. Returns false when nothing was staged.
|
|
@@ -3770,7 +3804,7 @@ const Sessions = (() => {
|
|
|
3770
3804
|
// it. The user bubble is rendered locally on the "subscribed" event (see
|
|
3771
3805
|
// ws-dispatcher), so callers never touch history or WS timing.
|
|
3772
3806
|
// Returns the created session.
|
|
3773
|
-
async startWith(command, { name, source = "setup", display = null } = {}) {
|
|
3807
|
+
async startWith(command, { name, source = "setup", display = null, agentProfile = null } = {}) {
|
|
3774
3808
|
if (!name) {
|
|
3775
3809
|
name = Sessions.nextDefaultName();
|
|
3776
3810
|
}
|
|
@@ -3778,7 +3812,7 @@ const Sessions = (() => {
|
|
|
3778
3812
|
const res = await fetch("/api/sessions", {
|
|
3779
3813
|
method: "POST",
|
|
3780
3814
|
headers: { "Content-Type": "application/json" },
|
|
3781
|
-
body: JSON.stringify({ name, source }),
|
|
3815
|
+
body: JSON.stringify({ name, source, agent_profile: agentProfile || undefined }),
|
|
3782
3816
|
});
|
|
3783
3817
|
const data = await res.json();
|
|
3784
3818
|
if (!res.ok) throw new Error(data.error || "failed to create session");
|
|
@@ -4908,11 +4942,11 @@ const Sessions = (() => {
|
|
|
4908
4942
|
if (Clacky.Workspace) Clacky.Workspace.onSession(s);
|
|
4909
4943
|
if (!s) {
|
|
4910
4944
|
// Hide all spans when no session. Fields that own a static caret (dir,
|
|
4911
|
-
//
|
|
4945
|
+
// mode) keep their markup and only blank the text node.
|
|
4912
4946
|
["sib-id", "sib-status", "sib-model", "sib-cost"].forEach(id => {
|
|
4913
4947
|
const el = $(id); if (el) el.textContent = "";
|
|
4914
4948
|
});
|
|
4915
|
-
["sib-dir-text", "sib-
|
|
4949
|
+
["sib-dir-text", "sib-mode-text"].forEach(id => {
|
|
4916
4950
|
const el = $(id); if (el) el.textContent = "";
|
|
4917
4951
|
});
|
|
4918
4952
|
const sibIdEl = $("sib-id");
|
|
@@ -5002,12 +5036,20 @@ const Sessions = (() => {
|
|
|
5002
5036
|
: (s.model || "");
|
|
5003
5037
|
// Same vendor badge as the dropdown rows, so the bar reads as the
|
|
5004
5038
|
// same object the user just picked from.
|
|
5039
|
+
// Reasoning rides inside the model pill as a small tag; its control
|
|
5040
|
+
// lives in the model dropdown. Models with no reasoning control get
|
|
5041
|
+
// no stops and therefore no tag.
|
|
5042
|
+
const eff = (s.reasoning_effort || "off").toLowerCase();
|
|
5043
|
+
const rsnLevels = Array.isArray(s.reasoning_levels) ? s.reasoning_levels : [];
|
|
5005
5044
|
sibModel.textContent = "";
|
|
5006
5045
|
if (display) {
|
|
5007
5046
|
sibModel.appendChild(ModelPicker.vendorBadge(display));
|
|
5008
5047
|
sibModel.appendChild(document.createTextNode(display));
|
|
5048
|
+
if (rsnLevels.length > 1) sibModel.appendChild(ModelPicker.reasoningChip(rsnLevels, eff));
|
|
5009
5049
|
sibModel.appendChild(ModelPicker.caret());
|
|
5010
5050
|
}
|
|
5051
|
+
sibModel.dataset.reasoningEffort = eff;
|
|
5052
|
+
sibModel.dataset.reasoningLevels = JSON.stringify(rsnLevels);
|
|
5011
5053
|
sibModel.dataset.sessionId = s.id;
|
|
5012
5054
|
if (s.model_id) {
|
|
5013
5055
|
sibModel.dataset.modelId = s.model_id;
|
|
@@ -5026,17 +5068,6 @@ const Sessions = (() => {
|
|
|
5026
5068
|
}
|
|
5027
5069
|
if (sibModelWrap) sibModelWrap.style.display = s.model ? "" : "none";
|
|
5028
5070
|
|
|
5029
|
-
const sibReasoning = $("sib-reasoning");
|
|
5030
|
-
const sibReasoningWrap = $("sib-reasoning-wrap");
|
|
5031
|
-
if (sibReasoning) {
|
|
5032
|
-
const eff = (s.reasoning_effort || "off").toLowerCase();
|
|
5033
|
-
const sibReasoningText = $("sib-reasoning-text");
|
|
5034
|
-
if (sibReasoningText) sibReasoningText.textContent = I18n.t(`sib.reasoning.${eff}`);
|
|
5035
|
-
sibReasoning.dataset.sessionId = s.id;
|
|
5036
|
-
sibReasoning.dataset.reasoningEffort = eff;
|
|
5037
|
-
}
|
|
5038
|
-
if (sibReasoningWrap) sibReasoningWrap.style.display = "";
|
|
5039
|
-
|
|
5040
5071
|
// Latency signal — read from s.latest_latency (populated by:
|
|
5041
5072
|
// - HTTP /api/sessions → session_registry#list (from agent.latest_latency)
|
|
5042
5073
|
// - WS session_update events patched by app.js
|
|
@@ -5664,7 +5695,10 @@ const Sessions = (() => {
|
|
|
5664
5695
|
}
|
|
5665
5696
|
}
|
|
5666
5697
|
if (parts.length === 0) return displayText;
|
|
5667
|
-
|
|
5698
|
+
// Server-provided labels often end in their own ellipsis ("正在执行命令...");
|
|
5699
|
+
// appending another one renders "…… (3s)".
|
|
5700
|
+
const label = displayText.replace(/(?:\.{2,}|…)\s*$/, "");
|
|
5701
|
+
return `${label}… (${parts.join(" · ")})`;
|
|
5668
5702
|
},
|
|
5669
5703
|
|
|
5670
5704
|
// Build the display label for a given progress type (pure — no side effects).
|
|
@@ -6191,13 +6225,24 @@ const Sessions = (() => {
|
|
|
6191
6225
|
const caretEl = e.target.closest("#sib-model .sib-caret");
|
|
6192
6226
|
if (modelEl) {
|
|
6193
6227
|
e.stopPropagation();
|
|
6194
|
-
if (modelEl.classList.contains("sib-model-disabled")) return;
|
|
6195
6228
|
|
|
6196
6229
|
if (_isOpen) {
|
|
6197
6230
|
_closeModelDropdown();
|
|
6198
6231
|
return;
|
|
6199
6232
|
}
|
|
6200
6233
|
|
|
6234
|
+
// A running session cannot switch models (the server answers 409), but
|
|
6235
|
+
// reasoning effort still applies from the next call, so a busy pill opens
|
|
6236
|
+
// the reasoning card on its own.
|
|
6237
|
+
if (modelEl.classList.contains("sib-model-disabled")) {
|
|
6238
|
+
const reasoning = _reasoningOpts(modelEl.dataset.sessionId);
|
|
6239
|
+
if (!reasoning || reasoning.levels.length < 2) return;
|
|
6240
|
+
_openDropdownAt(modelEl, (dropdown) => {
|
|
6241
|
+
ModelPicker.populate(dropdown, { models: [], currentId: null, onSelect: () => {}, reasoning });
|
|
6242
|
+
});
|
|
6243
|
+
return;
|
|
6244
|
+
}
|
|
6245
|
+
|
|
6201
6246
|
if (caretEl) {
|
|
6202
6247
|
const subInfo = _sibSubInfo(modelEl);
|
|
6203
6248
|
// Models on custom endpoints expose no sibling variants; without this
|
|
@@ -6214,20 +6259,8 @@ const Sessions = (() => {
|
|
|
6214
6259
|
}
|
|
6215
6260
|
}
|
|
6216
6261
|
|
|
6217
|
-
|
|
6218
|
-
|
|
6219
|
-
|
|
6220
|
-
await _populateModelDropdown(modelEl.dataset.sessionId, modelEl.dataset.modelId || null, _sibSubInfo(modelEl));
|
|
6221
|
-
|
|
6222
|
-
// Calculate position relative to the model element (fixed positioning)
|
|
6223
|
-
const rect = modelEl.getBoundingClientRect();
|
|
6224
|
-
dropdown.style.left = `${rect.left + rect.width / 2}px`;
|
|
6225
|
-
dropdown.style.top = `${rect.top - 6}px`; // 6px above the element
|
|
6226
|
-
dropdown.style.transform = "translate(-50%, -100%)"; // Center horizontally, move up by its own height
|
|
6227
|
-
|
|
6228
|
-
dropdown.style.display = "block";
|
|
6229
|
-
_isOpen = true;
|
|
6230
|
-
modelEl.classList.add("is-open");
|
|
6262
|
+
await _openDropdownAt(modelEl, () =>
|
|
6263
|
+
_populateModelDropdown(modelEl.dataset.sessionId, modelEl.dataset.modelId || null, _sibSubInfo(modelEl)));
|
|
6231
6264
|
return;
|
|
6232
6265
|
}
|
|
6233
6266
|
|
|
@@ -6237,6 +6270,21 @@ const Sessions = (() => {
|
|
|
6237
6270
|
}
|
|
6238
6271
|
});
|
|
6239
6272
|
|
|
6273
|
+
// Fill the dropdown, then pin it above the pill (fixed positioning,
|
|
6274
|
+
// centered, 6px gap).
|
|
6275
|
+
async function _openDropdownAt(modelEl, fill) {
|
|
6276
|
+
const dropdown = $("sib-model-dropdown");
|
|
6277
|
+
if (!dropdown) return;
|
|
6278
|
+
await fill(dropdown);
|
|
6279
|
+
const rect = modelEl.getBoundingClientRect();
|
|
6280
|
+
dropdown.style.left = `${rect.left + rect.width / 2}px`;
|
|
6281
|
+
dropdown.style.top = `${rect.top - 6}px`;
|
|
6282
|
+
dropdown.style.transform = "translate(-50%, -100%)";
|
|
6283
|
+
dropdown.style.display = "block";
|
|
6284
|
+
_isOpen = true;
|
|
6285
|
+
modelEl.classList.add("is-open");
|
|
6286
|
+
}
|
|
6287
|
+
|
|
6240
6288
|
function _sibSubInfo(modelEl) {
|
|
6241
6289
|
let options = [];
|
|
6242
6290
|
try { options = JSON.parse(modelEl.dataset.subModelOptions || "[]"); } catch (_) {}
|
|
@@ -6247,6 +6295,40 @@ const Sessions = (() => {
|
|
|
6247
6295
|
};
|
|
6248
6296
|
}
|
|
6249
6297
|
|
|
6298
|
+
// The reasoning card follows the model the session actually runs on (a
|
|
6299
|
+
// sub-model can belong to a different family than its card), so its stops
|
|
6300
|
+
// come from the session payload mirrored on the pill, not the catalog row.
|
|
6301
|
+
function _reasoningOpts(sessionId) {
|
|
6302
|
+
const pill = $("sib-model");
|
|
6303
|
+
if (!pill) return null;
|
|
6304
|
+
let levels = [];
|
|
6305
|
+
try { levels = JSON.parse(pill.dataset.reasoningLevels || "[]"); } catch (_) {}
|
|
6306
|
+
return {
|
|
6307
|
+
levels,
|
|
6308
|
+
current: pill.dataset.reasoningEffort || "off",
|
|
6309
|
+
onChange: (level) => _switchReasoning(sessionId, level),
|
|
6310
|
+
};
|
|
6311
|
+
}
|
|
6312
|
+
|
|
6313
|
+
// Resolves to the level the server stored (it may snap to a reachable stop),
|
|
6314
|
+
// or false so the card can roll back. The pill is redrawn by the session
|
|
6315
|
+
// broadcast, so nothing else is patched here.
|
|
6316
|
+
async function _switchReasoning(sessionId, level) {
|
|
6317
|
+
try {
|
|
6318
|
+
const res = await fetch(`/api/sessions/${sessionId}/reasoning_effort`, {
|
|
6319
|
+
method: "PATCH",
|
|
6320
|
+
headers: { "Content-Type": "application/json" },
|
|
6321
|
+
body: JSON.stringify({ reasoning_effort: level })
|
|
6322
|
+
});
|
|
6323
|
+
const data = await res.json();
|
|
6324
|
+
if (!res.ok) throw new Error(data.error || "Unknown error");
|
|
6325
|
+
return data.reasoning_effort || level;
|
|
6326
|
+
} catch (e) {
|
|
6327
|
+
console.error("Failed to switch reasoning effort:", e);
|
|
6328
|
+
return false;
|
|
6329
|
+
}
|
|
6330
|
+
}
|
|
6331
|
+
|
|
6250
6332
|
// Populate dropdown with available models
|
|
6251
6333
|
async function _populateModelDropdown(sessionId, currentModelId, subInfo) {
|
|
6252
6334
|
subInfo = subInfo || { options: [], current: null, cardModel: null };
|
|
@@ -6272,9 +6354,8 @@ const Sessions = (() => {
|
|
|
6272
6354
|
onSelect: (m) => _switchModel(sessionId, m.id, m.model),
|
|
6273
6355
|
onSwitchSubModel: (name, displayName) => _switchSubModel(sessionId, name, displayName),
|
|
6274
6356
|
onSwitchRowSubModel: (m, name, displayName) => _switchModelAndSubModel(sessionId, m, name, displayName),
|
|
6275
|
-
onBenchmark: () => _benchmarkSession(sessionId),
|
|
6276
|
-
onAddModel: _goAddModel,
|
|
6277
6357
|
onConfigureMedia: _goConfigureMedia,
|
|
6358
|
+
reasoning: _reasoningOpts(sessionId),
|
|
6278
6359
|
});
|
|
6279
6360
|
} catch (e) {
|
|
6280
6361
|
console.error("Failed to load models:", e);
|
|
@@ -6282,15 +6363,6 @@ const Sessions = (() => {
|
|
|
6282
6363
|
}
|
|
6283
6364
|
}
|
|
6284
6365
|
|
|
6285
|
-
// Fetch benchmark results for a session. The benchmark UI (pending markers,
|
|
6286
|
-
// latency cells) lives in ModelPicker; this only supplies the request.
|
|
6287
|
-
async function _benchmarkSession(sessionId) {
|
|
6288
|
-
const res = await fetch(`/api/sessions/${sessionId}/benchmark`, { method: "POST" });
|
|
6289
|
-
const data = await res.json();
|
|
6290
|
-
if (!res.ok || !data.ok) throw new Error(data.error || "benchmark failed");
|
|
6291
|
-
return data.results;
|
|
6292
|
-
}
|
|
6293
|
-
|
|
6294
6366
|
// Switch the session's current card. modelId is the stable runtime id,
|
|
6295
6367
|
// modelName is for optimistic display.
|
|
6296
6368
|
async function _switchModel(sessionId, modelId, modelName) {
|
|
@@ -6367,13 +6439,6 @@ const Sessions = (() => {
|
|
|
6367
6439
|
await _switchSubModel(sessionId, modelName, displayName);
|
|
6368
6440
|
}
|
|
6369
6441
|
|
|
6370
|
-
// The picker only lists models that are already configured, so this is the
|
|
6371
|
-
// way out when the wanted one is missing.
|
|
6372
|
-
function _goAddModel() {
|
|
6373
|
-
_closeModelDropdown();
|
|
6374
|
-
if (typeof Router !== "undefined") Router.navigate("settings", { tab: "models" });
|
|
6375
|
-
}
|
|
6376
|
-
|
|
6377
6442
|
// Navigate to media config.
|
|
6378
6443
|
function _goConfigureMedia() {
|
|
6379
6444
|
_closeModelDropdown();
|
|
@@ -7457,105 +7522,6 @@ const Sessions = (() => {
|
|
|
7457
7522
|
|
|
7458
7523
|
})();
|
|
7459
7524
|
|
|
7460
|
-
// ── Session Info Bar Reasoning Effort Switcher ────────────────────────────
|
|
7461
|
-
(function() {
|
|
7462
|
-
let _isOpen = false;
|
|
7463
|
-
const LEVELS = ["off", "low", "medium", "high", "xhigh", "max"];
|
|
7464
|
-
|
|
7465
|
-
document.addEventListener("click", async (e) => {
|
|
7466
|
-
const el = e.target.closest("#sib-reasoning");
|
|
7467
|
-
if (el) {
|
|
7468
|
-
e.stopPropagation();
|
|
7469
|
-
const dropdown = $("sib-reasoning-dropdown");
|
|
7470
|
-
if (!dropdown) return;
|
|
7471
|
-
|
|
7472
|
-
if (_isOpen) {
|
|
7473
|
-
dropdown.style.display = "none";
|
|
7474
|
-
_isOpen = false;
|
|
7475
|
-
el.classList.remove("is-open");
|
|
7476
|
-
return;
|
|
7477
|
-
}
|
|
7478
|
-
|
|
7479
|
-
_populate(dropdown, el.dataset.sessionId, el.dataset.reasoningEffort || "off");
|
|
7480
|
-
|
|
7481
|
-
const rect = el.getBoundingClientRect();
|
|
7482
|
-
dropdown.style.left = `${rect.left + rect.width / 2}px`;
|
|
7483
|
-
dropdown.style.top = `${rect.top - 6}px`;
|
|
7484
|
-
dropdown.style.transform = "translate(-50%, -100%)";
|
|
7485
|
-
dropdown.style.display = "block";
|
|
7486
|
-
_isOpen = true;
|
|
7487
|
-
el.classList.add("is-open");
|
|
7488
|
-
return;
|
|
7489
|
-
}
|
|
7490
|
-
|
|
7491
|
-
if (_isOpen && !e.target.closest("#sib-reasoning-dropdown")) {
|
|
7492
|
-
const dropdown = $("sib-reasoning-dropdown");
|
|
7493
|
-
if (dropdown) dropdown.style.display = "none";
|
|
7494
|
-
const el = $("sib-reasoning");
|
|
7495
|
-
if (el) el.classList.remove("is-open");
|
|
7496
|
-
_isOpen = false;
|
|
7497
|
-
}
|
|
7498
|
-
});
|
|
7499
|
-
|
|
7500
|
-
function _populate(dropdown, sessionId, current) {
|
|
7501
|
-
dropdown.innerHTML = "";
|
|
7502
|
-
|
|
7503
|
-
const header = document.createElement("div");
|
|
7504
|
-
header.className = "sib-reasoning-header";
|
|
7505
|
-
const heading = document.createElement("div");
|
|
7506
|
-
heading.className = "sib-reasoning-heading";
|
|
7507
|
-
heading.textContent = I18n.t("sib.reasoning.heading");
|
|
7508
|
-
const hint = document.createElement("div");
|
|
7509
|
-
hint.className = "sib-reasoning-hint";
|
|
7510
|
-
hint.textContent = I18n.t("sib.reasoning.hint");
|
|
7511
|
-
header.appendChild(heading);
|
|
7512
|
-
header.appendChild(hint);
|
|
7513
|
-
dropdown.appendChild(header);
|
|
7514
|
-
|
|
7515
|
-
LEVELS.forEach(level => {
|
|
7516
|
-
const opt = document.createElement("div");
|
|
7517
|
-
opt.className = "sib-reasoning-option";
|
|
7518
|
-
if (level === current) opt.classList.add("current");
|
|
7519
|
-
|
|
7520
|
-
const label = document.createElement("span");
|
|
7521
|
-
label.className = "sib-reasoning-name";
|
|
7522
|
-
label.textContent = I18n.t(`sib.reasoning.${level}`);
|
|
7523
|
-
opt.appendChild(label);
|
|
7524
|
-
|
|
7525
|
-
opt.addEventListener("click", () => _switch(sessionId, level));
|
|
7526
|
-
dropdown.appendChild(opt);
|
|
7527
|
-
});
|
|
7528
|
-
}
|
|
7529
|
-
|
|
7530
|
-
async function _switch(sessionId, level) {
|
|
7531
|
-
const dropdown = $("sib-reasoning-dropdown");
|
|
7532
|
-
if (dropdown) {
|
|
7533
|
-
dropdown.style.display = "none";
|
|
7534
|
-
_isOpen = false;
|
|
7535
|
-
}
|
|
7536
|
-
const sibReasoningEl = $("sib-reasoning");
|
|
7537
|
-
if (sibReasoningEl) sibReasoningEl.classList.remove("is-open");
|
|
7538
|
-
|
|
7539
|
-
try {
|
|
7540
|
-
const res = await fetch(`/api/sessions/${sessionId}/reasoning_effort`, {
|
|
7541
|
-
method: "PATCH",
|
|
7542
|
-
headers: { "Content-Type": "application/json" },
|
|
7543
|
-
body: JSON.stringify({ reasoning_effort: level })
|
|
7544
|
-
});
|
|
7545
|
-
const data = await res.json();
|
|
7546
|
-
if (!res.ok) throw new Error(data.error || "Unknown error");
|
|
7547
|
-
|
|
7548
|
-
const textEl = $("sib-reasoning-text");
|
|
7549
|
-
if (textEl) textEl.textContent = I18n.t(`sib.reasoning.${level}`);
|
|
7550
|
-
const sibReasoningEl = $("sib-reasoning");
|
|
7551
|
-
if (sibReasoningEl) sibReasoningEl.dataset.reasoningEffort = level;
|
|
7552
|
-
} catch (e) {
|
|
7553
|
-
console.error("Failed to switch reasoning effort:", e);
|
|
7554
|
-
alert("Failed to switch reasoning effort: " + e.message);
|
|
7555
|
-
}
|
|
7556
|
-
}
|
|
7557
|
-
})();
|
|
7558
|
-
|
|
7559
7525
|
document.addEventListener("langchange", () => {
|
|
7560
7526
|
if (Sessions._lastSession) Sessions.updateInfoBar(Sessions._lastSession);
|
|
7561
7527
|
Sessions._renderTodoPanel();
|