gaard-client 0.2.9__tar.gz → 0.2.11__tar.gz
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.
- {gaard_client-0.2.9 → gaard_client-0.2.11}/PKG-INFO +2 -2
- {gaard_client-0.2.9 → gaard_client-0.2.11}/pyproject.toml +8 -2
- {gaard_client-0.2.9 → gaard_client-0.2.11}/src/gaard_client/cli_commands.py +2 -2
- {gaard_client-0.2.9 → gaard_client-0.2.11}/src/gaard_client/client-web/assets/main.js +325 -28
- {gaard_client-0.2.9 → gaard_client-0.2.11}/src/gaard_client/client-web/assets/styles.css +10 -0
- {gaard_client-0.2.9 → gaard_client-0.2.11}/src/gaard_client/main.py +113 -50
- {gaard_client-0.2.9 → gaard_client-0.2.11}/src/gaard_client.egg-info/PKG-INFO +2 -2
- {gaard_client-0.2.9 → gaard_client-0.2.11}/src/gaard_client.egg-info/requires.txt +1 -1
- {gaard_client-0.2.9 → gaard_client-0.2.11}/tests/test_cli.py +3 -2
- {gaard_client-0.2.9 → gaard_client-0.2.11}/tests/test_client_app.py +152 -91
- {gaard_client-0.2.9 → gaard_client-0.2.11}/README.md +0 -0
- {gaard_client-0.2.9 → gaard_client-0.2.11}/setup.cfg +0 -0
- {gaard_client-0.2.9 → gaard_client-0.2.11}/src/gaard_client/__init__.py +0 -0
- {gaard_client-0.2.9 → gaard_client-0.2.11}/src/gaard_client/cli.py +0 -0
- {gaard_client-0.2.9 → gaard_client-0.2.11}/src/gaard_client/client-web/assets/getgaard.svg +0 -0
- {gaard_client-0.2.9 → gaard_client-0.2.11}/src/gaard_client/client-web/index.html +0 -0
- {gaard_client-0.2.9 → gaard_client-0.2.11}/src/gaard_client.egg-info/SOURCES.txt +0 -0
- {gaard_client-0.2.9 → gaard_client-0.2.11}/src/gaard_client.egg-info/dependency_links.txt +0 -0
- {gaard_client-0.2.9 → gaard_client-0.2.11}/src/gaard_client.egg-info/entry_points.txt +0 -0
- {gaard_client-0.2.9 → gaard_client-0.2.11}/src/gaard_client.egg-info/top_level.txt +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: gaard-client
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.11
|
|
4
4
|
Summary: GAARD frontend web services providing client interface
|
|
5
5
|
Requires-Python: >=3.11
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
7
|
-
Requires-Dist: gaard-plugin-api<0.3.0,>=0.2.
|
|
7
|
+
Requires-Dist: gaard-plugin-api<0.3.0,>=0.2.11
|
|
8
8
|
Requires-Dist: fastapi>=0.111.0
|
|
9
9
|
Requires-Dist: uvicorn[standard]>=0.30.0
|
|
10
10
|
Requires-Dist: pydantic>=2.7.0
|
|
@@ -4,13 +4,13 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "gaard-client"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.11"
|
|
8
8
|
description = "GAARD frontend web services providing client interface"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.11"
|
|
11
11
|
|
|
12
12
|
dependencies = [
|
|
13
|
-
"gaard-plugin-api>=0.2.
|
|
13
|
+
"gaard-plugin-api>=0.2.11,<0.3.0",
|
|
14
14
|
"fastapi>=0.111.0",
|
|
15
15
|
"uvicorn[standard]>=0.30.0",
|
|
16
16
|
"pydantic>=2.7.0",
|
|
@@ -46,5 +46,11 @@ gaard_client = [
|
|
|
46
46
|
line-length = 100
|
|
47
47
|
target-version = "py311"
|
|
48
48
|
|
|
49
|
+
[tool.ruff.flake8-bugbear]
|
|
50
|
+
extend-immutable-calls = ["fastapi.Depends", "fastapi.File", "fastapi.param_functions.Depends", "fastapi.param_functions.File", "fastapi.params.Depends", "fastapi.params.File"]
|
|
51
|
+
|
|
52
|
+
[tool.ruff.lint.per-file-ignores]
|
|
53
|
+
"tests/*.py" = ["PYI034", "PYI036"]
|
|
54
|
+
|
|
49
55
|
[tool.pytest.ini_options]
|
|
50
56
|
testpaths = ["tests"]
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
import os
|
|
3
|
+
import os as os
|
|
4
4
|
from argparse import ArgumentParser, ArgumentTypeError, Namespace, _SubParsersAction
|
|
5
5
|
from urllib.parse import urlparse
|
|
6
6
|
|
|
7
|
-
import uvicorn
|
|
7
|
+
import uvicorn as uvicorn
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
def normalize_api_url(value: str) -> str:
|
|
@@ -8,6 +8,7 @@ var storedRole = localStorage.getItem("gaard_client_role") || "";
|
|
|
8
8
|
var storedMustChangePassword = localStorage.getItem("gaard_client_must_change_password") === "true";
|
|
9
9
|
var storedEnterpriseAccess = localStorage.getItem("gaard_client_enterprise_access") === "true";
|
|
10
10
|
var storedActiveView = localStorage.getItem("gaard_client_active_view") || "";
|
|
11
|
+
var storedConversationId = localStorage.getItem("gaard_client_active_conversation_id") || "";
|
|
11
12
|
var state = {
|
|
12
13
|
backendUrl: configuredBackendUrl,
|
|
13
14
|
token: storedToken,
|
|
@@ -20,7 +21,11 @@ var state = {
|
|
|
20
21
|
queryMode: normalizeQueryMode(params.get("mode")),
|
|
21
22
|
messages: [],
|
|
22
23
|
nextMessageId: 1,
|
|
23
|
-
conversationId:
|
|
24
|
+
conversationId: storedConversationId,
|
|
25
|
+
conversations: [],
|
|
26
|
+
conversationsLoaded: false,
|
|
27
|
+
conversationsLoading: false,
|
|
28
|
+
conversationsError: "",
|
|
24
29
|
pending: false,
|
|
25
30
|
error: "",
|
|
26
31
|
apiError: null,
|
|
@@ -288,6 +293,11 @@ function renderIcon(name) {
|
|
|
288
293
|
<path d="M12 20h9" />
|
|
289
294
|
<path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z" />
|
|
290
295
|
</svg>`,
|
|
296
|
+
copy: `
|
|
297
|
+
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
|
298
|
+
<rect x="9" y="9" width="11" height="11" rx="2" />
|
|
299
|
+
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" />
|
|
300
|
+
</svg>`,
|
|
291
301
|
chevronDown: `
|
|
292
302
|
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
|
293
303
|
<path d="m6 9 6 6 6-6" />
|
|
@@ -974,27 +984,34 @@ function renderIssuesTable() {
|
|
|
974
984
|
<button class="link-button" type="button" aria-disabled="true">View all issues</button>`;
|
|
975
985
|
}
|
|
976
986
|
function renderQueriesView() {
|
|
977
|
-
const
|
|
987
|
+
const conversations = state.conversations;
|
|
978
988
|
return `
|
|
979
989
|
<section class="placeholder-view">
|
|
980
990
|
<div class="placeholder-intro">
|
|
981
991
|
<span>Marked feature</span>
|
|
982
992
|
<h1>My Queries</h1>
|
|
983
|
-
<p>
|
|
993
|
+
<p>Saved chat threads and their queries are loaded from the GAARD API.</p>
|
|
984
994
|
</div>
|
|
995
|
+
${state.conversationsError ? `<div class="source-error datasource-error" role="alert">${escapeHtml(state.conversationsError)}</div>` : ""}
|
|
985
996
|
<div class="placeholder-list query-list">
|
|
986
|
-
${
|
|
987
|
-
<
|
|
988
|
-
${renderIcon(
|
|
997
|
+
${state.conversationsLoading ? `
|
|
998
|
+
<div class="placeholder-item muted">
|
|
999
|
+
${renderIcon("history")}
|
|
1000
|
+
<span><strong>Loading conversations...</strong><small>Please wait.</small></span>
|
|
1001
|
+
</div>` : ""}
|
|
1002
|
+
${!state.conversationsLoading && conversations.length ? conversations.map((conversation) => `
|
|
1003
|
+
<button type="button" data-open-conversation="${escapeHtml(conversation.id)}" class="placeholder-item ${conversation.id === state.conversationId ? "active" : ""}">
|
|
1004
|
+
${renderIcon("history")}
|
|
989
1005
|
<span>
|
|
990
|
-
<strong>${escapeHtml(
|
|
991
|
-
<small>${escapeHtml(
|
|
1006
|
+
<strong>${escapeHtml(conversation.title || conversation.latest_question || "GAARD conversation")}</strong>
|
|
1007
|
+
<small>${escapeHtml(conversation.latest_question || "No queries yet")} · ${Number(conversation.turn_count || 0).toLocaleString()} quer${Number(conversation.turn_count || 0) === 1 ? "y" : "ies"} · ${escapeHtml(formatDateTime(conversation.updated_at))}</small>
|
|
992
1008
|
</span>
|
|
993
|
-
</button>`).join("") :
|
|
1009
|
+
</button>`).join("") : ""}
|
|
1010
|
+
${!state.conversationsLoading && !conversations.length ? `
|
|
994
1011
|
<div class="placeholder-item muted">
|
|
995
1012
|
${renderIcon("queries")}
|
|
996
|
-
<span><strong>No
|
|
997
|
-
</div>`}
|
|
1013
|
+
<span><strong>No saved queries yet</strong><small>Ask your data on Home to start a chat.</small></span>
|
|
1014
|
+
</div>` : ""}
|
|
998
1015
|
</div>
|
|
999
1016
|
</section>`;
|
|
1000
1017
|
}
|
|
@@ -1188,6 +1205,7 @@ function renderPlaceholderView({ title, description, items }) {
|
|
|
1188
1205
|
}
|
|
1189
1206
|
function render(options = {}) {
|
|
1190
1207
|
if (!app) return;
|
|
1208
|
+
const historyScroll = captureHistoryScroll();
|
|
1191
1209
|
app.innerHTML = `
|
|
1192
1210
|
<main class="app-shell">
|
|
1193
1211
|
${renderSidebar()}
|
|
@@ -1212,6 +1230,9 @@ function render(options = {}) {
|
|
|
1212
1230
|
document.querySelectorAll("[data-view]").forEach((button) => {
|
|
1213
1231
|
button.addEventListener("click", changeView);
|
|
1214
1232
|
});
|
|
1233
|
+
document.querySelectorAll("[data-open-conversation]").forEach((button) => {
|
|
1234
|
+
button.addEventListener("click", openConversation);
|
|
1235
|
+
});
|
|
1215
1236
|
document.querySelector("#query-form")?.addEventListener("submit", submitQuestion);
|
|
1216
1237
|
document.querySelector("[data-logout]")?.addEventListener("click", logout);
|
|
1217
1238
|
document.querySelector("[data-new-chat]")?.addEventListener("click", newChat);
|
|
@@ -1272,6 +1293,9 @@ function render(options = {}) {
|
|
|
1272
1293
|
document.querySelectorAll("[data-retry-question]").forEach((button) => {
|
|
1273
1294
|
button.addEventListener("click", retryQuestion);
|
|
1274
1295
|
});
|
|
1296
|
+
document.querySelectorAll("[data-copy-query]").forEach((button) => {
|
|
1297
|
+
button.addEventListener("click", copyQuery);
|
|
1298
|
+
});
|
|
1275
1299
|
document.querySelectorAll("[data-save-widget]").forEach((button) => {
|
|
1276
1300
|
button.addEventListener("click", saveWidgetFromMessage);
|
|
1277
1301
|
});
|
|
@@ -1306,12 +1330,11 @@ function render(options = {}) {
|
|
|
1306
1330
|
input?.focus();
|
|
1307
1331
|
}
|
|
1308
1332
|
initAnalysisDashboard();
|
|
1333
|
+
maybeLoadConversationsForActiveView();
|
|
1309
1334
|
maybeLoadDatasourcesForActiveView();
|
|
1310
1335
|
maybeLoadDashboardsForActiveView();
|
|
1311
1336
|
maybeLoadSavedMetricsForActiveView();
|
|
1312
|
-
|
|
1313
|
-
scrollToLatest();
|
|
1314
|
-
}
|
|
1337
|
+
restoreHistoryScroll(historyScroll, options);
|
|
1315
1338
|
}
|
|
1316
1339
|
var apiErrorTimer = null;
|
|
1317
1340
|
function apiErrorMessage(error, fallback = "Request failed.") {
|
|
@@ -1357,6 +1380,93 @@ function maybeLoadDatasourcesForActiveView() {
|
|
|
1357
1380
|
void loadDatasources();
|
|
1358
1381
|
}
|
|
1359
1382
|
}
|
|
1383
|
+
function maybeLoadConversationsForActiveView() {
|
|
1384
|
+
if (state.token && ["home", "queries"].includes(state.activeView) && !state.conversationsLoaded && !state.conversationsLoading) {
|
|
1385
|
+
void loadConversations({ selectActive: state.activeView === "home" });
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
async function loadConversations(options = {}) {
|
|
1389
|
+
if (!state.token) {
|
|
1390
|
+
state.conversations = [];
|
|
1391
|
+
state.conversationsLoaded = false;
|
|
1392
|
+
state.conversationsLoading = false;
|
|
1393
|
+
state.conversationsError = "";
|
|
1394
|
+
return;
|
|
1395
|
+
}
|
|
1396
|
+
state.conversationsLoading = true;
|
|
1397
|
+
state.conversationsError = "";
|
|
1398
|
+
if (!options.silent) render();
|
|
1399
|
+
try {
|
|
1400
|
+
const response = await fetch(`/api/conversations?backend_url=${encodeURIComponent(state.backendUrl)}`, {
|
|
1401
|
+
headers: authHeaders()
|
|
1402
|
+
});
|
|
1403
|
+
const payload = await response.json().catch(() => ({}));
|
|
1404
|
+
if (!response.ok) {
|
|
1405
|
+
throw new Error(formatApiResponseError(response, extractErrorMessage(payload)));
|
|
1406
|
+
}
|
|
1407
|
+
state.conversations = payload.items || [];
|
|
1408
|
+
state.conversationsLoaded = true;
|
|
1409
|
+
if (options.selectActive) {
|
|
1410
|
+
const preferredId = state.conversationId || localStorage.getItem("gaard_client_active_conversation_id") || "";
|
|
1411
|
+
const conversation =
|
|
1412
|
+
state.conversations.find((item) => item.id === preferredId) ||
|
|
1413
|
+
state.conversations[0] ||
|
|
1414
|
+
null;
|
|
1415
|
+
if (conversation) {
|
|
1416
|
+
await loadConversation(conversation.id, { silent: true });
|
|
1417
|
+
} else {
|
|
1418
|
+
state.messages = [];
|
|
1419
|
+
state.nextMessageId = 1;
|
|
1420
|
+
state.conversationId = "";
|
|
1421
|
+
rememberActiveConversation("");
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
} catch (error) {
|
|
1425
|
+
state.conversationsError = error.message || "Could not load conversation history.";
|
|
1426
|
+
state.conversationsLoaded = true;
|
|
1427
|
+
reportApiError(error, "Could not load conversation history.");
|
|
1428
|
+
} finally {
|
|
1429
|
+
state.conversationsLoading = false;
|
|
1430
|
+
if (!options.silent) render();
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
async function loadConversation(conversationId, options = {}) {
|
|
1434
|
+
if (!state.token || !conversationId) return;
|
|
1435
|
+
state.conversationsError = "";
|
|
1436
|
+
if (!options.silent) {
|
|
1437
|
+
state.conversationsLoading = true;
|
|
1438
|
+
render();
|
|
1439
|
+
}
|
|
1440
|
+
try {
|
|
1441
|
+
const response = await fetch(
|
|
1442
|
+
`/api/conversations/${encodeURIComponent(conversationId)}?backend_url=${encodeURIComponent(state.backendUrl)}`,
|
|
1443
|
+
{ headers: authHeaders() }
|
|
1444
|
+
);
|
|
1445
|
+
const payload = await response.json().catch(() => ({}));
|
|
1446
|
+
if (!response.ok) {
|
|
1447
|
+
throw new Error(formatApiResponseError(response, extractErrorMessage(payload)));
|
|
1448
|
+
}
|
|
1449
|
+
if (payload.item) {
|
|
1450
|
+
state.conversations = [
|
|
1451
|
+
payload.item,
|
|
1452
|
+
...state.conversations.filter((item) => item.id !== payload.item.id)
|
|
1453
|
+
];
|
|
1454
|
+
}
|
|
1455
|
+
state.conversationsLoaded = true;
|
|
1456
|
+
state.conversationId = payload.item?.id || conversationId;
|
|
1457
|
+
rememberActiveConversation(state.conversationId);
|
|
1458
|
+
state.messages = messagesFromConversationTurns(payload.turns || []);
|
|
1459
|
+
state.nextMessageId = Math.max(1, ...state.messages.map((message) => Number(message.id) || 0)) + 1;
|
|
1460
|
+
state.activeView = "home";
|
|
1461
|
+
rememberActiveView(state.activeView);
|
|
1462
|
+
} catch (error) {
|
|
1463
|
+
state.conversationsError = error.message || "Could not load conversation.";
|
|
1464
|
+
reportApiError(error, "Could not load conversation.");
|
|
1465
|
+
} finally {
|
|
1466
|
+
state.conversationsLoading = false;
|
|
1467
|
+
if (!options.silent) render({ scrollToLatest: true });
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1360
1470
|
function maybeLoadDashboardsForActiveView() {
|
|
1361
1471
|
if (state.activeView === "analysis" && state.token && !state.dashboardsLoaded && !state.dashboardsLoading) {
|
|
1362
1472
|
void loadDashboards();
|
|
@@ -2260,6 +2370,11 @@ async function changeView(event) {
|
|
|
2260
2370
|
state.dashboardEditId = "";
|
|
2261
2371
|
render();
|
|
2262
2372
|
}
|
|
2373
|
+
function openConversation(event) {
|
|
2374
|
+
const conversationId = event.currentTarget.dataset.openConversation || "";
|
|
2375
|
+
if (!conversationId || state.pending) return;
|
|
2376
|
+
void loadConversation(conversationId);
|
|
2377
|
+
}
|
|
2263
2378
|
function initAnalysisDashboard() {
|
|
2264
2379
|
if (state.activeView !== "analysis") return;
|
|
2265
2380
|
state.dashboardGrid = null;
|
|
@@ -2595,6 +2710,7 @@ function newChat() {
|
|
|
2595
2710
|
if (state.pending) return;
|
|
2596
2711
|
state.messages = [];
|
|
2597
2712
|
state.conversationId = "";
|
|
2713
|
+
rememberActiveConversation("");
|
|
2598
2714
|
state.error = "";
|
|
2599
2715
|
state.activeView = "home";
|
|
2600
2716
|
rememberActiveView(state.activeView);
|
|
@@ -2611,7 +2727,7 @@ function renderMessage(message) {
|
|
|
2611
2727
|
const progress = message.mode === "analysis" ? renderAnalysisProgress(message) : "";
|
|
2612
2728
|
const analysisReply = message.status === "waiting" ? renderAnalysisReply(message) : "";
|
|
2613
2729
|
return `
|
|
2614
|
-
<article class="exchange ${message.status}">
|
|
2730
|
+
<article class="exchange ${message.status}" data-message-id="${escapeHtml(message.id)}">
|
|
2615
2731
|
<div class="exchange-top">
|
|
2616
2732
|
<div class="question">
|
|
2617
2733
|
<span>Question \xB7 ${escapeHtml(formatMode(message.mode))}</span>
|
|
@@ -2638,6 +2754,7 @@ function renderMessageActions(message) {
|
|
|
2638
2754
|
const saveTitle = message.saveStatus === "saved" ? "Saved as widget" : saveDialogOpen || message.saveStatus === "saving" ? "Saving widget" : "Save as widget";
|
|
2639
2755
|
const explainDisabled = state.pending || message.explanationStatus === "loading";
|
|
2640
2756
|
const explainTitle = message.explanationStatus === "ok" ? "Refresh explanation" : message.explanationStatus === "loading" ? "Explaining answer" : "Explain answer";
|
|
2757
|
+
const copyTitle = message.copyStatus === "copied" ? "Copied" : message.copyStatus === "error" ? "Copy failed" : "Copy query";
|
|
2641
2758
|
return `
|
|
2642
2759
|
<div class="message-actions">
|
|
2643
2760
|
<button class="retry-button" type="button" data-retry-question="${message.id}" aria-label="Copy question to input" title="Retry question" ${state.pending ? "disabled" : ""}>
|
|
@@ -2646,6 +2763,9 @@ function renderMessageActions(message) {
|
|
|
2646
2763
|
<path d="M3 3v5h5" />
|
|
2647
2764
|
</svg>
|
|
2648
2765
|
</button>
|
|
2766
|
+
<button class="copy-query-button" type="button" data-copy-query="${message.id}" aria-label="${escapeHtml(copyTitle)}" title="${escapeHtml(copyTitle)}">
|
|
2767
|
+
${renderIcon("copy")}
|
|
2768
|
+
</button>
|
|
2649
2769
|
${canSaveWidget(message) ? `
|
|
2650
2770
|
<button class="save-widget-button" type="button" data-save-widget="${message.id}" aria-label="Save question as widget" title="${escapeHtml(saveTitle)}" ${saveDisabled ? "disabled" : ""}>
|
|
2651
2771
|
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
|
@@ -2788,6 +2908,65 @@ function normalizeView(value) {
|
|
|
2788
2908
|
function rememberActiveView(value) {
|
|
2789
2909
|
localStorage.setItem("gaard_client_active_view", normalizeView(value));
|
|
2790
2910
|
}
|
|
2911
|
+
function formatDateTime(value) {
|
|
2912
|
+
const date = new Date(value || "");
|
|
2913
|
+
if (Number.isNaN(date.getTime())) {
|
|
2914
|
+
return "-";
|
|
2915
|
+
}
|
|
2916
|
+
return date.toLocaleString([], {
|
|
2917
|
+
dateStyle: "medium",
|
|
2918
|
+
timeStyle: "short"
|
|
2919
|
+
});
|
|
2920
|
+
}
|
|
2921
|
+
function rememberActiveConversation(value) {
|
|
2922
|
+
const conversationId = String(value || "");
|
|
2923
|
+
if (conversationId) {
|
|
2924
|
+
localStorage.setItem("gaard_client_active_conversation_id", conversationId);
|
|
2925
|
+
} else {
|
|
2926
|
+
localStorage.removeItem("gaard_client_active_conversation_id");
|
|
2927
|
+
}
|
|
2928
|
+
}
|
|
2929
|
+
function messagesFromConversationTurns(turns) {
|
|
2930
|
+
return turns.map((turn, index) => {
|
|
2931
|
+
const status = turn.status === "failed" ? "error" : "ok";
|
|
2932
|
+
const response = {
|
|
2933
|
+
question: turn.question || "",
|
|
2934
|
+
answer: turn.answer || "",
|
|
2935
|
+
sql: turn.sql || "",
|
|
2936
|
+
rows: [],
|
|
2937
|
+
metadata: {
|
|
2938
|
+
...(turn.metadata || {}),
|
|
2939
|
+
conversation: {
|
|
2940
|
+
...(turn.metadata?.conversation || {}),
|
|
2941
|
+
id: turn.conversation_id,
|
|
2942
|
+
turn_id: turn.id
|
|
2943
|
+
}
|
|
2944
|
+
}
|
|
2945
|
+
};
|
|
2946
|
+
return {
|
|
2947
|
+
id: index + 1,
|
|
2948
|
+
question: turn.question || "",
|
|
2949
|
+
mode: normalizeQueryMode(turn.mode),
|
|
2950
|
+
status,
|
|
2951
|
+
response: status === "ok" ? response : null,
|
|
2952
|
+
error: status === "error" ? turn.answer || "Query failed." : "",
|
|
2953
|
+
dataOpen: false,
|
|
2954
|
+
saveStatus: "idle",
|
|
2955
|
+
saveError: "",
|
|
2956
|
+
explanationStatus: "idle",
|
|
2957
|
+
explanation: "",
|
|
2958
|
+
explanationError: "",
|
|
2959
|
+
explanationMetadata: {},
|
|
2960
|
+
copyStatus: "idle",
|
|
2961
|
+
progress: [],
|
|
2962
|
+
progressOpen: false,
|
|
2963
|
+
processingStage: "",
|
|
2964
|
+
analysisSessionId: turn.analysis_session_id || "",
|
|
2965
|
+
userQuestion: "",
|
|
2966
|
+
createdAt: turn.created_at || ""
|
|
2967
|
+
};
|
|
2968
|
+
});
|
|
2969
|
+
}
|
|
2791
2970
|
function handleModeChange(event) {
|
|
2792
2971
|
state.queryMode = normalizeQueryMode(event.currentTarget.value);
|
|
2793
2972
|
render();
|
|
@@ -2803,10 +2982,7 @@ function toggleDataTable(event) {
|
|
|
2803
2982
|
const message = state.messages.find((item) => item.id === id);
|
|
2804
2983
|
if (!message) return;
|
|
2805
2984
|
message.dataOpen = !message.dataOpen;
|
|
2806
|
-
|
|
2807
|
-
render({
|
|
2808
|
-
scrollToLatest: message.dataOpen && latestMessage?.id === message.id
|
|
2809
|
-
});
|
|
2985
|
+
render();
|
|
2810
2986
|
}
|
|
2811
2987
|
function toggleAnalysisProgress(event) {
|
|
2812
2988
|
const details = event.currentTarget;
|
|
@@ -2828,6 +3004,57 @@ function retryQuestion(event) {
|
|
|
2828
3004
|
refreshedInput.focus();
|
|
2829
3005
|
refreshedInput.setSelectionRange(refreshedInput.value.length, refreshedInput.value.length);
|
|
2830
3006
|
}
|
|
3007
|
+
async function copyQuery(event) {
|
|
3008
|
+
const id = Number(event.currentTarget.dataset.copyQuery);
|
|
3009
|
+
const message = state.messages.find((item) => item.id === id);
|
|
3010
|
+
if (!message) return;
|
|
3011
|
+
try {
|
|
3012
|
+
await writeClipboard(messageClipboardText(message));
|
|
3013
|
+
message.copyStatus = "copied";
|
|
3014
|
+
render();
|
|
3015
|
+
window.setTimeout(() => {
|
|
3016
|
+
if (message.copyStatus === "copied") {
|
|
3017
|
+
message.copyStatus = "idle";
|
|
3018
|
+
render();
|
|
3019
|
+
}
|
|
3020
|
+
}, 1500);
|
|
3021
|
+
} catch (error) {
|
|
3022
|
+
message.copyStatus = "error";
|
|
3023
|
+
reportApiError(error, "Could not copy query.");
|
|
3024
|
+
render();
|
|
3025
|
+
}
|
|
3026
|
+
}
|
|
3027
|
+
function messageClipboardText(message) {
|
|
3028
|
+
const parts = [`Question:\n${message.question}`];
|
|
3029
|
+
const answer = message.response?.answer || message.error || "";
|
|
3030
|
+
if (answer) {
|
|
3031
|
+
parts.push(`Answer:\n${answer}`);
|
|
3032
|
+
}
|
|
3033
|
+
const sql = message.response?.sql || "";
|
|
3034
|
+
if (sql) {
|
|
3035
|
+
parts.push(`SQL:\n${sql}`);
|
|
3036
|
+
}
|
|
3037
|
+
return parts.join("\n\n");
|
|
3038
|
+
}
|
|
3039
|
+
async function writeClipboard(value) {
|
|
3040
|
+
const text = String(value || "");
|
|
3041
|
+
if (navigator.clipboard?.writeText) {
|
|
3042
|
+
await navigator.clipboard.writeText(text);
|
|
3043
|
+
return;
|
|
3044
|
+
}
|
|
3045
|
+
const textarea = document.createElement("textarea");
|
|
3046
|
+
textarea.value = text;
|
|
3047
|
+
textarea.setAttribute("readonly", "");
|
|
3048
|
+
textarea.style.position = "fixed";
|
|
3049
|
+
textarea.style.opacity = "0";
|
|
3050
|
+
document.body.appendChild(textarea);
|
|
3051
|
+
textarea.select();
|
|
3052
|
+
const copied = document.execCommand("copy");
|
|
3053
|
+
textarea.remove();
|
|
3054
|
+
if (!copied) {
|
|
3055
|
+
throw new Error("Clipboard is not available.");
|
|
3056
|
+
}
|
|
3057
|
+
}
|
|
2831
3058
|
async function explainAnswer(event) {
|
|
2832
3059
|
const id = Number(event.currentTarget.dataset.explainAnswer);
|
|
2833
3060
|
const message = state.messages.find((item) => item.id === id);
|
|
@@ -2869,8 +3096,7 @@ async function explainAnswer(event) {
|
|
|
2869
3096
|
message.explanationError = error.message || "Explanation could not be prepared.";
|
|
2870
3097
|
reportApiError(error, "Explanation could not be prepared.");
|
|
2871
3098
|
} finally {
|
|
2872
|
-
|
|
2873
|
-
render({ scrollToLatest: latestMessage?.id === message.id });
|
|
3099
|
+
render();
|
|
2874
3100
|
}
|
|
2875
3101
|
}
|
|
2876
3102
|
async function saveWidgetFromMessage(event) {
|
|
@@ -3044,6 +3270,12 @@ async function login(event) {
|
|
|
3044
3270
|
state.dashboardsLoaded = false;
|
|
3045
3271
|
state.activeDashboardId = "";
|
|
3046
3272
|
state.dashboardEditMode = false;
|
|
3273
|
+
state.messages = [];
|
|
3274
|
+
state.conversationId = "";
|
|
3275
|
+
state.conversations = [];
|
|
3276
|
+
state.conversationsLoaded = false;
|
|
3277
|
+
state.conversationsError = "";
|
|
3278
|
+
rememberActiveConversation("");
|
|
3047
3279
|
if (!state.enterpriseAccess) {
|
|
3048
3280
|
state.activeView = "analysis";
|
|
3049
3281
|
rememberActiveView(state.activeView);
|
|
@@ -3131,6 +3363,10 @@ async function logout() {
|
|
|
3131
3363
|
state.passwordChangeError = "";
|
|
3132
3364
|
state.messages = [];
|
|
3133
3365
|
state.conversationId = "";
|
|
3366
|
+
state.conversations = [];
|
|
3367
|
+
state.conversationsLoaded = false;
|
|
3368
|
+
state.conversationsLoading = false;
|
|
3369
|
+
state.conversationsError = "";
|
|
3134
3370
|
state.datasources = [];
|
|
3135
3371
|
state.datasourcesLoaded = false;
|
|
3136
3372
|
state.datasourceError = "";
|
|
@@ -3166,6 +3402,7 @@ async function logout() {
|
|
|
3166
3402
|
localStorage.removeItem("gaard_client_role");
|
|
3167
3403
|
localStorage.removeItem("gaard_client_enterprise_access");
|
|
3168
3404
|
localStorage.removeItem("gaard_client_must_change_password");
|
|
3405
|
+
localStorage.removeItem("gaard_client_active_conversation_id");
|
|
3169
3406
|
render();
|
|
3170
3407
|
}
|
|
3171
3408
|
function buildWidgetLabel(question) {
|
|
@@ -3247,6 +3484,7 @@ function syncConversationFromResponse(response) {
|
|
|
3247
3484
|
const conversationId = response?.metadata?.conversation?.id || response?.conversation_id || response?.session_started?.conversation_id || response?.session_resumed?.conversation_id || "";
|
|
3248
3485
|
if (conversationId) {
|
|
3249
3486
|
state.conversationId = String(conversationId);
|
|
3487
|
+
rememberActiveConversation(state.conversationId);
|
|
3250
3488
|
}
|
|
3251
3489
|
}
|
|
3252
3490
|
async function submitQuestion(event) {
|
|
@@ -3284,6 +3522,7 @@ async function submitQuestion(event) {
|
|
|
3284
3522
|
explanation: "",
|
|
3285
3523
|
explanationError: "",
|
|
3286
3524
|
explanationMetadata: {},
|
|
3525
|
+
copyStatus: "idle",
|
|
3287
3526
|
progress: [],
|
|
3288
3527
|
progressOpen: false,
|
|
3289
3528
|
processingStage: "Processing query..",
|
|
@@ -3323,7 +3562,7 @@ async function submitQuestion(event) {
|
|
|
3323
3562
|
reportApiError(error, "Request failed.");
|
|
3324
3563
|
} finally {
|
|
3325
3564
|
state.pending = false;
|
|
3326
|
-
render(
|
|
3565
|
+
render();
|
|
3327
3566
|
}
|
|
3328
3567
|
}
|
|
3329
3568
|
async function readQueryStream(message, response) {
|
|
@@ -3363,14 +3602,15 @@ function handleQueryStreamLine(message, line) {
|
|
|
3363
3602
|
message.processingStage = payload.stage === "waiting_on_data_server"
|
|
3364
3603
|
? "Waiting on data server..."
|
|
3365
3604
|
: "Processing query..";
|
|
3366
|
-
render(
|
|
3605
|
+
render();
|
|
3367
3606
|
}
|
|
3368
3607
|
if (payload?.final) {
|
|
3369
3608
|
syncConversationFromResponse(payload.final);
|
|
3370
3609
|
message.status = "ok";
|
|
3371
3610
|
message.response = payload.final;
|
|
3372
3611
|
message.processingStage = "";
|
|
3373
|
-
|
|
3612
|
+
void loadConversations({ silent: true });
|
|
3613
|
+
render();
|
|
3374
3614
|
return true;
|
|
3375
3615
|
}
|
|
3376
3616
|
return false;
|
|
@@ -3416,7 +3656,7 @@ async function submitAnalysisReply(event) {
|
|
|
3416
3656
|
reportApiError(error, "Request failed.");
|
|
3417
3657
|
} finally {
|
|
3418
3658
|
state.pending = false;
|
|
3419
|
-
render(
|
|
3659
|
+
render();
|
|
3420
3660
|
}
|
|
3421
3661
|
}
|
|
3422
3662
|
async function continueAnalysis(message, reply) {
|
|
@@ -3476,7 +3716,8 @@ function handleAnalysisStreamLine(message, line) {
|
|
|
3476
3716
|
message.response = payload.final;
|
|
3477
3717
|
message.dataOpen = message.mode === "analysis" && getRows(payload.final).length > 0;
|
|
3478
3718
|
message.userQuestion = "";
|
|
3479
|
-
|
|
3719
|
+
void loadConversations({ silent: true });
|
|
3720
|
+
render();
|
|
3480
3721
|
return true;
|
|
3481
3722
|
}
|
|
3482
3723
|
if (payload?.session_id && !message.analysisSessionId) {
|
|
@@ -3496,13 +3737,13 @@ function handleAnalysisStreamLine(message, line) {
|
|
|
3496
3737
|
items: []
|
|
3497
3738
|
}
|
|
3498
3739
|
];
|
|
3499
|
-
render(
|
|
3740
|
+
render();
|
|
3500
3741
|
return false;
|
|
3501
3742
|
}
|
|
3502
3743
|
const progress = progressFromAnalysisEvent(payload);
|
|
3503
3744
|
if (progress) {
|
|
3504
3745
|
message.progress = [...message.progress, progress];
|
|
3505
|
-
render(
|
|
3746
|
+
render();
|
|
3506
3747
|
}
|
|
3507
3748
|
return false;
|
|
3508
3749
|
}
|
|
@@ -3672,6 +3913,62 @@ function formatCellValue(value) {
|
|
|
3672
3913
|
}
|
|
3673
3914
|
return String(value ?? "");
|
|
3674
3915
|
}
|
|
3916
|
+
const HISTORY_BOTTOM_TOLERANCE = 12;
|
|
3917
|
+
function captureHistoryScroll() {
|
|
3918
|
+
const history = document.querySelector(".history");
|
|
3919
|
+
if (!history) return null;
|
|
3920
|
+
const maxScrollTop = Math.max(0, history.scrollHeight - history.clientHeight);
|
|
3921
|
+
const distanceFromBottom = maxScrollTop - history.scrollTop;
|
|
3922
|
+
const anchor = findHistoryScrollAnchor(history);
|
|
3923
|
+
return {
|
|
3924
|
+
scrollTop: history.scrollTop,
|
|
3925
|
+
distanceFromBottom,
|
|
3926
|
+
atBottom: distanceFromBottom <= HISTORY_BOTTOM_TOLERANCE,
|
|
3927
|
+
anchorId: anchor?.id || "",
|
|
3928
|
+
anchorOffset: anchor?.offset || 0
|
|
3929
|
+
};
|
|
3930
|
+
}
|
|
3931
|
+
function findHistoryScrollAnchor(history) {
|
|
3932
|
+
const historyRect = history.getBoundingClientRect();
|
|
3933
|
+
const messages = Array.from(history.querySelectorAll("[data-message-id]"));
|
|
3934
|
+
for (const message of messages) {
|
|
3935
|
+
const rect = message.getBoundingClientRect();
|
|
3936
|
+
if (rect.bottom >= historyRect.top && rect.top <= historyRect.bottom) {
|
|
3937
|
+
return {
|
|
3938
|
+
id: message.dataset.messageId || "",
|
|
3939
|
+
offset: rect.top - historyRect.top
|
|
3940
|
+
};
|
|
3941
|
+
}
|
|
3942
|
+
}
|
|
3943
|
+
return null;
|
|
3944
|
+
}
|
|
3945
|
+
function restoreHistoryScroll(snapshot, options = {}) {
|
|
3946
|
+
if (options.scrollToLatest || snapshot?.atBottom) {
|
|
3947
|
+
scrollToLatest();
|
|
3948
|
+
return;
|
|
3949
|
+
}
|
|
3950
|
+
if (!snapshot) return;
|
|
3951
|
+
const restore = () => {
|
|
3952
|
+
const history = document.querySelector(".history");
|
|
3953
|
+
if (!history) return;
|
|
3954
|
+
const maxScrollTop = Math.max(0, history.scrollHeight - history.clientHeight);
|
|
3955
|
+
const anchor = snapshot.anchorId
|
|
3956
|
+
? Array.from(history.querySelectorAll("[data-message-id]")).find((message) => message.dataset.messageId === snapshot.anchorId)
|
|
3957
|
+
: null;
|
|
3958
|
+
if (anchor) {
|
|
3959
|
+
const historyRect = history.getBoundingClientRect();
|
|
3960
|
+
const anchorOffset = anchor.getBoundingClientRect().top - historyRect.top;
|
|
3961
|
+
history.scrollTop = Math.max(0, Math.min(maxScrollTop, history.scrollTop + anchorOffset - snapshot.anchorOffset));
|
|
3962
|
+
return;
|
|
3963
|
+
}
|
|
3964
|
+
history.scrollTop = Math.max(0, Math.min(maxScrollTop, snapshot.scrollTop));
|
|
3965
|
+
};
|
|
3966
|
+
restore();
|
|
3967
|
+
requestAnimationFrame(() => {
|
|
3968
|
+
restore();
|
|
3969
|
+
requestAnimationFrame(restore);
|
|
3970
|
+
});
|
|
3971
|
+
}
|
|
3675
3972
|
function scrollToLatest() {
|
|
3676
3973
|
const scroll = () => {
|
|
3677
3974
|
const history = document.querySelector(".history");
|
|
@@ -634,6 +634,7 @@ label {
|
|
|
634
634
|
}
|
|
635
635
|
|
|
636
636
|
.retry-button,
|
|
637
|
+
.copy-query-button,
|
|
637
638
|
.explain-answer-button,
|
|
638
639
|
.save-widget-button,
|
|
639
640
|
.icon-button {
|
|
@@ -650,6 +651,8 @@ label {
|
|
|
650
651
|
|
|
651
652
|
.retry-button:hover,
|
|
652
653
|
.retry-button:focus-visible,
|
|
654
|
+
.copy-query-button:hover,
|
|
655
|
+
.copy-query-button:focus-visible,
|
|
653
656
|
.explain-answer-button:hover,
|
|
654
657
|
.explain-answer-button:focus-visible,
|
|
655
658
|
.save-widget-button:hover,
|
|
@@ -662,12 +665,14 @@ label {
|
|
|
662
665
|
}
|
|
663
666
|
|
|
664
667
|
.retry-button:disabled,
|
|
668
|
+
.copy-query-button:disabled,
|
|
665
669
|
.explain-answer-button:disabled,
|
|
666
670
|
.save-widget-button:disabled {
|
|
667
671
|
opacity: 0.3;
|
|
668
672
|
}
|
|
669
673
|
|
|
670
674
|
.retry-button svg,
|
|
675
|
+
.copy-query-button svg,
|
|
671
676
|
.explain-answer-button svg,
|
|
672
677
|
.save-widget-button svg,
|
|
673
678
|
.icon-button svg {
|
|
@@ -2883,6 +2888,11 @@ button.placeholder-item {
|
|
|
2883
2888
|
cursor: pointer;
|
|
2884
2889
|
}
|
|
2885
2890
|
|
|
2891
|
+
button.placeholder-item.active {
|
|
2892
|
+
border-color: rgba(8, 120, 111, 0.36);
|
|
2893
|
+
background: rgba(8, 120, 111, 0.08);
|
|
2894
|
+
}
|
|
2895
|
+
|
|
2886
2896
|
.placeholder-item.muted {
|
|
2887
2897
|
color: #7a8793;
|
|
2888
2898
|
}
|