@clagentic/console 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CREDITS.md +3 -0
- package/LICENSE +21 -0
- package/README.md +250 -0
- package/bin/cli.js +2812 -0
- package/lib/agents-favorites.js +164 -0
- package/lib/agents.js +282 -0
- package/lib/ask-user-mcp-server.js +120 -0
- package/lib/browser-mcp-server.js +484 -0
- package/lib/build-user-env.js +63 -0
- package/lib/certs/fullchain.pem +47 -0
- package/lib/certs/privkey.pem +5 -0
- package/lib/cli-sessions.js +265 -0
- package/lib/codex-defaults.js +18 -0
- package/lib/config.js +332 -0
- package/lib/crisis-safety.js +60 -0
- package/lib/daemon-projects.js +164 -0
- package/lib/daemon.js +1602 -0
- package/lib/dm.js +128 -0
- package/lib/ipc.js +125 -0
- package/lib/ipv4-only.js +39 -0
- package/lib/mcp-local.js +385 -0
- package/lib/notes.js +141 -0
- package/lib/os-users.js +529 -0
- package/lib/pages.js +1325 -0
- package/lib/project-connection.js +302 -0
- package/lib/project-external-trigger.js +236 -0
- package/lib/project-file-watch.js +120 -0
- package/lib/project-filesystem.js +528 -0
- package/lib/project-http.js +753 -0
- package/lib/project-image.js +95 -0
- package/lib/project-knowledge.js +88 -0
- package/lib/project-loop.js +1304 -0
- package/lib/project-mcp.js +374 -0
- package/lib/project-memory.js +39 -0
- package/lib/project-notifications.js +262 -0
- package/lib/project-sessions.js +1581 -0
- package/lib/project-user-mention.js +193 -0
- package/lib/project-user-message.js +628 -0
- package/lib/project.js +1303 -0
- package/lib/public/app.js +1031 -0
- package/lib/public/apple-touch-icon.png +0 -0
- package/lib/public/claude-code-avatar.png +0 -0
- package/lib/public/codex-avatar.png +0 -0
- package/lib/public/console-icon.png +0 -0
- package/lib/public/css/admin.css +736 -0
- package/lib/public/css/agent-picker.css +119 -0
- package/lib/public/css/base.css +235 -0
- package/lib/public/css/channel-layout.css +441 -0
- package/lib/public/css/command-palette.css +559 -0
- package/lib/public/css/debate.css +1609 -0
- package/lib/public/css/diff.css +139 -0
- package/lib/public/css/filebrowser.css +1976 -0
- package/lib/public/css/highlight.css +144 -0
- package/lib/public/css/home-hub.css +545 -0
- package/lib/public/css/icon-strip.css +1856 -0
- package/lib/public/css/input.css +1349 -0
- package/lib/public/css/loop.css +1248 -0
- package/lib/public/css/mention.css +317 -0
- package/lib/public/css/menus.css +857 -0
- package/lib/public/css/messages.css +1833 -0
- package/lib/public/css/mobile-nav.css +1332 -0
- package/lib/public/css/notifications-center.css +296 -0
- package/lib/public/css/overlays.css +1273 -0
- package/lib/public/css/playbook.css +264 -0
- package/lib/public/css/profile.css +397 -0
- package/lib/public/css/rewind.css +671 -0
- package/lib/public/css/scheduler-modal.css +1495 -0
- package/lib/public/css/scheduler.css +1420 -0
- package/lib/public/css/server-settings.css +909 -0
- package/lib/public/css/session-search.css +159 -0
- package/lib/public/css/sidebar.css +2012 -0
- package/lib/public/css/skills.css +789 -0
- package/lib/public/css/sticky-notes.css +854 -0
- package/lib/public/css/stt.css +155 -0
- package/lib/public/css/title-bar.css +674 -0
- package/lib/public/css/tooltip.css +67 -0
- package/lib/public/css/user-settings.css +702 -0
- package/lib/public/emoji-data.json +1 -0
- package/lib/public/favicon-banded-32.png +0 -0
- package/lib/public/favicon-banded.png +0 -0
- package/lib/public/favicon-dark.svg +32 -0
- package/lib/public/favicon.svg +32 -0
- package/lib/public/icon-192.png +0 -0
- package/lib/public/icon-512.png +0 -0
- package/lib/public/icon-banded-76.png +0 -0
- package/lib/public/icon-banded-96.png +0 -0
- package/lib/public/icon-mono.svg +25 -0
- package/lib/public/icons/email/gmail.svg +7 -0
- package/lib/public/icons/email/outlook.svg +35 -0
- package/lib/public/icons/email/yahoo.svg +1 -0
- package/lib/public/index.html +1946 -0
- package/lib/public/manifest.json +27 -0
- package/lib/public/markdown-worker.js +43 -0
- package/lib/public/marked.min.js +6 -0
- package/lib/public/modules/admin.js +954 -0
- package/lib/public/modules/agent-picker.js +429 -0
- package/lib/public/modules/app-connection.js +216 -0
- package/lib/public/modules/app-cursors.js +492 -0
- package/lib/public/modules/app-dm.js +265 -0
- package/lib/public/modules/app-favicon.js +231 -0
- package/lib/public/modules/app-header.js +242 -0
- package/lib/public/modules/app-home-hub.js +432 -0
- package/lib/public/modules/app-loop-ui.js +691 -0
- package/lib/public/modules/app-loop-wizard.js +439 -0
- package/lib/public/modules/app-messages.js +1415 -0
- package/lib/public/modules/app-misc.js +463 -0
- package/lib/public/modules/app-notifications.js +651 -0
- package/lib/public/modules/app-panels.js +1061 -0
- package/lib/public/modules/app-projects.js +875 -0
- package/lib/public/modules/app-rate-limit.js +529 -0
- package/lib/public/modules/app-rendering.js +739 -0
- package/lib/public/modules/app-skills-install.js +285 -0
- package/lib/public/modules/avatar.js +36 -0
- package/lib/public/modules/command-palette.js +491 -0
- package/lib/public/modules/console-logo.js +162 -0
- package/lib/public/modules/context-sources.js +365 -0
- package/lib/public/modules/diff.js +412 -0
- package/lib/public/modules/dom-refs.js +21 -0
- package/lib/public/modules/emoji-picker.js +222 -0
- package/lib/public/modules/events.js +21 -0
- package/lib/public/modules/filebrowser.js +1966 -0
- package/lib/public/modules/fileicons.js +172 -0
- package/lib/public/modules/icons.js +80 -0
- package/lib/public/modules/input.js +1102 -0
- package/lib/public/modules/longpress.js +74 -0
- package/lib/public/modules/markdown.js +486 -0
- package/lib/public/modules/mcp-ui.js +295 -0
- package/lib/public/modules/mention.js +1093 -0
- package/lib/public/modules/notifications.js +613 -0
- package/lib/public/modules/playbook.js +578 -0
- package/lib/public/modules/profile.js +594 -0
- package/lib/public/modules/project-settings.js +849 -0
- package/lib/public/modules/project-switcher.js +375 -0
- package/lib/public/modules/qrcode.js +87 -0
- package/lib/public/modules/rewind.js +381 -0
- package/lib/public/modules/scheduler-config.js +1611 -0
- package/lib/public/modules/scheduler-history.js +131 -0
- package/lib/public/modules/scheduler.js +1689 -0
- package/lib/public/modules/server-settings.js +842 -0
- package/lib/public/modules/session-search.js +456 -0
- package/lib/public/modules/settings-defaults.js +253 -0
- package/lib/public/modules/sidebar-mobile.js +1425 -0
- package/lib/public/modules/sidebar-projects.js +2022 -0
- package/lib/public/modules/sidebar-sessions.js +1548 -0
- package/lib/public/modules/sidebar-users.js +449 -0
- package/lib/public/modules/sidebar.js +348 -0
- package/lib/public/modules/skills.js +793 -0
- package/lib/public/modules/state.js +3 -0
- package/lib/public/modules/sticky-notes.js +1221 -0
- package/lib/public/modules/store.js +34 -0
- package/lib/public/modules/stt.js +266 -0
- package/lib/public/modules/terminal.js +987 -0
- package/lib/public/modules/theme.js +812 -0
- package/lib/public/modules/tool-palette.js +562 -0
- package/lib/public/modules/tools.js +2285 -0
- package/lib/public/modules/tooltip.js +150 -0
- package/lib/public/modules/user-settings.js +544 -0
- package/lib/public/modules/utils.js +56 -0
- package/lib/public/modules/ws-ref.js +26 -0
- package/lib/public/style.css +34 -0
- package/lib/public/sw.js +159 -0
- package/lib/push.js +149 -0
- package/lib/scheduler.js +471 -0
- package/lib/sdk-bridge.js +1792 -0
- package/lib/sdk-message-processor.js +740 -0
- package/lib/sdk-message-queue.js +42 -0
- package/lib/sdk-skill-discovery.js +131 -0
- package/lib/sdk-worker.js +677 -0
- package/lib/server-admin.js +712 -0
- package/lib/server-auth.js +737 -0
- package/lib/server-dm.js +170 -0
- package/lib/server-palette.js +104 -0
- package/lib/server-settings.js +553 -0
- package/lib/server-skills.js +280 -0
- package/lib/server.js +1390 -0
- package/lib/session-search.js +693 -0
- package/lib/sessions.js +946 -0
- package/lib/smtp.js +221 -0
- package/lib/terminal-manager.js +219 -0
- package/lib/terminal.js +39 -0
- package/lib/themes/ayu-light.json +9 -0
- package/lib/themes/catppuccin-latte.json +9 -0
- package/lib/themes/catppuccin-mocha.json +9 -0
- package/lib/themes/clagentic-dark.json +10 -0
- package/lib/themes/clagentic-light.json +10 -0
- package/lib/themes/dracula.json +9 -0
- package/lib/themes/everforest-light.json +9 -0
- package/lib/themes/everforest.json +9 -0
- package/lib/themes/github-light.json +9 -0
- package/lib/themes/gruvbox-dark.json +9 -0
- package/lib/themes/gruvbox-light.json +9 -0
- package/lib/themes/monokai.json +9 -0
- package/lib/themes/nord-light.json +9 -0
- package/lib/themes/nord.json +9 -0
- package/lib/themes/one-dark.json +9 -0
- package/lib/themes/one-light.json +9 -0
- package/lib/themes/rose-pine-dawn.json +9 -0
- package/lib/themes/rose-pine.json +9 -0
- package/lib/themes/solarized-dark.json +9 -0
- package/lib/themes/solarized-light.json +9 -0
- package/lib/themes/tokyo-night-light.json +9 -0
- package/lib/themes/tokyo-night.json +9 -0
- package/lib/updater.js +124 -0
- package/lib/user-presence.js +92 -0
- package/lib/users-auth.js +146 -0
- package/lib/users-permissions.js +118 -0
- package/lib/users-preferences.js +254 -0
- package/lib/users.js +465 -0
- package/lib/utils.js +64 -0
- package/lib/worktree.js +134 -0
- package/lib/ws-schema.js +464 -0
- package/lib/yoke/adapters/claude-worker.js +759 -0
- package/lib/yoke/adapters/claude.js +1599 -0
- package/lib/yoke/adapters/codex.js +1559 -0
- package/lib/yoke/codex-app-server.js +352 -0
- package/lib/yoke/index.js +319 -0
- package/lib/yoke/instructions.js +61 -0
- package/lib/yoke/interface.js +98 -0
- package/lib/yoke/mcp-bridge-server.js +302 -0
- package/lib/yoke/package.json +7 -0
- package/package.json +72 -0
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
// --- In-session search (Cmd+F / Ctrl+F) ---
|
|
2
|
+
import { escapeHtml } from './utils.js';
|
|
3
|
+
import { iconHtml, refreshIcons } from './icons.js';
|
|
4
|
+
|
|
5
|
+
var ctx = null;
|
|
6
|
+
var searchBarEl = null;
|
|
7
|
+
var searchInputEl = null;
|
|
8
|
+
var matchCountEl = null;
|
|
9
|
+
var currentQuery = "";
|
|
10
|
+
var matches = []; // DOM highlight marks (for loaded messages)
|
|
11
|
+
var currentMatchIndex = -1;
|
|
12
|
+
var highlightClass = "session-search-highlight";
|
|
13
|
+
var activeHighlightClass = "session-search-highlight-active";
|
|
14
|
+
|
|
15
|
+
// Timeline state
|
|
16
|
+
var timelineEl = null;
|
|
17
|
+
var timelineScrollHandler = null;
|
|
18
|
+
var serverHits = []; // full history hits from server
|
|
19
|
+
var serverTotal = 0;
|
|
20
|
+
var pendingScrollTarget = null;
|
|
21
|
+
|
|
22
|
+
function initSessionSearch(context) {
|
|
23
|
+
ctx = context;
|
|
24
|
+
createSearchBar();
|
|
25
|
+
document.addEventListener("keydown", function (e) {
|
|
26
|
+
var isMod = e.metaKey || e.ctrlKey;
|
|
27
|
+
if (isMod && e.key === "f") {
|
|
28
|
+
e.preventDefault();
|
|
29
|
+
openSearch();
|
|
30
|
+
}
|
|
31
|
+
if (e.key === "Escape" && isSearchOpen()) {
|
|
32
|
+
e.preventDefault();
|
|
33
|
+
closeSearch();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function createSearchBar() {
|
|
39
|
+
searchBarEl = document.createElement("div");
|
|
40
|
+
searchBarEl.id = "session-search-bar";
|
|
41
|
+
searchBarEl.className = "session-search-bar hidden";
|
|
42
|
+
searchBarEl.innerHTML =
|
|
43
|
+
'<div class="session-search-inner">' +
|
|
44
|
+
'<input type="text" id="find-in-session-input" placeholder="Search in this session..." autocomplete="off" spellcheck="false">' +
|
|
45
|
+
'<span class="session-search-count" id="find-in-session-count"></span>' +
|
|
46
|
+
'<button class="session-search-btn" id="find-in-session-prev" title="Previous (Shift+Enter)" type="button"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="18 15 12 9 6 15"/></svg></button>' +
|
|
47
|
+
'<button class="session-search-btn" id="find-in-session-next" title="Next (Enter)" type="button"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg></button>' +
|
|
48
|
+
'<button class="session-search-btn" id="find-in-session-close" title="Close (Esc)" type="button"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg></button>' +
|
|
49
|
+
'</div>';
|
|
50
|
+
|
|
51
|
+
// Insert at top of #app
|
|
52
|
+
var appEl = ctx.messagesEl.parentElement;
|
|
53
|
+
appEl.insertBefore(searchBarEl, appEl.firstChild);
|
|
54
|
+
|
|
55
|
+
searchInputEl = document.getElementById("find-in-session-input");
|
|
56
|
+
matchCountEl = document.getElementById("find-in-session-count");
|
|
57
|
+
|
|
58
|
+
var debounceTimer = null;
|
|
59
|
+
searchInputEl.addEventListener("input", function () {
|
|
60
|
+
clearTimeout(debounceTimer);
|
|
61
|
+
debounceTimer = setTimeout(function () {
|
|
62
|
+
performSearch(searchInputEl.value);
|
|
63
|
+
}, 250);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
searchInputEl.addEventListener("keydown", function (e) {
|
|
67
|
+
if (e.key === "Enter") {
|
|
68
|
+
e.preventDefault();
|
|
69
|
+
if (e.shiftKey) {
|
|
70
|
+
goToPrevMatch();
|
|
71
|
+
} else {
|
|
72
|
+
goToNextMatch();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (e.key === "Escape") {
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
closeSearch();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
document.getElementById("find-in-session-prev").addEventListener("click", function () {
|
|
82
|
+
goToPrevMatch();
|
|
83
|
+
});
|
|
84
|
+
document.getElementById("find-in-session-next").addEventListener("click", function () {
|
|
85
|
+
goToNextMatch();
|
|
86
|
+
});
|
|
87
|
+
document.getElementById("find-in-session-close").addEventListener("click", function () {
|
|
88
|
+
closeSearch();
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function isSearchOpen() {
|
|
93
|
+
return searchBarEl && !searchBarEl.classList.contains("hidden");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function openSearch(prefill) {
|
|
97
|
+
if (!searchBarEl) return;
|
|
98
|
+
searchBarEl.classList.remove("hidden");
|
|
99
|
+
var btn = document.getElementById("find-in-session-btn");
|
|
100
|
+
if (btn) btn.classList.add("active");
|
|
101
|
+
if (typeof prefill === "string" && prefill) {
|
|
102
|
+
searchInputEl.value = prefill;
|
|
103
|
+
performSearch(prefill);
|
|
104
|
+
}
|
|
105
|
+
searchInputEl.focus();
|
|
106
|
+
searchInputEl.select();
|
|
107
|
+
if (!prefill && searchInputEl.value) {
|
|
108
|
+
performSearch(searchInputEl.value);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function closeSearch() {
|
|
113
|
+
if (!searchBarEl) return;
|
|
114
|
+
searchBarEl.classList.add("hidden");
|
|
115
|
+
var btn = document.getElementById("find-in-session-btn");
|
|
116
|
+
if (btn) btn.classList.remove("active");
|
|
117
|
+
clearHighlights();
|
|
118
|
+
removeTimeline();
|
|
119
|
+
currentQuery = "";
|
|
120
|
+
matches = [];
|
|
121
|
+
currentMatchIndex = -1;
|
|
122
|
+
serverHits = [];
|
|
123
|
+
serverTotal = 0;
|
|
124
|
+
matchCountEl.textContent = "";
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function toggleSearch() {
|
|
128
|
+
if (isSearchOpen()) {
|
|
129
|
+
closeSearch();
|
|
130
|
+
} else {
|
|
131
|
+
openSearch();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function performSearch(query) {
|
|
136
|
+
clearHighlights();
|
|
137
|
+
removeTimeline();
|
|
138
|
+
matches = [];
|
|
139
|
+
currentMatchIndex = -1;
|
|
140
|
+
serverHits = [];
|
|
141
|
+
serverTotal = 0;
|
|
142
|
+
currentQuery = query.trim();
|
|
143
|
+
|
|
144
|
+
if (!currentQuery) {
|
|
145
|
+
matchCountEl.textContent = "";
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Highlight in currently loaded DOM
|
|
150
|
+
highlightLoadedMessages();
|
|
151
|
+
|
|
152
|
+
// Request full-history search from server
|
|
153
|
+
if (ctx.ws && ctx.ws.readyState === 1) {
|
|
154
|
+
ctx.ws.send(JSON.stringify({ type: "search_session_content", query: currentQuery, source: "find_in_session" }));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function highlightLoadedMessages() {
|
|
159
|
+
var messagesEl = ctx.messagesEl;
|
|
160
|
+
var msgEls = messagesEl.querySelectorAll(".msg-user, .msg-assistant");
|
|
161
|
+
var queryLower = currentQuery.toLowerCase();
|
|
162
|
+
|
|
163
|
+
for (var i = 0; i < msgEls.length; i++) {
|
|
164
|
+
var contentEl = msgEls[i].querySelector(".bubble") || msgEls[i].querySelector(".md-content");
|
|
165
|
+
if (!contentEl) continue;
|
|
166
|
+
highlightInElement(contentEl, queryLower);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
matches = Array.from(messagesEl.querySelectorAll("." + highlightClass));
|
|
170
|
+
|
|
171
|
+
if (matches.length > 0) {
|
|
172
|
+
currentMatchIndex = 0;
|
|
173
|
+
setActiveMatch(0);
|
|
174
|
+
matchCountEl.textContent = "1 / " + matches.length;
|
|
175
|
+
} else {
|
|
176
|
+
matchCountEl.textContent = "Searching...";
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Handle server response with full-history search results
|
|
181
|
+
function handleFindInSessionResults(msg) {
|
|
182
|
+
if (!isSearchOpen()) return;
|
|
183
|
+
if (msg.query !== currentQuery) return; // stale
|
|
184
|
+
|
|
185
|
+
serverHits = msg.hits || [];
|
|
186
|
+
serverTotal = msg.total || 0;
|
|
187
|
+
|
|
188
|
+
// Update count to reflect total server hits
|
|
189
|
+
if (serverHits.length > 0) {
|
|
190
|
+
// Re-highlight loaded messages to get accurate DOM match count
|
|
191
|
+
clearHighlights();
|
|
192
|
+
highlightLoadedMessages();
|
|
193
|
+
if (matches.length > 0) {
|
|
194
|
+
matchCountEl.textContent = "1 / " + matches.length + " (" + serverHits.length + " total)";
|
|
195
|
+
} else {
|
|
196
|
+
matchCountEl.textContent = serverHits.length + " matches";
|
|
197
|
+
}
|
|
198
|
+
buildTimeline();
|
|
199
|
+
} else {
|
|
200
|
+
matchCountEl.textContent = "No results";
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Called after older history is prepended to DOM
|
|
205
|
+
function onHistoryPrepended() {
|
|
206
|
+
if (!pendingScrollTarget) return;
|
|
207
|
+
var target = pendingScrollTarget;
|
|
208
|
+
pendingScrollTarget = null;
|
|
209
|
+
// Re-highlight with current query
|
|
210
|
+
if (currentQuery && isSearchOpen()) {
|
|
211
|
+
clearHighlights();
|
|
212
|
+
highlightLoadedMessages();
|
|
213
|
+
}
|
|
214
|
+
requestAnimationFrame(function() {
|
|
215
|
+
findAndScrollToMatch(target.snippet, target.query);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// --- Timeline (scroll map) ---
|
|
220
|
+
function buildTimeline() {
|
|
221
|
+
removeTimeline();
|
|
222
|
+
if (serverHits.length === 0) return;
|
|
223
|
+
|
|
224
|
+
var messagesEl = ctx.messagesEl;
|
|
225
|
+
var appEl = messagesEl.parentElement;
|
|
226
|
+
|
|
227
|
+
timelineEl = document.createElement("div");
|
|
228
|
+
timelineEl.className = "find-in-session-timeline";
|
|
229
|
+
timelineEl.id = "find-in-session-timeline";
|
|
230
|
+
|
|
231
|
+
var track = document.createElement("div");
|
|
232
|
+
track.className = "rewind-timeline-track";
|
|
233
|
+
track.dataset.historyTotal = serverTotal;
|
|
234
|
+
|
|
235
|
+
var viewport = document.createElement("div");
|
|
236
|
+
viewport.className = "rewind-timeline-viewport";
|
|
237
|
+
track.appendChild(viewport);
|
|
238
|
+
|
|
239
|
+
for (var i = 0; i < serverHits.length; i++) {
|
|
240
|
+
var hit = serverHits[i];
|
|
241
|
+
var pct = serverTotal <= 1 ? 50 : 6 + (hit.historyIndex / (serverTotal - 1)) * 88;
|
|
242
|
+
|
|
243
|
+
var snippetText = hit.snippet;
|
|
244
|
+
if (snippetText.length > 24) snippetText = snippetText.substring(0, 24) + "\u2026";
|
|
245
|
+
|
|
246
|
+
var dateText = "";
|
|
247
|
+
if (hit.ts) {
|
|
248
|
+
var d = new Date(hit.ts);
|
|
249
|
+
var mon = d.getMonth() + 1;
|
|
250
|
+
var day = d.getDate();
|
|
251
|
+
var hr = d.getHours();
|
|
252
|
+
var min = d.getMinutes();
|
|
253
|
+
dateText = mon + "/" + day + " " + (hr < 10 ? "0" : "") + hr + ":" + (min < 10 ? "0" : "") + min;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
var marker = document.createElement("div");
|
|
257
|
+
marker.className = "rewind-timeline-marker search-hit-marker";
|
|
258
|
+
marker.innerHTML = iconHtml("search") +
|
|
259
|
+
(dateText ? '<span class="marker-date">' + dateText + '</span>' : '') +
|
|
260
|
+
'<span class="marker-text">' + escapeHtml(snippetText) + '</span>';
|
|
261
|
+
marker.style.top = pct + "%";
|
|
262
|
+
marker.dataset.historyIndex = hit.historyIndex;
|
|
263
|
+
|
|
264
|
+
(function(hitData, markerEl) {
|
|
265
|
+
markerEl.addEventListener("click", function() {
|
|
266
|
+
scrollToSearchHit(hitData.historyIndex, hitData.snippet, currentQuery);
|
|
267
|
+
});
|
|
268
|
+
})(hit, marker);
|
|
269
|
+
|
|
270
|
+
track.appendChild(marker);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
timelineEl.appendChild(track);
|
|
274
|
+
|
|
275
|
+
// Position timeline to align with messages area
|
|
276
|
+
var titleBarEl = document.querySelector(".title-bar-content");
|
|
277
|
+
var inputAreaEl = document.getElementById("input-area");
|
|
278
|
+
var appRect = appEl.getBoundingClientRect();
|
|
279
|
+
var titleBarRect = titleBarEl ? titleBarEl.getBoundingClientRect() : { bottom: appRect.top };
|
|
280
|
+
var inputRect = inputAreaEl.getBoundingClientRect();
|
|
281
|
+
|
|
282
|
+
timelineEl.style.top = (titleBarRect.bottom - appRect.top + 4) + "px";
|
|
283
|
+
timelineEl.style.bottom = (appRect.bottom - inputRect.top + 4) + "px";
|
|
284
|
+
|
|
285
|
+
appEl.appendChild(timelineEl);
|
|
286
|
+
refreshIcons();
|
|
287
|
+
|
|
288
|
+
timelineScrollHandler = function() { updateTimelineViewport(track, viewport); };
|
|
289
|
+
messagesEl.addEventListener("scroll", timelineScrollHandler);
|
|
290
|
+
updateTimelineViewport(track, viewport);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function removeTimeline() {
|
|
294
|
+
if (timelineEl) {
|
|
295
|
+
timelineEl.remove();
|
|
296
|
+
timelineEl = null;
|
|
297
|
+
}
|
|
298
|
+
if (timelineScrollHandler && ctx.messagesEl) {
|
|
299
|
+
ctx.messagesEl.removeEventListener("scroll", timelineScrollHandler);
|
|
300
|
+
timelineScrollHandler = null;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function updateTimelineViewport(track, viewport) {
|
|
305
|
+
if (!track) return;
|
|
306
|
+
var messagesEl = ctx.messagesEl;
|
|
307
|
+
var scrollH = messagesEl.scrollHeight;
|
|
308
|
+
var viewH = messagesEl.clientHeight;
|
|
309
|
+
|
|
310
|
+
var historyFrom = ctx.getHistoryFrom ? ctx.getHistoryFrom() : 0;
|
|
311
|
+
var total = parseInt(track.dataset.historyTotal || "0", 10) || 1;
|
|
312
|
+
var timelineStart = 6 + (historyFrom / (total - 1 || 1)) * 88;
|
|
313
|
+
var timelineEnd = 94;
|
|
314
|
+
var timelineRange = timelineEnd - timelineStart;
|
|
315
|
+
|
|
316
|
+
if (scrollH <= viewH) {
|
|
317
|
+
viewport.style.top = timelineStart + "%";
|
|
318
|
+
viewport.style.height = timelineRange + "%";
|
|
319
|
+
} else {
|
|
320
|
+
var scrollFrac = messagesEl.scrollTop / scrollH;
|
|
321
|
+
var viewFrac = viewH / scrollH;
|
|
322
|
+
viewport.style.top = (timelineStart + scrollFrac * timelineRange) + "%";
|
|
323
|
+
viewport.style.height = (viewFrac * timelineRange) + "%";
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function scrollToSearchHit(historyIndex, snippet, query) {
|
|
328
|
+
var historyFrom = ctx.getHistoryFrom ? ctx.getHistoryFrom() : 0;
|
|
329
|
+
if (historyIndex < historyFrom) {
|
|
330
|
+
// Need to load older history first
|
|
331
|
+
pendingScrollTarget = { historyIndex: historyIndex, snippet: snippet, query: query };
|
|
332
|
+
if (ctx.ws && ctx.ws.readyState === 1) {
|
|
333
|
+
ctx.ws.send(JSON.stringify({ type: "load_more_history", before: historyFrom, target: historyIndex }));
|
|
334
|
+
}
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
findAndScrollToMatch(snippet, query);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function findAndScrollToMatch(snippet, query) {
|
|
341
|
+
var messagesEl = ctx.messagesEl;
|
|
342
|
+
var q = query.toLowerCase();
|
|
343
|
+
var allMsgs = messagesEl.querySelectorAll(".msg-user, .msg-assistant");
|
|
344
|
+
var cleanSnippet = snippet.replace(/^\u2026/, "").replace(/\u2026$/, "");
|
|
345
|
+
|
|
346
|
+
for (var i = 0; i < allMsgs.length; i++) {
|
|
347
|
+
var msgEl = allMsgs[i];
|
|
348
|
+
var textEl = msgEl.querySelector(".bubble") || msgEl.querySelector(".md-content");
|
|
349
|
+
if (!textEl) continue;
|
|
350
|
+
var text = textEl.textContent || "";
|
|
351
|
+
if (text.indexOf(cleanSnippet) !== -1) {
|
|
352
|
+
msgEl.scrollIntoView({ behavior: "smooth", block: "center" });
|
|
353
|
+
msgEl.classList.remove("search-blink");
|
|
354
|
+
void msgEl.offsetWidth;
|
|
355
|
+
msgEl.classList.add("search-blink");
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
// Fallback: any element containing the query
|
|
360
|
+
for (var j = 0; j < allMsgs.length; j++) {
|
|
361
|
+
var el = allMsgs[j];
|
|
362
|
+
var tEl = el.querySelector(".bubble") || el.querySelector(".md-content");
|
|
363
|
+
if (!tEl) continue;
|
|
364
|
+
if ((tEl.textContent || "").toLowerCase().indexOf(q) !== -1) {
|
|
365
|
+
el.scrollIntoView({ behavior: "smooth", block: "center" });
|
|
366
|
+
el.classList.remove("search-blink");
|
|
367
|
+
void el.offsetWidth;
|
|
368
|
+
el.classList.add("search-blink");
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// --- DOM highlighting ---
|
|
375
|
+
function highlightInElement(el, queryLower) {
|
|
376
|
+
var walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT, null, false);
|
|
377
|
+
var textNodes = [];
|
|
378
|
+
var node;
|
|
379
|
+
while ((node = walker.nextNode())) {
|
|
380
|
+
textNodes.push(node);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
for (var i = 0; i < textNodes.length; i++) {
|
|
384
|
+
var textNode = textNodes[i];
|
|
385
|
+
var parent = textNode.parentNode;
|
|
386
|
+
if (!parent || parent.classList && parent.classList.contains(highlightClass)) continue;
|
|
387
|
+
if (parent.tagName === "BUTTON" || parent.tagName === "SCRIPT" || parent.tagName === "STYLE") continue;
|
|
388
|
+
|
|
389
|
+
var text = textNode.nodeValue;
|
|
390
|
+
var textLower = text.toLowerCase();
|
|
391
|
+
var idx = textLower.indexOf(queryLower);
|
|
392
|
+
if (idx === -1) continue;
|
|
393
|
+
|
|
394
|
+
var frag = document.createDocumentFragment();
|
|
395
|
+
var lastIdx = 0;
|
|
396
|
+
|
|
397
|
+
while (idx !== -1) {
|
|
398
|
+
if (idx > lastIdx) {
|
|
399
|
+
frag.appendChild(document.createTextNode(text.substring(lastIdx, idx)));
|
|
400
|
+
}
|
|
401
|
+
var mark = document.createElement("mark");
|
|
402
|
+
mark.className = highlightClass;
|
|
403
|
+
mark.textContent = text.substring(idx, idx + currentQuery.length);
|
|
404
|
+
frag.appendChild(mark);
|
|
405
|
+
lastIdx = idx + currentQuery.length;
|
|
406
|
+
idx = textLower.indexOf(queryLower, lastIdx);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
if (lastIdx < text.length) {
|
|
410
|
+
frag.appendChild(document.createTextNode(text.substring(lastIdx)));
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
parent.replaceChild(frag, textNode);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function clearHighlights() {
|
|
418
|
+
var messagesEl = ctx.messagesEl;
|
|
419
|
+
var marks = messagesEl.querySelectorAll("mark." + highlightClass);
|
|
420
|
+
for (var i = 0; i < marks.length; i++) {
|
|
421
|
+
var mark = marks[i];
|
|
422
|
+
var parent = mark.parentNode;
|
|
423
|
+
parent.replaceChild(document.createTextNode(mark.textContent), mark);
|
|
424
|
+
parent.normalize();
|
|
425
|
+
}
|
|
426
|
+
matches = [];
|
|
427
|
+
currentMatchIndex = -1;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
function setActiveMatch(index) {
|
|
431
|
+
var prev = ctx.messagesEl.querySelector("." + activeHighlightClass);
|
|
432
|
+
if (prev) prev.classList.remove(activeHighlightClass);
|
|
433
|
+
|
|
434
|
+
if (index >= 0 && index < matches.length) {
|
|
435
|
+
matches[index].classList.add(activeHighlightClass);
|
|
436
|
+
matches[index].scrollIntoView({ behavior: "smooth", block: "center" });
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function goToNextMatch() {
|
|
441
|
+
if (matches.length === 0) return;
|
|
442
|
+
currentMatchIndex = (currentMatchIndex + 1) % matches.length;
|
|
443
|
+
setActiveMatch(currentMatchIndex);
|
|
444
|
+
matchCountEl.textContent = (currentMatchIndex + 1) + " / " + matches.length +
|
|
445
|
+
(serverHits.length > matches.length ? " (" + serverHits.length + " total)" : "");
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function goToPrevMatch() {
|
|
449
|
+
if (matches.length === 0) return;
|
|
450
|
+
currentMatchIndex = (currentMatchIndex - 1 + matches.length) % matches.length;
|
|
451
|
+
setActiveMatch(currentMatchIndex);
|
|
452
|
+
matchCountEl.textContent = (currentMatchIndex + 1) + " / " + matches.length +
|
|
453
|
+
(serverHits.length > matches.length ? " (" + serverHits.length + " total)" : "");
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
export { initSessionSearch, openSearch, closeSearch, toggleSearch, isSearchOpen, handleFindInSessionResults, onHistoryPrepended };
|