@burdenoff/microfe-semanticfed 2026.1031.6 → 2026.1031.8
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/dist/semanticfed/api/semanticfedGraphql.js +1 -1
- package/dist/semanticfed/components/AskQuestionPanel.js +221 -103
- package/dist/semanticfed/components/AskQuestionPanel.js.map +1 -1
- package/dist/semanticfed/components/NlAssistSettings.js +143 -0
- package/dist/semanticfed/components/NlAssistSettings.js.map +1 -0
- package/dist/semanticfed/components/SavedQueryRunsPanel.js +407 -0
- package/dist/semanticfed/components/SavedQueryRunsPanel.js.map +1 -0
- package/dist/semanticfed/hooks/useNlQuery.js +63 -11
- package/dist/semanticfed/hooks/useNlQuery.js.map +1 -1
- package/dist/semanticfed/hooks/useQueryRuns.js +171 -0
- package/dist/semanticfed/hooks/useQueryRuns.js.map +1 -0
- package/dist/semanticfed/pages/QueryConsolePage.js +138 -138
- package/dist/semanticfed/pages/QueryConsolePage.js.map +1 -1
- package/dist/semanticfed/providers/SemanticFedProvider.js +22 -10
- package/dist/semanticfed/providers/SemanticFedProvider.js.map +1 -1
- package/dist/semanticfed/utils/format.js +8 -0
- package/dist/semanticfed/utils/format.js.map +1 -0
- package/package.json +1 -1
|
@@ -30,6 +30,6 @@ async function o(o, s = {}, c) {
|
|
|
30
30
|
return /^\s*mutation\b/.test(o) && i(), l.data;
|
|
31
31
|
}
|
|
32
32
|
//#endregion
|
|
33
|
-
export { a as SemRequestError, o as semRequest };
|
|
33
|
+
export { a as SemRequestError, i as clearGraphqlReadCaches, o as semRequest };
|
|
34
34
|
|
|
35
35
|
//# sourceMappingURL=semanticfedGraphql.js.map
|
|
@@ -1,161 +1,279 @@
|
|
|
1
1
|
import { useTr as e } from "../hooks/useTr.js";
|
|
2
2
|
import { useSemAskQuestion as t, useSemNlSuggestions as n } from "../hooks/useNlQuery.js";
|
|
3
3
|
import { sqlErrorMessage as r } from "../hooks/useSqlConsole.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { NlAssistSettings as i } from "./NlAssistSettings.js";
|
|
5
|
+
import { useRef as a, useState as o } from "react";
|
|
6
|
+
import { CornerDownRight as s, HelpCircle as c, Loader2 as l, MessageSquareText as u, PencilLine as d, RotateCcw as f, Send as p, Sparkles as m } from "lucide-react";
|
|
7
|
+
import { jsx as h, jsxs as g } from "react/jsx-runtime";
|
|
8
|
+
import { Badge as _, Button as v, Card as y, CardContent as b, CardHeader as x, CardTitle as S } from "@burdenoff/fe-libs/ui";
|
|
8
9
|
//#region src/semanticfed/components/AskQuestionPanel.tsx
|
|
9
|
-
var
|
|
10
|
-
function
|
|
10
|
+
var C = 1e3, w = 6, T = 10;
|
|
11
|
+
function E(e) {
|
|
12
|
+
return e.filter((e) => e.answer?.translation.status === "TRANSLATED").map((e) => e.answer?.translation.rephrasedQuestion ?? e.question).slice(-T);
|
|
13
|
+
}
|
|
14
|
+
function D(e) {
|
|
11
15
|
return e == null ? "NULL" : typeof e == "string" ? `'${e}'` : typeof e == "object" ? JSON.stringify(e) : String(e);
|
|
12
16
|
}
|
|
13
|
-
function
|
|
17
|
+
function O(e, t) {
|
|
14
18
|
let n = [e.entity, e.field].filter(Boolean).join(".");
|
|
15
19
|
switch (e.kind) {
|
|
16
20
|
case "MEASURE": return `${e.aggregation ?? ""}(${n})${e.governed ? ` ${t}` : ""}`;
|
|
17
|
-
case "FILTER": return `${n} ${e.operator ?? "="} ${
|
|
21
|
+
case "FILTER": return `${n} ${e.operator ?? "="} ${D(e.value)}`;
|
|
18
22
|
case "ORDER": return `${n} ${e.direction ?? ""}`.trim();
|
|
19
23
|
case "LIMIT": return String(e.count ?? "");
|
|
20
24
|
case "JOIN": return e.relationship ? `${n} (${e.relationship})` : n;
|
|
21
25
|
default: return n;
|
|
22
26
|
}
|
|
23
27
|
}
|
|
24
|
-
function
|
|
25
|
-
|
|
28
|
+
function k(e, t) {
|
|
29
|
+
return {
|
|
30
|
+
REPHRASED: {
|
|
31
|
+
text: t("semanticfed.queryConsole.ask.assist.rephrased", "Reworded by your AI provider ({provider}) as: “{question}”", {
|
|
32
|
+
provider: e.assistProvider ?? "",
|
|
33
|
+
question: e.rephrasedQuestion ?? ""
|
|
34
|
+
}),
|
|
35
|
+
tone: "info"
|
|
36
|
+
},
|
|
37
|
+
NO_IMPROVEMENT: {
|
|
38
|
+
text: t("semanticfed.queryConsole.ask.assist.noImprovement", "Your AI provider could not reword this question into one the model can answer."),
|
|
39
|
+
tone: "warn"
|
|
40
|
+
},
|
|
41
|
+
QUOTA_EXHAUSTED: {
|
|
42
|
+
text: t("semanticfed.queryConsole.ask.assist.quota", "AI assistance is paused: this workspace has used today’s AI operations."),
|
|
43
|
+
tone: "warn"
|
|
44
|
+
},
|
|
45
|
+
QUOTA_UNAVAILABLE: {
|
|
46
|
+
text: t("semanticfed.queryConsole.ask.assist.quotaUnavailable", "AI assistance is unavailable: the AI-operation allowance for this workspace could not be checked."),
|
|
47
|
+
tone: "warn"
|
|
48
|
+
},
|
|
49
|
+
PROVIDER_ERROR: {
|
|
50
|
+
text: t("semanticfed.queryConsole.ask.assist.providerError", "Your AI provider could not be used for this question (it was unreachable, refused the key, or returned an error)."),
|
|
51
|
+
tone: "warn"
|
|
52
|
+
},
|
|
53
|
+
NOT_CONFIGURED: {
|
|
54
|
+
text: t("semanticfed.queryConsole.ask.assist.notConfigured", "AI assistance is on, but its provider connection is missing or revoked. Choose a connection under AI assistance."),
|
|
55
|
+
tone: "warn"
|
|
56
|
+
}
|
|
57
|
+
}[e.assist] ?? null;
|
|
58
|
+
}
|
|
59
|
+
function A({ translation: t, governedLabel: n, onOpenInEditor: r, latest: i }) {
|
|
60
|
+
let a = e(), o = /* @__PURE__ */ h("pre", {
|
|
61
|
+
className: "overflow-x-auto rounded bg-muted p-3 font-mono text-xs text-foreground",
|
|
62
|
+
"data-testid": i ? "nl-ask-sql" : void 0,
|
|
63
|
+
children: t.sql
|
|
64
|
+
});
|
|
65
|
+
return /* @__PURE__ */ g("div", {
|
|
66
|
+
className: "space-y-2 rounded border p-3",
|
|
67
|
+
"data-testid": i ? "nl-ask-interpretation" : void 0,
|
|
68
|
+
children: [
|
|
69
|
+
/* @__PURE__ */ g("div", {
|
|
70
|
+
className: "flex flex-wrap items-center justify-between gap-2",
|
|
71
|
+
children: [/* @__PURE__ */ g("div", {
|
|
72
|
+
className: "flex flex-wrap items-center gap-2 text-xs",
|
|
73
|
+
children: [
|
|
74
|
+
/* @__PURE__ */ h("span", {
|
|
75
|
+
className: "font-medium",
|
|
76
|
+
children: a("semanticfed.queryConsole.ask.interpretation", "Interpretation")
|
|
77
|
+
}),
|
|
78
|
+
t.followUp && /* @__PURE__ */ g(_, {
|
|
79
|
+
variant: "outline",
|
|
80
|
+
"data-testid": i ? "nl-ask-followup" : void 0,
|
|
81
|
+
children: [/* @__PURE__ */ h(s, { className: "mr-1 h-3 w-3" }), a("semanticfed.queryConsole.ask.followUp", "Follow-up")]
|
|
82
|
+
}),
|
|
83
|
+
/* @__PURE__ */ h(_, {
|
|
84
|
+
variant: "outline",
|
|
85
|
+
"data-testid": i ? "nl-ask-confidence" : void 0,
|
|
86
|
+
children: a("semanticfed.queryConsole.ask.confidence", "Confidence {value}%", { value: Math.round(t.confidence * 100) })
|
|
87
|
+
}),
|
|
88
|
+
t.steps.map((e, t) => /* @__PURE__ */ g(_, {
|
|
89
|
+
variant: "secondary",
|
|
90
|
+
className: "font-mono",
|
|
91
|
+
children: [
|
|
92
|
+
e.kind.replace("_", " "),
|
|
93
|
+
": ",
|
|
94
|
+
O(e, n)
|
|
95
|
+
]
|
|
96
|
+
}, `${e.kind}-${t}`))
|
|
97
|
+
]
|
|
98
|
+
}), /* @__PURE__ */ g(v, {
|
|
99
|
+
size: "sm",
|
|
100
|
+
variant: "outline",
|
|
101
|
+
onClick: () => r(t.sql ?? ""),
|
|
102
|
+
"data-testid": i ? "nl-ask-open-editor" : void 0,
|
|
103
|
+
children: [/* @__PURE__ */ h(d, { className: "mr-2 h-4 w-4" }), a("semanticfed.queryConsole.ask.openInEditor", "Edit as SQL")]
|
|
104
|
+
})]
|
|
105
|
+
}),
|
|
106
|
+
i ? o : /* @__PURE__ */ g("details", { children: [/* @__PURE__ */ h("summary", {
|
|
107
|
+
className: "cursor-pointer text-xs text-muted-foreground",
|
|
108
|
+
children: a("semanticfed.queryConsole.ask.showSql", "Show SQL")
|
|
109
|
+
}), o] }),
|
|
110
|
+
t.unmatchedTerms.length > 0 && /* @__PURE__ */ h("p", {
|
|
111
|
+
className: "text-xs text-muted-foreground",
|
|
112
|
+
children: a("semanticfed.queryConsole.ask.ignored", "Ignored words: {terms}", { terms: t.unmatchedTerms.join(", ") })
|
|
113
|
+
})
|
|
114
|
+
]
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
function j({ modelId: s, maxRows: d, onAnswer: _, onError: T, onOpenInEditor: D }) {
|
|
118
|
+
let O = e(), [j, M] = o(""), [N, P] = o([]), [F, I] = o(s), [L, R] = o(!1), z = a(0), B = n(s), V = t();
|
|
119
|
+
F !== s && (I(s), P([]));
|
|
120
|
+
let H = async (e) => {
|
|
26
121
|
let t = e.trim();
|
|
27
|
-
if (!
|
|
28
|
-
|
|
122
|
+
if (!s || t === "" || V.isPending) return;
|
|
123
|
+
let n = E(N);
|
|
124
|
+
z.current += 1;
|
|
125
|
+
let i = z.current;
|
|
126
|
+
try {
|
|
127
|
+
let e = await V.mutateAsync({
|
|
29
128
|
question: t,
|
|
30
|
-
modelId:
|
|
31
|
-
maxRows:
|
|
129
|
+
modelId: s,
|
|
130
|
+
maxRows: d,
|
|
131
|
+
...n.length > 0 ? { history: n } : {}
|
|
32
132
|
});
|
|
33
|
-
|
|
133
|
+
P((n) => [...n, {
|
|
134
|
+
id: i,
|
|
135
|
+
question: t,
|
|
136
|
+
answer: e,
|
|
137
|
+
error: null
|
|
138
|
+
}]), M(""), _(e);
|
|
34
139
|
} catch (e) {
|
|
35
|
-
|
|
140
|
+
let n = r(e);
|
|
141
|
+
P((e) => [...e, {
|
|
142
|
+
id: i,
|
|
143
|
+
question: t,
|
|
144
|
+
answer: null,
|
|
145
|
+
error: n
|
|
146
|
+
}]), T(n);
|
|
36
147
|
}
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
},
|
|
40
|
-
return /* @__PURE__ */
|
|
148
|
+
}, U = (e) => {
|
|
149
|
+
M(e), H(e);
|
|
150
|
+
}, W = (N.at(-1) ?? null)?.answer?.translation ?? null, G = (W?.status === "NEEDS_CLARIFICATION" ? W.suggestions : N.length === 0 ? B.data ?? [] : []).slice(0, w), K = O("semanticfed.queryConsole.ask.governed", "(governed)");
|
|
151
|
+
return /* @__PURE__ */ g(y, {
|
|
41
152
|
"data-testid": "nl-ask-panel",
|
|
42
|
-
children: [/* @__PURE__ */
|
|
153
|
+
children: [/* @__PURE__ */ g(x, {
|
|
43
154
|
className: "pb-3",
|
|
44
|
-
children: [/* @__PURE__ */
|
|
45
|
-
className: "flex items-center gap-2
|
|
46
|
-
children: [/* @__PURE__ */
|
|
47
|
-
|
|
155
|
+
children: [/* @__PURE__ */ g("div", {
|
|
156
|
+
className: "flex flex-wrap items-center justify-between gap-2",
|
|
157
|
+
children: [/* @__PURE__ */ g(S, {
|
|
158
|
+
className: "flex items-center gap-2 text-base",
|
|
159
|
+
children: [/* @__PURE__ */ h(u, { className: "h-4 w-4" }), O("semanticfed.queryConsole.ask.title", "Ask a question")]
|
|
160
|
+
}), /* @__PURE__ */ g("div", {
|
|
161
|
+
className: "flex flex-wrap gap-2",
|
|
162
|
+
children: [N.length > 0 && /* @__PURE__ */ g(v, {
|
|
163
|
+
size: "sm",
|
|
164
|
+
variant: "ghost",
|
|
165
|
+
onClick: () => P([]),
|
|
166
|
+
disabled: V.isPending,
|
|
167
|
+
"data-testid": "nl-ask-new-conversation",
|
|
168
|
+
children: [/* @__PURE__ */ h(f, { className: "mr-2 h-4 w-4" }), O("semanticfed.queryConsole.ask.newConversation", "New conversation")]
|
|
169
|
+
}), /* @__PURE__ */ g(v, {
|
|
170
|
+
size: "sm",
|
|
171
|
+
variant: L ? "secondary" : "ghost",
|
|
172
|
+
onClick: () => R((e) => !e),
|
|
173
|
+
"aria-expanded": L,
|
|
174
|
+
"data-testid": "nl-assist-toggle",
|
|
175
|
+
children: [/* @__PURE__ */ h(m, { className: "mr-2 h-4 w-4" }), O("semanticfed.queryConsole.ask.assistSettings", "AI assistance")]
|
|
176
|
+
})]
|
|
177
|
+
})]
|
|
178
|
+
}), /* @__PURE__ */ h("p", {
|
|
48
179
|
className: "text-xs text-muted-foreground",
|
|
49
|
-
children:
|
|
180
|
+
children: O("semanticfed.queryConsole.ask.conversationDescription", "Ask in plain English, then refine with follow-ups such as “and by status?”, “only EU” or “top 3 instead”. Answers come from the model’s governed metrics and dimensions, with your access policies applied, and the SQL that ran is shown.")
|
|
50
181
|
})]
|
|
51
|
-
}), /* @__PURE__ */
|
|
182
|
+
}), /* @__PURE__ */ g(b, {
|
|
52
183
|
className: "space-y-3",
|
|
53
184
|
children: [
|
|
54
|
-
/* @__PURE__ */
|
|
185
|
+
L && /* @__PURE__ */ h(i, {}),
|
|
186
|
+
N.length > 0 && /* @__PURE__ */ h("ol", {
|
|
187
|
+
className: "space-y-3",
|
|
188
|
+
"data-testid": "nl-ask-thread",
|
|
189
|
+
"aria-live": "polite",
|
|
190
|
+
children: N.map((e, t) => {
|
|
191
|
+
let n = t === N.length - 1, r = e.answer?.translation ?? null, i = r ? k(r, O) : null;
|
|
192
|
+
return /* @__PURE__ */ g("li", {
|
|
193
|
+
className: "space-y-2",
|
|
194
|
+
"data-testid": "nl-ask-turn",
|
|
195
|
+
children: [
|
|
196
|
+
/* @__PURE__ */ h("p", {
|
|
197
|
+
className: "w-fit max-w-full rounded-lg bg-muted px-3 py-2 text-sm",
|
|
198
|
+
children: e.question
|
|
199
|
+
}),
|
|
200
|
+
e.error && /* @__PURE__ */ h("p", {
|
|
201
|
+
className: "text-xs text-destructive",
|
|
202
|
+
children: e.error
|
|
203
|
+
}),
|
|
204
|
+
i && /* @__PURE__ */ g("p", {
|
|
205
|
+
className: `flex items-start gap-1 text-xs ${i.tone === "warn" ? "text-muted-foreground" : "text-primary"}`,
|
|
206
|
+
"data-testid": n ? "nl-ask-assist-note" : void 0,
|
|
207
|
+
children: [/* @__PURE__ */ h(m, { className: "mt-0.5 h-3 w-3 shrink-0" }), i.text]
|
|
208
|
+
}),
|
|
209
|
+
r?.status === "NEEDS_CLARIFICATION" && /* @__PURE__ */ g("div", {
|
|
210
|
+
className: "flex items-start gap-2 rounded border border-dashed p-3 text-sm",
|
|
211
|
+
"data-testid": n ? "nl-ask-clarification" : void 0,
|
|
212
|
+
children: [/* @__PURE__ */ h(c, { className: "mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" }), /* @__PURE__ */ g("div", {
|
|
213
|
+
className: "min-w-0 space-y-1",
|
|
214
|
+
children: [/* @__PURE__ */ h("p", { children: r.clarification }), r.unmatchedTerms.length > 0 && /* @__PURE__ */ h("p", {
|
|
215
|
+
className: "text-xs text-muted-foreground",
|
|
216
|
+
children: O("semanticfed.queryConsole.ask.unmatched", "Not found in the model: {terms}", { terms: r.unmatchedTerms.join(", ") })
|
|
217
|
+
})]
|
|
218
|
+
})]
|
|
219
|
+
}),
|
|
220
|
+
r?.status === "TRANSLATED" && r.sql && /* @__PURE__ */ h(A, {
|
|
221
|
+
translation: r,
|
|
222
|
+
governedLabel: K,
|
|
223
|
+
onOpenInEditor: D,
|
|
224
|
+
latest: n
|
|
225
|
+
})
|
|
226
|
+
]
|
|
227
|
+
}, e.id);
|
|
228
|
+
})
|
|
229
|
+
}),
|
|
230
|
+
/* @__PURE__ */ g("form", {
|
|
55
231
|
className: "flex flex-col gap-2 sm:flex-row",
|
|
56
232
|
onSubmit: (e) => {
|
|
57
|
-
e.preventDefault(),
|
|
233
|
+
e.preventDefault(), H(j);
|
|
58
234
|
},
|
|
59
235
|
children: [
|
|
60
|
-
/* @__PURE__ */
|
|
236
|
+
/* @__PURE__ */ h("label", {
|
|
61
237
|
className: "sr-only",
|
|
62
238
|
htmlFor: "nl-ask-input",
|
|
63
|
-
children:
|
|
239
|
+
children: O("semanticfed.queryConsole.ask.inputLabel", "Your question")
|
|
64
240
|
}),
|
|
65
|
-
/* @__PURE__ */
|
|
241
|
+
/* @__PURE__ */ h("input", {
|
|
66
242
|
id: "nl-ask-input",
|
|
67
243
|
"data-testid": "nl-ask-input",
|
|
68
244
|
className: "min-w-0 flex-1 rounded border bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-primary",
|
|
69
|
-
value:
|
|
70
|
-
maxLength:
|
|
71
|
-
onChange: (e) =>
|
|
72
|
-
placeholder:
|
|
73
|
-
disabled: !
|
|
245
|
+
value: j,
|
|
246
|
+
maxLength: C,
|
|
247
|
+
onChange: (e) => M(e.target.value),
|
|
248
|
+
placeholder: N.length > 0 ? O("semanticfed.queryConsole.ask.followUpPlaceholder", "Ask a follow-up, e.g. and by status?") : O("semanticfed.queryConsole.ask.placeholder", "e.g. top 5 regions by revenue"),
|
|
249
|
+
disabled: !s
|
|
74
250
|
}),
|
|
75
|
-
/* @__PURE__ */
|
|
251
|
+
/* @__PURE__ */ g(v, {
|
|
76
252
|
type: "submit",
|
|
77
253
|
size: "sm",
|
|
78
254
|
className: "sm:self-stretch",
|
|
79
|
-
disabled: !
|
|
255
|
+
disabled: !s || j.trim() === "" || V.isPending,
|
|
80
256
|
"data-testid": "nl-ask-submit",
|
|
81
|
-
children: [
|
|
257
|
+
children: [V.isPending ? /* @__PURE__ */ h(l, { className: "mr-2 h-4 w-4 animate-spin" }) : /* @__PURE__ */ h(p, { className: "mr-2 h-4 w-4" }), O("semanticfed.queryConsole.ask.submit", "Ask")]
|
|
82
258
|
})
|
|
83
259
|
]
|
|
84
260
|
}),
|
|
85
|
-
|
|
261
|
+
G.length > 0 && /* @__PURE__ */ h("div", {
|
|
86
262
|
className: "flex flex-wrap gap-2",
|
|
87
263
|
"data-testid": "nl-ask-suggestions",
|
|
88
|
-
children:
|
|
264
|
+
children: G.map((e) => /* @__PURE__ */ h("button", {
|
|
89
265
|
type: "button",
|
|
90
266
|
className: "rounded-full border px-3 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground",
|
|
91
|
-
onClick: () =>
|
|
92
|
-
disabled:
|
|
267
|
+
onClick: () => U(e),
|
|
268
|
+
disabled: V.isPending,
|
|
93
269
|
children: e
|
|
94
270
|
}, e))
|
|
95
|
-
}),
|
|
96
|
-
F?.status === "NEEDS_CLARIFICATION" && /* @__PURE__ */ d("div", {
|
|
97
|
-
className: "flex items-start gap-2 rounded border border-dashed p-3 text-sm",
|
|
98
|
-
"data-testid": "nl-ask-clarification",
|
|
99
|
-
children: [/* @__PURE__ */ u(a, { className: "mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" }), /* @__PURE__ */ d("div", {
|
|
100
|
-
className: "min-w-0 space-y-1",
|
|
101
|
-
children: [/* @__PURE__ */ u("p", { children: F.clarification }), F.unmatchedTerms.length > 0 && /* @__PURE__ */ u("p", {
|
|
102
|
-
className: "text-xs text-muted-foreground",
|
|
103
|
-
children: E("semanticfed.queryConsole.ask.unmatched", "Not found in the model: {terms}", { terms: F.unmatchedTerms.join(", ") })
|
|
104
|
-
})]
|
|
105
|
-
})]
|
|
106
|
-
}),
|
|
107
|
-
F?.status === "TRANSLATED" && F.sql && /* @__PURE__ */ d("div", {
|
|
108
|
-
className: "space-y-2 rounded border p-3",
|
|
109
|
-
"data-testid": "nl-ask-interpretation",
|
|
110
|
-
children: [
|
|
111
|
-
/* @__PURE__ */ d("div", {
|
|
112
|
-
className: "flex flex-wrap items-center justify-between gap-2",
|
|
113
|
-
children: [/* @__PURE__ */ d("div", {
|
|
114
|
-
className: "flex flex-wrap items-center gap-2 text-xs",
|
|
115
|
-
children: [
|
|
116
|
-
/* @__PURE__ */ u("span", {
|
|
117
|
-
className: "font-medium",
|
|
118
|
-
children: E("semanticfed.queryConsole.ask.interpretation", "Interpretation")
|
|
119
|
-
}),
|
|
120
|
-
/* @__PURE__ */ u(f, {
|
|
121
|
-
variant: "outline",
|
|
122
|
-
"data-testid": "nl-ask-confidence",
|
|
123
|
-
children: E("semanticfed.queryConsole.ask.confidence", "Confidence {value}%", { value: Math.round(F.confidence * 100) })
|
|
124
|
-
}),
|
|
125
|
-
F.steps.map((e, t) => /* @__PURE__ */ d(f, {
|
|
126
|
-
variant: "secondary",
|
|
127
|
-
className: "font-mono",
|
|
128
|
-
children: [
|
|
129
|
-
e.kind.replace("_", " "),
|
|
130
|
-
": ",
|
|
131
|
-
x(e, L)
|
|
132
|
-
]
|
|
133
|
-
}, `${e.kind}-${t}`))
|
|
134
|
-
]
|
|
135
|
-
}), /* @__PURE__ */ d(p, {
|
|
136
|
-
size: "sm",
|
|
137
|
-
variant: "outline",
|
|
138
|
-
onClick: () => T(F.sql ?? ""),
|
|
139
|
-
"data-testid": "nl-ask-open-editor",
|
|
140
|
-
children: [/* @__PURE__ */ u(c, { className: "mr-2 h-4 w-4" }), E("semanticfed.queryConsole.ask.openInEditor", "Edit as SQL")]
|
|
141
|
-
})]
|
|
142
|
-
}),
|
|
143
|
-
/* @__PURE__ */ u("pre", {
|
|
144
|
-
className: "overflow-x-auto rounded bg-muted p-3 font-mono text-xs text-foreground",
|
|
145
|
-
"data-testid": "nl-ask-sql",
|
|
146
|
-
children: F.sql
|
|
147
|
-
}),
|
|
148
|
-
F.unmatchedTerms.length > 0 && /* @__PURE__ */ u("p", {
|
|
149
|
-
className: "text-xs text-muted-foreground",
|
|
150
|
-
children: E("semanticfed.queryConsole.ask.ignored", "Ignored words: {terms}", { terms: F.unmatchedTerms.join(", ") })
|
|
151
|
-
})
|
|
152
|
-
]
|
|
153
271
|
})
|
|
154
272
|
]
|
|
155
273
|
})]
|
|
156
274
|
});
|
|
157
275
|
}
|
|
158
276
|
//#endregion
|
|
159
|
-
export {
|
|
277
|
+
export { j as AskQuestionPanel };
|
|
160
278
|
|
|
161
279
|
//# sourceMappingURL=AskQuestionPanel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AskQuestionPanel.js","names":[],"sources":["../../../src/semanticfed/components/AskQuestionPanel.tsx"],"sourcesContent":["import { useState } from 'react';\nimport { Badge, Button, Card, CardContent, CardHeader, CardTitle } from '@burdenoff/fe-libs/ui';\nimport { HelpCircle, Loader2, MessageSquareText, PencilLine, Send } from 'lucide-react';\n\nimport {\n type SemNlAnswer,\n type SemNlStep,\n useSemAskQuestion,\n useSemNlSuggestions,\n} from '../hooks/useNlQuery';\nimport { sqlErrorMessage } from '../hooks/useSqlConsole';\nimport { useTr } from '../hooks/useTr';\n\n/** Longest question the service accepts (MAX_QUESTION_LENGTH in wspace-semanticfed-svc). */\nconst MAX_QUESTION_LENGTH = 1000;\n/** Example questions shown under the input. */\nconst SUGGESTION_LIMIT = 6;\n\nexport interface AskQuestionPanelProps {\n modelId: string | null;\n maxRows: number;\n /** Called with every answer, so the page can show its governed result rows. */\n onAnswer: (answer: SemNlAnswer) => void;\n /** Called when a question fails before it is answered (network, quota, access). */\n onError: (message: string) => void;\n /** Open the generated SQL in the console's editor for review or editing. */\n onOpenInEditor: (sql: string) => void;\n}\n\nfunction formatValue(value: unknown): string {\n if (value === null || value === undefined) return 'NULL';\n if (typeof value === 'string') return `'${value}'`;\n if (typeof value === 'object') return JSON.stringify(value);\n return String(value);\n}\n\n/** One interpretation step as a short phrase, e.g. \"SUM(revenue) (governed)\". */\nfunction describeStep(step: SemNlStep, governedLabel: string): string {\n const target = [step.entity, step.field].filter(Boolean).join('.');\n switch (step.kind) {\n case 'MEASURE':\n return `${step.aggregation ?? ''}(${target})${step.governed ? ` ${governedLabel}` : ''}`;\n case 'FILTER':\n return `${target} ${step.operator ?? '='} ${formatValue(step.value)}`;\n case 'ORDER':\n return `${target} ${step.direction ?? ''}`.trim();\n case 'LIMIT':\n return String(step.count ?? '');\n case 'JOIN':\n return step.relationship ? `${target} (${step.relationship})` : target;\n default:\n return target;\n }\n}\n\n/**\n * \"Ask a question\" — natural-language questions over the semantic layer\n * (BOFF-4276). The question is translated into SQL over the model's governed\n * metrics and dimensions and run with the caller's access policies; the\n * interpretation (generated SQL, steps, confidence, ignored words) is always\n * shown so the answer can be checked, and opened in the SQL editor.\n */\nexport function AskQuestionPanel({\n modelId,\n maxRows,\n onAnswer,\n onError,\n onOpenInEditor,\n}: AskQuestionPanelProps) {\n const tr = useTr();\n const [question, setQuestion] = useState('');\n const [answer, setAnswer] = useState<SemNlAnswer | null>(null);\n const suggestions = useSemNlSuggestions(modelId);\n const ask = useSemAskQuestion();\n\n const submit = async (text: string) => {\n const trimmed = text.trim();\n if (!modelId || trimmed === '' || ask.isPending) return;\n try {\n const data = await ask.mutateAsync({ question: trimmed, modelId, maxRows });\n setAnswer(data);\n onAnswer(data);\n } catch (e) {\n setAnswer(null);\n onError(sqlErrorMessage(e));\n }\n };\n\n const askSuggestion = (text: string) => {\n setQuestion(text);\n void submit(text);\n };\n\n const translation = answer?.translation ?? null;\n const shownSuggestions = (\n translation?.status === 'NEEDS_CLARIFICATION'\n ? translation.suggestions\n : (suggestions.data ?? [])\n ).slice(0, SUGGESTION_LIMIT);\n const governedLabel = tr('semanticfed.queryConsole.ask.governed', '(governed)');\n\n return (\n <Card data-testid=\"nl-ask-panel\">\n <CardHeader className=\"pb-3\">\n <CardTitle className=\"flex items-center gap-2 text-base\">\n <MessageSquareText className=\"h-4 w-4\" />\n {tr('semanticfed.queryConsole.ask.title', 'Ask a question')}\n </CardTitle>\n <p className=\"text-xs text-muted-foreground\">\n {tr(\n 'semanticfed.queryConsole.ask.description',\n 'Ask in plain English. The question is answered from the model’s governed metrics and dimensions, with your access policies applied, and the SQL it ran is shown below.'\n )}\n </p>\n </CardHeader>\n <CardContent className=\"space-y-3\">\n <form\n className=\"flex flex-col gap-2 sm:flex-row\"\n onSubmit={(e) => {\n e.preventDefault();\n void submit(question);\n }}\n >\n <label className=\"sr-only\" htmlFor=\"nl-ask-input\">\n {tr('semanticfed.queryConsole.ask.inputLabel', 'Your question')}\n </label>\n <input\n id=\"nl-ask-input\"\n data-testid=\"nl-ask-input\"\n className=\"min-w-0 flex-1 rounded border bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-primary\"\n value={question}\n maxLength={MAX_QUESTION_LENGTH}\n onChange={(e) => setQuestion(e.target.value)}\n placeholder={tr(\n 'semanticfed.queryConsole.ask.placeholder',\n 'e.g. top 5 regions by revenue'\n )}\n disabled={!modelId}\n />\n <Button\n type=\"submit\"\n size=\"sm\"\n className=\"sm:self-stretch\"\n disabled={!modelId || question.trim() === '' || ask.isPending}\n data-testid=\"nl-ask-submit\"\n >\n {ask.isPending ? (\n <Loader2 className=\"mr-2 h-4 w-4 animate-spin\" />\n ) : (\n <Send className=\"mr-2 h-4 w-4\" />\n )}\n {tr('semanticfed.queryConsole.ask.submit', 'Ask')}\n </Button>\n </form>\n\n {shownSuggestions.length > 0 && (\n <div className=\"flex flex-wrap gap-2\" data-testid=\"nl-ask-suggestions\">\n {shownSuggestions.map((text) => (\n <button\n key={text}\n type=\"button\"\n className=\"rounded-full border px-3 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground\"\n onClick={() => askSuggestion(text)}\n disabled={ask.isPending}\n >\n {text}\n </button>\n ))}\n </div>\n )}\n\n {translation?.status === 'NEEDS_CLARIFICATION' && (\n <div\n className=\"flex items-start gap-2 rounded border border-dashed p-3 text-sm\"\n data-testid=\"nl-ask-clarification\"\n >\n <HelpCircle className=\"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground\" />\n <div className=\"min-w-0 space-y-1\">\n <p>{translation.clarification}</p>\n {translation.unmatchedTerms.length > 0 && (\n <p className=\"text-xs text-muted-foreground\">\n {tr('semanticfed.queryConsole.ask.unmatched', 'Not found in the model: {terms}', {\n terms: translation.unmatchedTerms.join(', '),\n })}\n </p>\n )}\n </div>\n </div>\n )}\n\n {translation?.status === 'TRANSLATED' && translation.sql && (\n <div className=\"space-y-2 rounded border p-3\" data-testid=\"nl-ask-interpretation\">\n <div className=\"flex flex-wrap items-center justify-between gap-2\">\n <div className=\"flex flex-wrap items-center gap-2 text-xs\">\n <span className=\"font-medium\">\n {tr('semanticfed.queryConsole.ask.interpretation', 'Interpretation')}\n </span>\n <Badge variant=\"outline\" data-testid=\"nl-ask-confidence\">\n {tr('semanticfed.queryConsole.ask.confidence', 'Confidence {value}%', {\n value: Math.round(translation.confidence * 100),\n })}\n </Badge>\n {translation.steps.map((step, index) => (\n <Badge key={`${step.kind}-${index}`} variant=\"secondary\" className=\"font-mono\">\n {step.kind.replace('_', ' ')}: {describeStep(step, governedLabel)}\n </Badge>\n ))}\n </div>\n <Button\n size=\"sm\"\n variant=\"outline\"\n onClick={() => onOpenInEditor(translation.sql ?? '')}\n data-testid=\"nl-ask-open-editor\"\n >\n <PencilLine className=\"mr-2 h-4 w-4\" />\n {tr('semanticfed.queryConsole.ask.openInEditor', 'Edit as SQL')}\n </Button>\n </div>\n <pre\n className=\"overflow-x-auto rounded bg-muted p-3 font-mono text-xs text-foreground\"\n data-testid=\"nl-ask-sql\"\n >\n {translation.sql}\n </pre>\n {translation.unmatchedTerms.length > 0 && (\n <p className=\"text-xs text-muted-foreground\">\n {tr('semanticfed.queryConsole.ask.ignored', 'Ignored words: {terms}', {\n terms: translation.unmatchedTerms.join(', '),\n })}\n </p>\n )}\n </div>\n )}\n </CardContent>\n </Card>\n );\n}\n"],"mappings":";;;;;;;;AAcA,IAAM,IAAsB,KAEtB,IAAmB;AAazB,SAAS,EAAY,GAAwB;AAI3C,QAHI,KAAU,OAAoC,SAC9C,OAAO,KAAU,WAAiB,IAAI,EAAM,KAC5C,OAAO,KAAU,WAAiB,KAAK,UAAU,EAAM,GACpD,OAAO,EAAM;;AAItB,SAAS,EAAa,GAAiB,GAA+B;CACpE,IAAM,IAAS,CAAC,EAAK,QAAQ,EAAK,MAAM,CAAC,OAAO,QAAQ,CAAC,K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kBAAC,KAAD;OAAG,WAAU;iBACV,EAAG,0CAA0C,mCAAmC,EAC/E,OAAO,EAAY,eAAe,KAAK,KAAK,EAC7C,CAAC;OACA,CAAA,CAEF;QACF;;IAGP,GAAa,WAAW,gBAAgB,EAAY,OACnD,kBAAC,OAAD;KAAK,WAAU;KAA+B,eAAY;eAA1D;MACE,kBAAC,OAAD;OAAK,WAAU;iBAAf,CACE,kBAAC,OAAD;QAAK,WAAU;kBAAf;SACE,kBAAC,QAAD;UAAM,WAAU;oBACb,EAAG,+CAA+C,iBAAiB;UAC/D,CAAA;SACP,kBAAC,GAAD;UAAO,SAAQ;UAAU,eAAY;oBAClC,EAAG,2CAA2C,uBAAuB,EACpE,OAAO,KAAK,MAAM,EAAY,aAAa,IAAI,EAChD,CAAC;UACI,CAAA;SACP,EAAY,MAAM,KAAK,GAAM,MAC5B,kBAAC,GAAD;UAAqC,SAAQ;UAAY,WAAU;oBAAnE;WACG,EAAK,KAAK,QAAQ,KAAK,IAAI;WAAC;WAAG,EAAa,GAAM,EAAc;WAC3D;YAFI,GAAG,EAAK,KAAK,GAAG,IAEpB,CACR;SACE;WACN,kBAAC,GAAD;QACE,MAAK;QACL,SAAQ;QACR,eAAe,EAAe,EAAY,OAAO,GAAG;QACpD,eAAY;kBAJd,CAME,kBAAC,GAAD,EAAY,WAAU,gBAAiB,CAAA,EACtC,EAAG,6CAA6C,cAAc,CACxD;UACL;;MACN,kBAAC,OAAD;OACE,WAAU;OACV,eAAY;iBAEX,EAAY;OACT,CAAA;MACL,EAAY,eAAe,SAAS,KACnC,kBAAC,KAAD;OAAG,WAAU;iBACV,EAAG,wCAAwC,0BAA0B,EACpE,OAAO,EAAY,eAAe,KAAK,KAAK,EAC7C,CAAC;OACA,CAAA;MAEF;;IAEI;KACT"}
|
|
1
|
+
{"version":3,"file":"AskQuestionPanel.js","names":[],"sources":["../../../src/semanticfed/components/AskQuestionPanel.tsx"],"sourcesContent":["import { useRef, useState } from 'react';\nimport { Badge, Button, Card, CardContent, CardHeader, CardTitle } from '@burdenoff/fe-libs/ui';\nimport {\n CornerDownRight,\n HelpCircle,\n Loader2,\n MessageSquareText,\n PencilLine,\n RotateCcw,\n Send,\n Sparkles,\n} from 'lucide-react';\n\nimport {\n type SemNlAnswer,\n type SemNlAssistStatus,\n type SemNlStep,\n type SemNlTranslation,\n useSemAskQuestion,\n useSemNlSuggestions,\n} from '../hooks/useNlQuery';\nimport { NlAssistSettings } from './NlAssistSettings';\nimport { sqlErrorMessage } from '../hooks/useSqlConsole';\nimport { useTr } from '../hooks/useTr';\n\n/** Longest question the service accepts (MAX_QUESTION_LENGTH in wspace-semanticfed-svc). */\nconst MAX_QUESTION_LENGTH = 1000;\n/** Example questions shown under the input. */\nconst SUGGESTION_LIMIT = 6;\n/** Earlier questions sent with a follow-up (the service uses the last 10). */\nconst HISTORY_LIMIT = 10;\n\n/** One question of the conversation and what it got back. */\ninterface Turn {\n id: number;\n question: string;\n answer: SemNlAnswer | null;\n error: string | null;\n}\n\n/**\n * The questions a follow-up refines: the answered ones, oldest first. A turn\n * the AI provider reworded is carried as its rewrite, which uses the model's\n * own names.\n */\nexport function conversationHistory(turns: Turn[]): string[] {\n return turns\n .filter((t) => t.answer?.translation.status === 'TRANSLATED')\n .map((t) => t.answer?.translation.rephrasedQuestion ?? t.question)\n .slice(-HISTORY_LIMIT);\n}\n\nexport interface AskQuestionPanelProps {\n modelId: string | null;\n maxRows: number;\n /** Called with every answer, so the page can show its governed result rows. */\n onAnswer: (answer: SemNlAnswer) => void;\n /** Called when a question fails before it is answered (network, quota, access). */\n onError: (message: string) => void;\n /** Open the generated SQL in the console's editor for review or editing. */\n onOpenInEditor: (sql: string) => void;\n}\n\nfunction formatValue(value: unknown): string {\n if (value === null || value === undefined) return 'NULL';\n if (typeof value === 'string') return `'${value}'`;\n if (typeof value === 'object') return JSON.stringify(value);\n return String(value);\n}\n\n/** One interpretation step as a short phrase, e.g. \"SUM(revenue) (governed)\". */\nfunction describeStep(step: SemNlStep, governedLabel: string): string {\n const target = [step.entity, step.field].filter(Boolean).join('.');\n switch (step.kind) {\n case 'MEASURE':\n return `${step.aggregation ?? ''}(${target})${step.governed ? ` ${governedLabel}` : ''}`;\n case 'FILTER':\n return `${target} ${step.operator ?? '='} ${formatValue(step.value)}`;\n case 'ORDER':\n return `${target} ${step.direction ?? ''}`.trim();\n case 'LIMIT':\n return String(step.count ?? '');\n case 'JOIN':\n return step.relationship ? `${target} (${step.relationship})` : target;\n default:\n return target;\n }\n}\n\n/** A short, translated note on whether and how the workspace's AI provider helped. */\nfunction assistNote(\n translation: SemNlTranslation,\n tr: ReturnType<typeof useTr>\n): { text: string; tone: 'info' | 'warn' } | null {\n const provider = translation.assistProvider ?? '';\n const notes: Partial<Record<SemNlAssistStatus, { text: string; tone: 'info' | 'warn' }>> = {\n REPHRASED: {\n text: tr(\n 'semanticfed.queryConsole.ask.assist.rephrased',\n 'Reworded by your AI provider ({provider}) as: “{question}”',\n {\n provider,\n question: translation.rephrasedQuestion ?? '',\n }\n ),\n tone: 'info',\n },\n NO_IMPROVEMENT: {\n text: tr(\n 'semanticfed.queryConsole.ask.assist.noImprovement',\n 'Your AI provider could not reword this question into one the model can answer.'\n ),\n tone: 'warn',\n },\n QUOTA_EXHAUSTED: {\n text: tr(\n 'semanticfed.queryConsole.ask.assist.quota',\n 'AI assistance is paused: this workspace has used today’s AI operations.'\n ),\n tone: 'warn',\n },\n QUOTA_UNAVAILABLE: {\n text: tr(\n 'semanticfed.queryConsole.ask.assist.quotaUnavailable',\n 'AI assistance is unavailable: the AI-operation allowance for this workspace could not be checked.'\n ),\n tone: 'warn',\n },\n PROVIDER_ERROR: {\n text: tr(\n 'semanticfed.queryConsole.ask.assist.providerError',\n 'Your AI provider could not be used for this question (it was unreachable, refused the key, or returned an error).'\n ),\n tone: 'warn',\n },\n NOT_CONFIGURED: {\n text: tr(\n 'semanticfed.queryConsole.ask.assist.notConfigured',\n 'AI assistance is on, but its provider connection is missing or revoked. Choose a connection under AI assistance.'\n ),\n tone: 'warn',\n },\n };\n return notes[translation.assist] ?? null;\n}\n\n/** Steps, SQL and ignored words of a translated question. */\nfunction Interpretation({\n translation,\n governedLabel,\n onOpenInEditor,\n latest,\n}: {\n translation: SemNlTranslation;\n governedLabel: string;\n onOpenInEditor: (sql: string) => void;\n latest: boolean;\n}) {\n const tr = useTr();\n const sql = (\n <pre\n className=\"overflow-x-auto rounded bg-muted p-3 font-mono text-xs text-foreground\"\n data-testid={latest ? 'nl-ask-sql' : undefined}\n >\n {translation.sql}\n </pre>\n );\n return (\n <div\n className=\"space-y-2 rounded border p-3\"\n data-testid={latest ? 'nl-ask-interpretation' : undefined}\n >\n <div className=\"flex flex-wrap items-center justify-between gap-2\">\n <div className=\"flex flex-wrap items-center gap-2 text-xs\">\n <span className=\"font-medium\">\n {tr('semanticfed.queryConsole.ask.interpretation', 'Interpretation')}\n </span>\n {translation.followUp && (\n <Badge variant=\"outline\" data-testid={latest ? 'nl-ask-followup' : undefined}>\n <CornerDownRight className=\"mr-1 h-3 w-3\" />\n {tr('semanticfed.queryConsole.ask.followUp', 'Follow-up')}\n </Badge>\n )}\n <Badge variant=\"outline\" data-testid={latest ? 'nl-ask-confidence' : undefined}>\n {tr('semanticfed.queryConsole.ask.confidence', 'Confidence {value}%', {\n value: Math.round(translation.confidence * 100),\n })}\n </Badge>\n {translation.steps.map((step, index) => (\n <Badge key={`${step.kind}-${index}`} variant=\"secondary\" className=\"font-mono\">\n {step.kind.replace('_', ' ')}: {describeStep(step, governedLabel)}\n </Badge>\n ))}\n </div>\n <Button\n size=\"sm\"\n variant=\"outline\"\n onClick={() => onOpenInEditor(translation.sql ?? '')}\n data-testid={latest ? 'nl-ask-open-editor' : undefined}\n >\n <PencilLine className=\"mr-2 h-4 w-4\" />\n {tr('semanticfed.queryConsole.ask.openInEditor', 'Edit as SQL')}\n </Button>\n </div>\n {latest ? (\n sql\n ) : (\n <details>\n <summary className=\"cursor-pointer text-xs text-muted-foreground\">\n {tr('semanticfed.queryConsole.ask.showSql', 'Show SQL')}\n </summary>\n {sql}\n </details>\n )}\n {translation.unmatchedTerms.length > 0 && (\n <p className=\"text-xs text-muted-foreground\">\n {tr('semanticfed.queryConsole.ask.ignored', 'Ignored words: {terms}', {\n terms: translation.unmatchedTerms.join(', '),\n })}\n </p>\n )}\n </div>\n );\n}\n\n/**\n * \"Ask a question\" — natural-language questions over the semantic layer\n * (BOFF-4276), as a conversation (BOFF-10533). Each question is translated\n * into SQL over the model's governed metrics and dimensions and run with the\n * caller's access policies; a follow-up (\"and by status?\", \"only EU\", \"top 3\n * instead\") refines the previous answers. The interpretation (generated SQL,\n * steps, confidence, ignored words, and any AI rewording) is always shown so\n * the answer can be checked, and opened in the SQL editor.\n */\nexport function AskQuestionPanel({\n modelId,\n maxRows,\n onAnswer,\n onError,\n onOpenInEditor,\n}: AskQuestionPanelProps) {\n const tr = useTr();\n const [question, setQuestion] = useState('');\n const [turns, setTurns] = useState<Turn[]>([]);\n const [conversationModel, setConversationModel] = useState<string | null>(modelId);\n const [showSettings, setShowSettings] = useState(false);\n const nextTurnId = useRef(0);\n const suggestions = useSemNlSuggestions(modelId);\n const ask = useSemAskQuestion();\n\n // A conversation belongs to one model: switching models starts a new one.\n if (conversationModel !== modelId) {\n setConversationModel(modelId);\n setTurns([]);\n }\n\n const submit = async (text: string) => {\n const trimmed = text.trim();\n if (!modelId || trimmed === '' || ask.isPending) return;\n const history = conversationHistory(turns);\n nextTurnId.current += 1;\n const id = nextTurnId.current;\n try {\n const data = await ask.mutateAsync({\n question: trimmed,\n modelId,\n maxRows,\n ...(history.length > 0 ? { history } : {}),\n });\n setTurns((all) => [...all, { id, question: trimmed, answer: data, error: null }]);\n setQuestion('');\n onAnswer(data);\n } catch (e) {\n const message = sqlErrorMessage(e);\n setTurns((all) => [...all, { id, question: trimmed, answer: null, error: message }]);\n onError(message);\n }\n };\n\n const askSuggestion = (text: string) => {\n setQuestion(text);\n void submit(text);\n };\n\n const last = turns.at(-1) ?? null;\n const translation = last?.answer?.translation ?? null;\n const shownSuggestions = (\n translation?.status === 'NEEDS_CLARIFICATION'\n ? translation.suggestions\n : turns.length === 0\n ? (suggestions.data ?? [])\n : []\n ).slice(0, SUGGESTION_LIMIT);\n const governedLabel = tr('semanticfed.queryConsole.ask.governed', '(governed)');\n\n return (\n <Card data-testid=\"nl-ask-panel\">\n <CardHeader className=\"pb-3\">\n <div className=\"flex flex-wrap items-center justify-between gap-2\">\n <CardTitle className=\"flex items-center gap-2 text-base\">\n <MessageSquareText className=\"h-4 w-4\" />\n {tr('semanticfed.queryConsole.ask.title', 'Ask a question')}\n </CardTitle>\n <div className=\"flex flex-wrap gap-2\">\n {turns.length > 0 && (\n <Button\n size=\"sm\"\n variant=\"ghost\"\n onClick={() => setTurns([])}\n disabled={ask.isPending}\n data-testid=\"nl-ask-new-conversation\"\n >\n <RotateCcw className=\"mr-2 h-4 w-4\" />\n {tr('semanticfed.queryConsole.ask.newConversation', 'New conversation')}\n </Button>\n )}\n <Button\n size=\"sm\"\n variant={showSettings ? 'secondary' : 'ghost'}\n onClick={() => setShowSettings((v) => !v)}\n aria-expanded={showSettings}\n data-testid=\"nl-assist-toggle\"\n >\n <Sparkles className=\"mr-2 h-4 w-4\" />\n {tr('semanticfed.queryConsole.ask.assistSettings', 'AI assistance')}\n </Button>\n </div>\n </div>\n <p className=\"text-xs text-muted-foreground\">\n {tr(\n 'semanticfed.queryConsole.ask.conversationDescription',\n 'Ask in plain English, then refine with follow-ups such as “and by status?”, “only EU” or “top 3 instead”. Answers come from the model’s governed metrics and dimensions, with your access policies applied, and the SQL that ran is shown.'\n )}\n </p>\n </CardHeader>\n <CardContent className=\"space-y-3\">\n {showSettings && <NlAssistSettings />}\n\n {turns.length > 0 && (\n <ol className=\"space-y-3\" data-testid=\"nl-ask-thread\" aria-live=\"polite\">\n {turns.map((turn, index) => {\n const isLast = index === turns.length - 1;\n const t = turn.answer?.translation ?? null;\n const note = t ? assistNote(t, tr) : null;\n return (\n <li key={turn.id} className=\"space-y-2\" data-testid=\"nl-ask-turn\">\n <p className=\"w-fit max-w-full rounded-lg bg-muted px-3 py-2 text-sm\">\n {turn.question}\n </p>\n {turn.error && <p className=\"text-xs text-destructive\">{turn.error}</p>}\n {note && (\n <p\n className={`flex items-start gap-1 text-xs ${note.tone === 'warn' ? 'text-muted-foreground' : 'text-primary'}`}\n data-testid={isLast ? 'nl-ask-assist-note' : undefined}\n >\n <Sparkles className=\"mt-0.5 h-3 w-3 shrink-0\" />\n {note.text}\n </p>\n )}\n {t?.status === 'NEEDS_CLARIFICATION' && (\n <div\n className=\"flex items-start gap-2 rounded border border-dashed p-3 text-sm\"\n data-testid={isLast ? 'nl-ask-clarification' : undefined}\n >\n <HelpCircle className=\"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground\" />\n <div className=\"min-w-0 space-y-1\">\n <p>{t.clarification}</p>\n {t.unmatchedTerms.length > 0 && (\n <p className=\"text-xs text-muted-foreground\">\n {tr(\n 'semanticfed.queryConsole.ask.unmatched',\n 'Not found in the model: {terms}',\n {\n terms: t.unmatchedTerms.join(', '),\n }\n )}\n </p>\n )}\n </div>\n </div>\n )}\n {t?.status === 'TRANSLATED' && t.sql && (\n <Interpretation\n translation={t}\n governedLabel={governedLabel}\n onOpenInEditor={onOpenInEditor}\n latest={isLast}\n />\n )}\n </li>\n );\n })}\n </ol>\n )}\n\n <form\n className=\"flex flex-col gap-2 sm:flex-row\"\n onSubmit={(e) => {\n e.preventDefault();\n void submit(question);\n }}\n >\n <label className=\"sr-only\" htmlFor=\"nl-ask-input\">\n {tr('semanticfed.queryConsole.ask.inputLabel', 'Your question')}\n </label>\n <input\n id=\"nl-ask-input\"\n data-testid=\"nl-ask-input\"\n className=\"min-w-0 flex-1 rounded border bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-primary\"\n value={question}\n maxLength={MAX_QUESTION_LENGTH}\n onChange={(e) => setQuestion(e.target.value)}\n placeholder={\n turns.length > 0\n ? tr(\n 'semanticfed.queryConsole.ask.followUpPlaceholder',\n 'Ask a follow-up, e.g. and by status?'\n )\n : tr('semanticfed.queryConsole.ask.placeholder', 'e.g. top 5 regions by revenue')\n }\n disabled={!modelId}\n />\n <Button\n type=\"submit\"\n size=\"sm\"\n className=\"sm:self-stretch\"\n disabled={!modelId || question.trim() === '' || ask.isPending}\n data-testid=\"nl-ask-submit\"\n >\n {ask.isPending ? (\n <Loader2 className=\"mr-2 h-4 w-4 animate-spin\" />\n ) : (\n <Send className=\"mr-2 h-4 w-4\" />\n )}\n {tr('semanticfed.queryConsole.ask.submit', 'Ask')}\n </Button>\n </form>\n\n {shownSuggestions.length > 0 && (\n <div className=\"flex flex-wrap gap-2\" data-testid=\"nl-ask-suggestions\">\n {shownSuggestions.map((text) => (\n <button\n key={text}\n type=\"button\"\n className=\"rounded-full border px-3 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground\"\n onClick={() => askSuggestion(text)}\n disabled={ask.isPending}\n >\n {text}\n </button>\n ))}\n </div>\n )}\n </CardContent>\n </Card>\n );\n}\n"],"mappings":";;;;;;;;;AA0BA,IAAM,IAAsB,KAEtB,IAAmB,GAEnB,IAAgB;AAetB,SAAgB,EAAoB,GAAyB;AAC3D,QAAO,EACJ,QAAQ,MAAM,EAAE,QAAQ,YAAY,WAAW,aAAa,CAC5D,KAAK,MAAM,EAAE,QAAQ,YAAY,qBAAqB,EAAE,SAAS,CACjE,MAAM,CAAC,EAAc;;AAc1B,SAAS,EAAY,GAAwB;AAI3C,QAHI,KAAU,OAAoC,SAC9C,OAAO,KAAU,WAAiB,IAAI,EAAM,KAC5C,OAAO,KAAU,WAAiB,KAAK,UAAU,EAAM,GACpD,OAAO,EAAM;;AAItB,SAAS,EAAa,GAAiB,GAA+B;CACpE,IAAM,IAAS,CAAC,EAAK,QAAQ,EAAK,MAAM,CAAC,OAAO,QAAQ,CAAC,KAAK,IAAI;AAClE,SAAQ,EAAK,MAAb;EACE,KAAK,UACH,Q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BAAC,UAAD;MAEE,MAAK;MACL,WAAU;MACV,eAAe,EAAc,EAAK;MAClC,UAAU,EAAI;gBAEb;MACM,EAPF,EAOE,CACT;KACE,CAAA;IAEI;KACT"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { useTr as e } from "../hooks/useTr.js";
|
|
2
|
+
import { useSemAiConnections as t, useSemNlSettings as n, useSemUpdateNlSettings as r } from "../hooks/useNlQuery.js";
|
|
3
|
+
import { sqlErrorMessage as i } from "../hooks/useSqlConsole.js";
|
|
4
|
+
import { useState as a } from "react";
|
|
5
|
+
import { ExternalLink as o, Loader2 as s, Save as c, Sparkles as l } from "lucide-react";
|
|
6
|
+
import { jsx as u, jsxs as d } from "react/jsx-runtime";
|
|
7
|
+
import { Button as f } from "@burdenoff/fe-libs/ui";
|
|
8
|
+
//#region src/semanticfed/components/NlAssistSettings.tsx
|
|
9
|
+
function p() {
|
|
10
|
+
let t = e(), r = n();
|
|
11
|
+
return r.isLoading ? /* @__PURE__ */ d("div", {
|
|
12
|
+
className: "flex items-center gap-2 text-xs text-muted-foreground",
|
|
13
|
+
children: [/* @__PURE__ */ u(s, { className: "h-3 w-3 animate-spin" }), t("semanticfed.queryConsole.assist.loading", "Loading AI assistance settings…")]
|
|
14
|
+
}) : r.isError || !r.data ? /* @__PURE__ */ u("p", {
|
|
15
|
+
className: "text-xs text-destructive",
|
|
16
|
+
"data-testid": "nl-assist-settings-error",
|
|
17
|
+
children: i(r.error)
|
|
18
|
+
}) : /* @__PURE__ */ u(m, { initial: r.data }, r.data.updatedAt ?? "unsaved");
|
|
19
|
+
}
|
|
20
|
+
function m({ initial: n }) {
|
|
21
|
+
let p = e(), m = r(), h = t(!0, n.supportedProviders), [g, _] = a(n.llmAssistEnabled), [v, y] = a(n.aiConnectionId ?? ""), [b, x] = a(n.aiModel ?? ""), [S, C] = a(null), w = h.data?.find((e) => e.id === v) ?? null, T = w?.providerKey === "anthropic" ? "claude-opus-5-5" : w?.providerKey === "openai" ? "gpt-4o-mini" : n.defaultAiModel ?? "", E = async () => {
|
|
22
|
+
C(null);
|
|
23
|
+
try {
|
|
24
|
+
await m.mutateAsync({
|
|
25
|
+
llmAssistEnabled: g,
|
|
26
|
+
aiConnectionId: v || null,
|
|
27
|
+
aiModel: b.trim() || null
|
|
28
|
+
}), C({
|
|
29
|
+
ok: !0,
|
|
30
|
+
text: p("semanticfed.queryConsole.assist.saved", "Settings saved.")
|
|
31
|
+
});
|
|
32
|
+
} catch (e) {
|
|
33
|
+
C({
|
|
34
|
+
ok: !1,
|
|
35
|
+
text: i(e)
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}, D = h.isSuccess && h.data.length === 0;
|
|
39
|
+
return /* @__PURE__ */ d("div", {
|
|
40
|
+
className: "space-y-3 rounded border p-3 text-sm",
|
|
41
|
+
"data-testid": "nl-assist-settings",
|
|
42
|
+
children: [
|
|
43
|
+
/* @__PURE__ */ d("div", {
|
|
44
|
+
className: "flex items-start gap-2",
|
|
45
|
+
children: [/* @__PURE__ */ u(l, { className: "mt-0.5 h-4 w-4 shrink-0 text-primary" }), /* @__PURE__ */ d("div", {
|
|
46
|
+
className: "min-w-0 space-y-1",
|
|
47
|
+
children: [/* @__PURE__ */ u("p", {
|
|
48
|
+
className: "font-medium",
|
|
49
|
+
children: p("semanticfed.queryConsole.assist.title", "AI assistance (bring your own key)")
|
|
50
|
+
}), /* @__PURE__ */ u("p", {
|
|
51
|
+
className: "text-xs text-muted-foreground",
|
|
52
|
+
children: p("semanticfed.queryConsole.assist.description", "When a question cannot be matched to the model, your own OpenAI or Anthropic key rewords it with the model’s names and it is translated again. The AI never writes or runs SQL. Only the model’s names, descriptions and your questions are sent, never data rows. Each rewrite counts as one AI operation.")
|
|
53
|
+
})]
|
|
54
|
+
})]
|
|
55
|
+
}),
|
|
56
|
+
/* @__PURE__ */ d("label", {
|
|
57
|
+
className: "flex items-center gap-2 text-sm",
|
|
58
|
+
children: [/* @__PURE__ */ u("input", {
|
|
59
|
+
type: "checkbox",
|
|
60
|
+
checked: g,
|
|
61
|
+
onChange: (e) => _(e.target.checked),
|
|
62
|
+
"data-testid": "nl-assist-enabled"
|
|
63
|
+
}), p("semanticfed.queryConsole.assist.enable", "Reword unmatched questions with my AI provider")]
|
|
64
|
+
}),
|
|
65
|
+
/* @__PURE__ */ d("div", {
|
|
66
|
+
className: "grid gap-2 sm:grid-cols-2",
|
|
67
|
+
children: [/* @__PURE__ */ d("label", {
|
|
68
|
+
className: "space-y-1 text-xs",
|
|
69
|
+
children: [/* @__PURE__ */ u("span", {
|
|
70
|
+
className: "text-muted-foreground",
|
|
71
|
+
children: p("semanticfed.queryConsole.assist.connection", "AI provider connection")
|
|
72
|
+
}), /* @__PURE__ */ d("select", {
|
|
73
|
+
className: "w-full rounded border bg-background px-2 py-1.5 text-sm",
|
|
74
|
+
value: v,
|
|
75
|
+
onChange: (e) => y(e.target.value),
|
|
76
|
+
"data-testid": "nl-assist-connection",
|
|
77
|
+
children: [/* @__PURE__ */ u("option", {
|
|
78
|
+
value: "",
|
|
79
|
+
children: p("semanticfed.queryConsole.assist.noConnection", "None")
|
|
80
|
+
}), (h.data ?? []).map((e) => /* @__PURE__ */ d("option", {
|
|
81
|
+
value: e.id,
|
|
82
|
+
children: [
|
|
83
|
+
e.name,
|
|
84
|
+
" (",
|
|
85
|
+
e.providerName || e.providerKey,
|
|
86
|
+
")"
|
|
87
|
+
]
|
|
88
|
+
}, e.id))]
|
|
89
|
+
})]
|
|
90
|
+
}), /* @__PURE__ */ d("label", {
|
|
91
|
+
className: "space-y-1 text-xs",
|
|
92
|
+
children: [/* @__PURE__ */ u("span", {
|
|
93
|
+
className: "text-muted-foreground",
|
|
94
|
+
children: p("semanticfed.queryConsole.assist.model", "Model (optional)")
|
|
95
|
+
}), /* @__PURE__ */ u("input", {
|
|
96
|
+
className: "w-full rounded border bg-background px-2 py-1.5 text-sm",
|
|
97
|
+
value: b,
|
|
98
|
+
maxLength: 128,
|
|
99
|
+
onChange: (e) => x(e.target.value),
|
|
100
|
+
placeholder: T,
|
|
101
|
+
"data-testid": "nl-assist-model"
|
|
102
|
+
})]
|
|
103
|
+
})]
|
|
104
|
+
}),
|
|
105
|
+
D && /* @__PURE__ */ u("p", {
|
|
106
|
+
className: "text-xs text-muted-foreground",
|
|
107
|
+
"data-testid": "nl-assist-no-connections",
|
|
108
|
+
children: p("semanticfed.queryConsole.assist.connectFirst", "No OpenAI or Anthropic connection yet. Add one in Integrations, then choose it here.")
|
|
109
|
+
}),
|
|
110
|
+
h.isError && /* @__PURE__ */ u("p", {
|
|
111
|
+
className: "text-xs text-destructive",
|
|
112
|
+
children: i(h.error)
|
|
113
|
+
}),
|
|
114
|
+
/* @__PURE__ */ d("div", {
|
|
115
|
+
className: "flex flex-wrap items-center gap-2",
|
|
116
|
+
children: [
|
|
117
|
+
/* @__PURE__ */ d(f, {
|
|
118
|
+
size: "sm",
|
|
119
|
+
onClick: () => void E(),
|
|
120
|
+
disabled: m.isPending,
|
|
121
|
+
"data-testid": "nl-assist-save",
|
|
122
|
+
children: [m.isPending ? /* @__PURE__ */ u(s, { className: "mr-2 h-4 w-4 animate-spin" }) : /* @__PURE__ */ u(c, { className: "mr-2 h-4 w-4" }), p("semanticfed.queryConsole.assist.save", "Save")]
|
|
123
|
+
}),
|
|
124
|
+
/* @__PURE__ */ d("a", {
|
|
125
|
+
className: "inline-flex items-center gap-1 text-xs text-primary hover:underline",
|
|
126
|
+
href: "/integrations",
|
|
127
|
+
children: [/* @__PURE__ */ u(o, { className: "h-3 w-3" }), p("semanticfed.queryConsole.assist.manageConnections", "Manage connections")]
|
|
128
|
+
}),
|
|
129
|
+
S && /* @__PURE__ */ u("span", {
|
|
130
|
+
className: `text-xs ${S.ok ? "text-muted-foreground" : "text-destructive"}`,
|
|
131
|
+
"data-testid": "nl-assist-message",
|
|
132
|
+
role: "status",
|
|
133
|
+
children: S.text
|
|
134
|
+
})
|
|
135
|
+
]
|
|
136
|
+
})
|
|
137
|
+
]
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
//#endregion
|
|
141
|
+
export { p as NlAssistSettings };
|
|
142
|
+
|
|
143
|
+
//# sourceMappingURL=NlAssistSettings.js.map
|