@qmingjun/dsh-eda-mcp 0.0.0-stage → 1.1.12
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/AGENTS.md +63 -0
- package/CHANGELOG.md +792 -0
- package/CONTRIBUTING.md +154 -0
- package/LICENSE +55 -0
- package/README.md +290 -2
- package/README.zh.md +449 -0
- package/cordis.patch.yml +7 -0
- package/docs/design-rules.md +254 -0
- package/docs/dsh-version-sweep.md +73 -0
- package/docs/pitfalls.md +99 -0
- package/docs/project-status.md +100 -0
- package/docs/release.md +215 -0
- package/docs/schematic-workflow.md +297 -0
- package/docs/tools.md +184 -0
- package/jlc-extension/api-bridge.js +879 -0
- package/jlc-extension/extension.json +104 -0
- package/lib/bridge.mjs +4179 -0
- package/lib/client.js +1605 -0
- package/lib/extension-digest.json +6 -0
- package/lib/index.js +1261 -0
- package/package.json +144 -4
- package/src/bridge/design-intake.ts +133 -0
- package/src/bridge/design-rules.ts +228 -0
- package/src/bridge/eda-launch.ts +267 -0
- package/src/bridge/extension-package.ts +35 -0
- package/src/bridge/index.ts +3576 -0
- package/src/bridge/netlist-erc.ts +305 -0
- package/src/bridge/schematic-audit.ts +131 -0
- package/src/bridge/workflow-guide.ts +65 -0
- package/src/bridge-diagnostics.ts +185 -0
- package/src/client/EdaMcpSettingsCard.tsx +571 -0
- package/src/client/index.ts +40 -0
- package/src/client/locales.ts +83 -0
- package/src/client/settings-scope.ts +160 -0
- package/src/config-values.ts +60 -0
- package/src/guidance.ts +35 -0
- package/src/index.ts +365 -0
- package/src/loopback.ts +48 -0
- package/src/node-runtime.ts +120 -0
- package/src/routes.ts +377 -0
- package/src/skills-content.ts +309 -0
- package/src/skills.ts +91 -0
- package/test/config-values.test.ts +60 -0
- package/test/design-intake.test.ts +40 -0
- package/test/design-rules.test.ts +72 -0
- package/test/eda-launch.test.ts +114 -0
- package/test/extension-package.test.ts +27 -0
- package/test/extension-routes.test.ts +116 -0
- package/test/netlist-erc.test.ts +90 -0
- package/test/node-runtime.test.ts +65 -0
- package/test/schematic-audit.test.ts +71 -0
- package/test/seams.test.ts +164 -0
- package/test/skills.test.ts +68 -0
package/lib/client.js
ADDED
|
@@ -0,0 +1,1605 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "dsh-eda-mcp",
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
"use strict";
|
|
5
|
+
|
|
6
|
+
var module = { exports: {} };
|
|
7
|
+
var exports = module.exports;
|
|
8
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
11
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
12
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
13
|
+
var __export = (target, all) => {
|
|
14
|
+
for (var name in all)
|
|
15
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
|
+
|
|
27
|
+
// src/client/index.ts
|
|
28
|
+
var index_exports = {};
|
|
29
|
+
__export(index_exports, {
|
|
30
|
+
apply: () => apply,
|
|
31
|
+
inject: () => inject
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(index_exports);
|
|
34
|
+
|
|
35
|
+
// src/client/EdaMcpSettingsCard.tsx
|
|
36
|
+
var import_react = require("react");
|
|
37
|
+
|
|
38
|
+
var import_meta = {};
|
|
39
|
+
var createStoreImpl = (createState) => {
|
|
40
|
+
let state;
|
|
41
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
42
|
+
const setState = (partial, replace) => {
|
|
43
|
+
const nextState = typeof partial === "function" ? partial(state) : partial;
|
|
44
|
+
if (!Object.is(nextState, state)) {
|
|
45
|
+
const previousState = state;
|
|
46
|
+
state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
|
|
47
|
+
listeners.forEach((listener) => listener(state, previousState));
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const getState = () => state;
|
|
51
|
+
const subscribe = (listener) => {
|
|
52
|
+
listeners.add(listener);
|
|
53
|
+
return () => listeners.delete(listener);
|
|
54
|
+
};
|
|
55
|
+
const destroy = () => {
|
|
56
|
+
if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production") {
|
|
57
|
+
console.warn(
|
|
58
|
+
"[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
listeners.clear();
|
|
62
|
+
};
|
|
63
|
+
const api = { setState, getState, subscribe, destroy };
|
|
64
|
+
state = createState(setState, getState, api);
|
|
65
|
+
return api;
|
|
66
|
+
};
|
|
67
|
+
var createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
|
|
68
|
+
|
|
69
|
+
var subscribeWithSelectorImpl = (fn) => (set2, get, api) => {
|
|
70
|
+
const origSubscribe = api.subscribe;
|
|
71
|
+
api.subscribe = (selector, optListener, options) => {
|
|
72
|
+
let listener = selector;
|
|
73
|
+
if (optListener) {
|
|
74
|
+
const equalityFn = (options == null ? void 0 : options.equalityFn) || Object.is;
|
|
75
|
+
let currentSlice = selector(api.getState());
|
|
76
|
+
listener = (state) => {
|
|
77
|
+
const nextSlice = selector(state);
|
|
78
|
+
if (!equalityFn(currentSlice, nextSlice)) {
|
|
79
|
+
const previousSlice = currentSlice;
|
|
80
|
+
optListener(currentSlice = nextSlice, previousSlice);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
if (options == null ? void 0 : options.fireImmediately) {
|
|
84
|
+
optListener(currentSlice, currentSlice);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return origSubscribe(listener);
|
|
88
|
+
};
|
|
89
|
+
const initialState = fn(set2, get, api);
|
|
90
|
+
return initialState;
|
|
91
|
+
};
|
|
92
|
+
var subscribeWithSelector = subscribeWithSelectorImpl;
|
|
93
|
+
|
|
94
|
+
var NOTHING = Symbol.for("immer-nothing");
|
|
95
|
+
var DRAFTABLE = Symbol.for("immer-draftable");
|
|
96
|
+
var DRAFT_STATE = Symbol.for("immer-state");
|
|
97
|
+
var errors = true ? [
|
|
98
|
+
// All error codes, starting by 0:
|
|
99
|
+
function(plugin) {
|
|
100
|
+
return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`;
|
|
101
|
+
},
|
|
102
|
+
function(thing) {
|
|
103
|
+
return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${thing}'`;
|
|
104
|
+
},
|
|
105
|
+
"This object has been frozen and should not be mutated",
|
|
106
|
+
function(data) {
|
|
107
|
+
return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
|
|
108
|
+
},
|
|
109
|
+
"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
|
|
110
|
+
"Immer forbids circular references",
|
|
111
|
+
"The first or second argument to `produce` must be a function",
|
|
112
|
+
"The third argument to `produce` must be a function or undefined",
|
|
113
|
+
"First argument to `createDraft` must be a plain object, an array, or an immerable object",
|
|
114
|
+
"First argument to `finishDraft` must be a draft returned by `createDraft`",
|
|
115
|
+
function(thing) {
|
|
116
|
+
return `'current' expects a draft, got: ${thing}`;
|
|
117
|
+
},
|
|
118
|
+
"Object.defineProperty() cannot be used on an Immer draft",
|
|
119
|
+
"Object.setPrototypeOf() cannot be used on an Immer draft",
|
|
120
|
+
"Immer only supports deleting array indices",
|
|
121
|
+
"Immer only supports setting array indices and the 'length' property",
|
|
122
|
+
function(thing) {
|
|
123
|
+
return `'original' expects a draft, got: ${thing}`;
|
|
124
|
+
}
|
|
125
|
+
// Note: if more errors are added, the errorOffset in Patches.ts should be increased
|
|
126
|
+
// See Patches.ts for additional errors
|
|
127
|
+
] : [];
|
|
128
|
+
function die(error, ...args) {
|
|
129
|
+
if (true) {
|
|
130
|
+
const e = errors[error];
|
|
131
|
+
const msg = typeof e === "function" ? e.apply(null, args) : e;
|
|
132
|
+
throw new Error(`[Immer] ${msg}`);
|
|
133
|
+
}
|
|
134
|
+
throw new Error(
|
|
135
|
+
`[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
var getPrototypeOf = Object.getPrototypeOf;
|
|
139
|
+
function isDraft(value) {
|
|
140
|
+
return !!value && !!value[DRAFT_STATE];
|
|
141
|
+
}
|
|
142
|
+
function isDraftable(value) {
|
|
143
|
+
if (!value)
|
|
144
|
+
return false;
|
|
145
|
+
return isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!value.constructor?.[DRAFTABLE] || isMap(value) || isSet(value);
|
|
146
|
+
}
|
|
147
|
+
var objectCtorString = Object.prototype.constructor.toString();
|
|
148
|
+
var cachedCtorStrings = /* @__PURE__ */ new WeakMap();
|
|
149
|
+
function isPlainObject(value) {
|
|
150
|
+
if (!value || typeof value !== "object")
|
|
151
|
+
return false;
|
|
152
|
+
const proto = Object.getPrototypeOf(value);
|
|
153
|
+
if (proto === null || proto === Object.prototype)
|
|
154
|
+
return true;
|
|
155
|
+
const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
156
|
+
if (Ctor === Object)
|
|
157
|
+
return true;
|
|
158
|
+
if (typeof Ctor !== "function")
|
|
159
|
+
return false;
|
|
160
|
+
let ctorString = cachedCtorStrings.get(Ctor);
|
|
161
|
+
if (ctorString === void 0) {
|
|
162
|
+
ctorString = Function.toString.call(Ctor);
|
|
163
|
+
cachedCtorStrings.set(Ctor, ctorString);
|
|
164
|
+
}
|
|
165
|
+
return ctorString === objectCtorString;
|
|
166
|
+
}
|
|
167
|
+
function each(obj, iter, strict = true) {
|
|
168
|
+
if (getArchtype(obj) === 0) {
|
|
169
|
+
const keys = strict ? Reflect.ownKeys(obj) : Object.keys(obj);
|
|
170
|
+
keys.forEach((key) => {
|
|
171
|
+
iter(key, obj[key], obj);
|
|
172
|
+
});
|
|
173
|
+
} else {
|
|
174
|
+
obj.forEach((entry, index) => iter(index, entry, obj));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function getArchtype(thing) {
|
|
178
|
+
const state = thing[DRAFT_STATE];
|
|
179
|
+
return state ? state.type_ : Array.isArray(thing) ? 1 : isMap(thing) ? 2 : isSet(thing) ? 3 : 0;
|
|
180
|
+
}
|
|
181
|
+
function has(thing, prop) {
|
|
182
|
+
return getArchtype(thing) === 2 ? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
|
|
183
|
+
}
|
|
184
|
+
function set(thing, propOrOldValue, value) {
|
|
185
|
+
const t = getArchtype(thing);
|
|
186
|
+
if (t === 2)
|
|
187
|
+
thing.set(propOrOldValue, value);
|
|
188
|
+
else if (t === 3) {
|
|
189
|
+
thing.add(value);
|
|
190
|
+
} else
|
|
191
|
+
thing[propOrOldValue] = value;
|
|
192
|
+
}
|
|
193
|
+
function is(x, y) {
|
|
194
|
+
if (x === y) {
|
|
195
|
+
return x !== 0 || 1 / x === 1 / y;
|
|
196
|
+
} else {
|
|
197
|
+
return x !== x && y !== y;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function isMap(target) {
|
|
201
|
+
return target instanceof Map;
|
|
202
|
+
}
|
|
203
|
+
function isSet(target) {
|
|
204
|
+
return target instanceof Set;
|
|
205
|
+
}
|
|
206
|
+
function latest(state) {
|
|
207
|
+
return state.copy_ || state.base_;
|
|
208
|
+
}
|
|
209
|
+
function shallowCopy(base, strict) {
|
|
210
|
+
if (isMap(base)) {
|
|
211
|
+
return new Map(base);
|
|
212
|
+
}
|
|
213
|
+
if (isSet(base)) {
|
|
214
|
+
return new Set(base);
|
|
215
|
+
}
|
|
216
|
+
if (Array.isArray(base))
|
|
217
|
+
return Array.prototype.slice.call(base);
|
|
218
|
+
const isPlain = isPlainObject(base);
|
|
219
|
+
if (strict === true || strict === "class_only" && !isPlain) {
|
|
220
|
+
const descriptors = Object.getOwnPropertyDescriptors(base);
|
|
221
|
+
delete descriptors[DRAFT_STATE];
|
|
222
|
+
let keys = Reflect.ownKeys(descriptors);
|
|
223
|
+
for (let i = 0; i < keys.length; i++) {
|
|
224
|
+
const key = keys[i];
|
|
225
|
+
const desc = descriptors[key];
|
|
226
|
+
if (desc.writable === false) {
|
|
227
|
+
desc.writable = true;
|
|
228
|
+
desc.configurable = true;
|
|
229
|
+
}
|
|
230
|
+
if (desc.get || desc.set)
|
|
231
|
+
descriptors[key] = {
|
|
232
|
+
configurable: true,
|
|
233
|
+
writable: true,
|
|
234
|
+
// could live with !!desc.set as well here...
|
|
235
|
+
enumerable: desc.enumerable,
|
|
236
|
+
value: base[key]
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
return Object.create(getPrototypeOf(base), descriptors);
|
|
240
|
+
} else {
|
|
241
|
+
const proto = getPrototypeOf(base);
|
|
242
|
+
if (proto !== null && isPlain) {
|
|
243
|
+
return { ...base };
|
|
244
|
+
}
|
|
245
|
+
const obj = Object.create(proto);
|
|
246
|
+
return Object.assign(obj, base);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
function freeze(obj, deep = false) {
|
|
250
|
+
if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj))
|
|
251
|
+
return obj;
|
|
252
|
+
if (getArchtype(obj) > 1) {
|
|
253
|
+
Object.defineProperties(obj, {
|
|
254
|
+
set: dontMutateMethodOverride,
|
|
255
|
+
add: dontMutateMethodOverride,
|
|
256
|
+
clear: dontMutateMethodOverride,
|
|
257
|
+
delete: dontMutateMethodOverride
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
Object.freeze(obj);
|
|
261
|
+
if (deep)
|
|
262
|
+
Object.values(obj).forEach((value) => freeze(value, true));
|
|
263
|
+
return obj;
|
|
264
|
+
}
|
|
265
|
+
function dontMutateFrozenCollections() {
|
|
266
|
+
die(2);
|
|
267
|
+
}
|
|
268
|
+
var dontMutateMethodOverride = {
|
|
269
|
+
value: dontMutateFrozenCollections
|
|
270
|
+
};
|
|
271
|
+
function isFrozen(obj) {
|
|
272
|
+
if (obj === null || typeof obj !== "object")
|
|
273
|
+
return true;
|
|
274
|
+
return Object.isFrozen(obj);
|
|
275
|
+
}
|
|
276
|
+
var plugins = {};
|
|
277
|
+
function getPlugin(pluginKey) {
|
|
278
|
+
const plugin = plugins[pluginKey];
|
|
279
|
+
if (!plugin) {
|
|
280
|
+
die(0, pluginKey);
|
|
281
|
+
}
|
|
282
|
+
return plugin;
|
|
283
|
+
}
|
|
284
|
+
var currentScope;
|
|
285
|
+
function getCurrentScope() {
|
|
286
|
+
return currentScope;
|
|
287
|
+
}
|
|
288
|
+
function createScope(parent_, immer_) {
|
|
289
|
+
return {
|
|
290
|
+
drafts_: [],
|
|
291
|
+
parent_,
|
|
292
|
+
immer_,
|
|
293
|
+
// Whenever the modified draft contains a draft from another scope, we
|
|
294
|
+
// need to prevent auto-freezing so the unowned draft can be finalized.
|
|
295
|
+
canAutoFreeze_: true,
|
|
296
|
+
unfinalizedDrafts_: 0
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
function usePatchesInScope(scope, patchListener) {
|
|
300
|
+
if (patchListener) {
|
|
301
|
+
getPlugin("Patches");
|
|
302
|
+
scope.patches_ = [];
|
|
303
|
+
scope.inversePatches_ = [];
|
|
304
|
+
scope.patchListener_ = patchListener;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
function revokeScope(scope) {
|
|
308
|
+
leaveScope(scope);
|
|
309
|
+
scope.drafts_.forEach(revokeDraft);
|
|
310
|
+
scope.drafts_ = null;
|
|
311
|
+
}
|
|
312
|
+
function leaveScope(scope) {
|
|
313
|
+
if (scope === currentScope) {
|
|
314
|
+
currentScope = scope.parent_;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
function enterScope(immer2) {
|
|
318
|
+
return currentScope = createScope(currentScope, immer2);
|
|
319
|
+
}
|
|
320
|
+
function revokeDraft(draft) {
|
|
321
|
+
const state = draft[DRAFT_STATE];
|
|
322
|
+
if (state.type_ === 0 || state.type_ === 1)
|
|
323
|
+
state.revoke_();
|
|
324
|
+
else
|
|
325
|
+
state.revoked_ = true;
|
|
326
|
+
}
|
|
327
|
+
function processResult(result, scope) {
|
|
328
|
+
scope.unfinalizedDrafts_ = scope.drafts_.length;
|
|
329
|
+
const baseDraft = scope.drafts_[0];
|
|
330
|
+
const isReplaced = result !== void 0 && result !== baseDraft;
|
|
331
|
+
if (isReplaced) {
|
|
332
|
+
if (baseDraft[DRAFT_STATE].modified_) {
|
|
333
|
+
revokeScope(scope);
|
|
334
|
+
die(4);
|
|
335
|
+
}
|
|
336
|
+
if (isDraftable(result)) {
|
|
337
|
+
result = finalize(scope, result);
|
|
338
|
+
if (!scope.parent_)
|
|
339
|
+
maybeFreeze(scope, result);
|
|
340
|
+
}
|
|
341
|
+
if (scope.patches_) {
|
|
342
|
+
getPlugin("Patches").generateReplacementPatches_(
|
|
343
|
+
baseDraft[DRAFT_STATE].base_,
|
|
344
|
+
result,
|
|
345
|
+
scope.patches_,
|
|
346
|
+
scope.inversePatches_
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
} else {
|
|
350
|
+
result = finalize(scope, baseDraft, []);
|
|
351
|
+
}
|
|
352
|
+
revokeScope(scope);
|
|
353
|
+
if (scope.patches_) {
|
|
354
|
+
scope.patchListener_(scope.patches_, scope.inversePatches_);
|
|
355
|
+
}
|
|
356
|
+
return result !== NOTHING ? result : void 0;
|
|
357
|
+
}
|
|
358
|
+
function finalize(rootScope, value, path) {
|
|
359
|
+
if (isFrozen(value))
|
|
360
|
+
return value;
|
|
361
|
+
const useStrictIteration = rootScope.immer_.shouldUseStrictIteration();
|
|
362
|
+
const state = value[DRAFT_STATE];
|
|
363
|
+
if (!state) {
|
|
364
|
+
each(
|
|
365
|
+
value,
|
|
366
|
+
(key, childValue) => finalizeProperty(rootScope, state, value, key, childValue, path),
|
|
367
|
+
useStrictIteration
|
|
368
|
+
);
|
|
369
|
+
return value;
|
|
370
|
+
}
|
|
371
|
+
if (state.scope_ !== rootScope)
|
|
372
|
+
return value;
|
|
373
|
+
if (!state.modified_) {
|
|
374
|
+
maybeFreeze(rootScope, state.base_, true);
|
|
375
|
+
return state.base_;
|
|
376
|
+
}
|
|
377
|
+
if (!state.finalized_) {
|
|
378
|
+
state.finalized_ = true;
|
|
379
|
+
state.scope_.unfinalizedDrafts_--;
|
|
380
|
+
const result = state.copy_;
|
|
381
|
+
let resultEach = result;
|
|
382
|
+
let isSet2 = false;
|
|
383
|
+
if (state.type_ === 3) {
|
|
384
|
+
resultEach = new Set(result);
|
|
385
|
+
result.clear();
|
|
386
|
+
isSet2 = true;
|
|
387
|
+
}
|
|
388
|
+
each(
|
|
389
|
+
resultEach,
|
|
390
|
+
(key, childValue) => finalizeProperty(
|
|
391
|
+
rootScope,
|
|
392
|
+
state,
|
|
393
|
+
result,
|
|
394
|
+
key,
|
|
395
|
+
childValue,
|
|
396
|
+
path,
|
|
397
|
+
isSet2
|
|
398
|
+
),
|
|
399
|
+
useStrictIteration
|
|
400
|
+
);
|
|
401
|
+
maybeFreeze(rootScope, result, false);
|
|
402
|
+
if (path && rootScope.patches_) {
|
|
403
|
+
getPlugin("Patches").generatePatches_(
|
|
404
|
+
state,
|
|
405
|
+
path,
|
|
406
|
+
rootScope.patches_,
|
|
407
|
+
rootScope.inversePatches_
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return state.copy_;
|
|
412
|
+
}
|
|
413
|
+
function finalizeProperty(rootScope, parentState, targetObject, prop, childValue, rootPath, targetIsSet) {
|
|
414
|
+
if (childValue == null) {
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
if (typeof childValue !== "object" && !targetIsSet) {
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
const childIsFrozen = isFrozen(childValue);
|
|
421
|
+
if (childIsFrozen && !targetIsSet) {
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
if (childValue === targetObject)
|
|
425
|
+
die(5);
|
|
426
|
+
if (isDraft(childValue)) {
|
|
427
|
+
const path = rootPath && parentState && parentState.type_ !== 3 && // Set objects are atomic since they have no keys.
|
|
428
|
+
!has(parentState.assigned_, prop) ? rootPath.concat(prop) : void 0;
|
|
429
|
+
const res = finalize(rootScope, childValue, path);
|
|
430
|
+
set(targetObject, prop, res);
|
|
431
|
+
if (isDraft(res)) {
|
|
432
|
+
rootScope.canAutoFreeze_ = false;
|
|
433
|
+
} else
|
|
434
|
+
return;
|
|
435
|
+
} else if (targetIsSet) {
|
|
436
|
+
targetObject.add(childValue);
|
|
437
|
+
}
|
|
438
|
+
if (isDraftable(childValue) && !childIsFrozen) {
|
|
439
|
+
if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
if (parentState && parentState.base_ && parentState.base_[prop] === childValue && childIsFrozen) {
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
finalize(rootScope, childValue);
|
|
446
|
+
if ((!parentState || !parentState.scope_.parent_) && typeof prop !== "symbol" && (isMap(targetObject) ? targetObject.has(prop) : Object.prototype.propertyIsEnumerable.call(targetObject, prop)))
|
|
447
|
+
maybeFreeze(rootScope, childValue);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
function maybeFreeze(scope, value, deep = false) {
|
|
451
|
+
if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {
|
|
452
|
+
freeze(value, deep);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
function createProxyProxy(base, parent) {
|
|
456
|
+
const isArray = Array.isArray(base);
|
|
457
|
+
const state = {
|
|
458
|
+
type_: isArray ? 1 : 0,
|
|
459
|
+
// Track which produce call this is associated with.
|
|
460
|
+
scope_: parent ? parent.scope_ : getCurrentScope(),
|
|
461
|
+
// True for both shallow and deep changes.
|
|
462
|
+
modified_: false,
|
|
463
|
+
// Used during finalization.
|
|
464
|
+
finalized_: false,
|
|
465
|
+
// Track which properties have been assigned (true) or deleted (false).
|
|
466
|
+
assigned_: {},
|
|
467
|
+
// The parent draft state.
|
|
468
|
+
parent_: parent,
|
|
469
|
+
// The base state.
|
|
470
|
+
base_: base,
|
|
471
|
+
// The base proxy.
|
|
472
|
+
draft_: null,
|
|
473
|
+
// set below
|
|
474
|
+
// The base copy with any updated values.
|
|
475
|
+
copy_: null,
|
|
476
|
+
// Called by the `produce` function.
|
|
477
|
+
revoke_: null,
|
|
478
|
+
isManual_: false
|
|
479
|
+
};
|
|
480
|
+
let target = state;
|
|
481
|
+
let traps = objectTraps;
|
|
482
|
+
if (isArray) {
|
|
483
|
+
target = [state];
|
|
484
|
+
traps = arrayTraps;
|
|
485
|
+
}
|
|
486
|
+
const { revoke, proxy } = Proxy.revocable(target, traps);
|
|
487
|
+
state.draft_ = proxy;
|
|
488
|
+
state.revoke_ = revoke;
|
|
489
|
+
return proxy;
|
|
490
|
+
}
|
|
491
|
+
var objectTraps = {
|
|
492
|
+
get(state, prop) {
|
|
493
|
+
if (prop === DRAFT_STATE)
|
|
494
|
+
return state;
|
|
495
|
+
const source = latest(state);
|
|
496
|
+
if (!has(source, prop)) {
|
|
497
|
+
return readPropFromProto(state, source, prop);
|
|
498
|
+
}
|
|
499
|
+
const value = source[prop];
|
|
500
|
+
if (state.finalized_ || !isDraftable(value)) {
|
|
501
|
+
return value;
|
|
502
|
+
}
|
|
503
|
+
if (value === peek(state.base_, prop)) {
|
|
504
|
+
prepareCopy(state);
|
|
505
|
+
return state.copy_[prop] = createProxy(value, state);
|
|
506
|
+
}
|
|
507
|
+
return value;
|
|
508
|
+
},
|
|
509
|
+
has(state, prop) {
|
|
510
|
+
return prop in latest(state);
|
|
511
|
+
},
|
|
512
|
+
ownKeys(state) {
|
|
513
|
+
return Reflect.ownKeys(latest(state));
|
|
514
|
+
},
|
|
515
|
+
set(state, prop, value) {
|
|
516
|
+
const desc = getDescriptorFromProto(latest(state), prop);
|
|
517
|
+
if (desc?.set) {
|
|
518
|
+
desc.set.call(state.draft_, value);
|
|
519
|
+
return true;
|
|
520
|
+
}
|
|
521
|
+
if (!state.modified_) {
|
|
522
|
+
const current2 = peek(latest(state), prop);
|
|
523
|
+
const currentState = current2?.[DRAFT_STATE];
|
|
524
|
+
if (currentState && currentState.base_ === value) {
|
|
525
|
+
state.copy_[prop] = value;
|
|
526
|
+
state.assigned_[prop] = false;
|
|
527
|
+
return true;
|
|
528
|
+
}
|
|
529
|
+
if (is(value, current2) && (value !== void 0 || has(state.base_, prop)))
|
|
530
|
+
return true;
|
|
531
|
+
prepareCopy(state);
|
|
532
|
+
markChanged(state);
|
|
533
|
+
}
|
|
534
|
+
if (state.copy_[prop] === value && // special case: handle new props with value 'undefined'
|
|
535
|
+
(value !== void 0 || prop in state.copy_) || // special case: NaN
|
|
536
|
+
Number.isNaN(value) && Number.isNaN(state.copy_[prop]))
|
|
537
|
+
return true;
|
|
538
|
+
state.copy_[prop] = value;
|
|
539
|
+
state.assigned_[prop] = true;
|
|
540
|
+
return true;
|
|
541
|
+
},
|
|
542
|
+
deleteProperty(state, prop) {
|
|
543
|
+
if (peek(state.base_, prop) !== void 0 || prop in state.base_) {
|
|
544
|
+
state.assigned_[prop] = false;
|
|
545
|
+
prepareCopy(state);
|
|
546
|
+
markChanged(state);
|
|
547
|
+
} else {
|
|
548
|
+
delete state.assigned_[prop];
|
|
549
|
+
}
|
|
550
|
+
if (state.copy_) {
|
|
551
|
+
delete state.copy_[prop];
|
|
552
|
+
}
|
|
553
|
+
return true;
|
|
554
|
+
},
|
|
555
|
+
// Note: We never coerce `desc.value` into an Immer draft, because we can't make
|
|
556
|
+
// the same guarantee in ES5 mode.
|
|
557
|
+
getOwnPropertyDescriptor(state, prop) {
|
|
558
|
+
const owner = latest(state);
|
|
559
|
+
const desc = Reflect.getOwnPropertyDescriptor(owner, prop);
|
|
560
|
+
if (!desc)
|
|
561
|
+
return desc;
|
|
562
|
+
return {
|
|
563
|
+
writable: true,
|
|
564
|
+
configurable: state.type_ !== 1 || prop !== "length",
|
|
565
|
+
enumerable: desc.enumerable,
|
|
566
|
+
value: owner[prop]
|
|
567
|
+
};
|
|
568
|
+
},
|
|
569
|
+
defineProperty() {
|
|
570
|
+
die(11);
|
|
571
|
+
},
|
|
572
|
+
getPrototypeOf(state) {
|
|
573
|
+
return getPrototypeOf(state.base_);
|
|
574
|
+
},
|
|
575
|
+
setPrototypeOf() {
|
|
576
|
+
die(12);
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
var arrayTraps = {};
|
|
580
|
+
each(objectTraps, (key, fn) => {
|
|
581
|
+
arrayTraps[key] = function() {
|
|
582
|
+
arguments[0] = arguments[0][0];
|
|
583
|
+
return fn.apply(this, arguments);
|
|
584
|
+
};
|
|
585
|
+
});
|
|
586
|
+
arrayTraps.deleteProperty = function(state, prop) {
|
|
587
|
+
if (isNaN(parseInt(prop)))
|
|
588
|
+
die(13);
|
|
589
|
+
return arrayTraps.set.call(this, state, prop, void 0);
|
|
590
|
+
};
|
|
591
|
+
arrayTraps.set = function(state, prop, value) {
|
|
592
|
+
if (prop !== "length" && isNaN(parseInt(prop)))
|
|
593
|
+
die(14);
|
|
594
|
+
return objectTraps.set.call(this, state[0], prop, value, state[0]);
|
|
595
|
+
};
|
|
596
|
+
function peek(draft, prop) {
|
|
597
|
+
const state = draft[DRAFT_STATE];
|
|
598
|
+
const source = state ? latest(state) : draft;
|
|
599
|
+
return source[prop];
|
|
600
|
+
}
|
|
601
|
+
function readPropFromProto(state, source, prop) {
|
|
602
|
+
const desc = getDescriptorFromProto(source, prop);
|
|
603
|
+
return desc ? `value` in desc ? desc.value : (
|
|
604
|
+
// This is a very special case, if the prop is a getter defined by the
|
|
605
|
+
// prototype, we should invoke it with the draft as context!
|
|
606
|
+
desc.get?.call(state.draft_)
|
|
607
|
+
) : void 0;
|
|
608
|
+
}
|
|
609
|
+
function getDescriptorFromProto(source, prop) {
|
|
610
|
+
if (!(prop in source))
|
|
611
|
+
return void 0;
|
|
612
|
+
let proto = getPrototypeOf(source);
|
|
613
|
+
while (proto) {
|
|
614
|
+
const desc = Object.getOwnPropertyDescriptor(proto, prop);
|
|
615
|
+
if (desc)
|
|
616
|
+
return desc;
|
|
617
|
+
proto = getPrototypeOf(proto);
|
|
618
|
+
}
|
|
619
|
+
return void 0;
|
|
620
|
+
}
|
|
621
|
+
function markChanged(state) {
|
|
622
|
+
if (!state.modified_) {
|
|
623
|
+
state.modified_ = true;
|
|
624
|
+
if (state.parent_) {
|
|
625
|
+
markChanged(state.parent_);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
function prepareCopy(state) {
|
|
630
|
+
if (!state.copy_) {
|
|
631
|
+
state.copy_ = shallowCopy(
|
|
632
|
+
state.base_,
|
|
633
|
+
state.scope_.immer_.useStrictShallowCopy_
|
|
634
|
+
);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
var Immer2 = class {
|
|
638
|
+
constructor(config) {
|
|
639
|
+
this.autoFreeze_ = true;
|
|
640
|
+
this.useStrictShallowCopy_ = false;
|
|
641
|
+
this.useStrictIteration_ = true;
|
|
642
|
+
this.produce = (base, recipe, patchListener) => {
|
|
643
|
+
if (typeof base === "function" && typeof recipe !== "function") {
|
|
644
|
+
const defaultBase = recipe;
|
|
645
|
+
recipe = base;
|
|
646
|
+
const self = this;
|
|
647
|
+
return function curriedProduce(base2 = defaultBase, ...args) {
|
|
648
|
+
return self.produce(base2, (draft) => recipe.call(this, draft, ...args));
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
if (typeof recipe !== "function")
|
|
652
|
+
die(6);
|
|
653
|
+
if (patchListener !== void 0 && typeof patchListener !== "function")
|
|
654
|
+
die(7);
|
|
655
|
+
let result;
|
|
656
|
+
if (isDraftable(base)) {
|
|
657
|
+
const scope = enterScope(this);
|
|
658
|
+
const proxy = createProxy(base, void 0);
|
|
659
|
+
let hasError = true;
|
|
660
|
+
try {
|
|
661
|
+
result = recipe(proxy);
|
|
662
|
+
hasError = false;
|
|
663
|
+
} finally {
|
|
664
|
+
if (hasError)
|
|
665
|
+
revokeScope(scope);
|
|
666
|
+
else
|
|
667
|
+
leaveScope(scope);
|
|
668
|
+
}
|
|
669
|
+
usePatchesInScope(scope, patchListener);
|
|
670
|
+
return processResult(result, scope);
|
|
671
|
+
} else if (!base || typeof base !== "object") {
|
|
672
|
+
result = recipe(base);
|
|
673
|
+
if (result === void 0)
|
|
674
|
+
result = base;
|
|
675
|
+
if (result === NOTHING)
|
|
676
|
+
result = void 0;
|
|
677
|
+
if (this.autoFreeze_)
|
|
678
|
+
freeze(result, true);
|
|
679
|
+
if (patchListener) {
|
|
680
|
+
const p = [];
|
|
681
|
+
const ip = [];
|
|
682
|
+
getPlugin("Patches").generateReplacementPatches_(base, result, p, ip);
|
|
683
|
+
patchListener(p, ip);
|
|
684
|
+
}
|
|
685
|
+
return result;
|
|
686
|
+
} else
|
|
687
|
+
die(1, base);
|
|
688
|
+
};
|
|
689
|
+
this.produceWithPatches = (base, recipe) => {
|
|
690
|
+
if (typeof base === "function") {
|
|
691
|
+
return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));
|
|
692
|
+
}
|
|
693
|
+
let patches, inversePatches;
|
|
694
|
+
const result = this.produce(base, recipe, (p, ip) => {
|
|
695
|
+
patches = p;
|
|
696
|
+
inversePatches = ip;
|
|
697
|
+
});
|
|
698
|
+
return [result, patches, inversePatches];
|
|
699
|
+
};
|
|
700
|
+
if (typeof config?.autoFreeze === "boolean")
|
|
701
|
+
this.setAutoFreeze(config.autoFreeze);
|
|
702
|
+
if (typeof config?.useStrictShallowCopy === "boolean")
|
|
703
|
+
this.setUseStrictShallowCopy(config.useStrictShallowCopy);
|
|
704
|
+
if (typeof config?.useStrictIteration === "boolean")
|
|
705
|
+
this.setUseStrictIteration(config.useStrictIteration);
|
|
706
|
+
}
|
|
707
|
+
createDraft(base) {
|
|
708
|
+
if (!isDraftable(base))
|
|
709
|
+
die(8);
|
|
710
|
+
if (isDraft(base))
|
|
711
|
+
base = current(base);
|
|
712
|
+
const scope = enterScope(this);
|
|
713
|
+
const proxy = createProxy(base, void 0);
|
|
714
|
+
proxy[DRAFT_STATE].isManual_ = true;
|
|
715
|
+
leaveScope(scope);
|
|
716
|
+
return proxy;
|
|
717
|
+
}
|
|
718
|
+
finishDraft(draft, patchListener) {
|
|
719
|
+
const state = draft && draft[DRAFT_STATE];
|
|
720
|
+
if (!state || !state.isManual_)
|
|
721
|
+
die(9);
|
|
722
|
+
const { scope_: scope } = state;
|
|
723
|
+
usePatchesInScope(scope, patchListener);
|
|
724
|
+
return processResult(void 0, scope);
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* Pass true to automatically freeze all copies created by Immer.
|
|
728
|
+
*
|
|
729
|
+
* By default, auto-freezing is enabled.
|
|
730
|
+
*/
|
|
731
|
+
setAutoFreeze(value) {
|
|
732
|
+
this.autoFreeze_ = value;
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* Pass true to enable strict shallow copy.
|
|
736
|
+
*
|
|
737
|
+
* By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
|
|
738
|
+
*/
|
|
739
|
+
setUseStrictShallowCopy(value) {
|
|
740
|
+
this.useStrictShallowCopy_ = value;
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* Pass false to use faster iteration that skips non-enumerable properties
|
|
744
|
+
* but still handles symbols for compatibility.
|
|
745
|
+
*
|
|
746
|
+
* By default, strict iteration is enabled (includes all own properties).
|
|
747
|
+
*/
|
|
748
|
+
setUseStrictIteration(value) {
|
|
749
|
+
this.useStrictIteration_ = value;
|
|
750
|
+
}
|
|
751
|
+
shouldUseStrictIteration() {
|
|
752
|
+
return this.useStrictIteration_;
|
|
753
|
+
}
|
|
754
|
+
applyPatches(base, patches) {
|
|
755
|
+
let i;
|
|
756
|
+
for (i = patches.length - 1; i >= 0; i--) {
|
|
757
|
+
const patch = patches[i];
|
|
758
|
+
if (patch.path.length === 0 && patch.op === "replace") {
|
|
759
|
+
base = patch.value;
|
|
760
|
+
break;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
if (i > -1) {
|
|
764
|
+
patches = patches.slice(i + 1);
|
|
765
|
+
}
|
|
766
|
+
const applyPatchesImpl = getPlugin("Patches").applyPatches_;
|
|
767
|
+
if (isDraft(base)) {
|
|
768
|
+
return applyPatchesImpl(base, patches);
|
|
769
|
+
}
|
|
770
|
+
return this.produce(
|
|
771
|
+
base,
|
|
772
|
+
(draft) => applyPatchesImpl(draft, patches)
|
|
773
|
+
);
|
|
774
|
+
}
|
|
775
|
+
};
|
|
776
|
+
function createProxy(value, parent) {
|
|
777
|
+
const draft = isMap(value) ? getPlugin("MapSet").proxyMap_(value, parent) : isSet(value) ? getPlugin("MapSet").proxySet_(value, parent) : createProxyProxy(value, parent);
|
|
778
|
+
const scope = parent ? parent.scope_ : getCurrentScope();
|
|
779
|
+
scope.drafts_.push(draft);
|
|
780
|
+
return draft;
|
|
781
|
+
}
|
|
782
|
+
function current(value) {
|
|
783
|
+
if (!isDraft(value))
|
|
784
|
+
die(10, value);
|
|
785
|
+
return currentImpl(value);
|
|
786
|
+
}
|
|
787
|
+
function currentImpl(value) {
|
|
788
|
+
if (!isDraftable(value) || isFrozen(value))
|
|
789
|
+
return value;
|
|
790
|
+
const state = value[DRAFT_STATE];
|
|
791
|
+
let copy;
|
|
792
|
+
let strict = true;
|
|
793
|
+
if (state) {
|
|
794
|
+
if (!state.modified_)
|
|
795
|
+
return state.base_;
|
|
796
|
+
state.finalized_ = true;
|
|
797
|
+
copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
|
|
798
|
+
strict = state.scope_.immer_.shouldUseStrictIteration();
|
|
799
|
+
} else {
|
|
800
|
+
copy = shallowCopy(value, true);
|
|
801
|
+
}
|
|
802
|
+
each(
|
|
803
|
+
copy,
|
|
804
|
+
(key, childValue) => {
|
|
805
|
+
set(copy, key, currentImpl(childValue));
|
|
806
|
+
},
|
|
807
|
+
strict
|
|
808
|
+
);
|
|
809
|
+
if (state) {
|
|
810
|
+
state.finalized_ = false;
|
|
811
|
+
}
|
|
812
|
+
return copy;
|
|
813
|
+
}
|
|
814
|
+
var immer = new Immer2();
|
|
815
|
+
var produce = immer.produce;
|
|
816
|
+
|
|
817
|
+
function notifySubscribers(listeners, label, ...args) {
|
|
818
|
+
for (const listener of [...listeners]) try {
|
|
819
|
+
listener(...args);
|
|
820
|
+
} catch (error) {
|
|
821
|
+
console.error(`${label} subscriber failed:`, error);
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
function rafBatch(notify) {
|
|
825
|
+
const schedule = typeof requestAnimationFrame === "function" ? (fn) => {
|
|
826
|
+
requestAnimationFrame(() => {
|
|
827
|
+
fn();
|
|
828
|
+
});
|
|
829
|
+
} : (fn) => {
|
|
830
|
+
queueMicrotask(fn);
|
|
831
|
+
};
|
|
832
|
+
let scheduled = false;
|
|
833
|
+
return () => {
|
|
834
|
+
if (scheduled) return;
|
|
835
|
+
scheduled = true;
|
|
836
|
+
schedule(() => {
|
|
837
|
+
scheduled = false;
|
|
838
|
+
notify();
|
|
839
|
+
});
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
function createSnapshotStore(init, opts) {
|
|
843
|
+
const withSelector = subscribeWithSelector(() => init);
|
|
844
|
+
const api = createStore()(withSelector);
|
|
845
|
+
if (opts?.persist) attachPersistence(api, opts.persist.name);
|
|
846
|
+
let subscribe = (fn) => api.subscribe(() => {
|
|
847
|
+
notifySubscribers([fn], "[client-store]");
|
|
848
|
+
});
|
|
849
|
+
if (opts?.flush === "raf") {
|
|
850
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
851
|
+
const flush = rafBatch(() => {
|
|
852
|
+
notifySubscribers(listeners, "[client-store]");
|
|
853
|
+
});
|
|
854
|
+
api.subscribe(flush);
|
|
855
|
+
subscribe = (fn) => {
|
|
856
|
+
listeners.add(fn);
|
|
857
|
+
return () => {
|
|
858
|
+
listeners.delete(fn);
|
|
859
|
+
};
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
return {
|
|
863
|
+
getSnapshot: () => api.getState(),
|
|
864
|
+
subscribe: (fn) => subscribe(fn),
|
|
865
|
+
update: (mutator) => {
|
|
866
|
+
api.setState(produce(api.getState(), (draft) => {
|
|
867
|
+
mutator(draft);
|
|
868
|
+
}), true);
|
|
869
|
+
},
|
|
870
|
+
set: (next) => {
|
|
871
|
+
api.setState(devFreeze(next), true);
|
|
872
|
+
}
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
function attachPersistence(api, name) {
|
|
876
|
+
if (typeof localStorage === "undefined") return;
|
|
877
|
+
try {
|
|
878
|
+
const raw = localStorage.getItem(name);
|
|
879
|
+
if (raw !== null) api.setState(devFreeze(JSON.parse(raw)), true);
|
|
880
|
+
} catch (error) {
|
|
881
|
+
console.error(`snapshot store '${name}' rehydration failed:`, error);
|
|
882
|
+
}
|
|
883
|
+
api.subscribe((state) => {
|
|
884
|
+
try {
|
|
885
|
+
localStorage.setItem(name, JSON.stringify(state));
|
|
886
|
+
} catch (error) {
|
|
887
|
+
console.error(`snapshot store '${name}' persistence failed:`, error);
|
|
888
|
+
}
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
function devFreeze(value) {
|
|
892
|
+
return freeze(value, true);
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
// src/client/EdaMcpSettingsCard.tsx
|
|
896
|
+
var import_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
897
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
898
|
+
var EdaMcpSettingsCardController = class {
|
|
899
|
+
constructor(scope) {
|
|
900
|
+
this.scope = scope;
|
|
901
|
+
this.disposeScope = scope.subscribe(() => {
|
|
902
|
+
this.sync();
|
|
903
|
+
});
|
|
904
|
+
this.sync();
|
|
905
|
+
}
|
|
906
|
+
store = createSnapshotStore({ status: "loading", writable: false });
|
|
907
|
+
disposeScope;
|
|
908
|
+
sync() {
|
|
909
|
+
const snapshot = this.scope.getSnapshot();
|
|
910
|
+
this.store.set({
|
|
911
|
+
status: snapshot.status,
|
|
912
|
+
config: snapshot.value,
|
|
913
|
+
writable: snapshot.writable
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
inject() {
|
|
917
|
+
return {
|
|
918
|
+
hooks: { edaMcpSettingsCard: this.store },
|
|
919
|
+
save: async (draft) => {
|
|
920
|
+
await this.save(draft);
|
|
921
|
+
},
|
|
922
|
+
resetAll: async () => {
|
|
923
|
+
await this.resetAll();
|
|
924
|
+
},
|
|
925
|
+
testConnection: async () => {
|
|
926
|
+
await this.testConnection();
|
|
927
|
+
},
|
|
928
|
+
reconnect: async () => {
|
|
929
|
+
await this.reconnect();
|
|
930
|
+
}
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
dispose() {
|
|
934
|
+
this.disposeScope();
|
|
935
|
+
}
|
|
936
|
+
async save(draft) {
|
|
937
|
+
for (const [field, value] of Object.entries(draft)) {
|
|
938
|
+
if (value === void 0 || value === null || value === "") {
|
|
939
|
+
await this.scope.unset(field);
|
|
940
|
+
} else {
|
|
941
|
+
await this.scope.set(field, value);
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
async resetAll() {
|
|
946
|
+
const snapshot = this.scope.getSnapshot();
|
|
947
|
+
const user = snapshot.user;
|
|
948
|
+
if (user === void 0) return;
|
|
949
|
+
for (const field of Object.keys(user)) {
|
|
950
|
+
await this.scope.unset(field);
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
async testConnection() {
|
|
954
|
+
const response = await fetch("/api/dsh-eda-mcp/test", { method: "POST" });
|
|
955
|
+
let body;
|
|
956
|
+
try {
|
|
957
|
+
body = await response.json();
|
|
958
|
+
} catch {
|
|
959
|
+
body = void 0;
|
|
960
|
+
}
|
|
961
|
+
if (!response.ok || body?.ok !== true) {
|
|
962
|
+
throw new Error(body?.error ?? body?.message ?? `HTTP ${response.status}`);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
async reconnect() {
|
|
966
|
+
const response = await fetch("/api/dsh-eda-mcp/reconnect", { method: "POST" });
|
|
967
|
+
let body;
|
|
968
|
+
try {
|
|
969
|
+
body = await response.json();
|
|
970
|
+
} catch {
|
|
971
|
+
body = void 0;
|
|
972
|
+
}
|
|
973
|
+
if (!response.ok || body?.ok !== true) {
|
|
974
|
+
throw new Error(body?.error ?? body?.message ?? `HTTP ${response.status}`);
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
};
|
|
978
|
+
var cardStyle = {
|
|
979
|
+
border: "1px solid var(--dsw-alias-border-l2)",
|
|
980
|
+
background: "var(--dsw-alias-bg-layer-3)",
|
|
981
|
+
borderRadius: 12,
|
|
982
|
+
color: "var(--dsw-alias-label-primary)"
|
|
983
|
+
};
|
|
984
|
+
var headerStyle = {
|
|
985
|
+
display: "flex",
|
|
986
|
+
alignItems: "flex-start",
|
|
987
|
+
gap: 12,
|
|
988
|
+
padding: "14px 16px"
|
|
989
|
+
};
|
|
990
|
+
var titleStyle = {
|
|
991
|
+
margin: 0,
|
|
992
|
+
color: "var(--dsw-alias-label-primary)",
|
|
993
|
+
fontSize: 15,
|
|
994
|
+
fontWeight: 600,
|
|
995
|
+
lineHeight: 1.4
|
|
996
|
+
};
|
|
997
|
+
var descriptionStyle = {
|
|
998
|
+
margin: "4px 0 0",
|
|
999
|
+
color: "var(--dsw-alias-label-tertiary)",
|
|
1000
|
+
fontSize: 13,
|
|
1001
|
+
lineHeight: 1.5
|
|
1002
|
+
};
|
|
1003
|
+
var bodyStyle = {
|
|
1004
|
+
borderTop: "1px solid var(--dsw-alias-border-l2)",
|
|
1005
|
+
margin: "0 16px",
|
|
1006
|
+
padding: "8px 0 12px"
|
|
1007
|
+
};
|
|
1008
|
+
var footerStyle = {
|
|
1009
|
+
borderTop: "1px solid var(--dsw-alias-border-l2)",
|
|
1010
|
+
display: "flex",
|
|
1011
|
+
justifyContent: "flex-end",
|
|
1012
|
+
alignItems: "center",
|
|
1013
|
+
flexWrap: "wrap",
|
|
1014
|
+
gap: 8,
|
|
1015
|
+
margin: "0 16px",
|
|
1016
|
+
padding: "12px 0 16px"
|
|
1017
|
+
};
|
|
1018
|
+
var fieldStyle = {
|
|
1019
|
+
display: "flex",
|
|
1020
|
+
flexDirection: "column",
|
|
1021
|
+
gap: 6,
|
|
1022
|
+
padding: "12px 0"
|
|
1023
|
+
};
|
|
1024
|
+
var labelStyle = {
|
|
1025
|
+
color: "var(--dsw-alias-label-primary)",
|
|
1026
|
+
fontSize: 13,
|
|
1027
|
+
fontWeight: 500,
|
|
1028
|
+
lineHeight: 1.5
|
|
1029
|
+
};
|
|
1030
|
+
var hintStyle = {
|
|
1031
|
+
color: "var(--dsw-alias-label-tertiary)",
|
|
1032
|
+
fontSize: 12,
|
|
1033
|
+
lineHeight: 1.5
|
|
1034
|
+
};
|
|
1035
|
+
var inputStyle = {
|
|
1036
|
+
border: "1px solid var(--dsw-alias-border-l2)",
|
|
1037
|
+
background: "var(--dsw-alias-bg-layer-3)",
|
|
1038
|
+
color: "var(--dsw-alias-label-primary)",
|
|
1039
|
+
borderRadius: 8,
|
|
1040
|
+
padding: "0 12px",
|
|
1041
|
+
height: 34,
|
|
1042
|
+
fontSize: 13,
|
|
1043
|
+
lineHeight: 1.5,
|
|
1044
|
+
width: "100%",
|
|
1045
|
+
boxSizing: "border-box",
|
|
1046
|
+
font: "inherit"
|
|
1047
|
+
};
|
|
1048
|
+
var buttonBaseStyle = {
|
|
1049
|
+
appearance: "none",
|
|
1050
|
+
font: "inherit",
|
|
1051
|
+
cursor: "pointer",
|
|
1052
|
+
border: "1px solid transparent",
|
|
1053
|
+
borderRadius: 8,
|
|
1054
|
+
padding: "6px 16px",
|
|
1055
|
+
fontSize: 13,
|
|
1056
|
+
lineHeight: 1.5
|
|
1057
|
+
};
|
|
1058
|
+
var primaryButtonStyle = {
|
|
1059
|
+
...buttonBaseStyle,
|
|
1060
|
+
background: "var(--dsw-alias-label-primary)",
|
|
1061
|
+
color: "var(--dsw-alias-bg-layer-3)"
|
|
1062
|
+
};
|
|
1063
|
+
var secondaryButtonStyle = {
|
|
1064
|
+
...buttonBaseStyle,
|
|
1065
|
+
borderColor: "var(--dsw-alias-border-l2)",
|
|
1066
|
+
background: "transparent",
|
|
1067
|
+
color: "var(--dsw-alias-label-secondary)"
|
|
1068
|
+
};
|
|
1069
|
+
var disabledButtonStyle = {
|
|
1070
|
+
opacity: 0.4,
|
|
1071
|
+
cursor: "default"
|
|
1072
|
+
};
|
|
1073
|
+
function Field(props) {
|
|
1074
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: fieldStyle, children: [
|
|
1075
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: labelStyle, children: props.label }),
|
|
1076
|
+
props.children,
|
|
1077
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: hintStyle, children: props.hint })
|
|
1078
|
+
] });
|
|
1079
|
+
}
|
|
1080
|
+
function NumberField(props) {
|
|
1081
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, { label: props.label, hint: props.hint, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1082
|
+
"input",
|
|
1083
|
+
{
|
|
1084
|
+
type: "number",
|
|
1085
|
+
value: props.value ?? "",
|
|
1086
|
+
disabled: props.disabled,
|
|
1087
|
+
onChange: (event) => {
|
|
1088
|
+
const text = event.target.value.trim();
|
|
1089
|
+
if (text === "") {
|
|
1090
|
+
props.onChange(void 0);
|
|
1091
|
+
return;
|
|
1092
|
+
}
|
|
1093
|
+
const parsed = Number(text);
|
|
1094
|
+
props.onChange(Number.isFinite(parsed) ? parsed : void 0);
|
|
1095
|
+
},
|
|
1096
|
+
style: inputStyle
|
|
1097
|
+
}
|
|
1098
|
+
) });
|
|
1099
|
+
}
|
|
1100
|
+
function TextField(props) {
|
|
1101
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, { label: props.label, hint: props.hint, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1102
|
+
"input",
|
|
1103
|
+
{
|
|
1104
|
+
type: "text",
|
|
1105
|
+
value: props.value ?? "",
|
|
1106
|
+
placeholder: props.placeholder,
|
|
1107
|
+
disabled: props.disabled,
|
|
1108
|
+
onChange: (event) => {
|
|
1109
|
+
const text = event.target.value.trim();
|
|
1110
|
+
props.onChange(text === "" ? void 0 : text);
|
|
1111
|
+
},
|
|
1112
|
+
style: inputStyle
|
|
1113
|
+
}
|
|
1114
|
+
) });
|
|
1115
|
+
}
|
|
1116
|
+
function BooleanField(props) {
|
|
1117
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, { label: props.label, hint: props.hint, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1118
|
+
import_dsh_client_ui_primitives.Switch,
|
|
1119
|
+
{
|
|
1120
|
+
checked: props.value,
|
|
1121
|
+
disabled: props.disabled === true,
|
|
1122
|
+
label: props.label,
|
|
1123
|
+
onChange: (next) => {
|
|
1124
|
+
props.onChange(next);
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
) });
|
|
1128
|
+
}
|
|
1129
|
+
function EdaMcpSettingsCard(props) {
|
|
1130
|
+
const { t } = props;
|
|
1131
|
+
const state = props.useEdaMcpSettingsCard((snapshot) => snapshot);
|
|
1132
|
+
const [draft, setDraft] = (0, import_react.useState)({});
|
|
1133
|
+
const [seeded, setSeeded] = (0, import_react.useState)(false);
|
|
1134
|
+
const [saving, setSaving] = (0, import_react.useState)(false);
|
|
1135
|
+
const [testing, setTesting] = (0, import_react.useState)(false);
|
|
1136
|
+
const [reconnecting, setReconnecting] = (0, import_react.useState)(false);
|
|
1137
|
+
const [notice, setNotice] = (0, import_react.useState)();
|
|
1138
|
+
const [verifyingExtension, setVerifyingExtension] = (0, import_react.useState)(false);
|
|
1139
|
+
const [extensionVerdict, setExtensionVerdict] = (0, import_react.useState)();
|
|
1140
|
+
const [extensionInfo, setExtensionInfo] = (0, import_react.useState)();
|
|
1141
|
+
const verifyExtension = async () => {
|
|
1142
|
+
if (verifyingExtension) return;
|
|
1143
|
+
setVerifyingExtension(true);
|
|
1144
|
+
try {
|
|
1145
|
+
const response = await fetch("/api/dsh-eda-mcp/extension/verify");
|
|
1146
|
+
const body = await response.json();
|
|
1147
|
+
if (body.verified === "match") {
|
|
1148
|
+
const short = String(body.local?.sha256 ?? "").slice(0, 16) + "\u2026";
|
|
1149
|
+
setExtensionVerdict({ kind: "ok", text: t("settings.verifyMatch").replace("{hash}", short) });
|
|
1150
|
+
} else if (body.verified === "mismatch") {
|
|
1151
|
+
setExtensionVerdict({ kind: "error", text: t("settings.verifyMismatch").replace("{hash}", String(body.file ?? "")) });
|
|
1152
|
+
} else {
|
|
1153
|
+
const reason = String(body.error ?? "unknown");
|
|
1154
|
+
setExtensionVerdict({ kind: "error", text: t("settings.verifyUnverified").replace("{reason}", reason) });
|
|
1155
|
+
}
|
|
1156
|
+
} catch (error) {
|
|
1157
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
1158
|
+
setExtensionVerdict({ kind: "error", text: t("settings.verifyUnverified").replace("{reason}", reason) });
|
|
1159
|
+
} finally {
|
|
1160
|
+
setVerifyingExtension(false);
|
|
1161
|
+
}
|
|
1162
|
+
};
|
|
1163
|
+
(0, import_react.useEffect)(() => {
|
|
1164
|
+
if (!seeded && state.status === "ready") {
|
|
1165
|
+
setDraft(state.config ?? {});
|
|
1166
|
+
setSeeded(true);
|
|
1167
|
+
}
|
|
1168
|
+
}, [seeded, state.status, state.config]);
|
|
1169
|
+
if (state.status === "loading") return null;
|
|
1170
|
+
const disabled = !state.writable || saving || testing || reconnecting;
|
|
1171
|
+
const update = (field, value) => {
|
|
1172
|
+
setDraft((current2) => ({ ...current2, [field]: value }));
|
|
1173
|
+
};
|
|
1174
|
+
const clearNotice = () => {
|
|
1175
|
+
setNotice(void 0);
|
|
1176
|
+
};
|
|
1177
|
+
const onSave = async () => {
|
|
1178
|
+
setSaving(true);
|
|
1179
|
+
setNotice(void 0);
|
|
1180
|
+
try {
|
|
1181
|
+
await props.save(draft);
|
|
1182
|
+
setNotice({ kind: "ok", text: t("settings.saved") });
|
|
1183
|
+
} catch (error) {
|
|
1184
|
+
setNotice({ kind: "error", text: t("settings.saveFailed") + ": " + (error instanceof Error ? error.message : String(error)) });
|
|
1185
|
+
} finally {
|
|
1186
|
+
setSaving(false);
|
|
1187
|
+
}
|
|
1188
|
+
};
|
|
1189
|
+
const onReset = async () => {
|
|
1190
|
+
setSaving(true);
|
|
1191
|
+
setNotice(void 0);
|
|
1192
|
+
try {
|
|
1193
|
+
await props.resetAll();
|
|
1194
|
+
setDraft(state.config ?? {});
|
|
1195
|
+
setNotice({ kind: "ok", text: t("settings.saved") });
|
|
1196
|
+
} catch (error) {
|
|
1197
|
+
setNotice({ kind: "error", text: t("settings.saveFailed") + ": " + (error instanceof Error ? error.message : String(error)) });
|
|
1198
|
+
} finally {
|
|
1199
|
+
setSaving(false);
|
|
1200
|
+
}
|
|
1201
|
+
};
|
|
1202
|
+
const onTest = async () => {
|
|
1203
|
+
setTesting(true);
|
|
1204
|
+
setNotice(void 0);
|
|
1205
|
+
try {
|
|
1206
|
+
await props.save(draft);
|
|
1207
|
+
await props.testConnection();
|
|
1208
|
+
setNotice({ kind: "ok", text: t("settings.testOk") });
|
|
1209
|
+
} catch (error) {
|
|
1210
|
+
setNotice({ kind: "error", text: t("settings.testFailed") + ": " + (error instanceof Error ? error.message : String(error)) });
|
|
1211
|
+
} finally {
|
|
1212
|
+
setTesting(false);
|
|
1213
|
+
}
|
|
1214
|
+
};
|
|
1215
|
+
const onReconnect = async () => {
|
|
1216
|
+
setReconnecting(true);
|
|
1217
|
+
setNotice(void 0);
|
|
1218
|
+
try {
|
|
1219
|
+
await props.save(draft);
|
|
1220
|
+
await props.reconnect();
|
|
1221
|
+
setNotice({ kind: "ok", text: t("settings.reconnectOk") });
|
|
1222
|
+
} catch (error) {
|
|
1223
|
+
setNotice({ kind: "error", text: t("settings.reconnectFailed") + ": " + (error instanceof Error ? error.message : String(error)) });
|
|
1224
|
+
} finally {
|
|
1225
|
+
setReconnecting(false);
|
|
1226
|
+
}
|
|
1227
|
+
};
|
|
1228
|
+
const noticeStyle = {
|
|
1229
|
+
margin: "8px 0 0",
|
|
1230
|
+
fontSize: 12,
|
|
1231
|
+
lineHeight: 1.5,
|
|
1232
|
+
color: notice?.kind === "ok" ? "var(--dsw-alias-state-success-primary)" : "var(--dsw-alias-label-error)"
|
|
1233
|
+
};
|
|
1234
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: cardStyle, children: [
|
|
1235
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("header", { style: headerStyle, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
|
|
1236
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { style: titleStyle, children: t("settings.title") }),
|
|
1237
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { style: descriptionStyle, children: t("settings.description") })
|
|
1238
|
+
] }) }),
|
|
1239
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: bodyStyle, children: [
|
|
1240
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1241
|
+
BooleanField,
|
|
1242
|
+
{
|
|
1243
|
+
label: t("settings.enabled"),
|
|
1244
|
+
hint: t("settings.enabledHint"),
|
|
1245
|
+
value: draft.enabled ?? true,
|
|
1246
|
+
disabled,
|
|
1247
|
+
onChange: (value) => {
|
|
1248
|
+
clearNotice();
|
|
1249
|
+
update("enabled", value);
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
),
|
|
1253
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1254
|
+
BooleanField,
|
|
1255
|
+
{
|
|
1256
|
+
label: t("settings.announceToAgent"),
|
|
1257
|
+
hint: t("settings.announceToAgentHint"),
|
|
1258
|
+
value: draft.announceToAgent ?? true,
|
|
1259
|
+
disabled,
|
|
1260
|
+
onChange: (value) => {
|
|
1261
|
+
clearNotice();
|
|
1262
|
+
update("announceToAgent", value);
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
),
|
|
1266
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1267
|
+
NumberField,
|
|
1268
|
+
{
|
|
1269
|
+
label: t("settings.toolCallTimeoutMs"),
|
|
1270
|
+
hint: t("settings.toolCallTimeoutMsHint"),
|
|
1271
|
+
value: draft.toolCallTimeoutMs,
|
|
1272
|
+
disabled,
|
|
1273
|
+
onChange: (value) => {
|
|
1274
|
+
clearNotice();
|
|
1275
|
+
update("toolCallTimeoutMs", value);
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
),
|
|
1279
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1280
|
+
TextField,
|
|
1281
|
+
{
|
|
1282
|
+
label: t("settings.edaExecutable"),
|
|
1283
|
+
hint: t("settings.edaExecutableHint"),
|
|
1284
|
+
value: draft.edaExecutable,
|
|
1285
|
+
placeholder: "lceda-pro.exe",
|
|
1286
|
+
disabled,
|
|
1287
|
+
onChange: (value) => {
|
|
1288
|
+
clearNotice();
|
|
1289
|
+
update("edaExecutable", value);
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
),
|
|
1293
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1294
|
+
BooleanField,
|
|
1295
|
+
{
|
|
1296
|
+
label: t("settings.allowRawApi"),
|
|
1297
|
+
hint: t("settings.allowRawApiHint"),
|
|
1298
|
+
value: draft.allowRawApi ?? true,
|
|
1299
|
+
disabled,
|
|
1300
|
+
onChange: (value) => {
|
|
1301
|
+
clearNotice();
|
|
1302
|
+
update("allowRawApi", value);
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
),
|
|
1306
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1307
|
+
BooleanField,
|
|
1308
|
+
{
|
|
1309
|
+
label: t("settings.allowAutoLayoutRouting"),
|
|
1310
|
+
hint: t("settings.allowAutoLayoutRoutingHint"),
|
|
1311
|
+
value: draft.allowAutoLayoutRouting ?? false,
|
|
1312
|
+
disabled,
|
|
1313
|
+
onChange: (value) => {
|
|
1314
|
+
clearNotice();
|
|
1315
|
+
update("allowAutoLayoutRouting", value);
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
),
|
|
1319
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { style: { ...hintStyle, margin: "8px 0 0" }, children: t("settings.portLabel") }),
|
|
1320
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
1321
|
+
Field,
|
|
1322
|
+
{
|
|
1323
|
+
label: extensionInfo === void 0 ? t("settings.downloadExtension") : t("settings.downloadExtensionVersioned").replace("{version}", extensionInfo.version),
|
|
1324
|
+
hint: t("settings.installHint"),
|
|
1325
|
+
children: [
|
|
1326
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1327
|
+
"a",
|
|
1328
|
+
{
|
|
1329
|
+
href: "/api/dsh-eda-mcp/extension.zip",
|
|
1330
|
+
style: { ...secondaryButtonStyle, textDecoration: "none", display: "inline-flex", width: "fit-content" },
|
|
1331
|
+
children: extensionInfo === void 0 ? t("settings.downloadExtension") : t("settings.downloadExtensionVersioned").replace("{version}", extensionInfo.version)
|
|
1332
|
+
}
|
|
1333
|
+
),
|
|
1334
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1335
|
+
"button",
|
|
1336
|
+
{
|
|
1337
|
+
type: "button",
|
|
1338
|
+
onClick: () => {
|
|
1339
|
+
void verifyExtension();
|
|
1340
|
+
},
|
|
1341
|
+
disabled: verifyingExtension,
|
|
1342
|
+
style: verifyingExtension ? { ...secondaryButtonStyle, ...disabledButtonStyle, marginLeft: 8 } : { ...secondaryButtonStyle, marginLeft: 8 },
|
|
1343
|
+
children: verifyingExtension ? t("settings.verifyBusy") : t("settings.verifyExtension")
|
|
1344
|
+
}
|
|
1345
|
+
),
|
|
1346
|
+
extensionInfo !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { style: { ...hintStyle, margin: "6px 0 0" }, children: t("settings.extensionInfo").replace("{version}", extensionInfo.version).replace("{bytes}", String(extensionInfo.bytes)).replace("{hash}", extensionInfo.sha256.slice(0, 16) + "\u2026") }) : null,
|
|
1347
|
+
extensionVerdict !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { role: "status", style: { ...hintStyle, margin: "6px 0 0", color: extensionVerdict.kind === "ok" ? void 0 : "#c0392b" }, children: extensionVerdict.text }) : null
|
|
1348
|
+
]
|
|
1349
|
+
}
|
|
1350
|
+
)
|
|
1351
|
+
] }),
|
|
1352
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("footer", { style: footerStyle, children: [
|
|
1353
|
+
notice !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { style: noticeStyle, role: "status", children: notice.text }) : null,
|
|
1354
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1355
|
+
"button",
|
|
1356
|
+
{
|
|
1357
|
+
type: "button",
|
|
1358
|
+
disabled,
|
|
1359
|
+
style: disabled ? { ...primaryButtonStyle, ...disabledButtonStyle } : primaryButtonStyle,
|
|
1360
|
+
onClick: () => {
|
|
1361
|
+
void onSave();
|
|
1362
|
+
},
|
|
1363
|
+
children: t(saving ? "settings.saving" : "settings.save")
|
|
1364
|
+
}
|
|
1365
|
+
),
|
|
1366
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1367
|
+
"button",
|
|
1368
|
+
{
|
|
1369
|
+
type: "button",
|
|
1370
|
+
disabled,
|
|
1371
|
+
style: disabled ? { ...secondaryButtonStyle, ...disabledButtonStyle } : secondaryButtonStyle,
|
|
1372
|
+
onClick: () => {
|
|
1373
|
+
void onReset();
|
|
1374
|
+
},
|
|
1375
|
+
children: t("settings.resetAll")
|
|
1376
|
+
}
|
|
1377
|
+
),
|
|
1378
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1379
|
+
"button",
|
|
1380
|
+
{
|
|
1381
|
+
type: "button",
|
|
1382
|
+
disabled,
|
|
1383
|
+
style: disabled ? { ...secondaryButtonStyle, ...disabledButtonStyle } : secondaryButtonStyle,
|
|
1384
|
+
onClick: () => {
|
|
1385
|
+
void onTest();
|
|
1386
|
+
},
|
|
1387
|
+
children: t(testing ? "settings.testingConnection" : "settings.testConnection")
|
|
1388
|
+
}
|
|
1389
|
+
),
|
|
1390
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1391
|
+
"button",
|
|
1392
|
+
{
|
|
1393
|
+
type: "button",
|
|
1394
|
+
disabled,
|
|
1395
|
+
style: disabled ? { ...secondaryButtonStyle, ...disabledButtonStyle } : secondaryButtonStyle,
|
|
1396
|
+
onClick: () => {
|
|
1397
|
+
void onReconnect();
|
|
1398
|
+
},
|
|
1399
|
+
children: t(reconnecting ? "settings.reconnecting" : "settings.reconnect")
|
|
1400
|
+
}
|
|
1401
|
+
)
|
|
1402
|
+
] })
|
|
1403
|
+
] });
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
// src/client/settings-scope.ts
|
|
1407
|
+
var API = {
|
|
1408
|
+
describe: "/api/dsh-eda-mcp/settings/describe",
|
|
1409
|
+
mutate: "/api/dsh-eda-mcp/settings/mutate"
|
|
1410
|
+
};
|
|
1411
|
+
function createEdaMcpSettingsScope() {
|
|
1412
|
+
const store = createSnapshotStore({
|
|
1413
|
+
status: "loading",
|
|
1414
|
+
value: void 0,
|
|
1415
|
+
base: void 0,
|
|
1416
|
+
user: void 0,
|
|
1417
|
+
revision: void 0,
|
|
1418
|
+
writable: false,
|
|
1419
|
+
mode: "host"
|
|
1420
|
+
});
|
|
1421
|
+
let tail = Promise.resolve();
|
|
1422
|
+
let disposed = false;
|
|
1423
|
+
const post = async (path, body) => {
|
|
1424
|
+
const response = await fetch(path, {
|
|
1425
|
+
method: "POST",
|
|
1426
|
+
headers: { "content-type": "application/json" },
|
|
1427
|
+
body: JSON.stringify(body)
|
|
1428
|
+
});
|
|
1429
|
+
if (!response.ok) throw new Error("HTTP " + response.status);
|
|
1430
|
+
return await response.json();
|
|
1431
|
+
};
|
|
1432
|
+
const read = async () => {
|
|
1433
|
+
if (disposed) return;
|
|
1434
|
+
try {
|
|
1435
|
+
const body = await post(API.describe, {});
|
|
1436
|
+
if (body.ok !== true || body.value === void 0) throw new Error("settings bridge unavailable");
|
|
1437
|
+
const view = body.value.namespaces.find((candidate) => candidate.ns === "eda-mcp");
|
|
1438
|
+
if (view === void 0) throw new Error("eda-mcp settings namespace not exposed");
|
|
1439
|
+
accept(view, body.value.writable);
|
|
1440
|
+
} catch {
|
|
1441
|
+
if (!disposed) store.update((draft) => {
|
|
1442
|
+
draft.status = "unavailable";
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
};
|
|
1446
|
+
const accept = (view, writable) => {
|
|
1447
|
+
if (disposed) return;
|
|
1448
|
+
store.set({
|
|
1449
|
+
status: "ready",
|
|
1450
|
+
value: view.value,
|
|
1451
|
+
base: view.base,
|
|
1452
|
+
user: view.user,
|
|
1453
|
+
revision: view.revision,
|
|
1454
|
+
writable,
|
|
1455
|
+
mode: "host"
|
|
1456
|
+
});
|
|
1457
|
+
};
|
|
1458
|
+
const write = async (ops, expectedRevision) => {
|
|
1459
|
+
if (disposed) return;
|
|
1460
|
+
const revision = expectedRevision ?? store.getSnapshot().revision;
|
|
1461
|
+
try {
|
|
1462
|
+
const body = await post(API.mutate, {
|
|
1463
|
+
ns: "eda-mcp",
|
|
1464
|
+
ops,
|
|
1465
|
+
...revision === void 0 ? {} : { expectedRevision: revision }
|
|
1466
|
+
});
|
|
1467
|
+
if (body.ok !== true || body.value === void 0) {
|
|
1468
|
+
await read();
|
|
1469
|
+
throw new Error(body.message ?? body.code ?? "settings write failed");
|
|
1470
|
+
}
|
|
1471
|
+
accept(body.value, store.getSnapshot().writable);
|
|
1472
|
+
} catch {
|
|
1473
|
+
await read().catch(() => {
|
|
1474
|
+
});
|
|
1475
|
+
throw new Error("settings write failed");
|
|
1476
|
+
}
|
|
1477
|
+
};
|
|
1478
|
+
const enqueue = (operation) => {
|
|
1479
|
+
if (disposed) return Promise.resolve();
|
|
1480
|
+
const task = tail.then(operation, operation);
|
|
1481
|
+
tail = task.catch(() => {
|
|
1482
|
+
});
|
|
1483
|
+
return task;
|
|
1484
|
+
};
|
|
1485
|
+
void read();
|
|
1486
|
+
return {
|
|
1487
|
+
getSnapshot: () => store.getSnapshot(),
|
|
1488
|
+
subscribe: (listener) => store.subscribe(listener),
|
|
1489
|
+
mutate: (ops, expectedRevision) => enqueue(() => write(
|
|
1490
|
+
ops.map((op) => op.op === "set" ? { op: "set", path: [...op.path], value: op.value } : { op: "unset", path: [...op.path] }),
|
|
1491
|
+
expectedRevision
|
|
1492
|
+
)),
|
|
1493
|
+
set: (field, value) => enqueue(() => write([{ op: "set", path: [field], value }])),
|
|
1494
|
+
unset: (field) => enqueue(() => write([{ op: "unset", path: [field] }]))
|
|
1495
|
+
};
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
// src/client/locales.ts
|
|
1499
|
+
var zh = {
|
|
1500
|
+
"settings.title": "\u5609\u7ACB\u521BEDA MCP",
|
|
1501
|
+
"settings.description": "\u901A\u8FC7\u672C\u5730 MCP \u6865\u63A5\u5B50\u8FDB\u7A0B\u8FDE\u63A5\u5609\u7ACB\u521BEDA\u4E13\u4E1A\u7248\u6269\u5C55\uFF0C\u8BA9 DSH \u5728\u539F\u7406\u56FE\u91CC\u653E\u7F6E\u5668\u4EF6\u3001\u753B\u5BFC\u7EBF/\u77E9\u5F62/\u5706/\u6587\u672C\u3002",
|
|
1502
|
+
"settings.enabled": "\u542F\u7528\u63D2\u4EF6",
|
|
1503
|
+
"settings.enabledHint": "\u5173\u95ED\u540E\u4F1A\u5378\u8F7D MCP \u6865\u63A5\u5B50\u8FDB\u7A0B\uFF0C\u4E0D\u518D\u6CE8\u518C mcp__jlceda__* \u5DE5\u5177\u3002",
|
|
1504
|
+
"settings.announceToAgent": "\u5411 Agent \u516C\u544A\u672C\u63D2\u4EF6",
|
|
1505
|
+
"settings.announceToAgentHint": "\u5728\u7CFB\u7EDF\u63D0\u793A\u4E2D\u52A0\u5165 dsh-eda-mcp \u7684\u5750\u6807\u5355\u4F4D\u3001\u8FDE\u63A5\u6392\u969C\u7B49\u8BF4\u660E\u3002",
|
|
1506
|
+
"settings.toolCallTimeoutMs": "EDA \u8C03\u7528\u8D85\u65F6\uFF08\u6BEB\u79D2\uFF09",
|
|
1507
|
+
"settings.toolCallTimeoutMsHint": "\u5355\u6B21 EDA API \u8C03\u7528\u8D85\u65F6\uFF0C\u9ED8\u8BA4 60000\u3002",
|
|
1508
|
+
"settings.allowRawApi": "\u5141\u8BB8\u901A\u7528 eda_api_call",
|
|
1509
|
+
"settings.allowRawApiHint": "\u5F00\u542F\u540E MCP \u5DE5\u5177 eda_api_call \u53EF\u8C03\u7528\u767D\u540D\u5355\u5185\u7684 JLCEDA \u6269\u5C55 API\u3002",
|
|
1510
|
+
"settings.allowAutoLayoutRouting": "\u5141\u8BB8\u539F\u7406\u56FE\u81EA\u52A8\u5E03\u5C40 / \u81EA\u52A8\u5E03\u7EBF",
|
|
1511
|
+
"settings.allowAutoLayoutRoutingHint": "\u9ED8\u8BA4\u5173\u95ED\uFF1A\u5E03\u5C40\u6309\u6805\u683C\u624B\u5DE5\u6446\u653E\u3001\u5E03\u7EBF\u624B\u5DE5\u8D70\uFF0C\u7248\u9762\u68C0\u67E5\u7528\u5BFC\u51FA\u56FE\u7247\u81EA\u884C\u8BC6\u522B\u3002\u5F00\u542F\u540E eda_auto_layout / eda_auto_route \u624D\u53EF\u7528\u3002",
|
|
1512
|
+
"settings.edaExecutable": "\u5609\u7ACB\u521BEDA \u53EF\u6267\u884C\u6587\u4EF6\uFF08\u53EF\u9009\uFF09",
|
|
1513
|
+
"settings.edaExecutableHint": "\u7559\u7A7A\u5373\u81EA\u52A8\u63A2\u6D4B\uFF1A\u73AF\u5883\u53D8\u91CF \u2192 \u6CE8\u518C\u8868\u767B\u8BB0\u7684\u6587\u4EF6\u5173\u8054 \u2192 \u5E38\u89C1\u5B89\u88C5\u76EE\u5F55 \u2192 PATH\u3002\u53EA\u6709\u81EA\u52A8\u63A2\u6D4B\u5931\u8D25\u65F6\u624D\u9700\u8981\u586B\u5B8C\u6574\u8DEF\u5F84\u3002",
|
|
1514
|
+
"settings.save": "\u4FDD\u5B58",
|
|
1515
|
+
"settings.saving": "\u4FDD\u5B58\u4E2D\u2026",
|
|
1516
|
+
"settings.saved": "\u5DF2\u4FDD\u5B58",
|
|
1517
|
+
"settings.saveFailed": "\u4FDD\u5B58\u5931\u8D25",
|
|
1518
|
+
"settings.resetAll": "\u6062\u590D\u9ED8\u8BA4",
|
|
1519
|
+
"settings.testConnection": "\u6D4B\u8BD5\u8FDE\u63A5",
|
|
1520
|
+
"settings.testingConnection": "\u6D4B\u8BD5\u4E2D\u2026",
|
|
1521
|
+
"settings.testOk": "\u6865\u63A5\u670D\u52A1\u5728\u7EBF",
|
|
1522
|
+
"settings.testFailed": "\u6865\u63A5\u670D\u52A1\u4E0D\u53EF\u8FBE",
|
|
1523
|
+
"settings.reconnect": "\u91CD\u65B0\u8FDE\u63A5",
|
|
1524
|
+
"settings.reconnecting": "\u91CD\u8FDE\u4E2D\u2026",
|
|
1525
|
+
"settings.reconnectOk": "\u5DF2\u91CD\u65B0\u542F\u52A8\u6865\u63A5\u5B50\u8FDB\u7A0B",
|
|
1526
|
+
"settings.reconnectFailed": "\u91CD\u8FDE\u5931\u8D25",
|
|
1527
|
+
"settings.portLabel": "\u6865\u63A5 WebSocket \u7AEF\u53E3\uFF1A39009\uFF08\u56FA\u5B9A\uFF09",
|
|
1528
|
+
"settings.downloadExtension": "\u4E0B\u8F7D JLCEDA \u6269\u5C55\u5305",
|
|
1529
|
+
"settings.downloadExtensionVersioned": "\u4E0B\u8F7D JLCEDA \u6269\u5C55\u5305 v{version}",
|
|
1530
|
+
"settings.extensionInfo": "\u672C\u5730 v{version} \xB7 {bytes} \u5B57\u8282 \xB7 sha256 {hash}",
|
|
1531
|
+
"settings.extensionInfoUnknown": "\u6269\u5C55\u5305\u4FE1\u606F\u4E0D\u53EF\u7528",
|
|
1532
|
+
"settings.verifyExtension": "\u6821\u9A8C\u670D\u52A1\u5668\u526F\u672C",
|
|
1533
|
+
"settings.verifyBusy": "\u6821\u9A8C\u4E2D\u2026",
|
|
1534
|
+
"settings.verifyMatch": "\u4E00\u81F4\uFF1A\u670D\u52A1\u5668\u4E0A\u7684 zip \u4E0E\u672C\u5730\u8FD9\u4EFD\u9010\u5B57\u8282\u76F8\u540C\uFF08sha256 {hash}\uFF09",
|
|
1535
|
+
"settings.verifyMismatch": "\u4E0D\u4E00\u81F4\uFF1A\u670D\u52A1\u5668\u90A3\u4EFD\u4E0E\u672C\u5730\u4E0D\u540C\uFF0C\u8BF7\u91CD\u65B0\u4E0A\u4F20 {hash}",
|
|
1536
|
+
"settings.verifyUnverified": "\u65E0\u6CD5\u6821\u9A8C\uFF1A{reason}",
|
|
1537
|
+
"settings.installHint": "\u70B9\u4E0B\u8F7D\u4F1A\u4ECE\u4E0B\u8F7D\u670D\u52A1\u5668\u53D6\u56DE\u4E0E\u672C\u63D2\u4EF6\u7EBF\u534F\u8BAE\u4E00\u81F4\u7684 zip\uFF08\u53D1\u9001\u524D\u6821\u9A8C sha256\uFF0C\u4E0D\u4E00\u81F4\u5219\u62D2\u7EDD\u53D1\u9001\uFF09\uFF1B\u5728\u5609\u7ACB\u521BEDA\u4E13\u4E1A\u7248\u4E2D\uFF1A\u6269\u5C55 \u2192 \u5BFC\u5165 \u2192 \u9009\u62E9\u8BE5 zip \u2192 \u5728\u6269\u5C55\u5217\u8868\u5F00\u542F\u672C\u6269\u5C55\u7684\u300C\u5141\u8BB8\u5916\u90E8\u4EA4\u4E92\u300D\u3002"
|
|
1538
|
+
};
|
|
1539
|
+
var en = {
|
|
1540
|
+
"settings.title": "JLCEDA MCP",
|
|
1541
|
+
"settings.description": "Connect DSH to JLCEDA Pro through a local MCP bridge and draw schematics via the official extension API.",
|
|
1542
|
+
"settings.enabled": "Enable plugin",
|
|
1543
|
+
"settings.enabledHint": "When disabled, the bridge child is disposed and mcp__jlceda__* tools are unregistered.",
|
|
1544
|
+
"settings.announceToAgent": "Announce to Agent",
|
|
1545
|
+
"settings.announceToAgentHint": "Add dsh-eda-mcp coordinate and troubleshooting guidance to the system prompt.",
|
|
1546
|
+
"settings.toolCallTimeoutMs": "EDA call timeout (ms)",
|
|
1547
|
+
"settings.toolCallTimeoutMsHint": "Timeout for one EDA API call; default 60000.",
|
|
1548
|
+
"settings.allowRawApi": "Allow generic eda_api_call",
|
|
1549
|
+
"settings.allowRawApiHint": "Expose the eda_api_call tool restricted to the allow-listed JLCEDA APIs.",
|
|
1550
|
+
"settings.edaExecutable": "JLCEDA Pro executable (optional)",
|
|
1551
|
+
"settings.allowAutoLayoutRouting": "Allow automatic schematic layout / routing",
|
|
1552
|
+
"settings.allowAutoLayoutRoutingHint": "Off by default: place parts on the grid, route by hand, and check the sheet by exporting an image. Only with this on do eda_auto_layout / eda_auto_route run.",
|
|
1553
|
+
"settings.edaExecutableHint": "Leave empty to auto-detect: environment variable, the file-association command in the registry, conventional install directories, then PATH. Set a full path only when auto-detection fails.",
|
|
1554
|
+
"settings.save": "Save",
|
|
1555
|
+
"settings.saving": "Saving\u2026",
|
|
1556
|
+
"settings.saved": "Saved",
|
|
1557
|
+
"settings.saveFailed": "Save failed",
|
|
1558
|
+
"settings.resetAll": "Reset defaults",
|
|
1559
|
+
"settings.testConnection": "Test connection",
|
|
1560
|
+
"settings.testingConnection": "Testing\u2026",
|
|
1561
|
+
"settings.testOk": "Bridge service is online",
|
|
1562
|
+
"settings.testFailed": "Bridge service is unreachable",
|
|
1563
|
+
"settings.reconnect": "Reconnect",
|
|
1564
|
+
"settings.reconnecting": "Reconnecting\u2026",
|
|
1565
|
+
"settings.reconnectOk": "Bridge child restarted",
|
|
1566
|
+
"settings.reconnectFailed": "Reconnect failed",
|
|
1567
|
+
"settings.portLabel": "Bridge WebSocket port: 39009 (fixed)",
|
|
1568
|
+
"settings.downloadExtension": "Download JLCEDA extension zip",
|
|
1569
|
+
"settings.downloadExtensionVersioned": "Download JLCEDA extension zip v{version}",
|
|
1570
|
+
"settings.extensionInfo": "Bundled v{version} \xB7 {bytes} bytes \xB7 sha256 {hash}",
|
|
1571
|
+
"settings.extensionInfoUnknown": "Extension package info unavailable",
|
|
1572
|
+
"settings.verifyExtension": "Verify server copy",
|
|
1573
|
+
"settings.verifyBusy": "Verifying\u2026",
|
|
1574
|
+
"settings.verifyMatch": "Match: the served zip is byte-identical to the local one (sha256 {hash})",
|
|
1575
|
+
"settings.verifyMismatch": "Mismatch: the served zip differs \u2014 re-upload {hash}",
|
|
1576
|
+
"settings.verifyUnverified": "Could not verify: {reason}",
|
|
1577
|
+
"settings.installHint": 'Download fetches the zip whose wire version matches this plugin from the download server (sha256 is verified before the file is sent; a mismatch is refused). Then in JLCEDA Pro: Extensions \u2192 Import \u2192 select that zip \u2192 enable "Allow external interactions".'
|
|
1578
|
+
};
|
|
1579
|
+
|
|
1580
|
+
// src/client/index.ts
|
|
1581
|
+
var NS = "eda-mcp";
|
|
1582
|
+
var inject = ["slots", "locale"];
|
|
1583
|
+
function apply(ctx) {
|
|
1584
|
+
ctx.effect(() => ctx.locale.register(NS, { zh, en }), "eda-mcp: dictionaries");
|
|
1585
|
+
const settingsScope = createEdaMcpSettingsScope();
|
|
1586
|
+
const controller = new EdaMcpSettingsCardController(settingsScope);
|
|
1587
|
+
ctx.slots.inject("settings.section", () => {
|
|
1588
|
+
const unregister = ctx.slots.register({
|
|
1589
|
+
name: "settings.section",
|
|
1590
|
+
id: "eda-mcp",
|
|
1591
|
+
order: 40,
|
|
1592
|
+
label: () => ctx.locale.bind(NS)("settings.title"),
|
|
1593
|
+
locale: NS,
|
|
1594
|
+
inject: () => controller.inject()
|
|
1595
|
+
}, EdaMcpSettingsCard);
|
|
1596
|
+
return () => {
|
|
1597
|
+
controller.dispose();
|
|
1598
|
+
unregister();
|
|
1599
|
+
};
|
|
1600
|
+
});
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1603
|
+
return module.exports;
|
|
1604
|
+
}
|
|
1605
|
+
});
|