@linxin666/dsh-client-ui-plugin-manager 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +29 -0
- package/README.i18n.yaml +6 -0
- package/README.md +81 -0
- package/README.zh.md +81 -0
- package/cordis.patch.yml +7 -0
- package/lib/client.js +1464 -0
- package/lib/client.js.map +1 -0
- package/lib/index.js +1425 -0
- package/lib/types/client/PluginManagerTab.d.ts +38 -0
- package/lib/types/client/index.d.ts +42 -0
- package/lib/types/client/locales.d.ts +245 -0
- package/lib/types/core/conflict.d.ts +43 -0
- package/lib/types/core/patch-diff.d.ts +46 -0
- package/lib/types/core/protocol.d.ts +99 -0
- package/lib/types/core/repair.d.ts +71 -0
- package/lib/types/core/service.d.ts +45 -0
- package/lib/types/host/bundle-guard.d.ts +53 -0
- package/lib/types/host/dsh-home.d.ts +16 -0
- package/lib/types/host/gateway.d.ts +156 -0
- package/lib/types/host/loopback.d.ts +24 -0
- package/lib/types/host/profile.d.ts +60 -0
- package/lib/types/host/routes.d.ts +34 -0
- package/lib/types/host/rows.d.ts +101 -0
- package/lib/types/host/state.d.ts +58 -0
- package/lib/types/index.d.ts +22 -0
- package/lib/types/mount-once.d.ts +24 -0
- package/package.json +73 -0
package/lib/client.js
ADDED
|
@@ -0,0 +1,1464 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "@linxin666/dsh-client-ui-plugin-manager",
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
var module = { exports: {} };
|
|
5
|
+
var exports = module.exports;
|
|
6
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
|
+
let react = require("react");
|
|
8
|
+
let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
9
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
10
|
+
//#region src/core/conflict.ts
|
|
11
|
+
/**
|
|
12
|
+
* Diff two plugin-control snapshots by id. Only entries present in both
|
|
13
|
+
* snapshots with a changed state are reported; entries appearing or
|
|
14
|
+
* disappearing are ordinary install/uninstall outcomes, not conflicts.
|
|
15
|
+
* @param before - snapshot taken before the install.
|
|
16
|
+
* @param after - snapshot taken after the install.
|
|
17
|
+
* @returns one change per id whose state moved, in id order.
|
|
18
|
+
*/
|
|
19
|
+
function diffControls(before, after) {
|
|
20
|
+
const afterById = new Map(after.map((item) => [item.id, item]));
|
|
21
|
+
const changes = [];
|
|
22
|
+
for (const item of before) {
|
|
23
|
+
const current = afterById.get(item.id);
|
|
24
|
+
if (current === void 0 || current.state === item.state) continue;
|
|
25
|
+
changes.push({
|
|
26
|
+
id: item.id,
|
|
27
|
+
name: item.name,
|
|
28
|
+
from: item.state,
|
|
29
|
+
to: current.state
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return changes;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Classify one control-state change for messaging. A change into `disabled`
|
|
36
|
+
* is the conflict rule's action (reversible by re-enabling); a change out of
|
|
37
|
+
* `disabled` is a manual undo; anything else is reported neutrally.
|
|
38
|
+
* @param change - one diff entry.
|
|
39
|
+
* @returns the message kind.
|
|
40
|
+
*/
|
|
41
|
+
function classifyChange(change) {
|
|
42
|
+
if (change.to === "disabled") return "rule-disabled";
|
|
43
|
+
if (change.from === "disabled") return "rule-enabled";
|
|
44
|
+
return "state-change";
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/core/repair.ts
|
|
48
|
+
/** Default copy (zh): the package's zh dictionary keys map onto these strings. */
|
|
49
|
+
const DEFAULT_REPAIR_COPY = {
|
|
50
|
+
installTitle: "正在修复插件安装失败",
|
|
51
|
+
installSpecLabel: "安装目标",
|
|
52
|
+
installErrorLabel: "安装错误",
|
|
53
|
+
installAsk: "请在插件安装根目录内检查插件包或依赖并修复,然后重试安装。",
|
|
54
|
+
failureTitle: "正在修复插件启动失败",
|
|
55
|
+
failurePluginLabel: "插件",
|
|
56
|
+
failureKindLabel: "失败类型",
|
|
57
|
+
failureAtLabel: "时间",
|
|
58
|
+
failureMessageLabel: "错误信息",
|
|
59
|
+
failureStackLabel: "堆栈",
|
|
60
|
+
failurePathLabel: "安装路径",
|
|
61
|
+
failureAsk: "请修复插件后重新启用并重启 dsh web。",
|
|
62
|
+
conflictTitle: "正在处理插件安装冲突",
|
|
63
|
+
conflictPluginLabel: "冲突条目",
|
|
64
|
+
conflictChangeLabel: "状态变化",
|
|
65
|
+
conflictAsk: "请检查冲突双方的入口行 id 与挂载方式,消除重复挂载后告诉我如何重新启用。",
|
|
66
|
+
kindNames: {
|
|
67
|
+
"load-failure": "加载失败",
|
|
68
|
+
hang: "启动挂起",
|
|
69
|
+
"late-rejection": "迟到拒绝"
|
|
70
|
+
},
|
|
71
|
+
stateNames: {
|
|
72
|
+
enabled: "已开启",
|
|
73
|
+
disabled: "已关闭",
|
|
74
|
+
uninstalled: "已卸载"
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Seed text for a failed install: the target and the rendered error,
|
|
79
|
+
* self-contained for the agent.
|
|
80
|
+
* @param spec - the install target (npm spec or git URL) that failed.
|
|
81
|
+
* @param error - the rendered install error text.
|
|
82
|
+
* @param copy - localized fragments.
|
|
83
|
+
* @returns the repair prompt text.
|
|
84
|
+
*/
|
|
85
|
+
function installRepairMessage(spec, error, copy = DEFAULT_REPAIR_COPY) {
|
|
86
|
+
return [
|
|
87
|
+
copy.installTitle,
|
|
88
|
+
`${copy.installSpecLabel}: ${spec}`,
|
|
89
|
+
`${copy.installErrorLabel}:\n${error}`,
|
|
90
|
+
copy.installAsk
|
|
91
|
+
].join("\n\n");
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Seed text for one boot-failure ring row: the failure record, so the agent
|
|
95
|
+
* can attribute and fix it in place.
|
|
96
|
+
* @param failure - the recorded failure row.
|
|
97
|
+
* @param copy - localized fragments.
|
|
98
|
+
* @returns the repair prompt text.
|
|
99
|
+
*/
|
|
100
|
+
function failureRepairMessage(failure, copy = DEFAULT_REPAIR_COPY) {
|
|
101
|
+
const parts = [
|
|
102
|
+
copy.failureTitle,
|
|
103
|
+
`${copy.failurePluginLabel}: ${failure.pluginId || "-"}`,
|
|
104
|
+
`${copy.failureKindLabel}: ${copy.kindNames[failure.kind] ?? failure.kind}`,
|
|
105
|
+
`${copy.failureAtLabel}: ${failure.at}`,
|
|
106
|
+
`${copy.failureMessageLabel}:\n${failure.message}`
|
|
107
|
+
];
|
|
108
|
+
if (failure.stack !== "") parts.push(`${copy.failureStackLabel}:\n${failure.stack}`);
|
|
109
|
+
if (failure.installPath !== "") parts.push(`${copy.failurePathLabel}: ${failure.installPath}`);
|
|
110
|
+
parts.push(copy.failureAsk);
|
|
111
|
+
return parts.join("\n\n");
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Seed text for one install-conflict notice: the entry and its state change,
|
|
115
|
+
* so the agent can attribute the conflict and resolve the double mount.
|
|
116
|
+
* @param change - the conflict change (id, display name, from/to states).
|
|
117
|
+
* @param copy - localized fragments.
|
|
118
|
+
* @returns the repair prompt text.
|
|
119
|
+
*/
|
|
120
|
+
function conflictRepairMessage(change, copy = DEFAULT_REPAIR_COPY) {
|
|
121
|
+
return [
|
|
122
|
+
copy.conflictTitle,
|
|
123
|
+
`${copy.conflictPluginLabel}: ${change.name} (${change.id})`,
|
|
124
|
+
`${copy.conflictChangeLabel}: ${copy.stateNames[change.from] ?? change.from} -> ${copy.stateNames[change.to] ?? change.to}`,
|
|
125
|
+
copy.conflictAsk
|
|
126
|
+
].join("\n\n");
|
|
127
|
+
}
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region \0dsh-css:packages/dsh-plugin-manager/src/client/plugin-manager.module.css.mjs
|
|
130
|
+
const css = ".ZsMDKq_section{flex-direction:column;gap:12px;display:flex}.ZsMDKq_notice{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);border-radius:8px;flex-direction:column;gap:8px;padding:16px;display:flex}.ZsMDKq_notice p{color:var(--dsw-alias-label-secondary);margin:0}.ZsMDKq_state{color:var(--dsw-alias-label-secondary);padding:16px 0}.ZsMDKq_installRow{gap:8px;display:flex}.ZsMDKq_spec{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);min-width:0;color:var(--dsw-alias-label-primary);border-radius:6px;flex:1;padding:6px 10px}.ZsMDKq_spec:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary)}.ZsMDKq_hint{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px}.ZsMDKq_progressRow{flex-direction:column;gap:6px;display:flex}.ZsMDKq_progressTrack{background:var(--dsw-alias-bg-layer-2);border-radius:3px;height:6px;overflow:hidden}.ZsMDKq_progressBar{background:var(--dsw-alias-state-business-primary);height:100%;transition:width .2s}.ZsMDKq_progressBar[data-indeterminate=true]{width:40%;animation:1.2s ease-in-out infinite ZsMDKq_pluginManagerIndeterminate}@keyframes ZsMDKq_pluginManagerIndeterminate{0%{transform:translate(-100%)}to{transform:translate(250%)}}.ZsMDKq_progressLabel{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px}@media (prefers-reduced-motion:reduce){.ZsMDKq_progressBar[data-indeterminate=true]{width:40%;animation:none}}.ZsMDKq_errorRow{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-danger);border-radius:8px;flex-wrap:wrap;align-items:center;gap:8px;padding:8px 12px;display:flex}.ZsMDKq_error{min-width:200px;color:var(--dsw-alias-label-danger);word-break:break-all;flex:1}.ZsMDKq_group{flex-direction:column;gap:8px;display:flex}.ZsMDKq_sectionTitle{color:var(--dsw-alias-label-secondary);margin:0;font-size:13px;font-weight:600}.ZsMDKq_list{flex-direction:column;gap:8px;margin:0;padding:0;list-style:none;display:flex}.ZsMDKq_row{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);border-radius:8px;justify-content:space-between;align-items:flex-start;gap:12px;padding:10px 12px;display:flex}.ZsMDKq_meta{flex-direction:column;gap:4px;min-width:0;display:flex}.ZsMDKq_name{color:var(--dsw-alias-label-primary);text-overflow:ellipsis;white-space:nowrap;font-weight:600;overflow:hidden}.ZsMDKq_sub{color:var(--dsw-alias-label-tertiary);flex-wrap:wrap;align-items:center;gap:6px;min-width:0;font-size:12px;display:flex}.ZsMDKq_version{white-space:nowrap}.ZsMDKq_sourceBadge{border:1px solid var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);border-radius:4px;padding:0 4px;font-size:11px}.ZsMDKq_specText{text-overflow:ellipsis;white-space:nowrap;max-width:320px;overflow:hidden}.ZsMDKq_latest{color:var(--dsw-alias-state-business-primary);font-size:12px}.ZsMDKq_actions{flex-shrink:0;align-items:center;gap:8px;display:flex}.ZsMDKq_empty{color:var(--dsw-alias-label-tertiary);margin:0}.ZsMDKq_link{color:var(--dsw-alias-state-business-primary)}.ZsMDKq_stateLabel{color:var(--dsw-alias-label-secondary);font-size:12px}.ZsMDKq_stateLabel[data-state=enabled]{color:var(--dsw-alias-state-success-primary)}.ZsMDKq_stateLabel[data-state=disabled]{color:var(--dsw-alias-label-tertiary)}.ZsMDKq_switch{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-2);cursor:pointer;border-radius:10px;width:34px;height:20px;padding:0;transition:background .2s;position:relative}.ZsMDKq_switch:after{content:\"\";background:var(--dsw-alias-label-on-danger,#fff);border-radius:50%;width:14px;height:14px;transition:transform .2s;position:absolute;top:2px;left:2px}.ZsMDKq_switch[aria-checked=true]{background:var(--dsw-alias-state-success-primary)}.ZsMDKq_switch[aria-checked=true]:after{transform:translate(14px)}.ZsMDKq_switch:disabled{opacity:.5;cursor:not-allowed}.ZsMDKq_switch:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary)}@media (prefers-reduced-motion:reduce){.ZsMDKq_switch,.ZsMDKq_switch:after{transition:none}}.ZsMDKq_failure{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-danger);border-radius:6px;flex-direction:column;gap:6px;margin-top:4px;padding:8px;display:flex}.ZsMDKq_badge{background:var(--dsw-alias-label-danger);color:var(--dsw-alias-label-on-danger);border-radius:10px;align-self:flex-start;padding:2px 8px;font-size:11px}.ZsMDKq_failureMessage{color:var(--dsw-alias-label-danger);word-break:break-all;font-size:12px}.ZsMDKq_failureActions{flex-wrap:wrap;gap:8px;display:flex}.ZsMDKq_conflicts{flex-direction:column;gap:8px;display:flex}.ZsMDKq_actionsRow{align-items:center;gap:12px;display:flex}.ZsMDKq_ok{color:var(--dsw-alias-state-success-primary);margin:0;font-size:12px}.ZsMDKq_applying{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px}.ZsMDKq_restartRow{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-brand);border-radius:8px;padding:10px 12px}.ZsMDKq_restartRow p{color:var(--dsw-alias-brand-primary);margin:0}.ZsMDKq_safeModeBanner{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-warning);border-radius:8px;justify-content:space-between;align-items:center;gap:12px;padding:10px 12px;display:flex}.ZsMDKq_safeModeBanner p{color:var(--dsw-alias-label-primary);margin:0}.ZsMDKq_confirmBody{color:var(--dsw-alias-label-secondary);margin:0 0 12px}.ZsMDKq_modalActions{justify-content:flex-end;gap:8px;display:flex}.ZsMDKq_dangerButton{background:var(--dsw-alias-label-danger)!important;color:var(--dsw-alias-label-on-danger)!important}";
|
|
131
|
+
const tagId = "@linxin666/dsh-client-ui-plugin-manager/plugin-manager.module.css";
|
|
132
|
+
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
|
|
133
|
+
const tag = document.createElement("style");
|
|
134
|
+
tag.dataset.plugin = "@linxin666/dsh-client-ui-plugin-manager";
|
|
135
|
+
tag.dataset.pluginCss = tagId;
|
|
136
|
+
tag.textContent = css;
|
|
137
|
+
document.head.appendChild(tag);
|
|
138
|
+
}
|
|
139
|
+
var plugin_manager_module_css_default = {
|
|
140
|
+
"actions": "ZsMDKq_actions",
|
|
141
|
+
"actionsRow": "ZsMDKq_actionsRow",
|
|
142
|
+
"applying": "ZsMDKq_applying",
|
|
143
|
+
"badge": "ZsMDKq_badge",
|
|
144
|
+
"confirmBody": "ZsMDKq_confirmBody",
|
|
145
|
+
"conflicts": "ZsMDKq_conflicts",
|
|
146
|
+
"dangerButton": "ZsMDKq_dangerButton",
|
|
147
|
+
"empty": "ZsMDKq_empty",
|
|
148
|
+
"error": "ZsMDKq_error",
|
|
149
|
+
"errorRow": "ZsMDKq_errorRow",
|
|
150
|
+
"failure": "ZsMDKq_failure",
|
|
151
|
+
"failureActions": "ZsMDKq_failureActions",
|
|
152
|
+
"failureMessage": "ZsMDKq_failureMessage",
|
|
153
|
+
"group": "ZsMDKq_group",
|
|
154
|
+
"hint": "ZsMDKq_hint",
|
|
155
|
+
"installRow": "ZsMDKq_installRow",
|
|
156
|
+
"latest": "ZsMDKq_latest",
|
|
157
|
+
"link": "ZsMDKq_link",
|
|
158
|
+
"list": "ZsMDKq_list",
|
|
159
|
+
"meta": "ZsMDKq_meta",
|
|
160
|
+
"modalActions": "ZsMDKq_modalActions",
|
|
161
|
+
"name": "ZsMDKq_name",
|
|
162
|
+
"notice": "ZsMDKq_notice",
|
|
163
|
+
"ok": "ZsMDKq_ok",
|
|
164
|
+
"pluginManagerIndeterminate": "ZsMDKq_pluginManagerIndeterminate",
|
|
165
|
+
"progressBar": "ZsMDKq_progressBar",
|
|
166
|
+
"progressLabel": "ZsMDKq_progressLabel",
|
|
167
|
+
"progressRow": "ZsMDKq_progressRow",
|
|
168
|
+
"progressTrack": "ZsMDKq_progressTrack",
|
|
169
|
+
"restartRow": "ZsMDKq_restartRow",
|
|
170
|
+
"row": "ZsMDKq_row",
|
|
171
|
+
"safeModeBanner": "ZsMDKq_safeModeBanner",
|
|
172
|
+
"section": "ZsMDKq_section",
|
|
173
|
+
"sectionTitle": "ZsMDKq_sectionTitle",
|
|
174
|
+
"sourceBadge": "ZsMDKq_sourceBadge",
|
|
175
|
+
"spec": "ZsMDKq_spec",
|
|
176
|
+
"specText": "ZsMDKq_specText",
|
|
177
|
+
"state": "ZsMDKq_state",
|
|
178
|
+
"stateLabel": "ZsMDKq_stateLabel",
|
|
179
|
+
"sub": "ZsMDKq_sub",
|
|
180
|
+
"switch": "ZsMDKq_switch",
|
|
181
|
+
"version": "ZsMDKq_version"
|
|
182
|
+
};
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region src/client/PluginManagerTab.tsx
|
|
185
|
+
/**
|
|
186
|
+
* The plugin-manager tab: an install box, one row per installed user plugin
|
|
187
|
+
* (next-start enablement switch, source badge, update availability, update and
|
|
188
|
+
* uninstall actions, per-plugin boot-failure block), the built-in product
|
|
189
|
+
* switches, an install-conflict notice (the diff of the plugin-control
|
|
190
|
+
* snapshot around each install, reversible through the product switch), and
|
|
191
|
+
* the failure-repair affordances. Enablement switches and installs persist
|
|
192
|
+
* through the official host channels and apply at the next restart; the web
|
|
193
|
+
* build shows a restart hint instead of an in-place restart.
|
|
194
|
+
*
|
|
195
|
+
* This tab registers into the official Plugins settings section
|
|
196
|
+
* (`settings.plugins.tab` slot) next to the official installer tab; its added
|
|
197
|
+
* value over that tab is the conflict ledger, the bilingual repair seeds, and
|
|
198
|
+
* the family card vocabulary.
|
|
199
|
+
*/
|
|
200
|
+
/** Error text for a caught request or lifecycle failure. */
|
|
201
|
+
function messageOf(error) {
|
|
202
|
+
if (error instanceof AggregateError) {
|
|
203
|
+
const details = error.errors.map(messageOf).join("; ");
|
|
204
|
+
return details === "" ? error.message : `${error.message}: ${details}`;
|
|
205
|
+
}
|
|
206
|
+
return error instanceof Error ? error.message : String(error);
|
|
207
|
+
}
|
|
208
|
+
/** Localized fragments for the repair seed builders, read from the tab's dictionaries. */
|
|
209
|
+
function repairCopy(t) {
|
|
210
|
+
return {
|
|
211
|
+
installTitle: t("repairInstallTitle"),
|
|
212
|
+
installSpecLabel: t("repairInstallSpecLabel"),
|
|
213
|
+
installErrorLabel: t("repairInstallErrorLabel"),
|
|
214
|
+
installAsk: t("repairInstallAsk"),
|
|
215
|
+
failureTitle: t("repairFailureTitle"),
|
|
216
|
+
failurePluginLabel: t("repairFailurePluginLabel"),
|
|
217
|
+
failureKindLabel: t("repairFailureKindLabel"),
|
|
218
|
+
failureAtLabel: t("repairFailureAtLabel"),
|
|
219
|
+
failureMessageLabel: t("repairFailureMessageLabel"),
|
|
220
|
+
failureStackLabel: t("repairFailureStackLabel"),
|
|
221
|
+
failurePathLabel: t("repairFailurePathLabel"),
|
|
222
|
+
failureAsk: t("repairFailureAsk"),
|
|
223
|
+
kindNames: {
|
|
224
|
+
"load-failure": t("repairKindLoad"),
|
|
225
|
+
hang: t("repairKindHang"),
|
|
226
|
+
"late-rejection": t("repairKindLate")
|
|
227
|
+
},
|
|
228
|
+
conflictTitle: t("repairConflictTitle"),
|
|
229
|
+
conflictPluginLabel: t("repairConflictPluginLabel"),
|
|
230
|
+
conflictChangeLabel: t("repairConflictChangeLabel"),
|
|
231
|
+
conflictAsk: t("repairConflictAsk"),
|
|
232
|
+
stateNames: {
|
|
233
|
+
enabled: t("repairStateEnabled"),
|
|
234
|
+
disabled: t("repairStateDisabled"),
|
|
235
|
+
uninstalled: t("repairStateUninstalled")
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
/** Localized label for one install phase, with percent when the download has one. */
|
|
240
|
+
function progressLabel(progress, t) {
|
|
241
|
+
if (progress.stage === "fetch") return t("fetching");
|
|
242
|
+
if (progress.stage === "extract") return t("extracting");
|
|
243
|
+
if (progress.stage === "write") return t("writing");
|
|
244
|
+
return progress.percent === void 0 ? t("downloading") : t("downloadingPercent", { percent: String(progress.percent) });
|
|
245
|
+
}
|
|
246
|
+
/** The plugin-manager settings tab. */
|
|
247
|
+
function PluginManagerTab(props) {
|
|
248
|
+
const { t, isLoopback, list, install, update, uninstall, setEnabled, checkUpdates, status, failures, setSafeMode, repairPlugin, controlsList, controlsSetEnabled, lastInstallConflicts } = props;
|
|
249
|
+
const [view, setView] = (0, react.useState)({ status: "loading" });
|
|
250
|
+
const [busy, setBusy] = (0, react.useState)(void 0);
|
|
251
|
+
const [toggleBusy, setToggleBusy] = (0, react.useState)(void 0);
|
|
252
|
+
const [error, setError] = (0, react.useState)(void 0);
|
|
253
|
+
const [failedSpec, setFailedSpec] = (0, react.useState)(void 0);
|
|
254
|
+
const [installError, setInstallError] = (0, react.useState)(void 0);
|
|
255
|
+
const [spec, setSpec] = (0, react.useState)("");
|
|
256
|
+
const [dirty, setDirty] = (0, react.useState)(false);
|
|
257
|
+
const [repairing, setRepairing] = (0, react.useState)(void 0);
|
|
258
|
+
const [copied, setCopied] = (0, react.useState)(void 0);
|
|
259
|
+
const [updates, setUpdates] = (0, react.useState)(/* @__PURE__ */ new Map());
|
|
260
|
+
const [uninstallTarget, setUninstallTarget] = (0, react.useState)(void 0);
|
|
261
|
+
const [conflicts, setConflicts] = (0, react.useState)([]);
|
|
262
|
+
const [progress, setProgress] = (0, react.useState)({
|
|
263
|
+
kind: "idle",
|
|
264
|
+
stage: "fetch"
|
|
265
|
+
});
|
|
266
|
+
/** Synchronous in-flight mirror of `busy`: the render-time guard alone lets a
|
|
267
|
+
* click and an Enter land in the same frame and double-fire. */
|
|
268
|
+
const busyRef = (0, react.useRef)(false);
|
|
269
|
+
/** Reload every snapshot into the ready view. */
|
|
270
|
+
const reload = async () => {
|
|
271
|
+
const [plugins, controls, failureSnapshot] = await Promise.all([
|
|
272
|
+
list(),
|
|
273
|
+
controlsList(),
|
|
274
|
+
failures()
|
|
275
|
+
]);
|
|
276
|
+
setView({
|
|
277
|
+
status: "ready",
|
|
278
|
+
plugins,
|
|
279
|
+
controls,
|
|
280
|
+
failures: failureSnapshot
|
|
281
|
+
});
|
|
282
|
+
};
|
|
283
|
+
(0, react.useEffect)(() => {
|
|
284
|
+
let cancelled = false;
|
|
285
|
+
reload().catch(() => {
|
|
286
|
+
if (!cancelled) setView({ status: "error" });
|
|
287
|
+
});
|
|
288
|
+
return () => {
|
|
289
|
+
cancelled = true;
|
|
290
|
+
};
|
|
291
|
+
}, []);
|
|
292
|
+
/** One row/form operation: busy state, error row, dirty flag on success. */
|
|
293
|
+
const run = async (action, body) => {
|
|
294
|
+
if (busyRef.current) return;
|
|
295
|
+
busyRef.current = true;
|
|
296
|
+
setBusy(action);
|
|
297
|
+
setError(void 0);
|
|
298
|
+
try {
|
|
299
|
+
await body();
|
|
300
|
+
setDirty(true);
|
|
301
|
+
} catch (reason) {
|
|
302
|
+
setError(t("failed", { reason: messageOf(reason) }));
|
|
303
|
+
} finally {
|
|
304
|
+
busyRef.current = false;
|
|
305
|
+
setBusy(void 0);
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
/** Install one spec, then diff the product snapshot into a conflict notice. */
|
|
309
|
+
const onInstall = () => {
|
|
310
|
+
const target = spec.trim();
|
|
311
|
+
if (target === "" || busy !== void 0 || busyRef.current) return;
|
|
312
|
+
(async () => {
|
|
313
|
+
busyRef.current = true;
|
|
314
|
+
const before = view.status === "ready" ? view.controls : await controlsList().catch(() => []);
|
|
315
|
+
setBusy({ kind: "install" });
|
|
316
|
+
setError(void 0);
|
|
317
|
+
setFailedSpec(void 0);
|
|
318
|
+
setInstallError(void 0);
|
|
319
|
+
try {
|
|
320
|
+
await install(target);
|
|
321
|
+
setSpec("");
|
|
322
|
+
setDirty(true);
|
|
323
|
+
const after = await controlsList().catch(() => []);
|
|
324
|
+
setConflicts(lastInstallConflicts !== void 0 ? lastInstallConflicts() : diffControls(before, after));
|
|
325
|
+
await reload();
|
|
326
|
+
} catch (reason) {
|
|
327
|
+
const reasonText = messageOf(reason);
|
|
328
|
+
setFailedSpec(target);
|
|
329
|
+
setInstallError(reasonText);
|
|
330
|
+
setError(t("failed", { reason: reasonText }));
|
|
331
|
+
} finally {
|
|
332
|
+
busyRef.current = false;
|
|
333
|
+
setBusy(void 0);
|
|
334
|
+
}
|
|
335
|
+
})();
|
|
336
|
+
};
|
|
337
|
+
/** Poll install/update progress while such an operation is in flight. */
|
|
338
|
+
(0, react.useEffect)(() => {
|
|
339
|
+
if (busy === void 0 || busy.kind !== "install" && busy.kind !== "update") {
|
|
340
|
+
setProgress({
|
|
341
|
+
kind: "idle",
|
|
342
|
+
stage: "fetch"
|
|
343
|
+
});
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
let stopped = false;
|
|
347
|
+
let timer;
|
|
348
|
+
const tick = (delay) => {
|
|
349
|
+
timer = setTimeout(() => {
|
|
350
|
+
status().then((next) => {
|
|
351
|
+
if (!stopped && next !== void 0) {
|
|
352
|
+
setProgress(next);
|
|
353
|
+
tick(400);
|
|
354
|
+
}
|
|
355
|
+
}).catch(() => {});
|
|
356
|
+
}, delay);
|
|
357
|
+
};
|
|
358
|
+
tick(100);
|
|
359
|
+
return () => {
|
|
360
|
+
stopped = true;
|
|
361
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
362
|
+
};
|
|
363
|
+
}, [busy, status]);
|
|
364
|
+
const toggleDisabled = busy !== void 0 || toggleBusy !== void 0 || view.status === "ready" && view.failures.safeMode;
|
|
365
|
+
const onUserToggle = (id, enabled) => {
|
|
366
|
+
setToggleBusy({
|
|
367
|
+
kind: "user",
|
|
368
|
+
id
|
|
369
|
+
});
|
|
370
|
+
setError(void 0);
|
|
371
|
+
setEnabled(id, enabled).then((plugin) => {
|
|
372
|
+
setView((current) => current.status === "ready" ? {
|
|
373
|
+
...current,
|
|
374
|
+
plugins: current.plugins.map((item) => item.id === id ? plugin : item)
|
|
375
|
+
} : current);
|
|
376
|
+
setDirty(true);
|
|
377
|
+
setToggleBusy(void 0);
|
|
378
|
+
}).catch((reason) => {
|
|
379
|
+
setError(t("failed", { reason: messageOf(reason) }));
|
|
380
|
+
setToggleBusy(void 0);
|
|
381
|
+
});
|
|
382
|
+
};
|
|
383
|
+
const onProductToggle = (id, enabled) => {
|
|
384
|
+
setToggleBusy({
|
|
385
|
+
kind: "product",
|
|
386
|
+
id
|
|
387
|
+
});
|
|
388
|
+
setError(void 0);
|
|
389
|
+
controlsSetEnabled(id, enabled).then((controls) => {
|
|
390
|
+
setView((current) => current.status === "ready" ? {
|
|
391
|
+
...current,
|
|
392
|
+
controls
|
|
393
|
+
} : current);
|
|
394
|
+
setConflicts((previous) => previous.filter((change) => change.id !== id));
|
|
395
|
+
setDirty(true);
|
|
396
|
+
setToggleBusy(void 0);
|
|
397
|
+
}).catch((reason) => {
|
|
398
|
+
setError(t("failed", { reason: messageOf(reason) }));
|
|
399
|
+
setToggleBusy(void 0);
|
|
400
|
+
});
|
|
401
|
+
};
|
|
402
|
+
const onCheck = () => {
|
|
403
|
+
run({ kind: "check" }, async () => {
|
|
404
|
+
const found = await checkUpdates();
|
|
405
|
+
setUpdates(new Map(found.map((item) => [item.id, item.latest])));
|
|
406
|
+
});
|
|
407
|
+
};
|
|
408
|
+
const onUpdate = (id) => {
|
|
409
|
+
run({
|
|
410
|
+
kind: "update",
|
|
411
|
+
id
|
|
412
|
+
}, async () => {
|
|
413
|
+
await update(id);
|
|
414
|
+
setUpdates((previous) => {
|
|
415
|
+
const next = new Map(previous);
|
|
416
|
+
next.delete(id);
|
|
417
|
+
return next;
|
|
418
|
+
});
|
|
419
|
+
await reload();
|
|
420
|
+
});
|
|
421
|
+
};
|
|
422
|
+
const onUninstall = () => {
|
|
423
|
+
const target = uninstallTarget;
|
|
424
|
+
if (target === void 0) return;
|
|
425
|
+
run({
|
|
426
|
+
kind: "uninstall",
|
|
427
|
+
id: target.id
|
|
428
|
+
}, async () => {
|
|
429
|
+
await uninstall(target.id);
|
|
430
|
+
setUninstallTarget(void 0);
|
|
431
|
+
await reload();
|
|
432
|
+
});
|
|
433
|
+
};
|
|
434
|
+
/** Open a repair conversation seeded with one boot-failure record. `token`
|
|
435
|
+
* identifies the row for the in-flight label (plugin id, or a row key for
|
|
436
|
+
* unattributable failures). */
|
|
437
|
+
const onRepair = (failure, token) => {
|
|
438
|
+
if (view.status !== "ready" || busy !== void 0 || repairing !== void 0) return;
|
|
439
|
+
setError(void 0);
|
|
440
|
+
setRepairing(token);
|
|
441
|
+
repairPlugin(view.failures.pluginRoot, failureRepairMessage(failure, repairCopy(t))).then(() => {
|
|
442
|
+
setRepairing(void 0);
|
|
443
|
+
}).catch((reason) => {
|
|
444
|
+
setError(t("failed", { reason: messageOf(reason) }));
|
|
445
|
+
setRepairing(void 0);
|
|
446
|
+
});
|
|
447
|
+
};
|
|
448
|
+
/** Hand the latest failed install off to a repair conversation over the
|
|
449
|
+
* install root. The seed carries the install's own error (installError), not
|
|
450
|
+
* whatever error the row currently shows. */
|
|
451
|
+
const onRepairInstall = () => {
|
|
452
|
+
if (view.status !== "ready" || repairing !== void 0) return;
|
|
453
|
+
setError(void 0);
|
|
454
|
+
setRepairing("install");
|
|
455
|
+
repairPlugin(view.failures.pluginRoot, installRepairMessage(failedSpec ?? "", installError ?? "", repairCopy(t))).then(() => {
|
|
456
|
+
setError(void 0);
|
|
457
|
+
setFailedSpec(void 0);
|
|
458
|
+
setInstallError(void 0);
|
|
459
|
+
setRepairing(void 0);
|
|
460
|
+
}).catch((reason) => {
|
|
461
|
+
setError(t("failed", { reason: messageOf(reason) }));
|
|
462
|
+
setRepairing(void 0);
|
|
463
|
+
});
|
|
464
|
+
};
|
|
465
|
+
/** Copy a boot failure's message and stack for a manual repair conversation. */
|
|
466
|
+
const onCopy = (failure, token) => {
|
|
467
|
+
navigator.clipboard.writeText(`${failure.message}\n\n${failure.stack}`).then(() => {
|
|
468
|
+
setCopied(token);
|
|
469
|
+
}).catch(() => {
|
|
470
|
+
setError(t("failed", { reason: "clipboard unavailable" }));
|
|
471
|
+
});
|
|
472
|
+
};
|
|
473
|
+
const onExitSafeMode = () => {
|
|
474
|
+
if (busy !== void 0) return;
|
|
475
|
+
setError(void 0);
|
|
476
|
+
setSafeMode(false).then(() => {
|
|
477
|
+
setDirty(true);
|
|
478
|
+
reload().catch((reason) => {
|
|
479
|
+
setError(t("failed", { reason: messageOf(reason) }));
|
|
480
|
+
});
|
|
481
|
+
}).catch((reason) => {
|
|
482
|
+
setError(t("failed", { reason: messageOf(reason) }));
|
|
483
|
+
});
|
|
484
|
+
};
|
|
485
|
+
/** Undo one conflict action by flipping the product switch back. */
|
|
486
|
+
const onUndoConflict = (change) => {
|
|
487
|
+
if (change.to !== "disabled") return;
|
|
488
|
+
onProductToggle(change.id, true);
|
|
489
|
+
};
|
|
490
|
+
/** Hand one conflict notice off to a repair conversation over the plugin root. */
|
|
491
|
+
const onRepairConflict = (change) => {
|
|
492
|
+
if (view.status !== "ready" || busy !== void 0 || repairing !== void 0) return;
|
|
493
|
+
setError(void 0);
|
|
494
|
+
const token = `conflict:${change.id}`;
|
|
495
|
+
setRepairing(token);
|
|
496
|
+
repairPlugin(view.failures.pluginRoot, conflictRepairMessage({
|
|
497
|
+
id: change.id,
|
|
498
|
+
name: change.name,
|
|
499
|
+
from: change.from === "enabled" || change.from === "disabled" ? change.from : "uninstalled",
|
|
500
|
+
to: change.to === "enabled" || change.to === "disabled" ? change.to : "uninstalled"
|
|
501
|
+
}, repairCopy(t))).then(() => {
|
|
502
|
+
setRepairing(void 0);
|
|
503
|
+
}).catch((reason) => {
|
|
504
|
+
setError(t("failed", { reason: messageOf(reason) }));
|
|
505
|
+
setRepairing(void 0);
|
|
506
|
+
});
|
|
507
|
+
};
|
|
508
|
+
if (!isLoopback) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
509
|
+
className: plugin_manager_module_css_default.notice,
|
|
510
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: t("localOnlyTitle") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: t("localOnlyBody") })]
|
|
511
|
+
});
|
|
512
|
+
if (view.status === "loading") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
513
|
+
className: plugin_manager_module_css_default.state,
|
|
514
|
+
children: t("loading")
|
|
515
|
+
});
|
|
516
|
+
if (view.status === "error") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
517
|
+
className: plugin_manager_module_css_default.state,
|
|
518
|
+
children: t("failed", { reason: "load" })
|
|
519
|
+
});
|
|
520
|
+
const attributable = new Map(view.failures.items.filter((item) => item.pluginId !== "").map((item) => [item.pluginId, item]));
|
|
521
|
+
const unattributable = view.failures.items.filter((item) => item.pluginId === "");
|
|
522
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
523
|
+
className: plugin_manager_module_css_default.section,
|
|
524
|
+
"aria-busy": busy !== void 0 || toggleBusy !== void 0,
|
|
525
|
+
children: [
|
|
526
|
+
view.failures.safeMode && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
527
|
+
className: plugin_manager_module_css_default.safeModeBanner,
|
|
528
|
+
"data-safe-mode": true,
|
|
529
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: t("safeModeBanner") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
|
|
530
|
+
variant: "primary",
|
|
531
|
+
disabled: busy !== void 0,
|
|
532
|
+
onClick: onExitSafeMode,
|
|
533
|
+
children: t("exitSafeMode")
|
|
534
|
+
})]
|
|
535
|
+
}),
|
|
536
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
537
|
+
className: plugin_manager_module_css_default.installRow,
|
|
538
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
539
|
+
className: plugin_manager_module_css_default.spec,
|
|
540
|
+
type: "text",
|
|
541
|
+
value: spec,
|
|
542
|
+
placeholder: t("installPlaceholder"),
|
|
543
|
+
disabled: busy !== void 0,
|
|
544
|
+
onChange: (event) => {
|
|
545
|
+
setSpec(event.target.value);
|
|
546
|
+
},
|
|
547
|
+
onKeyDown: (event) => {
|
|
548
|
+
if (event.key === "Enter" && spec.trim() !== "" && busy === void 0) onInstall();
|
|
549
|
+
}
|
|
550
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
|
|
551
|
+
variant: "primary",
|
|
552
|
+
disabled: spec.trim() === "" || busy !== void 0,
|
|
553
|
+
onClick: onInstall,
|
|
554
|
+
children: busy !== void 0 && busy.kind === "install" ? t("installing") : t("install")
|
|
555
|
+
})]
|
|
556
|
+
}),
|
|
557
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
558
|
+
className: plugin_manager_module_css_default.hint,
|
|
559
|
+
children: t("installHint")
|
|
560
|
+
}),
|
|
561
|
+
(busy?.kind === "install" || busy?.kind === "update") && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
562
|
+
className: plugin_manager_module_css_default.progressRow,
|
|
563
|
+
role: "status",
|
|
564
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
565
|
+
className: plugin_manager_module_css_default.progressTrack,
|
|
566
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
567
|
+
className: plugin_manager_module_css_default.progressBar,
|
|
568
|
+
style: progress.percent === void 0 ? void 0 : { width: `${progress.percent}%` },
|
|
569
|
+
"data-indeterminate": progress.percent === void 0 ? "true" : void 0
|
|
570
|
+
})
|
|
571
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
572
|
+
className: plugin_manager_module_css_default.progressLabel,
|
|
573
|
+
children: progressLabel(progress, t)
|
|
574
|
+
})]
|
|
575
|
+
}),
|
|
576
|
+
error !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
577
|
+
className: plugin_manager_module_css_default.errorRow,
|
|
578
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
579
|
+
className: plugin_manager_module_css_default.error,
|
|
580
|
+
children: error
|
|
581
|
+
}), failedSpec !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
|
|
582
|
+
variant: "outline",
|
|
583
|
+
disabled: repairing !== void 0,
|
|
584
|
+
onClick: onRepairInstall,
|
|
585
|
+
children: repairing === "install" ? t("repairing") : t("repair")
|
|
586
|
+
})]
|
|
587
|
+
}),
|
|
588
|
+
conflicts.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
589
|
+
className: plugin_manager_module_css_default.conflicts,
|
|
590
|
+
children: [
|
|
591
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
|
|
592
|
+
className: plugin_manager_module_css_default.sectionTitle,
|
|
593
|
+
children: t("conflictTitle")
|
|
594
|
+
}),
|
|
595
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
|
|
596
|
+
className: plugin_manager_module_css_default.list,
|
|
597
|
+
children: conflicts.map((change) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
|
|
598
|
+
className: plugin_manager_module_css_default.row,
|
|
599
|
+
"data-conflict": change.id,
|
|
600
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
601
|
+
className: plugin_manager_module_css_default.meta,
|
|
602
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
603
|
+
className: plugin_manager_module_css_default.name,
|
|
604
|
+
children: change.name
|
|
605
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
606
|
+
className: plugin_manager_module_css_default.sub,
|
|
607
|
+
children: classifyChange(change) === "rule-disabled" ? t("conflictDisabled", { name: change.name }) : classifyChange(change) === "rule-enabled" ? t("conflictEnabled", { name: change.name }) : t("conflictChanged", { name: change.name })
|
|
608
|
+
})]
|
|
609
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
610
|
+
className: plugin_manager_module_css_default.actions,
|
|
611
|
+
children: [change.to === "disabled" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
|
|
612
|
+
variant: "outline",
|
|
613
|
+
disabled: toggleDisabled,
|
|
614
|
+
onClick: () => {
|
|
615
|
+
onUndoConflict(change);
|
|
616
|
+
},
|
|
617
|
+
children: t("undoConflict")
|
|
618
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
|
|
619
|
+
variant: "outline",
|
|
620
|
+
disabled: busy !== void 0 || repairing !== void 0,
|
|
621
|
+
onClick: () => {
|
|
622
|
+
onRepairConflict(change);
|
|
623
|
+
},
|
|
624
|
+
children: repairing === `conflict:${change.id}` ? t("repairing") : t("repair")
|
|
625
|
+
})]
|
|
626
|
+
})]
|
|
627
|
+
}, change.id))
|
|
628
|
+
}),
|
|
629
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
630
|
+
className: plugin_manager_module_css_default.hint,
|
|
631
|
+
children: t("conflictHint")
|
|
632
|
+
})
|
|
633
|
+
]
|
|
634
|
+
}),
|
|
635
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
636
|
+
className: plugin_manager_module_css_default.group,
|
|
637
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
|
|
638
|
+
className: plugin_manager_module_css_default.sectionTitle,
|
|
639
|
+
children: t("userPlugins")
|
|
640
|
+
}), view.plugins.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
641
|
+
className: plugin_manager_module_css_default.empty,
|
|
642
|
+
children: t("empty")
|
|
643
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
|
|
644
|
+
className: plugin_manager_module_css_default.list,
|
|
645
|
+
children: view.plugins.map((plugin) => {
|
|
646
|
+
const latest = updates.get(plugin.id);
|
|
647
|
+
const failure = attributable.get(plugin.id);
|
|
648
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
|
|
649
|
+
className: plugin_manager_module_css_default.row,
|
|
650
|
+
"data-plugin-id": plugin.id,
|
|
651
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
652
|
+
className: plugin_manager_module_css_default.meta,
|
|
653
|
+
children: [
|
|
654
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
655
|
+
className: plugin_manager_module_css_default.name,
|
|
656
|
+
children: plugin.name
|
|
657
|
+
}),
|
|
658
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
659
|
+
className: plugin_manager_module_css_default.sub,
|
|
660
|
+
children: [
|
|
661
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
662
|
+
className: plugin_manager_module_css_default.version,
|
|
663
|
+
children: t("version", { version: plugin.version })
|
|
664
|
+
}),
|
|
665
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
666
|
+
className: plugin_manager_module_css_default.sourceBadge,
|
|
667
|
+
"data-source": plugin.source.kind,
|
|
668
|
+
children: plugin.source.kind === "npm" ? t("npmSource") : t("gitSource")
|
|
669
|
+
}),
|
|
670
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
671
|
+
className: plugin_manager_module_css_default.specText,
|
|
672
|
+
title: plugin.source.spec,
|
|
673
|
+
children: plugin.source.spec
|
|
674
|
+
})
|
|
675
|
+
]
|
|
676
|
+
}),
|
|
677
|
+
latest !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
678
|
+
className: plugin_manager_module_css_default.latest,
|
|
679
|
+
children: t("latest", { version: latest })
|
|
680
|
+
}),
|
|
681
|
+
failure !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
682
|
+
className: plugin_manager_module_css_default.failure,
|
|
683
|
+
"data-plugin-failure": plugin.id,
|
|
684
|
+
children: [
|
|
685
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
686
|
+
className: plugin_manager_module_css_default.badge,
|
|
687
|
+
children: t("failureBadge")
|
|
688
|
+
}),
|
|
689
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
690
|
+
className: plugin_manager_module_css_default.failureMessage,
|
|
691
|
+
title: failure.message,
|
|
692
|
+
children: failure.message
|
|
693
|
+
}),
|
|
694
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
695
|
+
className: plugin_manager_module_css_default.failureActions,
|
|
696
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
|
|
697
|
+
variant: "primary",
|
|
698
|
+
disabled: busy !== void 0 || repairing !== void 0,
|
|
699
|
+
onClick: () => {
|
|
700
|
+
onRepair(failure, plugin.id);
|
|
701
|
+
},
|
|
702
|
+
children: repairing === plugin.id ? t("repairing") : t("repair")
|
|
703
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
|
|
704
|
+
variant: "outline",
|
|
705
|
+
disabled: busy !== void 0,
|
|
706
|
+
onClick: () => {
|
|
707
|
+
onCopy(failure, plugin.id);
|
|
708
|
+
},
|
|
709
|
+
children: copied === plugin.id ? t("copied") : t("copyError")
|
|
710
|
+
})]
|
|
711
|
+
})
|
|
712
|
+
]
|
|
713
|
+
})
|
|
714
|
+
]
|
|
715
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
716
|
+
className: plugin_manager_module_css_default.actions,
|
|
717
|
+
children: [
|
|
718
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
719
|
+
className: plugin_manager_module_css_default.stateLabel,
|
|
720
|
+
"data-state": plugin.enabled ? "enabled" : "disabled",
|
|
721
|
+
children: plugin.enabled ? t("enabled") : t("disabled")
|
|
722
|
+
}),
|
|
723
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
724
|
+
type: "button",
|
|
725
|
+
role: "switch",
|
|
726
|
+
"aria-checked": plugin.enabled,
|
|
727
|
+
"aria-label": plugin.enabled ? t("disableSwitch", { name: plugin.name }) : t("enableSwitch", { name: plugin.name }),
|
|
728
|
+
className: plugin_manager_module_css_default.switch,
|
|
729
|
+
disabled: toggleDisabled,
|
|
730
|
+
onClick: () => {
|
|
731
|
+
onUserToggle(plugin.id, !plugin.enabled);
|
|
732
|
+
}
|
|
733
|
+
}),
|
|
734
|
+
latest !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
|
|
735
|
+
variant: "outline",
|
|
736
|
+
disabled: busy !== void 0,
|
|
737
|
+
onClick: () => {
|
|
738
|
+
onUpdate(plugin.id);
|
|
739
|
+
},
|
|
740
|
+
children: busy?.kind === "update" && busy.id === plugin.id ? t("updating") : t("update")
|
|
741
|
+
}),
|
|
742
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
|
|
743
|
+
variant: "outline",
|
|
744
|
+
disabled: busy !== void 0,
|
|
745
|
+
onClick: () => {
|
|
746
|
+
setUninstallTarget({
|
|
747
|
+
id: plugin.id,
|
|
748
|
+
name: plugin.name
|
|
749
|
+
});
|
|
750
|
+
},
|
|
751
|
+
children: t("uninstall")
|
|
752
|
+
})
|
|
753
|
+
]
|
|
754
|
+
})]
|
|
755
|
+
}, plugin.id);
|
|
756
|
+
})
|
|
757
|
+
})]
|
|
758
|
+
}),
|
|
759
|
+
view.controls.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
760
|
+
className: plugin_manager_module_css_default.group,
|
|
761
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
|
|
762
|
+
className: plugin_manager_module_css_default.sectionTitle,
|
|
763
|
+
children: t("products")
|
|
764
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
|
|
765
|
+
className: plugin_manager_module_css_default.list,
|
|
766
|
+
children: view.controls.map((control) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
|
|
767
|
+
className: plugin_manager_module_css_default.row,
|
|
768
|
+
"data-product-id": control.id,
|
|
769
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
770
|
+
className: plugin_manager_module_css_default.meta,
|
|
771
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
772
|
+
className: plugin_manager_module_css_default.name,
|
|
773
|
+
children: control.name
|
|
774
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
775
|
+
className: plugin_manager_module_css_default.sub,
|
|
776
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
|
777
|
+
className: plugin_manager_module_css_default.link,
|
|
778
|
+
href: control.repository,
|
|
779
|
+
target: "_blank",
|
|
780
|
+
rel: "noreferrer",
|
|
781
|
+
children: t("source")
|
|
782
|
+
})
|
|
783
|
+
})]
|
|
784
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
785
|
+
className: plugin_manager_module_css_default.actions,
|
|
786
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
787
|
+
className: plugin_manager_module_css_default.stateLabel,
|
|
788
|
+
"data-state": control.state,
|
|
789
|
+
children: t(control.state)
|
|
790
|
+
}), control.state === "enabled" || control.state === "disabled" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
791
|
+
type: "button",
|
|
792
|
+
role: "switch",
|
|
793
|
+
"aria-checked": control.state === "enabled",
|
|
794
|
+
"aria-label": control.state === "enabled" ? t("disableSwitch", { name: control.name }) : t("enableSwitch", { name: control.name }),
|
|
795
|
+
className: plugin_manager_module_css_default.switch,
|
|
796
|
+
disabled: toggleDisabled,
|
|
797
|
+
onClick: () => {
|
|
798
|
+
onProductToggle(control.id, control.state !== "enabled");
|
|
799
|
+
}
|
|
800
|
+
}) : null]
|
|
801
|
+
})]
|
|
802
|
+
}, control.id))
|
|
803
|
+
})]
|
|
804
|
+
}),
|
|
805
|
+
unattributable.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
806
|
+
className: plugin_manager_module_css_default.group,
|
|
807
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
|
|
808
|
+
className: plugin_manager_module_css_default.sectionTitle,
|
|
809
|
+
children: t("failureGroupTitle")
|
|
810
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
|
|
811
|
+
className: plugin_manager_module_css_default.list,
|
|
812
|
+
children: unattributable.map((failure, index) => {
|
|
813
|
+
const token = `other:${index}`;
|
|
814
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", {
|
|
815
|
+
className: plugin_manager_module_css_default.row,
|
|
816
|
+
"data-plugin-failure": "other",
|
|
817
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
818
|
+
className: plugin_manager_module_css_default.meta,
|
|
819
|
+
children: [
|
|
820
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
821
|
+
className: plugin_manager_module_css_default.badge,
|
|
822
|
+
children: t("failureBadge")
|
|
823
|
+
}),
|
|
824
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
825
|
+
className: plugin_manager_module_css_default.failureMessage,
|
|
826
|
+
title: failure.message,
|
|
827
|
+
children: failure.message
|
|
828
|
+
}),
|
|
829
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
830
|
+
className: plugin_manager_module_css_default.failureActions,
|
|
831
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
|
|
832
|
+
variant: "primary",
|
|
833
|
+
disabled: busy !== void 0 || repairing !== void 0,
|
|
834
|
+
onClick: () => {
|
|
835
|
+
onRepair(failure, token);
|
|
836
|
+
},
|
|
837
|
+
children: repairing === token ? t("repairing") : t("repair")
|
|
838
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
|
|
839
|
+
variant: "outline",
|
|
840
|
+
disabled: busy !== void 0,
|
|
841
|
+
onClick: () => {
|
|
842
|
+
onCopy(failure, token);
|
|
843
|
+
},
|
|
844
|
+
children: copied === token ? t("copied") : t("copyError")
|
|
845
|
+
})]
|
|
846
|
+
})
|
|
847
|
+
]
|
|
848
|
+
})
|
|
849
|
+
}, `${failure.at}-${index}`);
|
|
850
|
+
})
|
|
851
|
+
})]
|
|
852
|
+
}),
|
|
853
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
854
|
+
className: plugin_manager_module_css_default.actionsRow,
|
|
855
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
|
|
856
|
+
variant: "outline",
|
|
857
|
+
disabled: busy !== void 0,
|
|
858
|
+
onClick: onCheck,
|
|
859
|
+
children: busy?.kind === "check" ? t("checking") : t("checkUpdates")
|
|
860
|
+
}), updates.size === 0 && busy === void 0 && view.plugins.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
861
|
+
className: plugin_manager_module_css_default.ok,
|
|
862
|
+
children: t("noUpdates")
|
|
863
|
+
})]
|
|
864
|
+
}),
|
|
865
|
+
toggleBusy !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
866
|
+
className: plugin_manager_module_css_default.applying,
|
|
867
|
+
"aria-live": "polite",
|
|
868
|
+
children: t("applying")
|
|
869
|
+
}),
|
|
870
|
+
dirty && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
871
|
+
className: plugin_manager_module_css_default.restartRow,
|
|
872
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: t("restartHint") })
|
|
873
|
+
}),
|
|
874
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_deepseek_ai_dsh_client_ui_primitives.Modal, {
|
|
875
|
+
title: t("uninstallConfirmTitle"),
|
|
876
|
+
open: uninstallTarget !== void 0,
|
|
877
|
+
onClose: () => {
|
|
878
|
+
setUninstallTarget(void 0);
|
|
879
|
+
},
|
|
880
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
881
|
+
className: plugin_manager_module_css_default.confirmBody,
|
|
882
|
+
children: t("uninstallConfirmBody", { name: uninstallTarget?.name ?? "" })
|
|
883
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
884
|
+
className: plugin_manager_module_css_default.modalActions,
|
|
885
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
|
|
886
|
+
variant: "outline",
|
|
887
|
+
disabled: busy !== void 0,
|
|
888
|
+
onClick: () => {
|
|
889
|
+
setUninstallTarget(void 0);
|
|
890
|
+
},
|
|
891
|
+
children: t("cancel")
|
|
892
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
|
|
893
|
+
variant: "primary",
|
|
894
|
+
className: plugin_manager_module_css_default.dangerButton,
|
|
895
|
+
disabled: busy !== void 0,
|
|
896
|
+
onClick: onUninstall,
|
|
897
|
+
children: t("confirm")
|
|
898
|
+
})]
|
|
899
|
+
})]
|
|
900
|
+
})
|
|
901
|
+
]
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
//#endregion
|
|
905
|
+
//#region src/client/locales.ts
|
|
906
|
+
/**
|
|
907
|
+
* Locale dictionaries for the plugin-manager tab. The zh dictionary is the
|
|
908
|
+
* key source; the en dictionary mirrors the exact key set.
|
|
909
|
+
* @module @linxin666/dsh-client-ui-plugin-manager/client
|
|
910
|
+
*/
|
|
911
|
+
/** Simplified Chinese copy (the key-set source of truth). */
|
|
912
|
+
const STATIC_ZH = {
|
|
913
|
+
tab: "插件管理",
|
|
914
|
+
loading: "正在读取插件…",
|
|
915
|
+
empty: "尚未安装任何用户插件。",
|
|
916
|
+
userPlugins: "用户插件",
|
|
917
|
+
products: "内置产品",
|
|
918
|
+
conflictTitle: "安装冲突",
|
|
919
|
+
conflictDisabled: "已自动禁用 {name},避免重复挂载。",
|
|
920
|
+
conflictEnabled: "已重新启用 {name}。",
|
|
921
|
+
conflictChanged: "{name} 的状态已变更。",
|
|
922
|
+
undoConflict: "撤销",
|
|
923
|
+
conflictHint: "冲突动作在安装时自动执行,撤销会写回开关并在重启后生效。",
|
|
924
|
+
installPlaceholder: "npm 包名(如 @scope/name)或 git 仓库 URL",
|
|
925
|
+
install: "安装",
|
|
926
|
+
installing: "安装中…",
|
|
927
|
+
installHint: "在 GitHub 或 npm 找到插件后,粘贴其 npm 包名或仓库地址安装;应用重启后插件生效。",
|
|
928
|
+
version: "已安装 {version}",
|
|
929
|
+
latest: "最新 {version}",
|
|
930
|
+
update: "更新",
|
|
931
|
+
updating: "更新中…",
|
|
932
|
+
checkUpdates: "检查更新",
|
|
933
|
+
checking: "检查中…",
|
|
934
|
+
noUpdates: "所有插件都是最新版本。",
|
|
935
|
+
uninstall: "卸载",
|
|
936
|
+
uninstallConfirmTitle: "卸载插件",
|
|
937
|
+
uninstallConfirmBody: "将删除 {name} 的安装目录与配置行,并在重启后生效。",
|
|
938
|
+
confirm: "确认卸载",
|
|
939
|
+
cancel: "取消",
|
|
940
|
+
restartHint: "插件变更将在重启应用后生效。",
|
|
941
|
+
failed: "操作失败:{reason}",
|
|
942
|
+
enabled: "已开启",
|
|
943
|
+
disabled: "已关闭",
|
|
944
|
+
mixed: "部分开启",
|
|
945
|
+
unavailable: "不可用",
|
|
946
|
+
uninstalled: "已卸载",
|
|
947
|
+
source: "查看源码",
|
|
948
|
+
applying: "正在应用更改…",
|
|
949
|
+
fetching: "正在获取插件信息…",
|
|
950
|
+
downloading: "正在下载…",
|
|
951
|
+
downloadingPercent: "正在下载 {percent}%",
|
|
952
|
+
extracting: "正在解压…",
|
|
953
|
+
writing: "正在写入配置…",
|
|
954
|
+
localOnlyTitle: "仅限本机操作",
|
|
955
|
+
localOnlyBody: "为了保护主机配置,插件管理只能从本机打开。",
|
|
956
|
+
failureBadge: "启动失败",
|
|
957
|
+
failureGroupTitle: "其他启动失败",
|
|
958
|
+
repair: "让 Agent 修复",
|
|
959
|
+
repairing: "正在创建修复对话…",
|
|
960
|
+
copyError: "复制错误",
|
|
961
|
+
copied: "已复制",
|
|
962
|
+
safeModeBanner: "安全模式:用户插件配置已跳过,插件开关不可用。",
|
|
963
|
+
exitSafeMode: "恢复正常模式并重启",
|
|
964
|
+
npmSource: "npm",
|
|
965
|
+
gitSource: "git",
|
|
966
|
+
enableSwitch: "开启 {name}",
|
|
967
|
+
disableSwitch: "关闭 {name}",
|
|
968
|
+
repairInstallTitle: "插件安装失败,请帮我诊断并修复。",
|
|
969
|
+
repairInstallSpecLabel: "安装目标",
|
|
970
|
+
repairInstallErrorLabel: "错误信息",
|
|
971
|
+
repairInstallAsk: "请检查该插件并重新安装;完成后告诉我结果。",
|
|
972
|
+
repairFailureTitle: "插件上次启动失败。请修复它。",
|
|
973
|
+
repairFailurePluginLabel: "插件",
|
|
974
|
+
repairFailureKindLabel: "失败类型",
|
|
975
|
+
repairFailureAtLabel: "时间",
|
|
976
|
+
repairFailureMessageLabel: "失败详情",
|
|
977
|
+
repairFailureStackLabel: "原始堆栈",
|
|
978
|
+
repairFailurePathLabel: "插件安装目录",
|
|
979
|
+
repairFailureAsk: "请检查并修复该插件;修复完成后告诉我如何重新启用。",
|
|
980
|
+
repairKindLoad: "加载失败",
|
|
981
|
+
repairKindHang: "启动挂起",
|
|
982
|
+
repairKindLate: "迟到拒绝",
|
|
983
|
+
repairConflictTitle: "正在处理插件安装冲突",
|
|
984
|
+
repairConflictPluginLabel: "冲突条目",
|
|
985
|
+
repairConflictChangeLabel: "状态变化",
|
|
986
|
+
repairConflictAsk: "请检查冲突双方的入口行 id 与挂载方式,消除重复挂载后告诉我如何重新启用。",
|
|
987
|
+
repairStateEnabled: "已开启",
|
|
988
|
+
repairStateDisabled: "已关闭",
|
|
989
|
+
repairStateUninstalled: "已卸载"
|
|
990
|
+
};
|
|
991
|
+
/** English copy, checked complete against the zh key set. */
|
|
992
|
+
const STATIC_EN = {
|
|
993
|
+
tab: "Plugin manager",
|
|
994
|
+
loading: "Reading plugins…",
|
|
995
|
+
empty: "No user plugins installed yet.",
|
|
996
|
+
userPlugins: "User plugins",
|
|
997
|
+
products: "Built-in products",
|
|
998
|
+
conflictTitle: "Install conflicts",
|
|
999
|
+
conflictDisabled: "Automatically disabled {name} to avoid double mounting.",
|
|
1000
|
+
conflictEnabled: "Re-enabled {name}.",
|
|
1001
|
+
conflictChanged: "The state of {name} changed.",
|
|
1002
|
+
undoConflict: "Undo",
|
|
1003
|
+
conflictHint: "Conflict actions run automatically at install time; undoing writes the switch back and applies after a restart.",
|
|
1004
|
+
installPlaceholder: "npm package (e.g. @scope/name) or git repository URL",
|
|
1005
|
+
install: "Install",
|
|
1006
|
+
installing: "Installing…",
|
|
1007
|
+
installHint: "Find a plugin on GitHub or npm, then paste its npm package name or repository URL; plugins load after a restart.",
|
|
1008
|
+
version: "Installed {version}",
|
|
1009
|
+
latest: "Latest {version}",
|
|
1010
|
+
update: "Update",
|
|
1011
|
+
updating: "Updating…",
|
|
1012
|
+
checkUpdates: "Check for updates",
|
|
1013
|
+
checking: "Checking…",
|
|
1014
|
+
noUpdates: "All plugins are up to date.",
|
|
1015
|
+
uninstall: "Uninstall",
|
|
1016
|
+
uninstallConfirmTitle: "Uninstall plugin",
|
|
1017
|
+
uninstallConfirmBody: "{name} and its configuration row will be removed; the change applies after a restart.",
|
|
1018
|
+
confirm: "Uninstall",
|
|
1019
|
+
cancel: "Cancel",
|
|
1020
|
+
restartHint: "Plugin changes take effect after restarting the application.",
|
|
1021
|
+
failed: "Operation failed: {reason}",
|
|
1022
|
+
enabled: "On",
|
|
1023
|
+
disabled: "Off",
|
|
1024
|
+
mixed: "Partially on",
|
|
1025
|
+
unavailable: "Unavailable",
|
|
1026
|
+
uninstalled: "Uninstalled",
|
|
1027
|
+
source: "View source",
|
|
1028
|
+
applying: "Applying change…",
|
|
1029
|
+
fetching: "Fetching plugin metadata…",
|
|
1030
|
+
downloading: "Downloading…",
|
|
1031
|
+
downloadingPercent: "Downloading {percent}%",
|
|
1032
|
+
extracting: "Extracting…",
|
|
1033
|
+
writing: "Writing configuration…",
|
|
1034
|
+
localOnlyTitle: "Available on this computer only",
|
|
1035
|
+
localOnlyBody: "To protect host configuration, plugin management is only available from a local browser.",
|
|
1036
|
+
failureBadge: "Startup failure",
|
|
1037
|
+
failureGroupTitle: "Other startup failures",
|
|
1038
|
+
repair: "Ask the agent to fix",
|
|
1039
|
+
repairing: "Opening repair conversation…",
|
|
1040
|
+
copyError: "Copy error",
|
|
1041
|
+
copied: "Copied",
|
|
1042
|
+
safeModeBanner: "Safe mode: user plugin configuration is skipped; plugin switches are disabled.",
|
|
1043
|
+
exitSafeMode: "Restore normal mode and restart",
|
|
1044
|
+
npmSource: "npm",
|
|
1045
|
+
gitSource: "git",
|
|
1046
|
+
enableSwitch: "Turn on {name}",
|
|
1047
|
+
disableSwitch: "Turn off {name}",
|
|
1048
|
+
repairInstallTitle: "The plugin installation failed. Please diagnose and fix it.",
|
|
1049
|
+
repairInstallSpecLabel: "Install target",
|
|
1050
|
+
repairInstallErrorLabel: "Error message",
|
|
1051
|
+
repairInstallAsk: "Please inspect the plugin and reinstall it; tell me when it is done.",
|
|
1052
|
+
repairFailureTitle: "A plugin failed to start last time. Please fix it.",
|
|
1053
|
+
repairFailurePluginLabel: "Plugin",
|
|
1054
|
+
repairFailureKindLabel: "Failure kind",
|
|
1055
|
+
repairFailureAtLabel: "At",
|
|
1056
|
+
repairFailureMessageLabel: "Failure details",
|
|
1057
|
+
repairFailureStackLabel: "Original stack",
|
|
1058
|
+
repairFailurePathLabel: "Plugin install directory",
|
|
1059
|
+
repairFailureAsk: "Please inspect and fix the plugin; tell me how to re-enable it afterwards.",
|
|
1060
|
+
repairKindLoad: "Load failure",
|
|
1061
|
+
repairKindHang: "Startup hang",
|
|
1062
|
+
repairKindLate: "Late rejection",
|
|
1063
|
+
repairConflictTitle: "Handling a plugin install conflict",
|
|
1064
|
+
repairConflictPluginLabel: "Conflicting entry",
|
|
1065
|
+
repairConflictChangeLabel: "State change",
|
|
1066
|
+
repairConflictAsk: "Inspect the entry ids and mounting of both sides, resolve the double mount, and tell me how to re-enable.",
|
|
1067
|
+
repairStateEnabled: "On",
|
|
1068
|
+
repairStateDisabled: "Off",
|
|
1069
|
+
repairStateUninstalled: "Uninstalled"
|
|
1070
|
+
};
|
|
1071
|
+
const zh = STATIC_ZH;
|
|
1072
|
+
const en = STATIC_EN;
|
|
1073
|
+
//#endregion
|
|
1074
|
+
//#region src/core/protocol.ts
|
|
1075
|
+
/** Whether a decoded value is a non-array object. */
|
|
1076
|
+
function isRecord(value) {
|
|
1077
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1078
|
+
}
|
|
1079
|
+
/** Whether a decoded value is a string. */
|
|
1080
|
+
function isString(value) {
|
|
1081
|
+
return typeof value === "string";
|
|
1082
|
+
}
|
|
1083
|
+
/** Validate one installed-plugin row. */
|
|
1084
|
+
function parsePlugin(value, index) {
|
|
1085
|
+
if (!isRecord(value) || !isString(value.id) || !isString(value.name) || !isString(value.version) || !isString(value.installedAt) || typeof value.enabled !== "boolean" || !isRecord(value.source) || value.source.kind !== "npm" && value.source.kind !== "git" || !isString(value.source.spec)) throw new Error(`plugin-manager: plugin row ${String(index)} is invalid`);
|
|
1086
|
+
return {
|
|
1087
|
+
id: value.id,
|
|
1088
|
+
name: value.name,
|
|
1089
|
+
version: value.version,
|
|
1090
|
+
source: {
|
|
1091
|
+
kind: value.source.kind,
|
|
1092
|
+
spec: value.source.spec
|
|
1093
|
+
},
|
|
1094
|
+
installedAt: value.installedAt,
|
|
1095
|
+
enabled: value.enabled,
|
|
1096
|
+
...isString(value.commit) ? { commit: value.commit } : {}
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
/**
|
|
1100
|
+
* Validate and normalize a `list` / `uninstall` response value.
|
|
1101
|
+
* @param value - decoded but untrusted response value.
|
|
1102
|
+
* @returns typed installed-plugin rows.
|
|
1103
|
+
*/
|
|
1104
|
+
function parsePluginList(value) {
|
|
1105
|
+
if (!isRecord(value) || !Array.isArray(value.plugins)) throw new Error("plugin-manager: response must contain a plugins array");
|
|
1106
|
+
return value.plugins.map((plugin, index) => parsePlugin(plugin, index));
|
|
1107
|
+
}
|
|
1108
|
+
/**
|
|
1109
|
+
* Validate and normalize an `install` / `update` / `set-enabled` response value.
|
|
1110
|
+
* @param value - decoded but untrusted response value.
|
|
1111
|
+
* @returns the typed installed-plugin row.
|
|
1112
|
+
*/
|
|
1113
|
+
function parseInstalledPlugin(value) {
|
|
1114
|
+
if (!isRecord(value) || value.plugin === void 0) throw new Error("plugin-manager: response must contain a plugin row");
|
|
1115
|
+
return parsePlugin(value.plugin, 0);
|
|
1116
|
+
}
|
|
1117
|
+
/**
|
|
1118
|
+
* Validate and normalize a plugin-control `list` / `set-enabled` response value.
|
|
1119
|
+
* @param value - decoded but untrusted response value.
|
|
1120
|
+
* @returns the typed control items.
|
|
1121
|
+
*/
|
|
1122
|
+
function parsePluginControlSnapshot(value) {
|
|
1123
|
+
if (!isRecord(value) || !Array.isArray(value.controls)) throw new Error("plugin-manager: response must contain a controls array");
|
|
1124
|
+
return value.controls.map((control, index) => {
|
|
1125
|
+
if (!isRecord(control) || !isString(control.id) || !isString(control.name) || !isString(control.repository) || control.state !== "enabled" && control.state !== "disabled" && control.state !== "mixed" && control.state !== "unavailable" && control.state !== "uninstalled") throw new Error(`plugin-manager: control row ${String(index)} is invalid`);
|
|
1126
|
+
return {
|
|
1127
|
+
id: control.id,
|
|
1128
|
+
name: control.name,
|
|
1129
|
+
repository: control.repository,
|
|
1130
|
+
state: control.state
|
|
1131
|
+
};
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
/**
|
|
1135
|
+
* Validate and normalize a `status` response value.
|
|
1136
|
+
* @param value - decoded but untrusted response value.
|
|
1137
|
+
* @returns the typed progress state.
|
|
1138
|
+
*/
|
|
1139
|
+
function parseInstallStatus(value) {
|
|
1140
|
+
if (!isRecord(value) || !isRecord(value.progress) || value.progress.kind !== "idle" && value.progress.kind !== "install" && value.progress.kind !== "update" || value.progress.stage !== "fetch" && value.progress.stage !== "download" && value.progress.stage !== "extract" && value.progress.stage !== "write" || value.progress.percent !== void 0 && (typeof value.progress.percent !== "number" || !Number.isFinite(value.progress.percent))) throw new Error("plugin-manager: response must contain a valid progress state");
|
|
1141
|
+
return {
|
|
1142
|
+
kind: value.progress.kind,
|
|
1143
|
+
stage: value.progress.stage,
|
|
1144
|
+
...typeof value.progress.percent === "number" ? { percent: value.progress.percent } : {}
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
/**
|
|
1148
|
+
* Validate and normalize a `check-updates` response value.
|
|
1149
|
+
* @param value - decoded but untrusted response value.
|
|
1150
|
+
* @returns typed update rows.
|
|
1151
|
+
*/
|
|
1152
|
+
function parseUpdateList(value) {
|
|
1153
|
+
if (!isRecord(value) || !Array.isArray(value.updates)) throw new Error("plugin-manager: response must contain an updates array");
|
|
1154
|
+
return value.updates.map((update, index) => {
|
|
1155
|
+
if (!isRecord(update) || !isString(update.id) || !isString(update.current) || !isString(update.latest)) throw new Error(`plugin-manager: update row ${String(index)} is invalid`);
|
|
1156
|
+
return {
|
|
1157
|
+
id: update.id,
|
|
1158
|
+
current: update.current,
|
|
1159
|
+
latest: update.latest
|
|
1160
|
+
};
|
|
1161
|
+
});
|
|
1162
|
+
}
|
|
1163
|
+
/**
|
|
1164
|
+
* Validate and normalize a `failures` response value.
|
|
1165
|
+
* @param value - decoded but untrusted response value.
|
|
1166
|
+
* @returns the typed failures snapshot.
|
|
1167
|
+
*/
|
|
1168
|
+
function parseFailuresSnapshot(value) {
|
|
1169
|
+
if (!isRecord(value) || !Array.isArray(value.items) || !isString(value.pluginRoot) || typeof value.safeMode !== "boolean") throw new Error("plugin-manager: response must contain a failures snapshot");
|
|
1170
|
+
return {
|
|
1171
|
+
items: value.items.map((item, index) => {
|
|
1172
|
+
if (!isRecord(item) || !isString(item.pluginId) || item.kind !== "load-failure" && item.kind !== "hang" && item.kind !== "late-rejection" || !isString(item.message) || !isString(item.stack) || !isString(item.installPath) || !isString(item.at)) throw new Error(`plugin-manager: failure row ${String(index)} is invalid`);
|
|
1173
|
+
return {
|
|
1174
|
+
pluginId: item.pluginId,
|
|
1175
|
+
kind: item.kind,
|
|
1176
|
+
message: item.message,
|
|
1177
|
+
stack: item.stack,
|
|
1178
|
+
installPath: item.installPath,
|
|
1179
|
+
at: item.at
|
|
1180
|
+
};
|
|
1181
|
+
}),
|
|
1182
|
+
pluginRoot: value.pluginRoot,
|
|
1183
|
+
safeMode: value.safeMode
|
|
1184
|
+
};
|
|
1185
|
+
}
|
|
1186
|
+
//#endregion
|
|
1187
|
+
//#region src/core/service.ts
|
|
1188
|
+
/** The cordis service name the browser half provides the face under. */
|
|
1189
|
+
const PLUGIN_MANAGER_SERVICE = "pluginManager";
|
|
1190
|
+
//#endregion
|
|
1191
|
+
//#region src/client/index.ts
|
|
1192
|
+
const NS = "settings.pluginManager";
|
|
1193
|
+
const CHANNEL = "/plugin-installer";
|
|
1194
|
+
const CONTROL_CHANNEL = "/plugin-control";
|
|
1195
|
+
const LIST_ENDPOINT = "list";
|
|
1196
|
+
const INSTALL_ENDPOINT = "install";
|
|
1197
|
+
const UPDATE_ENDPOINT = "update";
|
|
1198
|
+
const UNINSTALL_ENDPOINT = "uninstall";
|
|
1199
|
+
const SET_ENABLED_ENDPOINT = "set-enabled";
|
|
1200
|
+
const CHECK_UPDATES_ENDPOINT = "check-updates";
|
|
1201
|
+
const STATUS_ENDPOINT = "status";
|
|
1202
|
+
const FAILURES_ENDPOINT = "failures";
|
|
1203
|
+
const SET_SAFE_MODE_ENDPOINT = "set-safe-mode";
|
|
1204
|
+
const GATEWAY_PREFIX = "/api/plugin-manager";
|
|
1205
|
+
/** Gateway job polling cadence. */
|
|
1206
|
+
const JOB_POLL_MS = 500;
|
|
1207
|
+
/** Gateway job wait ceiling (the host add deadline is six minutes). */
|
|
1208
|
+
const JOB_WAIT_MS = 7 * 6e4;
|
|
1209
|
+
/** Services required by the slot registration and both channels. */
|
|
1210
|
+
const inject = [
|
|
1211
|
+
"slots",
|
|
1212
|
+
"locale",
|
|
1213
|
+
"connection",
|
|
1214
|
+
"workspaces",
|
|
1215
|
+
"sessions"
|
|
1216
|
+
];
|
|
1217
|
+
/**
|
|
1218
|
+
* Build the dual-channel face once: official-channel and gateway-channel
|
|
1219
|
+
* implementations, the mode detection that picks between them, the repair
|
|
1220
|
+
* handoff, and the change-notification listener set. The returned face is
|
|
1221
|
+
* both the tab's injected props and the value provided as the
|
|
1222
|
+
* `'pluginManager'` cordis service.
|
|
1223
|
+
* @param ctx - the client context (connection, workspaces, sessions).
|
|
1224
|
+
* @returns the shared face.
|
|
1225
|
+
*/
|
|
1226
|
+
function createPluginManagerFace(ctx) {
|
|
1227
|
+
const connection = ctx.get("connection");
|
|
1228
|
+
const call = async (endpoint, payload) => {
|
|
1229
|
+
const result = await connection.rpc.call(CHANNEL, endpoint, payload);
|
|
1230
|
+
if (!result.ok) throw new Error(`plugin-installer ${endpoint} failed: ${result.error.code}: ${result.error.message}`);
|
|
1231
|
+
return result.value;
|
|
1232
|
+
};
|
|
1233
|
+
const official = {
|
|
1234
|
+
list: async () => parsePluginList(await call(LIST_ENDPOINT, {})),
|
|
1235
|
+
install: async (spec) => parseInstalledPlugin(await call(INSTALL_ENDPOINT, { spec })),
|
|
1236
|
+
update: async (id) => parseInstalledPlugin(await call(UPDATE_ENDPOINT, { id })),
|
|
1237
|
+
uninstall: async (id) => parsePluginList(await call(UNINSTALL_ENDPOINT, { id })),
|
|
1238
|
+
setEnabled: async (id, enabled) => parseInstalledPlugin(await call(SET_ENABLED_ENDPOINT, {
|
|
1239
|
+
id,
|
|
1240
|
+
enabled
|
|
1241
|
+
})),
|
|
1242
|
+
checkUpdates: async () => parseUpdateList(await call(CHECK_UPDATES_ENDPOINT, {})),
|
|
1243
|
+
status: async () => parseInstallStatus(await call(STATUS_ENDPOINT, {})),
|
|
1244
|
+
failures: async () => parseFailuresSnapshot(await call(FAILURES_ENDPOINT, {})),
|
|
1245
|
+
setSafeMode: async (enabled) => {
|
|
1246
|
+
await call(SET_SAFE_MODE_ENDPOINT, { enabled });
|
|
1247
|
+
},
|
|
1248
|
+
controlsList: async () => parsePluginControlSnapshot(await connection.rpc.call(CONTROL_CHANNEL, "list", {}).then((result) => {
|
|
1249
|
+
if (!result.ok) throw new Error(`plugin-control list failed: ${result.error.code}: ${result.error.message}`);
|
|
1250
|
+
return result.value;
|
|
1251
|
+
})),
|
|
1252
|
+
controlsSetEnabled: async (pluginId, enabled) => parsePluginControlSnapshot(await connection.rpc.call(CONTROL_CHANNEL, "set-enabled", {
|
|
1253
|
+
pluginId,
|
|
1254
|
+
enabled
|
|
1255
|
+
}).then((result) => {
|
|
1256
|
+
if (!result.ok) throw new Error(`plugin-control set-enabled failed: ${result.error.code}: ${result.error.message}`);
|
|
1257
|
+
return result.value;
|
|
1258
|
+
}))
|
|
1259
|
+
};
|
|
1260
|
+
const gatewayJson = async (path, init) => {
|
|
1261
|
+
const response = await fetch(path, {
|
|
1262
|
+
...init,
|
|
1263
|
+
headers: {
|
|
1264
|
+
"content-type": "application/json",
|
|
1265
|
+
...init?.headers
|
|
1266
|
+
}
|
|
1267
|
+
});
|
|
1268
|
+
if (response.status === 403) throw new Error("plugin-manager: plugin management is only available from a local browser");
|
|
1269
|
+
if (!response.ok) {
|
|
1270
|
+
const body = await response.json().catch(() => ({}));
|
|
1271
|
+
throw new Error(body.error ?? `plugin-manager: gateway ${path} failed: HTTP ${String(response.status)}`);
|
|
1272
|
+
}
|
|
1273
|
+
return response.json();
|
|
1274
|
+
};
|
|
1275
|
+
/** Wait for one gateway job to settle, returning its wire state. */
|
|
1276
|
+
const waitJob = async (jobId) => {
|
|
1277
|
+
const deadline = Date.now() + JOB_WAIT_MS;
|
|
1278
|
+
for (;;) {
|
|
1279
|
+
const job = (await gatewayJson(`${GATEWAY_PREFIX}/status?job=${encodeURIComponent(jobId)}`)).job;
|
|
1280
|
+
if (job === void 0) throw new Error("plugin-manager: gateway job vanished");
|
|
1281
|
+
if (job.phase === "done") return job;
|
|
1282
|
+
if (job.phase === "error") throw new Error(job.error ?? "plugin-manager: gateway job failed");
|
|
1283
|
+
if (Date.now() > deadline) throw new Error("plugin-manager: gateway job timed out");
|
|
1284
|
+
await new Promise((resolve) => {
|
|
1285
|
+
setTimeout(resolve, JOB_POLL_MS);
|
|
1286
|
+
});
|
|
1287
|
+
}
|
|
1288
|
+
};
|
|
1289
|
+
/** The conflict ledger of the last settled gateway install. */
|
|
1290
|
+
let lastInstallConflicts = [];
|
|
1291
|
+
/** Whether a gateway install/remove is in flight (drives the progress row). */
|
|
1292
|
+
let gatewayInflight = false;
|
|
1293
|
+
const gateway = {
|
|
1294
|
+
list: async () => parsePluginList(await gatewayJson(`${GATEWAY_PREFIX}/list`)),
|
|
1295
|
+
install: async (spec) => {
|
|
1296
|
+
gatewayInflight = true;
|
|
1297
|
+
try {
|
|
1298
|
+
const started = await gatewayJson(`${GATEWAY_PREFIX}/install`, {
|
|
1299
|
+
method: "POST",
|
|
1300
|
+
body: JSON.stringify({ spec })
|
|
1301
|
+
});
|
|
1302
|
+
if (started.jobId === void 0) throw new Error("plugin-manager: gateway install returned no job");
|
|
1303
|
+
const job = await waitJob(started.jobId);
|
|
1304
|
+
lastInstallConflicts = Array.isArray(job.conflicts) ? job.conflicts : [];
|
|
1305
|
+
return parseInstalledPlugin({ plugin: job.plugin });
|
|
1306
|
+
} finally {
|
|
1307
|
+
gatewayInflight = false;
|
|
1308
|
+
}
|
|
1309
|
+
},
|
|
1310
|
+
update: async (id) => {
|
|
1311
|
+
const row = (await gateway.list()).find((item) => item.id === id);
|
|
1312
|
+
if (row === void 0) throw new Error(`plugin-manager: plugin ${id} is not installed`);
|
|
1313
|
+
return gateway.install(row.source.spec);
|
|
1314
|
+
},
|
|
1315
|
+
uninstall: async (id) => {
|
|
1316
|
+
gatewayInflight = true;
|
|
1317
|
+
try {
|
|
1318
|
+
const started = await gatewayJson(`${GATEWAY_PREFIX}/remove`, {
|
|
1319
|
+
method: "POST",
|
|
1320
|
+
body: JSON.stringify({ id })
|
|
1321
|
+
});
|
|
1322
|
+
if (started.jobId === void 0) throw new Error("plugin-manager: gateway remove returned no job");
|
|
1323
|
+
await waitJob(started.jobId);
|
|
1324
|
+
return gateway.list();
|
|
1325
|
+
} finally {
|
|
1326
|
+
gatewayInflight = false;
|
|
1327
|
+
}
|
|
1328
|
+
},
|
|
1329
|
+
setEnabled: async (id, enabled) => parseInstalledPlugin(await gatewayJson(`${GATEWAY_PREFIX}/set-enabled`, {
|
|
1330
|
+
method: "POST",
|
|
1331
|
+
body: JSON.stringify({
|
|
1332
|
+
id,
|
|
1333
|
+
enabled
|
|
1334
|
+
})
|
|
1335
|
+
})),
|
|
1336
|
+
checkUpdates: async () => parseUpdateList(await gatewayJson(`${GATEWAY_PREFIX}/check-updates`)),
|
|
1337
|
+
status: async () => gatewayInflight ? {
|
|
1338
|
+
kind: "install",
|
|
1339
|
+
stage: "download"
|
|
1340
|
+
} : {
|
|
1341
|
+
kind: "idle",
|
|
1342
|
+
stage: "fetch"
|
|
1343
|
+
},
|
|
1344
|
+
failures: async () => parseFailuresSnapshot(await gatewayJson(`${GATEWAY_PREFIX}/failures`)),
|
|
1345
|
+
setSafeMode: async () => {
|
|
1346
|
+
throw new Error("plugin-manager: safe mode is unavailable in this runtime");
|
|
1347
|
+
},
|
|
1348
|
+
controlsList: async () => [],
|
|
1349
|
+
controlsSetEnabled: async (pluginId, enabled) => {
|
|
1350
|
+
await gateway.setEnabled(pluginId, enabled);
|
|
1351
|
+
return [];
|
|
1352
|
+
}
|
|
1353
|
+
};
|
|
1354
|
+
let modePromise;
|
|
1355
|
+
const ensureMode = () => {
|
|
1356
|
+
if (modePromise === void 0) modePromise = (async () => {
|
|
1357
|
+
try {
|
|
1358
|
+
const mode = await gatewayJson(`${GATEWAY_PREFIX}/mode`);
|
|
1359
|
+
if (mode.official === true) return "official";
|
|
1360
|
+
if (mode.official === false) return "gateway";
|
|
1361
|
+
} catch {}
|
|
1362
|
+
try {
|
|
1363
|
+
return (await connection.rpc.call(CHANNEL, LIST_ENDPOINT, {})).ok ? "official" : "gateway";
|
|
1364
|
+
} catch {
|
|
1365
|
+
return "gateway";
|
|
1366
|
+
}
|
|
1367
|
+
})();
|
|
1368
|
+
return modePromise;
|
|
1369
|
+
};
|
|
1370
|
+
/**
|
|
1371
|
+
* Start a repair conversation for a failed plugin: resolve a workspace over
|
|
1372
|
+
* the plugin install root (created once, reused after), open a fresh
|
|
1373
|
+
* session there, and seed its first prompt with the failure details. The
|
|
1374
|
+
* session's workspace is the plugin home so the agent's file tools reach
|
|
1375
|
+
* the plugin code without leaving the workspace boundary.
|
|
1376
|
+
* @param pluginRoot - absolute plugin install root.
|
|
1377
|
+
* @param message - the seeded first user message.
|
|
1378
|
+
* @returns resolution after the prompt is accepted and the session opens.
|
|
1379
|
+
*/
|
|
1380
|
+
const repairPlugin = async (pluginRoot, message) => {
|
|
1381
|
+
const workspace = await ctx.workspaces.create({ path: pluginRoot });
|
|
1382
|
+
const sessionId = await ctx.workspaces.connectWorkspace(workspace.workspaceId);
|
|
1383
|
+
const binding = ctx.sessions.binding(sessionId);
|
|
1384
|
+
if (binding === void 0) throw new Error(`plugin-manager: repair session ${sessionId} is unavailable`);
|
|
1385
|
+
const result = await binding.session.prompt([{
|
|
1386
|
+
type: "text",
|
|
1387
|
+
text: message
|
|
1388
|
+
}], "queue");
|
|
1389
|
+
if (!result.ok) throw new Error(`plugin-manager: repair prompt failed: ${result.error.code}: ${result.error.message}`);
|
|
1390
|
+
ctx.sessions.open(sessionId);
|
|
1391
|
+
};
|
|
1392
|
+
/** Listeners subscribed through onChange; fired after successful mutations. */
|
|
1393
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
1394
|
+
/** Notify every listener; one listener throwing never breaks the others. */
|
|
1395
|
+
const notifyChange = () => {
|
|
1396
|
+
for (const listener of [...listeners]) try {
|
|
1397
|
+
listener();
|
|
1398
|
+
} catch {}
|
|
1399
|
+
};
|
|
1400
|
+
return {
|
|
1401
|
+
isLoopback: connection.isLoopback,
|
|
1402
|
+
list: async () => await ensureMode() === "official" ? official.list() : gateway.list(),
|
|
1403
|
+
install: async (spec) => {
|
|
1404
|
+
const item = await (await ensureMode() === "official" ? official.install(spec) : gateway.install(spec));
|
|
1405
|
+
notifyChange();
|
|
1406
|
+
return item;
|
|
1407
|
+
},
|
|
1408
|
+
update: async (id) => {
|
|
1409
|
+
const item = await (await ensureMode() === "official" ? official.update(id) : gateway.update(id));
|
|
1410
|
+
notifyChange();
|
|
1411
|
+
return item;
|
|
1412
|
+
},
|
|
1413
|
+
uninstall: async (id) => {
|
|
1414
|
+
const rows = await (await ensureMode() === "official" ? official.uninstall(id) : gateway.uninstall(id));
|
|
1415
|
+
notifyChange();
|
|
1416
|
+
return rows;
|
|
1417
|
+
},
|
|
1418
|
+
setEnabled: async (id, enabled) => {
|
|
1419
|
+
const item = await (await ensureMode() === "official" ? official.setEnabled(id, enabled) : gateway.setEnabled(id, enabled));
|
|
1420
|
+
notifyChange();
|
|
1421
|
+
return item;
|
|
1422
|
+
},
|
|
1423
|
+
checkUpdates: async () => await ensureMode() === "official" ? official.checkUpdates() : gateway.checkUpdates(),
|
|
1424
|
+
status: async () => await ensureMode() === "official" ? official.status() : gateway.status(),
|
|
1425
|
+
failures: async () => await ensureMode() === "official" ? official.failures() : gateway.failures(),
|
|
1426
|
+
setSafeMode: async (enabled) => await ensureMode() === "official" ? official.setSafeMode(enabled) : gateway.setSafeMode(),
|
|
1427
|
+
repairPlugin,
|
|
1428
|
+
controlsList: async () => await ensureMode() === "official" ? official.controlsList() : gateway.controlsList(),
|
|
1429
|
+
controlsSetEnabled: async (id, enabled) => await ensureMode() === "official" ? official.controlsSetEnabled(id, enabled) : gateway.controlsSetEnabled(id, enabled),
|
|
1430
|
+
lastInstallConflicts: () => lastInstallConflicts,
|
|
1431
|
+
onChange: (cb) => {
|
|
1432
|
+
listeners.add(cb);
|
|
1433
|
+
return () => {
|
|
1434
|
+
listeners.delete(cb);
|
|
1435
|
+
};
|
|
1436
|
+
}
|
|
1437
|
+
};
|
|
1438
|
+
}
|
|
1439
|
+
/** Contribute the family plugin-manager tab and provide the shared face. */
|
|
1440
|
+
function apply(ctx) {
|
|
1441
|
+
ctx.effect(() => ctx.locale.register(NS, {
|
|
1442
|
+
zh,
|
|
1443
|
+
en
|
|
1444
|
+
}), "plugin-manager: dictionaries");
|
|
1445
|
+
const face = createPluginManagerFace(ctx);
|
|
1446
|
+
ctx.provide(PLUGIN_MANAGER_SERVICE, face);
|
|
1447
|
+
ctx.slots.inject("settings.plugins.tab", () => ctx.slots.register({
|
|
1448
|
+
name: "settings.plugins.tab",
|
|
1449
|
+
id: "family-plugins",
|
|
1450
|
+
order: 20,
|
|
1451
|
+
label: () => ctx.locale.bind(NS)("tab"),
|
|
1452
|
+
locale: NS,
|
|
1453
|
+
inject: () => face
|
|
1454
|
+
}, PluginManagerTab));
|
|
1455
|
+
}
|
|
1456
|
+
//#endregion
|
|
1457
|
+
exports.apply = apply;
|
|
1458
|
+
exports.createPluginManagerFace = createPluginManagerFace;
|
|
1459
|
+
exports.inject = inject;
|
|
1460
|
+
return module.exports;
|
|
1461
|
+
}
|
|
1462
|
+
});
|
|
1463
|
+
|
|
1464
|
+
//# sourceMappingURL=client.js.map
|