dsh-chef 0.3.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.js CHANGED
@@ -127,6 +127,678 @@ window.__ModuleLoader__.load({
127
127
  /** 宿主目录选择命名空间的服务名(#736;出处与禁令见 cookbook §13)。 */
128
128
  const REMOTE_DIRECTORY_PICKER = "remote.directoryPicker";
129
129
  //#endregion
130
+ //#region ../plugin-manager/dist/directory-browser-contract.js
131
+ /** 目录浏览器的纯逻辑半(**不认识宿主**:只认两格原语)。
132
+ *
133
+ * 为什么在这里:六个单品插件的设置页各有一批「值是一个目录」的行,它们要的界面是同一个东西。
134
+ * 界面的**取数**来自宿主给的两个原语(`list`/`createDirectory`),而这两个原语的形状是**调用方喂进来的**
135
+ * ——本件不 import 宿主的任何实现,也不认识 `remote.directoryPicker` 这个名字(那两件住在各家的
136
+ * `dsh-ctx.ts` 镜像里)。于是本件在 Windows 桌面、远程浏览器、SSH 三种部署下是同一份代码。
137
+ *
138
+ * 装什么:本次要浏览的那一层怎么走(进子目录/回上一级/跳面包屑)、路径怎么切出「目录部分」与
139
+ * 「筛选词」、回执怎么认。**不装**任何 IO、不装任何持久化——`list`/`createDirectory` 由调用方执行。
140
+ *
141
+ * 与平台自带浏览器件的关系:`@deepseek-ai/dsh-client-ui-directory-picker-browse` 的 `DirectoryBrowser`
142
+ * 是包内私有件(只经 `ui-workspace` 的流程空位暴露),插件侧取不到,所以这里是一份独立实现,
143
+ * 只对齐它的**交互结果**(进/选/新建),不对齐它的 DOM。
144
+ */
145
+ /** 认一认某个值是不是可用的目录取数面(软依赖守卫用:认不出就当没有,绝不把页面带下来)。 */
146
+ function isBrowseFace(raw) {
147
+ if (typeof raw !== "object" || raw === null) return false;
148
+ const face = raw;
149
+ return typeof face.list === "function" && typeof face.createDirectory === "function";
150
+ }
151
+ /** 认一认某个值有没有 `pick`(对应宿主 composition 里的 `native` 能力)。 */
152
+ function hasPickFn(raw) {
153
+ if (typeof raw !== "object" || raw === null) return false;
154
+ return typeof raw.pick === "function";
155
+ }
156
+ /** 三态判定:先 native(有 pick),再 browse(有两格原语),都没有=`none`。 */
157
+ function pickerModeOf$1(raw) {
158
+ if (hasPickFn(raw)) return "native";
159
+ return isBrowseFace(raw) ? "browse" : "none";
160
+ }
161
+ /** 平台回执 → 三态(**永不抛**):成功回的是信封里的 `value` 不是路径;`ok:false` 是「供不了」不是「取消」。
162
+ *
163
+ * 出处:`@deepseek-ai/dsh-api-gateway/lib/client.js` 的 `invoke()`(失败不抛、成功也不回裸值),
164
+ * 第一方消费方 `@deepseek-ai/dsh-client-ui-workspace/lib/client.js:99-103` 就照这个信封拆。
165
+ * 裸串照收(老形状兜底),认不出的形状当「供不了」报出来,不当取消吞掉(#743 的教训)。 */
166
+ function readPickAnswer$1(raw) {
167
+ if (typeof raw === "string") return raw.trim() === "" ? { kind: "cancelled" } : {
168
+ kind: "picked",
169
+ path: raw
170
+ };
171
+ const answer = typeof raw === "object" && raw !== null ? raw : {};
172
+ if (answer.ok === true) {
173
+ const value = answer.value;
174
+ return typeof value === "string" && value.trim() !== "" ? {
175
+ kind: "picked",
176
+ path: value
177
+ } : { kind: "cancelled" };
178
+ }
179
+ const detail = answer.error?.message?.trim() ?? "";
180
+ return {
181
+ kind: "unavailable",
182
+ message: "打不开系统文件夹对话框" + (detail === "" ? "" : "(" + detail + ")") + ":请直接在框里填绝对路径。"
183
+ };
184
+ }
185
+ /** 一段路径里最后那个分隔符的位置(Windows 上 `\` 与 `/` 都算;POSIX 上 `\` 是合法文件名字符,不算)。 */
186
+ function lastSeparator(path) {
187
+ const back = path.lastIndexOf("\\");
188
+ const slash = path.lastIndexOf("/");
189
+ return back > slash ? back : slash;
190
+ }
191
+ /** 上一层:`'C:\\a\\b\\'` → `'C:\\a'`;已经是根则回自身;相对名(没有任何分隔符)也回自身。
192
+ *
193
+ * 尾分隔符先吃掉再切——否则「回上一级」会在原地打转。**盘根单独认**:`C:\` 掐掉尾分隔符会剩成
194
+ * `C:`,而 `C:` 是「当前盘」不是「上一层」,回它就会多跑一趟、还可能跨到别的盘上去。
195
+ * UNC(`\\server\share`)不特殊处理:切到头就是共享名本身,浏览停在共享根。 */
196
+ function parentOf(path) {
197
+ const trimmed = path.replace(/[\\/]+$/, "");
198
+ if (trimmed === "") return path;
199
+ const sep = path.includes("\\") ? "\\" : "/";
200
+ if (/^[A-Za-z]:$/.test(trimmed)) return trimmed + sep;
201
+ const cut = lastSeparator(trimmed);
202
+ if (cut === -1) return trimmed;
203
+ if (cut === 0) return path.slice(0, 1);
204
+ if (cut === 2 && /^[A-Za-z]:/.test(trimmed)) return trimmed.slice(0, 2) + sep;
205
+ return trimmed.slice(0, cut);
206
+ }
207
+ /** 一层列举里,哪些行可进:隐藏目录按开关过滤,其余照宿主给的顺序。 */
208
+ function visibleEntries(listing, showHidden) {
209
+ return showHidden ? listing.entries : listing.entries.filter((entry) => !entry.hidden);
210
+ }
211
+ /** 这一层有多少个被藏起来的目录(用来决定「显示隐藏目录」那个开关要不要出现在图上)。 */
212
+ function hiddenCount(listing) {
213
+ return listing.entries.filter((entry) => entry.hidden).length;
214
+ }
215
+ /** 拿一段文本按「最后一个分隔符」切成「目录部分 + 筛选词」。
216
+ *
217
+ * 没打过任何分隔符时目录部分=null(那段文字还不指任何目录,只当筛选词用)。
218
+ * Windows 上 `/` 也当分隔符(宿主那边两种都收),POSIX 上不。 */
219
+ function splitDraft(draft) {
220
+ const cut = lastSeparator(draft);
221
+ if (cut === -1) return {
222
+ directory: null,
223
+ filter: draft
224
+ };
225
+ return {
226
+ directory: draft.slice(0, cut + 1),
227
+ filter: draft.slice(cut + 1)
228
+ };
229
+ }
230
+ /** 按筛选词过一层目录(大小写不敏感;空筛选词=全留)。 */
231
+ function filterEntries(entries, filter) {
232
+ const needle = filter.trim().toLowerCase();
233
+ if (needle === "") return entries;
234
+ return entries.filter((entry) => entry.name.toLowerCase().includes(needle));
235
+ }
236
+ /** 给界面用的一句话位置说明:优先显示相对 home 的说法,省得整条绝对路径占满一行。 */
237
+ function locationLabel(listing) {
238
+ const home = listing.home.replace(/[\\/]+$/, "");
239
+ if (home !== "" && listing.path !== home && listing.path.startsWith(home)) {
240
+ const tail = listing.path.slice(home.length).replace(/^[\\/]+/, "");
241
+ if (tail !== "") return "~" + (listing.path.includes("\\") ? "\\" : "/") + tail;
242
+ }
243
+ return listing.path;
244
+ }
245
+ /** 新建文件夹的名字合不合法(单个路径段:不许分隔符、不许空、不许 `.`/`..`)。
246
+ *
247
+ * 与宿主 browse 后端的校验同口径——这里先拦一道,是为了在图上给得出人话,不是替代宿主校验。 */
248
+ function validateFolderName(name) {
249
+ const trimmed = name.trim();
250
+ if (trimmed === "") return {
251
+ ok: false,
252
+ reason: "文件夹名不能为空。"
253
+ };
254
+ if (/[\\/]/.test(trimmed)) return {
255
+ ok: false,
256
+ reason: "文件夹名里不能带路径分隔符。"
257
+ };
258
+ if (trimmed === "." || trimmed === "..") return {
259
+ ok: false,
260
+ reason: "「.」与「..」不是文件夹名。"
261
+ };
262
+ return { ok: true };
263
+ }
264
+ //#endregion
265
+ //#region ../plugin-manager/dist/directory-browser-state.js
266
+ /** 文件浏览器的操作半:把「进哪一层、这一层显示什么、选到了什么」算成状态,**IO 全部由调用方注入**。
267
+ *
268
+ * 分两层的原因:本件(操作)在 Node 里就能直测——喂一个假的取数面,就能把「进目录/回上一级/
269
+ * 跳面包屑/筛选/新建文件夹/失败出人话」全跑一遍;视图那半(`directory-browser-ui.ts`)
270
+ * 只负责把这份状态画成 DOM。两边都不认识宿主。
271
+ *
272
+ * 数据来源只有两格:`list(path?)` 与 `createDirectory(path, name)`(调用方注入的 `DirectoryBrowseFace`)。
273
+ */
274
+ /** 建一个浏览器控制器。取数、回调、初值全部由调用方给。 */
275
+ function createBrowseController(deps) {
276
+ const label = deps.failureLabel ?? "浏览失败";
277
+ const listeners = /* @__PURE__ */ new Set();
278
+ let state = {
279
+ phase: "idle",
280
+ listing: null,
281
+ failure: null,
282
+ selected: null,
283
+ showHidden: false,
284
+ draft: deps.initialPath,
285
+ filter: "",
286
+ creating: null,
287
+ notice: null
288
+ };
289
+ /** 每次列举带一个序号:晚回来的旧回执直接丢掉,不许覆盖新一层。 */
290
+ let generation = 0;
291
+ const emit = (next) => {
292
+ state = {
293
+ ...state,
294
+ ...next
295
+ };
296
+ for (const listener of [...listeners]) listener(state);
297
+ };
298
+ const humanize = (cause) => {
299
+ const raw = typeof cause === "object" && cause !== null ? cause : {};
300
+ const message = typeof raw.message === "string" && raw.message.trim() !== "" ? raw.message.trim() : String(cause);
301
+ return {
302
+ code: typeof raw.code === "string" && raw.code !== "" ? raw.code : "browse-failed",
303
+ message: `${label}:${message}`
304
+ };
305
+ };
306
+ const load = async (path) => {
307
+ const mine = ++generation;
308
+ emit({
309
+ phase: "loading",
310
+ failure: null,
311
+ notice: null
312
+ });
313
+ try {
314
+ const listing = path === null ? await deps.face.list() : await deps.face.list(path);
315
+ if (mine !== generation) return;
316
+ emit({
317
+ phase: "ready",
318
+ listing,
319
+ failure: null,
320
+ selected: null,
321
+ draft: listing.path,
322
+ filter: ""
323
+ });
324
+ } catch (cause) {
325
+ if (mine !== generation) return;
326
+ emit({
327
+ phase: "failed",
328
+ listing: null,
329
+ failure: humanize(cause),
330
+ selected: null
331
+ });
332
+ }
333
+ };
334
+ /** 草稿指到的那一层已经列举过时,按末段筛当前这一层的行;否则不过滤。
335
+ *
336
+ * 两边都先掐掉尾分隔符再比:草稿那边切开后天然带尾分隔符(`C:\a\` + `b`),
337
+ * 而这一层的 `path` 由宿主给、不带尾分隔符。 */
338
+ const applyDraft = (draft) => {
339
+ const { directory, filter } = splitDraft(draft);
340
+ const listing = state.listing;
341
+ const sameLevel = listing !== null && directory !== null && normalize(directory) === normalize(listing.path);
342
+ emit({
343
+ draft,
344
+ filter: sameLevel ? filter : ""
345
+ });
346
+ };
347
+ const normalize = (path) => path.replace(/[\\/]+$/, "");
348
+ return {
349
+ getState: () => state,
350
+ subscribe(listener) {
351
+ listeners.add(listener);
352
+ return () => listeners.delete(listener);
353
+ },
354
+ open: () => load(null),
355
+ enter: (path) => load(path),
356
+ async up() {
357
+ const listing = state.listing;
358
+ if (listing === null) return;
359
+ const parent = parentOf(listing.path);
360
+ if (parent === listing.path) return;
361
+ await load(parent);
362
+ },
363
+ pick() {
364
+ const target = state.selected ?? state.listing?.path ?? null;
365
+ if (target === null) return;
366
+ deps.onPicked(target);
367
+ },
368
+ cancel() {
369
+ deps.onClose();
370
+ },
371
+ close() {
372
+ deps.onClose();
373
+ },
374
+ select(path) {
375
+ emit({
376
+ selected: state.selected === path ? null : path,
377
+ notice: null
378
+ });
379
+ },
380
+ toggleHidden() {
381
+ emit({ showHidden: !state.showHidden });
382
+ },
383
+ setDraft(draft) {
384
+ applyDraft(draft);
385
+ },
386
+ async commitDraft() {
387
+ const trimmed = state.draft.trim();
388
+ if (trimmed === "") return;
389
+ await load(trimmed);
390
+ },
391
+ setCreating(name) {
392
+ emit({
393
+ creating: name,
394
+ notice: null
395
+ });
396
+ },
397
+ async createFolder(name) {
398
+ const checked = validateFolderName(name);
399
+ if (!checked.ok) {
400
+ emit({ notice: checked.reason });
401
+ return;
402
+ }
403
+ const base = state.selected ?? state.listing?.path ?? null;
404
+ if (base === null) {
405
+ emit({ notice: "还没有打开任何目录,无法新建文件夹。" });
406
+ return;
407
+ }
408
+ try {
409
+ const created = await deps.face.createDirectory(base, name.trim());
410
+ emit({
411
+ creating: null,
412
+ notice: null
413
+ });
414
+ await load(created);
415
+ emit({ selected: created });
416
+ } catch (cause) {
417
+ const failure = humanize(cause);
418
+ emit({
419
+ notice: failure.message,
420
+ creating: null
421
+ });
422
+ }
423
+ }
424
+ };
425
+ }
426
+ /** 图上这一层要画的行(按隐藏开关与草稿末段过滤之后的)。 */
427
+ function rowsOf(state) {
428
+ if (state.listing === null) return [];
429
+ return filterEntries(visibleEntries(state.listing, state.showHidden), state.filter);
430
+ }
431
+ /** 「打开」这颗按钮的目标:选中行优先,没选中就是当前层。 */
432
+ function targetOf(state) {
433
+ return state.selected ?? state.listing?.path ?? null;
434
+ }
435
+ /** 一段路径拼成可读的一句话(给用例与调试用;图上不直接显示)。 */
436
+ function describe(state) {
437
+ if (state.phase === "failed") return `${state.failure?.code ?? "browse-failed"} @ ${state.draft}`;
438
+ if (state.listing === null) return `${state.phase}`;
439
+ return `${state.listing.path}(${rowsOf(state).length} 行)`;
440
+ }
441
+ /** 建一份「目录行接线」:给一个取数面与初值,回一组动作。
442
+ *
443
+ * 只做接线:把控制器算出来的状态与回调打包好,不取数、不画图、不认宿主。 */
444
+ function createDirectoryRowBrowser(deps) {
445
+ const controller = createBrowseController({
446
+ face: deps.face,
447
+ initialPath: deps.initialPath,
448
+ onPicked: deps.onPicked,
449
+ onClose: () => deps.onClosed?.(),
450
+ ...deps.failureLabel === void 0 ? {} : { failureLabel: deps.failureLabel }
451
+ });
452
+ return {
453
+ open: () => controller.open(),
454
+ state: () => controller.getState(),
455
+ summary: () => describe(controller.getState()),
456
+ actions: {
457
+ onPick: () => controller.pick(),
458
+ onClose: () => controller.cancel(),
459
+ onEnter: (path) => void controller.enter(path),
460
+ onUp: () => void controller.up(),
461
+ onSelect: (path) => controller.select(path),
462
+ onToggleHidden: () => controller.toggleHidden(),
463
+ onDraft: (draft) => controller.setDraft(draft),
464
+ onCommitDraft: () => void controller.commitDraft(),
465
+ onCreate: (name) => void controller.createFolder(name),
466
+ onCreatingChange: (name) => controller.setCreating(name)
467
+ }
468
+ };
469
+ }
470
+ //#endregion
471
+ //#region ../plugin-manager/dist/directory-browser-ui.js
472
+ /** 文件浏览器的视图半:把 `BrowseState` 画成一张对话框。**不认识宿主**,也不自己做 IO。
473
+ *
474
+ * 手写 `React.createElement`(本包 client 束禁 JSX,见 `tsdown.config.ts` 的既成口径)。
475
+ * 只读状态、只回调;进哪一层、选到什么由操作半(`directory-browser-state.ts`)算。
476
+ */
477
+ const EMPTY_LISTING = {
478
+ path: "",
479
+ home: "",
480
+ crumbs: [],
481
+ entries: [],
482
+ truncated: false
483
+ };
484
+ const S$1 = {
485
+ scrim: {
486
+ position: "fixed",
487
+ inset: 0,
488
+ background: "rgba(0,0,0,0.35)",
489
+ display: "flex",
490
+ alignItems: "center",
491
+ justifyContent: "center",
492
+ zIndex: 9999
493
+ },
494
+ dialog: {
495
+ width: 680,
496
+ maxWidth: "92vw",
497
+ height: 500,
498
+ maxHeight: "86vh",
499
+ display: "flex",
500
+ flexDirection: "column",
501
+ background: "var(--dsw-alias-bg-layer-1, #1f1f23)",
502
+ color: "var(--dsw-alias-label-primary, inherit)",
503
+ border: "1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.35))",
504
+ borderRadius: 10,
505
+ boxShadow: "0 12px 32px rgba(0,0,0,0.35)",
506
+ overflow: "hidden"
507
+ },
508
+ head: {
509
+ display: "flex",
510
+ alignItems: "center",
511
+ gap: 8,
512
+ padding: "10px 12px",
513
+ borderBottom: "1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.25))"
514
+ },
515
+ title: {
516
+ fontSize: 14,
517
+ fontWeight: 700
518
+ },
519
+ headTail: {
520
+ marginLeft: "auto",
521
+ fontSize: 12,
522
+ opacity: .72,
523
+ overflow: "hidden",
524
+ textOverflow: "ellipsis",
525
+ whiteSpace: "nowrap"
526
+ },
527
+ crumbs: {
528
+ display: "flex",
529
+ flexWrap: "wrap",
530
+ alignItems: "center",
531
+ gap: 2,
532
+ padding: "8px 12px 0",
533
+ fontSize: 12
534
+ },
535
+ chromeButton: {
536
+ background: "transparent",
537
+ border: "none",
538
+ color: "var(--dsw-alias-label-primary, inherit)",
539
+ cursor: "pointer",
540
+ padding: "2px 4px",
541
+ fontSize: 12,
542
+ opacity: .85
543
+ },
544
+ crumbSep: {
545
+ opacity: .45,
546
+ fontSize: 12
547
+ },
548
+ pathRow: {
549
+ display: "flex",
550
+ gap: 6,
551
+ padding: "8px 12px"
552
+ },
553
+ input: {
554
+ flex: 1,
555
+ minWidth: 0,
556
+ fontSize: 12,
557
+ padding: "5px 8px",
558
+ background: "var(--dsw-alias-bg-layer-2, rgba(128,128,128,0.12))",
559
+ color: "inherit",
560
+ border: "1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.35))",
561
+ borderRadius: 6
562
+ },
563
+ button: {
564
+ fontSize: 12,
565
+ padding: "5px 10px",
566
+ cursor: "pointer",
567
+ background: "var(--dsw-alias-bg-layer-2, rgba(128,128,128,0.12))",
568
+ color: "inherit",
569
+ border: "1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.35))",
570
+ borderRadius: 6
571
+ },
572
+ buttonOff: {
573
+ opacity: .45,
574
+ cursor: "default"
575
+ },
576
+ list: {
577
+ flex: 1,
578
+ minHeight: 0,
579
+ overflowY: "auto",
580
+ margin: "0 12px",
581
+ border: "1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.25))",
582
+ borderRadius: 6
583
+ },
584
+ row: {
585
+ display: "flex",
586
+ alignItems: "center",
587
+ gap: 8,
588
+ width: "100%",
589
+ padding: "6px 10px",
590
+ textAlign: "left",
591
+ background: "transparent",
592
+ color: "inherit",
593
+ border: "none",
594
+ borderBottom: "1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.12))",
595
+ cursor: "pointer",
596
+ fontSize: 13
597
+ },
598
+ rowSelected: { background: "var(--dsw-alias-bg-layer-2, rgba(128,128,128,0.18))" },
599
+ empty: {
600
+ padding: "14px 12px",
601
+ fontSize: 12,
602
+ opacity: .7
603
+ },
604
+ footNote: {
605
+ padding: "6px 12px 0",
606
+ fontSize: 12,
607
+ minHeight: 20
608
+ },
609
+ foot: {
610
+ display: "flex",
611
+ alignItems: "center",
612
+ gap: 8,
613
+ padding: "10px 12px",
614
+ borderTop: "1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.25))"
615
+ },
616
+ target: {
617
+ marginRight: "auto",
618
+ fontSize: 12,
619
+ opacity: .8,
620
+ overflow: "hidden",
621
+ textOverflow: "ellipsis",
622
+ whiteSpace: "nowrap"
623
+ },
624
+ error: { color: "var(--dsw-alias-label-error, #e66)" }
625
+ };
626
+ function crumbRow(state, labels, onEnter) {
627
+ const listing = state.listing;
628
+ if (listing === null || listing.crumbs.length === 0) return null;
629
+ const parts = [];
630
+ listing.crumbs.forEach((crumb, index) => {
631
+ if (index > 0) parts.push(react.createElement("span", {
632
+ key: "sep-" + crumb.path,
633
+ style: S$1.crumbSep
634
+ }, "›"));
635
+ const isCurrent = crumb.path === listing.path;
636
+ parts.push(react.createElement("button", {
637
+ key: crumb.path,
638
+ type: "button",
639
+ style: {
640
+ ...S$1.chromeButton,
641
+ fontWeight: isCurrent ? 700 : 400
642
+ },
643
+ title: crumb.path,
644
+ onClick: () => onEnter(crumb.path)
645
+ }, index === 0 ? labels.up : crumb.name));
646
+ });
647
+ return react.createElement("div", { style: S$1.crumbs }, parts);
648
+ }
649
+ function entryRow(entry, selected, labels, onToggleSelect, onEnter) {
650
+ return react.createElement("div", {
651
+ key: entry.path,
652
+ style: {
653
+ ...S$1.row,
654
+ padding: 0,
655
+ ...selected ? S$1.rowSelected : {}
656
+ }
657
+ }, react.createElement("button", {
658
+ type: "button",
659
+ style: {
660
+ ...S$1.row,
661
+ flex: 1,
662
+ border: "none"
663
+ },
664
+ onClick: () => onEnter(entry.path)
665
+ }, "📁 " + entry.name), react.createElement("button", {
666
+ type: "button",
667
+ style: {
668
+ ...S$1.button,
669
+ marginRight: 8,
670
+ padding: "2px 8px"
671
+ },
672
+ "aria-pressed": selected,
673
+ title: selected ? labels.selected : labels.select,
674
+ onClick: () => onToggleSelect(entry.path)
675
+ }, selected ? "✓" : labels.select));
676
+ }
677
+ function createRow(labels, onName, onCancel, onCreate, creatingName) {
678
+ if (creatingName === null) return null;
679
+ return react.createElement("div", { style: {
680
+ ...S$1.pathRow,
681
+ borderTop: "1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.25))"
682
+ } }, react.createElement("input", {
683
+ style: S$1.input,
684
+ value: creatingName,
685
+ placeholder: labels.newFolder,
686
+ "aria-label": labels.newFolder,
687
+ onChange: (event) => onName(event.currentTarget.value),
688
+ onKeyDown: (event) => {
689
+ if (event.key === "Enter") onCreate(creatingName);
690
+ if (event.key === "Escape") onCancel();
691
+ }
692
+ }), react.createElement("button", {
693
+ type: "button",
694
+ style: S$1.button,
695
+ onClick: () => onCreate(creatingName)
696
+ }, labels.createConfirm), react.createElement("button", {
697
+ type: "button",
698
+ style: S$1.button,
699
+ onClick: onCancel
700
+ }, labels.createCancel));
701
+ }
702
+ /** 画一张文件浏览器对话框。`open=false` 时返回 null(本件不挂 portal,由调用方决定挂在哪)。 */
703
+ function DirectoryBrowser(props) {
704
+ const { open, state, labels } = props;
705
+ if (!open) return null;
706
+ const rows = rowsOf(state);
707
+ const target = targetOf(state);
708
+ const listing = state.listing ?? EMPTY_LISTING;
709
+ const hidden = hiddenCount(listing);
710
+ const body = [];
711
+ body.push(crumbRow(state, labels, props.onEnter));
712
+ body.push(react.createElement("div", { style: S$1.pathRow }, react.createElement("input", {
713
+ style: S$1.input,
714
+ value: state.draft,
715
+ placeholder: labels.pathPlaceholder,
716
+ "aria-label": labels.pathPlaceholder,
717
+ onChange: (event) => props.onDraft(event.currentTarget.value),
718
+ onKeyDown: (event) => {
719
+ if (event.key === "Enter") props.onCommitDraft();
720
+ }
721
+ }), react.createElement("button", {
722
+ type: "button",
723
+ style: S$1.button,
724
+ onClick: props.onUp
725
+ }, labels.up), react.createElement("button", {
726
+ type: "button",
727
+ style: S$1.button,
728
+ onClick: props.onCommitDraft
729
+ }, labels.go)));
730
+ body.push(react.createElement("div", {
731
+ style: S$1.list,
732
+ role: "listbox",
733
+ "aria-label": labels.title
734
+ }, rows.length === 0 ? react.createElement("div", { style: S$1.empty }, state.phase === "loading" ? labels.loading : labels.empty) : rows.map((entry) => entryRow(entry, state.selected === entry.path, labels, props.onSelect, props.onEnter))));
735
+ body.push(createRow(labels, props.onDraft, () => props.onCreatingChange(null), props.onCreate, state.creating));
736
+ body.push(react.createElement("div", { style: S$1.footNote }, hidden > 0 ? react.createElement("label", { style: {
737
+ fontSize: 12,
738
+ cursor: "pointer",
739
+ marginRight: 10
740
+ } }, react.createElement("input", {
741
+ type: "checkbox",
742
+ checked: state.showHidden,
743
+ onChange: props.onToggleHidden
744
+ }), " " + labels.showHidden(hidden)) : null, state.creating === null ? react.createElement("button", {
745
+ type: "button",
746
+ style: {
747
+ ...S$1.chromeButton,
748
+ textDecoration: "underline"
749
+ },
750
+ onClick: () => props.onCreatingChange("")
751
+ }, labels.newFolder) : null, state.notice !== null ? react.createElement("div", { style: S$1.error }, state.notice) : null, state.phase === "failed" && state.failure !== null ? react.createElement("div", { style: S$1.error }, state.failure.message) : null));
752
+ body.push(react.createElement("div", { style: S$1.foot }, react.createElement("span", {
753
+ style: S$1.target,
754
+ title: target ?? ""
755
+ }, target === null ? "" : labels.willPick + target), react.createElement("button", {
756
+ type: "button",
757
+ style: {
758
+ ...S$1.button,
759
+ ...target === null ? S$1.buttonOff : {}
760
+ },
761
+ onClick: props.onPick
762
+ }, labels.open), react.createElement("button", {
763
+ type: "button",
764
+ style: S$1.button,
765
+ onClick: props.onClose
766
+ }, labels.cancel)));
767
+ return react.createElement("div", {
768
+ style: S$1.scrim,
769
+ role: "presentation",
770
+ onMouseDown: (event) => {
771
+ if (event.target === event.currentTarget) props.onClose();
772
+ }
773
+ }, react.createElement("div", {
774
+ style: S$1.dialog,
775
+ role: "dialog",
776
+ "aria-modal": true,
777
+ "aria-label": labels.title
778
+ }, react.createElement("div", { style: S$1.head }, react.createElement("span", { style: S$1.title }, labels.title), react.createElement("span", {
779
+ style: S$1.headTail,
780
+ title: listing.path
781
+ }, state.listing === null ? "" : locationLabel(listing)), react.createElement("button", {
782
+ type: "button",
783
+ style: S$1.button,
784
+ "aria-label": labels.close,
785
+ title: labels.close,
786
+ onClick: props.onClose
787
+ }, "✕")), body));
788
+ }
789
+ /** 目录行接线的 React 半边:把操作半那组动作直接喂给组件。
790
+ *
791
+ * 操作半(`directory-browser-state.ts` 的 `createDirectoryRowBrowser`)不碰 React,
792
+ * 这里只把它的 `actions` 摊进 props —— 于是「进哪一层」那套在 Node 里可测,这里只做接线。 */
793
+ function DirectoryBrowserFromRow(props) {
794
+ return DirectoryBrowser({
795
+ open: props.open,
796
+ state: props.row.state(),
797
+ labels: props.labels,
798
+ ...props.row.actions
799
+ });
800
+ }
801
+ //#endregion
130
802
  //#region src/client.ts
131
803
  /** dsh-chef client 适配器:技能设置页(#696 起是真能配的页,只配置、不干活)。
132
804
  *
@@ -145,7 +817,10 @@ window.__ModuleLoader__.load({
145
817
  /** client 短名声明:只有这两个(#736 的目录选择走**可选查找**,不写进来——
146
818
  * 写进来=硬依赖,提供方缺席时整包被停靠,设置页会跟着装不上;见 cookbook §13)。 */
147
819
  const inject = ["slots", "connection"];
148
- /** 面板视觉(内联 style;颜色走 DSH 主题别名,深浅主题自适应,写死值只做回退)。 */
820
+ /** 面板视觉(内联 style;颜色走 DSH 主题别名,深浅主题自适应,写死值只做回退)。
821
+ *
822
+ * **六家逐项同形**(备忘·卡路里·记账·作息·居家·大厨):同一项在这六份里逐字相同,
823
+ * 改任一条要六家一起改,锁见 `test/panel-copy-743.test.mjs` 第 ⑤ 条。 */
149
824
  const S = {
150
825
  card: {
151
826
  padding: "12px 14px",
@@ -183,11 +858,12 @@ window.__ModuleLoader__.load({
183
858
  },
184
859
  input: {
185
860
  width: "100%",
861
+ boxSizing: "border-box",
186
862
  padding: "4px 8px",
187
863
  borderRadius: 6,
188
864
  border: "1px solid var(--dsw-alias-border, rgba(128,128,128,.45))",
189
- background: "var(--dsw-alias-bg-base, #fff)",
190
- color: "inherit"
865
+ background: "var(--dsw-alias-bg-base, transparent)",
866
+ color: "var(--dsw-alias-label-primary, inherit)"
191
867
  },
192
868
  pickRow: {
193
869
  display: "flex",
@@ -199,10 +875,10 @@ window.__ModuleLoader__.load({
199
875
  padding: "4px 10px",
200
876
  borderRadius: 6,
201
877
  border: "1px solid var(--dsw-alias-border, rgba(128,128,128,.45))",
202
- background: "transparent",
203
- color: "inherit",
204
- cursor: "pointer",
205
- whiteSpace: "nowrap"
878
+ background: "var(--dsw-alias-bg-base, transparent)",
879
+ color: "var(--dsw-alias-label-primary, inherit)",
880
+ whiteSpace: "nowrap",
881
+ cursor: "pointer"
206
882
  },
207
883
  advanced: { marginTop: 12 },
208
884
  summary: {
@@ -219,21 +895,21 @@ window.__ModuleLoader__.load({
219
895
  padding: "4px 12px",
220
896
  borderRadius: 6,
221
897
  border: "1px solid var(--dsw-alias-border, rgba(128,128,128,.45))",
222
- background: "transparent",
223
- color: "inherit",
898
+ background: "var(--dsw-alias-bg-base, transparent)",
899
+ color: "var(--dsw-alias-label-primary, inherit)",
224
900
  cursor: "pointer"
225
901
  },
226
902
  btnPrimary: {
227
903
  padding: "4px 12px",
228
904
  borderRadius: 6,
229
- border: "1px solid var(--dsw-alias-border, rgba(128,128,128,.45))",
905
+ border: "1px solid var(--dsw-alias-brand-primary, #2f6fed)",
230
906
  background: "var(--dsw-alias-brand-primary, #2f6fed)",
231
907
  color: "#fff",
232
908
  cursor: "pointer"
233
909
  },
234
910
  okText: {
235
911
  marginTop: 8,
236
- color: "var(--dsw-alias-label-success, #12805c)",
912
+ color: "var(--dsw-alias-state-success-primary, #12805c)",
237
913
  fontSize: "0.96em"
238
914
  },
239
915
  error: {
@@ -348,29 +1024,8 @@ window.__ModuleLoader__.load({
348
1024
  return null;
349
1025
  }
350
1026
  }
351
- /** 平台回执 → 三种结果(**永不抛**)。回执是信封 `{ok, value|error}`(见 dsh-ctx.ts 的
352
- * `DirectoryPickerAnswer`):成功回的是 `value` 不是路径本身,被拒回的是 `ok:false` 不是抛——
353
- * 照裸值解会把两种情况都误判成「用户取消」(#743 真机现象:点「选择文件夹」什么都没发生)。
354
- * 裸串照收(老形状兜底),认不出的形状当「供不了」报出来,不当取消吞掉。 */
355
- function readPickAnswer(raw) {
356
- if (typeof raw === "string") return raw.trim() === "" ? { kind: "cancelled" } : {
357
- kind: "picked",
358
- path: raw
359
- };
360
- const answer = typeof raw === "object" && raw !== null ? raw : {};
361
- if (answer.ok === true) {
362
- const value = answer.value;
363
- return typeof value === "string" && value.trim() !== "" ? {
364
- kind: "picked",
365
- path: value
366
- } : { kind: "cancelled" };
367
- }
368
- const detail = answer.error?.message?.trim() ?? "";
369
- return {
370
- kind: "unavailable",
371
- message: "打不开系统文件夹对话框" + (detail === "" ? "" : "(" + detail + ")") + ":请直接在框里填绝对路径。"
372
- };
373
- }
1027
+ const readPickAnswer = readPickAnswer$1;
1028
+ const pickerModeOf = pickerModeOf$1;
374
1029
  /** 唤起一次系统文件夹选择器并归一结果(**永不抛**)。 */
375
1030
  async function pickDirectory(picker) {
376
1031
  try {
@@ -412,12 +1067,14 @@ window.__ModuleLoader__.load({
412
1067
  spellCheck: false,
413
1068
  onChange
414
1069
  });
415
- const browse = item.control === "directory" && props.onBrowse !== void 0 ? react.createElement("button", {
1070
+ /** 三态入口:供不了(`none`/缺席)就不画,不摆一个点了没反应的死按钮。 */
1071
+ const entry = props.browser ?? null;
1072
+ const browse = item.control === "directory" && entry !== null && entry.mode !== "none" ? react.createElement("button", {
416
1073
  style: S.btnPick,
417
1074
  type: "button",
418
1075
  disabled: props.disabled,
419
- onClick: () => props.onBrowse?.(item.key)
420
- }, "选择文件夹…") : null;
1076
+ onClick: () => entry.onOpen(item.key)
1077
+ }, entry.mode === "native" ? "选择文件夹…" : "浏览…") : null;
421
1078
  return react.createElement("div", { style: S.row }, react.createElement("div", { style: S.label }, item.title), react.createElement("div", { style: S.hint }, item.hint), browse === null ? control : react.createElement("div", { style: S.pickRow }, control, browse));
422
1079
  }
423
1080
  /** 技能设置页:承载私家大厨自己的全部可配置项(只配置,不干活)。 */
@@ -469,24 +1126,42 @@ window.__ModuleLoader__.load({
469
1126
  setNotice(null);
470
1127
  setError(null);
471
1128
  }, []);
472
- /** 目录选择:拿不到命名空间就没有入口;被拒一次即收起入口(不留死按钮)。 */
1129
+ /** 三态入口的 React 接线:`native`=系统对话框;`browse`=应用内浏览器(票 #744)。
1130
+ *
1131
+ * 为什么写得比原来长:这台机器上(Windows 桌面版)宿主组合里只有 browse 那一档,
1132
+ * `pick` 会被拒(见 `docs/agents/desktop-directory-picker-browse.md` 的根因读数),
1133
+ * 于是这一行改成「开应用内浏览器」——同一个用户动作,不依赖系统对话框也能选到目录。 */
1134
+ const { mode: entryMode, openBrowse, browseRow } = props;
473
1135
  const picker = pickerGone ? null : props.getPicker();
474
- const onBrowse = react.useMemo(() => {
475
- if (picker === null) return void 0;
476
- const browse = createBrowseHandler({
477
- picker,
478
- onChange,
479
- onUnavailable: (message) => {
480
- setError(message);
481
- setPickerGone(true);
482
- }
483
- });
484
- return (key) => {
1136
+ /** 目录行的入口动作:三态各一条路;都供不了就不给入口(`undefined` ⇒ Row 不画按钮)。 */
1137
+ const onOpenRow = react.useCallback(async (key) => {
1138
+ if (pickerModeOf(picker) === "native") {
485
1139
  setPicking(true);
486
1140
  setError(null);
487
- browse(key).finally(() => setPicking(false));
488
- };
489
- }, [picker, onChange]);
1141
+ const outcome = await pickDirectory(picker);
1142
+ setPicking(false);
1143
+ if (outcome.kind === "picked") onChange(key, outcome.path);
1144
+ else if (outcome.kind === "unavailable") {
1145
+ setError(outcome.message);
1146
+ setPickerGone(true);
1147
+ }
1148
+ return;
1149
+ }
1150
+ const opened = openBrowse(key, draft[key] ?? "", onChange);
1151
+ if (opened === void 0) return;
1152
+ setError(null);
1153
+ await opened;
1154
+ }, [
1155
+ picker,
1156
+ onChange,
1157
+ openBrowse,
1158
+ draft
1159
+ ]);
1160
+ /** 给 Row 的三态入口:`none` 时给 null(不画按钮),否则把 mode 与动作一起递下去。 */
1161
+ const rowEntry = entryMode === "none" ? null : {
1162
+ mode: entryMode,
1163
+ onOpen: onOpenRow
1164
+ };
490
1165
  const surface = state.kind === "ready" ? state.surface : null;
491
1166
  const dirty = surface !== null && CONFIG_ITEMS.some((i) => (draft[i.key] ?? "") !== (toDraft(surface.values, surface)[i.key] ?? ""));
492
1167
  /** 写完之后重新读一份:写回执只有 {path, values},头部那两行要的是读整面。 */
@@ -545,7 +1220,7 @@ window.__ModuleLoader__.load({
545
1220
  value: draft[item.key] ?? "",
546
1221
  disabled: busy,
547
1222
  onChange,
548
- onBrowse
1223
+ browser: rowEntry
549
1224
  });
550
1225
  return react.createElement("div", { style: S.card }, head, react.createElement("div", { style: S.rows }, common.map(renderRow)), react.createElement("details", { style: S.advanced }, react.createElement("summary", { style: S.summary }, ADVANCED_GROUP_TITLE), react.createElement("div", { style: S.muted }, ADVANCED_GROUP_NOTE), advanced.map(renderRow)), react.createElement("div", { style: S.bar }, react.createElement("button", {
551
1226
  style: dirty ? S.btnPrimary : S.btn,
@@ -562,7 +1237,28 @@ window.__ModuleLoader__.load({
562
1237
  type: "button",
563
1238
  disabled: busy,
564
1239
  onClick: () => void load()
565
- }, "重新读取")), picking ? react.createElement("div", { style: S.muted }, "已唤起系统文件夹对话框:选中后自动填上,取消则不动。") : null, notice !== null ? react.createElement("div", { style: S.okText }, notice) : null, error !== null ? react.createElement("div", { style: S.error }, error) : null, react.createElement("div", { style: S.muted }, `${PLUGIN} 本页只配置;搜菜、做菜在对话里说。`));
1240
+ }, "重新读取")), picking ? react.createElement("div", { style: S.muted }, "已唤起系统文件夹对话框:选中后自动填上,取消则不动。") : null, browseRow !== null ? react.createElement("div", { style: S.muted }, "应用内文件夹浏览器已打开:选中后自动填上,取消则不动。") : null, browseRow !== null ? react.createElement(DirectoryBrowserFromRow, {
1241
+ open: true,
1242
+ row: browseRow,
1243
+ labels: {
1244
+ title: "选择文件夹",
1245
+ close: "关闭",
1246
+ up: "上一级",
1247
+ pathPlaceholder: "直接填绝对路径,回车即进入",
1248
+ go: "转到",
1249
+ showHidden: (n) => "显示隐藏目录(" + n + ")",
1250
+ empty: "这个目录里没有子目录。",
1251
+ loading: "正在读取…",
1252
+ newFolder: "新建文件夹",
1253
+ createConfirm: "创建",
1254
+ createCancel: "取消",
1255
+ select: "选",
1256
+ selected: "已选",
1257
+ open: "选定这个目录",
1258
+ cancel: "取消",
1259
+ willPick: "将选定:"
1260
+ }
1261
+ }) : null, notice !== null ? react.createElement("div", { style: S.okText }, notice) : null, error !== null ? react.createElement("div", { style: S.error }, error) : null);
566
1262
  }
567
1263
  function apply(ctx) {
568
1264
  const getCall = () => ctx.connection?.rpc?.call ?? null;
@@ -572,10 +1268,33 @@ window.__ModuleLoader__.load({
572
1268
  id: PLUGIN,
573
1269
  label: () => SLOT_TITLE,
574
1270
  channel: RPC_CHANNEL
575
- }, () => react.createElement(ChefConfig, {
576
- getCall,
577
- getPicker
578
- })));
1271
+ }, () => {
1272
+ return function ChefConfigSlot() {
1273
+ const [browseRow, setBrowseRow] = react.useState(null);
1274
+ const picker = resolveDirectoryPicker((name) => ctx.get?.(name));
1275
+ const openBrowse = (key, path, onChange) => {
1276
+ if (picker === null || pickerModeOf(picker) !== "browse") return void 0;
1277
+ const row = createDirectoryRowBrowser({
1278
+ face: picker,
1279
+ initialPath: path,
1280
+ onPicked: (picked) => {
1281
+ onChange(key, picked);
1282
+ setBrowseRow(null);
1283
+ },
1284
+ onClosed: () => setBrowseRow(null)
1285
+ });
1286
+ setBrowseRow(row);
1287
+ return row.open();
1288
+ };
1289
+ return react.createElement(ChefConfig, {
1290
+ getCall,
1291
+ getPicker,
1292
+ mode: pickerModeOf(picker),
1293
+ openBrowse,
1294
+ browseRow
1295
+ });
1296
+ };
1297
+ }));
579
1298
  }
580
1299
  //#endregion
581
1300
  exports.READ_TIMEOUT_MS = READ_TIMEOUT_MS;
@@ -588,6 +1307,7 @@ window.__ModuleLoader__.load({
588
1307
  exports.inject = inject;
589
1308
  exports.isDirectoryPicker = isDirectoryPicker;
590
1309
  exports.pickDirectory = pickDirectory;
1310
+ exports.pickerModeOf = pickerModeOf;
591
1311
  exports.readPickAnswer = readPickAnswer;
592
1312
  exports.resetConfigSurface = resetConfigSurface;
593
1313
  exports.resolveDirectoryPicker = resolveDirectoryPicker;