dsh-knowledge-library 0.1.1 → 0.2.0

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +107 -12
  3. package/dist/client.js +1420 -303
  4. package/dist/core/extract.d.ts +1 -0
  5. package/dist/core/extract.js +62 -5
  6. package/dist/core/fetch.js +82 -11
  7. package/dist/core/grouping.d.ts +6 -0
  8. package/dist/core/grouping.js +71 -0
  9. package/dist/core/incremental.d.ts +14 -0
  10. package/dist/core/incremental.js +52 -0
  11. package/dist/core/jobs.d.ts +1 -0
  12. package/dist/core/jobs.js +4 -0
  13. package/dist/core/knowledge.d.ts +37 -0
  14. package/dist/core/knowledge.js +617 -0
  15. package/dist/core/library.d.ts +20 -2
  16. package/dist/core/library.js +271 -12
  17. package/dist/core/page-access.d.ts +6 -0
  18. package/dist/core/page-access.js +38 -0
  19. package/dist/core/purge.d.ts +20 -0
  20. package/dist/core/purge.js +106 -0
  21. package/dist/directory-settings.d.ts +18 -0
  22. package/dist/directory-settings.js +92 -0
  23. package/dist/http.d.ts +3 -1
  24. package/dist/http.js +121 -4
  25. package/dist/index.js +17 -5
  26. package/dist/knowledge-model.d.ts +18 -0
  27. package/dist/knowledge-model.js +116 -0
  28. package/dist/preview-settings.d.ts +6 -0
  29. package/dist/preview-settings.js +42 -0
  30. package/dist/public/app.css +126 -2
  31. package/dist/public/app.js +11 -7
  32. package/dist/standalone.js +8 -3
  33. package/dist/tools.d.ts +2 -1
  34. package/dist/tools.js +10 -1
  35. package/dist/types.d.ts +143 -1
  36. package/dist/ui/App.js +243 -47
  37. package/dist/ui/Dialog.d.ts +7 -0
  38. package/dist/ui/Dialog.js +32 -0
  39. package/dist/ui/Grouping.d.ts +12 -0
  40. package/dist/ui/Grouping.js +93 -0
  41. package/dist/ui/Knowledge.d.ts +26 -0
  42. package/dist/ui/Knowledge.js +106 -0
  43. package/dist/ui/api.d.ts +7 -0
  44. package/dist/ui/api.js +16 -0
  45. package/dist/ui/icons.js +2 -0
  46. package/package.json +4 -1
package/dist/client.js CHANGED
@@ -27,7 +27,7 @@ __export(client_exports, {
27
27
  module.exports = __toCommonJS(client_exports);
28
28
 
29
29
  // src/ui/App.tsx
30
- var import_react = require("react");
30
+ var import_react4 = require("react");
31
31
 
32
32
  // src/ui/icons.tsx
33
33
  var import_jsx_runtime = require("react/jsx-runtime");
@@ -72,15 +72,632 @@ function Icon({ name, size = 20 }) {
72
72
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M4 7h16M4 17h16" }),
73
73
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "9", cy: "7", r: "3" }),
74
74
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "15", cy: "17", r: "3" })
75
- ] })
75
+ ] }),
76
+ trash: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M3 6h18M9 6V3h6v3M5 6l1 15h12l1-15M10 10v7M14 10v7" }) }),
77
+ restore: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M3 10a9 9 0 1 1 2 9M3 4v6h6M12 7v5l3 2" }) })
76
78
  };
77
79
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: paths[name] || paths.file });
78
80
  }
79
81
  var LibraryIcon = ({ size }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Icon, { name: "library", size });
80
82
 
81
- // src/ui/App.tsx
82
- var import_jsx_runtime2 = require("react/jsx-runtime");
83
+ // src/ui/api.ts
83
84
  var API = "/knowledge-library/api";
