@huaqiu/dsh-tool-pcb-viewer 0.4.3 → 0.4.5

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 CHANGED
@@ -58839,8 +58839,10 @@ void main() {
58839
58839
  }
58840
58840
  })] });
58841
58841
  }
58842
- function PreviewWatcher({ useSession }) {
58843
- const nodes = useSession ? useSession((s) => s && s.nodes || EMPTY_NODES) : EMPTY_NODES;
58842
+ function PreviewWatcher({ useChat, useSession }) {
58843
+ const chatNodes = useChat ? useChat((s) => s && s.legacy && s.legacy.nodes || EMPTY_NODES) : EMPTY_NODES;
58844
+ const sessionNodes = useSession ? useSession((s) => s && s.nodes || EMPTY_NODES) : EMPTY_NODES;
58845
+ const nodes = chatNodes.length > 0 ? chatNodes : sessionNodes;
58844
58846
  (0, react.useEffect)(() => {
58845
58847
  const idx = indexPreviews(nodes);
58846
58848
  previewIndex.byTurn = idx.byTurn;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huaqiu/dsh-tool-pcb-viewer",
3
- "version": "0.4.3",
3
+ "version": "0.4.5",
4
4
  "description": "KiCad .kicad_pcb → interactive 2D-layout + 3D board viewer DSH plugin: a pcb_preview tool, an in-conversation turn-tail card (live 3D thumbnail + actions), a big-screen split panel, and a standalone full-page route. Parses via @huaqiu/kicad-sexpr-parser through a model adapter.",
5
5
  "type": "module",
6
6
  "main": "./lib/index.mjs",
@@ -44,6 +44,15 @@ interface SessionOwner {
44
44
  }
45
45
  /** 会话快照的 useSession 选择器(宿主注入)。 */
46
46
  type UseSession = <T>(selector: (snapshot: SessionSnapshot | undefined) => T) => T
47
+ /**
48
+ * chat 视图快照(session 作用域的 chat 钩子,宿主以 useChat 注入)。
49
+ * 对话节点在这里:`nodes` 是 ChatNodeStore,数组形式是 `legacy.nodes`。
50
+ */
51
+ interface ChatSnapshot {
52
+ legacy?: { nodes?: SessionNode[] }
53
+ }
54
+ /** chat 快照的 useChat 选择器(宿主注入)。 */
55
+ type UseChat = <T>(selector: (snapshot: ChatSnapshot | undefined) => T) => T
47
56
 
48
57
  const inject = ['slots']
49
58
 
@@ -455,11 +464,16 @@ function PcbTailCard(props: PcbTailCardProps) {
455
464
 
456
465
  // ---------------------------------------------------------------- 会话观察器(渲染 null)
457
466
  interface PreviewWatcherProps {
467
+ useChat?: UseChat
458
468
  useSession?: UseSession
459
469
  }
460
470
 
461
- function PreviewWatcher({ useSession }: PreviewWatcherProps) {
462
- const nodes = useSession ? useSession((s) => (s && s.nodes) || EMPTY_NODES) : EMPTY_NODES
471
+ function PreviewWatcher({ useChat, useSession }: PreviewWatcherProps) {
472
+ // 对话节点现在由 chat 视图提供(ChatSnapshot.legacy.nodes);旧契约的 session.nodes 保留为回退。
473
+ // 两个 hook 都无条件调用,保证 hook 顺序稳定。
474
+ const chatNodes = useChat ? useChat((s) => (s && s.legacy && s.legacy.nodes) || EMPTY_NODES) : EMPTY_NODES
475
+ const sessionNodes = useSession ? useSession((s) => (s && s.nodes) || EMPTY_NODES) : EMPTY_NODES
476
+ const nodes = chatNodes.length > 0 ? chatNodes : sessionNodes
463
477
  useEffect(() => {
464
478
  const idx = indexPreviews(nodes)
465
479
  previewIndex.byTurn = idx.byTurn