@burdenoff/microfe-botmanor 2026.1119.4 → 2026.1120.2
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/botlit/components/KnowledgeBackendMigrationPanel.d.ts +3 -0
- package/dist/botlit/components/KnowledgeBackendMigrationPanel.js +240 -0
- package/dist/botlit/components/KnowledgeBackendMigrationPanel.js.map +1 -0
- package/dist/botlit/components/KnowledgeDocumentUploadPanel.d.ts +14 -0
- package/dist/botlit/components/KnowledgeDocumentUploadPanel.js +142 -0
- package/dist/botlit/components/KnowledgeDocumentUploadPanel.js.map +1 -0
- package/dist/botlit/components/KnowledgeRetrievalTestPanel.d.ts +10 -0
- package/dist/botlit/components/KnowledgeRetrievalTestPanel.js +174 -0
- package/dist/botlit/components/KnowledgeRetrievalTestPanel.js.map +1 -0
- package/dist/botlit/components/KnowledgeSearchPanel.d.ts +10 -0
- package/dist/botlit/components/KnowledgeSearchPanel.js +103 -0
- package/dist/botlit/components/KnowledgeSearchPanel.js.map +1 -0
- package/dist/botlit/components/KnowledgeSourceImportPanel.js +88 -51
- package/dist/botlit/components/KnowledgeSourceImportPanel.js.map +1 -1
- package/dist/botlit/hooks/useKnowledgeCuratorTools.d.ts +49 -0
- package/dist/botlit/hooks/useKnowledgeCuratorTools.js +183 -0
- package/dist/botlit/hooks/useKnowledgeCuratorTools.js.map +1 -0
- package/dist/botlit/pages/KnowledgeBaseDetailPage.js +378 -358
- package/dist/botlit/pages/KnowledgeBaseDetailPage.js.map +1 -1
- package/dist/botlit/utils/knowledgeImportStatus.js +2 -7
- package/dist/botlit/utils/knowledgeImportStatus.js.map +1 -1
- package/dist/generated/wspace-types.d.ts +20 -0
- package/dist/generated/wspace-types.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { useTr as e } from "../../shared/hooks/useTr.js";
|
|
2
|
+
import { useBotlit as t } from "../providers/BotlitProvider.js";
|
|
3
|
+
import { MIGRATION_DISCARDABLE_STATUSES as n, useKnowledgeBackendMigrations as r, useKnowledgeBaseBackend as i } from "../hooks/useKnowledgeCuratorTools.js";
|
|
4
|
+
import { confirmAction as a } from "../utils/confirmAction.js";
|
|
5
|
+
import { graphqlErrorMessage as o } from "../utils/errors.js";
|
|
6
|
+
import { formatRelativeTime as s } from "../utils/formatters.js";
|
|
7
|
+
import { Card as c, CardContent as l, CardDescription as u, CardHeader as d, CardTitle as f } from "./Card.js";
|
|
8
|
+
import { Button as p } from "./Button.js";
|
|
9
|
+
import { useState as m } from "react";
|
|
10
|
+
import { jsx as h, jsxs as g } from "react/jsx-runtime";
|
|
11
|
+
import { ArrowRightLeft as _ } from "lucide-react";
|
|
12
|
+
// src/botlit/components/KnowledgeBackendMigrationPanel.tsx
|
|
13
|
+
var v = "h-10 rounded-md border border-border-default bg-bg-surface px-3 text-sm text-text-primary", y = {
|
|
14
|
+
opensearch: "OpenSearch",
|
|
15
|
+
postgres: "PostgreSQL",
|
|
16
|
+
milvus: "Milvus"
|
|
17
|
+
}, b = {
|
|
18
|
+
READY: "Queued",
|
|
19
|
+
COPYING: "Copying",
|
|
20
|
+
VERIFIED: "Verified, ready for cutover",
|
|
21
|
+
BLOCKED: "Blocked",
|
|
22
|
+
COMPLETED: "Completed",
|
|
23
|
+
CANCELLED: "Discarded"
|
|
24
|
+
}, x = {
|
|
25
|
+
VERIFIED: "text-status-success-text",
|
|
26
|
+
COMPLETED: "text-status-success-text",
|
|
27
|
+
BLOCKED: "text-status-error-text",
|
|
28
|
+
CANCELLED: "text-text-secondary"
|
|
29
|
+
};
|
|
30
|
+
function S(e) {
|
|
31
|
+
return e ? y[e] ?? e : "—";
|
|
32
|
+
}
|
|
33
|
+
function C(e, t) {
|
|
34
|
+
return t <= 0 ? 100 : Math.min(100, Math.round(e / t * 100));
|
|
35
|
+
}
|
|
36
|
+
function w({ knowledgeBaseId: e }) {
|
|
37
|
+
let { workspaceId: n, currentUser: r } = t();
|
|
38
|
+
return /* @__PURE__ */ h(T, { knowledgeBaseId: e }, `${n}:${r?.id}:${e}`);
|
|
39
|
+
}
|
|
40
|
+
function T({ knowledgeBaseId: t }) {
|
|
41
|
+
let y = e(), w = i(t), { targets: T, migrations: E, begin: D, cutover: O, discard: k } = r(t), [A, j] = m(""), [M, N] = m(null), P = w.data?.vectorStoreDriver ?? null, F = (T.data ?? []).filter((e) => e !== P), I = F.includes(A) ? A : F[0] ?? "", L = E.data ?? [], R = L.find((e) => [
|
|
42
|
+
"READY",
|
|
43
|
+
"COPYING",
|
|
44
|
+
"VERIFIED"
|
|
45
|
+
].includes(e.status)), z = (e, t) => N({
|
|
46
|
+
tone: "error",
|
|
47
|
+
text: o(e, t)
|
|
48
|
+
}), B = async () => {
|
|
49
|
+
if (I && await a({
|
|
50
|
+
title: y("botlit.kb.migration.beginTitle", "Copy to {{target}}?", { target: S(I) }),
|
|
51
|
+
message: y("botlit.kb.migration.beginMessage", "A verified copy is built in {{target}} while agents keep using {{current}}. Nothing changes for agents until you cut over. Document changes are refused at cutover if the source changed.", {
|
|
52
|
+
target: S(I),
|
|
53
|
+
current: S(P)
|
|
54
|
+
}),
|
|
55
|
+
confirmLabel: y("botlit.kb.migration.beginConfirm", "Start copy"),
|
|
56
|
+
cancelLabel: y("botlit.common.cancel", "Cancel")
|
|
57
|
+
})) {
|
|
58
|
+
N(null);
|
|
59
|
+
try {
|
|
60
|
+
await D.mutateAsync(I), N({
|
|
61
|
+
tone: "info",
|
|
62
|
+
text: y("botlit.kb.migration.started", "Copy queued. Its progress appears below and refreshes by itself.")
|
|
63
|
+
});
|
|
64
|
+
} catch (e) {
|
|
65
|
+
z(e, y("botlit.kb.migration.beginFailed", "The copy could not start. Every document must be indexed and published first."));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}, V = async (e) => {
|
|
69
|
+
if (await a({
|
|
70
|
+
title: y("botlit.kb.migration.cutoverTitle", "Switch live retrieval to {{target}}?", { target: S(e.targetDriver) }),
|
|
71
|
+
message: y("botlit.kb.migration.cutoverMessage", "Agents start reading this knowledge base from {{target}} immediately. The {{source}} copy is kept until it is retired.", {
|
|
72
|
+
target: S(e.targetDriver),
|
|
73
|
+
source: S(e.sourceDriver)
|
|
74
|
+
}),
|
|
75
|
+
confirmLabel: y("botlit.kb.migration.cutoverConfirm", "Cut over"),
|
|
76
|
+
cancelLabel: y("botlit.common.cancel", "Cancel")
|
|
77
|
+
})) {
|
|
78
|
+
N(null);
|
|
79
|
+
try {
|
|
80
|
+
await O.mutateAsync(e.id), N({
|
|
81
|
+
tone: "info",
|
|
82
|
+
text: y("botlit.kb.migration.cutoverDone", "Live retrieval now uses {{target}}.", { target: S(e.targetDriver) })
|
|
83
|
+
});
|
|
84
|
+
} catch (e) {
|
|
85
|
+
z(e, y("botlit.kb.migration.cutoverFailed", "Cutover was refused. The source changed or the copy no longer verifies; discard it and start again."));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}, H = async (e) => {
|
|
89
|
+
if (await a({
|
|
90
|
+
title: y("botlit.kb.migration.discardTitle", "Discard this copy?"),
|
|
91
|
+
message: y("botlit.kb.migration.discardMessage", "The inactive {{target}} copy is retired. Live retrieval is not affected.", { target: S(e.targetDriver) }),
|
|
92
|
+
confirmLabel: y("botlit.kb.migration.discardConfirm", "Discard"),
|
|
93
|
+
cancelLabel: y("botlit.common.cancel", "Cancel")
|
|
94
|
+
})) {
|
|
95
|
+
N(null);
|
|
96
|
+
try {
|
|
97
|
+
await k.mutateAsync(e.id), N({
|
|
98
|
+
tone: "info",
|
|
99
|
+
text: y("botlit.kb.migration.discarded", "Copy discarded.")
|
|
100
|
+
});
|
|
101
|
+
} catch (e) {
|
|
102
|
+
z(e, y("botlit.kb.migration.discardFailed", "The copy could not be discarded."));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
return /* @__PURE__ */ g(c, { children: [/* @__PURE__ */ g(d, { children: [/* @__PURE__ */ g(f, {
|
|
107
|
+
className: "flex items-center gap-2",
|
|
108
|
+
children: [/* @__PURE__ */ h(_, {
|
|
109
|
+
size: 18,
|
|
110
|
+
"aria-hidden": "true"
|
|
111
|
+
}), y("botlit.kb.migration.title", "Vector backend")]
|
|
112
|
+
}), /* @__PURE__ */ h(u, { children: y("botlit.kb.migration.help", "Move this knowledge base to another vector backend: copy, verify, then cut over. It is never switched silently.") })] }), /* @__PURE__ */ g(l, {
|
|
113
|
+
className: "space-y-4",
|
|
114
|
+
children: [
|
|
115
|
+
/* @__PURE__ */ h("p", {
|
|
116
|
+
className: "text-sm",
|
|
117
|
+
children: y("botlit.kb.migration.current", "Live backend: {{driver}}", { driver: w.isPending ? "…" : S(P) })
|
|
118
|
+
}),
|
|
119
|
+
T.isError ? /* @__PURE__ */ h("p", {
|
|
120
|
+
role: "alert",
|
|
121
|
+
className: "text-sm text-status-error-text",
|
|
122
|
+
children: y("botlit.kb.migration.targetsError", "Migration options could not be loaded. Knowledge management permission is required.")
|
|
123
|
+
}) : T.isPending ? /* @__PURE__ */ h("p", {
|
|
124
|
+
role: "status",
|
|
125
|
+
className: "text-sm text-text-secondary",
|
|
126
|
+
children: y("botlit.kb.migration.loading", "Loading migration options…")
|
|
127
|
+
}) : F.length === 0 ? /* @__PURE__ */ h("p", {
|
|
128
|
+
className: "text-sm text-text-secondary",
|
|
129
|
+
children: y("botlit.kb.migration.noTargets", "No other vector backend is enabled for migration in this environment.")
|
|
130
|
+
}) : R ? /* @__PURE__ */ h("p", {
|
|
131
|
+
className: "text-sm text-text-secondary",
|
|
132
|
+
children: y("botlit.kb.migration.oneAtATime", "A migration is already in progress. Finish or discard it before starting another.")
|
|
133
|
+
}) : /* @__PURE__ */ g("div", {
|
|
134
|
+
className: "flex flex-wrap items-end gap-3",
|
|
135
|
+
children: [/* @__PURE__ */ g("label", {
|
|
136
|
+
className: "grid gap-2 text-sm",
|
|
137
|
+
children: [y("botlit.kb.migration.target", "Move to"), /* @__PURE__ */ h("select", {
|
|
138
|
+
className: v,
|
|
139
|
+
value: I,
|
|
140
|
+
onChange: (e) => j(e.target.value),
|
|
141
|
+
children: F.map((e) => /* @__PURE__ */ h("option", {
|
|
142
|
+
value: e,
|
|
143
|
+
children: S(e)
|
|
144
|
+
}, e))
|
|
145
|
+
})]
|
|
146
|
+
}), /* @__PURE__ */ h(p, {
|
|
147
|
+
isLoading: D.isPending,
|
|
148
|
+
onClick: () => void B(),
|
|
149
|
+
children: y("botlit.kb.migration.begin", "Start copy")
|
|
150
|
+
})]
|
|
151
|
+
}),
|
|
152
|
+
M && /* @__PURE__ */ h("p", {
|
|
153
|
+
role: M.tone === "error" ? "alert" : "status",
|
|
154
|
+
className: M.tone === "error" ? "text-sm text-status-error-text" : "text-sm",
|
|
155
|
+
children: M.text
|
|
156
|
+
}),
|
|
157
|
+
E.isError ? /* @__PURE__ */ h("p", {
|
|
158
|
+
role: "alert",
|
|
159
|
+
className: "text-sm text-status-error-text",
|
|
160
|
+
children: y("botlit.kb.migration.listError", "Migration history could not be loaded.")
|
|
161
|
+
}) : L.length > 0 ? /* @__PURE__ */ h("ul", {
|
|
162
|
+
className: "divide-y divide-border-subtle rounded-md border border-border-subtle",
|
|
163
|
+
children: L.map((e) => {
|
|
164
|
+
let t = C(e.copiedVectors, e.expectedVectors);
|
|
165
|
+
return /* @__PURE__ */ g("li", {
|
|
166
|
+
className: "space-y-2 p-3 text-sm",
|
|
167
|
+
children: [
|
|
168
|
+
/* @__PURE__ */ g("div", {
|
|
169
|
+
className: "flex flex-wrap items-center justify-between gap-2",
|
|
170
|
+
children: [/* @__PURE__ */ g("span", {
|
|
171
|
+
className: "font-medium",
|
|
172
|
+
children: [
|
|
173
|
+
S(e.sourceDriver),
|
|
174
|
+
" → ",
|
|
175
|
+
S(e.targetDriver)
|
|
176
|
+
]
|
|
177
|
+
}), /* @__PURE__ */ h("span", {
|
|
178
|
+
className: x[e.status] ?? "text-text-secondary",
|
|
179
|
+
children: y(`botlit.kb.migration.status.${e.status.toLowerCase()}`, b[e.status] ?? e.status)
|
|
180
|
+
})]
|
|
181
|
+
}),
|
|
182
|
+
[
|
|
183
|
+
"READY",
|
|
184
|
+
"COPYING",
|
|
185
|
+
"VERIFIED",
|
|
186
|
+
"BLOCKED"
|
|
187
|
+
].includes(e.status) && /* @__PURE__ */ h("div", {
|
|
188
|
+
role: "progressbar",
|
|
189
|
+
"aria-valuemin": 0,
|
|
190
|
+
"aria-valuemax": 100,
|
|
191
|
+
"aria-valuenow": t,
|
|
192
|
+
"aria-label": y("botlit.kb.migration.progress", "Copy progress"),
|
|
193
|
+
className: "h-2 overflow-hidden rounded-full bg-bg-sunken",
|
|
194
|
+
children: /* @__PURE__ */ h("div", {
|
|
195
|
+
className: "h-full bg-action-primary-bg",
|
|
196
|
+
style: { width: `${t}%` }
|
|
197
|
+
})
|
|
198
|
+
}),
|
|
199
|
+
/* @__PURE__ */ h("p", {
|
|
200
|
+
className: "text-text-secondary",
|
|
201
|
+
children: y("botlit.kb.migration.counts", "{{docs}} of {{expectedDocs}} documents · {{vectors}} of {{expectedVectors}} vectors · updated {{when}}", {
|
|
202
|
+
docs: e.copiedDocuments,
|
|
203
|
+
expectedDocs: e.expectedDocuments,
|
|
204
|
+
vectors: e.copiedVectors,
|
|
205
|
+
expectedVectors: e.expectedVectors,
|
|
206
|
+
when: s(e.updatedAt)
|
|
207
|
+
})
|
|
208
|
+
}),
|
|
209
|
+
(e.failureCount > 0 || e.errorCode) && /* @__PURE__ */ h("p", {
|
|
210
|
+
className: "text-status-error-text",
|
|
211
|
+
children: y("botlit.kb.migration.failures", "{{count}} failed attempts{{code}}", {
|
|
212
|
+
count: e.failureCount,
|
|
213
|
+
code: e.errorCode ? ` · ${e.errorCode}` : ""
|
|
214
|
+
})
|
|
215
|
+
}),
|
|
216
|
+
/* @__PURE__ */ g("div", {
|
|
217
|
+
className: "flex flex-wrap gap-2",
|
|
218
|
+
children: [e.status === "VERIFIED" && /* @__PURE__ */ h(p, {
|
|
219
|
+
size: "sm",
|
|
220
|
+
isLoading: O.isPending,
|
|
221
|
+
onClick: () => void V(e),
|
|
222
|
+
children: y("botlit.kb.migration.cutover", "Cut over")
|
|
223
|
+
}), n.includes(e.status) && /* @__PURE__ */ h(p, {
|
|
224
|
+
size: "sm",
|
|
225
|
+
variant: "outline",
|
|
226
|
+
isLoading: k.isPending,
|
|
227
|
+
onClick: () => void H(e),
|
|
228
|
+
children: y("botlit.kb.migration.discard", "Discard copy")
|
|
229
|
+
})]
|
|
230
|
+
})
|
|
231
|
+
]
|
|
232
|
+
}, e.id);
|
|
233
|
+
})
|
|
234
|
+
}) : null
|
|
235
|
+
]
|
|
236
|
+
})] });
|
|
237
|
+
}
|
|
238
|
+
export { w as KnowledgeBackendMigrationPanel };
|
|
239
|
+
|
|
240
|
+
//# sourceMappingURL=KnowledgeBackendMigrationPanel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KnowledgeBackendMigrationPanel.js","names":["FIELD_CLASS","DRIVER_LABEL","STATUS_LABEL","STATUS_TONE","driverLabel","driver","percent","total","done","KnowledgeBackendMigrationPanel","useBotlit","ScopedMigrationPanel","workspaceId","currentUser","knowledgeBaseId","t","useTr","backend","useKnowledgeBaseBackend","useKnowledgeBackendMigrations","target","setTarget","useState","message","setMessage","current","choices","targets","selected","rows","migrations","active","row","fail","graphqlErrorMessage","error","fallback","start","confirmAction","begin","cut","cutover","drop","discard","Card","CardHeader","CardTitle","ArrowRightLeft","CardDescription","CardContent","event","Button","progress","formatRelativeTime","MIGRATION_DISCARDABLE_STATUSES"],"sources":["../../../src/botlit/components/KnowledgeBackendMigrationPanel.tsx"],"sourcesContent":["/**\n * Vector backend migration (BOFF-15360): move a knowledge base to another\n * vector backend. The copy is made inactive and verified against a\n * fingerprint of the source; only an explicit cutover changes live retrieval.\n */\nimport { useState } from 'react';\nimport { ArrowRightLeft } from 'lucide-react';\nimport { useTr } from '../../shared/hooks/useTr';\nimport { useBotlit } from '../providers/BotlitProvider';\nimport {\n MIGRATION_DISCARDABLE_STATUSES,\n useKnowledgeBackendMigrations,\n useKnowledgeBaseBackend,\n type KnowledgeBackendMigration,\n} from '../hooks/useKnowledgeCuratorTools';\nimport { confirmAction } from '../utils/confirmAction';\nimport { graphqlErrorMessage } from '../utils/errors';\nimport { formatRelativeTime } from '../utils/formatters';\nimport { Card, CardContent, CardDescription, CardHeader, CardTitle } from './Card';\nimport { Button } from './Button';\n\nconst FIELD_CLASS =\n 'h-10 rounded-md border border-border-default bg-bg-surface px-3 text-sm text-text-primary';\n\nconst DRIVER_LABEL: Record<string, string> = {\n opensearch: 'OpenSearch',\n postgres: 'PostgreSQL',\n milvus: 'Milvus',\n};\n\nconst STATUS_LABEL: Record<string, string> = {\n READY: 'Queued',\n COPYING: 'Copying',\n VERIFIED: 'Verified, ready for cutover',\n BLOCKED: 'Blocked',\n COMPLETED: 'Completed',\n CANCELLED: 'Discarded',\n};\n\nconst STATUS_TONE: Record<string, string> = {\n VERIFIED: 'text-status-success-text',\n COMPLETED: 'text-status-success-text',\n BLOCKED: 'text-status-error-text',\n CANCELLED: 'text-text-secondary',\n};\n\nfunction driverLabel(driver: string | null | undefined): string {\n if (!driver) return '—';\n return DRIVER_LABEL[driver] ?? driver;\n}\n\nfunction percent(done: number, total: number): number {\n if (total <= 0) return 100;\n return Math.min(100, Math.round((done / total) * 100));\n}\n\nexport function KnowledgeBackendMigrationPanel({ knowledgeBaseId }: { knowledgeBaseId: string }) {\n const { workspaceId, currentUser } = useBotlit();\n return (\n <ScopedMigrationPanel\n key={`${workspaceId}:${currentUser?.id}:${knowledgeBaseId}`}\n knowledgeBaseId={knowledgeBaseId}\n />\n );\n}\n\nfunction ScopedMigrationPanel({ knowledgeBaseId }: { knowledgeBaseId: string }) {\n const t = useTr();\n const backend = useKnowledgeBaseBackend(knowledgeBaseId);\n const { targets, migrations, begin, cutover, discard } =\n useKnowledgeBackendMigrations(knowledgeBaseId);\n const [target, setTarget] = useState('');\n const [message, setMessage] = useState<{ tone: 'info' | 'error'; text: string } | null>(null);\n\n const current = backend.data?.vectorStoreDriver ?? null;\n const choices = (targets.data ?? []).filter((driver) => driver !== current);\n const selected = choices.includes(target) ? target : (choices[0] ?? '');\n const rows = migrations.data ?? [];\n const active = rows.find((row) => ['READY', 'COPYING', 'VERIFIED'].includes(row.status));\n\n const fail = (error: unknown, fallback: string) =>\n setMessage({ tone: 'error', text: graphqlErrorMessage(error, fallback) });\n\n const start = async () => {\n if (!selected) return;\n const ok = await confirmAction({\n title: t('botlit.kb.migration.beginTitle', 'Copy to {{target}}?', {\n target: driverLabel(selected),\n }),\n message: t(\n 'botlit.kb.migration.beginMessage',\n 'A verified copy is built in {{target}} while agents keep using {{current}}. Nothing changes for agents until you cut over. Document changes are refused at cutover if the source changed.',\n { target: driverLabel(selected), current: driverLabel(current) }\n ),\n confirmLabel: t('botlit.kb.migration.beginConfirm', 'Start copy'),\n cancelLabel: t('botlit.common.cancel', 'Cancel'),\n });\n if (!ok) return;\n setMessage(null);\n try {\n await begin.mutateAsync(selected);\n setMessage({\n tone: 'info',\n text: t(\n 'botlit.kb.migration.started',\n 'Copy queued. Its progress appears below and refreshes by itself.'\n ),\n });\n } catch (error) {\n fail(\n error,\n t(\n 'botlit.kb.migration.beginFailed',\n 'The copy could not start. Every document must be indexed and published first.'\n )\n );\n }\n };\n\n const cut = async (row: KnowledgeBackendMigration) => {\n const ok = await confirmAction({\n title: t('botlit.kb.migration.cutoverTitle', 'Switch live retrieval to {{target}}?', {\n target: driverLabel(row.targetDriver),\n }),\n message: t(\n 'botlit.kb.migration.cutoverMessage',\n 'Agents start reading this knowledge base from {{target}} immediately. The {{source}} copy is kept until it is retired.',\n { target: driverLabel(row.targetDriver), source: driverLabel(row.sourceDriver) }\n ),\n confirmLabel: t('botlit.kb.migration.cutoverConfirm', 'Cut over'),\n cancelLabel: t('botlit.common.cancel', 'Cancel'),\n });\n if (!ok) return;\n setMessage(null);\n try {\n await cutover.mutateAsync(row.id);\n setMessage({\n tone: 'info',\n text: t('botlit.kb.migration.cutoverDone', 'Live retrieval now uses {{target}}.', {\n target: driverLabel(row.targetDriver),\n }),\n });\n } catch (error) {\n fail(\n error,\n t(\n 'botlit.kb.migration.cutoverFailed',\n 'Cutover was refused. The source changed or the copy no longer verifies; discard it and start again.'\n )\n );\n }\n };\n\n const drop = async (row: KnowledgeBackendMigration) => {\n const ok = await confirmAction({\n title: t('botlit.kb.migration.discardTitle', 'Discard this copy?'),\n message: t(\n 'botlit.kb.migration.discardMessage',\n 'The inactive {{target}} copy is retired. Live retrieval is not affected.',\n { target: driverLabel(row.targetDriver) }\n ),\n confirmLabel: t('botlit.kb.migration.discardConfirm', 'Discard'),\n cancelLabel: t('botlit.common.cancel', 'Cancel'),\n });\n if (!ok) return;\n setMessage(null);\n try {\n await discard.mutateAsync(row.id);\n setMessage({\n tone: 'info',\n text: t('botlit.kb.migration.discarded', 'Copy discarded.'),\n });\n } catch (error) {\n fail(error, t('botlit.kb.migration.discardFailed', 'The copy could not be discarded.'));\n }\n };\n\n return (\n <Card>\n <CardHeader>\n <CardTitle className=\"flex items-center gap-2\">\n <ArrowRightLeft size={18} aria-hidden=\"true\" />\n {t('botlit.kb.migration.title', 'Vector backend')}\n </CardTitle>\n <CardDescription>\n {t(\n 'botlit.kb.migration.help',\n 'Move this knowledge base to another vector backend: copy, verify, then cut over. It is never switched silently.'\n )}\n </CardDescription>\n </CardHeader>\n <CardContent className=\"space-y-4\">\n <p className=\"text-sm\">\n {t('botlit.kb.migration.current', 'Live backend: {{driver}}', {\n driver: backend.isPending ? '…' : driverLabel(current),\n })}\n </p>\n\n {targets.isError ? (\n <p role=\"alert\" className=\"text-sm text-status-error-text\">\n {t(\n 'botlit.kb.migration.targetsError',\n 'Migration options could not be loaded. Knowledge management permission is required.'\n )}\n </p>\n ) : targets.isPending ? (\n <p role=\"status\" className=\"text-sm text-text-secondary\">\n {t('botlit.kb.migration.loading', 'Loading migration options…')}\n </p>\n ) : choices.length === 0 ? (\n <p className=\"text-sm text-text-secondary\">\n {t(\n 'botlit.kb.migration.noTargets',\n 'No other vector backend is enabled for migration in this environment.'\n )}\n </p>\n ) : active ? (\n <p className=\"text-sm text-text-secondary\">\n {t(\n 'botlit.kb.migration.oneAtATime',\n 'A migration is already in progress. Finish or discard it before starting another.'\n )}\n </p>\n ) : (\n <div className=\"flex flex-wrap items-end gap-3\">\n <label className=\"grid gap-2 text-sm\">\n {t('botlit.kb.migration.target', 'Move to')}\n <select\n className={FIELD_CLASS}\n value={selected}\n onChange={(event) => setTarget(event.target.value)}\n >\n {choices.map((driver) => (\n <option key={driver} value={driver}>\n {driverLabel(driver)}\n </option>\n ))}\n </select>\n </label>\n <Button isLoading={begin.isPending} onClick={() => void start()}>\n {t('botlit.kb.migration.begin', 'Start copy')}\n </Button>\n </div>\n )}\n\n {message && (\n <p\n role={message.tone === 'error' ? 'alert' : 'status'}\n className={message.tone === 'error' ? 'text-sm text-status-error-text' : 'text-sm'}\n >\n {message.text}\n </p>\n )}\n\n {migrations.isError ? (\n <p role=\"alert\" className=\"text-sm text-status-error-text\">\n {t('botlit.kb.migration.listError', 'Migration history could not be loaded.')}\n </p>\n ) : rows.length > 0 ? (\n <ul className=\"divide-y divide-border-subtle rounded-md border border-border-subtle\">\n {rows.map((row) => {\n const progress = percent(row.copiedVectors, row.expectedVectors);\n return (\n <li key={row.id} className=\"space-y-2 p-3 text-sm\">\n <div className=\"flex flex-wrap items-center justify-between gap-2\">\n <span className=\"font-medium\">\n {driverLabel(row.sourceDriver)} → {driverLabel(row.targetDriver)}\n </span>\n <span className={STATUS_TONE[row.status] ?? 'text-text-secondary'}>\n {t(\n `botlit.kb.migration.status.${row.status.toLowerCase()}`,\n STATUS_LABEL[row.status] ?? row.status\n )}\n </span>\n </div>\n {['READY', 'COPYING', 'VERIFIED', 'BLOCKED'].includes(row.status) && (\n <div\n role=\"progressbar\"\n aria-valuemin={0}\n aria-valuemax={100}\n aria-valuenow={progress}\n aria-label={t('botlit.kb.migration.progress', 'Copy progress')}\n className=\"h-2 overflow-hidden rounded-full bg-bg-sunken\"\n >\n <div\n className=\"h-full bg-action-primary-bg\"\n style={{ width: `${progress}%` }}\n />\n </div>\n )}\n <p className=\"text-text-secondary\">\n {t(\n 'botlit.kb.migration.counts',\n '{{docs}} of {{expectedDocs}} documents · {{vectors}} of {{expectedVectors}} vectors · updated {{when}}',\n {\n docs: row.copiedDocuments,\n expectedDocs: row.expectedDocuments,\n vectors: row.copiedVectors,\n expectedVectors: row.expectedVectors,\n when: formatRelativeTime(row.updatedAt),\n }\n )}\n </p>\n {(row.failureCount > 0 || row.errorCode) && (\n <p className=\"text-status-error-text\">\n {t('botlit.kb.migration.failures', '{{count}} failed attempts{{code}}', {\n count: row.failureCount,\n code: row.errorCode ? ` · ${row.errorCode}` : '',\n })}\n </p>\n )}\n <div className=\"flex flex-wrap gap-2\">\n {row.status === 'VERIFIED' && (\n <Button size=\"sm\" isLoading={cutover.isPending} onClick={() => void cut(row)}>\n {t('botlit.kb.migration.cutover', 'Cut over')}\n </Button>\n )}\n {MIGRATION_DISCARDABLE_STATUSES.includes(row.status) && (\n <Button\n size=\"sm\"\n variant=\"outline\"\n isLoading={discard.isPending}\n onClick={() => void drop(row)}\n >\n {t('botlit.kb.migration.discard', 'Discard copy')}\n </Button>\n )}\n </div>\n </li>\n );\n })}\n </ul>\n ) : null}\n </CardContent>\n </Card>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAqBA,IAAMA,IACJ,6FAEIC,IAAuC;CAC3C,YAAY;CACZ,UAAU;CACV,QAAQ;AACV,GAEMC,IAAuC;CAC3C,OAAO;CACP,SAAS;CACT,UAAU;CACV,SAAS;CACT,WAAW;CACX,WAAW;AACb,GAEMC,IAAsC;CAC1C,UAAU;CACV,WAAW;CACX,SAAS;CACT,WAAW;AACb;AAEA,SAASC,EAAY,GAA2C;CAE9D,OADKC,IACEJ,EAAaI,MAAWA,IADX;AAEtB;AAEA,SAASC,EAAQ,GAAc,GAAuB;CAEp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,EAAI;SACV,cAAcA,EAAI;SAClB,SAASA,EAAI;SACb,iBAAiBA,EAAI;SACrB,MAAMqB,EAAmBrB,EAAI,SAAS;QACxC,CACF;OACC,CAAA;QACDA,EAAI,eAAe,KAAKA,EAAI,cAC5B,kBAAC,KAAD;QAAG,WAAU;QACV,UAAAjB,EAAE,gCAAgC,qCAAqC;SACtE,OAAOiB,EAAI;SACX,MAAMA,EAAI,YAAY,MAAMA,EAAI,cAAc;QAChD,CAAC;OACA,CAAA;OAEL,kBAAC,OAAD;QAAK,WAAU;QAAf,UAAA,CACGA,EAAI,WAAW,cACd,kBAACmB,GAAD;SAAQ,MAAK;SAAK,WAAWV,EAAQ;SAAW,eAAe,KAAKD,EAAIR,CAAG;SACxE,UAAAjB,EAAE,+BAA+B,UAAU;QACtC,CAAA,GAETuC,EAA+B,SAAStB,EAAI,MAAM,KACjD,kBAACmB,GAAD;SACE,MAAK;SACL,SAAQ;SACR,WAAWR,EAAQ;SACnB,eAAe,KAAKD,EAAKV,CAAG;SAE3B,UAAAjB,EAAE,+BAA+B,cAAc;QAC1C,CAAA,CAEP;;MACH;KAjEK,GAAAiB,EAAI,EAiET;IAER,CAAC;GACC,CAAA,IACF;EACO;CACT,CAAA,CAAA,EAAA,CAAA;AAEV"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The service limit is 256 KiB; keep the same headroom as the text import. */
|
|
2
|
+
export declare const MAX_DOCUMENT_BYTES = 245760;
|
|
3
|
+
export declare const MAX_DOCUMENTS_PER_UPLOAD = 10;
|
|
4
|
+
export declare const ACCEPTED_EXTENSIONS: string[];
|
|
5
|
+
/** Why a picked file cannot be uploaded, or null when it can. */
|
|
6
|
+
export declare function documentRejection(file: {
|
|
7
|
+
name: string;
|
|
8
|
+
size: number;
|
|
9
|
+
}): string | null;
|
|
10
|
+
/** The document title: the file name without its extension, within the title limit. */
|
|
11
|
+
export declare function documentTitle(fileName: string): string;
|
|
12
|
+
export declare function KnowledgeDocumentUploadPanel({ knowledgeBaseId }: {
|
|
13
|
+
knowledgeBaseId: string;
|
|
14
|
+
}): import('react').JSX.Element;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { useTr as e } from "../../shared/hooks/useTr.js";
|
|
2
|
+
import { useBotlit as t } from "../providers/BotlitProvider.js";
|
|
3
|
+
import { useKnowledgeSourceImports as n } from "../hooks/useKnowledgeSourceImports.js";
|
|
4
|
+
import { graphqlErrorMessage as r } from "../utils/errors.js";
|
|
5
|
+
import { Card as i, CardContent as a, CardDescription as o, CardHeader as s, CardTitle as c } from "./Card.js";
|
|
6
|
+
import { Button as l } from "./Button.js";
|
|
7
|
+
import { useRef as u, useState as d } from "react";
|
|
8
|
+
import { jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
9
|
+
import { Upload as m } from "lucide-react";
|
|
10
|
+
// src/botlit/components/KnowledgeDocumentUploadPanel.tsx
|
|
11
|
+
var h = 245760, g = [
|
|
12
|
+
".txt",
|
|
13
|
+
".md",
|
|
14
|
+
".markdown",
|
|
15
|
+
".csv",
|
|
16
|
+
".json"
|
|
17
|
+
], _ = 255;
|
|
18
|
+
function v(e) {
|
|
19
|
+
let t = e.name.toLowerCase();
|
|
20
|
+
return g.some((e) => t.endsWith(e)) ? e.size === 0 ? "The file is empty." : e.size > 245760 ? "The file is larger than 240 KiB. Split it first." : null : "Only text documents (.txt, .md, .csv, .json) can be uploaded.";
|
|
21
|
+
}
|
|
22
|
+
function y(e) {
|
|
23
|
+
let t = e.lastIndexOf(".");
|
|
24
|
+
return ((t > 0 ? e.slice(0, t) : e).trim() || e).slice(0, _);
|
|
25
|
+
}
|
|
26
|
+
function b({ knowledgeBaseId: e }) {
|
|
27
|
+
let { workspaceId: n, currentUser: r } = t();
|
|
28
|
+
return /* @__PURE__ */ f(x, { knowledgeBaseId: e }, `${n}:${r?.id}:${e}`);
|
|
29
|
+
}
|
|
30
|
+
function x({ knowledgeBaseId: t }) {
|
|
31
|
+
let h = e(), _ = n(t), b = u(null), [x, S] = d([]), [C, w] = d([]), [T, E] = d(!1), D = u(/* @__PURE__ */ new Map()), O = async () => {
|
|
32
|
+
E(!0);
|
|
33
|
+
let e = [];
|
|
34
|
+
for (let t of x) {
|
|
35
|
+
let n = v(t);
|
|
36
|
+
if (n) {
|
|
37
|
+
e.push({
|
|
38
|
+
name: t.name,
|
|
39
|
+
ok: !1,
|
|
40
|
+
detail: n
|
|
41
|
+
});
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
let i;
|
|
45
|
+
try {
|
|
46
|
+
i = new TextDecoder("utf-8", { fatal: !0 }).decode(await t.arrayBuffer());
|
|
47
|
+
} catch {
|
|
48
|
+
e.push({
|
|
49
|
+
name: t.name,
|
|
50
|
+
ok: !1,
|
|
51
|
+
detail: h("botlit.kb.upload.notText", "The file is not UTF-8 text.")
|
|
52
|
+
});
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
let a = D.current.get(t);
|
|
56
|
+
a || (a = crypto.randomUUID(), D.current.set(t, a));
|
|
57
|
+
try {
|
|
58
|
+
await _.queue.mutateAsync({
|
|
59
|
+
clientRequestId: a,
|
|
60
|
+
title: y(t.name),
|
|
61
|
+
content: i
|
|
62
|
+
}), D.current.delete(t), e.push({
|
|
63
|
+
name: t.name,
|
|
64
|
+
ok: !0,
|
|
65
|
+
detail: h("botlit.kb.upload.queued", "Queued for import")
|
|
66
|
+
});
|
|
67
|
+
} catch (n) {
|
|
68
|
+
e.push({
|
|
69
|
+
name: t.name,
|
|
70
|
+
ok: !1,
|
|
71
|
+
detail: r(n, h("botlit.kb.upload.failed", "Not queued. Upload the same file again to retry safely."))
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
w(e);
|
|
76
|
+
let t = new Set(e.filter((e) => !e.ok).map((e) => e.name));
|
|
77
|
+
S((e) => e.filter((e) => t.has(e.name))), b.current && t.size === 0 && (b.current.value = ""), E(!1);
|
|
78
|
+
};
|
|
79
|
+
return /* @__PURE__ */ p(i, { children: [/* @__PURE__ */ p(s, { children: [/* @__PURE__ */ p(c, {
|
|
80
|
+
className: "flex items-center gap-2",
|
|
81
|
+
children: [/* @__PURE__ */ f(m, {
|
|
82
|
+
size: 18,
|
|
83
|
+
"aria-hidden": "true"
|
|
84
|
+
}), h("botlit.kb.upload.title", "Upload documents")]
|
|
85
|
+
}), /* @__PURE__ */ f(o, { children: h("botlit.kb.upload.help", "Text, Markdown, CSV or JSON files up to 240 KiB each, {{max}} at a time. Each file is imported, verified and published like pasted text; its progress appears with the imports.", { max: 10 }) })] }), /* @__PURE__ */ p(a, {
|
|
86
|
+
className: "space-y-4",
|
|
87
|
+
children: [
|
|
88
|
+
/* @__PURE__ */ p("label", {
|
|
89
|
+
className: "grid gap-2 text-sm",
|
|
90
|
+
children: [h("botlit.kb.upload.pick", "Documents"), /* @__PURE__ */ f("input", {
|
|
91
|
+
ref: b,
|
|
92
|
+
type: "file",
|
|
93
|
+
multiple: !0,
|
|
94
|
+
accept: g.join(","),
|
|
95
|
+
disabled: T,
|
|
96
|
+
className: "text-sm text-text-primary",
|
|
97
|
+
onChange: (e) => {
|
|
98
|
+
let t = Array.from(e.target.files ?? []);
|
|
99
|
+
w([]), D.current = /* @__PURE__ */ new Map(), S(t.slice(0, 10));
|
|
100
|
+
}
|
|
101
|
+
})]
|
|
102
|
+
}),
|
|
103
|
+
x.length > 0 && /* @__PURE__ */ f("ul", {
|
|
104
|
+
className: "space-y-1 text-sm",
|
|
105
|
+
children: x.map((e) => {
|
|
106
|
+
let t = v(e);
|
|
107
|
+
return /* @__PURE__ */ p("li", {
|
|
108
|
+
className: "flex justify-between gap-3",
|
|
109
|
+
children: [/* @__PURE__ */ f("span", {
|
|
110
|
+
className: "truncate",
|
|
111
|
+
children: e.name
|
|
112
|
+
}), /* @__PURE__ */ f("span", {
|
|
113
|
+
className: t ? "text-status-error-text" : "text-text-secondary",
|
|
114
|
+
children: t ?? `${Math.ceil(e.size / 1024)} KiB`
|
|
115
|
+
})]
|
|
116
|
+
}, `${e.name}:${e.size}`);
|
|
117
|
+
})
|
|
118
|
+
}),
|
|
119
|
+
/* @__PURE__ */ f(l, {
|
|
120
|
+
disabled: T || !x.some((e) => v(e) === null),
|
|
121
|
+
isLoading: T,
|
|
122
|
+
onClick: () => void O(),
|
|
123
|
+
children: h("botlit.kb.upload.submit", "Upload")
|
|
124
|
+
}),
|
|
125
|
+
C.length > 0 && /* @__PURE__ */ f("ul", {
|
|
126
|
+
role: "status",
|
|
127
|
+
className: "space-y-1 text-sm",
|
|
128
|
+
children: C.map((e) => /* @__PURE__ */ p("li", {
|
|
129
|
+
className: e.ok ? "text-status-success-text" : "text-status-error-text",
|
|
130
|
+
children: [
|
|
131
|
+
e.name,
|
|
132
|
+
": ",
|
|
133
|
+
e.detail
|
|
134
|
+
]
|
|
135
|
+
}, e.name))
|
|
136
|
+
})
|
|
137
|
+
]
|
|
138
|
+
})] });
|
|
139
|
+
}
|
|
140
|
+
export { g as ACCEPTED_EXTENSIONS, b as KnowledgeDocumentUploadPanel, h as MAX_DOCUMENT_BYTES, v as documentRejection, y as documentTitle };
|
|
141
|
+
|
|
142
|
+
//# sourceMappingURL=KnowledgeDocumentUploadPanel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KnowledgeDocumentUploadPanel.js","names":["MAX_DOCUMENT_BYTES","ACCEPTED_EXTENSIONS","TITLE_MAX_LENGTH","documentRejection","lower","file","extension","documentTitle","dot","fileName","KnowledgeDocumentUploadPanel","useBotlit","ScopedUploadPanel","workspaceId","currentUser","knowledgeBaseId","t","useTr","sources","useKnowledgeSourceImports","input","useRef","files","setFiles","useState","outcomes","setOutcomes","uploading","setUploading","requestIds","upload","results","rejection","content","requestId","error","graphqlErrorMessage","failed","row","current","Card","CardHeader","CardTitle","Upload","CardDescription","CardContent","picked","event","Button"],"sources":["../../../src/botlit/components/KnowledgeDocumentUploadPanel.tsx"],"sourcesContent":["/**\n * Document upload (BOFF-15360): pick text documents from disk and queue each\n * one through the managed knowledge import, the same path as pasted text, so\n * it is captured, verified and published before agents can retrieve it.\n *\n * Only UTF-8 text formats are accepted here. Binary documents (PDF, Word)\n * need server-side text extraction and are not offered.\n */\nimport { useRef, useState } from 'react';\nimport { Upload } from 'lucide-react';\nimport { useTr } from '../../shared/hooks/useTr';\nimport { useBotlit } from '../providers/BotlitProvider';\nimport { useKnowledgeSourceImports } from '../hooks/useKnowledgeSourceImports';\nimport { graphqlErrorMessage } from '../utils/errors';\nimport { Card, CardContent, CardDescription, CardHeader, CardTitle } from './Card';\nimport { Button } from './Button';\n\n/** The service limit is 256 KiB; keep the same headroom as the text import. */\nexport const MAX_DOCUMENT_BYTES = 245760;\nexport const MAX_DOCUMENTS_PER_UPLOAD = 10;\nexport const ACCEPTED_EXTENSIONS = ['.txt', '.md', '.markdown', '.csv', '.json'];\nconst TITLE_MAX_LENGTH = 255;\n\ninterface FileOutcome {\n name: string;\n ok: boolean;\n detail: string;\n}\n\n/** Why a picked file cannot be uploaded, or null when it can. */\nexport function documentRejection(file: { name: string; size: number }): string | null {\n const lower = file.name.toLowerCase();\n if (!ACCEPTED_EXTENSIONS.some((extension) => lower.endsWith(extension)))\n return 'Only text documents (.txt, .md, .csv, .json) can be uploaded.';\n if (file.size === 0) return 'The file is empty.';\n if (file.size > MAX_DOCUMENT_BYTES) return 'The file is larger than 240 KiB. Split it first.';\n return null;\n}\n\n/** The document title: the file name without its extension, within the title limit. */\nexport function documentTitle(fileName: string): string {\n const dot = fileName.lastIndexOf('.');\n const base = (dot > 0 ? fileName.slice(0, dot) : fileName).trim() || fileName;\n return base.slice(0, TITLE_MAX_LENGTH);\n}\n\nexport function KnowledgeDocumentUploadPanel({ knowledgeBaseId }: { knowledgeBaseId: string }) {\n const { workspaceId, currentUser } = useBotlit();\n return (\n <ScopedUploadPanel\n key={`${workspaceId}:${currentUser?.id}:${knowledgeBaseId}`}\n knowledgeBaseId={knowledgeBaseId}\n />\n );\n}\n\nfunction ScopedUploadPanel({ knowledgeBaseId }: { knowledgeBaseId: string }) {\n const t = useTr();\n const sources = useKnowledgeSourceImports(knowledgeBaseId);\n const input = useRef<HTMLInputElement>(null);\n const [files, setFiles] = useState<File[]>([]);\n const [outcomes, setOutcomes] = useState<FileOutcome[]>([]);\n const [uploading, setUploading] = useState(false);\n // One request id per file selection, so retrying the same files is idempotent.\n const requestIds = useRef(new Map<File, string>());\n\n const upload = async () => {\n setUploading(true);\n const results: FileOutcome[] = [];\n for (const file of files) {\n const rejection = documentRejection(file);\n if (rejection) {\n results.push({ name: file.name, ok: false, detail: rejection });\n continue;\n }\n let content: string;\n try {\n // fatal: true refuses a file that is not valid UTF-8 instead of indexing garbage.\n content = new TextDecoder('utf-8', { fatal: true }).decode(await file.arrayBuffer());\n } catch {\n results.push({\n name: file.name,\n ok: false,\n detail: t('botlit.kb.upload.notText', 'The file is not UTF-8 text.'),\n });\n continue;\n }\n let requestId = requestIds.current.get(file);\n if (!requestId) {\n requestId = crypto.randomUUID();\n requestIds.current.set(file, requestId);\n }\n try {\n await sources.queue.mutateAsync({\n clientRequestId: requestId,\n title: documentTitle(file.name),\n content,\n });\n requestIds.current.delete(file);\n results.push({\n name: file.name,\n ok: true,\n detail: t('botlit.kb.upload.queued', 'Queued for import'),\n });\n } catch (error) {\n results.push({\n name: file.name,\n ok: false,\n detail: graphqlErrorMessage(\n error,\n t('botlit.kb.upload.failed', 'Not queued. Upload the same file again to retry safely.')\n ),\n });\n }\n }\n setOutcomes(results);\n const failed = new Set(results.filter((row) => !row.ok).map((row) => row.name));\n setFiles((current) => current.filter((file) => failed.has(file.name)));\n if (input.current && failed.size === 0) input.current.value = '';\n setUploading(false);\n };\n\n return (\n <Card>\n <CardHeader>\n <CardTitle className=\"flex items-center gap-2\">\n <Upload size={18} aria-hidden=\"true\" />\n {t('botlit.kb.upload.title', 'Upload documents')}\n </CardTitle>\n <CardDescription>\n {t(\n 'botlit.kb.upload.help',\n 'Text, Markdown, CSV or JSON files up to 240 KiB each, {{max}} at a time. Each file is imported, verified and published like pasted text; its progress appears with the imports.',\n { max: MAX_DOCUMENTS_PER_UPLOAD }\n )}\n </CardDescription>\n </CardHeader>\n <CardContent className=\"space-y-4\">\n <label className=\"grid gap-2 text-sm\">\n {t('botlit.kb.upload.pick', 'Documents')}\n <input\n ref={input}\n type=\"file\"\n multiple\n accept={ACCEPTED_EXTENSIONS.join(',')}\n disabled={uploading}\n className=\"text-sm text-text-primary\"\n onChange={(event) => {\n const picked = Array.from(event.target.files ?? []);\n setOutcomes([]);\n requestIds.current = new Map();\n setFiles(picked.slice(0, MAX_DOCUMENTS_PER_UPLOAD));\n }}\n />\n </label>\n {files.length > 0 && (\n <ul className=\"space-y-1 text-sm\">\n {files.map((file) => {\n const rejection = documentRejection(file);\n return (\n <li key={`${file.name}:${file.size}`} className=\"flex justify-between gap-3\">\n <span className=\"truncate\">{file.name}</span>\n <span className={rejection ? 'text-status-error-text' : 'text-text-secondary'}>\n {rejection ?? `${Math.ceil(file.size / 1024)} KiB`}\n </span>\n </li>\n );\n })}\n </ul>\n )}\n <Button\n disabled={uploading || !files.some((file) => documentRejection(file) === null)}\n isLoading={uploading}\n onClick={() => void upload()}\n >\n {t('botlit.kb.upload.submit', 'Upload')}\n </Button>\n {outcomes.length > 0 && (\n <ul role=\"status\" className=\"space-y-1 text-sm\">\n {outcomes.map((row) => (\n <li\n key={row.name}\n className={row.ok ? 'text-status-success-text' : 'text-status-error-text'}\n >\n {row.name}: {row.detail}\n </li>\n ))}\n </ul>\n )}\n </CardContent>\n </Card>\n );\n}\n"],"mappings":";;;;;;;;;;AAkBA,IAAaA,IAAqB,QAErBC,IAAsB;CAAC;CAAQ;CAAO;CAAa;CAAQ;AAAO,GACzEC,IAAmB;AASzB,SAAgBC,EAAkB,GAAqD;CACrF,IAAMC,IAAQC,EAAK,KAAK,YAAY;CAKpC,OAJKJ,EAAoB,MAAM,MAAcG,EAAM,SAASE,CAAS,CAAC,IAElED,EAAK,SAAS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0 +1,10 @@
|
|
|
1
|
+
export interface RetrievalTestDocument {
|
|
2
|
+
id: string;
|
|
3
|
+
title: string;
|
|
4
|
+
}
|
|
5
|
+
export interface KnowledgeRetrievalTestPanelProps {
|
|
6
|
+
knowledgeBaseId: string;
|
|
7
|
+
/** The knowledge base's documents, to name the source of each passage. */
|
|
8
|
+
documents: RetrievalTestDocument[];
|
|
9
|
+
}
|
|
10
|
+
export declare function KnowledgeRetrievalTestPanel(props: KnowledgeRetrievalTestPanelProps): import('react').JSX.Element;
|