Skip to content

fix(client): read conversation nodes from the chat slot source (dsh >= 0.1.2) - #12

Merged
Max-Samson merged 9 commits into
Max-Samson:mainfrom
rezon-aki:pr/chat-source-nodes
Sep 23, 2026
Merged

Max-Samson merged 9 commits into
Max-Samson:mainfrom
rezon-aki:pr/chat-source-nodes

Conversation

@rezon-aki

Copy link
Copy Markdown
Contributor

Problem

On dsh >= 0.1.2 the per-turn cost badge never renders, the model chip in the dock line disappears, and the observed-round fallback in the panel piles every round onto turn 0.

Root cause

Since dsh 0.1.2 the conversation nodes are published by the chat scoped source, not by the session snapshot. SessionSnapshot has no chat/nodes field; ui-chat registers the source with uiSession.provide({ hooks: ["chat"] }) and slot entries receive it as props.useChat — the same call the built-in StatsPills makes (useChat((s) => s.legacy.nodes)). snapshotNodes() still read session.chat.legacy.nodes, so it returned an empty array and every node-derived value fell through silently.

Fix

  • Add useSessionNodes(useChat, useSession) (src/client/snapshot.ts): prefer chat.legacy.nodes, keep the session-snapshot path as the fallback for older runtimes. Both hooks are called unconditionally in a fixed order so the hook count stays stable across renders.
  • CostBadge and UsageIndicator read nodes through it and accept an optional useChat prop.

3 files, +35/-6, no new dependencies.

Verification

  • npm run typecheck — clean.
  • npm test — 41/41 pass (node 22, dsh 0.1.5-rc.2).
  • Runtime: on dsh 0.1.5-rc.2 the built client bundle serves the new selector (GET /plugins/??dsh-usage-chart/client.js → HTTP 200); with it the per-turn badge, the model chip and the per-turn fallback attribution are restored.

Max-Samson and others added 9 commits September 8, 2026 10:03
fix(host): use session.snapshotEvents() for dsh-session >= 0.1.2-rc.1
…session >= 0.1.2-rc.1)

- fix(host): adapt /usage route to use session.snapshotEvents() for dsh-session >= 0.1.2-rc.1 with fallback to legacy session.events (Max-Samson#7)
- test: add coverage for snapshotEvents() preference and fallback under /usage
- docs: update README and CHANGELOG to 1.1.4
- chore: bump version to 1.1.4 in package.json and package-lock.json
adj: add 4.1 flash and price change 0910
…ly time

ctx.effect(() => fileSource.dispose(), ...) calls dispose while the fiber is
being built and registers undefined as the disposer: the file source is dead
before its first read, so pricing.json is never applied and the change watcher
never fires. Return a disposer instead.

Test mocks now follow cordis semantics (run setup, keep the returned disposer,
release it in after()) and a /pricing route regression test covers the override
path - it fails against the old form.
…= 0.1.2)

The session snapshot no longer carries chat.legacy.nodes: since dsh 0.1.2 the
chat view is a separate scoped source exposed to slot entries as props.useChat.
snapshotNodes() therefore returned an empty array, which silently killed the
per-turn cost badge (messageId -> turn attribution), the model chip in the dock
line and the observed-round fallback.

Add useSessionNodes(useChat, useSession): it prefers the chat source and keeps
the old session.chat path as a fallback for older runtimes. Both hooks are
called unconditionally so the hook order stays stable.
@Max-Samson
Max-Samson self-requested a review September 23, 2026 15:16
@Max-Samson
Max-Samson merged commit da2a1ee into Max-Samson:main Sep 23, 2026
2 checks passed
@Max-Samson

Copy link
Copy Markdown
Owner

Thank you so much for this clean and timely fix!

Adapting to the new chat scoped source (props.useChat) for DSH >= 0.1.2 while maintaining backward compatibility for older runtimes via useSessionNodes is spot-on. The unconditional hook call pattern (NO_CHAT_NODES) is also very thoughtful and ensures strict React Hook stability.

Really appreciate your contribution and attention to detail!

rezon-aki added a commit to rezon-aki/dsh-usage-chart that referenced this pull request Sep 23, 2026
- 上游 v1.1.7 已收录本 fork 早先提的 4 项修复(PR Max-Samson#10/Max-Samson#12/Max-Samson#14/Max-Samson#15)与合并事故修复
  (9753856),fork 不再重复维护它们;README / FORK_NOTES 改为「已并入上游」的口径。
- fork 独有改动只剩「面板可拖动」:panel-position.ts(持久化 + 包含块夹取)+
  UsageIndicator 把手/双击复位 + i18n/styles + tests/panel-position.test.mjs,
  直接取自上游 v1.1.7 基线上的实现(与本地 live 仓库同一份代码)。
- CHANGELOG 中英新增 [1.1.7-dsh.1] 段。
@rezon-aki
rezon-aki deleted the pr/chat-source-nodes branch September 23, 2026 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants