gaard-client 0.2.17__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.17 → gaard_client-0.2.20}/PKG-INFO +2 -2
- {gaard_client-0.2.17 → gaard_client-0.2.20}/pyproject.toml +2 -2
- {gaard_client-0.2.17 → gaard_client-0.2.20}/src/gaard_client/client-web/assets/main.js +96 -0
- {gaard_client-0.2.17 → gaard_client-0.2.20}/src/gaard_client/client-web/assets/styles.css +51 -0
- {gaard_client-0.2.17 → gaard_client-0.2.20}/src/gaard_client/main.py +17 -1
- {gaard_client-0.2.17 → gaard_client-0.2.20}/src/gaard_client.egg-info/PKG-INFO +2 -2
- {gaard_client-0.2.17 → gaard_client-0.2.20}/src/gaard_client.egg-info/requires.txt +1 -1
- {gaard_client-0.2.17 → gaard_client-0.2.20}/tests/test_client_app.py +35 -0
- {gaard_client-0.2.17 → gaard_client-0.2.20}/README.md +0 -0
- {gaard_client-0.2.17 → gaard_client-0.2.20}/setup.cfg +0 -0
- {gaard_client-0.2.17 → gaard_client-0.2.20}/src/gaard_client/__init__.py +0 -0
- {gaard_client-0.2.17 → gaard_client-0.2.20}/src/gaard_client/cli.py +0 -0
- {gaard_client-0.2.17 → gaard_client-0.2.20}/src/gaard_client/cli_commands.py +0 -0
- {gaard_client-0.2.17 → gaard_client-0.2.20}/src/gaard_client/client-web/assets/getgaard.svg +0 -0
- {gaard_client-0.2.17 → gaard_client-0.2.20}/src/gaard_client/client-web/index.html +0 -0
- {gaard_client-0.2.17 → gaard_client-0.2.20}/src/gaard_client.egg-info/SOURCES.txt +0 -0
- {gaard_client-0.2.17 → gaard_client-0.2.20}/src/gaard_client.egg-info/dependency_links.txt +0 -0
- {gaard_client-0.2.17 → gaard_client-0.2.20}/src/gaard_client.egg-info/entry_points.txt +0 -0
- {gaard_client-0.2.17 → gaard_client-0.2.20}/src/gaard_client.egg-info/top_level.txt +0 -0
- {gaard_client-0.2.17 → 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,
|
|
@@ -1385,6 +1386,9 @@ function render(options = {}) {
|
|
|
1385
1386
|
button.addEventListener("click", changeView);
|
|
1386
1387
|
});
|
|
1387
1388
|
document.querySelector("[data-toggle-sidebar]")?.addEventListener("click", toggleSidebarCollapsed);
|
|
1389
|
+
document.querySelectorAll("[data-query-context]").forEach((button) => {
|
|
1390
|
+
button.addEventListener("click", openQueryContext);
|
|
1391
|
+
});
|
|
1388
1392
|
document.querySelectorAll("[data-open-conversation]").forEach((button) => {
|
|
1389
1393
|
button.addEventListener("click", openConversation);
|
|
1390
1394
|
});
|
|
@@ -3239,12 +3243,103 @@ function renderMeta(message, rows) {
|
|
|
3239
3243
|
<div><dt>Datasource</dt><dd>${escapeHtml(metadata.datasource_id || "-")}</dd></div>
|
|
3240
3244
|
<div><dt>Mode</dt><dd>${escapeHtml(formatMode(mode))}</dd></div>
|
|
3241
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
|
+
` : ""}
|
|
3242
3249
|
</dl>
|
|
3243
3250
|
<button class="data-toggle" type="button" data-toggle-data="${message.id}" aria-expanded="${message.dataOpen ? "true" : "false"}">
|
|
3244
3251
|
${escapeHtml(buttonText)}
|
|
3245
3252
|
</button>
|
|
3246
3253
|
</div>`;
|
|
3247
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
|
+
}
|
|
3248
3343
|
function formatDuration(value) {
|
|
3249
3344
|
const numeric = Number(value);
|
|
3250
3345
|
if (!Number.isFinite(numeric)) {
|
|
@@ -3702,6 +3797,7 @@ async function refreshPasswordChangeRequirement() {
|
|
|
3702
3797
|
}
|
|
3703
3798
|
}
|
|
3704
3799
|
async function logout() {
|
|
3800
|
+
closeQueryContext();
|
|
3705
3801
|
if (state.dashboardEditMode) {
|
|
3706
3802
|
await flushPendingDashboardLayoutSave();
|
|
3707
3803
|
}
|
|
@@ -936,6 +936,7 @@ label {
|
|
|
936
936
|
|
|
937
937
|
.meta {
|
|
938
938
|
display: flex;
|
|
939
|
+
align-items: center;
|
|
939
940
|
flex-wrap: wrap;
|
|
940
941
|
gap: 12px;
|
|
941
942
|
margin: 0;
|
|
@@ -2047,6 +2048,56 @@ button.primary {
|
|
|
2047
2048
|
color: var(--accent);
|
|
2048
2049
|
}
|
|
2049
2050
|
|
|
2051
|
+
.query-context-link {
|
|
2052
|
+
min-height: 0;
|
|
2053
|
+
padding: 0;
|
|
2054
|
+
border: 0;
|
|
2055
|
+
background: transparent;
|
|
2056
|
+
color: var(--accent);
|
|
2057
|
+
text-decoration: underline;
|
|
2058
|
+
cursor: pointer;
|
|
2059
|
+
font: inherit;
|
|
2060
|
+
line-height: inherit;
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
.query-context-dialog {
|
|
2064
|
+
width: min(640px, calc(100% - 32px));
|
|
2065
|
+
max-height: calc(100dvh - 32px);
|
|
2066
|
+
overflow: auto;
|
|
2067
|
+
padding: 24px;
|
|
2068
|
+
border: 1px solid #dfe7ef;
|
|
2069
|
+
border-radius: 8px;
|
|
2070
|
+
color: #111a24;
|
|
2071
|
+
background: #fff;
|
|
2072
|
+
}
|
|
2073
|
+
|
|
2074
|
+
.query-context-dialog::backdrop {
|
|
2075
|
+
background: rgba(17, 26, 36, 0.34);
|
|
2076
|
+
}
|
|
2077
|
+
|
|
2078
|
+
.query-context-dialog h2 {
|
|
2079
|
+
margin: 0 0 12px;
|
|
2080
|
+
font-size: 20px;
|
|
2081
|
+
}
|
|
2082
|
+
|
|
2083
|
+
.query-context-question {
|
|
2084
|
+
overflow-wrap: anywhere;
|
|
2085
|
+
}
|
|
2086
|
+
|
|
2087
|
+
.query-context-dialog textarea {
|
|
2088
|
+
box-sizing: border-box;
|
|
2089
|
+
width: 100%;
|
|
2090
|
+
min-height: 160px;
|
|
2091
|
+
max-height: 45dvh;
|
|
2092
|
+
padding: 12px;
|
|
2093
|
+
margin-bottom: 16px;
|
|
2094
|
+
border: 1px solid #dfe7ef;
|
|
2095
|
+
border-radius: 6px;
|
|
2096
|
+
resize: vertical;
|
|
2097
|
+
font: inherit;
|
|
2098
|
+
line-height: 1.5;
|
|
2099
|
+
}
|
|
2100
|
+
|
|
2050
2101
|
.dashboard-dialog-overlay {
|
|
2051
2102
|
position: fixed;
|
|
2052
2103
|
inset: 0;
|
|
@@ -20,7 +20,7 @@ DEFAULT_BACKEND_URL = "http://localhost:8000"
|
|
|
20
20
|
|
|
21
21
|
app = FastAPI(
|
|
22
22
|
title="GAARD Client",
|
|
23
|
-
version="0.2.
|
|
23
|
+
version="0.2.20",
|
|
24
24
|
description="Community client for asking governed natural-language questions.",
|
|
25
25
|
)
|
|
26
26
|
|
|
@@ -325,6 +325,22 @@ async def get_conversation_backend(
|
|
|
325
325
|
)
|
|
326
326
|
|
|
327
327
|
|
|
328
|
+
@app.get("/api/conversations/{conversation_id}/turns/{turn_id}/context")
|
|
329
|
+
async def get_query_context_backend(
|
|
330
|
+
conversation_id: str,
|
|
331
|
+
turn_id: str,
|
|
332
|
+
backend_url: str | None = None,
|
|
333
|
+
authorization: str | None = Header(default=None),
|
|
334
|
+
) -> dict[str, Any]:
|
|
335
|
+
resolved_backend_url = normalize_backend_url(backend_url or get_default_backend_url())
|
|
336
|
+
return await proxy_json_request(
|
|
337
|
+
"GET",
|
|
338
|
+
f"{resolved_backend_url}/api/v1/conversations/{conversation_id}/turns/{turn_id}/context",
|
|
339
|
+
timeout=30.0,
|
|
340
|
+
request_kwargs={"headers": backend_auth_headers(authorization)},
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
|
|
328
344
|
@app.post("/api/query/explain")
|
|
329
345
|
async def explain_query_backend(
|
|
330
346
|
request: ClientQueryExplanationRequest,
|
|
@@ -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
|
|
@@ -703,6 +703,41 @@ def test_client_app_proxies_conversation_history(monkeypatch: Any) -> None:
|
|
|
703
703
|
]
|
|
704
704
|
|
|
705
705
|
|
|
706
|
+
def test_client_app_proxies_query_context_snapshot(monkeypatch: Any) -> None:
|
|
707
|
+
captured: dict[str, Any] = {}
|
|
708
|
+
|
|
709
|
+
class FakeAsyncClient:
|
|
710
|
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
711
|
+
pass
|
|
712
|
+
|
|
713
|
+
async def __aenter__(self) -> "FakeAsyncClient":
|
|
714
|
+
return self
|
|
715
|
+
|
|
716
|
+
async def __aexit__(self, exc_type: Any, exc: Any, traceback: Any) -> None:
|
|
717
|
+
pass
|
|
718
|
+
|
|
719
|
+
async def request(self, method: str, url: str, **kwargs: Any) -> httpx.Response:
|
|
720
|
+
captured.update(method=method, url=url, headers=kwargs["headers"])
|
|
721
|
+
return httpx.Response(
|
|
722
|
+
200,
|
|
723
|
+
request=httpx.Request(method, url),
|
|
724
|
+
json={"context": "How many active patients in May?", "turn_id": "turn-2"},
|
|
725
|
+
)
|
|
726
|
+
|
|
727
|
+
monkeypatch.setattr(httpx, "AsyncClient", FakeAsyncClient)
|
|
728
|
+
response = TestClient(app).get(
|
|
729
|
+
"/api/conversations/chat-1/turns/turn-2/context?backend_url=http://backend.example/",
|
|
730
|
+
headers={"Authorization": "Bearer token"},
|
|
731
|
+
)
|
|
732
|
+
assert response.status_code == 200
|
|
733
|
+
assert response.json()["context"] == "How many active patients in May?"
|
|
734
|
+
assert captured == {
|
|
735
|
+
"method": "GET",
|
|
736
|
+
"url": "http://backend.example/api/v1/conversations/chat-1/turns/turn-2/context",
|
|
737
|
+
"headers": {"Authorization": "Bearer token"},
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
|
|
706
741
|
def test_client_app_proxies_query_conversation_id(monkeypatch: Any) -> None:
|
|
707
742
|
captured: dict[str, Any] = {}
|
|
708
743
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|