85
+ var ApiError = class extends Error {
86
+ constructor(message, status) {
87
+ super(message);
88
+ this.status = status;
89
+ }
90
+ };
91
+ async function api(path, options = {}) {
92
+ const response = await fetch(API + path, { ...options, headers: { "Content-Type": "application/json", "X-Knowledge-Library": "1", ...options.headers } });
93
+ const data = await response.json();
94
+ if (!response.ok) throw new ApiError(data.error || `\u8BF7\u6C42\u5931\u8D25\uFF1A${response.status}`, response.status);
95
+ return data;
96
+ }
97
+ var post = (path, value, method = "POST", signal) => api(path, { method, body: JSON.stringify(value), signal });
98
+
99
+ // src/ui/Dialog.tsx
100
+ var import_react = require("react");
101
+ var import_jsx_runtime2 = require("react/jsx-runtime");
102
+ function Dialog({ title, description, onClose, children }) {
103
+ const ref = (0, import_react.useRef)(null);
104
+ const closeRef = (0, import_react.useRef)(onClose);
105
+ closeRef.current = onClose;
106
+ (0, import_react.useEffect)(() => {
107
+ const previous = document.activeElement;
108
+ const timer = setTimeout(() => ref.current?.querySelector("input,textarea,button")?.focus(), 0);
109
+ const key = (event) => {
110
+ if (event.key === "Escape") closeRef.current();
111
+ if (event.key === "Tab") {
112
+ const elements = Array.from(ref.current?.querySelectorAll("button:not(:disabled),input:not(:disabled),textarea:not(:disabled),select,a[href]") || []);
113
+ const first = elements[0], last = elements[elements.length - 1];
114
+ if (event.shiftKey && document.activeElement === first) {
115
+ event.preventDefault();
116
+ last?.focus();
117
+ }
118
+ if (!event.shiftKey && document.activeElement === last) {
119
+ event.preventDefault();
120
+ first?.focus();
121
+ }
122
+ }
123
+ };
124
+ document.addEventListener("keydown", key);
125
+ return () => {
126
+ clearTimeout(timer);
127
+ document.removeEventListener("keydown", key);
128
+ previous?.focus();
129
+ };
130
+ }, []);
131
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "kl-modal-backdrop", onMouseDown: (event) => {
132
+ if (event.target === event.currentTarget) onClose();
133
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-dialog", role: "dialog", "aria-modal": "true", "aria-label": title, ref, children: [
134
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("header", { children: [
135
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
136
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h2", { children: title }),
137
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { children: description })
138
+ ] }),
139
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { "aria-label": "\u5173\u95ED\u5F39\u7A97", onClick: onClose, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "close" }) })
140
+ ] }),
141
+ children
142
+ ] }) });
143
+ }
144
+
145
+ // src/ui/Knowledge.tsx
146
+ var import_react3 = require("react");
147
+
148
+ // src/ui/Grouping.tsx
149
+ var import_react2 = require("react");
150
+ var import_jsx_runtime3 = require("react/jsx-runtime");
151
+ var splitTags = (value) => value.split(/[,,]/).map((t) => t.trim()).filter(Boolean);
152
+ function GroupingEditor({ root, job, model, onRefresh, onNotify, onOpenSource }) {
153
+ const [plan, setPlan] = (0, import_react2.useState)(job.plan);
154
+ const [version, setVersion] = (0, import_react2.useState)(job.planVersion);
155
+ const [tagText, setTagText] = (0, import_react2.useState)(Object.fromEntries(plan.groups.map((g) => [g.id, g.tags.join("\uFF0C")])));
156
+ const [apply2, setApply] = (0, import_react2.useState)(job.classification?.apply ?? plan.applyClassification ?? true);
157
+ const [busy, setBusy] = (0, import_react2.useState)(false);
158
+ const [error, setError] = (0, import_react2.useState)("");
159
+ const locked = !!job.classification;
160
+ const groups = plan.groups.filter((g) => g.sourceIds.length);
161
+ function groupValue(id, change) {
162
+ setPlan((p) => ({ ...p, groups: p.groups.map((g) => g.id === id ? { ...g, ...change } : g) }));
163
+ }
164
+ function newGroup(sourceId) {
165
+ const source = job.sources.find((s) => s.id === sourceId);
166
+ const analysis = job.analyses?.find((a) => a.sourceId === sourceId);
167
+ const id = `group_${crypto.randomUUID()}`;
168
+ const item = { id, title: analysis?.theme || source?.title || "\u65B0\u5206\u7EC4", reason: source ? "\u72EC\u7ACB\u6574\u7406\u8FD9\u4EFD\u8D44\u6599" : "\u8BF7\u586B\u5199\u8D44\u6599\u4E4B\u95F4\u7684\u5177\u4F53\u5173\u8054", sourceIds: sourceId ? [sourceId] : [], category: analysis?.category || "\u6536\u4EF6\u7BB1", tags: analysis?.tags || [] };
169
+ setTagText((values) => ({ ...values, [id]: item.tags.join("\uFF0C") }));
170
+ setPlan((p) => ({ ...p, groups: [...p.groups.map((g) => ({ ...g, sourceIds: g.sourceIds.filter((s) => s !== sourceId) })), item], unassigned: p.unassigned.filter((s) => s.sourceId !== sourceId) }));
171
+ }
172
+ function assign(sourceId, target) {
173
+ if (target === "__new__") {
174
+ newGroup(sourceId);
175
+ return;
176
+ }
177
+ const analysis = job.analyses?.find((a) => a.sourceId === sourceId);
178
+ setPlan((p) => ({
179
+ ...p,
180
+ groups: p.groups.map((g) => ({ ...g, sourceIds: g.id === target ? [...g.sourceIds.filter((id) => id !== sourceId), sourceId] : g.sourceIds.filter((id) => id !== sourceId) })),
181
+ unassigned: [...p.unassigned.filter((s) => s.sourceId !== sourceId), ...target ? [] : [{ sourceId, reason: analysis?.uncertainty || "\u6682\u7559\u5F85\u6574\u7406\uFF0C\u540E\u7EED\u518D\u5224\u65AD\u5173\u8054" }]]
182
+ }));
183
+ }
184
+ function removeGroup(id) {
185
+ setPlan((p) => ({ ...p, groups: p.groups.filter((g) => g.id !== id), unassigned: [...p.unassigned, ...(p.groups.find((g) => g.id === id)?.sourceIds || []).map((sourceId) => ({ sourceId, reason: "\u5DF2\u79FB\u51FA\u5206\u7EC4\uFF0C\u4FDD\u7559\u5F85\u6574\u7406" }))] }));
186
+ }
187
+ async function save(confirm, openSource) {
188
+ if (busy) return;
189
+ setBusy(true);
190
+ setError("");
191
+ try {
192
+ let currentVersion = version;
193
+ if (!locked) {
194
+ const value = { ...plan, applyClassification: apply2, groups: groups.map((g) => ({ ...g, tags: splitTags(tagText[g.id] || "") })) };
195
+ const edited = await post(`/knowledge/jobs/${job.id}/plan`, { expectedRoot: root, version, plan: value }, "PATCH");
196
+ currentVersion = edited.planVersion;
197
+ setVersion(currentVersion);
198
+ }
199
+ if (confirm) {
200
+ await post(`/knowledge/jobs/${job.id}/confirm-plan`, { expectedRoot: root, version: currentVersion, applyClassification: apply2, expectedModel: model.model, confirmed: true });
201
+ onNotify(`${groups.length} \u7EC4\u8D44\u6599\u5DF2\u63D0\u4EA4\u751F\u6210\u8349\u7A3F\uFF1B${plan.unassigned.length} \u4EFD\u4FDD\u7559\u5F85\u6574\u7406`);
202
+ onRefresh();
203
+ } else if (openSource) onOpenSource(openSource);
204
+ else {
205
+ onNotify("\u5206\u7EC4\u65B9\u6848\u5DF2\u4FDD\u5B58\uFF0C\u6765\u6E90\u5206\u7C7B\u5C1A\u672A\u4FEE\u6539");
206
+ onRefresh();
207
+ }
208
+ } catch (e) {
209
+ setError(e.message);
210
+ if (confirm) onRefresh();
211
+ } finally {
212
+ setBusy(false);
213
+ }
214
+ }
215
+ async function rollback() {
216
+ setBusy(true);
217
+ setError("");
218
+ try {
219
+ await post(`/knowledge/jobs/${job.id}/rollback-plan`, { expectedRoot: root, confirmed: true });
220
+ onNotify("\u672A\u5B8C\u6210\u7684\u5206\u7C7B\u4FEE\u6539\u5DF2\u56DE\u9000");
221
+ onRefresh();
222
+ } catch (e) {
223
+ setError(e.message);
224
+ onRefresh();
225
+ } finally {
226
+ setBusy(false);
227
+ }
228
+ }
229
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "kl-grouping-editor", children: [
230
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "kl-grouping-summary", children: [
231
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("b", { children: [
232
+ groups.length,
233
+ " \u4E2A\u5206\u7EC4"
234
+ ] }),
235
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { children: [
236
+ plan.unassigned.length,
237
+ " \u4EFD\u5F85\u6574\u7406"
238
+ ] })
239
+ ] }),
240
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "kl-knowledge-model", children: "\u5148\u6838\u5BF9\u9010\u7BC7\u5206\u6790\u4E0E\u5206\u7EC4\u7406\u7531\u3002\u65E0\u5173\u8054\u7684\u8D44\u6599\u53EF\u72EC\u7ACB\u6210\u7EC4\uFF0C\u4FE1\u606F\u4E0D\u8DB3\u7684\u8D44\u6599\u53EF\u4EE5\u7559\u5F85\u6574\u7406\u3002\u4FEE\u6539\u540E\u8BF7\u4FDD\u5B58\u65B9\u6848\uFF0C\u518D\u5173\u95ED\u7A97\u53E3\u3002" }),
241
+ job.error && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { role: "alert", className: "kl-form-error", children: job.error }),
242
+ locked && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "kl-grouping-recovery", role: "status", children: [
243
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("strong", { children: "\u4E0A\u6B21\u5F52\u7C7B\u5C1A\u672A\u5B8C\u6210" }),
244
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("p", { children: [
245
+ job.classification.steps.filter((s) => s.done).length,
246
+ " / ",
247
+ job.classification.steps.length,
248
+ " \u4EFD\u5DF2\u5B8C\u6210",
249
+ job.classification.direction === "rollback" ? "\u56DE\u9000" : "\u5F52\u7C7B",
250
+ "\u3002\u65B9\u6848\u5DF2\u9501\u5B9A\uFF0C\u53EF\u7EE7\u7EED\u5904\u7406\u6216\u56DE\u9000\u5DF2\u66F4\u6539\u7684\u5206\u7C7B\u3002"
251
+ ] }),
252
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "kl-secondary", disabled: busy, onClick: () => void rollback(), children: job.classification.direction === "rollback" ? "\u7EE7\u7EED\u56DE\u9000\u5206\u7C7B" : "\u56DE\u9000\u5DF2\u66F4\u6539\u7684\u5206\u7C7B" })
253
+ ] }),
254
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "kl-grouping-groups", children: plan.groups.map((group, index) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: "kl-grouping-group", "aria-label": `\u5206\u7EC4 ${index + 1}`, children: [
255
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "kl-grouping-group-title", children: [
256
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { children: [
257
+ "\u5206\u7EC4 ",
258
+ index + 1,
259
+ " \xB7 ",
260
+ group.sourceIds.length,
261
+ " \u4EFD\u8D44\u6599"
262
+ ] }),
263
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "kl-icon-button kl-danger", "aria-label": `\u5220\u9664\u5206\u7EC4 ${index + 1}`, disabled: busy || locked, onClick: () => removeGroup(group.id), children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Icon, { name: "trash", size: 15 }) })
264
+ ] }),
265
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { children: [
266
+ "\u5206\u7EC4\u540D\u79F0",
267
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("input", { "aria-label": `\u5206\u7EC4\u540D\u79F0 ${index + 1}`, maxLength: 200, value: group.title, disabled: busy || locked, onChange: (e) => groupValue(group.id, { title: e.target.value }) })
268
+ ] }),
269
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "kl-grouping-reason", children: group.reason }),
270
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("details", { className: "kl-grouping-settings", children: [
271
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("summary", { children: [
272
+ "\u5206\u7C7B\u4E0E\u5206\u7EC4\u8BBE\u7F6E ",
273
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: group.category })
274
+ ] }),
275
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { children: [
276
+ "\u5206\u7EC4\u7406\u7531",
277
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("textarea", { "aria-label": `\u5206\u7EC4\u7406\u7531 ${index + 1}`, rows: 2, maxLength: 1200, value: group.reason, disabled: busy || locked, onChange: (e) => groupValue(group.id, { reason: e.target.value }) })
278
+ ] }),
279
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "kl-knowledge-fields", children: [
280
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { children: [
281
+ "\u6765\u6E90\u5206\u7C7B",
282
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("input", { "aria-label": `\u6765\u6E90\u5206\u7C7B ${index + 1}`, value: group.category, maxLength: 180, disabled: busy || locked, onChange: (e) => groupValue(group.id, { category: e.target.value }) })
283
+ ] }),
284
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { children: [
285
+ "\u5206\u7EC4\u6807\u7B7E",
286
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("input", { "aria-label": `\u5206\u7EC4\u6807\u7B7E ${index + 1}`, value: tagText[group.id] || "", disabled: busy || locked, onChange: (e) => setTagText((v) => ({ ...v, [group.id]: e.target.value })) })
287
+ ] })
288
+ ] })
289
+ ] }),
290
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("ul", { children: group.sourceIds.map((id) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("li", { children: job.sources.find((s) => s.id === id)?.title }, id)) }),
291
+ !group.sourceIds.length && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "kl-muted", children: "\u6682\u65E0\u8D44\u6599\uFF0C\u4FDD\u5B58\u65F6\u4F1A\u5FFD\u7565\u7A7A\u5206\u7EC4\u3002" })
292
+ ] }, group.id)) }),
293
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("button", { className: "kl-secondary", disabled: busy || locked || plan.groups.length >= 10, onClick: () => newGroup(), children: [
294
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Icon, { name: "plus", size: 14 }),
295
+ "\u65B0\u589E\u5206\u7EC4"
296
+ ] }),
297
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h3", { className: "kl-grouping-section-title", children: "\u9010\u7BC7\u5206\u6790\u4E0E\u6210\u5458\u8C03\u6574" }),
298
+ job.sources.map((source) => {
299
+ const analysis = job.analyses?.find((a) => a.sourceId === source.id);
300
+ const unassigned = plan.unassigned.find((s) => s.sourceId === source.id);
301
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("article", { className: "kl-grouping-source", "aria-label": `${source.title} \u7684\u5206\u6790`, children: [
302
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "kl-grouping-source-title", children: [
303
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("strong", { children: source.title }),
304
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "kl-knowledge-badge", children: analysis?.certainty === "uncertain" ? "\u9700\u6838\u5BF9" : "\u4E3B\u9898\u5EFA\u8BAE" })
305
+ ] }),
306
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { children: analysis?.theme }),
307
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { children: [
308
+ "\u6240\u5C5E\u5206\u7EC4",
309
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("select", { "aria-label": `\u6240\u5C5E\u5206\u7EC4 ${source.title}`, value: plan.groups.find((g) => g.sourceIds.includes(source.id))?.id || "", disabled: busy || locked, onChange: (e) => assign(source.id, e.target.value), children: [
310
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: "", children: "\u4FDD\u7559\u5F85\u6574\u7406" }),
311
+ plan.groups.map((g) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: g.id, children: g.title || "\u672A\u547D\u540D\u5206\u7EC4" }, g.id)),
312
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: "__new__", children: "\u5355\u72EC\u6210\u7EC4" })
313
+ ] })
314
+ ] }),
315
+ unassigned && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { children: [
316
+ "\u5F85\u6574\u7406\u7406\u7531",
317
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("input", { "aria-label": `\u5F85\u6574\u7406\u7406\u7531 ${source.title}`, maxLength: 1200, value: unassigned.reason, disabled: busy || locked, onChange: (e) => setPlan((p) => ({ ...p, unassigned: p.unassigned.map((s) => s.sourceId === source.id ? { ...s, reason: e.target.value } : s) })) })
318
+ ] }),
319
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("details", { children: [
320
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("summary", { children: "\u5206\u6790\u8BE6\u60C5\u4E0E\u6765\u6E90" }),
321
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { children: analysis?.summary }),
322
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("p", { children: [
323
+ "\u7528\u9014\uFF1A",
324
+ analysis?.usage
325
+ ] }),
326
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("p", { children: [
327
+ "\u6982\u5FF5\uFF1A",
328
+ analysis?.concepts.join("\u3001")
329
+ ] }),
330
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("p", { children: [
331
+ "\u5EFA\u8BAE\u5206\u7C7B\uFF1A",
332
+ analysis?.category,
333
+ " \xB7 \u6807\u7B7E\uFF1A",
334
+ analysis?.tags.join("\u3001") || "\u65E0"
335
+ ] }),
336
+ analysis?.uncertainty && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("p", { children: [
337
+ "\u5F85\u6838\u5B9E\uFF1A",
338
+ analysis.uncertainty
339
+ ] }),
340
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("button", { className: "kl-secondary", disabled: busy || locked, onClick: () => void save(false, source.id), children: [
341
+ "\u4FDD\u5B58\u65B9\u6848\u5E76\u67E5\u770B\u6765\u6E90",
342
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Icon, { name: "arrow", size: 14 })
343
+ ] })
344
+ ] })
345
+ ] }, source.id);
346
+ }),
347
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { className: "kl-grouping-sync", children: [
348
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("input", { type: "checkbox", "aria-label": "\u540C\u6B65\u6765\u6E90\u5206\u7C7B\u548C\u6807\u7B7E", checked: apply2, disabled: busy || locked, onChange: (e) => setApply(e.target.checked) }),
349
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: "\u786E\u8BA4\u540E\u540C\u6B65\u6765\u6E90\u5206\u7C7B\u548C\u6807\u7B7E\u5230\u672C\u5730\u76EE\u5F55" })
350
+ ] }),
351
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "kl-knowledge-model", children: "\u540C\u6B65\u65F6\u4F1A\u79FB\u52A8\u5DF2\u5206\u7EC4\u8D44\u6599\u7684\u76EE\u5F55\u3001\u4FDD\u7559\u539F\u6807\u7B7E\u5E76\u6DFB\u52A0\u5206\u7EC4\u6807\u7B7E\uFF1B\u672A\u5206\u7EC4\u8D44\u6599\u4FDD\u6301\u5F85\u6574\u7406\u3002\u5173\u95ED\u540C\u6B65\u53EF\u53EA\u6309\u7EC4\u751F\u6210\u8349\u7A3F\u3002\u6BCF\u7EC4\u751F\u6210\u540E\u4ECD\u9700\u5355\u72EC\u786E\u8BA4\u4FDD\u5B58\u6B63\u5F0F\u7B14\u8BB0\u3002" }),
352
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("p", { className: "kl-knowledge-model", children: [
353
+ "\u751F\u6210\u8349\u7A3F\u4F7F\u7528\u6A21\u578B\uFF1A",
354
+ model.model || "\u5C1A\u672A\u914D\u7F6E",
355
+ "\u3002",
356
+ model.model !== job.model && `\u9010\u7BC7\u5206\u6790\u65F6\u4F7F\u7528\u7684\u662F ${job.model || "\u672A\u8BB0\u5F55\u6A21\u578B"}\u3002`,
357
+ "\u786E\u8BA4\u540E\u5C06\u7EE7\u7EED\u5411\u8BE5\u6A21\u578B\u53D1\u9001\u5404\u7EC4\u6B63\u6587\u53CA\u68C0\u7D22\u5230\u7684\u76F8\u5173\u77E5\u8BC6\u7B14\u8BB0\uFF0C\u7528\u4E8E\u751F\u6210\u8349\u7A3F\u548C\u5224\u65AD\u589E\u91CF\u8865\u5145\u3002\u672C\u6B21\u667A\u80FD\u6574\u7406\u53CA\u5176\u5B50\u4EFB\u52A1\u5408\u8BA1\u6700\u591A 80 \u6B21\u6A21\u578B\u8BF7\u6C42\uFF08\u5DF2\u4F7F\u7528 ",
358
+ job.modelCalls || 0,
359
+ " \u6B21\uFF09\uFF0C\u53EF\u80FD\u4EA7\u751F\u8C03\u7528\u8D39\u7528\u3002"
360
+ ] }),
361
+ !!groups.length && !model.available && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { role: "alert", className: "kl-form-error", children: model.reason || "\u8BF7\u5148\u914D\u7F6E\u751F\u6210\u6A21\u578B" }),
362
+ error && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { role: "alert", className: "kl-form-error", children: error }),
363
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("footer", { children: [
364
+ !locked && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "kl-secondary", disabled: busy, onClick: () => void save(false), children: "\u4FDD\u5B58\u5206\u7EC4\u65B9\u6848" }),
365
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "kl-primary", disabled: busy || !!groups.length && !model.available || job.classification?.direction === "rollback", onClick: () => void save(true), children: busy ? "\u6B63\u5728\u5904\u7406\u2026" : locked ? "\u7EE7\u7EED\u5F52\u7C7B\u5E76\u751F\u6210\u8349\u7A3F" : groups.length ? `\u786E\u8BA4${apply2 ? "\u5F52\u7C7B" : "\u5206\u7EC4"}\u5E76\u751F\u6210 ${groups.length} \u4EFD\u8349\u7A3F` : "\u786E\u8BA4\u4FDD\u7559\u5168\u90E8\u5F85\u6574\u7406" })
366
+ ] })
367
+ ] });
368
+ }
369
+
370
+ // src/ui/Knowledge.tsx
371
+ var import_jsx_runtime4 = require("react/jsx-runtime");
372
+ var stateLabels = { pending: "\u5F85\u6574\u7406", running: "\u6574\u7406\u4E2D", grouping: "\u5F85\u5206\u7EC4\u786E\u8BA4", draft: "\u5F85\u786E\u8BA4", completed: "\u5DF2\u6574\u7406", failed: "\u6574\u7406\u5931\u8D25" };
373
+ var jobLabels = { queued: "\u6392\u961F\u4E2D", running: "\u6574\u7406\u4E2D", grouping: "\u5F85\u5206\u7EC4\u786E\u8BA4", classifying: "\u5F52\u7C7B\u4E2D", grouped: "\u5DF2\u5206\u7EC4", draft: "\u5F85\u786E\u8BA4", completed: "\u5DF2\u4FDD\u5B58", failed: "\u5931\u8D25", cancelled: "\u5DF2\u53D6\u6D88", discarded: "\u5DF2\u820D\u5F03" };
374
+ function KnowledgeBadge({ state }) {
375
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: `kl-knowledge-badge ${state?.status || "pending"}`, children: stateLabels[state?.status || "pending"] });
376
+ }
377
+ function StartKnowledgeDialog({ root, sourceIds, model, initialMode, onClose, onCreated }) {
378
+ const [sources, setSources] = (0, import_react3.useState)();
379
+ const [topic, setTopic] = (0, import_react3.useState)("");
380
+ const [error, setError] = (0, import_react3.useState)("");
381
+ const [busy, setBusy] = (0, import_react3.useState)(false);
382
+ const [mode, setMode] = (0, import_react3.useState)(initialMode || (sourceIds.length > 1 ? "smart" : "compose"));
383
+ const smart = mode === "smart";
384
+ (0, import_react3.useEffect)(() => {
385
+ const abort = new AbortController();
386
+ void Promise.all(sourceIds.map((id) => api(`/materials/${id}`, { signal: abort.signal }))).then(setSources).catch((e) => {
387
+ if (!abort.signal.aborted) setError(e.message);
388
+ });
389
+ return () => abort.abort();
390
+ }, [sourceIds]);
391
+ const characters = sources?.reduce((sum, source) => sum + source.content.length, 0) || 0;
392
+ const invalidSource = sources?.some((s) => s.deletedAt || s.kind === "note" || s.status !== "ready");
393
+ async function start(event) {
394
+ event.preventDefault();
395
+ setBusy(true);
396
+ setError("");
397
+ try {
398
+ onCreated(await post("/knowledge/jobs", { expectedRoot: root, sourceIds, topic, mode }));
399
+ } catch (e) {
400
+ setError(e.message);
401
+ } finally {
402
+ setBusy(false);
403
+ }
404
+ }
405
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Dialog, { title: smart ? "\u667A\u80FD\u6574\u7406" : "\u751F\u6210\u77E5\u8BC6\u7B14\u8BB0", description: smart ? "\u5148\u9010\u7BC7\u5206\u6790\u3001\u5EFA\u8BAE\u5206\u7EC4\uFF0C\u518D\u786E\u8BA4\u5206\u7C7B\u4E0E\u751F\u6210\u5404\u7EC4\u77E5\u8BC6\u8349\u7A3F\u3002" : "\u5148\u63D0\u70BC\u8D44\u6599\uFF0C\u518D\u7531\u4F60\u786E\u8BA4\u3002\u539F\u59CB\u8D44\u6599\u4E0E\u6765\u6E90\u5F15\u7528\u4F1A\u4FDD\u7559\u3002", onClose: () => {
406
+ if (!busy) onClose();
407
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("form", { className: "kl-knowledge-form", onSubmit: (event) => void start(event), children: [
408
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "kl-knowledge-summary", children: [
409
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("b", { children: [
410
+ sourceIds.length,
411
+ " \u4EFD\u6765\u6E90\u8D44\u6599"
412
+ ] }),
413
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
414
+ characters.toLocaleString(),
415
+ " \u5B57"
416
+ ] })
417
+ ] }),
418
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { className: "kl-knowledge-source-list", children: sources?.map((s) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("li", { children: [
419
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "file", size: 14 }),
420
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: s.title })
421
+ ] }, s.id)) }),
422
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("fieldset", { className: "kl-knowledge-mode", children: [
423
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("legend", { children: "\u6574\u7406\u65B9\u5F0F" }),
424
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { children: [
425
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("input", { type: "radio", name: "knowledge-mode", value: "smart", checked: smart, disabled: !model.smartSupported || busy, onChange: () => setMode("smart") }),
426
+ "\u667A\u80FD\u5206\u7EC4",
427
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("small", { children: "\u9002\u5408\u96F6\u6563\u8D44\u6599\uFF0C\u5148\u5224\u65AD\u5173\u8054" })
428
+ ] }),
429
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { children: [
430
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("input", { type: "radio", name: "knowledge-mode", value: "compose", checked: !smart, disabled: busy, onChange: () => setMode("compose") }),
431
+ "\u540C\u4E3B\u9898\u76F4\u63A5\u7EFC\u5408",
432
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("small", { children: "\u5DF2\u786E\u8BA4\u56F4\u7ED5\u540C\u4E00\u95EE\u9898\u65F6\u4F7F\u7528" })
433
+ ] })
434
+ ] }),
435
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { children: [
436
+ smart ? "\u6574\u7406\u65B9\u5411\uFF08\u53EF\u9009\uFF09" : "\u6574\u7406\u4E3B\u9898",
437
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("input", { "aria-label": "\u6574\u7406\u4E3B\u9898", value: topic, onChange: (e) => setTopic(e.target.value), maxLength: 300, placeholder: smart ? "\u7559\u7A7A\u53EF\u6309\u8D44\u6599\u7684\u5B9E\u9645\u4E3B\u9898\u81EA\u52A8\u5206\u7EC4" : "\u4F8B\u5982\uFF1AHarness \u5982\u4F55\u63D0\u9AD8 Agent \u7684\u53EF\u9760\u6027" }),
438
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("small", { children: smart ? "\u65B9\u5411\u7528\u4E8E\u8F85\u52A9\u5224\u65AD\uFF0C\u4E0D\u4F1A\u8981\u6C42\u628A\u65E0\u5173\u8054\u8D44\u6599\u5408\u5E76\u3002" : "\u7559\u7A7A\u65F6\u56F4\u7ED5\u8D44\u6599\u672C\u8EAB\u6574\u7406\uFF1B\u591A\u7BC7\u8D44\u6599\u4F1A\u6BD4\u8F83\u5171\u8BC6\u3001\u5DEE\u5F02\u548C\u77DB\u76FE\u3002" })
439
+ ] }),
440
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "kl-muted", children: smart ? "\u9010\u7BC7\u63D0\u53D6\u4E3B\u9898\u3001\u6982\u5FF5\u4E0E\u7528\u9014\uFF0C\u7ED9\u51FA\u5206\u7EC4\u7406\u7531\u548C\u5206\u7C7B\u6807\u7B7E\u5EFA\u8BAE\u3002\u65E0\u5173\u8054\u8D44\u6599\u53EF\u72EC\u7ACB\u6210\u7EC4\uFF0C\u4FE1\u606F\u4E0D\u8DB3\u7684\u8D44\u6599\u4FDD\u7559\u5F85\u6574\u7406\u3002\u786E\u8BA4\u65B9\u6848\u524D\u4E0D\u79FB\u52A8\u8D44\u6599\u3002" : "\u5C06\u63D0\u70BC\u6838\u5FC3\u89C2\u70B9\u3001\u5173\u952E\u6982\u5FF5\u3001\u53EF\u590D\u7528\u65B9\u6CD5\u3001\u9002\u7528\u6761\u4EF6\u4E0E\u5C40\u9650\u3001\u5F85\u9A8C\u8BC1\u95EE\u9898\uFF0C\u5E76\u6807\u6CE8\u6765\u6E90\u6BB5\u843D\u3002" }),
441
+ smart && !model.smartSupported && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { role: "alert", className: "kl-form-error", children: "\u8BF7\u91CD\u542F\u8D44\u6599\u5E93\u670D\u52A1\u4EE5\u542F\u7528\u667A\u80FD\u5206\u7EC4\u3002" }),
442
+ model.available ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("p", { className: "kl-knowledge-model", children: [
443
+ "\u4F7F\u7528\u6A21\u578B\uFF1A",
444
+ model.model,
445
+ "\u3002\u70B9\u51FB\u5F00\u59CB\u540E\u4F1A\u5411\u8BE5\u6A21\u578B\u53D1\u9001\u6240\u9009\u6B63\u6587\u53CA\u68C0\u7D22\u5230\u7684\u76F8\u5173\u77E5\u8BC6\u7B14\u8BB0\uFF0C\u53EF\u80FD\u4EA7\u751F\u8C03\u7528\u8D39\u7528\u3002",
446
+ smart ? "\u9010\u7BC7\u5206\u6790\u548C\u5206\u7EC4\u6700\u591A 40 \u6B21\u8BF7\u6C42\uFF1B\u786E\u8BA4\u540E\u5404\u7EC4\u7EE7\u7EED\u751F\u6210\u8349\u7A3F\uFF0C\u6574\u6B21\u4EFB\u52A1\u5408\u8BA1\u6700\u591A 80 \u6B21\u3002" : "\u957F\u6587\u4F1A\u5206\u6BB5\u63D0\u70BC\uFF0C\u542B\u65E7\u7B14\u8BB0\u5BF9\u6BD4\u6700\u591A 22 \u6B21\u6A21\u578B\u8BF7\u6C42\u3002",
447
+ "\u5355\u6B21\u6700\u591A 10 \u4EFD\u3001\u6B63\u6587\u603B\u91CF 10 \u4E07\u5B57\u3002"
448
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { children: [
449
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { role: "alert", className: "kl-form-error", children: model.reason }),
450
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("a", { className: "kl-knowledge-help", href: "https://github.com/Alan-dong-dong/dsh-knowledge-library#\u5C06\u8D44\u6599\u6574\u7406\u4E3A\u77E5\u8BC6\u7B14\u8BB0", target: "_blank", rel: "noreferrer", children: [
451
+ "\u67E5\u770B\u6A21\u578B\u914D\u7F6E\u8BF4\u660E ",
452
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "arrow", size: 12 })
453
+ ] })
454
+ ] }),
455
+ characters > 1e5 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { role: "alert", className: "kl-form-error", children: "\u6B63\u6587\u8D85\u8FC7 10 \u4E07\u5B57\uFF0C\u8BF7\u51CF\u5C11\u9009\u62E9\u540E\u5206\u6279\u6574\u7406\u3002" }),
456
+ invalidSource && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { role: "alert", className: "kl-form-error", children: "\u90E8\u5206\u8D44\u6599\u5DF2\u5220\u9664\u3001\u4EC5\u5F52\u6863\u6216\u5C5E\u4E8E\u77E5\u8BC6\u7B14\u8BB0\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\u3002" }),
457
+ error && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { role: "alert", className: "kl-form-error", children: error }),
458
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("footer", { children: [
459
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: "kl-secondary", disabled: busy, onClick: onClose, children: "\u53D6\u6D88" }),
460
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { className: "kl-primary", disabled: busy || !sources || !model.available || smart && !model.smartSupported || characters > 1e5 || invalidSource, children: busy ? "\u6B63\u5728\u63D0\u4EA4\u2026" : smart ? "\u5F00\u59CB\u5206\u6790\u5206\u7EC4" : "\u5F00\u59CB\u6574\u7406" })
461
+ ] })
462
+ ] }) });
463
+ }
464
+ function KnowledgeJobsDialog(props) {
465
+ const { root, overview, onClose, onRefresh, onRegenerate, onOpenSource, onSaved, onNotify } = props;
466
+ const [selected, setSelected] = (0, import_react3.useState)(props.jobId);
467
+ const [error, setError] = (0, import_react3.useState)("");
468
+ const [busy, setBusy] = (0, import_react3.useState)(false);
469
+ const job = overview.jobs.find((j) => j.id === selected);
470
+ async function action(name) {
471
+ if (!job) return;
472
+ setBusy(true);
473
+ setError("");
474
+ try {
475
+ await post(`/knowledge/jobs/${job.id}/${name}`, { expectedRoot: root });
476
+ onRefresh();
477
+ } catch (e) {
478
+ setError(e.message);
479
+ } finally {
480
+ setBusy(false);
481
+ }
482
+ }
483
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Dialog, { title: job?.status === "draft" ? "\u786E\u8BA4\u77E5\u8BC6\u7B14\u8BB0" : job?.status === "grouping" ? "\u786E\u8BA4\u667A\u80FD\u5206\u7EC4" : "\u77E5\u8BC6\u6574\u7406", description: "\u5206\u6790\u3001\u5206\u7EC4\u65B9\u6848\u4E0E\u8349\u7A3F\u4FDD\u5B58\u5728\u672C\u5730\u3002\u6B63\u5F0F\u77E5\u8BC6\u7B14\u8BB0\u4ECD\u9700\u9010\u4EFD\u786E\u8BA4\u4FDD\u5B58\u3002", onClose: () => {
484
+ if (!busy) onClose();
485
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "kl-knowledge-jobs", children: [
486
+ !!selected && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { className: "kl-knowledge-back", onClick: () => {
487
+ setSelected(void 0);
488
+ setError("");
489
+ }, children: "\u2190 \u5168\u90E8\u6574\u7406\u4EFB\u52A1" }),
490
+ !overview.supported && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { role: "alert", className: "kl-form-error", children: overview.reason }),
491
+ error && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { role: "alert", className: "kl-form-error", children: error }),
492
+ !selected ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children: !overview.jobs.length ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "kl-knowledge-empty", children: [
493
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "note", size: 26 }),
494
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { children: "\u8FD8\u6CA1\u6709\u6574\u7406\u4EFB\u52A1" }),
495
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("small", { children: "\u6253\u5F00\u4E00\u4EFD\u8D44\u6599\u70B9\u51FB\u201C\u751F\u6210\u77E5\u8BC6\u7B14\u8BB0\u201D\uFF0C\u6216\u5728\u5217\u8868\u4E2D\u9009\u62E9\u201C\u667A\u80FD\u6574\u7406\u201D\u3002" })
496
+ ] }) : overview.jobs.map((item) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { className: "kl-knowledge-job", onClick: () => {
497
+ setSelected(item.id);
498
+ setError("");
499
+ }, children: [
500
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { children: [
501
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("strong", { children: item.topic || item.sources.map((s) => s.title).join("\u3001") }),
502
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: `kl-knowledge-badge ${item.status}`, children: jobLabels[item.status] })
503
+ ] }),
504
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("p", { children: [
505
+ item.mode === "smart" ? "\u667A\u80FD\u5206\u7EC4 \xB7 " : item.parentId ? "\u5206\u7EC4\u5B50\u4EFB\u52A1 \xB7 " : "",
506
+ item.sourceIds.length,
507
+ " \u4EFD\u6765\u6E90 \xB7 ",
508
+ new Date(item.updatedAt).toLocaleString("zh-CN")
509
+ ] }),
510
+ item.error && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("small", { children: item.error })
511
+ ] }, item.id)) }) : !job ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "kl-muted", children: "\u6B63\u5728\u8BFB\u53D6\u6574\u7406\u4EFB\u52A1\u2026" }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
512
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "kl-knowledge-job-heading", children: [
513
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("strong", { children: job.topic || job.sources.map((s) => s.title).join("\u3001") }),
514
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: `kl-knowledge-badge ${job.status}`, children: jobLabels[job.status] })
515
+ ] }),
516
+ job.status === "grouping" && job.plan ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(GroupingEditor, { root, job, model: overview, onRefresh, onOpenSource, onNotify }, `${job.id}:${job.planVersion}`) : job.status === "draft" && job.draft ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(DraftEditor, { root, job, onRefresh, onOpenSource, onSaved, onNotify }, `${job.id}:${job.draftVersion}`) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
517
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("p", { className: "kl-knowledge-progress", role: "status", children: [
518
+ ["queued", "running"].includes(job.status) && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "kl-spinner" }),
519
+ job.progress
520
+ ] }),
521
+ job.error && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { role: "alert", className: "kl-form-error", children: job.error }),
522
+ job.model && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("p", { className: "kl-muted", children: [
523
+ "\u6A21\u578B\uFF1A",
524
+ job.model
525
+ ] }),
526
+ job.status === "completed" && job.noteId && (job.sourceIds.some((id) => overview.states[id]?.noteIds.includes(job.noteId)) ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { className: "kl-primary", onClick: () => onOpenSource(job.noteId), children: "\u6253\u5F00\u77E5\u8BC6\u7B14\u8BB0" }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "kl-muted", children: "\u5173\u8054\u7B14\u8BB0\u5DF2\u79FB\u5165\u56DE\u6536\u7AD9\u6216\u6C38\u4E45\u5220\u9664\uFF0C\u53EF\u6062\u590D\u7B14\u8BB0\u6216\u91CD\u65B0\u6574\u7406\u3002" })),
527
+ job.status === "grouped" && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "kl-grouping-children", children: [
528
+ job.children?.map((child) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { className: "kl-knowledge-job", onClick: () => setSelected(child.jobId), children: [
529
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { children: [
530
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("strong", { children: job.plan?.groups.find((g) => g.id === child.groupId)?.title || "\u5206\u7EC4\u8349\u7A3F" }),
531
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "kl-knowledge-badge", children: jobLabels[overview.jobs.find((j) => j.id === child.jobId)?.status || "queued"] })
532
+ ] }),
533
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { children: "\u6253\u5F00\u672C\u7EC4\u4EFB\u52A1\uFF0C\u5355\u72EC\u6838\u5BF9\u5E76\u4FDD\u5B58\u77E5\u8BC6\u7B14\u8BB0" })
534
+ ] }, child.jobId)),
535
+ !!job.plan?.unassigned.length && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "kl-grouping-pending", children: [
536
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("strong", { children: "\u4FDD\u7559\u5F85\u6574\u7406" }),
537
+ job.plan.unassigned.map((item) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("p", { children: [
538
+ job.sources.find((s) => s.id === item.sourceId)?.title,
539
+ "\uFF1A",
540
+ item.reason
541
+ ] }, item.sourceId))
542
+ ] })
543
+ ] })
544
+ ] }),
545
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "kl-knowledge-actions", children: [
546
+ ["queued", "running"].includes(job.status) && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { className: "kl-secondary", disabled: busy, onClick: () => void action("cancel"), children: "\u53D6\u6D88\u6574\u7406" }),
547
+ ["draft", "failed", "grouping"].includes(job.status) && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { className: "kl-secondary kl-danger", disabled: busy || !!job.classification, onClick: () => void action("discard"), children: [
548
+ "\u820D\u5F03",
549
+ job.status === "draft" ? "\u8349\u7A3F" : job.status === "grouping" ? "\u65B9\u6848" : "\u4EFB\u52A1"
550
+ ] }),
551
+ ["failed", "cancelled", "discarded", "completed"].includes(job.status) && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { className: "kl-secondary", onClick: () => onRegenerate(job.sourceIds, job.mode), children: "\u91CD\u65B0\u6574\u7406" })
552
+ ] })
553
+ ] })
554
+ ] }) });
555
+ }
556
+ function DraftEditor({ root, job, onRefresh, onOpenSource, onSaved, onNotify }) {
557
+ const [draft, setDraft] = (0, import_react3.useState)(job.draft);
558
+ const [integration, setIntegration] = (0, import_react3.useState)(job.integration);
559
+ const [version, setVersion] = (0, import_react3.useState)(job.draftVersion);
560
+ const [tags, setTags] = (0, import_react3.useState)(draft.tags.join("\uFF0C"));
561
+ const [category, setCategory] = (0, import_react3.useState)(draft.category || "\u77E5\u8BC6\u7B14\u8BB0");
562
+ const [busy, setBusy] = (0, import_react3.useState)(false);
563
+ const [error, setError] = (0, import_react3.useState)("");
564
+ async function save(confirm, source) {
565
+ if (busy) return;
566
+ setBusy(true);
567
+ setError("");
568
+ try {
569
+ const edited = await post(`/knowledge/jobs/${job.id}`, { expectedRoot: root, version, draft: { ...draft, category, tags: tags.split(/[,,]/).map((t) => t.trim()).filter(Boolean) }, ...integration ? { integration: { choice: integration.choice, content: integration.content } } : {} }, "PATCH");
570
+ setVersion(edited.draftVersion);
571
+ if (confirm) {
572
+ const result = await post(`/knowledge/jobs/${job.id}/confirm`, { expectedRoot: root, version: edited.draftVersion, category, confirmed: true, integrationChoice: integration?.choice });
573
+ onSaved(result.material.id);
574
+ } else if (source) onOpenSource(source.id, source.segment);
575
+ else {
576
+ onNotify("\u8349\u7A3F\u5DF2\u4FDD\u5B58\uFF0C\u6B63\u5F0F\u77E5\u8BC6\u7B14\u8BB0\u5C1A\u672A\u4FEE\u6539");
577
+ onRefresh();
578
+ }
579
+ } catch (e) {
580
+ setError(e.message);
581
+ } finally {
582
+ setBusy(false);
583
+ }
584
+ }
585
+ const updating = integration?.choice === "append" || integration?.choice === "duplicate";
586
+ const confirmText = integration?.choice === "append" ? "\u786E\u8BA4\u8865\u5145\u5DF2\u6709\u7B14\u8BB0" : integration?.choice === "duplicate" ? "\u786E\u8BA4\u4EC5\u5173\u8054\u6765\u6E90" : "\u786E\u8BA4\u4FDD\u5B58\u7B14\u8BB0";
587
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("form", { className: "kl-knowledge-draft", onSubmit: (e) => {
588
+ e.preventDefault();
589
+ void save(true);
590
+ }, children: [
591
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "kl-knowledge-model", children: "\u8FD9\u662F\u6A21\u578B\u751F\u6210\u7684\u8349\u7A3F\uFF0C\u8BF7\u6838\u5BF9\u7406\u89E3\u4E0E\u8BC1\u636E\u3002\u4FEE\u6539\u540E\u8BF7\u4FDD\u5B58\u8349\u7A3F\uFF0C\u518D\u5173\u95ED\u7A97\u53E3\u3002" }),
592
+ integration && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("section", { className: "kl-note-integration", "aria-label": "\u5DF2\u6709\u77E5\u8BC6\u5BF9\u6BD4", children: [
593
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("strong", { children: [
594
+ "\u5EFA\u8BAE",
595
+ integration.recommendation === "append" ? "\u8865\u5145\u5DF2\u6709\u7B14\u8BB0" : integration.recommendation === "duplicate" ? "\u4EC5\u5173\u8054\u5DF2\u6709\u7B14\u8BB0" : "\u65B0\u5EFA\u7B14\u8BB0"
596
+ ] }),
597
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { children: integration.reason }),
598
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("p", { className: "kl-knowledge-model", children: [
599
+ "\u68C0\u7D22\u4E86 ",
600
+ integration.search.scanned,
601
+ " \u4EFD\u6709\u6548\u7B14\u8BB0\uFF0C\u627E\u5230 ",
602
+ integration.search.matched,
603
+ " \u4EFD\u8BCD\u9762\u76F8\u5173\u7B14\u8BB0\uFF0C\u672C\u6B21\u5B8C\u6574\u5BF9\u6BD4 ",
604
+ integration.search.compared,
605
+ " \u4EFD\uFF08\u6700\u591A 5 \u4EFD\uFF09\u3002",
606
+ integration.search.oversized > 0 && `${integration.search.oversized} \u4EFD\u8D85\u8FC7\u5BF9\u6BD4\u957F\u5EA6\u4E0A\u9650\u3002`,
607
+ "\u672A\u5339\u914D\u4E0D\u4EE3\u8868\u6574\u5E93\u6CA1\u6709\u76F8\u5173\u77E5\u8BC6\u3002"
608
+ ] }),
609
+ [["overlaps", "\u91CD\u590D\u5185\u5BB9"], ["additions", "\u65B0\u589E\u77E5\u8BC6"], ["conflicts", "\u5DEE\u5F02\u4E0E\u5F85\u6838\u5B9E"]].map(([key, title]) => !!integration[key].length && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "kl-integration-findings", children: [
610
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: title }),
611
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { children: integration[key].map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("li", { children: item }, index)) })
612
+ ] }, key)),
613
+ integration.target && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
614
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("p", { className: "kl-integration-target", children: [
615
+ integration.target.title,
616
+ " \xB7 ",
617
+ integration.target.category,
618
+ " \xB7 \u7248\u672C ",
619
+ integration.target.revision
620
+ ] }),
621
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("fieldset", { className: "kl-knowledge-mode", children: [
622
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("legend", { children: "\u672C\u6B21\u5982\u4F55\u4FDD\u5B58" }),
623
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { children: [
624
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("input", { type: "radio", name: "integration-choice", "aria-label": integration.recommendation === "duplicate" ? "\u4EC5\u5173\u8054\u5DF2\u6709\u7B14\u8BB0" : "\u8865\u5145\u5DF2\u6709\u7B14\u8BB0", checked: updating, onChange: () => setIntegration({ ...integration, choice: integration.recommendation }) }),
625
+ integration.recommendation === "duplicate" ? "\u4EC5\u5173\u8054\u6765\u6E90\uFF0C\u4E0D\u91CD\u590D\u6B63\u6587" : "\u8FFD\u52A0\u8865\u5145\u5230\u5DF2\u6709\u7B14\u8BB0"
626
+ ] }),
627
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { children: [
628
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("input", { type: "radio", name: "integration-choice", "aria-label": "\u53E6\u5B58\u4E3A\u65B0\u7B14\u8BB0", checked: !updating, onChange: () => setIntegration({ ...integration, choice: "new" }) }),
629
+ "\u53E6\u5B58\u4E3A\u65B0\u7B14\u8BB0"
630
+ ] })
631
+ ] }),
632
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("details", { children: [
633
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("summary", { children: "\u67E5\u770B\u5DF2\u6709\u7B14\u8BB0\u539F\u6587" }),
634
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("pre", { className: "kl-integration-preview", children: integration.target.content }),
635
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { type: "button", className: "kl-secondary", disabled: busy, onClick: () => void save(false, { id: integration.target.id }), children: [
636
+ "\u4FDD\u5B58\u8349\u7A3F\u5E76\u6253\u5F00\u5DF2\u6709\u7B14\u8BB0",
637
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "arrow", size: 14 })
638
+ ] })
639
+ ] })
640
+ ] })
641
+ ] }),
642
+ updating ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
643
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "kl-knowledge-model", children: "\u786E\u8BA4\u540E\u4FDD\u7559\u5DF2\u6709\u6807\u9898\u3001\u5206\u7C7B\u3001\u6B63\u6587\u4E0E\u65E7\u6BB5\u843D\u5F15\u7528\uFF0C\u5408\u5E76\u65B0\u6765\u6E90\u548C\u6807\u7B7E\u3002\u66F4\u65B0\u524D\u540E\u5FEB\u7167\u4FDD\u5B58\u5728\u672C\u5730\uFF1B\u5BA1\u6838\u671F\u95F4\u7B14\u8BB0\u53D8\u5316\u4F1A\u8981\u6C42\u91CD\u65B0\u6838\u5BF9\u3002" }),
644
+ integration?.choice === "append" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
645
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { children: [
646
+ "\u672C\u6B21\u65B0\u589E\u6B63\u6587",
647
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("textarea", { "aria-label": "\u672C\u6B21\u65B0\u589E\u6B63\u6587", required: true, rows: 12, maxLength: 5e4, value: integration.content, onChange: (e) => setIntegration({ ...integration, content: e.target.value }) })
648
+ ] }),
649
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("details", { children: [
650
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("summary", { children: "\u66F4\u65B0\u540E\u6B63\u6587\u9884\u89C8" }),
651
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("pre", { className: "kl-integration-preview", children: [
652
+ integration.target.content,
653
+ "\n\n## \u77E5\u8BC6\u8865\u5145 \xB7 " + (/* @__PURE__ */ new Date()).toISOString().slice(0, 10) + "\n\n" + integration.content
654
+ ] })
655
+ ] })
656
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "kl-muted", children: "\u672C\u6B21\u6CA1\u6709\u9700\u8981\u65B0\u589E\u7684\u6B63\u6587\u3002\u786E\u8BA4\u540E\u53EA\u628A\u8FD9\u4E9B\u6765\u6E90\u5173\u8054\u5230\u5DF2\u6709\u7B14\u8BB0\uFF0C\u4ECD\u4FDD\u7559\u5BF9\u6BD4\u7406\u7531\u4F9B\u6838\u67E5\u3002" })
657
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
658
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { children: [
659
+ "\u7B14\u8BB0\u6807\u9898",
660
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("input", { "aria-label": "\u7B14\u8BB0\u6807\u9898", required: true, maxLength: 300, value: draft.title, onChange: (e) => setDraft({ ...draft, title: e.target.value }) })
661
+ ] }),
662
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { children: [
663
+ "\u7B14\u8BB0\u6B63\u6587",
664
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("textarea", { "aria-label": "\u7B14\u8BB0\u6B63\u6587", required: true, rows: 14, maxLength: 5e4, value: draft.content, onChange: (e) => setDraft({ ...draft, content: e.target.value }) })
665
+ ] }),
666
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { children: [
667
+ "\u7B14\u8BB0\u5206\u7C7B",
668
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("input", { "aria-label": "\u7B14\u8BB0\u5206\u7C7B", value: category, onChange: (e) => setCategory(e.target.value), maxLength: 180 })
669
+ ] })
670
+ ] }),
671
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { children: [
672
+ updating ? "\u65B0\u589E\u6807\u7B7E" : "\u6807\u7B7E",
673
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("input", { "aria-label": "\u7B14\u8BB0\u6807\u7B7E", value: tags, onChange: (e) => setTags(e.target.value), placeholder: "\u9017\u53F7\u5206\u9694" })
674
+ ] }),
675
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("details", { className: "kl-knowledge-citations", children: [
676
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("summary", { children: [
677
+ draft.citations.length,
678
+ " \u6761\u6765\u6E90\u5F15\u7528"
679
+ ] }),
680
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { children: "\u67E5\u770B\u6765\u6E90\u524D\u4F1A\u5148\u4FDD\u5B58\u5F53\u524D\u8349\u7A3F\u3002" }),
681
+ draft.citations.map((citation, index) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { type: "button", disabled: busy, onClick: () => void save(false, { id: citation.materialId, segment: citation.segmentId }), children: [
682
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "file", size: 14 }),
683
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
684
+ job.sources.find((s) => s.id === citation.materialId)?.title,
685
+ " / ",
686
+ citation.segmentId
687
+ ] }),
688
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "arrow", size: 14 })
689
+ ] }, index))
690
+ ] }),
691
+ error && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { role: "alert", className: "kl-form-error", children: error }),
692
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("footer", { children: [
693
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: "kl-secondary", disabled: busy, onClick: () => void save(false), children: "\u4FDD\u5B58\u8349\u7A3F" }),
694
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { className: "kl-primary", disabled: busy, children: busy ? "\u6B63\u5728\u4FDD\u5B58\u2026" : confirmText })
695
+ ] })
696
+ ] });
697
+ }
698
+
699
+ // src/ui/App.tsx
700
+ var import_jsx_runtime5 = require("react/jsx-runtime");
84
701
  var kinds = {
85
702
  web: { label: "\u7F51\u9875", icon: "web" },
86
703
  text: { label: "\u6587\u672C", icon: "file" },
@@ -91,39 +708,41 @@ var kinds = {
91
708
  };
92
709
  var time = (v) => `${String(Math.floor(v / 3600)).padStart(2, "0")}:${String(Math.floor(v / 60) % 60).padStart(2, "0")}:${String(Math.floor(v) % 60).padStart(2, "0")}`;
93
710
  var date = (value) => new Intl.DateTimeFormat("zh-CN", { month: "2-digit", day: "2-digit" }).format(new Date(value));
94
- async function api(path, options = {}) {
95
- const response = await fetch(API + path, { ...options, headers: { "Content-Type": "application/json", "X-Knowledge-Library": "1", ...options.headers } });
96
- const data = await response.json();
97
- if (!response.ok) throw new Error(data.error || `\u8BF7\u6C42\u5931\u8D25\uFF1A${response.status}`);
98
- return data;
99
- }
100
- var post = (path, value, method = "POST") => api(path, { method, body: JSON.stringify(value) });
101
- function splitTags(value) {
711
+ function splitTags2(value) {
102
712
  return value.split(/[,,]/).map((v) => v.trim()).filter(Boolean);
103
713
  }
104
714
  function App() {
105
- const [stats, setStats] = (0, import_react.useState)();
106
- const [items, setItems] = (0, import_react.useState)([]);
107
- const [total, setTotal] = (0, import_react.useState)(0);
108
- const [query, setQuery] = (0, import_react.useState)("");
109
- const [filter, setFilter] = (0, import_react.useState)({});
110
- const [selected, setSelected] = (0, import_react.useState)();
111
- const [detail, setDetail] = (0, import_react.useState)();
112
- const [anchor, setAnchor] = (0, import_react.useState)();
113
- const [editor, setEditor] = (0, import_react.useState)();
114
- const [jobs, setJobs] = (0, import_react.useState)([]);
115
- const [showJobs, setShowJobs] = (0, import_react.useState)(false);
116
- const [showInfo, setShowInfo] = (0, import_react.useState)(false);
117
- const [showNavigation, setShowNavigation] = (0, import_react.useState)(false);
118
- const [error, setError] = (0, import_react.useState)("");
119
- const [toast, setToast] = (0, import_react.useState)("");
120
- const [loading, setLoading] = (0, import_react.useState)(true);
121
- const [detailLoading, setDetailLoading] = (0, import_react.useState)(false);
122
- const [revision, setRevision] = (0, import_react.useState)(0);
123
- const [limit, setLimit] = (0, import_react.useState)(40);
124
- const searchRef = (0, import_react.useRef)(null);
125
- const detailRef = (0, import_react.useRef)(null);
126
- const refresh = (0, import_react.useCallback)(() => setRevision((v) => v + 1), []);
715
+ const [stats, setStats] = (0, import_react4.useState)();
716
+ const [items, setItems] = (0, import_react4.useState)([]);
717
+ const [total, setTotal] = (0, import_react4.useState)(0);
718
+ const [query, setQuery] = (0, import_react4.useState)("");
719
+ const [filter, setFilter] = (0, import_react4.useState)({});
720
+ const [selected, setSelected] = (0, import_react4.useState)();
721
+ const [detail, setDetail] = (0, import_react4.useState)();
722
+ const [anchor, setAnchor] = (0, import_react4.useState)();
723
+ const [editor, setEditor] = (0, import_react4.useState)();
724
+ const [deletion, setDeletion] = (0, import_react4.useState)();
725
+ const [restoring, setRestoring] = (0, import_react4.useState)();
726
+ const [emptyRoot, setEmptyRoot] = (0, import_react4.useState)();
727
+ const [jobs, setJobs] = (0, import_react4.useState)([]);
728
+ const [knowledge, setKnowledge] = (0, import_react4.useState)();
729
+ const [batchMode, setBatchMode] = (0, import_react4.useState)(false);
730
+ const [checkedIds, setCheckedIds] = (0, import_react4.useState)([]);
731
+ const [generation, setGeneration] = (0, import_react4.useState)();
732
+ const [knowledgeOpen, setKnowledgeOpen] = (0, import_react4.useState)();
733
+ const [showJobs, setShowJobs] = (0, import_react4.useState)(false);
734
+ const [showInfo, setShowInfo] = (0, import_react4.useState)(false);
735
+ const [settingsFromJobs, setSettingsFromJobs] = (0, import_react4.useState)(false);
736
+ const [showNavigation, setShowNavigation] = (0, import_react4.useState)(false);
737
+ const [error, setError] = (0, import_react4.useState)("");
738
+ const [toast, setToast] = (0, import_react4.useState)("");
739
+ const [loading, setLoading] = (0, import_react4.useState)(true);
740
+ const [detailLoading, setDetailLoading] = (0, import_react4.useState)(false);
741
+ const [revision, setRevision] = (0, import_react4.useState)(0);
742
+ const [limit, setLimit] = (0, import_react4.useState)(40);
743
+ const searchRef = (0, import_react4.useRef)(null);
744
+ const detailRef = (0, import_react4.useRef)(null);
745
+ const refresh = (0, import_react4.useCallback)(() => setRevision((v) => v + 1), []);
127
746
  const notify = (message) => setToast(message);
128
747
  const chooseFilter = (next) => {
129
748
  setFilter(next);
@@ -132,16 +751,25 @@ function App() {
132
751
  setAnchor(void 0);
133
752
  setDetail(void 0);
134
753
  setShowNavigation(false);
754
+ setBatchMode(false);
755
+ setCheckedIds([]);
135
756
  };
136
- const refreshMeta = (0, import_react.useCallback)(async () => {
137
- const [s, j] = await Promise.all([api("/stats"), api("/jobs")]);
757
+ const refreshMeta = (0, import_react4.useCallback)(async () => {
758
+ const [s, j, k] = await Promise.all([api("/stats"), api("/jobs"), api("/knowledge").catch((e) => {
759
+ if (e instanceof ApiError && e.status === 404) return { supported: false, available: false, reason: "\u8BF7\u91CD\u542F\u8D44\u6599\u5E93\u670D\u52A1\u4EE5\u542F\u7528\u77E5\u8BC6\u6574\u7406\u3002", jobs: [], states: {} };
760
+ throw e;
761
+ })]);
138
762
  setStats(s);
139
763
  setJobs(j);
764
+ setKnowledge(k);
140
765
  }, []);
141
- (0, import_react.useEffect)(() => {
766
+ (0, import_react4.useEffect)(() => {
767
+ setCheckedIds([]);
768
+ }, [query]);
769
+ (0, import_react4.useEffect)(() => {
142
770
  void refreshMeta().catch((e) => setError(e.message));
143
771
  }, [revision, refreshMeta]);
144
- (0, import_react.useEffect)(() => {
772
+ (0, import_react4.useEffect)(() => {
145
773
  const controller = new AbortController();
146
774
  const timer = setTimeout(() => {
147
775
  setLoading(true);
@@ -161,7 +789,7 @@ function App() {
161
789
  controller.abort();
162
790
  };
163
791
  }, [query, filter, revision, limit]);
164
- (0, import_react.useEffect)(() => {
792
+ (0, import_react4.useEffect)(() => {
165
793
  if (!selected) {
166
794
  setDetail(void 0);
167
795
  return;
@@ -176,23 +804,25 @@ function App() {
176
804
  });
177
805
  return () => controller.abort();
178
806
  }, [selected, revision]);
179
- (0, import_react.useEffect)(() => {
807
+ (0, import_react4.useEffect)(() => {
180
808
  if (!detail || !anchor) return;
181
809
  const element = Array.from(detailRef.current?.querySelectorAll("[data-segment-id]") || []).find((el) => el.dataset.segmentId === anchor);
182
810
  element?.scrollIntoView({ block: "center" });
183
811
  }, [detail, anchor]);
184
812
  const pending = jobs.filter((j) => ["queued", "running"].includes(j.status)).length;
185
- (0, import_react.useEffect)(() => {
186
- if (!pending) return;
813
+ const knowledgePending = knowledge?.jobs.filter((j) => ["queued", "running"].includes(j.status)).length || 0;
814
+ const draftCount = knowledge?.jobs.filter((j) => ["draft", "grouping"].includes(j.status)).length || 0;
815
+ (0, import_react4.useEffect)(() => {
816
+ if (!pending && !knowledgePending) return;
187
817
  const interval = setInterval(refresh, 2500);
188
818
  return () => clearInterval(interval);
189
- }, [pending, refresh]);
190
- (0, import_react.useEffect)(() => {
819
+ }, [pending, knowledgePending, refresh]);
820
+ (0, import_react4.useEffect)(() => {
191
821
  if (!toast) return;
192
822
  const timer = setTimeout(() => setToast(""), 3500);
193
823
  return () => clearTimeout(timer);
194
824
  }, [toast]);
195
- (0, import_react.useEffect)(() => {
825
+ (0, import_react4.useEffect)(() => {
196
826
  const listener = (event) => {
197
827
  if ((event.ctrlKey || event.metaKey) && event.key === "k") {
198
828
  event.preventDefault();
@@ -210,223 +840,330 @@ function App() {
210
840
  setError("\u526A\u8D34\u677F\u4E0D\u53EF\u7528\uFF0C\u8BF7\u4ECE\u8D44\u6599\u8BE6\u60C5\u624B\u52A8\u590D\u5236\u8D44\u6599 ID");
211
841
  }
212
842
  }
213
- const currentTitle = filter.category || filter.collection || (filter.tag ? `\u6807\u7B7E \xB7 ${filter.tag}` : filter.kind === "note" ? "\u77E5\u8BC6\u7B14\u8BB0" : "\u5168\u90E8\u8D44\u6599");
214
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-app", children: [
215
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("main", { className: "kl-workspace", children: [
216
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("header", { className: "kl-header", children: [
217
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h1", { children: currentTitle }),
218
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-header-actions", children: [
219
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { className: "kl-secondary", onClick: () => setEditor({ mode: "note" }), children: [
220
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "note", size: 16 }),
843
+ function askDelete(item) {
844
+ if (stats) setDeletion({ id: item.id, title: item.title, root: stats.root });
845
+ }
846
+ function afterRemoval(id, message) {
847
+ if (selected === id) {
848
+ setSelected(void 0);
849
+ setDetail(void 0);
850
+ setAnchor(void 0);
851
+ }
852
+ refresh();
853
+ notify(message);
854
+ searchRef.current?.focus();
855
+ }
856
+ async function restoreItem(id) {
857
+ if (!stats || restoring) return;
858
+ setRestoring(id);
859
+ try {
860
+ await post(`/materials/${id}/restore`, { expectedRoot: stats.root });
861
+ afterRemoval(id, "\u8D44\u6599\u5DF2\u6062\u590D\u5230\u539F\u5206\u7C7B");
862
+ } catch (e) {
863
+ setError(e.message);
864
+ } finally {
865
+ setRestoring(void 0);
866
+ }
867
+ }
868
+ function openKnowledgeSource(id, segmentId) {
869
+ setKnowledgeOpen(void 0);
870
+ chooseFilter({});
871
+ setQuery("");
872
+ setSelected(id);
873
+ setAnchor(segmentId);
874
+ refresh();
875
+ }
876
+ function generateFor(ids, mode) {
877
+ if (stats) setGeneration({ root: stats.root, sourceIds: ids, mode });
878
+ }
879
+ const currentTitle = filter.trashed ? "\u56DE\u6536\u7AD9" : filter.category || filter.collection || (filter.tag ? `\u6807\u7B7E \xB7 ${filter.tag}` : filter.kind === "note" ? "\u77E5\u8BC6\u7B14\u8BB0" : "\u5168\u90E8\u8D44\u6599");
880
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-app", children: [
881
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("main", { className: "kl-workspace", children: [
882
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("header", { className: "kl-header", children: [
883
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h1", { children: currentTitle }),
884
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-header-actions", children: [
885
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { className: "kl-secondary", onClick: () => setEditor({ mode: "note" }), children: [
886
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "note", size: 16 }),
221
887
  "\u5199\u7B14\u8BB0"
222
888
  ] }),
223
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { className: "kl-primary", onClick: () => setEditor({ mode: "capture" }), children: [
224
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "plus", size: 16 }),
889
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { className: "kl-primary", onClick: () => setEditor({ mode: "capture" }), children: [
890
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "plus", size: 16 }),
225
891
  "\u6536\u96C6\u8D44\u6599"
226
892
  ] })
227
893
  ] })
228
894
  ] }),
229
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-navigation", children: [
230
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("nav", { "aria-label": "\u8D44\u6599\u5BFC\u822A", children: [
231
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { "aria-pressed": !Object.values(filter).some(Boolean), onClick: () => chooseFilter({}), children: "\u5168\u90E8\u8D44\u6599" }),
232
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { "aria-pressed": filter.category === "\u6536\u4EF6\u7BB1", onClick: () => chooseFilter({ category: "\u6536\u4EF6\u7BB1" }), children: "\u6536\u4EF6\u7BB1" }),
233
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { "aria-pressed": filter.kind === "note", onClick: () => chooseFilter({ kind: "note" }), children: "\u77E5\u8BC6\u7B14\u8BB0" })
895
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-navigation", children: [
896
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("nav", { "aria-label": "\u8D44\u6599\u5BFC\u822A", children: [
897
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { "aria-pressed": !Object.values(filter).some(Boolean), onClick: () => chooseFilter({}), children: "\u5168\u90E8\u8D44\u6599" }),
898
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { "aria-pressed": filter.category === "\u6536\u4EF6\u7BB1", onClick: () => chooseFilter({ category: "\u6536\u4EF6\u7BB1" }), children: "\u6536\u4EF6\u7BB1" }),
899
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { "aria-pressed": filter.kind === "note", onClick: () => chooseFilter({ kind: "note" }), children: "\u77E5\u8BC6\u7B14\u8BB0" }),
900
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { "aria-pressed": filter.trashed === "1", onClick: () => chooseFilter({ trashed: "1" }), children: "\u56DE\u6536\u7AD9" })
234
901
  ] }),
235
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { className: "kl-directory-toggle", "aria-expanded": showNavigation, "aria-controls": "kl-directory", onClick: () => setShowNavigation((v) => !v), children: [
236
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "folder", size: 16 }),
902
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { className: "kl-directory-toggle", "aria-expanded": showNavigation, "aria-controls": "kl-directory", onClick: () => setShowNavigation((v) => !v), children: [
903
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "folder", size: 16 }),
237
904
  "\u5206\u7C7B\u4E0E\u4E13\u9898"
238
905
  ] })
239
906
  ] }),
240
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-toolbar", children: [
241
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { className: "kl-search", children: [
242
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "search", size: 19 }),
243
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { ref: searchRef, "aria-label": "\u641C\u7D22\u8D44\u6599", placeholder: "\u641C\u7D22\u6B63\u6587\u3001\u6807\u9898\u3001\u6807\u7B7E\u2026", value: query, onChange: (e) => {
907
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-toolbar", children: [
908
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "kl-search", children: [
909
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "search", size: 19 }),
910
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("input", { ref: searchRef, "aria-label": "\u641C\u7D22\u8D44\u6599", placeholder: "\u641C\u7D22\u6B63\u6587\u3001\u6807\u9898\u3001\u6807\u7B7E\u2026", value: query, onChange: (e) => {
244
911
  setQuery(e.target.value);
245
912
  setLimit(40);
246
913
  } }),
247
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("kbd", { children: "Ctrl K" })
914
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("kbd", { children: "Ctrl K" })
248
915
  ] }),
249
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { "aria-label": pending ? `\u91C7\u96C6\u4EFB\u52A1\uFF0C${pending} \u9879\u5904\u7406\u4E2D` : "\u91C7\u96C6\u4EFB\u52A1", className: `kl-job-button ${pending ? "has-jobs" : ""}`, onClick: () => setShowJobs(true), children: [
250
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "clock", size: 17 }),
251
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: pending ? `${pending} \u9879\u5904\u7406\u4E2D` : "\u91C7\u96C6\u4EFB\u52A1" }),
252
- jobs.some((j) => j.status === "failed") && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("i", {})
916
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { "aria-label": pending ? `\u91C7\u96C6\u4EFB\u52A1\uFF0C${pending} \u9879\u5904\u7406\u4E2D` : "\u91C7\u96C6\u4EFB\u52A1", className: `kl-job-button ${pending ? "has-jobs" : ""}`, onClick: () => setShowJobs(true), children: [
917
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "clock", size: 17 }),
918
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: pending ? `${pending} \u9879\u5904\u7406\u4E2D` : "\u91C7\u96C6\u4EFB\u52A1" }),
919
+ jobs.some((j) => j.status === "failed") && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("i", {})
253
920
  ] }),
254
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { className: "kl-icon-button", "aria-label": "\u8D44\u6599\u5E93\u8BBE\u7F6E", title: "\u8D44\u6599\u5E93\u8BBE\u7F6E", onClick: () => setShowInfo(true), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "settings", size: 18 }) })
921
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { "aria-label": "\u77E5\u8BC6\u6574\u7406", title: "\u77E5\u8BC6\u6574\u7406", className: `kl-job-button ${knowledgePending || draftCount ? "has-jobs" : ""}`, onClick: () => {
922
+ refresh();
923
+ if (stats) setKnowledgeOpen({ root: stats.root });
924
+ }, children: [
925
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "note", size: 17 }),
926
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: draftCount ? `${draftCount} \u4EFD\u5F85\u786E\u8BA4` : "\u77E5\u8BC6\u6574\u7406" }),
927
+ !!knowledgePending && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "kl-spinner" })
928
+ ] }),
929
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: "kl-icon-button", "aria-label": "\u8D44\u6599\u5E93\u8BBE\u7F6E", title: "\u8D44\u6599\u5E93\u8BBE\u7F6E", onClick: () => {
930
+ setSettingsFromJobs(false);
931
+ setShowInfo(true);
932
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "settings", size: 18 }) })
255
933
  ] }),
