@huaqiu/dsh-hardware-ui 0.0.0-stage → 0.7.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 深圳华秋智联股份有限公司
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,32 @@
1
- # Temporary Holding Version
1
+ # @huaqiu/dsh-hardware-ui
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Hardware Engineering product UI for the Huaqiu DSH Desktop profile.
4
+
5
+ ## What it contributes
6
+
7
+ - Six persistent engineering destinations in `conversation.header.leading`:
8
+ Schematic, PCB, DFM, BOM, 3D CAD and Order Placing.
9
+ - One `keepMounted` right-panel tab (`hardware-engineering`) that shows the
10
+ selected artifact path, deterministic artifact selectors and explicit
11
+ loading/error states. The tab is driven by one declared store handle shared
12
+ with the other contributions.
13
+ - A contextual **Open in KiCad** / **Open in SolidCraft** action in
14
+ `conversation.session.header.corner`.
15
+ - A Hardware Engineering settings section with KiCad and SolidCraft
16
+ installation roots, persisted through DSH's host-backed config forms.
17
+
18
+ All host-side work (discovery, validated reads, installation probing, and
19
+ shell-free process creation) is delegated to `@huaqiu/hardware-artifacts`
20
+ through its same-origin `/api/v1/hardware/*` routes. The browser half never
21
+ touches Node APIs and never launches a process.
22
+
23
+ ## Extension points used
24
+
25
+ | Seat | Purpose |
26
+ |---|---|
27
+ | `conversation.header.leading` | one product navigation occupant |
28
+ | `conversation.session.header.corner` | contextual native-application action |
29
+ | `sidebar.right.pane.tab` | artifact viewer body (`keepMounted`) |
30
+ | `settings.section` | CAD installation settings |
31
+
32
+ No DSH core change and no new runtime is required.
@@ -0,0 +1,9 @@
1
+ # DSH bundle patch — @huaqiu/dsh-hardware-ui
2
+ #
3
+ # The browser half is loaded from the package's `./client` export by DSH's
4
+ # classic client module loader (see `dsh.client.platform` in package.json).
5
+ # The node half exists only to give the product bundle one installable identity;
6
+ # it deliberately provides no host service and injects nothing.
7
+ - insert:
8
+ - id: dsh-hardware-ui
9
+ name: '@huaqiu/dsh-hardware-ui'
package/lib/client.js ADDED
@@ -0,0 +1,599 @@
1
+ window.__ModuleLoader__.load({
2
+ id: "@huaqiu/dsh-hardware-ui",
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
+ //#region src/client/model.ts
9
+ const DESTINATIONS = Object.freeze([
10
+ "schematic",
11
+ "pcb",
12
+ "dfm",
13
+ "bom",
14
+ "3d",
15
+ "order"
16
+ ]);
17
+ const DESTINATION_LABELS = Object.freeze({
18
+ schematic: "Schematic",
19
+ pcb: "PCB",
20
+ dfm: "DFM",
21
+ bom: "BOM",
22
+ "3d": "3D CAD",
23
+ order: "Order Placing"
24
+ });
25
+ /** Which native application a destination can open, if any. */
26
+ function applicationFor(destination) {
27
+ if (destination === "schematic" || destination === "pcb" || destination === "dfm" || destination === "bom") return "kicad";
28
+ if (destination === "3d") return "solidcraft";
29
+ }
30
+ //#endregion
31
+ //#region src/client/components.tsx
32
+ /**
33
+ * Hardware Engineering UI components. All state reaches them through the
34
+ * standard slot props (`useStore`, `actions`) and one injected hook bundle;
35
+ * nothing here imports Node APIs or reaches into another plugin's singleton.
36
+ */
37
+ const NAV = {
38
+ display: "flex",
39
+ alignItems: "center",
40
+ gap: 4,
41
+ flexWrap: "wrap",
42
+ minWidth: 0,
43
+ fontSize: 12
44
+ };
45
+ const TAB = {
46
+ border: "1px solid var(--dsw-alias-border-default, rgba(127,127,127,0.3))",
47
+ borderRadius: 6,
48
+ background: "transparent",
49
+ color: "var(--dsw-alias-label-secondary)",
50
+ padding: "3px 8px",
51
+ cursor: "pointer",
52
+ font: "inherit",
53
+ whiteSpace: "nowrap"
54
+ };
55
+ const ACTIVE = {
56
+ ...TAB,
57
+ color: "var(--dsw-alias-label-primary)",
58
+ borderColor: "var(--dsw-alias-brand-primary, currentColor)",
59
+ background: "color-mix(in srgb, var(--dsw-alias-brand-primary, currentColor) 10%, transparent)"
60
+ };
61
+ const PATH = {
62
+ minWidth: 0,
63
+ maxWidth: 260,
64
+ overflow: "hidden",
65
+ textOverflow: "ellipsis",
66
+ whiteSpace: "nowrap",
67
+ color: "var(--dsw-alias-label-tertiary)",
68
+ fontSize: 11
69
+ };
70
+ const ROOT = {
71
+ display: "flex",
72
+ flexDirection: "column",
73
+ height: "100%",
74
+ minWidth: 0,
75
+ boxSizing: "border-box",
76
+ padding: 12,
77
+ gap: 10,
78
+ color: "var(--dsw-alias-label-primary)",
79
+ overflow: "auto"
80
+ };
81
+ const HEADER = {
82
+ display: "flex",
83
+ alignItems: "center",
84
+ justifyContent: "space-between",
85
+ gap: 8
86
+ };
87
+ const TITLE = {
88
+ margin: 0,
89
+ fontSize: 14,
90
+ fontWeight: 600
91
+ };
92
+ const BUTTON = {
93
+ ...TAB,
94
+ padding: "5px 10px",
95
+ color: "var(--dsw-alias-label-primary)"
96
+ };
97
+ const FIELD = {
98
+ display: "flex",
99
+ flexDirection: "column",
100
+ gap: 4,
101
+ fontSize: 12
102
+ };
103
+ const INPUT = {
104
+ width: "100%",
105
+ boxSizing: "border-box",
106
+ padding: "6px 8px",
107
+ borderRadius: 6,
108
+ border: "1px solid var(--dsw-alias-border-default, rgba(127,127,127,0.3))",
109
+ background: "transparent",
110
+ color: "inherit",
111
+ font: "inherit"
112
+ };
113
+ const MUTED = {
114
+ color: "var(--dsw-alias-label-tertiary)",
115
+ fontSize: 12,
116
+ margin: 0
117
+ };
118
+ const SELECT = {
119
+ ...INPUT,
120
+ cursor: "pointer"
121
+ };
122
+ function option(value, label, selected) {
123
+ return (0, react.createElement)("option", {
124
+ key: value,
125
+ value,
126
+ selected
127
+ }, label);
128
+ }
129
+ function artifactOptions(artifacts, kind) {
130
+ return (artifacts ?? []).filter((artifact) => artifact.kind === kind || kind === "any").map((artifact) => option(artifact.path, artifact.title || artifact.path, false));
131
+ }
132
+ /** Six persistent destinations in the conversation header's leading seat. */
133
+ function EngineeringNav({ useStore, actions, hooks, useSessions }) {
134
+ const active = useStore((state) => state.activeDestination);
135
+ const projectPath = useStore((state) => state.projectPath);
136
+ const cwd = useSessions?.((state) => {
137
+ const id = state.ids[0];
138
+ return id === void 0 ? void 0 : state.byId[id]?.cwd;
139
+ });
140
+ (0, react.useEffect)(() => {
141
+ hooks.refreshDiscovery(cwd);
142
+ }, [cwd, hooks]);
143
+ return (0, react.createElement)("div", {
144
+ style: NAV,
145
+ "data-hardware-nav": true
146
+ }, ...DESTINATIONS.map((destination) => (0, react.createElement)("button", {
147
+ key: destination,
148
+ type: "button",
149
+ style: destination === active ? ACTIVE : TAB,
150
+ "aria-pressed": destination === active,
151
+ onClick: () => {
152
+ actions.setActive(destination);
153
+ hooks.openDestination(destination);
154
+ }
155
+ }, DESTINATION_LABELS[destination])), ...projectPath === void 0 ? [] : [(0, react.createElement)("span", {
156
+ key: "path",
157
+ style: PATH,
158
+ title: projectPath
159
+ }, projectPath)]);
160
+ }
161
+ /** Right-panel body: one artifact at a time, with explicit selectors. */
162
+ function HardwareViewerBody({ useStore, actions, hooks, tab }) {
163
+ const active = useStore((state) => state.activeDestination);
164
+ const discovery = useStore((state) => state.discovery);
165
+ const projectPath = useStore((state) => state.projectPath);
166
+ const schematicPath = useStore((state) => state.schematicPath);
167
+ const pcbPath = useStore((state) => state.pcbPath);
168
+ const mechanicalPath = useStore((state) => state.mechanicalPath);
169
+ const notice = useStore((state) => state.notice);
170
+ const revision = tab?.navigation?.revision ?? 0;
171
+ const selectedProject = discovery?.selected ?? discovery?.projects?.[0];
172
+ const application = applicationFor(active);
173
+ const installed = useStore((state) => state.installations);
174
+ const configured = application === "kicad" ? installed?.kicad?.configured ?? false : installed?.solidcraft?.configured ?? false;
175
+ (0, react.useEffect)(() => {
176
+ hooks.refreshDiscovery();
177
+ }, [revision, hooks]);
178
+ (0, react.useEffect)(() => {
179
+ hooks.fetchInstallations();
180
+ }, [hooks]);
181
+ const artifactPath = active === "3d" ? mechanicalPath : active === "bom" ? schematicPath : active === "schematic" || active === "dfm" ? schematicPath : active === "pcb" ? pcbPath : void 0;
182
+ return (0, react.createElement)("div", {
183
+ style: ROOT,
184
+ "data-hardware-destination": active
185
+ }, (0, react.createElement)("div", { style: HEADER }, (0, react.createElement)("h2", { style: TITLE }, DESTINATION_LABELS[active]), (0, react.createElement)("button", {
186
+ type: "button",
187
+ style: BUTTON,
188
+ disabled: application === void 0 || !configured,
189
+ onClick: () => {
190
+ hooks.openNative(application, artifactPath).catch((error) => actions.setNotice(String(error)));
191
+ }
192
+ }, application === "kicad" ? "Open in KiCad" : application === "solidcraft" ? "Open in SolidCraft" : "No native action")), ...notice === void 0 ? [] : [(0, react.createElement)("p", {
193
+ key: "notice",
194
+ style: MUTED,
195
+ role: "status"
196
+ }, notice)], ...discovery?.issue === void 0 ? [] : [(0, react.createElement)("p", {
197
+ key: "issue",
198
+ style: MUTED,
199
+ role: "status"
200
+ }, discovery.issue.message)], (0, react.createElement)("p", { style: MUTED }, projectPath === void 0 ? "No canonical KiCad project selected." : `Project: ${projectPath}`), ...selectedProject === void 0 ? [(0, react.createElement)("div", { key: "empty" }, (0, react.createElement)("p", { style: MUTED }, "Open Project · New Project · Ask AI Hardware Engineer"))] : [
201
+ (0, react.createElement)("label", {
202
+ key: "project",
203
+ style: FIELD
204
+ }, "Project", (0, react.createElement)("select", {
205
+ style: SELECT,
206
+ value: projectPath ?? "",
207
+ onChange: (event) => {
208
+ hooks.refreshDiscovery(void 0, event.currentTarget.value);
209
+ }
210
+ }, option("", "Select a project…", projectPath === void 0), ...(discovery?.projects ?? []).map((project) => option(project.path, project.name, project.path === projectPath)))),
211
+ ...active === "schematic" || active === "bom" || active === "dfm" ? [(0, react.createElement)("label", {
212
+ key: "sheet",
213
+ style: FIELD
214
+ }, "Schematic / sheet", (0, react.createElement)("select", {
215
+ style: SELECT,
216
+ value: schematicPath ?? "",
217
+ onChange: (event) => {
218
+ actions.selectArtifact(event.currentTarget.value, "schematic");
219
+ hooks.openDestination(active, event.currentTarget.value);
220
+ }
221
+ }, option("", "Select a schematic…", schematicPath === void 0), ...selectedProject.schematic === void 0 ? [] : [option(selectedProject.schematic.path, selectedProject.schematic.title, false)], ...artifactOptions(selectedProject.sheets, "schematic")))] : [],
222
+ ...active === "pcb" || active === "dfm" ? [(0, react.createElement)("label", {
223
+ key: "board",
224
+ style: FIELD
225
+ }, "Board", (0, react.createElement)("select", {
226
+ style: SELECT,
227
+ value: pcbPath ?? "",
228
+ onChange: (event) => {
229
+ actions.selectArtifact(event.currentTarget.value, "pcb");
230
+ hooks.openDestination(active, event.currentTarget.value);
231
+ }
232
+ }, option("", "Select a board…", pcbPath === void 0), ...artifactOptions(selectedProject.boards, "pcb")))] : [],
233
+ ...active === "3d" ? [(0, react.createElement)("label", {
234
+ key: "model",
235
+ style: FIELD
236
+ }, "Mechanical model", (0, react.createElement)("select", {
237
+ style: SELECT,
238
+ value: mechanicalPath ?? "",
239
+ onChange: (event) => {
240
+ actions.selectArtifact(event.currentTarget.value, "mechanical-3d");
241
+ hooks.openDestination(active, event.currentTarget.value);
242
+ }
243
+ }, option("", "Select a model…", mechanicalPath === void 0), ...artifactOptions(selectedProject.mechanical, "mechanical-3d")))] : [],
244
+ ...active === "order" ? [(0, react.createElement)("p", {
245
+ key: "order",
246
+ style: MUTED
247
+ }, "PCB Fabrication and PCBA Assembly use the existing quote/order tools. Quote and order are separate steps.")] : [],
248
+ (0, react.createElement)("p", {
249
+ key: "artifact",
250
+ style: MUTED
251
+ }, artifactPath === void 0 ? "No artifact selected for this destination." : `Selected: ${artifactPath}`)
252
+ ], ...configured ? [] : [(0, react.createElement)("p", {
253
+ key: "unconfigured",
254
+ style: MUTED
255
+ }, `Configure ${application === "solidcraft" ? "SolidCraft" : "KiCad"} in Settings → Hardware Engineering to enable the native action.`)]);
256
+ }
257
+ /** Settings section for the two CAD installation roots. */
258
+ function HardwareSettingsSection({ hooks }) {
259
+ const form = hooks.useConfigForm?.();
260
+ const emptySnapshot = {};
261
+ const value = (0, react.useSyncExternalStore)(form?.subscribe.bind(form) ?? (() => () => {}), form?.getSnapshot.bind(form) ?? (() => emptySnapshot), form?.getSnapshot.bind(form) ?? (() => emptySnapshot)).value;
262
+ const [kicadRoot, setKicadRoot] = (0, react.useState)(value?.kicadRoot ?? "");
263
+ const [solidcraftRoot, setSolidcraftRoot] = (0, react.useState)(value?.solidcraftRoot ?? "");
264
+ const [message, setMessage] = (0, react.useState)("");
265
+ (0, react.useEffect)(() => {
266
+ setKicadRoot(value?.kicadRoot ?? "");
267
+ setSolidcraftRoot(value?.solidcraftRoot ?? "");
268
+ }, [value?.kicadRoot, value?.solidcraftRoot]);
269
+ const save = async (application, root) => {
270
+ try {
271
+ await hooks.saveInstallation(application, root);
272
+ await hooks.fetchInstallations();
273
+ setMessage(`${application === "kicad" ? "KiCad" : "SolidCraft"} installation saved and validated.`);
274
+ } catch (error) {
275
+ setMessage(String(error));
276
+ }
277
+ };
278
+ return (0, react.createElement)("div", {
279
+ style: {
280
+ ...ROOT,
281
+ height: "auto"
282
+ },
283
+ "data-hardware-settings": true
284
+ }, (0, react.createElement)("h2", { style: TITLE }, "Hardware Engineering"), (0, react.createElement)("label", { style: FIELD }, "KiCad installation root or kicad-cli path", (0, react.createElement)("input", {
285
+ style: INPUT,
286
+ value: kicadRoot,
287
+ onChange: (event) => setKicadRoot(event.currentTarget.value)
288
+ })), (0, react.createElement)("button", {
289
+ type: "button",
290
+ style: BUTTON,
291
+ onClick: () => {
292
+ save("kicad", kicadRoot);
293
+ }
294
+ }, "Validate / Save KiCad"), (0, react.createElement)("label", { style: FIELD }, "SolidCraft installation root or executable path", (0, react.createElement)("input", {
295
+ style: INPUT,
296
+ value: solidcraftRoot,
297
+ onChange: (event) => setSolidcraftRoot(event.currentTarget.value)
298
+ })), (0, react.createElement)("button", {
299
+ type: "button",
300
+ style: BUTTON,
301
+ onClick: () => {
302
+ save("solidcraft", solidcraftRoot);
303
+ }
304
+ }, "Validate / Save SolidCraft"), ...message === "" ? [] : [(0, react.createElement)("p", {
305
+ style: MUTED,
306
+ role: "status"
307
+ }, message)]);
308
+ }
309
+ /** Compact contextual action in the conversation header corner. */
310
+ function ContextualOpenAction({ useStore, hooks }) {
311
+ const active = useStore((state) => state.activeDestination);
312
+ const schematicPath = useStore((state) => state.schematicPath);
313
+ const pcbPath = useStore((state) => state.pcbPath);
314
+ const mechanicalPath = useStore((state) => state.mechanicalPath);
315
+ const application = applicationFor(active);
316
+ const installations = useStore((state) => state.installations);
317
+ const configured = application === "kicad" ? installed(installations?.kicad?.configured) : installed(installations?.solidcraft?.configured);
318
+ const label = (0, react.useMemo)(() => application === "kicad" ? "Open in KiCad" : application === "solidcraft" ? "Open in SolidCraft" : "", [application]);
319
+ if (label === "") return null;
320
+ const artifactPath = application === "solidcraft" ? mechanicalPath : active === "pcb" || active === "dfm" ? pcbPath : schematicPath;
321
+ return (0, react.createElement)("button", {
322
+ type: "button",
323
+ style: BUTTON,
324
+ disabled: !configured || artifactPath === void 0,
325
+ title: configured ? label : `${label} is unavailable until its installation is configured`,
326
+ onClick: () => {
327
+ hooks.openNative(application, artifactPath);
328
+ }
329
+ }, label);
330
+ }
331
+ function installed(value) {
332
+ return value ?? false;
333
+ }
334
+ //#endregion
335
+ //#region src/client/store.ts
336
+ function initial() {
337
+ return {
338
+ activeDestination: "schematic",
339
+ revision: 0
340
+ };
341
+ }
342
+ const mutators = {
343
+ setActive(draft, destination) {
344
+ draft.activeDestination = destination;
345
+ draft.revision += 1;
346
+ },
347
+ setWorkspaceRoot(draft, root) {
348
+ draft.workspaceRoot = root;
349
+ },
350
+ setDiscovery(draft, discovery) {
351
+ draft.discovery = discovery;
352
+ draft.workspaceRoot = discovery.cwd ?? draft.workspaceRoot;
353
+ draft.projectPath = discovery.selected?.path;
354
+ const selected = discovery.selected;
355
+ draft.schematicPath = selected?.sheetPath ?? selected?.schematic?.path;
356
+ draft.pcbPath = selected?.boards?.[0]?.path ?? selected?.pcb3d?.path;
357
+ draft.mechanicalPath = selected?.mechanical?.[0]?.path;
358
+ draft.revision += 1;
359
+ },
360
+ selectArtifact(draft, path, kind) {
361
+ if (kind === "schematic") draft.schematicPath = path;
362
+ else if (kind === "pcb") draft.pcbPath = path;
363
+ else draft.mechanicalPath = path;
364
+ draft.revision += 1;
365
+ },
366
+ setInstallations(draft, installations) {
367
+ draft.installations = installations;
368
+ draft.revision += 1;
369
+ },
370
+ setNotice(draft, notice) {
371
+ if (notice === void 0) delete draft.notice;
372
+ else draft.notice = notice;
373
+ },
374
+ refresh(draft) {
375
+ draft.revision += 1;
376
+ }
377
+ };
378
+ /** Create the shared handle. Call once inside `apply()`. */
379
+ function createHardwareStore() {
380
+ return {
381
+ spec: {
382
+ init: initial,
383
+ actions: mutators
384
+ },
385
+ create() {
386
+ let snapshot = initial();
387
+ const listeners = /* @__PURE__ */ new Set();
388
+ const commit = (mutate) => {
389
+ const draft = { ...snapshot };
390
+ mutate(draft);
391
+ snapshot = draft;
392
+ for (const listener of [...listeners]) listener();
393
+ };
394
+ return {
395
+ actions: {
396
+ setActive: (destination) => commit((draft) => mutators.setActive(draft, destination)),
397
+ setWorkspaceRoot: (root) => commit((draft) => {
398
+ draft.workspaceRoot = root;
399
+ }),
400
+ setDiscovery: (discovery) => commit((draft) => mutators.setDiscovery(draft, discovery)),
401
+ selectArtifact: (path, kind) => commit((draft) => mutators.selectArtifact(draft, path, kind)),
402
+ setInstallations: (installations) => commit((draft) => mutators.setInstallations(draft, installations)),
403
+ setNotice: (notice) => commit((draft) => mutators.setNotice(draft, notice)),
404
+ refresh: () => commit((draft) => mutators.refresh(draft))
405
+ },
406
+ getSnapshot: () => snapshot,
407
+ subscribe(listener) {
408
+ listeners.add(listener);
409
+ return () => {
410
+ listeners.delete(listener);
411
+ };
412
+ },
413
+ clearPersisted() {}
414
+ };
415
+ }
416
+ };
417
+ }
418
+ //#endregion
419
+ //#region src/client/transport.ts
420
+ const PREFIX = "/api/v1/hardware";
421
+ async function request(path, init) {
422
+ const response = await fetch(`${PREFIX}${path}`, init);
423
+ const body = await response.json().catch(() => void 0);
424
+ if (!response.ok || body?.ok === false) {
425
+ const detail = body?.error?.message ?? `HTTP ${response.status}`;
426
+ throw new Error(detail);
427
+ }
428
+ return body;
429
+ }
430
+ function query(cwd, project) {
431
+ const params = new URLSearchParams();
432
+ if (cwd !== void 0 && cwd !== "") params.set("cwd", cwd);
433
+ if (project !== void 0 && project !== "") params.set("project", project);
434
+ const text = params.toString();
435
+ return text === "" ? "" : `?${text}`;
436
+ }
437
+ async function loadProjects(cwd, project) {
438
+ const body = await request(`/projects${query(cwd, project)}`);
439
+ return {
440
+ cwd: body.cwd,
441
+ projects: Array.isArray(body.projects) ? body.projects : [],
442
+ ...body.selected === void 0 ? {} : { selected: body.selected },
443
+ ...body.issue === void 0 ? {} : { issue: body.issue }
444
+ };
445
+ }
446
+ async function loadInstallations() {
447
+ return request("/installations");
448
+ }
449
+ async function openArtifact(requestBody) {
450
+ await request("/open", {
451
+ method: "POST",
452
+ headers: { "content-type": "application/json" },
453
+ body: JSON.stringify(requestBody)
454
+ });
455
+ }
456
+ //#endregion
457
+ //#region src/client/index.ts
458
+ /**
459
+ * Browser half of `@huaqiu/dsh-hardware-ui`.
460
+ *
461
+ * Occupies existing DSH seats only: a root navigation occupant, a session
462
+ * header action, a `keepMounted` right-panel tab body, and a settings section.
463
+ * The shape below is structural on purpose: this package stays independently
464
+ * installable and does not import DSH internals.
465
+ */
466
+ /** Real Cordis service names this browser plugin waits for. */
467
+ const inject = [
468
+ "slots",
469
+ "sidebarRight",
470
+ "sidebarRightTabs",
471
+ "configForms"
472
+ ];
473
+ const HARDWARE_SETTINGS_ID = "hardware-engineering";
474
+ const HARDWARE_TAB_ID = "@huaqiu/dsh-hardware-ui";
475
+ const HARDWARE_TAB_KIND = "hardware-engineering";
476
+ function kindForPath(path) {
477
+ if (path.endsWith(".kicad_sch")) return "schematic";
478
+ if (path.endsWith(".kicad_pcb")) return "pcb";
479
+ if (path.endsWith(".kicad_pro")) return "project";
480
+ if (/\.(step|stp|glb)$/iu.test(path)) return "mechanical-3d";
481
+ return "bom";
482
+ }
483
+ /** Install all product UI contributions on a DSH client context. */
484
+ function apply(ctx) {
485
+ const store = createHardwareStore();
486
+ let actions;
487
+ let revision = 0;
488
+ const effect = (fn, label) => {
489
+ if (ctx.effect !== void 0) ctx.effect(fn, label);
490
+ else fn();
491
+ };
492
+ const captureActions = (...args) => {
493
+ for (const candidate of args) if (candidate !== null && typeof candidate === "object" && typeof candidate.setActive === "function") actions = candidate;
494
+ return { hooks: injected };
495
+ };
496
+ const injected = {
497
+ async refreshDiscovery(cwd, project) {
498
+ try {
499
+ const result = await loadProjects(cwd, project);
500
+ actions?.setDiscovery(result);
501
+ if (result.issue?.code === "bad-manifest") actions?.setNotice(result.issue.message);
502
+ } catch (error) {
503
+ actions?.setNotice(`Artifact discovery failed: ${String(error)}`);
504
+ }
505
+ },
506
+ openDestination(destination, path) {
507
+ revision += 1;
508
+ const kind = path === void 0 ? void 0 : kindForPath(path);
509
+ try {
510
+ ctx.sidebarRight?.openTab(HARDWARE_TAB_KIND, {
511
+ params: {
512
+ destination,
513
+ path,
514
+ kind,
515
+ revision
516
+ },
517
+ revealIfOpened: true
518
+ });
519
+ } catch (error) {
520
+ actions?.setNotice(`Open viewer failed: ${String(error)}`);
521
+ }
522
+ },
523
+ async openNative(application, artifactPath) {
524
+ if (artifactPath === void 0 || artifactPath === "") {
525
+ actions?.setNotice("Select an artifact before opening a native application.");
526
+ return;
527
+ }
528
+ try {
529
+ await openArtifact({
530
+ application: application ?? "kicad",
531
+ artifactPath,
532
+ kind: kindForPath(artifactPath)
533
+ });
534
+ } catch (error) {
535
+ actions?.setNotice(`Native launch failed: ${String(error)}`);
536
+ throw error;
537
+ }
538
+ },
539
+ async saveInstallation(application, root) {
540
+ const form = ctx.configForms?.get("hardware-artifacts");
541
+ if (form === void 0) throw new Error("host settings are unavailable");
542
+ const field = application === "kicad" ? "kicadRoot" : "solidcraftRoot";
543
+ if (!await form.set(field, root)) throw new Error(`the host rejected the ${field} setting`);
544
+ },
545
+ async fetchInstallations() {
546
+ try {
547
+ actions?.setInstallations(await loadInstallations());
548
+ } catch (error) {
549
+ actions?.setNotice(`Installation check failed: ${String(error)}`);
550
+ }
551
+ },
552
+ useConfigForm() {
553
+ return ctx.configForms?.get("hardware-artifacts");
554
+ }
555
+ };
556
+ effect(() => ctx.sidebarRightTabs?.register({
557
+ id: "@huaqiu/dsh-hardware-ui",
558
+ kind: "hardware-engineering",
559
+ keepMounted: true,
560
+ title: () => "Hardware Engineering"
561
+ }) ?? (() => {}), "hardware-ui: right-panel tab type");
562
+ const slots = ctx.slots;
563
+ if (slots === void 0) return;
564
+ effect(() => slots.inject("conversation.header.leading", () => slots.register({
565
+ name: "conversation.header.leading",
566
+ store,
567
+ inject: captureActions
568
+ }, EngineeringNav)), "hardware-ui: six-destination navigation");
569
+ effect(() => slots.inject("sidebar.right.pane.tab", () => slots.register({
570
+ name: "sidebar.right.pane.tab",
571
+ key: HARDWARE_TAB_ID,
572
+ store,
573
+ inject: captureActions
574
+ }, HardwareViewerBody)), "hardware-ui: viewer body");
575
+ effect(() => slots.inject("conversation.session.header.corner", () => slots.register({
576
+ name: "conversation.session.header.corner",
577
+ store,
578
+ inject: captureActions
579
+ }, ContextualOpenAction)), "hardware-ui: contextual native action");
580
+ effect(() => slots.inject("settings.section", () => slots.register({
581
+ name: "settings.section",
582
+ id: HARDWARE_SETTINGS_ID,
583
+ order: 85,
584
+ label: () => "Hardware Engineering",
585
+ store,
586
+ inject: captureActions
587
+ }, HardwareSettingsSection)), "hardware-ui: CAD installation settings");
588
+ }
589
+ //#endregion
590
+ exports.HARDWARE_SETTINGS_ID = HARDWARE_SETTINGS_ID;
591
+ exports.HARDWARE_TAB_ID = HARDWARE_TAB_ID;
592
+ exports.HARDWARE_TAB_KIND = HARDWARE_TAB_KIND;
593
+ exports.apply = apply;
594
+ exports.inject = inject;
595
+ return module.exports;
596
+ }
597
+ });
598
+
599
+ //# sourceMappingURL=client.js.map