@burdenoff/microfe-botmanor 2026.1120.1 → 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/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 +348 -333
- package/dist/botlit/pages/KnowledgeBaseDetailPage.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,174 @@
|
|
|
1
|
+
import { useTr as e } from "../../shared/hooks/useTr.js";
|
|
2
|
+
import { useBotlit as t } from "../providers/BotlitProvider.js";
|
|
3
|
+
import { useRetrievalProfiles as n } from "../hooks/useRetrievalProfiles.js";
|
|
4
|
+
import { useKnowledgeBaseBackend as r, useKnowledgeRetrievalTest as i } from "../hooks/useKnowledgeCuratorTools.js";
|
|
5
|
+
import { graphqlErrorMessage as a } from "../utils/errors.js";
|
|
6
|
+
import { Card as o, CardContent as s, CardDescription as c, CardHeader as l, CardTitle as u } from "./Card.js";
|
|
7
|
+
import { Button as d } from "./Button.js";
|
|
8
|
+
import { useState as f } from "react";
|
|
9
|
+
import { jsx as p, jsxs as m } from "react/jsx-runtime";
|
|
10
|
+
import { FlaskConical as h } from "lucide-react";
|
|
11
|
+
// src/botlit/components/KnowledgeRetrievalTestPanel.tsx
|
|
12
|
+
var g = "h-10 w-full rounded-md border border-border-default bg-bg-surface px-3 text-sm text-text-primary", _ = 20, v = 2e3, y = ["HYBRID", "BM25_ONLY"], b = {
|
|
13
|
+
VECTOR: "Vector",
|
|
14
|
+
HYBRID: "Hybrid",
|
|
15
|
+
BM25_ONLY: "Keyword"
|
|
16
|
+
};
|
|
17
|
+
function x(e) {
|
|
18
|
+
let { workspaceId: n, currentUser: r } = t();
|
|
19
|
+
return /* @__PURE__ */ p(C, { ...e }, `${n}:${r?.id}:${e.knowledgeBaseId}`);
|
|
20
|
+
}
|
|
21
|
+
function S(e) {
|
|
22
|
+
return e === null || !Number.isFinite(e) ? "—" : e.toFixed(3);
|
|
23
|
+
}
|
|
24
|
+
function C({ knowledgeBaseId: t, documents: x }) {
|
|
25
|
+
let C = e(), w = i(t), T = r(t), E = n(), D = (E.data ?? []).filter((e) => e.status !== "ARCHIVED"), [O, k] = f(""), [A, j] = f(""), [M, N] = f("5"), [P, F] = f(""), I = D.find((e) => e.id === A), L = T.data?.vectorStoreDriver ?? null, R = I !== void 0 && y.includes(I.strategyMode) && L !== null && L !== "opensearch", z = new Map(x.map((e) => [e.id, e.title])), B = Number.parseInt(M, 10), V = Number.isInteger(B) && B >= 1 && B <= _, H = O.trim().length > 0 && (I !== void 0 || V), U = () => {
|
|
26
|
+
if (!H) return;
|
|
27
|
+
let e = O.trim();
|
|
28
|
+
F(e), w.mutate({
|
|
29
|
+
query: e,
|
|
30
|
+
topK: I ? I.topK : B,
|
|
31
|
+
...I ? { retrievalProfileId: I.id } : {}
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
return /* @__PURE__ */ m(o, { children: [/* @__PURE__ */ m(l, { children: [/* @__PURE__ */ m(u, {
|
|
35
|
+
className: "flex items-center gap-2",
|
|
36
|
+
children: [/* @__PURE__ */ p(h, {
|
|
37
|
+
size: 18,
|
|
38
|
+
"aria-hidden": "true"
|
|
39
|
+
}), C("botlit.kb.retrievalTest.title", "Test retrieval")]
|
|
40
|
+
}), /* @__PURE__ */ p(c, { children: C("botlit.kb.retrievalTest.help", "Ask a question and see which passages an agent would be given, best first, before you rely on them.") })] }), /* @__PURE__ */ m(s, {
|
|
41
|
+
className: "space-y-4",
|
|
42
|
+
children: [
|
|
43
|
+
/* @__PURE__ */ m("form", {
|
|
44
|
+
className: "space-y-4",
|
|
45
|
+
onSubmit: (e) => {
|
|
46
|
+
e.preventDefault(), U();
|
|
47
|
+
},
|
|
48
|
+
children: [
|
|
49
|
+
/* @__PURE__ */ m("label", {
|
|
50
|
+
className: "grid gap-2 text-sm",
|
|
51
|
+
children: [C("botlit.kb.retrievalTest.query", "Question"), /* @__PURE__ */ p("textarea", {
|
|
52
|
+
className: "min-h-20 rounded-md border border-border-default bg-bg-surface p-3 text-sm text-text-primary",
|
|
53
|
+
value: O,
|
|
54
|
+
maxLength: v,
|
|
55
|
+
placeholder: C("botlit.kb.retrievalTest.queryPlaceholder", "For example: What is the refund window?"),
|
|
56
|
+
onChange: (e) => k(e.target.value)
|
|
57
|
+
})]
|
|
58
|
+
}),
|
|
59
|
+
/* @__PURE__ */ m("div", {
|
|
60
|
+
className: "grid gap-4 md:grid-cols-2",
|
|
61
|
+
children: [/* @__PURE__ */ m("label", {
|
|
62
|
+
className: "grid gap-2 text-sm",
|
|
63
|
+
children: [C("botlit.kb.retrievalTest.profile", "Retrieval profile"), /* @__PURE__ */ m("select", {
|
|
64
|
+
className: g,
|
|
65
|
+
value: A,
|
|
66
|
+
onChange: (e) => j(e.target.value),
|
|
67
|
+
children: [/* @__PURE__ */ p("option", {
|
|
68
|
+
value: "",
|
|
69
|
+
children: C("botlit.kb.retrievalTest.noProfile", "None: default search")
|
|
70
|
+
}), D.map((e) => /* @__PURE__ */ p("option", {
|
|
71
|
+
value: e.id,
|
|
72
|
+
children: e.name
|
|
73
|
+
}, e.id))]
|
|
74
|
+
})]
|
|
75
|
+
}), I ? /* @__PURE__ */ m("div", {
|
|
76
|
+
className: "grid gap-1 text-sm",
|
|
77
|
+
children: [/* @__PURE__ */ p("span", { children: C("botlit.kb.retrievalTest.applied", "Profile settings") }), /* @__PURE__ */ p("span", {
|
|
78
|
+
className: "text-text-secondary",
|
|
79
|
+
children: C("botlit.kb.retrievalTest.appliedValue", "{{mode}} · top {{topK}} · minimum score {{min}}", {
|
|
80
|
+
mode: b[I.strategyMode] ?? I.strategyMode,
|
|
81
|
+
topK: I.topK,
|
|
82
|
+
min: I.minRelevanceScore === null || I.minRelevanceScore === void 0 ? C("botlit.kb.retrievalTest.noMinimum", "none") : I.minRelevanceScore
|
|
83
|
+
})
|
|
84
|
+
})]
|
|
85
|
+
}) : /* @__PURE__ */ m("label", {
|
|
86
|
+
className: "grid gap-2 text-sm",
|
|
87
|
+
children: [C("botlit.kb.retrievalTest.topK", "Passages to return (1–{{max}})", { max: _ }), /* @__PURE__ */ p("input", {
|
|
88
|
+
className: g,
|
|
89
|
+
type: "number",
|
|
90
|
+
min: 1,
|
|
91
|
+
max: _,
|
|
92
|
+
value: M,
|
|
93
|
+
"aria-invalid": !V,
|
|
94
|
+
onChange: (e) => N(e.target.value)
|
|
95
|
+
})]
|
|
96
|
+
})]
|
|
97
|
+
}),
|
|
98
|
+
E.error && /* @__PURE__ */ p("p", {
|
|
99
|
+
role: "alert",
|
|
100
|
+
className: "text-sm text-status-warning-text",
|
|
101
|
+
children: C("botlit.kb.retrievalTest.profilesError", "Retrieval profiles could not be loaded. You can still run a default search.")
|
|
102
|
+
}),
|
|
103
|
+
R && /* @__PURE__ */ p("p", {
|
|
104
|
+
className: "text-sm text-status-warning-text",
|
|
105
|
+
children: C("botlit.kb.retrievalTest.degraded", "This knowledge base is stored in {{driver}}, which searches by vector only. The profile runs as vector search here, exactly as it does for agents.", { driver: L })
|
|
106
|
+
}),
|
|
107
|
+
/* @__PURE__ */ p(d, {
|
|
108
|
+
type: "submit",
|
|
109
|
+
disabled: !H,
|
|
110
|
+
isLoading: w.isPending,
|
|
111
|
+
children: C("botlit.kb.retrievalTest.run", "Run test")
|
|
112
|
+
})
|
|
113
|
+
]
|
|
114
|
+
}),
|
|
115
|
+
w.isError && /* @__PURE__ */ p("p", {
|
|
116
|
+
role: "alert",
|
|
117
|
+
className: "text-sm text-status-error-text",
|
|
118
|
+
children: a(w.error, C("botlit.kb.retrievalTest.failed", "The test could not run. The knowledge base must be indexed and its embedding model reachable."))
|
|
119
|
+
}),
|
|
120
|
+
w.isSuccess && (w.data.length === 0 ? /* @__PURE__ */ p("p", {
|
|
121
|
+
role: "status",
|
|
122
|
+
className: "text-sm text-text-secondary",
|
|
123
|
+
children: C("botlit.kb.retrievalTest.noHits", "No passage matched \"{{query}}\". An agent would answer that its sources do not cover this.", { query: P })
|
|
124
|
+
}) : /* @__PURE__ */ m("div", {
|
|
125
|
+
className: "space-y-2",
|
|
126
|
+
children: [/* @__PURE__ */ p("p", {
|
|
127
|
+
role: "status",
|
|
128
|
+
className: "text-sm text-text-secondary",
|
|
129
|
+
children: C("botlit.kb.retrievalTest.hits", "{{count}} passages for \"{{query}}\", best first", {
|
|
130
|
+
count: w.data.length,
|
|
131
|
+
query: P
|
|
132
|
+
})
|
|
133
|
+
}), /* @__PURE__ */ p("ol", {
|
|
134
|
+
className: "divide-y divide-border-subtle rounded-md border border-border-subtle",
|
|
135
|
+
children: w.data.map((e, t) => /* @__PURE__ */ m("li", {
|
|
136
|
+
className: "space-y-1 p-3",
|
|
137
|
+
children: [
|
|
138
|
+
/* @__PURE__ */ m("div", {
|
|
139
|
+
className: "flex flex-wrap items-center justify-between gap-2 text-sm",
|
|
140
|
+
children: [/* @__PURE__ */ m("span", {
|
|
141
|
+
className: "font-medium",
|
|
142
|
+
children: [
|
|
143
|
+
"#",
|
|
144
|
+
t + 1,
|
|
145
|
+
" ·",
|
|
146
|
+
" ",
|
|
147
|
+
z.get(e.documentId) ?? C("botlit.kb.retrievalTest.unknownSource", "Document {{id}}", { id: e.documentId.slice(0, 8) })
|
|
148
|
+
]
|
|
149
|
+
}), /* @__PURE__ */ p("span", {
|
|
150
|
+
className: "font-mono text-text-secondary",
|
|
151
|
+
children: C("botlit.kb.retrievalTest.score", "score {{score}}", { score: S(e.score) })
|
|
152
|
+
})]
|
|
153
|
+
}),
|
|
154
|
+
/* @__PURE__ */ p("p", {
|
|
155
|
+
className: "text-xs text-text-secondary",
|
|
156
|
+
children: C("botlit.kb.retrievalTest.passageMeta", "Passage {{sequence}} · {{tokens}} tokens", {
|
|
157
|
+
sequence: e.sequence + 1,
|
|
158
|
+
tokens: e.tokenCount
|
|
159
|
+
})
|
|
160
|
+
}),
|
|
161
|
+
/* @__PURE__ */ p("p", {
|
|
162
|
+
className: "whitespace-pre-wrap text-sm",
|
|
163
|
+
children: e.content
|
|
164
|
+
})
|
|
165
|
+
]
|
|
166
|
+
}, e.id))
|
|
167
|
+
})]
|
|
168
|
+
}))
|
|
169
|
+
]
|
|
170
|
+
})] });
|
|
171
|
+
}
|
|
172
|
+
export { x as KnowledgeRetrievalTestPanel };
|
|
173
|
+
|
|
174
|
+
//# sourceMappingURL=KnowledgeRetrievalTestPanel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KnowledgeRetrievalTestPanel.js","names":["FIELD_CLASS","MAX_TOP_K","QUERY_MAX_LENGTH","OPENSEARCH_ONLY_MODES","MODE_LABEL","KnowledgeRetrievalTestPanel","useBotlit","ScopedRetrievalTest","props","workspaceId","currentUser","formatScore","score","t","useTr","test","useKnowledgeRetrievalTest","knowledgeBaseId","backend","useKnowledgeBaseBackend","profiles","useRetrievalProfiles","liveProfiles","row","query","setQuery","useState","profileId","setProfileId","topK","setTopK","ranQuery","setRanQuery","profile","driver","degraded","titles","documents","document","parsedTopK","topKValid","canRun","run","trimmed","Card","CardHeader","CardTitle","FlaskConical","CardDescription","CardContent","event","Button","graphqlErrorMessage","index","hit"],"sources":["../../../src/botlit/components/KnowledgeRetrievalTestPanel.tsx"],"sourcesContent":["/**\n * Retrieval test (BOFF-15360): a curator runs a query against one knowledge\n * base, optionally through a retrieval profile, and sees the ranked passages\n * with their scores and source documents before any agent relies on them.\n */\nimport { useState } from 'react';\nimport { FlaskConical } from 'lucide-react';\nimport { useTr } from '../../shared/hooks/useTr';\nimport { useBotlit } from '../providers/BotlitProvider';\nimport { useRetrievalProfiles } from '../hooks/useRetrievalProfiles';\nimport {\n useKnowledgeBaseBackend,\n useKnowledgeRetrievalTest,\n} from '../hooks/useKnowledgeCuratorTools';\nimport { graphqlErrorMessage } from '../utils/errors';\nimport { Card, CardContent, CardDescription, CardHeader, CardTitle } from './Card';\nimport { Button } from './Button';\n\nconst FIELD_CLASS =\n 'h-10 w-full rounded-md border border-border-default bg-bg-surface px-3 text-sm text-text-primary';\nconst MAX_TOP_K = 20;\nconst QUERY_MAX_LENGTH = 2000;\n\n/** Modes that need the OpenSearch backend; elsewhere they run as vector search. */\nconst OPENSEARCH_ONLY_MODES = ['HYBRID', 'BM25_ONLY'];\n\nconst MODE_LABEL: Record<string, string> = {\n VECTOR: 'Vector',\n HYBRID: 'Hybrid',\n BM25_ONLY: 'Keyword',\n};\n\nexport interface RetrievalTestDocument {\n id: string;\n title: string;\n}\n\nexport interface KnowledgeRetrievalTestPanelProps {\n knowledgeBaseId: string;\n /** The knowledge base's documents, to name the source of each passage. */\n documents: RetrievalTestDocument[];\n}\n\nexport function KnowledgeRetrievalTestPanel(props: KnowledgeRetrievalTestPanelProps) {\n const { workspaceId, currentUser } = useBotlit();\n // A workspace, account or knowledge base switch starts a clean test.\n return (\n <ScopedRetrievalTest\n key={`${workspaceId}:${currentUser?.id}:${props.knowledgeBaseId}`}\n {...props}\n />\n );\n}\n\nfunction formatScore(score: number | null): string {\n if (score === null || !Number.isFinite(score)) return '—';\n return score.toFixed(3);\n}\n\nfunction ScopedRetrievalTest({ knowledgeBaseId, documents }: KnowledgeRetrievalTestPanelProps) {\n const t = useTr();\n const test = useKnowledgeRetrievalTest(knowledgeBaseId);\n const backend = useKnowledgeBaseBackend(knowledgeBaseId);\n const profiles = useRetrievalProfiles();\n // Agents use any profile that is not archived; the test offers the same set.\n const liveProfiles = (profiles.data ?? []).filter((row) => row.status !== 'ARCHIVED');\n const [query, setQuery] = useState('');\n const [profileId, setProfileId] = useState('');\n const [topK, setTopK] = useState('5');\n const [ranQuery, setRanQuery] = useState('');\n\n const profile = liveProfiles.find((row) => row.id === profileId);\n const driver = backend.data?.vectorStoreDriver ?? null;\n const degraded =\n profile !== undefined &&\n OPENSEARCH_ONLY_MODES.includes(profile.strategyMode) &&\n driver !== null &&\n driver !== 'opensearch';\n const titles = new Map(documents.map((document) => [document.id, document.title]));\n const parsedTopK = Number.parseInt(topK, 10);\n const topKValid = Number.isInteger(parsedTopK) && parsedTopK >= 1 && parsedTopK <= MAX_TOP_K;\n const canRun = query.trim().length > 0 && (profile !== undefined || topKValid);\n\n const run = () => {\n if (!canRun) return;\n const trimmed = query.trim();\n setRanQuery(trimmed);\n test.mutate({\n query: trimmed,\n topK: profile ? profile.topK : parsedTopK,\n ...(profile ? { retrievalProfileId: profile.id } : {}),\n });\n };\n\n return (\n <Card>\n <CardHeader>\n <CardTitle className=\"flex items-center gap-2\">\n <FlaskConical size={18} aria-hidden=\"true\" />\n {t('botlit.kb.retrievalTest.title', 'Test retrieval')}\n </CardTitle>\n <CardDescription>\n {t(\n 'botlit.kb.retrievalTest.help',\n 'Ask a question and see which passages an agent would be given, best first, before you rely on them.'\n )}\n </CardDescription>\n </CardHeader>\n <CardContent className=\"space-y-4\">\n <form\n className=\"space-y-4\"\n onSubmit={(event) => {\n event.preventDefault();\n run();\n }}\n >\n <label className=\"grid gap-2 text-sm\">\n {t('botlit.kb.retrievalTest.query', 'Question')}\n <textarea\n className=\"min-h-20 rounded-md border border-border-default bg-bg-surface p-3 text-sm text-text-primary\"\n value={query}\n maxLength={QUERY_MAX_LENGTH}\n placeholder={t(\n 'botlit.kb.retrievalTest.queryPlaceholder',\n 'For example: What is the refund window?'\n )}\n onChange={(event) => setQuery(event.target.value)}\n />\n </label>\n <div className=\"grid gap-4 md:grid-cols-2\">\n <label className=\"grid gap-2 text-sm\">\n {t('botlit.kb.retrievalTest.profile', 'Retrieval profile')}\n <select\n className={FIELD_CLASS}\n value={profileId}\n onChange={(event) => setProfileId(event.target.value)}\n >\n <option value=\"\">\n {t('botlit.kb.retrievalTest.noProfile', 'None: default search')}\n </option>\n {liveProfiles.map((row) => (\n <option key={row.id} value={row.id}>\n {row.name}\n </option>\n ))}\n </select>\n </label>\n {profile ? (\n <div className=\"grid gap-1 text-sm\">\n <span>{t('botlit.kb.retrievalTest.applied', 'Profile settings')}</span>\n <span className=\"text-text-secondary\">\n {t(\n 'botlit.kb.retrievalTest.appliedValue',\n '{{mode}} · top {{topK}} · minimum score {{min}}',\n {\n mode: MODE_LABEL[profile.strategyMode] ?? profile.strategyMode,\n topK: profile.topK,\n min:\n profile.minRelevanceScore === null ||\n profile.minRelevanceScore === undefined\n ? t('botlit.kb.retrievalTest.noMinimum', 'none')\n : profile.minRelevanceScore,\n }\n )}\n </span>\n </div>\n ) : (\n <label className=\"grid gap-2 text-sm\">\n {t('botlit.kb.retrievalTest.topK', 'Passages to return (1–{{max}})', {\n max: MAX_TOP_K,\n })}\n <input\n className={FIELD_CLASS}\n type=\"number\"\n min={1}\n max={MAX_TOP_K}\n value={topK}\n aria-invalid={!topKValid}\n onChange={(event) => setTopK(event.target.value)}\n />\n </label>\n )}\n </div>\n {profiles.error && (\n <p role=\"alert\" className=\"text-sm text-status-warning-text\">\n {t(\n 'botlit.kb.retrievalTest.profilesError',\n 'Retrieval profiles could not be loaded. You can still run a default search.'\n )}\n </p>\n )}\n {degraded && (\n <p className=\"text-sm text-status-warning-text\">\n {t(\n 'botlit.kb.retrievalTest.degraded',\n 'This knowledge base is stored in {{driver}}, which searches by vector only. The profile runs as vector search here, exactly as it does for agents.',\n { driver }\n )}\n </p>\n )}\n <Button type=\"submit\" disabled={!canRun} isLoading={test.isPending}>\n {t('botlit.kb.retrievalTest.run', 'Run test')}\n </Button>\n </form>\n\n {test.isError && (\n <p role=\"alert\" className=\"text-sm text-status-error-text\">\n {graphqlErrorMessage(\n test.error,\n t(\n 'botlit.kb.retrievalTest.failed',\n 'The test could not run. The knowledge base must be indexed and its embedding model reachable.'\n )\n )}\n </p>\n )}\n {test.isSuccess &&\n (test.data.length === 0 ? (\n <p role=\"status\" className=\"text-sm text-text-secondary\">\n {t(\n 'botlit.kb.retrievalTest.noHits',\n 'No passage matched \"{{query}}\". An agent would answer that its sources do not cover this.',\n { query: ranQuery }\n )}\n </p>\n ) : (\n <div className=\"space-y-2\">\n <p role=\"status\" className=\"text-sm text-text-secondary\">\n {t(\n 'botlit.kb.retrievalTest.hits',\n '{{count}} passages for \"{{query}}\", best first',\n { count: test.data.length, query: ranQuery }\n )}\n </p>\n <ol className=\"divide-y divide-border-subtle rounded-md border border-border-subtle\">\n {test.data.map((hit, index) => (\n <li key={hit.id} className=\"space-y-1 p-3\">\n <div className=\"flex flex-wrap items-center justify-between gap-2 text-sm\">\n <span className=\"font-medium\">\n #{index + 1} ·{' '}\n {titles.get(hit.documentId) ??\n t('botlit.kb.retrievalTest.unknownSource', 'Document {{id}}', {\n id: hit.documentId.slice(0, 8),\n })}\n </span>\n <span className=\"font-mono text-text-secondary\">\n {t('botlit.kb.retrievalTest.score', 'score {{score}}', {\n score: formatScore(hit.score),\n })}\n </span>\n </div>\n <p className=\"text-xs text-text-secondary\">\n {t(\n 'botlit.kb.retrievalTest.passageMeta',\n 'Passage {{sequence}} · {{tokens}} tokens',\n { sequence: hit.sequence + 1, tokens: hit.tokenCount }\n )}\n </p>\n <p className=\"whitespace-pre-wrap text-sm\">{hit.content}</p>\n </li>\n ))}\n </ol>\n </div>\n ))}\n </CardContent>\n </Card>\n );\n}\n"],"mappings":";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|
4
|
+
sequence: number;
|
|
5
|
+
content: string;
|
|
6
|
+
tokenCount: number;
|
|
7
|
+
/** The score the hit was ranked by; null when the backend reports none. */
|
|
8
|
+
score: number | null;
|
|
9
|
+
}
|
|
10
|
+
export interface RetrievalTestInput {
|
|
11
|
+
query: string;
|
|
12
|
+
topK: number;
|
|
13
|
+
retrievalProfileId?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface KnowledgeBackendMigration {
|
|
16
|
+
id: string;
|
|
17
|
+
knowledgeBaseId: string;
|
|
18
|
+
sourceDriver: string;
|
|
19
|
+
targetDriver: string;
|
|
20
|
+
status: string;
|
|
21
|
+
expectedDocuments: number;
|
|
22
|
+
expectedVectors: number;
|
|
23
|
+
copiedDocuments: number;
|
|
24
|
+
copiedVectors: number;
|
|
25
|
+
failureCount: number;
|
|
26
|
+
errorCode: string | null;
|
|
27
|
+
createdAt: string;
|
|
28
|
+
updatedAt: string;
|
|
29
|
+
}
|
|
30
|
+
/** Statuses in which the copy is still running and the list should keep refreshing. */
|
|
31
|
+
export declare const MIGRATION_RUNNING_STATUSES: string[];
|
|
32
|
+
/** Statuses an inactive copy can be discarded from (the service refuses the rest). */
|
|
33
|
+
export declare const MIGRATION_DISCARDABLE_STATUSES: string[];
|
|
34
|
+
/** Runs one retrieval test; the result is the ranked hits, best first. */
|
|
35
|
+
export declare function useKnowledgeRetrievalTest(knowledgeBaseId: string): import('@tanstack/react-query').UseMutationResult<RetrievalHit[], Error, RetrievalTestInput, unknown>;
|
|
36
|
+
/** The knowledge base's pinned vector backend and index state. */
|
|
37
|
+
export declare function useKnowledgeBaseBackend(knowledgeBaseId: string): import('@tanstack/react-query').UseQueryResult<{
|
|
38
|
+
id: string;
|
|
39
|
+
vectorStoreDriver: string | null;
|
|
40
|
+
indexStatus: string;
|
|
41
|
+
}, Error>;
|
|
42
|
+
/** Targets, history and the begin / cutover / discard actions for backend migration. */
|
|
43
|
+
export declare function useKnowledgeBackendMigrations(knowledgeBaseId: string): {
|
|
44
|
+
targets: import('@tanstack/react-query').UseQueryResult<string[], Error>;
|
|
45
|
+
migrations: import('@tanstack/react-query').UseQueryResult<KnowledgeBackendMigration[], Error>;
|
|
46
|
+
begin: import('@tanstack/react-query').UseMutationResult<KnowledgeBackendMigration, Error, string, unknown>;
|
|
47
|
+
cutover: import('@tanstack/react-query').UseMutationResult<KnowledgeBackendMigration, Error, string, unknown>;
|
|
48
|
+
discard: import('@tanstack/react-query').UseMutationResult<void, Error, string, unknown>;
|
|
49
|
+
};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { useBotlit as e } from "../providers/BotlitProvider.js";
|
|
2
|
+
import { gql as t } from "@apollo/client";
|
|
3
|
+
import { useGatewayClient as n } from "@burdenoff/fe-libs/shared/graphql";
|
|
4
|
+
import { useMutation as r, useQuery as i, useQueryClient as a } from "@tanstack/react-query";
|
|
5
|
+
// src/botlit/hooks/useKnowledgeCuratorTools.ts
|
|
6
|
+
var o = ["READY", "COPYING"], s = [
|
|
7
|
+
"READY",
|
|
8
|
+
"COPYING",
|
|
9
|
+
"VERIFIED",
|
|
10
|
+
"BLOCKED"
|
|
11
|
+
], c = "\n id\n knowledgeBaseId\n sourceDriver\n targetDriver\n status\n expectedDocuments\n expectedVectors\n copiedDocuments\n copiedVectors\n failureCount\n errorCode\n createdAt\n updatedAt\n", l = t`
|
|
12
|
+
query KnowledgeRetrievalTest(
|
|
13
|
+
$knowledgeBaseId: ID!
|
|
14
|
+
$query: String!
|
|
15
|
+
$topK: Int
|
|
16
|
+
$retrievalProfileId: ID
|
|
17
|
+
) {
|
|
18
|
+
searchKnowledge(
|
|
19
|
+
knowledgeBaseId: $knowledgeBaseId
|
|
20
|
+
query: $query
|
|
21
|
+
topK: $topK
|
|
22
|
+
retrievalProfileId: $retrievalProfileId
|
|
23
|
+
) {
|
|
24
|
+
id
|
|
25
|
+
documentId
|
|
26
|
+
sequence
|
|
27
|
+
content
|
|
28
|
+
tokenCount
|
|
29
|
+
score
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
`, u = t`
|
|
33
|
+
query KnowledgeBaseBackend($id: ID!) {
|
|
34
|
+
getKnowledgeBase(id: $id) {
|
|
35
|
+
id
|
|
36
|
+
vectorStoreDriver
|
|
37
|
+
indexStatus
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
`, d = t`
|
|
41
|
+
query KnowledgeBackendMigrationTargets {
|
|
42
|
+
knowledgeBackendMigrationTargets
|
|
43
|
+
}
|
|
44
|
+
`, f = t`
|
|
45
|
+
query KnowledgeBackendMigrations($knowledgeBaseId: ID!) {
|
|
46
|
+
knowledgeBackendMigrations(knowledgeBaseId: $knowledgeBaseId) {
|
|
47
|
+
${c}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
`, p = t`
|
|
51
|
+
mutation BeginKnowledgeBackendMigration($knowledgeBaseId: ID!, $targetDriver: String!) {
|
|
52
|
+
beginKnowledgeBackendMigration(knowledgeBaseId: $knowledgeBaseId, targetDriver: $targetDriver) {
|
|
53
|
+
${c}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
`, m = t`
|
|
57
|
+
mutation CutoverKnowledgeBackendMigration($id: ID!) {
|
|
58
|
+
cutoverKnowledgeBackendMigration(id: $id) {
|
|
59
|
+
${c}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
`, h = t`
|
|
63
|
+
mutation DiscardKnowledgeBackendMigration($id: ID!) {
|
|
64
|
+
discardKnowledgeBackendMigration(id: $id)
|
|
65
|
+
}
|
|
66
|
+
`;
|
|
67
|
+
function g(...t) {
|
|
68
|
+
let { workspaceId: n, currentUser: r } = e();
|
|
69
|
+
return {
|
|
70
|
+
key: [
|
|
71
|
+
...t,
|
|
72
|
+
n,
|
|
73
|
+
r?.id
|
|
74
|
+
],
|
|
75
|
+
ready: !!(n && r?.id)
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function _(e) {
|
|
79
|
+
let t = n("workspace");
|
|
80
|
+
return r({ mutationFn: async (n) => {
|
|
81
|
+
let r = (await t.query({
|
|
82
|
+
query: l,
|
|
83
|
+
variables: {
|
|
84
|
+
knowledgeBaseId: e,
|
|
85
|
+
query: n.query,
|
|
86
|
+
topK: n.topK,
|
|
87
|
+
retrievalProfileId: n.retrievalProfileId || null
|
|
88
|
+
},
|
|
89
|
+
fetchPolicy: "no-cache"
|
|
90
|
+
})).data?.searchKnowledge;
|
|
91
|
+
if (!r) throw Error("Retrieval test unavailable");
|
|
92
|
+
return r;
|
|
93
|
+
} });
|
|
94
|
+
}
|
|
95
|
+
function v(e) {
|
|
96
|
+
let t = n("workspace"), r = g("botmanor-kb-backend", e);
|
|
97
|
+
return i({
|
|
98
|
+
queryKey: r.key,
|
|
99
|
+
enabled: r.ready && !!e,
|
|
100
|
+
retry: !1,
|
|
101
|
+
queryFn: async () => {
|
|
102
|
+
let n = (await t.query({
|
|
103
|
+
query: u,
|
|
104
|
+
variables: { id: e },
|
|
105
|
+
fetchPolicy: "no-cache"
|
|
106
|
+
})).data?.getKnowledgeBase;
|
|
107
|
+
if (!n || n.id !== e) throw Error("Knowledge base unavailable");
|
|
108
|
+
return n;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
function y(e) {
|
|
113
|
+
let t = n("workspace"), s = a(), c = g("botmanor-kb-migrations", e), l = g("botmanor-kb-migration-targets"), u = g("botmanor-kb-backend", e), _ = i({
|
|
114
|
+
queryKey: l.key,
|
|
115
|
+
enabled: l.ready,
|
|
116
|
+
retry: !1,
|
|
117
|
+
queryFn: async () => {
|
|
118
|
+
let e = (await t.query({
|
|
119
|
+
query: d,
|
|
120
|
+
fetchPolicy: "no-cache"
|
|
121
|
+
})).data?.knowledgeBackendMigrationTargets;
|
|
122
|
+
if (!e) throw Error("Migration targets unavailable");
|
|
123
|
+
return e;
|
|
124
|
+
}
|
|
125
|
+
}), v = i({
|
|
126
|
+
queryKey: c.key,
|
|
127
|
+
enabled: c.ready && !!e,
|
|
128
|
+
retry: !1,
|
|
129
|
+
refetchInterval: (e) => e.state.data?.some((e) => o.includes(e.status)) ? 5e3 : !1,
|
|
130
|
+
queryFn: async () => {
|
|
131
|
+
let n = (await t.query({
|
|
132
|
+
query: f,
|
|
133
|
+
variables: { knowledgeBaseId: e },
|
|
134
|
+
fetchPolicy: "no-cache"
|
|
135
|
+
})).data?.knowledgeBackendMigrations;
|
|
136
|
+
if (!n || n.some((t) => t.knowledgeBaseId !== e)) throw Error("Migrations unavailable");
|
|
137
|
+
return n;
|
|
138
|
+
}
|
|
139
|
+
}), y = async () => {
|
|
140
|
+
await s.invalidateQueries({ queryKey: c.key }), await s.invalidateQueries({ queryKey: u.key });
|
|
141
|
+
};
|
|
142
|
+
return {
|
|
143
|
+
targets: _,
|
|
144
|
+
migrations: v,
|
|
145
|
+
begin: r({
|
|
146
|
+
mutationFn: async (n) => {
|
|
147
|
+
let r = (await t.mutate({
|
|
148
|
+
mutation: p,
|
|
149
|
+
variables: {
|
|
150
|
+
knowledgeBaseId: e,
|
|
151
|
+
targetDriver: n
|
|
152
|
+
}
|
|
153
|
+
})).data?.beginKnowledgeBackendMigration;
|
|
154
|
+
if (!r || r.knowledgeBaseId !== e) throw Error("Migration not started");
|
|
155
|
+
return r;
|
|
156
|
+
},
|
|
157
|
+
onSuccess: y
|
|
158
|
+
}),
|
|
159
|
+
cutover: r({
|
|
160
|
+
mutationFn: async (e) => {
|
|
161
|
+
let n = (await t.mutate({
|
|
162
|
+
mutation: m,
|
|
163
|
+
variables: { id: e }
|
|
164
|
+
})).data?.cutoverKnowledgeBackendMigration;
|
|
165
|
+
if (!n) throw Error("Cutover not confirmed");
|
|
166
|
+
return n;
|
|
167
|
+
},
|
|
168
|
+
onSuccess: y
|
|
169
|
+
}),
|
|
170
|
+
discard: r({
|
|
171
|
+
mutationFn: async (e) => {
|
|
172
|
+
if (!(await t.mutate({
|
|
173
|
+
mutation: h,
|
|
174
|
+
variables: { id: e }
|
|
175
|
+
})).data?.discardKnowledgeBackendMigration) throw Error("Discard not confirmed");
|
|
176
|
+
},
|
|
177
|
+
onSuccess: y
|
|
178
|
+
})
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
export { s as MIGRATION_DISCARDABLE_STATUSES, o as MIGRATION_RUNNING_STATUSES, y as useKnowledgeBackendMigrations, v as useKnowledgeBaseBackend, _ as useKnowledgeRetrievalTest };
|
|
182
|
+
|
|
183
|
+
//# sourceMappingURL=useKnowledgeCuratorTools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useKnowledgeCuratorTools.js","names":["MIGRATION_RUNNING_STATUSES","MIGRATION_DISCARDABLE_STATUSES","MIGRATION_FIELDS","SEARCH","BACKEND","TARGETS","MIGRATIONS","BEGIN","CUTOVER","DISCARD","useScopeKey","parts","useBotlit","workspaceId","currentUser","useKnowledgeRetrievalTest","client","useGatewayClient","useMutation","hits","input","useKnowledgeBaseBackend","scope","knowledgeBaseId","useQuery","kb","useKnowledgeBackendMigrations","cache","useQueryClient","listScope","targetScope","backendScope","targets","rows","migrations","query","row","refresh"],"sources":["../../../src/botlit/hooks/useKnowledgeCuratorTools.ts"],"sourcesContent":["/**\n * Knowledge curator tools (BOFF-15360): retrieval testing and vector backend\n * migration for one knowledge base.\n *\n * Backed by `searchKnowledge` (with an optional retrieval profile) and the\n * `knowledgeBackendMigration*` operations on wspace-botmanor-svc. Every query\n * key carries the workspace and the signed-in person so nothing leaks across a\n * workspace or account switch.\n */\nimport { gql } from '@apollo/client';\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';\nimport { useGatewayClient } from '@burdenoff/fe-libs/shared/graphql';\nimport { useBotlit } from '../providers/BotlitProvider';\n\nexport interface RetrievalHit {\n id: string;\n documentId: string;\n sequence: number;\n content: string;\n tokenCount: number;\n /** The score the hit was ranked by; null when the backend reports none. */\n score: number | null;\n}\n\nexport interface RetrievalTestInput {\n query: string;\n topK: number;\n retrievalProfileId?: string;\n}\n\nexport interface KnowledgeBackendMigration {\n id: string;\n knowledgeBaseId: string;\n sourceDriver: string;\n targetDriver: string;\n status: string;\n expectedDocuments: number;\n expectedVectors: number;\n copiedDocuments: number;\n copiedVectors: number;\n failureCount: number;\n errorCode: string | null;\n createdAt: string;\n updatedAt: string;\n}\n\n/** Statuses in which the copy is still running and the list should keep refreshing. */\nexport const MIGRATION_RUNNING_STATUSES = ['READY', 'COPYING'];\n/** Statuses an inactive copy can be discarded from (the service refuses the rest). */\nexport const MIGRATION_DISCARDABLE_STATUSES = ['READY', 'COPYING', 'VERIFIED', 'BLOCKED'];\n\nconst MIGRATION_FIELDS = `\n id\n knowledgeBaseId\n sourceDriver\n targetDriver\n status\n expectedDocuments\n expectedVectors\n copiedDocuments\n copiedVectors\n failureCount\n errorCode\n createdAt\n updatedAt\n`;\n\nconst SEARCH = gql`\n query KnowledgeRetrievalTest(\n $knowledgeBaseId: ID!\n $query: String!\n $topK: Int\n $retrievalProfileId: ID\n ) {\n searchKnowledge(\n knowledgeBaseId: $knowledgeBaseId\n query: $query\n topK: $topK\n retrievalProfileId: $retrievalProfileId\n ) {\n id\n documentId\n sequence\n content\n tokenCount\n score\n }\n }\n`;\nconst BACKEND = gql`\n query KnowledgeBaseBackend($id: ID!) {\n getKnowledgeBase(id: $id) {\n id\n vectorStoreDriver\n indexStatus\n }\n }\n`;\nconst TARGETS = gql`\n query KnowledgeBackendMigrationTargets {\n knowledgeBackendMigrationTargets\n }\n`;\nconst MIGRATIONS = gql`\n query KnowledgeBackendMigrations($knowledgeBaseId: ID!) {\n knowledgeBackendMigrations(knowledgeBaseId: $knowledgeBaseId) {\n ${MIGRATION_FIELDS}\n }\n }\n`;\nconst BEGIN = gql`\n mutation BeginKnowledgeBackendMigration($knowledgeBaseId: ID!, $targetDriver: String!) {\n beginKnowledgeBackendMigration(knowledgeBaseId: $knowledgeBaseId, targetDriver: $targetDriver) {\n ${MIGRATION_FIELDS}\n }\n }\n`;\nconst CUTOVER = gql`\n mutation CutoverKnowledgeBackendMigration($id: ID!) {\n cutoverKnowledgeBackendMigration(id: $id) {\n ${MIGRATION_FIELDS}\n }\n }\n`;\nconst DISCARD = gql`\n mutation DiscardKnowledgeBackendMigration($id: ID!) {\n discardKnowledgeBackendMigration(id: $id)\n }\n`;\n\nfunction useScopeKey(...parts: string[]) {\n const { workspaceId, currentUser } = useBotlit();\n return {\n key: [...parts, workspaceId, currentUser?.id],\n ready: Boolean(workspaceId && currentUser?.id),\n };\n}\n\n/** Runs one retrieval test; the result is the ranked hits, best first. */\nexport function useKnowledgeRetrievalTest(knowledgeBaseId: string) {\n const client = useGatewayClient('workspace');\n return useMutation({\n mutationFn: async (input: RetrievalTestInput): Promise<RetrievalHit[]> => {\n const response = await client.query<{ searchKnowledge: RetrievalHit[] }>({\n query: SEARCH,\n variables: {\n knowledgeBaseId,\n query: input.query,\n topK: input.topK,\n retrievalProfileId: input.retrievalProfileId || null,\n },\n fetchPolicy: 'no-cache',\n });\n const hits = response.data?.searchKnowledge;\n if (!hits) throw new Error('Retrieval test unavailable');\n return hits;\n },\n });\n}\n\n/** The knowledge base's pinned vector backend and index state. */\nexport function useKnowledgeBaseBackend(knowledgeBaseId: string) {\n const client = useGatewayClient('workspace');\n const scope = useScopeKey('botmanor-kb-backend', knowledgeBaseId);\n return useQuery({\n queryKey: scope.key,\n enabled: scope.ready && Boolean(knowledgeBaseId),\n retry: false,\n queryFn: async () => {\n const response = await client.query<{\n getKnowledgeBase: {\n id: string;\n vectorStoreDriver: string | null;\n indexStatus: string;\n } | null;\n }>({ query: BACKEND, variables: { id: knowledgeBaseId }, fetchPolicy: 'no-cache' });\n const kb = response.data?.getKnowledgeBase;\n if (!kb || kb.id !== knowledgeBaseId) throw new Error('Knowledge base unavailable');\n return kb;\n },\n });\n}\n\n/** Targets, history and the begin / cutover / discard actions for backend migration. */\nexport function useKnowledgeBackendMigrations(knowledgeBaseId: string) {\n const client = useGatewayClient('workspace');\n const cache = useQueryClient();\n const listScope = useScopeKey('botmanor-kb-migrations', knowledgeBaseId);\n const targetScope = useScopeKey('botmanor-kb-migration-targets');\n const backendScope = useScopeKey('botmanor-kb-backend', knowledgeBaseId);\n\n const targets = useQuery({\n queryKey: targetScope.key,\n enabled: targetScope.ready,\n retry: false,\n queryFn: async () => {\n const response = await client.query<{ knowledgeBackendMigrationTargets: string[] }>({\n query: TARGETS,\n fetchPolicy: 'no-cache',\n });\n const rows = response.data?.knowledgeBackendMigrationTargets;\n if (!rows) throw new Error('Migration targets unavailable');\n return rows;\n },\n });\n\n const migrations = useQuery({\n queryKey: listScope.key,\n enabled: listScope.ready && Boolean(knowledgeBaseId),\n retry: false,\n refetchInterval: (query) =>\n query.state.data?.some((row) => MIGRATION_RUNNING_STATUSES.includes(row.status))\n ? 5000\n : false,\n queryFn: async () => {\n const response = await client.query<{\n knowledgeBackendMigrations: KnowledgeBackendMigration[];\n }>({ query: MIGRATIONS, variables: { knowledgeBaseId }, fetchPolicy: 'no-cache' });\n const rows = response.data?.knowledgeBackendMigrations;\n if (!rows || rows.some((row) => row.knowledgeBaseId !== knowledgeBaseId))\n throw new Error('Migrations unavailable');\n return rows;\n },\n });\n\n const refresh = async () => {\n await cache.invalidateQueries({ queryKey: listScope.key });\n await cache.invalidateQueries({ queryKey: backendScope.key });\n };\n\n const begin = useMutation({\n mutationFn: async (targetDriver: string) => {\n const response = await client.mutate<{\n beginKnowledgeBackendMigration: KnowledgeBackendMigration;\n }>({ mutation: BEGIN, variables: { knowledgeBaseId, targetDriver } });\n const row = response.data?.beginKnowledgeBackendMigration;\n if (!row || row.knowledgeBaseId !== knowledgeBaseId) throw new Error('Migration not started');\n return row;\n },\n onSuccess: refresh,\n });\n const cutover = useMutation({\n mutationFn: async (id: string) => {\n const response = await client.mutate<{\n cutoverKnowledgeBackendMigration: KnowledgeBackendMigration;\n }>({ mutation: CUTOVER, variables: { id } });\n const row = response.data?.cutoverKnowledgeBackendMigration;\n if (!row) throw new Error('Cutover not confirmed');\n return row;\n },\n onSuccess: refresh,\n });\n const discard = useMutation({\n mutationFn: async (id: string) => {\n const response = await client.mutate<{ discardKnowledgeBackendMigration: boolean }>({\n mutation: DISCARD,\n variables: { id },\n });\n if (!response.data?.discardKnowledgeBackendMigration)\n throw new Error('Discard not confirmed');\n },\n onSuccess: refresh,\n });\n\n return { targets, migrations, begin, cutover, discard };\n}\n"],"mappings":";;;;;AA+CA,IAAaA,IAA6B,CAAC,SAAS,SAAS,GAEhDC,IAAiC;CAAC;CAAS;CAAW;CAAY;AAAS,GAElFC,IAAmB,4MAgBnBC,IAAS,CAAG;;;;;;;;;;;;;;;;;;;;;GAsBZC,IAAU,CAAG;;;;;;;;GASbC,IAAU,CAAG;;;;GAKbC,IAAa,CAAG;;;QAGdJ,EAAiB;;;GAInBK,IAAQ,CAAG;;;QAGTL,EAAiB;;;GAInBM,IAAU,CAAG;;;QAGXN,EAAiB;;;GAInBO,IAAU,CAAG;;;;;AAMnB,SAASC,EAAY,GAAGC,GAAiB;CACvC,IAAM,EAAE,gBAAa,mBAAgBC,EAAU;CAC/C,OAAO;EACL,KAAK;GAAC,GAAGD;GAAOE;GAAaC,GAAa;EAAE;EAC5C,OAAO,GAAQD,KAAeC,GAAa;CAC7C;AACF;AAGA,SAAgBC,EAA0B,GAAyB;CACjE,IAAMC,IAASC,EAAiB,WAAW;CAC3C,OAAOC,EAAY,EACjB,YAAY,OAAO,MAAuD;EAWxE,IAAMC,KAAO,MAVUH,EAAO,MAA2C;GACvE,OAAOb;GACP,WAAW;IACT;IACA,OAAOiB,EAAM;IACb,MAAMA,EAAM;IACZ,oBAAoBA,EAAM,sBAAsB;GAClD;GACA,aAAa;EACf,CAAC,EAAA,CACqB,MAAM;EAC5B,IAAI,CAACD,GAAM,MAAU,MAAM,4BAA4B;EACvD,OAAOA;CACT,EACF,CAAC;AACH;AAGA,SAAgBE,EAAwB,GAAyB;CAC/D,IAAML,IAASC,EAAiB,WAAW,GACrCK,IAAQZ,EAAY,uBAAuBa,CAAe;CAChE,O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