256
- !!error && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-error", role: "alert", children: [
257
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: error }),
258
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { "aria-label": "\u5173\u95ED\u9519\u8BEF", onClick: () => setError(""), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "close", size: 16 }) })
934
+ !!error && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-error", role: "alert", children: [
935
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: error }),
936
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { "aria-label": "\u5173\u95ED\u9519\u8BEF", onClick: () => setError(""), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "close", size: 16 }) })
259
937
  ] }),
260
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-filterbar", children: [
261
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
262
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("b", { children: total }),
938
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-filterbar", children: [
939
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { children: [
940
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("b", { children: total }),
263
941
  " \u4EFD\u8D44\u6599",
264
942
  query && ` \xB7 \u201C${query}\u201D`
265
943
  ] }),
266
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
267
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("select", { "aria-label": "\u6309\u7C7B\u578B\u7B5B\u9009", value: filter.kind || "", onChange: (e) => {
944
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
945
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("select", { "aria-label": "\u6309\u7C7B\u578B\u7B5B\u9009", value: filter.kind || "", onChange: (e) => {
268
946
  setFilter({ ...filter, kind: e.target.value || void 0 });
269
947
  setLimit(40);
270
948
  }, children: [
271
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "", children: "\u6240\u6709\u7C7B\u578B" }),
272
- Object.entries(kinds).map(([value, kind]) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value, children: kind.label }, value))
949
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "", children: "\u6240\u6709\u7C7B\u578B" }),
950
+ Object.entries(kinds).map(([value, kind]) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value, children: kind.label }, value))
273
951
  ] }),
