@jayyuen66/dsh-dir-prep-organize 0.1.12 → 0.1.14
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 +26 -0
- package/README.md +14 -5
- package/README.zh-CN.md +14 -5
- package/client.js +40 -2172
- package/cordis.patch.yml +4 -0
- package/docs/DETAIL.md +6 -0
- package/docs/DETAIL.zh.md +6 -0
- package/host.js +15 -7
- package/package.json +20 -16
package/client.js
CHANGED
|
@@ -5,2178 +5,46 @@ window.__ModuleLoader__.load({
|
|
|
5
5
|
'use strict';
|
|
6
6
|
const module = { exports: {} };
|
|
7
7
|
let exports = module.exports;
|
|
8
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
9
|
-
|
|
10
|
-
let zod = require("zod");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
else if (ids.has(id)) {
|
|
49
|
-
id = `${id}-i`;
|
|
50
|
-
while (ids.has(id)) id = `${id}i`;
|
|
51
|
-
}
|
|
52
|
-
ids.add(id);
|
|
53
|
-
out.push({
|
|
54
|
-
...rest,
|
|
55
|
-
id
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
return out;
|
|
59
|
-
}
|
|
60
|
-
/** 字段 → trim 后的 string;非字符串一律 ""。 */
|
|
61
|
-
function trimField(value) {
|
|
62
|
-
return typeof value === "string" ? value.trim() : "";
|
|
63
|
-
}
|
|
64
|
-
/** 单条归一化:剔除坏条目/空 name|text;id 缺失或撞名 → 确定性补 tpl-<index>,
|
|
65
|
-
* 返回 undefined 表示该条应被剔除。 */
|
|
66
|
-
function normalizeEntry(item, index, seen) {
|
|
67
|
-
let result;
|
|
68
|
-
if (e$1(item)) {
|
|
69
|
-
const { id, name, description, text, group, emoji } = item;
|
|
70
|
-
const nextName = trimField(name);
|
|
71
|
-
const nextText = trimField(text);
|
|
72
|
-
if (nextName !== "" && nextText !== "") {
|
|
73
|
-
const nextId = uniqueEntryId(trimField(id), index, seen);
|
|
74
|
-
seen.add(nextId);
|
|
75
|
-
result = {
|
|
76
|
-
id: nextId,
|
|
77
|
-
name: nextName,
|
|
78
|
-
description: trimField(description),
|
|
79
|
-
text: nextText,
|
|
80
|
-
group: trimField(group),
|
|
81
|
-
emoji: truncateCodePoints(trimField(emoji), EMOJI_MAX_LENGTH)
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return result;
|
|
86
|
-
}
|
|
87
|
-
/** 任意来源(settings 快照 / 设置卡未保存的 `draft`)→ 合法模板列表(纯函数,测试锁死)。
|
|
88
|
-
*
|
|
89
|
-
* - 非数组输入 → [](调用方自行决定是否回落 DEFAULT_TEMPLATES);
|
|
90
|
-
* - 剔除非对象条目与 name/text trim 后为空的条目;
|
|
91
|
-
* - name/text/description/group 一律 trim;emoji trim 后按码点截断至 12 个字符;
|
|
92
|
-
* - id 缺失与已收集 id 撞名都由 uniqueEntryId 按序号补成唯一(同输入同输出,可测试);
|
|
93
|
-
* - 绝不修改输入(深比较测试锁死)。 */
|
|
94
|
-
function sanitizeTemplateList(raw) {
|
|
95
|
-
if (!Array.isArray(raw)) return [];
|
|
96
|
-
const seen = /* @__PURE__ */ new Set();
|
|
97
|
-
const out = [];
|
|
98
|
-
for (const [index, item] of raw.entries()) {
|
|
99
|
-
const entry = normalizeEntry(item, index, seen);
|
|
100
|
-
if (entry !== void 0) out.push(entry);
|
|
101
|
-
}
|
|
102
|
-
return out;
|
|
103
|
-
}
|
|
104
|
-
const BACKSLASH = String.fromCodePoint(92);
|
|
105
|
-
const WIN_DRIVE_LETTER = /^[A-Za-z]:$/u;
|
|
106
|
-
const TRAILING_SEPARATORS = /[/\\]+$/u;
|
|
107
|
-
/** 绝对路径的形状(比 host 侧 path.isAbsolute 宽松一档的同一套判断:POSIX 根、win32 盘符、UNC)。
|
|
108
|
-
* client 半跑在浏览器里,没有 node:path 可用,故按形状判。 */
|
|
109
|
-
function isAbsolutePath(value) {
|
|
110
|
-
const winDrive = WIN_DRIVE_LETTER.test(value.slice(0, 2)) && (value[2] === "/" || value[2] === BACKSLASH);
|
|
111
|
-
return value.startsWith("/") || winDrive || value.startsWith(BACKSLASH + BACKSLASH);
|
|
112
|
-
}
|
|
113
|
-
/** 剥末尾分隔符;剥完为空(POSIX 根 `/`)或只剩盘符(`C:`)时留原值——后者在 win32
|
|
114
|
-
* 是「该盘当前目录」的相对形式,不是根。 */
|
|
115
|
-
function normalizeRootShape(value) {
|
|
116
|
-
const stripped = value.replace(TRAILING_SEPARATORS, "");
|
|
117
|
-
if (stripped.length === 0 || WIN_DRIVE_LETTER.test(stripped)) return value;
|
|
118
|
-
return stripped;
|
|
119
|
-
}
|
|
120
|
-
/** 任意来源(settings 快照 / 设置卡未保存的 `rootsDraft`)→ 合法的「导入允许目录」列表(纯函数)。
|
|
121
|
-
* host 的导入策略是「会话 cwd + 内置角色库 + importAllowRoots」,绝对路径默认拒绝,
|
|
122
|
-
* 这里登记的每一项都是**放一个读盘口子**,故:
|
|
123
|
-
* - 非数组 → [](未设置 = 一条都不登记,不是"全放行");
|
|
124
|
-
* - 非字符串 / trim 后为空 → 丢弃(空串在 host 侧 path.resolve 会落到进程 cwd,
|
|
125
|
-
* 绝不能让它变成一个隐式允许根);
|
|
126
|
-
* - **非绝对路径 → 丢弃**:契约是「额外允许的绝对目录」,相对项会被 host 按它自己的
|
|
127
|
-
* 进程 cwd 解析,等于登记了一条用户没写过、界面上也看不出指向哪里的允许根;`~`
|
|
128
|
-
* 靠 shell 展开,host 的 path.resolve 不展开它,同归这一档;
|
|
129
|
-
* - 末尾分隔符归一后去重(`/a` 与 `/a/` 是同一棵目录树,不该在界面上摆两行);
|
|
130
|
-
* - 条数与单条长度都不设上限:静默丢一条就是「看着成功、内容没进去」;条目多撑长的
|
|
131
|
-
* 越界的回执由 host 侧的列举上限限制住。 */
|
|
132
|
-
function sanitizeAllowRoots(raw) {
|
|
133
|
-
const out = [];
|
|
134
|
-
if (Array.isArray(raw)) for (const item of raw) {
|
|
135
|
-
const root = typeof item === "string" ? item.trim() : "";
|
|
136
|
-
const shaped = normalizeRootShape(root);
|
|
137
|
-
if (root.length > 0 && isAbsolutePath(shaped) && !out.includes(shaped)) out.push(shaped);
|
|
138
|
-
}
|
|
139
|
-
return out;
|
|
140
|
-
}
|
|
141
|
-
// src/client-timeouts.ts
|
|
142
|
-
/**
|
|
143
|
-
* `setTimeout` 延时上界(Node/V8 的 2^31-1 ms)。
|
|
144
|
-
*
|
|
145
|
-
* 超了它 V8 只往 stderr 打一条 TimeoutOverflowWarning,然后把延时**静默夹成 1 ms**。
|
|
146
|
-
*/
|
|
147
|
-
const MAX_TIMER_MS = 2147483647;
|
|
148
|
-
/** 配置表单里读不到 `organizeTimeoutMs` 时的回落值(与 host 侧 ORGANIZE_TIMEOUT_MS 同值)。 */
|
|
149
|
-
const ORGANIZE_TIMEOUT_FALLBACK_MS = 12e4;
|
|
150
|
-
/** 客户端比 host 多等的余量:host 先超时,客户端留一点时间把它的回执读回来。 */
|
|
151
|
-
const ORGANIZE_TIMEOUT_SLACK_MS = 5e3;
|
|
152
|
-
/** 配置投影值是否可当作毫秒数用(有限且 > 0;两处取表共用同一判据)。 */
|
|
153
|
-
function isUsableTimeoutMs(value) {
|
|
154
|
-
return typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* `organizeTimeoutMs` 的前端取表。
|
|
158
|
-
*
|
|
159
|
-
* 上界与 host 同为 `[1, MAX_TIMER_MS]`:host 自己夹了上界正是为了躲开上面那个静默的夹断,
|
|
160
|
-
* 而这里是**唯一**发起润色读取方法调用的地方,它要是没夹,host 夹得再对也没用。
|
|
161
|
-
*
|
|
162
|
-
* @param value - 配置表单投影值
|
|
163
|
-
* @returns `[1, MAX_TIMER_MS]` 区间内的整数;不合法时 undefined(回落默认)
|
|
164
|
-
*/
|
|
165
|
-
function rawOrganizeTimeoutMsOf(value) {
|
|
166
|
-
const raw = value["organizeTimeoutMs"];
|
|
167
|
-
return isUsableTimeoutMs(raw) ? Math.min(Math.max(Math.trunc(raw), 1), MAX_TIMER_MS) : void 0;
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* 润色请求的客户端超时:host 的润色时限 + 余量,整条结果同样夹进 `[1, MAX_TIMER_MS]`。
|
|
171
|
-
*
|
|
172
|
-
* **加法之后还要再夹一次**,因为 `MAX_TIMER_MS + ORGANIZE_TIMEOUT_SLACK_MS` 自己就越界了
|
|
173
|
-
* (实测 V8 把 2147488647 的延时夹成 1ms,点击润色立刻回「请求超时」)。
|
|
174
|
-
*
|
|
175
|
-
* @param raw - 配置表单投影里的润色时限(未夹)
|
|
176
|
-
* @returns 可安全交给 setTimeout 的毫秒数
|
|
177
|
-
*/
|
|
178
|
-
function organizeFetchTimeoutMs(raw) {
|
|
179
|
-
const base = isUsableTimeoutMs(raw) ? raw : ORGANIZE_TIMEOUT_FALLBACK_MS;
|
|
180
|
-
return Math.trunc(Math.min(Math.max(Math.min(base, 2147478647) + ORGANIZE_TIMEOUT_SLACK_MS, 1), MAX_TIMER_MS));
|
|
181
|
-
}
|
|
182
|
-
// src/client-styles.ts
|
|
183
|
-
const CARD_STYLES = [
|
|
184
|
-
".dpi-btn{appearance:none;border:1px solid var(--dsw-alias-border-l2,currentColor);background:var(--dsw-alias-bg-layer-1,transparent);color:var(--dsw-alias-label-primary,inherit);font:inherit;font-size:12px;line-height:1;border-radius:8px;padding:6px 10px;cursor:pointer;display:inline-flex;align-items:center;gap:6px;transition:background .16s,border-color .16s,color .16s}",
|
|
185
|
-
".dpi-btn:hover:not(:disabled){border-color:var(--dsw-alias-label-dimmed,currentColor);background:var(--dsw-alias-bg-layer-2,transparent)}",
|
|
186
|
-
".dpi-btn:disabled{opacity:.55;cursor:not-allowed}",
|
|
187
|
-
".dpi-btn:disabled[data-state=\"loading\"]{cursor:progress}",
|
|
188
|
-
".dpi-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,currentColor);outline-offset:1px}",
|
|
189
|
-
".dpi-btn svg{width:14px;height:14px;flex:none}",
|
|
190
|
-
".dpi-btn-err{border-color:var(--dsw-alias-state-error-primary,currentColor);color:var(--dsw-alias-state-error-secondary,currentColor)}",
|
|
191
|
-
".dpi-btn-err:hover:not(:disabled){border-color:var(--dsw-alias-state-error-primary,currentColor)}",
|
|
192
|
-
".dpi-spin{animation:dpi-rotate .8s linear infinite}",
|
|
193
|
-
"@keyframes dpi-rotate{to{transform:rotate(360deg)}}",
|
|
194
|
-
"@media (prefers-reduced-motion:reduce){.dpi-spin{animation:none}.dpi-btn{transition:none}}",
|
|
195
|
-
".dpi-wrap{position:relative;display:inline-flex;isolation:isolate}",
|
|
196
|
-
".dpi-menu{position:absolute;bottom:calc(100% + 6px);right:0;z-index:50;min-width:224px;max-height:340px;overflow-y:auto;background:var(--dsw-menu-surface-fill,transparent);backdrop-filter:var(--dsw-menu-backdrop-filter,none);border:0;border-radius:10px;padding:4px;display:flex;flex-direction:column;gap:2px;box-shadow:var(--dsw-elevation-panel,none)}",
|
|
197
|
-
".dpi-item{appearance:none;border:none;background:transparent;color:var(--dsw-alias-label-primary,inherit);font:inherit;font-size:12px;line-height:1.4;text-align:left;border-radius:6px;padding:8px 10px;cursor:pointer;white-space:nowrap}",
|
|
198
|
-
".dpi-item:hover,.dpi-item:focus-visible{background:var(--dsw-alias-bg-layer-2,transparent)}",
|
|
199
|
-
".dpi-item-empty{color:var(--dsw-alias-label-tertiary,inherit);cursor:default;font-size:12px;padding:8px 10px;white-space:nowrap}",
|
|
200
|
-
".dpi-split{display:inline-flex;align-items:stretch}",
|
|
201
|
-
".dpi-split .dpi-main{border-top-right-radius:0;border-bottom-right-radius:0;padding-right:8px}",
|
|
202
|
-
".dpi-split .dpi-caret{border-left:none;border-top-left-radius:0;border-bottom-left-radius:0;padding-left:4px;padding-right:6px}",
|
|
203
|
-
".dpi-split .dpi-caret svg{width:10px;height:10px}",
|
|
204
|
-
".dpi-group{padding:2px 0}",
|
|
205
|
-
".dpi-grouph{font-size:11px;font-weight:600;color:var(--dsw-alias-label-tertiary,inherit);padding:6px 10px 2px;letter-spacing:.02em}",
|
|
206
|
-
".dpic-row{padding:10px 0;border-bottom:1px dashed var(--dsw-alias-border-l2,currentColor)}",
|
|
207
|
-
".dpic-name{flex:1;min-width:0}",
|
|
208
|
-
".dpic-rowhead .dpic-name{width:auto}",
|
|
209
|
-
".dpic-rowhead .dpic-emoji{width:44px;flex:none;text-align:center}",
|
|
210
|
-
".dpic-rowhead .dpic-group{width:84px;flex:none}",
|
|
211
|
-
".dpic-desc{width:100%;margin-top:6px}",
|
|
212
|
-
".dpic-text{width:100%;margin-top:6px}",
|
|
213
|
-
".dpic-importpath{flex:1;min-width:0}",
|
|
214
|
-
".dpic-rowhead .dpic-importpath{width:auto}",
|
|
215
|
-
".dpic-del{flex:none}",
|
|
216
|
-
".dpic-toolbar{display:flex;gap:8px;flex-wrap:wrap;padding:8px 0}",
|
|
217
|
-
".dpic-rowhead{display:flex;gap:8px;align-items:center}",
|
|
218
|
-
".dpic-idx{font-size:12px;color:var(--dsw-alias-label-tertiary,inherit);flex:none;min-width:26px}",
|
|
219
|
-
".dpic-importrow{padding:12px 0;border-bottom:1px dashed var(--dsw-alias-border-l2,currentColor)}",
|
|
220
|
-
".dpic-hint{font-size:12px;color:var(--dsw-alias-label-tertiary,inherit);line-height:1.5;padding-top:6px}",
|
|
221
|
-
".dpic-err{color:var(--dsw-alias-state-error-primary,currentColor)}"
|
|
222
|
-
].join("\n");
|
|
223
|
-
// src/ui-messages.ts
|
|
224
|
-
const UI_MESSAGES = {
|
|
225
|
-
zh: {
|
|
226
|
-
rolesSection: "角色库",
|
|
227
|
-
rolesHint: "输入框「模板」下拉与「润色」▾ 角色菜单共用这一份列表,空表即回落到内置精选角色集(生成自插件 agents/ 角色库)。留空点「导入角色」可一键导入内置全部;填路径则按「会话 cwd + 内置角色库 + 下方导入允许目录」放行。编辑后点「保存」生效,重启不丢。",
|
|
228
|
-
statusReadOnly: "设置源不可写:编辑已禁用;下拉仍按当前列表生效。",
|
|
229
|
-
statusNotReady: "设置源未就绪:显示当前生效列表,就绪后可编辑。",
|
|
230
|
-
addTemplate: "+ 新增模板",
|
|
231
|
-
saveTitleDirty: "写入模板列表与导入允许目录(模板生效于新拉开的菜单)",
|
|
232
|
-
saveTitleClean: "无未保存修改",
|
|
233
|
-
saving: "保存中…",
|
|
234
|
-
save: "保存",
|
|
235
|
-
revert: "撤销",
|
|
236
|
-
resetTitle: "丢弃模板列表的全部自定义,回到内置默认(不影响已登记的导入允许目录;两步确认,点击即生效)",
|
|
237
|
-
resetConfirm: "确认恢复默认?再点一次({seconds} 秒内)",
|
|
238
|
-
resetDefault: "恢复默认",
|
|
239
|
-
footHint: "说明:编辑/新增/删除先在本地暂存,点「保存」一次写入(模板与导入允许目录同理);清空名称或正文的条目保存时会被剔除(删除请用行内「删除」);恢复默认只回滚模板列表。",
|
|
240
|
-
saveFailed: "保存失败:",
|
|
241
|
-
newTemplateName: "新模板 {index}",
|
|
242
|
-
persistUnconfirmed: "{action}结果不可确认:设置源未就绪(宿主未回读成功)",
|
|
243
|
-
persistRejected: "{action}未生效:宿主拒绝了本次写入(当前 revision {revision})",
|
|
244
|
-
rowAriaEmoji: "模板 {index} 视觉标记",
|
|
245
|
-
rowEmojiTitle: "可选视觉标记(emoji 或短文本),下拉菜单显示在名称前",
|
|
246
|
-
rowPlaceholderName: "菜单显示名",
|
|
247
|
-
rowAriaName: "模板 {index} 名称",
|
|
248
|
-
rowPlaceholderGroup: "分组",
|
|
249
|
-
rowAriaGroup: "模板 {index} 分组",
|
|
250
|
-
rowGroupTitle: "下拉按此分组展示;留空归入「通用」",
|
|
251
|
-
rowDeleteTitle: "删除此模板",
|
|
252
|
-
rowDelete: "删除",
|
|
253
|
-
rowPlaceholderDescription: "一句话介绍(下拉悬停时显示;如:威胁建模与 OWASP 代码审计)",
|
|
254
|
-
rowAriaDescription: "模板 {index} 一句话介绍",
|
|
255
|
-
rowPlaceholderText: "模板正文(点选后插入输入框,随你的消息一起发给模型)",
|
|
256
|
-
rowAriaText: "模板 {index} 正文",
|
|
257
|
-
importFailedUnknown: "导入失败(未知错误)",
|
|
258
|
-
importEmpty: "目录下没有符合条件的角色 .md(需含 name 的 frontmatter)",
|
|
259
|
-
importAllDone: "已从内置角色库导入全部 {count} 条{skips},编辑后点「保存」生效",
|
|
260
|
-
importFromDone: "已从 {path} 导入 {count} 条{skips},编辑后点「保存」生效",
|
|
261
|
-
importTruncated: "(回执标记本次导入有内容被上限截断)",
|
|
262
|
-
importPlaceholder: "留空 = 导入内置全部角色;或填 .md / 目录路径(须在允许根内)",
|
|
263
|
-
importAriaPath: "角色导入路径",
|
|
264
|
-
importBtnTitle: "留空 = 一键导入内置全部角色;填路径 = 导入该 .md 或目录下的角色(路径须在允许根内)",
|
|
265
|
-
importing: "导入中…",
|
|
266
|
-
importRoles: "导入角色",
|
|
267
|
-
importErrorPrefix: "导入失败:",
|
|
268
|
-
importHint: "导入说明:留空导入内置角色库全部(agents/);填路径时只放行「会话 cwd」「内置角色库 agents/」与下方「导入允许目录」之内的路径——绝对路径默认拒绝,越界会直接报「导入路径越界」并回显解析后的路径。本卡没有会话上下文,故只能填内置库或已登记目录里的路径。目录扫描顶层 + 一层子目录 .md(跳过隐藏项),文件须含 name 的 frontmatter,正文将提炼为模板正文。",
|
|
269
|
-
skipDeeper: "{count} 个更深层 .md 未扫描(导入只扫两层)",
|
|
270
|
-
skipTooLarge: "{count} 个文件超字节上限被跳过",
|
|
271
|
-
skipUnreadable: "{count} 个文件读取失败",
|
|
272
|
-
skipUnnamed: "{count} 个非角色文件(frontmatter 无 name)",
|
|
273
|
-
skipEscaped: "{count} 个文件的真实目标在允许根之外(符号链接),已按安全策略排除",
|
|
274
|
-
skipSummary: "({list})",
|
|
275
|
-
skipSeparator: ",",
|
|
276
|
-
rootsHeading: "导入允许目录(importAllowRoots)",
|
|
277
|
-
rootsAriaRow: "导入允许目录 {index}",
|
|
278
|
-
rootsRowTitle: "该目录(含其子目录)内的角色 .md 可经「导入角色」读取",
|
|
279
|
-
rootsRemoveTitle: "移除此允许目录",
|
|
280
|
-
rootsRemove: "移除",
|
|
281
|
-
rootsAddPlaceholder: "新增一个允许导入的目录绝对路径",
|
|
282
|
-
rootsAddAria: "新增导入允许目录",
|
|
283
|
-
rootsAddTitle: "加入待保存的允许目录列表",
|
|
284
|
-
rootsAdd: "登记目录",
|
|
285
|
-
rootsHint: "绝对路径默认拒绝:只有「当前会话 cwd」「插件内置角色库 agents/」与本列表登记的目录之内可导入。设置页没有会话上下文,卡上填的路径必须落在内置库或本列表内。改完点底部「保存」生效。",
|
|
286
|
-
dockOrganizeEntry: "润色",
|
|
287
|
-
dockTemplatesEntry: "模板",
|
|
288
|
-
organizeIdle: "润色",
|
|
289
|
-
organizeLoading: "润色中",
|
|
290
|
-
organizeFailedShort: "失败",
|
|
291
|
-
organizeIdleTitle: "结合当前目录润色输入框内容(主键直接润色;▾ 可选角色风格)",
|
|
292
|
-
organizeFailedTitle: "润色失败:{message}",
|
|
293
|
-
organizeErrContextFailed: "目录上下文读取失败:{message}",
|
|
294
|
-
organizeErrModelFailed: "读取模型失败:{message}",
|
|
295
|
-
organizeErrEmpty: "输入框为空,无内容可润色",
|
|
296
|
-
organizeErrTimeout: "润色请求超时:宿主没有在时限内回报结果",
|
|
297
|
-
organizeErrUnknownReason: "未知错误",
|
|
298
|
-
organizeErrUnknown: "润色失败(未知错误)",
|
|
299
|
-
organizeCaretAria: "选择润色的角色风格",
|
|
300
|
-
organizeCaretTitle: "按某个角色的风格润色(角色来自下方模板库)",
|
|
301
|
-
organizeMainAria: "润色输入框内容",
|
|
302
|
-
organizeDirectItem: "直接润色(默认,不带角色)",
|
|
303
|
-
organizeNoTemplates: "无模板可选作角色风格",
|
|
304
|
-
organizeRoleItem: "以「{name}」的风格润色",
|
|
305
|
-
organizeWriteBackUnavailable: "输入框动作不可用,无法写回",
|
|
306
|
-
organizeWriteBackStale: "输入框内容已变化,润色结果未写回",
|
|
307
|
-
organizeBusyTitle: "输入框正在提交,暂不能润色",
|
|
308
|
-
templatesIdleTitle: "选择一条模板插入光标处(按分组展示)",
|
|
309
|
-
templatesBrokenTitle: "输入框动作不可用,无法插入",
|
|
310
|
-
templatesBusyTitle: "输入框正在提交,暂不能插入模板",
|
|
311
|
-
templatesGroupCommon: "通用",
|
|
312
|
-
templatesAria: "插入模板",
|
|
313
|
-
templatesEmptyHint: "无模板:在设置页「角色库」中添加或恢复默认",
|
|
314
|
-
builtinLoading: "正在载入内置角色模板…",
|
|
315
|
-
builtinFailed: "内置模板加载失败:{message}",
|
|
316
|
-
builtinRetry: "重试"
|
|
317
|
-
},
|
|
318
|
-
en: {
|
|
319
|
-
rolesSection: "Role library",
|
|
320
|
-
rolesHint: "The input-box \"Template\" dropdown and the \"Polish\" ▾ role menu share this one list; an empty list falls back to the built-in curated role set (generated from this plugin's agents/ role library). Leave the path empty and press \"Import roles\" to import the whole built-in library; an explicit path is allowed within \"session cwd + built-in role library + the import allowed directories below\". Press \"Save\" after editing — it survives restarts.",
|
|
321
|
-
statusReadOnly: "Settings source is read-only: editing is disabled; the dropdown still uses the current list.",
|
|
322
|
-
statusNotReady: "Settings source is not ready yet: showing the list currently in effect, editing unlocks once it is ready.",
|
|
323
|
-
addTemplate: "+ Add template",
|
|
324
|
-
saveTitleDirty: "Write the template list and the import allowed directories (templates take effect in newly opened menus)",
|
|
325
|
-
saveTitleClean: "No unsaved changes",
|
|
326
|
-
saving: "Saving…",
|
|
327
|
-
save: "Save",
|
|
328
|
-
revert: "Revert",
|
|
329
|
-
resetTitle: "Discard every customization of the template list and go back to the built-in defaults (registered import directories are untouched; two-step confirm, takes effect on the next click)",
|
|
330
|
-
resetConfirm: "Restore defaults? Click once more (within {seconds}s)",
|
|
331
|
-
resetDefault: "Restore defaults",
|
|
332
|
-
footHint: "Note: edits, additions and deletions are staged locally first and written in one go when you press \"Save\" (same for templates and import directories); entries whose name or body is empty are dropped on save (use the inline \"Delete\" instead); \"Restore defaults\" only rolls back the template list.",
|
|
333
|
-
saveFailed: "Save failed: ",
|
|
334
|
-
newTemplateName: "New template {index}",
|
|
335
|
-
persistUnconfirmed: "{action} cannot be confirmed: the settings source is not ready (host read-back failed)",
|
|
336
|
-
persistRejected: "{action} did not take effect: the host rejected this write (current revision {revision})",
|
|
337
|
-
rowAriaEmoji: "Visual mark of template {index}",
|
|
338
|
-
rowEmojiTitle: "Optional visual mark (emoji or short text), shown before the name in the dropdown",
|
|
339
|
-
rowPlaceholderName: "Menu display name",
|
|
340
|
-
rowAriaName: "Name of template {index}",
|
|
341
|
-
rowPlaceholderGroup: "Group",
|
|
342
|
-
rowAriaGroup: "Group of template {index}",
|
|
343
|
-
rowGroupTitle: "The dropdown groups entries by this value; leave empty to fall into \"General\"",
|
|
344
|
-
rowDeleteTitle: "Delete this template",
|
|
345
|
-
rowDelete: "Delete",
|
|
346
|
-
rowPlaceholderDescription: "One-line intro (shown on dropdown hover; e.g. threat modelling and OWASP code auditing)",
|
|
347
|
-
rowAriaDescription: "One-line intro of template {index}",
|
|
348
|
-
rowPlaceholderText: "Template body (inserted into the input box and sent to the model with your message)",
|
|
349
|
-
rowAriaText: "Body of template {index}",
|
|
350
|
-
importFailedUnknown: "Import failed (unknown error)",
|
|
351
|
-
importEmpty: "No qualifying role .md in that directory (frontmatter must contain name)",
|
|
352
|
-
importAllDone: "Imported all {count} entries from the built-in role library{skips}; press \"Save\" after editing",
|
|
353
|
-
importFromDone: "Imported {count} entries from {path}{skips}; press \"Save\" after editing",
|
|
354
|
-
importTruncated: " (the reply flagged some content as truncated by a limit)",
|
|
355
|
-
importPlaceholder: "Empty = import every built-in role; or a .md / directory path (must be inside an allowed root)",
|
|
356
|
-
importAriaPath: "Role import path",
|
|
357
|
-
importBtnTitle: "Empty imports the whole built-in role library in one click; a path imports that .md or the roles in that directory (must be inside an allowed root)",
|
|
358
|
-
importing: "Importing…",
|
|
359
|
-
importRoles: "Import roles",
|
|
360
|
-
importErrorPrefix: "Import failed: ",
|
|
361
|
-
importHint: "Import notes: an empty path imports the whole built-in role library (agents/); an explicit path is only allowed inside \"session cwd\", \"built-in role library agents/\" and the \"import allowed directories\" below — absolute paths are refused by default, and anything out of bounds reports \"import path out of bounds\" with the resolved path echoed back. This card has no session context, so explicit paths must live in the built-in library or a registered directory. Directory scans cover the top level plus one level of sub-directory .md files (hidden entries skipped), each file needs a frontmatter name, and its body is condensed into the template text.",
|
|
362
|
-
skipDeeper: "{count} deeper .md files were not scanned (imports cover two levels)",
|
|
363
|
-
skipTooLarge: "{count} files were skipped for exceeding the byte limit",
|
|
364
|
-
skipUnreadable: "{count} files could not be read",
|
|
365
|
-
skipUnnamed: "{count} non-role files (no name in frontmatter)",
|
|
366
|
-
skipEscaped: "{count} files whose real target lies outside the allowed roots (symlinks) were excluded by policy",
|
|
367
|
-
skipSummary: " ({list})",
|
|
368
|
-
skipSeparator: ", ",
|
|
369
|
-
rootsHeading: "Import allowed directories (importAllowRoots)",
|
|
370
|
-
rootsAriaRow: "Import allowed directory {index}",
|
|
371
|
-
rootsRowTitle: "Role .md files inside this directory (and its subdirectories) can be read by \"Import roles\"",
|
|
372
|
-
rootsRemoveTitle: "Remove this allowed directory",
|
|
373
|
-
rootsRemove: "Remove",
|
|
374
|
-
rootsAddPlaceholder: "Absolute path of a directory newly allowed for imports",
|
|
375
|
-
rootsAddAria: "Add an import allowed directory",
|
|
376
|
-
rootsAddTitle: "Add it to the pending allowed-directory list",
|
|
377
|
-
rootsAdd: "Register directory",
|
|
378
|
-
rootsHint: "Absolute paths are refused by default: imports only succeed inside \"the current session cwd\", \"the plugin's built-in role library agents/\" and the directories registered below. The settings page has no session context, so a path typed here must fall inside the built-in library or this list. Press \"Save\" at the bottom to apply.",
|
|
379
|
-
dockOrganizeEntry: "Polish",
|
|
380
|
-
dockTemplatesEntry: "Templates",
|
|
381
|
-
organizeIdle: "Polish",
|
|
382
|
-
organizeLoading: "Polishing",
|
|
383
|
-
organizeFailedShort: "Failed",
|
|
384
|
-
organizeIdleTitle: "Polish the input-box content against the current directory (main key polishes directly; ▾ picks a role style)",
|
|
385
|
-
organizeFailedTitle: "Polish failed: {message}",
|
|
386
|
-
organizeErrContextFailed: "Failed to read the directory context: {message}",
|
|
387
|
-
organizeErrModelFailed: "Failed to read the model: {message}",
|
|
388
|
-
organizeErrEmpty: "The input box is empty; nothing to polish",
|
|
389
|
-
organizeErrTimeout: "Polish request timed out: the host did not reply in time",
|
|
390
|
-
organizeErrUnknownReason: "unknown error",
|
|
391
|
-
organizeErrUnknown: "Polish failed (unknown error)",
|
|
392
|
-
organizeCaretAria: "Choose a role style to polish with",
|
|
393
|
-
organizeCaretTitle: "Polish in a role's style (roles come from the template library below)",
|
|
394
|
-
organizeMainAria: "Polish the input-box content",
|
|
395
|
-
organizeDirectItem: "Polish directly (default, no role)",
|
|
396
|
-
organizeNoTemplates: "No templates available as a role style",
|
|
397
|
-
organizeRoleItem: "Polish in the style of \"{name}\"",
|
|
398
|
-
organizeWriteBackUnavailable: "Input-box actions unavailable; cannot write back",
|
|
399
|
-
organizeWriteBackStale: "The input box changed; the polished text was not applied",
|
|
400
|
-
organizeBusyTitle: "The input box is submitting; cannot polish right now",
|
|
401
|
-
templatesIdleTitle: "Pick a template to insert at the caret (shown grouped)",
|
|
402
|
-
templatesBrokenTitle: "Input-box actions unavailable; cannot insert",
|
|
403
|
-
templatesBusyTitle: "The input box is submitting; cannot insert a template",
|
|
404
|
-
templatesGroupCommon: "General",
|
|
405
|
-
templatesAria: "Insert a template",
|
|
406
|
-
templatesEmptyHint: "No templates: add or restore defaults under \"Role library\" in the settings page",
|
|
407
|
-
builtinLoading: "Loading built-in role templates…",
|
|
408
|
-
builtinFailed: "Failed to load built-in templates: {message}",
|
|
409
|
-
builtinRetry: "Retry"
|
|
410
|
-
}
|
|
411
|
-
};
|
|
412
|
-
// node_modules/@jayyuen66/dsh-plugin-shared/dist/card-ui-yf56_khz.js
|
|
413
|
-
const c = `
|
|
414
|
-
.dsu-form{display:flex;flex-direction:column}
|
|
415
|
-
.dsu-section{margin-top:24px;padding-top:24px;border-top:.5px solid var(--dsw-alias-border-l1)}
|
|
416
|
-
.dsu-form>.dsu-section:first-child{margin-top:0;padding-top:0;border-top:0}
|
|
417
|
-
.dsu-sectionTitle{margin:0;font-size:15px;font-weight:600;line-height:1.4;color:var(--dsw-alias-label-primary)}
|
|
418
|
-
.dsu-sectionHint{margin:4px 0 0;font-size:12px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}
|
|
419
|
-
.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)}
|
|
420
|
-
.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)}
|
|
421
|
-
.dsu-fieldMeta{display:flex;flex-direction:column;gap:4px;min-width:0}
|
|
422
|
-
.dsu-labelRow{display:flex;align-items:center;gap:6px;min-width:0}
|
|
423
|
-
.dsu-label{font-size:13px;font-weight:500;line-height:1.5;color:var(--dsw-alias-label-primary)}
|
|
424
|
-
.dsu-labelMono{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:12px}
|
|
425
|
-
.dsu-hint{margin:0;font-size:12px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}
|
|
426
|
-
.dsu-control{min-width:0;display:flex;align-items:center;gap:8px}
|
|
427
|
-
.dsu-fieldWide{grid-template-columns:minmax(0,1fr);align-items:start}
|
|
428
|
-
.dsu-fieldWide .dsu-control{width:100%;max-width:720px;margin-top:2px}
|
|
429
|
-
.dsu-help{display:inline-flex;align-items:center;gap:6px;min-width:0}
|
|
430
|
-
.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}
|
|
431
|
-
.dsu-help:hover .dsu-helpBtn,.dsu-helpBtn:focus-visible{color:var(--dsw-alias-label-primary)}
|
|
432
|
-
.dsu-helpBtn:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:1px}
|
|
433
|
-
.dsu-tip{width:max-content;position:fixed;position-area:block-end span-inline-end;justify-self:start;margin-top:8px;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)}
|
|
434
|
-
.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}
|
|
435
|
-
.dsu-input:focus-visible{outline:none;border-color:var(--dsw-alias-state-business-primary)}
|
|
436
|
-
.dsu-input[aria-invalid="true"]{border-color:var(--dsw-alias-state-error-primary)}
|
|
437
|
-
.dsu-input:disabled{color:var(--dsw-alias-label-tertiary);cursor:not-allowed}
|
|
438
|
-
.dsu-input::placeholder{color:var(--dsw-alias-label-tertiary)}
|
|
439
|
-
.dsu-textarea{height:auto;min-height:96px;padding:8px 12px;line-height:1.6;resize:vertical}
|
|
440
|
-
.dsu-mono{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
|
|
441
|
-
.dsu-numberWrap{display:flex;flex-direction:column;gap:4px;width:100%;min-width:0}
|
|
442
|
-
.dsu-number{display:flex;align-items:center;gap:8px;min-width:0}
|
|
443
|
-
.dsu-number .dsu-input{min-width:0}
|
|
444
|
-
.dsu-unit{flex:none;font-size:12px;color:var(--dsw-alias-label-tertiary)}
|
|
445
|
-
.dsu-error{margin:0;font-size:12px;line-height:1.5;color:var(--dsw-alias-state-error-primary)}
|
|
446
|
-
.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}
|
|
447
|
-
.dsu-knob{width:16px;height:16px;border-radius:50%;background:var(--dsw-alias-label-primary);transition:transform .16s,background-color .16s}
|
|
448
|
-
.dsu-switch[aria-checked="true"]{background:var(--dsw-alias-label-primary)}
|
|
449
|
-
.dsu-switch[aria-checked="true"] .dsu-knob{transform:translateX(16px);background:var(--dsw-alias-label-primary-foreground)}
|
|
450
|
-
.dsu-switch:disabled{opacity:.4;cursor:not-allowed}
|
|
451
|
-
.dsu-switch:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:2px}
|
|
452
|
-
.dsu-selectWrap{position:relative;width:100%;min-width:0}
|
|
453
|
-
.dsu-select{display:flex;align-items:center;justify-content:space-between;gap:8px;text-align:left;cursor:pointer}
|
|
454
|
-
.dsu-select[aria-expanded="true"]{border-color:var(--dsw-alias-state-business-primary)}
|
|
455
|
-
.dsu-selectValue{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
456
|
-
.dsu-chevron{flex:none;color:var(--dsw-alias-label-tertiary);transition:transform .16s}
|
|
457
|
-
.dsu-select[aria-expanded="true"] .dsu-chevron{transform:rotate(180deg)}
|
|
458
|
-
.dsu-menu{position:fixed;position-area:block-end span-inline-end;justify-self:start;margin-top:6px;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}
|
|
459
|
-
.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}
|
|
460
|
-
.dsu-option:hover,.dsu-option[data-active="true"]{background:var(--dsw-alias-bg-layer-3)}
|
|
461
|
-
.dsu-option:disabled{color:var(--dsw-alias-label-tertiary);cursor:not-allowed}
|
|
462
|
-
.dsu-option:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:-2px}
|
|
463
|
-
.dsu-optionGroup{padding:6px 10px 2px;font-size:11px;font-weight:600;color:var(--dsw-alias-label-tertiary)}
|
|
464
|
-
.dsu-check{opacity:0;flex:none}
|
|
465
|
-
.dsu-option[aria-selected="true"] .dsu-check{opacity:1}
|
|
466
|
-
.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)}
|
|
467
|
-
.dsu-savebar[data-dirty="true"]{position:sticky;bottom:0;z-index:2;box-shadow:0 -12px 24px rgb(0 0 0 / 35%)}
|
|
468
|
-
.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}
|
|
469
|
-
.dsu-btn:hover:not(:disabled){background:var(--dsw-alias-bg-layer-2);border-color:var(--dsw-alias-border-l3)}
|
|
470
|
-
.dsu-btn:active:not(:disabled){background:var(--dsw-alias-bg-layer-1)}
|
|
471
|
-
.dsu-btn:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:1px}
|
|
472
|
-
.dsu-btn:disabled{opacity:.4;cursor:not-allowed}
|
|
473
|
-
.dsu-btnPrimary{background:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-layer-3)}
|
|
474
|
-
.dsu-btnPrimary:hover:not(:disabled){background:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-primary);filter:brightness(.9)}
|
|
475
|
-
.dsu-btnPrimary:active:not(:disabled){background:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-primary);filter:brightness(.84)}
|
|
476
|
-
.dsu-btnDanger{color:var(--dsw-alias-state-error-primary)}
|
|
477
|
-
.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)}
|
|
478
|
-
.dsu-status{margin-left:auto;font-size:12px;color:var(--dsw-alias-label-tertiary)}
|
|
479
|
-
.dsu-statusError{color:var(--dsw-alias-state-error-primary)}
|
|
480
|
-
.dsu-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(200px,100%),1fr));gap:0 24px}
|
|
481
|
-
.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)}
|
|
482
|
-
.dsu-grid>.dsu-field .dsu-control{width:100%}
|
|
483
|
-
@media (max-width:640px){
|
|
484
|
-
.dsu-field{grid-template-columns:minmax(0,1fr);align-items:start}
|
|
485
|
-
.dsu-control{width:100%;max-width:720px}
|
|
486
|
-
.dsu-section{margin-top:20px;padding-top:20px}
|
|
487
|
-
}
|
|
488
|
-
@media (prefers-reduced-motion:reduce){
|
|
489
|
-
.dsu-switch,.dsu-knob,.dsu-chevron,.dsu-btn{transition:none}
|
|
490
|
-
}
|
|
491
|
-
`;
|
|
492
|
-
function u(t) {
|
|
493
|
-
return (0, react.createElement)(`div`, { className: `dsu-form` }, t.children);
|
|
494
|
-
}
|
|
495
|
-
function d(t) {
|
|
496
|
-
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);
|
|
497
|
-
}
|
|
498
|
-
function w(t) {
|
|
499
|
-
let n = !t.writable || t.busy || !t.dirty, r;
|
|
500
|
-
return r = t.error === null ? t.writable ? t.dirty ? t.dirtyLabel : t.cleanLabel : t.readOnlyLabel : t.error, (0, react.createElement)(`div`, {
|
|
501
|
-
className: `dsu-savebar`,
|
|
502
|
-
"data-dirty": t.dirty
|
|
503
|
-
}, (0, react.createElement)(`button`, {
|
|
504
|
-
type: `button`,
|
|
505
|
-
className: `dsu-btn dsu-btnPrimary`,
|
|
506
|
-
"data-field": `save`,
|
|
507
|
-
disabled: n,
|
|
508
|
-
onClick: t.onSave
|
|
509
|
-
}, t.busy ? t.savingLabel : t.saveLabel), (0, react.createElement)(`button`, {
|
|
510
|
-
type: `button`,
|
|
511
|
-
className: `dsu-btn`,
|
|
512
|
-
"data-field": `discard`,
|
|
513
|
-
disabled: n,
|
|
514
|
-
onClick: t.onDiscard
|
|
515
|
-
}, t.revertLabel), (0, react.createElement)(`span`, {
|
|
516
|
-
role: `status`,
|
|
517
|
-
className: t.error === null ? `dsu-status` : `dsu-status dsu-statusError`
|
|
518
|
-
}, r));
|
|
519
|
-
}
|
|
520
|
-
// node_modules/@jayyuen66/dsh-plugin-shared/dist/errors.js
|
|
521
|
-
function t(e) {
|
|
522
|
-
let t = Object.getOwnPropertyDescriptor(e, `message`);
|
|
523
|
-
return t !== void 0 && `value` in t && typeof t.value == `string` ? t.value : void 0;
|
|
524
|
-
}
|
|
525
|
-
function n(e, r) {
|
|
526
|
-
if (r.has(e)) return `<circular cause>`;
|
|
527
|
-
r.add(e);
|
|
528
|
-
try {
|
|
529
|
-
if (!(e instanceof Error)) {
|
|
530
|
-
if (typeof e == `object` && e) {
|
|
531
|
-
let n = t(e);
|
|
532
|
-
if (n !== void 0 && n !== ``) return n;
|
|
533
|
-
}
|
|
534
|
-
return String(e);
|
|
535
|
-
}
|
|
536
|
-
let i = e.message === `` ? e.name : e.message, a = typeof globalThis.AggregateError == `function` && 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);
|
|
537
|
-
return `${i}${a}${o === `` || o === i ? `` : `: ${o}`}`;
|
|
538
|
-
} catch {
|
|
539
|
-
return `<unrenderable value>`;
|
|
540
|
-
} finally {
|
|
541
|
-
r.delete(e);
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
function r(e) {
|
|
545
|
-
return n(e, /* @__PURE__ */ new Set());
|
|
546
|
-
}
|
|
547
|
-
// src/input-writeback.ts
|
|
548
|
-
/**
|
|
549
|
-
* 输入框异步写回的凭据与判定。
|
|
550
|
-
*
|
|
551
|
-
* 润色结果是整稿替换:发起时记下会话、`draftRev` 与输入动作对象,返回时用**最新一帧**
|
|
552
|
-
* 核对。任一项在途中变了(用户继续编辑、宿主进入提交期、会话被切换、组件重挂成
|
|
553
|
-
* 另一份 facade),结果都不许落地——宁可报「未写回」,也不能覆盖用户后来的输入。
|
|
554
|
-
* 模板走插入语义(captureInsertion + insertText),由宿主按发起的选区做版本校验。
|
|
555
|
-
*/
|
|
556
|
-
/** 宿主是否给了整稿替换接口(润色结果最后落到 setDraft)。 */
|
|
557
|
-
function hasDraftFace(actions) {
|
|
558
|
-
return actions !== void 0 && typeof actions.setDraft === "function";
|
|
559
|
-
}
|
|
560
|
-
/** 宿主是否给了版本校验的插入接口(模板走这一对,不整稿覆盖)。 */
|
|
561
|
-
function hasInsertFace(actions) {
|
|
562
|
-
return actions !== void 0 && typeof actions.captureInsertion === "function" && typeof actions.insertText === "function";
|
|
563
|
-
}
|
|
564
|
-
/** 提交期(`phase !== "plain"`)也算失效:发送成功后编辑器会被清空,失败时原稿要留着,
|
|
565
|
-
* 两种情况下在途的润色结果都不该再经 `setDraft` 写回输入框。 */
|
|
566
|
-
function useWriteBack(input, messages) {
|
|
567
|
-
const latest = (0, react.useRef)(input);
|
|
568
|
-
const active = (0, react.useRef)(void 0);
|
|
569
|
-
(0, react.useEffect)(() => {
|
|
570
|
-
latest.current = input;
|
|
571
|
-
const ticket = active.current;
|
|
572
|
-
if (ticket === void 0) return;
|
|
573
|
-
if (ticket.sessionId !== input.sessionId || ticket.actions !== input.actions || input.phase !== "plain") ticket.invalidated = true;
|
|
574
|
-
}, [input]);
|
|
575
|
-
(0, react.useEffect)(() => () => {
|
|
576
|
-
const ticket = active.current;
|
|
577
|
-
if (ticket !== void 0) {
|
|
578
|
-
ticket.invalidated = true;
|
|
579
|
-
active.current = void 0;
|
|
580
|
-
}
|
|
581
|
-
}, []);
|
|
582
|
-
return {
|
|
583
|
-
begin: () => {
|
|
584
|
-
const ticket = {
|
|
585
|
-
sessionId: latest.current.sessionId,
|
|
586
|
-
draftRev: latest.current.draftRev,
|
|
587
|
-
actions: latest.current.actions,
|
|
588
|
-
invalidated: false
|
|
589
|
-
};
|
|
590
|
-
active.current = ticket;
|
|
591
|
-
return ticket;
|
|
592
|
-
},
|
|
593
|
-
finish: (ticket) => {
|
|
594
|
-
if (active.current === ticket) active.current = void 0;
|
|
595
|
-
},
|
|
596
|
-
commit: (content, ticket) => {
|
|
597
|
-
const live = latest.current;
|
|
598
|
-
const { actions } = live;
|
|
599
|
-
if (!hasDraftFace(actions)) throw new Error(messages.unavailable);
|
|
600
|
-
if (ticket.sessionId !== live.sessionId || live.phase !== "plain") throw new Error(messages.stale);
|
|
601
|
-
let liveRev = live.draftRev;
|
|
602
|
-
if (hasInsertFace(actions)) liveRev = actions.captureInsertion().draftRev;
|
|
603
|
-
if (ticket.invalidated || liveRev !== ticket.draftRev) throw new Error(messages.stale);
|
|
604
|
-
actions.setDraft(content);
|
|
605
|
-
}
|
|
606
|
-
};
|
|
607
|
-
}
|
|
608
|
-
// src/remote.ts
|
|
609
|
-
/** Typert Remote 命名空间(client 半只用这一枚)。
|
|
610
|
-
*
|
|
611
|
-
* 宿主半的注册键在 host.ts 的 `DIR_PREP_REMOTE_NAMESPACE`——两半各自打包、client 包
|
|
612
|
-
* 不能 import host.ts,所以这一枚字面量必然有两份。两边取值必须一致:写岔了的表现是
|
|
613
|
-
* 网关挂上的是 A、报错文案说的是 B,而没有任何运行期信号。 */
|
|
614
|
-
const DIR_PREP_NAMESPACE = "dirPrepOrganize";
|
|
615
|
-
const DIR_PREP_SERVICE_KEY = `remote.${DIR_PREP_NAMESPACE}`;
|
|
616
|
-
const PACKAGE_NAME = "@jayyuen66/dsh-dir-prep-organize";
|
|
617
|
-
/** strict codec 的统一出口:失败交给 zod 的 `prettifyError`,读到的是一份带字段路径的说明。 */
|
|
618
|
-
function parseOrThrow(schema, value) {
|
|
619
|
-
const parsed = schema.safeParse(value);
|
|
620
|
-
if (!parsed.success) throw new TypeError(zod.z.prettifyError(parsed.error));
|
|
621
|
-
return parsed.data;
|
|
622
|
-
}
|
|
623
|
-
const SESSION_MESSAGE = "session request requires a string sessionId";
|
|
624
|
-
const SESSION_SCHEMA = zod.z.object({ sessionId: zod.z.string({ error: SESSION_MESSAGE }) }, { error: SESSION_MESSAGE });
|
|
625
|
-
const ORGANIZE_MESSAGE = "organize request requires string sessionId, prompt and entriesSummary";
|
|
626
|
-
const ORGANIZE_SCHEMA = zod.z.object({
|
|
627
|
-
sessionId: zod.z.string({ error: ORGANIZE_MESSAGE }),
|
|
628
|
-
prompt: zod.z.string({ error: ORGANIZE_MESSAGE }),
|
|
629
|
-
entriesSummary: zod.z.string({ error: ORGANIZE_MESSAGE }),
|
|
630
|
-
roleText: zod.z.string({ error: "organize request roleText must be a string when present" }).optional()
|
|
631
|
-
}, { error: ORGANIZE_MESSAGE });
|
|
632
|
-
const IMPORT_MESSAGE = "import request requires string path and sessionId";
|
|
633
|
-
const IMPORT_SCHEMA = zod.z.object({
|
|
634
|
-
path: zod.z.string({ error: IMPORT_MESSAGE }),
|
|
635
|
-
sessionId: zod.z.string({ error: IMPORT_MESSAGE })
|
|
636
|
-
}, { error: IMPORT_MESSAGE });
|
|
637
|
-
const SESSION_CODEC = {
|
|
638
|
-
mode: "strict",
|
|
639
|
-
typeSymbol: `${PACKAGE_NAME}#session-request`,
|
|
640
|
-
create: () => ({ parse(value) {
|
|
641
|
-
return parseOrThrow(SESSION_SCHEMA, value);
|
|
642
|
-
} })
|
|
643
|
-
};
|
|
644
|
-
const DIR_PREP_DESCRIPTORS = [
|
|
645
|
-
{
|
|
646
|
-
id: `${PACKAGE_NAME}#${DIR_PREP_NAMESPACE}/defaults`,
|
|
647
|
-
service: DIR_PREP_NAMESPACE,
|
|
648
|
-
namespace: DIR_PREP_NAMESPACE,
|
|
649
|
-
method: "defaults",
|
|
650
|
-
invocation: { kind: "direct" },
|
|
651
|
-
parameters: [],
|
|
652
|
-
result: { mode: "src-json" }
|
|
653
|
-
},
|
|
654
|
-
{
|
|
655
|
-
id: `${PACKAGE_NAME}#${DIR_PREP_NAMESPACE}/context`,
|
|
656
|
-
service: DIR_PREP_NAMESPACE,
|
|
657
|
-
namespace: DIR_PREP_NAMESPACE,
|
|
658
|
-
method: "context",
|
|
659
|
-
invocation: { kind: "direct" },
|
|
660
|
-
parameters: [{
|
|
661
|
-
name: "request",
|
|
662
|
-
wire: "request",
|
|
663
|
-
source: "json",
|
|
664
|
-
codec: SESSION_CODEC
|
|
665
|
-
}],
|
|
666
|
-
result: { mode: "src-json" }
|
|
667
|
-
},
|
|
668
|
-
{
|
|
669
|
-
id: `${PACKAGE_NAME}#${DIR_PREP_NAMESPACE}/model`,
|
|
670
|
-
service: DIR_PREP_NAMESPACE,
|
|
671
|
-
namespace: DIR_PREP_NAMESPACE,
|
|
672
|
-
method: "model",
|
|
673
|
-
invocation: { kind: "direct" },
|
|
674
|
-
parameters: [{
|
|
675
|
-
name: "request",
|
|
676
|
-
wire: "request",
|
|
677
|
-
source: "json",
|
|
678
|
-
codec: SESSION_CODEC
|
|
679
|
-
}],
|
|
680
|
-
result: { mode: "src-json" }
|
|
681
|
-
},
|
|
682
|
-
{
|
|
683
|
-
id: `${PACKAGE_NAME}#${DIR_PREP_NAMESPACE}/organize`,
|
|
684
|
-
service: DIR_PREP_NAMESPACE,
|
|
685
|
-
namespace: DIR_PREP_NAMESPACE,
|
|
686
|
-
method: "organize",
|
|
687
|
-
invocation: { kind: "direct" },
|
|
688
|
-
parameters: [{
|
|
689
|
-
name: "request",
|
|
690
|
-
wire: "request",
|
|
691
|
-
source: "json",
|
|
692
|
-
codec: {
|
|
693
|
-
mode: "strict",
|
|
694
|
-
typeSymbol: `${PACKAGE_NAME}#organize-request`,
|
|
695
|
-
create: () => ({ parse(value) {
|
|
696
|
-
const request = parseOrThrow(ORGANIZE_SCHEMA, value);
|
|
697
|
-
return request.roleText === void 0 ? {
|
|
698
|
-
sessionId: request.sessionId,
|
|
699
|
-
prompt: request.prompt,
|
|
700
|
-
entriesSummary: request.entriesSummary
|
|
701
|
-
} : {
|
|
702
|
-
...request,
|
|
703
|
-
roleText: request.roleText
|
|
704
|
-
};
|
|
705
|
-
} })
|
|
706
|
-
}
|
|
707
|
-
}],
|
|
708
|
-
result: { mode: "src-json" }
|
|
709
|
-
},
|
|
710
|
-
{
|
|
711
|
-
id: `${PACKAGE_NAME}#${DIR_PREP_NAMESPACE}/importTemplates`,
|
|
712
|
-
service: DIR_PREP_NAMESPACE,
|
|
713
|
-
namespace: DIR_PREP_NAMESPACE,
|
|
714
|
-
method: "importTemplates",
|
|
715
|
-
invocation: { kind: "direct" },
|
|
716
|
-
parameters: [{
|
|
717
|
-
name: "request",
|
|
718
|
-
wire: "request",
|
|
719
|
-
source: "json",
|
|
720
|
-
codec: {
|
|
721
|
-
mode: "strict",
|
|
722
|
-
typeSymbol: `${PACKAGE_NAME}#import-request`,
|
|
723
|
-
create: () => ({ parse(value) {
|
|
724
|
-
return parseOrThrow(IMPORT_SCHEMA, value);
|
|
725
|
-
} })
|
|
726
|
-
}
|
|
727
|
-
}],
|
|
728
|
-
result: { mode: "src-json" }
|
|
729
|
-
}
|
|
730
|
-
];
|
|
731
|
-
const isMounter = (value) => e$1(value) && typeof value["$mount"] === "function";
|
|
732
|
-
const isNamespace = (value) => e$1(value) && typeof value["defaults"] === "function" && typeof value["context"] === "function" && typeof value["model"] === "function" && typeof value["organize"] === "function" && typeof value["importTemplates"] === "function";
|
|
733
|
-
const unwrap = (raw) => {
|
|
734
|
-
if (!e$1(raw) || typeof raw["ok"] !== "boolean") throw new TypeError("Typert Remote 应答不是 RemoteResult:缺少布尔字段 ok");
|
|
735
|
-
if (!raw["ok"]) {
|
|
736
|
-
const { error } = raw;
|
|
737
|
-
if (!e$1(error) || typeof error["code"] !== "string" || typeof error["message"] !== "string") throw new TypeError("Typert Remote 应答的 error 分支缺 code/message");
|
|
738
|
-
throw new Error(`${error["code"]}: ${error["message"]}`);
|
|
739
|
-
}
|
|
740
|
-
if (!("value" in raw)) throw new TypeError("Typert Remote 应答的 ok 分支缺 value 字段");
|
|
741
|
-
return raw["value"];
|
|
742
|
-
};
|
|
743
|
-
function buildReader(ctx, remote) {
|
|
744
|
-
let mounted;
|
|
745
|
-
const namespaceOf = async () => {
|
|
746
|
-
mounted ??= remote.$mount({
|
|
747
|
-
package: PACKAGE_NAME,
|
|
748
|
-
descriptors: DIR_PREP_DESCRIPTORS
|
|
749
|
-
});
|
|
750
|
-
try {
|
|
751
|
-
await mounted;
|
|
752
|
-
} catch (error) {
|
|
753
|
-
mounted = void 0;
|
|
754
|
-
throw error;
|
|
755
|
-
}
|
|
756
|
-
const namespace = ctx.get?.(DIR_PREP_SERVICE_KEY, false);
|
|
757
|
-
if (!isNamespace(namespace)) throw new Error(`${DIR_PREP_SERVICE_KEY} 未提供:宿主网关没有挂上这枚命名空间`);
|
|
758
|
-
return namespace;
|
|
759
|
-
};
|
|
760
|
-
const call = async (invoke) => {
|
|
761
|
-
const namespace = await namespaceOf();
|
|
762
|
-
return unwrap(await invoke(namespace));
|
|
763
|
-
};
|
|
764
|
-
return {
|
|
765
|
-
defaults: async () => call((namespace) => namespace.defaults()),
|
|
766
|
-
context: async (sessionId) => call((namespace) => namespace.context({ sessionId })),
|
|
767
|
-
model: async (sessionId) => call((namespace) => namespace.model({ sessionId })),
|
|
768
|
-
organize: async (args) => call((namespace) => namespace.organize(args)),
|
|
769
|
-
importTemplates: async (args) => call((namespace) => namespace.importTemplates(args))
|
|
770
|
-
};
|
|
771
|
-
}
|
|
772
|
-
/** 造读取器;当前部署没有远程通道时 undefined(卡片只显示读不到)。
|
|
773
|
-
*
|
|
774
|
-
* `get` 这两处的做法和 buildReader 里查命名空间时保持一致,都显式传 `strict = false`:
|
|
775
|
-
* 不传时 cordis 默认只返回「提供者 fiber 当前 active」的实现,而设置卡可能在 fiber
|
|
776
|
-
* 就绪前就挂上——那时读取方法会拿到 undefined 并显示「读不到」,看起来是插件没装。
|
|
777
|
-
* `get` 本身也可能抛(宿主版本演进之后,反射接口可能不再接受 bool),接住它只是为了把这
|
|
778
|
-
* 一栏降级成「读不到」,不让整张卡片跟着炸。 */
|
|
779
|
-
function createDirPrepReader(ctx) {
|
|
780
|
-
let remote;
|
|
781
|
-
try {
|
|
782
|
-
remote = ctx.get?.("remote", false);
|
|
783
|
-
} catch {
|
|
784
|
-
remote = void 0;
|
|
785
|
-
}
|
|
786
|
-
return isMounter(remote) ? buildReader(ctx, remote) : void 0;
|
|
787
|
-
}
|
|
788
|
-
// src/client-entry.ts
|
|
789
|
-
const NS = "dir-prep-organize";
|
|
790
|
-
const BUNDLE_PKG = "@jayyuen66/dsh-dir-prep-organize";
|
|
791
|
-
const ERROR_FLASH_MS = 4e3;
|
|
792
|
-
/** 除润色之外的调用的等待上限。润色那一发有自己的超时(来自设置卡的 organizeTimeoutMs)。 */
|
|
793
|
-
const REMOTE_TIMEOUT_MS = 125e3;
|
|
794
|
-
const RESET_CONFIRM_MS = 4e3;
|
|
795
|
-
const EMOJI_PLACEHOLDER = "😀";
|
|
796
|
-
const ROOT_PATH_PLACEHOLDER = "/Users/me/roles";
|
|
797
|
-
const CLASS_ITEM_EMPTY = "dpi-item-empty";
|
|
798
|
-
const CLASS_ROW_HEAD = "dpic-rowhead";
|
|
799
|
-
const CLASS_IMPORT_PATH = "dpic-importpath";
|
|
800
|
-
const SLOT_INPUT_RIGHT = "conversation.input.right";
|
|
801
|
-
function parseDirEntry(raw) {
|
|
802
|
-
const { name, isDir, sizeBytes, snippet } = e$1(raw) ? raw : {};
|
|
803
|
-
return {
|
|
804
|
-
name: typeof name === "string" ? name : "",
|
|
805
|
-
isDir: isDir === true,
|
|
806
|
-
sizeBytes: typeof sizeBytes === "number" ? sizeBytes : 0,
|
|
807
|
-
...typeof snippet === "string" ? { snippet } : {}
|
|
808
|
-
};
|
|
809
|
-
}
|
|
810
|
-
/** 可选字符串位的窄化(`error`/`cwd`/`content` 等共用一条)。 */
|
|
811
|
-
function optionalString(rec, key) {
|
|
812
|
-
const value = rec[key];
|
|
813
|
-
return typeof value === "string" ? value : void 0;
|
|
814
|
-
}
|
|
815
|
-
/** 有值才铺开成对象成员;无值时铺 `{}`,于是「缺席」与「显式 undefined」在形状上一致。
|
|
816
|
-
*
|
|
817
|
-
* 抽出来是因为四个解析器共 9 处同形展开,逐处写 `...(x === undefined ? {} : {k: x})`
|
|
818
|
-
* 既占行又容易漏掉某一位(漏一位 = 那个字段被静默丢掉)。 */
|
|
819
|
-
function spreadIfDefined(value, key) {
|
|
820
|
-
return value === void 0 ? {} : { [key]: value };
|
|
821
|
-
}
|
|
822
|
-
/** 跳过计数的展示顺序(文案与顺序都在这里定;formatImportSkips 只负责拼句子)。 */
|
|
823
|
-
function skipCountsOf(skips) {
|
|
824
|
-
return [
|
|
825
|
-
["skipDeeper", skips.deeper],
|
|
826
|
-
["skipTooLarge", skips.tooLarge],
|
|
827
|
-
["skipUnreadable", skips.unreadable],
|
|
828
|
-
["skipUnnamed", skips.unnamed],
|
|
829
|
-
["skipEscaped", skips.escaped]
|
|
830
|
-
];
|
|
831
|
-
}
|
|
832
|
-
function parseContextResponse(raw) {
|
|
833
|
-
const rec = e$1(raw) ? raw : {};
|
|
834
|
-
const { ok, truncated, entries } = rec;
|
|
835
|
-
const parsedEntries = Array.isArray(entries) ? entries.map((entry) => parseDirEntry(entry)) : void 0;
|
|
836
|
-
return {
|
|
837
|
-
ok: ok === true,
|
|
838
|
-
...spreadIfDefined(optionalString(rec, "error"), "error"),
|
|
839
|
-
...spreadIfDefined(optionalString(rec, "cwd"), "cwd"),
|
|
840
|
-
...truncated === true ? { truncated: true } : {},
|
|
841
|
-
...parsedEntries === void 0 ? {} : { entries: parsedEntries }
|
|
842
|
-
};
|
|
843
|
-
}
|
|
844
|
-
function parseModelResponse(raw) {
|
|
845
|
-
const rec = e$1(raw) ? raw : {};
|
|
846
|
-
return {
|
|
847
|
-
ok: rec["ok"] === true,
|
|
848
|
-
...spreadIfDefined(optionalString(rec, "error"), "error"),
|
|
849
|
-
...spreadIfDefined(optionalString(rec, "provider"), "provider"),
|
|
850
|
-
...spreadIfDefined(optionalString(rec, "model"), "model"),
|
|
851
|
-
...spreadIfDefined(optionalString(rec, "reasoningEffort"), "reasoningEffort")
|
|
852
|
-
};
|
|
853
|
-
}
|
|
854
|
-
function parseOrganizeResponse(raw) {
|
|
855
|
-
const rec = e$1(raw) ? raw : {};
|
|
856
|
-
return {
|
|
857
|
-
ok: rec["ok"] === true,
|
|
858
|
-
...spreadIfDefined(optionalString(rec, "error"), "error"),
|
|
859
|
-
...spreadIfDefined(optionalString(rec, "content"), "content")
|
|
860
|
-
};
|
|
861
|
-
}
|
|
862
|
-
/** 计数位:非数字或非正一律 0(坏回执不该让界面显示 "NaN 个")。 */
|
|
863
|
-
function countField(value) {
|
|
864
|
-
return typeof value === "number" && value > 0 ? value : 0;
|
|
865
|
-
}
|
|
866
|
-
function parseImportSkips(rec) {
|
|
867
|
-
return {
|
|
868
|
-
tooLarge: countField(rec["tooLarge"]),
|
|
869
|
-
unreadable: countField(rec["unreadable"]),
|
|
870
|
-
deeper: countField(rec["deeper"]),
|
|
871
|
-
unnamed: countField(rec["unnamed"]),
|
|
872
|
-
escaped: countField(rec["escaped"])
|
|
873
|
-
};
|
|
874
|
-
}
|
|
875
|
-
/** 导入跳过计数 → 一句话(无计数时返回空串,调用方据此不追加任何文案)。 */
|
|
876
|
-
function formatImportSkips(t, skips) {
|
|
877
|
-
if (skips === void 0) return "";
|
|
878
|
-
const parts = [];
|
|
879
|
-
for (const [key, count] of skipCountsOf(skips)) if (count > 0) parts.push(t(key, { count }));
|
|
880
|
-
return parts.length === 0 ? "" : t("skipSummary", { list: parts.join(t("skipSeparator")) });
|
|
881
|
-
}
|
|
882
|
-
function parseImportResponse(raw) {
|
|
883
|
-
const { ok, error, count, truncated, skipped, entries } = e$1(raw) ? raw : {};
|
|
884
|
-
const parsedEntries = Array.isArray(entries) ? sanitizeTemplateList(entries) : void 0;
|
|
885
|
-
return {
|
|
886
|
-
ok: ok === true,
|
|
887
|
-
...typeof error === "string" ? { error } : {},
|
|
888
|
-
...typeof count === "number" ? { count } : {},
|
|
889
|
-
...truncated === true ? { truncated: true } : {},
|
|
890
|
-
...e$1(skipped) ? { skipped: parseImportSkips(skipped) } : {},
|
|
891
|
-
...parsedEntries === void 0 ? {} : { entries: parsedEntries }
|
|
892
|
-
};
|
|
893
|
-
}
|
|
894
|
-
function formatContextSummary(resp) {
|
|
895
|
-
const entries = resp.entries ?? [];
|
|
896
|
-
const lines = [`当前目录: ${resp.cwd ?? "(未提供)"}`];
|
|
897
|
-
const files = entries.filter((entry) => !entry.isDir);
|
|
898
|
-
const dirs = entries.filter((entry) => entry.isDir);
|
|
899
|
-
lines.push(`文件 ${files.length} 个, 目录 ${dirs.length} 个`);
|
|
900
|
-
if (resp.truncated === true) lines.push("(以上条目按上限截断,目录树并未完整列出,勿据此判断文件不存在)");
|
|
901
|
-
for (const dir of dirs) lines.push(`📁 ${dir.name}/`);
|
|
902
|
-
for (const file of files) {
|
|
903
|
-
const size = file.sizeBytes > 1024 ? `${(file.sizeBytes / 1024).toFixed(1)}KB` : `${file.sizeBytes}B`;
|
|
904
|
-
let line = `📄 ${file.name} (${size})`;
|
|
905
|
-
if (file.snippet !== void 0 && file.snippet.length > 0) line += ` ↳ ${file.snippet.replaceAll("\n", " ")}`;
|
|
906
|
-
lines.push(line);
|
|
907
|
-
}
|
|
908
|
-
return lines.join("\n");
|
|
909
|
-
}
|
|
910
|
-
const builtinInitial = {
|
|
911
|
-
phase: "idle",
|
|
912
|
-
list: [],
|
|
913
|
-
error: ""
|
|
914
|
-
};
|
|
915
|
-
let builtinState = builtinInitial;
|
|
916
|
-
let builtinInflight = null;
|
|
917
|
-
/**
|
|
918
|
-
* 在飞 Promise 的世代。reset 之后新一代重新起跑,上一代晚到的结果不许再写进 store,
|
|
919
|
-
* 否则用户点了「恢复默认」却拿回恢复前那次请求的快照。
|
|
920
|
-
*/
|
|
921
|
-
let builtinGeneration = 0;
|
|
922
|
-
const builtinListeners = /* @__PURE__ */ new Set();
|
|
923
|
-
function setBuiltinState(next) {
|
|
924
|
-
if (next === builtinState) return builtinState;
|
|
925
|
-
builtinState = next;
|
|
926
|
-
for (const listener of builtinListeners) listener();
|
|
927
|
-
return next;
|
|
928
|
-
}
|
|
929
|
-
function builtinTemplatesSnapshot() {
|
|
930
|
-
return builtinState;
|
|
931
|
-
}
|
|
932
|
-
let dirPrepReader;
|
|
933
|
-
/** 导出仅供单测:不经过 apply 的纯读取方法用例直接注入替身。 */
|
|
934
|
-
function setDirPrepReader(reader) {
|
|
935
|
-
dirPrepReader = reader;
|
|
936
|
-
}
|
|
937
|
-
function requireReader() {
|
|
938
|
-
if (dirPrepReader === void 0) throw new Error(`远程读面不可用:宿主网关没有挂上 ${DIR_PREP_NAMESPACE}`);
|
|
939
|
-
return dirPrepReader;
|
|
940
|
-
}
|
|
941
|
-
/**
|
|
942
|
-
* 润色链路里由客户端自己产生的错误:messageKey 指向 ui-messages 的键,捕获侧用当前
|
|
943
|
-
* 语言的 t 渲染成 tooltip——把文案直接写进 Error.message 会让英文界面看到硬编码中文。
|
|
944
|
-
* 宿主回执携带的原文(ctxRes.error / modelRes.error)不翻译,作为 {message} 原样带出。
|
|
945
|
-
*/
|
|
946
|
-
var LocalizedOrganizeError = class extends Error {
|
|
947
|
-
messageKey;
|
|
948
|
-
params;
|
|
949
|
-
constructor(messageKey, params = {}) {
|
|
950
|
-
super(messageKey);
|
|
951
|
-
this.name = "LocalizedOrganizeError";
|
|
952
|
-
this.messageKey = messageKey;
|
|
953
|
-
this.params = params;
|
|
954
|
-
}
|
|
955
|
-
};
|
|
956
|
-
/** 客户端的超时只影响等待:宿主侧的润色超时仍由它自己的 AbortController 收尾。 */
|
|
957
|
-
async function within(pending, timeoutMs) {
|
|
958
|
-
const gate = Promise.withResolvers();
|
|
959
|
-
const timer = setTimeout(() => {
|
|
960
|
-
gate.reject(new LocalizedOrganizeError("organizeErrTimeout"));
|
|
961
|
-
}, timeoutMs);
|
|
962
|
-
try {
|
|
963
|
-
return await Promise.race([pending, gate.promise]);
|
|
964
|
-
} finally {
|
|
965
|
-
clearTimeout(timer);
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
async function loadBuiltinTemplates() {
|
|
969
|
-
if (builtinState.phase === "ready") return builtinState;
|
|
970
|
-
if (builtinInflight !== null) return await builtinInflight;
|
|
971
|
-
const generation = builtinGeneration;
|
|
972
|
-
builtinInflight = (async () => {
|
|
973
|
-
setBuiltinState({
|
|
974
|
-
phase: "loading",
|
|
975
|
-
list: builtinState.list,
|
|
976
|
-
error: ""
|
|
977
|
-
});
|
|
978
|
-
let settled;
|
|
979
|
-
try {
|
|
980
|
-
const body = await within(requireReader().defaults(), REMOTE_TIMEOUT_MS);
|
|
981
|
-
const payload = e$1(body) ? body : void 0;
|
|
982
|
-
const okKey = "ok";
|
|
983
|
-
const templatesKey = "templates";
|
|
984
|
-
const rawReason = payload?.["error"];
|
|
985
|
-
settled = payload?.[okKey] === true ? {
|
|
986
|
-
phase: "ready",
|
|
987
|
-
list: sanitizeTemplateList(payload[templatesKey]),
|
|
988
|
-
error: ""
|
|
989
|
-
} : {
|
|
990
|
-
phase: "error",
|
|
991
|
-
list: [],
|
|
992
|
-
error: typeof rawReason === "string" && rawReason.trim() !== "" ? rawReason : "内置模板响应不是合法载荷"
|
|
993
|
-
};
|
|
994
|
-
} catch (error) {
|
|
995
|
-
settled = {
|
|
996
|
-
phase: "error",
|
|
997
|
-
list: [],
|
|
998
|
-
error: r(error)
|
|
999
|
-
};
|
|
1000
|
-
} finally {
|
|
1001
|
-
if (builtinGeneration === generation) builtinInflight = null;
|
|
1002
|
-
}
|
|
1003
|
-
return builtinGeneration === generation ? setBuiltinState(settled) : settled;
|
|
1004
|
-
})();
|
|
1005
|
-
return await builtinInflight;
|
|
1006
|
-
}
|
|
1007
|
-
function subscribeBuiltinTemplates(listener) {
|
|
1008
|
-
builtinListeners.add(listener);
|
|
1009
|
-
return () => {
|
|
1010
|
-
builtinListeners.delete(listener);
|
|
1011
|
-
};
|
|
1012
|
-
}
|
|
1013
|
-
function resetBuiltinTemplates() {
|
|
1014
|
-
builtinGeneration += 1;
|
|
1015
|
-
builtinInflight = null;
|
|
1016
|
-
setBuiltinState(builtinInitial);
|
|
1017
|
-
}
|
|
1018
|
-
function builtinStatusRow(snap, t) {
|
|
1019
|
-
const attrs = {
|
|
1020
|
-
className: CLASS_ITEM_EMPTY,
|
|
1021
|
-
"data-field": "dpi-builtin-state"
|
|
1022
|
-
};
|
|
1023
|
-
const retryButton = (0, react.createElement)("button", {
|
|
1024
|
-
type: "button",
|
|
1025
|
-
className: "dsu-btn",
|
|
1026
|
-
"data-field": "dpi-builtin-retry",
|
|
1027
|
-
onClick: () => {
|
|
1028
|
-
loadBuiltinTemplates();
|
|
1029
|
-
}
|
|
1030
|
-
}, t("builtinRetry"));
|
|
1031
|
-
let row;
|
|
1032
|
-
if (!snap.fromSettings && snap.builtinPhase !== "ready") row = snap.builtinPhase === "error" ? (0, react.createElement)("div", attrs, t("builtinFailed", { message: snap.builtinError }), retryButton) : (0, react.createElement)("div", attrs, t("builtinLoading"));
|
|
1033
|
-
return row;
|
|
1034
|
-
}
|
|
1035
|
-
function assertOrganizeReady(ctxRes, modelRes, prompt, unknownReason) {
|
|
1036
|
-
if (!ctxRes.ok) throw new LocalizedOrganizeError("organizeErrContextFailed", { message: ctxRes.error ?? unknownReason });
|
|
1037
|
-
if (!modelRes.ok || modelRes.provider === void 0 || modelRes.model === void 0) throw new LocalizedOrganizeError("organizeErrModelFailed", { message: modelRes.error ?? unknownReason });
|
|
1038
|
-
if (prompt.trim().length === 0) throw new LocalizedOrganizeError("organizeErrEmpty");
|
|
1039
|
-
}
|
|
1040
|
-
async function requestOrganize(args) {
|
|
1041
|
-
const { ctxRes, prompt, sessionId, roleText, timeoutMs } = args;
|
|
1042
|
-
const entriesSummary = formatContextSummary(ctxRes);
|
|
1043
|
-
const orgRes = parseOrganizeResponse(await within(requireReader().organize({
|
|
1044
|
-
sessionId,
|
|
1045
|
-
prompt,
|
|
1046
|
-
entriesSummary,
|
|
1047
|
-
...roleText === void 0 ? {} : { roleText }
|
|
1048
|
-
}), timeoutMs));
|
|
1049
|
-
if (!orgRes.ok || orgRes.content === void 0) throw orgRes.error === void 0 ? new LocalizedOrganizeError("organizeErrUnknown") : new Error(orgRes.error);
|
|
1050
|
-
return orgRes.content;
|
|
1051
|
-
}
|
|
1052
|
-
async function runOrganizeFlow(args) {
|
|
1053
|
-
const reader = requireReader();
|
|
1054
|
-
const [ctxRaw, modelRaw] = await Promise.all([within(reader.context(args.sessionId), REMOTE_TIMEOUT_MS), within(reader.model(args.sessionId), REMOTE_TIMEOUT_MS)]);
|
|
1055
|
-
const ctxRes = parseContextResponse(ctxRaw);
|
|
1056
|
-
assertOrganizeReady(ctxRes, parseModelResponse(modelRaw), args.prompt, args.unknownReason);
|
|
1057
|
-
return requestOrganize({
|
|
1058
|
-
ctxRes,
|
|
1059
|
-
prompt: args.prompt,
|
|
1060
|
-
sessionId: args.sessionId,
|
|
1061
|
-
roleText: args.roleText,
|
|
1062
|
-
timeoutMs: args.timeoutMs
|
|
1063
|
-
});
|
|
1064
|
-
}
|
|
1065
|
-
function projectFormSnapshot(snap) {
|
|
1066
|
-
const { value, status, writable, revision } = snap;
|
|
1067
|
-
return {
|
|
1068
|
-
value: value ?? {},
|
|
1069
|
-
ready: status === "ready",
|
|
1070
|
-
writable,
|
|
1071
|
-
revision: revision ?? 0
|
|
1072
|
-
};
|
|
1073
|
-
}
|
|
1074
|
-
function rawTemplatesOf(value) {
|
|
1075
|
-
return value["templates"];
|
|
1076
|
-
}
|
|
1077
|
-
function rawAllowRootsOf(value) {
|
|
1078
|
-
return value["importAllowRoots"];
|
|
1079
|
-
}
|
|
1080
|
-
function templatesStore(scope) {
|
|
1081
|
-
let cachedRaw = null;
|
|
1082
|
-
let cachedBuiltin = builtinState;
|
|
1083
|
-
let cachedView = {
|
|
1084
|
-
templates: builtinInitial.list,
|
|
1085
|
-
fromSettings: false,
|
|
1086
|
-
builtinPhase: "idle",
|
|
1087
|
-
builtinError: "",
|
|
1088
|
-
allowRoots: [],
|
|
1089
|
-
ready: false,
|
|
1090
|
-
writable: false,
|
|
1091
|
-
organizeTimeoutMs: void 0
|
|
1092
|
-
};
|
|
1093
|
-
return {
|
|
1094
|
-
getSnapshot() {
|
|
1095
|
-
const snap = scope.getSnapshot();
|
|
1096
|
-
if (snap === cachedRaw && builtinState === cachedBuiltin) return cachedView;
|
|
1097
|
-
cachedRaw = snap;
|
|
1098
|
-
cachedBuiltin = builtinState;
|
|
1099
|
-
const projected = projectFormSnapshot(snap);
|
|
1100
|
-
const rawTemplates = rawTemplatesOf(projected.value);
|
|
1101
|
-
const fromSettings = Array.isArray(rawTemplates) && rawTemplates.length > 0;
|
|
1102
|
-
cachedView = {
|
|
1103
|
-
templates: fromSettings ? sanitizeTemplateList(rawTemplates) : cachedBuiltin.list,
|
|
1104
|
-
fromSettings,
|
|
1105
|
-
builtinPhase: cachedBuiltin.phase,
|
|
1106
|
-
builtinError: cachedBuiltin.error,
|
|
1107
|
-
allowRoots: sanitizeAllowRoots(rawAllowRootsOf(projected.value)),
|
|
1108
|
-
ready: projected.ready,
|
|
1109
|
-
writable: projected.writable,
|
|
1110
|
-
organizeTimeoutMs: rawOrganizeTimeoutMsOf(projected.value)
|
|
1111
|
-
};
|
|
1112
|
-
return cachedView;
|
|
1113
|
-
},
|
|
1114
|
-
subscribe(listener) {
|
|
1115
|
-
const offForm = scope.subscribe(listener);
|
|
1116
|
-
const offBuiltin = subscribeBuiltinTemplates(listener);
|
|
1117
|
-
return () => {
|
|
1118
|
-
offForm();
|
|
1119
|
-
offBuiltin();
|
|
1120
|
-
};
|
|
1121
|
-
},
|
|
1122
|
-
readBack() {
|
|
1123
|
-
const projected = projectFormSnapshot(scope.getSnapshot());
|
|
1124
|
-
return {
|
|
1125
|
-
ready: projected.ready,
|
|
1126
|
-
revision: projected.revision,
|
|
1127
|
-
templates: sanitizeTemplateList(rawTemplatesOf(projected.value)),
|
|
1128
|
-
allowRoots: sanitizeAllowRoots(rawAllowRootsOf(projected.value))
|
|
1129
|
-
};
|
|
1130
|
-
}
|
|
1131
|
-
};
|
|
1132
|
-
}
|
|
1133
|
-
function persistError(t, persisted, expected, action, opts) {
|
|
1134
|
-
let message;
|
|
1135
|
-
const revertedToBase = opts?.treatEmptyAsReverted === true && persisted.templates.length === 0 && expected.length > 0;
|
|
1136
|
-
if (!persisted.ready) message = t("persistUnconfirmed", { action });
|
|
1137
|
-
else if (!revertedToBase && JSON.stringify(persisted.templates) !== JSON.stringify(expected)) message = t("persistRejected", {
|
|
1138
|
-
action,
|
|
1139
|
-
revision: persisted.revision
|
|
1140
|
-
});
|
|
1141
|
-
return message;
|
|
1142
|
-
}
|
|
1143
|
-
function rootsPersistError(t, persisted, expected, action) {
|
|
1144
|
-
let message;
|
|
1145
|
-
if (!persisted.ready) message = t("persistUnconfirmed", { action });
|
|
1146
|
-
else if (JSON.stringify(persisted.allowRoots) !== JSON.stringify(expected)) message = t("persistRejected", {
|
|
1147
|
-
action,
|
|
1148
|
-
revision: persisted.revision
|
|
1149
|
-
});
|
|
1150
|
-
return message;
|
|
1151
|
-
}
|
|
1152
|
-
/** 菜单项文字:有 emoji 就前缀一个(emoji 是用户自填的视觉标记,空串 = 不显示)。 */
|
|
1153
|
-
function templateItemLabel(tpl) {
|
|
1154
|
-
return `${tpl.emoji === "" ? "" : `${tpl.emoji} `}${tpl.name}`;
|
|
1155
|
-
}
|
|
1156
|
-
/** 模板 → 按 group 收拢的分组(空 group 归入「通用」)。
|
|
1157
|
-
*
|
|
1158
|
-
* 分组表用 `Map` 而不是对象字面量:分组标签是用户可填的 `template.group`,
|
|
1159
|
-
* `__proto__` / `constructor` 这类标签作为对象键会落进原型链而不是成为一个分组
|
|
1160
|
-
* (Map 没有这条缝)。顺序 = 首次出现顺序,渲染稳定可测。 */
|
|
1161
|
-
function groupTemplatesBy(templates, t) {
|
|
1162
|
-
const buckets = /* @__PURE__ */ new Map();
|
|
1163
|
-
for (const tpl of templates) {
|
|
1164
|
-
const key = tpl.group.trim() === "" ? t("templatesGroupCommon") : tpl.group;
|
|
1165
|
-
const bucket = buckets.get(key) ?? [];
|
|
1166
|
-
bucket.push(tpl);
|
|
1167
|
-
buckets.set(key, bucket);
|
|
1168
|
-
}
|
|
1169
|
-
return Array.from(buckets.entries(), ([group, items]) => ({
|
|
1170
|
-
group,
|
|
1171
|
-
items
|
|
1172
|
-
}));
|
|
1173
|
-
}
|
|
1174
|
-
function svgPathProps(dValue, strokeLinejoin = false) {
|
|
1175
|
-
const entries = [
|
|
1176
|
-
["d", dValue],
|
|
1177
|
-
["fill", "none"],
|
|
1178
|
-
["stroke", "currentColor"],
|
|
1179
|
-
["strokeWidth", 1.5],
|
|
1180
|
-
["strokeLinecap", "round"]
|
|
1181
|
-
];
|
|
1182
|
-
if (strokeLinejoin) entries.push(["strokeLinejoin", "round"]);
|
|
1183
|
-
return Object.fromEntries(entries);
|
|
1184
|
-
}
|
|
1185
|
-
function svgSpinProps() {
|
|
1186
|
-
return Object.fromEntries([
|
|
1187
|
-
["cx", 7],
|
|
1188
|
-
["cy", 7],
|
|
1189
|
-
["r", 5.5],
|
|
1190
|
-
["fill", "none"],
|
|
1191
|
-
["stroke", "currentColor"],
|
|
1192
|
-
["strokeWidth", 1.5],
|
|
1193
|
-
["strokeDasharray", "26 10"],
|
|
1194
|
-
["strokeLinecap", "round"]
|
|
1195
|
-
]);
|
|
1196
|
-
}
|
|
1197
|
-
function TidyIcon() {
|
|
1198
|
-
return (0, react.createElement)("svg", {
|
|
1199
|
-
width: 14,
|
|
1200
|
-
height: 14,
|
|
1201
|
-
viewBox: "0 0 14 14",
|
|
1202
|
-
"aria-hidden": true
|
|
1203
|
-
}, (0, react.createElement)("path", svgPathProps("M2 4l5 4 5-4", true)), (0, react.createElement)("path", svgPathProps("M2 8.5l5 4 5-4", true)));
|
|
1204
|
-
}
|
|
1205
|
-
function SpinIcon() {
|
|
1206
|
-
return (0, react.createElement)("svg", {
|
|
1207
|
-
width: 14,
|
|
1208
|
-
height: 14,
|
|
1209
|
-
viewBox: "0 0 14 14",
|
|
1210
|
-
"aria-hidden": true,
|
|
1211
|
-
className: "dpi-spin"
|
|
1212
|
-
}, (0, react.createElement)("circle", svgSpinProps()));
|
|
1213
|
-
}
|
|
1214
|
-
function FailIcon() {
|
|
1215
|
-
return (0, react.createElement)("svg", {
|
|
1216
|
-
width: 14,
|
|
1217
|
-
height: 14,
|
|
1218
|
-
viewBox: "0 0 14 14",
|
|
1219
|
-
"aria-hidden": true
|
|
1220
|
-
}, (0, react.createElement)("path", svgPathProps("M3 3l8 8M11 3l-8 8")));
|
|
1221
|
-
}
|
|
1222
|
-
function TemplateIcon() {
|
|
1223
|
-
return (0, react.createElement)("svg", {
|
|
1224
|
-
width: 14,
|
|
1225
|
-
height: 14,
|
|
1226
|
-
viewBox: "0 0 14 14",
|
|
1227
|
-
"aria-hidden": true
|
|
1228
|
-
}, (0, react.createElement)("path", svgPathProps("M2.5 3.5h9M2.5 7h9M2.5 10.5h5.5")));
|
|
1229
|
-
}
|
|
1230
|
-
function CaretIcon() {
|
|
1231
|
-
return (0, react.createElement)("svg", {
|
|
1232
|
-
width: 14,
|
|
1233
|
-
height: 14,
|
|
1234
|
-
viewBox: "0 0 14 14",
|
|
1235
|
-
"aria-hidden": true
|
|
1236
|
-
}, (0, react.createElement)("path", svgPathProps("M2.5 5.5L7 9.5l4.5-4", true)));
|
|
1237
|
-
}
|
|
1238
|
-
function useMenuDismiss(open, wrapRef, close) {
|
|
1239
|
-
(0, react.useEffect)(() => {
|
|
1240
|
-
function onDown(event) {
|
|
1241
|
-
if (wrapRef.current !== null && event.target instanceof Node && !wrapRef.current.contains(event.target)) close();
|
|
1242
|
-
}
|
|
1243
|
-
function onKey(event) {
|
|
1244
|
-
if (event.key === "Escape") close();
|
|
1245
|
-
}
|
|
1246
|
-
if (open) {
|
|
1247
|
-
document.addEventListener("mousedown", onDown);
|
|
1248
|
-
document.addEventListener("keydown", onKey);
|
|
1249
|
-
}
|
|
1250
|
-
return () => {
|
|
1251
|
-
document.removeEventListener("mousedown", onDown);
|
|
1252
|
-
document.removeEventListener("keydown", onKey);
|
|
1253
|
-
};
|
|
1254
|
-
}, [
|
|
1255
|
-
close,
|
|
1256
|
-
open,
|
|
1257
|
-
wrapRef
|
|
1258
|
-
]);
|
|
1259
|
-
}
|
|
1260
|
-
async function runOrganizeClick(args) {
|
|
1261
|
-
const { t, loading, inFlight, seq, prompt, sessionId, timeoutMs, roleText, setLoading, setMenuOpen, setFailed, flashTimer, writeDraft } = args;
|
|
1262
|
-
if (loading || inFlight.current) return;
|
|
1263
|
-
inFlight.current = true;
|
|
1264
|
-
seq.current += 1;
|
|
1265
|
-
const mySeq = seq.current;
|
|
1266
|
-
setLoading(true);
|
|
1267
|
-
setFailed(void 0);
|
|
1268
|
-
setMenuOpen(false);
|
|
1269
|
-
try {
|
|
1270
|
-
const content = await runOrganizeFlow({
|
|
1271
|
-
prompt,
|
|
1272
|
-
sessionId,
|
|
1273
|
-
...roleText === void 0 ? {} : { roleText },
|
|
1274
|
-
timeoutMs,
|
|
1275
|
-
unknownReason: t("organizeErrUnknownReason")
|
|
1276
|
-
});
|
|
1277
|
-
if (seq.current !== mySeq) return;
|
|
1278
|
-
writeDraft(content);
|
|
1279
|
-
} catch (error) {
|
|
1280
|
-
if (seq.current !== mySeq) return;
|
|
1281
|
-
setFailed(error instanceof LocalizedOrganizeError ? t(error.messageKey, error.params) : r(error));
|
|
1282
|
-
if (flashTimer.current !== null) clearTimeout(flashTimer.current);
|
|
1283
|
-
flashTimer.current = setTimeout(() => {
|
|
1284
|
-
setFailed(void 0);
|
|
1285
|
-
}, ERROR_FLASH_MS);
|
|
1286
|
-
} finally {
|
|
1287
|
-
inFlight.current = false;
|
|
1288
|
-
if (seq.current === mySeq) setLoading(false);
|
|
1289
|
-
}
|
|
1290
|
-
}
|
|
1291
|
-
/** 润色结果无处可写时的主按钮 title(与模板项那一档同一句话,同一套判据)。 */
|
|
1292
|
-
const NO_WRITE_BACK_TITLE_KEY = "organizeWriteBackUnavailable";
|
|
1293
|
-
function createOrganizeMainButton(ui) {
|
|
1294
|
-
const { t, icon, label, state, errClass, errTitle, loading, canWrite, onRun } = ui;
|
|
1295
|
-
return (0, react.createElement)("button", {
|
|
1296
|
-
type: "button",
|
|
1297
|
-
className: `dpi-btn dpi-main${errClass}`,
|
|
1298
|
-
"aria-label": t("organizeMainAria"),
|
|
1299
|
-
title: errTitle,
|
|
1300
|
-
"data-field": "dpi-organize-btn",
|
|
1301
|
-
"data-state": state,
|
|
1302
|
-
disabled: loading || !canWrite,
|
|
1303
|
-
onClick: () => {
|
|
1304
|
-
onRun();
|
|
1305
|
-
}
|
|
1306
|
-
}, icon, label);
|
|
1307
|
-
}
|
|
1308
|
-
function createOrganizeCaret(ui) {
|
|
1309
|
-
const { t, errClass, menuOpen, loading, onToggleMenu } = ui;
|
|
1310
|
-
return (0, react.createElement)("button", {
|
|
1311
|
-
type: "button",
|
|
1312
|
-
className: `dpi-btn dpi-caret${errClass}`,
|
|
1313
|
-
"aria-label": t("organizeCaretAria"),
|
|
1314
|
-
"aria-haspopup": "menu",
|
|
1315
|
-
"aria-expanded": menuOpen,
|
|
1316
|
-
title: t("organizeCaretTitle"),
|
|
1317
|
-
"data-field": "dpi-organize-caret",
|
|
1318
|
-
"data-state": menuOpen ? "open" : "idle",
|
|
1319
|
-
disabled: loading,
|
|
1320
|
-
onClick: onToggleMenu
|
|
1321
|
-
}, (0, react.createElement)(CaretIcon));
|
|
1322
|
-
}
|
|
1323
|
-
function createOrganizeRoleMenu(ui) {
|
|
1324
|
-
const { t, templates, onRun, directItemLabel, noTemplatesLabel, builtinRow, loading, canWrite, errTitle } = ui;
|
|
1325
|
-
const blocked = loading || !canWrite;
|
|
1326
|
-
const blockedTitle = canWrite ? void 0 : errTitle;
|
|
1327
|
-
return (0, react.createElement)("div", {
|
|
1328
|
-
className: "dpi-menu",
|
|
1329
|
-
role: "menu",
|
|
1330
|
-
"data-field": "dpi-organize-menu"
|
|
1331
|
-
}, (0, react.createElement)("button", {
|
|
1332
|
-
type: "button",
|
|
1333
|
-
className: "dpi-item",
|
|
1334
|
-
role: "menuitem",
|
|
1335
|
-
"data-field": "dpi-organize-role-direct",
|
|
1336
|
-
disabled: blocked,
|
|
1337
|
-
...blockedTitle === void 0 ? {} : { title: blockedTitle },
|
|
1338
|
-
onClick: () => {
|
|
1339
|
-
onRun();
|
|
1340
|
-
}
|
|
1341
|
-
}, directItemLabel), templates.length === 0 ? builtinRow ?? (0, react.createElement)("div", { className: CLASS_ITEM_EMPTY }, noTemplatesLabel) : templates.map((tpl) => (0, react.createElement)("button", {
|
|
1342
|
-
key: tpl.id,
|
|
1343
|
-
type: "button",
|
|
1344
|
-
className: "dpi-item",
|
|
1345
|
-
role: "menuitem",
|
|
1346
|
-
"data-field": "dpi-organize-role-item",
|
|
1347
|
-
disabled: blocked,
|
|
1348
|
-
title: blockedTitle ?? (tpl.description === "" ? tpl.text : tpl.description),
|
|
1349
|
-
onClick: () => {
|
|
1350
|
-
onRun(tpl.text);
|
|
1351
|
-
}
|
|
1352
|
-
}, `${tpl.emoji === "" ? "" : `${tpl.emoji} `}${t("organizeRoleItem", { name: tpl.name })}`)));
|
|
1353
|
-
}
|
|
1354
|
-
/** 主键的三态外观:失败 > 在途 > 空闲(三者互斥,按同一优先级判)。 */
|
|
1355
|
-
function organizeBadge(failed, loading, t) {
|
|
1356
|
-
if (failed !== void 0) return {
|
|
1357
|
-
icon: (0, react.createElement)(FailIcon),
|
|
1358
|
-
label: t("organizeFailedShort"),
|
|
1359
|
-
state: "error"
|
|
1360
|
-
};
|
|
1361
|
-
if (loading) return {
|
|
1362
|
-
icon: (0, react.createElement)(SpinIcon),
|
|
1363
|
-
label: t("organizeLoading"),
|
|
1364
|
-
state: "loading"
|
|
1365
|
-
};
|
|
1366
|
-
return {
|
|
1367
|
-
icon: (0, react.createElement)(TidyIcon),
|
|
1368
|
-
label: t("organizeIdle"),
|
|
1369
|
-
state: "idle"
|
|
1370
|
-
};
|
|
1371
|
-
}
|
|
1372
|
-
function createOrganizeButton() {
|
|
1373
|
-
return function OrganizeButton(props) {
|
|
1374
|
-
const [loading, setLoading] = (0, react.useState)(false);
|
|
1375
|
-
const [failed, setFailed] = (0, react.useState)(void 0);
|
|
1376
|
-
const [menuOpen, setMenuOpen] = (0, react.useState)(false);
|
|
1377
|
-
const seq = (0, react.useRef)(0);
|
|
1378
|
-
const inFlight = (0, react.useRef)(false);
|
|
1379
|
-
const flashTimer = (0, react.useRef)(null);
|
|
1380
|
-
const wrapRef = (0, react.useRef)(null);
|
|
1381
|
-
const draft = props.useInput === void 0 ? "" : props.useInput((state) => state.draft) ?? "";
|
|
1382
|
-
const draftRev = props.useInput === void 0 ? 0 : props.useInput((state) => state.draftRev);
|
|
1383
|
-
const phase = props.useInput === void 0 ? "plain" : props.useInput((state) => state.phase);
|
|
1384
|
-
const snap = props.useCard((state) => state);
|
|
1385
|
-
const { templates } = snap;
|
|
1386
|
-
const writeBack = useWriteBack({
|
|
1387
|
-
sessionId: props.sessionId ?? "",
|
|
1388
|
-
actions: props.inputActions,
|
|
1389
|
-
draftRev,
|
|
1390
|
-
phase
|
|
1391
|
-
}, {
|
|
1392
|
-
unavailable: props.t(NO_WRITE_BACK_TITLE_KEY),
|
|
1393
|
-
stale: props.t("organizeWriteBackStale")
|
|
1394
|
-
});
|
|
1395
|
-
useMenuDismiss(menuOpen, wrapRef, () => {
|
|
1396
|
-
setMenuOpen(false);
|
|
1397
|
-
});
|
|
1398
|
-
(0, react.useEffect)(() => () => {
|
|
1399
|
-
seq.current += 1;
|
|
1400
|
-
if (flashTimer.current !== null) clearTimeout(flashTimer.current);
|
|
1401
|
-
}, []);
|
|
1402
|
-
async function handleOrganize(roleText) {
|
|
1403
|
-
const ticket = writeBack.begin();
|
|
1404
|
-
try {
|
|
1405
|
-
await runOrganizeClick({
|
|
1406
|
-
t: props.t,
|
|
1407
|
-
loading,
|
|
1408
|
-
inFlight,
|
|
1409
|
-
seq,
|
|
1410
|
-
prompt: draft,
|
|
1411
|
-
sessionId: props.sessionId ?? "",
|
|
1412
|
-
timeoutMs: organizeFetchTimeoutMs(snap.organizeTimeoutMs),
|
|
1413
|
-
roleText,
|
|
1414
|
-
setLoading,
|
|
1415
|
-
setMenuOpen,
|
|
1416
|
-
setFailed,
|
|
1417
|
-
flashTimer,
|
|
1418
|
-
writeDraft: (content) => {
|
|
1419
|
-
writeBack.commit(content, ticket);
|
|
1420
|
-
}
|
|
1421
|
-
});
|
|
1422
|
-
} finally {
|
|
1423
|
-
writeBack.finish(ticket);
|
|
1424
|
-
}
|
|
1425
|
-
}
|
|
1426
|
-
function openMenu() {
|
|
1427
|
-
if (!snap.fromSettings) loadBuiltinTemplates();
|
|
1428
|
-
setMenuOpen((prev) => !prev);
|
|
1429
|
-
}
|
|
1430
|
-
const badge = organizeBadge(failed, loading, props.t);
|
|
1431
|
-
const replaceable = hasDraftFace(props.inputActions);
|
|
1432
|
-
const canWrite = replaceable && phase === "plain";
|
|
1433
|
-
let errTitle = props.t("organizeIdleTitle");
|
|
1434
|
-
if (failed !== void 0) errTitle = props.t("organizeFailedTitle", { message: failed });
|
|
1435
|
-
else if (!replaceable) errTitle = props.t(NO_WRITE_BACK_TITLE_KEY);
|
|
1436
|
-
else if (phase !== "plain") errTitle = props.t("organizeBusyTitle");
|
|
1437
|
-
const ui = {
|
|
1438
|
-
t: props.t,
|
|
1439
|
-
errTitle,
|
|
1440
|
-
icon: badge.icon,
|
|
1441
|
-
label: badge.label,
|
|
1442
|
-
state: badge.state,
|
|
1443
|
-
errClass: failed === void 0 ? "" : " dpi-btn-err",
|
|
1444
|
-
directItemLabel: props.t("organizeDirectItem"),
|
|
1445
|
-
noTemplatesLabel: props.t("organizeNoTemplates"),
|
|
1446
|
-
builtinRow: builtinStatusRow(snap, props.t),
|
|
1447
|
-
loading,
|
|
1448
|
-
menuOpen,
|
|
1449
|
-
canWrite,
|
|
1450
|
-
templates,
|
|
1451
|
-
onRun: handleOrganize,
|
|
1452
|
-
onToggleMenu: openMenu
|
|
1453
|
-
};
|
|
1454
|
-
return (0, react.createElement)("span", {
|
|
1455
|
-
className: "dpi-wrap dpi-split",
|
|
1456
|
-
ref: wrapRef
|
|
1457
|
-
}, createOrganizeMainButton(ui), createOrganizeCaret(ui), menuOpen ? createOrganizeRoleMenu(ui) : null);
|
|
1458
|
-
};
|
|
1459
|
-
}
|
|
1460
|
-
function createTemplateButton() {
|
|
1461
|
-
return function TemplateButton(props) {
|
|
1462
|
-
const [open, setOpen] = (0, react.useState)(false);
|
|
1463
|
-
const wrapRef = (0, react.useRef)(null);
|
|
1464
|
-
const phase = props.useInput === void 0 ? "plain" : props.useInput((state) => state.phase);
|
|
1465
|
-
const snap = props.useCard((state) => state);
|
|
1466
|
-
const { templates } = snap;
|
|
1467
|
-
useMenuDismiss(open, wrapRef, () => {
|
|
1468
|
-
setOpen(false);
|
|
1469
|
-
});
|
|
1470
|
-
function pick(text) {
|
|
1471
|
-
setOpen(false);
|
|
1472
|
-
const actions = props.inputActions;
|
|
1473
|
-
if (!hasInsertFace(actions)) return;
|
|
1474
|
-
actions.insertText(text, actions.captureInsertion());
|
|
1475
|
-
}
|
|
1476
|
-
const insertable = hasInsertFace(props.inputActions);
|
|
1477
|
-
const canWrite = insertable && phase === "plain";
|
|
1478
|
-
let title = props.t("templatesBrokenTitle");
|
|
1479
|
-
if (canWrite) title = props.t("templatesIdleTitle");
|
|
1480
|
-
else if (insertable) title = props.t("templatesBusyTitle");
|
|
1481
|
-
const grouped = groupTemplatesBy(templates, props.t);
|
|
1482
|
-
const emptyHintLabel = props.t("templatesEmptyHint");
|
|
1483
|
-
const builtinRow = builtinStatusRow(snap, props.t);
|
|
1484
|
-
return (0, react.createElement)("span", {
|
|
1485
|
-
className: "dpi-wrap",
|
|
1486
|
-
ref: wrapRef
|
|
1487
|
-
}, (0, react.createElement)("button", {
|
|
1488
|
-
type: "button",
|
|
1489
|
-
className: "dpi-btn",
|
|
1490
|
-
"aria-label": props.t("templatesAria"),
|
|
1491
|
-
"aria-haspopup": "menu",
|
|
1492
|
-
"aria-expanded": open,
|
|
1493
|
-
title,
|
|
1494
|
-
"data-field": "dpi-template-btn",
|
|
1495
|
-
"data-state": open ? "open" : "idle",
|
|
1496
|
-
disabled: !canWrite,
|
|
1497
|
-
onClick: () => {
|
|
1498
|
-
if (!snap.fromSettings) loadBuiltinTemplates();
|
|
1499
|
-
setOpen((prev) => !prev);
|
|
1500
|
-
}
|
|
1501
|
-
}, (0, react.createElement)(TemplateIcon), props.t("dockTemplatesEntry")), open ? (0, react.createElement)("div", {
|
|
1502
|
-
className: "dpi-menu",
|
|
1503
|
-
role: "menu",
|
|
1504
|
-
"data-field": "dpi-template-menu"
|
|
1505
|
-
}, templates.length === 0 ? builtinRow ?? (0, react.createElement)("div", { className: CLASS_ITEM_EMPTY }, emptyHintLabel) : grouped.map((slot) => (0, react.createElement)("div", {
|
|
1506
|
-
key: slot.group,
|
|
1507
|
-
className: "dpi-group"
|
|
1508
|
-
}, (0, react.createElement)("div", {
|
|
1509
|
-
className: "dpi-grouph",
|
|
1510
|
-
role: "presentation"
|
|
1511
|
-
}, slot.group), slot.items.map((tpl) => (0, react.createElement)("button", {
|
|
1512
|
-
key: tpl.id,
|
|
1513
|
-
type: "button",
|
|
1514
|
-
className: "dpi-item",
|
|
1515
|
-
role: "menuitem",
|
|
1516
|
-
"data-field": "dpi-template-item",
|
|
1517
|
-
title: tpl.description === "" ? tpl.text : tpl.description,
|
|
1518
|
-
onClick: () => {
|
|
1519
|
-
pick(tpl.text);
|
|
1520
|
-
}
|
|
1521
|
-
}, templateItemLabel(tpl)))))) : null);
|
|
1522
|
-
};
|
|
1523
|
-
}
|
|
1524
|
-
function newTemplateId() {
|
|
1525
|
-
let id;
|
|
1526
|
-
try {
|
|
1527
|
-
id = `tpl-${crypto.randomUUID()}`;
|
|
1528
|
-
} catch {
|
|
1529
|
-
id = `tpl-${Date.now().toString(36)}-${Math.floor(Math.random() * 1e9).toString(36)}`;
|
|
1530
|
-
}
|
|
1531
|
-
return id;
|
|
1532
|
-
}
|
|
1533
|
-
function createTemplateRowElement(view) {
|
|
1534
|
-
const { t, rowNum, disabled, values, setters } = view;
|
|
1535
|
-
const indexMark = (0, react.createElement)("span", { className: "dpic-idx" }, `#${rowNum}`);
|
|
1536
|
-
const emojiInput = (0, react.createElement)("input", {
|
|
1537
|
-
type: "text",
|
|
1538
|
-
className: "dpic-emoji dsu-input",
|
|
1539
|
-
value: values.emoji,
|
|
1540
|
-
placeholder: EMOJI_PLACEHOLDER,
|
|
1541
|
-
disabled,
|
|
1542
|
-
"aria-label": t("rowAriaEmoji", { index: rowNum }),
|
|
1543
|
-
title: t("rowEmojiTitle"),
|
|
1544
|
-
onChange: (event) => {
|
|
1545
|
-
setters.emoji(event.target.value);
|
|
1546
|
-
},
|
|
1547
|
-
onBlur: view.onBlur
|
|
1548
|
-
});
|
|
1549
|
-
const nameInput = (0, react.createElement)("input", {
|
|
1550
|
-
type: "text",
|
|
1551
|
-
className: "dpic-name dsu-input",
|
|
1552
|
-
value: values.name,
|
|
1553
|
-
placeholder: t("rowPlaceholderName"),
|
|
1554
|
-
disabled,
|
|
1555
|
-
"aria-label": t("rowAriaName", { index: rowNum }),
|
|
1556
|
-
onChange: (event) => {
|
|
1557
|
-
setters.name(event.target.value);
|
|
1558
|
-
},
|
|
1559
|
-
onBlur: view.onBlur
|
|
1560
|
-
});
|
|
1561
|
-
const groupInput = (0, react.createElement)("input", {
|
|
1562
|
-
type: "text",
|
|
1563
|
-
className: "dpic-group dsu-input",
|
|
1564
|
-
value: values.group,
|
|
1565
|
-
placeholder: t("rowPlaceholderGroup"),
|
|
1566
|
-
disabled,
|
|
1567
|
-
"aria-label": t("rowAriaGroup", { index: rowNum }),
|
|
1568
|
-
title: t("rowGroupTitle"),
|
|
1569
|
-
onChange: (event) => {
|
|
1570
|
-
setters.group(event.target.value);
|
|
1571
|
-
},
|
|
1572
|
-
onBlur: view.onBlur
|
|
1573
|
-
});
|
|
1574
|
-
const deleteButton = (0, react.createElement)("button", {
|
|
1575
|
-
type: "button",
|
|
1576
|
-
className: "dpic-del dsu-btn dsu-btnDanger",
|
|
1577
|
-
disabled,
|
|
1578
|
-
title: t("rowDeleteTitle"),
|
|
1579
|
-
onClick: () => {
|
|
1580
|
-
view.onDelete(view.templateId);
|
|
1581
|
-
}
|
|
1582
|
-
}, t("rowDelete"));
|
|
1583
|
-
const descriptionInput = (0, react.createElement)("input", {
|
|
1584
|
-
type: "text",
|
|
1585
|
-
className: "dpic-desc dsu-input",
|
|
1586
|
-
value: values.description,
|
|
1587
|
-
placeholder: t("rowPlaceholderDescription"),
|
|
1588
|
-
disabled,
|
|
1589
|
-
"aria-label": t("rowAriaDescription", { index: rowNum }),
|
|
1590
|
-
onChange: (event) => {
|
|
1591
|
-
setters.description(event.target.value);
|
|
1592
|
-
},
|
|
1593
|
-
onBlur: view.onBlur
|
|
1594
|
-
});
|
|
1595
|
-
const textArea = (0, react.createElement)("textarea", {
|
|
1596
|
-
className: "dpic-text dsu-input dsu-textarea dsu-mono",
|
|
1597
|
-
value: values.text,
|
|
1598
|
-
rows: 6,
|
|
1599
|
-
placeholder: t("rowPlaceholderText"),
|
|
1600
|
-
disabled,
|
|
1601
|
-
"aria-label": t("rowAriaText", { index: rowNum }),
|
|
1602
|
-
onChange: (event) => {
|
|
1603
|
-
setters.text(event.target.value);
|
|
1604
|
-
},
|
|
1605
|
-
onBlur: view.onBlur
|
|
1606
|
-
});
|
|
1607
|
-
return (0, react.createElement)("div", { className: "dpic-row" }, (0, react.createElement)("div", { className: CLASS_ROW_HEAD }, indexMark, emojiInput, nameInput, groupInput, deleteButton), descriptionInput, textArea);
|
|
1608
|
-
}
|
|
1609
|
-
function TemplateRow(props) {
|
|
1610
|
-
const { t } = props;
|
|
1611
|
-
const [name, setName] = (0, react.useState)(props.template.name);
|
|
1612
|
-
const [emoji, setEmoji] = (0, react.useState)(props.template.emoji);
|
|
1613
|
-
const [group, setGroup] = (0, react.useState)(props.template.group);
|
|
1614
|
-
const [description, setDescription] = (0, react.useState)(props.template.description);
|
|
1615
|
-
const [text, setText] = (0, react.useState)(props.template.text);
|
|
1616
|
-
const rowNum = String(props.index + 1);
|
|
1617
|
-
(0, react.useEffect)(() => {
|
|
1618
|
-
setName(props.template.name);
|
|
1619
|
-
setEmoji(props.template.emoji);
|
|
1620
|
-
setGroup(props.template.group);
|
|
1621
|
-
setDescription(props.template.description);
|
|
1622
|
-
setText(props.template.text);
|
|
1623
|
-
}, [
|
|
1624
|
-
props.template.id,
|
|
1625
|
-
props.template.name,
|
|
1626
|
-
props.template.emoji,
|
|
1627
|
-
props.template.group,
|
|
1628
|
-
props.template.description,
|
|
1629
|
-
props.template.text
|
|
1630
|
-
]);
|
|
1631
|
-
function commit() {
|
|
1632
|
-
const nextName = name.trim();
|
|
1633
|
-
const nextText = text.trim();
|
|
1634
|
-
if (nextName === "" || nextText === "") return;
|
|
1635
|
-
const nextEmoji = emoji.trim();
|
|
1636
|
-
const nextGroup = group.trim();
|
|
1637
|
-
const nextDescription = description.trim();
|
|
1638
|
-
if (nextName === props.template.name && nextEmoji === props.template.emoji && nextGroup === props.template.group && nextDescription === props.template.description && nextText === props.template.text) return;
|
|
1639
|
-
props.onCommit(props.template.id, {
|
|
1640
|
-
name: nextName,
|
|
1641
|
-
emoji: nextEmoji,
|
|
1642
|
-
group: nextGroup,
|
|
1643
|
-
description: nextDescription,
|
|
1644
|
-
text: nextText
|
|
1645
|
-
});
|
|
1646
|
-
}
|
|
1647
|
-
return createTemplateRowElement({
|
|
1648
|
-
t,
|
|
1649
|
-
rowNum,
|
|
1650
|
-
disabled: props.disabled,
|
|
1651
|
-
templateId: props.template.id,
|
|
1652
|
-
values: {
|
|
1653
|
-
name,
|
|
1654
|
-
emoji,
|
|
1655
|
-
group,
|
|
1656
|
-
description,
|
|
1657
|
-
text
|
|
1658
|
-
},
|
|
1659
|
-
setters: {
|
|
1660
|
-
name: setName,
|
|
1661
|
-
emoji: setEmoji,
|
|
1662
|
-
group: setGroup,
|
|
1663
|
-
text: setText,
|
|
1664
|
-
description: setDescription
|
|
1665
|
-
},
|
|
1666
|
-
onBlur: commit,
|
|
1667
|
-
onDelete: props.onDelete
|
|
1668
|
-
});
|
|
1669
|
-
}
|
|
1670
|
-
function ImportPanel(props) {
|
|
1671
|
-
const { t } = props;
|
|
1672
|
-
const [importPath, setImportPath] = (0, react.useState)("");
|
|
1673
|
-
const [importBusy, setImportBusy] = (0, react.useState)(false);
|
|
1674
|
-
const [importMsg, setImportMsg] = (0, react.useState)("");
|
|
1675
|
-
const [importError, setImportError] = (0, react.useState)("");
|
|
1676
|
-
async function onImport() {
|
|
1677
|
-
if (importBusy) return;
|
|
1678
|
-
const target = importPath.trim();
|
|
1679
|
-
setImportBusy(true);
|
|
1680
|
-
setImportError("");
|
|
1681
|
-
setImportMsg("");
|
|
1682
|
-
try {
|
|
1683
|
-
const resp = parseImportResponse(await within(requireReader().importTemplates({
|
|
1684
|
-
path: target,
|
|
1685
|
-
sessionId: ""
|
|
1686
|
-
}), REMOTE_TIMEOUT_MS));
|
|
1687
|
-
if (!resp.ok || resp.entries === void 0) throw new Error(resp.error ?? t("importFailedUnknown"));
|
|
1688
|
-
const usable = resp.entries.length;
|
|
1689
|
-
const declared = countField(resp.count);
|
|
1690
|
-
const count = declared === 0 ? usable : Math.min(declared, usable);
|
|
1691
|
-
if (count === 0) {
|
|
1692
|
-
setImportError(t("importEmpty"));
|
|
1693
|
-
return;
|
|
1694
|
-
}
|
|
1695
|
-
props.onImported(resp.entries);
|
|
1696
|
-
setImportPath("");
|
|
1697
|
-
const truncatedNote = resp.truncated === true ? t("importTruncated") : "";
|
|
1698
|
-
const skipNote = `${formatImportSkips(t, resp.skipped)}${truncatedNote}`;
|
|
1699
|
-
setImportMsg(target.length === 0 ? t("importAllDone", {
|
|
1700
|
-
count,
|
|
1701
|
-
skips: skipNote
|
|
1702
|
-
}) : t("importFromDone", {
|
|
1703
|
-
path: target,
|
|
1704
|
-
count,
|
|
1705
|
-
skips: skipNote
|
|
1706
|
-
}));
|
|
1707
|
-
} catch (error) {
|
|
1708
|
-
setImportError(r(error));
|
|
1709
|
-
} finally {
|
|
1710
|
-
setImportBusy(false);
|
|
1711
|
-
}
|
|
1712
|
-
}
|
|
1713
|
-
const canImport = props.editable && !importBusy;
|
|
1714
|
-
const importPathInput = (0, react.createElement)("input", {
|
|
1715
|
-
type: "text",
|
|
1716
|
-
className: `${CLASS_IMPORT_PATH} dsu-input`,
|
|
1717
|
-
value: importPath,
|
|
1718
|
-
placeholder: t("importPlaceholder"),
|
|
1719
|
-
disabled: !canImport,
|
|
1720
|
-
"aria-label": t("importAriaPath"),
|
|
1721
|
-
onChange: (event) => {
|
|
1722
|
-
setImportPath(event.target.value);
|
|
1723
|
-
},
|
|
1724
|
-
onKeyDown: (event) => {
|
|
1725
|
-
if (event.key === "Enter") onImport();
|
|
1726
|
-
}
|
|
1727
|
-
});
|
|
1728
|
-
const importBtn = (0, react.createElement)("button", {
|
|
1729
|
-
type: "button",
|
|
1730
|
-
className: "dsu-btn",
|
|
1731
|
-
disabled: !canImport,
|
|
1732
|
-
title: t("importBtnTitle"),
|
|
1733
|
-
onClick: onImport
|
|
1734
|
-
}, importBusy ? t("importing") : t("importRoles"));
|
|
1735
|
-
const importMsgEl = importMsg === "" ? null : (0, react.createElement)("div", { className: "dpic-hint" }, importMsg);
|
|
1736
|
-
const importErrorEl = importError === "" ? null : (0, react.createElement)("div", { className: "dpic-hint dpic-err" }, `${t("importErrorPrefix")}${importError}`);
|
|
1737
|
-
const importHintEl = (0, react.createElement)("div", { className: "dpic-hint" }, t("importHint"));
|
|
1738
|
-
return (0, react.createElement)("div", { className: "dpic-importrow" }, (0, react.createElement)("div", { className: CLASS_ROW_HEAD }, importPathInput, importBtn), importMsgEl, importErrorEl, importHintEl);
|
|
1739
|
-
}
|
|
1740
|
-
function AllowRootsPanel(props) {
|
|
1741
|
-
const { t } = props;
|
|
1742
|
-
const [pending, setPending] = (0, react.useState)("");
|
|
1743
|
-
const canAdd = !props.disabled && pending.trim().length > 0;
|
|
1744
|
-
const rowTitle = t("rootsRowTitle");
|
|
1745
|
-
const removeTitle = t("rootsRemoveTitle");
|
|
1746
|
-
const removeLabel = t("rootsRemove");
|
|
1747
|
-
const rows = props.roots.map((root, index) => {
|
|
1748
|
-
const rowAria = t("rootsAriaRow", { index: index + 1 });
|
|
1749
|
-
const rowInput = (0, react.createElement)("input", {
|
|
1750
|
-
type: "text",
|
|
1751
|
-
className: `${CLASS_IMPORT_PATH} dsu-input`,
|
|
1752
|
-
value: root,
|
|
1753
|
-
placeholder: ROOT_PATH_PLACEHOLDER,
|
|
1754
|
-
disabled: props.disabled,
|
|
1755
|
-
"aria-label": rowAria,
|
|
1756
|
-
title: rowTitle,
|
|
1757
|
-
onChange: (event) => {
|
|
1758
|
-
props.onChangeRoot(index, event.target.value);
|
|
1759
|
-
}
|
|
1760
|
-
});
|
|
1761
|
-
const rowButton = (0, react.createElement)("button", {
|
|
1762
|
-
type: "button",
|
|
1763
|
-
className: "dpic-del dsu-btn dsu-btnDanger",
|
|
1764
|
-
disabled: props.disabled,
|
|
1765
|
-
title: removeTitle,
|
|
1766
|
-
onClick: () => {
|
|
1767
|
-
props.onDeleteRoot(index);
|
|
1768
|
-
}
|
|
1769
|
-
}, removeLabel);
|
|
1770
|
-
return (0, react.createElement)("div", {
|
|
1771
|
-
className: CLASS_ROW_HEAD,
|
|
1772
|
-
key: `allow-root-${String(index)}`
|
|
1773
|
-
}, rowInput, rowButton);
|
|
1774
|
-
});
|
|
1775
|
-
const addPlaceholder = t("rootsAddPlaceholder");
|
|
1776
|
-
const addAria = t("rootsAddAria");
|
|
1777
|
-
const addTitle = t("rootsAddTitle");
|
|
1778
|
-
const addLabel = t("rootsAdd");
|
|
1779
|
-
const addInput = (0, react.createElement)("input", {
|
|
1780
|
-
type: "text",
|
|
1781
|
-
className: `${CLASS_IMPORT_PATH} dsu-input`,
|
|
1782
|
-
value: pending,
|
|
1783
|
-
placeholder: addPlaceholder,
|
|
1784
|
-
disabled: props.disabled,
|
|
1785
|
-
"aria-label": addAria,
|
|
1786
|
-
onChange: (event) => {
|
|
1787
|
-
setPending(event.target.value);
|
|
1788
|
-
},
|
|
1789
|
-
onKeyDown: (event) => {
|
|
1790
|
-
if (event.key === "Enter" && canAdd) {
|
|
1791
|
-
props.onAddRoot(pending.trim());
|
|
1792
|
-
setPending("");
|
|
1793
|
-
}
|
|
1794
|
-
}
|
|
1795
|
-
});
|
|
1796
|
-
const addButton = (0, react.createElement)("button", {
|
|
1797
|
-
type: "button",
|
|
1798
|
-
className: "dsu-btn",
|
|
1799
|
-
disabled: !canAdd,
|
|
1800
|
-
title: addTitle,
|
|
1801
|
-
onClick: () => {
|
|
1802
|
-
props.onAddRoot(pending.trim());
|
|
1803
|
-
setPending("");
|
|
1804
|
-
}
|
|
1805
|
-
}, addLabel);
|
|
1806
|
-
const addRow = (0, react.createElement)("div", { className: CLASS_ROW_HEAD }, addInput, addButton);
|
|
1807
|
-
return (0, react.createElement)("div", {
|
|
1808
|
-
className: "dpic-importrow",
|
|
1809
|
-
"data-field": "allow-roots"
|
|
1810
|
-
}, (0, react.createElement)("div", { className: "dpic-hint" }, t("rootsHeading")), rows, addRow, (0, react.createElement)("div", { className: "dpic-hint" }, t("rootsHint")));
|
|
1811
|
-
}
|
|
1812
|
-
/** 工具条:新增角色与恢复默认(保存/撤销交给卡片底部统一的 SaveBar)。 */
|
|
1813
|
-
function CardToolbar(props) {
|
|
1814
|
-
const { foot, editable, busy, confirmReset } = props;
|
|
1815
|
-
return (0, react.createElement)("div", { className: "dpic-toolbar" }, (0, react.createElement)("button", {
|
|
1816
|
-
type: "button",
|
|
1817
|
-
className: "dsu-btn",
|
|
1818
|
-
disabled: !editable,
|
|
1819
|
-
onClick: props.onAdd
|
|
1820
|
-
}, foot.add), (0, react.createElement)("button", {
|
|
1821
|
-
type: "button",
|
|
1822
|
-
className: "dsu-btn dsu-btnDanger",
|
|
1823
|
-
disabled: !editable || busy,
|
|
1824
|
-
title: foot.resetTitle,
|
|
1825
|
-
onClick: props.onReset
|
|
1826
|
-
}, confirmReset ? foot.resetConfirm : foot.reset));
|
|
1827
|
-
}
|
|
1828
|
-
function cardFootLabels(t) {
|
|
1829
|
-
return {
|
|
1830
|
-
add: t("addTemplate"),
|
|
1831
|
-
save: t("save"),
|
|
1832
|
-
saving: t("saving"),
|
|
1833
|
-
revert: t("revert"),
|
|
1834
|
-
reset: t("resetDefault"),
|
|
1835
|
-
resetConfirm: t("resetConfirm", { seconds: RESET_CONFIRM_MS / 1e3 }),
|
|
1836
|
-
saveTitleDirty: t("saveTitleDirty"),
|
|
1837
|
-
saveTitleClean: t("saveTitleClean"),
|
|
1838
|
-
resetTitle: t("resetTitle")
|
|
1839
|
-
};
|
|
1840
|
-
}
|
|
1841
|
-
function cardStatusHint(snap, t) {
|
|
1842
|
-
let hint;
|
|
1843
|
-
if (snap.ready) hint = snap.writable ? "" : t("statusReadOnly");
|
|
1844
|
-
else hint = t("statusNotReady");
|
|
1845
|
-
return hint;
|
|
1846
|
-
}
|
|
1847
|
-
function createDraftActions(t, draft, rootsDraft, setDraft, setRootsDraft) {
|
|
1848
|
-
function onCommit(id, fields) {
|
|
1849
|
-
setDraft(draft.map((tpl) => tpl.id === id ? {
|
|
1850
|
-
...tpl,
|
|
1851
|
-
...fields
|
|
1852
|
-
} : tpl));
|
|
1853
|
-
}
|
|
1854
|
-
function onDelete(id) {
|
|
1855
|
-
setDraft(draft.filter((tpl) => tpl.id !== id));
|
|
1856
|
-
}
|
|
1857
|
-
function onAdd() {
|
|
1858
|
-
setDraft([...draft, {
|
|
1859
|
-
id: newTemplateId(),
|
|
1860
|
-
name: t("newTemplateName", { index: draft.length + 1 }),
|
|
1861
|
-
description: "",
|
|
1862
|
-
text: "",
|
|
1863
|
-
group: "",
|
|
1864
|
-
emoji: ""
|
|
1865
|
-
}]);
|
|
1866
|
-
}
|
|
1867
|
-
function onImported(incoming) {
|
|
1868
|
-
setDraft((prev) => mergeImportedTemplates(prev, incoming));
|
|
1869
|
-
}
|
|
1870
|
-
function onRootChange(index, value) {
|
|
1871
|
-
setRootsDraft(rootsDraft.map((root, idx) => idx === index ? value : root));
|
|
1872
|
-
}
|
|
1873
|
-
function onRootDelete(index) {
|
|
1874
|
-
setRootsDraft(rootsDraft.filter((_root, idx) => idx !== index));
|
|
1875
|
-
}
|
|
1876
|
-
function onRootAdd(value) {
|
|
1877
|
-
setRootsDraft([...rootsDraft, value]);
|
|
1878
|
-
}
|
|
1879
|
-
return {
|
|
1880
|
-
onCommit,
|
|
1881
|
-
onDelete,
|
|
1882
|
-
onAdd,
|
|
1883
|
-
onImported,
|
|
1884
|
-
onRootChange,
|
|
1885
|
-
onRootDelete,
|
|
1886
|
-
onRootAdd
|
|
1887
|
-
};
|
|
1888
|
-
}
|
|
1889
|
-
function verifyTemplatesPersisted(t, persisted, expected, action, opts) {
|
|
1890
|
-
const problem = persistError(t, persisted, expected, t(action), opts);
|
|
1891
|
-
if (problem !== void 0) throw new Error(problem);
|
|
1892
|
-
}
|
|
1893
|
-
function verifyRootsPersisted(t, persisted, expected) {
|
|
1894
|
-
const problem = rootsPersistError(t, persisted, expected, t("save"));
|
|
1895
|
-
if (problem !== void 0) throw new Error(problem);
|
|
1896
|
-
}
|
|
1897
|
-
function createPersistActions(args) {
|
|
1898
|
-
const { t, editable, dirty, rootsDirty, anythingDirty, confirmReset, templates, allowRoots, draft, rootsDraft, set, unset, readBack, setDraft, setDraftFor, setRootsDraft, setBusy, setSaveError, setConfirmReset } = args;
|
|
1899
|
-
function reportError(err) {
|
|
1900
|
-
console.error("[dir-prep-organize] templates settings write failed:", err);
|
|
1901
|
-
setSaveError(r(err));
|
|
1902
|
-
}
|
|
1903
|
-
async function onSave() {
|
|
1904
|
-
if (!editable || !anythingDirty) return;
|
|
1905
|
-
setBusy(true);
|
|
1906
|
-
setSaveError("");
|
|
1907
|
-
const next = sanitizeTemplateList(draft);
|
|
1908
|
-
const nextRoots = sanitizeAllowRoots(rootsDraft);
|
|
1909
|
-
try {
|
|
1910
|
-
if (dirty) {
|
|
1911
|
-
await set("templates", next);
|
|
1912
|
-
verifyTemplatesPersisted(t, readBack(), next, "save");
|
|
1913
|
-
}
|
|
1914
|
-
if (rootsDirty) {
|
|
1915
|
-
await set("importAllowRoots", nextRoots);
|
|
1916
|
-
verifyRootsPersisted(t, readBack(), nextRoots);
|
|
1917
|
-
}
|
|
1918
|
-
setBusy(false);
|
|
1919
|
-
setDraft((prev) => prev === draft ? next : prev);
|
|
1920
|
-
setRootsDraft((prev) => prev === rootsDraft ? nextRoots : prev);
|
|
1921
|
-
} catch (error) {
|
|
1922
|
-
setBusy(false);
|
|
1923
|
-
reportError(error);
|
|
1924
|
-
}
|
|
1925
|
-
}
|
|
1926
|
-
function onDiscard() {
|
|
1927
|
-
setDraft(templates);
|
|
1928
|
-
setRootsDraft(allowRoots);
|
|
1929
|
-
setSaveError("");
|
|
1930
|
-
}
|
|
1931
|
-
function onReset() {
|
|
1932
|
-
if (!confirmReset) {
|
|
1933
|
-
setConfirmReset(true);
|
|
1934
|
-
return;
|
|
1935
|
-
}
|
|
1936
|
-
setConfirmReset(false);
|
|
1937
|
-
setBusy(true);
|
|
1938
|
-
(async () => {
|
|
1939
|
-
try {
|
|
1940
|
-
const builtin = await loadBuiltinTemplates();
|
|
1941
|
-
if (builtin.phase !== "ready") throw new Error(builtin.error);
|
|
1942
|
-
await unset("templates");
|
|
1943
|
-
verifyTemplatesPersisted(t, readBack(), builtin.list, "resetDefault", { treatEmptyAsReverted: true });
|
|
1944
|
-
setSaveError("");
|
|
1945
|
-
setDraft(builtin.list);
|
|
1946
|
-
setDraftFor(builtin.list);
|
|
1947
|
-
setRootsDraft(allowRoots);
|
|
1948
|
-
} catch (error) {
|
|
1949
|
-
reportError(error);
|
|
1950
|
-
} finally {
|
|
1951
|
-
setBusy(false);
|
|
1952
|
-
}
|
|
1953
|
-
})();
|
|
1954
|
-
}
|
|
1955
|
-
return {
|
|
1956
|
-
onSave,
|
|
1957
|
-
onDiscard,
|
|
1958
|
-
onReset
|
|
1959
|
-
};
|
|
1960
|
-
}
|
|
1961
|
-
/** 卡片正文:状态提示 + 工具条 + 角色行表 + 导入区 + 允许目录区 + 保存条。 */
|
|
1962
|
-
function createCardBody(view) {
|
|
1963
|
-
const { t, statusHint, draft, rootsDraft, foot, editable, anythingDirty, busy, confirmReset, saveError } = view;
|
|
1964
|
-
const { onCommit, onDelete, onAdd, onImported, onRootChange, onRootDelete, onRootAdd } = view.draftActions;
|
|
1965
|
-
const { onSave, onDiscard, onReset } = view.persistActions;
|
|
1966
|
-
const footHint = (0, react.createElement)("p", { className: "dpic-hint" }, t("footHint"));
|
|
1967
|
-
const saveBar = (0, react.createElement)(w, {
|
|
1968
|
-
dirty: anythingDirty,
|
|
1969
|
-
busy,
|
|
1970
|
-
writable: editable,
|
|
1971
|
-
error: saveError === "" ? null : `${t("saveFailed")}${saveError}`,
|
|
1972
|
-
saveLabel: t("save"),
|
|
1973
|
-
savingLabel: t("saving"),
|
|
1974
|
-
revertLabel: t("revert"),
|
|
1975
|
-
dirtyLabel: t("saveTitleDirty"),
|
|
1976
|
-
cleanLabel: t("saveTitleClean"),
|
|
1977
|
-
readOnlyLabel: t("statusReadOnly"),
|
|
1978
|
-
onSave: () => {
|
|
1979
|
-
onSave();
|
|
1980
|
-
},
|
|
1981
|
-
onDiscard
|
|
1982
|
-
});
|
|
1983
|
-
return (0, react.createElement)(u, null, statusHint === "" ? null : (0, react.createElement)("p", { className: "dpic-hint" }, statusHint), (0, react.createElement)(d, {
|
|
1984
|
-
title: t("rolesSection"),
|
|
1985
|
-
hint: t("rolesHint")
|
|
1986
|
-
}, (0, react.createElement)(CardToolbar, {
|
|
1987
|
-
foot,
|
|
1988
|
-
editable,
|
|
1989
|
-
busy,
|
|
1990
|
-
confirmReset,
|
|
1991
|
-
onAdd,
|
|
1992
|
-
onReset
|
|
1993
|
-
}), draft.map((tpl, idx) => (0, react.createElement)(TemplateRow, {
|
|
1994
|
-
key: tpl.id,
|
|
1995
|
-
t,
|
|
1996
|
-
index: idx,
|
|
1997
|
-
template: tpl,
|
|
1998
|
-
disabled: !editable || busy,
|
|
1999
|
-
onCommit,
|
|
2000
|
-
onDelete
|
|
2001
|
-
})), (0, react.createElement)(ImportPanel, {
|
|
2002
|
-
t,
|
|
2003
|
-
editable: editable && !busy,
|
|
2004
|
-
onImported
|
|
2005
|
-
}), (0, react.createElement)(AllowRootsPanel, {
|
|
2006
|
-
t,
|
|
2007
|
-
roots: rootsDraft,
|
|
2008
|
-
disabled: !editable || busy,
|
|
2009
|
-
onChangeRoot: onRootChange,
|
|
2010
|
-
onDeleteRoot: onRootDelete,
|
|
2011
|
-
onAddRoot: onRootAdd
|
|
2012
|
-
}), footHint), saveBar);
|
|
2013
|
-
}
|
|
2014
|
-
function TemplatesCard(props) {
|
|
2015
|
-
const { t } = props;
|
|
2016
|
-
const [confirmReset, setConfirmReset] = (0, react.useState)(false);
|
|
2017
|
-
const [saveError, setSaveError] = (0, react.useState)("");
|
|
2018
|
-
const [busy, setBusy] = (0, react.useState)(false);
|
|
2019
|
-
const foot = cardFootLabels(t);
|
|
2020
|
-
const snap = props.useCard((state) => state);
|
|
2021
|
-
const { templates } = snap;
|
|
2022
|
-
const editable = snap.ready && snap.writable;
|
|
2023
|
-
const statusHint = cardStatusHint(snap, t);
|
|
2024
|
-
(0, react.useEffect)(() => {
|
|
2025
|
-
if (!snap.fromSettings) loadBuiltinTemplates();
|
|
2026
|
-
}, [snap.fromSettings]);
|
|
2027
|
-
const [draft, setDraft] = (0, react.useState)(templates);
|
|
2028
|
-
const [draftFor, setDraftFor] = (0, react.useState)(templates);
|
|
2029
|
-
(0, react.useEffect)(() => {
|
|
2030
|
-
if (draftFor !== templates) {
|
|
2031
|
-
setDraftFor(templates);
|
|
2032
|
-
setDraft((prev) => JSON.stringify(prev) === JSON.stringify(draftFor) ? templates : prev);
|
|
2033
|
-
}
|
|
2034
|
-
}, [templates, draftFor]);
|
|
2035
|
-
(0, react.useEffect)(() => {
|
|
2036
|
-
let timer;
|
|
2037
|
-
if (confirmReset) timer = setTimeout(() => {
|
|
2038
|
-
setConfirmReset(false);
|
|
2039
|
-
}, RESET_CONFIRM_MS);
|
|
2040
|
-
return () => {
|
|
2041
|
-
if (timer !== void 0) clearTimeout(timer);
|
|
2042
|
-
};
|
|
2043
|
-
}, [confirmReset]);
|
|
2044
|
-
const [rootsDraft, setRootsDraft] = (0, react.useState)(snap.allowRoots);
|
|
2045
|
-
const [rootsFor, setRootsFor] = (0, react.useState)(snap.allowRoots);
|
|
2046
|
-
(0, react.useEffect)(() => {
|
|
2047
|
-
if (rootsFor !== snap.allowRoots) {
|
|
2048
|
-
setRootsFor(snap.allowRoots);
|
|
2049
|
-
setRootsDraft((prev) => JSON.stringify(prev) === JSON.stringify(rootsFor) ? snap.allowRoots : prev);
|
|
2050
|
-
}
|
|
2051
|
-
}, [rootsFor, snap.allowRoots]);
|
|
2052
|
-
const dirty = JSON.stringify(draft) !== JSON.stringify(templates);
|
|
2053
|
-
const rootsDirty = JSON.stringify(sanitizeAllowRoots(rootsDraft)) !== JSON.stringify(snap.allowRoots);
|
|
2054
|
-
const anythingDirty = dirty || rootsDirty;
|
|
2055
|
-
return createCardBody({
|
|
2056
|
-
t,
|
|
2057
|
-
statusHint,
|
|
2058
|
-
draft,
|
|
2059
|
-
rootsDraft,
|
|
2060
|
-
foot,
|
|
2061
|
-
editable,
|
|
2062
|
-
anythingDirty,
|
|
2063
|
-
busy,
|
|
2064
|
-
confirmReset,
|
|
2065
|
-
saveError,
|
|
2066
|
-
draftActions: createDraftActions(t, draft, rootsDraft, setDraft, setRootsDraft),
|
|
2067
|
-
persistActions: createPersistActions({
|
|
2068
|
-
t,
|
|
2069
|
-
editable,
|
|
2070
|
-
dirty,
|
|
2071
|
-
rootsDirty,
|
|
2072
|
-
anythingDirty,
|
|
2073
|
-
confirmReset,
|
|
2074
|
-
templates,
|
|
2075
|
-
allowRoots: snap.allowRoots,
|
|
2076
|
-
draft,
|
|
2077
|
-
rootsDraft,
|
|
2078
|
-
set: props.set,
|
|
2079
|
-
unset: props.unset,
|
|
2080
|
-
readBack: props.readBack,
|
|
2081
|
-
setDraft,
|
|
2082
|
-
setDraftFor,
|
|
2083
|
-
setRootsDraft,
|
|
2084
|
-
setBusy,
|
|
2085
|
-
setSaveError,
|
|
2086
|
-
setConfirmReset
|
|
2087
|
-
})
|
|
2088
|
-
});
|
|
2089
|
-
}
|
|
2090
|
-
const inject = [
|
|
2091
|
-
"slots",
|
|
2092
|
-
"configForms",
|
|
2093
|
-
"locale"
|
|
2094
|
-
];
|
|
2095
|
-
/** 注入输入框右侧的「润色」「模板」两个按钮(两枚共用同一份 store 与 t)。
|
|
2096
|
-
*
|
|
2097
|
-
* 一次 inject 挂两枚:它们的 inject 面完全相同(都只要 store 这一份 card hook),
|
|
2098
|
-
* 分成两次 inject 会让宿主多跑一轮 occupant 装配,而拆开的唯一好处只是少几行。 */
|
|
2099
|
-
function injectDock(ctx, store, t) {
|
|
2100
|
-
const hooks = () => ({ hooks: { card: store } });
|
|
2101
|
-
ctx.slots.inject(SLOT_INPUT_RIGHT, () => {
|
|
2102
|
-
const unregisterOrganize = ctx.slots.register({
|
|
2103
|
-
name: SLOT_INPUT_RIGHT,
|
|
2104
|
-
id: NS,
|
|
2105
|
-
order: 99,
|
|
2106
|
-
label: () => t("dockOrganizeEntry"),
|
|
2107
|
-
locale: NS,
|
|
2108
|
-
inject: hooks
|
|
2109
|
-
}, createOrganizeButton());
|
|
2110
|
-
const unregisterTemplates = ctx.slots.register({
|
|
2111
|
-
name: SLOT_INPUT_RIGHT,
|
|
2112
|
-
id: `${NS}-templates`,
|
|
2113
|
-
order: 100,
|
|
2114
|
-
label: () => t("dockTemplatesEntry"),
|
|
2115
|
-
locale: NS,
|
|
2116
|
-
inject: hooks
|
|
2117
|
-
}, createTemplateButton());
|
|
2118
|
-
return () => {
|
|
2119
|
-
unregisterOrganize();
|
|
2120
|
-
unregisterTemplates();
|
|
2121
|
-
};
|
|
2122
|
-
});
|
|
2123
|
-
}
|
|
2124
|
-
/** 注入设置页的「角色库」卡(插件自带卡片,宿主不再生成自动表单页)。
|
|
2125
|
-
* 这张卡管的就是「模板」下拉与「润色」▾ 共用的那一份列表。
|
|
2126
|
-
*
|
|
2127
|
-
* scope 作为参数传进来而不是就地取:卡片 inject 闭包里的 set/unset 必须落到
|
|
2128
|
-
* apply 期取的那**同一份**配置表单上(中途再 get 一次未必是同一个 provider 对象),
|
|
2129
|
-
* 而 apply 需要它同时喂给 store 与本函数,故显式传参而不是藏进模块级状态。 */
|
|
2130
|
-
function injectCard(ctx, store, t, scope) {
|
|
2131
|
-
ctx.slots.inject("plugins.bundle.config", () => {
|
|
2132
|
-
return ctx.slots.register({
|
|
2133
|
-
name: "plugins.bundle.config",
|
|
2134
|
-
key: BUNDLE_PKG,
|
|
2135
|
-
inject: () => ({
|
|
2136
|
-
t,
|
|
2137
|
-
hooks: { card: store },
|
|
2138
|
-
set: (field, value) => scope.set(field, value),
|
|
2139
|
-
unset: (field) => scope.unset(field),
|
|
2140
|
-
readBack: () => store.readBack()
|
|
2141
|
-
})
|
|
2142
|
-
}, TemplatesCard);
|
|
2143
|
-
});
|
|
2144
|
-
}
|
|
2145
|
-
function apply(ctx) {
|
|
2146
|
-
const reader = createDirPrepReader(ctx);
|
|
2147
|
-
dirPrepReader = reader;
|
|
2148
|
-
ctx.effect(() => () => {
|
|
2149
|
-
if (dirPrepReader === reader) dirPrepReader = void 0;
|
|
2150
|
-
}, "dir-prep-organize: remote reader");
|
|
2151
|
-
ctx.effect(() => {
|
|
2152
|
-
const tag = document.createElement("style");
|
|
2153
|
-
tag.id = "dir-prep-organize-css";
|
|
2154
|
-
tag.textContent = `${CARD_STYLES}\n${c}`;
|
|
2155
|
-
document.head.append(tag);
|
|
2156
|
-
return () => {
|
|
2157
|
-
tag.remove();
|
|
2158
|
-
};
|
|
2159
|
-
}, "dir-prep-organize: styles");
|
|
2160
|
-
const scope = ctx.configForms.get(NS);
|
|
2161
|
-
const store = templatesStore(scope);
|
|
2162
|
-
ctx.effect(() => ctx.locale.register(NS, UI_MESSAGES), "dir-prep-organize-card: locale dictionaries");
|
|
2163
|
-
const t = ctx.locale.bind(NS);
|
|
2164
|
-
injectDock(ctx, store, t);
|
|
2165
|
-
injectCard(ctx, store, t, scope);
|
|
2166
|
-
}
|
|
2167
|
-
exports.apply = apply;
|
|
2168
|
-
exports.builtinTemplatesSnapshot = builtinTemplatesSnapshot;
|
|
2169
|
-
exports.formatContextSummary = formatContextSummary;
|
|
2170
|
-
exports.formatImportSkips = formatImportSkips;
|
|
2171
|
-
exports.inject = inject;
|
|
2172
|
-
exports.loadBuiltinTemplates = loadBuiltinTemplates;
|
|
2173
|
-
exports.parseContextResponse = parseContextResponse;
|
|
2174
|
-
exports.parseOrganizeResponse = parseOrganizeResponse;
|
|
2175
|
-
exports.persistError = persistError;
|
|
2176
|
-
exports.resetBuiltinTemplates = resetBuiltinTemplates;
|
|
2177
|
-
exports.rootsPersistError = rootsPersistError;
|
|
2178
|
-
exports.setDirPrepReader = setDirPrepReader;
|
|
2179
|
-
exports.subscribeBuiltinTemplates = subscribeBuiltinTemplates;
|
|
8
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("react"),t=require("@jayyuen66/dsh-plugin-shared/client"),n=require("zod");function r(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}new TextEncoder,new TextDecoder;function i(e,t){if(t<1||Number.isNaN(t))return``;let n=0,r=0;for(let i of e){if(r>=t)break;n+=i.length,r+=1}return e.slice(0,n)}function a(e,t,n){if(e!==``&&!n.has(e))return e;let r=`tpl-${t}`;for(;n.has(r);)r=`${r}-${t}`;return r}function o(e,t){let n=new Set(e.map(({id:e})=>e)),r=[...e];for(let{id:e,...i}of t){let t=e.trim();if(t===``)t=a(``,r.length,n);else if(n.has(t))for(t=`${t}-i`;n.has(t);)t=`${t}i`;n.add(t),r.push({...i,id:t})}return r}function s(e){return typeof e==`string`?e.trim():``}function c(e,t,n){let o;if(r(e)){let{id:r,name:c,description:l,text:u,group:d,emoji:f}=e,p=s(c),m=s(u);if(p!==``&&m!==``){let e=a(s(r),t,n);n.add(e),o={id:e,name:p,description:s(l),text:m,group:s(d),emoji:i(s(f),12)}}}return o}function l(e){if(!Array.isArray(e))return[];let t=new Set,n=[];for(let[r,i]of e.entries()){let e=c(i,r,t);e!==void 0&&n.push(e)}return n}const u=String.fromCodePoint(92),d=/^[A-Za-z]:$/u,f=/[/\\]+$/u;function p(e){let t=d.test(e.slice(0,2))&&(e[2]===`/`||e[2]===u);return e.startsWith(`/`)||t||e.startsWith(u+u)}function m(e){let t=e.replace(f,``);return t.length===0||d.test(t)?e:t}function h(e){let t=[];if(Array.isArray(e))for(let n of e){let e=typeof n==`string`?n.trim():``,r=m(e);e.length>0&&p(r)&&!t.includes(r)&&t.push(r)}return t}const g=2147483647;function _(e){return typeof e==`number`&&Number.isFinite(e)&&e>0}function v(e){let t=e.organizeTimeoutMs;return _(t)?Math.min(Math.max(Math.trunc(t),1),g):void 0}function y(e){let t=_(e)?e:12e4;return Math.trunc(Math.min(Math.max(Math.min(t,2147478647)+5e3,1),g))}const b={zh:{rolesSection:`角色库`,rolesHint:`输入框「模板」下拉与「润色」▾ 角色菜单共用这一份列表,空表即回落到内置精选角色集(生成自插件 agents/ 角色库)。留空点「导入角色」可一键导入内置全部;填路径则按「会话 cwd + 内置角色库 + 下方导入允许目录」放行。编辑后点「保存」生效,重启不丢。`,statusReadOnly:`设置源不可写:编辑已禁用;下拉仍按当前列表生效。`,statusNotReady:`设置源未就绪:显示当前生效列表,就绪后可编辑。`,addTemplate:`+ 新增模板`,saveTitleDirty:`写入模板列表与导入允许目录(模板生效于新拉开的菜单)`,saveTitleClean:`无未保存修改`,saving:`保存中…`,save:`保存`,revert:`撤销`,resetTitle:`丢弃模板列表的全部自定义,回到内置默认(不影响已登记的导入允许目录;两步确认,点击即生效)`,resetConfirm:`确认恢复默认?再点一次({seconds} 秒内)`,resetDefault:`恢复默认`,footHint:`说明:编辑/新增/删除先在本地暂存,点「保存」一次写入(模板与导入允许目录同理);清空名称或正文的条目保存时会被剔除(删除请用行内「删除」);恢复默认只回滚模板列表。`,saveFailed:`保存失败:`,newTemplateName:`新模板 {index}`,persistUnconfirmed:`{action}结果不可确认:设置源未就绪(宿主未回读成功)`,persistRejected:`{action}未生效:宿主拒绝了本次写入(当前 revision {revision})`,rowAriaEmoji:`模板 {index} 视觉标记`,rowEmojiTitle:`可选视觉标记(emoji 或短文本),下拉菜单显示在名称前`,rowPlaceholderName:`菜单显示名`,rowAriaName:`模板 {index} 名称`,rowPlaceholderGroup:`分组`,rowAriaGroup:`模板 {index} 分组`,rowGroupTitle:`下拉按此分组展示;留空归入「通用」`,rowDeleteTitle:`删除此模板`,rowDelete:`删除`,rowPlaceholderDescription:`一句话介绍(下拉悬停时显示;如:威胁建模与 OWASP 代码审计)`,rowAriaDescription:`模板 {index} 一句话介绍`,rowPlaceholderText:`模板正文(点选后插入输入框,随你的消息一起发给模型)`,rowAriaText:`模板 {index} 正文`,importFailedUnknown:`导入失败(未知错误)`,importEmpty:`目录下没有符合条件的角色 .md(需含 name 的 frontmatter)`,importAllDone:`已从内置角色库导入全部 {count} 条{skips},编辑后点「保存」生效`,importFromDone:`已从 {path} 导入 {count} 条{skips},编辑后点「保存」生效`,importTruncated:`(回执标记本次导入有内容被上限截断)`,importPlaceholder:`留空 = 导入内置全部角色;或填 .md / 目录路径(须在允许根内)`,importAriaPath:`角色导入路径`,importBtnTitle:`留空 = 一键导入内置全部角色;填路径 = 导入该 .md 或目录下的角色(路径须在允许根内)`,importing:`导入中…`,importRoles:`导入角色`,importErrorPrefix:`导入失败:`,importHint:`导入说明:留空导入内置角色库全部(agents/);填路径时只放行「会话 cwd」「内置角色库 agents/」与下方「导入允许目录」之内的路径——绝对路径默认拒绝,越界会直接报「导入路径越界」并回显解析后的路径。本卡没有会话上下文,故只能填内置库或已登记目录里的路径。目录扫描顶层 + 一层子目录 .md(跳过隐藏项),文件须含 name 的 frontmatter,正文将提炼为模板正文。`,skipDeeper:`{count} 个更深层 .md 未扫描(导入只扫两层)`,skipTooLarge:`{count} 个文件超字节上限被跳过`,skipUnreadable:`{count} 个文件读取失败`,skipUnnamed:`{count} 个非角色文件(frontmatter 无 name)`,skipEscaped:`{count} 个文件的真实目标在允许根之外(符号链接),已按安全策略排除`,skipSummary:`({list})`,skipSeparator:`,`,rootsHeading:`导入允许目录(importAllowRoots)`,rootsAriaRow:`导入允许目录 {index}`,rootsRowTitle:`该目录(含其子目录)内的角色 .md 可经「导入角色」读取`,rootsRemoveTitle:`移除此允许目录`,rootsRemove:`移除`,rootsAddPlaceholder:`新增一个允许导入的目录绝对路径`,rootsAddAria:`新增导入允许目录`,rootsAddTitle:`加入待保存的允许目录列表`,rootsAdd:`登记目录`,rootsHint:`绝对路径默认拒绝:只有「当前会话 cwd」「插件内置角色库 agents/」与本列表登记的目录之内可导入。设置页没有会话上下文,卡上填的路径必须落在内置库或本列表内。改完点底部「保存」生效。`,dockOrganizeEntry:`润色`,dockTemplatesEntry:`模板`,organizeIdle:`润色`,organizeLoading:`润色中`,organizeFailedShort:`失败`,organizeIdleTitle:`结合当前目录润色输入框内容(主键直接润色;▾ 可选角色风格)`,organizeFailedTitle:`润色失败:{message}`,organizeErrContextFailed:`目录上下文读取失败:{message}`,organizeErrModelFailed:`读取模型失败:{message}`,organizeErrEmpty:`输入框为空,无内容可润色`,organizeErrTimeout:`润色请求超时:宿主没有在时限内回报结果`,organizeErrUnknownReason:`未知错误`,organizeErrUnknown:`润色失败(未知错误)`,organizeCaretAria:`选择润色的角色风格`,organizeCaretTitle:`按某个角色的风格润色(角色来自下方模板库)`,organizeMainAria:`润色输入框内容`,organizeDirectItem:`直接润色(默认,不带角色)`,organizeNoTemplates:`无模板可选作角色风格`,organizeRoleItem:`以「{name}」的风格润色`,organizeWriteBackUnavailable:`输入框动作不可用,无法写回`,organizeWriteBackStale:`输入框内容已变化,润色结果未写回`,organizeBusyTitle:`输入框正在提交,暂不能润色`,templatesIdleTitle:`选择一条模板插入光标处(按分组展示)`,templatesBrokenTitle:`输入框动作不可用,无法插入`,templatesBusyTitle:`输入框正在提交,暂不能插入模板`,templatesGroupCommon:`通用`,templatesAria:`插入模板`,templatesEmptyHint:`无模板:在设置页「角色库」中添加或恢复默认`,builtinLoading:`正在载入内置角色模板…`,builtinFailed:`内置模板加载失败:{message}`,builtinRetry:`重试`},en:{rolesSection:`Role library`,rolesHint:`The input-box "Template" dropdown and the "Polish" ▾ role menu share this one list; an empty list falls back to the built-in curated role set (generated from this plugin's agents/ role library). Leave the path empty and press "Import roles" to import the whole built-in library; an explicit path is allowed within "session cwd + built-in role library + the import allowed directories below". Press "Save" after editing — it survives restarts.`,statusReadOnly:`Settings source is read-only: editing is disabled; the dropdown still uses the current list.`,statusNotReady:`Settings source is not ready yet: showing the list currently in effect, editing unlocks once it is ready.`,addTemplate:`+ Add template`,saveTitleDirty:`Write the template list and the import allowed directories (templates take effect in newly opened menus)`,saveTitleClean:`No unsaved changes`,saving:`Saving…`,save:`Save`,revert:`Revert`,resetTitle:`Discard every customization of the template list and go back to the built-in defaults (registered import directories are untouched; two-step confirm, takes effect on the next click)`,resetConfirm:`Restore defaults? Click once more (within {seconds}s)`,resetDefault:`Restore defaults`,footHint:`Note: edits, additions and deletions are staged locally first and written in one go when you press "Save" (same for templates and import directories); entries whose name or body is empty are dropped on save (use the inline "Delete" instead); "Restore defaults" only rolls back the template list.`,saveFailed:`Save failed: `,newTemplateName:`New template {index}`,persistUnconfirmed:`{action} cannot be confirmed: the settings source is not ready (host read-back failed)`,persistRejected:`{action} did not take effect: the host rejected this write (current revision {revision})`,rowAriaEmoji:`Visual mark of template {index}`,rowEmojiTitle:`Optional visual mark (emoji or short text), shown before the name in the dropdown`,rowPlaceholderName:`Menu display name`,rowAriaName:`Name of template {index}`,rowPlaceholderGroup:`Group`,rowAriaGroup:`Group of template {index}`,rowGroupTitle:`The dropdown groups entries by this value; leave empty to fall into "General"`,rowDeleteTitle:`Delete this template`,rowDelete:`Delete`,rowPlaceholderDescription:`One-line intro (shown on dropdown hover; e.g. threat modelling and OWASP code auditing)`,rowAriaDescription:`One-line intro of template {index}`,rowPlaceholderText:`Template body (inserted into the input box and sent to the model with your message)`,rowAriaText:`Body of template {index}`,importFailedUnknown:`Import failed (unknown error)`,importEmpty:`No qualifying role .md in that directory (frontmatter must contain name)`,importAllDone:`Imported all {count} entries from the built-in role library{skips}; press "Save" after editing`,importFromDone:`Imported {count} entries from {path}{skips}; press "Save" after editing`,importTruncated:` (the reply flagged some content as truncated by a limit)`,importPlaceholder:`Empty = import every built-in role; or a .md / directory path (must be inside an allowed root)`,importAriaPath:`Role import path`,importBtnTitle:`Empty imports the whole built-in role library in one click; a path imports that .md or the roles in that directory (must be inside an allowed root)`,importing:`Importing…`,importRoles:`Import roles`,importErrorPrefix:`Import failed: `,importHint:`Import notes: an empty path imports the whole built-in role library (agents/); an explicit path is only allowed inside "session cwd", "built-in role library agents/" and the "import allowed directories" below — absolute paths are refused by default, and anything out of bounds reports "import path out of bounds" with the resolved path echoed back. This card has no session context, so explicit paths must live in the built-in library or a registered directory. Directory scans cover the top level plus one level of sub-directory .md files (hidden entries skipped), each file needs a frontmatter name, and its body is condensed into the template text.`,skipDeeper:`{count} deeper .md files were not scanned (imports cover two levels)`,skipTooLarge:`{count} files were skipped for exceeding the byte limit`,skipUnreadable:`{count} files could not be read`,skipUnnamed:`{count} non-role files (no name in frontmatter)`,skipEscaped:`{count} files whose real target lies outside the allowed roots (symlinks) were excluded by policy`,skipSummary:` ({list})`,skipSeparator:`, `,rootsHeading:`Import allowed directories (importAllowRoots)`,rootsAriaRow:`Import allowed directory {index}`,rootsRowTitle:`Role .md files inside this directory (and its subdirectories) can be read by "Import roles"`,rootsRemoveTitle:`Remove this allowed directory`,rootsRemove:`Remove`,rootsAddPlaceholder:`Absolute path of a directory newly allowed for imports`,rootsAddAria:`Add an import allowed directory`,rootsAddTitle:`Add it to the pending allowed-directory list`,rootsAdd:`Register directory`,rootsHint:`Absolute paths are refused by default: imports only succeed inside "the current session cwd", "the plugin's built-in role library agents/" and the directories registered below. The settings page has no session context, so a path typed here must fall inside the built-in library or this list. Press "Save" at the bottom to apply.`,dockOrganizeEntry:`Polish`,dockTemplatesEntry:`Templates`,organizeIdle:`Polish`,organizeLoading:`Polishing`,organizeFailedShort:`Failed`,organizeIdleTitle:`Polish the input-box content against the current directory (main key polishes directly; ▾ picks a role style)`,organizeFailedTitle:`Polish failed: {message}`,organizeErrContextFailed:`Failed to read the directory context: {message}`,organizeErrModelFailed:`Failed to read the model: {message}`,organizeErrEmpty:`The input box is empty; nothing to polish`,organizeErrTimeout:`Polish request timed out: the host did not reply in time`,organizeErrUnknownReason:`unknown error`,organizeErrUnknown:`Polish failed (unknown error)`,organizeCaretAria:`Choose a role style to polish with`,organizeCaretTitle:`Polish in a role's style (roles come from the template library below)`,organizeMainAria:`Polish the input-box content`,organizeDirectItem:`Polish directly (default, no role)`,organizeNoTemplates:`No templates available as a role style`,organizeRoleItem:`Polish in the style of "{name}"`,organizeWriteBackUnavailable:`Input-box actions unavailable; cannot write back`,organizeWriteBackStale:`The input box changed; the polished text was not applied`,organizeBusyTitle:`The input box is submitting; cannot polish right now`,templatesIdleTitle:`Pick a template to insert at the caret (shown grouped)`,templatesBrokenTitle:`Input-box actions unavailable; cannot insert`,templatesBusyTitle:`The input box is submitting; cannot insert a template`,templatesGroupCommon:`General`,templatesAria:`Insert a template`,templatesEmptyHint:`No templates: add or restore defaults under "Role library" in the settings page`,builtinLoading:`Loading built-in role templates…`,builtinFailed:`Failed to load built-in templates: {message}`,builtinRetry:`Retry`}};function x(e){return e!==void 0&&typeof e.setDraft==`function`}function S(e){return e!==void 0&&typeof e.captureInsertion==`function`&&typeof e.insertText==`function`}function C(t,n){let r=(0,e.useRef)(t),i=(0,e.useRef)(void 0);return(0,e.useEffect)(()=>{r.current=t;let e=i.current;e!==void 0&&(e.sessionId!==t.sessionId||e.actions!==t.actions||t.phase!==`plain`)&&(e.invalidated=!0)},[t]),(0,e.useEffect)(()=>()=>{let e=i.current;e!==void 0&&(e.invalidated=!0,i.current=void 0)},[]),{begin:()=>{let e={sessionId:r.current.sessionId,draftRev:r.current.draftRev,actions:r.current.actions,invalidated:!1};return i.current=e,e},finish:e=>{i.current===e&&(i.current=void 0)},commit:(e,t)=>{let i=r.current,{actions:a}=i;if(!x(a))throw Error(n.unavailable);if(t.sessionId!==i.sessionId||i.phase!==`plain`)throw Error(n.stale);let o=i.draftRev;if(S(a)&&(o=a.captureInsertion().draftRev),t.invalidated||o!==t.draftRev)throw Error(n.stale);a.setDraft(e)}}}const w=`dirPrepOrganize`,T=`remote.${w}`,E=`@jayyuen66/dsh-dir-prep-organize`;function D(e,t){let r=e.safeParse(t);if(!r.success)throw TypeError(n.z.prettifyError(r.error));return r.data}const ee=`session request requires a string sessionId`,te=n.z.object({sessionId:n.z.string({error:ee})},{error:ee}),O=`organize request requires string sessionId, prompt and entriesSummary`,ne=n.z.object({sessionId:n.z.string({error:O}),prompt:n.z.string({error:O}),entriesSummary:n.z.string({error:O}),roleText:n.z.string({error:`organize request roleText must be a string when present`}).optional()},{error:O}),k=`import request requires string path and sessionId`,re=n.z.object({path:n.z.string({error:k}),sessionId:n.z.string({error:k})},{error:k}),A={mode:`strict`,typeSymbol:`${E}#session-request`,create:()=>({parse(e){return D(te,e)}})},ie=[{id:`${E}#${w}/defaults`,service:w,namespace:w,method:`defaults`,invocation:{kind:`direct`},parameters:[],result:{mode:`src-json`}},{id:`${E}#${w}/context`,service:w,namespace:w,method:`context`,invocation:{kind:`direct`},parameters:[{name:`request`,wire:`request`,source:`json`,codec:A}],result:{mode:`src-json`}},{id:`${E}#${w}/model`,service:w,namespace:w,method:`model`,invocation:{kind:`direct`},parameters:[{name:`request`,wire:`request`,source:`json`,codec:A}],result:{mode:`src-json`}},{id:`${E}#${w}/organize`,service:w,namespace:w,method:`organize`,invocation:{kind:`direct`},parameters:[{name:`request`,wire:`request`,source:`json`,codec:{mode:`strict`,typeSymbol:`${E}#organize-request`,create:()=>({parse(e){let t=D(ne,e);return t.roleText===void 0?{sessionId:t.sessionId,prompt:t.prompt,entriesSummary:t.entriesSummary}:{...t,roleText:t.roleText}}})}}],result:{mode:`src-json`}},{id:`${E}#${w}/importTemplates`,service:w,namespace:w,method:`importTemplates`,invocation:{kind:`direct`},parameters:[{name:`request`,wire:`request`,source:`json`,codec:{mode:`strict`,typeSymbol:`${E}#import-request`,create:()=>({parse(e){return D(re,e)}})}}],result:{mode:`src-json`}}],ae=e=>(0,t.isRecord)(e)&&typeof e.$mount==`function`,oe=e=>(0,t.isRecord)(e)&&typeof e.defaults==`function`&&typeof e.context==`function`&&typeof e.model==`function`&&typeof e.organize==`function`&&typeof e.importTemplates==`function`,se=e=>{if(!(0,t.isRecord)(e)||typeof e.ok!=`boolean`)throw TypeError(`Typert Remote 应答不是 RemoteResult:缺少布尔字段 ok`);if(!e.ok){let{error:n}=e;throw!(0,t.isRecord)(n)||typeof n.code!=`string`||typeof n.message!=`string`?TypeError(`Typert Remote 应答的 error 分支缺 code/message`):Error(`${n.code}: ${n.message}`)}if(!(`value`in e))throw TypeError(`Typert Remote 应答的 ok 分支缺 value 字段`);return e.value};function ce(e,t){let n,r=async()=>{n??=t.$mount({package:E,descriptors:ie});try{await n}catch(e){throw n=void 0,e}let r=e.get?.(T,!1);if(!oe(r))throw Error(`${T} 未提供:宿主网关没有挂上这枚命名空间`);return r},i=async e=>{let t=await r();return se(await e(t))};return{defaults:async()=>i(e=>e.defaults()),context:async e=>i(t=>t.context({sessionId:e})),model:async e=>i(t=>t.model({sessionId:e})),organize:async e=>i(t=>t.organize(e)),importTemplates:async e=>i(t=>t.importTemplates(e))}}function le(e){let t;try{t=e.get?.(`remote`,!1)}catch{t=void 0}return ae(t)?ce(e,t):void 0}const j=`dir-prep-organize`,M=125e3,ue=4e3,N=`dpi-item-empty`,P=`dpic-rowhead`,F=`dpic-importpath`,I=`conversation.input.right`;function de(e){let{name:n,isDir:r,sizeBytes:i,snippet:a}=(0,t.isRecord)(e)?e:{};return{name:typeof n==`string`?n:``,isDir:r===!0,sizeBytes:typeof i==`number`?i:0,...typeof a==`string`?{snippet:a}:{}}}function L(e,t){let n=e[t];return typeof n==`string`?n:void 0}function R(e,t){return e===void 0?{}:{[t]:e}}function fe(e){return[[`skipDeeper`,e.deeper],[`skipTooLarge`,e.tooLarge],[`skipUnreadable`,e.unreadable],[`skipUnnamed`,e.unnamed],[`skipEscaped`,e.escaped]]}function z(e){let n=(0,t.isRecord)(e)?e:{},{ok:r,truncated:i,entries:a}=n,o=Array.isArray(a)?a.map(e=>de(e)):void 0;return{ok:r===!0,...R(L(n,`error`),`error`),...R(L(n,`cwd`),`cwd`),...i===!0?{truncated:!0}:{},...o===void 0?{}:{entries:o}}}function pe(e){let n=(0,t.isRecord)(e)?e:{};return{ok:n.ok===!0,...R(L(n,`error`),`error`),...R(L(n,`provider`),`provider`),...R(L(n,`model`),`model`),...R(L(n,`reasoningEffort`),`reasoningEffort`)}}function B(e){let n=(0,t.isRecord)(e)?e:{};return{ok:n.ok===!0,...R(L(n,`error`),`error`),...R(L(n,`content`),`content`)}}function V(e){return typeof e==`number`&&e>0?e:0}function me(e){return{tooLarge:V(e.tooLarge),unreadable:V(e.unreadable),deeper:V(e.deeper),unnamed:V(e.unnamed),escaped:V(e.escaped)}}function he(e,t){if(t===void 0)return``;let n=[];for(let[r,i]of fe(t))i>0&&n.push(e(r,{count:i}));return n.length===0?``:e(`skipSummary`,{list:n.join(e(`skipSeparator`))})}function ge(e){let{ok:n,error:r,count:i,truncated:a,skipped:o,entries:s}=(0,t.isRecord)(e)?e:{},c=Array.isArray(s)?l(s):void 0;return{ok:n===!0,...typeof r==`string`?{error:r}:{},...typeof i==`number`?{count:i}:{},...a===!0?{truncated:!0}:{},...(0,t.isRecord)(o)?{skipped:me(o)}:{},...c===void 0?{}:{entries:c}}}function _e(e){let t=e.entries??[],n=[`当前目录: ${e.cwd??`(未提供)`}`],r=t.filter(e=>!e.isDir),i=t.filter(e=>e.isDir);n.push(`文件 ${r.length} 个, 目录 ${i.length} 个`),e.truncated===!0&&n.push(`(以上条目按上限截断,目录树并未完整列出,勿据此判断文件不存在)`);for(let e of i)n.push(`📁 ${e.name}/`);for(let e of r){let t=e.sizeBytes>1024?`${(e.sizeBytes/1024).toFixed(1)}KB`:`${e.sizeBytes}B`,r=`📄 ${e.name} (${t})`;e.snippet!==void 0&&e.snippet.length>0&&(r+=` ↳ ${e.snippet.replaceAll(`
|
|
9
|
+
`,` `)}`),n.push(r)}return n.join(`
|
|
10
|
+
`)}const H={phase:`idle`,list:[],error:``};let U=H,W=null,G=0;const K=new Set;function q(e){if(e===U)return U;U=e;for(let e of K)e();return e}function ve(){return U}let J;function ye(e){J=e}function Y(){if(J===void 0)throw Error(`远程读面不可用:宿主网关没有挂上 ${w}`);return J}var X=class extends Error{messageKey;params;constructor(e,t={}){super(e),this.name=`LocalizedOrganizeError`,this.messageKey=e,this.params=t}};async function Z(e,t){let n=Promise.withResolvers(),r=setTimeout(()=>{n.reject(new X(`organizeErrTimeout`))},t);try{return await Promise.race([e,n.promise])}finally{clearTimeout(r)}}async function Q(){if(U.phase===`ready`)return U;if(W!==null)return await W;let e=G;return W=(async()=>{q({phase:`loading`,list:U.list,error:``});let n;try{let e=await Z(Y().defaults(),M),r=(0,t.isRecord)(e)?e:void 0,i=r?.error;n=r?.ok===!0?{phase:`ready`,list:l(r.templates),error:``}:{phase:`error`,list:[],error:typeof i==`string`&&i.trim()!==``?i:`内置模板响应不是合法载荷`}}catch(e){n={phase:`error`,list:[],error:(0,t.errorText)(e)}}finally{G===e&&(W=null)}return G===e?q(n):n})(),await W}function be(e){return K.add(e),()=>{K.delete(e)}}function xe(){G+=1,W=null,q(H)}function Se(t,n){let r={className:N,"data-field":`dpi-builtin-state`},i=(0,e.createElement)(`button`,{type:`button`,className:`dsu-btn`,"data-field":`dpi-builtin-retry`,onClick:()=>{Q()}},n(`builtinRetry`)),a;return!t.fromSettings&&t.builtinPhase!==`ready`&&(a=t.builtinPhase===`error`?(0,e.createElement)(`div`,r,n(`builtinFailed`,{message:t.builtinError}),i):(0,e.createElement)(`div`,r,n(`builtinLoading`))),a}function Ce(e,t,n,r){if(!e.ok)throw new X(`organizeErrContextFailed`,{message:e.error??r});if(!t.ok||t.provider===void 0||t.model===void 0)throw new X(`organizeErrModelFailed`,{message:t.error??r});if(n.trim().length===0)throw new X(`organizeErrEmpty`)}async function we(e){let{ctxRes:t,prompt:n,sessionId:r,roleText:i,timeoutMs:a}=e,o=_e(t),s=B(await Z(Y().organize({sessionId:r,prompt:n,entriesSummary:o,...i===void 0?{}:{roleText:i}}),a));if(!s.ok||s.content===void 0)throw s.error===void 0?new X(`organizeErrUnknown`):Error(s.error);return s.content}async function Te(e){let t=Y(),[n,r]=await Promise.all([Z(t.context(e.sessionId),M),Z(t.model(e.sessionId),M)]),i=z(n);return Ce(i,pe(r),e.prompt,e.unknownReason),we({ctxRes:i,prompt:e.prompt,sessionId:e.sessionId,roleText:e.roleText,timeoutMs:e.timeoutMs})}function Ee(e){let{value:t,status:n,writable:r,revision:i}=e;return{value:t??{},ready:n===`ready`,writable:r,revision:i??0}}function De(e){return e.templates}function Oe(e){return e.importAllowRoots}function ke(e){let t=null,n=U,r={templates:H.list,fromSettings:!1,builtinPhase:`idle`,builtinError:``,allowRoots:[],ready:!1,writable:!1,organizeTimeoutMs:void 0};return{getSnapshot(){let i=e.getSnapshot();if(i===t&&U===n)return r;t=i,n=U;let a=Ee(i),o=De(a.value),s=Array.isArray(o)&&o.length>0;return r={templates:s?l(o):n.list,fromSettings:s,builtinPhase:n.phase,builtinError:n.error,allowRoots:h(Oe(a.value)),ready:a.ready,writable:a.writable,organizeTimeoutMs:v(a.value)},r},subscribe(t){let n=e.subscribe(t),r=be(t);return()=>{n(),r()}},readBack(){let t=Ee(e.getSnapshot());return{ready:t.ready,revision:t.revision,templates:l(De(t.value)),allowRoots:h(Oe(t.value))}}}}function Ae(e,t,n,r,i){let a,o=i?.treatEmptyAsReverted===!0&&t.templates.length===0&&n.length>0;return t.ready?!o&&JSON.stringify(t.templates)!==JSON.stringify(n)&&(a=e(`persistRejected`,{action:r,revision:t.revision})):a=e(`persistUnconfirmed`,{action:r}),a}function je(e,t,n,r){let i;return t.ready?JSON.stringify(t.allowRoots)!==JSON.stringify(n)&&(i=e(`persistRejected`,{action:r,revision:t.revision})):i=e(`persistUnconfirmed`,{action:r}),i}function Me(e){return`${e.emoji===``?``:`${e.emoji} `}${e.name}`}function Ne(e,t){let n=new Map;for(let r of e){let e=r.group.trim()===``?t(`templatesGroupCommon`):r.group,i=n.get(e)??[];i.push(r),n.set(e,i)}return Array.from(n.entries(),([e,t])=>({group:e,items:t}))}function $(e,t=!1){let n=[[`d`,e],[`fill`,`none`],[`stroke`,`currentColor`],[`strokeWidth`,1.5],[`strokeLinecap`,`round`]];return t&&n.push([`strokeLinejoin`,`round`]),Object.fromEntries(n)}function Pe(){return Object.fromEntries([[`cx`,7],[`cy`,7],[`r`,5.5],[`fill`,`none`],[`stroke`,`currentColor`],[`strokeWidth`,1.5],[`strokeDasharray`,`26 10`],[`strokeLinecap`,`round`]])}function Fe(){return(0,e.createElement)(`svg`,{width:14,height:14,viewBox:`0 0 14 14`,"aria-hidden":!0},(0,e.createElement)(`path`,$(`M2 4l5 4 5-4`,!0)),(0,e.createElement)(`path`,$(`M2 8.5l5 4 5-4`,!0)))}function Ie(){return(0,e.createElement)(`svg`,{width:14,height:14,viewBox:`0 0 14 14`,"aria-hidden":!0,className:`dpi-spin`},(0,e.createElement)(`circle`,Pe()))}function Le(){return(0,e.createElement)(`svg`,{width:14,height:14,viewBox:`0 0 14 14`,"aria-hidden":!0},(0,e.createElement)(`path`,$(`M3 3l8 8M11 3l-8 8`)))}function Re(){return(0,e.createElement)(`svg`,{width:14,height:14,viewBox:`0 0 14 14`,"aria-hidden":!0},(0,e.createElement)(`path`,$(`M2.5 3.5h9M2.5 7h9M2.5 10.5h5.5`)))}function ze(){return(0,e.createElement)(`svg`,{width:14,height:14,viewBox:`0 0 14 14`,"aria-hidden":!0},(0,e.createElement)(`path`,$(`M2.5 5.5L7 9.5l4.5-4`,!0)))}function Be(t,n,r){(0,e.useEffect)(()=>{function e(e){n.current!==null&&e.target instanceof Node&&!n.current.contains(e.target)&&r()}function i(e){e.key===`Escape`&&r()}return t&&(document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,i)),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,i)}},[r,t,n])}async function Ve(e){let{t:n,loading:r,inFlight:i,seq:a,prompt:o,sessionId:s,timeoutMs:c,roleText:l,setLoading:u,setMenuOpen:d,setFailed:f,flashTimer:p,writeDraft:m}=e;if(r||i.current)return;i.current=!0,a.current+=1;let h=a.current;u(!0),f(void 0),d(!1);try{let e=await Te({prompt:o,sessionId:s,...l===void 0?{}:{roleText:l},timeoutMs:c,unknownReason:n(`organizeErrUnknownReason`)});if(a.current!==h)return;m(e)}catch(e){if(a.current!==h)return;f(e instanceof X?n(e.messageKey,e.params):(0,t.errorText)(e)),p.current!==null&&clearTimeout(p.current),p.current=setTimeout(()=>{f(void 0)},4e3)}finally{i.current=!1,a.current===h&&u(!1)}}const He=`organizeWriteBackUnavailable`;function Ue(t){let{t:n,icon:r,label:i,state:a,errClass:o,errTitle:s,loading:c,canWrite:l,onRun:u}=t;return(0,e.createElement)(`button`,{type:`button`,className:`dpi-btn dpi-main${o}`,"aria-label":n(`organizeMainAria`),title:s,"data-field":`dpi-organize-btn`,"data-state":a,disabled:c||!l,onClick:()=>{u()}},r,i)}function We(t){let{t:n,errClass:r,menuOpen:i,loading:a,onToggleMenu:o}=t;return(0,e.createElement)(`button`,{type:`button`,className:`dpi-btn dpi-caret${r}`,"aria-label":n(`organizeCaretAria`),"aria-haspopup":`menu`,"aria-expanded":i,title:n(`organizeCaretTitle`),"data-field":`dpi-organize-caret`,"data-state":i?`open`:`idle`,disabled:a,onClick:o},(0,e.createElement)(ze))}function Ge(t){let{t:n,templates:r,onRun:i,directItemLabel:a,noTemplatesLabel:o,builtinRow:s,loading:c,canWrite:l,errTitle:u}=t,d=c||!l,f=l?void 0:u;return(0,e.createElement)(`div`,{className:`dpi-menu`,role:`menu`,"data-field":`dpi-organize-menu`},(0,e.createElement)(`button`,{type:`button`,className:`dpi-item`,role:`menuitem`,"data-field":`dpi-organize-role-direct`,disabled:d,...f===void 0?{}:{title:f},onClick:()=>{i()}},a),r.length===0?s??(0,e.createElement)(`div`,{className:N},o):r.map(t=>(0,e.createElement)(`button`,{key:t.id,type:`button`,className:`dpi-item`,role:`menuitem`,"data-field":`dpi-organize-role-item`,disabled:d,title:f??(t.description===``?t.text:t.description),onClick:()=>{i(t.text)}},`${t.emoji===``?``:`${t.emoji} `}${n(`organizeRoleItem`,{name:t.name})}`)))}function Ke(t,n,r){return t===void 0?n?{icon:(0,e.createElement)(Ie),label:r(`organizeLoading`),state:`loading`}:{icon:(0,e.createElement)(Fe),label:r(`organizeIdle`),state:`idle`}:{icon:(0,e.createElement)(Le),label:r(`organizeFailedShort`),state:`error`}}function qe(){return function(t){let[n,r]=(0,e.useState)(!1),[i,a]=(0,e.useState)(void 0),[o,s]=(0,e.useState)(!1),c=(0,e.useRef)(0),l=(0,e.useRef)(!1),u=(0,e.useRef)(null),d=(0,e.useRef)(null),f=t.useInput===void 0?``:t.useInput(e=>e.draft)??``,p=t.useInput===void 0?0:t.useInput(e=>e.draftRev),m=t.useInput===void 0?`plain`:t.useInput(e=>e.phase),h=t.useCard(e=>e),{templates:g}=h,_=C({sessionId:t.sessionId??``,actions:t.inputActions,draftRev:p,phase:m},{unavailable:t.t(He),stale:t.t(`organizeWriteBackStale`)});Be(o,d,()=>{s(!1)}),(0,e.useEffect)(()=>()=>{c.current+=1,u.current!==null&&clearTimeout(u.current)},[]);async function v(e){let i=_.begin();try{await Ve({t:t.t,loading:n,inFlight:l,seq:c,prompt:f,sessionId:t.sessionId??``,timeoutMs:y(h.organizeTimeoutMs),roleText:e,setLoading:r,setMenuOpen:s,setFailed:a,flashTimer:u,writeDraft:e=>{_.commit(e,i)}})}finally{_.finish(i)}}function b(){h.fromSettings||Q(),s(e=>!e)}let S=Ke(i,n,t.t),w=x(t.inputActions),T=w&&m===`plain`,E=t.t(`organizeIdleTitle`);i===void 0?w?m!==`plain`&&(E=t.t(`organizeBusyTitle`)):E=t.t(He):E=t.t(`organizeFailedTitle`,{message:i});let D={t:t.t,errTitle:E,icon:S.icon,label:S.label,state:S.state,errClass:i===void 0?``:` dpi-btn-err`,directItemLabel:t.t(`organizeDirectItem`),noTemplatesLabel:t.t(`organizeNoTemplates`),builtinRow:Se(h,t.t),loading:n,menuOpen:o,canWrite:T,templates:g,onRun:v,onToggleMenu:b};return(0,e.createElement)(`span`,{className:`dpi-wrap dpi-split`,ref:d},Ue(D),We(D),o?Ge(D):null)}}function Je(){return function(t){let[n,r]=(0,e.useState)(!1),i=(0,e.useRef)(null),a=t.useInput===void 0?`plain`:t.useInput(e=>e.phase),o=t.useCard(e=>e),{templates:s}=o;Be(n,i,()=>{r(!1)});function c(e){r(!1);let n=t.inputActions;S(n)&&n.insertText(e,n.captureInsertion())}let l=S(t.inputActions),u=l&&a===`plain`,d=t.t(`templatesBrokenTitle`);u?d=t.t(`templatesIdleTitle`):l&&(d=t.t(`templatesBusyTitle`));let f=Ne(s,t.t),p=t.t(`templatesEmptyHint`),m=Se(o,t.t);return(0,e.createElement)(`span`,{className:`dpi-wrap`,ref:i},(0,e.createElement)(`button`,{type:`button`,className:`dpi-btn`,"aria-label":t.t(`templatesAria`),"aria-haspopup":`menu`,"aria-expanded":n,title:d,"data-field":`dpi-template-btn`,"data-state":n?`open`:`idle`,disabled:!u,onClick:()=>{o.fromSettings||Q(),r(e=>!e)}},(0,e.createElement)(Re),t.t(`dockTemplatesEntry`)),n?(0,e.createElement)(`div`,{className:`dpi-menu`,role:`menu`,"data-field":`dpi-template-menu`},s.length===0?m??(0,e.createElement)(`div`,{className:N},p):f.map(t=>(0,e.createElement)(`div`,{key:t.group,className:`dpi-group`},(0,e.createElement)(`div`,{className:`dpi-grouph`,role:`presentation`},t.group),t.items.map(t=>(0,e.createElement)(`button`,{key:t.id,type:`button`,className:`dpi-item`,role:`menuitem`,"data-field":`dpi-template-item`,title:t.description===``?t.text:t.description,onClick:()=>{c(t.text)}},Me(t)))))):null)}}function Ye(){let e;try{e=`tpl-${crypto.randomUUID()}`}catch{e=`tpl-${Date.now().toString(36)}-${Math.floor(Math.random()*1e9).toString(36)}`}return e}function Xe(t){let{t:n,rowNum:r,disabled:i,values:a,setters:o}=t,s=(0,e.createElement)(`span`,{className:`dpic-idx`},`#${r}`),c=(0,e.createElement)(`input`,{type:`text`,className:`dpic-emoji dsu-input`,value:a.emoji,placeholder:`😀`,disabled:i,"aria-label":n(`rowAriaEmoji`,{index:r}),title:n(`rowEmojiTitle`),onChange:e=>{o.emoji(e.target.value)},onBlur:t.onBlur}),l=(0,e.createElement)(`input`,{type:`text`,className:`dpic-name dsu-input`,value:a.name,placeholder:n(`rowPlaceholderName`),disabled:i,"aria-label":n(`rowAriaName`,{index:r}),onChange:e=>{o.name(e.target.value)},onBlur:t.onBlur}),u=(0,e.createElement)(`input`,{type:`text`,className:`dpic-group dsu-input`,value:a.group,placeholder:n(`rowPlaceholderGroup`),disabled:i,"aria-label":n(`rowAriaGroup`,{index:r}),title:n(`rowGroupTitle`),onChange:e=>{o.group(e.target.value)},onBlur:t.onBlur}),d=(0,e.createElement)(`button`,{type:`button`,className:`dpic-del dsu-btn dsu-btnDanger`,disabled:i,title:n(`rowDeleteTitle`),onClick:()=>{t.onDelete(t.templateId)}},n(`rowDelete`)),f=(0,e.createElement)(`input`,{type:`text`,className:`dpic-desc dsu-input`,value:a.description,placeholder:n(`rowPlaceholderDescription`),disabled:i,"aria-label":n(`rowAriaDescription`,{index:r}),onChange:e=>{o.description(e.target.value)},onBlur:t.onBlur}),p=(0,e.createElement)(`textarea`,{className:`dpic-text dsu-input dsu-textarea dsu-mono`,value:a.text,rows:6,placeholder:n(`rowPlaceholderText`),disabled:i,"aria-label":n(`rowAriaText`,{index:r}),onChange:e=>{o.text(e.target.value)},onBlur:t.onBlur});return(0,e.createElement)(`div`,{className:`dpic-row`},(0,e.createElement)(`div`,{className:P},s,c,l,u,d),f,p)}function Ze(t){let{t:n}=t,[r,i]=(0,e.useState)(t.template.name),[a,o]=(0,e.useState)(t.template.emoji),[s,c]=(0,e.useState)(t.template.group),[l,u]=(0,e.useState)(t.template.description),[d,f]=(0,e.useState)(t.template.text),p=String(t.index+1);(0,e.useEffect)(()=>{i(t.template.name),o(t.template.emoji),c(t.template.group),u(t.template.description),f(t.template.text)},[t.template.id,t.template.name,t.template.emoji,t.template.group,t.template.description,t.template.text]);function m(){let e=r.trim(),n=d.trim();if(e===``||n===``)return;let i=a.trim(),o=s.trim(),c=l.trim();(e!==t.template.name||i!==t.template.emoji||o!==t.template.group||c!==t.template.description||n!==t.template.text)&&t.onCommit(t.template.id,{name:e,emoji:i,group:o,description:c,text:n})}return Xe({t:n,rowNum:p,disabled:t.disabled,templateId:t.template.id,values:{name:r,emoji:a,group:s,description:l,text:d},setters:{name:i,emoji:o,group:c,text:f,description:u},onBlur:m,onDelete:t.onDelete})}function Qe(n){let{t:r}=n,[i,a]=(0,e.useState)(``),[o,s]=(0,e.useState)(!1),[c,l]=(0,e.useState)(``),[u,d]=(0,e.useState)(``);async function f(){if(o)return;let e=i.trim();s(!0),d(``),l(``);try{let t=ge(await Z(Y().importTemplates({path:e,sessionId:``}),M));if(!t.ok||t.entries===void 0)throw Error(t.error??r(`importFailedUnknown`));let i=t.entries.length,o=V(t.count),s=o===0?i:Math.min(o,i);if(s===0){d(r(`importEmpty`));return}n.onImported(t.entries),a(``);let c=t.truncated===!0?r(`importTruncated`):``,u=`${he(r,t.skipped)}${c}`;l(e.length===0?r(`importAllDone`,{count:s,skips:u}):r(`importFromDone`,{path:e,count:s,skips:u}))}catch(e){d((0,t.errorText)(e))}finally{s(!1)}}let p=n.editable&&!o,m=(0,e.createElement)(`input`,{type:`text`,className:`${F} dsu-input`,value:i,placeholder:r(`importPlaceholder`),disabled:!p,"aria-label":r(`importAriaPath`),onChange:e=>{a(e.target.value)},onKeyDown:e=>{e.key===`Enter`&&f()}}),h=(0,e.createElement)(`button`,{type:`button`,className:`dsu-btn`,disabled:!p,title:r(`importBtnTitle`),onClick:f},r(o?`importing`:`importRoles`)),g=c===``?null:(0,e.createElement)(`div`,{className:`dpic-hint`},c),_=u===``?null:(0,e.createElement)(`div`,{className:`dpic-hint dpic-err`},`${r(`importErrorPrefix`)}${u}`),v=(0,e.createElement)(`div`,{className:`dpic-hint`},r(`importHint`));return(0,e.createElement)(`div`,{className:`dpic-importrow`},(0,e.createElement)(`div`,{className:P},m,h),g,_,v)}function $e(t){let{t:n}=t,[r,i]=(0,e.useState)(``),a=!t.disabled&&r.trim().length>0,o=n(`rootsRowTitle`),s=n(`rootsRemoveTitle`),c=n(`rootsRemove`),l=t.roots.map((r,i)=>{let a=n(`rootsAriaRow`,{index:i+1}),l=(0,e.createElement)(`input`,{type:`text`,className:`${F} dsu-input`,value:r,placeholder:`/Users/me/roles`,disabled:t.disabled,"aria-label":a,title:o,onChange:e=>{t.onChangeRoot(i,e.target.value)}}),u=(0,e.createElement)(`button`,{type:`button`,className:`dpic-del dsu-btn dsu-btnDanger`,disabled:t.disabled,title:s,onClick:()=>{t.onDeleteRoot(i)}},c);return(0,e.createElement)(`div`,{className:P,key:`allow-root-${String(i)}`},l,u)}),u=n(`rootsAddPlaceholder`),d=n(`rootsAddAria`),f=n(`rootsAddTitle`),p=n(`rootsAdd`),m=(0,e.createElement)(`input`,{type:`text`,className:`${F} dsu-input`,value:r,placeholder:u,disabled:t.disabled,"aria-label":d,onChange:e=>{i(e.target.value)},onKeyDown:e=>{e.key===`Enter`&&a&&(t.onAddRoot(r.trim()),i(``))}}),h=(0,e.createElement)(`button`,{type:`button`,className:`dsu-btn`,disabled:!a,title:f,onClick:()=>{t.onAddRoot(r.trim()),i(``)}},p),g=(0,e.createElement)(`div`,{className:P},m,h);return(0,e.createElement)(`div`,{className:`dpic-importrow`,"data-field":`allow-roots`},(0,e.createElement)(`div`,{className:`dpic-hint`},n(`rootsHeading`)),l,g,(0,e.createElement)(`div`,{className:`dpic-hint`},n(`rootsHint`)))}function et(t){let{foot:n,editable:r,busy:i,confirmReset:a}=t;return(0,e.createElement)(`div`,{className:`dpic-toolbar`},(0,e.createElement)(`button`,{type:`button`,className:`dsu-btn`,disabled:!r,onClick:t.onAdd},n.add),(0,e.createElement)(`button`,{type:`button`,className:`dsu-btn dsu-btnDanger`,disabled:!r||i,title:n.resetTitle,onClick:t.onReset},a?n.resetConfirm:n.reset))}function tt(e){return{add:e(`addTemplate`),save:e(`save`),saving:e(`saving`),revert:e(`revert`),reset:e(`resetDefault`),resetConfirm:e(`resetConfirm`,{seconds:ue/1e3}),saveTitleDirty:e(`saveTitleDirty`),saveTitleClean:e(`saveTitleClean`),resetTitle:e(`resetTitle`)}}function nt(e,t){let n;return n=e.ready?e.writable?``:t(`statusReadOnly`):t(`statusNotReady`),n}function rt(e,t,n,r,i){function a(e,n){r(t.map(t=>t.id===e?{...t,...n}:t))}function s(e){r(t.filter(t=>t.id!==e))}function c(){r([...t,{id:Ye(),name:e(`newTemplateName`,{index:t.length+1}),description:``,text:``,group:``,emoji:``}])}function l(e){r(t=>o(t,e))}function u(e,t){i(n.map((n,r)=>r===e?t:n))}function d(e){i(n.filter((t,n)=>n!==e))}function f(e){i([...n,e])}return{onCommit:a,onDelete:s,onAdd:c,onImported:l,onRootChange:u,onRootDelete:d,onRootAdd:f}}function it(e,t,n,r,i){let a=Ae(e,t,n,e(r),i);if(a!==void 0)throw Error(a)}function at(e,t,n){let r=je(e,t,n,e(`save`));if(r!==void 0)throw Error(r)}function ot(e){let{t:n,editable:r,dirty:i,rootsDirty:a,anythingDirty:o,confirmReset:s,templates:c,allowRoots:u,draft:d,rootsDraft:f,set:p,unset:m,readBack:g,setDraft:_,setDraftFor:v,setRootsDraft:y,setBusy:b,setSaveError:x,setConfirmReset:S}=e;function C(e){console.error(`[dir-prep-organize] templates settings write failed:`,e),x((0,t.errorText)(e))}async function w(){if(!r||!o)return;b(!0),x(``);let e=l(d),t=h(f);try{i&&(await p(`templates`,e),it(n,g(),e,`save`)),a&&(await p(`importAllowRoots`,t),at(n,g(),t)),b(!1),_(t=>t===d?e:t),y(e=>e===f?t:e)}catch(e){b(!1),C(e)}}function T(){_(c),y(u),x(``)}function E(){s?(S(!1),b(!0),(async()=>{try{let e=await Q();if(e.phase!==`ready`)throw Error(e.error);await m(`templates`),it(n,g(),e.list,`resetDefault`,{treatEmptyAsReverted:!0}),x(``),_(e.list),v(e.list),y(u)}catch(e){C(e)}finally{b(!1)}})()):S(!0)}return{onSave:w,onDiscard:T,onReset:E}}function st(n){let{t:r,statusHint:i,draft:a,rootsDraft:o,foot:s,editable:c,anythingDirty:l,busy:u,confirmReset:d,saveError:f}=n,{onCommit:p,onDelete:m,onAdd:h,onImported:g,onRootChange:_,onRootDelete:v,onRootAdd:y}=n.draftActions,{onSave:b,onDiscard:x,onReset:S}=n.persistActions,C=(0,e.createElement)(`p`,{className:`dpic-hint`},r(`footHint`)),w=(0,e.createElement)(t.SaveBar,{dirty:l,busy:u,writable:c,error:f===``?null:`${r(`saveFailed`)}${f}`,saveLabel:r(`save`),savingLabel:r(`saving`),revertLabel:r(`revert`),dirtyLabel:r(`saveTitleDirty`),cleanLabel:r(`saveTitleClean`),readOnlyLabel:r(`statusReadOnly`),onSave:()=>{b()},onDiscard:x});return(0,e.createElement)(t.CardForm,null,i===``?null:(0,e.createElement)(`p`,{className:`dpic-hint`},i),(0,e.createElement)(t.Section,{title:r(`rolesSection`),hint:r(`rolesHint`)},(0,e.createElement)(et,{foot:s,editable:c,busy:u,confirmReset:d,onAdd:h,onReset:S}),a.map((t,n)=>(0,e.createElement)(Ze,{key:t.id,t:r,index:n,template:t,disabled:!c||u,onCommit:p,onDelete:m})),(0,e.createElement)(Qe,{t:r,editable:c&&!u,onImported:g}),(0,e.createElement)($e,{t:r,roots:o,disabled:!c||u,onChangeRoot:_,onDeleteRoot:v,onAddRoot:y}),C),w)}function ct(t){let{t:n}=t,[r,i]=(0,e.useState)(!1),[a,o]=(0,e.useState)(``),[s,c]=(0,e.useState)(!1),l=tt(n),u=t.useCard(e=>e),{templates:d}=u,f=u.ready&&u.writable,p=nt(u,n);(0,e.useEffect)(()=>{u.fromSettings||Q()},[u.fromSettings]);let[m,g]=(0,e.useState)(d),[_,v]=(0,e.useState)(d);(0,e.useEffect)(()=>{_!==d&&(v(d),g(e=>JSON.stringify(e)===JSON.stringify(_)?d:e))},[d,_]),(0,e.useEffect)(()=>{let e;return r&&(e=setTimeout(()=>{i(!1)},ue)),()=>{e!==void 0&&clearTimeout(e)}},[r]);let[y,b]=(0,e.useState)(u.allowRoots),[x,S]=(0,e.useState)(u.allowRoots);(0,e.useEffect)(()=>{x!==u.allowRoots&&(S(u.allowRoots),b(e=>JSON.stringify(e)===JSON.stringify(x)?u.allowRoots:e))},[x,u.allowRoots]);let C=JSON.stringify(m)!==JSON.stringify(d),w=JSON.stringify(h(y))!==JSON.stringify(u.allowRoots),T=C||w;return st({t:n,statusHint:p,draft:m,rootsDraft:y,foot:l,editable:f,anythingDirty:T,busy:s,confirmReset:r,saveError:a,draftActions:rt(n,m,y,g,b),persistActions:ot({t:n,editable:f,dirty:C,rootsDirty:w,anythingDirty:T,confirmReset:r,templates:d,allowRoots:u.allowRoots,draft:m,rootsDraft:y,set:t.set,unset:t.unset,readBack:t.readBack,setDraft:g,setDraftFor:v,setRootsDraft:b,setBusy:c,setSaveError:o,setConfirmReset:i})})}const lt=[`slots`,`configForms`,`locale`];function ut(e,t,n){let r=()=>({hooks:{card:t}});e.slots.inject(I,()=>{let t=e.slots.register({name:I,id:j,order:99,label:()=>n(`dockOrganizeEntry`),locale:j,inject:r},qe()),i=e.slots.register({name:I,id:`${j}-templates`,order:100,label:()=>n(`dockTemplatesEntry`),locale:j,inject:r},Je());return()=>{t(),i()}})}function dt(e,t,n,r){e.slots.inject(`plugins.bundle.config`,()=>e.slots.register({name:`plugins.bundle.config`,key:`@jayyuen66/dsh-dir-prep-organize`,inject:()=>({t:n,hooks:{card:t},set:(e,t)=>r.set(e,t),unset:e=>r.unset(e),readBack:()=>t.readBack()})},ct))}function ft(e){let n=le(e);J=n,e.effect(()=>()=>{J===n&&(J=void 0)},`dir-prep-organize: remote reader`),e.effect(()=>{let e=(0,t.ensureCardUiCss)(),n=document.createElement(`style`);return n.id=`dir-prep-organize-css`,n.textContent=`.dpi-btn{appearance:none;border:1px solid var(--dsw-alias-border-l2,currentColor);background:var(--dsw-alias-bg-layer-1,transparent);color:var(--dsw-alias-label-primary,inherit);font:inherit;font-size:12px;line-height:1;border-radius:8px;padding:6px 10px;cursor:pointer;display:inline-flex;align-items:center;gap:6px;transition:background .16s,border-color .16s,color .16s}
|
|
11
|
+
.dpi-btn:hover:not(:disabled){border-color:var(--dsw-alias-label-dimmed,currentColor);background:var(--dsw-alias-bg-layer-2,transparent)}
|
|
12
|
+
.dpi-btn:disabled{opacity:.55;cursor:not-allowed}
|
|
13
|
+
.dpi-btn:disabled[data-state="loading"]{cursor:progress}
|
|
14
|
+
.dpi-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,currentColor);outline-offset:1px}
|
|
15
|
+
.dpi-btn svg{width:14px;height:14px;flex:none}
|
|
16
|
+
.dpi-btn-err{border-color:var(--dsw-alias-state-error-primary,currentColor);color:var(--dsw-alias-state-error-secondary,currentColor)}
|
|
17
|
+
.dpi-btn-err:hover:not(:disabled){border-color:var(--dsw-alias-state-error-primary,currentColor)}
|
|
18
|
+
.dpi-spin{animation:dpi-rotate .8s linear infinite}
|
|
19
|
+
@keyframes dpi-rotate{to{transform:rotate(360deg)}}
|
|
20
|
+
@media (prefers-reduced-motion:reduce){.dpi-spin{animation:none}.dpi-btn{transition:none}}
|
|
21
|
+
.dpi-wrap{position:relative;display:inline-flex;isolation:isolate}
|
|
22
|
+
.dpi-menu{position:absolute;bottom:calc(100% + 6px);right:0;z-index:50;min-width:224px;max-height:340px;overflow-y:auto;background:var(--dsw-menu-surface-fill,transparent);backdrop-filter:var(--dsw-menu-backdrop-filter,none);border:0;border-radius:10px;padding:4px;display:flex;flex-direction:column;gap:2px;box-shadow:var(--dsw-elevation-panel,none)}
|
|
23
|
+
.dpi-item{appearance:none;border:none;background:transparent;color:var(--dsw-alias-label-primary,inherit);font:inherit;font-size:12px;line-height:1.4;text-align:left;border-radius:6px;padding:8px 10px;cursor:pointer;white-space:nowrap}
|
|
24
|
+
.dpi-item:hover,.dpi-item:focus-visible{background:var(--dsw-alias-bg-layer-2,transparent)}
|
|
25
|
+
.dpi-item-empty{color:var(--dsw-alias-label-tertiary,inherit);cursor:default;font-size:12px;padding:8px 10px;white-space:nowrap}
|
|
26
|
+
.dpi-split{display:inline-flex;align-items:stretch}
|
|
27
|
+
.dpi-split .dpi-main{border-top-right-radius:0;border-bottom-right-radius:0;padding-right:8px}
|
|
28
|
+
.dpi-split .dpi-caret{border-left:none;border-top-left-radius:0;border-bottom-left-radius:0;padding-left:4px;padding-right:6px}
|
|
29
|
+
.dpi-split .dpi-caret svg{width:10px;height:10px}
|
|
30
|
+
.dpi-group{padding:2px 0}
|
|
31
|
+
.dpi-grouph{font-size:11px;font-weight:600;color:var(--dsw-alias-label-tertiary,inherit);padding:6px 10px 2px;letter-spacing:.02em}
|
|
32
|
+
.dpic-row{padding:10px 0;border-bottom:1px dashed var(--dsw-alias-border-l2,currentColor)}
|
|
33
|
+
.dpic-name{flex:1;min-width:0}
|
|
34
|
+
.dpic-rowhead .dpic-name{width:auto}
|
|
35
|
+
.dpic-rowhead .dpic-emoji{width:44px;flex:none;text-align:center}
|
|
36
|
+
.dpic-rowhead .dpic-group{width:84px;flex:none}
|
|
37
|
+
.dpic-desc{width:100%;margin-top:6px}
|
|
38
|
+
.dpic-text{width:100%;margin-top:6px}
|
|
39
|
+
.dpic-importpath{flex:1;min-width:0}
|
|
40
|
+
.dpic-rowhead .dpic-importpath{width:auto}
|
|
41
|
+
.dpic-del{flex:none}
|
|
42
|
+
.dpic-toolbar{display:flex;gap:8px;flex-wrap:wrap;padding:8px 0}
|
|
43
|
+
.dpic-rowhead{display:flex;gap:8px;align-items:center}
|
|
44
|
+
.dpic-idx{font-size:12px;color:var(--dsw-alias-label-tertiary,inherit);flex:none;min-width:26px}
|
|
45
|
+
.dpic-importrow{padding:12px 0;border-bottom:1px dashed var(--dsw-alias-border-l2,currentColor)}
|
|
46
|
+
.dpic-hint{font-size:12px;color:var(--dsw-alias-label-tertiary,inherit);line-height:1.5;padding-top:6px}
|
|
47
|
+
.dpic-err{color:var(--dsw-alias-state-error-primary,currentColor)}`,document.head.append(n),()=>{n.remove(),e()}},`dir-prep-organize: styles`);let r=e.configForms.get(j),i=ke(r);e.effect(()=>e.locale.register(j,b),`dir-prep-organize-card: locale dictionaries`);let a=e.locale.bind(j);ut(e,i,a),dt(e,i,a,r)}exports.apply=ft,exports.builtinTemplatesSnapshot=ve,exports.formatContextSummary=_e,exports.formatImportSkips=he,exports.inject=lt,exports.loadBuiltinTemplates=Q,exports.parseContextResponse=z,exports.parseOrganizeResponse=B,exports.persistError=Ae,exports.resetBuiltinTemplates=xe,exports.rootsPersistError=je,exports.setDirPrepReader=ye,exports.subscribeBuiltinTemplates=be;
|
|
2180
48
|
return module.exports;
|
|
2181
49
|
},
|
|
2182
50
|
});
|