@dotdance/dsh-skill-scope 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.en.md +98 -0
- package/README.md +97 -2
- package/cordis.patch.yml +3 -0
- package/lib/client.js +1369 -0
- package/lib/client.js.map +1 -0
- package/lib/index.js +2157 -0
- package/package.json +81 -3
package/lib/client.js
ADDED
|
@@ -0,0 +1,1369 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "dsh-skill-scope",
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
var module = { exports: {} };
|
|
5
|
+
var exports = module.exports;
|
|
6
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
|
+
let react = require("react");
|
|
8
|
+
let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
9
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
10
|
+
//#region src/shared/unknown.ts
|
|
11
|
+
/**
|
|
12
|
+
* `unknown` 收窄工具。**全仓库唯一一份**。
|
|
13
|
+
*
|
|
14
|
+
* 这三个函数原先在 7 个文件里各写了一份(`assembly.ts`、`routes/handlers.ts`、
|
|
15
|
+
* `routes/session.ts`、`routes/register.ts`、`client/api.ts`、`client/parts.tsx`、
|
|
16
|
+
* `client/CapabilityPanel.tsx`),其中 `CapabilityPanel.tsx` 那份还改名成 `asRecordOf`,
|
|
17
|
+
* 让「同一份实现」看起来像「两份不同的实现」。改名本身就是「该收拢」的信号。
|
|
18
|
+
*
|
|
19
|
+
* 客户端与服务端共用本模块是安全的:这三个函数不依赖任何运行环境
|
|
20
|
+
* (不读 `node:fs`、不碰 DOM),只是类型收窄,因此不会把宿主侧依赖拖进 client bundle。
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* 把 `unknown` 收成可索引记录;数组与非对象拒绝。
|
|
24
|
+
*
|
|
25
|
+
* **数组也必须拒绝**:数组同样能取字符串键(`arr['length']` 合法),
|
|
26
|
+
* 但它不是记录——放行会让下游把「一个列表」当成「一个对象」处理。
|
|
27
|
+
*
|
|
28
|
+
* **不用 `as` 断言直接转型**(如 `value as Record<string, unknown>`):
|
|
29
|
+
* 断言不做运行时校验,输入是任意 JSON 时会把形状错误一路带到使用点才炸。
|
|
30
|
+
*/
|
|
31
|
+
function asRecord(value) {
|
|
32
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/client/api.ts
|
|
37
|
+
/**
|
|
38
|
+
* 面板与宿主之间的唯一传输面(设计 6.2)。
|
|
39
|
+
*
|
|
40
|
+
* **根绝对路径**:请求 URL 一律是 `'/' + route`。设计 6.2 明确要求这样拼,
|
|
41
|
+
* 因为面板可能被渲染在任意路由下(`/workspace/xxx`、`/settings`…)——相对路径会拼到
|
|
42
|
+
* 当前路由上,`api/...` 就打到 `/workspace/api/...` 这种不存在的地址。
|
|
43
|
+
*
|
|
44
|
+
* **Review Focus 6 的已知残余风险**:GUI 若部署在子路径下(`<base href="./">`),
|
|
45
|
+
* root-absolute 的 `/api/...` 可能打不到路由。此时本模块的行为是:超时中止并抛
|
|
46
|
+
* `ApiError('network')`,让面板显示**可重试的错误态**——绝不静默挂起。
|
|
47
|
+
* 也就是说,「打不到路由」不会变成白屏,而是变成一条用户可读的失败提示。
|
|
48
|
+
*/
|
|
49
|
+
/** 传输层失败。`code` 是承重字段:面板靠它区分「刷新重载」与「输入非法」。 */
|
|
50
|
+
var ApiError = class extends Error {
|
|
51
|
+
name = "ApiError";
|
|
52
|
+
code;
|
|
53
|
+
constructor(code, message) {
|
|
54
|
+
super(message);
|
|
55
|
+
this.code = code;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* 四条路由。**不含前导斜杠**(`post` 会补上);这样字符串本身就是设计 6.2 里写的那个值,
|
|
60
|
+
* 与 `src/routes/register.ts` 的 `ROUTES`(含 `/api` 前缀的完整 pathname)在语义上区分开:
|
|
61
|
+
* 那边的值是「宿主注册用的完整 pathname」,这边是「客户端要拼的路径片段」。
|
|
62
|
+
*/
|
|
63
|
+
const ROUTES = {
|
|
64
|
+
global: "api/skill-scope/global",
|
|
65
|
+
globalSave: "api/skill-scope/global/save",
|
|
66
|
+
workspace: "api/skill-scope/workspace",
|
|
67
|
+
workspaceSave: "api/skill-scope/workspace/save"
|
|
68
|
+
};
|
|
69
|
+
/** 默认超时。面板是交互入口,10 秒足够;超时必须兜底,不能让用户对着转圈等。 */
|
|
70
|
+
const DEFAULT_TIMEOUT_MS = 1e4;
|
|
71
|
+
/** 从错误信封里读 `code`,读不到就退回 `internal`(不假装知道是哪种失败)。 */
|
|
72
|
+
function errorCodeOf(error) {
|
|
73
|
+
const code = asRecord(error)?.["code"];
|
|
74
|
+
if (code === "bad-request" || code === "stale-revision" || code === "unknown-session" || code === "internal") return code;
|
|
75
|
+
return "internal";
|
|
76
|
+
}
|
|
77
|
+
/** 从错误信封里读 `message`,读不到就给一句不误导的兜底文案。 */
|
|
78
|
+
function errorMessageOf(error) {
|
|
79
|
+
const message = asRecord(error)?.["message"];
|
|
80
|
+
return typeof message === "string" && message !== "" ? message : "请求失败";
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* POST 一个 JSON 请求体并解包 `{ ok: true, value }`。
|
|
84
|
+
*
|
|
85
|
+
* 失败路径**全部**折成 `ApiError`(绝不让 `TypeError`/`DOMException` 漏给调用方)——
|
|
86
|
+
* 面板只认 `ApiError.code`,漏一种异常就多一条白屏路径。
|
|
87
|
+
*
|
|
88
|
+
* **定时器必须在 `finally` 里清掉**:`setTimeout` 会持有一个活动 handle,
|
|
89
|
+
* 不清就会让 vitest 进程得不到退出许可(表现为用例全绿但运行不结束)。
|
|
90
|
+
* 中止发生在 fetch 已 settle 之后时,`abort()` 本身是幂等的,不产生副作用。
|
|
91
|
+
*/
|
|
92
|
+
async function post(route, body, timeoutMs = DEFAULT_TIMEOUT_MS) {
|
|
93
|
+
const controller = new AbortController();
|
|
94
|
+
const timer = setTimeout(() => {
|
|
95
|
+
controller.abort();
|
|
96
|
+
}, timeoutMs);
|
|
97
|
+
try {
|
|
98
|
+
let response;
|
|
99
|
+
try {
|
|
100
|
+
response = await fetch(`/${route}`, {
|
|
101
|
+
method: "POST",
|
|
102
|
+
cache: "no-store",
|
|
103
|
+
headers: { "content-type": "application/json" },
|
|
104
|
+
body: JSON.stringify(body),
|
|
105
|
+
signal: controller.signal
|
|
106
|
+
});
|
|
107
|
+
} catch (error) {
|
|
108
|
+
throw new ApiError("network", describeNetworkFailure(error, timeoutMs));
|
|
109
|
+
}
|
|
110
|
+
let payload;
|
|
111
|
+
try {
|
|
112
|
+
payload = await response.json();
|
|
113
|
+
} catch (error) {
|
|
114
|
+
throw new ApiError("network", `响应不是合法 JSON:${String(error)}`);
|
|
115
|
+
}
|
|
116
|
+
const record = asRecord(payload);
|
|
117
|
+
if (record === null || typeof record["ok"] !== "boolean") throw new ApiError("network", "响应信封形状非法");
|
|
118
|
+
if (record["ok"] === false) throw new ApiError(errorCodeOf(record["error"]), errorMessageOf(record["error"]));
|
|
119
|
+
return record["value"];
|
|
120
|
+
} finally {
|
|
121
|
+
clearTimeout(timer);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/** 把中止/网络异常翻译成一句用户能自己处理的说明。 */
|
|
125
|
+
function describeNetworkFailure(error, timeoutMs) {
|
|
126
|
+
if (error instanceof DOMException && error.name === "AbortError") return `请求超时(${timeoutMs}ms)或已被取消`;
|
|
127
|
+
if (asRecord(error)?.["name"] === "AbortError") return `请求超时(${timeoutMs}ms)或已被取消`;
|
|
128
|
+
return `网络请求失败:${String(error)}`;
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region \0dsh-css-module:/Users/go/proj/dsh-skill-scope/src/client/styles.module.css?dsh-css-module
|
|
132
|
+
const css = ".p4Fk8G_panel{box-sizing:border-box;flex-direction:column;gap:16px;height:100%;padding:20px 24px 32px;display:flex;overflow-y:auto}.p4Fk8G_overlay{pointer-events:auto;background:var(--dsw-alias-bg-mask-1,#00000073);z-index:60;justify-content:center;align-items:center;display:flex;position:fixed;inset:0}.p4Fk8G_modal{z-index:1;background:var(--dsw-alias-bg-layer-1,Canvas);width:min(760px,100vw - 48px);max-width:calc(100vw - 48px);height:min(680px,100vh - 48px);color:var(--dsw-alias-label-primary,CanvasText);border-radius:24px;flex-direction:column;display:flex;position:relative;overflow:hidden;box-shadow:0 24px 64px #00000052}.p4Fk8G_panelHead{flex-direction:column;gap:16px;padding:24px 24px 16px;display:flex}.p4Fk8G_header{justify-content:space-between;align-items:center;gap:12px;display:flex}.p4Fk8G_title{margin:0;font-size:17px;font-weight:600;line-height:1.3}.p4Fk8G_intro{color:var(--dsw-alias-label-secondary,currentColor);margin:0;font-size:13px;line-height:1.55}.p4Fk8G_introWarn{color:var(--dsw-alias-state-warn-primary,currentColor);font-weight:600}.p4Fk8G_closeButton{width:28px;height:28px;color:var(--dsw-alias-label-secondary,currentColor);cursor:pointer;background:0 0;border:0;border-radius:8px;flex:none;justify-content:center;align-items:center;padding:0;display:inline-flex}.p4Fk8G_closeButton:hover{background:var(--dsw-alias-interactive-bg-hover,transparent);color:var(--dsw-alias-label-primary,currentColor)}.p4Fk8G_searchRow{align-items:center;display:flex;position:relative}.p4Fk8G_searchIcon{color:var(--dsw-alias-label-tertiary,currentColor);pointer-events:none;display:inline-flex;position:absolute;left:12px}.p4Fk8G_search{border:1px solid var(--dsw-alias-border-l2,currentColor);background:var(--dsw-alias-bg-layer-3,transparent);width:100%;color:var(--dsw-alias-label-primary,currentColor);font:inherit;border-radius:10px;padding:9px 12px 9px 36px;font-size:13px}.p4Fk8G_search::placeholder{color:var(--dsw-alias-label-tertiary,currentColor)}.p4Fk8G_search:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,currentColor);outline-offset:1px}.p4Fk8G_panelBody{flex:1;min-height:0;padding:4px 24px 24px;overflow-y:auto}.p4Fk8G_body{flex-direction:column;gap:14px;width:100%;display:flex}.p4Fk8G_section{flex-direction:column;gap:10px;min-width:0;display:flex}.p4Fk8G_sectionHead{align-items:center;gap:8px;min-width:0;display:flex}.p4Fk8G_sectionToggle{min-width:0;color:var(--dsw-alias-label-primary,currentColor);font:inherit;cursor:pointer;text-align:left;background:0 0;border:0;flex:1;align-items:center;gap:8px;padding:2px 0;display:flex}.p4Fk8G_sectionTitle{margin:0;font-size:14px;font-weight:600}.p4Fk8G_sectionCount{color:var(--dsw-alias-label-secondary,currentColor);font-size:13px}.p4Fk8G_sectionChevron{color:var(--dsw-alias-label-secondary,currentColor);margin-left:auto;transition:transform .14s;display:inline-flex}.p4Fk8G_sectionChevronOpen{transform:rotate(180deg)}.p4Fk8G_cards{grid-template-columns:repeat(2,minmax(0,1fr));align-items:start;gap:12px;margin:0;padding:0;list-style:none;display:grid}.p4Fk8G_groups{flex-direction:column;gap:14px;display:flex}.p4Fk8G_group{border-left:2px solid var(--dsw-alias-border-1,#00000014);flex-direction:column;gap:8px;min-width:0;padding-left:10px;display:flex}.p4Fk8G_groupToggle{min-width:0;color:var(--dsw-alias-label-secondary,currentColor);font:inherit;cursor:pointer;text-align:left;background:0 0;border:0;align-items:center;gap:6px;padding:2px 0;font-size:13px;font-weight:600;display:flex}.p4Fk8G_groupToggle:hover{color:var(--dsw-alias-label-primary,currentColor)}.p4Fk8G_groupChevron{flex:none;transition:transform .14s;display:inline-flex}.p4Fk8G_groupChevron[data-open=true]{transform:rotate(180deg)}.p4Fk8G_groupTitle{text-overflow:ellipsis;white-space:nowrap;min-width:0;overflow:hidden}.p4Fk8G_groupCount{color:var(--dsw-alias-label-tertiary,var(--dsw-alias-label-secondary,currentColor));font-variant-numeric:tabular-nums;flex:none;font-weight:400}@media (width<=640px){.p4Fk8G_cards{grid-template-columns:minmax(0,1fr)}}.p4Fk8G_card{border:1px solid var(--dsw-alias-border-l2,currentColor);background:var(--dsw-alias-bg-layer-3,transparent);border-radius:10px;min-width:0;overflow:hidden}.p4Fk8G_cardHead{align-items:center;gap:10px;min-width:0;padding:11px 12px;display:flex}.p4Fk8G_cardMain{flex:1;align-items:center;gap:10px;min-width:0;display:flex}.p4Fk8G_cardName{text-overflow:ellipsis;white-space:nowrap;flex:1;min-width:0;font-size:13px;font-weight:600;overflow:hidden}.p4Fk8G_cardDisabled .p4Fk8G_cardName{color:var(--dsw-alias-label-secondary,currentColor)}.p4Fk8G_cardTail{flex:0 3 auto;align-items:center;gap:6px;min-width:0;display:inline-flex}.p4Fk8G_expandButton{width:20px;height:20px;color:var(--dsw-alias-label-secondary,currentColor);cursor:pointer;background:0 0;border:0;border-radius:6px;flex:none;justify-content:center;align-items:center;padding:0;display:inline-flex}.p4Fk8G_expandButton:hover{background:var(--dsw-alias-interactive-bg-hover,transparent)}.p4Fk8G_expandChevron{transition:transform .14s;display:inline-flex}.p4Fk8G_expandChevronOpen{transform:rotate(180deg)}.p4Fk8G_cardBody{border-top:1px solid var(--dsw-alias-border-l2,currentColor);color:var(--dsw-alias-label-secondary,currentColor);padding:10px;font-size:12px;line-height:1.55}.p4Fk8G_cardDescription{overflow-wrap:anywhere;margin:0}.p4Fk8G_detailRow{gap:10px;margin-top:8px;display:flex}.p4Fk8G_detailKey{width:56px;color:var(--dsw-alias-label-secondary,currentColor);flex:none}.p4Fk8G_detailValue{min-width:0;color:var(--dsw-alias-label-primary,currentColor);overflow-wrap:anywhere}.p4Fk8G_detailOrigin{min-width:0;color:var(--dsw-alias-label-primary,currentColor);overflow-wrap:anywhere;word-break:break-all;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;line-height:1.5}.p4Fk8G_toolList{min-width:0;max-height:120px;margin:0;padding:0;list-style:none;overflow-y:auto}.p4Fk8G_toolName{color:var(--dsw-alias-label-primary,currentColor);overflow-wrap:anywhere;word-break:break-all;font-family:ui-monospace,SFMono-Regular,Menlo,monospace}.p4Fk8G_switch{cursor:pointer;background:0 0;border:0;border-radius:999px;flex:none;align-items:center;padding:0;display:inline-flex}.p4Fk8G_switch:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,currentColor);outline-offset:2px}.p4Fk8G_switchTrack{background:var(--dsw-alias-border-l2,currentColor);border-radius:999px;width:28px;height:16px;transition:background-color .12s ease-in-out;display:inline-block;position:relative}.p4Fk8G_switchOn .p4Fk8G_switchTrack{background:var(--dsw-alias-state-business-primary,currentColor)}.p4Fk8G_switchThumb{background:var(--dsw-alias-bg-layer-1,currentColor);border-radius:50%;width:12px;height:12px;transition:transform .12s ease-in-out;position:absolute;top:2px;left:2px}.p4Fk8G_switchOn .p4Fk8G_switchThumb{transform:translate(12px)}.p4Fk8G_switch:disabled{cursor:not-allowed;opacity:.5}.p4Fk8G_count{color:var(--dsw-alias-label-secondary,currentColor);font-size:13px}.p4Fk8G_badge{border:1px solid var(--dsw-alias-border-l3,currentColor);color:var(--dsw-alias-label-secondary,currentColor);white-space:nowrap;border-radius:999px;padding:1px 6px;font-size:11px;display:inline-block}.p4Fk8G_alert{border:1px solid var(--dsw-alias-state-error-primary,currentColor);color:var(--dsw-alias-state-error-primary,currentColor);border-radius:8px;justify-content:space-between;align-items:center;gap:8px;padding:8px 10px;font-size:12px;display:flex}.p4Fk8G_modeRow{flex-wrap:wrap;align-items:center;gap:6px;display:flex}.p4Fk8G_modeButton{border:1px solid var(--dsw-alias-border-l2,currentColor);color:var(--dsw-alias-label-secondary,currentColor);font:inherit;cursor:pointer;background:0 0;border-radius:999px;padding:4px 12px;font-size:12px}.p4Fk8G_modeButton:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover,transparent)}.p4Fk8G_modeButtonActive{border-color:var(--dsw-alias-brand-primary,currentColor);background:var(--dsw-alias-interactive-bg-active,transparent);color:var(--dsw-alias-brand-primary,currentColor)}.p4Fk8G_modeButton:disabled{cursor:not-allowed;opacity:.5}.p4Fk8G_button{border:1px solid var(--dsw-alias-border-l2,currentColor);color:var(--dsw-alias-label-secondary,currentColor);font:inherit;cursor:pointer;background:0 0;border-radius:8px;padding:4px 10px;font-size:12px}.p4Fk8G_button:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover,transparent)}.p4Fk8G_button:disabled{cursor:not-allowed;opacity:.5}.p4Fk8G_details{border:1px solid var(--dsw-alias-border-l2,currentColor);border-radius:8px;padding:8px 10px;font-size:12px}.p4Fk8G_detailsSummary{cursor:pointer;color:var(--dsw-alias-label-secondary,currentColor)}.p4Fk8G_detailsList{flex-direction:column;gap:4px;margin:8px 0 0;padding:0;list-style:none;display:flex}.p4Fk8G_detailsRow{justify-content:space-between;align-items:center;gap:10px;min-width:0;display:flex}.p4Fk8G_detailsName{text-overflow:ellipsis;white-space:nowrap;min-width:0;overflow:hidden}.p4Fk8G_empty{color:var(--dsw-alias-label-secondary,currentColor);padding:4px 2px;font-size:12px}.p4Fk8G_chip{border:1px solid var(--dsw-alias-border-l2,currentColor);color:var(--dsw-alias-label-secondary,currentColor);font:inherit;cursor:pointer;background:0 0;border-radius:999px;align-items:center;gap:5px;padding:3px 9px;font-size:12px;display:inline-flex}.p4Fk8G_chip:hover{background:var(--dsw-alias-interactive-bg-hover,transparent)}";
|
|
133
|
+
const tagId = "dsh-skill-scope/styles.module.css";
|
|
134
|
+
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
|
|
135
|
+
const tag = document.createElement("style");
|
|
136
|
+
tag.dataset.plugin = "dsh-skill-scope";
|
|
137
|
+
tag.dataset.pluginCss = tagId;
|
|
138
|
+
tag.textContent = css;
|
|
139
|
+
document.head.appendChild(tag);
|
|
140
|
+
}
|
|
141
|
+
var styles_module_default = {
|
|
142
|
+
"cardName": "p4Fk8G_cardName",
|
|
143
|
+
"cardTail": "p4Fk8G_cardTail",
|
|
144
|
+
"sectionChevronOpen": "p4Fk8G_sectionChevronOpen",
|
|
145
|
+
"detailKey": "p4Fk8G_detailKey",
|
|
146
|
+
"empty": "p4Fk8G_empty",
|
|
147
|
+
"cardBody": "p4Fk8G_cardBody",
|
|
148
|
+
"header": "p4Fk8G_header",
|
|
149
|
+
"introWarn": "p4Fk8G_introWarn",
|
|
150
|
+
"sectionTitle": "p4Fk8G_sectionTitle",
|
|
151
|
+
"modeButton": "p4Fk8G_modeButton",
|
|
152
|
+
"expandChevron": "p4Fk8G_expandChevron",
|
|
153
|
+
"detailOrigin": "p4Fk8G_detailOrigin",
|
|
154
|
+
"modal": "p4Fk8G_modal",
|
|
155
|
+
"sectionHead": "p4Fk8G_sectionHead",
|
|
156
|
+
"title": "p4Fk8G_title",
|
|
157
|
+
"detailsName": "p4Fk8G_detailsName",
|
|
158
|
+
"groups": "p4Fk8G_groups",
|
|
159
|
+
"toolList": "p4Fk8G_toolList",
|
|
160
|
+
"switchOn": "p4Fk8G_switchOn",
|
|
161
|
+
"detailsList": "p4Fk8G_detailsList",
|
|
162
|
+
"panelBody": "p4Fk8G_panelBody",
|
|
163
|
+
"overlay": "p4Fk8G_overlay",
|
|
164
|
+
"toolName": "p4Fk8G_toolName",
|
|
165
|
+
"cardMain": "p4Fk8G_cardMain",
|
|
166
|
+
"cardDisabled": "p4Fk8G_cardDisabled",
|
|
167
|
+
"groupChevron": "p4Fk8G_groupChevron",
|
|
168
|
+
"detailsRow": "p4Fk8G_detailsRow",
|
|
169
|
+
"body": "p4Fk8G_body",
|
|
170
|
+
"sectionCount": "p4Fk8G_sectionCount",
|
|
171
|
+
"expandButton": "p4Fk8G_expandButton",
|
|
172
|
+
"detailValue": "p4Fk8G_detailValue",
|
|
173
|
+
"cardDescription": "p4Fk8G_cardDescription",
|
|
174
|
+
"panel": "p4Fk8G_panel",
|
|
175
|
+
"groupCount": "p4Fk8G_groupCount",
|
|
176
|
+
"button": "p4Fk8G_button",
|
|
177
|
+
"panelHead": "p4Fk8G_panelHead",
|
|
178
|
+
"badge": "p4Fk8G_badge",
|
|
179
|
+
"groupTitle": "p4Fk8G_groupTitle",
|
|
180
|
+
"detailRow": "p4Fk8G_detailRow",
|
|
181
|
+
"detailsSummary": "p4Fk8G_detailsSummary",
|
|
182
|
+
"sectionChevron": "p4Fk8G_sectionChevron",
|
|
183
|
+
"section": "p4Fk8G_section",
|
|
184
|
+
"count": "p4Fk8G_count",
|
|
185
|
+
"closeButton": "p4Fk8G_closeButton",
|
|
186
|
+
"group": "p4Fk8G_group",
|
|
187
|
+
"switchTrack": "p4Fk8G_switchTrack",
|
|
188
|
+
"switchThumb": "p4Fk8G_switchThumb",
|
|
189
|
+
"card": "p4Fk8G_card",
|
|
190
|
+
"chip": "p4Fk8G_chip",
|
|
191
|
+
"cardHead": "p4Fk8G_cardHead",
|
|
192
|
+
"searchIcon": "p4Fk8G_searchIcon",
|
|
193
|
+
"modeRow": "p4Fk8G_modeRow",
|
|
194
|
+
"alert": "p4Fk8G_alert",
|
|
195
|
+
"sectionToggle": "p4Fk8G_sectionToggle",
|
|
196
|
+
"cards": "p4Fk8G_cards",
|
|
197
|
+
"groupToggle": "p4Fk8G_groupToggle",
|
|
198
|
+
"expandChevronOpen": "p4Fk8G_expandChevronOpen",
|
|
199
|
+
"details": "p4Fk8G_details",
|
|
200
|
+
"switch": "p4Fk8G_switch",
|
|
201
|
+
"searchRow": "p4Fk8G_searchRow",
|
|
202
|
+
"search": "p4Fk8G_search",
|
|
203
|
+
"intro": "p4Fk8G_intro",
|
|
204
|
+
"modeButtonActive": "p4Fk8G_modeButtonActive"
|
|
205
|
+
};
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region src/client/parts.tsx
|
|
208
|
+
/**
|
|
209
|
+
* 转义正则元字符。
|
|
210
|
+
*
|
|
211
|
+
* 搜索框的内容会进 `RegExp`:不转义时用户输入 `(` 或 `[` 会抛 `SyntaxError`,
|
|
212
|
+
* 把一个「输入过滤」变成白屏。这是审查里常见的真实缺陷,所以在这里一次性堵住。
|
|
213
|
+
*/
|
|
214
|
+
function escapeRegExp(text) {
|
|
215
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
216
|
+
}
|
|
217
|
+
/** 一个内联 SVG 箭头(chevron)。**不引第三方图标库**:宿主模块表里没有它,引了会多打一份包。 */
|
|
218
|
+
function Chevron(props) {
|
|
219
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
|
|
220
|
+
className: props.className,
|
|
221
|
+
width: "14",
|
|
222
|
+
height: "14",
|
|
223
|
+
viewBox: "0 0 16 16",
|
|
224
|
+
fill: "none",
|
|
225
|
+
"aria-hidden": "true",
|
|
226
|
+
focusable: "false",
|
|
227
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
228
|
+
d: "M4 6.5L8 10.5L12 6.5",
|
|
229
|
+
stroke: "currentColor",
|
|
230
|
+
strokeWidth: "1.6",
|
|
231
|
+
strokeLinecap: "round",
|
|
232
|
+
strokeLinejoin: "round"
|
|
233
|
+
})
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/** 放大镜图标(搜索框内)。 */
|
|
237
|
+
function SearchIcon() {
|
|
238
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
239
|
+
width: "15",
|
|
240
|
+
height: "15",
|
|
241
|
+
viewBox: "0 0 16 16",
|
|
242
|
+
fill: "none",
|
|
243
|
+
"aria-hidden": "true",
|
|
244
|
+
focusable: "false",
|
|
245
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
246
|
+
cx: "7",
|
|
247
|
+
cy: "7",
|
|
248
|
+
r: "4.5",
|
|
249
|
+
stroke: "currentColor",
|
|
250
|
+
strokeWidth: "1.5"
|
|
251
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
252
|
+
d: "M10.5 10.5L14 14",
|
|
253
|
+
stroke: "currentColor",
|
|
254
|
+
strokeWidth: "1.5",
|
|
255
|
+
strokeLinecap: "round"
|
|
256
|
+
})]
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
/** 关闭图标(✕)。 */
|
|
260
|
+
function CloseIcon() {
|
|
261
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
|
|
262
|
+
width: "15",
|
|
263
|
+
height: "15",
|
|
264
|
+
viewBox: "0 0 16 16",
|
|
265
|
+
fill: "none",
|
|
266
|
+
"aria-hidden": "true",
|
|
267
|
+
focusable: "false",
|
|
268
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
269
|
+
d: "M4 4L12 12M12 4L4 12",
|
|
270
|
+
stroke: "currentColor",
|
|
271
|
+
strokeWidth: "1.6",
|
|
272
|
+
strokeLinecap: "round"
|
|
273
|
+
})
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* 四叶草(**空心线描**)—— 本插件的标识图标,**两个入口共用同一个**:
|
|
278
|
+
* 侧栏 `sidebar.panellist` 的图标位与输入框右侧的工作区 chip。
|
|
279
|
+
*
|
|
280
|
+
* **为什么是四叶草而不是工具图形**:最初想画交叉的斧头与锤子,试了 8 轮都没成——
|
|
281
|
+
* 两件工具的头部各需约 10×6px,在 16px 画布上还要留出交叉的柄,必然糊成一团灰块。
|
|
282
|
+
* 旁证:Tabler 与 Lucide 都把 `hammer`、`axe` 作为**各自独立**的图标发布,
|
|
283
|
+
* 没有一家提供交叉的那对——这个缺席本身就说明该构图在该尺寸下不成立。
|
|
284
|
+
* 四叶草是一个紧凑的集中块面、无交叉结构,16px 下轮廓依然完整。
|
|
285
|
+
*
|
|
286
|
+
* **叶形要点(试错得到,勿轻易改)**:叶要**接近圆形**、外缘只有**浅凹口**,
|
|
287
|
+
* 且内侧在圆心附近**相接**。走偏的两个反例:notch 加深会让它变成「四个心形花瓣」
|
|
288
|
+
* 的花;叶子拉长再加宽又会变成「圆环套星」。
|
|
289
|
+
*
|
|
290
|
+
* **单色 `currentColor`**:图标会出现在两处继承色不同的位置
|
|
291
|
+
* (侧栏未选中是次级色、选中/悬停是强调色,chip 是一颗按钮)。
|
|
292
|
+
* 单一 `currentColor` 让它自动贴合任何一处的文字色,不会出现色块不一致。
|
|
293
|
+
*/
|
|
294
|
+
function CloverIcon(props) {
|
|
295
|
+
const size = props.size ?? 16;
|
|
296
|
+
const leaf = "M12 10.8C15.844 9.296 18.2 6.288 16.34 2.528C14.604 0.836 13.24 2 12 2.6C10.76 2 9.396 0.836 7.66 2.528C5.8 6.288 8.156 9.296 12 10.8Z";
|
|
297
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
|
|
298
|
+
width: size,
|
|
299
|
+
height: size,
|
|
300
|
+
viewBox: "0 0 24 24",
|
|
301
|
+
fill: "none",
|
|
302
|
+
stroke: "currentColor",
|
|
303
|
+
strokeWidth: "1.7",
|
|
304
|
+
strokeLinejoin: "round",
|
|
305
|
+
strokeLinecap: "round",
|
|
306
|
+
"aria-hidden": "true",
|
|
307
|
+
focusable: "false",
|
|
308
|
+
children: [
|
|
309
|
+
0,
|
|
310
|
+
90,
|
|
311
|
+
180,
|
|
312
|
+
270
|
|
313
|
+
].map((angle) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
314
|
+
d: leaf,
|
|
315
|
+
transform: `rotate(${angle} 12 12)`
|
|
316
|
+
}, angle))
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* 一张能力卡:开关 + 名称 + 状态 tag + 展开箭头,展开后显示描述与「状态」明细。
|
|
321
|
+
*
|
|
322
|
+
* **状态 tag 复用宿主 `Tag` 基元**(`tone="success"` / `"neutral"`),理由与原先的来源标签一致:
|
|
323
|
+
* ① 主题与暗色由基元统一处理,自己写会漂移;② `Tag` 在宿主模块表里,`require` 命中单例,
|
|
324
|
+
* 不会重复打包一份样式;③ 它让本 bundle 真的 import 了
|
|
325
|
+
* `@deepseek-ai/dsh-client-ui-primitives`——这与 `package.json` 的
|
|
326
|
+
* `dsh.client.external` 声明一致(声明为外部依赖,就必须真的有该模块请求)。
|
|
327
|
+
*/
|
|
328
|
+
function CapabilityCard(props) {
|
|
329
|
+
const { row, testId } = props;
|
|
330
|
+
const [open, setOpen] = (0, react.useState)(false);
|
|
331
|
+
const readonly = row.readonly === true;
|
|
332
|
+
const stateText = row.enabled ? props.enabledLabel : props.disabledLabel;
|
|
333
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
|
|
334
|
+
className: readonly ? `${styles_module_default.card} ${styles_module_default.cardDisabled}` : styles_module_default.card,
|
|
335
|
+
...testId === void 0 ? {} : { "data-testid": testId },
|
|
336
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
337
|
+
className: styles_module_default.cardHead,
|
|
338
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
339
|
+
className: styles_module_default.cardMain,
|
|
340
|
+
children: [readonly ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
341
|
+
className: styles_module_default.switch,
|
|
342
|
+
"aria-hidden": "true",
|
|
343
|
+
style: { visibility: "hidden" }
|
|
344
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Switch, {
|
|
345
|
+
checked: row.enabled,
|
|
346
|
+
label: row.name,
|
|
347
|
+
onChange: (next) => {
|
|
348
|
+
props.onToggle(row.name, next);
|
|
349
|
+
}
|
|
350
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
351
|
+
className: styles_module_default.cardName,
|
|
352
|
+
title: row.name,
|
|
353
|
+
children: row.name
|
|
354
|
+
})]
|
|
355
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
356
|
+
className: styles_module_default.cardTail,
|
|
357
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, {
|
|
358
|
+
tone: row.enabled ? "success" : "neutral",
|
|
359
|
+
children: stateText
|
|
360
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
361
|
+
type: "button",
|
|
362
|
+
className: styles_module_default.expandButton,
|
|
363
|
+
"aria-expanded": open,
|
|
364
|
+
"aria-label": `${open ? props.collapseLabel : props.expandLabel}: ${row.name}`,
|
|
365
|
+
onClick: () => {
|
|
366
|
+
setOpen((previous) => !previous);
|
|
367
|
+
},
|
|
368
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Chevron, {
|
|
369
|
+
open,
|
|
370
|
+
className: open ? `${styles_module_default.expandChevron} ${styles_module_default.expandChevronOpen}` : styles_module_default.expandChevron
|
|
371
|
+
})
|
|
372
|
+
})]
|
|
373
|
+
})]
|
|
374
|
+
}), open ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
375
|
+
className: styles_module_default.cardBody,
|
|
376
|
+
children: [
|
|
377
|
+
row.description === "" ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
378
|
+
className: styles_module_default.cardDescription,
|
|
379
|
+
children: row.description
|
|
380
|
+
}),
|
|
381
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
382
|
+
className: styles_module_default.detailRow,
|
|
383
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
384
|
+
className: styles_module_default.detailKey,
|
|
385
|
+
children: props.detailStateKey
|
|
386
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
387
|
+
className: styles_module_default.detailValue,
|
|
388
|
+
children: stateText
|
|
389
|
+
})]
|
|
390
|
+
}),
|
|
391
|
+
row.tools === void 0 || row.tools.length === 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
392
|
+
className: styles_module_default.detailRow,
|
|
393
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
394
|
+
className: styles_module_default.detailKey,
|
|
395
|
+
children: props.detailToolsKey
|
|
396
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
|
|
397
|
+
className: styles_module_default.toolList,
|
|
398
|
+
children: row.tools.map((toolName) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", {
|
|
399
|
+
className: styles_module_default.toolName,
|
|
400
|
+
title: toolName,
|
|
401
|
+
children: toolName
|
|
402
|
+
}, toolName))
|
|
403
|
+
})]
|
|
404
|
+
}),
|
|
405
|
+
row.origin === void 0 && row.group === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
406
|
+
className: styles_module_default.detailRow,
|
|
407
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
408
|
+
className: styles_module_default.detailKey,
|
|
409
|
+
children: props.detailSourceKey
|
|
410
|
+
}), row.origin === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
411
|
+
className: styles_module_default.detailOrigin,
|
|
412
|
+
children: props.ungroupedOriginLabel ?? ""
|
|
413
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
414
|
+
className: styles_module_default.detailOrigin,
|
|
415
|
+
title: row.origin,
|
|
416
|
+
children: row.origin
|
|
417
|
+
})]
|
|
418
|
+
})
|
|
419
|
+
]
|
|
420
|
+
}) : null]
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* 一段可切换能力列表。
|
|
425
|
+
*
|
|
426
|
+
* **不变量 21(承重)**:这里**没有**按名字自由添加的输入框。用户只能切换清单里**已经存在**
|
|
427
|
+
* 的名字;添加不存在的名字既没有输入口,也没有对应的写入字段。搜索框只做**过滤**,不产生新条目。
|
|
428
|
+
*
|
|
429
|
+
* 版式:分区头(标题 + 计数 + 折叠箭头)→ 两列卡片网格。搜索框在面板顶部统一渲染,
|
|
430
|
+
* 本组件只接收 `externalQuery` 做过滤,因此「技能」与「MCP」被同一个词同时过滤。
|
|
431
|
+
*
|
|
432
|
+
* **来源分组(可选)**:当每一行都带 `group` 时,卡片不再平铺,而是按组渲染成若干
|
|
433
|
+
* 可独立折叠的小节(见 `SkillGroups`)。只要有一行缺 `group`,整段就保持扁平 ——
|
|
434
|
+
* 这样 MCP 段与工作区弹层的 MCP 段自动不受影响,两个面板共用同一段实现。
|
|
435
|
+
*/
|
|
436
|
+
function CapabilityList(props) {
|
|
437
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CapabilitySection, { ...props });
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* 把行按 `group` 归拢,并**保持组内原有顺序**。
|
|
441
|
+
*
|
|
442
|
+
* 组的先后按**首次出现**决定,不排序:服务端的清单已按 skill 名做过稳定排序
|
|
443
|
+
* (`compareSkillSummary`),组内顺序因此与扁平视图一致。组间用「首次出现」而不是
|
|
444
|
+
* 按名字排序,是为了让顺序与清单同源 —— 换一次排序就会让用户折叠过的组跳位置。
|
|
445
|
+
*/
|
|
446
|
+
function groupRows(rows) {
|
|
447
|
+
const order = [];
|
|
448
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
449
|
+
for (const row of rows) {
|
|
450
|
+
const key = row.group ?? "";
|
|
451
|
+
let bucket = buckets.get(key);
|
|
452
|
+
if (bucket === void 0) {
|
|
453
|
+
bucket = [];
|
|
454
|
+
buckets.set(key, bucket);
|
|
455
|
+
order.push(key);
|
|
456
|
+
}
|
|
457
|
+
bucket.push(row);
|
|
458
|
+
}
|
|
459
|
+
return order.map((key) => ({
|
|
460
|
+
key,
|
|
461
|
+
label: buckets.get(key)?.[0]?.groupLabel ?? "",
|
|
462
|
+
rows: buckets.get(key) ?? []
|
|
463
|
+
}));
|
|
464
|
+
}
|
|
465
|
+
/** 一行都不缺 `group` 时才启用分组。空列表不分组(没有行可归拢)。 */
|
|
466
|
+
function groupsEnabled(rows) {
|
|
467
|
+
return rows.length > 0 && rows.every((row) => row.group !== void 0);
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* 计数文案 `启用量/总量`。**分区标题与分组头共用这一份**,两处口径不许分叉。
|
|
471
|
+
*
|
|
472
|
+
* 两个数都取自**同一批可见行**(搜索过滤之后),所以搜索时两个数一起变小 ——
|
|
473
|
+
* 不会出现「4/34」而屏幕上只剩 3 张卡片。
|
|
474
|
+
*
|
|
475
|
+
* 只读行(MCP 的未加载 / 不可限制项)照样计入总量与启用数:它们也是列表里实实在在
|
|
476
|
+
* 占了一格的东西,从总量里扣掉会让「这一组有几个」对不上眼前的卡片数。
|
|
477
|
+
*/
|
|
478
|
+
function countText(rows) {
|
|
479
|
+
return `${rows.filter((row) => row.enabled).length}/${rows.length}`;
|
|
480
|
+
}
|
|
481
|
+
/** 分区实现。折叠状态由本组件自己持有(默认展开),调用方不干预。 */
|
|
482
|
+
function CapabilitySection(props) {
|
|
483
|
+
const { rows, testIdPrefix } = props;
|
|
484
|
+
const [open, setOpen] = (0, react.useState)(true);
|
|
485
|
+
const query = (props.externalQuery ?? "").trim();
|
|
486
|
+
const matcher = query === "" ? null : new RegExp(escapeRegExp(query), "i");
|
|
487
|
+
const visible = matcher === null ? rows : rows.filter((row) => matcher.test(row.name));
|
|
488
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
489
|
+
className: styles_module_default.section,
|
|
490
|
+
...props.sectionTitleId === void 0 ? {} : { "aria-labelledby": props.sectionTitleId },
|
|
491
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
492
|
+
className: styles_module_default.sectionHead,
|
|
493
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
494
|
+
type: "button",
|
|
495
|
+
className: styles_module_default.sectionToggle,
|
|
496
|
+
"aria-expanded": open,
|
|
497
|
+
onClick: () => {
|
|
498
|
+
setOpen((previous) => !previous);
|
|
499
|
+
},
|
|
500
|
+
children: [
|
|
501
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
502
|
+
className: styles_module_default.sectionTitle,
|
|
503
|
+
id: props.sectionTitleId,
|
|
504
|
+
children: props.title
|
|
505
|
+
}),
|
|
506
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
507
|
+
className: styles_module_default.sectionCount,
|
|
508
|
+
"data-testid": `${testIdPrefix ?? ""}count`,
|
|
509
|
+
children: props.countLabel === void 0 ? countText(visible) : `${countText(visible)} ${props.countLabel}`
|
|
510
|
+
}),
|
|
511
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
512
|
+
className: open ? `${styles_module_default.sectionChevron} ${styles_module_default.sectionChevronOpen}` : styles_module_default.sectionChevron,
|
|
513
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Chevron, { open })
|
|
514
|
+
})
|
|
515
|
+
]
|
|
516
|
+
})
|
|
517
|
+
}), open ? visible.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
518
|
+
className: styles_module_default.empty,
|
|
519
|
+
children: props.emptyText
|
|
520
|
+
}) : groupsEnabled(visible) ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SkillGroups, {
|
|
521
|
+
groups: groupRows(visible),
|
|
522
|
+
section: props,
|
|
523
|
+
...testIdPrefix === void 0 ? {} : { testIdPrefix }
|
|
524
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
|
|
525
|
+
className: styles_module_default.cards,
|
|
526
|
+
children: visible.map((row) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CapabilityCard, {
|
|
527
|
+
...props,
|
|
528
|
+
row,
|
|
529
|
+
...testIdPrefix === void 0 ? {} : { testId: `${testIdPrefix}${row.name}` }
|
|
530
|
+
}, row.name))
|
|
531
|
+
}) : null]
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* 按来源分组的卡片区:每组一个小节头(组名 + 项数 + 折叠箭头)+ 两列卡片网格。
|
|
536
|
+
*
|
|
537
|
+
* **每组各自持有一份折叠状态**(`openGroups` 是 `Set` 而不是单个布尔):用户折叠
|
|
538
|
+
* `gbrain` 那一组之后,不该把 `superpowers` 也一起折掉——那样「视觉分组」就退化成
|
|
539
|
+
* 「整段折叠」,批量浏览反而更费事。
|
|
540
|
+
*
|
|
541
|
+
* **默认全部展开**:需求是「方便批量管理」,进去先看到全貌再决定折哪一组;
|
|
542
|
+
* 默认折叠会让用户每进一次都要先点开 6 组。
|
|
543
|
+
*/
|
|
544
|
+
function SkillGroups(params) {
|
|
545
|
+
const [collapsed, setCollapsed] = (0, react.useState)(() => /* @__PURE__ */ new Set());
|
|
546
|
+
const toggle = (key) => {
|
|
547
|
+
setCollapsed((previous) => {
|
|
548
|
+
const next = new Set(previous);
|
|
549
|
+
if (next.has(key)) next.delete(key);
|
|
550
|
+
else next.add(key);
|
|
551
|
+
return next;
|
|
552
|
+
});
|
|
553
|
+
};
|
|
554
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
555
|
+
className: styles_module_default.groups,
|
|
556
|
+
...params.testIdPrefix === void 0 ? {} : { "data-testid": `${params.testIdPrefix}groups` },
|
|
557
|
+
children: params.groups.map((group) => {
|
|
558
|
+
const open = !collapsed.has(group.key);
|
|
559
|
+
const label = group.label === "" ? params.section.ungroupedLabel ?? "" : group.label;
|
|
560
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
561
|
+
className: styles_module_default.group,
|
|
562
|
+
"data-testid": `group:${group.key}`,
|
|
563
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
564
|
+
type: "button",
|
|
565
|
+
className: styles_module_default.groupToggle,
|
|
566
|
+
"aria-expanded": open,
|
|
567
|
+
onClick: () => {
|
|
568
|
+
toggle(group.key);
|
|
569
|
+
},
|
|
570
|
+
children: [
|
|
571
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
572
|
+
className: styles_module_default.groupChevron,
|
|
573
|
+
"data-open": open ? "true" : "false",
|
|
574
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Chevron, { open })
|
|
575
|
+
}),
|
|
576
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
577
|
+
className: styles_module_default.groupTitle,
|
|
578
|
+
title: group.key,
|
|
579
|
+
children: label
|
|
580
|
+
}),
|
|
581
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
582
|
+
className: styles_module_default.groupCount,
|
|
583
|
+
children: countText(group.rows)
|
|
584
|
+
})
|
|
585
|
+
]
|
|
586
|
+
}), open ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
|
|
587
|
+
className: styles_module_default.cards,
|
|
588
|
+
children: group.rows.map((row) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CapabilityCard, {
|
|
589
|
+
...params.section,
|
|
590
|
+
row,
|
|
591
|
+
...params.testIdPrefix === void 0 ? {} : { testId: `${params.testIdPrefix}${row.name}` }
|
|
592
|
+
}, row.name))
|
|
593
|
+
}) : null]
|
|
594
|
+
}, group.key);
|
|
595
|
+
})
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* 开关。**用 `<button role="switch" aria-checked>` 而不是 `<input type="checkbox">`**:
|
|
600
|
+
* 测试按 `getByRole('switch', { name })` 取它,并且断言 `aria-checked` **实体属性**的值
|
|
601
|
+
* (`toHaveProperty('aria-checked', 'true')`)。checkbox 的 `aria-checked` 是浏览器隐式映射,
|
|
602
|
+
* 在 jsdom 下读不到实体属性,会让「断言回滚」这条用例变成假绿。
|
|
603
|
+
*
|
|
604
|
+
* 结构为**两层**:外层 `button` 透明、只管命中与无障碍;内层 track/thumb 两个 `span` 画视觉。
|
|
605
|
+
* 两个内层 `span` 都是 `aria-hidden` 的纯装饰——可达名由 `button` 的 `aria-label` 提供,
|
|
606
|
+
* 不能让屏幕阅读器把轨道与滑块也念一遍。改结构的原因见 `styles.module.css` 的 `.switch` 注释。
|
|
607
|
+
*/
|
|
608
|
+
function Switch(props) {
|
|
609
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
610
|
+
type: "button",
|
|
611
|
+
role: "switch",
|
|
612
|
+
"aria-checked": props.checked,
|
|
613
|
+
"aria-label": props.label,
|
|
614
|
+
className: props.checked ? `${styles_module_default.switch} ${styles_module_default.switchOn}` : styles_module_default.switch,
|
|
615
|
+
onClick: () => {
|
|
616
|
+
props.onChange(!props.checked);
|
|
617
|
+
},
|
|
618
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
619
|
+
className: styles_module_default.switchTrack,
|
|
620
|
+
"aria-hidden": "true",
|
|
621
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: styles_module_default.switchThumb })
|
|
622
|
+
})
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
/** 可重试的错误条(Review Focus 6:失败必须可见且可重试,绝不白屏)。 */
|
|
626
|
+
function ErrorAlert(props) {
|
|
627
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
628
|
+
className: styles_module_default.alert,
|
|
629
|
+
role: "alert",
|
|
630
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: props.message }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
631
|
+
type: "button",
|
|
632
|
+
className: styles_module_default.button,
|
|
633
|
+
onClick: props.onRetry,
|
|
634
|
+
children: props.retryLabel
|
|
635
|
+
})]
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
//#endregion
|
|
639
|
+
//#region src/client/locales.ts
|
|
640
|
+
/**
|
|
641
|
+
* 面板共用的词条与值类型。
|
|
642
|
+
*
|
|
643
|
+
* 两个面板共用 `NS` 与这里的字典:各写一份会让「同一句话两处不同」成为必然。
|
|
644
|
+
*/
|
|
645
|
+
/** locale 命名空间。与 `apply` 里 `ctx.locale.register(NS, ...)` 一致。 */
|
|
646
|
+
const NS = "skill-scope";
|
|
647
|
+
/** 中文词条(权威文案;英文是它的对照翻译)。 */
|
|
648
|
+
const zh = {
|
|
649
|
+
"panel.label": "全局 Skills",
|
|
650
|
+
"global.title": "全局能力 · 对所有工作区生效",
|
|
651
|
+
"workspace.title": "本工程能力 · 只影响 {project}",
|
|
652
|
+
"view.all": "全部",
|
|
653
|
+
"view.enabled": "已启用",
|
|
654
|
+
"view.disabled": "已禁用",
|
|
655
|
+
"section.skills": "Skill",
|
|
656
|
+
"section.mcps": "MCP",
|
|
657
|
+
"search.placeholder": "搜索",
|
|
658
|
+
"action.retry": "重试",
|
|
659
|
+
"action.close": "关闭",
|
|
660
|
+
"action.open": "工作区 Skills",
|
|
661
|
+
"state.notLive": "非实时",
|
|
662
|
+
"state.notLiveHint": "该会话当前没有实时 Agent,下面显示的是全局清单,不是本作用域的完整集合。",
|
|
663
|
+
"state.loading": "加载中…",
|
|
664
|
+
"state.empty": "没有条目",
|
|
665
|
+
"state.global": "全局",
|
|
666
|
+
"state.scope": "本作用域",
|
|
667
|
+
"state.enabled": "已启用",
|
|
668
|
+
"state.disabled": "已禁用",
|
|
669
|
+
"action.expand": "展开",
|
|
670
|
+
"action.collapse": "收起",
|
|
671
|
+
"detail.state": "状态",
|
|
672
|
+
"detail.source": "来源",
|
|
673
|
+
"detail.tools": "工具",
|
|
674
|
+
"detail.originRuntime": "运行时注入(无磁盘文件)",
|
|
675
|
+
"count.unit": "项",
|
|
676
|
+
"group.ungrouped": "运行时注入",
|
|
677
|
+
"workspace.intro": "下面是未被全局禁用的项, 改动对本 workspace 新 session 生效,不影响已有 session"
|
|
678
|
+
};
|
|
679
|
+
/** 英文词条。键必须与 `zh` 完全一致(少一条就是一段只显示 key 的界面)。 */
|
|
680
|
+
const en = {
|
|
681
|
+
"panel.label": "Global Skills",
|
|
682
|
+
"global.title": "Global capabilities · applies to all workspaces",
|
|
683
|
+
"workspace.title": "Project capabilities · affects {project} only",
|
|
684
|
+
"view.all": "All",
|
|
685
|
+
"view.enabled": "Enabled",
|
|
686
|
+
"view.disabled": "Disabled",
|
|
687
|
+
"section.skills": "Skills",
|
|
688
|
+
"section.mcps": "MCP",
|
|
689
|
+
"search.placeholder": "Search",
|
|
690
|
+
"action.retry": "Retry",
|
|
691
|
+
"action.close": "Close",
|
|
692
|
+
"action.open": "Workspace Skills",
|
|
693
|
+
"state.notLive": "Not live",
|
|
694
|
+
"state.notLiveHint": "This session has no live agent, so the list below is the global inventory, not this scope’s full set.",
|
|
695
|
+
"state.loading": "Loading…",
|
|
696
|
+
"state.empty": "No entries",
|
|
697
|
+
"state.global": "Global",
|
|
698
|
+
"state.scope": "This scope",
|
|
699
|
+
"state.enabled": "Enabled",
|
|
700
|
+
"state.disabled": "Disabled",
|
|
701
|
+
"action.expand": "Expand",
|
|
702
|
+
"action.collapse": "Collapse",
|
|
703
|
+
"detail.state": "State",
|
|
704
|
+
"detail.source": "Source",
|
|
705
|
+
"detail.tools": "Tools",
|
|
706
|
+
"detail.originRuntime": "Runtime-injected (no file on disk)",
|
|
707
|
+
"count.unit": "items",
|
|
708
|
+
"group.ungrouped": "Runtime-injected",
|
|
709
|
+
"workspace.intro": "Listed below are the items not disabled globally. Changes apply to new sessions in this workspace; existing sessions are unaffected."
|
|
710
|
+
};
|
|
711
|
+
//#endregion
|
|
712
|
+
//#region src/client/CapabilityPanel.tsx
|
|
713
|
+
/**
|
|
714
|
+
* 全局面板与工作区弹层的**共享内核**。
|
|
715
|
+
*
|
|
716
|
+
* 两个面板原先各写一份行派生、开关接线与词条包(重构前 `GlobalPanel.tsx` 494 行、
|
|
717
|
+
* `WorkspaceModal.tsx` 585 行)。逐段归一化比对后,可复用的是:
|
|
718
|
+
*
|
|
719
|
+
* 1. 纯函数(本文件上半部)—— 可单测、无 React
|
|
720
|
+
* 2. `usePolicyPanel` —— 加载 / 乐观改 / 回滚,**保存的线上形状与合并策略由外壳注入**
|
|
721
|
+
* 3. `CapabilityPanelBody` —— 视图条 + 搜索框 + 锁提示 + 错误条 + 两段 `CapabilityList`
|
|
722
|
+
*
|
|
723
|
+
* 两个外壳只保留**真正不同**的部分:
|
|
724
|
+
* - 外壳:全局用 `styles.panel`(main 槽位内),工作区用 `overlay` + `modal` + 关闭按钮
|
|
725
|
+
* - 标题与说明文案
|
|
726
|
+
* - 工作区独有:非实时提示、顶部说明段(「下面是未被全局禁用的项…」)
|
|
727
|
+
* - 保存请求体与响应合并
|
|
728
|
+
*
|
|
729
|
+
* 承重不变量(不可为「复用」而抹平):
|
|
730
|
+
* - 视图按钮只是**列表谓词**,不发保存请求。
|
|
731
|
+
* - 工作区保存后**只合并 `revision` 与 `policy`**,绝不整体替换视图(响应里的
|
|
732
|
+
* `exists` 是写文件之前采集的旧值)。见 `docs/design.md`。
|
|
733
|
+
*/
|
|
734
|
+
/** 视图按钮的呈现顺序:全部 → 已启用 → 已禁用。`ViewBar` 按它渲染。 */
|
|
735
|
+
const VIEW_ORDER = [
|
|
736
|
+
"all",
|
|
737
|
+
"enabled",
|
|
738
|
+
"disabled"
|
|
739
|
+
];
|
|
740
|
+
/** 视图按钮的 `data-testid`;两面板共用,测试引用它而不手抄字符串。 */
|
|
741
|
+
const viewTestId = (view) => `view-${view}`;
|
|
742
|
+
/**
|
|
743
|
+
* 无宿主 i18n 时的兜底词条。
|
|
744
|
+
*
|
|
745
|
+
* 两处原先各写一份:全局版直接用 `withParams`,工作区版内联展开了一遍同样的 `{k}`
|
|
746
|
+
* 替换。合并成一份,行为等价(`params === undefined` 时原样返回)。
|
|
747
|
+
*/
|
|
748
|
+
function createDefaultTranslate() {
|
|
749
|
+
const dictionary = zh;
|
|
750
|
+
return (key, params) => {
|
|
751
|
+
const template = dictionary[key] ?? key;
|
|
752
|
+
if (params === void 0) return template;
|
|
753
|
+
return Object.entries(params).reduce((text, [k, v]) => text.replaceAll(`{${k}}`, v), template);
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
/** 把任意抛出物收成一句可展示的文案:`Error` 取 message,其余 `String()`。 */
|
|
757
|
+
function describeError(error) {
|
|
758
|
+
return error instanceof Error ? error.message : String(error);
|
|
759
|
+
}
|
|
760
|
+
/** 名单里列的就是被关掉的(唯一语义)。 */
|
|
761
|
+
function isEnabled(names, name) {
|
|
762
|
+
return !names.includes(name);
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Skill 行派生。两面板原为同一份实现,**分组与出处字段必须原样透传**:
|
|
766
|
+
* - `CapabilityList` 靠「每一行都有 `group`」决定是否启用分组;前端补默认值会把
|
|
767
|
+
* 「服务端没给」伪装成「给了空组」,MCP 段也会跟着被分组。
|
|
768
|
+
* - `origin` 只在有值时挂:`null`/`undefined` 都表示「无磁盘出处」,挂空串会破坏
|
|
769
|
+
* 「runtime skill 出文案 / MCP 行整行不渲染」那个判断。
|
|
770
|
+
*/
|
|
771
|
+
function toSkillRows(skills, policySkills, t) {
|
|
772
|
+
return skills.map((skill) => ({
|
|
773
|
+
name: skill.name,
|
|
774
|
+
description: skill.description,
|
|
775
|
+
source: skill.source,
|
|
776
|
+
enabled: isEnabled(policySkills, skill.name),
|
|
777
|
+
...skill.group === void 0 ? {} : { group: skill.group },
|
|
778
|
+
...skill.groupLabel === void 0 ? {} : { groupLabel: skill.groupLabel },
|
|
779
|
+
...skill.sourceLabel === void 0 || skill.sourceLabel === null ? {} : { origin: skill.sourceLabel }
|
|
780
|
+
}));
|
|
781
|
+
}
|
|
782
|
+
/**
|
|
783
|
+
* MCP 行派生。`excludeNames` 是工作区独有的「被全局关掉则不列出」(全局传空)。
|
|
784
|
+
* 只读判定:未加载或宿主不允许限制都不可切换。
|
|
785
|
+
*
|
|
786
|
+
* `tools` 原样透传服务端的 `toolNames`(**不在这里排序、不去重、不改写前缀**):
|
|
787
|
+
* 展开区要显示的就是用户能在日志与源码里对得上的那串完整名字,服务端已保证次序稳定。
|
|
788
|
+
* 空数组也照传——`CapabilityCard` 用「空即不渲染工具段」来决定,前端不参与这个判断。
|
|
789
|
+
*/
|
|
790
|
+
function toMcpRows(mcps, policyMcps, t, excludeNames = []) {
|
|
791
|
+
return mcps.filter((server) => !excludeNames.includes(server.serverName)).map((server) => {
|
|
792
|
+
const readonly = !server.restrictable || !server.loaded;
|
|
793
|
+
return {
|
|
794
|
+
name: server.serverName,
|
|
795
|
+
description: `${server.toolCount} tools`,
|
|
796
|
+
tools: server.toolNames,
|
|
797
|
+
source: server.source === "global" ? t("state.global") : t("state.scope"),
|
|
798
|
+
enabled: isEnabled(policyMcps, server.serverName),
|
|
799
|
+
...readonly ? { readonly: true } : {}
|
|
800
|
+
};
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* 加载 + 三件改动操作。
|
|
805
|
+
*
|
|
806
|
+
* 回滚依赖**提交时刻捕获的快照**,不是 `value` 的闭包 —— 后者在连续快速点击时会拿到
|
|
807
|
+
* 过期的值,回滚到更早的状态。提交串行化(`chain`),避免并发写入互相覆盖。
|
|
808
|
+
*/
|
|
809
|
+
function usePolicyPanel({ load, save, mergeSaved }) {
|
|
810
|
+
const [value, setValue] = (0, react.useState)(null);
|
|
811
|
+
const [error, setError] = (0, react.useState)(null);
|
|
812
|
+
const [busy, setBusy] = (0, react.useState)(false);
|
|
813
|
+
const [loadFailed, setLoadFailed] = (0, react.useState)(false);
|
|
814
|
+
const [view, setView] = (0, react.useState)("all");
|
|
815
|
+
const [query, setQuery] = (0, react.useState)("");
|
|
816
|
+
const alive = (0, react.useRef)(true);
|
|
817
|
+
const [nonce, setNonce] = (0, react.useState)(0);
|
|
818
|
+
(0, react.useEffect)(() => () => {
|
|
819
|
+
alive.current = false;
|
|
820
|
+
}, []);
|
|
821
|
+
const refresh = (0, react.useCallback)(async () => {
|
|
822
|
+
setNonce((n) => n + 1);
|
|
823
|
+
}, []);
|
|
824
|
+
(0, react.useEffect)(() => {
|
|
825
|
+
let current = true;
|
|
826
|
+
setError(null);
|
|
827
|
+
setLoadFailed(false);
|
|
828
|
+
load().then((loaded) => {
|
|
829
|
+
if (current && alive.current) {
|
|
830
|
+
setValue(loaded);
|
|
831
|
+
setLoadFailed(false);
|
|
832
|
+
}
|
|
833
|
+
}, (cause) => {
|
|
834
|
+
if (current && alive.current) {
|
|
835
|
+
setError(describeError(cause));
|
|
836
|
+
setLoadFailed(true);
|
|
837
|
+
}
|
|
838
|
+
});
|
|
839
|
+
return () => {
|
|
840
|
+
current = false;
|
|
841
|
+
};
|
|
842
|
+
}, [nonce, load]);
|
|
843
|
+
const chain = (0, react.useRef)(Promise.resolve());
|
|
844
|
+
const valueRef = (0, react.useRef)(null);
|
|
845
|
+
valueRef.current = value;
|
|
846
|
+
const commit = (0, react.useCallback)(async (mutate) => {
|
|
847
|
+
const current = valueRef.current;
|
|
848
|
+
if (current === null) return;
|
|
849
|
+
const nextPolicy = mutate(current);
|
|
850
|
+
if (nextPolicy === null) return;
|
|
851
|
+
setValue({
|
|
852
|
+
...current,
|
|
853
|
+
policy: nextPolicy
|
|
854
|
+
});
|
|
855
|
+
setBusy(true);
|
|
856
|
+
const snapshot = current;
|
|
857
|
+
const optimistic = {
|
|
858
|
+
...snapshot,
|
|
859
|
+
policy: nextPolicy
|
|
860
|
+
};
|
|
861
|
+
chain.current = chain.current.then(() => save(optimistic, nextPolicy)).then((saved) => {
|
|
862
|
+
if (!alive.current) return;
|
|
863
|
+
setValue((prev) => prev === null ? prev : mergeSaved === void 0 ? saved : mergeSaved(prev, saved));
|
|
864
|
+
setError(null);
|
|
865
|
+
}, (cause) => {
|
|
866
|
+
if (!alive.current) return;
|
|
867
|
+
setValue(snapshot);
|
|
868
|
+
setError(describeError(cause));
|
|
869
|
+
}).finally(() => {
|
|
870
|
+
if (alive.current) setBusy(false);
|
|
871
|
+
});
|
|
872
|
+
return chain.current;
|
|
873
|
+
}, [save, mergeSaved]);
|
|
874
|
+
return {
|
|
875
|
+
value,
|
|
876
|
+
error,
|
|
877
|
+
busy,
|
|
878
|
+
loadFailed,
|
|
879
|
+
refresh,
|
|
880
|
+
view,
|
|
881
|
+
setView,
|
|
882
|
+
query,
|
|
883
|
+
setQuery,
|
|
884
|
+
commit,
|
|
885
|
+
toggle: (0, react.useCallback)((name, next, which) => {
|
|
886
|
+
commit((current) => {
|
|
887
|
+
if (isEnabled(current.policy[which], name) === next) return null;
|
|
888
|
+
current.policy[which].includes(name);
|
|
889
|
+
const updated = next ? current.policy[which].filter((item) => item !== name) : [...current.policy[which], name];
|
|
890
|
+
return {
|
|
891
|
+
...current.policy,
|
|
892
|
+
[which]: updated
|
|
893
|
+
};
|
|
894
|
+
});
|
|
895
|
+
}, [commit])
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
/** 三个视图按钮。切换**只改组件状态**,不触发保存。 */
|
|
899
|
+
function ViewBar({ view, onChange, t }) {
|
|
900
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
901
|
+
className: styles_module_default.modeRow,
|
|
902
|
+
"data-testid": "view-row",
|
|
903
|
+
children: VIEW_ORDER.map((candidate) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
904
|
+
type: "button",
|
|
905
|
+
className: `${styles_module_default.modeButton} ${view === candidate ? styles_module_default.modeButtonActive : ""}`,
|
|
906
|
+
"aria-pressed": view === candidate,
|
|
907
|
+
"data-testid": viewTestId(candidate),
|
|
908
|
+
onClick: () => {
|
|
909
|
+
onChange(candidate);
|
|
910
|
+
},
|
|
911
|
+
children: t(`view.${candidate}`)
|
|
912
|
+
}, candidate))
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
/** 两段列表共用的词条包。抽一次,避免改文案时两处漂移。 */
|
|
916
|
+
function listLabels(t) {
|
|
917
|
+
return {
|
|
918
|
+
searchPlaceholder: t("search.placeholder"),
|
|
919
|
+
emptyText: t("state.empty"),
|
|
920
|
+
enabledLabel: t("state.enabled"),
|
|
921
|
+
disabledLabel: t("state.disabled"),
|
|
922
|
+
detailStateKey: t("detail.state"),
|
|
923
|
+
detailSourceKey: t("detail.source"),
|
|
924
|
+
detailToolsKey: t("detail.tools"),
|
|
925
|
+
expandLabel: t("action.expand"),
|
|
926
|
+
collapseLabel: t("action.collapse"),
|
|
927
|
+
ungroupedLabel: t("group.ungrouped"),
|
|
928
|
+
ungroupedOriginLabel: t("detail.originRuntime")
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* 视图条 + 错误条 + 两段列表。
|
|
933
|
+
*
|
|
934
|
+
* 搜索框由外壳渲染(各自的位置与图标不同)、查询值经 `query` 传入
|
|
935
|
+
* (`CapabilityList` 的 `externalQuery`),因此一个输入框**同筛两段**。
|
|
936
|
+
*/
|
|
937
|
+
function CapabilityPanelBody(props) {
|
|
938
|
+
const { t } = props;
|
|
939
|
+
const labels = listLabels(t);
|
|
940
|
+
const visible = (rows) => props.view === "all" ? rows : rows.filter((row) => row.enabled === (props.view === "enabled"));
|
|
941
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
942
|
+
props.error === null ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorAlert, {
|
|
943
|
+
message: props.error,
|
|
944
|
+
retryLabel: t("action.retry"),
|
|
945
|
+
onRetry: props.onRetry
|
|
946
|
+
}),
|
|
947
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CapabilityList, {
|
|
948
|
+
title: t("section.skills"),
|
|
949
|
+
sectionTitleId: "skill-scope-skills-title",
|
|
950
|
+
rows: visible(props.skills),
|
|
951
|
+
...labels,
|
|
952
|
+
externalQuery: props.query,
|
|
953
|
+
testIdPrefix: props.skillTestIdPrefix,
|
|
954
|
+
countLabel: t("count.unit"),
|
|
955
|
+
onToggle: props.onToggleSkill
|
|
956
|
+
}),
|
|
957
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CapabilityList, {
|
|
958
|
+
title: t("section.mcps"),
|
|
959
|
+
sectionTitleId: "skill-scope-mcps-title",
|
|
960
|
+
rows: visible(props.mcps),
|
|
961
|
+
...labels,
|
|
962
|
+
externalQuery: props.query,
|
|
963
|
+
testIdPrefix: props.mcpTestIdPrefix,
|
|
964
|
+
countLabel: t("count.unit"),
|
|
965
|
+
onToggle: props.onToggleMcp
|
|
966
|
+
})
|
|
967
|
+
] });
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* 顶部统一搜索框:**一份**输入同时过滤技能与 MCP 两段。
|
|
971
|
+
*
|
|
972
|
+
* 两个面板共用它,是为了让「同一个词在两段里同时生效」这条行为只有一处实现。
|
|
973
|
+
* 分工区各留一个输入框会让同一个词要输两遍,且两个框的过滤状态无法一致。
|
|
974
|
+
*/
|
|
975
|
+
function SearchRow({ id, value, onChange, t }) {
|
|
976
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
977
|
+
className: styles_module_default.searchRow,
|
|
978
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
979
|
+
className: styles_module_default.searchIcon,
|
|
980
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SearchIcon, {})
|
|
981
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
982
|
+
id,
|
|
983
|
+
className: styles_module_default.search,
|
|
984
|
+
type: "search",
|
|
985
|
+
value,
|
|
986
|
+
placeholder: t("search.placeholder"),
|
|
987
|
+
"aria-label": t("search.placeholder"),
|
|
988
|
+
onChange: (event) => {
|
|
989
|
+
onChange(readInputValue(event.target));
|
|
990
|
+
}
|
|
991
|
+
})]
|
|
992
|
+
});
|
|
993
|
+
}
|
|
994
|
+
/**
|
|
995
|
+
* 从受控输入框读值(受 `noUncheckedIndexedAccess` 约束,需显式判空)。
|
|
996
|
+
*
|
|
997
|
+
* 不直接用 `event.target.value`:`EventTarget` 上没有 `value`,需要先收窄类型。
|
|
998
|
+
*/
|
|
999
|
+
function readInputValue(target) {
|
|
1000
|
+
const value = asRecord(target)?.["value"];
|
|
1001
|
+
return typeof value === "string" ? value : "";
|
|
1002
|
+
}
|
|
1003
|
+
function WiredCapabilityBody(props) {
|
|
1004
|
+
const { t, panel } = props;
|
|
1005
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [props.searchInputId === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SearchRow, {
|
|
1006
|
+
id: props.searchInputId,
|
|
1007
|
+
value: panel.query,
|
|
1008
|
+
onChange: panel.setQuery,
|
|
1009
|
+
t
|
|
1010
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CapabilityPanelBody, {
|
|
1011
|
+
t,
|
|
1012
|
+
error: panel.error,
|
|
1013
|
+
onRetry: props.onRetry,
|
|
1014
|
+
query: panel.query,
|
|
1015
|
+
view: panel.view,
|
|
1016
|
+
skills: props.skills,
|
|
1017
|
+
mcps: props.mcps,
|
|
1018
|
+
onToggleSkill: (name, next) => {
|
|
1019
|
+
panel.toggle(name, next, "skills");
|
|
1020
|
+
},
|
|
1021
|
+
onToggleMcp: (name, next) => {
|
|
1022
|
+
panel.toggle(name, next, "mcps");
|
|
1023
|
+
},
|
|
1024
|
+
mcpTestIdPrefix: props.mcpTestIdPrefix,
|
|
1025
|
+
skillTestIdPrefix: props.skillTestIdPrefix
|
|
1026
|
+
})] });
|
|
1027
|
+
}
|
|
1028
|
+
//#endregion
|
|
1029
|
+
//#region src/client/GlobalPanel.tsx
|
|
1030
|
+
/**
|
|
1031
|
+
* 读路由返回体并做最小形状校验;形状不对时当作传输失败(宁可报错也不要渲染半张界面)。
|
|
1032
|
+
*
|
|
1033
|
+
* 异常文案统一交给共享内核的 `describeError`(`ApiError` 的 message 已是可读文案),
|
|
1034
|
+
* 这里不再自带一份同名不同实现的包装。
|
|
1035
|
+
*/
|
|
1036
|
+
async function loadGlobal(sessionId) {
|
|
1037
|
+
const value = await post(ROUTES.global, sessionId === void 0 ? {} : { sessionId });
|
|
1038
|
+
if (value === null || typeof value !== "object" || value.inventory === null || typeof value.inventory !== "object") throw new ApiError("network", "全局视图形状非法");
|
|
1039
|
+
return value;
|
|
1040
|
+
}
|
|
1041
|
+
function GlobalPanel(props) {
|
|
1042
|
+
const [fallbackTranslate] = (0, react.useState)(createDefaultTranslate);
|
|
1043
|
+
const t = props.t ?? fallbackTranslate;
|
|
1044
|
+
const sessionId = props.sessionId;
|
|
1045
|
+
/**
|
|
1046
|
+
* 保存:全局路由的响应就是**完整的** `GlobalValue`,因此整体替换(不注入 `mergeSaved`)。
|
|
1047
|
+
*
|
|
1048
|
+
* `revision` 三态:`null` 表示「我期望文件还不存在」。原样透传,不做 `??` 折叠——
|
|
1049
|
+
* 把 `null` 折成 `undefined` 会改变服务端的守卫语义。
|
|
1050
|
+
*/
|
|
1051
|
+
const save = (0, react.useCallback)(async (current, nextPolicy) => post(ROUTES.globalSave, {
|
|
1052
|
+
mode: nextPolicy.mode,
|
|
1053
|
+
skills: nextPolicy.skills,
|
|
1054
|
+
mcps: nextPolicy.mcps,
|
|
1055
|
+
revision: current.revision,
|
|
1056
|
+
...sessionId === void 0 ? {} : { sessionId }
|
|
1057
|
+
}), [sessionId]);
|
|
1058
|
+
const panel = usePolicyPanel({
|
|
1059
|
+
load: (0, react.useCallback)(async () => loadGlobal(sessionId), [sessionId]),
|
|
1060
|
+
save
|
|
1061
|
+
});
|
|
1062
|
+
const refresh = () => {
|
|
1063
|
+
panel.refresh();
|
|
1064
|
+
};
|
|
1065
|
+
const value = panel.value;
|
|
1066
|
+
if (value === null) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1067
|
+
className: styles_module_default.panel,
|
|
1068
|
+
"data-testid": "global-panel",
|
|
1069
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
|
|
1070
|
+
className: styles_module_default.title,
|
|
1071
|
+
children: t("global.title")
|
|
1072
|
+
}), panel.error === null ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1073
|
+
className: styles_module_default.empty,
|
|
1074
|
+
children: t("state.loading")
|
|
1075
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1076
|
+
className: styles_module_default.empty,
|
|
1077
|
+
role: "alert",
|
|
1078
|
+
children: panel.error
|
|
1079
|
+
})]
|
|
1080
|
+
});
|
|
1081
|
+
const skillRows = toSkillRows(value.inventory.skills, value.policy.skills, t);
|
|
1082
|
+
const mcpRows = toMcpRows(value.inventory.mcps, value.policy.mcps, t);
|
|
1083
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1084
|
+
className: styles_module_default.panel,
|
|
1085
|
+
"data-testid": "global-panel",
|
|
1086
|
+
children: [
|
|
1087
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1088
|
+
className: styles_module_default.header,
|
|
1089
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
|
|
1090
|
+
className: styles_module_default.title,
|
|
1091
|
+
children: t("global.title")
|
|
1092
|
+
})
|
|
1093
|
+
}),
|
|
1094
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewBar, {
|
|
1095
|
+
view: panel.view,
|
|
1096
|
+
onChange: panel.setView,
|
|
1097
|
+
t
|
|
1098
|
+
}),
|
|
1099
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(WiredCapabilityBody, {
|
|
1100
|
+
t,
|
|
1101
|
+
panel,
|
|
1102
|
+
skills: skillRows,
|
|
1103
|
+
mcps: mcpRows,
|
|
1104
|
+
onRetry: refresh,
|
|
1105
|
+
mcpTestIdPrefix: "mcp-",
|
|
1106
|
+
skillTestIdPrefix: "skill-",
|
|
1107
|
+
searchInputId: "skill-scope-global-search"
|
|
1108
|
+
})
|
|
1109
|
+
]
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
//#endregion
|
|
1113
|
+
//#region src/client/WorkspaceModal.tsx
|
|
1114
|
+
/** 取工程名:`cwd` 的 basename。用 `/` 与 `\` 都切,避免宿主报一个 Windows 路径时整条标题变成完整路径。 */
|
|
1115
|
+
function projectNameOf(cwd) {
|
|
1116
|
+
const parts = cwd.split(/[/\\]/).filter((part) => part !== "");
|
|
1117
|
+
return parts[parts.length - 1] ?? cwd;
|
|
1118
|
+
}
|
|
1119
|
+
/** 读工作区路由。**只传 sessionId**(不变量 5:scope 由服务端给)。 */
|
|
1120
|
+
async function loadWorkspace(sessionId) {
|
|
1121
|
+
const value = await post(ROUTES.workspace, { sessionId });
|
|
1122
|
+
if (value === null || typeof value !== "object" || value.inventory === null || typeof value.inventory !== "object") throw new ApiError("network", "工作区视图形状非法");
|
|
1123
|
+
return value;
|
|
1124
|
+
}
|
|
1125
|
+
function WorkspaceModal(props) {
|
|
1126
|
+
const [fallbackTranslate] = (0, react.useState)(createDefaultTranslate);
|
|
1127
|
+
const t = props.t ?? fallbackTranslate;
|
|
1128
|
+
const sessionId = props.sessionId;
|
|
1129
|
+
/**
|
|
1130
|
+
* 保存:工作区路由**只返回可合并的字段**,因此注入 `mergeSaved` 只取 `revision`
|
|
1131
|
+
* 与 `policy`,绝不整体替换视图。
|
|
1132
|
+
*
|
|
1133
|
+
* 设计 6.2 规定保存路由只返回 `{ revision }`。而读取路由返回的是**视图快照**:
|
|
1134
|
+
* `exists` / `cwd` / `policyPath` / `inventory` / `live` —— 这些是「读取那一刻」的事实。
|
|
1135
|
+
* 保存响应**不能**用来覆盖它们:
|
|
1136
|
+
* - 本仓库 host 侧(`src/routes/handlers.ts`)出于方便会把整个 `WorkspaceValue` 回吐,
|
|
1137
|
+
* 其中的 `exists` 是**写文件之前**采集的旧值,拿它覆盖会把状态行改错。
|
|
1138
|
+
* - 真实场景里 `exists` 是对的(保存后文件确实存在了),但**界面此刻仍应显示用户做出
|
|
1139
|
+
* 这次保存所依据的状态**,否则「未创建,保存后创建」会在保存后瞬间变成「已有策略」,
|
|
1140
|
+
* 用户就看不出这次保存到底创建了什么。
|
|
1141
|
+
*
|
|
1142
|
+
* 因此只合并 `revision`(下一次保存的乐观锁依据)与 `policy`(服务端规范化后的名单,
|
|
1143
|
+
* 比如排序、去重、上限截断)。其余视图字段保留读取时的那一份。
|
|
1144
|
+
*/
|
|
1145
|
+
const save = (0, react.useCallback)(async (current, nextPolicy) => post(ROUTES.workspaceSave, {
|
|
1146
|
+
sessionId,
|
|
1147
|
+
mode: nextPolicy.mode,
|
|
1148
|
+
skills: nextPolicy.skills,
|
|
1149
|
+
mcps: nextPolicy.mcps,
|
|
1150
|
+
revision: current.revision
|
|
1151
|
+
}), [sessionId]);
|
|
1152
|
+
const mergeSaved = (0, react.useCallback)((previous, saved) => ({
|
|
1153
|
+
...previous,
|
|
1154
|
+
revision: saved.revision,
|
|
1155
|
+
...saved.policy === void 0 ? {} : { policy: saved.policy }
|
|
1156
|
+
}), []);
|
|
1157
|
+
const panel = usePolicyPanel({
|
|
1158
|
+
load: (0, react.useCallback)(async () => loadWorkspace(sessionId), [sessionId]),
|
|
1159
|
+
save,
|
|
1160
|
+
mergeSaved
|
|
1161
|
+
});
|
|
1162
|
+
const refresh = () => {
|
|
1163
|
+
panel.refresh();
|
|
1164
|
+
};
|
|
1165
|
+
const value = panel.value;
|
|
1166
|
+
if (value === null) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1167
|
+
className: styles_module_default.overlay,
|
|
1168
|
+
role: "dialog",
|
|
1169
|
+
"aria-modal": "true",
|
|
1170
|
+
"data-testid": "workspace-modal",
|
|
1171
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1172
|
+
className: styles_module_default.modal,
|
|
1173
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1174
|
+
className: styles_module_default.panelHead,
|
|
1175
|
+
children: panel.loadFailed ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1176
|
+
className: styles_module_default.empty,
|
|
1177
|
+
role: "alert",
|
|
1178
|
+
children: panel.error
|
|
1179
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1180
|
+
className: styles_module_default.empty,
|
|
1181
|
+
children: t("state.loading")
|
|
1182
|
+
})
|
|
1183
|
+
})
|
|
1184
|
+
})
|
|
1185
|
+
});
|
|
1186
|
+
const disabledGlobally = value.disabledGlobally ?? [];
|
|
1187
|
+
const skillRows = toSkillRows(value.inventory.skills, value.policy.skills, t);
|
|
1188
|
+
const mcpRows = toMcpRows(value.inventory.mcps, value.policy.mcps, t, disabledGlobally);
|
|
1189
|
+
const project = projectNameOf(value.cwd);
|
|
1190
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1191
|
+
className: styles_module_default.overlay,
|
|
1192
|
+
role: "dialog",
|
|
1193
|
+
"aria-modal": "true",
|
|
1194
|
+
"data-testid": "workspace-modal",
|
|
1195
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1196
|
+
className: styles_module_default.modal,
|
|
1197
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1198
|
+
className: styles_module_default.panelHead,
|
|
1199
|
+
children: [
|
|
1200
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1201
|
+
className: styles_module_default.header,
|
|
1202
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
|
|
1203
|
+
className: styles_module_default.title,
|
|
1204
|
+
children: t("workspace.title").replace("{project}", project)
|
|
1205
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1206
|
+
type: "button",
|
|
1207
|
+
className: styles_module_default.closeButton,
|
|
1208
|
+
"aria-label": t("action.close"),
|
|
1209
|
+
"data-testid": "workspace-close",
|
|
1210
|
+
onClick: () => {
|
|
1211
|
+
props.onClose();
|
|
1212
|
+
},
|
|
1213
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CloseIcon, {})
|
|
1214
|
+
})]
|
|
1215
|
+
}),
|
|
1216
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1217
|
+
className: styles_module_default.intro,
|
|
1218
|
+
children: value.live ? t("workspace.intro") : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
1219
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", {
|
|
1220
|
+
className: styles_module_default.introWarn,
|
|
1221
|
+
"data-testid": "workspace-not-live",
|
|
1222
|
+
children: t("state.notLive")
|
|
1223
|
+
}),
|
|
1224
|
+
" ",
|
|
1225
|
+
t("state.notLiveHint"),
|
|
1226
|
+
" ",
|
|
1227
|
+
t("workspace.intro")
|
|
1228
|
+
] })
|
|
1229
|
+
}),
|
|
1230
|
+
value.live ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1231
|
+
hidden: true,
|
|
1232
|
+
"data-testid": "workspace-live"
|
|
1233
|
+
}) : null,
|
|
1234
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewBar, {
|
|
1235
|
+
view: panel.view,
|
|
1236
|
+
onChange: panel.setView,
|
|
1237
|
+
t
|
|
1238
|
+
})
|
|
1239
|
+
]
|
|
1240
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1241
|
+
className: styles_module_default.panelBody,
|
|
1242
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1243
|
+
className: styles_module_default.body,
|
|
1244
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WiredCapabilityBody, {
|
|
1245
|
+
t,
|
|
1246
|
+
panel,
|
|
1247
|
+
skills: skillRows,
|
|
1248
|
+
mcps: mcpRows,
|
|
1249
|
+
onRetry: refresh,
|
|
1250
|
+
mcpTestIdPrefix: "mcp-",
|
|
1251
|
+
skillTestIdPrefix: "ws-skill-",
|
|
1252
|
+
searchInputId: "skill-scope-ws-search"
|
|
1253
|
+
})
|
|
1254
|
+
})
|
|
1255
|
+
})]
|
|
1256
|
+
})
|
|
1257
|
+
});
|
|
1258
|
+
}
|
|
1259
|
+
function WorkspaceChip(props) {
|
|
1260
|
+
const [fallbackTranslate] = (0, react.useState)(createDefaultTranslate);
|
|
1261
|
+
const t = props.t ?? fallbackTranslate;
|
|
1262
|
+
const blank = props.useSession === void 0 ? false : props.useSession((state) => state.blank);
|
|
1263
|
+
if (!props.hasSession || !blank) return null;
|
|
1264
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
1265
|
+
type: "button",
|
|
1266
|
+
className: styles_module_default.chip,
|
|
1267
|
+
"data-testid": "workspace-chip",
|
|
1268
|
+
onClick: props.onOpen,
|
|
1269
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CloverIcon, { size: 15 }), t("action.open")]
|
|
1270
|
+
});
|
|
1271
|
+
}
|
|
1272
|
+
//#endregion
|
|
1273
|
+
//#region src/client/index.tsx
|
|
1274
|
+
/** 插件要求宿主提供的服务名。与 `package.json` 的 `dsh.client.inject` **不同**:
|
|
1275
|
+
* 那是包名图(依赖哪些客户端包),这里是 cordis 服务名(`slots`/`layout`/`locale`)。 */
|
|
1276
|
+
const inject = [
|
|
1277
|
+
"slots",
|
|
1278
|
+
"layout",
|
|
1279
|
+
"locale"
|
|
1280
|
+
];
|
|
1281
|
+
/** 槽位 id 常量。**侧栏与 main 共用同一个 id**,避免「侧栏按钮指向不存在的面板」。 */
|
|
1282
|
+
const PANEL_ID = "skill-scope";
|
|
1283
|
+
const WORKSPACE_CHIP_ID = "skill-scope-workspace";
|
|
1284
|
+
const WORKSPACE_MODAL_ID = "skill-scope-workspace-modal";
|
|
1285
|
+
/** 从 locale 服务取一个 `{name}` 占位符替换器;缺参数时保留原样(不塞 `undefined`)。 */
|
|
1286
|
+
function withParams(template, params) {
|
|
1287
|
+
if (params === void 0) return template;
|
|
1288
|
+
return Object.entries(params).reduce((text, [key, value]) => text.replaceAll(`{${key}}`, value), template);
|
|
1289
|
+
}
|
|
1290
|
+
/**
|
|
1291
|
+
* 装配客户端插件:注册词条与三个槽位,返回 `undefined`。
|
|
1292
|
+
*
|
|
1293
|
+
* `effect` 顺序**有依赖**:locale 必须先注册,否则下面 `bind` 出来的取值器在
|
|
1294
|
+
* 首帧拿不到词条(会闪一段 key 文本)。这不是致命错误,但顺序是免费的。
|
|
1295
|
+
*/
|
|
1296
|
+
function apply(ctx) {
|
|
1297
|
+
ctx.effect(() => ctx.locale.register(NS, {
|
|
1298
|
+
zh,
|
|
1299
|
+
en
|
|
1300
|
+
}), `${NS}: dictionaries`);
|
|
1301
|
+
const bind = ctx.locale.bind(NS);
|
|
1302
|
+
const t = (key, params) => withParams(bind(key), params);
|
|
1303
|
+
ctx.slots.inject("sidebar.panellist", () => ctx.slots.register({
|
|
1304
|
+
name: "sidebar.panellist",
|
|
1305
|
+
id: PANEL_ID,
|
|
1306
|
+
order: 30,
|
|
1307
|
+
label: () => t("panel.label")
|
|
1308
|
+
}, ((props) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CloverIcon, { size: props.size }))));
|
|
1309
|
+
ctx.slots.inject("main", () => ctx.slots.register({
|
|
1310
|
+
name: "main",
|
|
1311
|
+
key: PANEL_ID
|
|
1312
|
+
}, (() => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GlobalPanel, { t }))));
|
|
1313
|
+
let open = false;
|
|
1314
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
1315
|
+
const notify = () => {
|
|
1316
|
+
for (const listener of listeners) listener();
|
|
1317
|
+
};
|
|
1318
|
+
const subscribe = (listener) => {
|
|
1319
|
+
listeners.add(listener);
|
|
1320
|
+
return () => {
|
|
1321
|
+
listeners.delete(listener);
|
|
1322
|
+
};
|
|
1323
|
+
};
|
|
1324
|
+
const readOpen = () => open;
|
|
1325
|
+
/** 会话 id 在渲染期由槽位标准 props 给出,注册期还没有;用可变引用承接。 */
|
|
1326
|
+
let sessionId;
|
|
1327
|
+
ctx.slots.inject("conversation.input.right", () => ctx.slots.register({
|
|
1328
|
+
name: "conversation.input.right",
|
|
1329
|
+
id: WORKSPACE_CHIP_ID,
|
|
1330
|
+
order: 30
|
|
1331
|
+
}, ((props) => {
|
|
1332
|
+
sessionId = props.sessionId;
|
|
1333
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WorkspaceChip, {
|
|
1334
|
+
hasSession: typeof props.sessionId === "string" && props.sessionId !== "",
|
|
1335
|
+
t,
|
|
1336
|
+
...props.useSession === void 0 ? {} : { useSession: props.useSession },
|
|
1337
|
+
onOpen: () => {
|
|
1338
|
+
open = true;
|
|
1339
|
+
notify();
|
|
1340
|
+
}
|
|
1341
|
+
});
|
|
1342
|
+
})));
|
|
1343
|
+
ctx.slots.inject("shell.overlay", () => ctx.slots.register({
|
|
1344
|
+
name: "shell.overlay",
|
|
1345
|
+
id: WORKSPACE_MODAL_ID,
|
|
1346
|
+
order: 50
|
|
1347
|
+
}, (() => {
|
|
1348
|
+
if (!(0, react.useSyncExternalStore)(subscribe, readOpen, readOpen)) return null;
|
|
1349
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WorkspaceModal, {
|
|
1350
|
+
sessionId: sessionId ?? "",
|
|
1351
|
+
t,
|
|
1352
|
+
onClose: () => {
|
|
1353
|
+
open = false;
|
|
1354
|
+
notify();
|
|
1355
|
+
}
|
|
1356
|
+
});
|
|
1357
|
+
})));
|
|
1358
|
+
}
|
|
1359
|
+
//#endregion
|
|
1360
|
+
exports.PANEL_ID = PANEL_ID;
|
|
1361
|
+
exports.WORKSPACE_CHIP_ID = WORKSPACE_CHIP_ID;
|
|
1362
|
+
exports.WORKSPACE_MODAL_ID = WORKSPACE_MODAL_ID;
|
|
1363
|
+
exports.apply = apply;
|
|
1364
|
+
exports.inject = inject;
|
|
1365
|
+
return module.exports;
|
|
1366
|
+
}
|
|
1367
|
+
});
|
|
1368
|
+
|
|
1369
|
+
//# sourceMappingURL=client.js.map
|