@jayyuen66/dsh-zvec-grep 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +44 -0
- package/README.md +7 -5
- package/README.zh-CN.md +7 -5
- package/THIRD_PARTY_NOTICES.md +6 -4
- package/client.js +735 -320
- package/docs/DETAIL.md +28 -0
- package/docs/DETAIL.zh.md +28 -0
- package/host.js +57 -21
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +53 -41
package/client.js
CHANGED
|
@@ -7,6 +7,7 @@ window.__ModuleLoader__.load({
|
|
|
7
7
|
let exports = module.exports;
|
|
8
8
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
9
9
|
let react = require("react");
|
|
10
|
+
let zod = require("zod");
|
|
10
11
|
// lib/embedding-catalog.ts
|
|
11
12
|
/** 默认模型:本地最强(1024 维 / 8192 上下文 / 中英通用),约 640MB 一次性下载。 */
|
|
12
13
|
const DEFAULT_EMBEDDING = "local/qwen3-embedding-0.6b";
|
|
@@ -83,20 +84,552 @@ const LOCAL_EMBEDDINGS = [
|
|
|
83
84
|
}
|
|
84
85
|
];
|
|
85
86
|
// node_modules/@jayyuen66/dsh-plugin-shared/dist/card-diff.js
|
|
86
|
-
function e$
|
|
87
|
+
function e$2(t, n, r) {
|
|
87
88
|
if (t == null || n == null) return (t ?? null) === (n ?? null);
|
|
88
89
|
if (Object.is(t, n)) return !0;
|
|
89
90
|
if (typeof t != `object` || typeof n != `object`) return !1;
|
|
90
91
|
if (r.get(t) === n) return !0;
|
|
91
|
-
if (r.set(t, n), Array.isArray(t) || Array.isArray(n)) return !Array.isArray(t) || !Array.isArray(n) || t.length !== n.length ? !1 : t.every((t, i) => e$
|
|
92
|
+
if (r.set(t, n), Array.isArray(t) || Array.isArray(n)) return !Array.isArray(t) || !Array.isArray(n) || t.length !== n.length ? !1 : t.every((t, i) => e$2(t, n[i], r));
|
|
92
93
|
let i = Object.keys(t), a = Object.keys(n);
|
|
93
|
-
return i.length === a.length && i.every((i) => Object.hasOwn(n, i) && e$
|
|
94
|
+
return i.length === a.length && i.every((i) => Object.hasOwn(n, i) && e$2(Reflect.get(t, i), Reflect.get(n, i), r));
|
|
94
95
|
}
|
|
95
|
-
function t$
|
|
96
|
+
function t$2(t, n) {
|
|
96
97
|
let r = [];
|
|
97
|
-
for (let i of Object.keys(t)) e$
|
|
98
|
+
for (let i of Object.keys(t)) e$2(t[i], n[i], /* @__PURE__ */ new WeakMap()) || r.push(i);
|
|
98
99
|
return r;
|
|
99
100
|
}
|
|
101
|
+
// node_modules/@jayyuen66/dsh-plugin-shared/dist/card-ui.js
|
|
102
|
+
const c = `
|
|
103
|
+
.dsu-form{display:flex;flex-direction:column}
|
|
104
|
+
.dsu-section{margin-top:24px;padding-top:24px;border-top:.5px solid var(--dsw-alias-border-l1)}
|
|
105
|
+
.dsu-form>.dsu-section:first-child{margin-top:0;padding-top:0;border-top:0}
|
|
106
|
+
.dsu-sectionTitle{margin:0;font-size:15px;font-weight:600;line-height:1.4;color:var(--dsw-alias-label-primary)}
|
|
107
|
+
.dsu-sectionHint{margin:4px 0 0;font-size:12px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}
|
|
108
|
+
.dsu-statusbar{display:flex;flex-wrap:wrap;gap:4px 8px;margin-top:8px;font-size:12px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}
|
|
109
|
+
.dsu-field{display:grid;grid-template-columns:minmax(0,1fr) minmax(240px,360px);column-gap:32px;align-items:center;padding:12px 0;border-top:.5px solid var(--dsw-alias-border-l2)}
|
|
110
|
+
.dsu-fieldMeta{display:flex;flex-direction:column;gap:4px;min-width:0}
|
|
111
|
+
.dsu-labelRow{display:flex;align-items:center;gap:6px;min-width:0}
|
|
112
|
+
.dsu-label{font-size:13px;font-weight:500;line-height:1.5;color:var(--dsw-alias-label-primary)}
|
|
113
|
+
.dsu-labelMono{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:12px}
|
|
114
|
+
.dsu-hint{margin:0;font-size:12px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}
|
|
115
|
+
.dsu-control{min-width:0;display:flex;align-items:center;gap:8px}
|
|
116
|
+
.dsu-fieldWide{grid-template-columns:minmax(0,1fr);align-items:start}
|
|
117
|
+
.dsu-fieldWide .dsu-control{width:100%;max-width:720px;margin-top:2px}
|
|
118
|
+
.dsu-help{display:inline-flex;align-items:center;gap:6px;min-width:0}
|
|
119
|
+
.dsu-helpBtn{appearance:none;border:0;background:transparent;padding:0;width:16px;height:16px;display:inline-flex;align-items:center;justify-content:center;color:var(--dsw-alias-label-tertiary);cursor:help;border-radius:50%;flex:none}
|
|
120
|
+
.dsu-help:hover .dsu-helpBtn,.dsu-helpBtn:focus-visible{color:var(--dsw-alias-label-primary)}
|
|
121
|
+
.dsu-helpBtn:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:1px}
|
|
122
|
+
.dsu-tip{position:fixed;z-index:60;box-sizing:border-box;max-width:min(340px,calc(100vw - 16px));max-height:calc(100vh - 16px);overflow:auto;overflow-wrap:anywhere;padding:10px 12px;border-radius:10px;background:var(--dsw-alias-bg-layer-2);border:.5px solid var(--dsw-alias-border-l3);box-shadow:0 12px 32px rgb(0 0 0 / 45%);font-size:12px;line-height:1.6;font-weight:400;color:var(--dsw-alias-label-secondary)}
|
|
123
|
+
.dsu-input{width:100%;height:34px;padding:0 12px;border:.5px solid var(--dsw-alias-border-l4);border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-primary);font:inherit;font-size:13px}
|
|
124
|
+
.dsu-input:focus-visible{outline:none;border-color:var(--dsw-alias-state-business-primary)}
|
|
125
|
+
.dsu-input[aria-invalid="true"]{border-color:var(--dsw-alias-state-error-primary)}
|
|
126
|
+
.dsu-input:disabled{color:var(--dsw-alias-label-tertiary);cursor:default}
|
|
127
|
+
.dsu-input::placeholder{color:var(--dsw-alias-label-tertiary)}
|
|
128
|
+
.dsu-textarea{height:auto;min-height:96px;padding:8px 12px;line-height:1.6;resize:vertical}
|
|
129
|
+
.dsu-mono{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
|
|
130
|
+
.dsu-numberWrap{display:flex;flex-direction:column;gap:4px;width:100%;min-width:0}
|
|
131
|
+
.dsu-number{display:flex;align-items:center;gap:8px;min-width:0}
|
|
132
|
+
.dsu-number .dsu-input{min-width:0}
|
|
133
|
+
.dsu-unit{flex:none;font-size:12px;color:var(--dsw-alias-label-tertiary)}
|
|
134
|
+
.dsu-error{margin:0;font-size:12px;line-height:1.5;color:var(--dsw-alias-state-error-primary)}
|
|
135
|
+
.dsu-switch{appearance:none;width:36px;height:20px;border-radius:999px;border:0;padding:2px;background:var(--dsw-alias-border-l3);display:flex;align-items:center;cursor:pointer;flex:none;transition:background-color .16s}
|
|
136
|
+
.dsu-knob{width:16px;height:16px;border-radius:50%;background:var(--dsw-alias-label-primary);transition:transform .16s,background-color .16s}
|
|
137
|
+
.dsu-switch[aria-checked="true"]{background:var(--dsw-alias-label-primary)}
|
|
138
|
+
.dsu-switch[aria-checked="true"] .dsu-knob{transform:translateX(16px);background:var(--dsw-alias-label-primary-foreground)}
|
|
139
|
+
.dsu-switch:disabled{opacity:.4;cursor:not-allowed}
|
|
140
|
+
.dsu-switch:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:2px}
|
|
141
|
+
.dsu-selectWrap{position:relative;width:100%;min-width:0}
|
|
142
|
+
.dsu-select{display:flex;align-items:center;justify-content:space-between;gap:8px;text-align:left;cursor:pointer}
|
|
143
|
+
.dsu-select[aria-expanded="true"]{border-color:var(--dsw-alias-state-business-primary)}
|
|
144
|
+
.dsu-selectValue{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
145
|
+
.dsu-chevron{flex:none;color:var(--dsw-alias-label-tertiary);transition:transform .16s}
|
|
146
|
+
.dsu-select[aria-expanded="true"] .dsu-chevron{transform:rotate(180deg)}
|
|
147
|
+
.dsu-menu{position:fixed;z-index:70;padding:4px;background:var(--dsw-alias-bg-layer-2);border:.5px solid var(--dsw-alias-border-l3);border-radius:12px;box-shadow:0 12px 32px rgb(0 0 0 / 50%);max-height:280px;overflow:auto}
|
|
148
|
+
.dsu-option{appearance:none;border:0;background:transparent;color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;line-height:1.4;width:100%;display:flex;align-items:center;justify-content:space-between;gap:12px;padding:8px 10px;border-radius:8px;cursor:pointer;text-align:left}
|
|
149
|
+
.dsu-option:hover,.dsu-option[data-active="true"]{background:var(--dsw-alias-bg-layer-3)}
|
|
150
|
+
.dsu-option:disabled{color:var(--dsw-alias-label-tertiary);cursor:not-allowed}
|
|
151
|
+
.dsu-option:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:-2px}
|
|
152
|
+
.dsu-optionGroup{padding:6px 10px 2px;font-size:11px;font-weight:600;color:var(--dsw-alias-label-tertiary)}
|
|
153
|
+
.dsu-check{opacity:0;flex:none}
|
|
154
|
+
.dsu-option[aria-selected="true"] .dsu-check{opacity:1}
|
|
155
|
+
.dsu-savebar{display:flex;align-items:center;gap:8px;padding:12px 0;margin-top:24px;border-top:.5px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-base)}
|
|
156
|
+
.dsu-savebar[data-dirty="true"]{position:sticky;bottom:0;z-index:2;box-shadow:0 -12px 24px rgb(0 0 0 / 35%)}
|
|
157
|
+
.dsu-btn{appearance:none;border:.5px solid var(--dsw-alias-border-l2);background:transparent;color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;line-height:1.5;border-radius:var(--dsw-radius-md);padding:5px 14px;cursor:pointer;transition:background-color .12s,border-color .12s,color .12s,filter .12s}
|
|
158
|
+
.dsu-btn:hover:not(:disabled){background:var(--dsw-alias-bg-layer-2);border-color:var(--dsw-alias-border-l3)}
|
|
159
|
+
.dsu-btn:active:not(:disabled){background:var(--dsw-alias-bg-layer-1)}
|
|
160
|
+
.dsu-btn:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:1px}
|
|
161
|
+
.dsu-btn:disabled{opacity:.4;cursor:not-allowed}
|
|
162
|
+
.dsu-btnPrimary{background:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-layer-3)}
|
|
163
|
+
.dsu-btnPrimary:hover:not(:disabled){background:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-primary);filter:brightness(.9)}
|
|
164
|
+
.dsu-btnPrimary:active:not(:disabled){background:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-primary);filter:brightness(.84)}
|
|
165
|
+
.dsu-btnDanger{color:var(--dsw-alias-state-error-primary)}
|
|
166
|
+
.dsu-btnDanger:hover:not(:disabled){color:var(--dsw-alias-state-error-primary);border-color:var(--dsw-alias-state-error-primary);background:var(--dsw-alias-bg-layer-2)}
|
|
167
|
+
.dsu-status{margin-left:auto;font-size:12px;color:var(--dsw-alias-label-tertiary)}
|
|
168
|
+
.dsu-statusError{color:var(--dsw-alias-state-error-primary)}
|
|
169
|
+
.dsu-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(200px,100%),1fr));gap:0 24px}
|
|
170
|
+
.dsu-grid>.dsu-field{display:flex;flex-direction:column;align-items:stretch;gap:6px;padding:10px 0;border-top:.5px solid var(--dsw-alias-border-l1)}
|
|
171
|
+
.dsu-grid>.dsu-field .dsu-control{width:100%}
|
|
172
|
+
@media (max-width:640px){
|
|
173
|
+
.dsu-field{grid-template-columns:minmax(0,1fr);align-items:start}
|
|
174
|
+
.dsu-control{width:100%;max-width:720px}
|
|
175
|
+
.dsu-section{margin-top:20px;padding-top:20px}
|
|
176
|
+
}
|
|
177
|
+
@media (prefers-reduced-motion:reduce){
|
|
178
|
+
.dsu-switch,.dsu-knob,.dsu-chevron,.dsu-btn{transition:none}
|
|
179
|
+
}
|
|
180
|
+
`;
|
|
181
|
+
function l(e, t = 30) {
|
|
182
|
+
return e.length <= t ? { hint: e } : { detail: e };
|
|
183
|
+
}
|
|
184
|
+
function u(t) {
|
|
185
|
+
return (0, react.createElement)(`div`, { className: `dsu-form` }, t.children);
|
|
186
|
+
}
|
|
187
|
+
function d(t) {
|
|
188
|
+
return (0, react.createElement)(`section`, { className: `dsu-section` }, (0, react.createElement)(`h2`, { className: `dsu-sectionTitle` }, t.title), t.hint === void 0 ? null : (0, react.createElement)(`p`, { className: `dsu-sectionHint` }, t.hint), t.children);
|
|
189
|
+
}
|
|
190
|
+
function m(a) {
|
|
191
|
+
let c = (0, react.useId)(), [l, u] = (0, react.useState)(!1), [d, f] = (0, react.useState)(!1), p = (0, react.useRef)(!1), m = (0, react.useRef)(!1), h = (0, react.useRef)(!1), g = (0, react.useRef)(null), _ = (0, react.useRef)(null), v = (0, react.useRef)(null), y = (0, react.useCallback)(() => {
|
|
192
|
+
v.current !== null && (clearTimeout(v.current), v.current = null);
|
|
193
|
+
}, []), b = (0, react.useCallback)(() => {
|
|
194
|
+
let e = g.current, t = _.current;
|
|
195
|
+
/* v8 ignore next 3 -- place 只在 open 的 layout effect 与挂载期监听器里调用;refs 为空只可能是卸载竞态 */
|
|
196
|
+
if (e === null || t === null) return;
|
|
197
|
+
let n = e.getBoundingClientRect(), r = t.offsetWidth, i = t.offsetHeight, { left: a } = n, o = n.bottom + 8;
|
|
198
|
+
o + i > window.innerHeight - 8 && (o = n.top - i - 8), a + r > window.innerWidth - 8 && (a = window.innerWidth - r - 8);
|
|
199
|
+
let s = Math.max(8, window.innerWidth - r - 8), c = Math.max(8, window.innerHeight - i - 8);
|
|
200
|
+
t.style.left = `${Math.min(Math.max(8, a), s)}px`, t.style.top = `${Math.min(Math.max(8, o), c)}px`;
|
|
201
|
+
}, []), x = (0, react.useCallback)(() => {
|
|
202
|
+
y(), h.current = !1, f(!1), u(!1);
|
|
203
|
+
}, [y]), S = (0, react.useCallback)(() => {
|
|
204
|
+
y(), u(!0);
|
|
205
|
+
}, [y]), C = (0, react.useCallback)(() => {
|
|
206
|
+
y(), !(p.current || m.current || h.current) && (v.current = setTimeout(() => {
|
|
207
|
+
/* v8 ignore next 3 -- 任何重新进入/钉住都会 cancelHide;这次复查只防未来的异步路径 */
|
|
208
|
+
v.current = null, p.current || m.current || h.current || u(!1);
|
|
209
|
+
}, 120));
|
|
210
|
+
}, [y]), w = (0, react.useCallback)((e) => {
|
|
211
|
+
h.current = e, f(e);
|
|
212
|
+
}, []);
|
|
213
|
+
(0, react.useLayoutEffect)(() => {
|
|
214
|
+
if (!l) return () => {};
|
|
215
|
+
b();
|
|
216
|
+
let e = (e) => {
|
|
217
|
+
let { target: t } = e;
|
|
218
|
+
t instanceof Node && _.current?.contains(t) === !0 || (h.current ? b() : x());
|
|
219
|
+
}, t = () => {
|
|
220
|
+
b();
|
|
221
|
+
};
|
|
222
|
+
return window.addEventListener(`scroll`, e, !0), window.addEventListener(`resize`, t), () => {
|
|
223
|
+
window.removeEventListener(`scroll`, e, !0), window.removeEventListener(`resize`, t);
|
|
224
|
+
};
|
|
225
|
+
}, [
|
|
226
|
+
l,
|
|
227
|
+
a.detail,
|
|
228
|
+
b,
|
|
229
|
+
x
|
|
230
|
+
]), (0, react.useEffect)(() => {
|
|
231
|
+
if (!l) return () => {};
|
|
232
|
+
let e = (e) => {
|
|
233
|
+
e.key === `Escape` && x();
|
|
234
|
+
};
|
|
235
|
+
return document.addEventListener(`keydown`, e), () => {
|
|
236
|
+
document.removeEventListener(`keydown`, e);
|
|
237
|
+
};
|
|
238
|
+
}, [l, x]), (0, react.useEffect)(() => y, [y]);
|
|
239
|
+
let T = (0, react.createElement)(`button`, {
|
|
240
|
+
ref: g,
|
|
241
|
+
type: `button`,
|
|
242
|
+
className: `dsu-helpBtn`,
|
|
243
|
+
"aria-label": `${a.label} 说明`,
|
|
244
|
+
"aria-describedby": c,
|
|
245
|
+
"aria-pressed": d,
|
|
246
|
+
onClick: () => {
|
|
247
|
+
h.current ? x() : (w(!0), S());
|
|
248
|
+
}
|
|
249
|
+
}, (0, react.createElement)(`svg`, {
|
|
250
|
+
width: 12,
|
|
251
|
+
height: 12,
|
|
252
|
+
viewBox: `0 0 14 14`,
|
|
253
|
+
"aria-hidden": !0
|
|
254
|
+
}, (0, react.createElement)(`circle`, {
|
|
255
|
+
cx: 7,
|
|
256
|
+
cy: 7,
|
|
257
|
+
r: 6,
|
|
258
|
+
fill: `none`,
|
|
259
|
+
stroke: `currentColor`,
|
|
260
|
+
strokeWidth: 1.2
|
|
261
|
+
}), (0, react.createElement)(`path`, {
|
|
262
|
+
d: `M7 6.2v4`,
|
|
263
|
+
stroke: `currentColor`,
|
|
264
|
+
strokeWidth: 1.3,
|
|
265
|
+
strokeLinecap: `round`
|
|
266
|
+
}), (0, react.createElement)(`circle`, {
|
|
267
|
+
cx: 7,
|
|
268
|
+
cy: 4.3,
|
|
269
|
+
r: .8,
|
|
270
|
+
fill: `currentColor`
|
|
271
|
+
}))), E = (0, react.createElement)(`div`, {
|
|
272
|
+
ref: _,
|
|
273
|
+
id: c,
|
|
274
|
+
role: `tooltip`,
|
|
275
|
+
className: `dsu-tip`,
|
|
276
|
+
hidden: !l
|
|
277
|
+
}, a.detail), D = a.showLabel === !1 ? null : (0, react.createElement)(`span`, { className: `dsu-label${a.compact === !0 ? ` dsu-labelMono` : ``}` }, a.label);
|
|
278
|
+
return (0, react.createElement)(`span`, {
|
|
279
|
+
className: `dsu-help`,
|
|
280
|
+
onMouseEnter: () => {
|
|
281
|
+
p.current = !0, S();
|
|
282
|
+
},
|
|
283
|
+
onMouseLeave: () => {
|
|
284
|
+
p.current = !1, C();
|
|
285
|
+
},
|
|
286
|
+
onFocus: () => {
|
|
287
|
+
m.current = !0, S();
|
|
288
|
+
},
|
|
289
|
+
onBlur: (e) => {
|
|
290
|
+
let t = e.relatedTarget;
|
|
291
|
+
t instanceof Node && e.currentTarget.contains(t) || (m.current = !1, C());
|
|
292
|
+
}
|
|
293
|
+
}, D, T, E);
|
|
294
|
+
}
|
|
295
|
+
function h(t) {
|
|
296
|
+
let n = `dsu-label${t.compact === !0 ? ` dsu-labelMono` : ``}`, r = t.controlId === void 0 ? (0, react.createElement)(`span`, { className: n }, t.label) : (0, react.createElement)(`label`, {
|
|
297
|
+
className: n,
|
|
298
|
+
htmlFor: t.controlId
|
|
299
|
+
}, t.label);
|
|
300
|
+
return (0, react.createElement)(`div`, { className: `dsu-labelRow` }, r, t.detail === void 0 ? null : (0, react.createElement)(m, {
|
|
301
|
+
label: t.label,
|
|
302
|
+
detail: t.detail,
|
|
303
|
+
showLabel: !1
|
|
304
|
+
}));
|
|
305
|
+
}
|
|
306
|
+
function g(t) {
|
|
307
|
+
let n = t.controlId === void 0 ? void 0 : `${t.controlId}-hint`;
|
|
308
|
+
return (0, react.createElement)(`div`, { className: `dsu-field${t.wide === !0 ? ` dsu-fieldWide` : ``}` }, (0, react.createElement)(`div`, { className: `dsu-fieldMeta` }, (0, react.createElement)(h, {
|
|
309
|
+
label: t.label,
|
|
310
|
+
detail: t.detail,
|
|
311
|
+
compact: t.compact,
|
|
312
|
+
controlId: t.controlId
|
|
313
|
+
}), t.hint === void 0 ? null : (0, react.createElement)(`p`, {
|
|
314
|
+
className: `dsu-hint`,
|
|
315
|
+
id: n
|
|
316
|
+
}, t.hint)), (0, react.createElement)(`div`, { className: `dsu-control` }, t.children));
|
|
317
|
+
}
|
|
318
|
+
function _(t) {
|
|
319
|
+
let n = (0, react.useId)(), i = t.hint === void 0 ? void 0 : `${n}-hint`;
|
|
320
|
+
return (0, react.createElement)(g, {
|
|
321
|
+
...t,
|
|
322
|
+
controlId: n
|
|
323
|
+
}, (0, react.createElement)(`button`, {
|
|
324
|
+
type: `button`,
|
|
325
|
+
role: `switch`,
|
|
326
|
+
id: n,
|
|
327
|
+
className: `dsu-switch`,
|
|
328
|
+
"aria-checked": t.checked,
|
|
329
|
+
"aria-describedby": i,
|
|
330
|
+
"data-field": t.field,
|
|
331
|
+
disabled: t.disabled === !0,
|
|
332
|
+
onClick: () => {
|
|
333
|
+
t.onChange(!t.checked);
|
|
334
|
+
}
|
|
335
|
+
}, (0, react.createElement)(`span`, { className: `dsu-knob` })));
|
|
336
|
+
}
|
|
337
|
+
function v(t) {
|
|
338
|
+
let i = typeof t.value == `number` && Number.isFinite(t.value) ? String(t.value) : ``, [a, c] = (0, react.useState)(i), [l, u] = (0, react.useState)(!1), d = (0, react.useRef)(void 0), f = (0, react.useId)(), p = (0, react.useId)(), m = [t.hint === void 0 ? void 0 : `${f}-hint`, l ? p : void 0].filter((e) => e !== void 0), h = m.length === 0 ? void 0 : m.join(` `);
|
|
339
|
+
(0, react.useEffect)(() => {
|
|
340
|
+
t.value !== d.current && (d.current = t.value, c(i), u(!1));
|
|
341
|
+
}, [t.value, i]);
|
|
342
|
+
let _ = (e) => {
|
|
343
|
+
let n = t.min ?? -1 / 0, r = t.max ?? 1 / 0;
|
|
344
|
+
if (!Number.isFinite(e) || e < n || e > r) return !1;
|
|
345
|
+
let { step: i } = t;
|
|
346
|
+
if (i === void 0 || i <= 0) return !0;
|
|
347
|
+
let a = (e - (t.min ?? 0)) / i;
|
|
348
|
+
return Math.abs(a - Math.round(a)) < 1e-9;
|
|
349
|
+
}, v = (e) => {
|
|
350
|
+
if (c(e), e === ``) {
|
|
351
|
+
u(!1), d.current = void 0, t.onChange(void 0);
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
let n = Number(e);
|
|
355
|
+
_(n) ? (u(!1), d.current = n, t.onChange(n)) : u(!0);
|
|
356
|
+
}, y = () => {
|
|
357
|
+
a === `` || l || c(String(Number(a)));
|
|
358
|
+
};
|
|
359
|
+
return (0, react.createElement)(g, {
|
|
360
|
+
...t,
|
|
361
|
+
controlId: f
|
|
362
|
+
}, (0, react.createElement)(`div`, { className: `dsu-numberWrap` }, (0, react.createElement)(`div`, { className: `dsu-number` }, (0, react.createElement)(`input`, {
|
|
363
|
+
className: `dsu-input`,
|
|
364
|
+
type: `number`,
|
|
365
|
+
inputMode: `numeric`,
|
|
366
|
+
id: f,
|
|
367
|
+
value: a,
|
|
368
|
+
min: t.min,
|
|
369
|
+
max: t.max,
|
|
370
|
+
step: t.step,
|
|
371
|
+
placeholder: t.placeholder,
|
|
372
|
+
"aria-invalid": l || void 0,
|
|
373
|
+
"aria-describedby": h,
|
|
374
|
+
"data-field": t.field,
|
|
375
|
+
disabled: t.disabled === !0,
|
|
376
|
+
onChange: (e) => {
|
|
377
|
+
v(e.target.value);
|
|
378
|
+
},
|
|
379
|
+
onBlur: y
|
|
380
|
+
}), t.unit === void 0 ? null : (0, react.createElement)(`span`, { className: `dsu-unit` }, t.unit)), l ? (0, react.createElement)(`p`, {
|
|
381
|
+
className: `dsu-error`,
|
|
382
|
+
id: p
|
|
383
|
+
}, t.invalidHint) : null));
|
|
384
|
+
}
|
|
385
|
+
function y(t) {
|
|
386
|
+
let [i, a] = (0, react.useState)(t.value), [o, c] = (0, react.useState)(!1), l = (0, react.useId)(), u = t.hint === void 0 ? void 0 : `${l}-hint`;
|
|
387
|
+
(0, react.useEffect)(() => {
|
|
388
|
+
o || a(t.value);
|
|
389
|
+
}, [t.value, o]);
|
|
390
|
+
let d = {
|
|
391
|
+
id: l,
|
|
392
|
+
className: `dsu-input${t.multiline === !0 ? ` dsu-textarea` : ``}${t.monospace === !0 ? ` dsu-mono` : ``}`,
|
|
393
|
+
value: i,
|
|
394
|
+
placeholder: t.placeholder,
|
|
395
|
+
"aria-describedby": u,
|
|
396
|
+
"data-field": t.field,
|
|
397
|
+
disabled: t.disabled === !0,
|
|
398
|
+
onFocus: () => {
|
|
399
|
+
c(!0);
|
|
400
|
+
},
|
|
401
|
+
onBlur: () => {
|
|
402
|
+
c(!1);
|
|
403
|
+
},
|
|
404
|
+
onChange: (e) => {
|
|
405
|
+
a(e.target.value), t.onChange(e.target.value);
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
return (0, react.createElement)(g, {
|
|
409
|
+
...t,
|
|
410
|
+
controlId: l
|
|
411
|
+
}, t.multiline === !0 ? (0, react.createElement)(`textarea`, d) : (0, react.createElement)(`input`, d));
|
|
412
|
+
}
|
|
413
|
+
function x(c) {
|
|
414
|
+
let [l, u] = (0, react.useState)(!1), [d, f] = (0, react.useState)(0), p = (0, react.useRef)(null), m = (0, react.useRef)(null), h = (0, react.useId)(), _ = (0, react.useId)(), v = c.hint === void 0 ? void 0 : `${_}-hint`, { disabled: y, value: b, options: x, onChange: S } = c, C = (0, react.useMemo)(() => x.map((e, t) => ({
|
|
415
|
+
option: e,
|
|
416
|
+
index: t
|
|
417
|
+
})).filter((e) => e.option.disabled !== !0), [x]), w = x.find((e) => e.value === b)?.label ?? b, T = x[d], E = T !== void 0 && T.disabled !== !0, D = (0, react.useCallback)(() => {
|
|
418
|
+
let e = p.current, t = m.current;
|
|
419
|
+
/* v8 ignore next 3 -- place 只在 open 的 layout effect 里调用;refs 为空只可能是卸载竞态 */
|
|
420
|
+
if (e === null || t === null) return;
|
|
421
|
+
let n = e.getBoundingClientRect(), r = Math.min(n.width, window.innerWidth - 16), { left: i } = n;
|
|
422
|
+
i + r > window.innerWidth - 8 && (i = window.innerWidth - r - 8);
|
|
423
|
+
let a = t.offsetHeight, o = n.bottom + 6;
|
|
424
|
+
o + a > window.innerHeight - 8 && (o = n.top - a - 6);
|
|
425
|
+
let s = Math.max(8, window.innerWidth - r - 8), c = Math.max(8, window.innerHeight - a - 8);
|
|
426
|
+
t.style.width = `${r}px`, t.style.left = `${Math.min(Math.max(8, i), s)}px`, t.style.top = `${Math.min(Math.max(8, o), c)}px`;
|
|
427
|
+
}, []), O = (0, react.useCallback)(() => {
|
|
428
|
+
u(!1);
|
|
429
|
+
}, []), k = (0, react.useCallback)(() => {
|
|
430
|
+
if (y === !0) return;
|
|
431
|
+
let e = C.find((e) => e.option.value === b) ?? C.at(0);
|
|
432
|
+
e !== void 0 && (f(e.index), u(!0));
|
|
433
|
+
}, [
|
|
434
|
+
y,
|
|
435
|
+
b,
|
|
436
|
+
C
|
|
437
|
+
]), A = (0, react.useCallback)((e) => {
|
|
438
|
+
/* v8 ignore next 3 -- 浮层只能经由 openMenu 打开;组件禁用时打不开 */
|
|
439
|
+
if (y === !0) return;
|
|
440
|
+
let t = x[e];
|
|
441
|
+
/* v8 ignore next 3 -- disabled 选项在浏览器里不派发 click;越界下标由调用面保证 */
|
|
442
|
+
t !== void 0 && t.disabled !== !0 && (S(t.value), O(), p.current?.focus());
|
|
443
|
+
}, [
|
|
444
|
+
y,
|
|
445
|
+
x,
|
|
446
|
+
S,
|
|
447
|
+
O
|
|
448
|
+
]), j = (0, react.useCallback)((e) => {
|
|
449
|
+
let t = C.findIndex((e) => e.index === d);
|
|
450
|
+
/* v8 ignore next 5 -- open 时归一 effect 已保证 enabled 非空且 active 落在可用项上 */
|
|
451
|
+
if (t === -1 || C.length === 0) return;
|
|
452
|
+
let n = (t + e + C.length) % C.length, r = C[n];
|
|
453
|
+
/* v8 ignore next 3 -- next 由取模保证在界内 */
|
|
454
|
+
r !== void 0 && f(r.index);
|
|
455
|
+
}, [d, C]);
|
|
456
|
+
(0, react.useLayoutEffect)(() => {
|
|
457
|
+
if (!l) return () => {};
|
|
458
|
+
D();
|
|
459
|
+
let e = (e) => {
|
|
460
|
+
let t = e.target;
|
|
461
|
+
m.current?.contains(t) !== !0 && p.current?.contains(t) !== !0 && O();
|
|
462
|
+
}, t = (e) => {
|
|
463
|
+
let { target: t } = e;
|
|
464
|
+
t instanceof Node && m.current?.contains(t) === !0 || O();
|
|
465
|
+
}, n = () => {
|
|
466
|
+
D();
|
|
467
|
+
};
|
|
468
|
+
return document.addEventListener(`pointerdown`, e, !0), window.addEventListener(`scroll`, t, !0), window.addEventListener(`resize`, n), () => {
|
|
469
|
+
document.removeEventListener(`pointerdown`, e, !0), window.removeEventListener(`scroll`, t, !0), window.removeEventListener(`resize`, n);
|
|
470
|
+
};
|
|
471
|
+
}, [
|
|
472
|
+
l,
|
|
473
|
+
c.options,
|
|
474
|
+
D,
|
|
475
|
+
O
|
|
476
|
+
]), (0, react.useEffect)(() => {
|
|
477
|
+
if (!l) return;
|
|
478
|
+
if (y === !0 || C.length === 0) {
|
|
479
|
+
O();
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
if (C.some((e) => e.index === d)) return;
|
|
483
|
+
let e = C.find((e) => e.option.value === b) ?? C.at(0);
|
|
484
|
+
/* v8 ignore next 3 -- enabled 非空在上一分支已保证 */
|
|
485
|
+
e !== void 0 && f(e.index);
|
|
486
|
+
}, [
|
|
487
|
+
l,
|
|
488
|
+
y,
|
|
489
|
+
b,
|
|
490
|
+
x,
|
|
491
|
+
d,
|
|
492
|
+
O,
|
|
493
|
+
C
|
|
494
|
+
]), (0, react.useLayoutEffect)(() => {
|
|
495
|
+
if (!l) return;
|
|
496
|
+
let e = m.current;
|
|
497
|
+
/* v8 ignore next 2 -- 同上,menu 在 open 的 commit 之后必然已挂上 */
|
|
498
|
+
if (e === null) return;
|
|
499
|
+
let t = e.querySelector(`[data-active="true"]`);
|
|
500
|
+
/* v8 ignore next 2 -- active 已由归一 effect 保证落在可用项上 */
|
|
501
|
+
t !== null && (t.offsetTop < e.scrollTop ? e.scrollTop = t.offsetTop : t.offsetTop + t.offsetHeight > e.scrollTop + e.clientHeight && (e.scrollTop = t.offsetTop + t.offsetHeight - e.clientHeight));
|
|
502
|
+
}, [
|
|
503
|
+
l,
|
|
504
|
+
d,
|
|
505
|
+
x
|
|
506
|
+
]);
|
|
507
|
+
let M = (e) => {
|
|
508
|
+
if (e.key === `ArrowDown` || e.key === `ArrowUp`) {
|
|
509
|
+
if (e.preventDefault(), !l) {
|
|
510
|
+
k();
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
j(e.key === `ArrowDown` ? 1 : -1);
|
|
514
|
+
} else if (e.key === `Home` || e.key === `End`) {
|
|
515
|
+
if (e.preventDefault(), l || k(), C.length === 0) return;
|
|
516
|
+
let t = e.key === `Home` ? C.at(0) : C.at(-1);
|
|
517
|
+
/* v8 ignore next 3 -- enabled 为空已在上一条返回 */
|
|
518
|
+
if (t === void 0) return;
|
|
519
|
+
f(t.index);
|
|
520
|
+
} else if (e.key === `Enter` || e.key === ` `) {
|
|
521
|
+
if (e.preventDefault(), !l) {
|
|
522
|
+
k();
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
A(d);
|
|
526
|
+
} else (e.key === `Tab` || e.key === `Escape`) && O();
|
|
527
|
+
}, N = [], P;
|
|
528
|
+
for (let [t, n] of x.entries()) n.group !== P && (n.group !== void 0 && N.push((0, react.createElement)(`div`, {
|
|
529
|
+
key: `group-${t}-${n.group}`,
|
|
530
|
+
className: `dsu-optionGroup`,
|
|
531
|
+
role: `presentation`
|
|
532
|
+
}, n.group)), P = n.group), N.push((0, react.createElement)(`button`, {
|
|
533
|
+
key: `option-${n.value}`,
|
|
534
|
+
type: `button`,
|
|
535
|
+
role: `option`,
|
|
536
|
+
id: `${h}-${t}`,
|
|
537
|
+
className: `dsu-option`,
|
|
538
|
+
tabIndex: -1,
|
|
539
|
+
"aria-selected": n.value === c.value,
|
|
540
|
+
"data-active": t === d,
|
|
541
|
+
disabled: n.disabled === !0,
|
|
542
|
+
onMouseDown: (e) => {
|
|
543
|
+
e.preventDefault();
|
|
544
|
+
},
|
|
545
|
+
onClick: () => {
|
|
546
|
+
A(t);
|
|
547
|
+
},
|
|
548
|
+
onMouseEnter: () => {
|
|
549
|
+
/* v8 ignore next -- happy-dom 对 disabled 元素不派发 mouse 事件;浏览器实现各有差异,保留禁用检查 */
|
|
550
|
+
n.disabled !== !0 && f(t);
|
|
551
|
+
}
|
|
552
|
+
}, (0, react.createElement)(`span`, null, n.label), (0, react.createElement)(`svg`, {
|
|
553
|
+
className: `dsu-check`,
|
|
554
|
+
width: 14,
|
|
555
|
+
height: 14,
|
|
556
|
+
viewBox: `0 0 14 14`,
|
|
557
|
+
"aria-hidden": !0
|
|
558
|
+
}, (0, react.createElement)(`path`, {
|
|
559
|
+
d: `M2.5 7.5l3 3 6-7`,
|
|
560
|
+
fill: `none`,
|
|
561
|
+
stroke: `currentColor`,
|
|
562
|
+
strokeWidth: 1.5,
|
|
563
|
+
strokeLinecap: `round`,
|
|
564
|
+
strokeLinejoin: `round`
|
|
565
|
+
}))));
|
|
566
|
+
return (0, react.createElement)(g, {
|
|
567
|
+
...c,
|
|
568
|
+
controlId: _
|
|
569
|
+
}, (0, react.createElement)(`div`, {
|
|
570
|
+
className: `dsu-selectWrap`,
|
|
571
|
+
onBlur: (e) => {
|
|
572
|
+
let t = e.relatedTarget;
|
|
573
|
+
t instanceof Node && e.currentTarget.contains(t) || O();
|
|
574
|
+
}
|
|
575
|
+
}, (0, react.createElement)(`button`, {
|
|
576
|
+
ref: p,
|
|
577
|
+
type: `button`,
|
|
578
|
+
id: _,
|
|
579
|
+
className: `dsu-select dsu-input`,
|
|
580
|
+
role: `combobox`,
|
|
581
|
+
"aria-haspopup": `listbox`,
|
|
582
|
+
"aria-expanded": l,
|
|
583
|
+
"aria-controls": `${h}-list`,
|
|
584
|
+
"aria-activedescendant": l && E ? `${h}-${d}` : void 0,
|
|
585
|
+
"aria-describedby": v,
|
|
586
|
+
"data-field": c.field,
|
|
587
|
+
disabled: y === !0 || x.length === 0,
|
|
588
|
+
onClick: () => {
|
|
589
|
+
l ? O() : k();
|
|
590
|
+
},
|
|
591
|
+
onKeyDown: M
|
|
592
|
+
}, (0, react.createElement)(`span`, { className: `dsu-selectValue` }, w), (0, react.createElement)(`svg`, {
|
|
593
|
+
className: `dsu-chevron`,
|
|
594
|
+
width: 14,
|
|
595
|
+
height: 14,
|
|
596
|
+
viewBox: `0 0 14 14`,
|
|
597
|
+
"aria-hidden": !0
|
|
598
|
+
}, (0, react.createElement)(`path`, {
|
|
599
|
+
d: `M3 5l4 4 4-4`,
|
|
600
|
+
fill: `none`,
|
|
601
|
+
stroke: `currentColor`,
|
|
602
|
+
strokeWidth: 1.5,
|
|
603
|
+
strokeLinecap: `round`,
|
|
604
|
+
strokeLinejoin: `round`
|
|
605
|
+
}))), (0, react.createElement)(`div`, {
|
|
606
|
+
ref: m,
|
|
607
|
+
id: `${h}-list`,
|
|
608
|
+
role: `listbox`,
|
|
609
|
+
className: `dsu-menu`,
|
|
610
|
+
"aria-label": c.label,
|
|
611
|
+
hidden: !l
|
|
612
|
+
}, ...N)));
|
|
613
|
+
}
|
|
614
|
+
function S(t) {
|
|
615
|
+
let n = !t.writable || t.busy || !t.dirty, r;
|
|
616
|
+
return r = t.error === null ? t.writable ? t.dirty ? t.dirtyLabel : t.cleanLabel : t.readOnlyLabel : t.error, (0, react.createElement)(`div`, {
|
|
617
|
+
className: `dsu-savebar`,
|
|
618
|
+
"data-dirty": t.dirty
|
|
619
|
+
}, (0, react.createElement)(`button`, {
|
|
620
|
+
type: `button`,
|
|
621
|
+
className: `dsu-btn dsu-btnPrimary`,
|
|
622
|
+
"data-field": `save`,
|
|
623
|
+
disabled: n,
|
|
624
|
+
onClick: t.onSave
|
|
625
|
+
}, t.busy ? t.savingLabel : t.saveLabel), (0, react.createElement)(`button`, {
|
|
626
|
+
type: `button`,
|
|
627
|
+
className: `dsu-btn`,
|
|
628
|
+
"data-field": `discard`,
|
|
629
|
+
disabled: n,
|
|
630
|
+
onClick: t.onDiscard
|
|
631
|
+
}, t.revertLabel), (0, react.createElement)(`span`, { className: t.error === null ? `dsu-status` : `dsu-status dsu-statusError` }, r));
|
|
632
|
+
}
|
|
100
633
|
// lib/card-draft.ts
|
|
101
634
|
/** 草稿优先取值:touched 有该键(哪怕值是 undefined=待清空)即用草稿。
|
|
102
635
|
* 只判**自有**属性:本函数收任意字段名,`in` 会沿原型链命中 `toString` /
|
|
@@ -164,6 +697,8 @@ function numericFieldDisplay(touched, value, field, fallback) {
|
|
|
164
697
|
if (draft === void 0) return Object.hasOwn(touched, field) ? "" : fallback;
|
|
165
698
|
return numberText(draft, fallback);
|
|
166
699
|
}
|
|
700
|
+
/** 端点字段的 URL 形态:空串(= 恢复默认)与坏文本都显示成空,输入框只收 HTTP(S)。 */
|
|
701
|
+
const HTTP_URL_SCHEMA = zod.z.url({ protocol: /^https?$/u });
|
|
167
702
|
/** 六个字段的草稿显示值(ZgCard 只渲染这里算出来的东西)。 */
|
|
168
703
|
function draftFields(touched, value) {
|
|
169
704
|
const embedding = draftOf(touched, value, "defaultEmbedding");
|
|
@@ -172,16 +707,25 @@ function draftFields(touched, value) {
|
|
|
172
707
|
return {
|
|
173
708
|
embedding: typeof embedding === "string" && embedding.length > 0 ? embedding : DEFAULT_EMBEDDING,
|
|
174
709
|
limitDisplay: numericFieldDisplay(touched, value, "defaultLimit", String(10)),
|
|
175
|
-
hfEndpoint: typeof endpoint === "string" ? endpoint : "",
|
|
710
|
+
hfEndpoint: typeof endpoint === "string" && HTTP_URL_SCHEMA.safeParse(endpoint).success ? endpoint : "",
|
|
176
711
|
enforceSearchFirst: enforce !== false,
|
|
177
712
|
grepBudget: numericFieldDisplay(touched, value, "grepBudgetPerSearch", String(3)),
|
|
178
713
|
unlockWindow: numericFieldDisplay(touched, value, "unlockWindowMin", String(10))
|
|
179
714
|
};
|
|
180
715
|
}
|
|
716
|
+
/** 三个数值字段的 zod 域:输入校验与卡片显示共用,host schema 的区间是同一组常量。 */
|
|
717
|
+
const LIMIT_SCHEMA = zod.z.int().min(1).max(50);
|
|
718
|
+
const BUDGET_SCHEMA = zod.z.int().min(1).max(20);
|
|
719
|
+
const WINDOW_SCHEMA = zod.z.int().min(1).max(240);
|
|
181
720
|
function resolveLimitInput(raw, t) {
|
|
182
721
|
const trimmed = raw.trim();
|
|
183
722
|
if (trimmed.length === 0) return { kind: "empty" };
|
|
184
723
|
const num = Number(trimmed);
|
|
724
|
+
const parsed = LIMIT_SCHEMA.safeParse(num);
|
|
725
|
+
if (parsed.success) return {
|
|
726
|
+
kind: "valid",
|
|
727
|
+
value: parsed.data
|
|
728
|
+
};
|
|
185
729
|
if (!Number.isSafeInteger(num)) return {
|
|
186
730
|
kind: "invalid",
|
|
187
731
|
hint: t("limitInvalid", {
|
|
@@ -198,7 +742,7 @@ function resolveLimitInput(raw, t) {
|
|
|
198
742
|
value: 1
|
|
199
743
|
})
|
|
200
744
|
};
|
|
201
|
-
|
|
745
|
+
return {
|
|
202
746
|
kind: "clamped",
|
|
203
747
|
value: 50,
|
|
204
748
|
hint: t("limitClamped", {
|
|
@@ -207,29 +751,21 @@ function resolveLimitInput(raw, t) {
|
|
|
207
751
|
value: 50
|
|
208
752
|
})
|
|
209
753
|
};
|
|
210
|
-
return {
|
|
211
|
-
kind: "valid",
|
|
212
|
-
value: num
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
function limitDraftOf(raw, t) {
|
|
216
|
-
const resolution = resolveLimitInput(raw, t);
|
|
217
|
-
if (resolution.kind === "invalid") return {
|
|
218
|
-
draft: void 0,
|
|
219
|
-
error: resolution.hint,
|
|
220
|
-
hint: null
|
|
221
|
-
};
|
|
222
|
-
if (resolution.kind === "empty") return {
|
|
223
|
-
draft: void 0,
|
|
224
|
-
error: null,
|
|
225
|
-
hint: null
|
|
226
|
-
};
|
|
227
|
-
return {
|
|
228
|
-
draft: resolution.value,
|
|
229
|
-
error: null,
|
|
230
|
-
hint: resolution.kind === "clamped" ? resolution.hint : null
|
|
231
|
-
};
|
|
232
754
|
}
|
|
755
|
+
/** 轮询应答的宽容形状:未知状态、非数字退出码、非字符串输出都折成缺位,
|
|
756
|
+
* 下游文案只按“缺位”兜底,不把坏类型带到渲染期。 */
|
|
757
|
+
const REBUILD_STATUSES = [
|
|
758
|
+
"running",
|
|
759
|
+
"stopping",
|
|
760
|
+
"completed",
|
|
761
|
+
"killed",
|
|
762
|
+
"failed"
|
|
763
|
+
];
|
|
764
|
+
const REBUILD_POLL_SCHEMA = zod.z.object({
|
|
765
|
+
status: zod.z.preprocess((value) => typeof value === "string" && REBUILD_STATUSES.some((status) => status === value) ? value : void 0, zod.z.enum(REBUILD_STATUSES).optional()),
|
|
766
|
+
exitCode: zod.z.preprocess((value) => typeof value === "number" && Number.isFinite(value) ? value : void 0, zod.z.number().optional()),
|
|
767
|
+
output: zod.z.preprocess((value) => typeof value === "string" ? value : void 0, zod.z.string().optional())
|
|
768
|
+
});
|
|
233
769
|
/**
|
|
234
770
|
* 轮询应答 → 卡片状态。
|
|
235
771
|
* 关键:harness 的 bash-local 对**任何自然退出**都置 `status:'completed'`
|
|
@@ -241,8 +777,9 @@ function limitDraftOf(raw, t) {
|
|
|
241
777
|
* - `failed`:注册表侧判定失败(生产者的 done 被拒、或收尾抛错),此时没有退出码可读。
|
|
242
778
|
*/
|
|
243
779
|
function parseRebuildPoll(body, t) {
|
|
244
|
-
const
|
|
245
|
-
const
|
|
780
|
+
const parsed = REBUILD_POLL_SCHEMA.safeParse(body);
|
|
781
|
+
const { status, exitCode, output } = parsed.success ? parsed.data : {};
|
|
782
|
+
const outputText = output ?? "";
|
|
246
783
|
if (status === "running" || status === "stopping") return {
|
|
247
784
|
phase: "running",
|
|
248
785
|
output: outputText.length > 0 ? outputText : t("rebuildRunning")
|
|
@@ -272,6 +809,14 @@ const REBUILD_NAMESPACE = "zvecGrepRebuild";
|
|
|
272
809
|
const REBUILD_SERVICE_KEY = `remote.${REBUILD_NAMESPACE}`;
|
|
273
810
|
/** 卡片所在 bundle 的包名(`$mount` 的 `package` 位与槽位键同源,见 client-entry.ts 的 BUNDLE_PKG)。 */
|
|
274
811
|
const PACKAGE_NAME = "@jayyuen66/dsh-zvec-grep";
|
|
812
|
+
/** strict codec 的统一出口:失败交给 zod 的 `prettifyError`,读到的是一份带字段路径的说明。 */
|
|
813
|
+
function parseOrThrow(schema, value) {
|
|
814
|
+
const parsed = schema.safeParse(value);
|
|
815
|
+
if (!parsed.success) throw new TypeError(zod.z.prettifyError(parsed.error));
|
|
816
|
+
return parsed.data;
|
|
817
|
+
}
|
|
818
|
+
const START_SCHEMA = zod.z.object({ root: zod.z.string({ error: "rebuild request requires a string root" }) }, { error: "rebuild request requires a string root" });
|
|
819
|
+
const STATUS_SCHEMA = zod.z.object({ jobId: zod.z.string({ error: "rebuild status request requires a string jobId" }) }, { error: "rebuild status request requires a string jobId" });
|
|
275
820
|
/** 把宿主那三个方法挂到客户端远程面上的描述符(`id` 的形状照生成器:`<包>#<命名空间>/<方法>`)。
|
|
276
821
|
* 导出它只为一件事:`test/rebuild-remote.test.ts` 拿它与宿主侧 `remoteMethods()` 的标记对质
|
|
277
822
|
* —— 两侧分叉时卡片不会报错,只会"读不到",所以那条比较必须在门禁里。 */
|
|
@@ -299,8 +844,7 @@ const REBUILD_DESCRIPTORS = [
|
|
|
299
844
|
mode: "strict",
|
|
300
845
|
typeSymbol: `${PACKAGE_NAME}#rebuild-request`,
|
|
301
846
|
create: () => ({ parse(value) {
|
|
302
|
-
|
|
303
|
-
return { root: value["root"] };
|
|
847
|
+
return parseOrThrow(START_SCHEMA, value);
|
|
304
848
|
} })
|
|
305
849
|
}
|
|
306
850
|
}],
|
|
@@ -320,8 +864,7 @@ const REBUILD_DESCRIPTORS = [
|
|
|
320
864
|
mode: "strict",
|
|
321
865
|
typeSymbol: `${PACKAGE_NAME}#rebuild-status-request`,
|
|
322
866
|
create: () => ({ parse(value) {
|
|
323
|
-
|
|
324
|
-
return { jobId: value["jobId"] };
|
|
867
|
+
return parseOrThrow(STATUS_SCHEMA, value);
|
|
325
868
|
} })
|
|
326
869
|
}
|
|
327
870
|
}],
|
|
@@ -398,31 +941,34 @@ function createRebuildReader(ctx) {
|
|
|
398
941
|
// src/ui-messages.ts
|
|
399
942
|
const UI_MESSAGES = {
|
|
400
943
|
zh: {
|
|
401
|
-
cardTitle: "zvec-grep(zg)",
|
|
402
|
-
cardDescription: "工作区语义检索:zg_search / zg_index / zg_status;本地 embedding + BM25 + 向量 RRF",
|
|
403
944
|
statusReadOnly: "当前作用域只读",
|
|
404
945
|
statusDirty: "有未保存的修改,点「保存」生效",
|
|
405
946
|
statusClean: "无未保存的修改",
|
|
947
|
+
dirtyCount: "已修改 {count} 项",
|
|
406
948
|
save: "保存",
|
|
407
949
|
saving: "保存中…",
|
|
408
950
|
revert: "撤销",
|
|
409
951
|
saveFailed: "保存失败:{reason}",
|
|
410
952
|
saveRejected: "保存被宿主拒绝(配置校验未通过或写入被跳过),修改未生效",
|
|
953
|
+
modelSection: "检索模型",
|
|
954
|
+
indexSection: "网络与索引",
|
|
955
|
+
unitResults: "条",
|
|
956
|
+
unitTimes: "次",
|
|
957
|
+
unitMinutes: "分钟",
|
|
958
|
+
outOfRange: "超出允许范围,未保存",
|
|
411
959
|
embeddingLabel: "默认本地 embedding",
|
|
412
960
|
embeddingHint: "只影响「新建」索引;切换并保存后,已有索引需点下方「重建」重新 embedding",
|
|
413
|
-
limitLabel: "
|
|
961
|
+
limitLabel: "默认每组结果数",
|
|
414
962
|
limitInvalid: "请输入 {min}-{max} 的整数",
|
|
415
963
|
limitClamped: "已钳到 {min}-{max} 范围:{value}",
|
|
416
|
-
endpointLabel: "HuggingFace
|
|
964
|
+
endpointLabel: "HuggingFace 镜像地址",
|
|
417
965
|
endpointHint: "留空走 huggingface.co;国内网络可填 https://modelscope.cn/models 等兼容镜像(仅 llama-cpp 后端生效,如 qwen3)",
|
|
418
966
|
enforceLabel: "强制 search-first(先 zg_search 再 grep/rg)",
|
|
419
967
|
enforceHint: "开启后,已建索引工作区内的 grep/rg 受配额门禁约束:每次成功 zg_search 解锁下方次数的 grep/rg(时效见下),用尽或过期后再次拦截(提高检索覆盖与准确性)",
|
|
420
|
-
budgetLabel: "每次 zg_search 解锁的 grep/rg
|
|
968
|
+
budgetLabel: "每次 zg_search 解锁的 grep/rg 次数",
|
|
421
969
|
budgetHint: "配额越小语义检索越频繁、准确性约束越强;清空恢复默认 {default}",
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
windowHint: "超过该时长未再次 zg_search,配额整体过期;清空恢复默认 {default}",
|
|
425
|
-
windowInvalid: "解锁时效必须是 {min}-{max} 的整数",
|
|
970
|
+
windowLabel: "解锁时效",
|
|
971
|
+
windowHint: "超过该时长未再次 zg_search,配额整体过期;清空恢复默认 {default}(单位:分钟)",
|
|
426
972
|
rebuildLabel: "工作区重建(切换 embedding 并保存后执行)",
|
|
427
973
|
daemonReadyNote: "守护进程:就绪(zg server 在跑)。",
|
|
428
974
|
daemonOfflineNote: "守护进程:未就绪。守护进程提供的索引增量刷新、refresh=background 与常驻模型池在缺席时都不可用;需要时在终端执行 `zg server on`。",
|
|
@@ -446,31 +992,34 @@ const UI_MESSAGES = {
|
|
|
446
992
|
backendModel2Vec: "model2vec(纯 JS worker,最轻)"
|
|
447
993
|
},
|
|
448
994
|
en: {
|
|
449
|
-
cardTitle: "zvec-grep (zg)",
|
|
450
|
-
cardDescription: "Workspace semantic search: zg_search / zg_index / zg_status; local embedding + BM25 + vector RRF",
|
|
451
995
|
statusReadOnly: "This scope is read-only",
|
|
452
996
|
statusDirty: "Unsaved changes — press Save to apply",
|
|
453
997
|
statusClean: "No unsaved changes",
|
|
998
|
+
dirtyCount: "{count} changed",
|
|
454
999
|
save: "Save",
|
|
455
1000
|
saving: "Saving…",
|
|
456
1001
|
revert: "Revert",
|
|
457
1002
|
saveFailed: "save failed: {reason}",
|
|
458
1003
|
saveRejected: "save rejected by host (validation failed or write skipped) — changes not applied",
|
|
1004
|
+
modelSection: "Retrieval model",
|
|
1005
|
+
indexSection: "Network and index",
|
|
1006
|
+
unitResults: "hits",
|
|
1007
|
+
unitTimes: "times",
|
|
1008
|
+
unitMinutes: "minutes",
|
|
1009
|
+
outOfRange: "Out of the allowed range — not saved",
|
|
459
1010
|
embeddingLabel: "Default local embedding",
|
|
460
1011
|
embeddingHint: "Affects newly built indexes only; after switching and saving, press Rebuild below to re-embed existing indexes",
|
|
461
|
-
limitLabel: "Default hits per group
|
|
1012
|
+
limitLabel: "Default hits per group",
|
|
462
1013
|
limitInvalid: "enter an integer between {min} and {max}",
|
|
463
1014
|
limitClamped: "clamped into the {min}-{max} range: {value}",
|
|
464
|
-
endpointLabel: "HuggingFace mirror URL
|
|
1015
|
+
endpointLabel: "HuggingFace mirror URL",
|
|
465
1016
|
endpointHint: "Leave empty for huggingface.co; on networks that cannot reach HF, fill a compatible mirror such as https://modelscope.cn/models (llama-cpp backends only, e.g. qwen3)",
|
|
466
1017
|
enforceLabel: "Enforce search-first (zg_search before grep/rg)",
|
|
467
1018
|
enforceHint: "When on, grep/rg inside indexed workspaces is quota-gated: each successful zg_search unlocks the number of grep/rg calls below (valid for the window below), and the gate blocks again once it is spent or expired (better coverage and relevance)",
|
|
468
|
-
budgetLabel: "grep/rg calls unlocked per zg_search
|
|
1019
|
+
budgetLabel: "grep/rg calls unlocked per zg_search",
|
|
469
1020
|
budgetHint: "A smaller quota means more semantic searches and a stronger relevance constraint; clear to restore the default {default}",
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
windowHint: "Without another zg_search inside this window the whole quota expires; clear to restore the default {default}",
|
|
473
|
-
windowInvalid: "the unlock window must be an integer between {min} and {max}",
|
|
1021
|
+
windowLabel: "Unlock window",
|
|
1022
|
+
windowHint: "Without another zg_search inside this window the whole quota expires; clear to restore the default {default} (minutes)",
|
|
474
1023
|
rebuildLabel: "Workspace rebuild (run after switching embedding and saving)",
|
|
475
1024
|
daemonReadyNote: "Daemon: ready (zg server is running).",
|
|
476
1025
|
daemonOfflineNote: "Daemon: not ready. What the daemon provides — incremental index refresh, refresh=background and the resident embedding model pool — is unavailable while it is absent; run `zg server on` in a terminal when you want it.",
|
|
@@ -543,44 +1092,15 @@ const BUNDLE_PKG = "@jayyuen66/dsh-zvec-grep";
|
|
|
543
1092
|
/** 重建轮询间隔(宿主后台进程,2s 足够跟上 zg 的进度输出)。 */
|
|
544
1093
|
const REBUILD_POLL_MS = 2e3;
|
|
545
1094
|
const CARD_CSS = [
|
|
546
|
-
".zgc-
|
|
547
|
-
".zgc-
|
|
548
|
-
".zgc-
|
|
549
|
-
".zgc-card-header{appearance:none;width:100%;font:inherit;color:inherit;text-align:left;cursor:pointer;background:transparent;border:0;border-radius:12px;align-items:center;gap:12px;padding:14px 16px;display:flex}",
|
|
550
|
-
".zgc-card-header:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:-2px}",
|
|
551
|
-
".zgc-card-head{flex-direction:column;flex:1;gap:4px;min-width:0;display:flex}",
|
|
552
|
-
".zgc-card-name{color:var(--dsw-alias-label-primary);font-size:15px;font-weight:600;line-height:1.4}",
|
|
553
|
-
".zgc-card-desc{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1.5}",
|
|
554
|
-
".zgc-card-chevron{color:var(--dsw-alias-label-tertiary);flex:none;transition:transform .16s}",
|
|
555
|
-
".zgc-card-chevron-open{transform:rotate(180deg)}",
|
|
556
|
-
".zgc-card-body{border-top:1px solid var(--dsw-alias-border-l2);margin:0 16px;padding:8px 0 12px}",
|
|
557
|
-
".zgc-row{display:flex;flex-direction:column;gap:6px;padding:9px 0}",
|
|
558
|
-
".zgc-label{font-size:13px;color:var(--dsw-alias-label-primary,inherit)}",
|
|
559
|
-
".zgc-hint{font-size:12px;color:var(--dsw-alias-label-tertiary,#8a8f99)}",
|
|
560
|
-
".zgc-select{width:100%;font:inherit;font-size:13px;color:var(--dsw-alias-label-primary,inherit);background:var(--dsw-alias-fill-primary,transparent);border:1px solid var(--dsw-alias-border-l3,#d8dbe2);border-radius:6px;padding:6px 8px;box-sizing:border-box}",
|
|
561
|
-
".zgc-input{width:100%;font:inherit;font-size:13px;color:var(--dsw-alias-label-primary,inherit);background:var(--dsw-alias-fill-primary,transparent);border:1px solid var(--dsw-alias-border-l3,#d8dbe2);border-radius:6px;padding:6px 8px;box-sizing:border-box}",
|
|
562
|
-
".zgc-button{appearance:none;border:1px solid var(--dsw-alias-brand-primary,#2f6fed);color:var(--dsw-alias-brand-primary,#2f6fed);background:transparent;border-radius:6px;padding:5px 12px;font:inherit;font-size:13px;cursor:pointer}",
|
|
563
|
-
".zgc-button:hover:not(:disabled){background:var(--dsw-alias-fill-secondary,rgba(0,0,0,.05))}",
|
|
564
|
-
".zgc-button:disabled{opacity:.5;cursor:progress}",
|
|
565
|
-
".zgc-output{font-size:12px;line-height:1.6;color:var(--dsw-alias-label-secondary,inherit);white-space:pre-wrap;word-break:break-all;max-height:180px;overflow:auto;background:var(--dsw-alias-fill-primary,transparent);border:1px solid var(--dsw-alias-border-l2);border-radius:6px;padding:8px}",
|
|
566
|
-
".zgc-error{font-size:12px;color:var(--dsw-alias-text-danger,#d33)}",
|
|
567
|
-
".zgc-savebar{display:flex;gap:8px;align-items:center;padding:10px 0 2px;border-top:1px dashed var(--dsw-alias-border-l2);margin-top:6px;flex-wrap:wrap}",
|
|
568
|
-
".zgc-btn-primary{appearance:none;border:1px solid var(--dsw-alias-brand-primary,#2f6fed);background:var(--dsw-alias-brand-primary,#2f6fed);color:var(--dsw-alias-label-primary-foreground,#fff);border-radius:6px;padding:5px 12px;font:inherit;font-size:13px;cursor:pointer}",
|
|
569
|
-
".zgc-btn-plain{appearance:none;border:1px solid var(--dsw-alias-border-l2,#d8dbe2);background:transparent;color:var(--dsw-alias-label-primary,inherit);border-radius:6px;padding:5px 12px;font:inherit;font-size:13px;cursor:pointer}",
|
|
570
|
-
".zgc-button:focus-visible,.zgc-btn-primary:focus-visible,.zgc-btn-plain:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#2f6fed);outline-offset:1px}",
|
|
571
|
-
".zgc-btn-primary:hover:not(:disabled){filter:brightness(.96)}",
|
|
572
|
-
".zgc-btn-plain:hover:not(:disabled){background:var(--dsw-alias-fill-secondary,rgba(0,0,0,.05))}",
|
|
573
|
-
".zgc-btn-primary:disabled,.zgc-btn-plain:disabled{opacity:.5;cursor:not-allowed}",
|
|
574
|
-
".zgc-dirty{font-size:12px;color:var(--dsw-alias-label-tertiary,#8a8f99)}",
|
|
575
|
-
".zgc-saveerr{font-size:12px;color:var(--dsw-alias-text-danger,#d33)}"
|
|
1095
|
+
".zgc-rebuildInput{flex:1 1 240px;min-width:0}",
|
|
1096
|
+
".zgc-output{font-size:12px;line-height:1.6;color:var(--dsw-alias-label-secondary,inherit);white-space:pre-wrap;word-break:break-all;max-height:180px;overflow:auto;background:var(--dsw-alias-fill-primary,transparent);border:1px solid var(--dsw-alias-border-l2);border-radius:6px;padding:8px;margin-top:8px}",
|
|
1097
|
+
".zgc-error{font-size:12px;color:var(--dsw-alias-text-danger,#d33);margin-top:8px}"
|
|
576
1098
|
].join("\n");
|
|
577
1099
|
const BACKENDS = [
|
|
578
1100
|
"llama-cpp",
|
|
579
1101
|
"transformers-js",
|
|
580
1102
|
"model2vec"
|
|
581
1103
|
];
|
|
582
|
-
/** SVG path 的 data 属性键(id-length 豁免需经变量计算键表达,oxfmt 不解引号)。 */
|
|
583
|
-
const PATH_DATA_KEY = "d";
|
|
584
1104
|
/** 重建 root 输入框的候选列表 id(与 <datalist> 配对)。 */
|
|
585
1105
|
const ROOT_OPTIONS_ID = "zgc-rebuild-root-options";
|
|
586
1106
|
/** 候选按后端分组,供 <optgroup> 使用(文案取自 UI 字典,这里只留键)。 */
|
|
@@ -594,59 +1114,6 @@ const BACKEND_LABEL_KEY = {
|
|
|
594
1114
|
function snapshotValue(snap) {
|
|
595
1115
|
return snap.value;
|
|
596
1116
|
}
|
|
597
|
-
function PluginCard(props) {
|
|
598
|
-
const { title, description, children } = props;
|
|
599
|
-
const [open, setOpen] = (0, react.useState)(false);
|
|
600
|
-
const headInner = (0, react.createElement)("span", { className: "zgc-card-head" }, (0, react.createElement)("span", { className: "zgc-card-name" }, title), (0, react.createElement)("span", { className: "zgc-card-desc" }, description));
|
|
601
|
-
const chevron = (0, react.createElement)("svg", {
|
|
602
|
-
width: 14,
|
|
603
|
-
height: 14,
|
|
604
|
-
viewBox: "0 0 14 14",
|
|
605
|
-
"aria-hidden": true,
|
|
606
|
-
className: open ? "zgc-card-chevron zgc-card-chevron-open" : "zgc-card-chevron"
|
|
607
|
-
}, (0, react.createElement)("path", {
|
|
608
|
-
[PATH_DATA_KEY]: "M3 5l4 4 4-4",
|
|
609
|
-
fill: "none",
|
|
610
|
-
stroke: "currentColor",
|
|
611
|
-
strokeWidth: 1.5,
|
|
612
|
-
strokeLinecap: "round",
|
|
613
|
-
strokeLinejoin: "round"
|
|
614
|
-
}));
|
|
615
|
-
const header = (0, react.createElement)("button", {
|
|
616
|
-
type: "button",
|
|
617
|
-
className: "zgc-card-header",
|
|
618
|
-
"aria-expanded": open,
|
|
619
|
-
onClick: () => {
|
|
620
|
-
setOpen(!open);
|
|
621
|
-
}
|
|
622
|
-
}, headInner, chevron);
|
|
623
|
-
const body = open ? (0, react.createElement)("div", { className: "zgc-card-body" }, children) : null;
|
|
624
|
-
return (0, react.createElement)("li", { className: open ? "zgc-card zgc-card-open" : "zgc-card" }, header, body);
|
|
625
|
-
}
|
|
626
|
-
/** 保存条(全自研插件统一)。 */
|
|
627
|
-
function SaveBar(props) {
|
|
628
|
-
const { t } = props;
|
|
629
|
-
const disabled = !props.writable || props.busy;
|
|
630
|
-
const saveBtn = (0, react.createElement)("button", {
|
|
631
|
-
type: "button",
|
|
632
|
-
className: "zgc-btn-primary",
|
|
633
|
-
"data-field": "save",
|
|
634
|
-
disabled: disabled || !props.dirty,
|
|
635
|
-
onClick: props.onSave
|
|
636
|
-
}, props.busy ? t("saving") : t("save"));
|
|
637
|
-
const discardBtn = (0, react.createElement)("button", {
|
|
638
|
-
type: "button",
|
|
639
|
-
className: "zgc-btn-plain",
|
|
640
|
-
"data-field": "discard",
|
|
641
|
-
disabled: disabled || !props.dirty,
|
|
642
|
-
onClick: props.onDiscard
|
|
643
|
-
}, t("revert"));
|
|
644
|
-
let statusNode;
|
|
645
|
-
if (props.error !== null) statusNode = (0, react.createElement)("span", { className: "zgc-saveerr" }, props.error);
|
|
646
|
-
else if (props.writable) statusNode = (0, react.createElement)("span", { className: "zgc-dirty" }, props.dirty ? t("statusDirty") : t("statusClean"));
|
|
647
|
-
else statusNode = (0, react.createElement)("span", { className: "zgc-dirty" }, t("statusReadOnly"));
|
|
648
|
-
return (0, react.createElement)("div", { className: "zgc-savebar" }, saveBtn, discardBtn, statusNode);
|
|
649
|
-
}
|
|
650
1117
|
/**
|
|
651
1118
|
* embedding 候选项文本(官方 locale 的 {name} 插值)。提成模块级函数是为了不把
|
|
652
1119
|
* t() 嵌进 createElement(unicorn/max-nested-calls 上限 3)。
|
|
@@ -664,149 +1131,65 @@ function rebuildHintText(t, embedding, hasRoots) {
|
|
|
664
1131
|
roots: t(hasRoots ? "rootsNoteWith" : "rootsNoteEmpty")
|
|
665
1132
|
});
|
|
666
1133
|
}
|
|
667
|
-
/**
|
|
668
|
-
function
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
1134
|
+
/** embedding 候选的显示文本与分组(供共享 SelectField 的 options)。 */
|
|
1135
|
+
function embeddingOptions(t) {
|
|
1136
|
+
const options = [];
|
|
1137
|
+
for (const backend of BACKENDS) for (const entry of LOCAL_EMBEDDINGS) if (entry.backend === backend) options.push({
|
|
1138
|
+
value: entry.reference,
|
|
1139
|
+
label: modelOptionText(t, entry.reference, entry.dimension),
|
|
1140
|
+
group: t(BACKEND_LABEL_KEY[backend])
|
|
672
1141
|
});
|
|
1142
|
+
return options;
|
|
673
1143
|
}
|
|
674
|
-
/**
|
|
675
|
-
function
|
|
676
|
-
const
|
|
677
|
-
|
|
678
|
-
const options = [];
|
|
679
|
-
for (const entry of LOCAL_EMBEDDINGS) if (entry.backend === backend) {
|
|
680
|
-
const { reference, dimension } = entry;
|
|
681
|
-
options.push((0, react.createElement)("option", {
|
|
682
|
-
key: reference,
|
|
683
|
-
value: reference
|
|
684
|
-
}, modelOptionText(t, reference, dimension)));
|
|
685
|
-
}
|
|
686
|
-
groups.push((0, react.createElement)("optgroup", {
|
|
687
|
-
key: backend,
|
|
688
|
-
label: t(BACKEND_LABEL_KEY[backend])
|
|
689
|
-
}, options));
|
|
690
|
-
}
|
|
691
|
-
return [(0, react.createElement)("select", {
|
|
692
|
-
className: "zgc-select",
|
|
693
|
-
value: embeddingValue,
|
|
694
|
-
disabled: !editable,
|
|
695
|
-
onChange: (ev) => {
|
|
696
|
-
setField("defaultEmbedding", ev.target.value);
|
|
697
|
-
}
|
|
698
|
-
}, groups)];
|
|
699
|
-
}
|
|
700
|
-
/** embedding 行:本地后端分组的 <select>(候选文本带维度插值)。 */
|
|
701
|
-
function buildEmbeddingRow(deps) {
|
|
702
|
-
const { editable, fields, setField, t } = deps;
|
|
703
|
-
const embeddingLabel = (0, react.createElement)("div", { className: "zgc-label" }, t("embeddingLabel"));
|
|
704
|
-
const embeddingHint = (0, react.createElement)("div", { className: "zgc-hint" }, t("embeddingHint"));
|
|
705
|
-
const embeddingSelects = buildOptionGroups(t, fields.embedding, editable, setField);
|
|
706
|
-
return (0, react.createElement)("div", { className: "zgc-row" }, embeddingLabel, embeddingHint, embeddingSelects[0]);
|
|
707
|
-
}
|
|
708
|
-
/** defaultLimit 行:数字输入,区间判定在 lib/card-logic.ts 的 limitDraftOf。 */
|
|
709
|
-
function buildLimitRow(deps) {
|
|
710
|
-
const { editable, fields, setField, setSaveError, t } = deps;
|
|
711
|
-
const limitLabel = (0, react.createElement)("div", { className: "zgc-label" }, t("limitLabel", {
|
|
712
|
-
min: 1,
|
|
713
|
-
max: 50
|
|
714
|
-
}));
|
|
715
|
-
const limitInput = (0, react.createElement)("input", {
|
|
716
|
-
className: "zgc-input",
|
|
717
|
-
type: "number",
|
|
718
|
-
min: 1,
|
|
719
|
-
max: 50,
|
|
720
|
-
value: fields.limitDisplay,
|
|
721
|
-
disabled: !editable,
|
|
722
|
-
onChange: (ev) => {
|
|
723
|
-
const draft = limitDraftOf(ev.target.value, t);
|
|
724
|
-
setSaveError(draft.error ?? draft.hint);
|
|
725
|
-
if (draft.error === null) setField("defaultLimit", draft.draft);
|
|
726
|
-
}
|
|
727
|
-
});
|
|
728
|
-
return (0, react.createElement)("div", { className: "zgc-row" }, limitLabel, limitInput);
|
|
729
|
-
}
|
|
730
|
-
/** hfEndpoint 行:镜像基地址(占位符即 schema 默认的那枚镜像,留空走官方 HF)。 */
|
|
731
|
-
function buildEndpointRow(deps) {
|
|
732
|
-
const { editable, fields, setField, t } = deps;
|
|
733
|
-
const endpointLabel = (0, react.createElement)("div", { className: "zgc-label" }, t("endpointLabel"));
|
|
734
|
-
const endpointHint = (0, react.createElement)("div", { className: "zgc-hint" }, t("endpointHint"));
|
|
735
|
-
const endpointInput = (0, react.createElement)("input", {
|
|
736
|
-
className: "zgc-input",
|
|
737
|
-
value: fields.hfEndpoint,
|
|
738
|
-
placeholder: "https://modelscope.cn/models",
|
|
739
|
-
disabled: !editable,
|
|
740
|
-
onChange: (ev) => {
|
|
741
|
-
setField("hfEndpoint", ev.target.value);
|
|
742
|
-
}
|
|
743
|
-
});
|
|
744
|
-
return (0, react.createElement)("div", { className: "zgc-row" }, endpointLabel, endpointHint, endpointInput);
|
|
1144
|
+
/** 数字草稿串 → 控件值:区间由 zod schema 判定;空串是「清空 = 恢复默认」,不是 0。 */
|
|
1145
|
+
function numberDisplay(display, schema) {
|
|
1146
|
+
const parsed = schema.safeParse(display === "" ? NaN : Number(display));
|
|
1147
|
+
return parsed.success ? parsed.data : void 0;
|
|
745
1148
|
}
|
|
746
|
-
/**
|
|
747
|
-
function
|
|
1149
|
+
/** 检索模型小节:embedding 下拉(按本地后端分组)+ 每组结果数。 */
|
|
1150
|
+
function buildModelSection(deps) {
|
|
748
1151
|
const { editable, fields, setField, t } = deps;
|
|
749
|
-
const
|
|
750
|
-
|
|
751
|
-
|
|
1152
|
+
const embedding = (0, react.createElement)(x, {
|
|
1153
|
+
label: t("embeddingLabel"),
|
|
1154
|
+
...l(t("embeddingHint")),
|
|
1155
|
+
field: "defaultEmbedding",
|
|
1156
|
+
value: fields.embedding,
|
|
1157
|
+
options: embeddingOptions(t),
|
|
752
1158
|
disabled: !editable,
|
|
753
|
-
onChange: (
|
|
754
|
-
setField("
|
|
1159
|
+
onChange: (next) => {
|
|
1160
|
+
setField("defaultEmbedding", next);
|
|
755
1161
|
}
|
|
756
1162
|
});
|
|
757
|
-
const
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
const label = (0, react.createElement)("div", { className: "zgc-label" }, t(spec.labelKey, {
|
|
771
|
-
min: 1,
|
|
772
|
-
max: spec.max
|
|
773
|
-
}));
|
|
774
|
-
const hint = (0, react.createElement)("div", { className: "zgc-hint" }, t(spec.hintKey, { default: spec.default }));
|
|
775
|
-
const input = (0, react.createElement)("input", {
|
|
776
|
-
className: "zgc-input",
|
|
777
|
-
type: "number",
|
|
778
|
-
min: 1,
|
|
779
|
-
max: spec.max,
|
|
780
|
-
value: spec.value,
|
|
1163
|
+
const limit = (0, react.createElement)(v, {
|
|
1164
|
+
label: t("limitLabel"),
|
|
1165
|
+
hint: t("limitInvalid", {
|
|
1166
|
+
min: 1,
|
|
1167
|
+
max: 50
|
|
1168
|
+
}),
|
|
1169
|
+
field: "defaultLimit",
|
|
1170
|
+
value: numberDisplay(fields.limitDisplay, LIMIT_SCHEMA),
|
|
1171
|
+
min: LIMIT_SCHEMA.minValue ?? 1,
|
|
1172
|
+
max: LIMIT_SCHEMA.maxValue ?? 50,
|
|
1173
|
+
step: 1,
|
|
1174
|
+
unit: t("unitResults"),
|
|
1175
|
+
invalidHint: t("outOfRange"),
|
|
781
1176
|
disabled: !editable,
|
|
782
|
-
onChange: (
|
|
783
|
-
|
|
784
|
-
if (raw === "") {
|
|
785
|
-
setSaveError(null);
|
|
786
|
-
setField(spec.field, void 0);
|
|
787
|
-
return;
|
|
788
|
-
}
|
|
789
|
-
const num = Number(raw);
|
|
790
|
-
if (Number.isSafeInteger(num) && num >= 1 && num <= spec.max) {
|
|
791
|
-
setSaveError(null);
|
|
792
|
-
setField(spec.field, num);
|
|
793
|
-
} else setSaveError(rangeErrorText(t, spec.invalidKey, spec.max));
|
|
1177
|
+
onChange: (next) => {
|
|
1178
|
+
setField("defaultLimit", next);
|
|
794
1179
|
}
|
|
795
1180
|
});
|
|
796
|
-
return (0, react.createElement)(
|
|
1181
|
+
return (0, react.createElement)(d, { title: t("modelSection") }, embedding, limit);
|
|
797
1182
|
}
|
|
798
1183
|
/** 重建行:root 输入(白名单候选进 <datalist>)+ 触发按钮(在跑时禁用)。 */
|
|
799
|
-
function
|
|
1184
|
+
function buildRebuildField(deps) {
|
|
800
1185
|
const { fields, rebuild, root, roots, setRoot, t } = deps;
|
|
801
|
-
const rebuildLabel = (0, react.createElement)("div", { className: "zgc-label" }, t("rebuildLabel"));
|
|
802
|
-
const rebuildHint = (0, react.createElement)("div", { className: "zgc-hint" }, rebuildHintText(t, fields.embedding, roots.length > 0));
|
|
803
1186
|
const rootOptions = roots.map((entry) => (0, react.createElement)("option", {
|
|
804
1187
|
key: entry,
|
|
805
1188
|
value: entry
|
|
806
1189
|
}));
|
|
807
1190
|
const rootDatalist = (0, react.createElement)("datalist", { id: ROOT_OPTIONS_ID }, ...rootOptions);
|
|
808
1191
|
const rebuildInput = (0, react.createElement)("input", {
|
|
809
|
-
className: "zgc-
|
|
1192
|
+
className: "dsu-input zgc-rebuildInput",
|
|
810
1193
|
value: root,
|
|
811
1194
|
list: ROOT_OPTIONS_ID,
|
|
812
1195
|
placeholder: "/absolute/path/to/workspace",
|
|
@@ -816,12 +1199,16 @@ function buildRebuildRow(deps) {
|
|
|
816
1199
|
});
|
|
817
1200
|
const rebuildButton = (0, react.createElement)("button", {
|
|
818
1201
|
type: "button",
|
|
819
|
-
className: "
|
|
1202
|
+
className: "dsu-btn",
|
|
820
1203
|
"data-field": "rebuild",
|
|
821
1204
|
disabled: rebuild.phase === "running",
|
|
822
1205
|
onClick: deps.onRebuild
|
|
823
1206
|
}, rebuild.phase === "running" ? t("rebuildRunning") : t("rebuildButton"));
|
|
824
|
-
return (0, react.createElement)(
|
|
1207
|
+
return (0, react.createElement)(g, {
|
|
1208
|
+
label: t("rebuildLabel"),
|
|
1209
|
+
...l(rebuildHintText(t, fields.embedding, roots.length > 0)),
|
|
1210
|
+
wide: true
|
|
1211
|
+
}, rootDatalist, rebuildInput, rebuildButton);
|
|
825
1212
|
}
|
|
826
1213
|
/**
|
|
827
1214
|
* 守护进程(`zg server`)就绪态一行,取自 rebuild-roots 引导端点。
|
|
@@ -835,8 +1222,7 @@ function buildDaemonNote(deps) {
|
|
|
835
1222
|
const { t } = deps;
|
|
836
1223
|
const key = daemonNoteKey(deps.serverReady);
|
|
837
1224
|
if (key === void 0) return null;
|
|
838
|
-
|
|
839
|
-
return (0, react.createElement)("div", { className: "zgc-row" }, note);
|
|
1225
|
+
return (0, react.createElement)("p", { className: "dsu-hint" }, t(key));
|
|
840
1226
|
}
|
|
841
1227
|
/** 重建状态节点:phase 非 idle 才出现;done 且无输出时给一句「已完成」。 */
|
|
842
1228
|
function buildRebuildStatusRow(deps) {
|
|
@@ -848,50 +1234,81 @@ function buildRebuildStatusRow(deps) {
|
|
|
848
1234
|
else displayText = rebuild.output;
|
|
849
1235
|
return (0, react.createElement)("div", { className: displayClass }, displayText);
|
|
850
1236
|
}
|
|
851
|
-
/**
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
1237
|
+
/** 网络与索引小节:镜像地址、search-first 开关、配额与时效、工作区重建与守护进程状态。 */
|
|
1238
|
+
function buildIndexSection(deps) {
|
|
1239
|
+
const { editable, fields, setField, t } = deps;
|
|
1240
|
+
const endpoint = (0, react.createElement)(y, {
|
|
1241
|
+
label: t("endpointLabel"),
|
|
1242
|
+
...l(t("endpointHint")),
|
|
1243
|
+
field: "hfEndpoint",
|
|
1244
|
+
value: fields.hfEndpoint,
|
|
1245
|
+
placeholder: "https://modelscope.cn/models",
|
|
1246
|
+
monospace: true,
|
|
1247
|
+
disabled: !editable,
|
|
1248
|
+
onChange: (next) => {
|
|
1249
|
+
setField("hfEndpoint", next.trim() === "" ? void 0 : next.trim());
|
|
1250
|
+
}
|
|
1251
|
+
});
|
|
1252
|
+
const enforce = (0, react.createElement)(_, {
|
|
1253
|
+
label: t("enforceLabel"),
|
|
1254
|
+
...l(t("enforceHint")),
|
|
1255
|
+
field: "enforceSearchFirst",
|
|
1256
|
+
checked: fields.enforceSearchFirst,
|
|
1257
|
+
disabled: !editable,
|
|
1258
|
+
onChange: (next) => {
|
|
1259
|
+
setField("enforceSearchFirst", next);
|
|
1260
|
+
}
|
|
1261
|
+
});
|
|
1262
|
+
const budget = (0, react.createElement)(v, {
|
|
1263
|
+
label: t("budgetLabel"),
|
|
1264
|
+
...l(t("budgetHint", { default: 3 })),
|
|
1265
|
+
field: "grepBudgetPerSearch",
|
|
1266
|
+
value: numberDisplay(fields.grepBudget, BUDGET_SCHEMA),
|
|
1267
|
+
min: BUDGET_SCHEMA.minValue ?? 1,
|
|
1268
|
+
max: BUDGET_SCHEMA.maxValue ?? 20,
|
|
1269
|
+
step: 1,
|
|
1270
|
+
unit: t("unitTimes"),
|
|
1271
|
+
invalidHint: t("outOfRange"),
|
|
1272
|
+
disabled: !editable,
|
|
1273
|
+
onChange: (next) => {
|
|
1274
|
+
setField("grepBudgetPerSearch", next);
|
|
1275
|
+
}
|
|
1276
|
+
});
|
|
1277
|
+
const window = (0, react.createElement)(v, {
|
|
1278
|
+
label: t("windowLabel"),
|
|
1279
|
+
...l(t("windowHint", { default: 10 })),
|
|
1280
|
+
field: "unlockWindowMin",
|
|
1281
|
+
value: numberDisplay(fields.unlockWindow, WINDOW_SCHEMA),
|
|
1282
|
+
min: WINDOW_SCHEMA.minValue ?? 1,
|
|
1283
|
+
max: WINDOW_SCHEMA.maxValue ?? 240,
|
|
1284
|
+
step: 1,
|
|
1285
|
+
unit: t("unitMinutes"),
|
|
1286
|
+
invalidHint: t("outOfRange"),
|
|
1287
|
+
disabled: !editable,
|
|
1288
|
+
onChange: (next) => {
|
|
1289
|
+
setField("unlockWindowMin", next);
|
|
1290
|
+
}
|
|
1291
|
+
});
|
|
1292
|
+
return (0, react.createElement)(d, { title: t("indexSection") }, endpoint, enforce, budget, window, buildDaemonNote(deps), buildRebuildField(deps), buildRebuildStatusRow(deps));
|
|
1293
|
+
}
|
|
1294
|
+
/** 卡片主体:检索模型 / 网络与索引两节 + 保存条。 */
|
|
855
1295
|
function buildCardBody(deps) {
|
|
856
|
-
const {
|
|
857
|
-
const
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
labelKey: "windowLabel",
|
|
873
|
-
hintKey: "windowHint",
|
|
874
|
-
field: "unlockWindowMin",
|
|
875
|
-
invalidKey: "windowInvalid",
|
|
876
|
-
max: 240,
|
|
877
|
-
default: 10,
|
|
878
|
-
value: fields.unlockWindow
|
|
879
|
-
}),
|
|
880
|
-
(0, react.createElement)(SaveBar, {
|
|
881
|
-
t,
|
|
882
|
-
dirty: deps.dirty,
|
|
883
|
-
writable: deps.writable,
|
|
884
|
-
busy: deps.busy,
|
|
885
|
-
error: deps.saveError,
|
|
886
|
-
onSave: deps.onSave,
|
|
887
|
-
onDiscard: deps.onDiscard
|
|
888
|
-
}),
|
|
889
|
-
buildDaemonNote(deps),
|
|
890
|
-
buildRebuildRow(deps)
|
|
891
|
-
];
|
|
892
|
-
const status = buildRebuildStatusRow(deps);
|
|
893
|
-
if (status !== null) rows.push(status);
|
|
894
|
-
return rows;
|
|
1296
|
+
const { t } = deps;
|
|
1297
|
+
const saveBar = (0, react.createElement)(S, {
|
|
1298
|
+
dirty: deps.dirty,
|
|
1299
|
+
busy: deps.busy,
|
|
1300
|
+
writable: deps.writable,
|
|
1301
|
+
error: deps.saveError,
|
|
1302
|
+
saveLabel: t("save"),
|
|
1303
|
+
savingLabel: t("saving"),
|
|
1304
|
+
revertLabel: t("revert"),
|
|
1305
|
+
dirtyLabel: t("dirtyCount", { count: deps.dirtyCount }),
|
|
1306
|
+
cleanLabel: t("statusClean"),
|
|
1307
|
+
readOnlyLabel: t("statusReadOnly"),
|
|
1308
|
+
onSave: deps.onSave,
|
|
1309
|
+
onDiscard: deps.onDiscard
|
|
1310
|
+
});
|
|
1311
|
+
return (0, react.createElement)(u, null, buildModelSection(deps), buildIndexSection(deps), saveBar);
|
|
895
1312
|
}
|
|
896
1313
|
/** 显式字段写入(schema-coverage 门禁按 set('字段名') 字面量识别绑定)。 */
|
|
897
1314
|
function pushFieldWrite(ops, key, draft, set) {
|
|
@@ -984,8 +1401,9 @@ function useRebuild(t, reader) {
|
|
|
984
1401
|
/** 发起一次重建;成功后进入轮询。 */
|
|
985
1402
|
async function startOnce() {
|
|
986
1403
|
const started = await requireReader(reader, t).rebuild(root.trim());
|
|
987
|
-
|
|
988
|
-
|
|
1404
|
+
const parsedStarted = zod.z.object({ jobId: zod.z.string() }).safeParse(started);
|
|
1405
|
+
if (!parsedStarted.success) throw new TypeError(t("rebuildMissingJobId"));
|
|
1406
|
+
const { jobId } = parsedStarted.data;
|
|
989
1407
|
pollRef.current = setInterval(() => {
|
|
990
1408
|
pollStatus(jobId);
|
|
991
1409
|
}, REBUILD_POLL_MS);
|
|
@@ -1033,7 +1451,8 @@ function ZgCard(props) {
|
|
|
1033
1451
|
const [saveError, setSaveError] = (0, react.useState)(null);
|
|
1034
1452
|
const rebuildView = useRebuild(t, props.rebuildRemote);
|
|
1035
1453
|
const fields = draftFields(touched, value);
|
|
1036
|
-
const
|
|
1454
|
+
const dirtyCount = t$2(touched, value).length;
|
|
1455
|
+
const dirty = dirtyCount > 0;
|
|
1037
1456
|
const setField = (field, draft) => {
|
|
1038
1457
|
setTouched((prev) => ({
|
|
1039
1458
|
...prev,
|
|
@@ -1041,7 +1460,7 @@ function ZgCard(props) {
|
|
|
1041
1460
|
}));
|
|
1042
1461
|
};
|
|
1043
1462
|
const save = async () => {
|
|
1044
|
-
const keys = t$
|
|
1463
|
+
const keys = t$2(touched, value);
|
|
1045
1464
|
if (keys.length === 0) return;
|
|
1046
1465
|
setBusy(true);
|
|
1047
1466
|
setSaveError(null);
|
|
@@ -1071,7 +1490,7 @@ function ZgCard(props) {
|
|
|
1071
1490
|
setTouched({});
|
|
1072
1491
|
setSaveError(null);
|
|
1073
1492
|
};
|
|
1074
|
-
|
|
1493
|
+
return buildCardBody({
|
|
1075
1494
|
t,
|
|
1076
1495
|
fields,
|
|
1077
1496
|
writable,
|
|
@@ -1081,6 +1500,7 @@ function ZgCard(props) {
|
|
|
1081
1500
|
root: rebuildView.root,
|
|
1082
1501
|
rebuild: rebuildView.state,
|
|
1083
1502
|
dirty,
|
|
1503
|
+
dirtyCount,
|
|
1084
1504
|
busy,
|
|
1085
1505
|
saveError,
|
|
1086
1506
|
setField,
|
|
@@ -1094,11 +1514,6 @@ function ZgCard(props) {
|
|
|
1094
1514
|
rebuildView.start();
|
|
1095
1515
|
}
|
|
1096
1516
|
});
|
|
1097
|
-
const body = (0, react.createElement)("div", { style: { padding: "2px 0" } }, rows);
|
|
1098
|
-
return (0, react.createElement)(PluginCard, {
|
|
1099
|
-
title: t("cardTitle"),
|
|
1100
|
-
description: t("cardDescription")
|
|
1101
|
-
}, body);
|
|
1102
1517
|
}
|
|
1103
1518
|
const inject = [
|
|
1104
1519
|
"slots",
|
|
@@ -1109,7 +1524,7 @@ function apply(ctx) {
|
|
|
1109
1524
|
ctx.effect(() => {
|
|
1110
1525
|
const tag = document.createElement("style");
|
|
1111
1526
|
tag.id = "zvec-grep-card-css";
|
|
1112
|
-
tag.textContent = CARD_CSS
|
|
1527
|
+
tag.textContent = `${CARD_CSS}\n${c}`;
|
|
1113
1528
|
document.head.append(tag);
|
|
1114
1529
|
return () => {
|
|
1115
1530
|
tag.remove();
|