@huaqiu/dsh-hardware-ui 0.7.13 → 0.7.15
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/lib/client.js +3096 -725
- package/lib/client.js.map +1 -1
- package/package.json +3 -3
- package/src/client/components.tsx +472 -192
- package/src/client/copy.ts +346 -0
- package/src/client/ecad.ts +35 -6
- package/src/client/index.ts +56 -75
- package/src/client/model.ts +51 -17
- package/src/client/order.tsx +453 -0
- package/src/client/preview.tsx +259 -115
- package/src/client/store.ts +41 -8
- package/src/client/theme.ts +158 -0
- package/src/client/transport.ts +175 -13
- package/src/client/wizard.tsx +322 -0
package/src/client/preview.tsx
CHANGED
|
@@ -1,45 +1,103 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* One preview surface per destination.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* One preview surface per destination.
|
|
3
|
+
*
|
|
4
|
+
* Every asynchronous mount is keyed by the navigation revision and owns an
|
|
5
|
+
* AbortController, so a superseded navigation disposes its predecessor instead
|
|
6
|
+
* of painting over it. A load that finishes after the viewer moved on is
|
|
7
|
+
* disposed, never attached.
|
|
5
8
|
*/
|
|
6
9
|
import { createElement, useEffect, useRef, useState, type CSSProperties, type ReactNode } from 'react'
|
|
7
10
|
import { isAbortError, mountEcad } from './ecad.js'
|
|
8
11
|
import { mountGlb } from './glb.js'
|
|
9
|
-
import { loadBom, prepareBoardGlb, type BomProjection } from './transport.js'
|
|
12
|
+
import { loadBom, messageOf, prepareBoardGlb, type BomProjection } from './transport.js'
|
|
13
|
+
import { OrderPanel } from './order.js'
|
|
14
|
+
import { COPY } from './copy.js'
|
|
15
|
+
import {
|
|
16
|
+
C, cardStyle, dotStyle, MONO, MONO_TEXT, pillStyle, R, SECTION_TITLE,
|
|
17
|
+
} from './theme.js'
|
|
10
18
|
import type { HardwareArtifactInfo, HardwareDestination } from './model.js'
|
|
11
19
|
|
|
12
20
|
const STAGE: CSSProperties = {
|
|
13
|
-
position: 'relative', flex: '1 1
|
|
14
|
-
border:
|
|
15
|
-
|
|
21
|
+
position: 'relative', flex: '1 1 0', minHeight: 200, overflow: 'hidden',
|
|
22
|
+
border: `1px solid ${C.border}`, borderRadius: R.lg, background: C.base,
|
|
23
|
+
}
|
|
24
|
+
const OVERLAY: CSSProperties = {
|
|
25
|
+
position: 'absolute', bottom: 8, left: 8, display: 'flex', alignItems: 'center', gap: 6,
|
|
26
|
+
padding: '2px 8px', borderRadius: R.pill, background: 'rgba(0,0,0,0.55)', color: '#e4e4e7',
|
|
27
|
+
fontSize: 10, fontFamily: MONO, backdropFilter: 'blur(6px)', pointerEvents: 'none',
|
|
28
|
+
maxWidth: 'calc(100% - 16px)', overflow: 'hidden',
|
|
29
|
+
}
|
|
30
|
+
const TOP_RIGHT: CSSProperties = {
|
|
31
|
+
position: 'absolute', top: 8, right: 8, display: 'flex', alignItems: 'center', gap: 4,
|
|
32
|
+
padding: '1px 3px', pointerEvents: 'none',
|
|
16
33
|
}
|
|
17
|
-
const
|
|
18
|
-
display: 'flex',
|
|
19
|
-
|
|
20
|
-
|
|
34
|
+
const CENTER: CSSProperties = {
|
|
35
|
+
display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center',
|
|
36
|
+
height: '100%', gap: 6, padding: 20, textAlign: 'center',
|
|
37
|
+
}
|
|
38
|
+
const CENTER_TEXT: CSSProperties = { margin: 0, fontSize: 11, color: C.text3, maxWidth: 340, lineHeight: 1.6 }
|
|
39
|
+
const TABLE: CSSProperties = { width: '100%', borderCollapse: 'collapse', fontSize: 11 }
|
|
40
|
+
const TH: CSSProperties = {
|
|
41
|
+
textAlign: 'left', padding: '5px 8px', position: 'sticky', top: 0, zIndex: 1,
|
|
42
|
+
background: C.raised, color: C.text2, fontWeight: 600, fontSize: 10,
|
|
43
|
+
borderBottom: `1px solid ${C.border}`, whiteSpace: 'nowrap',
|
|
44
|
+
}
|
|
45
|
+
const TD: CSSProperties = {
|
|
46
|
+
padding: '4px 8px', borderBottom: `1px solid ${C.borderSoft}`, verticalAlign: 'top', color: C.text,
|
|
21
47
|
}
|
|
22
|
-
const TABLE: CSSProperties = { width: '100%', borderCollapse: 'collapse', fontSize: 12 }
|
|
23
|
-
const TH: CSSProperties = { textAlign: 'left', padding: '4px 6px', borderBottom: '1px solid rgba(127,127,127,0.3)' }
|
|
24
|
-
const TD: CSSProperties = { padding: '4px 6px', borderBottom: '1px solid rgba(127,127,127,0.15)', verticalAlign: 'top' }
|
|
25
48
|
const SCRIPT: CSSProperties = {
|
|
26
|
-
margin: 0, padding: '8px
|
|
27
|
-
|
|
49
|
+
margin: 0, padding: '6px 8px', borderRadius: R.md, fontSize: 10, whiteSpace: 'pre-wrap',
|
|
50
|
+
wordBreak: 'break-all', background: C.base, fontFamily: MONO, color: C.text2,
|
|
28
51
|
}
|
|
29
52
|
|
|
30
53
|
type Status = 'loading' | 'ready' | 'error'
|
|
31
54
|
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
return String(error)
|
|
55
|
+
function shortRevision(revision: string | undefined): string {
|
|
56
|
+
return revision === undefined ? '' : revision.slice(0, 10)
|
|
35
57
|
}
|
|
36
58
|
|
|
37
|
-
function statusLine(status: Status, message?: string): ReactNode {
|
|
38
|
-
|
|
39
|
-
|
|
59
|
+
function statusLine(status: Status, message?: string, hint?: string): ReactNode {
|
|
60
|
+
const text = message ?? (status === 'loading' ? COPY.preview.loading : '')
|
|
61
|
+
return createElement(
|
|
62
|
+
'div',
|
|
63
|
+
{ style: CENTER, role: 'status', 'data-hardware-stage': status },
|
|
64
|
+
status === 'loading'
|
|
65
|
+
? createElement('span', {
|
|
66
|
+
style: {
|
|
67
|
+
width: 18, height: 18, borderRadius: R.pill, border: `2px solid ${C.borderSoft}`,
|
|
68
|
+
borderTopColor: C.info, animation: 'dsh-hw-spin 900ms linear infinite',
|
|
69
|
+
},
|
|
70
|
+
})
|
|
71
|
+
: createElement('span', { style: { ...pillStyle('warn'), fontFamily: MONO } }, COPY.preview.unavailable),
|
|
72
|
+
createElement('p', { style: CENTER_TEXT }, text),
|
|
73
|
+
hint === undefined ? null : createElement('p', { style: { ...CENTER_TEXT, fontSize: 10, color: C.text3 } }, hint),
|
|
74
|
+
)
|
|
40
75
|
}
|
|
41
76
|
|
|
42
|
-
function
|
|
77
|
+
function Stage(props: {
|
|
78
|
+
/** Passed as the third `createElement` argument; React folds it into props. */
|
|
79
|
+
readonly children?: ReactNode
|
|
80
|
+
readonly overlay?: ReactNode
|
|
81
|
+
readonly topRight?: ReactNode
|
|
82
|
+
readonly label: string
|
|
83
|
+
readonly attrs?: Record<string, unknown>
|
|
84
|
+
}): ReactNode {
|
|
85
|
+
return createElement(
|
|
86
|
+
'div',
|
|
87
|
+
{ style: { ...STAGE, display: 'flex', flexDirection: 'column' }, ...props.attrs },
|
|
88
|
+
props.topRight === undefined ? null : createElement('div', { style: TOP_RIGHT }, props.topRight),
|
|
89
|
+
props.children,
|
|
90
|
+
props.overlay === undefined ? null : createElement('div', { style: OVERLAY }, props.overlay),
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function EcadStage({ kind, path, revision, session, cwd }: {
|
|
95
|
+
kind: 'schematic' | 'pcb'
|
|
96
|
+
path: string
|
|
97
|
+
revision?: string
|
|
98
|
+
session?: string
|
|
99
|
+
cwd?: string
|
|
100
|
+
}): ReactNode {
|
|
43
101
|
const container = useRef<HTMLDivElement>(null)
|
|
44
102
|
const [status, setStatus] = useState<Status>('loading')
|
|
45
103
|
const [message, setMessage] = useState<string>()
|
|
@@ -57,6 +115,8 @@ function EcadStage({ kind, path, revision }: { kind: 'schematic' | 'pcb'; path:
|
|
|
57
115
|
mountEcad(kind, path, element, {
|
|
58
116
|
signal: controller.signal,
|
|
59
117
|
...(revision === undefined ? {} : { revision }),
|
|
118
|
+
...(session === undefined ? {} : { session }),
|
|
119
|
+
...(cwd === undefined ? {} : { cwd }),
|
|
60
120
|
})
|
|
61
121
|
.then((result) => {
|
|
62
122
|
if (!live) {
|
|
@@ -70,7 +130,7 @@ function EcadStage({ kind, path, revision }: { kind: 'schematic' | 'pcb'; path:
|
|
|
70
130
|
.catch((error: unknown) => {
|
|
71
131
|
if (!live || isAbortError(error)) return
|
|
72
132
|
setStatus('error')
|
|
73
|
-
setMessage(
|
|
133
|
+
setMessage(messageOf(error))
|
|
74
134
|
})
|
|
75
135
|
return () => {
|
|
76
136
|
live = false
|
|
@@ -78,51 +138,82 @@ function EcadStage({ kind, path, revision }: { kind: 'schematic' | 'pcb'; path:
|
|
|
78
138
|
mounted?.dispose()
|
|
79
139
|
element.replaceChildren()
|
|
80
140
|
}
|
|
81
|
-
}, [kind, path, revision])
|
|
141
|
+
}, [kind, path, revision, session, cwd])
|
|
82
142
|
|
|
83
143
|
return createElement(
|
|
84
|
-
|
|
85
|
-
{
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
144
|
+
Stage,
|
|
145
|
+
{
|
|
146
|
+
label: kind,
|
|
147
|
+
attrs: { 'data-hardware-ecad': kind },
|
|
148
|
+
topRight: status === 'ready'
|
|
149
|
+
? [
|
|
150
|
+
createElement('span', { key: 'kind', style: { ...pillStyle('muted'), fontSize: 9.5 } }, kind === 'schematic' ? COPY.preview.kindSchematic : COPY.preview.kindBoard),
|
|
151
|
+
sourceRevision === undefined
|
|
152
|
+
? null
|
|
153
|
+
: createElement('span', { key: 'rev', style: { ...pillStyle('muted'), fontSize: 9.5 } }, COPY.preview.revision(shortRevision(sourceRevision))),
|
|
154
|
+
]
|
|
155
|
+
: undefined,
|
|
156
|
+
overlay: status === 'ready'
|
|
157
|
+
? [createElement('span', { key: 'dot', style: dotStyle(kind === 'schematic' ? C.info : C.ok, 6) }),
|
|
158
|
+
COPY.preview.ecadOverlay]
|
|
159
|
+
: undefined,
|
|
160
|
+
},
|
|
161
|
+
createElement(
|
|
162
|
+
'div',
|
|
163
|
+
{ style: { position: 'relative', flex: '1 1 0', minHeight: 160 } },
|
|
164
|
+
...(status === 'ready'
|
|
165
|
+
? []
|
|
166
|
+
: [statusLine(status, message, status === 'error' ? COPY.preview.ecadHint : undefined)]),
|
|
167
|
+
createElement('div', { key: 'canvas', ref: container, style: { position: 'absolute', inset: 0 } }),
|
|
168
|
+
),
|
|
93
169
|
)
|
|
94
170
|
}
|
|
95
171
|
|
|
96
|
-
function GlbStage({ boardPath, cwd
|
|
172
|
+
function GlbStage({ boardPath, cwd, session, configured }: {
|
|
173
|
+
boardPath: string
|
|
174
|
+
/** Workspace root the host authorizes against; omitted when discovery did not report one. */
|
|
175
|
+
cwd?: string
|
|
176
|
+
session?: string
|
|
177
|
+
configured: boolean
|
|
178
|
+
}): ReactNode {
|
|
97
179
|
const container = useRef<HTMLDivElement>(null)
|
|
98
180
|
const [status, setStatus] = useState<Status>('loading')
|
|
99
181
|
const [message, setMessage] = useState<string>()
|
|
100
182
|
const [revision, setRevision] = useState<string>()
|
|
183
|
+
const [cached, setCached] = useState(false)
|
|
101
184
|
|
|
102
185
|
useEffect(() => {
|
|
103
186
|
const element = container.current
|
|
104
187
|
if (element === null) return
|
|
188
|
+
if (!configured) {
|
|
189
|
+
setStatus('error')
|
|
190
|
+
setMessage(COPY.preview.kicadNotConfigured)
|
|
191
|
+
return
|
|
192
|
+
}
|
|
105
193
|
const controller = new AbortController()
|
|
106
194
|
let live = true
|
|
107
195
|
let mounted: { dispose(): void } | undefined
|
|
108
196
|
setStatus('loading')
|
|
109
|
-
setMessage(
|
|
197
|
+
setMessage(COPY.preview.glbExporting)
|
|
110
198
|
element.replaceChildren()
|
|
111
199
|
const run = async (): Promise<void> => {
|
|
112
|
-
const glb = await prepareBoardGlb(boardPath, cwd, controller.signal)
|
|
200
|
+
const glb = await prepareBoardGlb(boardPath, cwd, controller.signal, session)
|
|
113
201
|
if (!live) return
|
|
114
202
|
setRevision(glb.revision)
|
|
203
|
+
setCached(glb.cached)
|
|
204
|
+
setMessage(COPY.preview.glbLoading)
|
|
115
205
|
mounted = await mountGlb(glb.url, element, { signal: controller.signal })
|
|
116
206
|
if (!live) {
|
|
117
207
|
mounted.dispose()
|
|
118
208
|
return
|
|
119
209
|
}
|
|
120
210
|
setStatus('ready')
|
|
211
|
+
setMessage(undefined)
|
|
121
212
|
}
|
|
122
213
|
run().catch((error: unknown) => {
|
|
123
214
|
if (!live || isAbortError(error)) return
|
|
124
215
|
setStatus('error')
|
|
125
|
-
setMessage(
|
|
216
|
+
setMessage(messageOf(error))
|
|
126
217
|
})
|
|
127
218
|
return () => {
|
|
128
219
|
live = false
|
|
@@ -130,31 +221,61 @@ function GlbStage({ boardPath, cwd }: { boardPath: string; cwd?: string }): Reac
|
|
|
130
221
|
mounted?.dispose()
|
|
131
222
|
element.replaceChildren()
|
|
132
223
|
}
|
|
133
|
-
}, [boardPath, cwd])
|
|
224
|
+
}, [boardPath, cwd, session, configured])
|
|
134
225
|
|
|
135
226
|
return createElement(
|
|
136
|
-
|
|
137
|
-
{
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
227
|
+
Stage,
|
|
228
|
+
{
|
|
229
|
+
label: '3d',
|
|
230
|
+
attrs: { 'data-hardware-glb': true },
|
|
231
|
+
topRight: status === 'ready'
|
|
232
|
+
? [
|
|
233
|
+
createElement('span', { key: 'mode', style: pillStyle('muted', { fontSize: 9.5 }) }, cached ? COPY.preview.glbCached : COPY.preview.glbGenerated),
|
|
234
|
+
createElement('span', { key: 'rev', style: pillStyle('muted', { fontSize: 9.5 }) }, COPY.preview.revision(shortRevision(revision))),
|
|
235
|
+
]
|
|
236
|
+
: undefined,
|
|
237
|
+
overlay: status === 'ready' ? COPY.preview.glbOverlay : 'kicad-cli pcb export glb',
|
|
238
|
+
},
|
|
239
|
+
createElement(
|
|
240
|
+
'div',
|
|
241
|
+
{ style: { position: 'relative', flex: '1 1 0', minHeight: 160 } },
|
|
242
|
+
...(status === 'ready' ? [] : [statusLine(status, message)]),
|
|
243
|
+
createElement('div', { key: 'canvas', ref: container, style: { position: 'absolute', inset: 0 } }),
|
|
244
|
+
),
|
|
145
245
|
)
|
|
146
246
|
}
|
|
147
247
|
|
|
148
|
-
|
|
248
|
+
/**
|
|
249
|
+
* BOM table.
|
|
250
|
+
*
|
|
251
|
+
* Rows come from `kicad-cli sch export bom`, so a missing installation is a
|
|
252
|
+
* configuration state, not a failure: the stage reports it without calling the
|
|
253
|
+
* host, the same way the 3D stage does.
|
|
254
|
+
*/
|
|
255
|
+
function BomStage({ schematicPath, session, cwd, configured }: {
|
|
256
|
+
schematicPath: string
|
|
257
|
+
session?: string
|
|
258
|
+
cwd?: string
|
|
259
|
+
configured: boolean
|
|
260
|
+
}): ReactNode {
|
|
149
261
|
const [status, setStatus] = useState<Status>('loading')
|
|
150
262
|
const [message, setMessage] = useState<string>()
|
|
151
263
|
const [bom, setBom] = useState<BomProjection>()
|
|
152
264
|
|
|
153
265
|
useEffect(() => {
|
|
266
|
+
if (!configured) {
|
|
267
|
+
setStatus('error')
|
|
268
|
+
setMessage(COPY.preview.kicadNotConfigured)
|
|
269
|
+
return
|
|
270
|
+
}
|
|
154
271
|
const controller = new AbortController()
|
|
155
272
|
let live = true
|
|
156
273
|
setStatus('loading')
|
|
157
|
-
loadBom(schematicPath,
|
|
274
|
+
loadBom(schematicPath, {
|
|
275
|
+
signal: controller.signal,
|
|
276
|
+
...(session === undefined ? {} : { session }),
|
|
277
|
+
...(cwd === undefined ? {} : { cwd }),
|
|
278
|
+
})
|
|
158
279
|
.then((projection) => {
|
|
159
280
|
if (!live) return
|
|
160
281
|
setBom(projection)
|
|
@@ -163,98 +284,121 @@ function BomStage({ schematicPath }: { schematicPath: string }): ReactNode {
|
|
|
163
284
|
.catch((error: unknown) => {
|
|
164
285
|
if (!live || isAbortError(error)) return
|
|
165
286
|
setStatus('error')
|
|
166
|
-
setMessage(
|
|
287
|
+
setMessage(messageOf(error))
|
|
167
288
|
})
|
|
168
289
|
return () => { live = false; controller.abort() }
|
|
169
|
-
}, [schematicPath])
|
|
290
|
+
}, [schematicPath, session, cwd, configured])
|
|
170
291
|
|
|
171
292
|
if (status !== 'ready' || bom === undefined) {
|
|
172
|
-
return createElement(
|
|
293
|
+
return createElement(
|
|
294
|
+
Stage,
|
|
295
|
+
{ label: 'bom', attrs: { 'data-hardware-bom': true }, overlay: 'kicad-cli sch export bom' },
|
|
296
|
+
createElement('div', { style: { flex: '1 1 0', display: 'flex' } }, statusLine(
|
|
297
|
+
status,
|
|
298
|
+
message,
|
|
299
|
+
status === 'error' && !configured
|
|
300
|
+
? COPY.preview.bomHint
|
|
301
|
+
: undefined,
|
|
302
|
+
)),
|
|
303
|
+
)
|
|
173
304
|
}
|
|
305
|
+
|
|
306
|
+
const total = bom.rows.reduce((sum, row) => sum + row.quantity, 0)
|
|
174
307
|
return createElement(
|
|
175
308
|
'div',
|
|
176
|
-
{
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
309
|
+
{
|
|
310
|
+
style: cardStyle({ padding: 0, overflow: 'hidden', flex: '1 1 0', minHeight: 0 }),
|
|
311
|
+
'data-hardware-bom': true,
|
|
312
|
+
},
|
|
313
|
+
createElement(
|
|
314
|
+
'div',
|
|
315
|
+
{ style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8, padding: '8px 10px', borderBottom: `1px solid ${C.border}` } },
|
|
316
|
+
createElement('span', { style: SECTION_TITLE }, COPY.preview.bomTitle(bom.rows.length)),
|
|
317
|
+
createElement('div', { style: { display: 'flex', gap: 4, alignItems: 'center' } },
|
|
318
|
+
createElement('span', { style: pillStyle('muted') }, COPY.preview.bomPlacements(total)),
|
|
319
|
+
createElement('span', { style: pillStyle('muted') }, COPY.preview.revision(shortRevision(bom.revision))),
|
|
320
|
+
),
|
|
321
|
+
),
|
|
322
|
+
createElement(
|
|
323
|
+
'div',
|
|
324
|
+
{ style: { flex: '1 1 0', minHeight: 0, overflow: 'auto' } },
|
|
325
|
+
createElement(
|
|
326
|
+
'table',
|
|
327
|
+
{ style: TABLE },
|
|
328
|
+
createElement('thead', {}, createElement('tr', {},
|
|
329
|
+
...COPY.preview.bomColumns.map(label =>
|
|
330
|
+
createElement('th', { key: label, style: TH }, label)))),
|
|
331
|
+
createElement('tbody', {},
|
|
332
|
+
...bom.rows.map((row, index) => createElement('tr', {
|
|
333
|
+
key: `${row.references.join(',')}:${String(index)}`,
|
|
334
|
+
style: index % 2 === 1 ? { background: 'color-mix(in srgb, currentColor 3%, transparent)' } : undefined,
|
|
335
|
+
},
|
|
336
|
+
createElement('td', { style: { ...TD, ...MONO_TEXT, whiteSpace: 'nowrap' } }, row.references.join(' ')),
|
|
337
|
+
createElement('td', { style: { ...TD, ...MONO_TEXT } }, String(row.quantity)),
|
|
186
338
|
createElement('td', { style: TD }, row.value),
|
|
187
|
-
createElement('td', { style: TD }, row.footprint),
|
|
188
|
-
createElement('td', { style: TD },
|
|
339
|
+
createElement('td', { style: { ...TD, color: C.text2, fontFamily: MONO, fontSize: 10 } }, row.footprint),
|
|
340
|
+
createElement('td', { style: { ...TD, color: C.text3, fontSize: 10 } },
|
|
189
341
|
[row.dnp ? 'DNP' : '', ...Object.entries(row.fields).map(([key, value]) => `${key}=${value}`)]
|
|
190
342
|
.filter(Boolean).join(' · ')),
|
|
191
|
-
|
|
343
|
+
))),
|
|
344
|
+
),
|
|
192
345
|
),
|
|
193
346
|
)
|
|
194
347
|
}
|
|
195
348
|
|
|
196
|
-
/**
|
|
197
|
-
* Order Placing entry points.
|
|
198
|
-
*
|
|
199
|
-
* The UI never constructs a quote/order URL or a second backend: it shows the
|
|
200
|
-
* exact existing agent tool call for the selected board so the purchase path
|
|
201
|
-
* still runs through the tool's own confirmation flow.
|
|
202
|
-
*/
|
|
203
|
-
function OrderStage({ boardPath, schematicPath }: { boardPath: string; schematicPath?: string }): ReactNode {
|
|
204
|
-
const [lines, setLines] = useState<number>()
|
|
205
|
-
useEffect(() => {
|
|
206
|
-
if (schematicPath === undefined) return
|
|
207
|
-
const controller = new AbortController()
|
|
208
|
-
let live = true
|
|
209
|
-
loadBom(schematicPath, controller.signal)
|
|
210
|
-
.then((bom) => { if (live) setLines(bom.rows.length) })
|
|
211
|
-
.catch(() => { if (live) setLines(undefined) })
|
|
212
|
-
return () => { live = false; controller.abort() }
|
|
213
|
-
}, [schematicPath])
|
|
214
|
-
|
|
215
|
-
const calls = [
|
|
216
|
-
{ tool: 'quote_pcb', args: { pcbPath: boardPath } },
|
|
217
|
-
{ tool: 'place_pcb_order', args: { pcbPath: boardPath } },
|
|
218
|
-
{ tool: 'quote_smt', args: { pcbPath: boardPath } },
|
|
219
|
-
{ tool: 'place_smt_order', args: { pcbPath: boardPath } },
|
|
220
|
-
]
|
|
221
|
-
return createElement(
|
|
222
|
-
'div',
|
|
223
|
-
{ style: { ...STAGE, overflow: 'auto', padding: 10, display: 'flex', flexDirection: 'column', gap: 8 }, 'data-hardware-order': true },
|
|
224
|
-
createElement('p', { style: { ...MESSAGE, height: 'auto', padding: 0, justifyContent: 'flex-start' } },
|
|
225
|
-
`Selected board: ${boardPath}`),
|
|
226
|
-
createElement('p', { style: { ...MESSAGE, height: 'auto', padding: 0, justifyContent: 'flex-start' } },
|
|
227
|
-
lines === undefined ? 'BOM context unavailable.' : `BOM context: ${String(lines)} grouped lines from the selected project.`),
|
|
228
|
-
createElement('p', { style: { ...MESSAGE, height: 'auto', padding: 0, justifyContent: 'flex-start' } },
|
|
229
|
-
'Ask the agent to run one of these existing tool calls. Quoting and ordering keep their own confirmation step; this panel never places an order.'),
|
|
230
|
-
...calls.map(call => createElement('div', { key: call.tool },
|
|
231
|
-
createElement('p', { style: { margin: '0 0 4px', fontSize: 12, fontWeight: 600 } }, call.tool),
|
|
232
|
-
createElement('pre', { style: SCRIPT }, JSON.stringify(call, null, 2)),
|
|
233
|
-
)),
|
|
234
|
-
)
|
|
235
|
-
}
|
|
236
|
-
|
|
237
349
|
export interface HardwarePreviewProps {
|
|
238
350
|
readonly destination: HardwareDestination
|
|
239
351
|
readonly artifact?: HardwareArtifactInfo
|
|
240
|
-
|
|
352
|
+
/** Selected schematic, used for the BOM/order context. */
|
|
353
|
+
readonly schematicPath?: string
|
|
354
|
+
/** Workspace root of the session on screen; every host read is authorized against it. */
|
|
355
|
+
readonly workspaceRoot?: string
|
|
356
|
+
/** DSH session the panel belongs to; sent with every host read. */
|
|
357
|
+
readonly session?: string
|
|
241
358
|
/** Monotonic navigation revision; a change disposes the previous mount. */
|
|
242
359
|
readonly revision: number
|
|
243
|
-
|
|
360
|
+
/** Whether a validated KiCad installation exists. */
|
|
361
|
+
readonly configured?: boolean
|
|
244
362
|
}
|
|
245
363
|
|
|
246
364
|
/** Destination → preview dispatcher. */
|
|
247
|
-
export function HardwarePreview({
|
|
365
|
+
export function HardwarePreview({
|
|
366
|
+
destination, artifact, schematicPath, workspaceRoot, session, revision, configured = false,
|
|
367
|
+
}: HardwarePreviewProps): ReactNode {
|
|
248
368
|
if (artifact === undefined) return null
|
|
249
369
|
const key = `${destination}:${artifact.path}:${String(revision)}`
|
|
250
370
|
if (destination === 'schematic' || destination === 'pcb') {
|
|
251
371
|
return createElement(EcadStage, {
|
|
252
|
-
key,
|
|
372
|
+
key,
|
|
373
|
+
kind: destination === 'schematic' ? 'schematic' : 'pcb',
|
|
374
|
+
path: artifact.path,
|
|
375
|
+
...(artifact.revision === undefined ? {} : { revision: artifact.revision }),
|
|
376
|
+
...(session === undefined ? {} : { session }),
|
|
377
|
+
...(workspaceRoot === undefined ? {} : { cwd: workspaceRoot }),
|
|
378
|
+
})
|
|
379
|
+
}
|
|
380
|
+
if (destination === '3d') {
|
|
381
|
+
return createElement(GlbStage, {
|
|
382
|
+
key, boardPath: artifact.path, ...(workspaceRoot === undefined ? {} : { cwd: workspaceRoot }),
|
|
383
|
+
...(session === undefined ? {} : { session }), configured,
|
|
384
|
+
})
|
|
385
|
+
}
|
|
386
|
+
if (destination === 'bom') {
|
|
387
|
+
return createElement(BomStage, {
|
|
388
|
+
key,
|
|
389
|
+
schematicPath: artifact.path,
|
|
390
|
+
...(session === undefined ? {} : { session }),
|
|
391
|
+
...(workspaceRoot === undefined ? {} : { cwd: workspaceRoot }),
|
|
392
|
+
configured,
|
|
253
393
|
})
|
|
254
394
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
395
|
+
return createElement(OrderPanel, {
|
|
396
|
+
key,
|
|
397
|
+
boardPath: artifact.path,
|
|
398
|
+
boardTitle: artifact.title || artifact.path,
|
|
399
|
+
...(schematicPath === undefined ? {} : { schematicPath }),
|
|
400
|
+
...(workspaceRoot === undefined ? {} : { workspaceRoot }),
|
|
401
|
+
...(session === undefined ? {} : { session }),
|
|
402
|
+
configured,
|
|
259
403
|
})
|
|
260
404
|
}
|
package/src/client/store.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
2
|
+
* Product state handle: a spec (init + complete write set) plus a per-scope
|
|
3
|
+
* instance factory, following DSH's declared-store contract.
|
|
4
|
+
*
|
|
5
|
+
* DSH pins one handle to one slot scope ("one handle, one scope"): the
|
|
6
|
+
* navigation and settings seats are `root`, the right-panel viewer seat is
|
|
7
|
+
* `session`. That is why `apply()` creates two handles — `root` state for the
|
|
8
|
+
* product chrome, `session` state for one viewer — instead of sharing one.
|
|
9
|
+
* Handles are created inside `apply()`, never at module scope, so a plugin
|
|
10
|
+
* reload cannot resurrect an old snapshot.
|
|
7
11
|
*/
|
|
8
12
|
import type {
|
|
9
13
|
HardwareActions, HardwareDestination, HardwareState, DiscoveryInfo, InstallationsInfo,
|
|
14
|
+
ViewerNavigationParams,
|
|
10
15
|
} from './model.js'
|
|
11
16
|
|
|
12
17
|
type Mutable<T> = { -readonly [K in keyof T]: T[K] }
|
|
@@ -54,10 +59,24 @@ const mutators = {
|
|
|
54
59
|
setWorkspaceRoot(draft: Mutable<HardwareState>, root: string): void {
|
|
55
60
|
draft.workspaceRoot = root
|
|
56
61
|
},
|
|
57
|
-
setDiscovery(draft: Mutable<HardwareState>, discovery: DiscoveryInfo): void {
|
|
62
|
+
setDiscovery(draft: Mutable<HardwareState>, discovery: DiscoveryInfo, preserveSelection?: boolean): void {
|
|
63
|
+
// A different workspace invalidates every artifact path held from the old
|
|
64
|
+
// one: the host authorizes against the session's workspace, so keeping a
|
|
65
|
+
// selection across that move turns the next read into "artifact is outside
|
|
66
|
+
// the authorized workspace". The session's workspace moving is also
|
|
67
|
+
// user-triggered, so it takes the same reset path as a new project.
|
|
68
|
+
const moved = discovery.cwd !== undefined
|
|
69
|
+
&& draft.workspaceRoot !== undefined
|
|
70
|
+
&& discovery.cwd !== draft.workspaceRoot
|
|
58
71
|
draft.discovery = discovery
|
|
59
72
|
draft.workspaceRoot = discovery.cwd ?? draft.workspaceRoot
|
|
60
|
-
|
|
73
|
+
// A viewer refresh must not clobber the artifact a navigation just selected:
|
|
74
|
+
// it only learns which project the workspace resolves to.
|
|
75
|
+
if (preserveSelection === true && !moved) {
|
|
76
|
+
if (discovery.selected !== undefined) draft.projectPath = discovery.selected.path
|
|
77
|
+
} else {
|
|
78
|
+
adoptProject(draft, discovery.selected)
|
|
79
|
+
}
|
|
61
80
|
draft.revision += 1
|
|
62
81
|
},
|
|
63
82
|
selectProject(draft: Mutable<HardwareState>, path: string): void {
|
|
@@ -74,6 +93,19 @@ const mutators = {
|
|
|
74
93
|
}
|
|
75
94
|
draft.revision += 1
|
|
76
95
|
},
|
|
96
|
+
applyNavigation(draft: Mutable<HardwareState>, params: ViewerNavigationParams): void {
|
|
97
|
+
draft.activeDestination = params.destination
|
|
98
|
+
if (params.projectPath !== undefined) draft.projectPath = params.projectPath
|
|
99
|
+
if (params.path !== undefined) {
|
|
100
|
+
if (params.destination === 'schematic' || params.destination === 'bom') {
|
|
101
|
+
draft.schematicPath = params.path
|
|
102
|
+
draft.sheetPath = params.path
|
|
103
|
+
} else if (params.destination === 'pcb' || params.destination === '3d' || params.destination === 'order') {
|
|
104
|
+
draft.pcbPath = params.path
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
draft.revision += 1
|
|
108
|
+
},
|
|
77
109
|
setInstallations(draft: Mutable<HardwareState>, installations: InstallationsInfo): void {
|
|
78
110
|
draft.installations = installations
|
|
79
111
|
draft.revision += 1
|
|
@@ -104,9 +136,10 @@ export function createHardwareStore(): HardwareStoreHandle {
|
|
|
104
136
|
actions: {
|
|
105
137
|
setActive: destination => commit(draft => mutators.setActive(draft, destination)),
|
|
106
138
|
setWorkspaceRoot: root => commit(draft => { draft.workspaceRoot = root }),
|
|
107
|
-
setDiscovery: discovery => commit(draft => mutators.setDiscovery(draft, discovery)),
|
|
139
|
+
setDiscovery: (discovery, preserveSelection) => commit(draft => mutators.setDiscovery(draft, discovery, preserveSelection)),
|
|
108
140
|
selectProject: path => commit(draft => mutators.selectProject(draft, path)),
|
|
109
141
|
selectArtifact: (path, kind) => commit(draft => mutators.selectArtifact(draft, path, kind)),
|
|
142
|
+
applyNavigation: params => commit(draft => mutators.applyNavigation(draft, params)),
|
|
110
143
|
setInstallations: installations => commit(draft => mutators.setInstallations(draft, installations)),
|
|
111
144
|
setNotice: notice => commit(draft => mutators.setNotice(draft, notice)),
|
|
112
145
|
refresh: () => commit(draft => mutators.refresh(draft)),
|