@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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","names":["createElement","useSyncExternalStore","useState","useMemo"],"sources":["../src/client/model.ts","../src/client/components.tsx","../src/client/store.ts","../src/client/transport.ts","../src/client/index.ts"],"sourcesContent":["/** Product-owned navigation and artifact identity. No shadow project database. */\n\nexport type HardwareDestination = 'schematic' | 'pcb' | 'dfm' | 'bom' | '3d' | 'order'\nexport type NativeApplication = 'kicad' | 'solidcraft'\n\nexport const DESTINATIONS: readonly HardwareDestination[] = Object.freeze([\n 'schematic', 'pcb', 'dfm', 'bom', '3d', 'order',\n])\n\nexport const DESTINATION_LABELS: Readonly<Record<HardwareDestination, string>> = Object.freeze({\n schematic: 'Schematic',\n pcb: 'PCB',\n dfm: 'DFM',\n bom: 'BOM',\n '3d': '3D CAD',\n order: 'Order Placing',\n})\n\n/** Which native application a destination can open, if any. */\nexport function applicationFor(destination: HardwareDestination): NativeApplication | undefined {\n if (destination === 'schematic' || destination === 'pcb' || destination === 'dfm' || destination === 'bom') return 'kicad'\n if (destination === '3d') return 'solidcraft'\n return undefined\n}\n\nexport interface HardwareArtifactInfo {\n readonly id: string\n readonly kind: string\n readonly path: string\n readonly title: string\n readonly sourcePath?: string\n}\n\nexport interface HardwareProjectInfo {\n readonly path: string\n readonly name: string\n readonly sheetPath?: string\n readonly schematic?: HardwareArtifactInfo\n readonly bom?: HardwareArtifactInfo\n readonly pcb3d?: HardwareArtifactInfo\n readonly sheets?: readonly HardwareArtifactInfo[]\n readonly boards?: readonly HardwareArtifactInfo[]\n readonly mechanical?: readonly HardwareArtifactInfo[]\n}\n\nexport interface InstallationsInfo {\n readonly kicad?: {\n readonly configured: boolean\n readonly version?: string\n readonly cli?: string\n readonly pcbEditor?: string\n readonly schematicEditor?: string\n readonly error?: string\n }\n readonly solidcraft?: {\n readonly configured: boolean\n readonly executable?: string\n readonly error?: string\n }\n}\n\nexport interface DiscoveryInfo {\n readonly cwd?: string\n readonly projects?: readonly HardwareProjectInfo[]\n readonly selected?: HardwareProjectInfo\n readonly issue?: { readonly code: string; readonly message: string }\n}\n\nexport interface HardwareState {\n readonly activeDestination: HardwareDestination\n readonly workspaceRoot?: string\n readonly projectPath?: string\n readonly schematicPath?: string\n readonly sheetPath?: string\n readonly pcbPath?: string\n readonly mechanicalPath?: string\n readonly discovery?: DiscoveryInfo\n readonly installations?: InstallationsInfo\n readonly revision: number\n readonly notice?: string\n}\n\nexport interface HardwareActions {\n setActive(destination: HardwareDestination): void\n setWorkspaceRoot(root: string): void\n setDiscovery(discovery: DiscoveryInfo): void\n selectArtifact(path: string, kind: 'schematic' | 'pcb' | 'mechanical-3d'): void\n setInstallations(installations: InstallationsInfo): void\n setNotice(notice?: string): void\n refresh(): void\n}\n\nexport interface ConfigFormLike<T> {\n getSnapshot(): { readonly value?: T; readonly status?: string; readonly writable?: boolean }\n subscribe(listener: () => void): () => void\n set(field: string, value: unknown): Promise<boolean>\n}\n\nexport interface HardwareInstallationConfig {\n readonly kicadRoot?: string\n readonly solidcraftRoot?: string\n}\n\n/** Functions the UI receives through the slot `inject` face. */\nexport interface HardwareInjected {\n refreshDiscovery(cwd?: string, project?: string): Promise<void>\n openDestination(destination: HardwareDestination, path?: string): void\n openNative(application?: NativeApplication, artifactPath?: string): Promise<void>\n saveInstallation(application: NativeApplication, root: string): Promise<void>\n fetchInstallations(): Promise<void>\n useConfigForm?(): ConfigFormLike<HardwareInstallationConfig> | undefined\n useSessions?(selector: (state: {\n readonly ids: readonly string[]\n readonly byId: Readonly<Record<string, { readonly cwd?: string }>>\n }) => string | undefined): string | undefined\n}\n","/**\n * Hardware Engineering UI components. All state reaches them through the\n * standard slot props (`useStore`, `actions`) and one injected hook bundle;\n * nothing here imports Node APIs or reaches into another plugin's singleton.\n */\nimport {\n createElement, useEffect, useMemo, useState, useSyncExternalStore,\n type ChangeEvent, type CSSProperties, type ReactNode,\n} from 'react'\nimport {\n applicationFor, DESTINATIONS, DESTINATION_LABELS,\n type HardwareActions, type HardwareArtifactInfo, type HardwareDestination,\n type HardwareInjected, type HardwareInstallationConfig, type HardwareState,\n} from './model.js'\n\ntype UseStore = <S>(selector: (state: HardwareState) => S) => S\n\ninterface SlotProps {\n readonly useStore: UseStore\n readonly actions: HardwareActions\n readonly hooks: HardwareInjected\n readonly t?: (key: string) => string\n}\n\nconst ROW: CSSProperties = { display: 'flex', alignItems: 'center', gap: 4, flexWrap: 'wrap' }\nconst NAV: CSSProperties = { ...ROW, minWidth: 0, fontSize: 12 }\nconst TAB: CSSProperties = {\n border: '1px solid var(--dsw-alias-border-default, rgba(127,127,127,0.3))',\n borderRadius: 6, background: 'transparent', color: 'var(--dsw-alias-label-secondary)',\n padding: '3px 8px', cursor: 'pointer', font: 'inherit', whiteSpace: 'nowrap',\n}\nconst ACTIVE: CSSProperties = {\n ...TAB, color: 'var(--dsw-alias-label-primary)', borderColor: 'var(--dsw-alias-brand-primary, currentColor)',\n background: 'color-mix(in srgb, var(--dsw-alias-brand-primary, currentColor) 10%, transparent)',\n}\nconst PATH: CSSProperties = {\n minWidth: 0, maxWidth: 260, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',\n color: 'var(--dsw-alias-label-tertiary)', fontSize: 11,\n}\nconst ROOT: CSSProperties = {\n display: 'flex', flexDirection: 'column', height: '100%', minWidth: 0,\n boxSizing: 'border-box', padding: 12, gap: 10,\n color: 'var(--dsw-alias-label-primary)', overflow: 'auto',\n}\nconst HEADER: CSSProperties = { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8 }\nconst TITLE: CSSProperties = { margin: 0, fontSize: 14, fontWeight: 600 }\nconst BUTTON: CSSProperties = {\n ...TAB, padding: '5px 10px', color: 'var(--dsw-alias-label-primary)',\n}\nconst FIELD: CSSProperties = { display: 'flex', flexDirection: 'column', gap: 4, fontSize: 12 }\nconst INPUT: CSSProperties = {\n width: '100%', boxSizing: 'border-box', padding: '6px 8px', borderRadius: 6,\n border: '1px solid var(--dsw-alias-border-default, rgba(127,127,127,0.3))',\n background: 'transparent', color: 'inherit', font: 'inherit',\n}\nconst MUTED: CSSProperties = { color: 'var(--dsw-alias-label-tertiary)', fontSize: 12, margin: 0 }\nconst SELECT: CSSProperties = { ...INPUT, cursor: 'pointer' }\n\nfunction option(value: string, label: string, selected: boolean): ReactNode {\n return createElement('option', { key: value, value, selected }, label)\n}\n\nfunction artifactOptions(artifacts: readonly HardwareArtifactInfo[] | undefined, kind: string): ReactNode[] {\n return (artifacts ?? []).filter(artifact => artifact.kind === kind || kind === 'any')\n .map(artifact => option(artifact.path, artifact.title || artifact.path, false))\n}\n\n/** Six persistent destinations in the conversation header's leading seat. */\nexport function EngineeringNav({\n useStore, actions, hooks, useSessions,\n}: SlotProps & {\n useSessions?: (selector: (state: {\n readonly ids: readonly string[]\n readonly byId: Readonly<Record<string, { readonly cwd?: string }>>\n }) => string | undefined) => string | undefined\n}): ReactNode {\n const active = useStore(state => state.activeDestination)\n const projectPath = useStore(state => state.projectPath)\n const cwd = useSessions?.(state => {\n const id = state.ids[0]\n return id === undefined ? undefined : state.byId[id]?.cwd\n })\n useEffect(() => { void hooks.refreshDiscovery(cwd) }, [cwd, hooks])\n return createElement(\n 'div',\n { style: NAV, 'data-hardware-nav': true },\n ...DESTINATIONS.map(destination => createElement(\n 'button',\n {\n key: destination, type: 'button',\n style: destination === active ? ACTIVE : TAB,\n 'aria-pressed': destination === active,\n onClick: () => {\n actions.setActive(destination)\n hooks.openDestination(destination)\n },\n },\n DESTINATION_LABELS[destination],\n )),\n ...(projectPath === undefined ? [] : [createElement('span', { key: 'path', style: PATH, title: projectPath }, projectPath)]),\n )\n}\n\n/** Right-panel body: one artifact at a time, with explicit selectors. */\nexport function HardwareViewerBody({\n useStore, actions, hooks, tab,\n}: SlotProps & {\n tab?: { readonly navigation?: { readonly params?: Readonly<Record<string, unknown>>; readonly revision?: number } }\n}): ReactNode {\n const active = useStore(state => state.activeDestination)\n const discovery = useStore(state => state.discovery)\n const projectPath = useStore(state => state.projectPath)\n const schematicPath = useStore(state => state.schematicPath)\n const pcbPath = useStore(state => state.pcbPath)\n const mechanicalPath = useStore(state => state.mechanicalPath)\n const notice = useStore(state => state.notice)\n const revision = tab?.navigation?.revision ?? 0\n const selectedProject = discovery?.selected ?? discovery?.projects?.[0]\n const application = applicationFor(active)\n const installed = useStore(state => state.installations)\n const configured = application === 'kicad'\n ? installed?.kicad?.configured ?? false\n : installed?.solidcraft?.configured ?? false\n\n useEffect(() => { void hooks.refreshDiscovery() }, [revision, hooks])\n useEffect(() => { void hooks.fetchInstallations() }, [hooks])\n\n const artifactPath = active === '3d' ? mechanicalPath\n : active === 'bom' ? schematicPath\n : active === 'schematic' || active === 'dfm' ? schematicPath\n : active === 'pcb' ? pcbPath : undefined\n\n return createElement(\n 'div',\n { style: ROOT, 'data-hardware-destination': active },\n createElement(\n 'div',\n { style: HEADER },\n createElement('h2', { style: TITLE }, DESTINATION_LABELS[active]),\n createElement(\n 'button',\n {\n type: 'button', style: BUTTON, disabled: application === undefined || !configured,\n onClick: () => { void hooks.openNative(application, artifactPath).catch(error => actions.setNotice(String(error))) },\n },\n application === 'kicad' ? 'Open in KiCad'\n : application === 'solidcraft' ? 'Open in SolidCraft' : 'No native action',\n ),\n ),\n ...(notice === undefined ? [] : [createElement('p', { key: 'notice', style: MUTED, role: 'status' }, notice)]),\n ...(discovery?.issue === undefined ? [] : [createElement('p', {\n key: 'issue', style: MUTED, role: 'status',\n }, discovery.issue.message)]),\n createElement('p', { style: MUTED }, projectPath === undefined ? 'No canonical KiCad project selected.' : `Project: ${projectPath}`),\n ...(selectedProject === undefined ? [createElement('div', { key: 'empty' },\n createElement('p', { style: MUTED }, 'Open Project · New Project · Ask AI Hardware Engineer'),\n )] : [\n createElement(\n 'label',\n { key: 'project', style: FIELD },\n 'Project',\n createElement('select', {\n style: SELECT, value: projectPath ?? '',\n onChange: (event: ChangeEvent<HTMLSelectElement>) => { void hooks.refreshDiscovery(undefined, event.currentTarget.value) },\n },\n option('', 'Select a project…', projectPath === undefined),\n ...(discovery?.projects ?? []).map(project => option(project.path, project.name, project.path === projectPath))),\n ),\n ...(active === 'schematic' || active === 'bom' || active === 'dfm' ? [\n createElement('label', { key: 'sheet', style: FIELD }, 'Schematic / sheet',\n createElement('select', {\n style: SELECT, value: schematicPath ?? '',\n onChange: (event: ChangeEvent<HTMLSelectElement>) => { actions.selectArtifact(event.currentTarget.value, 'schematic'); hooks.openDestination(active, event.currentTarget.value) },\n },\n option('', 'Select a schematic…', schematicPath === undefined),\n ...(selectedProject.schematic === undefined ? [] : [option(selectedProject.schematic.path, selectedProject.schematic.title, false)]),\n ...artifactOptions(selectedProject.sheets, 'schematic'))),\n ] : []),\n ...(active === 'pcb' || active === 'dfm' ? [\n createElement('label', { key: 'board', style: FIELD }, 'Board',\n createElement('select', {\n style: SELECT, value: pcbPath ?? '',\n onChange: (event: ChangeEvent<HTMLSelectElement>) => { actions.selectArtifact(event.currentTarget.value, 'pcb'); hooks.openDestination(active, event.currentTarget.value) },\n },\n option('', 'Select a board…', pcbPath === undefined),\n ...artifactOptions(selectedProject.boards, 'pcb'))),\n ] : []),\n ...(active === '3d' ? [\n createElement('label', { key: 'model', style: FIELD }, 'Mechanical model',\n createElement('select', {\n style: SELECT, value: mechanicalPath ?? '',\n onChange: (event: ChangeEvent<HTMLSelectElement>) => { actions.selectArtifact(event.currentTarget.value, 'mechanical-3d'); hooks.openDestination(active, event.currentTarget.value) },\n },\n option('', 'Select a model…', mechanicalPath === undefined),\n ...artifactOptions(selectedProject.mechanical, 'mechanical-3d'))),\n ] : []),\n ...(active === 'order' ? [\n createElement('p', { key: 'order', style: MUTED },\n 'PCB Fabrication and PCBA Assembly use the existing quote/order tools. Quote and order are separate steps.'),\n ] : []),\n createElement('p', { key: 'artifact', style: MUTED },\n artifactPath === undefined ? 'No artifact selected for this destination.' : `Selected: ${artifactPath}`),\n ]),\n ...(configured ? [] : [createElement('p', {\n key: 'unconfigured', style: MUTED,\n }, `Configure ${application === 'solidcraft' ? 'SolidCraft' : 'KiCad'} in Settings → Hardware Engineering to enable the native action.`)]),\n )\n}\n\n/** Settings section for the two CAD installation roots. */\nexport function HardwareSettingsSection({ hooks }: { readonly hooks: HardwareInjected }): ReactNode {\n const form = hooks.useConfigForm?.()\n const emptySnapshot: { value?: HardwareInstallationConfig } = {}\n const snapshot = useSyncExternalStore<{ value?: HardwareInstallationConfig }>(\n form?.subscribe.bind(form) ?? (() => () => {}),\n form?.getSnapshot.bind(form) ?? (() => emptySnapshot),\n form?.getSnapshot.bind(form) ?? (() => emptySnapshot),\n )\n const value = snapshot.value\n const [kicadRoot, setKicadRoot] = useState(value?.kicadRoot ?? '')\n const [solidcraftRoot, setSolidcraftRoot] = useState(value?.solidcraftRoot ?? '')\n const [message, setMessage] = useState('')\n useEffect(() => {\n setKicadRoot(value?.kicadRoot ?? '')\n setSolidcraftRoot(value?.solidcraftRoot ?? '')\n }, [value?.kicadRoot, value?.solidcraftRoot])\n\n const save = async (application: 'kicad' | 'solidcraft', root: string): Promise<void> => {\n try {\n await hooks.saveInstallation(application, root)\n await hooks.fetchInstallations()\n setMessage(`${application === 'kicad' ? 'KiCad' : 'SolidCraft'} installation saved and validated.`)\n } catch (error) {\n setMessage(String(error))\n }\n }\n\n return createElement(\n 'div',\n { style: { ...ROOT, height: 'auto' }, 'data-hardware-settings': true },\n createElement('h2', { style: TITLE }, 'Hardware Engineering'),\n createElement('label', { style: FIELD }, 'KiCad installation root or kicad-cli path',\n createElement('input', { style: INPUT, value: kicadRoot, onChange: event => setKicadRoot(event.currentTarget.value) }),\n ),\n createElement('button', { type: 'button', style: BUTTON, onClick: () => { void save('kicad', kicadRoot) } }, 'Validate / Save KiCad'),\n createElement('label', { style: FIELD }, 'SolidCraft installation root or executable path',\n createElement('input', { style: INPUT, value: solidcraftRoot, onChange: event => setSolidcraftRoot(event.currentTarget.value) }),\n ),\n createElement('button', { type: 'button', style: BUTTON, onClick: () => { void save('solidcraft', solidcraftRoot) } }, 'Validate / Save SolidCraft'),\n ...(message === '' ? [] : [createElement('p', { style: MUTED, role: 'status' }, message)]),\n )\n}\n\n/** Compact contextual action in the conversation header corner. */\nexport function ContextualOpenAction({ useStore, hooks }: SlotProps): ReactNode {\n const active = useStore(state => state.activeDestination)\n const schematicPath = useStore(state => state.schematicPath)\n const pcbPath = useStore(state => state.pcbPath)\n const mechanicalPath = useStore(state => state.mechanicalPath)\n const application = applicationFor(active)\n const installations = useStore(state => state.installations)\n const configured = application === 'kicad'\n ? installed(installations?.kicad?.configured)\n : installed(installations?.solidcraft?.configured)\n const label = useMemo(() => application === 'kicad' ? 'Open in KiCad'\n : application === 'solidcraft' ? 'Open in SolidCraft' : '', [application])\n if (label === '') return null\n const artifactPath = application === 'solidcraft' ? mechanicalPath\n : active === 'pcb' || active === 'dfm' ? pcbPath : schematicPath\n return createElement(\n 'button',\n {\n type: 'button', style: BUTTON, disabled: !configured || artifactPath === undefined,\n title: configured ? label : `${label} is unavailable until its installation is configured`,\n onClick: () => { void hooks.openNative(application, artifactPath) },\n },\n label,\n )\n}\n\nfunction installed(value: boolean | undefined): boolean {\n return value ?? false\n}\n","/**\n * One store handle shared by the navigation, viewer, context action and\n * settings registrations. It follows DSH's declared-store contract: a spec\n * (init + complete write set) plus a per-scope instance factory. The handle is\n * created inside `apply()`, never at module scope, so a plugin reload cannot\n * resurrect an old snapshot.\n */\nimport type {\n HardwareActions, HardwareDestination, HardwareState, DiscoveryInfo, InstallationsInfo,\n} from './model.js'\n\ntype Mutable<T> = { -readonly [K in keyof T]: T[K] }\n\ntype Mutator = (draft: Mutable<HardwareState>, ...params: unknown[]) => void\n\nexport interface HardwareStoreInstance {\n readonly actions: HardwareActions\n getSnapshot(): HardwareState\n subscribe(listener: () => void): () => void\n clearPersisted(): void\n}\n\nexport interface HardwareStoreHandle {\n readonly spec: {\n readonly init: () => HardwareState\n readonly actions: Record<string, Mutator>\n }\n create(scopeKey?: string): HardwareStoreInstance\n}\n\nfunction initial(): HardwareState {\n return { activeDestination: 'schematic', revision: 0 }\n}\n\nconst mutators = {\n setActive(draft: Mutable<HardwareState>, destination: HardwareDestination): void {\n draft.activeDestination = destination\n draft.revision += 1\n },\n setWorkspaceRoot(draft: Mutable<HardwareState>, root: string): void {\n draft.workspaceRoot = root\n },\n setDiscovery(draft: Mutable<HardwareState>, discovery: DiscoveryInfo): void {\n draft.discovery = discovery\n draft.workspaceRoot = discovery.cwd ?? draft.workspaceRoot\n draft.projectPath = discovery.selected?.path\n const selected = discovery.selected\n draft.schematicPath = selected?.sheetPath ?? selected?.schematic?.path\n draft.pcbPath = selected?.boards?.[0]?.path ?? selected?.pcb3d?.path\n draft.mechanicalPath = selected?.mechanical?.[0]?.path\n draft.revision += 1\n },\n selectArtifact(draft: Mutable<HardwareState>, path: string, kind: 'schematic' | 'pcb' | 'mechanical-3d'): void {\n if (kind === 'schematic') draft.schematicPath = path\n else if (kind === 'pcb') draft.pcbPath = path\n else draft.mechanicalPath = path\n draft.revision += 1\n },\n setInstallations(draft: Mutable<HardwareState>, installations: InstallationsInfo): void {\n draft.installations = installations\n draft.revision += 1\n },\n setNotice(draft: Mutable<HardwareState>, notice?: string): void {\n if (notice === undefined) delete draft.notice\n else draft.notice = notice\n },\n refresh(draft: Mutable<HardwareState>): void {\n draft.revision += 1\n },\n}\n\n/** Create the shared handle. Call once inside `apply()`. */\nexport function createHardwareStore(): HardwareStoreHandle {\n return {\n spec: { init: initial, actions: mutators as unknown as Record<string, Mutator> },\n create(): HardwareStoreInstance {\n let snapshot = initial()\n const listeners = new Set<() => void>()\n const commit = (mutate: (draft: Mutable<HardwareState>) => void): void => {\n const draft: Mutable<HardwareState> = { ...snapshot }\n mutate(draft)\n snapshot = draft\n for (const listener of [...listeners]) listener()\n }\n return {\n actions: {\n setActive: destination => commit(draft => mutators.setActive(draft, destination)),\n setWorkspaceRoot: root => commit(draft => { draft.workspaceRoot = root }),\n setDiscovery: discovery => commit(draft => mutators.setDiscovery(draft, discovery)),\n selectArtifact: (path, kind) => commit(draft => mutators.selectArtifact(draft, path, kind)),\n setInstallations: installations => commit(draft => mutators.setInstallations(draft, installations)),\n setNotice: notice => commit(draft => mutators.setNotice(draft, notice)),\n refresh: () => commit(draft => mutators.refresh(draft)),\n },\n getSnapshot: () => snapshot,\n subscribe(listener) {\n listeners.add(listener)\n return () => { listeners.delete(listener) }\n },\n clearPersisted() {},\n }\n },\n }\n}\n","/** Same-origin calls to the `@huaqiu/hardware-artifacts` Host routes. */\nimport type {\n DiscoveryInfo, HardwareProjectInfo, InstallationsInfo, NativeApplication,\n} from './model.js'\n\nconst PREFIX = '/api/v1/hardware'\n\ninterface Envelope<T> {\n readonly ok?: boolean\n readonly error?: { readonly code?: string; readonly message?: string }\n readonly data?: T\n readonly [key: string]: unknown\n}\n\nasync function request<T>(path: string, init?: RequestInit): Promise<T> {\n const response = await fetch(`${PREFIX}${path}`, init)\n const body = await response.json().catch(() => undefined) as Envelope<T> | undefined\n if (!response.ok || body?.ok === false) {\n const detail = body?.error?.message ?? `HTTP ${response.status}`\n throw new Error(detail)\n }\n return body as T\n}\n\nfunction query(cwd: string | undefined, project?: string): string {\n const params = new URLSearchParams()\n if (cwd !== undefined && cwd !== '') params.set('cwd', cwd)\n if (project !== undefined && project !== '') params.set('project', project)\n const text = params.toString()\n return text === '' ? '' : `?${text}`\n}\n\nexport async function loadProjects(cwd?: string, project?: string): Promise<DiscoveryInfo> {\n const body = await request<DiscoveryInfo>(`/projects${query(cwd, project)}`)\n const fallback: DiscoveryInfo = {\n cwd: body.cwd,\n projects: Array.isArray(body.projects) ? body.projects : [],\n ...(body.selected === undefined ? {} : { selected: body.selected as HardwareProjectInfo }),\n ...(body.issue === undefined ? {} : { issue: body.issue }),\n }\n return fallback\n}\n\nexport async function loadInstallations(): Promise<InstallationsInfo> {\n return request<InstallationsInfo>('/installations')\n}\n\nexport async function environment(): Promise<{ text?: string; childEnv?: Record<string, string> }> {\n return request<{ text?: string; childEnv?: Record<string, string> }>('/environment')\n}\n\nexport async function openArtifact(requestBody: {\n application: NativeApplication\n artifactPath: string\n kind: string\n projectPath?: string\n}): Promise<void> {\n await request('/open', {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify(requestBody),\n })\n}\n","/**\n * Browser half of `@huaqiu/dsh-hardware-ui`.\n *\n * Occupies existing DSH seats only: a root navigation occupant, a session\n * header action, a `keepMounted` right-panel tab body, and a settings section.\n * The shape below is structural on purpose: this package stays independently\n * installable and does not import DSH internals.\n */\nimport {\n ContextualOpenAction, EngineeringNav, HardwareSettingsSection, HardwareViewerBody,\n} from './components.js'\nimport type {\n ConfigFormLike, HardwareActions, HardwareDestination, HardwareInjected,\n HardwareInstallationConfig, NativeApplication,\n} from './model.js'\nimport { createHardwareStore } from './store.js'\nimport { loadInstallations, loadProjects, openArtifact } from './transport.js'\n\n/** Real Cordis service names this browser plugin waits for. */\nexport const inject = ['slots', 'sidebarRight', 'sidebarRightTabs', 'configForms'] as const\n\nexport const HARDWARE_SETTINGS_ID = 'hardware-engineering'\nexport const HARDWARE_TAB_ID = '@huaqiu/dsh-hardware-ui'\nexport const HARDWARE_TAB_KIND = 'hardware-engineering'\n\ninterface SlotSpec {\n name: string\n id?: string\n key?: string\n order?: number\n label?: () => string\n store?: unknown\n inject?: (...args: unknown[]) => unknown\n}\n\ninterface ClientContext {\n readonly slots?: {\n inject(key: string, callback: () => () => void): () => void\n register(spec: SlotSpec, component: unknown): () => void\n }\n readonly sidebarRight?: {\n openTab(kind: string, options?: {\n params?: Readonly<Record<string, unknown>>\n revealIfOpened?: boolean\n }): void\n }\n readonly sidebarRightTabs?: {\n register(definition: {\n id: string\n kind: string\n keepMounted?: boolean\n title: (address: string) => string\n }): () => void\n }\n readonly configForms?: {\n get<T>(entryId: string): ConfigFormLike<T>\n }\n effect?(fn: () => (() => void) | void, label?: string): void\n}\n\nfunction kindForPath(path: string): string {\n if (path.endsWith('.kicad_sch')) return 'schematic'\n if (path.endsWith('.kicad_pcb')) return 'pcb'\n if (path.endsWith('.kicad_pro')) return 'project'\n if (/\\.(step|stp|glb)$/iu.test(path)) return 'mechanical-3d'\n return 'bom'\n}\n\n/** Install all product UI contributions on a DSH client context. */\nexport function apply(ctx: ClientContext): void {\n const store = createHardwareStore()\n let actions: HardwareActions | undefined\n let revision = 0\n const effect = (fn: () => (() => void) | void, label: string): void => {\n if (ctx.effect !== undefined) ctx.effect(fn, label)\n else fn()\n }\n\n const captureActions = (...args: unknown[]): { hooks: HardwareInjected } => {\n for (const candidate of args) {\n if (candidate !== null && typeof candidate === 'object'\n && typeof (candidate as HardwareActions).setActive === 'function') {\n actions = candidate as HardwareActions\n }\n }\n return { hooks: injected }\n }\n\n const injected: HardwareInjected = {\n async refreshDiscovery(cwd, project) {\n try {\n const result = await loadProjects(cwd, project)\n actions?.setDiscovery(result)\n if (result.issue?.code === 'bad-manifest') actions?.setNotice(result.issue.message)\n } catch (error) {\n actions?.setNotice(`Artifact discovery failed: ${String(error)}`)\n }\n },\n openDestination(destination: HardwareDestination, path) {\n revision += 1\n const kind = path === undefined ? undefined : kindForPath(path)\n try {\n ctx.sidebarRight?.openTab(HARDWARE_TAB_KIND, {\n params: { destination, path, kind, revision },\n revealIfOpened: true,\n })\n } catch (error) {\n actions?.setNotice(`Open viewer failed: ${String(error)}`)\n }\n },\n async openNative(application?: NativeApplication, artifactPath?: string) {\n if (artifactPath === undefined || artifactPath === '') {\n actions?.setNotice('Select an artifact before opening a native application.')\n return\n }\n try {\n await openArtifact({\n application: application ?? 'kicad',\n artifactPath,\n kind: kindForPath(artifactPath),\n })\n } catch (error) {\n actions?.setNotice(`Native launch failed: ${String(error)}`)\n throw error\n }\n },\n async saveInstallation(application, root) {\n const form = ctx.configForms?.get<HardwareInstallationConfig>('hardware-artifacts')\n if (form === undefined) throw new Error('host settings are unavailable')\n const field = application === 'kicad' ? 'kicadRoot' : 'solidcraftRoot'\n const accepted = await form.set(field, root)\n if (!accepted) throw new Error(`the host rejected the ${field} setting`)\n },\n async fetchInstallations() {\n try {\n actions?.setInstallations(await loadInstallations())\n } catch (error) {\n actions?.setNotice(`Installation check failed: ${String(error)}`)\n }\n },\n useConfigForm() {\n return ctx.configForms?.get<HardwareInstallationConfig>('hardware-artifacts')\n },\n }\n\n effect(() => ctx.sidebarRightTabs?.register({\n id: HARDWARE_TAB_ID,\n kind: HARDWARE_TAB_KIND,\n keepMounted: true,\n title: () => 'Hardware Engineering',\n }) ?? (() => {}), 'hardware-ui: right-panel tab type')\n\n const slots = ctx.slots\n if (slots === undefined) return\n\n effect(() => slots.inject('conversation.header.leading', () => slots.register({\n name: 'conversation.header.leading',\n store,\n inject: captureActions,\n }, EngineeringNav)), 'hardware-ui: six-destination navigation')\n\n effect(() => slots.inject('sidebar.right.pane.tab', () => slots.register({\n name: 'sidebar.right.pane.tab',\n key: HARDWARE_TAB_ID,\n store,\n inject: captureActions,\n }, HardwareViewerBody)), 'hardware-ui: viewer body')\n\n effect(() => slots.inject('conversation.session.header.corner', () => slots.register({\n name: 'conversation.session.header.corner',\n store,\n inject: captureActions,\n }, ContextualOpenAction)), 'hardware-ui: contextual native action')\n\n effect(() => slots.inject('settings.section', () => slots.register({\n name: 'settings.section',\n id: HARDWARE_SETTINGS_ID,\n order: 85,\n label: () => 'Hardware Engineering',\n store,\n inject: captureActions,\n }, HardwareSettingsSection)), 'hardware-ui: CAD installation settings')\n}\n"],"mappings":";;;;;;;;EAKA,MAAa,eAA+C,OAAO,OAAO;GACxE;GAAa;GAAO;GAAO;GAAO;GAAM;EAC1C,CAAC;EAED,MAAa,qBAAoE,OAAO,OAAO;GAC7F,WAAW;GACX,KAAK;GACL,KAAK;GACL,KAAK;GACL,MAAM;GACN,OAAO;EACT,CAAC;;EAGD,SAAgB,eAAe,aAAiE;GAC9F,IAAI,gBAAgB,eAAe,gBAAgB,S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AAI;IACJ,OAAO;IACP,aAAa;IACb;IACA,QAAQ;GACV,GAAG,uBAAuB,CAAC,GAAG,wCAAwC;EACxE"}
@@ -0,0 +1,17 @@
1
+ //#region src/index.d.ts
2
+ /**
3
+ * Node half of `@huaqiu/dsh-hardware-ui`.
4
+ *
5
+ * All product UI is browser-side. This entry exists so the package is a normal
6
+ * installable plugin in the DSH bundle; it intentionally provides no service
7
+ * and injects nothing. Host operations live in `@huaqiu/hardware-artifacts`.
8
+ */
9
+ declare const name = "@huaqiu/dsh-hardware-ui";
10
+ /** Browser-only plugin: the node Loader seat intentionally does nothing. */
11
+ declare function apply(): void;
12
+ /** The tab kind owned by this product UI. */
13
+ declare const HARDWARE_TAB_KIND = "hardware-engineering";
14
+ /** Slots this product UI occupies. Exported for contract tests and readers. */
15
+ declare const HARDWARE_UI_SLOTS: readonly ["conversation.header.leading", "conversation.session.header.corner", "sidebar.right.pane.tab", "settings.section"];
16
+ //#endregion
17
+ export { HARDWARE_TAB_KIND, HARDWARE_UI_SLOTS, apply, name };
package/lib/index.mjs ADDED
@@ -0,0 +1,22 @@
1
+ //#region src/index.ts
2
+ /**
3
+ * Node half of `@huaqiu/dsh-hardware-ui`.
4
+ *
5
+ * All product UI is browser-side. This entry exists so the package is a normal
6
+ * installable plugin in the DSH bundle; it intentionally provides no service
7
+ * and injects nothing. Host operations live in `@huaqiu/hardware-artifacts`.
8
+ */
9
+ const name = "@huaqiu/dsh-hardware-ui";
10
+ /** Browser-only plugin: the node Loader seat intentionally does nothing. */
11
+ function apply() {}
12
+ /** The tab kind owned by this product UI. */
13
+ const HARDWARE_TAB_KIND = "hardware-engineering";
14
+ /** Slots this product UI occupies. Exported for contract tests and readers. */
15
+ const HARDWARE_UI_SLOTS = Object.freeze([
16
+ "conversation.header.leading",
17
+ "conversation.session.header.corner",
18
+ "sidebar.right.pane.tab",
19
+ "settings.section"
20
+ ]);
21
+ //#endregion
22
+ export { HARDWARE_TAB_KIND, HARDWARE_UI_SLOTS, apply, name };
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "@huaqiu/dsh-hardware-ui",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.7.12",
4
+ "type": "module",
5
+ "description": "Hardware Engineering product UI for DSH: six-destination engineering navigation, right-panel artifact viewer, CAD installation settings and contextual native-application actions.",
6
+ "license": "MIT",
7
+ "main": "./lib/index.mjs",
8
+ "types": "./lib/index.d.mts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./lib/index.d.mts",
12
+ "default": "./lib/index.mjs"
13
+ },
14
+ "./client": {
15
+ "default": "./lib/client.js"
16
+ },
17
+ "./cordis.patch.yml": "./cordis.patch.yml",
18
+ "./package.json": "./package.json"
19
+ },
20
+ "dsh": {
21
+ "bundle": {
22
+ "patch": "./cordis.patch.yml"
23
+ },
24
+ "client": {
25
+ "platform": "web",
26
+ "inject": [
27
+ "@deepseek-ai/dsh-client-ui-slots"
28
+ ]
29
+ }
30
+ },
31
+ "engines": {
32
+ "dsh": "^0.2.2-rc.1"
33
+ },
34
+ "peerDependencies": {
35
+ "@deepseek-ai/cordis": "^4.0.1",
36
+ "react": "^18"
37
+ },
38
+ "devDependencies": {
39
+ "@deepseek-ai/cordis": "^4.0.2",
40
+ "@types/react": "~18.3.1",
41
+ "react": "^18.3.1",
42
+ "react-dom": "^18.3.1",
43
+ "tsdown": "^0.22.14",
44
+ "typescript": "^5.9.0",
45
+ "vitest": "^4.1.0"
46
+ },
47
+ "files": [
48
+ "lib",
49
+ "src",
50
+ "cordis.patch.yml",
51
+ "README.md"
52
+ ],
53
+ "publishConfig": {
54
+ "access": "public"
55
+ },
56
+ "scripts": {
57
+ "typecheck": "tsc --noEmit",
58
+ "build": "tsdown",
59
+ "test": "vitest run"
60
+ }
6
61
  }