274
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "kl-sort-label", children: "\u6700\u8FD1\u66F4\u65B0 \u2193" })
952
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "kl-sort-label", children: "\u6700\u8FD1\u66F4\u65B0 \u2193" })
275
953
  ] })
276
954
  ] }),
277
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: `kl-body ${detail || detailLoading ? "with-detail" : ""}`, children: [
278
- showNavigation && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("aside", { className: "kl-nav", id: "kl-directory", "aria-label": "\u5206\u7C7B\u4E0E\u4E13\u9898", children: [
279
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-directory-title", children: [
280
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: "\u5206\u7C7B\u4E0E\u4E13\u9898" }),
281
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { className: "kl-icon-button", "aria-label": "\u5173\u95ED\u5206\u7C7B\u5BFC\u822A", onClick: () => setShowNavigation(false), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "close", size: 16 }) })
955
+ filter.trashed && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-trash-toolbar", children: [
956
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: stats?.canEmptyTrash ? stats.purgePending ? `${stats.purgePending} \u4EFD\u8D44\u6599\u7684\u6587\u4EF6\u6E05\u7406\u672A\u5B8C\u6210\uFF0C\u53EF\u518D\u6B21\u6E05\u7A7A\u4EE5\u91CD\u8BD5\u3002` : "\u6E05\u7A7A\u5C06\u6C38\u4E45\u5220\u9664\u6574\u4E2A\u56DE\u6536\u7AD9\uFF0C\u4E0D\u53D7\u5F53\u524D\u641C\u7D22\u548C\u7C7B\u578B\u7B5B\u9009\u9650\u5236\u3002" : "\u8BF7\u91CD\u542F\u8D44\u6599\u5E93\u670D\u52A1\u4EE5\u542F\u7528\u6E05\u7A7A\u56DE\u6536\u7AD9\u3002" }),
957
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { className: "kl-secondary kl-danger", disabled: !stats?.canEmptyTrash || !(stats.trashed || stats.purgePending) || !!restoring, onClick: () => stats && setEmptyRoot(stats.root), children: [
958
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "trash", size: 15 }),
959
+ "\u6E05\u7A7A\u56DE\u6536\u7AD9"
960
+ ] })
961
+ ] }),
962
+ !filter.trashed && filter.kind !== "note" && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-knowledge-toolbar", children: [
963
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: batchMode ? `\u5DF2\u9009\u62E9 ${checkedIds.length} / 10 \u4EFD\u8D44\u6599\uFF1B\u5207\u6362\u641C\u7D22\u6216\u5206\u7C7B\u4F1A\u6E05\u9664\u9009\u62E9\u3002` : knowledge?.smartSupported ? "\u96F6\u6563\u8D44\u6599\u5148\u667A\u80FD\u5206\u7EC4\uFF0C\u518D\u6309\u7EC4\u5F62\u6210\u77E5\u8BC6\u7B14\u8BB0\u3002" : "\u8BF7\u91CD\u542F\u8D44\u6599\u5E93\u670D\u52A1\u4EE5\u542F\u7528\u667A\u80FD\u5206\u7EC4\u3002" }),
964
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
965
+ batchMode && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: "kl-primary", disabled: !checkedIds.length || !knowledge?.smartSupported, onClick: () => generateFor(checkedIds, "smart"), children: "\u667A\u80FD\u5206\u6790\u5206\u7EC4" }),
966
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: "kl-secondary", disabled: !knowledge?.smartSupported, onClick: () => {
967
+ setBatchMode(!batchMode);
968
+ setCheckedIds([]);
969
+ }, children: batchMode ? "\u53D6\u6D88\u9009\u62E9" : "\u667A\u80FD\u6574\u7406" })
970
+ ] })
971
+ ] }),
972
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: `kl-body ${detail || detailLoading ? "with-detail" : ""}`, children: [
973
+ showNavigation && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("aside", { className: "kl-nav", id: "kl-directory", "aria-label": "\u5206\u7C7B\u4E0E\u4E13\u9898", children: [
974
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-directory-title", children: [
975
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "\u5206\u7C7B\u4E0E\u4E13\u9898" }),
976
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: "kl-icon-button", "aria-label": "\u5173\u95ED\u5206\u7C7B\u5BFC\u822A", onClick: () => setShowNavigation(false), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "close", size: 16 }) })
282
977
  ] }),
283
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-nav-section", children: [
284
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "kl-nav-label", children: "\u5206\u7C7B" }),
285
- stats?.categories.filter((c) => c.name !== "\u6536\u4EF6\u7BB1").map((c) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { "aria-pressed": filter.category === c.name, className: "kl-nav-row", onClick: () => chooseFilter({ category: c.name }), children: [
286
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "folder", size: 16 }),
287
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { title: c.name, children: c.name }),
288
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("small", { children: c.count })
978
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-nav-section", children: [
979
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "kl-nav-label", children: "\u5206\u7C7B" }),
980
+ stats?.categories.filter((c) => c.name !== "\u6536\u4EF6\u7BB1").map((c) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { "aria-pressed": filter.category === c.name, className: "kl-nav-row", onClick: () => chooseFilter({ category: c.name }), children: [
981
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "folder", size: 16 }),
982
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { title: c.name, children: c.name }),
983
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("small", { children: c.count })
289
984
  ] }, c.name)),
290
- !stats?.categories.some((c) => c.name !== "\u6536\u4EF6\u7BB1") && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "kl-nav-hint", children: "\u6536\u96C6\u8D44\u6599\u65F6\u6DFB\u52A0\u5206\u7C7B" })
985
+ !stats?.categories.some((c) => c.name !== "\u6536\u4EF6\u7BB1") && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "kl-nav-hint", children: "\u6536\u96C6\u8D44\u6599\u65F6\u6DFB\u52A0\u5206\u7C7B" })
291
986
  ] }),
292
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-nav-section", children: [
293
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "kl-nav-label", children: "\u4E13\u9898" }),
294
- stats?.collections.map((c) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { "aria-pressed": filter.collection === c.name, className: "kl-nav-row", onClick: () => chooseFilter({ collection: c.name }), children: [
295
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "kl-collection-dot" }),
296
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { title: c.name, children: c.name }),
297
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("small", { children: c.count })
987
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-nav-section", children: [
988
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "kl-nav-label", children: "\u4E13\u9898" }),
989
+ stats?.collections.map((c) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { "aria-pressed": filter.collection === c.name, className: "kl-nav-row", onClick: () => chooseFilter({ collection: c.name }), children: [
990
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "kl-collection-dot" }),
991
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { title: c.name, children: c.name }),
992
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("small", { children: c.count })
298
993
  ] }, c.name)),
299
- !stats?.collections.length && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "kl-nav-hint", children: "\u6536\u96C6\u8D44\u6599\u65F6\u6DFB\u52A0\u4E13\u9898" })
994
+ !stats?.collections.length && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "kl-nav-hint", children: "\u6536\u96C6\u8D44\u6599\u65F6\u6DFB\u52A0\u4E13\u9898" })
300
995
  ] }),
301
- !!stats?.tags.length && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-nav-section", children: [
302
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "kl-nav-label", children: "\u6807\u7B7E" }),
303
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "kl-tag-cloud", children: stats.tags.slice(0, 15).map((tag) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { "aria-pressed": filter.tag === tag.name, onClick: () => chooseFilter({ tag: tag.name }), children: [
996
+ !!stats?.tags.length && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-nav-section", children: [
997
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "kl-nav-label", children: "\u6807\u7B7E" }),
998
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "kl-tag-cloud", children: stats.tags.slice(0, 15).map((tag) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { "aria-pressed": filter.tag === tag.name, onClick: () => chooseFilter({ tag: tag.name }), children: [
304
999
  "#",
305
1000
  tag.name
306
1001
  ] }, tag.name)) })
307
1002
  ] }),
308
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-nav-bottom", children: [
309
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "kl-live-dot" }),
1003
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-nav-bottom", children: [
1004
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "kl-live-dot" }),
310
1005
  "\u4FDD\u5B58\u5728\u8FD9\u53F0\u7535\u8111"
311
1006
  ] })
312
1007
  ] }),
313
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("section", { className: "kl-list", "aria-label": "\u8D44\u6599\u5217\u8868", "aria-busy": loading, children: [
314
- loading && !items.length ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-empty", children: [
315
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "kl-spinner" }),
1008
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { className: "kl-list", "aria-label": "\u8D44\u6599\u5217\u8868", "aria-busy": loading, children: [
1009
+ loading && !items.length ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-empty", children: [
1010
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "kl-spinner" }),
316
1011
  "\u6B63\u5728\u8BFB\u53D6\u8D44\u6599\u5E93\u2026"
317
- ] }) : !items.length ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-empty", children: [
318
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "inbox", size: 28 }),
319
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h2", { children: query || Object.values(filter).some(Boolean) ? "\u6CA1\u6709\u627E\u5230\u5339\u914D\u7684\u8D44\u6599" : "\u8FD8\u6CA1\u6709\u8D44\u6599\uFF0C\u6536\u96C6\u7684\u5185\u5BB9\u4F1A\u663E\u793A\u5728\u8FD9\u91CC" }),
320
- query && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { children: "\u8BD5\u8BD5\u5176\u4ED6\u5173\u952E\u8BCD\uFF0C\u6216\u5207\u6362\u5206\u7C7B\u3002" }),
321
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { className: "kl-secondary", onClick: () => query || Object.values(filter).some(Boolean) ? (setQuery(""), chooseFilter({})) : setEditor({ mode: "capture" }), children: query || Object.values(filter).some(Boolean) ? "\u67E5\u770B\u5168\u90E8\u8D44\u6599" : "\u6536\u96C6\u7B2C\u4E00\u4EFD\u8D44\u6599" })
322
- ] }) : items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { className: `kl-item ${selected === item.id ? "selected" : ""}`, onClick: () => {
323
- setAnchor(void 0);
324
- setSelected(item.id);
325
- }, children: [
326
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-item-top", children: [
327
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: `kl-type kl-type-${item.kind}`, children: [
328
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: kinds[item.kind].icon, size: 15 }),
329
- kinds[item.kind].label
1012
+ ] }) : !items.length ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-empty", children: [
1013
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: filter.trashed ? "trash" : "inbox", size: 28 }),
1014
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h2", { children: filter.trashed ? "\u56DE\u6536\u7AD9\u4E2D\u6CA1\u6709\u5339\u914D\u7684\u8D44\u6599" : query || Object.values(filter).some(Boolean) ? "\u6CA1\u6709\u627E\u5230\u5339\u914D\u7684\u8D44\u6599" : "\u8FD8\u6CA1\u6709\u8D44\u6599\uFF0C\u6536\u96C6\u7684\u5185\u5BB9\u4F1A\u663E\u793A\u5728\u8FD9\u91CC" }),
1015
+ query && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: "\u8BD5\u8BD5\u5176\u4ED6\u5173\u952E\u8BCD\uFF0C\u6216\u5207\u6362\u5206\u7C7B\u3002" }),
1016
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: "kl-secondary", onClick: () => query || Object.values(filter).some(Boolean) ? (setQuery(""), chooseFilter({})) : setEditor({ mode: "capture" }), children: query || Object.values(filter).some(Boolean) ? "\u67E5\u770B\u5168\u90E8\u8D44\u6599" : "\u6536\u96C6\u7B2C\u4E00\u4EFD\u8D44\u6599" })
1017
+ ] }) : items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: `kl-item-row ${batchMode ? "kl-selectable" : ""}`, children: [
1018
+ batchMode && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("input", { type: "checkbox", className: "kl-material-checkbox", "aria-label": `\u9009\u62E9 ${item.title}`, checked: checkedIds.includes(item.id), disabled: item.kind === "note" || item.status !== "ready" || !!checkedIds.length && checkedIds.length >= 10 && !checkedIds.includes(item.id), onChange: (e) => setCheckedIds((ids) => e.target.checked ? [...ids, item.id] : ids.filter((id) => id !== item.id)) }),
1019
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { className: `kl-item ${selected === item.id ? "selected" : ""}`, onClick: () => {
1020
+ setAnchor(void 0);
1021
+ setSelected(item.id);
1022
+ }, children: [
1023
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-item-top", children: [
1024
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: `kl-type kl-type-${item.kind}`, children: [
1025
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: kinds[item.kind].icon, size: 15 }),
1026
+ kinds[item.kind].label
1027
+ ] }),
1028
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("time", { children: date(item.createdAt) })
330
1029
  ] }),
331
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("time", { children: date(item.createdAt) })
1030
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h2", { children: item.title }),
1031
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: item.excerpt || item.extraction }),
1032
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-item-bottom", children: [
1033
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "kl-category", children: [
1034
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "folder", size: 13 }),
1035
+ item.category
1036
+ ] }),
1037
+ item.tags.slice(0, 2).map((tag) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "kl-chip", children: tag }, tag)),
1038
+ item.status === "stored" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "kl-stored", children: "\u4EC5\u5F52\u6863" }),
1039
+ !item.deletedAt && item.kind !== "note" && item.status === "ready" && knowledge?.supported && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(KnowledgeBadge, { state: knowledge.states[item.id] }),
1040
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "arrow", size: 15 })
1041
+ ] })
332
1042
  ] }),
333
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h2", { children: item.title }),
334
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { children: item.excerpt || item.extraction }),
335
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-item-bottom", children: [
336
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "kl-category", children: [
337
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "folder", size: 13 }),
338
- item.category
339
- ] }),
340
- item.tags.slice(0, 2).map((tag) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "kl-chip", children: tag }, tag)),
341
- item.status === "stored" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "kl-stored", children: "\u4EC5\u5F52\u6863" }),
342
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "arrow", size: 15 })
343
- ] })
1043
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: `kl-icon-button kl-row-action ${item.deletedAt ? "" : "kl-danger"}`, title: item.deletedAt ? "\u6062\u590D\u8D44\u6599" : "\u5220\u9664\u8D44\u6599", "aria-label": `${item.deletedAt ? "\u6062\u590D" : "\u5220\u9664"} ${item.title}`, disabled: !stats || !!restoring, onClick: () => item.deletedAt ? void restoreItem(item.id) : askDelete(item), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: item.deletedAt ? "restore" : "trash", size: 16 }) })
344
1044
  ] }, item.id)),
345
- items.length < total && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { className: "kl-load-more", onClick: () => setLimit((v) => Math.min(100, v + 40)), disabled: limit >= 100, children: limit >= 100 ? "\u8BF7\u7F29\u5C0F\u641C\u7D22\u8303\u56F4\uFF08\u6700\u591A\u663E\u793A 100 \u6761\uFF09" : "\u52A0\u8F7D\u66F4\u591A" })
1045
+ items.length < total && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: "kl-load-more", onClick: () => setLimit((v) => Math.min(100, v + 40)), disabled: limit >= 100, children: limit >= 100 ? "\u8BF7\u7F29\u5C0F\u641C\u7D22\u8303\u56F4\uFF08\u6700\u591A\u663E\u793A 100 \u6761\uFF09" : "\u52A0\u8F7D\u66F4\u591A" })
346
1046
  ] }),
347
- selected && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("section", { className: "kl-detail", "aria-label": "\u8D44\u6599\u8BE6\u60C5", ref: detailRef, children: [
348
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-detail-toolbar", children: [
349
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { className: "kl-back", onClick: () => {
1047
+ selected && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { className: "kl-detail", "aria-label": "\u8D44\u6599\u8BE6\u60C5", ref: detailRef, children: [
1048
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-detail-toolbar", children: [
1049
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { className: "kl-back", onClick: () => {
350
1050
  setSelected(void 0);
351
1051
  setDetail(void 0);
352
1052
  }, children: [
353
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "close", size: 18 }),
354
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: "\u5173\u95ED\u9605\u8BFB" })
1053
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "close", size: 18 }),
1054
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "\u5173\u95ED\u9605\u8BFB" })
355
1055
  ] }),
356
- detail && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
357
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { title: "\u590D\u5236\u8D44\u6599\u5F15\u7528", "aria-label": "\u590D\u5236\u8D44\u6599\u5F15\u7528", onClick: () => void copy(`library://${detail.id}`), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "copy", size: 17 }) }),
358
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", { title: "\u5BFC\u51FA Markdown", "aria-label": "\u5BFC\u51FA Markdown", href: `${API}/materials/${detail.id}/export`, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "download", size: 17 }) }),
359
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { onClick: () => setEditor({ mode: "edit", source: detail }), children: "\u7F16\u8F91\u4FE1\u606F" })
1056
+ detail && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
1057
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { title: "\u590D\u5236\u8D44\u6599\u5F15\u7528", "aria-label": "\u590D\u5236\u8D44\u6599\u5F15\u7528", onClick: () => void copy(`library://${detail.id}`), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "copy", size: 17 }) }),
1058
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("a", { title: "\u5BFC\u51FA Markdown", "aria-label": "\u5BFC\u51FA Markdown", href: `${API}/materials/${detail.id}/export`, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "download", size: 17 }) }),
1059
+ detail.deletedAt ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { disabled: !stats || !!restoring, onClick: () => void restoreItem(detail.id), children: [
1060
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "restore", size: 16 }),
1061
+ "\u6062\u590D\u8D44\u6599"
1062
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
1063
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { onClick: () => setEditor({ mode: "edit", source: detail }), children: "\u7F16\u8F91\u4FE1\u606F" }),
1064
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: "kl-danger", title: "\u5220\u9664\u8D44\u6599", "aria-label": "\u5220\u9664\u8D44\u6599", disabled: !stats || !!restoring, onClick: () => askDelete(detail), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "trash", size: 17 }) })
1065
+ ] })
360
1066
  ] })
361
1067
  ] }),
362
- detailLoading ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-empty", children: [
363
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "kl-spinner" }),
1068
+ detailLoading ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-empty", children: [
1069
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "kl-spinner" }),
364
1070
  "\u8BFB\u53D6\u4E2D\u2026"
365
- ] }) : detail && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("article", { children: [
366
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-detail-kicker", children: [
367
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: kinds[detail.kind].label }),
368
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: detail.category })
1071
+ ] }) : detail && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("article", { children: [
1072
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-detail-kicker", children: [
1073
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: kinds[detail.kind].label }),
1074
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: detail.category })
369
1075
  ] }),
370
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h2", { children: detail.title }),
371
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-source", children: [
372
- detail.sourceUrl ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("a", { href: detail.sourceUrl, target: "_blank", rel: "noreferrer", children: [
1076
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h2", { children: detail.title }),
1077
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-source", children: [
1078
+ detail.sourceUrl ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("a", { href: detail.sourceUrl, target: "_blank", rel: "noreferrer", children: [
373
1079
  new URL(detail.sourceUrl).hostname,
374
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "arrow", size: 12 })
375
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: detail.originalName || "\u672C\u5730\u6536\u96C6" }),
376
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: new Date(detail.createdAt).toLocaleDateString("zh-CN") }),
377
- detail.author && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: detail.author })
1080
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "arrow", size: 12 })
1081
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: detail.originalName || "\u672C\u5730\u6536\u96C6" }),
1082
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: new Date(detail.createdAt).toLocaleDateString("zh-CN") }),
1083
+ detail.author && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: detail.author })
378
1084
  ] }),
379
- !!detail.tags.length && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "kl-detail-tags", children: detail.tags.map((t) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "kl-chip", children: [
1085
+ !!detail.tags.length && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "kl-detail-tags", children: detail.tags.map((t) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "kl-chip", children: [
380
1086
  "#",
381
1087
  t
382
1088
  ] }, t)) }),
383
- detail.sourceNote && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("aside", { className: "kl-source-note", children: detail.sourceNote }),
384
- detail.status === "stored" && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-notice", children: [
385
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "file" }),
386
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
387
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("strong", { children: "\u539F\u6587\u4EF6\u5DF2\u5B89\u5168\u5F52\u6863" }),
388
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { children: detail.extraction })
1089
+ detail.sourceNote && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("aside", { className: "kl-source-note", children: detail.sourceNote }),
1090
+ detail.deletedAt && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-notice", children: [
1091
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "trash" }),
1092
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
1093
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: "\u8FD9\u4EFD\u8D44\u6599\u5728\u56DE\u6536\u7AD9" }),
1094
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: "\u539F\u6587\u4E0E\u6765\u6E90\u5F15\u7528\u4ECD\u53EF\u67E5\u770B\uFF0C\u6062\u590D\u540E\u56DE\u5230\u539F\u5206\u7C7B\u3002" })
389
1095
  ] })
390
1096
  ] }),
391
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "kl-content", children: detail.segments.map((segment) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: `kl-segment ${anchor === segment.id ? "kl-cited" : ""}`, id: segment.id, "data-segment-id": segment.id, children: [
392
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-segment-line", children: [
393
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: segment.startSeconds !== void 0 ? time(segment.startSeconds) : segment.id }),
394
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { title: "\u6458\u5F55\u4E3A\u7B14\u8BB0", "aria-label": `\u6458\u5F55 ${segment.id} \u4E3A\u7B14\u8BB0`, onClick: () => setEditor({ mode: "note", source: detail, segment }), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "note", size: 14 }) }),
395
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { title: "\u590D\u5236\u6BB5\u843D\u5F15\u7528", "aria-label": `\u590D\u5236 ${segment.id} \u5F15\u7528`, onClick: () => void copy(`library://${detail.id}/${segment.id}`), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "copy", size: 14 }) })
1097
+ detail.status === "stored" && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-notice", children: [
1098
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "file" }),
1099
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
1100
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: "\u539F\u6587\u4EF6\u5DF2\u5B89\u5168\u5F52\u6863" }),
1101
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: detail.extraction })
1102
+ ] })
1103
+ ] }),
1104
+ !detail.deletedAt && detail.kind !== "note" && detail.status === "ready" && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-knowledge-source", children: [
1105
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
1106
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(KnowledgeBadge, { state: knowledge?.states[detail.id] }),
1107
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "\u4ECE\u8FD9\u4EFD\u8D44\u6599\u5F62\u6210\u7406\u89E3\u3001\u65B9\u6CD5\u4E0E\u5F85\u9A8C\u8BC1\u7684\u95EE\u9898\u3002" })
1108
+ ] }),
1109
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-knowledge-actions", children: [
1110
+ ["running", "draft", "grouping"].includes(knowledge?.states[detail.id]?.status || "") ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: "kl-secondary", onClick: () => stats && setKnowledgeOpen({ root: stats.root, jobId: knowledge?.states[detail.id]?.jobId }), children: knowledge?.states[detail.id]?.status === "grouping" ? "\u67E5\u770B\u5206\u7EC4\u65B9\u6848" : "\u67E5\u770B\u6574\u7406\u4EFB\u52A1" }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: "kl-secondary", disabled: !knowledge?.supported, onClick: () => generateFor([detail.id]), children: "\u751F\u6210\u77E5\u8BC6\u7B14\u8BB0" }),
1111
+ knowledge?.states[detail.id]?.noteIds.map((id) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { className: "kl-secondary", onClick: () => openKnowledgeSource(id), children: [
1112
+ "\u67E5\u770B\u77E5\u8BC6\u7B14\u8BB0",
1113
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "arrow", size: 14 })
1114
+ ] }, id))
396
1115
  ] }),
397
- /^#{1,6}\s/.test(segment.text) ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h3", { children: segment.text.replace(/^#{1,6}\s+/, "") }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { children: segment.text })
1116
+ !knowledge?.supported && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "kl-muted", children: "\u8BF7\u91CD\u542F\u8D44\u6599\u5E93\u670D\u52A1\u4EE5\u542F\u7528\u77E5\u8BC6\u6574\u7406\u3002" })
1117
+ ] }),
1118
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "kl-content", children: detail.segments.map((segment) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: `kl-segment ${anchor === segment.id ? "kl-cited" : ""}`, id: segment.id, "data-segment-id": segment.id, children: [
1119
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-segment-line", children: [
1120
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: segment.startSeconds !== void 0 ? time(segment.startSeconds) : segment.id }),
1121
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { title: "\u6458\u5F55\u4E3A\u7B14\u8BB0", "aria-label": `\u6458\u5F55 ${segment.id} \u4E3A\u7B14\u8BB0`, onClick: () => setEditor({ mode: "note", source: detail, segment }), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "note", size: 14 }) }),
1122
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { title: "\u590D\u5236\u6BB5\u843D\u5F15\u7528", "aria-label": `\u590D\u5236 ${segment.id} \u5F15\u7528`, onClick: () => void copy(`library://${detail.id}/${segment.id}`), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "copy", size: 14 }) })
1123
+ ] }),
1124
+ /^#{1,6}\s/.test(segment.text) ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h3", { children: segment.text.replace(/^#{1,6}\s+/, "") }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: segment.text })
398
1125
  ] }, segment.id)) }),
399
- !!detail.citations.length && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-references", children: [
400
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h3", { children: "\u6765\u6E90\u5F15\u7528" }),
401
- detail.citations.map((c, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { "aria-label": `\u67E5\u770B\u5F15\u7528 ${i + 1}`, onClick: () => {
1126
+ !!detail.citations.length && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-references", children: [
1127
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h3", { children: "\u6765\u6E90\u5F15\u7528" }),
1128
+ detail.citations.map((c, i) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { disabled: detail.missingSources?.includes(c.materialId), "aria-label": `\u67E5\u770B\u5F15\u7528 ${i + 1}`, onClick: () => {
402
1129
  setAnchor(c.segmentId);
403
1130
  setSelected(c.materialId);
404
1131
  }, children: [
405
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "file", size: 15 }),
406
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
407
- c.materialId.slice(0, 15),
408
- "\u2026",
409
- c.segmentId ? ` / ${c.segmentId}` : ""
410
- ] }),
411
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "arrow", size: 14 })
1132
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "file", size: 15 }),
1133
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: detail.missingSources?.includes(c.materialId) ? "\u6765\u6E90\u5DF2\u6C38\u4E45\u5220\u9664" : `${c.materialId.slice(0, 15)}\u2026${c.segmentId ? ` / ${c.segmentId}` : ""}` }),
1134
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "arrow", size: 14 })
412
1135
  ] }, i))
413
1136
  ] }),
414
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("footer", { className: "kl-detail-footer", children: [
415
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
416
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "kl-live-dot" }),
1137
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("footer", { className: "kl-detail-footer", children: [
1138
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
1139
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "kl-live-dot" }),
417
1140
  detail.extraction
418
1141
  ] }),
419
- detail.originalFile && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("a", { href: `${API}/materials/${detail.id}/original`, children: [
1142
+ detail.originalFile && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("a", { href: `${API}/materials/${detail.id}/original`, children: [
420
1143
  "\u4E0B\u8F7D\u539F\u59CB\u6587\u4EF6",
421
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "download", size: 14 })
1144
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "download", size: 14 })
422
1145
  ] }),
423
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("code", { children: detail.id })
1146
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("code", { children: detail.id })
424
1147
  ] })
425
1148
  ] })
426
1149
  ] })
427
1150
  ] })
428
1151
  ] }),
429
- editor && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(EditorDialog, { editor, categories: stats?.categories.map((c) => c.name) || [], onClose: () => setEditor(void 0), onSaved: (result) => {
1152
+ generation && knowledge && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(StartKnowledgeDialog, { root: generation.root, sourceIds: generation.sourceIds, model: knowledge, initialMode: generation.mode, onClose: () => setGeneration(void 0), onCreated: (job) => {
1153
+ setGeneration(void 0);
1154
+ setCheckedIds([]);
1155
+ setBatchMode(false);
1156
+ setKnowledgeOpen({ root: generation.root, jobId: job.id });
1157
+ refresh();
1158
+ } }),
1159
+ knowledgeOpen && knowledge && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(KnowledgeJobsDialog, { root: knowledgeOpen.root, jobId: knowledgeOpen.jobId, overview: knowledge, onClose: () => setKnowledgeOpen(void 0), onRefresh: refresh, onRegenerate: (ids, mode) => {
1160
+ setKnowledgeOpen(void 0);
1161
+ generateFor(ids, mode);
1162
+ }, onOpenSource: openKnowledgeSource, onSaved: (id) => {
1163
+ openKnowledgeSource(id);
1164
+ notify("\u77E5\u8BC6\u7B14\u8BB0\u5DF2\u4FDD\u5B58\uFF0C\u539F\u59CB\u8D44\u6599\u5DF2\u4FDD\u7559");
1165
+ }, onNotify: notify }),
1166
+ editor && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(EditorDialog, { editor, categories: stats?.categories.map((c) => c.name) || [], onClose: () => setEditor(void 0), onSaved: (result) => {
430
1167
  setEditor(void 0);
431
1168
  refresh();
432
1169
  if (result.material) {
@@ -442,107 +1179,357 @@ function App() {
442
1179
  notify("\u7F51\u9875\u5DF2\u52A0\u5165\u91C7\u96C6\u961F\u5217");
443
1180
  }
444
1181
  } }),
445
- showJobs && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Dialog, { title: "\u91C7\u96C6\u4EFB\u52A1", description: "\u7F51\u9875\u5728\u540E\u53F0\u63D0\u53D6\u6B63\u6587\u3002\u5173\u95ED\u5E94\u7528\u540E\uFF0C\u4E0B\u6B21\u542F\u52A8\u4F1A\u6062\u590D\u672A\u5B8C\u6210\u4EFB\u52A1\u3002", onClose: () => setShowJobs(false), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "kl-jobs", children: !jobs.length ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "kl-muted", children: "\u8FD8\u6CA1\u6709\u91C7\u96C6\u4EFB\u52A1\u3002\u6DFB\u52A0\u4E00\u4E2A\u7F51\u9875\u94FE\u63A5\u5F00\u59CB\u3002" }) : jobs.map((job) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-job", children: [
446
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
447
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: `kl-job-status ${job.status}`, children: { queued: "\u6392\u961F\u4E2D", running: "\u63D0\u53D6\u4E2D", completed: "\u5DF2\u5B8C\u6210", failed: "\u5931\u8D25" }[job.status] }),
448
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("time", { children: date(job.createdAt) })
1182
+ deletion && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(DeleteDialog, { item: deletion, onClose: () => setDeletion(void 0), onDeleted: () => {
1183
+ setDeletion(void 0);
1184
+ afterRemoval(deletion.id, "\u8D44\u6599\u5DF2\u79FB\u5165\u56DE\u6536\u7AD9\uFF0C\u53EF\u968F\u65F6\u6062\u590D");
1185
+ } }),
1186
+ emptyRoot && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(EmptyTrashDialog, { root: emptyRoot, onClose: () => setEmptyRoot(void 0), onEmptied: (result) => {
1187
+ setEmptyRoot(void 0);
1188
+ setSelected(void 0);
1189
+ setDetail(void 0);
1190
+ setAnchor(void 0);
1191
+ setError("");
1192
+ refresh();
1193
+ if (result.errors.length || result.pending) setError(`\u5DF2\u6C38\u4E45\u5220\u9664 ${result.deleted} \u4EFD\u8D44\u6599\uFF1B${result.pending} \u4EFD\u6587\u4EF6\u5F85\u6E05\u7406\u3002${result.errors.join("\uFF1B")}`);
1194
+ else notify(`\u56DE\u6536\u7AD9\u5DF2\u6E05\u7A7A\uFF0C\u6C38\u4E45\u5220\u9664 ${result.deleted} \u4EFD\u8D44\u6599`);
1195
+ searchRef.current?.focus();
1196
+ } }),
1197
+ showJobs && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Dialog, { title: "\u91C7\u96C6\u4EFB\u52A1", description: "\u7F51\u9875\u5728\u540E\u53F0\u63D0\u53D6\u6B63\u6587\u3002\u5173\u95ED\u5E94\u7528\u540E\uFF0C\u4E0B\u6B21\u542F\u52A8\u4F1A\u6062\u590D\u672A\u5B8C\u6210\u4EFB\u52A1\u3002", onClose: () => setShowJobs(false), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "kl-jobs", children: !jobs.length ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "kl-muted", children: "\u8FD8\u6CA1\u6709\u91C7\u96C6\u4EFB\u52A1\u3002\u6DFB\u52A0\u4E00\u4E2A\u7F51\u9875\u94FE\u63A5\u5F00\u59CB\u3002" }) : jobs.map((job) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-job", children: [
1198
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
1199
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: `kl-job-status ${job.status}`, children: job.status === "failed" && job.errorCode === "PAGE_REQUIRES_BROWSER" ? "\u9700\u6D4F\u89C8\u5668\u9A8C\u8BC1" : { queued: "\u6392\u961F\u4E2D", running: "\u63D0\u53D6\u4E2D", completed: "\u5DF2\u5B8C\u6210", failed: "\u5931\u8D25" }[job.status] }),
1200
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("time", { children: date(job.createdAt) })
449
1201
  ] }),
