@jayyuen66/dsh-dir-prep-organize 0.1.2 → 0.1.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/README.md +26 -29
- package/README.zh-CN.md +29 -32
- package/client.js +215 -108
- package/cordis.patch.yml +12 -16
- package/host.js +270 -358
- package/package.json +49 -43
- package/types/host.d.ts +105 -74
- package/types/src/client-entry.d.ts +5 -1
- package/types/src/client-timeouts.d.ts +1 -1
- package/types/src/host-messages.d.ts +0 -2
- package/types/src/remote.d.ts +27 -0
- package/types/src/templates.d.ts +4 -4
- package/types/src/ui-messages.d.ts +3 -3
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.
|
|
10
|
-
function 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
|
|
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
|
-
*
|
|
124
|
+
* 而这一侧是**唯一**发起整理读面调用的地方,它要是没夹,host 夹得再对也没用。
|
|
125
125
|
*
|
|
126
126
|
* @param value - 配置表单投影值
|
|
127
127
|
* @returns `[1, MAX_TIMER_MS]` 区间内的整数;不合法时 undefined(回落默认)
|
|
@@ -376,43 +376,181 @@ const UI_MESSAGES = {
|
|
|
376
376
|
}
|
|
377
377
|
};
|
|
378
378
|
//#endregion
|
|
379
|
-
//#region node_modules/.pnpm/@jayyuen66+dsh-plugin-shared@0.1.
|
|
380
|
-
function
|
|
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
|
|
385
|
-
if (r.has(
|
|
386
|
-
r.add(
|
|
384
|
+
function n(e, r) {
|
|
385
|
+
if (r.has(e)) return `<circular cause>`;
|
|
386
|
+
r.add(e);
|
|
387
387
|
try {
|
|
388
|
-
if (!(
|
|
389
|
-
if (typeof
|
|
390
|
-
let
|
|
391
|
-
if (
|
|
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(
|
|
393
|
+
return String(e);
|
|
394
394
|
}
|
|
395
|
-
let i =
|
|
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(
|
|
400
|
+
r.delete(e);
|
|
401
401
|
}
|
|
402
402
|
}
|
|
403
|
-
function
|
|
404
|
-
return
|
|
403
|
+
function r(e) {
|
|
404
|
+
return n(e, /* @__PURE__ */ new Set());
|
|
405
|
+
}
|
|
406
|
+
//#endregion
|
|
407
|
+
//#region src/remote.ts
|
|
408
|
+
/** Typert Remote 命名空间。**单源**:错误文案与宿主侧注册都用这一枚,
|
|
409
|
+
* 写死两处会让"网关挂的是 A、报错说的是 B"这种漂移没有任何运行期信号。 */
|
|
410
|
+
const DIR_PREP_NAMESPACE = "dirPrepOrganize";
|
|
411
|
+
const DIR_PREP_SERVICE_KEY = `remote.${DIR_PREP_NAMESPACE}`;
|
|
412
|
+
const PACKAGE_NAME = "@jayyuen66/dsh-dir-prep-organize";
|
|
413
|
+
const SESSION_CODEC = {
|
|
414
|
+
mode: "strict",
|
|
415
|
+
typeSymbol: `${PACKAGE_NAME}#session-request`,
|
|
416
|
+
create: () => ({ parse(value) {
|
|
417
|
+
if (!e(value) || typeof value["sessionId"] !== "string") throw new TypeError("session request requires a string sessionId");
|
|
418
|
+
return { sessionId: value["sessionId"] };
|
|
419
|
+
} })
|
|
420
|
+
};
|
|
421
|
+
const DIR_PREP_DESCRIPTORS = [
|
|
422
|
+
{
|
|
423
|
+
id: `${PACKAGE_NAME}#${DIR_PREP_NAMESPACE}/defaults`,
|
|
424
|
+
service: DIR_PREP_NAMESPACE,
|
|
425
|
+
namespace: DIR_PREP_NAMESPACE,
|
|
426
|
+
method: "defaults",
|
|
427
|
+
invocation: { kind: "direct" },
|
|
428
|
+
parameters: [],
|
|
429
|
+
result: { mode: "src-json" }
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
id: `${PACKAGE_NAME}#${DIR_PREP_NAMESPACE}/context`,
|
|
433
|
+
service: DIR_PREP_NAMESPACE,
|
|
434
|
+
namespace: DIR_PREP_NAMESPACE,
|
|
435
|
+
method: "context",
|
|
436
|
+
invocation: { kind: "direct" },
|
|
437
|
+
parameters: [{
|
|
438
|
+
name: "request",
|
|
439
|
+
wire: "request",
|
|
440
|
+
source: "json",
|
|
441
|
+
codec: SESSION_CODEC
|
|
442
|
+
}],
|
|
443
|
+
result: { mode: "src-json" }
|
|
444
|
+
},
|
|
445
|
+
{
|
|
446
|
+
id: `${PACKAGE_NAME}#${DIR_PREP_NAMESPACE}/model`,
|
|
447
|
+
service: DIR_PREP_NAMESPACE,
|
|
448
|
+
namespace: DIR_PREP_NAMESPACE,
|
|
449
|
+
method: "model",
|
|
450
|
+
invocation: { kind: "direct" },
|
|
451
|
+
parameters: [{
|
|
452
|
+
name: "request",
|
|
453
|
+
wire: "request",
|
|
454
|
+
source: "json",
|
|
455
|
+
codec: SESSION_CODEC
|
|
456
|
+
}],
|
|
457
|
+
result: { mode: "src-json" }
|
|
458
|
+
},
|
|
459
|
+
{
|
|
460
|
+
id: `${PACKAGE_NAME}#${DIR_PREP_NAMESPACE}/organize`,
|
|
461
|
+
service: DIR_PREP_NAMESPACE,
|
|
462
|
+
namespace: DIR_PREP_NAMESPACE,
|
|
463
|
+
method: "organize",
|
|
464
|
+
invocation: { kind: "direct" },
|
|
465
|
+
parameters: [{
|
|
466
|
+
name: "request",
|
|
467
|
+
wire: "request",
|
|
468
|
+
source: "json",
|
|
469
|
+
codec: {
|
|
470
|
+
mode: "strict",
|
|
471
|
+
typeSymbol: `${PACKAGE_NAME}#organize-request`,
|
|
472
|
+
create: () => ({ parse(value) {
|
|
473
|
+
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");
|
|
474
|
+
const { roleText } = value;
|
|
475
|
+
if (roleText !== void 0 && typeof roleText !== "string") throw new TypeError("organize request roleText must be a string when present");
|
|
476
|
+
return {
|
|
477
|
+
sessionId: value["sessionId"],
|
|
478
|
+
prompt: value["prompt"],
|
|
479
|
+
entriesSummary: value["entriesSummary"],
|
|
480
|
+
...roleText === void 0 ? {} : { roleText }
|
|
481
|
+
};
|
|
482
|
+
} })
|
|
483
|
+
}
|
|
484
|
+
}],
|
|
485
|
+
result: { mode: "src-json" }
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
id: `${PACKAGE_NAME}#${DIR_PREP_NAMESPACE}/importTemplates`,
|
|
489
|
+
service: DIR_PREP_NAMESPACE,
|
|
490
|
+
namespace: DIR_PREP_NAMESPACE,
|
|
491
|
+
method: "importTemplates",
|
|
492
|
+
invocation: { kind: "direct" },
|
|
493
|
+
parameters: [{
|
|
494
|
+
name: "request",
|
|
495
|
+
wire: "request",
|
|
496
|
+
source: "json",
|
|
497
|
+
codec: {
|
|
498
|
+
mode: "strict",
|
|
499
|
+
typeSymbol: `${PACKAGE_NAME}#import-request`,
|
|
500
|
+
create: () => ({ parse(value) {
|
|
501
|
+
if (!e(value) || typeof value["path"] !== "string" || typeof value["sessionId"] !== "string") throw new TypeError("import request requires string path and sessionId");
|
|
502
|
+
return {
|
|
503
|
+
path: value["path"],
|
|
504
|
+
sessionId: value["sessionId"]
|
|
505
|
+
};
|
|
506
|
+
} })
|
|
507
|
+
}
|
|
508
|
+
}],
|
|
509
|
+
result: { mode: "src-json" }
|
|
510
|
+
}
|
|
511
|
+
];
|
|
512
|
+
const isMounter = (value) => e(value) && typeof value["$mount"] === "function";
|
|
513
|
+
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";
|
|
514
|
+
const unwrap = (result) => {
|
|
515
|
+
if (!result.ok) throw new Error(`${result.error.code}: ${result.error.message}`);
|
|
516
|
+
return result.value;
|
|
517
|
+
};
|
|
518
|
+
function buildReader(ctx, remote) {
|
|
519
|
+
let mounted;
|
|
520
|
+
const namespaceOf = async () => {
|
|
521
|
+
mounted ??= remote.$mount({
|
|
522
|
+
package: PACKAGE_NAME,
|
|
523
|
+
descriptors: DIR_PREP_DESCRIPTORS
|
|
524
|
+
});
|
|
525
|
+
await mounted;
|
|
526
|
+
const namespace = ctx.get?.(DIR_PREP_SERVICE_KEY, false);
|
|
527
|
+
if (!isNamespace(namespace)) throw new Error(`${DIR_PREP_SERVICE_KEY} 未提供:宿主网关没有挂上这枚命名空间`);
|
|
528
|
+
return namespace;
|
|
529
|
+
};
|
|
530
|
+
const call = async (invoke) => {
|
|
531
|
+
const namespace = await namespaceOf();
|
|
532
|
+
return unwrap(await invoke(namespace));
|
|
533
|
+
};
|
|
534
|
+
return {
|
|
535
|
+
defaults: async () => call((namespace) => namespace.defaults()),
|
|
536
|
+
context: async (sessionId) => call((namespace) => namespace.context({ sessionId })),
|
|
537
|
+
model: async (sessionId) => call((namespace) => namespace.model({ sessionId })),
|
|
538
|
+
organize: async (args) => call((namespace) => namespace.organize(args)),
|
|
539
|
+
importTemplates: async (args) => call((namespace) => namespace.importTemplates(args))
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
/** 造读取器;当前部署没有远程面时 undefined(卡片只显示读不到)。 */
|
|
543
|
+
function createDirPrepReader(ctx) {
|
|
544
|
+
const remote = ctx.get?.("remote");
|
|
545
|
+
return isMounter(remote) ? buildReader(ctx, remote) : void 0;
|
|
405
546
|
}
|
|
406
547
|
//#endregion
|
|
407
548
|
//#region src/client-entry.ts
|
|
408
549
|
const NS = "dir-prep-organize";
|
|
409
550
|
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
551
|
const ERROR_FLASH_MS = 4e3;
|
|
552
|
+
/** 非整理读面的等待上限(与迁移前 HTTP 读面的常量同值)。 */
|
|
553
|
+
const REMOTE_TIMEOUT_MS = 125e3;
|
|
416
554
|
const RESET_CONFIRM_MS = 4e3;
|
|
417
555
|
const EMOJI_PLACEHOLDER = "😀";
|
|
418
556
|
const ROOT_PATH_PLACEHOLDER = "/Users/me/roles";
|
|
@@ -421,7 +559,7 @@ const CLASS_ROW_HEAD = "dpic-rowhead";
|
|
|
421
559
|
const CLASS_IMPORT_PATH = "dpic-importpath";
|
|
422
560
|
const SLOT_INPUT_RIGHT = "conversation.input.right";
|
|
423
561
|
function parseDirEntry(raw) {
|
|
424
|
-
const { name, isDir, sizeBytes, snippet } = e
|
|
562
|
+
const { name, isDir, sizeBytes, snippet } = e(raw) ? raw : {};
|
|
425
563
|
return {
|
|
426
564
|
name: typeof name === "string" ? name : "",
|
|
427
565
|
isDir: isDir === true,
|
|
@@ -429,7 +567,7 @@ function parseDirEntry(raw) {
|
|
|
429
567
|
...typeof snippet === "string" ? { snippet } : {}
|
|
430
568
|
};
|
|
431
569
|
}
|
|
432
|
-
/** 可选字符串位的窄化(`error`/`
|
|
570
|
+
/** 可选字符串位的窄化(`error`/`cwd`/`content` 等共用一条)。 */
|
|
433
571
|
function optionalString(rec, key) {
|
|
434
572
|
const value = rec[key];
|
|
435
573
|
return typeof value === "string" ? value : void 0;
|
|
@@ -452,31 +590,29 @@ function skipCountsOf(skips) {
|
|
|
452
590
|
];
|
|
453
591
|
}
|
|
454
592
|
function parseContextResponse(raw) {
|
|
455
|
-
const rec = e
|
|
593
|
+
const rec = e(raw) ? raw : {};
|
|
456
594
|
const { ok, truncated, entries } = rec;
|
|
457
595
|
const parsedEntries = Array.isArray(entries) ? entries.map((entry) => parseDirEntry(entry)) : void 0;
|
|
458
596
|
return {
|
|
459
597
|
ok: ok === true,
|
|
460
598
|
...spreadIfDefined(optionalString(rec, "error"), "error"),
|
|
461
|
-
...spreadIfDefined(optionalString(rec, "csrf"), "csrf"),
|
|
462
599
|
...spreadIfDefined(optionalString(rec, "cwd"), "cwd"),
|
|
463
600
|
...truncated === true ? { truncated: true } : {},
|
|
464
601
|
...parsedEntries === void 0 ? {} : { entries: parsedEntries }
|
|
465
602
|
};
|
|
466
603
|
}
|
|
467
604
|
function parseModelResponse(raw) {
|
|
468
|
-
const rec = e
|
|
605
|
+
const rec = e(raw) ? raw : {};
|
|
469
606
|
return {
|
|
470
607
|
ok: rec["ok"] === true,
|
|
471
608
|
...spreadIfDefined(optionalString(rec, "error"), "error"),
|
|
472
|
-
...spreadIfDefined(optionalString(rec, "csrf"), "csrf"),
|
|
473
609
|
...spreadIfDefined(optionalString(rec, "provider"), "provider"),
|
|
474
610
|
...spreadIfDefined(optionalString(rec, "model"), "model"),
|
|
475
611
|
...spreadIfDefined(optionalString(rec, "reasoningEffort"), "reasoningEffort")
|
|
476
612
|
};
|
|
477
613
|
}
|
|
478
614
|
function parseOrganizeResponse(raw) {
|
|
479
|
-
const rec = e
|
|
615
|
+
const rec = e(raw) ? raw : {};
|
|
480
616
|
return {
|
|
481
617
|
ok: rec["ok"] === true,
|
|
482
618
|
...spreadIfDefined(optionalString(rec, "error"), "error"),
|
|
@@ -504,14 +640,14 @@ function formatImportSkips(t, skips) {
|
|
|
504
640
|
return parts.length === 0 ? "" : t("skipSummary", { list: parts.join(t("skipSeparator")) });
|
|
505
641
|
}
|
|
506
642
|
function parseImportResponse(raw) {
|
|
507
|
-
const { ok, error, count, truncated, skipped, entries } = e
|
|
643
|
+
const { ok, error, count, truncated, skipped, entries } = e(raw) ? raw : {};
|
|
508
644
|
const parsedEntries = Array.isArray(entries) ? sanitizeTemplateList(entries) : void 0;
|
|
509
645
|
return {
|
|
510
646
|
ok: ok === true,
|
|
511
647
|
...typeof error === "string" ? { error } : {},
|
|
512
648
|
...typeof count === "number" ? { count } : {},
|
|
513
649
|
...truncated === true ? { truncated: true } : {},
|
|
514
|
-
...e
|
|
650
|
+
...e(skipped) ? { skipped: parseImportSkips(skipped) } : {},
|
|
515
651
|
...parsedEntries === void 0 ? {} : { entries: parsedEntries }
|
|
516
652
|
};
|
|
517
653
|
}
|
|
@@ -531,48 +667,6 @@ function formatContextSummary(resp) {
|
|
|
531
667
|
}
|
|
532
668
|
return lines.join("\n");
|
|
533
669
|
}
|
|
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
670
|
const builtinInitial = {
|
|
577
671
|
phase: "idle",
|
|
578
672
|
list: [],
|
|
@@ -590,6 +684,27 @@ function setBuiltinState(next) {
|
|
|
590
684
|
function builtinTemplatesSnapshot() {
|
|
591
685
|
return builtinState;
|
|
592
686
|
}
|
|
687
|
+
let dirPrepReader;
|
|
688
|
+
/** 导出仅供单测:不经过 apply 的纯读面用例直接注入替身。 */
|
|
689
|
+
function setDirPrepReader(reader) {
|
|
690
|
+
dirPrepReader = reader;
|
|
691
|
+
}
|
|
692
|
+
function requireReader() {
|
|
693
|
+
if (dirPrepReader === void 0) throw new Error(`远程读面不可用:宿主网关没有挂上 ${DIR_PREP_NAMESPACE}`);
|
|
694
|
+
return dirPrepReader;
|
|
695
|
+
}
|
|
696
|
+
/** 客户端超时只影响等待:宿主侧的整理超时仍由它自己的 AbortController 收口。 */
|
|
697
|
+
async function within(pending, timeoutMs) {
|
|
698
|
+
const gate = Promise.withResolvers();
|
|
699
|
+
const timer = setTimeout(() => {
|
|
700
|
+
gate.reject(/* @__PURE__ */ new Error("请求超时"));
|
|
701
|
+
}, timeoutMs);
|
|
702
|
+
try {
|
|
703
|
+
return await Promise.race([pending, gate.promise]);
|
|
704
|
+
} finally {
|
|
705
|
+
clearTimeout(timer);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
593
708
|
async function loadBuiltinTemplates() {
|
|
594
709
|
if (builtinState.phase === "ready") return builtinState;
|
|
595
710
|
if (builtinInflight !== null) return await builtinInflight;
|
|
@@ -601,8 +716,8 @@ async function loadBuiltinTemplates() {
|
|
|
601
716
|
});
|
|
602
717
|
let settled;
|
|
603
718
|
try {
|
|
604
|
-
const body = await
|
|
605
|
-
const payload = e
|
|
719
|
+
const body = await within(requireReader().defaults(), REMOTE_TIMEOUT_MS);
|
|
720
|
+
const payload = e(body) ? body : void 0;
|
|
606
721
|
const okKey = "ok";
|
|
607
722
|
const templatesKey = "templates";
|
|
608
723
|
const rawReason = payload?.["error"];
|
|
@@ -619,7 +734,7 @@ async function loadBuiltinTemplates() {
|
|
|
619
734
|
settled = {
|
|
620
735
|
phase: "error",
|
|
621
736
|
list: [],
|
|
622
|
-
error:
|
|
737
|
+
error: r(error)
|
|
623
738
|
};
|
|
624
739
|
} finally {
|
|
625
740
|
builtinInflight = null;
|
|
@@ -659,35 +774,25 @@ function assertOrganizeReady(ctxRes, modelRes, prompt) {
|
|
|
659
774
|
if (!ctxRes.ok) throw new Error(`目录上下文失败: ${ctxRes.error ?? "未知错误"}`);
|
|
660
775
|
if (!modelRes.ok || modelRes.provider === void 0 || modelRes.model === void 0) throw new Error(`读取模型失败: ${modelRes.error ?? "未知错误"}`);
|
|
661
776
|
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
777
|
}
|
|
666
778
|
async function requestOrganize(args) {
|
|
667
|
-
const {
|
|
668
|
-
const
|
|
669
|
-
|
|
779
|
+
const { ctxRes, prompt, sessionId, roleText, timeoutMs } = args;
|
|
780
|
+
const entriesSummary = formatContextSummary(ctxRes);
|
|
781
|
+
const orgRes = parseOrganizeResponse(await within(requireReader().organize({
|
|
670
782
|
sessionId,
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
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));
|
|
783
|
+
prompt,
|
|
784
|
+
entriesSummary,
|
|
785
|
+
...roleText === void 0 ? {} : { roleText }
|
|
786
|
+
}), timeoutMs));
|
|
683
787
|
if (!orgRes.ok || orgRes.content === void 0) throw new Error(orgRes.error ?? "整理失败(未知错误)");
|
|
684
788
|
return orgRes.content;
|
|
685
789
|
}
|
|
686
790
|
async function runOrganizeFlow(args) {
|
|
687
|
-
const
|
|
791
|
+
const reader = requireReader();
|
|
792
|
+
const [ctxRaw, modelRaw] = await Promise.all([within(reader.context(args.sessionId), REMOTE_TIMEOUT_MS), within(reader.model(args.sessionId), REMOTE_TIMEOUT_MS)]);
|
|
688
793
|
const ctxRes = parseContextResponse(ctxRaw);
|
|
794
|
+
assertOrganizeReady(ctxRes, parseModelResponse(modelRaw), args.prompt);
|
|
689
795
|
return requestOrganize({
|
|
690
|
-
csrf: assertOrganizeReady(ctxRes, parseModelResponse(modelRaw), args.prompt),
|
|
691
796
|
ctxRes,
|
|
692
797
|
prompt: args.prompt,
|
|
693
798
|
sessionId: args.sessionId,
|
|
@@ -914,7 +1019,7 @@ async function runOrganizeClick(args) {
|
|
|
914
1019
|
writeDraft(content);
|
|
915
1020
|
} catch (error) {
|
|
916
1021
|
if (seq.current !== mySeq) return;
|
|
917
|
-
setFailed(
|
|
1022
|
+
setFailed(r(error));
|
|
918
1023
|
if (flashTimer.current !== null) clearTimeout(flashTimer.current);
|
|
919
1024
|
flashTimer.current = setTimeout(() => {
|
|
920
1025
|
setFailed(void 0);
|
|
@@ -1285,14 +1390,10 @@ function ImportPanel(props) {
|
|
|
1285
1390
|
setImportError("");
|
|
1286
1391
|
setImportMsg("");
|
|
1287
1392
|
try {
|
|
1288
|
-
const resp = parseImportResponse(await
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
path: target,
|
|
1293
|
-
sessionId: ""
|
|
1294
|
-
})
|
|
1295
|
-
}));
|
|
1393
|
+
const resp = parseImportResponse(await within(requireReader().importTemplates({
|
|
1394
|
+
path: target,
|
|
1395
|
+
sessionId: ""
|
|
1396
|
+
}), REMOTE_TIMEOUT_MS));
|
|
1296
1397
|
if (!resp.ok || resp.entries === void 0) throw new Error(resp.error ?? t("importFailedUnknown"));
|
|
1297
1398
|
const usable = resp.entries.length;
|
|
1298
1399
|
const count = Math.min(resp.count ?? usable, usable);
|
|
@@ -1312,7 +1413,7 @@ function ImportPanel(props) {
|
|
|
1312
1413
|
skips: skipNote
|
|
1313
1414
|
}));
|
|
1314
1415
|
} catch (error) {
|
|
1315
|
-
setImportError(
|
|
1416
|
+
setImportError(r(error));
|
|
1316
1417
|
} finally {
|
|
1317
1418
|
setImportBusy(false);
|
|
1318
1419
|
}
|
|
@@ -1539,7 +1640,7 @@ function createPersistActions(args) {
|
|
|
1539
1640
|
const { t, editable, dirty, rootsDirty, anythingDirty, confirmReset, templates, allowRoots, draft, rootsDraft, set, unset, readBack, setDraft, setDraftFor, setRootsDraft, setBusy, setSaveError, setConfirmReset } = args;
|
|
1540
1641
|
function reportError(err) {
|
|
1541
1642
|
console.error("[dir-prep-organize] templates settings write failed:", err);
|
|
1542
|
-
setSaveError(
|
|
1643
|
+
setSaveError(r(err));
|
|
1543
1644
|
}
|
|
1544
1645
|
async function onSave() {
|
|
1545
1646
|
if (!editable || !anythingDirty) return;
|
|
@@ -1772,6 +1873,11 @@ function injectCard(ctx, store, t, scope) {
|
|
|
1772
1873
|
});
|
|
1773
1874
|
}
|
|
1774
1875
|
function apply(ctx) {
|
|
1876
|
+
const reader = createDirPrepReader(ctx);
|
|
1877
|
+
dirPrepReader = reader;
|
|
1878
|
+
ctx.effect(() => () => {
|
|
1879
|
+
if (dirPrepReader === reader) dirPrepReader = void 0;
|
|
1880
|
+
}, "dir-prep-organize: remote reader");
|
|
1775
1881
|
ctx.effect(() => {
|
|
1776
1882
|
const tag = document.createElement("style");
|
|
1777
1883
|
tag.id = "dir-prep-organize-css";
|
|
@@ -1801,6 +1907,7 @@ exports.parseOrganizeResponse = parseOrganizeResponse;
|
|
|
1801
1907
|
exports.persistError = persistError;
|
|
1802
1908
|
exports.resetBuiltinTemplates = resetBuiltinTemplates;
|
|
1803
1909
|
exports.rootsPersistError = rootsPersistError;
|
|
1910
|
+
exports.setDirPrepReader = setDirPrepReader;
|
|
1804
1911
|
exports.subscribeBuiltinTemplates = subscribeBuiltinTemplates;
|
|
1805
1912
|
return module.exports;
|
|
1806
1913
|
},
|
package/cordis.patch.yml
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
# dir-prep-organize(整理 + 模板;内容源为内置角色库)。
|
|
2
2
|
# 功能一「整理」:输入框右上角分段按钮。主键点击 → 按当前目录结构 + 当前 session
|
|
3
3
|
# 模型整理优化草稿(成功直接替换,失败保持原值);▾ → 「以 XX 视角整理」(角色菜单,
|
|
4
|
-
# 角色上下文 = 模板正文提炼,随 organize
|
|
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)+ 两步确认恢复默认 + 角色导入(
|
|
12
|
-
#
|
|
11
|
+
# group/description/text)+ 两步确认恢复默认 + 角色导入(importTemplates:留空 = 一键
|
|
12
|
+
# 导入内置 agents/ 全部;填路径 = 导入本地 .md 或目录)。client 直读本条目的配置表单
|
|
13
13
|
# (ctx.configForms.get(条目 id);0.1.7 已移除 settingsScope)。
|
|
14
14
|
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
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"
|