dsh-ws-recency 0.30.1 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -2
- package/client.js +1017 -242
- package/index.js +259 -14
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -49,6 +49,12 @@
|
|
|
49
49
|
var NS = "ws-recency";
|
|
50
50
|
var h = react.createElement;
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Master switch for the search feature: its panel icon and the page behind
|
|
54
|
+
* it. Off leaves the plugin present but registers no search side at all.
|
|
55
|
+
*/
|
|
56
|
+
var SEARCH_ENABLED = true;
|
|
57
|
+
|
|
52
58
|
var HEADER_PREFIX = "workspace:";
|
|
53
59
|
var SESSION_PREFIX = "session:";
|
|
54
60
|
var SECTION_TOKEN = "_groupSection";
|
|
@@ -352,6 +358,20 @@
|
|
|
352
358
|
'[' + STATE_ATTR + '="followup"] [class*="_title"]{color:#d99a2b}',
|
|
353
359
|
'[' + STATE_ATTR + '="waiting"] [class*="_title"]{color:#d99a2b}',
|
|
354
360
|
".wsr-search-bar{display:flex;gap:8px;align-items:center}",
|
|
361
|
+
".wsr-hit-actions{display:flex;gap:6px;justify-content:flex-end;margin-top:2px}",
|
|
362
|
+
".wsr-hit-context-toggle,.wsr-hit-context-jump{border:.5px solid var(--dsw-alias-border-l2,rgba(255,255,255,.14));background:0 0;color:var(--dsw-alias-label-tertiary);font:inherit;font-size:11px;line-height:18px;padding:0 8px;border-radius:9px;cursor:pointer}",
|
|
363
|
+
".wsr-hit-context-toggle:hover,.wsr-hit-context-jump:hover{color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-border-l3,rgba(255,255,255,.24))}",
|
|
364
|
+
".wsr-hit-context{max-height:38vh;overflow:auto;margin-top:4px;padding:6px 8px;border-radius:6px;background:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.04));color:var(--dsw-alias-label-secondary);font-size:11px;line-height:1.65;white-space:pre-wrap;word-break:break-word}",
|
|
365
|
+
".wsr-search-hint{font-size:11px;line-height:1.5;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums}",
|
|
366
|
+
".wsr-search-history{display:flex;align-items:center;flex-wrap:wrap;gap:6px;font-size:11px;color:var(--dsw-alias-label-tertiary)}",
|
|
367
|
+
".wsr-search-history-label{flex:none}",
|
|
368
|
+
".wsr-search-chip{display:inline-flex;align-items:center;border-radius:9px;background:var(--dsw-alias-bg-layer-3,rgba(255,255,255,.07));overflow:hidden}",
|
|
369
|
+
".wsr-search-chip-run{border:none;background:0 0;color:var(--dsw-alias-label-secondary);font:inherit;font-size:11px;line-height:18px;padding:0 4px 0 8px;cursor:pointer;max-width:220px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
|
370
|
+
".wsr-search-chip-run:hover{color:var(--dsw-alias-label-primary)}",
|
|
371
|
+
".wsr-search-chip-drop{border:none;background:0 0;color:var(--dsw-alias-label-tertiary);font:inherit;font-size:12px;line-height:18px;padding:0 7px 0 2px;cursor:pointer}",
|
|
372
|
+
".wsr-search-chip-drop:hover{color:var(--dsw-alias-state-error-primary,#d9534f)}",
|
|
373
|
+
".wsr-search-history-clear{border:none;background:0 0;color:var(--dsw-alias-label-tertiary);font:inherit;font-size:11px;cursor:pointer;text-decoration:underline;padding:0 2px}",
|
|
374
|
+
".wsr-search-history-clear:hover{color:var(--dsw-alias-label-primary)}",
|
|
355
375
|
".wsr-search-input{flex:1;min-width:0;height:30px;padding:0 10px;border-radius:6px;border:.5px solid var(--dsw-alias-border-l2);background:transparent;color:inherit;font-size:13px}",
|
|
356
376
|
".wsr-hit{display:flex;flex-direction:column;gap:4px;padding:8px 10px;border-radius:8px;cursor:pointer}",
|
|
357
377
|
".wsr-hit:hover{background:var(--dsw-alias-bg-layer-2)}",
|
|
@@ -363,6 +383,13 @@
|
|
|
363
383
|
".wsr-hit-ws{flex:none;max-width:30%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
|
364
384
|
".wsr-hit-turn{flex:none}",
|
|
365
385
|
".wsr-hit-snippet{font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary);word-break:break-word}",
|
|
386
|
+
".wsr-hit-meta{display:flex;align-items:center;gap:8px;font-size:11px;color:var(--dsw-alias-label-tertiary)}",
|
|
387
|
+
".wsr-hit-time{flex:none;font-variant-numeric:tabular-nums}",
|
|
388
|
+
".wsr-hit-step{flex:none;color:var(--dsw-alias-label-secondary)}",
|
|
389
|
+
".wsr-jump-toast{position:fixed;left:50%;bottom:28px;transform:translateX(-50%);z-index:9999;padding:6px 12px;border-radius:8px;font-size:12px;background:var(--dsw-alias-bg-layer-3,rgba(32,34,38,.96));color:var(--dsw-alias-label-primary);border:.5px solid var(--dsw-alias-border-l2,rgba(255,255,255,.14));box-shadow:0 8px 24px rgba(0,0,0,.4);pointer-events:none}",
|
|
390
|
+
".wsr-diagnose-toast{max-width:min(680px,90vw);white-space:normal;line-height:1.6;text-align:left;font-variant-numeric:tabular-nums}",
|
|
391
|
+
".wsr-jump-toast-warn{border-color:color-mix(in srgb,var(--dsw-alias-state-error-primary,#d9534f) 45%,transparent);color:var(--dsw-alias-state-error-primary,#d9534f)}",
|
|
392
|
+
".wsr-hit-cwd{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;direction:rtl;text-align:left}",
|
|
366
393
|
".wsr-mark{background:rgba(79,142,247,.28);color:inherit;border-radius:2px}",
|
|
367
394
|
'[data-wsr-flash="true"]{outline:2px solid #4f8ef7;outline-offset:2px;border-radius:8px}',
|
|
368
395
|
".wsr-dot{display:block;width:7px;height:7px;border-radius:50%;margin:0 auto;background:#d99a2b;cursor:pointer}",
|
|
@@ -479,6 +506,23 @@
|
|
|
479
506
|
"search.you": "你",
|
|
480
507
|
"search.assistant": "助手",
|
|
481
508
|
"search.turn": "第 {n} 轮",
|
|
509
|
+
"search.pluginCost": "插件 {ms}ms",
|
|
510
|
+
"menu.diagnose": "插件耗时诊断",
|
|
511
|
+
"diagnose.report": "近 60 秒:扫描 {passes} 次 / 共 {total}ms / 最慢 {worst}ms · 页面节点 {nodes} · 已挂载轮次 {turns}",
|
|
512
|
+
"search.contextShow": "看上下文",
|
|
513
|
+
"search.contextHide": "收起",
|
|
514
|
+
"search.openSession": "打开会话",
|
|
515
|
+
"search.hint": "空格=都要有 · \"词组\" · a|b 或 · -排除 · ws:工作区 · in:会话 · role:user",
|
|
516
|
+
"search.history": "最近搜索",
|
|
517
|
+
"search.historyRun": "再搜一次:{query}",
|
|
518
|
+
"search.historyDrop": "从历史里删除",
|
|
519
|
+
"search.historyClear": "清空",
|
|
520
|
+
"search.step": "第 {n} 步",
|
|
521
|
+
"search.jumpTurn": "已定位:第 {turn} 轮 · 按轮次",
|
|
522
|
+
"search.jumpText": "已定位:第 {turn} 轮 · 按文字",
|
|
523
|
+
"search.jumpNoSession": "打不开这个会话(可能已归档、或不在当前工作区)",
|
|
524
|
+
"search.jumpNoTurn": "会话已打开,但没找到第 {turn} 轮(共 {turns} 轮)",
|
|
525
|
+
"search.jumpCollapsed": "找到了第 {turn} 轮,但这一轮的历史内容没有被渲染(长会话的旧轮次是折叠的),请手动向上翻一点",
|
|
482
526
|
"ui.reload": "刷新界面",
|
|
483
527
|
"ui.refresh": "刷新列表",
|
|
484
528
|
"trash.title": "回收站",
|
|
@@ -536,6 +580,10 @@
|
|
|
536
580
|
"stats.argModeNote": "当前把工具参数计入主 agent:每个工具只算返回结果,表格里「参数」列显示为淡色(那些 token 记在主 agent 那一行)。",
|
|
537
581
|
"stats.amplified.title": "放大成本(账单归因)",
|
|
538
582
|
"stats.amplified.kindTitle": "账单构成",
|
|
583
|
+
"stats.amplified.repeatTitle": "重复读取合计",
|
|
584
|
+
"stats.amplified.repeatMeta": "{count} 次 · 合计 {tokens}",
|
|
585
|
+
"stats.amplified.repeatTitle": "Repeated reads",
|
|
586
|
+
"stats.amplified.repeatMeta": "{count} times · {tokens} total",
|
|
539
587
|
"stats.amplified.lead": "按「内容大小 × 之后重读次数」排序:一块内容读进来一次,之后每一步都会再发一遍,乘上重读次数才是它真正的开销。上面的分布统计只算内容本身多大,两个数不能直接比。",
|
|
540
588
|
"stats.amplified.summary": "账单 {bill} token;可归因内容经重读放大后占 {share}({attributed})",
|
|
541
589
|
"stats.amplified.contextCaption": "每步上下文(面积≈账单):一步=一次模型调用,越早进入的内容被重读越多",
|
|
@@ -664,6 +712,23 @@
|
|
|
664
712
|
"search.you": "You",
|
|
665
713
|
"search.assistant": "Assistant",
|
|
666
714
|
"search.turn": "turn {n}",
|
|
715
|
+
"search.pluginCost": "plugin {ms}ms",
|
|
716
|
+
"menu.diagnose": "Plugin cost",
|
|
717
|
+
"diagnose.report": "Last 60s: {passes} passes / {total}ms total / {worst}ms worst · {nodes} nodes · {turns} turns mounted",
|
|
718
|
+
"search.contextShow": "Show context",
|
|
719
|
+
"search.contextHide": "Hide",
|
|
720
|
+
"search.openSession": "Open session",
|
|
721
|
+
"search.hint": "space = all of them · \"phrase\" · a|b either · -exclude · ws:workspace · in:session · role:user",
|
|
722
|
+
"search.history": "Recent",
|
|
723
|
+
"search.historyRun": "Search again: {query}",
|
|
724
|
+
"search.historyDrop": "Remove from history",
|
|
725
|
+
"search.historyClear": "Clear",
|
|
726
|
+
"search.step": "step {n}",
|
|
727
|
+
"search.jumpTurn": "Landed on turn {turn} (by turn)",
|
|
728
|
+
"search.jumpText": "Landed on turn {turn} (by text)",
|
|
729
|
+
"search.jumpNoSession": "Could not open that session (archived, or outside the current workspace)",
|
|
730
|
+
"search.jumpNoTurn": "Session opened, but turn {turn} was not found (of {turns})",
|
|
731
|
+
"search.jumpCollapsed": "Turn {turn} was found, but its history is not rendered (old turns of a long session are collapsed); scroll up a little",
|
|
667
732
|
"ui.reload": "Reload UI",
|
|
668
733
|
"ui.refresh": "Refresh",
|
|
669
734
|
"trash.title": "Trash",
|
|
@@ -779,7 +844,62 @@
|
|
|
779
844
|
return text;
|
|
780
845
|
}
|
|
781
846
|
|
|
782
|
-
|
|
847
|
+
/**
|
|
848
|
+
* Whether a mutated node belongs to the conversation, not the sidebar.
|
|
849
|
+
*
|
|
850
|
+
* The observer used to watch the whole body, so a chat that mounts a page
|
|
851
|
+
* of history - thousands of nodes - ran this plugin's sidebar pass over and
|
|
852
|
+
* over while the host was rendering, and that is what made a jump into a
|
|
853
|
+
* long session feel frozen. Nothing here decorates the chat, so its
|
|
854
|
+
* mutations are none of this observer's business.
|
|
855
|
+
*/
|
|
856
|
+
/**
|
|
857
|
+
* The sidebar's own containers, as a set of ancestors of a workspace row.
|
|
858
|
+
*
|
|
859
|
+
* Filtering by "is the chat in this node" was not enough: the turn rail and
|
|
860
|
+
* the host's hover preview are portalled onto <body>, outside the chat, so
|
|
861
|
+
* moving the pointer along the rail ran this plugin's sidebar pass on every
|
|
862
|
+
* preview repaint - which is exactly the delay felt after a long jump. The
|
|
863
|
+
* sidebar is a sibling subtree, and only its containers can hold a row.
|
|
864
|
+
*/
|
|
865
|
+
var sidebarAncestors = null;
|
|
866
|
+
|
|
867
|
+
function sidebarChain() {
|
|
868
|
+
if (sidebarAncestors !== null && sidebarAncestors.size > 0) {
|
|
869
|
+
/* Revalidate cheaply: a stale set would stop noticing real changes. */
|
|
870
|
+
var alive = 0;
|
|
871
|
+
sidebarAncestors.forEach(function (node) {
|
|
872
|
+
if (node.isConnected !== false) alive += 1;
|
|
873
|
+
});
|
|
874
|
+
if (alive > 0) return sidebarAncestors;
|
|
875
|
+
}
|
|
876
|
+
var set = new Set();
|
|
877
|
+
var header = document.querySelector('[data-row-key^="' + HEADER_PREFIX + '"]');
|
|
878
|
+
if (header === null || header === undefined) return set;
|
|
879
|
+
var node = header.parentElement;
|
|
880
|
+
while (node !== null && node !== undefined && node.parentElement !== null
|
|
881
|
+
&& node.parentElement !== undefined && node.parentElement !== document.body) {
|
|
882
|
+
set.add(node);
|
|
883
|
+
node = node.parentElement;
|
|
884
|
+
}
|
|
885
|
+
sidebarAncestors = set;
|
|
886
|
+
return set;
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
function outsideSidebar(node, chain) {
|
|
890
|
+
if (node === null || node === undefined) return false;
|
|
891
|
+
var element = node;
|
|
892
|
+
if (element.nodeType !== 1) element = element.parentElement;
|
|
893
|
+
if (element === null || element === undefined) return false;
|
|
894
|
+
var containers = chain === undefined || chain === null ? sidebarChain() : chain;
|
|
895
|
+
var current = element;
|
|
896
|
+
while (current !== null && current !== undefined) {
|
|
897
|
+
if (containers.has(current)) return false;
|
|
898
|
+
if (current === document.body) return true;
|
|
899
|
+
current = current.parentElement;
|
|
900
|
+
}
|
|
901
|
+
return true;
|
|
902
|
+
} function top() {
|
|
783
903
|
return typeof document !== "undefined" && document.body !== null ? document.body : null;
|
|
784
904
|
}
|
|
785
905
|
|
|
@@ -1055,7 +1175,20 @@
|
|
|
1055
1175
|
var hostButton = overflowButtonOf(section);
|
|
1056
1176
|
markHeader(entry.header, entry.key);
|
|
1057
1177
|
|
|
1058
|
-
|
|
1178
|
+
/* Everything this project holds is history: no session inside it is
|
|
1179
|
+
recent, so the user's expansion of the project is itself the
|
|
1180
|
+
request to see its sessions. Folding here only adds a second click
|
|
1181
|
+
for a group the user has already gone looking for. */
|
|
1182
|
+
var onlyHistory = rows.length > 0;
|
|
1183
|
+
for (var scan = 0; scan < rows.length; scan += 1) {
|
|
1184
|
+
var scannedAt = updatedAtOf(rows[scan], sessions);
|
|
1185
|
+
var covers = scannedAt === null || scannedAt >= cutoff;
|
|
1186
|
+
if (covers && !isBlankRow(rows[scan], sessions)) {
|
|
1187
|
+
onlyHistory = false;
|
|
1188
|
+
break;
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
var expanded = expandedSections.has(entry.key) || onlyHistory;
|
|
1059
1192
|
var hostHidden = hostButton === null ? 0 : labelNumber(hostButton);
|
|
1060
1193
|
var hostExpanded = hostButton !== null
|
|
1061
1194
|
&& typeof hostButton.getAttribute === "function"
|
|
@@ -1104,7 +1237,9 @@
|
|
|
1104
1237
|
folded. Expanding drives the hidden host button until nothing is left
|
|
1105
1238
|
unrendered, so one click reveals the whole group. */
|
|
1106
1239
|
var remaining = folded + hostHidden;
|
|
1107
|
-
|
|
1240
|
+
/* A project that is entirely history is open because opening it is the
|
|
1241
|
+
request; there is nothing to offer to fold back. */
|
|
1242
|
+
if (expanded && !onlyHistory) {
|
|
1108
1243
|
(function (entryKey) {
|
|
1109
1244
|
ensureToggle(section, entryKey, t("fold.hide"), function () {
|
|
1110
1245
|
expandedSections.delete(entryKey);
|
|
@@ -1719,18 +1854,66 @@
|
|
|
1719
1854
|
decorateComposerStats();
|
|
1720
1855
|
}
|
|
1721
1856
|
|
|
1857
|
+
/**
|
|
1858
|
+
* While this is in the future the sidebar pass stays off.
|
|
1859
|
+
*
|
|
1860
|
+
* Jumping to a hit in a long session makes the host mount a whole page of
|
|
1861
|
+
* history. That is thousands of DOM changes, and each one used to run this
|
|
1862
|
+
* plugin's sidebar pass on top of the host's own rendering, which is what
|
|
1863
|
+
* still froze the window even after chat mutations were filtered out.
|
|
1864
|
+
*/
|
|
1865
|
+
var suppressedUntil = 0;
|
|
1866
|
+
|
|
1867
|
+
function suspendPasses(ms) {
|
|
1868
|
+
var span = typeof ms === "number" && ms > 0 ? ms : 8000;
|
|
1869
|
+
suppressedUntil = Date.now() + span;
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1872
|
+
function passesSuspended() {
|
|
1873
|
+
return suppressedUntil !== 0 && Date.now() < suppressedUntil;
|
|
1874
|
+
}
|
|
1875
|
+
/** At most this often, whatever happens: a pass writes DOM, and writing DOM
|
|
1876
|
+
* can be observed by our own observer, so the interval is the guarantee that
|
|
1877
|
+
* a feedback loop cannot turn into a busy main thread. */
|
|
1878
|
+
var PASS_MIN_GAP = 400;
|
|
1879
|
+
var lastPassAt = 0;
|
|
1880
|
+
var passCount = 0;
|
|
1881
|
+
/* Rolling record for the diagnostic row: how often the pass runs and how
|
|
1882
|
+
long it takes, so a claim about cost can be checked on screen. */
|
|
1883
|
+
var passSamples = [];
|
|
1884
|
+
|
|
1885
|
+
function recordPass(spent) {
|
|
1886
|
+
passSamples.push({ at: Date.now(), ms: spent });
|
|
1887
|
+
if (passSamples.length > 200) passSamples.shift();
|
|
1888
|
+
}
|
|
1889
|
+
|
|
1722
1890
|
function schedule() {
|
|
1723
1891
|
if (disposed || timer !== null) return;
|
|
1892
|
+
sidebarAncestors = null;
|
|
1893
|
+
if (passesSuspended()) {
|
|
1894
|
+
/* One pass, once the host has finished mounting. */
|
|
1895
|
+
var wait = Math.max(120, suppressedUntil - Date.now() + 60);
|
|
1896
|
+
window.setTimeout(function () {
|
|
1897
|
+
if (!disposed) schedule();
|
|
1898
|
+
}, wait);
|
|
1899
|
+
return;
|
|
1900
|
+
}
|
|
1901
|
+
var since = Date.now() - lastPassAt;
|
|
1902
|
+
var delay = since >= PASS_MIN_GAP ? 60 : PASS_MIN_GAP - since + 16;
|
|
1724
1903
|
timer = window.setTimeout(function () {
|
|
1725
1904
|
timer = null;
|
|
1905
|
+
lastPassAt = Date.now();
|
|
1906
|
+
passCount += 1;
|
|
1907
|
+
var began = Date.now();
|
|
1726
1908
|
try {
|
|
1727
1909
|
apply();
|
|
1728
1910
|
} catch (error) {
|
|
1729
1911
|
console.warn("[dsh-ws-recency] pass failed:", error);
|
|
1730
1912
|
}
|
|
1731
|
-
|
|
1913
|
+
recordPass(Date.now() - began);
|
|
1914
|
+
if (typeof window !== "undefined") window.__DSH_WSR_PASSES__ = passCount;
|
|
1915
|
+
}, delay);
|
|
1732
1916
|
}
|
|
1733
|
-
|
|
1734
1917
|
/** `shell.overlay` occupant; it renders no chrome of its own. */
|
|
1735
1918
|
function Sorter(props) {
|
|
1736
1919
|
if (typeof props.useSessions === "function") {
|
|
@@ -1797,6 +1980,46 @@
|
|
|
1797
1980
|
* `<home>/.trash/ws-recency/`. The browser half only asks for confirmation
|
|
1798
1981
|
* and posts the id.
|
|
1799
1982
|
*/
|
|
1983
|
+
/**
|
|
1984
|
+
* Session menu row that reports this plugin's own cost.
|
|
1985
|
+
*
|
|
1986
|
+
* Without devtools there was no way to tell a slow plugin from a slow host,
|
|
1987
|
+
* and several rounds went into guessing. This prints the numbers where the
|
|
1988
|
+
* lag is felt. */
|
|
1989
|
+
function DiagnoseMenuItem(props) {
|
|
1990
|
+
var Item = ui.MenuItemButton;
|
|
1991
|
+
if (typeof Item !== "function") return null;
|
|
1992
|
+
return h(Item, {
|
|
1993
|
+
icon: undefined,
|
|
1994
|
+
onSelect: function () {
|
|
1995
|
+
var now = Date.now();
|
|
1996
|
+
var recent = passSamples.filter(function (sample) {
|
|
1997
|
+
return now - sample.at <= 60000;
|
|
1998
|
+
});
|
|
1999
|
+
var total = 0;
|
|
2000
|
+
var worst = 0;
|
|
2001
|
+
for (var i = 0; i < recent.length; i += 1) {
|
|
2002
|
+
total += recent[i].ms;
|
|
2003
|
+
if (recent[i].ms > worst) worst = recent[i].ms;
|
|
2004
|
+
}
|
|
2005
|
+
var nodes = typeof document !== "undefined" ? document.querySelectorAll("*").length : 0;
|
|
2006
|
+
var turns = typeof document !== "undefined" ? document.querySelectorAll("[data-chat-turn]").length : 0;
|
|
2007
|
+
var note = statsDiv("wsr-jump-toast wsr-diagnose-toast");
|
|
2008
|
+
note.textContent = t("diagnose.report", {
|
|
2009
|
+
passes: String(recent.length),
|
|
2010
|
+
total: String(total),
|
|
2011
|
+
worst: String(worst),
|
|
2012
|
+
nodes: String(nodes),
|
|
2013
|
+
turns: String(turns),
|
|
2014
|
+
});
|
|
2015
|
+
document.body.appendChild(note);
|
|
2016
|
+
window.setTimeout(function () {
|
|
2017
|
+
if (note.parentElement !== null) note.remove();
|
|
2018
|
+
}, 8000);
|
|
2019
|
+
},
|
|
2020
|
+
}, t("menu.diagnose"));
|
|
2021
|
+
}
|
|
2022
|
+
|
|
1800
2023
|
function TrashMenuItem(props) {
|
|
1801
2024
|
var Item = ui.MenuItemButton;
|
|
1802
2025
|
if (typeof Item !== "function") return null;
|
|
@@ -2110,6 +2333,28 @@
|
|
|
2110
2333
|
/** The neutral an unknown tool gets: no family, no claim of one. */
|
|
2111
2334
|
var TOOL_FAMILY_NEUTRAL = { key: "other", hue: 210 };
|
|
2112
2335
|
|
|
2336
|
+
/**
|
|
2337
|
+
* A stable hue for a tool that belongs to no family.
|
|
2338
|
+
*
|
|
2339
|
+
* Every unknown tool used to share the neutral hue, so the chart showed
|
|
2340
|
+
* several tools in one colour. A hash of the name spreads them out, and a
|
|
2341
|
+
* nudge keeps the result clear of the family hues it would otherwise
|
|
2342
|
+
* collide with.
|
|
2343
|
+
*/
|
|
2344
|
+
function hueOfUnknown(name) {
|
|
2345
|
+
var hash = 2166136261;
|
|
2346
|
+
for (var i = 0; i < name.length; i += 1) {
|
|
2347
|
+
hash ^= name.charCodeAt(i);
|
|
2348
|
+
hash = Math.imul(hash, 16777619) >>> 0;
|
|
2349
|
+
}
|
|
2350
|
+
var hue = hash % 360;
|
|
2351
|
+
for (var f = 0; f < TOOL_FAMILIES.length; f += 1) {
|
|
2352
|
+
var distance = Math.abs(hue - TOOL_FAMILIES[f].hue);
|
|
2353
|
+
if (distance < 16 || distance > 344) hue = (hue + 41) % 360;
|
|
2354
|
+
}
|
|
2355
|
+
return hue;
|
|
2356
|
+
}
|
|
2357
|
+
|
|
2113
2358
|
function toolFamily(name) {
|
|
2114
2359
|
if (typeof name !== "string" || name === "") return TOOL_FAMILY_NEUTRAL;
|
|
2115
2360
|
var key = name.toLowerCase();
|
|
@@ -2498,6 +2743,31 @@
|
|
|
2498
2743
|
list.appendChild(row);
|
|
2499
2744
|
}
|
|
2500
2745
|
ranking.appendChild(list);
|
|
2746
|
+
|
|
2747
|
+
/* Repetition is the actionable part: reading one file twice costs the
|
|
2748
|
+
same as two files, and the list above shows it as two rows. */
|
|
2749
|
+
var repeated = amplified.repeated || [];
|
|
2750
|
+
if (repeated.length > 0) {
|
|
2751
|
+
ranking.appendChild(statsDiv("wsr-amplified-subtitle", t("stats.amplified.repeatTitle")));
|
|
2752
|
+
var repeats = statsDiv("wsr-amplified-list");
|
|
2753
|
+
for (var rp = 0; rp < repeated.length; rp += 1) {
|
|
2754
|
+
var item = repeated[rp];
|
|
2755
|
+
var row = statsDiv("wsr-amplified-row");
|
|
2756
|
+
var main = statsDiv("wsr-amplified-main");
|
|
2757
|
+
main.appendChild(statsDiv("wsr-amplified-name", typeof item.detail === "string" ? item.detail : ""));
|
|
2758
|
+
main.appendChild(statsDiv("wsr-amplified-meta", t("stats.amplified.repeatMeta", {
|
|
2759
|
+
count: String(item.count),
|
|
2760
|
+
tokens: formatTokens(item.tokens),
|
|
2761
|
+
})));
|
|
2762
|
+
row.appendChild(main);
|
|
2763
|
+
var value = statsDiv("wsr-amplified-value", formatTokens(item.amplified));
|
|
2764
|
+
value.setAttribute("title", String(Math.round(Number(item.amplified) || 0)) + " tokens");
|
|
2765
|
+
row.appendChild(value);
|
|
2766
|
+
row.appendChild(statsDiv("wsr-amplified-share", formatShare(item.share || 0)));
|
|
2767
|
+
repeats.appendChild(row);
|
|
2768
|
+
}
|
|
2769
|
+
ranking.appendChild(repeats);
|
|
2770
|
+
}
|
|
2501
2771
|
return { top: section, ranking: ranking };
|
|
2502
2772
|
}
|
|
2503
2773
|
|
|
@@ -3614,149 +3884,7 @@
|
|
|
3614
3884
|
}
|
|
3615
3885
|
}
|
|
3616
3886
|
|
|
3617
|
-
|
|
3618
|
-
function openTrashPanel() {
|
|
3619
|
-
if (typeof document === "undefined") return;
|
|
3620
|
-
closeStatsPanel();
|
|
3621
|
-
var backdrop = statsDiv("wsr-modal-backdrop");
|
|
3622
|
-
var panel = statsDiv("wsr-modal");
|
|
3623
|
-
backdrop.appendChild(panel);
|
|
3624
|
-
var head = statsDiv("wsr-modal-head");
|
|
3625
|
-
head.appendChild(statsDiv("wsr-modal-title", t("trash.title")));
|
|
3626
|
-
var tools = statsDiv("wsr-modal-tools");
|
|
3627
|
-
var adopt = document.createElement("button");
|
|
3628
|
-
adopt.type = "button";
|
|
3629
|
-
adopt.className = "wsr-btn";
|
|
3630
|
-
adopt.title = t("adopt.description");
|
|
3631
|
-
adopt.textContent = t("adopt.action");
|
|
3632
|
-
tools.appendChild(adopt);
|
|
3633
|
-
var close = document.createElement("button");
|
|
3634
|
-
close.type = "button";
|
|
3635
|
-
close.className = "wsr-modal-close";
|
|
3636
|
-
close.textContent = "\u00d7";
|
|
3637
|
-
close.addEventListener("click", closeStatsPanel);
|
|
3638
|
-
tools.appendChild(close);
|
|
3639
|
-
head.appendChild(tools);
|
|
3640
|
-
panel.appendChild(head);
|
|
3641
|
-
var body = statsDiv("wsr-modal-body");
|
|
3642
|
-
panel.appendChild(body);
|
|
3643
|
-
backdrop.addEventListener("click", function (event) {
|
|
3644
|
-
if (event !== undefined && event.target === backdrop) closeStatsPanel();
|
|
3645
|
-
});
|
|
3646
|
-
document.body.appendChild(backdrop);
|
|
3647
|
-
statsModal = backdrop;
|
|
3648
|
-
document.addEventListener("keydown", onStatsKey);
|
|
3649
|
-
|
|
3650
|
-
var post = function (payload) {
|
|
3651
|
-
return fetch("/ws-recency/trash", {
|
|
3652
|
-
method: "POST",
|
|
3653
|
-
headers: { "content-type": "application/json" },
|
|
3654
|
-
body: JSON.stringify(payload),
|
|
3655
|
-
}).then(function (response) {
|
|
3656
|
-
return response.text().then(function (text) {
|
|
3657
|
-
var parsed = null;
|
|
3658
|
-
try { parsed = JSON.parse(text); } catch (error) { parsed = null; }
|
|
3659
|
-
return { status: response.status, text: text, json: parsed };
|
|
3660
|
-
});
|
|
3661
|
-
});
|
|
3662
|
-
};
|
|
3663
|
-
|
|
3664
|
-
var load = function (note) {
|
|
3665
|
-
body.textContent = t("trash.loading");
|
|
3666
|
-
post({ action: "list" }).then(function (answer) {
|
|
3667
|
-
body.textContent = "";
|
|
3668
|
-
if (note !== undefined && note !== "") {
|
|
3669
|
-
body.appendChild(statsDiv("wsr-stats-detail", note));
|
|
3670
|
-
var noteActions = statsDiv("wsr-trash-actions");
|
|
3671
|
-
noteActions.appendChild(reloadButton());
|
|
3672
|
-
body.appendChild(noteActions);
|
|
3673
|
-
}
|
|
3674
|
-
if (answer.json === null || answer.json.ok !== true) {
|
|
3675
|
-
body.appendChild(statsDiv("wsr-stats-note", t("trash.failed") + "HTTP " + answer.status + " \u00b7 " + (answer.text || "").slice(0, 120)));
|
|
3676
|
-
return;
|
|
3677
|
-
}
|
|
3678
|
-
var entries = Array.isArray(answer.json.entries) ? answer.json.entries : [];
|
|
3679
|
-
if (entries.length === 0) {
|
|
3680
|
-
body.appendChild(statsDiv("wsr-stats-note", t("trash.empty")));
|
|
3681
|
-
return;
|
|
3682
|
-
}
|
|
3683
|
-
var list = statsDiv("wsr-move-list");
|
|
3684
|
-
for (var i = 0; i < entries.length; i += 1) {
|
|
3685
|
-
(function (entry) {
|
|
3686
|
-
var row = document.createElement("div");
|
|
3687
|
-
row.className = "wsr-trash-row";
|
|
3688
|
-
var text = statsDiv("wsr-move-text");
|
|
3689
|
-
var title = entry.sessionId === null ? entry.name : entry.sessionId;
|
|
3690
|
-
text.appendChild(statsDiv("wsr-move-title", title));
|
|
3691
|
-
var meta = [];
|
|
3692
|
-
if (entry.reason === "delete") meta.push(t("trash.reason.delete"));
|
|
3693
|
-
else if (entry.reason === "move") meta.push(t("trash.reason.move"));
|
|
3694
|
-
meta.push(formatBytes(entry.sizeBytes));
|
|
3695
|
-
var when = formatWhen(entry.at);
|
|
3696
|
-
if (when !== "") meta.push(when);
|
|
3697
|
-
text.appendChild(statsDiv("wsr-move-path", meta.join(" \u00b7 ")));
|
|
3698
|
-
if (typeof entry.cwd === "string" && entry.cwd !== "") {
|
|
3699
|
-
text.appendChild(statsDiv("wsr-move-path", entry.cwd));
|
|
3700
|
-
}
|
|
3701
|
-
row.appendChild(text);
|
|
3702
|
-
|
|
3703
|
-
var actions = statsDiv("wsr-trash-actions");
|
|
3704
|
-
if (entry.restorable === true) {
|
|
3705
|
-
var restore = document.createElement("button");
|
|
3706
|
-
restore.type = "button";
|
|
3707
|
-
restore.className = "wsr-btn";
|
|
3708
|
-
restore.textContent = t("trash.restore");
|
|
3709
|
-
restore.addEventListener("click", function () {
|
|
3710
|
-
askConfirm(t("trash.confirmRestore"), function () {
|
|
3711
|
-
load(t("trash.working"));
|
|
3712
|
-
post({ action: "restore", name: entry.name }).then(function (result) {
|
|
3713
|
-
var ok = result.json !== null && result.json.ok === true;
|
|
3714
|
-
load(ok ? t("trash.restored") : t("trash.failed") + (result.json && result.json.error ? result.json.error : result.text));
|
|
3715
|
-
}).catch(function (error) {
|
|
3716
|
-
load(t("trash.failed") + (error && error.message ? error.message : error));
|
|
3717
|
-
});
|
|
3718
|
-
});
|
|
3719
|
-
});
|
|
3720
|
-
actions.appendChild(restore);
|
|
3721
|
-
}
|
|
3722
|
-
var purge = document.createElement("button");
|
|
3723
|
-
purge.type = "button";
|
|
3724
|
-
purge.className = "wsr-btn wsr-btn-danger";
|
|
3725
|
-
purge.textContent = t("trash.purge");
|
|
3726
|
-
purge.addEventListener("click", function () {
|
|
3727
|
-
askConfirm(t("trash.confirmPurge"), function () {
|
|
3728
|
-
load(t("trash.working"));
|
|
3729
|
-
post({ action: "purge", name: entry.name }).then(function (result) {
|
|
3730
|
-
var ok = result.json !== null && result.json.ok === true;
|
|
3731
|
-
load(ok ? t("trash.purged") : t("trash.failed") + (result.json && result.json.error ? result.json.error : result.text));
|
|
3732
|
-
}).catch(function (error) {
|
|
3733
|
-
load(t("trash.failed") + (error && error.message ? error.message : error));
|
|
3734
|
-
});
|
|
3735
|
-
});
|
|
3736
|
-
});
|
|
3737
|
-
actions.appendChild(purge);
|
|
3738
|
-
row.appendChild(actions);
|
|
3739
|
-
list.appendChild(row);
|
|
3740
|
-
})(entries[i]);
|
|
3741
|
-
}
|
|
3742
|
-
body.appendChild(list);
|
|
3743
|
-
body.appendChild(statsDiv("wsr-stats-note", t("trash.note")));
|
|
3744
|
-
}).catch(function (error) {
|
|
3745
|
-
body.textContent = t("trash.failed") + (error && error.message ? error.message : error);
|
|
3746
|
-
});
|
|
3747
|
-
};
|
|
3748
|
-
adopt.addEventListener("click", function () {
|
|
3749
|
-
adopt.disabled = true;
|
|
3750
|
-
adopt.textContent = t("adopt.working");
|
|
3751
|
-
adoptUnlistedSessions(function (message) {
|
|
3752
|
-
adopt.disabled = false;
|
|
3753
|
-
adopt.textContent = t("adopt.action");
|
|
3754
|
-
load(message);
|
|
3755
|
-
});
|
|
3756
|
-
});
|
|
3757
|
-
load("");
|
|
3758
|
-
}
|
|
3759
|
-
|
|
3887
|
+
|
|
3760
3888
|
/* --------------------------- trash panel page ------------------------ */
|
|
3761
3889
|
|
|
3762
3890
|
function trashPost(payload) {
|
|
@@ -3775,10 +3903,21 @@
|
|
|
3775
3903
|
|
|
3776
3904
|
/* ---------- session content search -------------------------------- */
|
|
3777
3905
|
|
|
3906
|
+
/** How many recent queries the panel remembers. */
|
|
3907
|
+
var SEARCH_HISTORY_MAX = 12;
|
|
3908
|
+
|
|
3778
3909
|
/** What the uncontrolled input holds; the panel keeps only results in state. */
|
|
3779
3910
|
var searchDraft = "";
|
|
3780
3911
|
/** Bumped per search so a slow answer cannot overwrite a newer one. */
|
|
3781
3912
|
var searchGeneration = 0;
|
|
3913
|
+
/**
|
|
3914
|
+
* The last answer, kept outside the component.
|
|
3915
|
+
*
|
|
3916
|
+
* Opening a hit switches the main view to the conversation, which unmounts
|
|
3917
|
+
* this page; without this the results were gone when the user came back
|
|
3918
|
+
* and every search had to be run again.
|
|
3919
|
+
*/
|
|
3920
|
+
var searchLast = null;
|
|
3782
3921
|
|
|
3783
3922
|
function searchPost(body) {
|
|
3784
3923
|
return fetch("/ws-recency/search", {
|
|
@@ -3801,6 +3940,39 @@
|
|
|
3801
3940
|
return h(Icon, { size: size });
|
|
3802
3941
|
}
|
|
3803
3942
|
|
|
3943
|
+
/**
|
|
3944
|
+
* Move a scroller and announce it.
|
|
3945
|
+
*
|
|
3946
|
+
* The chat pages older history in when its own scroll handler sees movement.
|
|
3947
|
+
* Assigning `scrollTop` from script does not fire that handler, so a long
|
|
3948
|
+
* session stayed at the same page no matter how often the value was set;
|
|
3949
|
+
* a synthetic scroll event is what lets the next page load.
|
|
3950
|
+
*/
|
|
3951
|
+
function scrollTo(scroller, top) {
|
|
3952
|
+
if (scroller === null || scroller === undefined) return;
|
|
3953
|
+
var target = Math.max(0, Number(top) || 0);
|
|
3954
|
+
try {
|
|
3955
|
+
scroller.scrollTop = target;
|
|
3956
|
+
} catch (error) {
|
|
3957
|
+
return;
|
|
3958
|
+
}
|
|
3959
|
+
var fire = function () {
|
|
3960
|
+
try {
|
|
3961
|
+
var event = document.createEvent("Event");
|
|
3962
|
+
event.initEvent("scroll", true, false);
|
|
3963
|
+
scroller.dispatchEvent(event);
|
|
3964
|
+
} catch (error) {
|
|
3965
|
+
/* an engine without createEvent still got the assignment */
|
|
3966
|
+
}
|
|
3967
|
+
};
|
|
3968
|
+
fire();
|
|
3969
|
+
try {
|
|
3970
|
+
if (typeof requestAnimationFrame === "function") requestAnimationFrame(fire);
|
|
3971
|
+
else window.setTimeout(fire, 16);
|
|
3972
|
+
} catch (error) {
|
|
3973
|
+
/* the first dispatch is usually enough */
|
|
3974
|
+
}
|
|
3975
|
+
}
|
|
3804
3976
|
function conversationScroller() {
|
|
3805
3977
|
if (typeof document === "undefined") return null;
|
|
3806
3978
|
try {
|
|
@@ -3823,12 +3995,60 @@
|
|
|
3823
3995
|
function turnRowOf(turn) {
|
|
3824
3996
|
if (typeof document === "undefined" || !isFinite(turn)) return null;
|
|
3825
3997
|
try {
|
|
3826
|
-
|
|
3998
|
+
/* Scoped when possible: a document-wide attribute query on a long
|
|
3999
|
+
transcript is the expensive part of a jump's polling loop. The
|
|
4000
|
+
document stays as the fallback because the scroller is not always
|
|
4001
|
+
the element that holds the rows. */
|
|
4002
|
+
var selector = '[data-chat-turn="' + String(turn) + '"]';
|
|
4003
|
+
var scope = conversationScroller();
|
|
4004
|
+
if (scope !== null && typeof scope.querySelector === "function") {
|
|
4005
|
+
var scoped = scope.querySelector(selector);
|
|
4006
|
+
if (scoped !== null && scoped !== undefined) return scoped;
|
|
4007
|
+
}
|
|
4008
|
+
return document.querySelector(selector);
|
|
3827
4009
|
} catch (error) {
|
|
3828
4010
|
return null;
|
|
3829
4011
|
}
|
|
3830
4012
|
}
|
|
3831
4013
|
|
|
4014
|
+
/** A short-lived line that says where the jump landed and how it got there. */
|
|
4015
|
+
function announceJump(hit, byText, costMs) {
|
|
4016
|
+
if (typeof document === "undefined") return;
|
|
4017
|
+
try {
|
|
4018
|
+
var note = statsDiv("wsr-jump-toast");
|
|
4019
|
+
var text = t(byText === true ? "search.jumpText" : "search.jumpTurn", { turn: String(hit.turn) });
|
|
4020
|
+
if (isFinite(Number(costMs))) text += " · " + t("search.pluginCost", { ms: String(Math.round(Number(costMs))) });
|
|
4021
|
+
note.textContent = text;
|
|
4022
|
+
document.body.appendChild(note);
|
|
4023
|
+
window.setTimeout(function () {
|
|
4024
|
+
if (note.parentElement !== null) note.remove();
|
|
4025
|
+
}, 3200);
|
|
4026
|
+
} catch (error) {
|
|
4027
|
+
/* a toast is a nicety: never break the jump for it */
|
|
4028
|
+
}
|
|
4029
|
+
}
|
|
4030
|
+
/**
|
|
4031
|
+
* Say why a jump did not land.
|
|
4032
|
+
*
|
|
4033
|
+
* Without this a failed jump is indistinguishable from a jump that landed
|
|
4034
|
+
* in the wrong place: the panel just sits where it was and the user cannot
|
|
4035
|
+
* tell whether the session opened, whether the turn exists, or whether the
|
|
4036
|
+
* text was never rendered.
|
|
4037
|
+
*/
|
|
4038
|
+
function announceJumpFailure(hit, reason) {
|
|
4039
|
+
if (typeof document === "undefined") return;
|
|
4040
|
+
try {
|
|
4041
|
+
var note = statsDiv("wsr-jump-toast wsr-jump-toast-warn");
|
|
4042
|
+
note.textContent = t(reason, { turn: String(hit.turn), turns: String(hit.turns) });
|
|
4043
|
+
document.body.appendChild(note);
|
|
4044
|
+
window.setTimeout(function () {
|
|
4045
|
+
if (note.parentElement !== null) note.remove();
|
|
4046
|
+
}, 5000);
|
|
4047
|
+
} catch (error) {
|
|
4048
|
+
/* nothing to do if the toast itself fails */
|
|
4049
|
+
}
|
|
4050
|
+
}
|
|
4051
|
+
|
|
3832
4052
|
/** Ring the row the search sent the user to, without taking keyboard focus. */
|
|
3833
4053
|
function flashTurnRow(row) {
|
|
3834
4054
|
try {
|
|
@@ -3887,9 +4107,422 @@
|
|
|
3887
4107
|
window.setTimeout(tick, 120);
|
|
3888
4108
|
}
|
|
3889
4109
|
|
|
3890
|
-
|
|
4110
|
+
/** Collapsed text of an element, for matching a message fragment. */
|
|
4111
|
+
function normalizedText(node) {
|
|
4112
|
+
var text = node !== null && node !== undefined && typeof node.textContent === "string" ? node.textContent : "";
|
|
4113
|
+
return text.replace(/\s+/g, " ").trim();
|
|
4114
|
+
}
|
|
4115
|
+
|
|
4116
|
+
/**
|
|
4117
|
+
* The smallest element in the transcript that holds this fragment.
|
|
4118
|
+
*
|
|
4119
|
+
* The conversation view renders no per-turn anchor (`data-chat-turn` does
|
|
4120
|
+
* not exist in it), so text is the only handle a jump has. The needle is
|
|
4121
|
+
* retried in shorter pieces because markdown rendering can split or drop
|
|
4122
|
+
* parts of a long sentence.
|
|
4123
|
+
*/
|
|
4124
|
+
function findByText(scroller, seeks) {
|
|
4125
|
+
if (scroller === null) return null;
|
|
4126
|
+
var candidates = Array.isArray(seeks) ? seeks : (typeof seeks === "string" ? [seeks] : []);
|
|
4127
|
+
if (candidates.length === 0) return null;
|
|
4128
|
+
var probes = [];
|
|
4129
|
+
for (var c = 0; c < candidates.length; c += 1) {
|
|
4130
|
+
var needle = String(candidates[c] || "").replace(/\s+/g, " ").trim();
|
|
4131
|
+
if (needle === "") continue;
|
|
4132
|
+
probes.push(needle);
|
|
4133
|
+
if (needle.length > 34) probes.push(needle.slice(0, 34));
|
|
4134
|
+
if (needle.length > 16) probes.push(needle.slice(0, 16));
|
|
4135
|
+
}
|
|
4136
|
+
/* Walk the turn rows, not every element: one `textContent` read per row
|
|
4137
|
+
is a few dozen reads, where sweeping `querySelectorAll("*")` over a
|
|
4138
|
+
126-turn transcript is tens of thousands and freezes the panel. */
|
|
4139
|
+
var rows = [];
|
|
4140
|
+
try {
|
|
4141
|
+
var found = scroller.querySelectorAll("[data-chat-turn]");
|
|
4142
|
+
for (var r = 0; r < found.length && r < 400; r += 1) rows.push(found[r]);
|
|
4143
|
+
} catch (error) {
|
|
4144
|
+
rows = [];
|
|
4145
|
+
}
|
|
4146
|
+
for (var p = 0; p < probes.length; p += 1) {
|
|
4147
|
+
var probe = probes[p].trim();
|
|
4148
|
+
if (probe === "") continue;
|
|
4149
|
+
for (var q = 0; q < rows.length; q += 1) {
|
|
4150
|
+
if (normalizedText(rows[q]).indexOf(probe) !== -1) return rows[q];
|
|
4151
|
+
}
|
|
4152
|
+
}
|
|
4153
|
+
return null;
|
|
4154
|
+
}
|
|
4155
|
+
/**
|
|
4156
|
+
* Whether a turn row actually carries the matched text.
|
|
4157
|
+
*
|
|
4158
|
+
* A very long session renders its old turns through a lighter path than
|
|
4159
|
+
* the recent ones - the per-message action bar is absent - and that path
|
|
4160
|
+
* may hold a collapsed placeholder instead of the message body. Landing on
|
|
4161
|
+
* one of those scrolls somewhere useless, so a row is only trusted when
|
|
4162
|
+
* the matched text (or at least a real block of text) is inside it.
|
|
4163
|
+
*/
|
|
4164
|
+
function rowCarriesSeek(row, seeks) {
|
|
4165
|
+
if (row === null || row === undefined) return false;
|
|
4166
|
+
var text = normalizedText(row);
|
|
4167
|
+
var candidates = Array.isArray(seeks) ? seeks : (typeof seeks === "string" ? [seeks] : []);
|
|
4168
|
+
for (var i = 0; i < candidates.length; i += 1) {
|
|
4169
|
+
var needle = String(candidates[i] || "").replace(/\s+/g, " ").trim();
|
|
4170
|
+
if (needle === "") continue;
|
|
4171
|
+
if (text.indexOf(needle) !== -1) return true;
|
|
4172
|
+
if (needle.length > 20 && text.indexOf(needle.slice(0, 20)) !== -1) return true;
|
|
4173
|
+
}
|
|
4174
|
+
/* No needle matched: a body of text still proves the row is rendered. */
|
|
4175
|
+
return text.length > 200;
|
|
4176
|
+
}
|
|
4177
|
+
|
|
4178
|
+
|
|
4179
|
+
/** The rail mark for one turn, if the rail currently renders it. */
|
|
4180
|
+
function railMarkFor(turn) {
|
|
4181
|
+
var wanted = Number(turn);
|
|
4182
|
+
if (!isFinite(wanted)) return null;
|
|
4183
|
+
var marks = railMarks();
|
|
4184
|
+
for (var i = 0; i < marks.length; i += 1) {
|
|
4185
|
+
if (turnOfRailMark(marks[i]) === wanted) return marks[i];
|
|
4186
|
+
}
|
|
4187
|
+
return null;
|
|
4188
|
+
}
|
|
4189
|
+
/**
|
|
4190
|
+
* The rail's own scroll container.
|
|
4191
|
+
*
|
|
4192
|
+
* A mark's parent is the marks list, not the scroller: scrolling the list
|
|
4193
|
+
* does nothing, so the ancestor that actually scrolls is what has to move.
|
|
4194
|
+
*/
|
|
4195
|
+
function railList() {
|
|
4196
|
+
var marks = railMarks();
|
|
4197
|
+
if (marks.length === 0) return null;
|
|
4198
|
+
var node = marks[0].parentElement;
|
|
4199
|
+
while (node !== null && node !== undefined) {
|
|
4200
|
+
var scrolls = typeof node.scrollHeight === "number" && typeof node.clientHeight === "number"
|
|
4201
|
+
&& node.scrollHeight > node.clientHeight && node.clientHeight > 0;
|
|
4202
|
+
if (scrolls) return node;
|
|
4203
|
+
node = node.parentElement;
|
|
4204
|
+
}
|
|
4205
|
+
return null;
|
|
4206
|
+
}
|
|
4207
|
+
|
|
4208
|
+
/** The style rule the Custom Highlight API paints matches with. */
|
|
4209
|
+
var searchHighlightReady = false;
|
|
4210
|
+
|
|
4211
|
+
function ensureSearchHighlight() {
|
|
4212
|
+
if (searchHighlightReady || typeof document === "undefined") return;
|
|
4213
|
+
searchHighlightReady = true;
|
|
4214
|
+
try {
|
|
4215
|
+
var style = document.createElement("style");
|
|
4216
|
+
style.setAttribute("data-wsr-search-highlight", "true");
|
|
4217
|
+
style.textContent = "::highlight(wsr-search-hit){background:rgba(245,197,66,.45);color:inherit}";
|
|
4218
|
+
if (document.head !== null && document.head !== undefined) document.head.appendChild(style);
|
|
4219
|
+
} catch (error) {
|
|
4220
|
+
/* without the rule the jump still scrolls; only the paint is lost */
|
|
4221
|
+
}
|
|
4222
|
+
}
|
|
4223
|
+
|
|
4224
|
+
/** Text nodes under a root, for finding the query terms inside a message. */
|
|
4225
|
+
function textNodesIn(root, limit) {
|
|
4226
|
+
var out = [];
|
|
4227
|
+
var cap = typeof limit === "number" && limit > 0 ? limit : 3000;
|
|
4228
|
+
if (root === null || root === undefined) return out;
|
|
4229
|
+
if (typeof NodeFilter === "undefined" || typeof document.createTreeWalker !== "function") return out;
|
|
4230
|
+
try {
|
|
4231
|
+
var walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, null);
|
|
4232
|
+
while (out.length < cap && walker.nextNode() !== null) out.push(walker.currentNode);
|
|
4233
|
+
} catch (error) {
|
|
4234
|
+
return out;
|
|
4235
|
+
}
|
|
4236
|
+
return out;
|
|
4237
|
+
}
|
|
4238
|
+
/**
|
|
4239
|
+
* Paints the query's terms where they appear and centres the first one.
|
|
4240
|
+
*
|
|
4241
|
+
* Landing on the right turn is not enough: a long turn buries the match,
|
|
4242
|
+
* and reading it out of the chat by hand is what this panel exists to
|
|
4243
|
+
* avoid. The Custom Highlight API paints the ranges without touching the
|
|
4244
|
+
* React-managed DOM, so nothing is re-rendered or fought over.
|
|
4245
|
+
*/
|
|
4246
|
+
function markHitTerms(terms) {
|
|
4247
|
+
if (typeof document === "undefined") return;
|
|
4248
|
+
var needles = [];
|
|
4249
|
+
for (var i = 0; i < (Array.isArray(terms) ? terms.length : 0); i += 1) {
|
|
4250
|
+
var term = String(terms[i] || "").toLowerCase();
|
|
4251
|
+
if (term !== "" && needles.indexOf(term) === -1) needles.push(term);
|
|
4252
|
+
}
|
|
4253
|
+
if (needles.length === 0) return;
|
|
4254
|
+
/* Four short attempts at most: every attempt walks text nodes, and a
|
|
4255
|
+
long transcript has enough of them that polling was felt as lag. */
|
|
4256
|
+
var attempts = 0;
|
|
4257
|
+
var tick = function () {
|
|
4258
|
+
attempts += 1;
|
|
4259
|
+
if (attempts > 2) return;
|
|
4260
|
+
var scroller = conversationScroller();
|
|
4261
|
+
if (scroller === null) {
|
|
4262
|
+
window.setTimeout(tick, 300);
|
|
4263
|
+
return;
|
|
4264
|
+
}
|
|
4265
|
+
var beganScan = Date.now();
|
|
4266
|
+
var nodes = textNodesIn(scroller, 1200);
|
|
4267
|
+
var ranges = [];
|
|
4268
|
+
for (var n = 0; n < nodes.length && ranges.length < 40; n += 1) {
|
|
4269
|
+
var node = nodes[n];
|
|
4270
|
+
var text = String(node.nodeValue || "");
|
|
4271
|
+
if (text === "") continue;
|
|
4272
|
+
var lower = text.toLowerCase();
|
|
4273
|
+
for (var k = 0; k < needles.length && ranges.length < 40; k += 1) {
|
|
4274
|
+
var from = 0;
|
|
4275
|
+
while (from < lower.length && ranges.length < 40) {
|
|
4276
|
+
var at = lower.indexOf(needles[k], from);
|
|
4277
|
+
if (at < 0) break;
|
|
4278
|
+
try {
|
|
4279
|
+
var range = document.createRange();
|
|
4280
|
+
range.setStart(node, at);
|
|
4281
|
+
range.setEnd(node, at + needles[k].length);
|
|
4282
|
+
ranges.push(range);
|
|
4283
|
+
} catch (error) {
|
|
4284
|
+
/* a node the range API refuses is simply skipped */
|
|
4285
|
+
}
|
|
4286
|
+
from = at + needles[k].length;
|
|
4287
|
+
}
|
|
4288
|
+
}
|
|
4289
|
+
}
|
|
4290
|
+
if (ranges.length === 0) {
|
|
4291
|
+
if (attempts < 2) window.setTimeout(tick, 600);
|
|
4292
|
+
return;
|
|
4293
|
+
}
|
|
4294
|
+
var painted = false;
|
|
4295
|
+
try {
|
|
4296
|
+
/* `CSS` in this module is the plugin's stylesheet array, so the
|
|
4297
|
+
DOM API has to be reached through `window`. */
|
|
4298
|
+
var cssApi = typeof window !== "undefined" && window !== null ? window.CSS : undefined;
|
|
4299
|
+
var HighlightCtor = typeof window !== "undefined" && window !== null ? window.Highlight : undefined;
|
|
4300
|
+
if (cssApi !== undefined && cssApi !== null && cssApi.highlights !== undefined && typeof HighlightCtor === "function") {
|
|
4301
|
+
ensureSearchHighlight();
|
|
4302
|
+
cssApi.highlights.set("wsr-search-hit", new HighlightCtor(ranges));
|
|
4303
|
+
painted = true;
|
|
4304
|
+
window.setTimeout(function () {
|
|
4305
|
+
try {
|
|
4306
|
+
cssApi.highlights.delete("wsr-search-hit");
|
|
4307
|
+
} catch (error) {
|
|
4308
|
+
/* the panel may have closed already */
|
|
4309
|
+
}
|
|
4310
|
+
}, 12000);
|
|
4311
|
+
}
|
|
4312
|
+
} catch (error) {
|
|
4313
|
+
painted = false;
|
|
4314
|
+
}
|
|
4315
|
+
var spentScan = Date.now() - beganScan;
|
|
4316
|
+
if (spentScan > 120 && typeof window !== "undefined") window.__DSH_WSR_LAST_TAIL_MS__ = spentScan;
|
|
4317
|
+
var first = ranges[0];
|
|
4318
|
+
var holder = first !== undefined && first !== null
|
|
4319
|
+
&& first.startContainer !== undefined && first.startContainer !== null
|
|
4320
|
+
? first.startContainer.parentElement
|
|
4321
|
+
: null;
|
|
4322
|
+
if (holder !== null && holder !== undefined) flashTurnRow(holder);
|
|
4323
|
+
else if (!painted) window.setTimeout(tick, 300);
|
|
4324
|
+
};
|
|
4325
|
+
window.setTimeout(tick, 120);
|
|
4326
|
+
} /**
|
|
4327
|
+
* Bring one search hit into view.
|
|
4328
|
+
*
|
|
4329
|
+
* Three routes, best first: a mounted `data-chat-turn` row (the chat keeps
|
|
4330
|
+
* one per flow item), the turn rail's own mark for that turn (it loads a
|
|
4331
|
+
* turn that is outside the window), and finally a proportional scroll plus
|
|
4332
|
+
* a text search, with the upward walk while older history loads.
|
|
4333
|
+
*/
|
|
4334
|
+
/** The badge currently pinned to a rail cell, if any. */
|
|
4335
|
+
|
|
4336
|
+
|
|
4337
|
+
/**
|
|
4338
|
+
* Bring one search hit into view.
|
|
4339
|
+
*
|
|
4340
|
+
* Scrolling the transcript does not page older history in: the chat asks the
|
|
4341
|
+
* user to load it. Clicking the turn rail's mark for that turn does load it,
|
|
4342
|
+
* which is the route the host itself uses, so the rail is the primary path
|
|
4343
|
+
* here. Mounted rows and a text search remain as fallbacks.
|
|
4344
|
+
*/
|
|
4345
|
+
/**
|
|
4346
|
+
* One last look after a rail click: the host is loading a whole page of
|
|
4347
|
+
* history, so nothing here may poll while that runs.
|
|
4348
|
+
*/
|
|
4349
|
+
function finaliseJump(hit, terms) {
|
|
4350
|
+
if (typeof document === "undefined") return;
|
|
4351
|
+
var began = Date.now();
|
|
4352
|
+
var seeks = Array.isArray(hit.seeks) ? hit.seeks : hit.seek;
|
|
4353
|
+
var scroller = conversationScroller();
|
|
4354
|
+
if (scroller !== null) {
|
|
4355
|
+
var row = findByText(scroller, seeks);
|
|
4356
|
+
if (row !== null) flashTurnRow(row);
|
|
4357
|
+
}
|
|
4358
|
+
markHitTerms(terms);
|
|
4359
|
+
/* Anything past a frame is ours to answer for, so say so rather than
|
|
4360
|
+
letting it pass as the host being slow. */
|
|
4361
|
+
var spent = Date.now() - began;
|
|
4362
|
+
if (spent > 120 && typeof window !== "undefined") {
|
|
4363
|
+
window.__DSH_WSR_LAST_TAIL_MS__ = spent;
|
|
4364
|
+
}
|
|
4365
|
+
}
|
|
4366
|
+
/**
|
|
4367
|
+
* Bring one search hit into view.
|
|
4368
|
+
*
|
|
4369
|
+
* Scrolling the transcript does not page older history in: the chat asks the
|
|
4370
|
+
* user to load it, while clicking the turn rail's mark loads and aligns that
|
|
4371
|
+
* turn. The rail is therefore the primary route. Everything here is kept
|
|
4372
|
+
* to a few cheap lookups: the host is rendering history at the same time,
|
|
4373
|
+
* and a polling loop on top of that is what made the jump feel frozen.
|
|
4374
|
+
*/
|
|
4375
|
+
function revealHit(hit, terms) {
|
|
4376
|
+
if (typeof document === "undefined" || hit === null || hit === undefined) return;
|
|
4377
|
+
var sessionId = hit.sessionId;
|
|
4378
|
+
var turn = Number(hit.turn);
|
|
4379
|
+
var seeksNow = Array.isArray(hit.seeks) ? hit.seeks : hit.seek;
|
|
4380
|
+
var deadline = Date.now() + (Number(hit.turns) > 40 ? 15000 : 9000);
|
|
4381
|
+
var opened = false;
|
|
4382
|
+
var reportedStub = false;
|
|
4383
|
+
var pokes = 0;
|
|
4384
|
+
var ticks = 0;
|
|
4385
|
+
/* Wall time includes the host opening the session and loading its
|
|
4386
|
+
history; only the synchronous work in here belongs to this plugin. */
|
|
4387
|
+
var spentMs = 0;
|
|
4388
|
+
var started = Date.now();
|
|
4389
|
+
var tick = function () {
|
|
4390
|
+
var beganTick = Date.now();
|
|
4391
|
+
var done = function () {
|
|
4392
|
+
spentMs += Date.now() - beganTick;
|
|
4393
|
+
};
|
|
4394
|
+
var result = tickOnce();
|
|
4395
|
+
done();
|
|
4396
|
+
return result;
|
|
4397
|
+
};
|
|
4398
|
+
var tickOnce = function () {
|
|
4399
|
+
if (Date.now() > deadline) {
|
|
4400
|
+
announceJumpFailure(hit, opened ? "search.jumpNoTurn" : "search.jumpNoSession");
|
|
4401
|
+
return;
|
|
4402
|
+
}
|
|
4403
|
+
if (currentConversationId() !== sessionId) {
|
|
4404
|
+
window.setTimeout(tick, 250);
|
|
4405
|
+
return;
|
|
4406
|
+
}
|
|
4407
|
+
opened = true;
|
|
4408
|
+
ticks += 1;
|
|
4409
|
+
var row = turnRowOf(turn);
|
|
4410
|
+
if (row !== null) {
|
|
4411
|
+
flashTurnRow(row);
|
|
4412
|
+
if (rowCarriesSeek(row, seeksNow)) {
|
|
4413
|
+
announceJump(hit, false, spentMs);
|
|
4414
|
+
markHitTerms(terms);
|
|
4415
|
+
return;
|
|
4416
|
+
}
|
|
4417
|
+
if (!reportedStub) {
|
|
4418
|
+
reportedStub = true;
|
|
4419
|
+
announceJumpFailure(hit, "search.jumpCollapsed");
|
|
4420
|
+
}
|
|
4421
|
+
window.setTimeout(tick, 500);
|
|
4422
|
+
return;
|
|
4423
|
+
}
|
|
4424
|
+
/* Query the rail every other tick: it is a document-wide lookup. */
|
|
4425
|
+
if (ticks % 2 === 1) {
|
|
4426
|
+
var mark = railMarkFor(turn);
|
|
4427
|
+
if (mark !== null) {
|
|
4428
|
+
try {
|
|
4429
|
+
mark.click();
|
|
4430
|
+
announceJump(hit, false, spentMs);
|
|
4431
|
+
/* The click starts a real history load: hand the thread back to
|
|
4432
|
+
the host and look once when it has had time to render. */
|
|
4433
|
+
window.setTimeout(function () {
|
|
4434
|
+
finaliseJump(hit, terms);
|
|
4435
|
+
suppressedUntil = 0;
|
|
4436
|
+
schedule();
|
|
4437
|
+
}, 1200);
|
|
4438
|
+
return;
|
|
4439
|
+
} catch (error) {
|
|
4440
|
+
/* fall through */
|
|
4441
|
+
}
|
|
4442
|
+
}
|
|
4443
|
+
}
|
|
4444
|
+
/* The rail is virtualised too: nudge it so the wanted mark renders. */
|
|
4445
|
+
if (pokes < 4) {
|
|
4446
|
+
var list = railList();
|
|
4447
|
+
var turns = Number(hit.turns);
|
|
4448
|
+
if (list !== null && turn > 0 && turns > 0) {
|
|
4449
|
+
var span = Math.max(0, (Number(list.scrollHeight) || 0) - (Number(list.clientHeight) || 0));
|
|
4450
|
+
var ratio = Math.min(1, Math.max(0, (turn - 1) / Math.max(1, turns - 1)));
|
|
4451
|
+
scrollTo(list, span * ratio);
|
|
4452
|
+
pokes += 1;
|
|
4453
|
+
window.setTimeout(tick, 350);
|
|
4454
|
+
return;
|
|
4455
|
+
}
|
|
4456
|
+
}
|
|
4457
|
+
window.setTimeout(tick, 350);
|
|
4458
|
+
};
|
|
4459
|
+
window.setTimeout(tick, 200);
|
|
4460
|
+
}
|
|
4461
|
+
function jumpToSearchHit(hit, terms) {
|
|
4462
|
+
suspendPasses(12000);
|
|
3891
4463
|
openSessionRow(hit.sessionId);
|
|
3892
|
-
|
|
4464
|
+
revealHit(hit, terms);
|
|
4465
|
+
}
|
|
4466
|
+
|
|
4467
|
+
/**
|
|
4468
|
+
* The chat's own turn rail: one button per turn, `data-index` + an
|
|
4469
|
+
* aria-label that names the turn. Clicking a mark is the official
|
|
4470
|
+
* navigation, and it also loads a turn that is not in the window yet.
|
|
4471
|
+
*/
|
|
4472
|
+
function railMarks() {
|
|
4473
|
+
if (typeof document === "undefined") return [];
|
|
4474
|
+
var all = null;
|
|
4475
|
+
try {
|
|
4476
|
+
/* The rail's own frame first: the same collection, found without
|
|
4477
|
+
walking the whole document. */
|
|
4478
|
+
var frame = document.querySelector('[class*="_frame"]');
|
|
4479
|
+
var scopedAll = frame === null ? null : frame.querySelectorAll("button[data-index]");
|
|
4480
|
+
all = scopedAll !== null && scopedAll.length > 0 ? scopedAll : document.querySelectorAll("button[data-index]");
|
|
4481
|
+
} catch (error) {
|
|
4482
|
+
return [];
|
|
4483
|
+
}
|
|
4484
|
+
var marks = [];
|
|
4485
|
+
for (var i = 0; i < (all === null ? 0 : all.length); i += 1) {
|
|
4486
|
+
var button = all[i];
|
|
4487
|
+
var className = typeof button.className === "string" ? button.className : "";
|
|
4488
|
+
if (className.indexOf("_mark") === -1) continue;
|
|
4489
|
+
marks.push(button);
|
|
4490
|
+
}
|
|
4491
|
+
return marks;
|
|
4492
|
+
}
|
|
4493
|
+
|
|
4494
|
+
/** The turn a rail mark points at: the last integer in its label. */
|
|
4495
|
+
/**
|
|
4496
|
+
* The turn a rail mark points at.
|
|
4497
|
+
*
|
|
4498
|
+
* The label starts with the turn number ("Jump to turn 3", "跳转到第 3 轮");
|
|
4499
|
+
* any count a wording appends comes later, so the first integer is the turn.
|
|
4500
|
+
* A label that carries a count instead of a turn would make the FIRST match
|
|
4501
|
+
* wrong in exactly the same way the LAST one was, so both are tried and the
|
|
4502
|
+
* mark's own order breaks the tie.
|
|
4503
|
+
*/
|
|
4504
|
+
function turnOfRailMark(button) {
|
|
4505
|
+
if (button === null || button === undefined || typeof button.getAttribute !== "function") return NaN;
|
|
4506
|
+
var label = String(button.getAttribute("aria-label") || "");
|
|
4507
|
+
var found = label.match(/\d+/);
|
|
4508
|
+
return found === null ? NaN : Number(found[0]);
|
|
4509
|
+
}
|
|
4510
|
+
|
|
4511
|
+
/** Click the rail mark for one turn, if it is currently rendered. */
|
|
4512
|
+
function jumpViaRail(turn) {
|
|
4513
|
+
var wanted = Number(turn);
|
|
4514
|
+
if (!isFinite(wanted)) return false;
|
|
4515
|
+
var marks = railMarks();
|
|
4516
|
+
for (var i = 0; i < marks.length; i += 1) {
|
|
4517
|
+
if (turnOfRailMark(marks[i]) !== wanted) continue;
|
|
4518
|
+
try {
|
|
4519
|
+
marks[i].click();
|
|
4520
|
+
return true;
|
|
4521
|
+
} catch (error) {
|
|
4522
|
+
return false;
|
|
4523
|
+
}
|
|
4524
|
+
}
|
|
4525
|
+
return false;
|
|
3893
4526
|
}
|
|
3894
4527
|
|
|
3895
4528
|
/** Snippet text with every query term wrapped in a mark. */
|
|
@@ -3929,29 +4562,129 @@
|
|
|
3929
4562
|
* budget plus how many are still pending, so this asks again until the
|
|
3930
4563
|
* index has caught up instead of making the user press search twice.
|
|
3931
4564
|
*/
|
|
3932
|
-
|
|
3933
|
-
|
|
4565
|
+
/** A session id is a UUID; the head and tail are what tells two apart. */
|
|
4566
|
+
function shortSessionId(sessionId) {
|
|
4567
|
+
if (typeof sessionId !== "string" || sessionId === "") return "";
|
|
4568
|
+
return sessionId.length > 12 ? sessionId.slice(0, 8) + "\u2026" + sessionId.slice(-4) : sessionId;
|
|
4569
|
+
}
|
|
4570
|
+
|
|
4571
|
+
/**
|
|
4572
|
+
* One search hit.
|
|
4573
|
+
*
|
|
4574
|
+
* A hit is only useful if it says which conversation and when: the
|
|
4575
|
+
* workspace narrows it down, but two sessions in one workspace read the
|
|
4576
|
+
* same without a title and a timestamp.
|
|
4577
|
+
*/
|
|
4578
|
+
function searchHitRow(hit, terms, onClick, extra) {
|
|
4579
|
+
var title = typeof hit.title === "string" && hit.title.trim() !== ""
|
|
4580
|
+
? hit.title.trim()
|
|
4581
|
+
: (typeof hit.sessionId === "string" ? shortSessionId(hit.sessionId) : "");
|
|
4582
|
+
var when = formatWhen(Number(hit.at) || 0);
|
|
4583
|
+
return h("div", {
|
|
4584
|
+
className: "wsr-hit",
|
|
4585
|
+
title: hit.cwd || "",
|
|
4586
|
+
onClick: onClick,
|
|
4587
|
+
},
|
|
4588
|
+
h("div", { className: "wsr-hit-head" },
|
|
4589
|
+
h("span", { className: "wsr-hit-role " + (hit.role === "user" ? "wsr-hit-user" : "wsr-hit-agent") }, hit.role === "user" ? t("search.you") : t("search.assistant")),
|
|
4590
|
+
h("span", { className: "wsr-hit-title", title: title }, title),
|
|
4591
|
+
typeof hit.workspace === "string" && hit.workspace !== "" ? h("span", { className: "wsr-hit-ws" }, hit.workspace) : null,
|
|
4592
|
+
h("span", { className: "wsr-hit-turn" }, t("search.turn", { n: String(hit.turn) })),
|
|
4593
|
+
/* The step inside the turn: it is what the reader checks against the
|
|
4594
|
+
chat after jumping, so a hit that looks wrong can be told apart
|
|
4595
|
+
from a jump that landed wrong. */
|
|
4596
|
+
typeof hit.step === "number" && isFinite(hit.step)
|
|
4597
|
+
? h("span", { className: "wsr-hit-step" }, t("search.step", { n: String(hit.step) }))
|
|
4598
|
+
: null,
|
|
4599
|
+
),
|
|
4600
|
+
h("div", { className: "wsr-hit-meta" },
|
|
4601
|
+
when !== "" ? h("span", { className: "wsr-hit-time" }, when) : null,
|
|
4602
|
+
typeof hit.cwd === "string" && hit.cwd !== "" ? h("span", { className: "wsr-hit-cwd" }, hit.cwd) : null,
|
|
4603
|
+
),
|
|
4604
|
+
h("div", { className: "wsr-hit-snippet" },
|
|
4605
|
+
hit.lead === true ? "\u2026" : null,
|
|
4606
|
+
highlightSnippet(hit.snippet || "", terms),
|
|
4607
|
+
hit.tail === true ? "\u2026" : null,
|
|
4608
|
+
),
|
|
4609
|
+
extra === undefined || extra === null ? null : extra,
|
|
4610
|
+
);
|
|
4611
|
+
}
|
|
4612
|
+
|
|
4613
|
+
/**
|
|
4614
|
+
* One search hit, with the surrounding text on demand.
|
|
4615
|
+
*
|
|
4616
|
+
* Opening a hit in a long session makes the chat mount a page of history,
|
|
4617
|
+
* which can take seconds. Reading the hit does not have to: the host ships
|
|
4618
|
+
* the matched neighbourhood, so the row can show it where it stands.
|
|
4619
|
+
*/
|
|
4620
|
+
function SearchHitRow(props) {
|
|
4621
|
+
var opened = react.useState(false);
|
|
4622
|
+
var context = typeof props.hit.context === "string" ? props.hit.context : "";
|
|
4623
|
+
var extra = context === "" ? null : [
|
|
4624
|
+
h("div", { className: "wsr-hit-actions" },
|
|
4625
|
+
h("button", {
|
|
4626
|
+
type: "button",
|
|
4627
|
+
className: "wsr-hit-context-toggle",
|
|
4628
|
+
onClick: function (event) {
|
|
4629
|
+
if (event !== undefined && typeof event.stopPropagation === "function") event.stopPropagation();
|
|
4630
|
+
opened[1](opened[0] !== true);
|
|
4631
|
+
},
|
|
4632
|
+
}, opened[0] === true ? t("search.contextHide") : t("search.contextShow")),
|
|
4633
|
+
h("button", {
|
|
4634
|
+
type: "button",
|
|
4635
|
+
className: "wsr-hit-context-jump",
|
|
4636
|
+
onClick: function (event) {
|
|
4637
|
+
if (event !== undefined && typeof event.stopPropagation === "function") event.stopPropagation();
|
|
4638
|
+
if (typeof props.onJump === "function") props.onJump();
|
|
4639
|
+
},
|
|
4640
|
+
}, t("search.openSession")),
|
|
4641
|
+
),
|
|
4642
|
+
opened[0] === true ? h("div", { className: "wsr-hit-context" }, context) : null,
|
|
4643
|
+
];
|
|
4644
|
+
return searchHitRow(props.hit, props.terms, props.onJump, extra);
|
|
4645
|
+
}
|
|
4646
|
+
|
|
4647
|
+
function SearchPanelPage(props) {
|
|
4648
|
+
var state = react.useState(searchLast === null
|
|
4649
|
+
? { loaded: false, query: "", hits: [], terms: [], scanned: 0, total: 0, pending: 0, took: 0, busy: false, error: "" }
|
|
4650
|
+
: searchLast);
|
|
3934
4651
|
var view = state[0];
|
|
3935
4652
|
var setView = state[1];
|
|
4653
|
+
/* The recent-query list lives in the shared store, so it survives a
|
|
4654
|
+
restart and is the same list on every panel. */
|
|
4655
|
+
var preferences = props !== undefined && props !== null && typeof props.useStore === "function"
|
|
4656
|
+
? props.useStore(function (snapshot) { return snapshot; })
|
|
4657
|
+
: (data.settings || {});
|
|
4658
|
+
var actions = props !== undefined && props !== null && props.actions !== undefined ? props.actions : {};
|
|
4659
|
+
var historyList = preferences !== null && preferences !== undefined && Array.isArray(preferences.searchHistory)
|
|
4660
|
+
? preferences.searchHistory
|
|
4661
|
+
: [];
|
|
4662
|
+
/* Every update also parks the answer outside the component, so coming
|
|
4663
|
+
back from a hit restores the list instead of asking for a new search. */
|
|
4664
|
+
var commit = function (next) {
|
|
4665
|
+
searchLast = next;
|
|
4666
|
+
setView(next);
|
|
4667
|
+
};
|
|
3936
4668
|
|
|
3937
4669
|
var run = function (text, refresh) {
|
|
3938
4670
|
var query = typeof text === "string" ? text.trim() : "";
|
|
3939
4671
|
searchGeneration += 1;
|
|
3940
4672
|
var generation = searchGeneration;
|
|
3941
4673
|
if (query === "") {
|
|
3942
|
-
|
|
4674
|
+
commit({ loaded: true, query: "", hits: [], terms: [], scanned: 0, total: 0, pending: 0, took: 0, busy: false, error: "" });
|
|
3943
4675
|
return;
|
|
3944
4676
|
}
|
|
3945
|
-
|
|
4677
|
+
if (typeof actions.pushSearch === "function") actions.pushSearch(query);
|
|
4678
|
+
commit({ loaded: true, query: query, hits: view.hits, terms: view.terms, scanned: view.scanned, total: view.total, pending: view.pending, took: view.took, busy: true, error: "" });
|
|
3946
4679
|
var ask = function (needRefresh) {
|
|
3947
4680
|
searchPost({ query: query, refresh: needRefresh === true }).then(function (answer) {
|
|
3948
4681
|
if (generation !== searchGeneration) return;
|
|
3949
4682
|
var json = answer.json;
|
|
3950
4683
|
if (json === null || json.ok !== true) {
|
|
3951
|
-
|
|
4684
|
+
commit({ loaded: true, query: query, hits: [], terms: [], scanned: 0, total: 0, pending: 0, took: 0, busy: false, error: t("search.failed") + "HTTP " + answer.status });
|
|
3952
4685
|
return;
|
|
3953
4686
|
}
|
|
3954
|
-
|
|
4687
|
+
commit({
|
|
3955
4688
|
loaded: true,
|
|
3956
4689
|
query: query,
|
|
3957
4690
|
hits: Array.isArray(json.hits) ? json.hits : [],
|
|
@@ -3970,7 +4703,7 @@
|
|
|
3970
4703
|
}
|
|
3971
4704
|
}).catch(function (error) {
|
|
3972
4705
|
if (generation !== searchGeneration) return;
|
|
3973
|
-
|
|
4706
|
+
commit({ loaded: true, query: query, hits: [], terms: [], scanned: 0, total: 0, pending: 0, took: 0, busy: false, error: t("search.failed") + (error && error.message ? error.message : error) });
|
|
3974
4707
|
});
|
|
3975
4708
|
};
|
|
3976
4709
|
ask(refresh === true);
|
|
@@ -3980,7 +4713,8 @@
|
|
|
3980
4713
|
className: "wsr-search-input",
|
|
3981
4714
|
type: "search",
|
|
3982
4715
|
placeholder: t("search.placeholder"),
|
|
3983
|
-
|
|
4716
|
+
/* The box comes back with the query that produced the results below. */
|
|
4717
|
+
defaultValue: view.query || searchDraft,
|
|
3984
4718
|
onChange: function (event) {
|
|
3985
4719
|
searchDraft = event !== undefined && event.target !== undefined ? String(event.target.value || "") : "";
|
|
3986
4720
|
},
|
|
@@ -3993,30 +4727,54 @@
|
|
|
3993
4727
|
});
|
|
3994
4728
|
|
|
3995
4729
|
var rows = view.hits.map(function (hit, index) {
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
h("span", { className: "wsr-hit-role " + (hit.role === "user" ? "wsr-hit-user" : "wsr-hit-agent") }, hit.role === "user" ? t("search.you") : t("search.assistant")),
|
|
4004
|
-
h("span", { className: "wsr-hit-title" }, hit.title || hit.sessionId || ""),
|
|
4005
|
-
typeof hit.workspace === "string" && hit.workspace !== "" ? h("span", { className: "wsr-hit-ws" }, hit.workspace) : null,
|
|
4006
|
-
h("span", { className: "wsr-hit-turn" }, t("search.turn", { n: String(hit.turn) })),
|
|
4007
|
-
),
|
|
4008
|
-
h("div", { className: "wsr-hit-snippet" },
|
|
4009
|
-
hit.lead === true ? "\u2026" : null,
|
|
4010
|
-
highlightSnippet(hit.snippet || "", view.terms),
|
|
4011
|
-
hit.tail === true ? "\u2026" : null,
|
|
4012
|
-
),
|
|
4013
|
-
);
|
|
4730
|
+
var row = h(SearchHitRow, {
|
|
4731
|
+
hit: hit,
|
|
4732
|
+
terms: view.terms,
|
|
4733
|
+
onJump: function () { jumpToSearchHit(hit, view.terms); },
|
|
4734
|
+
});
|
|
4735
|
+
row.key = String(hit.sessionId || "") + ":" + String(hit.seq || 0) + ":" + String(index);
|
|
4736
|
+
return row;
|
|
4014
4737
|
});
|
|
4015
4738
|
|
|
4016
4739
|
return h("div", { className: "wsr-page wsr-search-page" },
|
|
4017
4740
|
h("div", { className: "wsr-page-head" },
|
|
4018
4741
|
h("div", { className: "wsr-page-heading" }, t("search.title")),
|
|
4019
4742
|
),
|
|
4743
|
+
historyList.length === 0 ? null : h("div", { className: "wsr-search-history" },
|
|
4744
|
+
h("span", { className: "wsr-search-history-label" }, t("search.history")),
|
|
4745
|
+
historyList.map(function (item, index) {
|
|
4746
|
+
var text = String(item);
|
|
4747
|
+
return h("span", { className: "wsr-search-chip", key: text + ":" + String(index) },
|
|
4748
|
+
h("button", {
|
|
4749
|
+
type: "button",
|
|
4750
|
+
className: "wsr-search-chip-run",
|
|
4751
|
+
title: t("search.historyRun", { query: text }),
|
|
4752
|
+
onClick: function () {
|
|
4753
|
+
searchDraft = text;
|
|
4754
|
+
run(text, false);
|
|
4755
|
+
},
|
|
4756
|
+
}, text),
|
|
4757
|
+
h("button", {
|
|
4758
|
+
type: "button",
|
|
4759
|
+
className: "wsr-search-chip-drop",
|
|
4760
|
+
title: t("search.historyDrop"),
|
|
4761
|
+
"aria-label": t("search.historyDrop"),
|
|
4762
|
+
onClick: function (event) {
|
|
4763
|
+
if (event !== undefined && typeof event.stopPropagation === "function") event.stopPropagation();
|
|
4764
|
+
if (typeof actions.dropSearch === "function") actions.dropSearch(text);
|
|
4765
|
+
},
|
|
4766
|
+
}, "\u00d7"),
|
|
4767
|
+
);
|
|
4768
|
+
}),
|
|
4769
|
+
h("button", {
|
|
4770
|
+
type: "button",
|
|
4771
|
+
className: "wsr-search-history-clear",
|
|
4772
|
+
onClick: function () {
|
|
4773
|
+
if (typeof actions.clearSearches === "function") actions.clearSearches();
|
|
4774
|
+
},
|
|
4775
|
+
}, t("search.historyClear")),
|
|
4776
|
+
),
|
|
4777
|
+
h("div", { className: "wsr-search-hint" }, t("search.hint")),
|
|
4020
4778
|
h("div", { className: "wsr-search-bar" },
|
|
4021
4779
|
input,
|
|
4022
4780
|
h("button", { type: "button", className: "wsr-btn", onClick: function () { run(searchDraft, false); } }, t("search.run")),
|
|
@@ -4318,53 +5076,7 @@
|
|
|
4318
5076
|
);
|
|
4319
5077
|
}
|
|
4320
5078
|
|
|
4321
|
-
|
|
4322
|
-
* Sidebar footer action: the trash, one click away from the account area.
|
|
4323
|
-
*
|
|
4324
|
-
* Geometry is the same house rule the official launchers follow
|
|
4325
|
-
* (`dshUpdateLauncher` / `dshMarketLauncher`): full-width seat bled 2px
|
|
4326
|
-
* per side, 42px tall, 12px radius. `wide` comes from the slot, so the
|
|
4327
|
-
* narrow rail keeps its 36px circle instead of a stretched row.
|
|
4328
|
-
*/
|
|
4329
|
-
function TrashFooterAction(props) {
|
|
4330
|
-
var wide = props === undefined || props === null || props.wide !== false;
|
|
4331
|
-
var label = t("trash.title");
|
|
4332
|
-
var Icon = ui.IconTrashOutlineRegular;
|
|
4333
|
-
return h("button", {
|
|
4334
|
-
type: "button",
|
|
4335
|
-
className: "wsr-footer-action",
|
|
4336
|
-
title: label,
|
|
4337
|
-
"aria-label": label,
|
|
4338
|
-
"aria-haspopup": "dialog",
|
|
4339
|
-
style: {
|
|
4340
|
-
boxSizing: "border-box",
|
|
4341
|
-
width: "100%",
|
|
4342
|
-
alignSelf: "stretch",
|
|
4343
|
-
display: "flex",
|
|
4344
|
-
alignItems: "center",
|
|
4345
|
-
justifyContent: "flex-start",
|
|
4346
|
-
gap: "10px",
|
|
4347
|
-
minHeight: "40px",
|
|
4348
|
-
padding: "0 10px",
|
|
4349
|
-
border: "none",
|
|
4350
|
-
background: "transparent",
|
|
4351
|
-
color: "var(--dsw-alias-label-primary)",
|
|
4352
|
-
borderRadius: "10px",
|
|
4353
|
-
font: "inherit",
|
|
4354
|
-
fontSize: "14px",
|
|
4355
|
-
lineHeight: "22px",
|
|
4356
|
-
cursor: "pointer",
|
|
4357
|
-
textAlign: "left",
|
|
4358
|
-
},
|
|
4359
|
-
onClick: function () { openTrashPanel(); },
|
|
4360
|
-
},
|
|
4361
|
-
h("span", {
|
|
4362
|
-
style: { display: "inline-flex", alignItems: "center", justifyContent: "center", width: "20px", height: "20px", flex: "none" },
|
|
4363
|
-
"aria-hidden": "true",
|
|
4364
|
-
}, typeof Icon === "function" ? h(Icon, { size: 18 }) : null),
|
|
4365
|
-
wide ? h("span", { style: { whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } }, label) : null);
|
|
4366
|
-
}
|
|
4367
|
-
|
|
5079
|
+
|
|
4368
5080
|
/**
|
|
4369
5081
|
* Re-attach sessions that belong to no workspace.
|
|
4370
5082
|
*
|
|
@@ -4485,6 +5197,10 @@
|
|
|
4485
5197
|
|
|
4486
5198
|
function apply_(ctx) {
|
|
4487
5199
|
installCss();
|
|
5200
|
+
/* The turn rail's cells carry no text, and the host's own hover preview
|
|
5201
|
+
shows a turn's prompt (a number appears only when that prompt is
|
|
5202
|
+
empty). Labelling belongs to the search feature, so it is off with
|
|
5203
|
+
it. */
|
|
4488
5204
|
/* Navigation and unpinning live in the Workspace UI service. It can be
|
|
4489
5205
|
provided after this plugin applies, so take it now when it is there and
|
|
4490
5206
|
let cordis hand it over later when it is not. Never fail the plugin over
|
|
@@ -4502,7 +5218,7 @@
|
|
|
4502
5218
|
}
|
|
4503
5219
|
var prefs = clientStore.defineStore({
|
|
4504
5220
|
init: function () {
|
|
4505
|
-
return { enabled: true, foldDays: DEFAULT_DAYS, keepActive: true, colors: true, pinnedSection: true, argMode: "tool", followUps: {} };
|
|
5221
|
+
return { enabled: true, foldDays: DEFAULT_DAYS, keepActive: true, colors: true, pinnedSection: true, argMode: "tool", followUps: {}, searchHistory: [] };
|
|
4506
5222
|
},
|
|
4507
5223
|
persist: "dsh.ws-recency.prefs.v1",
|
|
4508
5224
|
actions: {
|
|
@@ -4526,6 +5242,30 @@
|
|
|
4526
5242
|
if (draft.followUps === null || typeof draft.followUps !== "object") return;
|
|
4527
5243
|
if (draft.followUps[sessionId] !== undefined) delete draft.followUps[sessionId];
|
|
4528
5244
|
},
|
|
5245
|
+
/* Recent queries, newest first, case-insensitively de-duplicated. */
|
|
5246
|
+
pushSearch: function (draft, query) {
|
|
5247
|
+
var text = typeof query === "string" ? query.trim() : "";
|
|
5248
|
+
if (text === "") return;
|
|
5249
|
+
var list = Array.isArray(draft.searchHistory) ? draft.searchHistory : [];
|
|
5250
|
+
var lower = text.toLowerCase();
|
|
5251
|
+
var next = [text];
|
|
5252
|
+
for (var i = 0; i < list.length && next.length < SEARCH_HISTORY_MAX; i += 1) {
|
|
5253
|
+
if (String(list[i]).toLowerCase() === lower) continue;
|
|
5254
|
+
next.push(list[i]);
|
|
5255
|
+
}
|
|
5256
|
+
draft.searchHistory = next;
|
|
5257
|
+
},
|
|
5258
|
+
dropSearch: function (draft, query) {
|
|
5259
|
+
var text = typeof query === "string" ? query.trim().toLowerCase() : "";
|
|
5260
|
+
if (text === "") return;
|
|
5261
|
+
var list = Array.isArray(draft.searchHistory) ? draft.searchHistory : [];
|
|
5262
|
+
draft.searchHistory = list.filter(function (item) {
|
|
5263
|
+
return String(item).trim().toLowerCase() !== text;
|
|
5264
|
+
});
|
|
5265
|
+
},
|
|
5266
|
+
clearSearches: function (draft) {
|
|
5267
|
+
draft.searchHistory = [];
|
|
5268
|
+
},
|
|
4529
5269
|
},
|
|
4530
5270
|
});
|
|
4531
5271
|
|
|
@@ -4539,7 +5279,19 @@
|
|
|
4539
5279
|
prefsStore = prefs;
|
|
4540
5280
|
|
|
4541
5281
|
if (typeof MutationObserver === "function" && top() !== null) {
|
|
4542
|
-
observer = new MutationObserver(
|
|
5282
|
+
observer = new MutationObserver(function (records) {
|
|
5283
|
+
if (passesSuspended()) return;
|
|
5284
|
+
/* One relevant record is enough: the pass itself is the expensive
|
|
5285
|
+
part, and it always looks at the whole sidebar. */
|
|
5286
|
+
var list = Array.isArray(records) ? records : [];
|
|
5287
|
+
var chain = sidebarChain();
|
|
5288
|
+
for (var i = 0; i < list.length; i += 1) {
|
|
5289
|
+
if (outsideSidebar(list[i] === undefined || list[i] === null ? null : list[i].target, chain)) {
|
|
5290
|
+
schedule();
|
|
5291
|
+
return;
|
|
5292
|
+
}
|
|
5293
|
+
}
|
|
5294
|
+
});
|
|
4543
5295
|
observer.observe(top(), {
|
|
4544
5296
|
childList: true,
|
|
4545
5297
|
subtree: true,
|
|
@@ -4578,23 +5330,27 @@
|
|
|
4578
5330
|
}, ColorsRow);
|
|
4579
5331
|
});
|
|
4580
5332
|
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
5333
|
+
if (SEARCH_ENABLED) {
|
|
5334
|
+
ctx.slots.inject("sidebar.panellist", function () {
|
|
5335
|
+
return ctx.slots.register({
|
|
5336
|
+
name: "sidebar.panellist",
|
|
5337
|
+
id: "ws-recency-search",
|
|
5338
|
+
order: 19,
|
|
5339
|
+
locale: NS,
|
|
5340
|
+
label: function () { return t("search.title"); },
|
|
5341
|
+
}, SearchPanelIcon);
|
|
5342
|
+
});
|
|
5343
|
+
|
|
5344
|
+
ctx.slots.inject("main", function () {
|
|
5345
|
+
return ctx.slots.register({
|
|
5346
|
+
name: "main",
|
|
5347
|
+
key: "ws-recency-search",
|
|
5348
|
+
locale: NS,
|
|
5349
|
+
store: prefs,
|
|
5350
|
+
}, SearchPanelPage);
|
|
5351
|
+
});
|
|
5352
|
+
}
|
|
4590
5353
|
|
|
4591
|
-
ctx.slots.inject("main", function () {
|
|
4592
|
-
return ctx.slots.register({
|
|
4593
|
-
name: "main",
|
|
4594
|
-
key: "ws-recency-search",
|
|
4595
|
-
locale: NS,
|
|
4596
|
-
}, SearchPanelPage);
|
|
4597
|
-
});
|
|
4598
5354
|
|
|
4599
5355
|
ctx.slots.inject("sidebar.panellist", function () {
|
|
4600
5356
|
return ctx.slots.register({
|
|
@@ -4704,6 +5460,16 @@
|
|
|
4704
5460
|
}, StatsMenuItem);
|
|
4705
5461
|
});
|
|
4706
5462
|
|
|
5463
|
+
ctx.slots.inject("sidebar.workspaces.session.menu.item", function () {
|
|
5464
|
+
return ctx.slots.register({
|
|
5465
|
+
name: "sidebar.workspaces.session.menu.item",
|
|
5466
|
+
id: "ws-recency-diagnose",
|
|
5467
|
+
order: 690,
|
|
5468
|
+
store: prefs,
|
|
5469
|
+
locale: NS,
|
|
5470
|
+
}, DiagnoseMenuItem);
|
|
5471
|
+
});
|
|
5472
|
+
|
|
4707
5473
|
ctx.slots.inject("sidebar.workspaces.session.menu.item", function () {
|
|
4708
5474
|
return ctx.slots.register({
|
|
4709
5475
|
name: "sidebar.workspaces.session.menu.item",
|
|
@@ -4741,6 +5507,15 @@
|
|
|
4741
5507
|
reveal: revealTurn,
|
|
4742
5508
|
jump: jumpToSearchHit,
|
|
4743
5509
|
turnRow: turnRowOf,
|
|
5510
|
+
hitRow: searchHitRow,
|
|
5511
|
+
shortId: shortSessionId,
|
|
5512
|
+
resumePasses: function () { suppressedUntil = 0; },
|
|
5513
|
+
};
|
|
5514
|
+
|
|
5515
|
+
/* The search feature ships disabled while its cost is being isolated;
|
|
5516
|
+
tests turn it on so the code stays covered. */
|
|
5517
|
+
exports.__setSearchEnabled = function (value) {
|
|
5518
|
+
SEARCH_ENABLED = value === true;
|
|
4744
5519
|
};
|
|
4745
5520
|
|
|
4746
5521
|
exports.name = "dsh-ws-recency";
|