450
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("strong", { children: job.url }),
451
- job.error && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { role: job.status === "failed" ? "alert" : void 0, children: job.error }),
452
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
453
- job.materialId && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { onClick: () => {
1202
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: job.url }),
1203
+ job.error && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { role: job.status === "failed" ? "alert" : void 0, children: job.error }),
1204
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-job-actions", children: [
1205
+ job.materialId && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { onClick: () => {
454
1206
  setSelected(job.materialId);
455
1207
  setShowJobs(false);
456
1208
  refresh();
457
1209
  }, children: [
458
1210
  "\u67E5\u770B\u8D44\u6599 ",
459
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "arrow", size: 14 })
1211
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "arrow", size: 14 })
460
1212
  ] }),
461
- job.status === "failed" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { onClick: () => void post(`/jobs/${job.id}/retry`, {}).then(refresh).catch((e) => setError(e.message)), children: "\u91CD\u65B0\u91C7\u96C6" })
1213
+ job.status === "failed" && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
1214
+ /^https?:\/\//i.test(job.url) && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("a", { href: job.url, target: "_blank", rel: "noopener noreferrer", children: [
1215
+ "\u6253\u5F00\u539F\u7F51\u9875",
1216
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "arrow", size: 14 })
1217
+ ] }),
1218
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { onClick: () => {
1219
+ setShowJobs(false);
1220
+ setEditor({ mode: "capture", initialType: "text", sourceUrl: job.url });
1221
+ }, children: "\u7C98\u8D34\u6B63\u6587" }),
1222
+ /fake-ip/i.test(job.error || "") && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { onClick: () => {
1223
+ setShowJobs(false);
1224
+ setSettingsFromJobs(true);
1225
+ setShowInfo(true);
1226
+ }, children: "\u4EE3\u7406\u517C\u5BB9\u8BBE\u7F6E" }),
1227
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { onClick: () => void post(`/jobs/${job.id}/retry`, {}).then(refresh).catch((e) => setError(e.message)), children: "\u91CD\u65B0\u91C7\u96C6" })
1228
+ ] })
462
1229
  ] })
463
1230
  ] }, job.id)) }) }),
464
- showInfo && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Dialog, { title: "\u4F60\u7684\u8D44\u6599\uFF0C\u7531\u4F60\u4FDD\u7BA1", description: "\u5185\u5BB9\u4EE5\u666E\u901A\u6587\u4EF6\u4FDD\u5B58\uFF0C\u7D22\u5F15\u53EF\u4EE5\u91CD\u5EFA\u3002", onClose: () => setShowInfo(false), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-info", children: [
465
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "\u8D44\u6599\u5E93\u76EE\u5F55" }),
466
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("code", { children: stats?.root }),
467
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { children: "\u6BCF\u4EFD\u8D44\u6599\u4FDD\u7559\u539F\u59CB\u6587\u4EF6\u3001\u6B63\u6587\u3001\u5143\u6570\u636E\u548C\u5F15\u7528\u6BB5\u843D\u3002\u5206\u7C7B\u5BF9\u5E94\u672C\u5730\u6587\u4EF6\u5939\uFF0C\u63D2\u4EF6\u5378\u8F7D\u4E0D\u4F1A\u5220\u9664\u8FD9\u4E9B\u6587\u4EF6\u3002" }),
468
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { children: "\u672C\u7248\u672C\u53EF\u63D0\u53D6\u6587\u7AE0\u6B63\u6587\u53CA\u5B57\u5E55\uFF1B\u97F3\u89C6\u9891\u3001PDF \u7B49\u683C\u5F0F\u53EF\u4EE5\u5F52\u6863\uFF0C\u81EA\u52A8\u8F6C\u5199\u548C OCR \u5C1A\u672A\u63A5\u5165\u3002" }),
469
- stats?.warnings.map((w) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { role: "alert", children: w }, w)),
470
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { className: "kl-secondary", onClick: () => void post("/rebuild", {}).then(() => {
471
- refresh();
472
- notify("\u7D22\u5F15\u5DF2\u91CD\u5EFA");
473
- }).catch((e) => setError(e.message)), children: "\u4ECE\u8D44\u6599\u6587\u4EF6\u91CD\u5EFA\u7D22\u5F15" })
474
- ] }) }),
475
- toast && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-toast", role: "status", children: [
476
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "check", size: 17 }),
1231
+ showInfo && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SettingsDialog, { root: stats?.root || "", warnings: stats?.warnings || [], onClose: () => {
1232
+ setShowInfo(false);
1233
+ if (settingsFromJobs) setShowJobs(true);
1234
+ setSettingsFromJobs(false);
1235
+ }, onChanged: () => {
1236
+ setSelected(void 0);
1237
+ setDetail(void 0);
1238
+ setAnchor(void 0);
1239
+ setItems([]);
1240
+ setQuery("");
1241
+ chooseFilter({});
1242
+ refresh();
1243
+ notify("\u8D44\u6599\u5E93\u76EE\u5F55\u5DF2\u5207\u6362");
1244
+ }, onRebuilt: () => {
1245
+ refresh();
1246
+ notify("\u7D22\u5F15\u5DF2\u91CD\u5EFA");
1247
+ }, onProxySaved: (enabled) => {
1248
+ refresh();
1249
+ notify(enabled ? "\u4EE3\u7406\u517C\u5BB9\u5DF2\u5F00\u542F\uFF0C\u53EF\u91CD\u65B0\u91C7\u96C6\u5931\u8D25\u4EFB\u52A1" : "\u4EE3\u7406\u517C\u5BB9\u5DF2\u5173\u95ED");
1250
+ if (settingsFromJobs) {
1251
+ setShowInfo(false);
1252
+ setShowJobs(true);
1253
+ setSettingsFromJobs(false);
1254
+ }
1255
+ } }),
1256
+ toast && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-toast", role: "status", children: [
1257
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "check", size: 17 }),
477
1258
  toast
478
1259
  ] })
479
1260
  ] });
480
1261
  }
481
- function Dialog({ title, description, onClose, children }) {
482
- const ref = (0, import_react.useRef)(null);
483
- const closeRef = (0, import_react.useRef)(onClose);
484
- closeRef.current = onClose;
485
- (0, import_react.useEffect)(() => {
486
- const previous = document.activeElement;
487
- const timer = setTimeout(() => ref.current?.querySelector("input,textarea,button")?.focus(), 0);
488
- const key = (event) => {
489
- if (event.key === "Escape") closeRef.current();
490
- if (event.key === "Tab") {
491
- const elements = Array.from(ref.current?.querySelectorAll("button:not(:disabled),input:not(:disabled),textarea:not(:disabled),select,a[href]") || []);
492
- const first = elements[0], last = elements[elements.length - 1];
493
- if (event.shiftKey && document.activeElement === first) {
494
- event.preventDefault();
495
- last?.focus();
496
- }
497
- if (!event.shiftKey && document.activeElement === last) {
498
- event.preventDefault();
499
- first?.focus();
500
- }
501
- }
502
- };
503
- document.addEventListener("keydown", key);
1262
+ function DeleteDialog({ item, onClose, onDeleted }) {
1263
+ const [busy, setBusy] = (0, import_react4.useState)(false);
1264
+ const [error, setError] = (0, import_react4.useState)("");
1265
+ async function remove() {
1266
+ setBusy(true);
1267
+ setError("");
1268
+ try {
1269
+ await post(`/materials/${item.id}`, { expectedRoot: item.root }, "DELETE");
1270
+ onDeleted();
1271
+ } catch (e) {
1272
+ setError(e.message);
1273
+ } finally {
1274
+ setBusy(false);
1275
+ }
1276
+ }
1277
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Dialog, { title: "\u5220\u9664\u8D44\u6599", description: "\u8D44\u6599\u5C06\u79FB\u5165\u56DE\u6536\u7AD9\uFF0C\u539F\u6587\u4EF6\u4FDD\u7559\uFF0C\u53EF\u968F\u65F6\u6062\u590D\u3002", onClose: () => {
1278
+ if (!busy) onClose();
1279
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-delete-dialog", children: [
1280
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "kl-delete-title", children: item.title }),
1281
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "kl-muted", children: "\u5DF2\u6709\u7B14\u8BB0\u4ECD\u80FD\u67E5\u770B\u8FD9\u4EFD\u8D44\u6599\u7684\u6765\u6E90\u5F15\u7528\u3002" }),
1282
+ error && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "kl-form-error", role: "alert", children: error }),
1283
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("footer", { children: [
1284
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: "kl-secondary", disabled: busy, onClick: onClose, children: "\u53D6\u6D88" }),
1285
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: "kl-secondary kl-danger", disabled: busy, onClick: () => void remove(), children: busy ? "\u6B63\u5728\u5220\u9664\u2026" : "\u79FB\u5165\u56DE\u6536\u7AD9" })
1286
+ ] })
1287
+ ] }) });
1288
+ }
1289
+ function EmptyTrashDialog({ root, onClose, onEmptied }) {
1290
+ const [snapshot, setSnapshot] = (0, import_react4.useState)();
1291
+ const [busy, setBusy] = (0, import_react4.useState)(false);
1292
+ const [error, setError] = (0, import_react4.useState)("");
1293
+ (0, import_react4.useEffect)(() => {
1294
+ const abort = new AbortController();
1295
+ void api("/trash", { signal: abort.signal }).then(setSnapshot).catch((e) => {
1296
+ if (!abort.signal.aborted) setError(e.message);
1297
+ });
1298
+ return () => abort.abort();
1299
+ }, []);
1300
+ async function empty() {
1301
+ if (!snapshot || busy) return;
1302
+ setBusy(true);
1303
+ setError("");
1304
+ try {
1305
+ onEmptied(await post("/trash/empty", { expectedRoot: root, confirmed: true, token: snapshot.token }));
1306
+ } catch (e) {
1307
+ setError(e.message);
1308
+ setSnapshot(void 0);
1309
+ } finally {
1310
+ setBusy(false);
1311
+ }
1312
+ }
1313
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Dialog, { title: "\u6E05\u7A7A\u56DE\u6536\u7AD9", description: "\u6C38\u4E45\u5220\u9664\u540E\u65E0\u6CD5\u6062\u590D\uFF0C\u8BF7\u786E\u8BA4\u6574\u4E2A\u56DE\u6536\u7AD9\u5185\u7684\u8D44\u6599\u90FD\u4E0D\u518D\u9700\u8981\u3002", onClose: () => {
1314
+ if (!busy) onClose();
1315
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-delete-dialog", children: [
1316
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "kl-delete-title", children: snapshot ? `\u5C06\u6C38\u4E45\u5220\u9664\u56DE\u6536\u7AD9\u4E2D\u7684\u5168\u90E8 ${snapshot.count} \u4EFD\u8D44\u6599\u3002` : error ? "\u8BF7\u5173\u95ED\u7A97\u53E3\u540E\u91CD\u65B0\u786E\u8BA4\u3002" : "\u6B63\u5728\u6838\u5BF9\u56DE\u6536\u7AD9\u2026" }),
1317
+ !!snapshot?.pending && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("p", { children: [
1318
+ "\u53E6\u6709 ",
1319
+ snapshot.pending,
1320
+ " \u4EFD\u5DF2\u786E\u8BA4\u5220\u9664\u7684\u6587\u4EF6\u5C06\u7EE7\u7EED\u6E05\u7406\u3002"
1321
+ ] }),
1322
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "kl-muted", children: "\u6B63\u6587\u3001\u539F\u59CB\u9644\u4EF6\u548C\u7D22\u5F15\u5C06\u88AB\u79FB\u9664\u3002\u76F8\u5173\u7B14\u8BB0\u7684\u6B63\u6587\u4F1A\u4FDD\u7559\uFF0C\u5F15\u7528\u8FD9\u4E9B\u8D44\u6599\u7684\u4F4D\u7F6E\u5C06\u6807\u8BB0\u4E3A\u201C\u6765\u6E90\u5DF2\u6C38\u4E45\u5220\u9664\u201D\u3002" }),
1323
+ error && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { role: "alert", className: "kl-form-error", children: error }),
1324
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("footer", { children: [
1325
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: "kl-secondary", disabled: busy, onClick: onClose, children: "\u53D6\u6D88" }),
1326
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: "kl-secondary kl-danger", disabled: busy || !snapshot || !(snapshot.count || snapshot.pending), onClick: () => void empty(), children: busy ? "\u6B63\u5728\u6C38\u4E45\u5220\u9664\u2026" : "\u6C38\u4E45\u6E05\u7A7A" })
1327
+ ] })
1328
+ ] }) });
1329
+ }
1330
+ function SettingsDialog({ root, warnings, onClose, onChanged, onRebuilt, onProxySaved }) {
1331
+ const [settings, setSettings] = (0, import_react4.useState)();
1332
+ const [proxyMode, setProxyMode] = (0, import_react4.useState)(false);
1333
+ const [target, setTarget] = (0, import_react4.useState)(root);
1334
+ const [listing, setListing] = (0, import_react4.useState)();
1335
+ const [browsePath, setBrowsePath] = (0, import_react4.useState)("");
1336
+ const [browsing, setBrowsing] = (0, import_react4.useState)(false);
1337
+ const [busy, setBusy] = (0, import_react4.useState)(false);
1338
+ const [saving, setSaving] = (0, import_react4.useState)(false);
1339
+ const [error, setError] = (0, import_react4.useState)("");
1340
+ const request = (0, import_react4.useRef)();
1341
+ (0, import_react4.useEffect)(() => {
1342
+ const abort = new AbortController();
1343
+ void api("/settings", { signal: abort.signal }).then((data) => {
1344
+ setSettings(data);
1345
+ setProxyMode(data.allowProxyFakeIp === true);
1346
+ }).catch((e) => {
1347
+ if (!abort.signal.aborted) setError(e.message);
1348
+ });
504
1349
  return () => {
505
- clearTimeout(timer);
506
- document.removeEventListener("keydown", key);
507
- previous?.focus();
1350
+ abort.abort();
1351
+ request.current?.abort();
508
1352
  };
509
1353
  }, []);
510
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "kl-modal-backdrop", onMouseDown: (event) => {
511
- if (event.target === event.currentTarget) onClose();
512
- }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-dialog", role: "dialog", "aria-modal": "true", "aria-label": title, ref, children: [
513
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("header", { children: [
514
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
515
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h2", { children: title }),
516
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { children: description })
1354
+ (0, import_react4.useEffect)(() => {
1355
+ setTarget(root);
1356
+ }, [root]);
1357
+ async function browse(path) {
1358
+ request.current?.abort();
1359
+ const abort = new AbortController();
1360
+ request.current = abort;
1361
+ setBusy(true);
1362
+ setError("");
1363
+ setListing(void 0);
1364
+ try {
1365
+ const result = await post("/directory/list", { path }, "POST", abort.signal);
1366
+ setListing(result);
1367
+ setBrowsePath(result.path);
1368
+ } catch (e) {
1369
+ if (!abort.signal.aborted) setError(e.message);
1370
+ } finally {
1371
+ if (!abort.signal.aborted) setBusy(false);
1372
+ }
1373
+ }
1374
+ async function pick() {
1375
+ if (settings?.picker === "browse") {
1376
+ setBrowsing(true);
1377
+ setListing(void 0);
1378
+ setBrowsePath(target);
1379
+ await browse(target || void 0);
1380
+ return;
1381
+ }
1382
+ setBusy(true);
1383
+ setError("");
1384
+ const abort = new AbortController();
1385
+ request.current = abort;
1386
+ try {
1387
+ const result = await post("/directory/pick", {}, "POST", abort.signal);
1388
+ if (result.path) setTarget(result.path);
1389
+ } catch (e) {
1390
+ if (!abort.signal.aborted) setError(e.message);
1391
+ } finally {
1392
+ if (!abort.signal.aborted) setBusy(false);
1393
+ }
1394
+ }
1395
+ async function change() {
1396
+ setSaving(true);
1397
+ setError("");
1398
+ try {
1399
+ const result = await post("/settings/root", { root: target.trim(), expectedRoot: root });
1400
+ setTarget(result.root);
1401
+ onChanged();
1402
+ } catch (e) {
1403
+ setError(e.message);
1404
+ } finally {
1405
+ setSaving(false);
1406
+ }
1407
+ }
1408
+ async function saveProxyMode() {
1409
+ if (!settings) return;
1410
+ setSaving(true);
1411
+ setError("");
1412
+ try {
1413
+ const result = await post("/settings/network", { allowProxyFakeIp: proxyMode, expected: settings.allowProxyFakeIp, expectedRoot: root });
1414
+ setSettings({ ...settings, allowProxyFakeIp: result.allowProxyFakeIp });
1415
+ setProxyMode(result.allowProxyFakeIp);
1416
+ onProxySaved(result.allowProxyFakeIp);
1417
+ } catch (e) {
1418
+ setError(e.message);
1419
+ } finally {
1420
+ setSaving(false);
1421
+ }
1422
+ }
1423
+ const changed = target.trim() && target.trim() !== root;
1424
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Dialog, { title: "\u4F60\u7684\u8D44\u6599\uFF0C\u7531\u4F60\u4FDD\u7BA1", description: "\u5185\u5BB9\u4EE5\u666E\u901A\u6587\u4EF6\u4FDD\u5B58\uFF0C\u7D22\u5F15\u53EF\u4EE5\u91CD\u5EFA\u3002", onClose: () => {
1425
+ if (!saving) onClose();
1426
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-info", children: [
1427
+ browsing ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-folder-browser", "aria-label": "\u9009\u62E9\u8D44\u6599\u5E93\u76EE\u5F55", children: [
1428
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-folder-heading", children: [
1429
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: "\u9009\u62E9\u8D44\u6599\u5E93\u76EE\u5F55" }),
1430
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: "kl-secondary", disabled: busy, onClick: () => void browse(), children: "\u4E3B\u76EE\u5F55" })
517
1431
  ] }),
