gaard-client 0.2.12__tar.gz → 0.2.20__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.12 → gaard_client-0.2.20}/PKG-INFO +2 -2
- {gaard_client-0.2.12 → gaard_client-0.2.20}/pyproject.toml +2 -2
- {gaard_client-0.2.12 → gaard_client-0.2.20}/src/gaard_client/client-web/assets/main.js +228 -57
- {gaard_client-0.2.12 → gaard_client-0.2.20}/src/gaard_client/client-web/assets/styles.css +95 -31
- {gaard_client-0.2.12 → gaard_client-0.2.20}/src/gaard_client/main.py +309 -653
- {gaard_client-0.2.12 → gaard_client-0.2.20}/src/gaard_client.egg-info/PKG-INFO +2 -2
- {gaard_client-0.2.12 → gaard_client-0.2.20}/src/gaard_client.egg-info/requires.txt +1 -1
- {gaard_client-0.2.12 → gaard_client-0.2.20}/tests/test_client_app.py +735 -106
- {gaard_client-0.2.12 → gaard_client-0.2.20}/README.md +0 -0
- {gaard_client-0.2.12 → gaard_client-0.2.20}/setup.cfg +0 -0
- {gaard_client-0.2.12 → gaard_client-0.2.20}/src/gaard_client/__init__.py +0 -0
- {gaard_client-0.2.12 → gaard_client-0.2.20}/src/gaard_client/cli.py +0 -0
- {gaard_client-0.2.12 → gaard_client-0.2.20}/src/gaard_client/cli_commands.py +0 -0
- {gaard_client-0.2.12 → gaard_client-0.2.20}/src/gaard_client/client-web/assets/getgaard.svg +0 -0
- {gaard_client-0.2.12 → gaard_client-0.2.20}/src/gaard_client/client-web/index.html +0 -0
- {gaard_client-0.2.12 → gaard_client-0.2.20}/src/gaard_client.egg-info/SOURCES.txt +0 -0
- {gaard_client-0.2.12 → gaard_client-0.2.20}/src/gaard_client.egg-info/dependency_links.txt +0 -0
- {gaard_client-0.2.12 → gaard_client-0.2.20}/src/gaard_client.egg-info/entry_points.txt +0 -0
- {gaard_client-0.2.12 → gaard_client-0.2.20}/src/gaard_client.egg-info/top_level.txt +0 -0
- {gaard_client-0.2.12 → gaard_client-0.2.20}/tests/test_cli.py +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.20
|
|
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.20
|
|
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.20"
|
|
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.20,<0.3.0",
|
|
14
14
|
"fastapi>=0.111.0",
|
|
15
15
|
"uvicorn[standard]>=0.30.0",
|
|
16
16
|
"pydantic>=2.7.0",
|
|
@@ -28,6 +28,7 @@ var state = {
|
|
|
28
28
|
conversationsLoaded: false,
|
|
29
29
|
conversationsLoading: false,
|
|
30
30
|
conversationsError: "",
|
|
31
|
+
queryContextDialog: null,
|
|
31
32
|
pending: false,
|
|
32
33
|
error: "",
|
|
33
34
|
apiError: null,
|
|
@@ -40,6 +41,7 @@ var state = {
|
|
|
40
41
|
datasourceError: "",
|
|
41
42
|
datasourceUploadPending: false,
|
|
42
43
|
excelUploadAllowed: false,
|
|
44
|
+
csvUploadAllowed: false,
|
|
43
45
|
datasourceSelectionPending: false,
|
|
44
46
|
selectedDatasourceIds: [],
|
|
45
47
|
multipleDatasourceSelectionAllowed: false,
|
|
@@ -406,7 +408,7 @@ function renderSourcesPanel() {
|
|
|
406
408
|
return `
|
|
407
409
|
<div class="sources-panel">
|
|
408
410
|
<div class="source-actions">
|
|
409
|
-
<button class="source-add" type="button" data-
|
|
411
|
+
<button class="source-add" type="button" data-view="datasources" aria-label="Manage data sources" title="Manage data sources">
|
|
410
412
|
<span aria-hidden="true">+</span>
|
|
411
413
|
</button>
|
|
412
414
|
</div>
|
|
@@ -440,6 +442,16 @@ function renderAuthControls() {
|
|
|
440
442
|
}
|
|
441
443
|
return `<button class="primary auth-button" type="button" data-open-login>Log in</button>`;
|
|
442
444
|
}
|
|
445
|
+
function renderTopbar(options = {}) {
|
|
446
|
+
return `
|
|
447
|
+
<header class="topbar ${options.chat ? "chat-toolbar" : ""} ${state.activeView === "analysis" ? "analysis-topbar" : ""}">
|
|
448
|
+
${renderViewHeading()}
|
|
449
|
+
<div class="header-actions">
|
|
450
|
+
${renderAnalysisTopbarActions()}
|
|
451
|
+
${renderAuthControls()}
|
|
452
|
+
</div>
|
|
453
|
+
</header>`;
|
|
454
|
+
}
|
|
443
455
|
function renderEmptyState() {
|
|
444
456
|
if (!state.token) {
|
|
445
457
|
return `
|
|
@@ -542,6 +554,7 @@ function renderApiErrorBanner() {
|
|
|
542
554
|
function renderHomeView() {
|
|
543
555
|
return `
|
|
544
556
|
<section class="chat-shell" aria-label="GAARD chat">
|
|
557
|
+
${renderTopbar({ chat: true })}
|
|
545
558
|
<section class="history" aria-live="polite">
|
|
546
559
|
${state.messages.length ? state.messages.map(renderMessage).join("") : renderEmptyState()}
|
|
547
560
|
</section>
|
|
@@ -594,44 +607,47 @@ function canDeleteDashboard(dashboard) {
|
|
|
594
607
|
function dashboardSharingAvailable() {
|
|
595
608
|
return Number(state.dashboardShareUserCount || 0) > 1 || state.dashboardShareUsers.length > 1;
|
|
596
609
|
}
|
|
597
|
-
function
|
|
610
|
+
function renderAnalysisTopbarActions() {
|
|
611
|
+
if (state.activeView !== "analysis") return "";
|
|
598
612
|
const dashboard = getActiveDashboard();
|
|
599
613
|
const editable = canEditDashboard(dashboard);
|
|
600
614
|
const shareable = canShareDashboard(dashboard) && dashboardSharingAvailable();
|
|
615
|
+
return `
|
|
616
|
+
<div class="analysis-topbar-actions">
|
|
617
|
+
${dashboard && state.token && shareable ? `
|
|
618
|
+
<button
|
|
619
|
+
class="dashboard-edit-mode-button"
|
|
620
|
+
type="button"
|
|
621
|
+
data-open-dashboard-share
|
|
622
|
+
aria-label="Share dashboard"
|
|
623
|
+
title="Share dashboard"
|
|
624
|
+
${state.dashboardSharesLoading ? "disabled" : ""}
|
|
625
|
+
>
|
|
626
|
+
${state.dashboardSharesLoading ? `<span class="dashboard-edit-saving-spinner" aria-hidden="true"></span>` : renderIcon("share")}
|
|
627
|
+
</button>` : ""}
|
|
628
|
+
${dashboard && state.token && editable ? `
|
|
629
|
+
<button
|
|
630
|
+
class="dashboard-edit-mode-button ${state.dashboardEditMode ? "active" : ""} ${state.dashboardLayoutSaving ? "saving" : ""}"
|
|
631
|
+
type="button"
|
|
632
|
+
data-toggle-dashboard-edit
|
|
633
|
+
aria-pressed="${state.dashboardEditMode ? "true" : "false"}"
|
|
634
|
+
aria-label="${state.dashboardLayoutSaving ? "Saving dashboard layout" : state.dashboardEditMode ? "Finish editing dashboard layout" : "Edit dashboard layout"}"
|
|
635
|
+
title="${state.dashboardLayoutSaving ? "Saving..." : state.dashboardEditMode ? "Finish editing" : "Edit layout"}"
|
|
636
|
+
${state.dashboardLayoutSaving ? "disabled" : ""}
|
|
637
|
+
>
|
|
638
|
+
${state.dashboardLayoutSaving ? `<span class="dashboard-edit-saving-spinner" aria-hidden="true"></span>` : renderIcon("edit")}
|
|
639
|
+
${state.dashboardLayoutSaving ? `<span>Saving...</span>` : ""}
|
|
640
|
+
</button>` : ""}
|
|
641
|
+
${dashboard && state.token && state.dashboardEditMode && editable ? `
|
|
642
|
+
<button class="dashboard-add-widget-button" type="button" data-open-widget-dialog aria-label="Add widget" title="Add widget">
|
|
643
|
+
${renderIcon("plus")}
|
|
644
|
+
</button>` : ""}
|
|
645
|
+
</div>`;
|
|
646
|
+
}
|
|
647
|
+
function renderAnalysisView() {
|
|
648
|
+
const dashboard = getActiveDashboard();
|
|
601
649
|
return `
|
|
602
650
|
<section class="dashboard-view" aria-label="Dashboard Analysis">
|
|
603
|
-
<div class="dashboard-toolbar dashboard-toolbar-compact">
|
|
604
|
-
<div class="dashboard-toolbar-actions">
|
|
605
|
-
${dashboard && state.token && shareable ? `
|
|
606
|
-
<button
|
|
607
|
-
class="dashboard-edit-mode-button"
|
|
608
|
-
type="button"
|
|
609
|
-
data-open-dashboard-share
|
|
610
|
-
aria-label="Share dashboard"
|
|
611
|
-
title="Share dashboard"
|
|
612
|
-
${state.dashboardSharesLoading ? "disabled" : ""}
|
|
613
|
-
>
|
|
614
|
-
${state.dashboardSharesLoading ? `<span class="dashboard-edit-saving-spinner" aria-hidden="true"></span>` : renderIcon("share")}
|
|
615
|
-
</button>` : ""}
|
|
616
|
-
${dashboard && state.token && editable ? `
|
|
617
|
-
<button
|
|
618
|
-
class="dashboard-edit-mode-button ${state.dashboardEditMode ? "active" : ""} ${state.dashboardLayoutSaving ? "saving" : ""}"
|
|
619
|
-
type="button"
|
|
620
|
-
data-toggle-dashboard-edit
|
|
621
|
-
aria-pressed="${state.dashboardEditMode ? "true" : "false"}"
|
|
622
|
-
aria-label="${state.dashboardLayoutSaving ? "Saving dashboard layout" : state.dashboardEditMode ? "Finish editing dashboard layout" : "Edit dashboard layout"}"
|
|
623
|
-
title="${state.dashboardLayoutSaving ? "Saving..." : state.dashboardEditMode ? "Finish editing" : "Edit layout"}"
|
|
624
|
-
${state.dashboardLayoutSaving ? "disabled" : ""}
|
|
625
|
-
>
|
|
626
|
-
${state.dashboardLayoutSaving ? `<span class="dashboard-edit-saving-spinner" aria-hidden="true"></span>` : renderIcon("edit")}
|
|
627
|
-
${state.dashboardLayoutSaving ? `<span>Saving...</span>` : ""}
|
|
628
|
-
</button>` : ""}
|
|
629
|
-
${dashboard && state.token && state.dashboardEditMode && editable ? `
|
|
630
|
-
<button class="dashboard-add-widget-button" type="button" data-open-widget-dialog aria-label="Add widget" title="Add widget">
|
|
631
|
-
${renderIcon("plus")}
|
|
632
|
-
</button>` : ""}
|
|
633
|
-
</div>
|
|
634
|
-
</div>
|
|
635
651
|
${state.dashboardsError ? `<div class="source-error datasource-error" role="alert">${escapeHtml(state.dashboardsError)}</div>` : ""}
|
|
636
652
|
${state.dashboardWidgetsError ? `<div class="source-error datasource-error" role="alert">${escapeHtml(state.dashboardWidgetsError)}</div>` : ""}
|
|
637
653
|
${renderAnalysisDashboardBody(dashboard)}
|
|
@@ -1045,7 +1061,7 @@ function renderDashboardWidgetContent(widget) {
|
|
|
1045
1061
|
return `<div class="dashboard-widget-error">${escapeHtml(result.message || result.error || "Widget data could not be loaded.")}</div>`;
|
|
1046
1062
|
}
|
|
1047
1063
|
if (widget.visualization_type === "table") {
|
|
1048
|
-
return `<div class="dashboard-table-widget">${renderDataTable(getRowsFromResult(result))}</div>`;
|
|
1064
|
+
return `<div class="dashboard-table-widget">${renderDataTable(getRowsFromResult(result), { allowHtml: true })}</div>`;
|
|
1049
1065
|
}
|
|
1050
1066
|
if (widget.visualization_type === "number") {
|
|
1051
1067
|
return renderDashboardNumberWidget(result);
|
|
@@ -1261,6 +1277,7 @@ function renderSavedMetricCard(metric) {
|
|
|
1261
1277
|
function renderDatasourcesView() {
|
|
1262
1278
|
const visibleSources = state.datasources.filter((item) => item.connector_key !== "metadata-db");
|
|
1263
1279
|
const uploadAllowed = Boolean(state.token && state.excelUploadAllowed);
|
|
1280
|
+
const csvUploadAllowed = Boolean(state.token && state.csvUploadAllowed);
|
|
1264
1281
|
const uploadLabel = state.datasourceUploadPending
|
|
1265
1282
|
? "Uploading..."
|
|
1266
1283
|
: uploadAllowed
|
|
@@ -1268,17 +1285,24 @@ function renderDatasourcesView() {
|
|
|
1268
1285
|
: state.token
|
|
1269
1286
|
? "Enterprise access required"
|
|
1270
1287
|
: "Log in to upload .xlsx workbook";
|
|
1288
|
+
const csvUploadLabel = state.datasourceUploadPending
|
|
1289
|
+
? "Uploading..."
|
|
1290
|
+
: csvUploadAllowed
|
|
1291
|
+
? "Upload .csv file"
|
|
1292
|
+
: state.token
|
|
1293
|
+
? "Enterprise access required"
|
|
1294
|
+
: "Log in to upload .csv file";
|
|
1271
1295
|
return `
|
|
1272
1296
|
<section class="datasources-view placeholder-view">
|
|
1273
1297
|
<div class="datasource-actions-grid">
|
|
1274
|
-
<button class="placeholder-item datasource-upload-card" type="button" data-add-source ${state.datasourceUploadPending || !uploadAllowed ? "disabled" : ""}>
|
|
1298
|
+
<button class="placeholder-item datasource-upload-card" type="button" data-add-source="excel" ${state.datasourceUploadPending || !uploadAllowed ? "disabled" : ""}>
|
|
1275
1299
|
${renderIcon("plus")}
|
|
1276
1300
|
<span><strong>Excel workbooks</strong><small>${escapeHtml(uploadLabel)}</small></span>
|
|
1277
1301
|
</button>
|
|
1278
|
-
<
|
|
1302
|
+
<button class="placeholder-item datasource-upload-card" type="button" data-add-source="csv" ${state.datasourceUploadPending || !csvUploadAllowed ? "disabled" : ""}>
|
|
1279
1303
|
${renderIcon("plus")}
|
|
1280
|
-
<span><strong>CSV uploads</strong><small
|
|
1281
|
-
</
|
|
1304
|
+
<span><strong>CSV uploads</strong><small>${escapeHtml(csvUploadLabel)}</small></span>
|
|
1305
|
+
</button>
|
|
1282
1306
|
<div class="placeholder-item muted">
|
|
1283
1307
|
${renderIcon("plus")}
|
|
1284
1308
|
<span><strong>Connected databases</strong><small>Coming soon</small></span>
|
|
@@ -1343,17 +1367,13 @@ function render(options = {}) {
|
|
|
1343
1367
|
app.innerHTML = `
|
|
1344
1368
|
<main class="app-shell ${state.sidebarCollapsed ? "sidebar-collapsed" : ""}">
|
|
1345
1369
|
${renderSidebar()}
|
|
1346
|
-
<section class="workspace-shell" aria-label="GAARD workspace">
|
|
1347
|
-
|
|
1348
|
-
${renderViewHeading()}
|
|
1349
|
-
<div class="header-actions">
|
|
1350
|
-
${renderAuthControls()}
|
|
1351
|
-
</div>
|
|
1352
|
-
</header>
|
|
1370
|
+
<section class="workspace-shell ${state.activeView === "home" ? "home-workspace" : ""}" aria-label="GAARD workspace">
|
|
1371
|
+
${state.activeView === "home" ? "" : renderTopbar()}
|
|
1353
1372
|
<div class="api-error-slot">${renderApiErrorBanner()}</div>
|
|
1354
1373
|
${renderActiveView()}
|
|
1355
1374
|
</section>
|
|
1356
1375
|
<input id="excel-source-input" type="file" accept=".xlsx,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" hidden />
|
|
1376
|
+
<input id="csv-source-input" type="file" accept=".csv,text/csv" hidden />
|
|
1357
1377
|
${state.loginOpen ? renderLoginDialog() : ""}
|
|
1358
1378
|
${state.mustChangePassword ? renderPasswordChangeDialog() : ""}
|
|
1359
1379
|
${state.dashboardCreateOpen ? renderDashboardCreateDialog() : ""}
|
|
@@ -1366,6 +1386,9 @@ function render(options = {}) {
|
|
|
1366
1386
|
button.addEventListener("click", changeView);
|
|
1367
1387
|
});
|
|
1368
1388
|
document.querySelector("[data-toggle-sidebar]")?.addEventListener("click", toggleSidebarCollapsed);
|
|
1389
|
+
document.querySelectorAll("[data-query-context]").forEach((button) => {
|
|
1390
|
+
button.addEventListener("click", openQueryContext);
|
|
1391
|
+
});
|
|
1369
1392
|
document.querySelectorAll("[data-open-conversation]").forEach((button) => {
|
|
1370
1393
|
button.addEventListener("click", openConversation);
|
|
1371
1394
|
});
|
|
@@ -1378,7 +1401,9 @@ function render(options = {}) {
|
|
|
1378
1401
|
document.querySelector("[data-close-login]")?.addEventListener("click", closeLogin);
|
|
1379
1402
|
document.querySelector("[data-dismiss-api-error]")?.addEventListener("click", dismissApiError);
|
|
1380
1403
|
document.querySelector("[data-toggle-sources]")?.addEventListener("click", toggleSources);
|
|
1381
|
-
document.
|
|
1404
|
+
document.querySelectorAll("[data-add-source]").forEach((button) => {
|
|
1405
|
+
button.addEventListener("click", openSourcePicker);
|
|
1406
|
+
});
|
|
1382
1407
|
document.querySelector("[data-refresh-sources]")?.addEventListener("click", () => loadDatasources());
|
|
1383
1408
|
document.querySelectorAll("[data-source-selected]").forEach((input2) => {
|
|
1384
1409
|
input2.addEventListener("change", updateSelectedSources);
|
|
@@ -1423,6 +1448,7 @@ function render(options = {}) {
|
|
|
1423
1448
|
button.addEventListener("click", deleteDashboardWidget);
|
|
1424
1449
|
});
|
|
1425
1450
|
document.querySelector("#excel-source-input")?.addEventListener("change", uploadSelectedSource);
|
|
1451
|
+
document.querySelector("#csv-source-input")?.addEventListener("change", uploadSelectedSource);
|
|
1426
1452
|
document.querySelector("#login-form")?.addEventListener("submit", login);
|
|
1427
1453
|
document.querySelector("#password-change-form")?.addEventListener("submit", changePassword);
|
|
1428
1454
|
document.querySelectorAll('input[name="mode"]').forEach((input2) => {
|
|
@@ -2521,14 +2547,16 @@ function collectDashboardLayout() {
|
|
|
2521
2547
|
function canPersistDashboardLayout(grid = state.dashboardGrid) {
|
|
2522
2548
|
return Boolean(grid) && Number(grid.getColumn?.()) === 12;
|
|
2523
2549
|
}
|
|
2524
|
-
function openSourcePicker() {
|
|
2550
|
+
function openSourcePicker(event) {
|
|
2525
2551
|
if (state.datasourceUploadPending) return;
|
|
2526
2552
|
if (!state.token) {
|
|
2527
2553
|
openLogin();
|
|
2528
2554
|
return;
|
|
2529
2555
|
}
|
|
2530
|
-
|
|
2531
|
-
const
|
|
2556
|
+
const sourceType = event?.currentTarget?.dataset?.addSource || "excel";
|
|
2557
|
+
const allowed = sourceType === "csv" ? state.csvUploadAllowed : state.excelUploadAllowed;
|
|
2558
|
+
if (!allowed) return;
|
|
2559
|
+
const input = document.querySelector(`#${sourceType}-source-input`);
|
|
2532
2560
|
if (!input) return;
|
|
2533
2561
|
input.value = "";
|
|
2534
2562
|
input.click();
|
|
@@ -2570,6 +2598,7 @@ async function loadDatasources(options = {}) {
|
|
|
2570
2598
|
state.selectedDatasourceIds = (payload.selected_datasource_ids || []).filter((id) => availableDatasourceIds.has(id));
|
|
2571
2599
|
state.multipleDatasourceSelectionAllowed = Boolean(payload.multiple_selection_allowed);
|
|
2572
2600
|
state.excelUploadAllowed = Boolean(payload.excel_upload_allowed);
|
|
2601
|
+
state.csvUploadAllowed = Boolean(payload.csv_upload_allowed);
|
|
2573
2602
|
state.datasourcesLoaded = true;
|
|
2574
2603
|
} catch (error) {
|
|
2575
2604
|
state.datasourceError = error.message || "Could not load data sources.";
|
|
@@ -2584,8 +2613,10 @@ async function uploadSelectedSource(event) {
|
|
|
2584
2613
|
const input = event.currentTarget;
|
|
2585
2614
|
const file = input.files?.[0];
|
|
2586
2615
|
if (!file) return;
|
|
2587
|
-
|
|
2588
|
-
|
|
2616
|
+
const sourceType = input.id === "csv-source-input" ? "csv" : "excel";
|
|
2617
|
+
const expectedSuffix = sourceType === "csv" ? ".csv" : ".xlsx";
|
|
2618
|
+
if (!file.name.toLowerCase().endsWith(expectedSuffix)) {
|
|
2619
|
+
state.datasourceError = `Choose a ${expectedSuffix} file.`;
|
|
2589
2620
|
render();
|
|
2590
2621
|
return;
|
|
2591
2622
|
}
|
|
@@ -2599,7 +2630,7 @@ async function uploadSelectedSource(event) {
|
|
|
2599
2630
|
backend_url: state.backendUrl,
|
|
2600
2631
|
active: "true"
|
|
2601
2632
|
});
|
|
2602
|
-
const response = await fetch(`/api/datasources
|
|
2633
|
+
const response = await fetch(`/api/datasources/${sourceType}?${params.toString()}`, {
|
|
2603
2634
|
method: "POST",
|
|
2604
2635
|
headers: authHeaders(),
|
|
2605
2636
|
body: formData
|
|
@@ -2681,7 +2712,10 @@ function friendlyDatasourceError(message) {
|
|
|
2681
2712
|
}
|
|
2682
2713
|
async function changeView(event) {
|
|
2683
2714
|
const view = normalizeView(event.currentTarget.dataset.view);
|
|
2684
|
-
if (state.activeView === view)
|
|
2715
|
+
if (state.activeView === view) {
|
|
2716
|
+
if (view === "home") scrollToLatest();
|
|
2717
|
+
return;
|
|
2718
|
+
}
|
|
2685
2719
|
if (state.activeView === "analysis" && state.dashboardEditMode) {
|
|
2686
2720
|
await flushPendingDashboardLayoutSave();
|
|
2687
2721
|
}
|
|
@@ -2695,7 +2729,7 @@ async function changeView(event) {
|
|
|
2695
2729
|
state.dashboardEditId = "";
|
|
2696
2730
|
state.dashboardShareOpen = false;
|
|
2697
2731
|
state.dashboardShareDashboardId = "";
|
|
2698
|
-
render();
|
|
2732
|
+
render({ scrollToLatest: view === "home" });
|
|
2699
2733
|
}
|
|
2700
2734
|
function openConversation(event) {
|
|
2701
2735
|
const conversationId = event.currentTarget.dataset.openConversation || "";
|
|
@@ -3209,12 +3243,103 @@ function renderMeta(message, rows) {
|
|
|
3209
3243
|
<div><dt>Datasource</dt><dd>${escapeHtml(metadata.datasource_id || "-")}</dd></div>
|
|
3210
3244
|
<div><dt>Mode</dt><dd>${escapeHtml(formatMode(mode))}</dd></div>
|
|
3211
3245
|
<div><dt>Output</dt><dd>${escapeHtml(metadata.output_classification || "unknown")}</dd></div>
|
|
3246
|
+
${metadata.conversation?.id && metadata.conversation?.turn_id ? `
|
|
3247
|
+
<div><dd><button class="query-context-link" type="button" data-query-context="${message.id}" aria-haspopup="dialog">kontekst</button></dd></div>
|
|
3248
|
+
` : ""}
|
|
3212
3249
|
</dl>
|
|
3213
3250
|
<button class="data-toggle" type="button" data-toggle-data="${message.id}" aria-expanded="${message.dataOpen ? "true" : "false"}">
|
|
3214
3251
|
${escapeHtml(buttonText)}
|
|
3215
3252
|
</button>
|
|
3216
3253
|
</div>`;
|
|
3217
3254
|
}
|
|
3255
|
+
function renderQueryContextDialog() {
|
|
3256
|
+
const dialog = state.queryContextDialog;
|
|
3257
|
+
return `
|
|
3258
|
+
<dialog id="query-context-dialog" class="query-context-dialog" aria-labelledby="query-context-title">
|
|
3259
|
+
<h2 id="query-context-title">Query context</h2>
|
|
3260
|
+
<p class="query-context-question">${escapeHtml(dialog.question)}</p>
|
|
3261
|
+
${dialog.loading ? '<p role="status">Loading...</p>' : ""}
|
|
3262
|
+
${dialog.error ? `<p class="source-error" role="alert">${escapeHtml(dialog.error)}</p>` : ""}
|
|
3263
|
+
${!dialog.loading && !dialog.error ? `
|
|
3264
|
+
<textarea readonly aria-label="Context at query execution" rows="7">${escapeHtml(dialog.context)}</textarea>
|
|
3265
|
+
` : ""}
|
|
3266
|
+
<div class="dashboard-create-actions">
|
|
3267
|
+
${dialog.error ? '<button type="button" data-retry-query-context>Retry</button>' : ""}
|
|
3268
|
+
<button type="button" data-close-query-context autofocus>Close</button>
|
|
3269
|
+
</div>
|
|
3270
|
+
</dialog>`;
|
|
3271
|
+
}
|
|
3272
|
+
|
|
3273
|
+
function updateQueryContextDialog() {
|
|
3274
|
+
// The dialog is independent of the chat render, so loading it cannot reset the scroll.
|
|
3275
|
+
const template = document.createElement("template");
|
|
3276
|
+
template.innerHTML = renderQueryContextDialog();
|
|
3277
|
+
let element = document.querySelector("#query-context-dialog");
|
|
3278
|
+
if (element) {
|
|
3279
|
+
element.innerHTML = template.content.firstElementChild.innerHTML;
|
|
3280
|
+
} else {
|
|
3281
|
+
element = template.content.firstElementChild;
|
|
3282
|
+
document.body.appendChild(element);
|
|
3283
|
+
}
|
|
3284
|
+
element.querySelector("[data-close-query-context]").addEventListener("click", closeQueryContext);
|
|
3285
|
+
element.querySelector("[data-retry-query-context]")?.addEventListener("click", () => {
|
|
3286
|
+
const dialog = state.queryContextDialog;
|
|
3287
|
+
if (dialog) void loadQueryContext(dialog, dialog.conversation);
|
|
3288
|
+
});
|
|
3289
|
+
element.oncancel = (event) => {
|
|
3290
|
+
event.preventDefault();
|
|
3291
|
+
closeQueryContext();
|
|
3292
|
+
};
|
|
3293
|
+
if (!element.open) element.showModal();
|
|
3294
|
+
}
|
|
3295
|
+
|
|
3296
|
+
async function openQueryContext(event) {
|
|
3297
|
+
const messageId = Number(event.currentTarget.dataset.queryContext);
|
|
3298
|
+
const message = state.messages.find((item) => item.id === messageId);
|
|
3299
|
+
const conversation = message?.response?.metadata?.conversation;
|
|
3300
|
+
if (!conversation?.id || !conversation?.turn_id) return;
|
|
3301
|
+
const dialog = {
|
|
3302
|
+
messageId,
|
|
3303
|
+
conversation,
|
|
3304
|
+
question: message.question,
|
|
3305
|
+
context: "",
|
|
3306
|
+
error: "",
|
|
3307
|
+
loading: true
|
|
3308
|
+
};
|
|
3309
|
+
state.queryContextDialog = dialog;
|
|
3310
|
+
await loadQueryContext(dialog, conversation);
|
|
3311
|
+
}
|
|
3312
|
+
|
|
3313
|
+
async function loadQueryContext(dialog, conversation) {
|
|
3314
|
+
dialog.loading = true;
|
|
3315
|
+
dialog.error = "";
|
|
3316
|
+
updateQueryContextDialog();
|
|
3317
|
+
try {
|
|
3318
|
+
const response = await fetch(
|
|
3319
|
+
`/api/conversations/${encodeURIComponent(conversation.id)}/turns/${encodeURIComponent(conversation.turn_id)}/context?backend_url=${encodeURIComponent(state.backendUrl)}`,
|
|
3320
|
+
{ headers: authHeaders() }
|
|
3321
|
+
);
|
|
3322
|
+
const payload = await response.json().catch(() => ({}));
|
|
3323
|
+
if (!response.ok) throw new Error(formatApiResponseError(response, extractErrorMessage(payload)));
|
|
3324
|
+
dialog.context = String(payload.context || "");
|
|
3325
|
+
} catch (error) {
|
|
3326
|
+
dialog.error = error.message || "Could not load query context.";
|
|
3327
|
+
} finally {
|
|
3328
|
+
dialog.loading = false;
|
|
3329
|
+
if (state.queryContextDialog === dialog) {
|
|
3330
|
+
updateQueryContextDialog();
|
|
3331
|
+
}
|
|
3332
|
+
}
|
|
3333
|
+
}
|
|
3334
|
+
|
|
3335
|
+
function closeQueryContext() {
|
|
3336
|
+
const messageId = state.queryContextDialog?.messageId;
|
|
3337
|
+
state.queryContextDialog = null;
|
|
3338
|
+
const dialog = document.querySelector("#query-context-dialog");
|
|
3339
|
+
dialog?.close();
|
|
3340
|
+
dialog?.remove();
|
|
3341
|
+
document.querySelector(`[data-query-context="${messageId}"]`)?.focus({ preventScroll: true });
|
|
3342
|
+
}
|
|
3218
3343
|
function formatDuration(value) {
|
|
3219
3344
|
const numeric = Number(value);
|
|
3220
3345
|
if (!Number.isFinite(numeric)) {
|
|
@@ -3672,6 +3797,7 @@ async function refreshPasswordChangeRequirement() {
|
|
|
3672
3797
|
}
|
|
3673
3798
|
}
|
|
3674
3799
|
async function logout() {
|
|
3800
|
+
closeQueryContext();
|
|
3675
3801
|
if (state.dashboardEditMode) {
|
|
3676
3802
|
await flushPendingDashboardLayoutSave();
|
|
3677
3803
|
}
|
|
@@ -4210,7 +4336,46 @@ function getColumns(rows) {
|
|
|
4210
4336
|
});
|
|
4211
4337
|
return columns;
|
|
4212
4338
|
}
|
|
4213
|
-
|
|
4339
|
+
const TABLE_CELL_ALLOWED_TAGS = new Set([
|
|
4340
|
+
"A", "B", "BR", "CODE", "EM", "I", "LI", "OL", "P", "SMALL", "SPAN", "STRONG", "SUB", "SUP", "U", "UL"
|
|
4341
|
+
]);
|
|
4342
|
+
const TABLE_CELL_ALLOWED_LINK_PROTOCOLS = new Set(["http:", "https:", "mailto:", "tel:"]);
|
|
4343
|
+
function sanitizeTableCellHtml(value) {
|
|
4344
|
+
const template = document.createElement("template");
|
|
4345
|
+
template.innerHTML = String(value ?? "");
|
|
4346
|
+
Array.from(template.content.querySelectorAll("*")).forEach((element) => {
|
|
4347
|
+
if (!TABLE_CELL_ALLOWED_TAGS.has(element.tagName)) {
|
|
4348
|
+
element.replaceWith(...element.childNodes);
|
|
4349
|
+
return;
|
|
4350
|
+
}
|
|
4351
|
+
Array.from(element.attributes).forEach((attribute) => {
|
|
4352
|
+
if (element.tagName !== "A" || !["href", "target", "title"].includes(attribute.name.toLowerCase())) {
|
|
4353
|
+
element.removeAttribute(attribute.name);
|
|
4354
|
+
}
|
|
4355
|
+
});
|
|
4356
|
+
if (element.tagName !== "A") return;
|
|
4357
|
+
const href = element.getAttribute("href")?.trim() || "";
|
|
4358
|
+
if (href) {
|
|
4359
|
+
try {
|
|
4360
|
+
const url = new URL(href, window.location.origin);
|
|
4361
|
+
if (!TABLE_CELL_ALLOWED_LINK_PROTOCOLS.has(url.protocol)) {
|
|
4362
|
+
element.removeAttribute("href");
|
|
4363
|
+
}
|
|
4364
|
+
} catch {
|
|
4365
|
+
element.removeAttribute("href");
|
|
4366
|
+
}
|
|
4367
|
+
}
|
|
4368
|
+
const target = element.getAttribute("target");
|
|
4369
|
+
if (target && !["_blank", "_self"].includes(target)) {
|
|
4370
|
+
element.removeAttribute("target");
|
|
4371
|
+
}
|
|
4372
|
+
if (element.getAttribute("target") === "_blank") {
|
|
4373
|
+
element.setAttribute("rel", "noopener noreferrer");
|
|
4374
|
+
}
|
|
4375
|
+
});
|
|
4376
|
+
return template.innerHTML;
|
|
4377
|
+
}
|
|
4378
|
+
function renderDataTable(rows, options = {}) {
|
|
4214
4379
|
const columns = getColumns(rows);
|
|
4215
4380
|
if (!rows.length) {
|
|
4216
4381
|
return `<div class="data-table-empty">No rows returned.</div>`;
|
|
@@ -4227,7 +4392,13 @@ function renderDataTable(rows) {
|
|
|
4227
4392
|
<tbody>
|
|
4228
4393
|
${rows.map((row) => `
|
|
4229
4394
|
<tr>
|
|
4230
|
-
${columns.map((column) =>
|
|
4395
|
+
${columns.map((column) => {
|
|
4396
|
+
const value = row?.[column];
|
|
4397
|
+
const rendered = options.allowHtml && typeof value === "string"
|
|
4398
|
+
? sanitizeTableCellHtml(value)
|
|
4399
|
+
: escapeHtml(formatCellValue(value));
|
|
4400
|
+
return `<td>${rendered}</td>`;
|
|
4401
|
+
}).join("")}
|
|
4231
4402
|
</tr>`).join("")}
|
|
4232
4403
|
</tbody>
|
|
4233
4404
|
</table>
|