@jayyuen66/dsh-dir-prep-organize 0.1.2 → 0.1.3

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/client.js CHANGED
@@ -6,8 +6,8 @@ window.__ModuleLoader__.load({
6
6
  var exports = module.exports;
7
7
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
8
  let react = require("react");
9
- //#region node_modules/.pnpm/@jayyuen66+dsh-plugin-shared@0.1.5-rc_@deepseek-ai+cordis@4.0.5-alpha.1_@deepseek-ai+ds_72b6c52124160350b2d74ac4902eb816/node_modules/@jayyuen66/dsh-plugin-shared/dist/record.js
10
- function e$1(e) {
9
+ //#region node_modules/.pnpm/@jayyuen66+dsh-plugin-shared@0.1.6_@deepseek-ai+cordis@4.0.5_@deepseek-ai+dsh-client-lo_421050e71de450f7d7bae78e31868f4a/node_modules/@jayyuen66/dsh-plugin-shared/dist/record.js
10
+ function e(e) {
11
11
  return typeof e == `object` && !!e && !Array.isArray(e);
12
12
  }
13
13
  //#endregion
@@ -63,7 +63,7 @@ function uniqueEntryId(candidate, index, seen) {
63
63
  * 返回 undefined 表示该条应被剔除。 */
64
64
  function normalizeEntry(item, index, seen) {
65
65
  let result;
66
- if (e$1(item)) {
66
+ if (e(item)) {
67
67
  const { id, name, description, text, group, emoji } = item;
68
68
  const nextName = trimField(name);
69
69
  const nextText = trimField(text);
@@ -121,7 +121,7 @@ const ORGANIZE_TIMEOUT_SLACK_MS = 5e3;
121
121
  * `organizeTimeoutMs` 的前端取表。
122
122
  *
123
123
  * 上界与 host 同为 `[1, MAX_TIMER_MS]`:host 自己夹了上界正是为了躲开上面那个静默夹断,
124
- * 而这一侧是**唯一**发起 fetch 的地方,它要是没夹,host 夹得再对也没用。
124
+ * 而这一侧是**唯一**发起整理读面调用的地方,它要是没夹,host 夹得再对也没用。
125
125
  *
126
126
  * @param value - 配置表单投影值
127
127
  * @returns `[1, MAX_TIMER_MS]` 区间内的整数;不合法时 undefined(回落默认)
@@ -376,43 +376,179 @@ const UI_MESSAGES = {
376
376
  }
377
377
  };
378
378
  //#endregion
379
- //#region node_modules/.pnpm/@jayyuen66+dsh-plugin-shared@0.1.5-rc_@deepseek-ai+cordis@4.0.5-alpha.1_@deepseek-ai+ds_72b6c52124160350b2d74ac4902eb816/node_modules/@jayyuen66/dsh-plugin-shared/dist/errors.js
380
- function e(e) {
379
+ //#region node_modules/.pnpm/@jayyuen66+dsh-plugin-shared@0.1.6_@deepseek-ai+cordis@4.0.5_@deepseek-ai+dsh-client-lo_421050e71de450f7d7bae78e31868f4a/node_modules/@jayyuen66/dsh-plugin-shared/dist/errors.js
380
+ function t(e) {
381
381
  let t = Object.getOwnPropertyDescriptor(e, `message`);
382
382
  return t !== void 0 && `value` in t && typeof t.value == `string` ? t.value : void 0;
383
383
  }
384
- function t(n, r) {
385
- if (r.has(n)) return `<circular cause>`;
386
- r.add(n);
384
+ function n(e, r) {
385
+ if (r.has(e)) return `<circular cause>`;
386
+ r.add(e);
387
387
  try {
388
- if (!(n instanceof Error)) {
389
- if (typeof n == `object` && n) {
390
- let t = e(n);
391
- if (t !== void 0) return t;
388
+ if (!(e instanceof Error)) {
389
+ if (typeof e == `object` && e) {
390
+ let n = t(e);
391
+ if (n !== void 0) return n;
392
392
  }
393
- return String(n);
393
+ return String(e);
394
394
  }
395
- let i = n.message === `` ? n.name : n.message, a = n instanceof AggregateError && n.errors.length > 0 ? ` [${n.errors.map((e) => t(e, r)).join(`; `)}]` : ``, o = n.cause === void 0 || n.cause === null ? `` : t(n.cause, r);
395
+ let i = e.message === `` ? e.name : e.message, a = e instanceof AggregateError && e.errors.length > 0 ? ` [${e.errors.map((e) => n(e, r)).join(`; `)}]` : ``, o = e.cause === void 0 || e.cause === null ? `` : n(e.cause, r);
396
396
  return `${i}${a}${o === `` || o === i ? `` : `: ${o}`}`;
397
397
  } catch {
398
398
  return `<unrenderable value>`;
399
399
  } finally {
400
- r.delete(n);
400
+ r.delete(e);
401
401
  }
402
402
  }
403
- function n(e) {
404
- return t(e, /* @__PURE__ */ new Set());
403
+ function r(e) {
404
+ return n(e, /* @__PURE__ */ new Set());
405
+ }
406
+ //#endregion
407
+ //#region src/remote.ts
408
+ const DIR_PREP_NAMESPACE = "dirPrepOrganize";
409
+ const DIR_PREP_SERVICE_KEY = `remote.${DIR_PREP_NAMESPACE}`;
410
+ const PACKAGE_NAME = "@jayyuen66/dsh-dir-prep-organize";
411
+ const SESSION_CODEC = {
412
+ mode: "strict",
413
+ typeSymbol: `${PACKAGE_NAME}#session-request`,
414
+ create: () => ({ parse(value) {
415
+ if (!e(value) || typeof value["sessionId"] !== "string") throw new TypeError("session request requires a string sessionId");
416
+ return { sessionId: value["sessionId"] };
417
+ } })
418
+ };
419
+ const DIR_PREP_DESCRIPTORS = [
420
+ {
421
+ id: `${PACKAGE_NAME}#${DIR_PREP_NAMESPACE}/defaults`,
422
+ service: DIR_PREP_NAMESPACE,
423
+ namespace: DIR_PREP_NAMESPACE,
424
+ method: "defaults",
425
+ invocation: { kind: "direct" },
426
+ parameters: [],
427
+ result: { mode: "src-json" }
428
+ },
429
+ {
430
+ id: `${PACKAGE_NAME}#${DIR_PREP_NAMESPACE}/context`,
431
+ service: DIR_PREP_NAMESPACE,
432
+ namespace: DIR_PREP_NAMESPACE,
433
+ method: "context",
434
+ invocation: { kind: "direct" },
435
+ parameters: [{
436
+ name: "request",
437
+ wire: "request",
438
+ source: "json",
439
+ codec: SESSION_CODEC
440
+ }],
441
+ result: { mode: "src-json" }
442
+ },
443
+ {
444
+ id: `${PACKAGE_NAME}#${DIR_PREP_NAMESPACE}/model`,
445
+ service: DIR_PREP_NAMESPACE,
446
+ namespace: DIR_PREP_NAMESPACE,
447
+ method: "model",
448
+ invocation: { kind: "direct" },
449
+ parameters: [{
450
+ name: "request",
451
+ wire: "request",
452
+ source: "json",
453
+ codec: SESSION_CODEC
454
+ }],
455
+ result: { mode: "src-json" }
456
+ },
457
+ {
458
+ id: `${PACKAGE_NAME}#${DIR_PREP_NAMESPACE}/organize`,
459
+ service: DIR_PREP_NAMESPACE,
460
+ namespace: DIR_PREP_NAMESPACE,
461
+ method: "organize",
462
+ invocation: { kind: "direct" },
463
+ parameters: [{
464
+ name: "request",
465
+ wire: "request",
466
+ source: "json",
467
+ codec: {
468
+ mode: "strict",
469
+ typeSymbol: `${PACKAGE_NAME}#organize-request`,
470
+ create: () => ({ parse(value) {
471
+ if (!e(value) || typeof value["sessionId"] !== "string" || typeof value["prompt"] !== "string" || typeof value["entriesSummary"] !== "string") throw new TypeError("organize request requires string sessionId, prompt and entriesSummary");
472
+ const { roleText } = value;
473
+ if (roleText !== void 0 && typeof roleText !== "string") throw new TypeError("organize request roleText must be a string when present");
474
+ return {
475
+ sessionId: value["sessionId"],
476
+ prompt: value["prompt"],
477
+ entriesSummary: value["entriesSummary"],
478
+ ...roleText === void 0 ? {} : { roleText }
479
+ };
480
+ } })
481
+ }
482
+ }],
483
+ result: { mode: "src-json" }
484
+ },
485
+ {
486
+ id: `${PACKAGE_NAME}#${DIR_PREP_NAMESPACE}/importTemplates`,
487
+ service: DIR_PREP_NAMESPACE,
488
+ namespace: DIR_PREP_NAMESPACE,
489
+ method: "importTemplates",
490
+ invocation: { kind: "direct" },
491
+ parameters: [{
492
+ name: "request",
493
+ wire: "request",
494
+ source: "json",
495
+ codec: {
496
+ mode: "strict",
497
+ typeSymbol: `${PACKAGE_NAME}#import-request`,
498
+ create: () => ({ parse(value) {
499
+ if (!e(value) || typeof value["path"] !== "string" || typeof value["sessionId"] !== "string") throw new TypeError("import request requires string path and sessionId");
500
+ return {
501
+ path: value["path"],
502
+ sessionId: value["sessionId"]
503
+ };
504
+ } })
505
+ }
506
+ }],
507
+ result: { mode: "src-json" }
508
+ }
509
+ ];
510
+ const isMounter = (value) => e(value) && typeof value["$mount"] === "function";
511
+ const isNamespace = (value) => e(value) && typeof value["defaults"] === "function" && typeof value["context"] === "function" && typeof value["model"] === "function" && typeof value["organize"] === "function" && typeof value["importTemplates"] === "function";
512
+ const unwrap = (result) => {
513
+ if (!result.ok) throw new Error(`${result.error.code}: ${result.error.message}`);
514
+ return result.value;
515
+ };
516
+ function buildReader(ctx, remote) {
517
+ let mounted;
518
+ const namespaceOf = async () => {
519
+ mounted ??= remote.$mount({
520
+ package: PACKAGE_NAME,
521
+ descriptors: DIR_PREP_DESCRIPTORS
522
+ });
523
+ await mounted;
524
+ const namespace = ctx.get?.(DIR_PREP_SERVICE_KEY, false);
525
+ if (!isNamespace(namespace)) throw new Error(`${DIR_PREP_SERVICE_KEY} 未提供:宿主网关没有挂上这枚命名空间`);
526
+ return namespace;
527
+ };
528
+ const call = async (invoke) => {
529
+ const namespace = await namespaceOf();
530
+ return unwrap(await invoke(namespace));
531
+ };
532
+ return {
533
+ defaults: async () => call((namespace) => namespace.defaults()),
534
+ context: async (sessionId) => call((namespace) => namespace.context({ sessionId })),
535
+ model: async (sessionId) => call((namespace) => namespace.model({ sessionId })),
536
+ organize: async (args) => call((namespace) => namespace.organize(args)),
537
+ importTemplates: async (args) => call((namespace) => namespace.importTemplates(args))
538
+ };
539
+ }
540
+ /** 造读取器;当前部署没有远程面时 undefined(卡片只显示读不到)。 */
541
+ function createDirPrepReader(ctx) {
542
+ const remote = ctx.get?.("remote");
543
+ return isMounter(remote) ? buildReader(ctx, remote) : void 0;
405
544
  }
406
545
  //#endregion
407
546
  //#region src/client-entry.ts
408
547
  const NS = "dir-prep-organize";
409
548
  const BUNDLE_PKG = "@jayyuen66/dsh-dir-prep-organize";
410
- const CONTEXT_URL = "/_dsh/dir-prep/context";
411
- const MODEL_URL = "/_dsh/dir-prep/model";
412
- const ORGANIZE_URL = "/_dsh/dir-prep/organize";
413
- const IMPORT_URL = "/_dsh/dir-prep/import";
414
- const FETCH_TIMEOUT_MS = 125e3;
415
549
  const ERROR_FLASH_MS = 4e3;
550
+ /** 非整理读面的等待上限(与迁移前 HTTP 读面的常量同值)。 */
551
+ const REMOTE_TIMEOUT_MS = 125e3;
416
552
  const RESET_CONFIRM_MS = 4e3;
417
553
  const EMOJI_PLACEHOLDER = "😀";
418
554
  const ROOT_PATH_PLACEHOLDER = "/Users/me/roles";
@@ -421,7 +557,7 @@ const CLASS_ROW_HEAD = "dpic-rowhead";
421
557
  const CLASS_IMPORT_PATH = "dpic-importpath";
422
558
  const SLOT_INPUT_RIGHT = "conversation.input.right";
423
559
  function parseDirEntry(raw) {
424
- const { name, isDir, sizeBytes, snippet } = e$1(raw) ? raw : {};
560
+ const { name, isDir, sizeBytes, snippet } = e(raw) ? raw : {};
425
561
  return {
426
562
  name: typeof name === "string" ? name : "",
427
563
  isDir: isDir === true,
@@ -429,7 +565,7 @@ function parseDirEntry(raw) {
429
565
  ...typeof snippet === "string" ? { snippet } : {}
430
566
  };
431
567
  }
432
- /** 可选字符串位的窄化(`error`/`csrf`/`cwd`/`content` 等共用一条)。 */
568
+ /** 可选字符串位的窄化(`error`/`cwd`/`content` 等共用一条)。 */
433
569
  function optionalString(rec, key) {
434
570
  const value = rec[key];
435
571
  return typeof value === "string" ? value : void 0;
@@ -452,31 +588,29 @@ function skipCountsOf(skips) {
452
588
  ];
453
589
  }
454
590
  function parseContextResponse(raw) {
455
- const rec = e$1(raw) ? raw : {};
591
+ const rec = e(raw) ? raw : {};
456
592
  const { ok, truncated, entries } = rec;
457
593
  const parsedEntries = Array.isArray(entries) ? entries.map((entry) => parseDirEntry(entry)) : void 0;
458
594
  return {
459
595
  ok: ok === true,
460
596
  ...spreadIfDefined(optionalString(rec, "error"), "error"),
461
- ...spreadIfDefined(optionalString(rec, "csrf"), "csrf"),
462
597
  ...spreadIfDefined(optionalString(rec, "cwd"), "cwd"),
463
598
  ...truncated === true ? { truncated: true } : {},
464
599
  ...parsedEntries === void 0 ? {} : { entries: parsedEntries }
465
600
  };
466
601
  }
467
602
  function parseModelResponse(raw) {
468
- const rec = e$1(raw) ? raw : {};
603
+ const rec = e(raw) ? raw : {};
469
604
  return {
470
605
  ok: rec["ok"] === true,
471
606
  ...spreadIfDefined(optionalString(rec, "error"), "error"),
472
- ...spreadIfDefined(optionalString(rec, "csrf"), "csrf"),
473
607
  ...spreadIfDefined(optionalString(rec, "provider"), "provider"),
474
608
  ...spreadIfDefined(optionalString(rec, "model"), "model"),
475
609
  ...spreadIfDefined(optionalString(rec, "reasoningEffort"), "reasoningEffort")
476
610
  };
477
611
  }
478
612
  function parseOrganizeResponse(raw) {
479
- const rec = e$1(raw) ? raw : {};
613
+ const rec = e(raw) ? raw : {};
480
614
  return {
481
615
  ok: rec["ok"] === true,
482
616
  ...spreadIfDefined(optionalString(rec, "error"), "error"),
@@ -504,14 +638,14 @@ function formatImportSkips(t, skips) {
504
638
  return parts.length === 0 ? "" : t("skipSummary", { list: parts.join(t("skipSeparator")) });
505
639
  }
506
640
  function parseImportResponse(raw) {
507
- const { ok, error, count, truncated, skipped, entries } = e$1(raw) ? raw : {};
641
+ const { ok, error, count, truncated, skipped, entries } = e(raw) ? raw : {};
508
642
  const parsedEntries = Array.isArray(entries) ? sanitizeTemplateList(entries) : void 0;
509
643
  return {
510
644
  ok: ok === true,
511
645
  ...typeof error === "string" ? { error } : {},
512
646
  ...typeof count === "number" ? { count } : {},
513
647
  ...truncated === true ? { truncated: true } : {},
514
- ...e$1(skipped) ? { skipped: parseImportSkips(skipped) } : {},
648
+ ...e(skipped) ? { skipped: parseImportSkips(skipped) } : {},
515
649
  ...parsedEntries === void 0 ? {} : { entries: parsedEntries }
516
650
  };
517
651
  }
@@ -531,48 +665,6 @@ function formatContextSummary(resp) {
531
665
  }
532
666
  return lines.join("\n");
533
667
  }
534
- async function httpErrorMessage(response) {
535
- const fallback = `HTTP ${String(response.status)}`;
536
- const body = await response.json().catch(() => null);
537
- const { error } = e$1(body) ? body : {};
538
- return typeof error === "string" && error.length > 0 ? error : fallback;
539
- }
540
- /**
541
- * fetch + 超时 + JSON 解析:四个端点唯一的取数口。
542
- *
543
- * 超时用 AbortController(不是 Promise.race):竞速只能让**调用方**提前放弃,
544
- * 底层请求仍在跑、连接与响应体照常被读进内存;abort 才真的把传输停掉。
545
- * 定时器在 finally 里清(成功/失败/超时三条路都过),否则每次请求在长驻页面里
546
- * 留一个悬挂的 timer。
547
- *
548
- * @param url - 端点路径(常量,见文件头那一组 URL)
549
- * @param init - fetch init(method/headers/body)
550
- * @param timeoutMs - 中止时限;越界值由调用方先夹好(见 client-timeouts.ts)
551
- * @returns 解析后的 JSON(unknown:形状交给各 parse* 判)
552
- */
553
- async function fetchJson(url, init, timeoutMs = FETCH_TIMEOUT_MS) {
554
- const controller = new AbortController();
555
- const timer = setTimeout(() => {
556
- controller.abort();
557
- }, timeoutMs);
558
- try {
559
- const headers = new Headers(init?.headers);
560
- headers.set("accept", "application/json");
561
- const response = await fetch(url, {
562
- ...init,
563
- signal: controller.signal,
564
- headers
565
- });
566
- if (!response.ok) throw new Error(await httpErrorMessage(response));
567
- return await response.json();
568
- } catch (error) {
569
- if (error instanceof Error && error.name === "AbortError") throw new Error("请求超时", { cause: error });
570
- throw new Error(n(error), { cause: error });
571
- } finally {
572
- clearTimeout(timer);
573
- }
574
- }
575
- const BUILTIN_TEMPLATES_URL = "/_dsh/dir-prep/default-templates";
576
668
  const builtinInitial = {
577
669
  phase: "idle",
578
670
  list: [],
@@ -590,6 +682,27 @@ function setBuiltinState(next) {
590
682
  function builtinTemplatesSnapshot() {
591
683
  return builtinState;
592
684
  }
685
+ let dirPrepReader;
686
+ /** 导出仅供单测:不经过 apply 的纯读面用例直接注入替身。 */
687
+ function setDirPrepReader(reader) {
688
+ dirPrepReader = reader;
689
+ }
690
+ function requireReader() {
691
+ if (dirPrepReader === void 0) throw new Error("远程读面不可用:宿主网关没有挂上 dirPrepOrganize");
692
+ return dirPrepReader;
693
+ }
694
+ /** 客户端超时只影响等待:宿主侧的整理超时仍由它自己的 AbortController 收口。 */
695
+ async function within(pending, timeoutMs) {
696
+ const gate = Promise.withResolvers();
697
+ const timer = setTimeout(() => {
698
+ gate.reject(/* @__PURE__ */ new Error("请求超时"));
699
+ }, timeoutMs);
700
+ try {
701
+ return await Promise.race([pending, gate.promise]);
702
+ } finally {
703
+ clearTimeout(timer);
704
+ }
705
+ }
593
706
  async function loadBuiltinTemplates() {
594
707
  if (builtinState.phase === "ready") return builtinState;
595
708
  if (builtinInflight !== null) return await builtinInflight;
@@ -601,8 +714,8 @@ async function loadBuiltinTemplates() {
601
714
  });
602
715
  let settled;
603
716
  try {
604
- const body = await fetchJson(BUILTIN_TEMPLATES_URL);
605
- const payload = e$1(body) ? body : void 0;
717
+ const body = await within(requireReader().defaults(), REMOTE_TIMEOUT_MS);
718
+ const payload = e(body) ? body : void 0;
606
719
  const okKey = "ok";
607
720
  const templatesKey = "templates";
608
721
  const rawReason = payload?.["error"];
@@ -619,7 +732,7 @@ async function loadBuiltinTemplates() {
619
732
  settled = {
620
733
  phase: "error",
621
734
  list: [],
622
- error: n(error)
735
+ error: r(error)
623
736
  };
624
737
  } finally {
625
738
  builtinInflight = null;
@@ -659,35 +772,25 @@ function assertOrganizeReady(ctxRes, modelRes, prompt) {
659
772
  if (!ctxRes.ok) throw new Error(`目录上下文失败: ${ctxRes.error ?? "未知错误"}`);
660
773
  if (!modelRes.ok || modelRes.provider === void 0 || modelRes.model === void 0) throw new Error(`读取模型失败: ${modelRes.error ?? "未知错误"}`);
661
774
  if (prompt.trim().length === 0) throw new Error("输入框为空,无内容可整理");
662
- const csrf = ctxRes.csrf ?? modelRes.csrf ?? "";
663
- if (csrf === "") throw new Error(`整理令牌缺失:${ctxRes.error ?? modelRes.error ?? "请重试"}`);
664
- return csrf;
665
775
  }
666
776
  async function requestOrganize(args) {
667
- const { csrf, ctxRes, prompt, sessionId, roleText, timeoutMs } = args;
668
- const body = {
669
- prompt,
777
+ const { ctxRes, prompt, sessionId, roleText, timeoutMs } = args;
778
+ const entriesSummary = formatContextSummary(ctxRes);
779
+ const orgRes = parseOrganizeResponse(await within(requireReader().organize({
670
780
  sessionId,
671
- entriesSummary: formatContextSummary(ctxRes)
672
- };
673
- const roleKey = "roleText";
674
- if (roleText !== void 0) body[roleKey] = roleText;
675
- const orgRes = parseOrganizeResponse(await fetchJson(ORGANIZE_URL, {
676
- method: "POST",
677
- headers: {
678
- "content-type": "application/json",
679
- "x-dir-prep-csrf": csrf
680
- },
681
- body: JSON.stringify(body)
682
- }, timeoutMs));
781
+ prompt,
782
+ entriesSummary,
783
+ ...roleText === void 0 ? {} : { roleText }
784
+ }), timeoutMs));
683
785
  if (!orgRes.ok || orgRes.content === void 0) throw new Error(orgRes.error ?? "整理失败(未知错误)");
684
786
  return orgRes.content;
685
787
  }
686
788
  async function runOrganizeFlow(args) {
687
- const [ctxRaw, modelRaw] = await Promise.all([fetchJson(`${CONTEXT_URL}?sessionId=${encodeURIComponent(args.sessionId)}`), fetchJson(`${MODEL_URL}?sessionId=${encodeURIComponent(args.sessionId)}`)]);
789
+ const reader = requireReader();
790
+ const [ctxRaw, modelRaw] = await Promise.all([within(reader.context(args.sessionId), REMOTE_TIMEOUT_MS), within(reader.model(args.sessionId), REMOTE_TIMEOUT_MS)]);
688
791
  const ctxRes = parseContextResponse(ctxRaw);
792
+ assertOrganizeReady(ctxRes, parseModelResponse(modelRaw), args.prompt);
689
793
  return requestOrganize({
690
- csrf: assertOrganizeReady(ctxRes, parseModelResponse(modelRaw), args.prompt),
691
794
  ctxRes,
692
795
  prompt: args.prompt,
693
796
  sessionId: args.sessionId,
@@ -914,7 +1017,7 @@ async function runOrganizeClick(args) {
914
1017
  writeDraft(content);
915
1018
  } catch (error) {
916
1019
  if (seq.current !== mySeq) return;
917
- setFailed(n(error));
1020
+ setFailed(r(error));
918
1021
  if (flashTimer.current !== null) clearTimeout(flashTimer.current);
919
1022
  flashTimer.current = setTimeout(() => {
920
1023
  setFailed(void 0);
@@ -1285,14 +1388,10 @@ function ImportPanel(props) {
1285
1388
  setImportError("");
1286
1389
  setImportMsg("");
1287
1390
  try {
1288
- const resp = parseImportResponse(await fetchJson(IMPORT_URL, {
1289
- method: "POST",
1290
- headers: { "content-type": "application/json" },
1291
- body: JSON.stringify({
1292
- path: target,
1293
- sessionId: ""
1294
- })
1295
- }));
1391
+ const resp = parseImportResponse(await within(requireReader().importTemplates({
1392
+ path: target,
1393
+ sessionId: ""
1394
+ }), REMOTE_TIMEOUT_MS));
1296
1395
  if (!resp.ok || resp.entries === void 0) throw new Error(resp.error ?? t("importFailedUnknown"));
1297
1396
  const usable = resp.entries.length;
1298
1397
  const count = Math.min(resp.count ?? usable, usable);
@@ -1312,7 +1411,7 @@ function ImportPanel(props) {
1312
1411
  skips: skipNote
1313
1412
  }));
1314
1413
  } catch (error) {
1315
- setImportError(n(error));
1414
+ setImportError(r(error));
1316
1415
  } finally {
1317
1416
  setImportBusy(false);
1318
1417
  }
@@ -1539,7 +1638,7 @@ function createPersistActions(args) {
1539
1638
  const { t, editable, dirty, rootsDirty, anythingDirty, confirmReset, templates, allowRoots, draft, rootsDraft, set, unset, readBack, setDraft, setDraftFor, setRootsDraft, setBusy, setSaveError, setConfirmReset } = args;
1540
1639
  function reportError(err) {
1541
1640
  console.error("[dir-prep-organize] templates settings write failed:", err);
1542
- setSaveError(n(err));
1641
+ setSaveError(r(err));
1543
1642
  }
1544
1643
  async function onSave() {
1545
1644
  if (!editable || !anythingDirty) return;
@@ -1772,6 +1871,11 @@ function injectCard(ctx, store, t, scope) {
1772
1871
  });
1773
1872
  }
1774
1873
  function apply(ctx) {
1874
+ const reader = createDirPrepReader(ctx);
1875
+ dirPrepReader = reader;
1876
+ ctx.effect(() => () => {
1877
+ if (dirPrepReader === reader) dirPrepReader = void 0;
1878
+ }, "dir-prep-organize: remote reader");
1775
1879
  ctx.effect(() => {
1776
1880
  const tag = document.createElement("style");
1777
1881
  tag.id = "dir-prep-organize-css";
@@ -1801,6 +1905,7 @@ exports.parseOrganizeResponse = parseOrganizeResponse;
1801
1905
  exports.persistError = persistError;
1802
1906
  exports.resetBuiltinTemplates = resetBuiltinTemplates;
1803
1907
  exports.rootsPersistError = rootsPersistError;
1908
+ exports.setDirPrepReader = setDirPrepReader;
1804
1909
  exports.subscribeBuiltinTemplates = subscribeBuiltinTemplates;
1805
1910
  return module.exports;
1806
1911
  },
package/cordis.patch.yml CHANGED
@@ -1,30 +1,26 @@
1
1
  # dir-prep-organize(整理 + 模板;内容源为内置角色库)。
2
2
  # 功能一「整理」:输入框右上角分段按钮。主键点击 → 按当前目录结构 + 当前 session
3
3
  # 模型整理优化草稿(成功直接替换,失败保持原值);▾ → 「以 XX 视角整理」(角色菜单,
4
- # 角色上下文 = 模板正文提炼,随 organize POST 注入 system,走同一 LLM 流)。
4
+ # 角色上下文 = 模板正文提炼,随 organize 调用注入 system,走同一 LLM 流)。
5
5
  # 功能二「模板」:输入框旁「模板」下拉,默认展示精选角色集(由 scripts/gen-defaults.mjs
6
6
  # 从插件 agents/ 目录生成,src/default-templates.generated.ts 单源),按 group 分组
7
7
  # 渲染(emoji + 名称 + description 悬停);点选插入草稿(空整段填入 / 非空末尾追加)。
8
8
  # 列表存 settings(0.1.7 隐式注册:命名空间 = 本条目 id,可编辑字段 = host.ts 导出的
9
9
  # Config 上标了 .volatile() 的 templates/importAllowRoots;生成集不再是 register 的 base,
10
10
  # 而是 client 半的回落),设置页卡逐条增删改(name/emoji/
11
- # group/description/text)+ 两步确认恢复默认 + 角色导入(POST import:留空 = 一键导入
12
- # 内置 agents/ 全部;填路径 = 导入本地 .md 或目录)。client 直读本条目的配置表单
11
+ # group/description/text)+ 两步确认恢复默认 + 角色导入(importTemplates:留空 = 一键
12
+ # 导入内置 agents/ 全部;填路径 = 导入本地 .md 或目录)。client 直读本条目的配置表单
13
13
  # (ctx.configForms.get(条目 id);0.1.7 已移除 settingsScope)。
14
14
  #
15
- # 架构(全量源码复核后定为 webServer + fetch;harness.handle/
16
- # host.call 是动态插件闭包 RPC,loader 行插件的 Client 半没有该通道):
17
- # Host 半(host.ts)注册四个 webServer 路由(session-rescue 同款已验证模式):
18
- # GET /_dsh/dir-prep/context 目录上下文(会话 cwd,文件名+大小+关键摘要)
19
- # GET /_dsh/dir-prep/model 当前默认模型(agentDefaultModel.currentSelection)
20
- # POST /_dsh/dir-prep/organize LLM 整理(llm.stream,cwd + 目录摘要 + 可选角色)
21
- # POST /_dsh/dir-prep/import 角色导入(只读;空路径=内置 agents/ 全部)
22
- # Client 半(src/client-entry.ts → client.js)注册 conversation.input.right
23
- # list 槽(整理 id=dir-prep-organize order 99 / 模板 id=…-templates order 100)
24
- # 与 plugins.bundle.config 设置卡(keyed;0.1.6 起 settings.plugin.item 已随旧设置页
25
- # 删除);整理 fetch 上述端点,写回走
26
- # inputActions.setDraft;模板读写配置表单 ctx.configForms.get(条目 id)(数组 set=字段级整体替换,
27
- # 已按 dsh-settings applyPathOp/cloneJsonShaped 源码取证)。
15
+ # 架构:Host 半(host.ts)注册官方 Typert Remote 的服务键 `dirPrepOrganize`,
16
+ # defaults / context / model / organize / importTemplates 五个方法就是全部读面;
17
+ # 认证、Host/DNS 重绑定/Origin 判据与请求体上限由宿主 /api 网关承担,本包不注册
18
+ # HTTP 路由、也没有自建 CSRF 令牌。Client 半(src/client-entry.ts → client.js)注册
19
+ # conversation.input.right list 槽(整理 id=dir-prep-organize order 99 / 模板
20
+ # id=…-templates order 100)与 plugins.bundle.config 设置卡(keyed;0.1.6 起
21
+ # settings.plugin.item 已随旧设置页删除);整理经 Remote 读取器调用上述方法,写回走
22
+ # inputActions.setDraft;模板读写配置表单 ctx.configForms.get(条目 id)(数组 set=字段级整体替换,
23
+ # 已按 dsh-settings applyPathOp/cloneJsonShaped 源码取证)。
28
24
  - insert:
29
25
  - id: dir-prep-organize
30
26
  name: "@jayyuen66/dsh-dir-prep-organize"