518
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { "aria-label": "\u5173\u95ED\u5F39\u7A97", onClick: onClose, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "close" }) })
1432
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("form", { className: "kl-folder-path", onSubmit: (e) => {
1433
+ e.preventDefault();
1434
+ void browse(browsePath);
1435
+ }, children: [
1436
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("input", { "aria-label": "\u6D4F\u89C8\u76EE\u5F55\u8DEF\u5F84", value: browsePath, onChange: (e) => setBrowsePath(e.target.value) }),
1437
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: "kl-secondary", disabled: busy || !browsePath.trim(), children: "\u524D\u5F80" })
1438
+ ] }),
1439
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("nav", { className: "kl-folder-crumbs", "aria-label": "\u76EE\u5F55\u5C42\u7EA7", children: listing?.crumbs.map((c) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { disabled: busy, onClick: () => void browse(c.path), children: [
1440
+ c.name,
1441
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "/" })
1442
+ ] }, c.path)) }),
1443
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "kl-folder-entries", "aria-busy": busy, children: busy ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "kl-muted", children: "\u6B63\u5728\u8BFB\u53D6\u76EE\u5F55\u2026" }) : listing && !listing.entries.length ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "kl-muted", children: "\u6B64\u76EE\u5F55\u6CA1\u6709\u5B50\u6587\u4EF6\u5939" }) : listing?.entries.map((entry) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { onClick: () => void browse(entry.path), children: [
1444
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "folder", size: 17 }),
1445
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: entry.name }),
1446
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "arrow", size: 15 })
1447
+ ] }, entry.path)) }),
1448
+ listing?.truncated && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "kl-muted", children: "\u5B50\u76EE\u5F55\u8F83\u591A\uFF0C\u4EC5\u663E\u793A\u90E8\u5206\u3002\u53EF\u586B\u5199\u5B8C\u6574\u8DEF\u5F84\u524D\u5F80\u3002" }),
1449
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-folder-actions", children: [
1450
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: "kl-secondary", onClick: () => {
1451
+ request.current?.abort();
1452
+ setBusy(false);
1453
+ setBrowsing(false);
1454
+ setError("");
1455
+ }, children: "\u53D6\u6D88\u9009\u62E9" }),
1456
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: "kl-primary", disabled: busy || !listing, onClick: () => {
1457
+ setTarget(listing.path);
1458
+ setBrowsing(false);
1459
+ setError("");
1460
+ }, children: "\u9009\u62E9\u6B64\u76EE\u5F55" })
1461
+ ] })
1462
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
1463
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { htmlFor: "kl-library-root", children: "\u8D44\u6599\u5E93\u76EE\u5F55" }),
1464
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-root-field", children: [
1465
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("input", { id: "kl-library-root", value: target, title: target, spellCheck: false, readOnly: !settings?.canChange, disabled: saving || busy, onChange: (e) => setTarget(e.target.value) }),
1466
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { className: "kl-secondary", disabled: !settings?.canChange || !settings.picker || busy || saving, onClick: () => void pick(), children: [
1467
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "folder", size: 16 }),
1468
+ busy ? "\u9009\u62E9\u4E2D\u2026" : "\u9009\u62E9\u76EE\u5F55"
1469
+ ] })
1470
+ ] }),
1471
+ settings && !settings.canChange && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "kl-muted", children: "\u8BF7\u5728 Harness \u4E2D\u9009\u62E9\u548C\u5207\u6362\u76EE\u5F55\uFF1B\u72EC\u7ACB\u9884\u89C8\u53EF\u901A\u8FC7\u542F\u52A8\u914D\u7F6E\u6307\u5B9A\u76EE\u5F55\u3002" }),
1472
+ !!changed && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-root-confirm", children: [
1473
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: "\u5207\u6362\u540E\u5C06\u8BFB\u53D6\u65B0\u76EE\u5F55\uFF0C\u5E76\u5C06\u540E\u7EED\u8D44\u6599\u4FDD\u5B58\u5230\u90A3\u91CC\u3002\u539F\u76EE\u5F55\u7684\u8D44\u6599\u4F1A\u4FDD\u7559\uFF0C\u4E0D\u4F1A\u81EA\u52A8\u642C\u8FC1\u3002" }),
1474
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
1475
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: "kl-secondary", disabled: saving || busy, onClick: () => {
1476
+ setTarget(root);
1477
+ setError("");
1478
+ }, children: "\u53D6\u6D88\u4FEE\u6539" }),
1479
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: "kl-primary", disabled: saving || busy, onClick: () => void change(), children: saving ? "\u6B63\u5728\u5207\u6362\u2026" : "\u5207\u6362\u8D44\u6599\u5E93" })
1480
+ ] })
1481
+ ] }),
1482
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { className: "kl-network-settings", "aria-label": "\u7F51\u9875\u91C7\u96C6\u8BBE\u7F6E", children: [
1483
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h3", { children: "\u7F51\u9875\u91C7\u96C6" }),
1484
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "kl-proxy-option", children: [
1485
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("input", { type: "checkbox", "aria-describedby": "kl-proxy-help", checked: proxyMode, disabled: !settings?.canChangeNetwork || saving || busy, onChange: (e) => {
1486
+ setProxyMode(e.target.checked);
1487
+ setError("");
1488
+ } }),
1489
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "Clash/Mihomo \u4EE3\u7406\u517C\u5BB9\uFF08fake-IP\uFF09" })
1490
+ ] }),
1491
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { id: "kl-proxy-help", children: "\u672C\u673A\u4F7F\u7528 Clash/Mihomo TUN \u7684 fake-IP DNS \u65F6\u5F00\u542F\uFF0C\u5141\u8BB8\u901A\u8FC7\u4EE3\u7406\u91C7\u96C6\u89E3\u6790\u5230 198.18.* \u6216 198.19.* \u7684\u7F51\u7AD9\u3002\u672C\u673A\u53CA\u5176\u4ED6\u5185\u7F51\u5730\u5740\u4ECD\u4E0D\u5141\u8BB8\u8BBF\u95EE\u3002" }),
1492
+ settings?.canChangeNetwork && !settings.canChange && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "kl-muted", children: "\u6B64\u8BBE\u7F6E\u7528\u4E8E\u5F53\u524D\u8D44\u6599\u5E93\u7684\u72EC\u7ACB\u9884\u89C8\uFF0C\u4FDD\u5B58\u540E\u5BF9\u540E\u7EED\u91C7\u96C6\u751F\u6548\u3002" }),
1493
+ settings && !settings.canChangeNetwork && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "kl-muted", children: "\u5F53\u524D\u73AF\u5883\u65E0\u6CD5\u4FDD\u5B58\u91C7\u96C6\u8BBE\u7F6E\u3002" }),
1494
+ settings?.canChangeNetwork && proxyMode !== settings.allowProxyFakeIp && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: "kl-secondary", disabled: saving || busy, onClick: () => void saveProxyMode(), children: saving ? "\u6B63\u5728\u4FDD\u5B58\u2026" : "\u4FDD\u5B58\u91C7\u96C6\u8BBE\u7F6E" })
1495
+ ] }),
1496
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: "\u6BCF\u4EFD\u8D44\u6599\u4FDD\u7559\u539F\u59CB\u6587\u4EF6\u3001\u6B63\u6587\u3001\u5143\u6570\u636E\u548C\u5F15\u7528\u6BB5\u843D\u3002\u5206\u7C7B\u5BF9\u5E94\u672C\u5730\u6587\u4EF6\u5939\uFF0C\u63D2\u4EF6\u5378\u8F7D\u4E0D\u4F1A\u5220\u9664\u8FD9\u4E9B\u6587\u4EF6\u3002" }),
1497
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: "\u672C\u7248\u672C\u53EF\u63D0\u53D6\u6587\u7AE0\u6B63\u6587\u53CA\u5B57\u5E55\uFF1B\u97F3\u89C6\u9891\u3001PDF \u7B49\u683C\u5F0F\u53EF\u4EE5\u5F52\u6863\uFF0C\u81EA\u52A8\u8F6C\u5199\u548C OCR \u5C1A\u672A\u63A5\u5165\u3002" }),
1498
+ warnings.map((w) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { role: "alert", children: w }, w)),
1499
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: "kl-secondary", disabled: busy || saving, onClick: () => {
1500
+ setSaving(true);
1501
+ setError("");
1502
+ void post("/rebuild", {}).then(onRebuilt).catch((e) => setError(e.message)).finally(() => setSaving(false));
1503
+ }, children: "\u4ECE\u8D44\u6599\u6587\u4EF6\u91CD\u5EFA\u7D22\u5F15" })
519
1504
  ] }),
520
- children
1505
+ error && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "kl-settings-error", role: "alert", children: error })
521
1506
  ] }) });
522
1507
  }
523
1508
  function EditorDialog({ editor, categories, onClose, onSaved }) {
524
1509
  const editing = editor.mode === "edit";
525
1510
  const note = editor.mode === "note";
526
1511
  const source = editor.source;
527
- const [type, setType] = (0, import_react.useState)("url");
528
- const [title, setTitle] = (0, import_react.useState)(editing ? source?.title || "" : note && source ? `${source.title} \xB7 \u6458\u5F55` : "");
529
- const [content, setContent] = (0, import_react.useState)(editor.segment ? `> ${editor.segment.text}
1512
+ const [type, setType] = (0, import_react4.useState)(editor.initialType || "url");
1513
+ const [sourceUrl, setSourceUrl] = (0, import_react4.useState)(editor.sourceUrl || "");
1514
+ const [title, setTitle] = (0, import_react4.useState)(editing ? source?.title || "" : note && source ? `${source.title} \xB7 \u6458\u5F55` : "");
1515
+ const [content, setContent] = (0, import_react4.useState)(editor.segment ? `> ${editor.segment.text}
530
1516
 
531
1517
  ` : "");
532
- const [category, setCategory] = (0, import_react.useState)(editing ? source?.category || "\u6536\u4EF6\u7BB1" : note ? "\u77E5\u8BC6\u7B14\u8BB0" : "\u6536\u4EF6\u7BB1");
533
- const [tags, setTags] = (0, import_react.useState)(editing ? source?.tags.join("\uFF0C") || "" : "");
534
- const [collection, setCollection] = (0, import_react.useState)(source?.collection || "");
535
- const [sourceNote, setSourceNote] = (0, import_react.useState)(editing ? source?.sourceNote || "" : "");
536
- const [file, setFile] = (0, import_react.useState)();
537
- const [busy, setBusy] = (0, import_react.useState)(false);
538
- const [error, setError] = (0, import_react.useState)("");
1518
+ const [category, setCategory] = (0, import_react4.useState)(editing ? source?.category || "\u6536\u4EF6\u7BB1" : note ? "\u77E5\u8BC6\u7B14\u8BB0" : "\u6536\u4EF6\u7BB1");
1519
+ const [tags, setTags] = (0, import_react4.useState)(editing ? source?.tags.join("\uFF0C") || "" : "");
1520
+ const [collection, setCollection] = (0, import_react4.useState)(source?.collection || "");
1521
+ const [sourceNote, setSourceNote] = (0, import_react4.useState)(editing ? source?.sourceNote || "" : "");
1522
+ const [file, setFile] = (0, import_react4.useState)();
1523
+ const [busy, setBusy] = (0, import_react4.useState)(false);
1524
+ const [error, setError] = (0, import_react4.useState)("");
539
1525
  const citations = source && note ? [{ materialId: source.id, ...editor.segment ? { segmentId: editor.segment.id } : {} }] : [];
540
1526
  async function submit(event) {
541
1527
  event.preventDefault();
542
1528
  setError("");
543
1529
  setBusy(true);
544
1530
  try {
545
- const data = { title, category, tags: splitTags(tags), collection, sourceNote };
1531
+ const data = { title, category, tags: splitTags2(tags), collection, sourceNote };
1532
+ if (!editing && !note && type === "text" && sourceUrl.trim()) data.sourceUrl = sourceUrl.trim();
546
1533
  let result;
547
1534
  if (editing) result = await post(`/materials/${source.id}`, data, "PATCH");
548
1535
  else if (note) result = await post("/notes", { ...data, content, citations });
@@ -569,74 +1556,80 @@ function EditorDialog({ editor, categories, onClose, onSaved }) {
569
1556
  setContent("");
570
1557
  setError("");
571
1558
  };
572
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Dialog, { title: editing ? "\u6574\u7406\u8D44\u6599" : note ? "\u5199\u4E00\u4EFD\u77E5\u8BC6\u7B14\u8BB0" : "\u6536\u96C6\u4E00\u4EFD\u8D44\u6599", description: editing ? "\u5206\u7C7B\u4F1A\u540C\u6B65\u5230\u672C\u5730\u6587\u4EF6\u5939\uFF0C\u539F\u6587\u548C\u5F15\u7528\u4FDD\u6301\u4E0D\u53D8\u3002" : note ? "\u5199\u4E0B\u7406\u89E3\uFF0C\u4E5F\u7559\u4E0B\u5B83\u7684\u6765\u6E90\u3002" : "\u5148\u6536\u96C6\uFF0C\u518D\u6162\u6162\u6574\u7406\u3002\u6240\u6709\u5185\u5BB9\u4FDD\u5B58\u5728\u4F60\u7684\u7535\u8111\u3002", onClose: () => {
1559
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Dialog, { title: editing ? "\u6574\u7406\u8D44\u6599" : note ? "\u5199\u4E00\u4EFD\u77E5\u8BC6\u7B14\u8BB0" : "\u6536\u96C6\u4E00\u4EFD\u8D44\u6599", description: editing ? "\u5206\u7C7B\u4F1A\u540C\u6B65\u5230\u672C\u5730\u6587\u4EF6\u5939\uFF0C\u539F\u6587\u548C\u5F15\u7528\u4FDD\u6301\u4E0D\u53D8\u3002" : note ? "\u5199\u4E0B\u7406\u89E3\uFF0C\u4E5F\u7559\u4E0B\u5B83\u7684\u6765\u6E90\u3002" : "\u5148\u6536\u96C6\uFF0C\u518D\u6162\u6162\u6574\u7406\u3002\u6240\u6709\u5185\u5BB9\u4FDD\u5B58\u5728\u4F60\u7684\u7535\u8111\u3002", onClose: () => {
573
1560
  if (!busy) onClose();
574
- }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("form", { onSubmit: submit, className: "kl-editor", children: [
575
- !editing && !note && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "kl-tabs", role: "tablist", "aria-label": "\u91C7\u96C6\u65B9\u5F0F", children: ["url", "text", "file"].map((value) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { type: "button", role: "tab", "aria-selected": type === value, className: type === value ? "active" : "", onClick: () => changeType(value), children: [
576
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: value === "url" ? "web" : value === "file" ? "upload" : "file", size: 17 }),
1561
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("form", { onSubmit: submit, className: "kl-editor", children: [
1562
+ !editing && !note && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "kl-tabs", role: "tablist", "aria-label": "\u91C7\u96C6\u65B9\u5F0F", children: ["url", "text", "file"].map((value) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { type: "button", role: "tab", "aria-selected": type === value, className: type === value ? "active" : "", onClick: () => changeType(value), children: [
1563
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: value === "url" ? "web" : value === "file" ? "upload" : "file", size: 17 }),
577
1564
  value === "url" ? "\u7F51\u9875\u94FE\u63A5" : value === "file" ? "\u672C\u5730\u6587\u4EF6" : "\u6587\u672C\u6458\u5F55"
578
1565
  ] }, value)) }),
579
- !editing && !note && type === "url" && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { children: [
1566
+ !editing && !note && type === "url" && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { children: [
580
1567
  "\u7F51\u9875\u5730\u5740",
581
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { type: "url", required: true, placeholder: "https://\u2026", value: content, onChange: (e) => setContent(e.target.value) }),
582
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("small", { children: "\u652F\u6301\u53EF\u76F4\u63A5\u8BBF\u95EE\u7684\u6587\u7AE0\u7F51\u9875\u3002\u767B\u5F55\u9875\u6216\u52A8\u6001\u9875\u9762\u53EF\u590D\u5236\u6B63\u6587\u5BFC\u5165\u3002" })
1568
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("input", { type: "url", required: true, placeholder: "https://\u2026", value: content, onChange: (e) => setContent(e.target.value) }),
1569
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("small", { children: "\u652F\u6301\u53EF\u76F4\u63A5\u8BBF\u95EE\u7684\u6587\u7AE0\u7F51\u9875\u3002\u767B\u5F55\u9875\u6216\u52A8\u6001\u9875\u9762\u53EF\u590D\u5236\u6B63\u6587\u5BFC\u5165\u3002" })
583
1570
  ] }),
584
- !editing && !note && type === "file" && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { className: "kl-upload", children: [
585
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "upload", size: 27 }),
586
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("strong", { children: file?.name || "\u9009\u62E9\u6216\u62D6\u5165\u6587\u4EF6" }),
587
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: "\u6587\u672C\u3001HTML\u3001SRT / VTT \u5B57\u5E55\u53CA\u5176\u4ED6\u6587\u4EF6 \xB7 \u6700\u5927 64 MB" }),
588
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { "aria-label": "\u9009\u62E9\u672C\u5730\u6587\u4EF6", type: "file", onChange: (e) => setFile(e.target.files?.[0]) }),
589
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("small", { children: "\u89C6\u9891\u548C PDF \u53EF\u5F52\u6863\uFF0C\u5F53\u524D\u7248\u672C\u4E0D\u4F1A\u81EA\u52A8\u8F6C\u5199\u6216 OCR\u3002" })
1571
+ !editing && !note && type === "file" && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "kl-upload", children: [
1572
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "upload", size: 27 }),
1573
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: file?.name || "\u9009\u62E9\u6216\u62D6\u5165\u6587\u4EF6" }),
1574
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "\u6587\u672C\u3001HTML\u3001SRT / VTT \u5B57\u5E55\u53CA\u5176\u4ED6\u6587\u4EF6 \xB7 \u6700\u5927 64 MB" }),
1575
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("input", { "aria-label": "\u9009\u62E9\u672C\u5730\u6587\u4EF6", type: "file", onChange: (e) => setFile(e.target.files?.[0]) }),
1576
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("small", { children: "\u89C6\u9891\u548C PDF \u53EF\u5F52\u6863\uFF0C\u5F53\u524D\u7248\u672C\u4E0D\u4F1A\u81EA\u52A8\u8F6C\u5199\u6216 OCR\u3002" })
590
1577
  ] }),
591
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { children: [
1578
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { children: [
592
1579
  "\u6807\u9898",
593
- !editing && !note && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("em", { children: "\u53EF\u9009" }),
594
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { required: editing || note, value: title, onChange: (e) => setTitle(e.target.value), placeholder: type === "url" && !note ? "\u81EA\u52A8\u63D0\u53D6\u7F51\u9875\u6807\u9898\uFF0C\u4E5F\u53EF\u4EE5\u81EA\u5DF1\u586B\u5199" : "\u7ED9\u8FD9\u4EFD\u5185\u5BB9\u8D77\u4E2A\u540D\u5B57", maxLength: 300 })
1580
+ !editing && !note && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("em", { children: "\u53EF\u9009" }),
1581
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("input", { required: editing || note, value: title, onChange: (e) => setTitle(e.target.value), placeholder: type === "url" && !note ? "\u81EA\u52A8\u63D0\u53D6\u7F51\u9875\u6807\u9898\uFF0C\u4E5F\u53EF\u4EE5\u81EA\u5DF1\u586B\u5199" : "\u7ED9\u8FD9\u4EFD\u5185\u5BB9\u8D77\u4E2A\u540D\u5B57", maxLength: 300 })
595
1582
  ] }),
596
- !editing && (note || type === "text") && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { children: [
1583
+ !editing && (note || type === "text") && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { children: [
597
1584
  note ? "\u7B14\u8BB0\u5185\u5BB9" : "\u6B63\u6587",
598
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("textarea", { required: true, rows: 7, value: content, onChange: (e) => setContent(e.target.value), placeholder: note ? "\u8BB0\u5F55\u4F60\u7684\u7406\u89E3\u3001\u7ED3\u8BBA\u4E0E\u5C1A\u5F85\u9A8C\u8BC1\u7684\u95EE\u9898\u2026" : "\u7C98\u8D34\u60F3\u4FDD\u7559\u7684\u6587\u5B57\uFF0C\u652F\u6301 Markdown\u2026" })
1585
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("textarea", { required: true, rows: 7, value: content, onChange: (e) => setContent(e.target.value), placeholder: note ? "\u8BB0\u5F55\u4F60\u7684\u7406\u89E3\u3001\u7ED3\u8BBA\u4E0E\u5C1A\u5F85\u9A8C\u8BC1\u7684\u95EE\u9898\u2026" : "\u7C98\u8D34\u60F3\u4FDD\u7559\u7684\u6587\u5B57\uFF0C\u652F\u6301 Markdown\u2026" })
599
1586
  ] }),
600
- !!citations.length && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-citation-preview", children: [
601
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "file", size: 16 }),
602
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
1587
+ !editing && !note && type === "text" && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { children: [
1588
+ "\u6765\u6E90\u7F51\u9875",
1589
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("em", { children: "\u53EF\u9009" }),
1590
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("input", { type: "url", "aria-label": "\u6765\u6E90\u7F51\u9875", placeholder: "https://\u2026", value: sourceUrl, onChange: (e) => setSourceUrl(e.target.value) }),
1591
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("small", { children: "\u4FDD\u7559\u539F\u7F51\u9875\u5730\u5740\uFF0C\u65B9\u4FBF\u56DE\u6EAF\u6765\u6E90\u3002" })
1592
+ ] }),
1593
+ !!citations.length && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-citation-preview", children: [
1594
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "file", size: 16 }),
1595
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { children: [
603
1596
  "\u5F15\u7528\uFF1A",
604
1597
  source.title,
605
1598
  editor.segment ? ` / ${editor.segment.id}` : ""
606
1599
  ] })
607
1600
  ] }),
608
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "kl-form-grid", children: [
609
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { children: [
1601
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "kl-form-grid", children: [
1602
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { children: [
610
1603
  "\u5206\u7C7B",
611
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { list: "kl-categories", value: category, onChange: (e) => setCategory(e.target.value), placeholder: "\u4F8B\u5982 \u6280\u672F/AI" }),
612
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("datalist", { id: "kl-categories", children: categories.map((c) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: c }, c)) })
1604
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("input", { list: "kl-categories", value: category, onChange: (e) => setCategory(e.target.value), placeholder: "\u4F8B\u5982 \u6280\u672F/AI" }),
1605
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("datalist", { id: "kl-categories", children: categories.map((c) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: c }, c)) })
613
1606
  ] }),
614
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { children: [
1607
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { children: [
615
1608
  "\u4E13\u9898",
616
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("em", { children: "\u53EF\u9009" }),
617
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { value: collection, onChange: (e) => setCollection(e.target.value), placeholder: "\u56F4\u7ED5\u4E00\u4E2A\u95EE\u9898\u7EC4\u7EC7\u8D44\u6599" })
1609
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("em", { children: "\u53EF\u9009" }),
1610
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("input", { value: collection, onChange: (e) => setCollection(e.target.value), placeholder: "\u56F4\u7ED5\u4E00\u4E2A\u95EE\u9898\u7EC4\u7EC7\u8D44\u6599" })
618
1611
  ] })
619
1612
  ] }),
620
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { children: [
1613
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { children: [
621
1614
  "\u6807\u7B7E",
622
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("em", { children: "\u53EF\u9009" }),
623
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { value: tags, onChange: (e) => setTags(e.target.value), placeholder: "\u7528\u9017\u53F7\u5206\u9694\uFF0C\u4F8B\u5982\uFF1A\u5F85\u8BFB\uFF0CRAG\uFF0C\u5B9E\u8DF5" })
1615
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("em", { children: "\u53EF\u9009" }),
1616
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("input", { value: tags, onChange: (e) => setTags(e.target.value), placeholder: "\u7528\u9017\u53F7\u5206\u9694\uFF0C\u4F8B\u5982\uFF1A\u5F85\u8BFB\uFF0CRAG\uFF0C\u5B9E\u8DF5" })
624
1617
  ] }),
625
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { children: [
1618
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { children: [
626
1619
  "\u6765\u6E90\u5907\u6CE8",
627
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("em", { children: "\u53EF\u9009" }),
628
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { value: sourceNote, onChange: (e) => setSourceNote(e.target.value), placeholder: "\u4E3A\u4EC0\u4E48\u503C\u5F97\u4FDD\u5B58\uFF0C\u6216\u8005\u5B83\u6765\u81EA\u54EA\u91CC" })
1620
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("em", { children: "\u53EF\u9009" }),
1621
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("input", { value: sourceNote, onChange: (e) => setSourceNote(e.target.value), placeholder: "\u4E3A\u4EC0\u4E48\u503C\u5F97\u4FDD\u5B58\uFF0C\u6216\u8005\u5B83\u6765\u81EA\u54EA\u91CC" })
629
1622
  ] }),
630
- error && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "kl-form-error", role: "alert", children: error }),
631
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("footer", { children: [
632
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
633
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "kl-live-dot" }),
1623
+ error && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "kl-form-error", role: "alert", children: error }),
1624
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("footer", { children: [
1625
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { children: [
1626
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "kl-live-dot" }),
634
1627
  "\u4EC5\u4FDD\u5B58\u5728\u672C\u5730"
635
1628
  ] }),
636
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "kl-secondary", disabled: busy, onClick: onClose, children: "\u53D6\u6D88" }),
637
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { className: "kl-primary", type: "submit", disabled: busy, children: [
1629
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", className: "kl-secondary", disabled: busy, onClick: onClose, children: "\u53D6\u6D88" }),
1630
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { className: "kl-primary", type: "submit", disabled: busy, children: [
638
1631
  busy ? "\u4FDD\u5B58\u4E2D\u2026" : editing ? "\u4FDD\u5B58\u4FEE\u6539" : note ? "\u4FDD\u5B58\u7B14\u8BB0" : type === "url" ? "\u5F00\u59CB\u91C7\u96C6" : "\u4FDD\u5B58\u8D44\u6599",
639
- !busy && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "arrow", size: 16 })
1632
+ !busy && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "arrow", size: 16 })
640
1633
  ] })
641
1634
  ] })
642
1635
  ] }) });
@@ -736,11 +1729,100 @@ var style_default = `/* Harness owns the palette and font. Fallbacks are for the
736
1729
  .kl-filterbar b { font-weight: 400; }
737
1730
  .kl-filterbar > div { display: flex; align-items: center; gap: 16px; flex: none; }
738
1731
  .kl-filterbar select { background: var(--kl-bg); color: var(--kl-muted); border: 0; border-radius: 6px; padding: 3px; max-width: 110px; font-size: 12px; }
1732
+ .kl-trash-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 var(--kl-gutter) 12px; }
1733
+ .kl-trash-toolbar p { color: var(--kl-muted); font-size: 12px; margin: 0; min-width: 0; }
1734
+ .kl-trash-toolbar button { flex: none; }
1735
+ .kl-knowledge-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 var(--kl-gutter) 12px; }
1736
+ .kl-knowledge-toolbar p { margin: 0; font-size: 12px; color: var(--kl-muted); }
1737
+ .kl-knowledge-toolbar > div, .kl-knowledge-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
1738
+ .kl-knowledge-toolbar > div { flex: none; }
1739
+ .kl-knowledge-badge { display: inline-flex; align-items: center; padding: 2px 6px; border-radius: 5px; background: var(--kl-hover); color: var(--kl-muted); font-size: 11px; line-height: 18px; white-space: nowrap; font-weight: 400; }
1740
+ .kl-knowledge-badge:is(.draft, .running, .queued, .grouping, .classifying) { color: var(--kl-link); }
1741
+ .kl-knowledge-badge.failed { color: var(--kl-error); }
1742
+ .kl-knowledge-badge.completed { color: var(--kl-ink); }
1743
+ .kl-item-bottom { flex-wrap: wrap; }
1744
+ .kl-item-row.kl-selectable { padding-left: 30px; }
1745
+ .kl-material-checkbox { position: absolute; left: 9px; top: 17px; width: 15px; height: 15px; accent-color: var(--kl-primary); cursor: pointer; }
1746
+ .kl-knowledge-source { border-block: .5px solid var(--kl-line); padding-block: 16px; margin: 20px 0; }
1747
+ .kl-knowledge-source > div:first-child { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--kl-muted); margin-bottom: 12px; }
1748
+ .kl-knowledge-form, .kl-knowledge-jobs { padding: 0 24px 24px; }
1749
+ .kl-knowledge-form label, .kl-knowledge-draft label { display: flex; flex-direction: column; gap: 7px; font-size: 13px; margin: 16px 0; }
1750
+ .kl-knowledge-form input, .kl-knowledge-draft input, .kl-knowledge-draft textarea { width: 100%; border: .5px solid var(--kl-line); border-radius: 8px; padding: 10px 12px; color: var(--kl-ink); background: var(--kl-bg); min-width: 0; font: inherit; }
1751
+ .kl-knowledge-draft textarea { line-height: 1.8; resize: vertical; font-size: 13px; }
1752
+ .kl-knowledge-form small, .kl-knowledge-jobs small { font-size: 12px; color: var(--kl-muted); line-height: 1.7; }
1753
+ .kl-knowledge-summary { display: flex; align-items: center; justify-content: space-between; font-size: 13px; }
1754
+ .kl-knowledge-summary b { font-weight: 500; }
1755
+ .kl-knowledge-summary span { color: var(--kl-muted); }
1756
+ .kl-knowledge-source-list { padding: 0; list-style: none; max-height: 150px; overflow: auto; }
1757
+ .kl-knowledge-source-list li { display: flex; align-items: center; gap: 8px; margin-block: 8px; font-size: 13px; overflow-wrap: anywhere; }
1758
+ .kl-knowledge-model { color: var(--kl-muted); font-size: 12px; line-height: 1.8; }
1759
+ .kl-knowledge-help { font-size: 12px; color: var(--kl-link); display: inline-flex; align-items: center; gap: 4px; }
1760
+ .kl-knowledge-form > .kl-muted { font-size: 13px; line-height: 1.8; }
1761
+ .kl-knowledge-form footer, .kl-knowledge-draft footer { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 20px; }
1762
+ .kl-knowledge-back { background: transparent; border: 0; padding: 0; color: var(--kl-muted); font-size: 12px; margin-bottom: 18px; }
1763
+ .kl-knowledge-empty { display: flex; align-items: center; flex-direction: column; text-align: center; padding: 24px 0; color: var(--kl-muted); }
1764
+ .kl-knowledge-empty p { color: var(--kl-ink); }
1765
+ .kl-knowledge-job { display: block; width: 100%; border: 0; border-top: .5px solid var(--kl-line); background: transparent; text-align: left; padding: 16px 0; }
1766
+ .kl-knowledge-job:hover { background: var(--kl-hover); }
1767
+ .kl-knowledge-job > div, .kl-knowledge-job-heading { display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; }
1768
+ .kl-knowledge-job strong, .kl-knowledge-job-heading strong { font-size: 14px; font-weight: 500; overflow-wrap: anywhere; min-width: 0; }
1769
+ .kl-knowledge-job p { color: var(--kl-muted); font-size: 12px; margin: 8px 0 0; }
1770
+ .kl-knowledge-job small { display: block; margin-top: 8px; }
1771
+ .kl-knowledge-progress { display: flex; align-items: center; gap: 8px; color: var(--kl-muted); font-size: 13px; margin: 20px 0; }
1772
+ .kl-knowledge-jobs > .kl-knowledge-actions { margin-top: 18px; }
1773
+ .kl-knowledge-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
1774
+ .kl-knowledge-citations { font-size: 12px; color: var(--kl-muted); border-block: .5px solid var(--kl-line); padding-block: 12px; }
1775
+ .kl-knowledge-citations summary { cursor: pointer; }
1776
+ .kl-knowledge-citations button { border: 0; background: transparent; display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 8px 0; }
1777
+ .kl-knowledge-citations button span { min-width: 0; overflow-wrap: anywhere; }
1778
+ .kl-knowledge-mode { margin: 16px 0; padding: 12px; border: .5px solid var(--kl-line); border-radius: 8px; }
1779
+ .kl-knowledge-mode legend { padding: 0 4px; font-size: 12px; color: var(--kl-muted); }
1780
+ .kl-knowledge-mode label { flex-direction: row; align-items: center; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
1781
+ .kl-knowledge-mode input { width: 15px; padding: 0; accent-color: var(--kl-primary); }
1782
+ .kl-knowledge-mode small { margin-left: auto; }
1783
+ .kl-grouping-editor { margin-top: 18px; }
1784
+ .kl-grouping-summary { display: flex; align-items: center; gap: 14px; font-size: 13px; }
1785
+ .kl-grouping-summary b { font-weight: 500; }
1786
+ .kl-grouping-summary span { color: var(--kl-muted); }
1787
+ .kl-grouping-group { border: .5px solid var(--kl-line); border-radius: 8px; padding: 12px 14px; margin: 12px 0; }
1788
+ .kl-grouping-group-title, .kl-grouping-source-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
1789
+ .kl-grouping-group-title { font-size: 12px; color: var(--kl-muted); }
1790
+ .kl-grouping-group ul { margin: 10px 0 0; padding-left: 18px; color: var(--kl-muted); font-size: 12px; line-height: 1.8; }
1791
+ .kl-grouping-group li { overflow-wrap: anywhere; }
1792
+ .kl-grouping-editor label { display: flex; flex-direction: column; gap: 7px; margin: 12px 0; font-size: 12px; }
1793
+ .kl-grouping-editor :is(input,textarea,select) { width: 100%; min-width: 0; border: .5px solid var(--kl-line); border-radius: 8px; padding: 9px 10px; background: var(--kl-bg); color: var(--kl-ink); font: inherit; }
1794
+ .kl-grouping-editor textarea { line-height: 1.7; resize: vertical; }
1795
+ .kl-grouping-reason { margin: 8px 0; font-size: 12px; line-height: 1.8; color: var(--kl-muted); overflow-wrap: anywhere; }
1796
+ .kl-grouping-settings summary, .kl-grouping-source summary { cursor: pointer; font-size: 12px; color: var(--kl-muted); }
1797
+ .kl-grouping-settings summary span { margin-left: 8px; color: var(--kl-ink); }
1798
+ .kl-grouping-section-title { font-size: 14px; font-weight: 500; margin: 24px 0 10px; }
1799
+ .kl-grouping-source { border-top: .5px solid var(--kl-line); padding: 14px 0; }
1800
+ .kl-grouping-source-title strong { font-size: 13px; font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
1801
+ .kl-grouping-source p, .kl-grouping-pending p, .kl-grouping-recovery p { font-size: 12px; line-height: 1.8; color: var(--kl-muted); overflow-wrap: anywhere; }
1802
+ .kl-grouping-source details button { margin-top: 8px; }
1803
+ .kl-grouping-editor .kl-grouping-sync { flex-direction: row; align-items: center; gap: 8px; margin-top: 20px; }
1804
+ .kl-grouping-sync input { width: 15px; height: 15px; padding: 0; accent-color: var(--kl-primary); flex: none; }
1805
+ .kl-grouping-editor footer { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
1806
+ .kl-grouping-recovery { border-left: 2px solid var(--kl-link); padding-left: 12px; font-size: 13px; }
1807
+ .kl-grouping-pending { border-top: .5px solid var(--kl-line); padding-top: 14px; font-size: 13px; }
1808
+ .kl-note-integration { border: .5px solid var(--kl-line); border-radius: 8px; padding: 14px; margin: 16px 0; }
1809
+ .kl-note-integration > strong { font-size: 14px; font-weight: 500; }
1810
+ .kl-note-integration p, .kl-integration-findings { font-size: 12px; line-height: 1.8; overflow-wrap: anywhere; }
1811
+ .kl-integration-findings { display: grid; grid-template-columns: 90px minmax(0, 1fr); gap: 12px; padding: 8px 0; border-top: .5px solid var(--kl-line); }
1812
+ .kl-integration-findings > span { color: var(--kl-muted); }
1813
+ .kl-integration-findings ul { margin: 0; padding-left: 16px; }
1814
+ .kl-integration-target { font-weight: 500; }
1815
+ .kl-integration-preview { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 300px; overflow-y: auto; padding: 12px; background: var(--kl-hover); border-radius: 6px; font: inherit; font-size: 12px; line-height: 1.8; }
1816
+ .kl-note-integration details summary, .kl-knowledge-draft > details summary { cursor: pointer; font-size: 12px; color: var(--kl-muted); }
739
1817
  .kl-body { position: relative; display: flex; flex: 1; min-height: 0; overflow: hidden; }
740
1818
  .kl-list { flex: 1; min-width: 0; min-height: 0; overflow-y: auto; padding: 0 calc(var(--kl-gutter) - 8px) 24px; }
741
1819
  .kl-body.with-detail .kl-list { flex: 0 0 38%; padding: 0 16px 24px calc(var(--kl-gutter) - 8px); }
742
1820
  .kl-item { width: 100%; display: block; text-align: left; padding: 14px 12px; margin-bottom: 2px; border: 0; border-radius: var(--kl-radius); background: transparent; }
743
1821
  .kl-item:hover, .kl-item.selected { background: var(--kl-hover); }
1822
+ .kl-item-row { position: relative; }
1823
+ .kl-item-row .kl-item { padding-right: 48px; }
1824
+ .kl-app .kl-row-action { position: absolute; top: 8px; right: 8px; }
1825
+ .kl-app .kl-danger, .kl-app .kl-danger:hover { color: var(--kl-error); }
744
1826
  .kl-item-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 5px; }
745
1827
  .kl-type { display: inline-flex; gap: 5px; align-items: center; font-size: 12px; color: var(--kl-muted); }
746
1828
  .kl-item time { color: var(--kl-muted); font-size: 12px; }
@@ -821,6 +1903,9 @@ var style_default = `/* Harness owns the palette and font. Fallbacks are for the
821
1903
  .kl-dialog > header p { margin: 0; color: var(--kl-muted); font-size: 12px; line-height: 1.7; }
822
1904
  .kl-dialog > header > button { border: 0; border-radius: 8px; background: transparent; color: var(--kl-muted); padding: 4px; display: flex; }
823
1905
  .kl-dialog > header > button:hover { background: var(--kl-hover); }
1906
+ .kl-delete-dialog { padding: 0 24px 24px; }
1907
+ .kl-delete-title { margin: 0 0 12px; font-weight: 500; overflow-wrap: anywhere; }
1908
+ .kl-delete-dialog footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }
824
1909
  .kl-editor { padding: 0 24px; }
825
1910
  .kl-tabs { display: flex; gap: 8px; margin-bottom: 20px; }
826
1911
  .kl-tabs button { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; background: transparent; border: 0; color: var(--kl-muted); border-radius: 14px; min-height: 32px; padding: 5px 8px; font-size: 13px; }
@@ -847,14 +1932,39 @@ var style_default = `/* Harness owns the palette and font. Fallbacks are for the
847
1932
  .kl-job time { font-size: 11px; color: var(--kl-muted); }
848
1933
  .kl-job > strong { display: block; overflow-wrap: anywhere; font-size: 13px; font-weight: 400; margin: 12px 0; }
849
1934
  .kl-job > p { font-size: 12px; color: var(--kl-error); line-height: 1.7; }
850
- .kl-job button { display: flex; align-items: center; gap: 4px; color: var(--kl-link); font-size: 12px; border: 0; background: transparent; border-radius: 6px; padding: 4px; }
851
- .kl-job button:hover { background: var(--kl-hover); }
1935
+ .kl-job button, .kl-job a { display: flex; align-items: center; gap: 4px; color: var(--kl-link); font-size: 12px; border: 0; background: transparent; border-radius: 6px; padding: 4px; text-decoration: none; }
1936
+ .kl-job button:hover, .kl-job a:hover { background: var(--kl-hover); }
1937
+ .kl-job .kl-job-actions { justify-content: flex-start; flex-wrap: wrap; gap: 8px; }
852
1938
  .kl-job-status { font-size: 11px; border-radius: 6px; padding: 3px 7px; background: var(--kl-hover); color: var(--kl-secondary); }
853
1939
  .kl-job-status.failed { color: var(--kl-error); }
854
1940
  .kl-job-status.running { color: var(--kl-link); }
855
1941
  .kl-info label { display: block; font-size: 12px; color: var(--kl-muted); margin-bottom: 8px; }
856
1942
  .kl-info code { display: block; overflow-wrap: anywhere; background: var(--kl-sidebar); padding: 12px; border-radius: 8px; font-size: 12px; }
857
1943
  .kl-info p { font-size: 13px; line-height: 1.8; color: var(--kl-secondary); margin: 16px 0; }
1944
+ .kl-root-field, .kl-folder-path { display: flex; gap: 8px; align-items: center; }
1945
+ .kl-root-field input, .kl-folder-path input { flex: 1; min-width: 0; border: .5px solid var(--kl-line); background: var(--kl-panel); border-radius: var(--kl-radius); padding: 10px 12px; font-size: 12px; }
1946
+ .kl-root-field input[readonly] { background: var(--kl-sidebar); }
1947
+ .kl-root-field button, .kl-folder-path button { flex-shrink: 0; }
1948
+ .kl-root-confirm { margin-top: 14px; padding: 12px; border: .5px solid var(--kl-line); border-radius: 10px; background: var(--kl-sidebar); }
1949
+ .kl-root-confirm p { margin: 0 0 12px; }
1950
+ .kl-root-confirm > div, .kl-folder-actions { display: flex; justify-content: flex-end; gap: 8px; }
1951
+ .kl-folder-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
1952
+ .kl-folder-heading strong { font-size: 14px; font-weight: 500; }
1953
+ .kl-folder-crumbs { display: flex; flex-wrap: wrap; gap: 4px; margin: 12px 0; }
1954
+ .kl-folder-crumbs button { border: 0; background: transparent; padding: 3px 0; font-size: 12px; color: var(--kl-muted); overflow-wrap: anywhere; }
1955
+ .kl-folder-crumbs span { padding: 0 6px; color: var(--kl-caption); }
1956
+ .kl-folder-entries { height: 240px; overflow: auto; border: .5px solid var(--kl-line); border-radius: 10px; padding: 6px; }
1957
+ .kl-folder-entries > button { width: 100%; display: flex; align-items: center; gap: 10px; text-align: left; border: 0; border-radius: 6px; padding: 10px; background: transparent; }
1958
+ .kl-folder-entries > button:hover { background: var(--kl-hover); }
1959
+ .kl-folder-entries > button span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
1960
+ .kl-folder-entries > p { padding: 0 10px; }
1961
+ .kl-folder-actions { margin-top: 16px; }
1962
+ .kl-info .kl-settings-error { color: var(--kl-error); overflow-wrap: anywhere; }
1963
+ .kl-network-settings { margin-top: 20px; padding-top: 16px; border-top: .5px solid var(--kl-line); }
1964
+ .kl-network-settings h3 { font-size: 13px; font-weight: 500; margin: 0 0 12px; }
1965
+ .kl-info .kl-proxy-option { display: flex; align-items: flex-start; gap: 8px; color: var(--kl-ink); font-size: 13px; line-height: 20px; cursor: pointer; }
1966
+ .kl-proxy-option input { flex: none; width: 16px; height: 16px; margin: 2px 0; accent-color: var(--kl-ink); }
1967
+ .kl-network-settings p { font-size: 12px; margin: 8px 0 12px; }
858
1968
  .kl-error, .kl-form-error { background: var(--kl-sidebar); color: var(--kl-error); font-size: 13px; line-height: 1.7; padding: 10px 12px; border-radius: 8px; overflow-wrap: anywhere; }
859
1969
  .kl-error { display: flex; align-items: center; gap: 12px; margin: 0 var(--kl-gutter) 14px; }
860
1970
  .kl-error button { margin-left: auto; border: 0; background: transparent; color: inherit; display: flex; padding: 4px; }
@@ -882,10 +1992,14 @@ var style_default = `/* Harness owns the palette and font. Fallbacks are for the
882
1992
  .kl-toolbar { padding: 0 20px 12px; gap: 4px; }
883
1993
  .kl-search kbd, .kl-job-button span, .kl-sort-label { display: none; }
884
1994
  .kl-filterbar { padding: 0 20px 10px; }
1995
+ .kl-trash-toolbar { padding: 0 20px 12px; flex-wrap: wrap; }
1996
+ .kl-knowledge-toolbar { padding: 0 20px 12px; flex-wrap: wrap; }
885
1997
  .kl-list { padding: 0 12px 16px; }
886
1998
  .kl-empty { padding: 40px 12px; }
887
1999
  .kl-detail article { padding: 20px; }
888
2000
  .kl-detail-toolbar { padding: 8px 12px; }
2001
+ .kl-detail-toolbar { flex-wrap: wrap; }
2002
+ .kl-detail-toolbar > div { margin-left: auto; }
889
2003
  .kl-error { margin: 0 20px 12px; }
890
2004
  }
891
2005
  /* Fixed dialogs use viewport width even when the host panel is narrow. */
@@ -893,6 +2007,8 @@ var style_default = `/* Harness owns the palette and font. Fallbacks are for the
893
2007
  .kl-modal-backdrop { padding: 12px; }
894
2008
  .kl-dialog { max-height: calc(100dvh - 24px); }
895
2009
  .kl-dialog > header { padding: 20px 18px 16px; }
2010
+ .kl-knowledge-form, .kl-knowledge-jobs { padding-inline: 18px; }
2011
+ .kl-knowledge-fields { grid-template-columns: 1fr; gap: 0; }
896
2012
  .kl-editor { padding: 0 18px; }
897
2013
  .kl-editor footer { margin-left: -18px; margin-right: -18px; padding: 14px 18px; }
898
2014
  .kl-editor footer > span { font-size: 10px; }
@@ -900,6 +2016,7 @@ var style_default = `/* Harness owns the palette and font. Fallbacks are for the
900
2016
  .kl-tabs button { padding: 5px; font-size: 12px; }
901
2017
  .kl-form-grid { gap: 12px; }
902
2018
  .kl-jobs, .kl-info { padding: 0 18px 20px; }
2019
+ .kl-delete-dialog { padding: 0 18px 20px; }
903
2020
  }
904
2021
  @media (prefers-reduced-motion: reduce) {
905
2022
  .kl-app * { animation: none !important; transition: none !important; }
@@ -907,7 +2024,7 @@ var style_default = `/* Harness owns the palette and font. Fallbacks are for the
907
2024
  `;
908
2025
 
909
2026
  // src/client.tsx
910
- var import_jsx_runtime3 = require("react/jsx-runtime");
2027
+ var import_jsx_runtime6 = require("react/jsx-runtime");
911
2028
  var inject = ["slots"];
912
2029
  function apply(ctx) {
913
2030
  ctx.effect(() => {
@@ -917,13 +2034,13 @@ function apply(ctx) {
917
2034
  document.head.append(style);
918
2035
  return () => style.remove();
919
2036
  });
920
- ctx.slots.inject("main", () => ctx.slots.register({ name: "main", key: "knowledge-library" }, () => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(App, {})));
2037
+ ctx.slots.inject("main", () => ctx.slots.register({ name: "main", key: "knowledge-library" }, () => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(App, {})));
921
2038
  ctx.slots.inject("sidebar.panellist", () => ctx.slots.register({
922
2039
  name: "sidebar.panellist",
923
2040
  id: "knowledge-library",
924
2041
  order: 20,
925
2042
  label: "\u8D44\u6599\u5E93"
926
- }, () => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(LibraryIcon, { size: 20 })));
2043
+ }, () => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(LibraryIcon, { size: 20 })));
927
2044
  }
928
2045
 
929
2046
  return module.exports;}});