@burdenoff/microfe-botmanor 2026.1119.3 → 2026.1120.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ import { FC } from 'react';
2
+ import { BotDraftScope, CreatedDraft } from '../hooks/useBotCopilot';
3
+ interface DescribeBotDialogProps {
4
+ scope: BotDraftScope;
5
+ /** Receives what was created (every entity is DRAFT). */
6
+ onCreated: (created: CreatedDraft) => void;
7
+ /** Called instead of an inline message when the plan's bot limit is reached. */
8
+ onQuotaExhausted?: () => void;
9
+ }
10
+ export declare const DescribeBotDialog: FC<DescribeBotDialogProps>;
11
+ export {};
@@ -0,0 +1,354 @@
1
+ import { Badge as e } from "./Badge.js";
2
+ import { Button as t } from "./Button.js";
3
+ import { Card as n, CardContent as r, CardDescription as ee, CardHeader as te, CardTitle as i } from "./Card.js";
4
+ import { FormField as a, Input as o, Textarea as s } from "./Input.js";
5
+ import { useCreateFromDraft as c, useDraftBot as l } from "../hooks/useBotCopilot.js";
6
+ import { useLLMModels as ne, useLLMProviders as re } from "../hooks/useLLMProviders.js";
7
+ import { configuredAnswerModels as ie } from "../utils/embedding-models.js";
8
+ import "../utils/agentSettings.js";
9
+ import { useEffect as u, useMemo as d, useState as f } from "react";
10
+ import { ResponsiveDialog as p, ResponsiveDialogContent as m, ResponsiveDialogDescription as h, ResponsiveDialogFooter as g, ResponsiveDialogHeader as ae, ResponsiveDialogTitle as oe } from "@burdenoff/fe-libs/ui";
11
+ import { Fragment as _, jsx as v, jsxs as y } from "react/jsx-runtime";
12
+ import { isQuotaExhaustedError as b } from "@burdenoff/fe-libs/shared/utils";
13
+ import { Sparkles as x, WandSparkles as se } from "lucide-react";
14
+ import { toast as ce } from "sonner";
15
+ // src/botlit/components/DescribeBotDialog.tsx
16
+ var S = 10, C = 1e3, le = "flex h-10 w-full rounded-md border border-border-default bg-bg-surface px-3 py-2 text-sm";
17
+ function w(e) {
18
+ return {
19
+ app: e.app ? { ...e.app } : null,
20
+ agents: e.agents.map((e) => ({
21
+ ...e,
22
+ include: !0
23
+ }))
24
+ };
25
+ }
26
+ function T(e, t) {
27
+ return e instanceof Error && e.message ? e.message : t;
28
+ }
29
+ var E = ({ scope: E, onCreated: ue, onQuotaExhausted: D }) => {
30
+ let O = E === "BOT" ? "bot" : "agent", [de, k] = f(!1), [A, fe] = f(""), [j, M] = f(""), [N, P] = f(null), [F, I] = f(null), [L, R] = f(null), z = ne(), B = re(), V = d(() => ie(z.data ?? [], B.data ?? []), [z.data, B.data]), H = V.some((e) => e.id === j) ? j : V[0]?.id || "", U = l(), [pe, W] = c(E), G = A.trim(), K = G.length > 0 && G.length < S ? `Write at least ${S} characters.` : G.length > C ? `Use at most ${C} characters.` : void 0, q = F?.agents.filter((e) => e.include) ?? [], J = () => {
31
+ U.cancel(), P(null), I(null), R(null);
32
+ };
33
+ u(() => {
34
+ M(""), P(null), I(null), R(null);
35
+ }, [U.workspaceId]);
36
+ let Y = z.error ?? B.error, X = z.loading || B.loading, Z = () => {
37
+ J(), k(!1);
38
+ }, me = async () => {
39
+ R(null);
40
+ try {
41
+ let e = await U.draft({
42
+ description: G,
43
+ llmModelId: H,
44
+ scope: E
45
+ });
46
+ if (!e) return;
47
+ P(e), I(w(e));
48
+ } catch (e) {
49
+ R(b(e) ? "This workspace has no AI credits left for the copilot. The Free plan does not include AI-assisted creation; Pro does." : T(e, `Could not draft the ${O}.`));
50
+ }
51
+ }, he = async () => {
52
+ if (!N || !F) return;
53
+ R(null);
54
+ let e = q.map(({ include: e, ...t }) => t);
55
+ try {
56
+ let t = await pe({
57
+ draft: N,
58
+ app: F.app,
59
+ agents: e,
60
+ links: N.links
61
+ });
62
+ ce.success(E === "BOT" ? `Draft bot "${t.app?.name ?? ""}" created with ${t.agents.length} draft agent(s)` : `${t.agents.length} draft agent(s) created`), Z(), ue(t);
63
+ } catch (e) {
64
+ if (D && b(e)) {
65
+ Z(), D();
66
+ return;
67
+ }
68
+ R(T(e, `Could not create the draft ${O}.`));
69
+ }
70
+ }, Q = (e, t) => I((n) => n && {
71
+ ...n,
72
+ agents: n.agents.map((n) => n.key === e ? {
73
+ ...n,
74
+ ...t
75
+ } : n)
76
+ }), ge = (e, t, n) => {
77
+ let r = F?.agents.find((t) => t.key === e);
78
+ r && Q(e, { knowledgeBaseIds: n ? [.../* @__PURE__ */ new Set([...r.knowledgeBaseIds, t])] : r.knowledgeBaseIds.filter((e) => e !== t) });
79
+ }, $ = F?.app?.name.trim() ?? "", _e = q.length > 0 && q.every((e) => {
80
+ let t = e.name.trim();
81
+ return t.length > 0 && t.length <= 100 && e.systemPrompt.trim().length > 0;
82
+ }) && (E === "AGENTS" || $.length > 0 && $.length <= 100);
83
+ return /* @__PURE__ */ y(_, { children: [/* @__PURE__ */ y(n, {
84
+ className: "max-w-2xl",
85
+ children: [/* @__PURE__ */ y(te, { children: [/* @__PURE__ */ y(i, {
86
+ className: "flex items-center gap-2",
87
+ children: [
88
+ /* @__PURE__ */ v(se, {
89
+ size: 18,
90
+ "aria-hidden": "true"
91
+ }),
92
+ "Describe your ",
93
+ O
94
+ ]
95
+ }), /* @__PURE__ */ y(ee, { children: [
96
+ "Write one sentence and the copilot drafts",
97
+ " ",
98
+ E === "BOT" ? "a bot with its agents" : "agents",
99
+ " for you to review. Nothing goes live until you publish it. Uses AI credits."
100
+ ] })] }), /* @__PURE__ */ v(r, { children: /* @__PURE__ */ y(t, {
101
+ leftIcon: /* @__PURE__ */ v(x, { size: 16 }),
102
+ onClick: () => k(!0),
103
+ children: ["Describe your ", O]
104
+ }) })]
105
+ }), /* @__PURE__ */ v(p, {
106
+ open: de,
107
+ onOpenChange: (e) => e ? k(!0) : Z(),
108
+ children: /* @__PURE__ */ y(m, {
109
+ className: "max-h-[90vh] overflow-y-auto sm:max-w-3xl",
110
+ children: [
111
+ /* @__PURE__ */ y(ae, { children: [/* @__PURE__ */ y(oe, { children: ["Describe your ", O] }), /* @__PURE__ */ v(h, { children: F ? "Review the draft. Edit or untick anything you do not want. Everything is created as a draft." : "One sentence is enough, for example: \"A bot that answers HR policy questions from our handbook and escalates payroll to a human.\"" })] }),
112
+ !F && /* @__PURE__ */ y("div", {
113
+ className: "space-y-4",
114
+ children: [
115
+ /* @__PURE__ */ v(a, {
116
+ label: "Description",
117
+ htmlFor: "copilot-description",
118
+ required: !0,
119
+ error: K,
120
+ description: `${G.length}/${C}`,
121
+ children: /* @__PURE__ */ v(s, {
122
+ id: "copilot-description",
123
+ rows: 3,
124
+ value: A,
125
+ disabled: U.loading,
126
+ "aria-invalid": K ? !0 : void 0,
127
+ onChange: (e) => fe(e.target.value)
128
+ })
129
+ }),
130
+ /* @__PURE__ */ v(a, {
131
+ label: "Model",
132
+ htmlFor: "copilot-model",
133
+ required: !0,
134
+ description: "A model registered in this workspace drafts the bot, and the drafted agents use it.",
135
+ children: /* @__PURE__ */ y("select", {
136
+ id: "copilot-model",
137
+ className: le,
138
+ value: H,
139
+ disabled: U.loading || z.loading || B.loading,
140
+ onChange: (e) => M(e.target.value),
141
+ children: [V.length === 0 && /* @__PURE__ */ v("option", {
142
+ value: "",
143
+ children: X ? "Loading models…" : Y ? "Models could not be loaded" : "No model registered yet"
144
+ }), V.map((e) => /* @__PURE__ */ y("option", {
145
+ value: e.id,
146
+ children: [
147
+ e.name,
148
+ " (",
149
+ e.modelId,
150
+ ")"
151
+ ]
152
+ }, e.id))]
153
+ })
154
+ }),
155
+ Y && !X && /* @__PURE__ */ y("div", {
156
+ role: "alert",
157
+ className: "flex items-center gap-2 text-sm text-status-error-text",
158
+ children: ["The models in this workspace could not be loaded.", /* @__PURE__ */ v(t, {
159
+ type: "button",
160
+ variant: "outline",
161
+ size: "sm",
162
+ onClick: () => {
163
+ z.refetch(), B.refetch();
164
+ },
165
+ children: "Retry"
166
+ })]
167
+ }),
168
+ U.loading && /* @__PURE__ */ v("p", {
169
+ role: "status",
170
+ className: "text-sm text-text-secondary",
171
+ children: "Drafting… this can take up to a minute. Cancel at any time; nothing is created."
172
+ })
173
+ ]
174
+ }),
175
+ F && N && /* @__PURE__ */ y("div", {
176
+ className: "space-y-5",
177
+ children: [
178
+ /* @__PURE__ */ y("div", {
179
+ className: "flex flex-wrap items-center gap-2 text-xs text-text-secondary",
180
+ children: [
181
+ N.template && /* @__PURE__ */ y(e, {
182
+ variant: "secondary",
183
+ children: ["Started from template: ", N.template.name]
184
+ }),
185
+ /* @__PURE__ */ y(e, {
186
+ variant: "outline",
187
+ children: ["Model: ", N.model]
188
+ }),
189
+ /* @__PURE__ */ v(e, {
190
+ variant: "outline",
191
+ children: N.aiCredits == null ? "AI credits: not recorded" : `${N.aiCredits} AI credits used`
192
+ })
193
+ ]
194
+ }),
195
+ N.notes && /* @__PURE__ */ v("p", {
196
+ className: "rounded-md border border-border-subtle p-3 text-sm",
197
+ children: N.notes
198
+ }),
199
+ F.app && /* @__PURE__ */ y("fieldset", {
200
+ className: "space-y-3 rounded-lg border border-border-subtle p-4",
201
+ children: [
202
+ /* @__PURE__ */ v("legend", {
203
+ className: "px-1 text-sm font-medium",
204
+ children: "Bot (draft)"
205
+ }),
206
+ /* @__PURE__ */ v(a, {
207
+ label: "Name",
208
+ htmlFor: "copilot-app-name",
209
+ required: !0,
210
+ children: /* @__PURE__ */ v(o, {
211
+ id: "copilot-app-name",
212
+ maxLength: 100,
213
+ value: F.app.name,
214
+ onChange: (e) => I({
215
+ ...F,
216
+ app: {
217
+ ...F.app,
218
+ name: e.target.value
219
+ }
220
+ })
221
+ })
222
+ }),
223
+ /* @__PURE__ */ v(a, {
224
+ label: "Welcome message",
225
+ htmlFor: "copilot-app-welcome",
226
+ children: /* @__PURE__ */ v(o, {
227
+ id: "copilot-app-welcome",
228
+ value: F.app.welcomeMessage ?? "",
229
+ onChange: (e) => I({
230
+ ...F,
231
+ app: {
232
+ ...F.app,
233
+ welcomeMessage: e.target.value
234
+ }
235
+ })
236
+ })
237
+ }),
238
+ /* @__PURE__ */ y("p", {
239
+ className: "text-xs text-text-secondary",
240
+ children: [
241
+ "Routing: ",
242
+ q.length > 1 ? F.app.routingStrategy : "SINGLE",
243
+ F.app.description ? ` · ${F.app.description}` : ""
244
+ ]
245
+ })
246
+ ]
247
+ }),
248
+ F.agents.map((e) => {
249
+ let t = N.links.find((t) => t.agentKey === e.key), n = N.knowledgeBases.filter((t) => t.agentKeys.includes(e.key));
250
+ return /* @__PURE__ */ y("fieldset", {
251
+ className: "space-y-3 rounded-lg border border-border-subtle p-4",
252
+ children: [/* @__PURE__ */ v("legend", {
253
+ className: "px-1 text-sm font-medium",
254
+ children: /* @__PURE__ */ y("label", {
255
+ className: "flex items-center gap-2",
256
+ children: [
257
+ /* @__PURE__ */ v("input", {
258
+ type: "checkbox",
259
+ checked: e.include,
260
+ onChange: (t) => Q(e.key, { include: t.target.checked })
261
+ }),
262
+ "Agent (draft): ",
263
+ e.name
264
+ ]
265
+ })
266
+ }), e.include && /* @__PURE__ */ y(_, { children: [
267
+ /* @__PURE__ */ v(a, {
268
+ label: "Name",
269
+ htmlFor: `copilot-agent-${e.key}-name`,
270
+ required: !0,
271
+ children: /* @__PURE__ */ v(o, {
272
+ id: `copilot-agent-${e.key}-name`,
273
+ maxLength: 100,
274
+ value: e.name,
275
+ onChange: (t) => Q(e.key, { name: t.target.value })
276
+ })
277
+ }),
278
+ /* @__PURE__ */ v(a, {
279
+ label: "System prompt",
280
+ htmlFor: `copilot-agent-${e.key}-prompt`,
281
+ required: !0,
282
+ children: /* @__PURE__ */ v(s, {
283
+ id: `copilot-agent-${e.key}-prompt`,
284
+ rows: 6,
285
+ value: e.systemPrompt,
286
+ onChange: (t) => Q(e.key, { systemPrompt: t.target.value })
287
+ })
288
+ }),
289
+ n.length > 0 && /* @__PURE__ */ y("div", {
290
+ className: "space-y-1",
291
+ children: [/* @__PURE__ */ v("p", {
292
+ className: "text-sm font-medium",
293
+ children: "Suggested knowledge bases"
294
+ }), n.map((t) => /* @__PURE__ */ y("label", {
295
+ className: "flex items-start gap-2 text-sm",
296
+ children: [/* @__PURE__ */ v("input", {
297
+ type: "checkbox",
298
+ className: "mt-1",
299
+ checked: e.knowledgeBaseIds.includes(t.knowledgeBaseId),
300
+ onChange: (n) => ge(e.key, t.knowledgeBaseId, n.target.checked)
301
+ }), /* @__PURE__ */ y("span", { children: [t.name, t.reason && /* @__PURE__ */ v("span", {
302
+ className: "block text-xs text-text-secondary",
303
+ children: t.reason
304
+ })] })]
305
+ }, t.knowledgeBaseId))]
306
+ }),
307
+ E === "BOT" && t && /* @__PURE__ */ y("p", {
308
+ className: "text-xs text-text-secondary",
309
+ children: [
310
+ "Routing: priority ",
311
+ t.priority,
312
+ t.isDefault ? " · default agent" : "",
313
+ t.intentPatterns.length > 0 ? ` · intents: ${t.intentPatterns.join(", ")}` : "",
314
+ t.triggerKeywords.length > 0 ? ` · keywords: ${t.triggerKeywords.join(", ")}` : ""
315
+ ]
316
+ })
317
+ ] })]
318
+ }, e.key);
319
+ })
320
+ ]
321
+ }),
322
+ L && /* @__PURE__ */ v("p", {
323
+ role: "alert",
324
+ className: "text-sm text-status-error-text",
325
+ children: L
326
+ }),
327
+ /* @__PURE__ */ v(g, { children: F ? /* @__PURE__ */ y(_, { children: [/* @__PURE__ */ v(t, {
328
+ variant: "outline",
329
+ onClick: J,
330
+ disabled: W.loading,
331
+ children: "Discard draft"
332
+ }), /* @__PURE__ */ v(t, {
333
+ isLoading: W.loading,
334
+ disabled: !_e || W.loading,
335
+ onClick: () => void he(),
336
+ children: "Create drafts"
337
+ })] }) : /* @__PURE__ */ y(_, { children: [/* @__PURE__ */ v(t, {
338
+ variant: "outline",
339
+ onClick: U.loading ? U.cancel : Z,
340
+ children: U.loading ? "Cancel drafting" : "Close"
341
+ }), /* @__PURE__ */ y(t, {
342
+ leftIcon: /* @__PURE__ */ v(x, { size: 16 }),
343
+ isLoading: U.loading,
344
+ disabled: U.loading || !H || G.length < S || G.length > C,
345
+ onClick: () => void me(),
346
+ children: ["Draft ", O]
347
+ })] }) })
348
+ ]
349
+ })
350
+ })] });
351
+ };
352
+ export { E as DescribeBotDialog };
353
+
354
+ //# sourceMappingURL=DescribeBotDialog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DescribeBotDialog.js","names":["_Fragment","Textarea","Textarea$1","Fragment$1","DESCRIPTION_MIN","DESCRIPTION_MAX","SELECT_CLASS","reviewFrom","draft","agent","errorText","error","fallback","DescribeBotDialog","noun","scope","open","setOpen","useState","description","setDescription","modelId","setModelId","setDraft","review","setReview","setError","models","useLLMModels","providers","useLLMProviders","answerModels","useMemo","configuredAnswerModels","chosenModel","model","drafting","useDraftBot","createDrafts","createState","useCreateFromDraft","trimmed","descriptionError","included","reset","catalogError","catalogLoading","close","runDraft","result","draftError","isQuotaExhaustedError","create","agents","_include","created","toast","onCreated","createError","onQuotaExhausted","updateAgent","current","key","patch","toggleKnowledgeBase","entry","agentKey","on","kbId","id","appName","canCreate","name","Card","CardHeader","CardTitle","WandSparkles","CardDescription","CardContent","Button","Sparkles","ResponsiveDialog","next","ResponsiveDialogContent","ResponsiveDialogHeader","ResponsiveDialogTitle","ResponsiveDialogDescription","FormField","event","Badge","Input","link","suggestions","kb","ResponsiveDialogFooter"],"sources":["../../../src/botlit/components/DescribeBotDialog.tsx"],"sourcesContent":["/**\n * Copilot \"Describe your bot\" (BOFF-15360, ABOUT §9, BL-UC-21)\n * @module botlit/components\n *\n * One sentence → a reviewable draft: the bot (on the bot create page), its\n * agents, routing links, the model and knowledge-base suggestions, started\n * from a workspace template when one fits. The draft is shown for review and\n * editing; nothing exists until the person clicks \"Create drafts\", and even\n * then every entity is a DRAFT that goes live only when it is published.\n * Drafting can be cancelled at any time and leaves nothing behind. It is\n * metered as AI credits on the workspace plan.\n */\n\nimport { useEffect, useMemo, useState, type FC } from 'react';\nimport { Sparkles, WandSparkles } from 'lucide-react';\nimport { toast } from 'sonner';\nimport { isQuotaExhaustedError } from '@burdenoff/fe-libs/shared/utils';\nimport {\n ResponsiveDialog,\n ResponsiveDialogContent,\n ResponsiveDialogDescription,\n ResponsiveDialogFooter,\n ResponsiveDialogHeader,\n ResponsiveDialogTitle,\n} from '@burdenoff/fe-libs/ui';\n\nimport { Badge } from './Badge';\nimport { Button } from './Button';\nimport { Card, CardContent, CardDescription, CardHeader, CardTitle } from './Card';\nimport { FormField, Input, Textarea } from './Input';\nimport {\n useCreateFromDraft,\n useDraftBot,\n type BotDraft,\n type BotDraftAgent,\n type BotDraftApp,\n type BotDraftScope,\n type CreatedDraft,\n} from '../hooks/useBotCopilot';\nimport { useLLMModels, useLLMProviders } from '../hooks/useLLMProviders';\nimport { configuredAnswerModels } from '../utils/embedding-models';\nimport { AGENT_NAME_MAX_LENGTH } from '../utils/agentSettings';\nimport { BOT_NAME_MAX_LENGTH } from '../utils/botIdentity';\n\nconst DESCRIPTION_MIN = 10;\nconst DESCRIPTION_MAX = 1000;\nconst SELECT_CLASS =\n 'flex h-10 w-full rounded-md border border-border-default bg-bg-surface px-3 py-2 text-sm';\n\ninterface DescribeBotDialogProps {\n scope: BotDraftScope;\n /** Receives what was created (every entity is DRAFT). */\n onCreated: (created: CreatedDraft) => void;\n /** Called instead of an inline message when the plan's bot limit is reached. */\n onQuotaExhausted?: () => void;\n}\n\ninterface ReviewState {\n app: BotDraftApp | null;\n agents: Array<BotDraftAgent & { include: boolean }>;\n}\n\nfunction reviewFrom(draft: BotDraft): ReviewState {\n return {\n app: draft.app ? { ...draft.app } : null,\n agents: draft.agents.map((agent) => ({ ...agent, include: true })),\n };\n}\n\nfunction errorText(error: unknown, fallback: string): string {\n return error instanceof Error && error.message ? error.message : fallback;\n}\n\nexport const DescribeBotDialog: FC<DescribeBotDialogProps> = ({\n scope,\n onCreated,\n onQuotaExhausted,\n}) => {\n const noun = scope === 'BOT' ? 'bot' : 'agent';\n const [open, setOpen] = useState(false);\n const [description, setDescription] = useState('');\n const [modelId, setModelId] = useState('');\n const [draft, setDraft] = useState<BotDraft | null>(null);\n const [review, setReview] = useState<ReviewState | null>(null);\n const [error, setError] = useState<string | null>(null);\n\n const models = useLLMModels();\n const providers = useLLMProviders();\n const answerModels = useMemo(\n () => configuredAnswerModels(models.data ?? [], providers.data ?? []),\n [models.data, providers.data]\n );\n // A selection only counts while it is still one of this workspace's models.\n const chosenModel = answerModels.some((model) => model.id === modelId)\n ? modelId\n : answerModels[0]?.id || '';\n\n const drafting = useDraftBot();\n const [createDrafts, createState] = useCreateFromDraft(scope);\n\n const trimmed = description.trim();\n const descriptionError =\n trimmed.length > 0 && trimmed.length < DESCRIPTION_MIN\n ? `Write at least ${DESCRIPTION_MIN} characters.`\n : trimmed.length > DESCRIPTION_MAX\n ? `Use at most ${DESCRIPTION_MAX} characters.`\n : undefined;\n const included = review?.agents.filter((agent) => agent.include) ?? [];\n\n const reset = () => {\n drafting.cancel();\n setDraft(null);\n setReview(null);\n setError(null);\n };\n\n // A draft from another workspace must never be created in this one.\n useEffect(() => {\n setModelId('');\n setDraft(null);\n setReview(null);\n setError(null);\n }, [drafting.workspaceId]);\n\n const catalogError = models.error ?? providers.error;\n const catalogLoading = models.loading || providers.loading;\n\n const close = () => {\n reset();\n setOpen(false);\n };\n\n const runDraft = async () => {\n setError(null);\n try {\n const result = await drafting.draft({ description: trimmed, llmModelId: chosenModel, scope });\n if (!result) return; // cancelled\n setDraft(result);\n setReview(reviewFrom(result));\n } catch (draftError: unknown) {\n setError(\n isQuotaExhaustedError(draftError)\n ? 'This workspace has no AI credits left for the copilot. The Free plan does not include AI-assisted creation; Pro does.'\n : errorText(draftError, `Could not draft the ${noun}.`)\n );\n }\n };\n\n const create = async () => {\n if (!draft || !review) return;\n setError(null);\n const agents = included.map(({ include: _include, ...agent }) => agent);\n try {\n const created = await createDrafts({ draft, app: review.app, agents, links: draft.links });\n toast.success(\n scope === 'BOT'\n ? `Draft bot \"${created.app?.name ?? ''}\" created with ${created.agents.length} draft agent(s)`\n : `${created.agents.length} draft agent(s) created`\n );\n close();\n onCreated(created);\n } catch (createError: unknown) {\n if (onQuotaExhausted && isQuotaExhaustedError(createError)) {\n close();\n onQuotaExhausted();\n return;\n }\n setError(errorText(createError, `Could not create the draft ${noun}.`));\n }\n };\n\n const updateAgent = (key: string, patch: Partial<BotDraftAgent & { include: boolean }>) =>\n setReview((current) =>\n current\n ? {\n ...current,\n agents: current.agents.map((agent) =>\n agent.key === key ? { ...agent, ...patch } : agent\n ),\n }\n : current\n );\n\n const toggleKnowledgeBase = (agentKey: string, kbId: string, on: boolean) => {\n const agent = review?.agents.find((entry) => entry.key === agentKey);\n if (!agent) return;\n updateAgent(agentKey, {\n knowledgeBaseIds: on\n ? [...new Set([...agent.knowledgeBaseIds, kbId])]\n : agent.knowledgeBaseIds.filter((id) => id !== kbId),\n });\n };\n\n const appName = review?.app?.name.trim() ?? '';\n const canCreate =\n included.length > 0 &&\n included.every((agent) => {\n const name = agent.name.trim();\n return (\n name.length > 0 &&\n name.length <= AGENT_NAME_MAX_LENGTH &&\n agent.systemPrompt.trim().length > 0\n );\n }) &&\n (scope === 'AGENTS' || (appName.length > 0 && appName.length <= BOT_NAME_MAX_LENGTH));\n\n return (\n <>\n <Card className=\"max-w-2xl\">\n <CardHeader>\n <CardTitle className=\"flex items-center gap-2\">\n <WandSparkles size={18} aria-hidden=\"true\" />\n Describe your {noun}\n </CardTitle>\n <CardDescription>\n Write one sentence and the copilot drafts{' '}\n {scope === 'BOT' ? 'a bot with its agents' : 'agents'} for you to review. Nothing goes\n live until you publish it. Uses AI credits.\n </CardDescription>\n </CardHeader>\n <CardContent>\n <Button leftIcon={<Sparkles size={16} />} onClick={() => setOpen(true)}>\n Describe your {noun}\n </Button>\n </CardContent>\n </Card>\n\n <ResponsiveDialog open={open} onOpenChange={(next) => (next ? setOpen(true) : close())}>\n <ResponsiveDialogContent className=\"max-h-[90vh] overflow-y-auto sm:max-w-3xl\">\n <ResponsiveDialogHeader>\n <ResponsiveDialogTitle>Describe your {noun}</ResponsiveDialogTitle>\n <ResponsiveDialogDescription>\n {review\n ? 'Review the draft. Edit or untick anything you do not want. Everything is created as a draft.'\n : 'One sentence is enough, for example: \"A bot that answers HR policy questions from our handbook and escalates payroll to a human.\"'}\n </ResponsiveDialogDescription>\n </ResponsiveDialogHeader>\n\n {!review && (\n <div className=\"space-y-4\">\n <FormField\n label=\"Description\"\n htmlFor=\"copilot-description\"\n required\n error={descriptionError}\n description={`${trimmed.length}/${DESCRIPTION_MAX}`}\n >\n <Textarea\n id=\"copilot-description\"\n rows={3}\n value={description}\n disabled={drafting.loading}\n aria-invalid={descriptionError ? true : undefined}\n onChange={(event) => setDescription(event.target.value)}\n />\n </FormField>\n <FormField\n label=\"Model\"\n htmlFor=\"copilot-model\"\n required\n description=\"A model registered in this workspace drafts the bot, and the drafted agents use it.\"\n >\n <select\n id=\"copilot-model\"\n className={SELECT_CLASS}\n value={chosenModel}\n disabled={drafting.loading || models.loading || providers.loading}\n onChange={(event) => setModelId(event.target.value)}\n >\n {answerModels.length === 0 && (\n <option value=\"\">\n {catalogLoading\n ? 'Loading models…'\n : catalogError\n ? 'Models could not be loaded'\n : 'No model registered yet'}\n </option>\n )}\n {answerModels.map((model) => (\n <option key={model.id} value={model.id}>\n {model.name} ({model.modelId})\n </option>\n ))}\n </select>\n </FormField>\n {catalogError && !catalogLoading && (\n <div\n role=\"alert\"\n className=\"flex items-center gap-2 text-sm text-status-error-text\"\n >\n The models in this workspace could not be loaded.\n <Button\n type=\"button\"\n variant=\"outline\"\n size=\"sm\"\n onClick={() => {\n void models.refetch();\n void providers.refetch();\n }}\n >\n Retry\n </Button>\n </div>\n )}\n {drafting.loading && (\n <p role=\"status\" className=\"text-sm text-text-secondary\">\n Drafting… this can take up to a minute. Cancel at any time; nothing is created.\n </p>\n )}\n </div>\n )}\n\n {review && draft && (\n <div className=\"space-y-5\">\n <div className=\"flex flex-wrap items-center gap-2 text-xs text-text-secondary\">\n {draft.template && (\n <Badge variant=\"secondary\">Started from template: {draft.template.name}</Badge>\n )}\n <Badge variant=\"outline\">Model: {draft.model}</Badge>\n <Badge variant=\"outline\">\n {draft.aiCredits != null\n ? `${draft.aiCredits} AI credits used`\n : 'AI credits: not recorded'}\n </Badge>\n </div>\n {draft.notes && (\n <p className=\"rounded-md border border-border-subtle p-3 text-sm\">{draft.notes}</p>\n )}\n\n {review.app && (\n <fieldset className=\"space-y-3 rounded-lg border border-border-subtle p-4\">\n <legend className=\"px-1 text-sm font-medium\">Bot (draft)</legend>\n <FormField label=\"Name\" htmlFor=\"copilot-app-name\" required>\n <Input\n id=\"copilot-app-name\"\n maxLength={BOT_NAME_MAX_LENGTH}\n value={review.app.name}\n onChange={(event) =>\n setReview({ ...review, app: { ...review.app!, name: event.target.value } })\n }\n />\n </FormField>\n <FormField label=\"Welcome message\" htmlFor=\"copilot-app-welcome\">\n <Input\n id=\"copilot-app-welcome\"\n value={review.app.welcomeMessage ?? ''}\n onChange={(event) =>\n setReview({\n ...review,\n app: { ...review.app!, welcomeMessage: event.target.value },\n })\n }\n />\n </FormField>\n <p className=\"text-xs text-text-secondary\">\n Routing: {included.length > 1 ? review.app.routingStrategy : 'SINGLE'}\n {review.app.description ? ` · ${review.app.description}` : ''}\n </p>\n </fieldset>\n )}\n\n {review.agents.map((agent) => {\n const link = draft.links.find((entry) => entry.agentKey === agent.key);\n const suggestions = draft.knowledgeBases.filter((kb) =>\n kb.agentKeys.includes(agent.key)\n );\n return (\n <fieldset\n key={agent.key}\n className=\"space-y-3 rounded-lg border border-border-subtle p-4\"\n >\n <legend className=\"px-1 text-sm font-medium\">\n <label className=\"flex items-center gap-2\">\n <input\n type=\"checkbox\"\n checked={agent.include}\n onChange={(event) =>\n updateAgent(agent.key, { include: event.target.checked })\n }\n />\n Agent (draft): {agent.name}\n </label>\n </legend>\n {agent.include && (\n <>\n <FormField\n label=\"Name\"\n htmlFor={`copilot-agent-${agent.key}-name`}\n required\n >\n <Input\n id={`copilot-agent-${agent.key}-name`}\n maxLength={AGENT_NAME_MAX_LENGTH}\n value={agent.name}\n onChange={(event) =>\n updateAgent(agent.key, { name: event.target.value })\n }\n />\n </FormField>\n <FormField\n label=\"System prompt\"\n htmlFor={`copilot-agent-${agent.key}-prompt`}\n required\n >\n <Textarea\n id={`copilot-agent-${agent.key}-prompt`}\n rows={6}\n value={agent.systemPrompt}\n onChange={(event) =>\n updateAgent(agent.key, { systemPrompt: event.target.value })\n }\n />\n </FormField>\n {suggestions.length > 0 && (\n <div className=\"space-y-1\">\n <p className=\"text-sm font-medium\">Suggested knowledge bases</p>\n {suggestions.map((kb) => (\n <label\n key={kb.knowledgeBaseId}\n className=\"flex items-start gap-2 text-sm\"\n >\n <input\n type=\"checkbox\"\n className=\"mt-1\"\n checked={agent.knowledgeBaseIds.includes(kb.knowledgeBaseId)}\n onChange={(event) =>\n toggleKnowledgeBase(\n agent.key,\n kb.knowledgeBaseId,\n event.target.checked\n )\n }\n />\n <span>\n {kb.name}\n {kb.reason && (\n <span className=\"block text-xs text-text-secondary\">\n {kb.reason}\n </span>\n )}\n </span>\n </label>\n ))}\n </div>\n )}\n {scope === 'BOT' && link && (\n <p className=\"text-xs text-text-secondary\">\n Routing: priority {link.priority}\n {link.isDefault ? ' · default agent' : ''}\n {link.intentPatterns.length > 0\n ? ` · intents: ${link.intentPatterns.join(', ')}`\n : ''}\n {link.triggerKeywords.length > 0\n ? ` · keywords: ${link.triggerKeywords.join(', ')}`\n : ''}\n </p>\n )}\n </>\n )}\n </fieldset>\n );\n })}\n </div>\n )}\n\n {error && (\n <p role=\"alert\" className=\"text-sm text-status-error-text\">\n {error}\n </p>\n )}\n\n <ResponsiveDialogFooter>\n {!review ? (\n <>\n <Button variant=\"outline\" onClick={drafting.loading ? drafting.cancel : close}>\n {drafting.loading ? 'Cancel drafting' : 'Close'}\n </Button>\n <Button\n leftIcon={<Sparkles size={16} />}\n isLoading={drafting.loading}\n disabled={\n drafting.loading ||\n !chosenModel ||\n trimmed.length < DESCRIPTION_MIN ||\n trimmed.length > DESCRIPTION_MAX\n }\n onClick={() => void runDraft()}\n >\n Draft {noun}\n </Button>\n </>\n ) : (\n <>\n <Button variant=\"outline\" onClick={reset} disabled={createState.loading}>\n Discard draft\n </Button>\n <Button\n isLoading={createState.loading}\n disabled={!canCreate || createState.loading}\n onClick={() => void create()}\n >\n Create drafts\n </Button>\n </>\n )}\n </ResponsiveDialogFooter>\n </ResponsiveDialogContent>\n </ResponsiveDialog>\n </>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;AA4CA,IAAMI,IAAkB,IAClBC,IAAkB,KAClBC,KACJ;AAeF,SAASC,EAAW,GAA8B;CAChD,OAAO;EACL,KAAKC,EAAM,MAAM,EAAE,GAAGA,EAAM,IAAI,IAAI;EACpC,QAAQA,EAAM,OAAO,KAAK,OAAW;GAAE,GAAGC;GAAO,SAAS;EAAK,EAAE;CACnE;AACF;AAEA,SAASC,EAAU,GAAgB,GAA0B;CAC3D,OAAOC,aAAiB,SAASA,EAAM,UAAUA,EAAM,UAAUC;AACnE;AAEA,IAAaC,KAAiD,EAC5D,UACA,eACA,0BACI;CACJ,IAAMC,IAAOC,MAAU,QAAQ,QAAQ,SACjC,CAACC,IAAMC,KAAWC,EAAS,EAAK,GAChC,CAACC,GAAaC,MAAkBF,EAAS,EAAE,GAC3C,CAACG,GAASC,KAAcJ,EAAS,EAAE,GACnC,CAACV,GAAOe,KAAYL,EAA0B,IAAI,GAClD,CAACM,GAAQC,KAAaP,EAA6B,IAAI,GACvD,CAACP,GAAOe,KAAYR,EAAwB,IAAI,GAEhDS,IAASC,GAAa,GACtBC,IAAYC,GAAgB,GAC5BC,IAAeC,QACbC,GAAuBN,EAAO,QAAQ,CAAC,GAAGE,EAAU,QAAQ,CAAC,CAAC,GACpE,CAACF,EAAO,MAAME,EAAU,IAAI,CAC9B,GAEMK,IAAcH,EAAa,MAAM,MAAUI,EAAM,OAAOd,CAAO,IACjEA,IACAU,EAAa,EAAE,EAAE,MAAM,IAErBK,IAAWC,EAAY,GACvB,CAACC,IAAcC,KAAeC,EAAmBzB,CAAK,GAEtD0B,I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,EAAK,gBAAgB,SAAS,IAC3B,gBAAgBA,EAAK,gBAAgB,KAAK,IAAI,MAC9C;UACH;;QAEL,EAAA,CAAA,CAEI;OA3FH,GAAAlF,EAAM,GA2FH;MAEd,CAAC;KACE;;IAGNE,KACC,kBAAC,KAAD;KAAG,MAAK;KAAQ,WAAU;KACvB,UAAAA;IACA,CAAA;IAGL,kBAACmF,GAAD,EAAA,UACItE,IAoBA,kBAAAxB,GAAA,EAAA,UAAA,CACE,kBAAC+E,GAAD;KAAQ,SAAQ;KAAU,SAASnC;KAAO,UAAUL,EAAY;KAAS,UAAA;IAEjE,CAAA,GACR,kBAACwC,GAAD;KACE,WAAWxC,EAAY;KACvB,UAAU,CAACgC,MAAahC,EAAY;KACpC,eAAe,KAAKa,GAAO;KAC5B,UAAA;IAEO,CAAA,CACR,EAAA,CAAA,IA9BF,kBAAApD,GAAA,EAAA,UAAA,CACE,kBAAC+E,GAAD;KAAQ,SAAQ;KAAU,SAAS3C,EAAS,UAAUA,EAAS,SAASW;KACrE,UAAAX,EAAS,UAAU,oBAAoB;IAClC,CAAA,GACR,kBAAC2C,GAAD;KACE,UAAU,kBAACC,GAAD,EAAU,MAAM,GAAK,CAAA;KAC/B,WAAW5C,EAAS;KACpB,UACEA,EAAS,WACT,CAACF,KACDO,EAAQ,SAASrC,KACjBqC,EAAQ,SAASpC;KAEnB,eAAe,KAAK2C,GAAS;KAT/B,UAAA,CAUC,UACQlC,CACD;IACR,CAAA,CAAA,EAAA,CAAA,EAekB,CAAA;GACD;;CACT,CAAA,CAClB,EAAA,CAAA;AAEN"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Try a question against the knowledge base and see which chunks retrieval
3
+ * returns, before an agent uses it (BOFF-15360). Uses the same
4
+ * `searchKnowledge` query the runtime relies on.
5
+ */
6
+ export declare function KnowledgeSearchPanel({ knowledgeBaseId, documentTitles, }: {
7
+ knowledgeBaseId: string;
8
+ /** Document id → title, to say where each hit came from. */
9
+ documentTitles: ReadonlyMap<string, string>;
10
+ }): import('react').JSX.Element;
@@ -0,0 +1,103 @@
1
+ import { useTr as e } from "../../shared/hooks/useTr.js";
2
+ import { graphqlErrorMessage as t } from "../utils/errors.js";
3
+ import { Button as n } from "./Button.js";
4
+ import { Card as r, CardContent as i, CardDescription as a, CardHeader as o, CardTitle as s } from "./Card.js";
5
+ import { useState as c } from "react";
6
+ import { jsx as l, jsxs as u } from "react/jsx-runtime";
7
+ import { gql as d } from "@apollo/client";
8
+ import { useGatewayClient as f } from "@burdenoff/fe-libs/shared/graphql";
9
+ import { useMutation as p } from "@tanstack/react-query";
10
+ import { Search as m } from "lucide-react";
11
+ // src/botlit/components/KnowledgeSearchPanel.tsx
12
+ var h = d`
13
+ query SearchKnowledgeBase($knowledgeBaseId: ID!, $query: String!, $topK: Int) {
14
+ searchKnowledge(knowledgeBaseId: $knowledgeBaseId, query: $query, topK: $topK) {
15
+ id
16
+ documentId
17
+ sequence
18
+ content
19
+ }
20
+ }
21
+ `, g = 1e3;
22
+ function _({ knowledgeBaseId: d, documentTitles: _ }) {
23
+ let v = e(), y = f("workspace"), [b, x] = c(""), S = p({ mutationFn: async (e) => {
24
+ let t = (await y.query({
25
+ query: h,
26
+ variables: {
27
+ knowledgeBaseId: d,
28
+ query: e,
29
+ topK: 5
30
+ },
31
+ fetchPolicy: "no-cache"
32
+ })).data?.searchKnowledge;
33
+ if (!t) throw Error("Search unavailable");
34
+ return t;
35
+ } });
36
+ return /* @__PURE__ */ u(r, { children: [/* @__PURE__ */ u(o, { children: [/* @__PURE__ */ u(s, {
37
+ className: "flex items-center gap-2",
38
+ children: [/* @__PURE__ */ l(m, {
39
+ size: 18,
40
+ "aria-hidden": "true"
41
+ }), v("botlit.kb.search.title", "Search this knowledge base")]
42
+ }), /* @__PURE__ */ l(a, { children: v("botlit.kb.search.help", "Ask a question to see the passages an agent would retrieve from the indexed documents.") })] }), /* @__PURE__ */ u(i, {
43
+ className: "space-y-4",
44
+ children: [/* @__PURE__ */ u("form", {
45
+ onSubmit: (e) => {
46
+ e.preventDefault();
47
+ let t = b.trim();
48
+ t && S.mutate(t);
49
+ },
50
+ className: "flex flex-col gap-2 sm:flex-row",
51
+ children: [
52
+ /* @__PURE__ */ l("label", {
53
+ className: "sr-only",
54
+ htmlFor: `kb-search-${d}`,
55
+ children: v("botlit.kb.search.label", "Search query")
56
+ }),
57
+ /* @__PURE__ */ l("input", {
58
+ id: `kb-search-${d}`,
59
+ type: "search",
60
+ className: "h-10 flex-1 rounded-md border border-border-default bg-bg-surface px-3",
61
+ placeholder: v("botlit.kb.search.placeholder", "For example: What is the returns window?"),
62
+ value: b,
63
+ maxLength: g,
64
+ onChange: (e) => x(e.target.value)
65
+ }),
66
+ /* @__PURE__ */ l(n, {
67
+ type: "submit",
68
+ disabled: !b.trim(),
69
+ isLoading: S.isPending,
70
+ children: v("botlit.kb.search.submit", "Search")
71
+ })
72
+ ]
73
+ }), S.isError ? /* @__PURE__ */ l("p", {
74
+ role: "alert",
75
+ className: "text-sm text-status-error-text",
76
+ children: t(S.error, v("botlit.kb.search.failed", "Search failed. The knowledge base must be indexed and its embedding provider reachable."))
77
+ }) : S.data ? S.data.length === 0 ? /* @__PURE__ */ l("p", {
78
+ role: "status",
79
+ className: "text-sm text-text-secondary",
80
+ children: v("botlit.kb.search.empty", "No passages matched. Try other words, or add documents.")
81
+ }) : /* @__PURE__ */ l("ol", {
82
+ className: "space-y-3",
83
+ "aria-label": v("botlit.kb.search.results", "Search results"),
84
+ children: S.data.map((e, t) => /* @__PURE__ */ u("li", {
85
+ className: "rounded-md border border-border-subtle p-3 text-sm",
86
+ children: [/* @__PURE__ */ l("p", {
87
+ className: "mb-1 font-medium text-text-secondary",
88
+ children: v("botlit.kb.search.hit", "[{{rank}}] {{title}} · chunk {{sequence}}", {
89
+ rank: t + 1,
90
+ title: _.get(e.documentId) ?? v("botlit.kb.search.unknownDocument", "Document"),
91
+ sequence: e.sequence + 1
92
+ })
93
+ }), /* @__PURE__ */ l("p", {
94
+ className: "whitespace-pre-wrap break-words text-text-primary",
95
+ children: e.content
96
+ })]
97
+ }, e.id))
98
+ }) : null]
99
+ })] });
100
+ }
101
+ export { _ as KnowledgeSearchPanel };
102
+
103
+ //# sourceMappingURL=KnowledgeSearchPanel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KnowledgeSearchPanel.js","names":["SEARCH","MAX_QUERY_LENGTH","KnowledgeSearchPanel","t","useTr","client","useGatewayClient","query","setQuery","useState","search","useMutation","hits","text","Card","CardHeader","CardTitle","Search","CardDescription","CardContent","knowledgeBaseId","event","Button","graphqlErrorMessage","index","documentTitles","hit"],"sources":["../../../src/botlit/components/KnowledgeSearchPanel.tsx"],"sourcesContent":["import { gql } from '@apollo/client';\nimport { useMutation } from '@tanstack/react-query';\nimport { useGatewayClient } from '@burdenoff/fe-libs/shared/graphql';\nimport { Search } from 'lucide-react';\nimport { useState } from 'react';\nimport type { FormEvent } from 'react';\nimport { useTr } from '../../shared/hooks/useTr';\nimport { graphqlErrorMessage } from '../utils/errors';\nimport { Button } from './Button';\nimport { Card, CardContent, CardDescription, CardHeader, CardTitle } from './Card';\n\ninterface KnowledgeSearchHit {\n id: string;\n documentId: string;\n sequence: number;\n content: string;\n}\n\nconst SEARCH = gql`\n query SearchKnowledgeBase($knowledgeBaseId: ID!, $query: String!, $topK: Int) {\n searchKnowledge(knowledgeBaseId: $knowledgeBaseId, query: $query, topK: $topK) {\n id\n documentId\n sequence\n content\n }\n }\n`;\n\nconst MAX_QUERY_LENGTH = 1000;\n\n/**\n * Try a question against the knowledge base and see which chunks retrieval\n * returns, before an agent uses it (BOFF-15360). Uses the same\n * `searchKnowledge` query the runtime relies on.\n */\nexport function KnowledgeSearchPanel({\n knowledgeBaseId,\n documentTitles,\n}: {\n knowledgeBaseId: string;\n /** Document id → title, to say where each hit came from. */\n documentTitles: ReadonlyMap<string, string>;\n}) {\n const t = useTr();\n const client = useGatewayClient('workspace');\n const [query, setQuery] = useState('');\n const search = useMutation({\n mutationFn: async (text: string) => {\n const response = await client.query<{ searchKnowledge: KnowledgeSearchHit[] }>({\n query: SEARCH,\n variables: { knowledgeBaseId, query: text, topK: 5 },\n fetchPolicy: 'no-cache',\n });\n const hits = response.data?.searchKnowledge;\n if (!hits) throw new Error('Search unavailable');\n return hits;\n },\n });\n\n const submit = (event: FormEvent) => {\n event.preventDefault();\n const text = query.trim();\n if (text) search.mutate(text);\n };\n\n return (\n <Card>\n <CardHeader>\n <CardTitle className=\"flex items-center gap-2\">\n <Search size={18} aria-hidden=\"true\" />\n {t('botlit.kb.search.title', 'Search this knowledge base')}\n </CardTitle>\n <CardDescription>\n {t(\n 'botlit.kb.search.help',\n 'Ask a question to see the passages an agent would retrieve from the indexed documents.'\n )}\n </CardDescription>\n </CardHeader>\n <CardContent className=\"space-y-4\">\n <form onSubmit={submit} className=\"flex flex-col gap-2 sm:flex-row\">\n <label className=\"sr-only\" htmlFor={`kb-search-${knowledgeBaseId}`}>\n {t('botlit.kb.search.label', 'Search query')}\n </label>\n <input\n id={`kb-search-${knowledgeBaseId}`}\n type=\"search\"\n className=\"h-10 flex-1 rounded-md border border-border-default bg-bg-surface px-3\"\n placeholder={t(\n 'botlit.kb.search.placeholder',\n 'For example: What is the returns window?'\n )}\n value={query}\n maxLength={MAX_QUERY_LENGTH}\n onChange={(event) => setQuery(event.target.value)}\n />\n <Button type=\"submit\" disabled={!query.trim()} isLoading={search.isPending}>\n {t('botlit.kb.search.submit', 'Search')}\n </Button>\n </form>\n {search.isError ? (\n <p role=\"alert\" className=\"text-sm text-status-error-text\">\n {graphqlErrorMessage(\n search.error,\n t(\n 'botlit.kb.search.failed',\n 'Search failed. The knowledge base must be indexed and its embedding provider reachable.'\n )\n )}\n </p>\n ) : search.data ? (\n search.data.length === 0 ? (\n <p role=\"status\" className=\"text-sm text-text-secondary\">\n {t(\n 'botlit.kb.search.empty',\n 'No passages matched. Try other words, or add documents.'\n )}\n </p>\n ) : (\n <ol className=\"space-y-3\" aria-label={t('botlit.kb.search.results', 'Search results')}>\n {search.data.map((hit, index) => (\n <li key={hit.id} className=\"rounded-md border border-border-subtle p-3 text-sm\">\n <p className=\"mb-1 font-medium text-text-secondary\">\n {t('botlit.kb.search.hit', '[{{rank}}] {{title}} · chunk {{sequence}}', {\n rank: index + 1,\n title:\n documentTitles.get(hit.documentId) ??\n t('botlit.kb.search.unknownDocument', 'Document'),\n sequence: hit.sequence + 1,\n })}\n </p>\n <p className=\"whitespace-pre-wrap break-words text-text-primary\">{hit.content}</p>\n </li>\n ))}\n </ol>\n )\n ) : null}\n </CardContent>\n </Card>\n );\n}\n"],"mappings":";;;;;;;;;;;AAkBA,IAAMA,IAAS,CAAG;;;;;;;;;GAWZC,IAAmB;AAOzB,SAAgBC,EAAqB,EACnC,oBACA,qBAKC;CACD,IAAMC,IAAIC,EAAM,GACVC,IAASC,EAAiB,WAAW,GACrC,CAACC,GAAOC,KAAYC,EAAS,EAAE,GAC/BC,IAASC,EAAY,EACzB,YAAY,OAAO,MAAiB;EAMlC,IAAMC,KAAO,MALUP,EAAO,MAAiD;GAC7E,OAAOL;GACP,WAAW;IAAE;IAAiB,OAAOa;IAAM,MAAM;GAAE;GACnD,aAAa;EACf,CAAC,EAAA,CACqB,MAAM;EAC5B,IAAI,CAACD,GAAM,MAAU,MAAM,oBAAoB;EAC/C,OAAOA;CACT,EACF,CAAC;CAQD,OACE,kBAACE,GAAD,EAAA,UAAA,CACE,kBAACC,GAAD,EAAA,UAAA,CACE,kBAACC,GAAD;EAAW,WAAU;EAArB,UAAA,CACE,kBAACC,GAAD;GAAQ,MAAM;GAAI,eAAY;EAAQ,CAAA,GACrCd,EAAE,0BAA0B,4BAA4B,CAChD;CACX,CAAA,GAAA,kBAACe,GAAD,EAAA,UACGf,EACC,yBACA,wFACF,EACe,CAAA,CACP,EAAA,CAAA,GACZ,kBAACgB,GAAD;EAAa,WAAU;EAAvB,UAAA,CACE,kBAAC,QAAD;GAAM,WArBI,MAAqB;IACnC,EAAM,e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