dsh-taskbridge 0.0.0-stage → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +754 -0
- package/LICENSE +21 -0
- package/README.md +624 -3
- package/bin/dsh-delegate-codex-agent.js +115 -0
- package/bin/dsh-delegate-control.d.ts +90 -0
- package/bin/dsh-delegate-control.js +450 -0
- package/bin/dsh-delegate-mcp.d.ts +121 -0
- package/bin/dsh-delegate-mcp.js +273 -0
- package/codex/dsh-delegate.toml +245 -0
- package/cordis.patch.yml +6 -0
- package/docs/INTRODUCTION.md +15 -0
- package/docs/INTRODUCTION.zh.md +32 -0
- package/docs/auth-contract.md +138 -0
- package/docs/claude-code.md +31 -0
- package/docs/codex-integration.md +922 -0
- package/docs/contracts-stage-b.md +443 -0
- package/docs/conversation-placement.md +293 -0
- package/docs/plugin-market.md +30 -0
- package/docs/redaction-contract.md +127 -0
- package/docs/runtime-compatibility.md +220 -0
- package/docs/silent-wait.md +191 -0
- package/docs/taskbridge-upgrade.md +28 -0
- package/docs/taskdispatch-upgrade.md +25 -0
- package/docs/worker-permissions.md +347 -0
- package/docs/workspace-contract.md +538 -0
- package/icon.svg +1 -0
- package/lib/client.d.ts +118 -0
- package/lib/client.js +3232 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +135 -4
- package/src/auth/fence.js +361 -0
- package/src/auth/grants.js +789 -0
- package/src/client/api.js +2322 -0
- package/src/client/index.jsx +2333 -0
- package/src/client/styles.js +251 -0
- package/src/codex/installer.js +3260 -0
- package/src/codex/seam.js +429 -0
- package/src/codex/toml.js +784 -0
- package/src/config/defaults.js +164 -0
- package/src/config/redact.js +184 -0
- package/src/config/settings.js +629 -0
- package/src/config/store.js +186 -0
- package/src/config/validate.js +763 -0
- package/src/credentials/seam.js +202 -0
- package/src/http/execution-plane.js +454 -0
- package/src/http/respond.js +175 -0
- package/src/http/user-plane.js +1122 -0
- package/src/index.d.ts +332 -0
- package/src/index.js +657 -0
- package/src/jobs/activity.js +1008 -0
- package/src/jobs/engine.js +3609 -0
- package/src/jobs/history.js +1467 -0
- package/src/mcp/server.js +1820 -0
- package/src/mcp/wait.js +536 -0
- package/src/model/connectivity.js +371 -0
- package/src/model/discovery.js +582 -0
- package/src/model/native-catalog.js +68 -0
- package/src/model/openai-adapter.js +671 -0
- package/src/model/probe.js +264 -0
- package/src/model/providers.js +756 -0
- package/src/model/routing.js +321 -0
- package/src/review/preset.js +868 -0
- package/src/review/prompts.js +126 -0
- package/src/review/reviewer.js +933 -0
- package/src/runtime/agent-runner.js +1738 -0
- package/src/runtime/endpoint-discovery.js +118 -0
- package/src/runtime/permissions.js +1429 -0
- package/src/runtime/sandbox.js +358 -0
- package/src/runtime/session-placement.js +1103 -0
- package/src/workspace/audit.js +775 -0
- package/src/workspace/locks.js +167 -0
- package/src/workspace/preflight.js +424 -0
- package/src/workspace/worktrees.js +613 -0
package/lib/client.js
ADDED
|
@@ -0,0 +1,3232 @@
|
|
|
1
|
+
// Generated by scripts/build-client.mjs — do not edit.
|
|
2
|
+
// Source: src/client/index.jsx, src/client/api.js, src/client/styles.js.
|
|
3
|
+
window.__ModuleLoader__.load({
|
|
4
|
+
id: "dsh-taskbridge",
|
|
5
|
+
factory: (require) => {
|
|
6
|
+
var module = { exports: {} };
|
|
7
|
+
var exports = module.exports;
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
|
|
26
|
+
// src/client/index.jsx
|
|
27
|
+
var index_exports = {};
|
|
28
|
+
__export(index_exports, {
|
|
29
|
+
DelegateConfigPage: () => DelegateConfigPage,
|
|
30
|
+
PLUGIN_BUNDLE_KEY: () => PLUGIN_BUNDLE_KEY,
|
|
31
|
+
PLUGIN_CONFIG_SLOT: () => PLUGIN_CONFIG_SLOT,
|
|
32
|
+
apply: () => apply,
|
|
33
|
+
describeError: () => describeError,
|
|
34
|
+
documentFromDraft: () => documentFromDraft,
|
|
35
|
+
exportDocument: () => exportDocument,
|
|
36
|
+
inject: () => inject,
|
|
37
|
+
registerBundleConfiguration: () => registerBundleConfiguration
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(index_exports);
|
|
40
|
+
var import_react = require("react");
|
|
41
|
+
|
|
42
|
+
// src/client/api.js
|
|
43
|
+
var USER_PLANE_PREFIX = "/api/dsh-delegate";
|
|
44
|
+
var ROUTES = Object.freeze({
|
|
45
|
+
status: `${USER_PLANE_PREFIX}/status`,
|
|
46
|
+
delegation: `${USER_PLANE_PREFIX}/delegation`,
|
|
47
|
+
nativeProviders: `${USER_PLANE_PREFIX}/native-providers`,
|
|
48
|
+
settings: `${USER_PLANE_PREFIX}/settings`,
|
|
49
|
+
// One narrow, authenticated operator route for the two silence thresholds. It is
|
|
50
|
+
// a browser-plane write only: the MCP surface never gains a settings write.
|
|
51
|
+
monitoring: `${USER_PLANE_PREFIX}/monitoring`,
|
|
52
|
+
catalog: `${USER_PLANE_PREFIX}/catalog`,
|
|
53
|
+
connections: `${USER_PLANE_PREFIX}/connections`,
|
|
54
|
+
connectionsRevoke: `${USER_PLANE_PREFIX}/connections/revoke`,
|
|
55
|
+
grants: `${USER_PLANE_PREFIX}/grants`,
|
|
56
|
+
grantsRevoke: `${USER_PLANE_PREFIX}/grants/revoke`,
|
|
57
|
+
revokeAll: `${USER_PLANE_PREFIX}/authorization/revoke-all`,
|
|
58
|
+
tasks: `${USER_PLANE_PREFIX}/tasks`,
|
|
59
|
+
tasksGet: `${USER_PLANE_PREFIX}/tasks/get`,
|
|
60
|
+
tasksCancel: `${USER_PLANE_PREFIX}/tasks/cancel`,
|
|
61
|
+
models: `${USER_PLANE_PREFIX}/models`,
|
|
62
|
+
credentialsStatus: `${USER_PLANE_PREFIX}/credentials/status`,
|
|
63
|
+
credentialsSet: `${USER_PLANE_PREFIX}/credentials/set`,
|
|
64
|
+
credentialsUnset: `${USER_PLANE_PREFIX}/credentials/unset`,
|
|
65
|
+
connectivity: `${USER_PLANE_PREFIX}/connectivity`,
|
|
66
|
+
// One path, two methods: `GET` diagnoses, `POST` performs one explicit action.
|
|
67
|
+
codex: `${USER_PLANE_PREFIX}/codex`
|
|
68
|
+
});
|
|
69
|
+
var ApiError = class extends Error {
|
|
70
|
+
/**
|
|
71
|
+
* @param {string} code - stable machine code (`SETTINGS_INVALID`, `HTTP_404`, ...).
|
|
72
|
+
* @param {string} message - short English diagnostic from the host.
|
|
73
|
+
* @param {object} [options] - `status`, `details`.
|
|
74
|
+
*/
|
|
75
|
+
constructor(code, message, options = {}) {
|
|
76
|
+
super(message);
|
|
77
|
+
this.name = "ApiError";
|
|
78
|
+
this.code = code;
|
|
79
|
+
this.status = options.status ?? 0;
|
|
80
|
+
this.details = options.details ?? {};
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
function createApi(options = {}) {
|
|
84
|
+
const fetchImpl = options.fetchImpl ?? ((url, init) => globalThis.fetch(url, init));
|
|
85
|
+
const base = typeof options.base === "string" ? options.base : "";
|
|
86
|
+
async function request(method, route, body) {
|
|
87
|
+
const url = `${base}${route.replace(/^\//, "")}`;
|
|
88
|
+
let response;
|
|
89
|
+
try {
|
|
90
|
+
response = await fetchImpl(url, {
|
|
91
|
+
method,
|
|
92
|
+
// The browser session cookie is the user plane's credential. Sending it
|
|
93
|
+
// cross-origin is impossible here, and the native carrier fences Host and
|
|
94
|
+
// Origin before any handler runs.
|
|
95
|
+
credentials: "same-origin",
|
|
96
|
+
cache: "no-store",
|
|
97
|
+
headers: body === void 0 ? { accept: "application/json" } : { accept: "application/json", "content-type": "application/json" },
|
|
98
|
+
...body === void 0 ? {} : { body: JSON.stringify(body) }
|
|
99
|
+
});
|
|
100
|
+
} catch (error) {
|
|
101
|
+
throw new ApiError("USER_PLANE_UNREACHABLE", "the delegation settings service could not be reached", {
|
|
102
|
+
details: { detail: String(error?.message ?? error).slice(0, 200) }
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
let text = "";
|
|
106
|
+
try {
|
|
107
|
+
text = typeof response.text === "function" ? await response.text() : "";
|
|
108
|
+
} catch {
|
|
109
|
+
text = "";
|
|
110
|
+
}
|
|
111
|
+
let parsed = null;
|
|
112
|
+
try {
|
|
113
|
+
parsed = text === "" ? null : JSON.parse(text);
|
|
114
|
+
} catch {
|
|
115
|
+
parsed = null;
|
|
116
|
+
}
|
|
117
|
+
if (!response.ok || parsed === null || parsed.ok !== true) {
|
|
118
|
+
const failure = parsed !== null && typeof parsed === "object" ? parsed.error : void 0;
|
|
119
|
+
const code = typeof failure?.code === "string" ? failure.code : response.ok ? "USER_PLANE_MALFORMED" : `HTTP_${response.status}`;
|
|
120
|
+
const message = typeof failure?.message === "string" ? failure.message : `the settings service answered HTTP ${response.status}`;
|
|
121
|
+
throw new ApiError(code, message, {
|
|
122
|
+
status: response.status,
|
|
123
|
+
details: typeof failure?.details === "object" && failure.details !== null ? failure.details : {}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return parsed;
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
/** @returns {Promise<object>} plugin/delegation posture. */
|
|
130
|
+
async getStatus() {
|
|
131
|
+
return await request("GET", ROUTES.status);
|
|
132
|
+
},
|
|
133
|
+
/** @param {boolean} enabled - master dispatch switch. */
|
|
134
|
+
async setDelegationEnabled(enabled) {
|
|
135
|
+
return await request("POST", ROUTES.delegation, { enabled });
|
|
136
|
+
},
|
|
137
|
+
/** @returns {Promise<object>} DSH's already registered providers and models. */
|
|
138
|
+
async getNativeProviders() {
|
|
139
|
+
return await request("GET", ROUTES.nativeProviders);
|
|
140
|
+
},
|
|
141
|
+
/** @returns {Promise<object>} `{ settings, secrets }`. */
|
|
142
|
+
async getSettings() {
|
|
143
|
+
return await request("GET", ROUTES.settings);
|
|
144
|
+
},
|
|
145
|
+
/**
|
|
146
|
+
* Replace the whole settings document.
|
|
147
|
+
* @param {object} settings - full document (never carrying a secret).
|
|
148
|
+
* @returns {Promise<object>} `{ settings }`.
|
|
149
|
+
*/
|
|
150
|
+
async putSettings(settings) {
|
|
151
|
+
return await request("POST", ROUTES.settings, { settings });
|
|
152
|
+
},
|
|
153
|
+
/**
|
|
154
|
+
* Replace only the two silence thresholds.
|
|
155
|
+
*
|
|
156
|
+
* This is the narrow route the advanced monitoring controls use, so a operator
|
|
157
|
+
* adjusting a timer cannot accidentally rewrite a provider list. The host
|
|
158
|
+
* re-validates: whole seconds, each in range, and the attention threshold strictly
|
|
159
|
+
* greater than the self-check one.
|
|
160
|
+
* @param {{ selfCheckSeconds: number, attentionSeconds: number }} monitoring - thresholds in seconds.
|
|
161
|
+
* @returns {Promise<object>} `{ monitoring, settings }`.
|
|
162
|
+
*/
|
|
163
|
+
async putMonitoring(monitoring) {
|
|
164
|
+
return await request("POST", ROUTES.monitoring, { monitoring });
|
|
165
|
+
},
|
|
166
|
+
/**
|
|
167
|
+
* Resolve provider models/efforts plus the composed effective config.
|
|
168
|
+
* @param {object} [body] - `{ projectPath }`.
|
|
169
|
+
* @returns {Promise<object>} `{ catalog, effective }`.
|
|
170
|
+
*/
|
|
171
|
+
async getCatalog(body = {}) {
|
|
172
|
+
return await request("POST", ROUTES.catalog, body);
|
|
173
|
+
},
|
|
174
|
+
/** @returns {Promise<object>} `{ connections }`. */
|
|
175
|
+
async listConnections() {
|
|
176
|
+
return await request("GET", ROUTES.connections);
|
|
177
|
+
},
|
|
178
|
+
/**
|
|
179
|
+
* Issue a connection. The response is the only place a token is ever visible.
|
|
180
|
+
* @param {string} label - display label.
|
|
181
|
+
* @returns {Promise<object>} `{ connection, token, tokenReturnedOnce }`.
|
|
182
|
+
*/
|
|
183
|
+
async issueConnection(label) {
|
|
184
|
+
return await request("POST", ROUTES.connections, { label });
|
|
185
|
+
},
|
|
186
|
+
/**
|
|
187
|
+
* Revoke one connection and its grants.
|
|
188
|
+
* @param {string} connectionId - server-issued identity.
|
|
189
|
+
* @returns {Promise<object>} `{ grantsRevoked }`.
|
|
190
|
+
*/
|
|
191
|
+
async revokeConnection(connectionId) {
|
|
192
|
+
return await request("POST", ROUTES.connectionsRevoke, { connectionId });
|
|
193
|
+
},
|
|
194
|
+
/**
|
|
195
|
+
* List one connection's grants.
|
|
196
|
+
* @param {string} connectionId - server-issued identity.
|
|
197
|
+
* @returns {Promise<object>} `{ grants }`.
|
|
198
|
+
*/
|
|
199
|
+
async listGrants(connectionId) {
|
|
200
|
+
return await request("GET", `${ROUTES.grants}?${new URLSearchParams({ connectionId })}`);
|
|
201
|
+
},
|
|
202
|
+
/**
|
|
203
|
+
* Issue one grant.
|
|
204
|
+
* @param {object} body - `{ connectionId, kind, workspacePath, ttlSeconds? }`.
|
|
205
|
+
* @returns {Promise<object>} `{ grant }`.
|
|
206
|
+
*/
|
|
207
|
+
async issueGrant(body) {
|
|
208
|
+
return await request("POST", ROUTES.grants, body);
|
|
209
|
+
},
|
|
210
|
+
/**
|
|
211
|
+
* Revoke one grant.
|
|
212
|
+
* @param {string} grantId - grant identity.
|
|
213
|
+
* @returns {Promise<object>} `{ grant }`.
|
|
214
|
+
*/
|
|
215
|
+
async revokeGrant(grantId) {
|
|
216
|
+
return await request("POST", ROUTES.grantsRevoke, { grantId });
|
|
217
|
+
},
|
|
218
|
+
/** @returns {Promise<object>} `{ grantsRevoked }`. */
|
|
219
|
+
async revokeAll() {
|
|
220
|
+
return await request("POST", ROUTES.revokeAll, {});
|
|
221
|
+
},
|
|
222
|
+
/**
|
|
223
|
+
* List tasks (never carrying a prompt).
|
|
224
|
+
* @param {string | null} [connectionId] - optional filter.
|
|
225
|
+
* @returns {Promise<object>} `{ tasks }`.
|
|
226
|
+
*/
|
|
227
|
+
async listTasks(connectionId = null) {
|
|
228
|
+
const suffix = connectionId === null ? "" : `?${new URLSearchParams({ connectionId })}`;
|
|
229
|
+
return await request("GET", `${ROUTES.tasks}${suffix}`);
|
|
230
|
+
},
|
|
231
|
+
/**
|
|
232
|
+
* Read one task including its prompt.
|
|
233
|
+
* @param {string} taskId - task identity.
|
|
234
|
+
* @returns {Promise<object>} `{ task }`.
|
|
235
|
+
*/
|
|
236
|
+
async getTask(taskId) {
|
|
237
|
+
return await request("POST", ROUTES.tasksGet, { taskId });
|
|
238
|
+
},
|
|
239
|
+
/**
|
|
240
|
+
* Cancel a task as the operator.
|
|
241
|
+
* @param {string} taskId - task identity.
|
|
242
|
+
* @returns {Promise<object>} `{ task }`.
|
|
243
|
+
*/
|
|
244
|
+
async cancelTask(taskId) {
|
|
245
|
+
return await request("POST", ROUTES.tasksCancel, { taskId });
|
|
246
|
+
},
|
|
247
|
+
/**
|
|
248
|
+
* Discover one provider's model list from its own API (remote discovery).
|
|
249
|
+
*
|
|
250
|
+
* The host performs one authenticated request to the provider's configured
|
|
251
|
+
* base URL with *that profile's* credential reference, so this answers "what
|
|
252
|
+
* does the endpoint say it serves" — not "what can the harness resolve" (that
|
|
253
|
+
* is `getCatalog`). A failed discovery still answers `ok: true` with
|
|
254
|
+
* `models: []` and a `discovery` diagnosis, so a caller must read
|
|
255
|
+
* `body.discovery?.failed` and `body.error` rather than treating an empty list
|
|
256
|
+
* as "the provider has no models".
|
|
257
|
+
* @param {string} providerId - configured provider id.
|
|
258
|
+
* @returns {Promise<object>} `{ models: [{ id, efforts }], source, discovery, error }`.
|
|
259
|
+
*/
|
|
260
|
+
async fetchModels(providerId) {
|
|
261
|
+
return await request("POST", ROUTES.models, { providerId });
|
|
262
|
+
},
|
|
263
|
+
/**
|
|
264
|
+
* Read whether a provider's credential is configured (target route).
|
|
265
|
+
* @param {string} providerId - configured provider id.
|
|
266
|
+
* @returns {Promise<object>} `{ credential: { configured, source?, writable? } }`.
|
|
267
|
+
*/
|
|
268
|
+
async credentialStatus(providerId) {
|
|
269
|
+
return await request("POST", ROUTES.credentialsStatus, { providerId });
|
|
270
|
+
},
|
|
271
|
+
/**
|
|
272
|
+
* Store a credential value through the separate authenticated seam.
|
|
273
|
+
* @param {string} providerId - configured provider id.
|
|
274
|
+
* @param {string} value - the literal value; never retained by the caller.
|
|
275
|
+
* @returns {Promise<object>} `{ credential }`.
|
|
276
|
+
*/
|
|
277
|
+
async setCredential(providerId, value) {
|
|
278
|
+
return await request("POST", ROUTES.credentialsSet, { providerId, value });
|
|
279
|
+
},
|
|
280
|
+
/**
|
|
281
|
+
* Remove a stored credential value.
|
|
282
|
+
* @param {string} providerId - configured provider id.
|
|
283
|
+
* @returns {Promise<object>} `{ credential }`.
|
|
284
|
+
*/
|
|
285
|
+
async unsetCredential(providerId) {
|
|
286
|
+
return await request("POST", ROUTES.credentialsUnset, { providerId });
|
|
287
|
+
},
|
|
288
|
+
/**
|
|
289
|
+
* Run the layered connectivity check.
|
|
290
|
+
* @param {object} body - `{ providerId, model?, reasoningEffort? }`.
|
|
291
|
+
* @returns {Promise<object>} `{ report }`.
|
|
292
|
+
*/
|
|
293
|
+
async checkConnectivity(body) {
|
|
294
|
+
return await request("POST", ROUTES.connectivity, body);
|
|
295
|
+
},
|
|
296
|
+
/**
|
|
297
|
+
* Diagnose the Codex integration. Read-only on the host.
|
|
298
|
+
* @returns {Promise<object>} `{ codex, switch }`.
|
|
299
|
+
*/
|
|
300
|
+
async getCodexStatus() {
|
|
301
|
+
return await request("GET", ROUTES.codex);
|
|
302
|
+
},
|
|
303
|
+
/**
|
|
304
|
+
* Perform one explicit Codex action.
|
|
305
|
+
*
|
|
306
|
+
* Only an operator click reaches this: there is no load-time or save-time
|
|
307
|
+
* caller, so visiting the page never writes into the Codex home.
|
|
308
|
+
* @param {'install'|'repair'|'remove'} action - the action to perform.
|
|
309
|
+
* @returns {Promise<object>} `{ action, changed, refused, codex, switch }`.
|
|
310
|
+
*/
|
|
311
|
+
async runCodexAction(action) {
|
|
312
|
+
return await request("POST", ROUTES.codex, { action });
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
var KNOWN_EFFORTS = Object.freeze(["off", "minimal", "low", "medium", "high", "xhigh", "max"]);
|
|
317
|
+
var EFFORT_LABELS = Object.freeze({
|
|
318
|
+
off: "关闭推理",
|
|
319
|
+
minimal: "最少",
|
|
320
|
+
low: "低",
|
|
321
|
+
medium: "中",
|
|
322
|
+
high: "高",
|
|
323
|
+
xhigh: "很高",
|
|
324
|
+
max: "最高"
|
|
325
|
+
});
|
|
326
|
+
var EFFORT_UNSET = "";
|
|
327
|
+
var ISOLATION_MODES = Object.freeze(["worktree", "shared"]);
|
|
328
|
+
var ISOLATION_LABELS = Object.freeze({
|
|
329
|
+
worktree: "独立工作树(临时 git worktree,不碰当前检出)",
|
|
330
|
+
shared: "共享工作区(直接修改所选目录)"
|
|
331
|
+
});
|
|
332
|
+
var CONVERSATION_MODES = Object.freeze(["new", "reuse"]);
|
|
333
|
+
var CONVERSATION_LABELS = Object.freeze({
|
|
334
|
+
new: "每个任务新开对话",
|
|
335
|
+
reuse: "复用同一执行目录最近的对话(已移除)"
|
|
336
|
+
});
|
|
337
|
+
var CONVERSATION_POLICY_LABEL = "每次提交默认新开对话;只有带上 continueFromTaskId 的跟进任务才续接同一条对话";
|
|
338
|
+
function conversationOf(draft) {
|
|
339
|
+
const requested = draft?.conversation?.mode;
|
|
340
|
+
return { mode: CONVERSATION_MODES.includes(requested) ? requested : CONVERSATION_MODES[0] };
|
|
341
|
+
}
|
|
342
|
+
function monitoringOf(source) {
|
|
343
|
+
const block = source?.monitoring;
|
|
344
|
+
if (block === null || typeof block !== "object" || Array.isArray(block)) return { ...MONITORING_DEFAULTS };
|
|
345
|
+
const whole = (value, fallback) => Number.isFinite(value) ? Math.trunc(value) : fallback;
|
|
346
|
+
return {
|
|
347
|
+
selfCheckSeconds: whole(block.selfCheckSeconds, MONITORING_DEFAULTS.selfCheckSeconds),
|
|
348
|
+
attentionSeconds: whole(block.attentionSeconds, MONITORING_DEFAULTS.attentionSeconds)
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
function secondsToMinutes(seconds) {
|
|
352
|
+
if (!Number.isFinite(seconds)) return 0;
|
|
353
|
+
return seconds / 60;
|
|
354
|
+
}
|
|
355
|
+
function minutesToSeconds(minutes) {
|
|
356
|
+
if (typeof minutes === "string" && minutes.trim() === "") return Number.NaN;
|
|
357
|
+
if (minutes === null || minutes === void 0) return Number.NaN;
|
|
358
|
+
const value = typeof minutes === "number" ? minutes : Number(String(minutes).trim());
|
|
359
|
+
if (!Number.isFinite(value)) return Number.NaN;
|
|
360
|
+
return Math.round(value * 60);
|
|
361
|
+
}
|
|
362
|
+
var GRANT_KINDS = Object.freeze(["task", "session"]);
|
|
363
|
+
var GRANT_KIND_LABELS = Object.freeze({
|
|
364
|
+
task: "单次任务(用掉即失效)",
|
|
365
|
+
session: "本连接会话(限时、可撤销)"
|
|
366
|
+
});
|
|
367
|
+
var PERMISSION_STATE_LABELS = Object.freeze({
|
|
368
|
+
pending: "等待本机指挥官决定(仅这一次调用)",
|
|
369
|
+
decided: "已决定",
|
|
370
|
+
expired: "已超时(未决定即为拒绝)",
|
|
371
|
+
cancelled: "已撤回",
|
|
372
|
+
unavailable: "无法建立请求身份(已按拒绝处理)"
|
|
373
|
+
});
|
|
374
|
+
var PERMISSION_DECISION_LABELS = Object.freeze({
|
|
375
|
+
"allow-once": "仅本次允许",
|
|
376
|
+
reject: "拒绝"
|
|
377
|
+
});
|
|
378
|
+
var PERMISSION_OUTCOME_LABELS = Object.freeze({
|
|
379
|
+
"allowed-once": "仅本次允许",
|
|
380
|
+
rejected: "已拒绝",
|
|
381
|
+
cancelled: "已撤回",
|
|
382
|
+
unavailable: "无可用审批通道"
|
|
383
|
+
});
|
|
384
|
+
var TASK_PHASE_LABELS = Object.freeze({
|
|
385
|
+
created: "已创建",
|
|
386
|
+
workspace: "解析工作区",
|
|
387
|
+
authorization: "校验授权",
|
|
388
|
+
settings: "读取设置",
|
|
389
|
+
providers: "确认提供方",
|
|
390
|
+
worktree: "准备工作树",
|
|
391
|
+
audit: "记录基线",
|
|
392
|
+
"before-create": "即将创建执行器",
|
|
393
|
+
execute: "执行中",
|
|
394
|
+
"awaiting-permission": "等待本次调用授权决定",
|
|
395
|
+
review: "附加审查中",
|
|
396
|
+
"awaiting-host-review": "等待宿主审查",
|
|
397
|
+
failed: "已失败",
|
|
398
|
+
cancelled: "已取消"
|
|
399
|
+
});
|
|
400
|
+
var TASK_STATES = Object.freeze(["pending", "running", "awaiting-host-review", "failed", "cancelled"]);
|
|
401
|
+
var TASK_STATE_LABELS = Object.freeze({
|
|
402
|
+
pending: "排队中",
|
|
403
|
+
running: "执行中",
|
|
404
|
+
"awaiting-host-review": "等待宿主审查",
|
|
405
|
+
failed: "执行失败",
|
|
406
|
+
cancelled: "已取消",
|
|
407
|
+
// A task persisted by a restart is stored with this state. It is NOT "still
|
|
408
|
+
// running": the execution does not resume, so the panel says exactly that. The
|
|
409
|
+
// engine never sets it for a live run — the same word is also the reason an
|
|
410
|
+
// OBSERVATION was interrupted, and that is a different thing (see
|
|
411
|
+
// `WAIT_REASON_LABELS.interrupted`).
|
|
412
|
+
interrupted: "已中断(进程重启后不会继续执行)"
|
|
413
|
+
});
|
|
414
|
+
var REVIEW_STATE_LABELS = Object.freeze({
|
|
415
|
+
disabled: "未启用附加审查",
|
|
416
|
+
not_run: "未运行",
|
|
417
|
+
completed: "已完成",
|
|
418
|
+
failed: "审查失败(与任务成败无关)"
|
|
419
|
+
});
|
|
420
|
+
var REVIEW_VERDICT_LABELS = Object.freeze({
|
|
421
|
+
approve: "建议通过",
|
|
422
|
+
"changes-requested": "建议修改",
|
|
423
|
+
unknown: "未给出结论"
|
|
424
|
+
});
|
|
425
|
+
var CONNECTIVITY_LAYERS = Object.freeze([
|
|
426
|
+
{ key: "transport", label: "传输(地址可达)" },
|
|
427
|
+
{ key: "authentication", label: "认证(凭据可用)" },
|
|
428
|
+
{ key: "catalog", label: "模型目录" },
|
|
429
|
+
{ key: "modelResponse", label: "模型实际响应" }
|
|
430
|
+
]);
|
|
431
|
+
var LIMITS = Object.freeze({
|
|
432
|
+
timeoutSecondsMin: 30,
|
|
433
|
+
timeoutSecondsMax: 7200,
|
|
434
|
+
maxParallelismMin: 1,
|
|
435
|
+
maxParallelismMax: 8,
|
|
436
|
+
taskGrantTtlSecondsMin: 30,
|
|
437
|
+
taskGrantTtlSecondsMax: 3600,
|
|
438
|
+
sessionGrantTtlSecondsMin: 60,
|
|
439
|
+
sessionGrantTtlSecondsMax: 43200,
|
|
440
|
+
providers: 32,
|
|
441
|
+
// Silence thresholds. Mirrors `LIMITS` in `src/config/defaults.js`; the host is
|
|
442
|
+
// still the authority, these only drive input attributes and the local precheck.
|
|
443
|
+
selfCheckSecondsMin: 30,
|
|
444
|
+
selfCheckSecondsMax: 3600,
|
|
445
|
+
attentionSecondsMin: 31,
|
|
446
|
+
attentionSecondsMax: 7200
|
|
447
|
+
});
|
|
448
|
+
var MONITORING_DEFAULTS = Object.freeze({
|
|
449
|
+
selfCheckSeconds: 300,
|
|
450
|
+
attentionSeconds: 600
|
|
451
|
+
});
|
|
452
|
+
var SELF_CHECK_LABELS = Object.freeze({
|
|
453
|
+
"executor-alive-silent": "执行器健在,这段时间没有新输出",
|
|
454
|
+
"executor-not-started": "执行器尚未开始",
|
|
455
|
+
"idle-between-steps": "两步之间,执行器已停止输出",
|
|
456
|
+
"tool-running": "某个工具调用仍在运行",
|
|
457
|
+
"waiting-for-permission": "正在等待本次调用授权决定",
|
|
458
|
+
settled: "任务已经结束"
|
|
459
|
+
});
|
|
460
|
+
var WAIT_REASON_LABELS = Object.freeze({
|
|
461
|
+
heartbeat: "没有需要处理的事(内部心跳)",
|
|
462
|
+
attention: "长时间没有任何新进展,需要你判断",
|
|
463
|
+
permission: "有一次工具调用在等待授权决定",
|
|
464
|
+
ready: "执行已结束,等待宿主审查(不等于已接受)",
|
|
465
|
+
failed: "执行失败",
|
|
466
|
+
cancelled: "已取消",
|
|
467
|
+
// The reason describes the WAIT, and only a TERMINAL answer means the task record is
|
|
468
|
+
// itself interrupted. Both readings are named, because a serialised host reads this
|
|
469
|
+
// through `delegate_wait`'s answer: a live task stays live (`wait-limit`, below), a
|
|
470
|
+
// restart history does not resume.
|
|
471
|
+
interrupted: "这次等待被中断;任务是否仍在运行要看答案里的 terminal/state(任务记录本身中断才是重启历史,不会继续执行)",
|
|
472
|
+
"wait-limit": "本轮等待时间用完,任务仍在运行"
|
|
473
|
+
});
|
|
474
|
+
var CODEX_ACTIONS = Object.freeze(["install", "repair", "remove"]);
|
|
475
|
+
var CODEX_TARGETS = Object.freeze([
|
|
476
|
+
{ key: "agent", label: "Codex 子智能体文件" },
|
|
477
|
+
{ key: "mcp", label: "Codex MCP 条目" },
|
|
478
|
+
{ key: "switch", label: "DSH 本机调用开关" }
|
|
479
|
+
]);
|
|
480
|
+
var CODEX_STATE_LABELS = Object.freeze({
|
|
481
|
+
"not-installed": "未安装",
|
|
482
|
+
installed: "已安装",
|
|
483
|
+
outdated: "旧版本,可更新",
|
|
484
|
+
modified: "不属于已知版本(插件不会改动)",
|
|
485
|
+
conflict: "存在冲突(插件不会改动)",
|
|
486
|
+
"not-configured": "未配置",
|
|
487
|
+
configured: "已配置",
|
|
488
|
+
unreadable: "无法读取(不会写入)"
|
|
489
|
+
});
|
|
490
|
+
function codexTargetView(codex, switchState, target) {
|
|
491
|
+
const label = CODEX_TARGETS.find((entry) => entry.key === target)?.label ?? target;
|
|
492
|
+
if (target === "switch") {
|
|
493
|
+
const authorized = switchState?.authorized === true;
|
|
494
|
+
return {
|
|
495
|
+
key: "switch",
|
|
496
|
+
label,
|
|
497
|
+
state: authorized ? "on" : "off",
|
|
498
|
+
tone: authorized ? "on" : "off",
|
|
499
|
+
detail: authorized ? "已开启:Codex 可以通过 MCP 提交任务。" : "已关闭:Codex 可以查询状态,但新任务会被拒绝;本页不会替你打开它。"
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
const block = target === "agent" ? codex?.agent : codex?.mcp;
|
|
503
|
+
if (block === null || block === void 0 || typeof block !== "object") {
|
|
504
|
+
return { key: target, label, state: "unknown", tone: "off", detail: "宿主尚未回报该状态。" };
|
|
505
|
+
}
|
|
506
|
+
const state = String(block.state ?? "unknown");
|
|
507
|
+
const done = target === "agent" ? block.installed === true : block.configured === true;
|
|
508
|
+
const detailParts = [];
|
|
509
|
+
if (typeof block.path === "string" && block.path !== "") detailParts.push(block.path);
|
|
510
|
+
if (target === "mcp" && typeof block.script === "string" && block.script !== "") {
|
|
511
|
+
detailParts.push(`入口:${block.script}`);
|
|
512
|
+
}
|
|
513
|
+
if (target === "mcp") {
|
|
514
|
+
if (typeof block.node === "string" && block.node !== "") detailParts.push(`Node:${block.node}`);
|
|
515
|
+
else if (block.nodeResolved === false) detailParts.push("Node:未确定(不会写入桌面应用自身的 exe)");
|
|
516
|
+
}
|
|
517
|
+
return {
|
|
518
|
+
key: target,
|
|
519
|
+
label,
|
|
520
|
+
state,
|
|
521
|
+
tone: done ? "on" : state === "conflict" || state === "unreadable" || state === "modified" ? "warn" : "off",
|
|
522
|
+
detail: CODEX_STATE_LABELS[state] ?? state,
|
|
523
|
+
path: typeof block.path === "string" ? block.path : "",
|
|
524
|
+
paths: detailParts
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
function describeCodexOutcome(outcome) {
|
|
528
|
+
if (outcome === null || outcome === void 0) return "";
|
|
529
|
+
const names = { agent: "子智能体文件", mcp: "MCP 条目" };
|
|
530
|
+
const changed = Array.isArray(outcome.changed) ? outcome.changed.map((key) => names[key] ?? key) : [];
|
|
531
|
+
const refused = Array.isArray(outcome.refused) ? outcome.refused : [];
|
|
532
|
+
const parts = [];
|
|
533
|
+
if (changed.length > 0) parts.push(`已写入:${changed.join("、")}`);
|
|
534
|
+
if (refused.length > 0) parts.push(`未改动:${refused.map((entry) => names[entry?.target] ?? entry?.target ?? "未知").join("、")}`);
|
|
535
|
+
if (parts.length === 0) {
|
|
536
|
+
return outcome.action === "remove" ? "没有需要移除的插件托管文件。" : "已是最新,没有需要写入的内容。";
|
|
537
|
+
}
|
|
538
|
+
return parts.join(";") + "。";
|
|
539
|
+
}
|
|
540
|
+
var SUPPORTED_PROTOCOLS = Object.freeze(["openai-chat"]);
|
|
541
|
+
function clone(value) {
|
|
542
|
+
return value === void 0 ? void 0 : JSON.parse(JSON.stringify(value));
|
|
543
|
+
}
|
|
544
|
+
function defaultDraft() {
|
|
545
|
+
return {
|
|
546
|
+
schemaVersion: 1,
|
|
547
|
+
delegationEnabled: false,
|
|
548
|
+
providers: [],
|
|
549
|
+
worker: {
|
|
550
|
+
providerId: null,
|
|
551
|
+
model: null,
|
|
552
|
+
reasoningEffort: null,
|
|
553
|
+
timeoutSeconds: 1800,
|
|
554
|
+
maxParallelism: 1,
|
|
555
|
+
isolation: "worktree"
|
|
556
|
+
},
|
|
557
|
+
review: { enabled: false, providerId: null, model: null, reasoningEffort: null },
|
|
558
|
+
authorization: { taskGrantTtlSeconds: 900, sessionGrantTtlSeconds: 14400 },
|
|
559
|
+
// Silence thresholds. Present in a fresh draft so the controls render without a
|
|
560
|
+
// second load, and normalized from the served document below so an older host
|
|
561
|
+
// (or an older stored file) still opens with the documented defaults.
|
|
562
|
+
monitoring: { ...MONITORING_DEFAULTS },
|
|
563
|
+
projectOverrides: {},
|
|
564
|
+
presets: [],
|
|
565
|
+
// Deprecated and inert, kept only so a save round-trips the stored document
|
|
566
|
+
// instead of rewriting it. There is no conversation-mode control: a submission
|
|
567
|
+
// starts a new DSH conversation unless it names `continueFromTaskId`.
|
|
568
|
+
conversation: { mode: CONVERSATION_MODES[0] }
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
function draftFromSettings(document2) {
|
|
572
|
+
const source = document2 ?? {};
|
|
573
|
+
const base = defaultDraft();
|
|
574
|
+
return {
|
|
575
|
+
schemaVersion: typeof source.schemaVersion === "number" ? source.schemaVersion : base.schemaVersion,
|
|
576
|
+
delegationEnabled: source.delegationEnabled === true,
|
|
577
|
+
providers: Array.isArray(source.providers) ? source.providers.map((provider) => ({
|
|
578
|
+
id: String(provider.id ?? ""),
|
|
579
|
+
name: String(provider.name ?? ""),
|
|
580
|
+
source: provider.source ?? "custom",
|
|
581
|
+
protocol: provider.source === "native" ? null : String(provider.protocol ?? "openai-chat"),
|
|
582
|
+
baseUrl: provider.source === "native" ? null : String(provider.baseUrl ?? ""),
|
|
583
|
+
credentialRef: provider.source === "native" ? null : provider.credentialRef ?? null,
|
|
584
|
+
models: Array.isArray(provider.models) ? provider.models.map((model) => ({
|
|
585
|
+
id: String(model.id ?? ""),
|
|
586
|
+
efforts: Array.isArray(model.efforts) ? [...model.efforts] : []
|
|
587
|
+
})) : []
|
|
588
|
+
})) : [],
|
|
589
|
+
worker: { ...base.worker, ...source.worker ?? {} },
|
|
590
|
+
review: { ...base.review, ...source.review ?? {} },
|
|
591
|
+
authorization: { ...base.authorization, ...source.authorization ?? {} },
|
|
592
|
+
// A document written before this block existed has no `monitoring` key at all,
|
|
593
|
+
// and a host that predates it never serves one. Both open with the documented
|
|
594
|
+
// defaults instead of a blank control, and the values are coerced to whole
|
|
595
|
+
// seconds because that is the only shape the host accepts.
|
|
596
|
+
monitoring: monitoringOf(source),
|
|
597
|
+
projectOverrides: clone(source.projectOverrides ?? {}),
|
|
598
|
+
presets: Array.isArray(source.presets) ? source.presets.map((preset) => ({
|
|
599
|
+
id: String(preset.id ?? ""),
|
|
600
|
+
name: String(preset.name ?? preset.id ?? ""),
|
|
601
|
+
worker: preset.worker === null || preset.worker === void 0 ? null : { ...preset.worker },
|
|
602
|
+
review: preset.review === null || preset.review === void 0 ? null : { ...preset.review }
|
|
603
|
+
})) : [],
|
|
604
|
+
// Read back through the same resolver the save path uses, so a document written
|
|
605
|
+
// before this field existed opens with the default and an inert stored `reuse`
|
|
606
|
+
// is preserved verbatim rather than silently rewritten.
|
|
607
|
+
conversation: conversationOf(source)
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
function documentFromDraft(draft) {
|
|
611
|
+
const source = draft ?? defaultDraft();
|
|
612
|
+
return {
|
|
613
|
+
schemaVersion: source.schemaVersion ?? 1,
|
|
614
|
+
delegationEnabled: source.delegationEnabled === true,
|
|
615
|
+
providers: (source.providers ?? []).map((provider) => {
|
|
616
|
+
const common = {
|
|
617
|
+
id: provider.id,
|
|
618
|
+
name: provider.name,
|
|
619
|
+
source: provider.source ?? "custom",
|
|
620
|
+
models: (provider.models ?? []).map((model) => ({ id: model.id, efforts: [...model.efforts ?? []] }))
|
|
621
|
+
};
|
|
622
|
+
if (common.source === "native") return common;
|
|
623
|
+
return {
|
|
624
|
+
...common,
|
|
625
|
+
protocol: provider.protocol,
|
|
626
|
+
baseUrl: provider.baseUrl,
|
|
627
|
+
credentialRef: provider.credentialRef === "" ? null : provider.credentialRef ?? null
|
|
628
|
+
};
|
|
629
|
+
}),
|
|
630
|
+
worker: { ...source.worker },
|
|
631
|
+
review: { ...source.review },
|
|
632
|
+
authorization: { ...source.authorization },
|
|
633
|
+
// Sent on every save, normalized to whole seconds: the host refuses anything
|
|
634
|
+
// else, and a document that omitted the block would store the defaults.
|
|
635
|
+
monitoring: monitoringOf(source),
|
|
636
|
+
projectOverrides: clone(source.projectOverrides ?? {}),
|
|
637
|
+
presets: (source.presets ?? []).map((preset) => ({
|
|
638
|
+
id: preset.id,
|
|
639
|
+
name: preset.name,
|
|
640
|
+
...preset.worker === null ? {} : { worker: { ...preset.worker } },
|
|
641
|
+
...preset.review === null ? {} : { review: { ...preset.review } }
|
|
642
|
+
})),
|
|
643
|
+
// Sent on every save only so the round-trip is faithful. It is inert: the host
|
|
644
|
+
// validates it as a retired value and no run consults it.
|
|
645
|
+
conversation: conversationOf(source)
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
function exportDocument(draft) {
|
|
649
|
+
return `${JSON.stringify(documentFromDraft(draft), null, 2)}
|
|
650
|
+
`;
|
|
651
|
+
}
|
|
652
|
+
function previewEffective(draft, projectPath = null) {
|
|
653
|
+
const applied = [];
|
|
654
|
+
let worker = { ...draft?.worker ?? {} };
|
|
655
|
+
let review = { ...draft?.review ?? {} };
|
|
656
|
+
const overrides = draft?.projectOverrides ?? {};
|
|
657
|
+
if (typeof projectPath === "string" && projectPath.trim() !== "") {
|
|
658
|
+
const wanted = projectPath.trim().replace(/[\\/]+$/, "");
|
|
659
|
+
const key = Object.keys(overrides).find((candidate) => candidate === wanted || candidate.toLowerCase() === wanted.toLowerCase());
|
|
660
|
+
if (key !== void 0) {
|
|
661
|
+
const block = overrides[key] ?? {};
|
|
662
|
+
if (block.worker !== void 0 && block.worker !== null) {
|
|
663
|
+
worker = { ...worker, ...block.worker };
|
|
664
|
+
applied.push("项目覆盖:执行设置");
|
|
665
|
+
}
|
|
666
|
+
if (block.review !== void 0 && block.review !== null) {
|
|
667
|
+
review = { ...review, ...block.review };
|
|
668
|
+
applied.push("项目覆盖:附加审查");
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
if (review.enabled !== true) review = { enabled: false, providerId: null, model: null, reasoningEffort: null };
|
|
673
|
+
return {
|
|
674
|
+
worker: { ...worker, providerRoute: worker.providerId ?? null },
|
|
675
|
+
review: { ...review, providerRoute: review.providerId ?? null },
|
|
676
|
+
// Global-only, like the host's own snapshot: no project or per-job layer can
|
|
677
|
+
// retime a task, so the preview reports the same pair the task would freeze.
|
|
678
|
+
monitoring: monitoringOf(draft),
|
|
679
|
+
applied
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
function precheckDraft(draft) {
|
|
683
|
+
const problems = [];
|
|
684
|
+
const providers = draft?.providers ?? [];
|
|
685
|
+
const ids = /* @__PURE__ */ new Set();
|
|
686
|
+
for (const provider of providers) {
|
|
687
|
+
if (!/^[a-z0-9][a-z0-9-]{1,38}[a-z0-9]$/.test(String(provider.id ?? ""))) {
|
|
688
|
+
problems.push(`提供方标识「${provider.id || "(空)"}」需为 3–40 位小写字母、数字或连字符`);
|
|
689
|
+
}
|
|
690
|
+
if (ids.has(provider.id)) problems.push(`提供方标识「${provider.id}」重复`);
|
|
691
|
+
ids.add(provider.id);
|
|
692
|
+
if (!String(provider.name ?? "").trim()) problems.push(`提供方「${provider.id}」缺少显示名称`);
|
|
693
|
+
if (provider.source !== "native" && !String(provider.baseUrl ?? "").trim()) {
|
|
694
|
+
problems.push(`提供方「${provider.id}」缺少接口地址`);
|
|
695
|
+
}
|
|
696
|
+
const modelIds = /* @__PURE__ */ new Set();
|
|
697
|
+
for (const model of provider.models ?? []) {
|
|
698
|
+
if (!String(model.id ?? "").trim()) problems.push(`提供方「${provider.id}」存在空的模型 ID`);
|
|
699
|
+
if (modelIds.has(model.id)) problems.push(`提供方「${provider.id}」的模型「${model.id}」重复`);
|
|
700
|
+
modelIds.add(model.id);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
for (const [role, block] of [["执行设置", draft?.worker], ["附加审查", draft?.review]]) {
|
|
704
|
+
if (role === "附加审查" && block?.enabled !== true) continue;
|
|
705
|
+
if (block?.providerId === null || block?.providerId === void 0) {
|
|
706
|
+
if (role === "执行设置" && providers.length > 0) problems.push("执行设置尚未选择提供方");
|
|
707
|
+
continue;
|
|
708
|
+
}
|
|
709
|
+
const provider = providers.find((entry) => entry.id === block.providerId);
|
|
710
|
+
if (provider === void 0) {
|
|
711
|
+
problems.push(`${role}选择了未配置的提供方「${block.providerId}」`);
|
|
712
|
+
continue;
|
|
713
|
+
}
|
|
714
|
+
const model = (provider.models ?? []).find((entry) => entry.id === block.model);
|
|
715
|
+
if (model === void 0) {
|
|
716
|
+
problems.push(`${role}的模型「${block.model ?? "(空)"}」不在提供方「${provider.id}」的模型列表中`);
|
|
717
|
+
} else if (block.reasoningEffort !== null && block.reasoningEffort !== void 0 && !(model.efforts ?? []).includes(block.reasoningEffort)) {
|
|
718
|
+
problems.push(`${role}的推理强度「${block.reasoningEffort}」不是模型「${model.id}」声明的能力`);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
const timeout = Number(draft?.worker?.timeoutSeconds);
|
|
722
|
+
if (!Number.isInteger(timeout) || timeout < LIMITS.timeoutSecondsMin || timeout > LIMITS.timeoutSecondsMax) {
|
|
723
|
+
problems.push(`超时需为 ${LIMITS.timeoutSecondsMin}–${LIMITS.timeoutSecondsMax} 秒之间的整数`);
|
|
724
|
+
}
|
|
725
|
+
const parallelism = Number(draft?.worker?.maxParallelism);
|
|
726
|
+
if (!Number.isInteger(parallelism) || parallelism < LIMITS.maxParallelismMin || parallelism > LIMITS.maxParallelismMax) {
|
|
727
|
+
problems.push(`最大并发需为 ${LIMITS.maxParallelismMin}–${LIMITS.maxParallelismMax} 之间的整数`);
|
|
728
|
+
}
|
|
729
|
+
const monitoring = monitoringOf(draft);
|
|
730
|
+
for (const [field, label] of [
|
|
731
|
+
["selfCheckSeconds", "程序自检间隔"],
|
|
732
|
+
["attentionSeconds", "提醒你的间隔"]
|
|
733
|
+
]) {
|
|
734
|
+
const value = monitoring[field];
|
|
735
|
+
const min = field === "selfCheckSeconds" ? LIMITS.selfCheckSecondsMin : LIMITS.attentionSecondsMin;
|
|
736
|
+
const max = field === "selfCheckSeconds" ? LIMITS.selfCheckSecondsMax : LIMITS.attentionSecondsMax;
|
|
737
|
+
if (!Number.isInteger(value) || value < min || value > max) {
|
|
738
|
+
problems.push(`${label}需为 ${min}–${max} 秒之间的整数`);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
if (Number.isInteger(monitoring.selfCheckSeconds) && Number.isInteger(monitoring.attentionSeconds) && monitoring.attentionSeconds <= monitoring.selfCheckSeconds) {
|
|
742
|
+
problems.push("提醒你的间隔必须大于程序自检间隔");
|
|
743
|
+
}
|
|
744
|
+
return problems;
|
|
745
|
+
}
|
|
746
|
+
function taskStateLabel(state) {
|
|
747
|
+
return TASK_STATE_LABELS[state] ?? String(state ?? "未知状态");
|
|
748
|
+
}
|
|
749
|
+
function isCancellable(state) {
|
|
750
|
+
return state === "pending" || state === "running";
|
|
751
|
+
}
|
|
752
|
+
function taskPhaseLabel(phase) {
|
|
753
|
+
if (typeof phase !== "string" || phase === "") return "—";
|
|
754
|
+
return TASK_PHASE_LABELS[phase] ?? phase;
|
|
755
|
+
}
|
|
756
|
+
function isAwaitingPermission(task) {
|
|
757
|
+
if (task?.permission?.waiting === true) return true;
|
|
758
|
+
return task?.phase === "awaiting-permission";
|
|
759
|
+
}
|
|
760
|
+
function pendingPermission(task) {
|
|
761
|
+
const pending = task?.permission?.pending ?? null;
|
|
762
|
+
return pending !== null && typeof pending === "object" ? pending : null;
|
|
763
|
+
}
|
|
764
|
+
function permissionSummary(task) {
|
|
765
|
+
const permission = task?.permission ?? null;
|
|
766
|
+
const waiting = isAwaitingPermission(task);
|
|
767
|
+
if (waiting) {
|
|
768
|
+
const pending = pendingPermission(task);
|
|
769
|
+
const tool = pending?.toolName ?? "未知工具";
|
|
770
|
+
const access = pending?.requestedAccess?.mode;
|
|
771
|
+
return {
|
|
772
|
+
waiting: true,
|
|
773
|
+
label: "等待本次调用授权决定",
|
|
774
|
+
note: access === null || access === void 0 ? `工作进程暂停在 ${tool} 这一次调用上,等待本机指挥官决定。任务仍在运行,未失败,也未完成。` : `工作进程暂停在 ${tool} 这一次调用上,请求把该次调用的沙箱权限提升到 ${access},等待本机指挥官决定。无论是否允许,会话的常规权限(workspace-write)保持不变。`,
|
|
775
|
+
detail: `请求编号 ${pending?.requestId ?? "—"} · 调用 ${pending?.callId ?? "—"}`
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
if (permission === null || permission === void 0) {
|
|
779
|
+
return { waiting: false, label: "未使用逐次授权桥", note: "本次任务未挂载逐次授权桥:工作进程的提权请求会被直接拒绝,不会等待。", detail: "" };
|
|
780
|
+
}
|
|
781
|
+
const evidence = Array.isArray(permission.evidence) ? permission.evidence : [];
|
|
782
|
+
if (evidence.length === 0) {
|
|
783
|
+
return { waiting: false, label: "本次任务尚无授权请求", note: "暂无。请求出现时,该次调用会暂停,并在这里显示。", detail: "" };
|
|
784
|
+
}
|
|
785
|
+
const last = evidence[evidence.length - 1];
|
|
786
|
+
const outcome = PERMISSION_OUTCOME_LABELS[last?.outcome] ?? last?.outcome ?? "未知结果";
|
|
787
|
+
return {
|
|
788
|
+
waiting: false,
|
|
789
|
+
label: "最近一次决定",
|
|
790
|
+
note: `最近一次调用授权请求:${outcome}。该决定只对那一次调用有效,不构成常规权限,也不会被后续调用复用。`,
|
|
791
|
+
detail: `请求编号 ${last?.requestId ?? "—"}(共 ${evidence.length} 条记录)`
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
function formatDuration(ms) {
|
|
795
|
+
if (typeof ms !== "number" || !Number.isFinite(ms) || ms < 0) return "—";
|
|
796
|
+
const totalSeconds = Math.floor(ms / 1e3);
|
|
797
|
+
if (totalSeconds < 60) return `${totalSeconds} 秒`;
|
|
798
|
+
const minutes = Math.floor(totalSeconds / 60);
|
|
799
|
+
if (minutes < 60) return `${minutes} 分 ${totalSeconds % 60} 秒`;
|
|
800
|
+
const hours = Math.floor(minutes / 60);
|
|
801
|
+
return `${hours} 小时 ${minutes % 60} 分`;
|
|
802
|
+
}
|
|
803
|
+
function taskActivity(task) {
|
|
804
|
+
const activity = task?.activity;
|
|
805
|
+
if (activity === null || typeof activity !== "object" || Array.isArray(activity)) return null;
|
|
806
|
+
const tool = activity.currentTool;
|
|
807
|
+
const selfCheck = activity.selfCheck;
|
|
808
|
+
return {
|
|
809
|
+
lastActivityAt: Number.isFinite(activity.lastActivityAt) ? activity.lastActivityAt : null,
|
|
810
|
+
idleForMs: Number.isFinite(activity.idleForMs) ? activity.idleForMs : null,
|
|
811
|
+
waitingOn: activity.waitingOn === "tool" ? "tool" : "idle",
|
|
812
|
+
currentTool: tool === null || typeof tool !== "object" ? null : {
|
|
813
|
+
name: typeof tool.name === "string" && tool.name !== "" ? tool.name : "未知工具",
|
|
814
|
+
callId: typeof tool.callId === "string" ? tool.callId : null,
|
|
815
|
+
startedAt: Number.isFinite(tool.startedAt) ? tool.startedAt : null,
|
|
816
|
+
elapsedMs: Number.isFinite(tool.elapsedMs) ? tool.elapsedMs : null
|
|
817
|
+
},
|
|
818
|
+
lastTool: activity.lastTool !== null && typeof activity.lastTool === "object" ? { name: activity.lastTool.name ?? null, durationMs: Number.isFinite(activity.lastTool.durationMs) ? activity.lastTool.durationMs : null } : null,
|
|
819
|
+
events: Number.isFinite(activity.events) ? activity.events : null,
|
|
820
|
+
activityEvents: Number.isFinite(activity.activityEvents) ? activity.activityEvents : null,
|
|
821
|
+
toolCallsStarted: Number.isFinite(activity.toolCallsStarted) ? activity.toolCallsStarted : null,
|
|
822
|
+
toolCallsFinished: Number.isFinite(activity.toolCallsFinished) ? activity.toolCallsFinished : null,
|
|
823
|
+
selfCheckSeconds: Number.isFinite(activity.selfCheckSeconds) ? activity.selfCheckSeconds : null,
|
|
824
|
+
attentionSeconds: Number.isFinite(activity.attentionSeconds) ? activity.attentionSeconds : null,
|
|
825
|
+
selfCheck: selfCheck === null || typeof selfCheck !== "object" ? null : {
|
|
826
|
+
episode: Number.isFinite(selfCheck.episode) ? selfCheck.episode : null,
|
|
827
|
+
checkedAt: Number.isFinite(selfCheck.checkedAt) ? selfCheck.checkedAt : null,
|
|
828
|
+
verdict: typeof selfCheck.verdict === "string" ? selfCheck.verdict : null
|
|
829
|
+
},
|
|
830
|
+
finalizedAt: Number.isFinite(activity.finalizedAt) ? activity.finalizedAt : null,
|
|
831
|
+
interrupted: activity.interrupted === true
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
function taskProgress(task) {
|
|
835
|
+
const activity = taskActivity(task);
|
|
836
|
+
const phase = taskPhaseLabel(task?.phase);
|
|
837
|
+
if (activity === null) {
|
|
838
|
+
return {
|
|
839
|
+
available: false,
|
|
840
|
+
headline: `${phase} · 未采集到进展信息`,
|
|
841
|
+
detail: "这条记录没有进展信息(可能是旧版本写入的记录,或任务尚未进入执行)。没有信息不等于没有进展,也不代表失败。",
|
|
842
|
+
tone: "off"
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
const settled = typeof activity.finalizedAt === "number";
|
|
846
|
+
const idle = formatDuration(activity.idleForMs);
|
|
847
|
+
const parts = [phase, `距上次进展 ${idle}`];
|
|
848
|
+
if (activity.currentTool !== null) {
|
|
849
|
+
parts.push(`正在运行 ${activity.currentTool.name}(已 ${formatDuration(activity.currentTool.elapsedMs)})`);
|
|
850
|
+
}
|
|
851
|
+
const headline = parts.join(" · ");
|
|
852
|
+
const detailParts = [];
|
|
853
|
+
if (activity.currentTool !== null) {
|
|
854
|
+
detailParts.push("有一个工具调用正在运行;它本身耗时较长不算失败,也不会让插件结束任务。");
|
|
855
|
+
}
|
|
856
|
+
if (activity.selfCheck !== null && activity.selfCheck.verdict !== null) {
|
|
857
|
+
detailParts.push(`程序自检结论:${SELF_CHECK_LABELS[activity.selfCheck.verdict] ?? activity.selfCheck.verdict}`);
|
|
858
|
+
}
|
|
859
|
+
if (settled) {
|
|
860
|
+
detailParts.push("任务已结束,这些时间不再变化。");
|
|
861
|
+
} else if (task?.state === "interrupted") {
|
|
862
|
+
detailParts.push("这条记录来自一次进程重启:任务已经中断,不会继续执行,也不会再有新的进展。");
|
|
863
|
+
} else if (activity.attentionSeconds !== null) {
|
|
864
|
+
detailParts.push(`超过 ${formatDuration(activity.attentionSeconds * 1e3)} 没有新进展时会提醒你;提醒只是提示,不会自动判失败。`);
|
|
865
|
+
}
|
|
866
|
+
if (activity.activityEvents !== null && activity.events !== null) {
|
|
867
|
+
detailParts.push(`已记录 ${activity.events} 个执行事件,其中 ${activity.activityEvents} 个是真正的进展。`);
|
|
868
|
+
}
|
|
869
|
+
return {
|
|
870
|
+
available: true,
|
|
871
|
+
headline,
|
|
872
|
+
detail: detailParts.join(" "),
|
|
873
|
+
tone: activity.currentTool !== null ? "on" : settled ? "off" : "on"
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
var CODEX_MCP_DRIFT_LABELS = Object.freeze({
|
|
877
|
+
tool_timeout_sec: "缺少工具超时(部分客户端可能因此提前中断长时间等待)",
|
|
878
|
+
args: "入口脚本路径已变化(插件已升级或移动)",
|
|
879
|
+
command: "command 仍是旧版写下的路径",
|
|
880
|
+
env: "发现文件的环境变量与当前不一致"
|
|
881
|
+
});
|
|
882
|
+
function codexMcpDriftText(mcp) {
|
|
883
|
+
const drift = Array.isArray(mcp?.drift) ? mcp.drift : [];
|
|
884
|
+
if (drift.length === 0) return "托管 MCP 条目需要更新";
|
|
885
|
+
return drift.map((key) => CODEX_MCP_DRIFT_LABELS[key] ?? key).join(";");
|
|
886
|
+
}
|
|
887
|
+
function isLiveTask(task) {
|
|
888
|
+
return task?.state === "pending" || task?.state === "running";
|
|
889
|
+
}
|
|
890
|
+
function hasLiveTasks(tasks) {
|
|
891
|
+
return Array.isArray(tasks) && tasks.some(isLiveTask);
|
|
892
|
+
}
|
|
893
|
+
function precheckMonitoring(monitoring) {
|
|
894
|
+
const problems = [];
|
|
895
|
+
const self = monitoring?.selfCheckSeconds;
|
|
896
|
+
const attention = monitoring?.attentionSeconds;
|
|
897
|
+
if (!Number.isInteger(self) || self < LIMITS.selfCheckSecondsMin || self > LIMITS.selfCheckSecondsMax) {
|
|
898
|
+
problems.push(`程序自检间隔需为 ${LIMITS.selfCheckSecondsMin}–${LIMITS.selfCheckSecondsMax} 秒之间的整数`);
|
|
899
|
+
}
|
|
900
|
+
if (!Number.isInteger(attention) || attention < LIMITS.attentionSecondsMin || attention > LIMITS.attentionSecondsMax) {
|
|
901
|
+
problems.push(`提醒你的间隔需为 ${LIMITS.attentionSecondsMin}–${LIMITS.attentionSecondsMax} 秒之间的整数`);
|
|
902
|
+
}
|
|
903
|
+
if (Number.isInteger(self) && Number.isInteger(attention) && attention <= self) {
|
|
904
|
+
problems.push("提醒你的间隔必须大于程序自检间隔");
|
|
905
|
+
}
|
|
906
|
+
return problems;
|
|
907
|
+
}
|
|
908
|
+
function taskOutcome(task) {
|
|
909
|
+
const state = String(task?.state ?? "");
|
|
910
|
+
const accepted = task?.hostAcceptance !== null && task?.hostAcceptance !== void 0;
|
|
911
|
+
const executed = state === "awaiting-host-review" || accepted === true;
|
|
912
|
+
const note = state === "awaiting-host-review" ? "执行已完成,等待宿主(Codex)审查;插件不会自行验收。" : accepted === true ? "宿主已记录验收结论。" : state === "failed" ? "执行失败;错误详情见下方证据。" : state === "cancelled" ? "任务已取消,未产生验收结论。" : "任务尚未产生结果。";
|
|
913
|
+
return { label: taskStateLabel(state), executed, accepted, note };
|
|
914
|
+
}
|
|
915
|
+
function changedFiles(task) {
|
|
916
|
+
const candidates = [task?.diff?.files, task?.diff?.changedFiles, task?.changedFiles];
|
|
917
|
+
for (const candidate of candidates) {
|
|
918
|
+
if (!Array.isArray(candidate)) continue;
|
|
919
|
+
const files = [];
|
|
920
|
+
for (const entry of candidate) {
|
|
921
|
+
if (typeof entry === "string") {
|
|
922
|
+
if (entry !== "") files.push(entry);
|
|
923
|
+
continue;
|
|
924
|
+
}
|
|
925
|
+
const path = entry?.path ?? entry?.file;
|
|
926
|
+
if (typeof path !== "string" || path === "") continue;
|
|
927
|
+
const code = typeof entry?.status === "string" && entry.status !== "" ? entry.status : typeof entry?.code === "string" && entry.code !== "" ? entry.code : null;
|
|
928
|
+
const from = typeof entry?.from === "string" && entry.from !== "" ? entry.from : null;
|
|
929
|
+
const label = from === null ? path : `${from} → ${path}`;
|
|
930
|
+
const mark = entry?.sensitive === true ? "(内容已扣留)" : "";
|
|
931
|
+
files.push(code === null ? `${label}${mark}` : `${code} ${label}${mark}`);
|
|
932
|
+
}
|
|
933
|
+
if (files.length > 0) return files;
|
|
934
|
+
}
|
|
935
|
+
return null;
|
|
936
|
+
}
|
|
937
|
+
function boundedText(value, max = 2e4) {
|
|
938
|
+
if (value === null || value === void 0) return "";
|
|
939
|
+
const text = typeof value === "string" ? value : JSON.stringify(value, null, 2);
|
|
940
|
+
return text.length > max ? `${text.slice(0, max)}
|
|
941
|
+
…(已截断)` : text;
|
|
942
|
+
}
|
|
943
|
+
function formatTime(value) {
|
|
944
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return "—";
|
|
945
|
+
try {
|
|
946
|
+
return new Date(value).toLocaleString("zh-CN", { hour12: false });
|
|
947
|
+
} catch {
|
|
948
|
+
return new Date(value).toISOString();
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
function describeError(error) {
|
|
952
|
+
const code = typeof error?.code === "string" ? error.code : "";
|
|
953
|
+
const messages = {
|
|
954
|
+
USER_PLANE_UNREACHABLE: "无法连接宿主设置接口:请确认 DSH 网页仍在运行,并刷新页面后重试。",
|
|
955
|
+
USER_PLANE_MALFORMED: "宿主返回了无法识别的内容。",
|
|
956
|
+
SETTINGS_MISSING: "请求中没有设置文档。",
|
|
957
|
+
SETTINGS_INVALID: "设置内容不合法,已保留你的草稿。",
|
|
958
|
+
SETTINGS_NO_PROVIDERS: "至少需要配置一个提供方。",
|
|
959
|
+
SETTINGS_SCHEMA_UNSUPPORTED: "设置文档版本不被当前插件支持。",
|
|
960
|
+
PROVIDER_ID_INVALID: "提供方标识格式不合法。",
|
|
961
|
+
PROVIDER_NAME_INVALID: "提供方显示名称不合法。",
|
|
962
|
+
PROVIDER_BASE_URL_INVALID: "接口地址不合法(需为 http/https,且不得包含账号密码、查询串或片段)。",
|
|
963
|
+
PROVIDER_CREDENTIAL_REF_INVALID: "凭据引用名不合法(需为环境变量风格名称)。",
|
|
964
|
+
PROVIDER_PROTOCOL_UNSUPPORTED: "该协议当前不受支持。",
|
|
965
|
+
PROVIDER_SECRET_IN_SETTINGS: "设置文档中不能包含密钥;请使用单独的凭据输入框。",
|
|
966
|
+
PROVIDER_DUPLICATE: "提供方标识重复。",
|
|
967
|
+
PROVIDER_IN_USE: "该提供方仍被当前设置引用,无法删除。",
|
|
968
|
+
MODEL_INVALID: "模型条目不合法。",
|
|
969
|
+
MODEL_DUPLICATE: "模型 ID 重复。",
|
|
970
|
+
MODEL_EFFORTS_INVALID: "模型的推理强度声明不合法。",
|
|
971
|
+
SELECTION_PROVIDER_REQUIRED: "请选择提供方。",
|
|
972
|
+
SELECTION_PROVIDER_UNKNOWN: "所选提供方未配置。",
|
|
973
|
+
SELECTION_MODEL_REQUIRED: "请选择模型。",
|
|
974
|
+
SELECTION_MODEL_UNKNOWN: "所选模型不在该提供方的模型列表中。",
|
|
975
|
+
SELECTION_EFFORT_UNKNOWN: "推理强度取值不存在。",
|
|
976
|
+
SELECTION_EFFORT_UNSUPPORTED: "该模型未声明此推理强度。",
|
|
977
|
+
WORKER_TIMEOUT_INVALID: "超时时间超出允许范围。",
|
|
978
|
+
WORKER_PARALLELISM_INVALID: "最大并发超出允许范围。",
|
|
979
|
+
WORKER_ISOLATION_INVALID: "工作区隔离方式不受支持。",
|
|
980
|
+
AUTHORIZATION_INVALID: "授权有效期取值不合法。",
|
|
981
|
+
PRESET_INVALID: "预设内容不合法。",
|
|
982
|
+
PRESET_DUPLICATE: "预设标识重复。",
|
|
983
|
+
PROJECT_OVERRIDE_INVALID: "项目覆盖内容不合法。",
|
|
984
|
+
PROJECT_OVERRIDE_DUPLICATE: "同一项目存在重复覆盖。",
|
|
985
|
+
CONNECTION_ID_REQUIRED: "缺少连接标识。",
|
|
986
|
+
CONNECTION_UNKNOWN: "该连接不存在或已失效。",
|
|
987
|
+
CONNECTION_LIMIT: "连接数量已达上限,请先撤销不用的连接。",
|
|
988
|
+
GRANT_ID_REQUIRED: "缺少授权标识。",
|
|
989
|
+
GRANT_UNKNOWN: "该授权不存在。",
|
|
990
|
+
GRANT_KIND_INVALID: "授权范围不合法。",
|
|
991
|
+
GRANT_TTL_INVALID: "授权有效期不合法。",
|
|
992
|
+
GRANT_LIMIT: "授权数量已达上限。",
|
|
993
|
+
GRANT_MISMATCH: "该授权不适用于当前连接或工作区。",
|
|
994
|
+
JOB_TASK_NOT_FOUND: "任务不存在或已被清理。",
|
|
995
|
+
PROVIDER_ID_REQUIRED: "请选择一个提供方。",
|
|
996
|
+
PROVIDER_UNKNOWN: "该提供方不在当前设置中,请先保存配置文件。",
|
|
997
|
+
PROVIDER_CREDENTIAL_REF_MISSING: "该提供方未声明凭据引用名,无法保存密钥;请先在提供方设置中填写引用名。",
|
|
998
|
+
CREDENTIAL_EMPTY: "请先输入密钥内容。",
|
|
999
|
+
CREDENTIAL_VALUE_REQUIRED: "请先输入密钥内容;如需删除请使用「清除密钥」。",
|
|
1000
|
+
CREDENTIAL_VALUE_TOO_LARGE: "密钥内容超出长度上限。",
|
|
1001
|
+
CREDENTIAL_OPERATION_FAILED: "宿主凭据服务拒绝了本次操作。",
|
|
1002
|
+
CREDENTIAL_READ_ONLY: "该凭据引用为只读(由外部环境提供),无法在此修改。",
|
|
1003
|
+
CREDENTIAL_REF_INVALID: "凭据引用名不合法。",
|
|
1004
|
+
CREDENTIAL_SEAM_UNAVAILABLE: "当前宿主尚未提供凭据写入接口,密钥无法保存。",
|
|
1005
|
+
ROUTING_PROVIDER_NOT_REGISTERED: "该提供方尚未注册到宿主模型路由中。",
|
|
1006
|
+
ROUTING_MODEL_UNRESOLVED: "该模型无法在宿主模型路由中解析。",
|
|
1007
|
+
ROUTING_EFFORT_UNSUPPORTED: "该模型不支持所选推理强度。",
|
|
1008
|
+
ROUTING_SERVICE_UNAVAILABLE: "宿主模型服务当前不可用。",
|
|
1009
|
+
// Remote model discovery: each code is a different fix, so each gets its own
|
|
1010
|
+
// sentence. None of them can quote the endpoint, the credential or the body.
|
|
1011
|
+
DISCOVERY_PROVIDER_UNKNOWN: "未找到该提供方配置。",
|
|
1012
|
+
DISCOVERY_BASE_URL_INVALID: "接口地址不可用于获取模型列表(需为 http/https,且不含账号密码、查询串或片段)。",
|
|
1013
|
+
DISCOVERY_CREDENTIAL_REF_MISSING: "该提供方未设置凭据引用名,无法向提供方取模型;请先填写引用名并保存。",
|
|
1014
|
+
DISCOVERY_CREDENTIAL_SEAM_UNAVAILABLE: "当前宿主未提供凭据服务,无法带上密钥向提供方取模型。",
|
|
1015
|
+
DISCOVERY_CREDENTIAL_UNAVAILABLE: "宿主凭据服务无法读取该引用名对应的密钥。",
|
|
1016
|
+
DISCOVERY_CREDENTIAL_NOT_CONFIGURED: "该凭据引用名尚未保存密钥,请先在「密钥」处保存。",
|
|
1017
|
+
DISCOVERY_CREDENTIAL_EMPTY: "该凭据引用名的密钥内容为空,请重新保存。",
|
|
1018
|
+
DISCOVERY_AUTH_REFUSED: "提供方拒绝了该密钥(401/403):请确认密钥是否有效、是否属于该接口地址。",
|
|
1019
|
+
DISCOVERY_HTTP_ERROR: "提供方返回了错误状态码;详情见上方诊断。",
|
|
1020
|
+
DISCOVERY_REDIRECT_REFUSED: "提供方返回了重定向,为保护密钥没有跟随;请直接填写最终接口地址。",
|
|
1021
|
+
DISCOVERY_NETWORK_FAILED: "无法连接提供方接口地址:请检查地址、端口与网络。",
|
|
1022
|
+
DISCOVERY_TIMEOUT: "提供方在规定时间内没有响应,请稍后重试。",
|
|
1023
|
+
DISCOVERY_CANCELLED: "获取模型的请求已被取消。",
|
|
1024
|
+
DISCOVERY_MALFORMED_RESPONSE: '提供方返回的内容不是可识别的模型列表(需要 OpenAI 兼容的 {"data":[{"id":...}]})。',
|
|
1025
|
+
DISCOVERY_BODY_TOO_LARGE: "提供方返回的内容超过大小上限,已中止读取。",
|
|
1026
|
+
USER_PLANE_METHOD_NOT_ALLOWED: "该请求方法不被允许。"
|
|
1027
|
+
};
|
|
1028
|
+
const known = messages[code];
|
|
1029
|
+
if (known !== void 0) return `${known}(${code})`;
|
|
1030
|
+
if (code.startsWith("HTTP_")) return `宿主返回 ${code.slice(5)},请刷新后重试。`;
|
|
1031
|
+
const detail = typeof error?.message === "string" && error.message !== "" ? error.message.slice(0, 200) : "未知错误";
|
|
1032
|
+
return code === "" ? detail : `${detail}(${code})`;
|
|
1033
|
+
}
|
|
1034
|
+
function createStore(options = {}) {
|
|
1035
|
+
const api = options.api ?? createApi();
|
|
1036
|
+
const now = typeof options.now === "function" ? options.now : () => Date.now();
|
|
1037
|
+
let state = {
|
|
1038
|
+
revision: 0,
|
|
1039
|
+
loading: {},
|
|
1040
|
+
notices: [],
|
|
1041
|
+
status: null,
|
|
1042
|
+
nativeProviders: [],
|
|
1043
|
+
nativeProvidersError: null,
|
|
1044
|
+
settings: null,
|
|
1045
|
+
draft: null,
|
|
1046
|
+
dirty: false,
|
|
1047
|
+
catalog: null,
|
|
1048
|
+
catalogError: null,
|
|
1049
|
+
modelCatalog: {},
|
|
1050
|
+
connections: [],
|
|
1051
|
+
selectedConnectionId: null,
|
|
1052
|
+
grants: [],
|
|
1053
|
+
tasks: [],
|
|
1054
|
+
taskDetail: null,
|
|
1055
|
+
token: null,
|
|
1056
|
+
tokenConnectionId: null,
|
|
1057
|
+
credentials: {},
|
|
1058
|
+
connectivity: {},
|
|
1059
|
+
// Codex integration. `codex` holds the last served status document,
|
|
1060
|
+
// `codexError` its last refusal, `codexOutcome` the last action's result. None
|
|
1061
|
+
// of them is a credential: the status document is a file/config diagnosis.
|
|
1062
|
+
codex: null,
|
|
1063
|
+
codexError: null,
|
|
1064
|
+
codexOutcome: null
|
|
1065
|
+
};
|
|
1066
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
1067
|
+
let disposed = false;
|
|
1068
|
+
function emit() {
|
|
1069
|
+
for (const listener of [...listeners]) {
|
|
1070
|
+
try {
|
|
1071
|
+
listener();
|
|
1072
|
+
} catch {
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
function patch(next) {
|
|
1077
|
+
if (disposed) return;
|
|
1078
|
+
state = { ...state, ...next, revision: state.revision + 1 };
|
|
1079
|
+
emit();
|
|
1080
|
+
}
|
|
1081
|
+
function notify(level, text) {
|
|
1082
|
+
const id = state.revision + 1 + Math.random();
|
|
1083
|
+
patch({ notices: [...state.notices, { id, level, text }].slice(-6) });
|
|
1084
|
+
return id;
|
|
1085
|
+
}
|
|
1086
|
+
function dismissNotice(id) {
|
|
1087
|
+
patch({ notices: state.notices.filter((notice) => notice.id !== id) });
|
|
1088
|
+
}
|
|
1089
|
+
async function track(key, work) {
|
|
1090
|
+
patch({ loading: { ...state.loading, [key]: true } });
|
|
1091
|
+
try {
|
|
1092
|
+
return await work();
|
|
1093
|
+
} finally {
|
|
1094
|
+
if (!disposed) patch({ loading: { ...state.loading, [key]: false } });
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
const store = {
|
|
1098
|
+
subscribe(listener) {
|
|
1099
|
+
listeners.add(listener);
|
|
1100
|
+
return () => listeners.delete(listener);
|
|
1101
|
+
},
|
|
1102
|
+
getSnapshot() {
|
|
1103
|
+
return state;
|
|
1104
|
+
},
|
|
1105
|
+
notify,
|
|
1106
|
+
dismissNotice,
|
|
1107
|
+
/** Read the delegation posture. */
|
|
1108
|
+
async refreshStatus() {
|
|
1109
|
+
return await track("status", async () => {
|
|
1110
|
+
try {
|
|
1111
|
+
const body = await api.getStatus();
|
|
1112
|
+
patch({ status: body });
|
|
1113
|
+
return { ok: true, body };
|
|
1114
|
+
} catch (error) {
|
|
1115
|
+
notify("error", describeError(error));
|
|
1116
|
+
return { ok: false, error };
|
|
1117
|
+
}
|
|
1118
|
+
});
|
|
1119
|
+
},
|
|
1120
|
+
/** Load configured provider connections from the native DSH registry. */
|
|
1121
|
+
async loadNativeProviders() {
|
|
1122
|
+
return await track("nativeProviders", async () => {
|
|
1123
|
+
try {
|
|
1124
|
+
const body = await api.getNativeProviders();
|
|
1125
|
+
patch({ nativeProviders: Array.isArray(body.providers) ? body.providers : [], nativeProvidersError: body.error ?? null });
|
|
1126
|
+
return { ok: true, providers: body.providers ?? [], error: body.error ?? null };
|
|
1127
|
+
} catch (error) {
|
|
1128
|
+
patch({ nativeProvidersError: describeError(error) });
|
|
1129
|
+
notify("error", describeError(error));
|
|
1130
|
+
return { ok: false, error };
|
|
1131
|
+
}
|
|
1132
|
+
});
|
|
1133
|
+
},
|
|
1134
|
+
/** Persist and immediately apply the single authorization switch. */
|
|
1135
|
+
async setDelegationEnabled(enabled) {
|
|
1136
|
+
if (typeof enabled !== "boolean") return { ok: false };
|
|
1137
|
+
return await track("delegationSwitch", async () => {
|
|
1138
|
+
try {
|
|
1139
|
+
const body = await api.setDelegationEnabled(enabled);
|
|
1140
|
+
const settings = state.settings === null ? null : { ...state.settings, delegationEnabled: enabled };
|
|
1141
|
+
const draft = state.draft === null ? null : { ...state.draft, delegationEnabled: enabled };
|
|
1142
|
+
patch({ status: { ...state.status ?? {}, delegation: body.delegation }, settings, draft });
|
|
1143
|
+
notify("success", enabled ? "本机 DSH 委派已开启。" : "本机 DSH 委派已关闭,运行中的任务已请求停止。");
|
|
1144
|
+
return { ok: true, delegation: body.delegation };
|
|
1145
|
+
} catch (error) {
|
|
1146
|
+
notify("error", describeError(error));
|
|
1147
|
+
return { ok: false, error };
|
|
1148
|
+
}
|
|
1149
|
+
});
|
|
1150
|
+
},
|
|
1151
|
+
/** Read the committed document (and reset the draft unless it is dirty). */
|
|
1152
|
+
async loadSettings() {
|
|
1153
|
+
return await track("settings", async () => {
|
|
1154
|
+
try {
|
|
1155
|
+
const body = await api.getSettings();
|
|
1156
|
+
patch({
|
|
1157
|
+
settings: body.settings ?? null,
|
|
1158
|
+
draft: state.dirty && state.draft !== null ? state.draft : draftFromSettings(body.settings),
|
|
1159
|
+
...state.dirty && state.draft !== null ? {} : { dirty: false }
|
|
1160
|
+
});
|
|
1161
|
+
return { ok: true, settings: body.settings ?? null };
|
|
1162
|
+
} catch (error) {
|
|
1163
|
+
notify("error", describeError(error));
|
|
1164
|
+
return { ok: false, error };
|
|
1165
|
+
}
|
|
1166
|
+
});
|
|
1167
|
+
},
|
|
1168
|
+
/** Read the served catalog (models, effort capabilities, effective config). */
|
|
1169
|
+
async loadCatalog(projectPath = null) {
|
|
1170
|
+
return await track("catalog", async () => {
|
|
1171
|
+
try {
|
|
1172
|
+
const body = await api.getCatalog(projectPath === null ? {} : { projectPath });
|
|
1173
|
+
patch({ catalog: body, catalogError: null });
|
|
1174
|
+
return { ok: true, catalog: body };
|
|
1175
|
+
} catch (error) {
|
|
1176
|
+
patch({ catalogError: { code: error?.code ?? "", text: describeError(error) } });
|
|
1177
|
+
return { ok: false, error };
|
|
1178
|
+
}
|
|
1179
|
+
});
|
|
1180
|
+
},
|
|
1181
|
+
/** Read the connection list. */
|
|
1182
|
+
async loadConnections() {
|
|
1183
|
+
return await track("connections", async () => {
|
|
1184
|
+
try {
|
|
1185
|
+
const body = await api.listConnections();
|
|
1186
|
+
const connections = Array.isArray(body.connections) ? body.connections : [];
|
|
1187
|
+
const live = connections.filter((entry) => entry.revoked !== true);
|
|
1188
|
+
const selected = connections.some((entry) => entry.connectionId === state.selectedConnectionId && entry.revoked !== true) ? state.selectedConnectionId : live[0]?.connectionId ?? null;
|
|
1189
|
+
patch({ connections, selectedConnectionId: selected });
|
|
1190
|
+
if (selected !== null && selected !== state.selectedConnectionId) await store.loadGrants(selected);
|
|
1191
|
+
return { ok: true, connections };
|
|
1192
|
+
} catch (error) {
|
|
1193
|
+
notify("error", describeError(error));
|
|
1194
|
+
return { ok: false, error };
|
|
1195
|
+
}
|
|
1196
|
+
});
|
|
1197
|
+
},
|
|
1198
|
+
/**
|
|
1199
|
+
* Issue a connection. The token is kept in memory, tied to its connection id.
|
|
1200
|
+
* @param {string} label - display label.
|
|
1201
|
+
*/
|
|
1202
|
+
async issueConnection(label) {
|
|
1203
|
+
return await track("issueConnection", async () => {
|
|
1204
|
+
try {
|
|
1205
|
+
const body = await api.issueConnection(String(label ?? "").trim() || "codex");
|
|
1206
|
+
patch({
|
|
1207
|
+
token: typeof body.token === "string" ? body.token : null,
|
|
1208
|
+
tokenConnectionId: body.connection?.connectionId ?? null,
|
|
1209
|
+
selectedConnectionId: body.connection?.connectionId ?? state.selectedConnectionId
|
|
1210
|
+
});
|
|
1211
|
+
await store.loadConnections();
|
|
1212
|
+
notify("success", "连接已签发。授权令牌只显示这一次,请立即复制到 MCP 宿主配置。");
|
|
1213
|
+
return { ok: true, connection: body.connection, token: body.token };
|
|
1214
|
+
} catch (error) {
|
|
1215
|
+
notify("error", describeError(error));
|
|
1216
|
+
return { ok: false, error };
|
|
1217
|
+
}
|
|
1218
|
+
});
|
|
1219
|
+
},
|
|
1220
|
+
/** Drop the one-time token from memory. */
|
|
1221
|
+
clearToken() {
|
|
1222
|
+
patch({ token: null, tokenConnectionId: null });
|
|
1223
|
+
},
|
|
1224
|
+
/**
|
|
1225
|
+
* Revoke one connection (and every grant it holds).
|
|
1226
|
+
* @param {string} connectionId - server-issued identity.
|
|
1227
|
+
*/
|
|
1228
|
+
async revokeConnection(connectionId) {
|
|
1229
|
+
return await track("revokeConnection", async () => {
|
|
1230
|
+
try {
|
|
1231
|
+
const body = await api.revokeConnection(connectionId);
|
|
1232
|
+
if (state.tokenConnectionId === connectionId) patch({ token: null, tokenConnectionId: null });
|
|
1233
|
+
await store.loadConnections();
|
|
1234
|
+
await store.refreshStatus();
|
|
1235
|
+
notify("success", `已撤销该连接及其授权(${body.grantsRevoked ?? 0} 条授权)。`);
|
|
1236
|
+
return { ok: true, grantsRevoked: body.grantsRevoked ?? 0 };
|
|
1237
|
+
} catch (error) {
|
|
1238
|
+
notify("error", describeError(error));
|
|
1239
|
+
return { ok: false, error };
|
|
1240
|
+
}
|
|
1241
|
+
});
|
|
1242
|
+
},
|
|
1243
|
+
/** Revoke every grant and connection ("stop everything now"). */
|
|
1244
|
+
async revokeAll() {
|
|
1245
|
+
return await track("revokeAll", async () => {
|
|
1246
|
+
try {
|
|
1247
|
+
const body = await api.revokeAll();
|
|
1248
|
+
patch({ token: null, tokenConnectionId: null, grants: [] });
|
|
1249
|
+
await store.loadConnections();
|
|
1250
|
+
await store.refreshStatus();
|
|
1251
|
+
notify("success", `已撤销全部授权与连接(${body.grantsRevoked ?? 0} 条授权)。当前委托已关闭。`);
|
|
1252
|
+
return { ok: true, grantsRevoked: body.grantsRevoked ?? 0 };
|
|
1253
|
+
} catch (error) {
|
|
1254
|
+
notify("error", describeError(error));
|
|
1255
|
+
return { ok: false, error };
|
|
1256
|
+
}
|
|
1257
|
+
});
|
|
1258
|
+
},
|
|
1259
|
+
/**
|
|
1260
|
+
* Select a server-issued connection identity and load its grants.
|
|
1261
|
+
* @param {string} connectionId - connection id from the served list.
|
|
1262
|
+
*/
|
|
1263
|
+
async selectConnection(connectionId) {
|
|
1264
|
+
patch({ selectedConnectionId: connectionId, grants: [] });
|
|
1265
|
+
return await store.loadGrants(connectionId);
|
|
1266
|
+
},
|
|
1267
|
+
/**
|
|
1268
|
+
* Load the grants of one connection.
|
|
1269
|
+
* @param {string} connectionId - connection id.
|
|
1270
|
+
*/
|
|
1271
|
+
async loadGrants(connectionId) {
|
|
1272
|
+
return await track("grants", async () => {
|
|
1273
|
+
try {
|
|
1274
|
+
const body = await api.listGrants(connectionId);
|
|
1275
|
+
patch({ grants: Array.isArray(body.grants) ? body.grants : [] });
|
|
1276
|
+
return { ok: true, grants: body.grants ?? [] };
|
|
1277
|
+
} catch (error) {
|
|
1278
|
+
notify("error", describeError(error));
|
|
1279
|
+
return { ok: false, error };
|
|
1280
|
+
}
|
|
1281
|
+
});
|
|
1282
|
+
},
|
|
1283
|
+
/**
|
|
1284
|
+
* Issue one grant for the selected connection.
|
|
1285
|
+
* @param {object} form - `{ connectionId, kind, workspacePath, ttlSeconds }`.
|
|
1286
|
+
*/
|
|
1287
|
+
async issueGrant(form) {
|
|
1288
|
+
const connectionId = form?.connectionId ?? state.selectedConnectionId;
|
|
1289
|
+
const workspacePath = String(form?.workspacePath ?? "").trim();
|
|
1290
|
+
const kind = form?.kind === "session" ? "session" : "task";
|
|
1291
|
+
if (typeof connectionId !== "string" || connectionId === "") {
|
|
1292
|
+
notify("error", "请先签发并选择一个连接,授权只能绑定到宿主签发的连接身份。");
|
|
1293
|
+
return { ok: false };
|
|
1294
|
+
}
|
|
1295
|
+
if (workspacePath === "") {
|
|
1296
|
+
notify("error", "请填写授权的绝对工作区路径。");
|
|
1297
|
+
return { ok: false };
|
|
1298
|
+
}
|
|
1299
|
+
return await track("issueGrant", async () => {
|
|
1300
|
+
try {
|
|
1301
|
+
const body = {
|
|
1302
|
+
connectionId,
|
|
1303
|
+
kind,
|
|
1304
|
+
workspacePath
|
|
1305
|
+
};
|
|
1306
|
+
const ttl = Number(form?.ttlSeconds);
|
|
1307
|
+
if (Number.isInteger(ttl) && ttl > 0) body.ttlSeconds = ttl;
|
|
1308
|
+
const answer = await api.issueGrant(body);
|
|
1309
|
+
await store.loadGrants(connectionId);
|
|
1310
|
+
await store.refreshStatus();
|
|
1311
|
+
notify("success", kind === "task" ? "已签发单次任务授权(用掉即失效)。" : "已签发本连接会话授权(限时、可撤销)。");
|
|
1312
|
+
return { ok: true, grant: answer.grant };
|
|
1313
|
+
} catch (error) {
|
|
1314
|
+
notify("error", describeError(error));
|
|
1315
|
+
return { ok: false, error };
|
|
1316
|
+
}
|
|
1317
|
+
});
|
|
1318
|
+
},
|
|
1319
|
+
/**
|
|
1320
|
+
* Revoke one grant.
|
|
1321
|
+
* @param {string} grantId - grant identity.
|
|
1322
|
+
*/
|
|
1323
|
+
async revokeGrant(grantId) {
|
|
1324
|
+
return await track("revokeGrant", async () => {
|
|
1325
|
+
try {
|
|
1326
|
+
await api.revokeGrant(grantId);
|
|
1327
|
+
if (state.selectedConnectionId !== null) await store.loadGrants(state.selectedConnectionId);
|
|
1328
|
+
await store.refreshStatus();
|
|
1329
|
+
notify("success", "已撤销该授权。");
|
|
1330
|
+
return { ok: true };
|
|
1331
|
+
} catch (error) {
|
|
1332
|
+
notify("error", describeError(error));
|
|
1333
|
+
return { ok: false, error };
|
|
1334
|
+
}
|
|
1335
|
+
});
|
|
1336
|
+
},
|
|
1337
|
+
/**
|
|
1338
|
+
* Apply an edit to the draft.
|
|
1339
|
+
* @param {(draft: object) => void} mutate - edits the cloned draft in place.
|
|
1340
|
+
*/
|
|
1341
|
+
editDraft(mutate) {
|
|
1342
|
+
const draft = clone(state.draft ?? defaultDraft());
|
|
1343
|
+
mutate(draft);
|
|
1344
|
+
patch({ draft, dirty: true });
|
|
1345
|
+
},
|
|
1346
|
+
/** Discard uncommitted edits. */
|
|
1347
|
+
resetDraft() {
|
|
1348
|
+
patch({ draft: draftFromSettings(state.settings), dirty: false });
|
|
1349
|
+
},
|
|
1350
|
+
/**
|
|
1351
|
+
* Validate the draft locally, then replace the stored document.
|
|
1352
|
+
* @returns {Promise<{ ok: boolean, error?: unknown }>} outcome.
|
|
1353
|
+
*/
|
|
1354
|
+
async saveSettings() {
|
|
1355
|
+
if (state.draft === null) return { ok: false };
|
|
1356
|
+
const problems = precheckDraft(state.draft);
|
|
1357
|
+
if (problems.length > 0) {
|
|
1358
|
+
notify("error", `未保存:${problems.slice(0, 4).join(";")}`);
|
|
1359
|
+
return { ok: false, problems };
|
|
1360
|
+
}
|
|
1361
|
+
return await track("save", async () => {
|
|
1362
|
+
try {
|
|
1363
|
+
const body = await api.putSettings(documentFromDraft(state.draft));
|
|
1364
|
+
patch({ settings: body.settings ?? null, draft: draftFromSettings(body.settings), dirty: false });
|
|
1365
|
+
notify("success", "设置已保存。");
|
|
1366
|
+
return { ok: true };
|
|
1367
|
+
} catch (error) {
|
|
1368
|
+
notify("error", describeError(error));
|
|
1369
|
+
return { ok: false, error };
|
|
1370
|
+
}
|
|
1371
|
+
});
|
|
1372
|
+
},
|
|
1373
|
+
/**
|
|
1374
|
+
* Discover one provider's models from its own API, then keep the result.
|
|
1375
|
+
*
|
|
1376
|
+
* This is remote discovery, not a catalog read: the host calls the provider's
|
|
1377
|
+
* configured endpoint with that provider's credential reference. Consequences
|
|
1378
|
+
* this function has to honour:
|
|
1379
|
+
*
|
|
1380
|
+
* * an empty list plus a `discovery` diagnosis is a *failure*, not "the
|
|
1381
|
+
* provider serves nothing", so it is reported as one and no merge is
|
|
1382
|
+
* attempted;
|
|
1383
|
+
* * discovery never returns capabilities. New ids arrive with `efforts: []`,
|
|
1384
|
+
* so the operator still has to declare what a model supports;
|
|
1385
|
+
* * a host that predates the route (a carrier 404) gets the old fallback,
|
|
1386
|
+
* which is then labelled honestly as a catalog read rather than as
|
|
1387
|
+
* discovery.
|
|
1388
|
+
* @param {string} providerId - provider id.
|
|
1389
|
+
*/
|
|
1390
|
+
async fetchModels(providerId) {
|
|
1391
|
+
patch({ loading: { ...state.loading, [`models:${providerId}`]: true } });
|
|
1392
|
+
try {
|
|
1393
|
+
let models = [];
|
|
1394
|
+
let source = "remote";
|
|
1395
|
+
let providerError = null;
|
|
1396
|
+
let discovery = null;
|
|
1397
|
+
try {
|
|
1398
|
+
const body = await api.fetchModels(providerId);
|
|
1399
|
+
models = Array.isArray(body.models) ? body.models : [];
|
|
1400
|
+
providerError = body.error ?? null;
|
|
1401
|
+
discovery = body.discovery ?? null;
|
|
1402
|
+
source = typeof body.source === "string" ? body.source : "remote";
|
|
1403
|
+
} catch (error) {
|
|
1404
|
+
const routeMissing = error?.code === "HTTP_404" || error?.code === "USER_PLANE_UNKNOWN_ROUTE";
|
|
1405
|
+
if (!routeMissing) throw error;
|
|
1406
|
+
const body = await api.getCatalog({});
|
|
1407
|
+
const entry = (body.catalog ?? []).find((candidate) => candidate.providerId === providerId);
|
|
1408
|
+
models = Array.isArray(entry?.models) ? entry.models : [];
|
|
1409
|
+
providerError = entry?.error ?? null;
|
|
1410
|
+
source = "catalog";
|
|
1411
|
+
discovery = {
|
|
1412
|
+
attempted: false,
|
|
1413
|
+
failed: providerError !== null,
|
|
1414
|
+
code: providerError?.code ?? null,
|
|
1415
|
+
message: "this host does not serve model discovery yet; the configured catalog was read instead"
|
|
1416
|
+
};
|
|
1417
|
+
}
|
|
1418
|
+
const failed = source === "remote" && discovery?.failed === true;
|
|
1419
|
+
patch({
|
|
1420
|
+
modelCatalog: {
|
|
1421
|
+
...state.modelCatalog,
|
|
1422
|
+
[providerId]: { models, source, error: providerError, discovery, fetchedAt: now() }
|
|
1423
|
+
}
|
|
1424
|
+
});
|
|
1425
|
+
if (source === "catalog") {
|
|
1426
|
+
notify("info", "宿主尚未提供从提供方获取模型的接口,已改用模型目录结果(不是远程模型列表)。");
|
|
1427
|
+
}
|
|
1428
|
+
if (source === "remote" && discovery?.failed !== true && providerError !== null) {
|
|
1429
|
+
notify("error", `提供方「${providerId}」无法解析模型:${providerError.message ?? providerError.code ?? ""}`);
|
|
1430
|
+
}
|
|
1431
|
+
if (failed) {
|
|
1432
|
+
notify("error", `从提供方「${providerId}」获取模型失败:${describeError(providerError ?? discovery)}`);
|
|
1433
|
+
return { ok: false, models: [], source, error: providerError };
|
|
1434
|
+
}
|
|
1435
|
+
return { ok: true, models, source, discovery };
|
|
1436
|
+
} catch (error) {
|
|
1437
|
+
patch({
|
|
1438
|
+
modelCatalog: {
|
|
1439
|
+
...state.modelCatalog,
|
|
1440
|
+
[providerId]: {
|
|
1441
|
+
models: [],
|
|
1442
|
+
source: "error",
|
|
1443
|
+
error: { code: error?.code ?? "", message: describeError(error) },
|
|
1444
|
+
discovery: { attempted: true, failed: true, code: error?.code ?? "" },
|
|
1445
|
+
fetchedAt: now()
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
});
|
|
1449
|
+
notify("error", describeError(error));
|
|
1450
|
+
return { ok: false, error };
|
|
1451
|
+
} finally {
|
|
1452
|
+
if (!disposed) patch({ loading: { ...state.loading, [`models:${providerId}`]: false } });
|
|
1453
|
+
}
|
|
1454
|
+
},
|
|
1455
|
+
/**
|
|
1456
|
+
* Merge discovered models into the draft provider, keeping manual-only entries.
|
|
1457
|
+
*
|
|
1458
|
+
* The asymmetry is the point: a model the operator already declared keeps its
|
|
1459
|
+
* declared `efforts` (discovery cannot lend or revoke a capability), a newly
|
|
1460
|
+
* discovered id arrives with no efforts at all, and an id the endpoint did not
|
|
1461
|
+
* list is never removed — a manual entry stays configured.
|
|
1462
|
+
* @param {string} providerId - provider id.
|
|
1463
|
+
* @param {object[]} models - `[{ id, efforts }]`.
|
|
1464
|
+
*/
|
|
1465
|
+
mergeModelsIntoDraft(providerId, models) {
|
|
1466
|
+
store.editDraft((draft) => {
|
|
1467
|
+
const provider = draft.providers.find((entry) => entry.id === providerId);
|
|
1468
|
+
if (provider === void 0) return;
|
|
1469
|
+
for (const model of models) {
|
|
1470
|
+
if (typeof model?.id !== "string" || model.id === "") continue;
|
|
1471
|
+
const existing = provider.models.find((entry) => entry.id === model.id);
|
|
1472
|
+
if (existing !== void 0) {
|
|
1473
|
+
continue;
|
|
1474
|
+
}
|
|
1475
|
+
const served = Array.isArray(model.efforts) ? [...model.efforts] : [];
|
|
1476
|
+
provider.models.push({ id: model.id, efforts: served });
|
|
1477
|
+
}
|
|
1478
|
+
});
|
|
1479
|
+
},
|
|
1480
|
+
/**
|
|
1481
|
+
* Read whether one provider's credential is configured.
|
|
1482
|
+
* @param {string} providerId - provider id.
|
|
1483
|
+
*/
|
|
1484
|
+
async credentialStatus(providerId) {
|
|
1485
|
+
patch({ loading: { ...state.loading, [`credential:${providerId}`]: true } });
|
|
1486
|
+
try {
|
|
1487
|
+
const body = await api.credentialStatus(providerId);
|
|
1488
|
+
patch({
|
|
1489
|
+
credentials: {
|
|
1490
|
+
...state.credentials,
|
|
1491
|
+
[providerId]: { ...body.credential ?? {}, loaded: true }
|
|
1492
|
+
}
|
|
1493
|
+
});
|
|
1494
|
+
return { ok: true, credential: body.credential };
|
|
1495
|
+
} catch (error) {
|
|
1496
|
+
patch({
|
|
1497
|
+
credentials: {
|
|
1498
|
+
...state.credentials,
|
|
1499
|
+
[providerId]: {
|
|
1500
|
+
configured: null,
|
|
1501
|
+
loaded: true,
|
|
1502
|
+
unavailable: true,
|
|
1503
|
+
reason: describeError(error)
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
});
|
|
1507
|
+
return { ok: false, error };
|
|
1508
|
+
} finally {
|
|
1509
|
+
if (!disposed) patch({ loading: { ...state.loading, [`credential:${providerId}`]: false } });
|
|
1510
|
+
}
|
|
1511
|
+
},
|
|
1512
|
+
/**
|
|
1513
|
+
* Forward a credential value to the host and forget it.
|
|
1514
|
+
* @param {string} providerId - provider id.
|
|
1515
|
+
* @param {string} value - the literal; discarded immediately after the call.
|
|
1516
|
+
*/
|
|
1517
|
+
async setCredential(providerId, value) {
|
|
1518
|
+
const literal = typeof value === "string" ? value : "";
|
|
1519
|
+
if (literal.trim() === "") {
|
|
1520
|
+
notify("error", describeError(new ApiError("CREDENTIAL_EMPTY", "no value was entered")));
|
|
1521
|
+
return { ok: false };
|
|
1522
|
+
}
|
|
1523
|
+
return await track(`credential:${providerId}`, async () => {
|
|
1524
|
+
try {
|
|
1525
|
+
const body = await api.setCredential(providerId, literal);
|
|
1526
|
+
patch({
|
|
1527
|
+
credentials: { ...state.credentials, [providerId]: { ...body.credential ?? {}, loaded: true } }
|
|
1528
|
+
});
|
|
1529
|
+
notify("success", `已保存提供方「${providerId}」的密钥(值不会回显)。`);
|
|
1530
|
+
return { ok: true, credential: body.credential };
|
|
1531
|
+
} catch (error) {
|
|
1532
|
+
notify("error", error?.code === "HTTP_404" || error?.code === "USER_PLANE_UNKNOWN_ROUTE" ? describeError(new ApiError("CREDENTIAL_SEAM_UNAVAILABLE", "credential route unavailable")) : describeError(error));
|
|
1533
|
+
return { ok: false, error };
|
|
1534
|
+
}
|
|
1535
|
+
});
|
|
1536
|
+
},
|
|
1537
|
+
/**
|
|
1538
|
+
* Remove one provider's stored credential.
|
|
1539
|
+
* @param {string} providerId - provider id.
|
|
1540
|
+
*/
|
|
1541
|
+
async unsetCredential(providerId) {
|
|
1542
|
+
return await track(`credential:${providerId}`, async () => {
|
|
1543
|
+
try {
|
|
1544
|
+
const body = await api.unsetCredential(providerId);
|
|
1545
|
+
patch({
|
|
1546
|
+
credentials: { ...state.credentials, [providerId]: { ...body.credential ?? {}, loaded: true } }
|
|
1547
|
+
});
|
|
1548
|
+
notify("success", `已清除提供方「${providerId}」的密钥。`);
|
|
1549
|
+
return { ok: true, credential: body.credential };
|
|
1550
|
+
} catch (error) {
|
|
1551
|
+
notify("error", describeError(error));
|
|
1552
|
+
return { ok: false, error };
|
|
1553
|
+
}
|
|
1554
|
+
});
|
|
1555
|
+
},
|
|
1556
|
+
/**
|
|
1557
|
+
* Run one provider's layered connectivity check.
|
|
1558
|
+
* @param {object} form - `{ providerId, model, reasoningEffort }`.
|
|
1559
|
+
*/
|
|
1560
|
+
async checkConnectivity(form) {
|
|
1561
|
+
const providerId = String(form?.providerId ?? "");
|
|
1562
|
+
if (providerId === "") {
|
|
1563
|
+
notify("error", "请先选择提供方。");
|
|
1564
|
+
return { ok: false };
|
|
1565
|
+
}
|
|
1566
|
+
return await track(`connectivity:${providerId}`, async () => {
|
|
1567
|
+
try {
|
|
1568
|
+
const body = { providerId };
|
|
1569
|
+
if (typeof form.model === "string" && form.model !== "") body.model = form.model;
|
|
1570
|
+
if (typeof form.reasoningEffort === "string" && form.reasoningEffort !== "") body.reasoningEffort = form.reasoningEffort;
|
|
1571
|
+
const answer = await api.checkConnectivity(body);
|
|
1572
|
+
patch({ connectivity: { ...state.connectivity, [providerId]: answer.report ?? null } });
|
|
1573
|
+
return { ok: true, report: answer.report };
|
|
1574
|
+
} catch (error) {
|
|
1575
|
+
patch({ connectivity: { ...state.connectivity, [providerId]: null } });
|
|
1576
|
+
notify("error", describeError(error));
|
|
1577
|
+
return { ok: false, error };
|
|
1578
|
+
}
|
|
1579
|
+
});
|
|
1580
|
+
},
|
|
1581
|
+
/**
|
|
1582
|
+
* Read the Codex integration status. Read-only: this is what `init()` calls,
|
|
1583
|
+
* so opening the page never writes to the Codex home.
|
|
1584
|
+
*/
|
|
1585
|
+
async refreshCodexStatus() {
|
|
1586
|
+
return await track("codexStatus", async () => {
|
|
1587
|
+
try {
|
|
1588
|
+
const body = await api.getCodexStatus();
|
|
1589
|
+
patch({ codex: body.codex ?? null, codexError: null });
|
|
1590
|
+
return { ok: true, codex: body.codex ?? null, switch: body.switch ?? null };
|
|
1591
|
+
} catch (error) {
|
|
1592
|
+
const unavailable = error?.code === "HTTP_404" || error?.code === "USER_PLANE_UNKNOWN_ROUTE";
|
|
1593
|
+
patch({
|
|
1594
|
+
codex: null,
|
|
1595
|
+
codexError: unavailable ? "当前宿主未提供 Codex 集成接口(插件版本可能较旧)。" : describeError(error)
|
|
1596
|
+
});
|
|
1597
|
+
return { ok: false, error };
|
|
1598
|
+
}
|
|
1599
|
+
});
|
|
1600
|
+
},
|
|
1601
|
+
/**
|
|
1602
|
+
* Perform one explicit Codex action and keep its outcome.
|
|
1603
|
+
*
|
|
1604
|
+
* This is only reachable from a button click: nothing calls it from `init()`,
|
|
1605
|
+
* from `saveSettings()` or from a render pass. Installed files are therefore
|
|
1606
|
+
* always the result of an operator decision.
|
|
1607
|
+
* @param {'install'|'repair'|'remove'} action - action to perform.
|
|
1608
|
+
*/
|
|
1609
|
+
async runCodexAction(action) {
|
|
1610
|
+
if (!CODEX_ACTIONS.includes(action)) {
|
|
1611
|
+
notify("error", `未知的 Codex 操作:${String(action)}`);
|
|
1612
|
+
return { ok: false };
|
|
1613
|
+
}
|
|
1614
|
+
return await track("codexAction", async () => {
|
|
1615
|
+
try {
|
|
1616
|
+
const body = await api.runCodexAction(action);
|
|
1617
|
+
const outcome = {
|
|
1618
|
+
action: body.action ?? action,
|
|
1619
|
+
changed: Array.isArray(body.changed) ? body.changed : [],
|
|
1620
|
+
refused: Array.isArray(body.refused) ? body.refused : []
|
|
1621
|
+
};
|
|
1622
|
+
const codex = body.codex ?? state.codex;
|
|
1623
|
+
patch({ codex, codexError: null, codexOutcome: outcome });
|
|
1624
|
+
const summary = describeCodexOutcome(outcome);
|
|
1625
|
+
const failed = outcome.refused.length > 0;
|
|
1626
|
+
notify(failed ? "error" : "success", summary === "" ? "操作完成。" : summary);
|
|
1627
|
+
return { ok: !failed, outcome, codex };
|
|
1628
|
+
} catch (error) {
|
|
1629
|
+
patch({ codexOutcome: null });
|
|
1630
|
+
notify("error", describeError(error));
|
|
1631
|
+
return { ok: false, error };
|
|
1632
|
+
}
|
|
1633
|
+
});
|
|
1634
|
+
},
|
|
1635
|
+
/**
|
|
1636
|
+
* Replace only the two silence thresholds.
|
|
1637
|
+
*
|
|
1638
|
+
* The narrow route exists so an operator adjusting a timer cannot rewrite a
|
|
1639
|
+
* provider list. On success the committed document is adopted for `settings` and
|
|
1640
|
+
* the draft's monitoring block, and OTHER unsaved draft edits are left alone —
|
|
1641
|
+
* a timer save must never discard a half-finished provider edit.
|
|
1642
|
+
* @param {{ selfCheckSeconds: number, attentionSeconds: number }} monitoring - already-validated block.
|
|
1643
|
+
* @returns {Promise<{ ok: boolean, error?: unknown }>} outcome.
|
|
1644
|
+
*/
|
|
1645
|
+
async saveMonitoring(monitoring) {
|
|
1646
|
+
const normalized = monitoringOf({ monitoring });
|
|
1647
|
+
const problems = precheckMonitoring(normalized);
|
|
1648
|
+
if (problems.length > 0) {
|
|
1649
|
+
notify("error", `未保存:${problems.join(";")}`);
|
|
1650
|
+
return { ok: false, problems };
|
|
1651
|
+
}
|
|
1652
|
+
return await track("monitoring", async () => {
|
|
1653
|
+
try {
|
|
1654
|
+
const body = await api.putMonitoring(normalized);
|
|
1655
|
+
const committed = body.settings ?? null;
|
|
1656
|
+
const draft = state.draft === null ? draftFromSettings(committed) : { ...state.draft, monitoring: monitoringOf(committed ?? { monitoring: normalized }) };
|
|
1657
|
+
patch({ settings: committed, draft });
|
|
1658
|
+
notify("success", "监控间隔已保存。已开始运行的任务保留它自己的快照,新任务使用新值。");
|
|
1659
|
+
return { ok: true, monitoring: body.monitoring ?? normalized };
|
|
1660
|
+
} catch (error) {
|
|
1661
|
+
notify("error", describeError(error));
|
|
1662
|
+
return { ok: false, error };
|
|
1663
|
+
}
|
|
1664
|
+
});
|
|
1665
|
+
},
|
|
1666
|
+
/**
|
|
1667
|
+
* Refresh the task list without operator-facing noise.
|
|
1668
|
+
*
|
|
1669
|
+
* Used by the bounded auto-refresh only. It differs from {@link store.loadTasks}
|
|
1670
|
+
* in three ways that matter for a background read: it never notifies on failure
|
|
1671
|
+
* (a transient blip must not spam the page), it never clears a previously loaded
|
|
1672
|
+
* list on error, and it is a pure read — no model call, no task action — so a
|
|
1673
|
+
* visible page cannot cause work by being visible.
|
|
1674
|
+
* @param {string} [reason] - `auto` for the timer, `manual` for an explicit click.
|
|
1675
|
+
* @returns {Promise<{ ok: boolean, tasks?: object[] }>} outcome.
|
|
1676
|
+
*/
|
|
1677
|
+
async refreshTasks(reason = "auto") {
|
|
1678
|
+
if (state.loading?.tasks === true) return { ok: false, skipped: "in-flight" };
|
|
1679
|
+
patch({ loading: { ...state.loading, tasks: true } });
|
|
1680
|
+
try {
|
|
1681
|
+
const body = await api.listTasks();
|
|
1682
|
+
const tasks = Array.isArray(body.tasks) ? body.tasks : [];
|
|
1683
|
+
const detail = state.taskDetail === null ? null : tasks.find((task) => task.taskId === state.taskDetail.taskId) ?? state.taskDetail;
|
|
1684
|
+
patch({ tasks, taskDetail: detail });
|
|
1685
|
+
return { ok: true, tasks, reason };
|
|
1686
|
+
} catch (error) {
|
|
1687
|
+
if (reason === "manual") notify("error", describeError(error));
|
|
1688
|
+
return { ok: false, error };
|
|
1689
|
+
} finally {
|
|
1690
|
+
if (!disposed) patch({ loading: { ...state.loading, tasks: false } });
|
|
1691
|
+
}
|
|
1692
|
+
},
|
|
1693
|
+
/** Read the task list. */
|
|
1694
|
+
async loadTasks() {
|
|
1695
|
+
return await track("tasks", async () => {
|
|
1696
|
+
try {
|
|
1697
|
+
const body = await api.listTasks();
|
|
1698
|
+
patch({ tasks: Array.isArray(body.tasks) ? body.tasks : [] });
|
|
1699
|
+
return { ok: true, tasks: body.tasks ?? [] };
|
|
1700
|
+
} catch (error) {
|
|
1701
|
+
notify("error", describeError(error));
|
|
1702
|
+
return { ok: false, error };
|
|
1703
|
+
}
|
|
1704
|
+
});
|
|
1705
|
+
},
|
|
1706
|
+
/**
|
|
1707
|
+
* Read one task with its prompt and evidence.
|
|
1708
|
+
* @param {string} taskId - task identity.
|
|
1709
|
+
*/
|
|
1710
|
+
async openTask(taskId) {
|
|
1711
|
+
return await track("taskDetail", async () => {
|
|
1712
|
+
try {
|
|
1713
|
+
const body = await api.getTask(taskId);
|
|
1714
|
+
patch({ taskDetail: body.task ?? null });
|
|
1715
|
+
return { ok: true, task: body.task };
|
|
1716
|
+
} catch (error) {
|
|
1717
|
+
notify("error", describeError(error));
|
|
1718
|
+
return { ok: false, error };
|
|
1719
|
+
}
|
|
1720
|
+
});
|
|
1721
|
+
},
|
|
1722
|
+
/**
|
|
1723
|
+
* Cancel one task as the operator.
|
|
1724
|
+
* @param {string} taskId - task identity.
|
|
1725
|
+
*/
|
|
1726
|
+
async cancelTask(taskId) {
|
|
1727
|
+
return await track("cancelTask", async () => {
|
|
1728
|
+
try {
|
|
1729
|
+
const body = await api.cancelTask(taskId);
|
|
1730
|
+
patch({
|
|
1731
|
+
tasks: state.tasks.map((task) => task.taskId === taskId ? { ...task, ...body.task } : task),
|
|
1732
|
+
taskDetail: state.taskDetail?.taskId === taskId ? { ...state.taskDetail, ...body.task } : state.taskDetail
|
|
1733
|
+
});
|
|
1734
|
+
notify("success", "已请求取消。");
|
|
1735
|
+
return { ok: true, task: body.task };
|
|
1736
|
+
} catch (error) {
|
|
1737
|
+
notify("error", describeError(error));
|
|
1738
|
+
return { ok: false, error };
|
|
1739
|
+
}
|
|
1740
|
+
});
|
|
1741
|
+
},
|
|
1742
|
+
/** Load everything the page needs; the catalog is loaded but not awaited. */
|
|
1743
|
+
async init() {
|
|
1744
|
+
await Promise.all([store.refreshStatus(), store.loadSettings(), store.loadNativeProviders(), store.loadTasks()]);
|
|
1745
|
+
void store.refreshCodexStatus();
|
|
1746
|
+
void store.loadCatalog();
|
|
1747
|
+
},
|
|
1748
|
+
/** Release subscriptions and drop the one-time token. */
|
|
1749
|
+
dispose() {
|
|
1750
|
+
disposed = true;
|
|
1751
|
+
state = { ...state, token: null, tokenConnectionId: null };
|
|
1752
|
+
listeners.clear();
|
|
1753
|
+
}
|
|
1754
|
+
};
|
|
1755
|
+
return store;
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
// src/client/styles.js
|
|
1759
|
+
var STYLE_PLUGIN_ATTRIBUTE = "data-plugin";
|
|
1760
|
+
var STYLE_PLUGIN_ID = "dsh-delegate";
|
|
1761
|
+
var STYLE_ELEMENT_ID = "dsh-delegate-settings";
|
|
1762
|
+
var CSS_TEXT = `
|
|
1763
|
+
.dshdg-root {
|
|
1764
|
+
display: flex;
|
|
1765
|
+
flex-direction: column;
|
|
1766
|
+
gap: 16px;
|
|
1767
|
+
padding: 4px 2px 24px;
|
|
1768
|
+
color: var(--dsw-alias-label-primary, #1f2329);
|
|
1769
|
+
font-family: var(--dsw-font-family, system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif);
|
|
1770
|
+
font-size: 13px;
|
|
1771
|
+
line-height: 1.55;
|
|
1772
|
+
}
|
|
1773
|
+
.dshdg-root * { box-sizing: border-box; }
|
|
1774
|
+
.dshdg-root h3, .dshdg-root h4 { margin: 0; font-weight: 600; }
|
|
1775
|
+
.dshdg-root h3 { font-size: 15px; }
|
|
1776
|
+
.dshdg-root h4 { font-size: 13px; }
|
|
1777
|
+
.dshdg-root p { margin: 0; }
|
|
1778
|
+
.dshdg-muted { color: var(--dsw-alias-label-secondary, #61666d); }
|
|
1779
|
+
.dshdg-faint { color: var(--dsw-alias-label-tertiary, #8a9098); }
|
|
1780
|
+
.dshdg-mono {
|
|
1781
|
+
font-family: var(--ds-font-family-code, ui-monospace, SFMono-Regular, Consolas, monospace);
|
|
1782
|
+
font-size: 12px;
|
|
1783
|
+
}
|
|
1784
|
+
.dshdg-card {
|
|
1785
|
+
border: 1px solid var(--dsw-alias-border-l2, #e2e5e9);
|
|
1786
|
+
border-radius: var(--dsw-radius-md, 8px);
|
|
1787
|
+
background: var(--dsw-alias-bg-layer-3, #fff);
|
|
1788
|
+
padding: 12px 14px;
|
|
1789
|
+
display: flex;
|
|
1790
|
+
flex-direction: column;
|
|
1791
|
+
gap: 10px;
|
|
1792
|
+
min-width: 0;
|
|
1793
|
+
}
|
|
1794
|
+
.dshdg-card-danger { border-color: var(--dsw-alias-label-error, #d92d20); }
|
|
1795
|
+
.dshdg-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-width: 0; }
|
|
1796
|
+
.dshdg-row-end { justify-content: flex-end; }
|
|
1797
|
+
.dshdg-switch { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
|
|
1798
|
+
.dshdg-switch input { width: 18px; height: 18px; margin: 0; accent-color: #087e8b; }
|
|
1799
|
+
.dshdg-spacer { flex: 1 1 auto; }
|
|
1800
|
+
.dshdg-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); min-width: 0; }
|
|
1801
|
+
.dshdg-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
|
|
1802
|
+
.dshdg-field > label { font-weight: 500; color: var(--dsw-alias-label-secondary, #61666d); font-size: 12px; }
|
|
1803
|
+
.dshdg-hint { font-size: 12px; color: var(--dsw-alias-label-tertiary, #8a9098); }
|
|
1804
|
+
.dshdg-root input[type="text"],
|
|
1805
|
+
.dshdg-root input[type="password"],
|
|
1806
|
+
.dshdg-root input[type="number"],
|
|
1807
|
+
.dshdg-root select,
|
|
1808
|
+
.dshdg-root textarea {
|
|
1809
|
+
width: 100%;
|
|
1810
|
+
padding: 5px 8px;
|
|
1811
|
+
color: inherit;
|
|
1812
|
+
font: inherit;
|
|
1813
|
+
background: var(--dsw-alias-bg-base, #f7f8f9);
|
|
1814
|
+
border: 1px solid var(--dsw-alias-border-l3, #d3d7dd);
|
|
1815
|
+
border-radius: var(--dsw-radius-sm, 6px);
|
|
1816
|
+
min-width: 0;
|
|
1817
|
+
}
|
|
1818
|
+
.dshdg-root textarea { resize: vertical; min-height: 76px; }
|
|
1819
|
+
.dshdg-root input:focus-visible,
|
|
1820
|
+
.dshdg-root select:focus-visible,
|
|
1821
|
+
.dshdg-root textarea:focus-visible,
|
|
1822
|
+
.dshdg-root button:focus-visible {
|
|
1823
|
+
outline: var(--dsw-focus-ring-width, 2px) solid var(--dsw-focus-ring-color, #3457d5);
|
|
1824
|
+
outline-offset: 1px;
|
|
1825
|
+
}
|
|
1826
|
+
.dshdg-root input:disabled, .dshdg-root select:disabled, .dshdg-root textarea:disabled {
|
|
1827
|
+
opacity: 0.6;
|
|
1828
|
+
cursor: not-allowed;
|
|
1829
|
+
}
|
|
1830
|
+
.dshdg-root button {
|
|
1831
|
+
font: inherit;
|
|
1832
|
+
padding: 5px 12px;
|
|
1833
|
+
border-radius: var(--dsw-radius-sm, 6px);
|
|
1834
|
+
border: 1px solid var(--dsw-alias-border-l3, #d3d7dd);
|
|
1835
|
+
background: var(--dsw-alias-button-tool-bar-fill, #f2f3f5);
|
|
1836
|
+
color: inherit;
|
|
1837
|
+
cursor: pointer;
|
|
1838
|
+
white-space: nowrap;
|
|
1839
|
+
}
|
|
1840
|
+
.dshdg-root button:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover, #e9ebee); }
|
|
1841
|
+
.dshdg-root button:disabled { opacity: 0.55; cursor: not-allowed; }
|
|
1842
|
+
.dshdg-root button.dshdg-primary {
|
|
1843
|
+
background: var(--dsw-alias-button-primary-fill, #3457d5);
|
|
1844
|
+
border-color: transparent;
|
|
1845
|
+
color: var(--dsw-alias-label-primary-foreground, #fff);
|
|
1846
|
+
}
|
|
1847
|
+
.dshdg-root button.dshdg-primary:hover:not(:disabled) { background: var(--dsw-alias-button-primary-hover, #2b49b8); }
|
|
1848
|
+
.dshdg-root button.dshdg-danger { color: var(--dsw-alias-label-error, #d92d20); }
|
|
1849
|
+
.dshdg-check { display: flex; flex-wrap: wrap; gap: 6px 12px; }
|
|
1850
|
+
.dshdg-check label { display: inline-flex; gap: 5px; align-items: center; font-size: 12px; }
|
|
1851
|
+
.dshdg-check input { margin: 0; }
|
|
1852
|
+
.dshdg-tabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--dsw-alias-border-l2, #e2e5e9); }
|
|
1853
|
+
.dshdg-tab {
|
|
1854
|
+
border: 1px solid transparent;
|
|
1855
|
+
border-bottom: none;
|
|
1856
|
+
border-radius: var(--dsw-radius-sm, 6px) var(--dsw-radius-sm, 6px) 0 0;
|
|
1857
|
+
background: transparent;
|
|
1858
|
+
padding: 6px 14px;
|
|
1859
|
+
}
|
|
1860
|
+
.dshdg-tab[aria-selected="true"] {
|
|
1861
|
+
background: var(--dsw-alias-bg-layer-3, #fff);
|
|
1862
|
+
border-color: var(--dsw-alias-border-l2, #e2e5e9);
|
|
1863
|
+
font-weight: 600;
|
|
1864
|
+
}
|
|
1865
|
+
.dshdg-panel { display: flex; flex-direction: column; gap: 14px; }
|
|
1866
|
+
.dshdg-notices { display: flex; flex-direction: column; gap: 6px; }
|
|
1867
|
+
.dshdg-notice {
|
|
1868
|
+
display: flex;
|
|
1869
|
+
gap: 8px;
|
|
1870
|
+
align-items: flex-start;
|
|
1871
|
+
padding: 7px 10px;
|
|
1872
|
+
border-radius: var(--dsw-radius-sm, 6px);
|
|
1873
|
+
border: 1px solid var(--dsw-alias-border-l2, #e2e5e9);
|
|
1874
|
+
background: var(--dsw-alias-bg-layer-4, #f7f8f9);
|
|
1875
|
+
}
|
|
1876
|
+
.dshdg-notice-error { border-color: var(--dsw-alias-label-error, #d92d20); }
|
|
1877
|
+
.dshdg-notice-success { border-color: var(--dsw-alias-state-business-primary, #12b76a); }
|
|
1878
|
+
.dshdg-notice > span { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
|
|
1879
|
+
.dshdg-badge {
|
|
1880
|
+
display: inline-block;
|
|
1881
|
+
padding: 1px 8px;
|
|
1882
|
+
border-radius: 999px;
|
|
1883
|
+
border: 1px solid var(--dsw-alias-border-l3, #d3d7dd);
|
|
1884
|
+
font-size: 11px;
|
|
1885
|
+
white-space: nowrap;
|
|
1886
|
+
}
|
|
1887
|
+
.dshdg-badge-on { border-color: var(--dsw-alias-state-business-primary, #12b76a); }
|
|
1888
|
+
.dshdg-badge-off { border-color: var(--dsw-alias-label-tertiary, #8a9098); color: var(--dsw-alias-label-secondary, #61666d); }
|
|
1889
|
+
.dshdg-badge-warn { border-color: var(--dsw-alias-label-error, #d92d20); color: var(--dsw-alias-label-error, #d92d20); }
|
|
1890
|
+
.dshdg-list { display: flex; flex-direction: column; gap: 8px; }
|
|
1891
|
+
.dshdg-item {
|
|
1892
|
+
border: 1px solid var(--dsw-alias-border-l2, #e2e5e9);
|
|
1893
|
+
border-radius: var(--dsw-radius-sm, 6px);
|
|
1894
|
+
padding: 10px 12px;
|
|
1895
|
+
display: flex;
|
|
1896
|
+
flex-direction: column;
|
|
1897
|
+
gap: 8px;
|
|
1898
|
+
min-width: 0;
|
|
1899
|
+
}
|
|
1900
|
+
.dshdg-item-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-width: 0; }
|
|
1901
|
+
.dshdg-item-head strong { overflow-wrap: anywhere; }
|
|
1902
|
+
.dshdg-secret-warning {
|
|
1903
|
+
border: 1px solid var(--dsw-alias-label-error, #d92d20);
|
|
1904
|
+
border-radius: var(--dsw-radius-sm, 6px);
|
|
1905
|
+
padding: 10px 12px;
|
|
1906
|
+
display: flex;
|
|
1907
|
+
flex-direction: column;
|
|
1908
|
+
gap: 8px;
|
|
1909
|
+
}
|
|
1910
|
+
.dshdg-token {
|
|
1911
|
+
display: block;
|
|
1912
|
+
width: 100%;
|
|
1913
|
+
padding: 8px 10px;
|
|
1914
|
+
border-radius: var(--dsw-radius-sm, 6px);
|
|
1915
|
+
border: 1px dashed var(--dsw-alias-border-l3, #d3d7dd);
|
|
1916
|
+
background: var(--dsw-alias-bg-base, #f7f8f9);
|
|
1917
|
+
overflow-wrap: anywhere;
|
|
1918
|
+
user-select: all;
|
|
1919
|
+
}
|
|
1920
|
+
.dshdg-pre {
|
|
1921
|
+
margin: 0;
|
|
1922
|
+
padding: 8px 10px;
|
|
1923
|
+
max-height: 320px;
|
|
1924
|
+
overflow: auto;
|
|
1925
|
+
background: var(--dsw-alias-markdown-code-block, #f5f6f8);
|
|
1926
|
+
border-radius: var(--dsw-radius-sm, 6px);
|
|
1927
|
+
white-space: pre-wrap;
|
|
1928
|
+
overflow-wrap: anywhere;
|
|
1929
|
+
font-family: var(--ds-font-family-code, ui-monospace, SFMono-Regular, Consolas, monospace);
|
|
1930
|
+
font-size: 12px;
|
|
1931
|
+
}
|
|
1932
|
+
.dshdg-layers { display: grid; gap: 6px; }
|
|
1933
|
+
.dshdg-layer { display: grid; grid-template-columns: minmax(120px, 180px) minmax(0, 1fr); gap: 8px; align-items: start; }
|
|
1934
|
+
.dshdg-layer-detail { overflow-wrap: anywhere; }
|
|
1935
|
+
.dshdg-ok { color: var(--dsw-alias-state-business-primary, #12b76a); }
|
|
1936
|
+
.dshdg-fail { color: var(--dsw-alias-label-error, #d92d20); }
|
|
1937
|
+
.dshdg-unknown { color: var(--dsw-alias-label-tertiary, #8a9098); }
|
|
1938
|
+
.dshdg-table { display: grid; gap: 4px; }
|
|
1939
|
+
.dshdg-kv { display: grid; grid-template-columns: minmax(96px, 140px) minmax(0, 1fr); gap: 4px 10px; }
|
|
1940
|
+
.dshdg-kv dt { color: var(--dsw-alias-label-secondary, #61666d); }
|
|
1941
|
+
.dshdg-kv dd { margin: 0; overflow-wrap: anywhere; }
|
|
1942
|
+
@media (max-width: 560px) {
|
|
1943
|
+
.dshdg-layer, .dshdg-kv { grid-template-columns: minmax(0, 1fr); }
|
|
1944
|
+
}
|
|
1945
|
+
`;
|
|
1946
|
+
function injectStyles(doc) {
|
|
1947
|
+
const document_ = doc ?? (typeof document === "undefined" ? null : document);
|
|
1948
|
+
if (document_ === null || typeof document_.createElement !== "function") return () => {
|
|
1949
|
+
};
|
|
1950
|
+
const existing = typeof document_.getElementById === "function" ? document_.getElementById(STYLE_ELEMENT_ID) : null;
|
|
1951
|
+
if (existing !== null && existing !== void 0) {
|
|
1952
|
+
return () => {
|
|
1953
|
+
existing.remove?.();
|
|
1954
|
+
};
|
|
1955
|
+
}
|
|
1956
|
+
const element = document_.createElement("style");
|
|
1957
|
+
element.id = STYLE_ELEMENT_ID;
|
|
1958
|
+
element.setAttribute(STYLE_PLUGIN_ATTRIBUTE, STYLE_PLUGIN_ID);
|
|
1959
|
+
element.textContent = CSS_TEXT;
|
|
1960
|
+
const parent = document_.head ?? document_.documentElement ?? document_.body;
|
|
1961
|
+
parent.appendChild(element);
|
|
1962
|
+
return () => {
|
|
1963
|
+
element.remove?.();
|
|
1964
|
+
};
|
|
1965
|
+
}
|
|
1966
|
+
|
|
1967
|
+
// src/client/index.jsx
|
|
1968
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1969
|
+
var PLUGIN_CONFIG_SLOT = "plugins.bundle.config";
|
|
1970
|
+
var PLUGIN_BUNDLE_KEY = "dsh-taskbridge";
|
|
1971
|
+
var inject = ["slots"];
|
|
1972
|
+
function registerBundleConfiguration(ctx, options) {
|
|
1973
|
+
const store = options.store;
|
|
1974
|
+
const injectFace = () => ({ store });
|
|
1975
|
+
return ctx.slots.inject(PLUGIN_CONFIG_SLOT, () => ctx.slots.register({
|
|
1976
|
+
name: PLUGIN_CONFIG_SLOT,
|
|
1977
|
+
key: PLUGIN_BUNDLE_KEY,
|
|
1978
|
+
inject: injectFace
|
|
1979
|
+
}, DelegateConfigPage));
|
|
1980
|
+
}
|
|
1981
|
+
function apply(ctx) {
|
|
1982
|
+
ctx.effect(() => injectStyles(globalThis.document), "dsh-delegate: settings styles");
|
|
1983
|
+
const store = createStore({ api: createApi() });
|
|
1984
|
+
ctx.effect(() => () => store.dispose(), "dsh-delegate: settings store");
|
|
1985
|
+
ctx.effect(() => registerBundleConfiguration(ctx, { store }), "dsh-delegate: bundle configuration");
|
|
1986
|
+
}
|
|
1987
|
+
function Badge({ tone = "off", children }) {
|
|
1988
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: `dshdg-badge dshdg-badge-${tone}`, children });
|
|
1989
|
+
}
|
|
1990
|
+
function Field({ label, hint, htmlFor, children }) {
|
|
1991
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-field", children: [
|
|
1992
|
+
label === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor, children: label }),
|
|
1993
|
+
children,
|
|
1994
|
+
hint === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-hint", children: hint })
|
|
1995
|
+
] });
|
|
1996
|
+
}
|
|
1997
|
+
function IntegerField({ label, value, min, max, onChange, hint, disabled = false, id }) {
|
|
1998
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, { label, hint, htmlFor: id, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1999
|
+
"input",
|
|
2000
|
+
{
|
|
2001
|
+
id,
|
|
2002
|
+
type: "number",
|
|
2003
|
+
inputMode: "numeric",
|
|
2004
|
+
min,
|
|
2005
|
+
max,
|
|
2006
|
+
step: 1,
|
|
2007
|
+
disabled,
|
|
2008
|
+
value: Number.isFinite(Number(value)) ? String(value) : "",
|
|
2009
|
+
onChange: (event) => {
|
|
2010
|
+
const raw = event.target.value;
|
|
2011
|
+
onChange(raw === "" ? "" : Number(raw));
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
) });
|
|
2015
|
+
}
|
|
2016
|
+
function SelectionFields(props) {
|
|
2017
|
+
const { providers, value, onChange, idPrefix } = props;
|
|
2018
|
+
const provider = providers.find((entry) => entry.id === value.providerId) ?? null;
|
|
2019
|
+
const models = provider === null ? [] : provider.models ?? [];
|
|
2020
|
+
const model = models.find((entry) => entry.id === value.model) ?? null;
|
|
2021
|
+
const efforts = model === null ? [] : model.efforts ?? [];
|
|
2022
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-grid", children: [
|
|
2023
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, { label: "提供方", htmlFor: `${idPrefix}-provider`, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
2024
|
+
"select",
|
|
2025
|
+
{
|
|
2026
|
+
id: `${idPrefix}-provider`,
|
|
2027
|
+
value: value.providerId ?? "",
|
|
2028
|
+
onChange: (event) => {
|
|
2029
|
+
onChange({ providerId: event.target.value === "" ? null : event.target.value, model: null, reasoningEffort: null });
|
|
2030
|
+
},
|
|
2031
|
+
children: [
|
|
2032
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "", children: "(未选择)" }),
|
|
2033
|
+
providers.map((entry) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: entry.id, children: entry.name === "" ? entry.id : `${entry.name}(${entry.id})` }, entry.id))
|
|
2034
|
+
]
|
|
2035
|
+
}
|
|
2036
|
+
) }),
|
|
2037
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, { label: "模型", htmlFor: `${idPrefix}-model`, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
2038
|
+
"select",
|
|
2039
|
+
{
|
|
2040
|
+
id: `${idPrefix}-model`,
|
|
2041
|
+
value: value.model ?? "",
|
|
2042
|
+
disabled: provider === null,
|
|
2043
|
+
onChange: (event) => {
|
|
2044
|
+
const nextModel = event.target.value === "" ? null : event.target.value;
|
|
2045
|
+
const declared = models.find((entry) => entry.id === nextModel)?.efforts ?? [];
|
|
2046
|
+
const keep = value.reasoningEffort === null || declared.includes(value.reasoningEffort) ? value.reasoningEffort : null;
|
|
2047
|
+
onChange({ providerId: value.providerId ?? null, model: nextModel, reasoningEffort: keep });
|
|
2048
|
+
},
|
|
2049
|
+
children: [
|
|
2050
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "", children: "(未选择)" }),
|
|
2051
|
+
models.map((entry) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: entry.id, children: entry.id }, entry.id))
|
|
2052
|
+
]
|
|
2053
|
+
}
|
|
2054
|
+
) }),
|
|
2055
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2056
|
+
Field,
|
|
2057
|
+
{
|
|
2058
|
+
label: "推理强度",
|
|
2059
|
+
htmlFor: `${idPrefix}-effort`,
|
|
2060
|
+
hint: model === null ? "选择模型后显示该模型声明的推理强度" : efforts.length === 0 ? "该模型未声明推理强度,只能不指定" : "仅列出该模型声明的能力",
|
|
2061
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
2062
|
+
"select",
|
|
2063
|
+
{
|
|
2064
|
+
id: `${idPrefix}-effort`,
|
|
2065
|
+
value: value.reasoningEffort ?? EFFORT_UNSET,
|
|
2066
|
+
disabled: model === null || efforts.length === 0,
|
|
2067
|
+
onChange: (event) => {
|
|
2068
|
+
onChange({ ...value, reasoningEffort: event.target.value === EFFORT_UNSET ? null : event.target.value });
|
|
2069
|
+
},
|
|
2070
|
+
children: [
|
|
2071
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: EFFORT_UNSET, children: "(不指定)" }),
|
|
2072
|
+
efforts.map((effort) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: effort, children: `${EFFORT_LABELS[effort] ?? effort}(${effort})` }, effort))
|
|
2073
|
+
]
|
|
2074
|
+
}
|
|
2075
|
+
)
|
|
2076
|
+
}
|
|
2077
|
+
)
|
|
2078
|
+
] });
|
|
2079
|
+
}
|
|
2080
|
+
function Notices({ store, notices }) {
|
|
2081
|
+
if (notices.length === 0) return null;
|
|
2082
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dshdg-notices", role: "status", "aria-live": "polite", children: notices.map((notice) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: `dshdg-notice dshdg-notice-${notice.level}`, children: [
|
|
2083
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: notice.text }),
|
|
2084
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: () => store.dismissNotice(notice.id), "aria-label": "关闭提示", children: "关闭" })
|
|
2085
|
+
] }, String(notice.id))) });
|
|
2086
|
+
}
|
|
2087
|
+
function AuthorizationPanel({ store, snapshot }) {
|
|
2088
|
+
const enabled = snapshot.status?.delegation?.mode === "switch" ? snapshot.status.delegation.authorized === true : snapshot.settings?.delegationEnabled === true;
|
|
2089
|
+
const busy = snapshot.loading?.delegationSwitch === true;
|
|
2090
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: "dshdg-card", "aria-labelledby": "dshdg-auth-title", children: [
|
|
2091
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-row", children: [
|
|
2092
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { id: "dshdg-auth-title", children: "本机调用授权" }),
|
|
2093
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-spacer" }),
|
|
2094
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Badge, { tone: enabled ? "on" : "off", children: enabled ? "已开启" : "已关闭" })
|
|
2095
|
+
] }),
|
|
2096
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-row", children: [
|
|
2097
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { className: "dshdg-switch", htmlFor: "dshdg-delegation-switch", children: [
|
|
2098
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2099
|
+
"input",
|
|
2100
|
+
{
|
|
2101
|
+
id: "dshdg-delegation-switch",
|
|
2102
|
+
type: "checkbox",
|
|
2103
|
+
role: "switch",
|
|
2104
|
+
checked: enabled,
|
|
2105
|
+
disabled: busy || snapshot.status === null,
|
|
2106
|
+
onChange: (event) => {
|
|
2107
|
+
void store.setDelegationEnabled(event.target.checked);
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2110
|
+
),
|
|
2111
|
+
"允许本机 MCP 调用 DSH 委派"
|
|
2112
|
+
] }),
|
|
2113
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-spacer" }),
|
|
2114
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-hint", children: busy ? "正在更新…" : enabled ? "关闭后会拒绝新任务并停止运行中的任务" : "关闭状态会拒绝所有委派请求" })
|
|
2115
|
+
] })
|
|
2116
|
+
] });
|
|
2117
|
+
}
|
|
2118
|
+
function ProvidersPanel({ store, snapshot }) {
|
|
2119
|
+
const providers = snapshot.draft?.providers ?? [];
|
|
2120
|
+
const selectedIds = new Set(providers.map((provider) => provider.id));
|
|
2121
|
+
const available = (snapshot.nativeProviders ?? []).filter((provider) => !selectedIds.has(provider.id));
|
|
2122
|
+
const [candidateId, setCandidateId] = (0, import_react.useState)("");
|
|
2123
|
+
const nativeProviders = snapshot.nativeProviders ?? [];
|
|
2124
|
+
function isUsed(id) {
|
|
2125
|
+
const draft = snapshot.draft ?? {};
|
|
2126
|
+
const selections = [draft.worker, draft.review, ...(draft.presets ?? []).flatMap((preset) => [preset.worker, preset.review])];
|
|
2127
|
+
for (const block of Object.values(draft.projectOverrides ?? {})) {
|
|
2128
|
+
selections.push(block?.worker, block?.review);
|
|
2129
|
+
}
|
|
2130
|
+
return selections.some((selection) => selection?.providerId === id);
|
|
2131
|
+
}
|
|
2132
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-panel", children: [
|
|
2133
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-row", children: [
|
|
2134
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, { label: "DSH 已启用的接口", htmlFor: "dshdg-native-provider", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("select", { id: "dshdg-native-provider", value: candidateId, onChange: (event) => setCandidateId(event.target.value), children: [
|
|
2135
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "", children: "(选择已有接口)" }),
|
|
2136
|
+
available.map((provider) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: provider.id, children: `${provider.name} (${provider.id})` }, provider.id))
|
|
2137
|
+
] }) }),
|
|
2138
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2139
|
+
"button",
|
|
2140
|
+
{
|
|
2141
|
+
type: "button",
|
|
2142
|
+
className: "dshdg-primary",
|
|
2143
|
+
disabled: candidateId === "",
|
|
2144
|
+
onClick: () => {
|
|
2145
|
+
const provider = nativeProviders.find((entry) => entry.id === candidateId);
|
|
2146
|
+
if (provider === void 0) return;
|
|
2147
|
+
store.editDraft((draft) => {
|
|
2148
|
+
if (draft.providers.some((entry) => entry.id === provider.id)) return;
|
|
2149
|
+
draft.providers.push({
|
|
2150
|
+
id: provider.id,
|
|
2151
|
+
name: provider.name,
|
|
2152
|
+
source: "native",
|
|
2153
|
+
protocol: null,
|
|
2154
|
+
baseUrl: null,
|
|
2155
|
+
credentialRef: null,
|
|
2156
|
+
models: (provider.models ?? []).map((model) => ({ ...model, efforts: [...model.efforts ?? []] }))
|
|
2157
|
+
});
|
|
2158
|
+
});
|
|
2159
|
+
setCandidateId("");
|
|
2160
|
+
},
|
|
2161
|
+
children: "添加所选接口"
|
|
2162
|
+
}
|
|
2163
|
+
),
|
|
2164
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", disabled: snapshot.loading?.nativeProviders === true, onClick: () => {
|
|
2165
|
+
void store.loadNativeProviders();
|
|
2166
|
+
}, children: snapshot.loading?.nativeProviders === true ? "刷新中…" : "刷新接口列表" })
|
|
2167
|
+
] }),
|
|
2168
|
+
snapshot.nativeProvidersError ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-fail", children: snapshot.nativeProvidersError }) : null,
|
|
2169
|
+
nativeProviders.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-muted", children: "DSH 当前没有可选的已启用接口。先在 DSH 的模型设置中配置并启用接口。" }) : null,
|
|
2170
|
+
providers.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-muted", children: "尚未选择委派可用的接口。" }) : null,
|
|
2171
|
+
providers.map((provider) => {
|
|
2172
|
+
const current = nativeProviders.find((entry) => entry.id === provider.id);
|
|
2173
|
+
const legacy = provider.source !== "native";
|
|
2174
|
+
const used = isUsed(provider.id);
|
|
2175
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-item", children: [
|
|
2176
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-item-head", children: [
|
|
2177
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: provider.name }),
|
|
2178
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-mono dshdg-faint", children: provider.id }),
|
|
2179
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Badge, { tone: legacy ? "warn" : "on", children: legacy ? "旧版自定义接口" : "DSH 接口" }),
|
|
2180
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-spacer" }),
|
|
2181
|
+
current !== void 0 && !legacy ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2182
|
+
"button",
|
|
2183
|
+
{
|
|
2184
|
+
type: "button",
|
|
2185
|
+
disabled: snapshot.loading?.nativeProviders === true || (current.models ?? []).length === 0,
|
|
2186
|
+
onClick: () => store.editDraft((draft) => {
|
|
2187
|
+
const target = draft.providers.find((entry) => entry.id === provider.id);
|
|
2188
|
+
if (target === void 0) return;
|
|
2189
|
+
target.name = current.name;
|
|
2190
|
+
target.models = current.models.map((model) => ({ ...model, efforts: [...model.efforts ?? []] }));
|
|
2191
|
+
}),
|
|
2192
|
+
children: "同步模型"
|
|
2193
|
+
}
|
|
2194
|
+
) : null,
|
|
2195
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2196
|
+
"button",
|
|
2197
|
+
{
|
|
2198
|
+
type: "button",
|
|
2199
|
+
className: "dshdg-danger",
|
|
2200
|
+
disabled: used,
|
|
2201
|
+
title: used ? "先将执行、审查和预设中的该接口改为其他接口" : void 0,
|
|
2202
|
+
onClick: () => store.editDraft((draft) => {
|
|
2203
|
+
draft.providers = draft.providers.filter((entry) => entry.id !== provider.id);
|
|
2204
|
+
}),
|
|
2205
|
+
children: "移除"
|
|
2206
|
+
}
|
|
2207
|
+
)
|
|
2208
|
+
] }),
|
|
2209
|
+
legacy ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-hint", children: "此接口来自旧版插件配置。新接口请从上方 DSH 列表选择。" }) : null,
|
|
2210
|
+
current?.error ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-fail", children: current.error }) : null,
|
|
2211
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dshdg-list", children: (current?.models ?? provider.models ?? []).map((model) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-item-head", children: [
|
|
2212
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-mono", children: model.id }),
|
|
2213
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-spacer" }),
|
|
2214
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-hint", children: (model.efforts ?? []).map((effort) => EFFORT_LABELS[effort] ?? effort).join("、") || "未声明思考强度" })
|
|
2215
|
+
] }, model.id)) })
|
|
2216
|
+
] }, provider.id);
|
|
2217
|
+
})
|
|
2218
|
+
] });
|
|
2219
|
+
}
|
|
2220
|
+
function EffectiveSummary({ label, effective, note }) {
|
|
2221
|
+
const worker = effective?.worker ?? {};
|
|
2222
|
+
const review = effective?.review ?? {};
|
|
2223
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-card", children: [
|
|
2224
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h4", { children: label }),
|
|
2225
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("dl", { className: "dshdg-kv", children: [
|
|
2226
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "执行提供方" }),
|
|
2227
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { className: "dshdg-mono", children: worker.providerId ?? worker.providerRoute ?? "(未配置)" }),
|
|
2228
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "执行模型" }),
|
|
2229
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { className: "dshdg-mono", children: worker.model ?? "(未配置)" }),
|
|
2230
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "执行推理强度" }),
|
|
2231
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { className: "dshdg-mono", children: worker.reasoningEffort ?? "(不指定)" }),
|
|
2232
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "超时" }),
|
|
2233
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { children: worker.timeoutSeconds === void 0 ? "—" : `${worker.timeoutSeconds} 秒` }),
|
|
2234
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "最大并发" }),
|
|
2235
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { children: worker.maxParallelism ?? "—" }),
|
|
2236
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "工作区隔离" }),
|
|
2237
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { children: ISOLATION_LABELS[worker.isolation] ?? worker.isolation ?? "—" }),
|
|
2238
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "对话" }),
|
|
2239
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { children: CONVERSATION_POLICY_LABEL }),
|
|
2240
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "附加审查" }),
|
|
2241
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { children: review.enabled === true ? `开启 · ${review.providerId ?? "(未配置)"} / ${review.model ?? "(未配置)"} / ${review.reasoningEffort ?? "不指定"}` : "关闭" }),
|
|
2242
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "静默监控" }),
|
|
2243
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { children: effective?.monitoring === null || effective?.monitoring === void 0 ? "未采集到" : `自检 ${formatDuration(effective.monitoring.selfCheckSeconds * 1e3)} · 提醒 ${formatDuration(effective.monitoring.attentionSeconds * 1e3)}` })
|
|
2244
|
+
] }),
|
|
2245
|
+
note === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-hint", children: note })
|
|
2246
|
+
] });
|
|
2247
|
+
}
|
|
2248
|
+
function PresetsCard({ store, snapshot }) {
|
|
2249
|
+
const draft = snapshot.draft;
|
|
2250
|
+
const presets = draft?.presets ?? [];
|
|
2251
|
+
const overrides = draft?.projectOverrides ?? {};
|
|
2252
|
+
const [presetName, setPresetName] = (0, import_react.useState)("");
|
|
2253
|
+
const [presetId, setPresetId] = (0, import_react.useState)("");
|
|
2254
|
+
const [importText, setImportText] = (0, import_react.useState)("");
|
|
2255
|
+
const [importError, setImportError] = (0, import_react.useState)("");
|
|
2256
|
+
const [exportCopied, setExportCopied] = (0, import_react.useState)("");
|
|
2257
|
+
const [overridePath, setOverridePath] = (0, import_react.useState)("");
|
|
2258
|
+
const [overrideJson, setOverrideJson] = (0, import_react.useState)("");
|
|
2259
|
+
const [overrideError, setOverrideError] = (0, import_react.useState)("");
|
|
2260
|
+
const [editingPath, setEditingPath] = (0, import_react.useState)("");
|
|
2261
|
+
const exportText = (0, import_react.useMemo)(() => draft === null ? "" : exportDocument(draft), [draft]);
|
|
2262
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-card", children: [
|
|
2263
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h4", { children: "预设、导出与项目覆盖" }),
|
|
2264
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-hint", children: "预设只包含执行/审查组合;导出内容全部是非敏感配置,任何密钥都不会出现(密钥只存在宿主的凭据存储里)。 正在运行的任务保留它自己的生效快照,之后的修改不会改写历史。" }),
|
|
2265
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-row", children: [
|
|
2266
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2267
|
+
"input",
|
|
2268
|
+
{
|
|
2269
|
+
type: "text",
|
|
2270
|
+
"aria-label": "预设名称",
|
|
2271
|
+
placeholder: "预设标识,例如 fast-local",
|
|
2272
|
+
value: presetId,
|
|
2273
|
+
onChange: (event) => setPresetId(event.target.value.trim().toLowerCase())
|
|
2274
|
+
}
|
|
2275
|
+
),
|
|
2276
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2277
|
+
"input",
|
|
2278
|
+
{
|
|
2279
|
+
type: "text",
|
|
2280
|
+
"aria-label": "预设显示名",
|
|
2281
|
+
placeholder: "显示名",
|
|
2282
|
+
value: presetName,
|
|
2283
|
+
onChange: (event) => setPresetName(event.target.value)
|
|
2284
|
+
}
|
|
2285
|
+
),
|
|
2286
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2287
|
+
"button",
|
|
2288
|
+
{
|
|
2289
|
+
type: "button",
|
|
2290
|
+
disabled: presetId === "",
|
|
2291
|
+
onClick: () => {
|
|
2292
|
+
store.editDraft((current) => {
|
|
2293
|
+
const existing = current.presets.find((entry) => entry.id === presetId);
|
|
2294
|
+
const snapshotWorker = clone(current.worker);
|
|
2295
|
+
const snapshotReview = current.review?.enabled === true ? clone(current.review) : null;
|
|
2296
|
+
if (existing === void 0) {
|
|
2297
|
+
current.presets.push({
|
|
2298
|
+
id: presetId,
|
|
2299
|
+
name: presetName === "" ? presetId : presetName,
|
|
2300
|
+
worker: snapshotWorker,
|
|
2301
|
+
...snapshotReview === null ? {} : { review: snapshotReview }
|
|
2302
|
+
});
|
|
2303
|
+
} else {
|
|
2304
|
+
existing.name = presetName === "" ? existing.name : presetName;
|
|
2305
|
+
existing.worker = snapshotWorker;
|
|
2306
|
+
existing.review = snapshotReview;
|
|
2307
|
+
}
|
|
2308
|
+
});
|
|
2309
|
+
setPresetId("");
|
|
2310
|
+
setPresetName("");
|
|
2311
|
+
},
|
|
2312
|
+
children: "用当前设置保存预设"
|
|
2313
|
+
}
|
|
2314
|
+
)
|
|
2315
|
+
] }),
|
|
2316
|
+
presets.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-faint", children: "还没有预设。" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dshdg-list", children: presets.map((preset) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dshdg-item", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-item-head", children: [
|
|
2317
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: preset.name }),
|
|
2318
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-mono dshdg-faint", children: preset.id }),
|
|
2319
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-spacer" }),
|
|
2320
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2321
|
+
"button",
|
|
2322
|
+
{
|
|
2323
|
+
type: "button",
|
|
2324
|
+
onClick: () => {
|
|
2325
|
+
store.editDraft((current) => {
|
|
2326
|
+
if (preset.worker !== null && preset.worker !== void 0) current.worker = { ...preset.worker };
|
|
2327
|
+
if (preset.review !== null && preset.review !== void 0) current.review = { ...preset.review };
|
|
2328
|
+
});
|
|
2329
|
+
},
|
|
2330
|
+
children: "应用到草稿"
|
|
2331
|
+
}
|
|
2332
|
+
),
|
|
2333
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2334
|
+
"button",
|
|
2335
|
+
{
|
|
2336
|
+
type: "button",
|
|
2337
|
+
className: "dshdg-danger",
|
|
2338
|
+
onClick: () => {
|
|
2339
|
+
store.editDraft((current) => {
|
|
2340
|
+
current.presets = current.presets.filter((entry) => entry.id !== preset.id);
|
|
2341
|
+
});
|
|
2342
|
+
},
|
|
2343
|
+
children: "删除"
|
|
2344
|
+
}
|
|
2345
|
+
)
|
|
2346
|
+
] }) }, preset.id)) }),
|
|
2347
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, { label: "导出(非敏感)", htmlFor: "dshdg-export", hint: "复制这段文本即可备份或在另一台机器恢复。", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("textarea", { id: "dshdg-export", readOnly: true, rows: 6, value: exportText }) }),
|
|
2348
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-row", children: [
|
|
2349
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2350
|
+
"button",
|
|
2351
|
+
{
|
|
2352
|
+
type: "button",
|
|
2353
|
+
onClick: async () => {
|
|
2354
|
+
try {
|
|
2355
|
+
await globalThis.navigator?.clipboard?.writeText(exportText);
|
|
2356
|
+
setExportCopied("已复制");
|
|
2357
|
+
} catch {
|
|
2358
|
+
setExportCopied("无法访问剪贴板,请手动复制");
|
|
2359
|
+
}
|
|
2360
|
+
},
|
|
2361
|
+
children: "复制导出内容"
|
|
2362
|
+
}
|
|
2363
|
+
),
|
|
2364
|
+
exportCopied === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-hint", children: exportCopied }),
|
|
2365
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-spacer" }),
|
|
2366
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2367
|
+
"button",
|
|
2368
|
+
{
|
|
2369
|
+
type: "button",
|
|
2370
|
+
onClick: async () => {
|
|
2371
|
+
try {
|
|
2372
|
+
const text = await globalThis.navigator?.clipboard?.readText?.();
|
|
2373
|
+
if (typeof text === "string") setImportText(text);
|
|
2374
|
+
} catch {
|
|
2375
|
+
setExportCopied("无法访问剪贴板,请手动粘贴");
|
|
2376
|
+
}
|
|
2377
|
+
},
|
|
2378
|
+
children: "从剪贴板粘贴"
|
|
2379
|
+
}
|
|
2380
|
+
)
|
|
2381
|
+
] }),
|
|
2382
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2383
|
+
Field,
|
|
2384
|
+
{
|
|
2385
|
+
label: "导入(覆盖草稿,保存后才生效)",
|
|
2386
|
+
htmlFor: "dshdg-import",
|
|
2387
|
+
hint: "只接受本插件导出的非敏感文档;包含密钥的字段会被宿主拒绝。",
|
|
2388
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2389
|
+
"textarea",
|
|
2390
|
+
{
|
|
2391
|
+
id: "dshdg-import",
|
|
2392
|
+
rows: 6,
|
|
2393
|
+
value: importText,
|
|
2394
|
+
onChange: (event) => {
|
|
2395
|
+
setImportText(event.target.value);
|
|
2396
|
+
setImportError("");
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
)
|
|
2400
|
+
}
|
|
2401
|
+
),
|
|
2402
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-row", children: [
|
|
2403
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2404
|
+
"button",
|
|
2405
|
+
{
|
|
2406
|
+
type: "button",
|
|
2407
|
+
onClick: () => {
|
|
2408
|
+
try {
|
|
2409
|
+
const parsed = JSON.parse(importText);
|
|
2410
|
+
const next = draftFromSettings(parsed);
|
|
2411
|
+
store.editDraft((current) => {
|
|
2412
|
+
current.providers = next.providers;
|
|
2413
|
+
current.worker = next.worker;
|
|
2414
|
+
current.review = next.review;
|
|
2415
|
+
current.authorization = next.authorization;
|
|
2416
|
+
current.projectOverrides = next.projectOverrides;
|
|
2417
|
+
current.presets = next.presets;
|
|
2418
|
+
});
|
|
2419
|
+
setImportError("");
|
|
2420
|
+
} catch (error) {
|
|
2421
|
+
setImportError(`无法解析:${String(error?.message ?? error).slice(0, 160)}`);
|
|
2422
|
+
}
|
|
2423
|
+
},
|
|
2424
|
+
disabled: importText.trim() === "",
|
|
2425
|
+
children: "解析并应用到草稿"
|
|
2426
|
+
}
|
|
2427
|
+
),
|
|
2428
|
+
importError === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-fail", children: importError })
|
|
2429
|
+
] }),
|
|
2430
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h4", { children: "项目覆盖" }),
|
|
2431
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-hint", children: "为某个绝对路径单独指定执行/审查覆盖;任务生效值会显示实际用了哪一层。" }),
|
|
2432
|
+
Object.keys(overrides).length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-faint", children: "还没有项目覆盖。" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dshdg-list", children: Object.entries(overrides).map(([path, block]) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-item", children: [
|
|
2433
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-item-head", children: [
|
|
2434
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-mono", children: path }),
|
|
2435
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-spacer" }),
|
|
2436
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2437
|
+
"button",
|
|
2438
|
+
{
|
|
2439
|
+
type: "button",
|
|
2440
|
+
onClick: () => {
|
|
2441
|
+
setEditingPath(path);
|
|
2442
|
+
setOverridePath(path);
|
|
2443
|
+
setOverrideJson(`${JSON.stringify(block, null, 2)}
|
|
2444
|
+
`);
|
|
2445
|
+
setOverrideError("");
|
|
2446
|
+
},
|
|
2447
|
+
children: "编辑"
|
|
2448
|
+
}
|
|
2449
|
+
),
|
|
2450
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2451
|
+
"button",
|
|
2452
|
+
{
|
|
2453
|
+
type: "button",
|
|
2454
|
+
className: "dshdg-danger",
|
|
2455
|
+
onClick: () => {
|
|
2456
|
+
store.editDraft((current) => {
|
|
2457
|
+
const copy = { ...current.projectOverrides };
|
|
2458
|
+
delete copy[path];
|
|
2459
|
+
current.projectOverrides = copy;
|
|
2460
|
+
});
|
|
2461
|
+
if (editingPath === path) setEditingPath("");
|
|
2462
|
+
},
|
|
2463
|
+
children: "删除"
|
|
2464
|
+
}
|
|
2465
|
+
)
|
|
2466
|
+
] }),
|
|
2467
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", { className: "dshdg-pre", children: boundedText(block, 4e3) })
|
|
2468
|
+
] }, path)) }),
|
|
2469
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2470
|
+
Field,
|
|
2471
|
+
{
|
|
2472
|
+
label: editingPath === "" ? "新增覆盖:绝对路径" : `编辑覆盖:${editingPath}`,
|
|
2473
|
+
htmlFor: "dshdg-override-path",
|
|
2474
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2475
|
+
"input",
|
|
2476
|
+
{
|
|
2477
|
+
id: "dshdg-override-path",
|
|
2478
|
+
type: "text",
|
|
2479
|
+
value: overridePath,
|
|
2480
|
+
readOnly: editingPath !== "",
|
|
2481
|
+
placeholder: "C:\\\\work\\\\project",
|
|
2482
|
+
onChange: (event) => setOverridePath(event.target.value)
|
|
2483
|
+
}
|
|
2484
|
+
)
|
|
2485
|
+
}
|
|
2486
|
+
),
|
|
2487
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2488
|
+
Field,
|
|
2489
|
+
{
|
|
2490
|
+
label: `覆盖内容(JSON,仅允许 worker / review)`,
|
|
2491
|
+
htmlFor: "dshdg-override-json",
|
|
2492
|
+
hint: '例如 {"worker":{"model":"deepseek-chat","reasoningEffort":"high"},"review":{"enabled":false}}',
|
|
2493
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2494
|
+
"textarea",
|
|
2495
|
+
{
|
|
2496
|
+
id: "dshdg-override-json",
|
|
2497
|
+
rows: 5,
|
|
2498
|
+
value: overrideJson,
|
|
2499
|
+
onChange: (event) => {
|
|
2500
|
+
setOverrideJson(event.target.value);
|
|
2501
|
+
setOverrideError("");
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
)
|
|
2505
|
+
}
|
|
2506
|
+
),
|
|
2507
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-row", children: [
|
|
2508
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2509
|
+
"button",
|
|
2510
|
+
{
|
|
2511
|
+
type: "button",
|
|
2512
|
+
disabled: overridePath.trim() === "",
|
|
2513
|
+
onClick: () => {
|
|
2514
|
+
let parsed;
|
|
2515
|
+
try {
|
|
2516
|
+
parsed = overrideJson.trim() === "" ? {} : JSON.parse(overrideJson);
|
|
2517
|
+
} catch (error) {
|
|
2518
|
+
setOverrideError(`无法解析:${String(error?.message ?? error).slice(0, 160)}`);
|
|
2519
|
+
return;
|
|
2520
|
+
}
|
|
2521
|
+
const unknown = Object.keys(parsed).filter((key) => key !== "worker" && key !== "review");
|
|
2522
|
+
if (unknown.length > 0) {
|
|
2523
|
+
setOverrideError(`不支持的字段:${unknown.join("、")}`);
|
|
2524
|
+
return;
|
|
2525
|
+
}
|
|
2526
|
+
setOverrideError("");
|
|
2527
|
+
const path = overridePath.trim().replace(/[\\/]+$/, "");
|
|
2528
|
+
store.editDraft((current) => {
|
|
2529
|
+
const copy = { ...current.projectOverrides };
|
|
2530
|
+
if (editingPath !== "" && editingPath !== path) delete copy[editingPath];
|
|
2531
|
+
copy[path] = parsed;
|
|
2532
|
+
current.projectOverrides = copy;
|
|
2533
|
+
});
|
|
2534
|
+
setEditingPath("");
|
|
2535
|
+
setOverrideJson("");
|
|
2536
|
+
setOverridePath("");
|
|
2537
|
+
},
|
|
2538
|
+
children: editingPath === "" ? "添加覆盖" : "保存覆盖"
|
|
2539
|
+
}
|
|
2540
|
+
),
|
|
2541
|
+
editingPath === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: () => {
|
|
2542
|
+
setEditingPath("");
|
|
2543
|
+
setOverrideJson("");
|
|
2544
|
+
setOverridePath("");
|
|
2545
|
+
setOverrideError("");
|
|
2546
|
+
}, children: "取消编辑" }),
|
|
2547
|
+
overrideError === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-fail", children: overrideError })
|
|
2548
|
+
] })
|
|
2549
|
+
] });
|
|
2550
|
+
}
|
|
2551
|
+
function MonitoringCard({ store, snapshot }) {
|
|
2552
|
+
const draft = snapshot.draft;
|
|
2553
|
+
const monitoring = monitoringOf(draft);
|
|
2554
|
+
const saved = monitoringOf(snapshot.settings);
|
|
2555
|
+
const [saving, setSaving] = (0, import_react.useState)(false);
|
|
2556
|
+
const problems = precheckMonitoring(monitoring);
|
|
2557
|
+
const dirty = monitoring.selfCheckSeconds !== saved.selfCheckSeconds || monitoring.attentionSeconds !== saved.attentionSeconds;
|
|
2558
|
+
const edit = (field, raw) => {
|
|
2559
|
+
store.editDraft((current) => {
|
|
2560
|
+
current.monitoring = { ...monitoringOf(current), [field]: minutesToSeconds(raw) };
|
|
2561
|
+
});
|
|
2562
|
+
};
|
|
2563
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-card", "data-dshdg-monitoring": "", children: [
|
|
2564
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h4", { children: "进阶:静默监控间隔" }),
|
|
2565
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { className: "dshdg-hint", children: [
|
|
2566
|
+
"任务长时间没有新输出时,插件自己会看一眼执行器还在不在(程序自检),再过一段时间才提醒你。",
|
|
2567
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: "这些检查完全在本机进行,不会调用任何大模型,也不消耗 token。" })
|
|
2568
|
+
] }),
|
|
2569
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-grid", children: [
|
|
2570
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2571
|
+
Field,
|
|
2572
|
+
{
|
|
2573
|
+
label: "程序自检间隔(分钟)",
|
|
2574
|
+
htmlFor: "dshdg-monitoring-selfcheck",
|
|
2575
|
+
hint: `${LIMITS.selfCheckSecondsMin / 60}–${LIMITS.selfCheckSecondsMax / 60} 分钟;存成整秒(当前 ${monitoring.selfCheckSeconds} 秒)`,
|
|
2576
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2577
|
+
"input",
|
|
2578
|
+
{
|
|
2579
|
+
id: "dshdg-monitoring-selfcheck",
|
|
2580
|
+
type: "number",
|
|
2581
|
+
inputMode: "decimal",
|
|
2582
|
+
min: LIMITS.selfCheckSecondsMin / 60,
|
|
2583
|
+
max: LIMITS.selfCheckSecondsMax / 60,
|
|
2584
|
+
step: 0.5,
|
|
2585
|
+
value: String(Number.isFinite(secondsToMinutes(monitoring.selfCheckSeconds)) ? secondsToMinutes(monitoring.selfCheckSeconds) : ""),
|
|
2586
|
+
onChange: (event) => {
|
|
2587
|
+
const raw = event.target.value;
|
|
2588
|
+
edit("selfCheckSeconds", raw === "" ? "" : raw);
|
|
2589
|
+
}
|
|
2590
|
+
}
|
|
2591
|
+
)
|
|
2592
|
+
}
|
|
2593
|
+
),
|
|
2594
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2595
|
+
Field,
|
|
2596
|
+
{
|
|
2597
|
+
label: "提醒你的间隔(分钟)",
|
|
2598
|
+
htmlFor: "dshdg-monitoring-attention",
|
|
2599
|
+
hint: `${LIMITS.attentionSecondsMin / 60}–${LIMITS.attentionSecondsMax / 60} 分钟,且必须大于自检间隔;存成整秒(当前 ${monitoring.attentionSeconds} 秒)`,
|
|
2600
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2601
|
+
"input",
|
|
2602
|
+
{
|
|
2603
|
+
id: "dshdg-monitoring-attention",
|
|
2604
|
+
type: "number",
|
|
2605
|
+
inputMode: "decimal",
|
|
2606
|
+
min: LIMITS.attentionSecondsMin / 60,
|
|
2607
|
+
max: LIMITS.attentionSecondsMax / 60,
|
|
2608
|
+
step: 0.5,
|
|
2609
|
+
value: String(Number.isFinite(secondsToMinutes(monitoring.attentionSeconds)) ? secondsToMinutes(monitoring.attentionSeconds) : ""),
|
|
2610
|
+
onChange: (event) => {
|
|
2611
|
+
const raw = event.target.value;
|
|
2612
|
+
edit("attentionSeconds", raw === "" ? "" : raw);
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
)
|
|
2616
|
+
}
|
|
2617
|
+
)
|
|
2618
|
+
] }),
|
|
2619
|
+
problems.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-fail", children: problems.join(";") }),
|
|
2620
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("ul", { className: "dshdg-hint", children: [
|
|
2621
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: "「没有新进展」本身不等于失败:插件不会因为安静、也不会因为单个工具跑得久就判定任务失败。" }),
|
|
2622
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: "只有确实没有进展、并且超过「提醒你的间隔」之后,才会把这件事报告给派工方。" }),
|
|
2623
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { children: [
|
|
2624
|
+
"修改只影响",
|
|
2625
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: "之后新提交" }),
|
|
2626
|
+
"的任务;已经运行的任务保留它开始时的那份间隔快照。"
|
|
2627
|
+
] }),
|
|
2628
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: "程序自检只读取本机已有的事实(任务是否还在、当前阶段、有没有待决定的调用、正在跑哪个工具),不读取代码差异,也不会读取你的文件内容。" })
|
|
2629
|
+
] }),
|
|
2630
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-row", children: [
|
|
2631
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2632
|
+
"button",
|
|
2633
|
+
{
|
|
2634
|
+
type: "button",
|
|
2635
|
+
disabled: !dirty || saving || snapshot.loading?.monitoring === true || problems.length > 0,
|
|
2636
|
+
onClick: async () => {
|
|
2637
|
+
setSaving(true);
|
|
2638
|
+
try {
|
|
2639
|
+
await store.saveMonitoring(monitoring);
|
|
2640
|
+
} finally {
|
|
2641
|
+
setSaving(false);
|
|
2642
|
+
}
|
|
2643
|
+
},
|
|
2644
|
+
children: snapshot.loading?.monitoring === true || saving ? "保存中…" : "只保存监控间隔"
|
|
2645
|
+
}
|
|
2646
|
+
),
|
|
2647
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-hint", children: dirty ? "与已保存的值不同。" : `已保存:自检 ${saved.selfCheckSeconds} 秒,提醒 ${saved.attentionSeconds} 秒。` })
|
|
2648
|
+
] }),
|
|
2649
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-hint", children: "也可以点页面底部的「保存设置」一起保存;保存的是同一个设置文档。" })
|
|
2650
|
+
] });
|
|
2651
|
+
}
|
|
2652
|
+
function ExecutionPanel({ store, snapshot }) {
|
|
2653
|
+
const draft = snapshot.draft;
|
|
2654
|
+
const providers = draft?.providers ?? [];
|
|
2655
|
+
const worker = draft?.worker ?? {};
|
|
2656
|
+
const preview = draft === null ? null : previewEffective(draft, null);
|
|
2657
|
+
const served = snapshot.catalog?.effective ?? null;
|
|
2658
|
+
if (draft === null) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-faint", children: "正在读取设置…" });
|
|
2659
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-panel", children: [
|
|
2660
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2661
|
+
SelectionFields,
|
|
2662
|
+
{
|
|
2663
|
+
providers,
|
|
2664
|
+
idPrefix: "dshdg-worker",
|
|
2665
|
+
value: { providerId: worker.providerId ?? null, model: worker.model ?? null, reasoningEffort: worker.reasoningEffort ?? null },
|
|
2666
|
+
onChange: (next) => {
|
|
2667
|
+
store.editDraft((current) => {
|
|
2668
|
+
current.worker.providerId = next.providerId;
|
|
2669
|
+
current.worker.model = next.model;
|
|
2670
|
+
current.worker.reasoningEffort = next.reasoningEffort;
|
|
2671
|
+
});
|
|
2672
|
+
}
|
|
2673
|
+
}
|
|
2674
|
+
),
|
|
2675
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-grid", children: [
|
|
2676
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2677
|
+
IntegerField,
|
|
2678
|
+
{
|
|
2679
|
+
id: "dshdg-worker-timeout",
|
|
2680
|
+
label: "超时(秒)",
|
|
2681
|
+
value: worker.timeoutSeconds,
|
|
2682
|
+
min: LIMITS.timeoutSecondsMin,
|
|
2683
|
+
max: LIMITS.timeoutSecondsMax,
|
|
2684
|
+
hint: `${LIMITS.timeoutSecondsMin}–${LIMITS.timeoutSecondsMax}`,
|
|
2685
|
+
onChange: (value) => {
|
|
2686
|
+
store.editDraft((current) => {
|
|
2687
|
+
current.worker.timeoutSeconds = value;
|
|
2688
|
+
});
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2691
|
+
),
|
|
2692
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2693
|
+
IntegerField,
|
|
2694
|
+
{
|
|
2695
|
+
id: "dshdg-worker-parallelism",
|
|
2696
|
+
label: "最大并发",
|
|
2697
|
+
value: worker.maxParallelism,
|
|
2698
|
+
min: LIMITS.maxParallelismMin,
|
|
2699
|
+
max: LIMITS.maxParallelismMax,
|
|
2700
|
+
hint: `${LIMITS.maxParallelismMin}–${LIMITS.maxParallelismMax},超出会被拒绝而不是自动调整`,
|
|
2701
|
+
onChange: (value) => {
|
|
2702
|
+
store.editDraft((current) => {
|
|
2703
|
+
current.worker.maxParallelism = value;
|
|
2704
|
+
});
|
|
2705
|
+
}
|
|
2706
|
+
}
|
|
2707
|
+
),
|
|
2708
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, { label: "工作区隔离", htmlFor: "dshdg-worker-isolation", hint: "默认独立工作树;共享工作区需要你明确选择。", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2709
|
+
"select",
|
|
2710
|
+
{
|
|
2711
|
+
id: "dshdg-worker-isolation",
|
|
2712
|
+
value: worker.isolation ?? ISOLATION_MODES[0],
|
|
2713
|
+
onChange: (event) => {
|
|
2714
|
+
store.editDraft((current) => {
|
|
2715
|
+
current.worker.isolation = event.target.value;
|
|
2716
|
+
});
|
|
2717
|
+
},
|
|
2718
|
+
children: ISOLATION_MODES.map((mode) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: mode, children: ISOLATION_LABELS[mode] }, mode))
|
|
2719
|
+
}
|
|
2720
|
+
) }),
|
|
2721
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2722
|
+
Field,
|
|
2723
|
+
{
|
|
2724
|
+
label: "对话",
|
|
2725
|
+
htmlFor: "dshdg-conversation-policy",
|
|
2726
|
+
hint: "固定的按任务策略:每个新提交在执行目录对应的 Workspace 里新开一条会话;只有显式带 continueFromTaskId 的跟进任务才续接那一条会话。",
|
|
2727
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { id: "dshdg-conversation-policy", className: "dshdg-hint", children: CONVERSATION_POLICY_LABEL })
|
|
2728
|
+
}
|
|
2729
|
+
)
|
|
2730
|
+
] }),
|
|
2731
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-hint", children: "不会自动回退到别的模型,也不会隐式使用 Harness 默认模型:选中的组合不可路由时任务直接拒绝。" }),
|
|
2732
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { className: "dshdg-hint", children: [
|
|
2733
|
+
"目录级的「复用上一对话」设置已移除:它曾经让同目录的第二个任务自动接续上一次会话,现在不会发生。 需要续接时由派工方在 ",
|
|
2734
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { children: "delegate_submit" }),
|
|
2735
|
+
" 里带上 ",
|
|
2736
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { children: "continueFromTaskId" }),
|
|
2737
|
+
", 指向要继续的那条任务历史;隔离工作树的跟进任务必须回到同一棵工作树,否则会被拒绝。"
|
|
2738
|
+
] }),
|
|
2739
|
+
preview === null ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2740
|
+
EffectiveSummary,
|
|
2741
|
+
{
|
|
2742
|
+
label: "保存后生效(当前草稿预览)",
|
|
2743
|
+
effective: preview,
|
|
2744
|
+
note: preview.applied.length === 0 ? "未命中项目覆盖。" : `已应用:${preview.applied.join(";")}`
|
|
2745
|
+
}
|
|
2746
|
+
),
|
|
2747
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(MonitoringCard, { store, snapshot }),
|
|
2748
|
+
served === null ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-faint", children: "宿主尚未回报实际生效值(模型目录不可用或尚未加载)。" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2749
|
+
EffectiveSummary,
|
|
2750
|
+
{
|
|
2751
|
+
label: "宿主当前实际生效",
|
|
2752
|
+
effective: served,
|
|
2753
|
+
note: "这是任务真正会用的配置快照;模型目录无法解析时会在这里显示拒绝原因。"
|
|
2754
|
+
}
|
|
2755
|
+
),
|
|
2756
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(PresetsCard, { store, snapshot })
|
|
2757
|
+
] });
|
|
2758
|
+
}
|
|
2759
|
+
function ReviewPanel({ store, snapshot }) {
|
|
2760
|
+
const draft = snapshot.draft;
|
|
2761
|
+
const providers = draft?.providers ?? [];
|
|
2762
|
+
const review = draft?.review ?? { enabled: false };
|
|
2763
|
+
const enabled = review.enabled === true;
|
|
2764
|
+
const worker = draft?.worker ?? {};
|
|
2765
|
+
const sameRoute = enabled && review.providerId === (worker.providerId ?? null) && review.model === (worker.model ?? null);
|
|
2766
|
+
if (draft === null) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-faint", children: "正在读取设置…" });
|
|
2767
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-panel", children: [
|
|
2768
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-card", children: [
|
|
2769
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-row", children: [
|
|
2770
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { htmlFor: "dshdg-review-enabled", children: [
|
|
2771
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2772
|
+
"input",
|
|
2773
|
+
{
|
|
2774
|
+
id: "dshdg-review-enabled",
|
|
2775
|
+
type: "checkbox",
|
|
2776
|
+
checked: enabled,
|
|
2777
|
+
onChange: (event) => {
|
|
2778
|
+
store.editDraft((current) => {
|
|
2779
|
+
current.review.enabled = event.target.checked;
|
|
2780
|
+
});
|
|
2781
|
+
}
|
|
2782
|
+
}
|
|
2783
|
+
),
|
|
2784
|
+
" ",
|
|
2785
|
+
"启用附加模型审查(默认关闭)"
|
|
2786
|
+
] }),
|
|
2787
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-spacer" }),
|
|
2788
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Badge, { tone: enabled ? "on" : "off", children: enabled ? "已启用" : "关闭" })
|
|
2789
|
+
] }),
|
|
2790
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { className: "dshdg-muted", children: [
|
|
2791
|
+
"附加审查是独立的只读检查:它读交付的 diff 与证据,给出建议,但",
|
|
2792
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: "不能" }),
|
|
2793
|
+
"代替宿主验收、不能修改文件、 也不会触发自动修复循环。它和本机调用开关相互独立。"
|
|
2794
|
+
] }),
|
|
2795
|
+
sameRoute ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-fail", children: "审查与执行的提供方/模型相同,独立性问题无法保证;建议换一个模型。宿主可能会拒绝这种组合。" }) : null
|
|
2796
|
+
] }),
|
|
2797
|
+
enabled ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2798
|
+
SelectionFields,
|
|
2799
|
+
{
|
|
2800
|
+
providers,
|
|
2801
|
+
idPrefix: "dshdg-review",
|
|
2802
|
+
value: {
|
|
2803
|
+
providerId: review.providerId ?? null,
|
|
2804
|
+
model: review.model ?? null,
|
|
2805
|
+
reasoningEffort: review.reasoningEffort ?? null
|
|
2806
|
+
},
|
|
2807
|
+
onChange: (next) => {
|
|
2808
|
+
store.editDraft((current) => {
|
|
2809
|
+
current.review.providerId = next.providerId;
|
|
2810
|
+
current.review.model = next.model;
|
|
2811
|
+
if ("reasoningEffort" in next) current.review.reasoningEffort = next.reasoningEffort;
|
|
2812
|
+
});
|
|
2813
|
+
}
|
|
2814
|
+
}
|
|
2815
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-faint", children: "关闭时不创建审查代理,也不发出任何审查请求。" })
|
|
2816
|
+
] });
|
|
2817
|
+
}
|
|
2818
|
+
function TaskDetail({ store, task }) {
|
|
2819
|
+
const outcome = taskOutcome(task);
|
|
2820
|
+
const files = changedFiles(task);
|
|
2821
|
+
const progress = taskProgress(task);
|
|
2822
|
+
const activity = taskActivity(task);
|
|
2823
|
+
const worker = task.effective?.worker ?? {};
|
|
2824
|
+
const review = task.review ?? null;
|
|
2825
|
+
const reviewState = review === null ? "not_run" : review.state ?? "not_run";
|
|
2826
|
+
const diff = task.diff ?? null;
|
|
2827
|
+
const execution = task.execution ?? null;
|
|
2828
|
+
const error = task.error ?? execution?.error ?? null;
|
|
2829
|
+
const permission = permissionSummary(task);
|
|
2830
|
+
const pending = pendingPermission(task);
|
|
2831
|
+
const evidence = Array.isArray(task.permission?.evidence) ? task.permission.evidence : [];
|
|
2832
|
+
const badgeTone = isAwaitingPermission(task) ? "warn" : task.state === "awaiting-host-review" ? "warn" : task.state === "failed" ? "warn" : "off";
|
|
2833
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-item", children: [
|
|
2834
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-item-head", children: [
|
|
2835
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { className: "dshdg-mono", children: task.taskId }),
|
|
2836
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Badge, { tone: badgeTone, children: taskStateLabel(task.state) }),
|
|
2837
|
+
isAwaitingPermission(task) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Badge, { tone: "warn", children: PERMISSION_STATE_LABELS.pending }) : null,
|
|
2838
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-spacer" }),
|
|
2839
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
2840
|
+
"button",
|
|
2841
|
+
{
|
|
2842
|
+
type: "button",
|
|
2843
|
+
className: "dshdg-danger",
|
|
2844
|
+
disabled: !isCancellable(task.state),
|
|
2845
|
+
onClick: () => {
|
|
2846
|
+
void store.cancelTask(task.taskId);
|
|
2847
|
+
},
|
|
2848
|
+
children: "取消任务"
|
|
2849
|
+
}
|
|
2850
|
+
)
|
|
2851
|
+
] }),
|
|
2852
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-muted", children: outcome.note }),
|
|
2853
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-card", "data-dshdg-task-progress": "", children: [
|
|
2854
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h4", { children: "进展" }),
|
|
2855
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-mono", children: progress.headline }),
|
|
2856
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-hint", children: progress.detail })
|
|
2857
|
+
] }),
|
|
2858
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("dl", { className: "dshdg-kv", children: [
|
|
2859
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "生效提供方" }),
|
|
2860
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { className: "dshdg-mono", children: worker.providerId ?? "—" }),
|
|
2861
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "生效模型" }),
|
|
2862
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { className: "dshdg-mono", children: worker.model ?? "—" }),
|
|
2863
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "推理强度" }),
|
|
2864
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { className: "dshdg-mono", children: worker.reasoningEffort ?? "(不指定)" }),
|
|
2865
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "工作区" }),
|
|
2866
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { className: "dshdg-mono", children: task.workspacePath ?? "—" }),
|
|
2867
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "隔离" }),
|
|
2868
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { children: ISOLATION_LABELS[task.isolation ?? worker.isolation] ?? task.isolation ?? worker.isolation ?? "—" }),
|
|
2869
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "对话" }),
|
|
2870
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { children: execution?.conversation === null || execution?.conversation === void 0 ? task.continueFromTaskId === null || task.continueFromTaskId === void 0 ? "(未放置对话)" : `(未放置对话;本任务声明续接 ${task.continueFromTaskId})` : execution.conversation.reused === true ? `续接 ${execution.conversation.continuedFromTaskId ?? "上一任务"} · 工作区 ${execution.conversation.workspaceId ?? "—"}` : `新开 · 工作区 ${execution.conversation.workspaceId ?? "—"}` }),
|
|
2871
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "阶段" }),
|
|
2872
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { children: taskPhaseLabel(task.phase) }),
|
|
2873
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "最近进展" }),
|
|
2874
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { children: activity === null || activity.lastActivityAt === null ? "未采集到" : `${formatTime(activity.lastActivityAt)}(距上次进展 ${formatDuration(activity.idleForMs)})` }),
|
|
2875
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "当前工具" }),
|
|
2876
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { children: activity === null || activity.currentTool === null ? activity === null ? "未采集到" : "当前没有正在运行的工具" : `${activity.currentTool.name} · 已运行 ${formatDuration(activity.currentTool.elapsedMs)}` }),
|
|
2877
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "无进展诊断" }),
|
|
2878
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { children: activity === null || activity.selfCheck === null || activity.selfCheck.verdict === null ? activity === null ? "未采集到" : "尚未触发程序自检(安静时间还没到自检间隔)" : `${SELF_CHECK_LABELS[activity.selfCheck.verdict] ?? activity.selfCheck.verdict}` + (activity.selfCheck.checkedAt === null ? "" : `(${formatTime(activity.selfCheck.checkedAt)})`) }),
|
|
2879
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "监控间隔" }),
|
|
2880
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { children: activity === null || activity.selfCheckSeconds === null ? "未采集到" : `自检 ${formatDuration(activity.selfCheckSeconds * 1e3)} · 提醒 ${formatDuration((activity.attentionSeconds ?? 0) * 1e3)}` }),
|
|
2881
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "创建" }),
|
|
2882
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { children: formatTime(task.createdAt) }),
|
|
2883
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "结束" }),
|
|
2884
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { children: formatTime(task.endedAt) }),
|
|
2885
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "用量" }),
|
|
2886
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { children: execution?.usage === null || execution?.usage === void 0 ? "不可用" : boundedText(execution.usage, 600) }),
|
|
2887
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "附加审查" }),
|
|
2888
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("dd", { children: [
|
|
2889
|
+
REVIEW_STATE_LABELS[reviewState] ?? reviewState,
|
|
2890
|
+
review?.verdict === null || review?.verdict === void 0 ? "" : ` · ${REVIEW_VERDICT_LABELS[review.verdict] ?? review.verdict}`
|
|
2891
|
+
] }),
|
|
2892
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "宿主验收" }),
|
|
2893
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { children: task.hostAcceptance === null || task.hostAcceptance === void 0 ? "未记录(插件不会自行验收)" : "已由宿主记录" })
|
|
2894
|
+
] }),
|
|
2895
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h4", { children: "改动文件" }),
|
|
2896
|
+
files === null ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-faint", children: "宿主未回报可识别的文件摘要,请以下方原始 diff 为准。" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", { className: "dshdg-mono", children: files.map((file) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: file }, file)) }),
|
|
2897
|
+
diff?.patchWithheld === true ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-fail", children: "宿主判定这批改动不宜展示内容(命中敏感路径或超出上限),只给出说明。" }) : null,
|
|
2898
|
+
diff?.patchTruncated === true ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-hint", children: "diff 已截断。" }) : null,
|
|
2899
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h4", { children: "diff" }),
|
|
2900
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", { className: "dshdg-pre", children: boundedText(diff?.patchText ?? "(无 diff 内容)") }),
|
|
2901
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h4", { children: "验证证据" }),
|
|
2902
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", { className: "dshdg-pre", children: boundedText(execution?.text ?? execution ?? "(无验证证据)") }),
|
|
2903
|
+
error === null ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
2904
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h4", { children: "错误" }),
|
|
2905
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", { className: "dshdg-pre", children: boundedText(error, 4e3) })
|
|
2906
|
+
] }),
|
|
2907
|
+
review?.text === void 0 || review?.text === null || review.text === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
2908
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h4", { children: "审查发现" }),
|
|
2909
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", { className: "dshdg-pre", children: boundedText(review.text, 8e3) })
|
|
2910
|
+
] }),
|
|
2911
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h4", { children: "本次调用授权" }),
|
|
2912
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: isAwaitingPermission(task) ? "dshdg-hint" : "dshdg-faint", children: permission.note }),
|
|
2913
|
+
permission.detail === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-faint dshdg-mono", children: permission.detail }),
|
|
2914
|
+
pending === null ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("dl", { className: "dshdg-kv", children: [
|
|
2915
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "工具" }),
|
|
2916
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { className: "dshdg-mono", children: pending.toolName ?? "—" }),
|
|
2917
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "调用编号" }),
|
|
2918
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { className: "dshdg-mono", children: pending.callId ?? "—" }),
|
|
2919
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "请求的权限" }),
|
|
2920
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { className: "dshdg-mono", children: pending.requestedAccess?.mode ?? "(该工具自身的调用)" }),
|
|
2921
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "实际参数(已脱敏)" }),
|
|
2922
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { className: "dshdg-mono", children: boundedText(pending.arguments ?? "(不可读)", 2e3) }),
|
|
2923
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "工作进程给出的理由" }),
|
|
2924
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("dd", { children: [
|
|
2925
|
+
pending.reason ?? "(未给出)",
|
|
2926
|
+
"(这是工作进程自己的说法,不是被决定的操作本身)"
|
|
2927
|
+
] }),
|
|
2928
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { children: "截止" }),
|
|
2929
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { children: formatTime(pending.deadlineAt) })
|
|
2930
|
+
] }),
|
|
2931
|
+
evidence.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
2932
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h4", { children: "授权决定记录" }),
|
|
2933
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", { className: "dshdg-mono", children: evidence.slice().reverse().map((entry) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: `${entry.requestId} · ${entry.toolName ?? "—"} · ${PERMISSION_STATE_LABELS[entry.state] ?? entry.state ?? "—"} · ${PERMISSION_OUTCOME_LABELS[entry.outcome] ?? entry.outcome ?? "—"}${entry.decidedBy === "commander" ? ` · ${PERMISSION_DECISION_LABELS[entry.outcome === "allowed-once" ? "allow-once" : "reject"] ?? "本机指挥官"}` : ""}` }, entry.requestId)) })
|
|
2934
|
+
] }),
|
|
2935
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-hint", children: "逐次授权桥只决定“这一次调用”。它不能创建或扩大任何长期有效的授权(“长期有效”指跨调用、跨会话持久的授权),不能修改设置、凭据、本机调用开关、提供方、模型或隔离方式, 也不能预先批准后续调用;工作进程的常规沙箱权限始终保持 workspace-write。此界面不提供手工批准按钮,决定由本机 MCP 指挥官通过 delegate_permission_decide 作出。" }),
|
|
2936
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-hint", children: "重试前请确认顶部的本机调用开关已开启,然后在 MCP 宿主重新提交任务。本界面不会直接提交任务。" })
|
|
2937
|
+
] });
|
|
2938
|
+
}
|
|
2939
|
+
function useTaskAutoRefresh({ store, snapshot, intervalMs = 5e3 }) {
|
|
2940
|
+
const live = hasLiveTasks(snapshot.tasks) || snapshot.taskDetail !== null && isLiveTask(snapshot.taskDetail);
|
|
2941
|
+
const liveRef = (0, import_react.useRef)(live);
|
|
2942
|
+
liveRef.current = live;
|
|
2943
|
+
(0, import_react.useEffect)(() => {
|
|
2944
|
+
if (!live) return void 0;
|
|
2945
|
+
let timer = null;
|
|
2946
|
+
let disposed = false;
|
|
2947
|
+
const schedule = () => {
|
|
2948
|
+
if (disposed) return;
|
|
2949
|
+
if (timer !== null) clearTimeout(timer);
|
|
2950
|
+
timer = setTimeout(tick, intervalMs);
|
|
2951
|
+
timer.unref?.();
|
|
2952
|
+
};
|
|
2953
|
+
const tick = () => {
|
|
2954
|
+
timer = null;
|
|
2955
|
+
if (disposed) return;
|
|
2956
|
+
if (globalThis.document?.hidden === true) return;
|
|
2957
|
+
if (!liveRef.current) return;
|
|
2958
|
+
void store.refreshTasks("auto").finally(() => {
|
|
2959
|
+
schedule();
|
|
2960
|
+
});
|
|
2961
|
+
};
|
|
2962
|
+
const onVisibility = () => {
|
|
2963
|
+
if (globalThis.document?.hidden === true) return;
|
|
2964
|
+
if (!liveRef.current) return;
|
|
2965
|
+
if (timer !== null) clearTimeout(timer);
|
|
2966
|
+
timer = null;
|
|
2967
|
+
void store.refreshTasks("auto").finally(() => {
|
|
2968
|
+
schedule();
|
|
2969
|
+
});
|
|
2970
|
+
};
|
|
2971
|
+
schedule();
|
|
2972
|
+
const doc = globalThis.document;
|
|
2973
|
+
doc?.addEventListener?.("visibilitychange", onVisibility);
|
|
2974
|
+
return () => {
|
|
2975
|
+
disposed = true;
|
|
2976
|
+
if (timer !== null) clearTimeout(timer);
|
|
2977
|
+
timer = null;
|
|
2978
|
+
doc?.removeEventListener?.("visibilitychange", onVisibility);
|
|
2979
|
+
};
|
|
2980
|
+
}, [store, live, intervalMs]);
|
|
2981
|
+
}
|
|
2982
|
+
function TasksPanel({ store, snapshot }) {
|
|
2983
|
+
const tasks = snapshot.tasks ?? [];
|
|
2984
|
+
const detail = snapshot.taskDetail;
|
|
2985
|
+
useTaskAutoRefresh({ store, snapshot });
|
|
2986
|
+
const liveCount = tasks.filter(isLiveTask).length;
|
|
2987
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-panel", children: [
|
|
2988
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-row", children: [
|
|
2989
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-muted", children: "这里只记录执行事实。执行完成不等于被接受:“等待宿主审查”要由宿主(例如 Codex)单独给出结论。" }),
|
|
2990
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-spacer" }),
|
|
2991
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-hint", children: liveCount === 0 && !(detail !== null && isLiveTask(detail)) ? "当前没有运行中的任务,不会自动刷新。" : `有 ${liveCount} 个进行中的任务,页面可见时每 5 秒自动刷新一次(只读,不调用模型)。` }),
|
|
2992
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", disabled: snapshot.loading?.tasks === true, onClick: () => {
|
|
2993
|
+
void store.refreshTasks("manual");
|
|
2994
|
+
}, children: snapshot.loading?.tasks === true ? "读取中…" : "刷新" })
|
|
2995
|
+
] }),
|
|
2996
|
+
tasks.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-faint", children: "还没有任务记录。" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dshdg-list", children: tasks.map((task) => {
|
|
2997
|
+
const progress = taskProgress(task);
|
|
2998
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-item", children: [
|
|
2999
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-item-head", children: [
|
|
3000
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-mono", children: task.taskId }),
|
|
3001
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Badge, { tone: isAwaitingPermission(task) ? "warn" : task.state === "awaiting-host-review" ? "warn" : task.state === "failed" ? "warn" : "off", children: taskStateLabel(task.state) }),
|
|
3002
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Badge, { tone: progress.tone, children: taskPhaseLabel(task.phase) }),
|
|
3003
|
+
isAwaitingPermission(task) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Badge, { tone: "warn", children: PERMISSION_STATE_LABELS.pending }) : null,
|
|
3004
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "dshdg-mono dshdg-faint", children: [
|
|
3005
|
+
task.config?.worker?.model ?? task.effective?.worker?.model ?? "—",
|
|
3006
|
+
" / ",
|
|
3007
|
+
task.config?.worker?.reasoningEffort ?? task.effective?.worker?.reasoningEffort ?? "不指定"
|
|
3008
|
+
] }),
|
|
3009
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-spacer" }),
|
|
3010
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-faint", children: formatTime(task.createdAt) }),
|
|
3011
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
3012
|
+
"button",
|
|
3013
|
+
{
|
|
3014
|
+
type: "button",
|
|
3015
|
+
disabled: snapshot.loading?.taskDetail === true,
|
|
3016
|
+
onClick: () => {
|
|
3017
|
+
void store.openTask(task.taskId);
|
|
3018
|
+
},
|
|
3019
|
+
children: "详情"
|
|
3020
|
+
}
|
|
3021
|
+
),
|
|
3022
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
3023
|
+
"button",
|
|
3024
|
+
{
|
|
3025
|
+
type: "button",
|
|
3026
|
+
className: "dshdg-danger",
|
|
3027
|
+
disabled: !isCancellable(task.state),
|
|
3028
|
+
onClick: () => {
|
|
3029
|
+
void store.cancelTask(task.taskId);
|
|
3030
|
+
},
|
|
3031
|
+
children: "取消"
|
|
3032
|
+
}
|
|
3033
|
+
)
|
|
3034
|
+
] }),
|
|
3035
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-hint", children: progress.headline }),
|
|
3036
|
+
isAwaitingPermission(task) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-hint", children: permissionSummary(task).note }) : null
|
|
3037
|
+
] }, task.taskId);
|
|
3038
|
+
}) }),
|
|
3039
|
+
detail === null ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TaskDetail, { store, task: detail }),
|
|
3040
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-faint", children: `状态集合:${TASK_STATES.map(taskStateLabel).join(" / ")}` })
|
|
3041
|
+
] });
|
|
3042
|
+
}
|
|
3043
|
+
function CodexTargetRow({ view }) {
|
|
3044
|
+
const paths = Array.isArray(view.paths) ? view.paths : [];
|
|
3045
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-item", children: [
|
|
3046
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-item-head", children: [
|
|
3047
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: view.label }),
|
|
3048
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Badge, { tone: view.tone, children: view.detail }),
|
|
3049
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-spacer" }),
|
|
3050
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-mono dshdg-faint", children: paths[0] ?? "" })
|
|
3051
|
+
] }),
|
|
3052
|
+
paths.length > 1 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-mono dshdg-faint", children: paths.slice(1).join(";") }) : null
|
|
3053
|
+
] });
|
|
3054
|
+
}
|
|
3055
|
+
function CodexPanel({ store, snapshot }) {
|
|
3056
|
+
const codex = snapshot.codex ?? null;
|
|
3057
|
+
const error = snapshot.codexError ?? null;
|
|
3058
|
+
const busy = snapshot.loading?.codexAction === true;
|
|
3059
|
+
const refreshing = snapshot.loading?.codexStatus === true;
|
|
3060
|
+
const agentView = codexTargetView(codex, null, "agent");
|
|
3061
|
+
const mcpView = codexTargetView(codex, null, "mcp");
|
|
3062
|
+
const switchAuthorized = snapshot.status?.delegation?.authorized === true || snapshot.settings?.delegationEnabled === true;
|
|
3063
|
+
const switchView = codexTargetView(codex, { authorized: switchAuthorized }, "switch");
|
|
3064
|
+
const ready = codex?.ready === true;
|
|
3065
|
+
const notes = Array.isArray(codex?.notes) ? codex.notes : [];
|
|
3066
|
+
const disabled = busy || refreshing || codex === null;
|
|
3067
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: "dshdg-card", "aria-labelledby": "dshdg-codex-title", children: [
|
|
3068
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-row", children: [
|
|
3069
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { id: "dshdg-codex-title", children: "Codex 集成(子智能体 + MCP)" }),
|
|
3070
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-spacer" }),
|
|
3071
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Badge, { tone: ready ? "on" : "off", children: ready ? "已就绪" : "未就绪" })
|
|
3072
|
+
] }),
|
|
3073
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { className: "dshdg-muted", children: [
|
|
3074
|
+
"点下面的按钮,把 ",
|
|
3075
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-mono", children: "agents/dsh-delegate.toml" }),
|
|
3076
|
+
" 装进 Codex 目录,并在 Codex 的 ",
|
|
3077
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-mono", children: "config.toml" }),
|
|
3078
|
+
" 里登记本插件的 stdio MCP 服务(delegate_status / delegate_submit / delegate_result / delegate_wait / delegate_cancel)。首次安装只会由你点击触发:打开本页、安装或升级本插件都不会自动创建子智能体文件或 MCP 条目。已经安装过的情况下,插件下次启动会把本插件自己写入的过期托管条目就地更新(例如补上 tool_timeout_sec);它不会改写非托管、被你改过的条目,也不会触碰 Codex 的其他设置。下面会显示当前条目缺了什么。"
|
|
3079
|
+
] }),
|
|
3080
|
+
error === null ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-fail", children: error }),
|
|
3081
|
+
codex === null ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-faint", children: "正在读取 Codex 状态…" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
3082
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { className: "dshdg-faint", children: [
|
|
3083
|
+
"Codex 目录:",
|
|
3084
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-mono", children: String(codex.codexHome ?? "") }),
|
|
3085
|
+
"(设置环境变量 CODEX_HOME 可改到别处)"
|
|
3086
|
+
] }),
|
|
3087
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-list", "data-dshdg-codex-targets": "", children: [
|
|
3088
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(CodexTargetRow, { view: agentView }),
|
|
3089
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(CodexTargetRow, { view: mcpView }),
|
|
3090
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(CodexTargetRow, { view: switchView })
|
|
3091
|
+
] }),
|
|
3092
|
+
codex.mcp?.state === "outdated" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { className: "dshdg-hint", "data-dshdg-codex-drift": "", children: [
|
|
3093
|
+
"这个托管 MCP 条目已经过期:",
|
|
3094
|
+
codexMcpDriftText(codex.mcp),
|
|
3095
|
+
"。插件下次启动会自动在原地更新;也可以点上面的「安装 / 更新 Codex 集成」。"
|
|
3096
|
+
] }) : null,
|
|
3097
|
+
notes.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", { className: "dshdg-hint", children: notes.map((note) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: note.text }, note.code)) }),
|
|
3098
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-row", children: [
|
|
3099
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", disabled: busy || refreshing, onClick: () => {
|
|
3100
|
+
void store.refreshCodexStatus();
|
|
3101
|
+
}, children: refreshing ? "读取中…" : "刷新状态" }),
|
|
3102
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "dshdg-primary", disabled, onClick: () => {
|
|
3103
|
+
void store.runCodexAction("install");
|
|
3104
|
+
}, children: busy ? "处理中…" : "安装 / 更新 Codex 集成" }),
|
|
3105
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", disabled, onClick: () => {
|
|
3106
|
+
void store.runCodexAction("repair");
|
|
3107
|
+
}, children: "仅修复 MCP 配置" }),
|
|
3108
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "dshdg-danger", disabled, onClick: () => {
|
|
3109
|
+
void store.runCodexAction("remove");
|
|
3110
|
+
}, children: "移除插件托管项" })
|
|
3111
|
+
] }),
|
|
3112
|
+
snapshot.codexOutcome === null || snapshot.codexOutcome === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-hint", children: describeCodexOutcome(snapshot.codexOutcome) })
|
|
3113
|
+
] }),
|
|
3114
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-hint", children: "安装后需要让 Codex 重新载入:新开会话或重启 Codex,才会读到新的子智能体和 MCP 条目。本插件不宣称当前 Codex 桌面版/CLI 能在输入框用 @dsh-delegate 直接选中该子智能体——这取决于 Codex 版本自身是否提供提及选择;这里只保证子智能体文件与 MCP 工具存在,并由你在 Codex 提供的选择方式中指派它。子智能体只在明确指派时派发任务,并在提交前先检查上面的本机调用开关;本页不会替你打开该开关。同名的自定义 agent 会被保留并报告为冲突;没有本插件托管标记注释的同名 MCP 条目也视为你自己写的,不会被覆盖或删除。" })
|
|
3115
|
+
] });
|
|
3116
|
+
}
|
|
3117
|
+
var TABS = Object.freeze([
|
|
3118
|
+
{ key: "providers", label: "接口管理" },
|
|
3119
|
+
{ key: "execution", label: "执行设置" },
|
|
3120
|
+
{ key: "review", label: "附加审查" },
|
|
3121
|
+
{ key: "tasks", label: "任务记录" },
|
|
3122
|
+
{ key: "codex", label: "Codex 集成" }
|
|
3123
|
+
]);
|
|
3124
|
+
function DelegateConfigPage(props) {
|
|
3125
|
+
const store = props.store;
|
|
3126
|
+
const snapshot = (0, import_react.useSyncExternalStore)(
|
|
3127
|
+
(0, import_react.useCallback)((listener) => store.subscribe(listener), [store]),
|
|
3128
|
+
(0, import_react.useCallback)(() => store.getSnapshot(), [store]),
|
|
3129
|
+
(0, import_react.useCallback)(() => store.getSnapshot(), [store])
|
|
3130
|
+
);
|
|
3131
|
+
const [tab, setTab] = (0, import_react.useState)(TABS[0].key);
|
|
3132
|
+
const [saving, setSaving] = (0, import_react.useState)(false);
|
|
3133
|
+
const loaded = (0, import_react.useRef)(false);
|
|
3134
|
+
(0, import_react.useEffect)(() => {
|
|
3135
|
+
if (loaded.current) return;
|
|
3136
|
+
loaded.current = true;
|
|
3137
|
+
void store.init();
|
|
3138
|
+
}, [store]);
|
|
3139
|
+
const problems = (0, import_react.useMemo)(
|
|
3140
|
+
() => snapshot.draft === null ? [] : precheckDraft(snapshot.draft),
|
|
3141
|
+
[snapshot.draft]
|
|
3142
|
+
);
|
|
3143
|
+
const tabRefs = (0, import_react.useRef)(/* @__PURE__ */ new Map());
|
|
3144
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-root", children: [
|
|
3145
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Notices, { store, notices: snapshot.notices ?? [] }),
|
|
3146
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(AuthorizationPanel, { store, snapshot }),
|
|
3147
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dshdg-tabs", role: "tablist", "aria-label": "DSH 委托设置", children: TABS.map((entry) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
3148
|
+
"button",
|
|
3149
|
+
{
|
|
3150
|
+
type: "button",
|
|
3151
|
+
role: "tab",
|
|
3152
|
+
className: "dshdg-tab",
|
|
3153
|
+
id: `dshdg-tab-${entry.key}`,
|
|
3154
|
+
"aria-selected": tab === entry.key,
|
|
3155
|
+
"aria-controls": `dshdg-panel-${entry.key}`,
|
|
3156
|
+
tabIndex: tab === entry.key ? 0 : -1,
|
|
3157
|
+
ref: (node) => {
|
|
3158
|
+
if (node === null) tabRefs.current.delete(entry.key);
|
|
3159
|
+
else tabRefs.current.set(entry.key, node);
|
|
3160
|
+
},
|
|
3161
|
+
onClick: () => setTab(entry.key),
|
|
3162
|
+
onKeyDown: (event) => {
|
|
3163
|
+
if (event.key !== "ArrowRight" && event.key !== "ArrowLeft") return;
|
|
3164
|
+
event.preventDefault();
|
|
3165
|
+
const index = TABS.findIndex((candidate) => candidate.key === tab);
|
|
3166
|
+
const step = event.key === "ArrowRight" ? 1 : -1;
|
|
3167
|
+
const next = TABS[(index + step + TABS.length) % TABS.length];
|
|
3168
|
+
setTab(next.key);
|
|
3169
|
+
tabRefs.current.get(next.key)?.focus?.();
|
|
3170
|
+
},
|
|
3171
|
+
children: entry.label
|
|
3172
|
+
},
|
|
3173
|
+
entry.key
|
|
3174
|
+
)) }),
|
|
3175
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
3176
|
+
"div",
|
|
3177
|
+
{
|
|
3178
|
+
className: "dshdg-panel",
|
|
3179
|
+
role: "tabpanel",
|
|
3180
|
+
id: `dshdg-panel-${tab}`,
|
|
3181
|
+
"aria-labelledby": `dshdg-tab-${tab}`,
|
|
3182
|
+
tabIndex: -1,
|
|
3183
|
+
children: [
|
|
3184
|
+
tab === "providers" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ProvidersPanel, { store, snapshot }) : null,
|
|
3185
|
+
tab === "execution" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ExecutionPanel, { store, snapshot }) : null,
|
|
3186
|
+
tab === "review" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReviewPanel, { store, snapshot }) : null,
|
|
3187
|
+
tab === "tasks" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TasksPanel, { store, snapshot }) : null,
|
|
3188
|
+
tab === "codex" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CodexPanel, { store, snapshot }) : null
|
|
3189
|
+
]
|
|
3190
|
+
}
|
|
3191
|
+
),
|
|
3192
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshdg-row", children: [
|
|
3193
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "dshdg-hint", children: [
|
|
3194
|
+
snapshot.dirty === true ? "有未保存的修改。" : "所有修改已保存。",
|
|
3195
|
+
problems.length === 0 ? "" : ` 待修正:${problems[0]}${problems.length > 1 ? ` 等 ${problems.length} 项` : ""}`
|
|
3196
|
+
] }),
|
|
3197
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dshdg-spacer" }),
|
|
3198
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
3199
|
+
"button",
|
|
3200
|
+
{
|
|
3201
|
+
type: "button",
|
|
3202
|
+
disabled: snapshot.dirty !== true || snapshot.loading?.save === true,
|
|
3203
|
+
onClick: () => {
|
|
3204
|
+
store.resetDraft();
|
|
3205
|
+
},
|
|
3206
|
+
children: "放弃修改"
|
|
3207
|
+
}
|
|
3208
|
+
),
|
|
3209
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
3210
|
+
"button",
|
|
3211
|
+
{
|
|
3212
|
+
type: "button",
|
|
3213
|
+
className: "dshdg-primary",
|
|
3214
|
+
disabled: snapshot.dirty !== true || snapshot.loading?.save === true || saving,
|
|
3215
|
+
onClick: async () => {
|
|
3216
|
+
setSaving(true);
|
|
3217
|
+
try {
|
|
3218
|
+
await store.saveSettings();
|
|
3219
|
+
} finally {
|
|
3220
|
+
setSaving(false);
|
|
3221
|
+
}
|
|
3222
|
+
},
|
|
3223
|
+
children: snapshot.loading?.save === true || saving ? "保存中…" : "保存设置"
|
|
3224
|
+
}
|
|
3225
|
+
)
|
|
3226
|
+
] }),
|
|
3227
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshdg-faint", children: "保存会整体替换设置文档;正在运行的任务保留它自己的快照。密钥从不随设置保存或导出。" })
|
|
3228
|
+
] });
|
|
3229
|
+
}
|
|
3230
|
+
return module.exports;
|
|
3231
|
+
}
|
|
3232
|
+
});
|