@dotdance/dsh-skill-scope 0.3.1 → 0.4.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/README.en.md +2 -5
- package/README.md +2 -5
- package/lib/client.js +168 -94
- package/lib/client.js.map +1 -1
- package/lib/index.js +280 -207
- package/package.json +10 -10
package/README.en.md
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
[](https://www.npmjs.com/package/@dotdance/dsh-skill-scope)
|
|
7
7
|
[](https://www.npmjs.com/package/@dotdance/dsh-skill-scope)
|
|
8
8
|
[](https://github.com/dotdance/dsh-skill-scope)
|
|
9
|
-
[](#installation)
|
|
10
10
|

|
|
11
11
|
|
|
12
|
-
**
|
|
12
|
+
**Lighten the load on your agent: one-click toggles for skills and MCP, so the context holds only what this turn actually needs. Skills and MCP servers you switch off are no longer injected into the model context — cleaner, and lighter on tokens.**
|
|
13
13
|
|
|
14
14
|
**English** · [简体中文](README.md)
|
|
15
15
|
</div>
|
|
@@ -24,9 +24,6 @@ dsh plugin --profile web add @dotdance/dsh-skill-scope
|
|
|
24
24
|
|
|
25
25
|
Replace `--profile web` with the name of your own profile.
|
|
26
26
|
|
|
27
|
-
Requires DSH `≥0.2.0-rc.2` and `<0.3.0` (older hosts do not read `engines.dsh` and judge the plugin incompatible).
|
|
28
|
-
|
|
29
|
-
|
|
30
27
|
## The problem it solves
|
|
31
28
|
|
|
32
29
|
The more you install in DSH, the longer the list your agent has to read every turn.
|
package/README.md
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
[](https://www.npmjs.com/package/@dotdance/dsh-skill-scope)
|
|
7
7
|
[](https://www.npmjs.com/package/@dotdance/dsh-skill-scope)
|
|
8
8
|
[](https://github.com/dotdance/dsh-skill-scope)
|
|
9
|
-
[](#安装)
|
|
10
10
|

|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
**给你的 Agent 减负:Skill 与 MCP 一键启停,让上下文只装这一轮真正要用的能力。关掉的 skill / MCP 不再进入模型上下文,更干净,更省 token。**
|
|
13
13
|
|
|
14
14
|
[English](README.en.md) · **简体中文**
|
|
15
15
|
</div>
|
|
@@ -24,9 +24,6 @@ dsh plugin --profile web add @dotdance/dsh-skill-scope
|
|
|
24
24
|
|
|
25
25
|
`--profile web` 换成你自己的 profile 名即可。
|
|
26
26
|
|
|
27
|
-
要求 DSH `≥0.2.0-rc.2` 且 `<0.3.0`(更早的宿主不认 `engines.dsh`,会被判为不兼容)。
|
|
28
|
-
|
|
29
|
-
|
|
30
27
|
## 它解决什么问题
|
|
31
28
|
|
|
32
29
|
你在 DSH 里装得越多,Agent 每一轮要读的清单就越长。
|
package/lib/client.js
CHANGED
|
@@ -137,8 +137,8 @@ window.__ModuleLoader__.load({
|
|
|
137
137
|
return `网络请求失败:${String(error)}`;
|
|
138
138
|
}
|
|
139
139
|
//#endregion
|
|
140
|
-
//#region \0dsh-css-module:/
|
|
141
|
-
const css = ".
|
|
140
|
+
//#region \0dsh-css-module:/Users/go/proj/dsh-skill-scope/src/client/styles.module.css?dsh-css-module
|
|
141
|
+
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_overridden{align-items:center;display:inline-flex}.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_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_modeRowTrailing{align-items:center;margin-left:auto;display:flex}.p4Fk8G_toggleRow{color:var(--dsw-alias-label-secondary,currentColor);align-items:center;gap:8px;font-size:12px;display:flex}.p4Fk8G_toggleLabel{cursor:default;user-select:none}.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_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)}";
|
|
142
142
|
const tagId = "@dotdance/dsh-skill-scope/styles.module.css";
|
|
143
143
|
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
|
|
144
144
|
const tag = document.createElement("style");
|
|
@@ -148,66 +148,66 @@ window.__ModuleLoader__.load({
|
|
|
148
148
|
document.head.appendChild(tag);
|
|
149
149
|
}
|
|
150
150
|
var styles_module_default = {
|
|
151
|
-
"
|
|
152
|
-
"
|
|
153
|
-
"
|
|
154
|
-
"
|
|
155
|
-
"
|
|
156
|
-
"
|
|
157
|
-
"
|
|
158
|
-
"
|
|
159
|
-
"
|
|
160
|
-
"
|
|
161
|
-
"
|
|
162
|
-
"
|
|
163
|
-
"
|
|
164
|
-
"
|
|
165
|
-
"
|
|
166
|
-
"
|
|
167
|
-
"
|
|
168
|
-
"
|
|
169
|
-
"
|
|
170
|
-
"
|
|
171
|
-
"
|
|
172
|
-
"
|
|
173
|
-
"
|
|
174
|
-
"
|
|
175
|
-
"
|
|
176
|
-
"
|
|
177
|
-
"
|
|
178
|
-
"
|
|
179
|
-
"
|
|
180
|
-
"
|
|
181
|
-
"
|
|
182
|
-
"
|
|
183
|
-
"
|
|
184
|
-
"
|
|
185
|
-
"
|
|
186
|
-
"
|
|
187
|
-
"
|
|
188
|
-
"
|
|
189
|
-
"
|
|
190
|
-
"
|
|
191
|
-
"
|
|
192
|
-
"
|
|
193
|
-
"searchRow": "
|
|
194
|
-
"
|
|
195
|
-
"
|
|
196
|
-
"
|
|
197
|
-
"
|
|
198
|
-
"
|
|
199
|
-
"
|
|
200
|
-
"
|
|
201
|
-
"
|
|
202
|
-
"
|
|
203
|
-
"
|
|
204
|
-
"
|
|
205
|
-
"
|
|
206
|
-
"
|
|
207
|
-
"
|
|
208
|
-
"
|
|
209
|
-
"
|
|
210
|
-
"
|
|
151
|
+
"detailValue": "p4Fk8G_detailValue",
|
|
152
|
+
"cards": "p4Fk8G_cards",
|
|
153
|
+
"detailKey": "p4Fk8G_detailKey",
|
|
154
|
+
"groups": "p4Fk8G_groups",
|
|
155
|
+
"sectionChevronOpen": "p4Fk8G_sectionChevronOpen",
|
|
156
|
+
"alert": "p4Fk8G_alert",
|
|
157
|
+
"cardName": "p4Fk8G_cardName",
|
|
158
|
+
"switchOn": "p4Fk8G_switchOn",
|
|
159
|
+
"sectionHead": "p4Fk8G_sectionHead",
|
|
160
|
+
"sectionCount": "p4Fk8G_sectionCount",
|
|
161
|
+
"empty": "p4Fk8G_empty",
|
|
162
|
+
"search": "p4Fk8G_search",
|
|
163
|
+
"panelBody": "p4Fk8G_panelBody",
|
|
164
|
+
"sectionChevron": "p4Fk8G_sectionChevron",
|
|
165
|
+
"overlay": "p4Fk8G_overlay",
|
|
166
|
+
"cardMain": "p4Fk8G_cardMain",
|
|
167
|
+
"group": "p4Fk8G_group",
|
|
168
|
+
"sectionToggle": "p4Fk8G_sectionToggle",
|
|
169
|
+
"intro": "p4Fk8G_intro",
|
|
170
|
+
"panelHead": "p4Fk8G_panelHead",
|
|
171
|
+
"modeButton": "p4Fk8G_modeButton",
|
|
172
|
+
"modeButtonActive": "p4Fk8G_modeButtonActive",
|
|
173
|
+
"title": "p4Fk8G_title",
|
|
174
|
+
"introWarn": "p4Fk8G_introWarn",
|
|
175
|
+
"cardBody": "p4Fk8G_cardBody",
|
|
176
|
+
"groupChevron": "p4Fk8G_groupChevron",
|
|
177
|
+
"section": "p4Fk8G_section",
|
|
178
|
+
"cardTail": "p4Fk8G_cardTail",
|
|
179
|
+
"panel": "p4Fk8G_panel",
|
|
180
|
+
"closeButton": "p4Fk8G_closeButton",
|
|
181
|
+
"groupToggle": "p4Fk8G_groupToggle",
|
|
182
|
+
"modeRow": "p4Fk8G_modeRow",
|
|
183
|
+
"groupCount": "p4Fk8G_groupCount",
|
|
184
|
+
"card": "p4Fk8G_card",
|
|
185
|
+
"cardDisabled": "p4Fk8G_cardDisabled",
|
|
186
|
+
"detailRow": "p4Fk8G_detailRow",
|
|
187
|
+
"toolList": "p4Fk8G_toolList",
|
|
188
|
+
"modeRowTrailing": "p4Fk8G_modeRowTrailing",
|
|
189
|
+
"body": "p4Fk8G_body",
|
|
190
|
+
"expandChevron": "p4Fk8G_expandChevron",
|
|
191
|
+
"cardHead": "p4Fk8G_cardHead",
|
|
192
|
+
"toggleLabel": "p4Fk8G_toggleLabel",
|
|
193
|
+
"searchRow": "p4Fk8G_searchRow",
|
|
194
|
+
"groupTitle": "p4Fk8G_groupTitle",
|
|
195
|
+
"header": "p4Fk8G_header",
|
|
196
|
+
"button": "p4Fk8G_button",
|
|
197
|
+
"toolName": "p4Fk8G_toolName",
|
|
198
|
+
"chip": "p4Fk8G_chip",
|
|
199
|
+
"detailOrigin": "p4Fk8G_detailOrigin",
|
|
200
|
+
"switch": "p4Fk8G_switch",
|
|
201
|
+
"modal": "p4Fk8G_modal",
|
|
202
|
+
"switchTrack": "p4Fk8G_switchTrack",
|
|
203
|
+
"switchThumb": "p4Fk8G_switchThumb",
|
|
204
|
+
"searchIcon": "p4Fk8G_searchIcon",
|
|
205
|
+
"overridden": "p4Fk8G_overridden",
|
|
206
|
+
"expandButton": "p4Fk8G_expandButton",
|
|
207
|
+
"toggleRow": "p4Fk8G_toggleRow",
|
|
208
|
+
"expandChevronOpen": "p4Fk8G_expandChevronOpen",
|
|
209
|
+
"cardDescription": "p4Fk8G_cardDescription",
|
|
210
|
+
"sectionTitle": "p4Fk8G_sectionTitle"
|
|
211
211
|
};
|
|
212
212
|
//#endregion
|
|
213
213
|
//#region src/client/parts.tsx
|
|
@@ -988,8 +988,8 @@ window.__ModuleLoader__.load({
|
|
|
988
988
|
/**
|
|
989
989
|
* 加载 + 三件改动操作。
|
|
990
990
|
*
|
|
991
|
-
*
|
|
992
|
-
*
|
|
991
|
+
* 保存时从最近一次成功的服务端状态重算操作;成功后重放尚未发送的操作,
|
|
992
|
+
* 失败则取消本批剩余操作并回滚到最近确认的状态。
|
|
993
993
|
*/
|
|
994
994
|
function usePolicyPanel({ load, save, toggle: applyToggle, mergeSaved }) {
|
|
995
995
|
const [value, setValue] = (0, react.useState)(null);
|
|
@@ -998,20 +998,46 @@ window.__ModuleLoader__.load({
|
|
|
998
998
|
const [loadFailed, setLoadFailed] = (0, react.useState)(false);
|
|
999
999
|
const [view, setView] = (0, react.useState)("all");
|
|
1000
1000
|
const [query, setQuery] = (0, react.useState)("");
|
|
1001
|
+
const confirmed = (0, react.useRef)(null);
|
|
1002
|
+
const pending = (0, react.useRef)([]);
|
|
1003
|
+
const running = (0, react.useRef)(false);
|
|
1004
|
+
const refreshPending = (0, react.useRef)(false);
|
|
1005
|
+
const saveFailed = (0, react.useRef)(false);
|
|
1006
|
+
const generation = (0, react.useRef)(0);
|
|
1007
|
+
const valueRef = (0, react.useRef)(null);
|
|
1001
1008
|
const alive = (0, react.useRef)(true);
|
|
1002
1009
|
const [nonce, setNonce] = (0, react.useState)(0);
|
|
1003
|
-
(0, react.useEffect)(() =>
|
|
1004
|
-
alive.current =
|
|
1010
|
+
(0, react.useEffect)(() => {
|
|
1011
|
+
alive.current = true;
|
|
1012
|
+
return () => {
|
|
1013
|
+
alive.current = false;
|
|
1014
|
+
};
|
|
1005
1015
|
}, []);
|
|
1006
1016
|
const refresh = (0, react.useCallback)(async () => {
|
|
1017
|
+
if (!alive.current) return;
|
|
1018
|
+
if (running.current) {
|
|
1019
|
+
refreshPending.current = true;
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1007
1022
|
setNonce((n) => n + 1);
|
|
1008
1023
|
}, []);
|
|
1009
1024
|
(0, react.useEffect)(() => {
|
|
1025
|
+
if (running.current) {
|
|
1026
|
+
refreshPending.current = true;
|
|
1027
|
+
return;
|
|
1028
|
+
}
|
|
1010
1029
|
let current = true;
|
|
1030
|
+
const startedAt = generation.current;
|
|
1011
1031
|
setError(null);
|
|
1012
1032
|
setLoadFailed(false);
|
|
1013
1033
|
load().then((loaded) => {
|
|
1014
1034
|
if (current && alive.current) {
|
|
1035
|
+
if (startedAt !== generation.current) {
|
|
1036
|
+
if (!saveFailed.current) refresh();
|
|
1037
|
+
return;
|
|
1038
|
+
}
|
|
1039
|
+
confirmed.current = loaded;
|
|
1040
|
+
valueRef.current = loaded;
|
|
1015
1041
|
setValue(loaded);
|
|
1016
1042
|
setLoadFailed(false);
|
|
1017
1043
|
}
|
|
@@ -1024,31 +1050,73 @@ window.__ModuleLoader__.load({
|
|
|
1024
1050
|
return () => {
|
|
1025
1051
|
current = false;
|
|
1026
1052
|
};
|
|
1027
|
-
}, [
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1053
|
+
}, [
|
|
1054
|
+
nonce,
|
|
1055
|
+
load,
|
|
1056
|
+
refresh
|
|
1057
|
+
]);
|
|
1058
|
+
const publish = (0, react.useCallback)((next) => {
|
|
1059
|
+
valueRef.current = next;
|
|
1060
|
+
if (alive.current) setValue(next);
|
|
1061
|
+
}, []);
|
|
1031
1062
|
const commit = (0, react.useCallback)(async (mutate) => {
|
|
1032
1063
|
const current = valueRef.current;
|
|
1033
|
-
if (current === null) return;
|
|
1064
|
+
if (current === null || !alive.current) return false;
|
|
1034
1065
|
const next = mutate(current);
|
|
1035
|
-
if (next === null) return;
|
|
1036
|
-
|
|
1066
|
+
if (next === null) return true;
|
|
1067
|
+
generation.current++;
|
|
1068
|
+
publish(next);
|
|
1037
1069
|
setBusy(true);
|
|
1038
|
-
const
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1070
|
+
const completion = new Promise((done) => pending.current.push({
|
|
1071
|
+
mutate,
|
|
1072
|
+
done
|
|
1073
|
+
}));
|
|
1074
|
+
if (!running.current) {
|
|
1075
|
+
running.current = true;
|
|
1076
|
+
(async () => {
|
|
1077
|
+
try {
|
|
1078
|
+
while (pending.current.length > 0) {
|
|
1079
|
+
const operation = pending.current[0];
|
|
1080
|
+
if (operation === void 0) break;
|
|
1081
|
+
const base = confirmed.current ?? current;
|
|
1082
|
+
const target = operation.mutate(base);
|
|
1083
|
+
if (target !== null) {
|
|
1084
|
+
const saved = await save(base, target);
|
|
1085
|
+
confirmed.current = mergeSaved === void 0 ? saved : mergeSaved(target, saved);
|
|
1086
|
+
}
|
|
1087
|
+
saveFailed.current = false;
|
|
1088
|
+
pending.current.shift();
|
|
1089
|
+
operation.done(true);
|
|
1090
|
+
let preview = confirmed.current ?? base;
|
|
1091
|
+
for (const queued of pending.current) preview = queued.mutate(preview) ?? preview;
|
|
1092
|
+
publish(preview);
|
|
1093
|
+
if (alive.current) setError(null);
|
|
1094
|
+
}
|
|
1095
|
+
} catch (cause) {
|
|
1096
|
+
refreshPending.current = false;
|
|
1097
|
+
saveFailed.current = true;
|
|
1098
|
+
const cancelled = pending.current.splice(0);
|
|
1099
|
+
publish(confirmed.current ?? current);
|
|
1100
|
+
if (alive.current) setError(describeError(cause));
|
|
1101
|
+
for (const operation of cancelled) operation.done(false);
|
|
1102
|
+
} finally {
|
|
1103
|
+
running.current = false;
|
|
1104
|
+
if (alive.current) {
|
|
1105
|
+
setBusy(false);
|
|
1106
|
+
if (refreshPending.current) {
|
|
1107
|
+
refreshPending.current = false;
|
|
1108
|
+
setNonce((n) => n + 1);
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
})();
|
|
1113
|
+
}
|
|
1114
|
+
return completion;
|
|
1115
|
+
}, [
|
|
1116
|
+
save,
|
|
1117
|
+
mergeSaved,
|
|
1118
|
+
publish
|
|
1119
|
+
]);
|
|
1052
1120
|
return {
|
|
1053
1121
|
value,
|
|
1054
1122
|
error,
|
|
@@ -1215,7 +1283,8 @@ window.__ModuleLoader__.load({
|
|
|
1215
1283
|
* 会把服务端模块拖进浏览器包。
|
|
1216
1284
|
*/
|
|
1217
1285
|
function isOpen(value, which, name) {
|
|
1218
|
-
|
|
1286
|
+
const local = value.workspace[which];
|
|
1287
|
+
return (Object.hasOwn(local, name) ? local[name] : void 0) ?? isEnabled(value.global[which], name);
|
|
1219
1288
|
}
|
|
1220
1289
|
/**
|
|
1221
1290
|
* 是否「与全局不同」——**只由这一个条件决定**(用户明确要求)。
|
|
@@ -1225,7 +1294,8 @@ window.__ModuleLoader__.load({
|
|
|
1225
1294
|
* 表里有键且与全局反向 ⇒ 是差异 ⇒ 标红。
|
|
1226
1295
|
*/
|
|
1227
1296
|
function isOverridden(value, which, name) {
|
|
1228
|
-
const
|
|
1297
|
+
const map = value.workspace[which];
|
|
1298
|
+
const local = Object.hasOwn(map, name) ? map[name] : void 0;
|
|
1229
1299
|
return local !== void 0 && local !== isEnabled(value.global[which], name);
|
|
1230
1300
|
}
|
|
1231
1301
|
/** 取工程名:`cwd` 的 basename。用 `/` 与 `\` 都切,避免宿主报一个 Windows 路径时整条标题变成完整路径。 */
|
|
@@ -1277,9 +1347,11 @@ window.__ModuleLoader__.load({
|
|
|
1277
1347
|
*/
|
|
1278
1348
|
const toggle = (0, react.useCallback)((current, which, name, open) => {
|
|
1279
1349
|
const base = isEnabled(current.global[which], name);
|
|
1280
|
-
const next = {
|
|
1350
|
+
const next = {
|
|
1351
|
+
...current.workspace[which],
|
|
1352
|
+
[name]: open
|
|
1353
|
+
};
|
|
1281
1354
|
if (open === base) delete next[name];
|
|
1282
|
-
else next[name] = open;
|
|
1283
1355
|
return {
|
|
1284
1356
|
...current,
|
|
1285
1357
|
workspace: {
|
|
@@ -1314,7 +1386,9 @@ window.__ModuleLoader__.load({
|
|
|
1314
1386
|
...current.global,
|
|
1315
1387
|
showOfficialSkills: open
|
|
1316
1388
|
}
|
|
1317
|
-
}).then(() =>
|
|
1389
|
+
}).then((saved) => {
|
|
1390
|
+
if (saved) return panel.refresh();
|
|
1391
|
+
});
|
|
1318
1392
|
}, [panel.commit, panel.refresh]);
|
|
1319
1393
|
const refresh = () => {
|
|
1320
1394
|
panel.refresh();
|
|
@@ -1479,19 +1553,19 @@ window.__ModuleLoader__.load({
|
|
|
1479
1553
|
};
|
|
1480
1554
|
};
|
|
1481
1555
|
const readOpen = () => open;
|
|
1482
|
-
/**
|
|
1556
|
+
/** 最近一次被点击的会话 id;不能在 chip 渲染时写入,否则多个会话会互相覆盖。 */
|
|
1483
1557
|
let sessionId;
|
|
1484
1558
|
ctx.slots.inject("conversation.input.right", () => ctx.slots.register({
|
|
1485
1559
|
name: "conversation.input.right",
|
|
1486
1560
|
id: WORKSPACE_CHIP_ID,
|
|
1487
1561
|
order: 30
|
|
1488
1562
|
}, ((props) => {
|
|
1489
|
-
sessionId = props.sessionId;
|
|
1490
1563
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WorkspaceChip, {
|
|
1491
1564
|
hasSession: typeof props.sessionId === "string" && props.sessionId !== "",
|
|
1492
1565
|
t,
|
|
1493
1566
|
...props.useSession === void 0 ? {} : { useSession: props.useSession },
|
|
1494
1567
|
onOpen: () => {
|
|
1568
|
+
sessionId = props.sessionId;
|
|
1495
1569
|
open = true;
|
|
1496
1570
|
notify();
|
|
1497
1571
|
}
|