@huaqiu/dsh-hardware-ui 0.0.0-stage → 0.7.13

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.
@@ -0,0 +1,188 @@
1
+ /**
2
+ * Browser half of `@huaqiu/dsh-hardware-ui`.
3
+ *
4
+ * Occupies existing DSH seats only: one root navigation occupant, one
5
+ * `keepMounted` right-panel tab body, and one settings section. Native open
6
+ * lives inside the viewer with the resolved artifact in scope, so no
7
+ * conversation-level action is registered.
8
+ */
9
+ import { EngineeringNav, HardwareSettingsSection, HardwareViewerBody } from './components.js'
10
+ import type {
11
+ ConfigFormLike, HardwareActions, HardwareDestination, HardwareInjected,
12
+ HardwareInstallationConfig, NativeApplication,
13
+ } from './model.js'
14
+ import { createHardwareStore } from './store.js'
15
+ import { loadInstallations, loadProjects, openArtifact } from './transport.js'
16
+
17
+ /** Real Cordis service names this browser plugin waits for. */
18
+ export const inject = ['slots', 'sidebarRight', 'sidebarRightTabs', 'configForms'] as const
19
+
20
+ export const HARDWARE_SETTINGS_ID = 'hardware-engineering'
21
+ export const HARDWARE_TAB_ID = '@huaqiu/dsh-hardware-ui'
22
+ export const HARDWARE_TAB_KIND = 'hardware-engineering'
23
+
24
+ interface SlotSpec {
25
+ name: string
26
+ id?: string
27
+ key?: string
28
+ order?: number
29
+ label?: () => string
30
+ store?: unknown
31
+ inject?: (...args: unknown[]) => unknown
32
+ }
33
+
34
+ interface ClientContext {
35
+ readonly slots?: {
36
+ inject(key: string, callback: () => () => void): () => void
37
+ register(spec: SlotSpec, component: unknown): () => void
38
+ }
39
+ readonly sidebarRight?: {
40
+ openTab(kind: string, options?: {
41
+ params?: Readonly<Record<string, unknown>>
42
+ revealIfOpened?: boolean
43
+ }): void
44
+ }
45
+ readonly sidebarRightTabs?: {
46
+ register(definition: {
47
+ id: string
48
+ kind: string
49
+ keepMounted?: boolean
50
+ title: (address: string) => string
51
+ }): () => void
52
+ }
53
+ readonly configForms?: {
54
+ get<T>(entryId: string): ConfigFormLike<T>
55
+ }
56
+ effect?(fn: () => (() => void) | void, label?: string): void
57
+ }
58
+
59
+ /** Artifact kind discriminator carried in navigation params. */
60
+ export function kindForPath(path: string): string {
61
+ if (path.toLowerCase().endsWith('.kicad_sch')) return 'schematic'
62
+ if (path.toLowerCase().endsWith('.kicad_pcb')) return 'pcb'
63
+ if (path.toLowerCase().endsWith('.kicad_pro')) return 'project'
64
+ return 'bom'
65
+ }
66
+
67
+ /** Destination-specific artifact kind used by the host `open` route. */
68
+ function nativeKindFor(destination: HardwareDestination, path: string): string {
69
+ if (destination === '3d') return 'pcb-3d'
70
+ if (destination === 'bom') return 'bom'
71
+ return kindForPath(path)
72
+ }
73
+
74
+ /** Install all product UI contributions on a DSH client context. */
75
+ export function apply(ctx: ClientContext): void {
76
+ const store = createHardwareStore()
77
+ let actions: HardwareActions | undefined
78
+ let revision = 0
79
+ const effect = (fn: () => (() => void) | void, label: string): void => {
80
+ if (ctx.effect !== undefined) ctx.effect(fn, label)
81
+ else fn()
82
+ }
83
+
84
+ const captureActions = (...args: unknown[]): { hooks: HardwareInjected } => {
85
+ for (const candidate of args) {
86
+ if (candidate !== null && typeof candidate === 'object'
87
+ && typeof (candidate as HardwareActions).setActive === 'function') {
88
+ actions = candidate as HardwareActions
89
+ }
90
+ }
91
+ return { hooks: injected }
92
+ }
93
+
94
+ const injected: HardwareInjected = {
95
+ async refreshDiscovery(cwd, project) {
96
+ try {
97
+ const result = await loadProjects(cwd, project)
98
+ actions?.setDiscovery(result)
99
+ if (result.issue?.code === 'bad-manifest') actions?.setNotice(result.issue.message)
100
+ } catch (error) {
101
+ actions?.setNotice(`Artifact discovery failed: ${String(error)}`)
102
+ }
103
+ },
104
+ openDestination(destination: HardwareDestination, path) {
105
+ revision += 1
106
+ const kind = path === undefined ? undefined : kindForPath(path)
107
+ try {
108
+ ctx.sidebarRight?.openTab(HARDWARE_TAB_KIND, {
109
+ params: {
110
+ destination,
111
+ ...(path === undefined ? {} : { path }),
112
+ ...(kind === undefined ? {} : { kind }),
113
+ navigationRevision: revision,
114
+ },
115
+ revealIfOpened: true,
116
+ })
117
+ } catch (error) {
118
+ actions?.setNotice(`Open viewer failed: ${String(error)}`)
119
+ }
120
+ },
121
+ async openNative(application?: NativeApplication, artifactPath?: string) {
122
+ if (artifactPath === undefined || artifactPath === '') {
123
+ actions?.setNotice('Select an artifact before opening it in KiCad.')
124
+ return
125
+ }
126
+ const destination = store.create().getSnapshot().activeDestination
127
+ try {
128
+ await openArtifact({
129
+ application: application ?? 'kicad',
130
+ artifactPath,
131
+ kind: nativeKindFor(destination, artifactPath),
132
+ })
133
+ } catch (error) {
134
+ actions?.setNotice(`Native launch failed: ${String(error)}`)
135
+ throw error
136
+ }
137
+ },
138
+ async saveInstallation(application, root) {
139
+ const form = ctx.configForms?.get<HardwareInstallationConfig>('hardware-artifacts')
140
+ if (form === undefined) throw new Error('host settings are unavailable')
141
+ const field = application === 'kicad' ? 'kicadRoot' : 'solidcraftRoot'
142
+ const accepted = await form.set(field, root)
143
+ if (!accepted) throw new Error(`the host rejected the ${field} setting`)
144
+ },
145
+ async fetchInstallations() {
146
+ try {
147
+ actions?.setInstallations(await loadInstallations())
148
+ } catch (error) {
149
+ actions?.setNotice(`Installation check failed: ${String(error)}`)
150
+ }
151
+ },
152
+ useConfigForm() {
153
+ return ctx.configForms?.get<HardwareInstallationConfig>('hardware-artifacts')
154
+ },
155
+ }
156
+
157
+ effect(() => ctx.sidebarRightTabs?.register({
158
+ id: HARDWARE_TAB_ID,
159
+ kind: HARDWARE_TAB_KIND,
160
+ keepMounted: true,
161
+ title: () => 'Hardware Engineering',
162
+ }) ?? (() => {}), 'hardware-ui: right-panel tab type')
163
+
164
+ const slots = ctx.slots
165
+ if (slots === undefined) return
166
+
167
+ effect(() => slots.inject('conversation.header.leading', () => slots.register({
168
+ name: 'conversation.header.leading',
169
+ store,
170
+ inject: captureActions,
171
+ }, EngineeringNav)), 'hardware-ui: five-destination navigation')
172
+
173
+ effect(() => slots.inject('sidebar.right.pane.tab', () => slots.register({
174
+ name: 'sidebar.right.pane.tab',
175
+ key: HARDWARE_TAB_ID,
176
+ store,
177
+ inject: captureActions,
178
+ }, HardwareViewerBody)), 'hardware-ui: viewer body')
179
+
180
+ effect(() => slots.inject('settings.section', () => slots.register({
181
+ name: 'settings.section',
182
+ id: HARDWARE_SETTINGS_ID,
183
+ order: 85,
184
+ label: () => 'Hardware Engineering',
185
+ store,
186
+ inject: captureActions,
187
+ }, HardwareSettingsSection)), 'hardware-ui: CAD installation settings')
188
+ }
@@ -0,0 +1,141 @@
1
+ /** Product-owned navigation and artifact identity. No shadow project database. */
2
+
3
+ /** The five persistent product destinations. DFM and mechanical are out of scope. */
4
+ export type HardwareDestination = 'schematic' | 'pcb' | 'bom' | '3d' | 'order'
5
+
6
+ /**
7
+ * Native applications a destination can hand off to.
8
+ *
9
+ * `3d` maps to KiCad because its source artifact is the selected `.kicad_pcb`;
10
+ * SolidCraft is agent environment context only in this POC and never receives
11
+ * a native-open action.
12
+ */
13
+ export type NativeApplication = 'kicad'
14
+
15
+ export const DESTINATIONS: readonly HardwareDestination[] = Object.freeze([
16
+ 'schematic', 'pcb', 'bom', '3d', 'order',
17
+ ])
18
+
19
+ export const DESTINATION_LABELS: Readonly<Record<HardwareDestination, string>> = Object.freeze({
20
+ schematic: 'Schematic',
21
+ pcb: 'PCB',
22
+ bom: 'BOM',
23
+ '3d': '3D CAD',
24
+ order: 'Order Placing',
25
+ })
26
+
27
+ /** Which native application a destination can open, if any. */
28
+ export function applicationFor(destination: HardwareDestination): NativeApplication | undefined {
29
+ if (destination === 'schematic' || destination === 'pcb' || destination === 'bom' || destination === '3d') return 'kicad'
30
+ return undefined
31
+ }
32
+
33
+ export interface HardwareArtifactInfo {
34
+ readonly id: string
35
+ readonly kind: string
36
+ readonly path: string
37
+ readonly title: string
38
+ readonly sourcePath?: string
39
+ readonly revision?: string
40
+ }
41
+
42
+ export interface HardwareProjectInfo {
43
+ readonly path: string
44
+ readonly name: string
45
+ readonly sheetPath?: string
46
+ readonly schematic?: HardwareArtifactInfo
47
+ readonly bom?: HardwareArtifactInfo
48
+ readonly pcb3d?: HardwareArtifactInfo
49
+ readonly rootSheet?: HardwareArtifactInfo
50
+ readonly sheets?: readonly HardwareArtifactInfo[]
51
+ readonly boards?: readonly HardwareArtifactInfo[]
52
+ readonly defaultBoard?: string
53
+ readonly selectionRequired?: boolean
54
+ }
55
+
56
+ export interface InstallationsInfo {
57
+ readonly kicad?: {
58
+ readonly configured: boolean
59
+ readonly version?: string
60
+ readonly cli?: string
61
+ readonly pcbEditor?: string
62
+ readonly schematicEditor?: string
63
+ readonly error?: string
64
+ }
65
+ readonly solidcraft?: {
66
+ readonly configured: boolean
67
+ readonly executable?: string
68
+ readonly error?: string
69
+ }
70
+ }
71
+
72
+ export interface DiscoveryInfo {
73
+ readonly cwd?: string
74
+ readonly projects?: readonly HardwareProjectInfo[]
75
+ readonly selected?: HardwareProjectInfo
76
+ readonly issue?: { readonly code: string; readonly message: string }
77
+ }
78
+
79
+ export interface HardwareState {
80
+ readonly activeDestination: HardwareDestination
81
+ readonly workspaceRoot?: string
82
+ readonly projectPath?: string
83
+ readonly schematicPath?: string
84
+ readonly sheetPath?: string
85
+ readonly pcbPath?: string
86
+ readonly bomPath?: string
87
+ readonly discovery?: DiscoveryInfo
88
+ readonly installations?: InstallationsInfo
89
+ readonly revision: number
90
+ readonly notice?: string
91
+ }
92
+
93
+ export interface HardwareActions {
94
+ setActive(destination: HardwareDestination): void
95
+ setWorkspaceRoot(root: string): void
96
+ setDiscovery(discovery: DiscoveryInfo): void
97
+ selectProject(path: string): void
98
+ selectArtifact(path: string, kind: 'schematic' | 'pcb'): void
99
+ setInstallations(installations: InstallationsInfo): void
100
+ setNotice(notice?: string): void
101
+ refresh(): void
102
+ }
103
+
104
+ export interface ConfigFormLike<T> {
105
+ getSnapshot(): { readonly value?: T; readonly status?: string; readonly writable?: boolean }
106
+ subscribe(listener: () => void): () => void
107
+ set(field: string, value: unknown): Promise<boolean>
108
+ }
109
+
110
+ export interface HardwareInstallationConfig {
111
+ readonly kicadRoot?: string
112
+ readonly solidcraftRoot?: string
113
+ }
114
+
115
+ /** Parameters carried by one `sidebar.right.openTab` navigation. */
116
+ export interface ViewerNavigationParams {
117
+ readonly destination: HardwareDestination
118
+ /** Canonical absolute artifact path for this destination. */
119
+ readonly path?: string
120
+ /** Artifact kind discriminator (`schematic` | `pcb` | `bom` | `pcb-3d`). */
121
+ readonly kind?: string
122
+ /** Source revision of the artifact at navigation time, when known. */
123
+ readonly revision?: string
124
+ readonly projectPath?: string
125
+ /** Monotonic navigation counter: increments even when params are unchanged. */
126
+ readonly navigationRevision: number
127
+ }
128
+
129
+ /** Functions the UI receives through the slot `inject` face. */
130
+ export interface HardwareInjected {
131
+ refreshDiscovery(cwd?: string, project?: string): Promise<void>
132
+ openDestination(destination: HardwareDestination, path?: string): void
133
+ openNative(application?: NativeApplication, artifactPath?: string): Promise<void>
134
+ saveInstallation(application: 'kicad' | 'solidcraft', root: string): Promise<void>
135
+ fetchInstallations(): Promise<void>
136
+ useConfigForm?(): ConfigFormLike<HardwareInstallationConfig> | undefined
137
+ useSessions?(selector: (state: {
138
+ readonly ids: readonly string[]
139
+ readonly byId: Readonly<Record<string, { readonly cwd?: string }>>
140
+ }) => string | undefined): string | undefined
141
+ }
@@ -0,0 +1,260 @@
1
+ /**
2
+ * One preview surface per destination. Every asynchronous mount is keyed by the
3
+ * navigation revision and owns an AbortController, so a superseded navigation
4
+ * disposes its predecessor instead of painting over it.
5
+ */
6
+ import { createElement, useEffect, useRef, useState, type CSSProperties, type ReactNode } from 'react'
7
+ import { isAbortError, mountEcad } from './ecad.js'
8
+ import { mountGlb } from './glb.js'
9
+ import { loadBom, prepareBoardGlb, type BomProjection } from './transport.js'
10
+ import type { HardwareArtifactInfo, HardwareDestination } from './model.js'
11
+
12
+ const STAGE: CSSProperties = {
13
+ position: 'relative', flex: '1 1 auto', minHeight: 240, overflow: 'hidden',
14
+ border: '1px solid var(--dsw-alias-border-default, rgba(127,127,127,0.3))', borderRadius: 8,
15
+ background: 'var(--dsw-alias-bg-base, #111318)',
16
+ }
17
+ const MESSAGE: CSSProperties = {
18
+ display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100%',
19
+ margin: 0, padding: 16, textAlign: 'center', fontSize: 12,
20
+ color: 'var(--dsw-alias-label-tertiary)',
21
+ }
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
+ const SCRIPT: CSSProperties = {
26
+ margin: 0, padding: '8px 10px', borderRadius: 6, fontSize: 11, whiteSpace: 'pre-wrap', wordBreak: 'break-all',
27
+ background: 'color-mix(in srgb, currentColor 6%, transparent)',
28
+ }
29
+
30
+ type Status = 'loading' | 'ready' | 'error'
31
+
32
+ function describe(error: unknown): string {
33
+ if (error instanceof Error) return error.message
34
+ return String(error)
35
+ }
36
+
37
+ function statusLine(status: Status, message?: string): ReactNode {
38
+ return createElement('p', { style: MESSAGE, role: 'status', 'data-hardware-stage': status }, message
39
+ ?? (status === 'loading' ? 'Loading saved artifact…' : ''))
40
+ }
41
+
42
+ function EcadStage({ kind, path, revision }: { kind: 'schematic' | 'pcb'; path: string; revision?: string }): ReactNode {
43
+ const container = useRef<HTMLDivElement>(null)
44
+ const [status, setStatus] = useState<Status>('loading')
45
+ const [message, setMessage] = useState<string>()
46
+ const [sourceRevision, setSourceRevision] = useState<string>()
47
+
48
+ useEffect(() => {
49
+ const element = container.current
50
+ if (element === null) return
51
+ const controller = new AbortController()
52
+ let live = true
53
+ let mounted: { dispose(): void } | undefined
54
+ setStatus('loading')
55
+ setMessage(undefined)
56
+ element.replaceChildren()
57
+ mountEcad(kind, path, element, {
58
+ signal: controller.signal,
59
+ ...(revision === undefined ? {} : { revision }),
60
+ })
61
+ .then((result) => {
62
+ if (!live) {
63
+ result.dispose()
64
+ return
65
+ }
66
+ mounted = result
67
+ setSourceRevision(result.sourceRevision)
68
+ setStatus('ready')
69
+ })
70
+ .catch((error: unknown) => {
71
+ if (!live || isAbortError(error)) return
72
+ setStatus('error')
73
+ setMessage(describe(error))
74
+ })
75
+ return () => {
76
+ live = false
77
+ controller.abort()
78
+ mounted?.dispose()
79
+ element.replaceChildren()
80
+ }
81
+ }, [kind, path, revision])
82
+
83
+ return createElement(
84
+ 'div',
85
+ { style: STAGE, 'data-hardware-ecad': kind },
86
+ ...(status === 'ready' ? [] : [statusLine(status, message)]),
87
+ createElement('div', { key: 'canvas', ref: container, style: { width: '100%', height: '100%' } }),
88
+ ...(status === 'ready' && sourceRevision !== undefined
89
+ ? [createElement('p', {
90
+ key: 'rev', style: { ...MESSAGE, height: 'auto', justifyContent: 'flex-start', padding: '4px 8px' },
91
+ }, `Saved source revision ${sourceRevision.slice(0, 12)}…`)]
92
+ : []),
93
+ )
94
+ }
95
+
96
+ function GlbStage({ boardPath, cwd }: { boardPath: string; cwd?: string }): ReactNode {
97
+ const container = useRef<HTMLDivElement>(null)
98
+ const [status, setStatus] = useState<Status>('loading')
99
+ const [message, setMessage] = useState<string>()
100
+ const [revision, setRevision] = useState<string>()
101
+
102
+ useEffect(() => {
103
+ const element = container.current
104
+ if (element === null) return
105
+ const controller = new AbortController()
106
+ let live = true
107
+ let mounted: { dispose(): void } | undefined
108
+ setStatus('loading')
109
+ setMessage(undefined)
110
+ element.replaceChildren()
111
+ const run = async (): Promise<void> => {
112
+ const glb = await prepareBoardGlb(boardPath, cwd, controller.signal)
113
+ if (!live) return
114
+ setRevision(glb.revision)
115
+ mounted = await mountGlb(glb.url, element, { signal: controller.signal })
116
+ if (!live) {
117
+ mounted.dispose()
118
+ return
119
+ }
120
+ setStatus('ready')
121
+ }
122
+ run().catch((error: unknown) => {
123
+ if (!live || isAbortError(error)) return
124
+ setStatus('error')
125
+ setMessage(describe(error))
126
+ })
127
+ return () => {
128
+ live = false
129
+ controller.abort()
130
+ mounted?.dispose()
131
+ element.replaceChildren()
132
+ }
133
+ }, [boardPath, cwd])
134
+
135
+ return createElement(
136
+ 'div',
137
+ { style: STAGE, 'data-hardware-glb': true },
138
+ ...(status === 'ready' ? [] : [statusLine(status, message)]),
139
+ createElement('div', { key: 'canvas', ref: container, style: { width: '100%', height: '100%' } }),
140
+ ...(status === 'ready' && revision !== undefined
141
+ ? [createElement('p', {
142
+ key: 'rev', style: { ...MESSAGE, height: 'auto', justifyContent: 'flex-start', padding: '4px 8px' },
143
+ }, `Generated from saved board revision ${revision.slice(0, 12)}…`)]
144
+ : []),
145
+ )
146
+ }
147
+
148
+ function BomStage({ schematicPath }: { schematicPath: string }): ReactNode {
149
+ const [status, setStatus] = useState<Status>('loading')
150
+ const [message, setMessage] = useState<string>()
151
+ const [bom, setBom] = useState<BomProjection>()
152
+
153
+ useEffect(() => {
154
+ const controller = new AbortController()
155
+ let live = true
156
+ setStatus('loading')
157
+ loadBom(schematicPath, controller.signal)
158
+ .then((projection) => {
159
+ if (!live) return
160
+ setBom(projection)
161
+ setStatus('ready')
162
+ })
163
+ .catch((error: unknown) => {
164
+ if (!live || isAbortError(error)) return
165
+ setStatus('error')
166
+ setMessage(describe(error))
167
+ })
168
+ return () => { live = false; controller.abort() }
169
+ }, [schematicPath])
170
+
171
+ if (status !== 'ready' || bom === undefined) {
172
+ return createElement('div', { style: { ...STAGE, overflow: 'auto' } }, statusLine(status, message))
173
+ }
174
+ return createElement(
175
+ 'div',
176
+ { style: { ...STAGE, overflow: 'auto', padding: 8 }, 'data-hardware-bom': true },
177
+ createElement('p', { style: { ...MESSAGE, height: 'auto', padding: '0 0 8px' } },
178
+ `${bom.rows.length} grouped lines from ${bom.path} (revision ${bom.revision.slice(0, 12)}…)`),
179
+ createElement('table', { style: TABLE },
180
+ createElement('thead', {}, createElement('tr', {},
181
+ ...['Refs', 'Qty', 'Value', 'Footprint', 'Notes'].map(label => createElement('th', { key: label, style: TH }, label)))),
182
+ createElement('tbody', {},
183
+ ...bom.rows.map((row, index) => createElement('tr', { key: `${row.references.join(',')}:${String(index)}` },
184
+ createElement('td', { style: TD }, row.references.join(' ')),
185
+ createElement('td', { style: TD }, String(row.quantity)),
186
+ createElement('td', { style: TD }, row.value),
187
+ createElement('td', { style: TD }, row.footprint),
188
+ createElement('td', { style: TD },
189
+ [row.dnp ? 'DNP' : '', ...Object.entries(row.fields).map(([key, value]) => `${key}=${value}`)]
190
+ .filter(Boolean).join(' · ')),
191
+ ))),
192
+ ),
193
+ )
194
+ }
195
+
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
+ export interface HardwarePreviewProps {
238
+ readonly destination: HardwareDestination
239
+ readonly artifact?: HardwareArtifactInfo
240
+ readonly projectPath?: string
241
+ /** Monotonic navigation revision; a change disposes the previous mount. */
242
+ readonly revision: number
243
+ readonly notice?: string
244
+ }
245
+
246
+ /** Destination → preview dispatcher. */
247
+ export function HardwarePreview({ destination, artifact, projectPath, revision }: HardwarePreviewProps): ReactNode {
248
+ if (artifact === undefined) return null
249
+ const key = `${destination}:${artifact.path}:${String(revision)}`
250
+ if (destination === 'schematic' || destination === 'pcb') {
251
+ return createElement(EcadStage, {
252
+ key, kind: destination === 'schematic' ? 'schematic' : 'pcb', path: artifact.path, revision: artifact.revision,
253
+ })
254
+ }
255
+ if (destination === '3d') return createElement(GlbStage, { key, boardPath: artifact.path, cwd: projectPath })
256
+ if (destination === 'bom') return createElement(BomStage, { key, schematicPath: artifact.path })
257
+ return createElement(OrderStage, {
258
+ key, boardPath: artifact.path, ...(projectPath === undefined ? {} : { schematicPath: artifact.sourcePath ?? undefined }),
259
+ })
260
+ }