@@ -0,0 +1,283 @@
1
+ /**
2
+ * Hardware Engineering UI components. All state reaches them through the
3
+ * standard slot props (`useStore`, `actions`) and one injected hook bundle;
4
+ * nothing here imports Node APIs or reaches into another plugin's singleton.
5
+ */
6
+ import {
7
+ createElement, useEffect, useMemo, useState, useSyncExternalStore,
8
+ type ChangeEvent, type CSSProperties, type ReactNode,
9
+ } from 'react'
10
+ import {
11
+ applicationFor, DESTINATIONS, DESTINATION_LABELS,
12
+ type HardwareActions, type HardwareArtifactInfo, type HardwareDestination,
13
+ type HardwareInjected, type HardwareInstallationConfig, type HardwareState,
14
+ } from './model.js'
15
+
16
+ type UseStore = <S>(selector: (state: HardwareState) => S) => S
17
+
18
+ interface SlotProps {
19
+ readonly useStore: UseStore
20
+ readonly actions: HardwareActions
21
+ readonly hooks: HardwareInjected
22
+ readonly t?: (key: string) => string
23
+ }
24
+
25
+ const ROW: CSSProperties = { display: 'flex', alignItems: 'center', gap: 4, flexWrap: 'wrap' }
26
+ const NAV: CSSProperties = { ...ROW, minWidth: 0, fontSize: 12 }
27
+ const TAB: CSSProperties = {
28
+ border: '1px solid var(--dsw-alias-border-default, rgba(127,127,127,0.3))',
29
+ borderRadius: 6, background: 'transparent', color: 'var(--dsw-alias-label-secondary)',
30
+ padding: '3px 8px', cursor: 'pointer', font: 'inherit', whiteSpace: 'nowrap',
31
+ }
32
+ const ACTIVE: CSSProperties = {
33
+ ...TAB, color: 'var(--dsw-alias-label-primary)', borderColor: 'var(--dsw-alias-brand-primary, currentColor)',
34
+ background: 'color-mix(in srgb, var(--dsw-alias-brand-primary, currentColor) 10%, transparent)',
35
+ }
36
+ const PATH: CSSProperties = {
37
+ minWidth: 0, maxWidth: 260, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
38
+ color: 'var(--dsw-alias-label-tertiary)', fontSize: 11,
39
+ }
40
+ const ROOT: CSSProperties = {
41
+ display: 'flex', flexDirection: 'column', height: '100%', minWidth: 0,
42
+ boxSizing: 'border-box', padding: 12, gap: 10,
43
+ color: 'var(--dsw-alias-label-primary)', overflow: 'auto',
44
+ }
45
+ const HEADER: CSSProperties = { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8 }
46
+ const TITLE: CSSProperties = { margin: 0, fontSize: 14, fontWeight: 600 }
47
+ const BUTTON: CSSProperties = {
48
+ ...TAB, padding: '5px 10px', color: 'var(--dsw-alias-label-primary)',
49
+ }
50
+ const FIELD: CSSProperties = { display: 'flex', flexDirection: 'column', gap: 4, fontSize: 12 }
51
+ const INPUT: CSSProperties = {
52
+ width: '100%', boxSizing: 'border-box', padding: '6px 8px', borderRadius: 6,
53
+ border: '1px solid var(--dsw-alias-border-default, rgba(127,127,127,0.3))',
54
+ background: 'transparent', color: 'inherit', font: 'inherit',
55
+ }
56
+ const MUTED: CSSProperties = { color: 'var(--dsw-alias-label-tertiary)', fontSize: 12, margin: 0 }
57
+ const SELECT: CSSProperties = { ...INPUT, cursor: 'pointer' }
58
+
59
+ function option(value: string, label: string, selected: boolean): ReactNode {
60
+ return createElement('option', { key: value, value, selected }, label)
61
+ }
62
+
63
+ function artifactOptions(artifacts: readonly HardwareArtifactInfo[] | undefined, kind: string): ReactNode[] {
64
+ return (artifacts ?? []).filter(artifact => artifact.kind === kind || kind === 'any')
65
+ .map(artifact => option(artifact.path, artifact.title || artifact.path, false))
66
+ }
67
+
68
+ /** Six persistent destinations in the conversation header's leading seat. */
69
+ export function EngineeringNav({
70
+ useStore, actions, hooks, useSessions,
71
+ }: SlotProps & {
72
+ useSessions?: (selector: (state: {
73
+ readonly ids: readonly string[]
74
+ readonly byId: Readonly<Record<string, { readonly cwd?: string }>>
75
+ }) => string | undefined) => string | undefined
76
+ }): ReactNode {
77
+ const active = useStore(state => state.activeDestination)
78
+ const projectPath = useStore(state => state.projectPath)
79
+ const cwd = useSessions?.(state => {
80
+ const id = state.ids[0]
81
+ return id === undefined ? undefined : state.byId[id]?.cwd
82
+ })
83
+ useEffect(() => { void hooks.refreshDiscovery(cwd) }, [cwd, hooks])
84
+ return createElement(
85
+ 'div',
86
+ { style: NAV, 'data-hardware-nav': true },
87
+ ...DESTINATIONS.map(destination => createElement(
88
+ 'button',
89
+ {
90
+ key: destination, type: 'button',
91
+ style: destination === active ? ACTIVE : TAB,
92
+ 'aria-pressed': destination === active,
93
+ onClick: () => {
94
+ actions.setActive(destination)
95
+ hooks.openDestination(destination)
96
+ },
97
+ },
98
+ DESTINATION_LABELS[destination],
99
+ )),
100
+ ...(projectPath === undefined ? [] : [createElement('span', { key: 'path', style: PATH, title: projectPath }, projectPath)]),
101
+ )
102
+ }
103
+
104
+ /** Right-panel body: one artifact at a time, with explicit selectors. */
105
+ export function HardwareViewerBody({
106
+ useStore, actions, hooks, tab,
107
+ }: SlotProps & {
108
+ tab?: { readonly navigation?: { readonly params?: Readonly<Record<string, unknown>>; readonly revision?: number } }
109
+ }): ReactNode {
110
+ const active = useStore(state => state.activeDestination)
111
+ const discovery = useStore(state => state.discovery)
112
+ const projectPath = useStore(state => state.projectPath)
113
+ const schematicPath = useStore(state => state.schematicPath)
114
+ const pcbPath = useStore(state => state.pcbPath)
115
+ const mechanicalPath = useStore(state => state.mechanicalPath)
116
+ const notice = useStore(state => state.notice)
117
+ const revision = tab?.navigation?.revision ?? 0
118
+ const selectedProject = discovery?.selected ?? discovery?.projects?.[0]
119
+ const application = applicationFor(active)
120
+ const installed = useStore(state => state.installations)
121
+ const configured = application === 'kicad'
122
+ ? installed?.kicad?.configured ?? false
123
+ : installed?.solidcraft?.configured ?? false
124
+
125
+ useEffect(() => { void hooks.refreshDiscovery() }, [revision, hooks])
126
+ useEffect(() => { void hooks.fetchInstallations() }, [hooks])
127
+
128
+ const artifactPath = active === '3d' ? mechanicalPath
129
+ : active === 'bom' ? schematicPath
130
+ : active === 'schematic' || active === 'dfm' ? schematicPath
131
+ : active === 'pcb' ? pcbPath : undefined
132
+
133
+ return createElement(
134
+ 'div',
135
+ { style: ROOT, 'data-hardware-destination': active },
136
+ createElement(
137
+ 'div',
138
+ { style: HEADER },
139
+ createElement('h2', { style: TITLE }, DESTINATION_LABELS[active]),
140
+ createElement(
141
+ 'button',
142
+ {
143
+ type: 'button', style: BUTTON, disabled: application === undefined || !configured,
144
+ onClick: () => { void hooks.openNative(application, artifactPath).catch(error => actions.setNotice(String(error))) },
145
+ },
146
+ application === 'kicad' ? 'Open in KiCad'
147
+ : application === 'solidcraft' ? 'Open in SolidCraft' : 'No native action',
148
+ ),
149
+ ),
150
+ ...(notice === undefined ? [] : [createElement('p', { key: 'notice', style: MUTED, role: 'status' }, notice)]),
151
+ ...(discovery?.issue === undefined ? [] : [createElement('p', {
152
+ key: 'issue', style: MUTED, role: 'status',
153
+ }, discovery.issue.message)]),
154
+ createElement('p', { style: MUTED }, projectPath === undefined ? 'No canonical KiCad project selected.' : `Project: ${projectPath}`),
155
+ ...(selectedProject === undefined ? [createElement('div', { key: 'empty' },
156
+ createElement('p', { style: MUTED }, 'Open Project · New Project · Ask AI Hardware Engineer'),
157
+ )] : [
158
+ createElement(
159
+ 'label',
160
+ { key: 'project', style: FIELD },
161
+ 'Project',
162
+ createElement('select', {
163
+ style: SELECT, value: projectPath ?? '',
164
+ onChange: (event: ChangeEvent<HTMLSelectElement>) => { void hooks.refreshDiscovery(undefined, event.currentTarget.value) },
165
+ },
166
+ option('', 'Select a project…', projectPath === undefined),
167
+ ...(discovery?.projects ?? []).map(project => option(project.path, project.name, project.path === projectPath))),
168
+ ),
169
+ ...(active === 'schematic' || active === 'bom' || active === 'dfm' ? [
170
+ createElement('label', { key: 'sheet', style: FIELD }, 'Schematic / sheet',
171
+ createElement('select', {
172
+ style: SELECT, value: schematicPath ?? '',
173
+ onChange: (event: ChangeEvent<HTMLSelectElement>) => { actions.selectArtifact(event.currentTarget.value, 'schematic'); hooks.openDestination(active, event.currentTarget.value) },
174
+ },
175
+ option('', 'Select a schematic…', schematicPath === undefined),
176
+ ...(selectedProject.schematic === undefined ? [] : [option(selectedProject.schematic.path, selectedProject.schematic.title, false)]),
177
+ ...artifactOptions(selectedProject.sheets, 'schematic'))),
178
+ ] : []),
179
+ ...(active === 'pcb' || active === 'dfm' ? [
180
+ createElement('label', { key: 'board', style: FIELD }, 'Board',
181
+ createElement('select', {
182
+ style: SELECT, value: pcbPath ?? '',
183
+ onChange: (event: ChangeEvent<HTMLSelectElement>) => { actions.selectArtifact(event.currentTarget.value, 'pcb'); hooks.openDestination(active, event.currentTarget.value) },
184
+ },
185
+ option('', 'Select a board…', pcbPath === undefined),
186
+ ...artifactOptions(selectedProject.boards, 'pcb'))),
187
+ ] : []),
188
+ ...(active === '3d' ? [
189
+ createElement('label', { key: 'model', style: FIELD }, 'Mechanical model',
190
+ createElement('select', {
191
+ style: SELECT, value: mechanicalPath ?? '',
192
+ onChange: (event: ChangeEvent<HTMLSelectElement>) => { actions.selectArtifact(event.currentTarget.value, 'mechanical-3d'); hooks.openDestination(active, event.currentTarget.value) },
193
+ },
194
+ option('', 'Select a model…', mechanicalPath === undefined),
195
+ ...artifactOptions(selectedProject.mechanical, 'mechanical-3d'))),
196
+ ] : []),
197
+ ...(active === 'order' ? [
198
+ createElement('p', { key: 'order', style: MUTED },
199
+ 'PCB Fabrication and PCBA Assembly use the existing quote/order tools. Quote and order are separate steps.'),
200
+ ] : []),
201
+ createElement('p', { key: 'artifact', style: MUTED },
202
+ artifactPath === undefined ? 'No artifact selected for this destination.' : `Selected: ${artifactPath}`),
203
+ ]),
204
+ ...(configured ? [] : [createElement('p', {
205
+ key: 'unconfigured', style: MUTED,
206
+ }, `Configure ${application === 'solidcraft' ? 'SolidCraft' : 'KiCad'} in Settings → Hardware Engineering to enable the native action.`)]),
207
+ )
208
+ }
209
+
210
+ /** Settings section for the two CAD installation roots. */
211
+ export function HardwareSettingsSection({ hooks }: { readonly hooks: HardwareInjected }): ReactNode {
212
+ const form = hooks.useConfigForm?.()
213
+ const emptySnapshot: { value?: HardwareInstallationConfig } = {}
214
+ const snapshot = useSyncExternalStore<{ value?: HardwareInstallationConfig }>(
215
+ form?.subscribe.bind(form) ?? (() => () => {}),
216
+ form?.getSnapshot.bind(form) ?? (() => emptySnapshot),
217
+ form?.getSnapshot.bind(form) ?? (() => emptySnapshot),
218
+ )
219
+ const value = snapshot.value
220
+ const [kicadRoot, setKicadRoot] = useState(value?.kicadRoot ?? '')
221
+ const [solidcraftRoot, setSolidcraftRoot] = useState(value?.solidcraftRoot ?? '')
222
+ const [message, setMessage] = useState('')
223
+ useEffect(() => {
224
+ setKicadRoot(value?.kicadRoot ?? '')
225
+ setSolidcraftRoot(value?.solidcraftRoot ?? '')
226
+ }, [value?.kicadRoot, value?.solidcraftRoot])
227
+
228
+ const save = async (application: 'kicad' | 'solidcraft', root: string): Promise<void> => {
229
+ try {
230
+ await hooks.saveInstallation(application, root)
231
+ await hooks.fetchInstallations()
232
+ setMessage(`${application === 'kicad' ? 'KiCad' : 'SolidCraft'} installation saved and validated.`)
233
+ } catch (error) {
234
+ setMessage(String(error))
235
+ }
236
+ }
237
+
238
+ return createElement(
239
+ 'div',
240
+ { style: { ...ROOT, height: 'auto' }, 'data-hardware-settings': true },
241
+ createElement('h2', { style: TITLE }, 'Hardware Engineering'),
242
+ createElement('label', { style: FIELD }, 'KiCad installation root or kicad-cli path',
243
+ createElement('input', { style: INPUT, value: kicadRoot, onChange: event => setKicadRoot(event.currentTarget.value) }),
244
+ ),
245
+ createElement('button', { type: 'button', style: BUTTON, onClick: () => { void save('kicad', kicadRoot) } }, 'Validate / Save KiCad'),
246
+ createElement('label', { style: FIELD }, 'SolidCraft installation root or executable path',
247
+ createElement('input', { style: INPUT, value: solidcraftRoot, onChange: event => setSolidcraftRoot(event.currentTarget.value) }),
248
+ ),
249
+ createElement('button', { type: 'button', style: BUTTON, onClick: () => { void save('solidcraft', solidcraftRoot) } }, 'Validate / Save SolidCraft'),
250
+ ...(message === '' ? [] : [createElement('p', { style: MUTED, role: 'status' }, message)]),
251
+ )
252
+ }
253
+
254
+ /** Compact contextual action in the conversation header corner. */
255
+ export function ContextualOpenAction({ useStore, hooks }: SlotProps): ReactNode {
256
+ const active = useStore(state => state.activeDestination)
257
+ const schematicPath = useStore(state => state.schematicPath)
258
+ const pcbPath = useStore(state => state.pcbPath)
259
+ const mechanicalPath = useStore(state => state.mechanicalPath)
260
+ const application = applicationFor(active)
261
+ const installations = useStore(state => state.installations)
262
+ const configured = application === 'kicad'
263
+ ? installed(installations?.kicad?.configured)
264
+ : installed(installations?.solidcraft?.configured)
265
+ const label = useMemo(() => application === 'kicad' ? 'Open in KiCad'
266
+ : application === 'solidcraft' ? 'Open in SolidCraft' : '', [application])
267
+ if (label === '') return null
268
+ const artifactPath = application === 'solidcraft' ? mechanicalPath
269
+ : active === 'pcb' || active === 'dfm' ? pcbPath : schematicPath
270
+ return createElement(
271
+ 'button',
272
+ {
273
+ type: 'button', style: BUTTON, disabled: !configured || artifactPath === undefined,
274
+ title: configured ? label : `${label} is unavailable until its installation is configured`,
275
+ onClick: () => { void hooks.openNative(application, artifactPath) },
276
+ },
277
+ label,
278
+ )
279
+ }
280
+
281
+ function installed(value: boolean | undefined): boolean {
282
+ return value ?? false
283
+ }