@deepseek-ai/dsh-client-ui-chat 0.2.2-alpha.3 → 0.2.2-rc.2
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/README.i18n.yaml +16 -16
- package/README.md +17 -5
- package/README.zh.md +17 -5
- package/lib/client.js +18 -15587
- package/lib/client.js.map +1 -0
- package/lib/types/chat-settings.d.ts.map +1 -0
- package/lib/types/chat-settings.js.map +1 -0
- package/lib/types/client/apply.d.ts.map +1 -0
- package/lib/types/client/apply.js.map +1 -0
- package/lib/types/client/chat/ApprovalCommand.d.ts +4 -3
- package/lib/types/client/chat/ApprovalCommand.d.ts.map +1 -0
- package/lib/types/client/chat/ApprovalCommand.js.map +1 -0
- package/lib/types/client/chat/AssistantMarkdown.d.ts.map +1 -0
- package/lib/types/client/chat/AssistantMarkdown.js.map +1 -0
- package/lib/types/client/chat/AssistantNodeView.d.ts.map +1 -0
- package/lib/types/client/chat/AssistantNodeView.js.map +1 -0
- package/lib/types/client/chat/ChatFlow.d.ts.map +1 -0
- package/lib/types/client/chat/ChatFlow.js.map +1 -0
- package/lib/types/client/chat/ChatGroupSeat.d.ts.map +1 -0
- package/lib/types/client/chat/ChatGroupSeat.js.map +1 -0
- package/lib/types/client/chat/ChatNodeSeat.d.ts.map +1 -0
- package/lib/types/client/chat/ChatNodeSeat.js.map +1 -0
- package/lib/types/client/chat/ChatView.d.ts +1 -1
- package/lib/types/client/chat/ChatView.d.ts.map +1 -0
- package/lib/types/client/chat/ChatView.js.map +1 -0
- package/lib/types/client/chat/CommandNodeView.d.ts.map +1 -0
- package/lib/types/client/chat/CommandNodeView.js.map +1 -0
- package/lib/types/client/chat/CompactionCommandCard.d.ts.map +1 -0
- package/lib/types/client/chat/CompactionCommandCard.js.map +1 -0
- package/lib/types/client/chat/CompactionItem.d.ts.map +1 -0
- package/lib/types/client/chat/CompactionItem.js.map +1 -0
- package/lib/types/client/chat/ContextBody.d.ts.map +1 -0
- package/lib/types/client/chat/ContextBody.js.map +1 -0
- package/lib/types/client/chat/ContextInjectionRow.d.ts.map +1 -0
- package/lib/types/client/chat/ContextInjectionRow.js.map +1 -0
- package/lib/types/client/chat/GenericCommandCard.d.ts.map +1 -0
- package/lib/types/client/chat/GenericCommandCard.js.map +1 -0
- package/lib/types/client/chat/MessageIconActions.d.ts.map +1 -0
- package/lib/types/client/chat/MessageIconActions.js.map +1 -0
- package/lib/types/client/chat/MessageItem.d.ts.map +1 -0
- package/lib/types/client/chat/MessageItem.js.map +1 -0
- package/lib/types/client/chat/QuotaNoticeHost.d.ts.map +1 -0
- package/lib/types/client/chat/QuotaNoticeHost.js.map +1 -0
- package/lib/types/client/chat/ReasoningContent.d.ts.map +1 -0
- package/lib/types/client/chat/ReasoningContent.js.map +1 -0
- package/lib/types/client/chat/ReasoningRow.d.ts.map +1 -0
- package/lib/types/client/chat/ReasoningRow.js.map +1 -0
- package/lib/types/client/chat/RunningStatus.d.ts.map +1 -0
- package/lib/types/client/chat/RunningStatus.js.map +1 -0
- package/lib/types/client/chat/RunningWhaleTail.d.ts.map +1 -0
- package/lib/types/client/chat/RunningWhaleTail.js.map +1 -0
- package/lib/types/client/chat/StatsPills.d.ts.map +1 -0
- package/lib/types/client/chat/StatsPills.js.map +1 -0
- package/lib/types/client/chat/SystemPromptRow.d.ts.map +1 -0
- package/lib/types/client/chat/SystemPromptRow.js.map +1 -0
- package/lib/types/client/chat/TurnNavigator.d.ts.map +1 -0
- package/lib/types/client/chat/TurnNavigator.js.map +1 -0
- package/lib/types/client/chat/TurnProcessNodeView.d.ts.map +1 -0
- package/lib/types/client/chat/TurnProcessNodeView.js.map +1 -0
- package/lib/types/client/chat/TurnTailNodeView.d.ts.map +1 -0
- package/lib/types/client/chat/TurnTailNodeView.js.map +1 -0
- package/lib/types/client/chat/TurnTriggerNodeView.d.ts.map +1 -0
- package/lib/types/client/chat/TurnTriggerNodeView.js.map +1 -0
- package/lib/types/client/chat/TurnUsagePanel.d.ts.map +1 -0
- package/lib/types/client/chat/TurnUsagePanel.js.map +1 -0
- package/lib/types/client/chat/UserContent.d.ts.map +1 -0
- package/lib/types/client/chat/UserContent.js.map +1 -0
- package/lib/types/client/chat/flow-motion.d.ts +2 -0
- package/lib/types/client/chat/flow-motion.d.ts.map +1 -0
- package/lib/types/client/chat/flow-motion.js.map +1 -0
- package/lib/types/client/chat/message-chrome.d.ts.map +1 -0
- package/lib/types/client/chat/message-chrome.js.map +1 -0
- package/lib/types/client/chat/register-node-renderers.d.ts.map +1 -0
- package/lib/types/client/chat/register-node-renderers.js.map +1 -0
- package/lib/types/client/chat/render-entry.d.ts.map +1 -0
- package/lib/types/client/chat/render-entry.js.map +1 -0
- package/lib/types/client/chat/searchable-hidden.d.ts.map +1 -0
- package/lib/types/client/chat/searchable-hidden.js.map +1 -0
- package/lib/types/client/chat/stat-dialog.d.ts +5 -10
- package/lib/types/client/chat/stat-dialog.d.ts.map +1 -0
- package/lib/types/client/chat/stat-dialog.js.map +1 -0
- package/lib/types/client/chat/step-process.d.ts.map +1 -0
- package/lib/types/client/chat/step-process.js.map +1 -0
- package/lib/types/client/chat/text-interaction.d.ts.map +1 -0
- package/lib/types/client/chat/text-interaction.js.map +1 -0
- package/lib/types/client/chat/text-selection.d.ts.map +1 -0
- package/lib/types/client/chat/text-selection.js.map +1 -0
- package/lib/types/client/chat/token-format.d.ts.map +1 -0
- package/lib/types/client/chat/token-format.js.map +1 -0
- package/lib/types/client/chat/turn-assistant.d.ts.map +1 -0
- package/lib/types/client/chat/turn-assistant.js.map +1 -0
- package/lib/types/client/chat/turn-rail-items.d.ts.map +1 -0
- package/lib/types/client/chat/turn-rail-items.js.map +1 -0
- package/lib/types/client/chat/turn-trigger.d.ts +3 -2
- package/lib/types/client/chat/turn-trigger.d.ts.map +1 -0
- package/lib/types/client/chat/turn-trigger.js.map +1 -0
- package/lib/types/client/chat/use-calendar-day.d.ts.map +1 -0
- package/lib/types/client/chat/use-calendar-day.js.map +1 -0
- package/lib/types/client/chat/use-chat-navigation.d.ts +21 -5
- package/lib/types/client/chat/use-chat-navigation.d.ts.map +1 -0
- package/lib/types/client/chat/use-chat-navigation.js.map +1 -0
- package/lib/types/client/chat/use-chat-reading.d.ts.map +1 -0
- package/lib/types/client/chat/use-chat-reading.js.map +1 -0
- package/lib/types/client/chat/use-chat-scroll.d.ts +5 -2
- package/lib/types/client/chat/use-chat-scroll.d.ts.map +1 -0
- package/lib/types/client/chat/use-chat-scroll.js.map +1 -0
- package/lib/types/client/chat/use-chat-viewport.d.ts +53 -0
- package/lib/types/client/chat/use-chat-viewport.d.ts.map +1 -0
- package/lib/types/client/chat/use-chat-viewport.js.map +1 -0
- package/lib/types/client/chat/use-disclosure.d.ts.map +1 -0
- package/lib/types/client/chat/use-disclosure.js.map +1 -0
- package/lib/types/client/chat/use-process-scroll.d.ts.map +1 -0
- package/lib/types/client/chat/use-process-scroll.js.map +1 -0
- package/lib/types/client/chat/use-scroll-follow.d.ts.map +1 -0
- package/lib/types/client/chat/use-scroll-follow.js.map +1 -0
- package/lib/types/client/chat/use-turn-data.d.ts.map +1 -0
- package/lib/types/client/chat/use-turn-data.js.map +1 -0
- package/lib/types/client/contract/assistant-content.d.ts.map +1 -0
- package/lib/types/client/contract/assistant-content.js.map +1 -0
- package/lib/types/client/contract/chat-nodes.d.ts.map +1 -0
- package/lib/types/client/contract/chat-nodes.js.map +1 -0
- package/lib/types/client/contract/chat-visibility.d.ts +2 -2
- package/lib/types/client/contract/chat-visibility.d.ts.map +1 -0
- package/lib/types/client/contract/chat-visibility.js.map +1 -0
- package/lib/types/client/contract/group-tree.d.ts.map +1 -0
- package/lib/types/client/contract/group-tree.js.map +1 -0
- package/lib/types/client/contract/process-groups.d.ts +6 -3
- package/lib/types/client/contract/process-groups.d.ts.map +1 -0
- package/lib/types/client/contract/process-groups.js.map +1 -0
- package/lib/types/client/contract/slots.d.ts +11 -2
- package/lib/types/client/contract/slots.d.ts.map +1 -0
- package/lib/types/client/contract/slots.js.map +1 -0
- package/lib/types/client/contract/snapshot.d.ts.map +1 -0
- package/lib/types/client/contract/snapshot.js.map +1 -0
- package/lib/types/client/contract/store.d.ts.map +1 -0
- package/lib/types/client/contract/store.js.map +1 -0
- package/lib/types/client/contract/turn-metrics.d.ts.map +1 -0
- package/lib/types/client/contract/turn-metrics.js.map +1 -0
- package/lib/types/client/contract/turn-process.d.ts.map +1 -0
- package/lib/types/client/contract/turn-process.js.map +1 -0
- package/lib/types/client/conversation-nodes/assistant.d.ts.map +1 -0
- package/lib/types/client/conversation-nodes/assistant.js.map +1 -0
- package/lib/types/client/conversation-nodes/chat-snapshot-builder.d.ts.map +1 -0
- package/lib/types/client/conversation-nodes/chat-snapshot-builder.js.map +1 -0
- package/lib/types/client/conversation-nodes/command.d.ts.map +1 -0
- package/lib/types/client/conversation-nodes/command.js.map +1 -0
- package/lib/types/client/conversation-nodes/common.d.ts.map +1 -0
- package/lib/types/client/conversation-nodes/common.js.map +1 -0
- package/lib/types/client/conversation-nodes/compaction.d.ts.map +1 -0
- package/lib/types/client/conversation-nodes/compaction.js.map +1 -0
- package/lib/types/client/conversation-nodes/event-projection.d.ts.map +1 -0
- package/lib/types/client/conversation-nodes/event-projection.js.map +1 -0
- package/lib/types/client/conversation-nodes/fallback.d.ts.map +1 -0
- package/lib/types/client/conversation-nodes/fallback.js.map +1 -0
- package/lib/types/client/conversation-nodes/group-tree-segments.d.ts.map +1 -0
- package/lib/types/client/conversation-nodes/group-tree-segments.js.map +1 -0
- package/lib/types/client/conversation-nodes/inbox.d.ts.map +1 -0
- package/lib/types/client/conversation-nodes/inbox.js.map +1 -0
- package/lib/types/client/conversation-nodes/message.d.ts +1 -1
- package/lib/types/client/conversation-nodes/message.d.ts.map +1 -0
- package/lib/types/client/conversation-nodes/message.js.map +1 -0
- package/lib/types/client/conversation-nodes/process-activity.d.ts +1 -0
- package/lib/types/client/conversation-nodes/process-activity.d.ts.map +1 -0
- package/lib/types/client/conversation-nodes/process-activity.js.map +1 -0
- package/lib/types/client/conversation-nodes/process-groups.d.ts.map +1 -0
- package/lib/types/client/conversation-nodes/process-groups.js.map +1 -0
- package/lib/types/client/conversation-nodes/register.d.ts.map +1 -0
- package/lib/types/client/conversation-nodes/register.js.map +1 -0
- package/lib/types/client/conversation-nodes/request-prompt.d.ts.map +1 -0
- package/lib/types/client/conversation-nodes/request-prompt.js.map +1 -0
- package/lib/types/client/conversation-nodes/retry.d.ts.map +1 -0
- package/lib/types/client/conversation-nodes/retry.js.map +1 -0
- package/lib/types/client/conversation-nodes/tool.d.ts.map +1 -0
- package/lib/types/client/conversation-nodes/tool.js.map +1 -0
- package/lib/types/client/conversation-nodes/turn-error.d.ts.map +1 -0
- package/lib/types/client/conversation-nodes/turn-error.js.map +1 -0
- package/lib/types/client/conversation-nodes/turn-max-tokens.d.ts.map +1 -0
- package/lib/types/client/conversation-nodes/turn-max-tokens.js.map +1 -0
- package/lib/types/client/conversation-nodes/turn-navigation.d.ts.map +1 -0
- package/lib/types/client/conversation-nodes/turn-navigation.js.map +1 -0
- package/lib/types/client/conversation-nodes/turn-process-presentation.d.ts.map +1 -0
- package/lib/types/client/conversation-nodes/turn-process-presentation.js.map +1 -0
- package/lib/types/client/conversation-nodes/turn-process.d.ts.map +1 -0
- package/lib/types/client/conversation-nodes/turn-process.js.map +1 -0
- package/lib/types/client/conversation-nodes/turn-tail.d.ts.map +1 -0
- package/lib/types/client/conversation-nodes/turn-tail.js.map +1 -0
- package/lib/types/client/fence/FenceLayers.d.ts +21 -0
- package/lib/types/client/fence/FenceLayers.d.ts.map +1 -0
- package/lib/types/client/fence/FenceLayers.js.map +1 -0
- package/lib/types/client/fence/register.d.ts +10 -0
- package/lib/types/client/fence/register.d.ts.map +1 -0
- package/lib/types/client/fence/register.js.map +1 -0
- package/lib/types/client/file-path.d.ts.map +1 -0
- package/lib/types/client/file-path.js.map +1 -0
- package/lib/types/client/index.d.ts +1 -1
- package/lib/types/client/index.d.ts.map +1 -0
- package/lib/types/client/index.js.map +1 -0
- package/lib/types/client/locale.d.ts +96 -0
- package/lib/types/client/locale.d.ts.map +1 -0
- package/lib/types/client/locale.js.map +1 -0
- package/lib/types/client/markdown-labels.d.ts.map +1 -0
- package/lib/types/client/markdown-labels.js.map +1 -0
- package/lib/types/client/model/conversation-context.d.ts.map +1 -0
- package/lib/types/client/model/conversation-context.js.map +1 -0
- package/lib/types/client/model/steering-history.d.ts.map +1 -0
- package/lib/types/client/model/steering-history.js.map +1 -0
- package/lib/types/client/model/tool-call-tree.d.ts.map +1 -0
- package/lib/types/client/model/tool-call-tree.js.map +1 -0
- package/lib/types/client/performance-usage.d.ts.map +1 -0
- package/lib/types/client/performance-usage.js.map +1 -0
- package/lib/types/client/presentation-policy.d.ts.map +1 -0
- package/lib/types/client/presentation-policy.js.map +1 -0
- package/lib/types/client/reasoning-text.d.ts.map +1 -0
- package/lib/types/client/reasoning-text.js.map +1 -0
- package/lib/types/client/settings/LinkOpeningRow.d.ts.map +1 -0
- package/lib/types/client/settings/LinkOpeningRow.js.map +1 -0
- package/lib/types/client/settings/PerformanceUsageRow.d.ts.map +1 -0
- package/lib/types/client/settings/PerformanceUsageRow.js.map +1 -0
- package/lib/types/client/settings/PreferenceRow.d.ts.map +1 -0
- package/lib/types/client/settings/PreferenceRow.js.map +1 -0
- package/lib/types/client/settings/TranscriptViewRow.d.ts.map +1 -0
- package/lib/types/client/settings/TranscriptViewRow.js.map +1 -0
- package/lib/types/client/stores.d.ts.map +1 -0
- package/lib/types/client/stores.js.map +1 -0
- package/lib/types/client/transcript-view.d.ts.map +1 -0
- package/lib/types/client/transcript-view.js.map +1 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js.map +1 -0
- package/package.json +47 -44
- package/src/chat-settings.ts +98 -0
- package/src/client/apply.ts +355 -0
- package/src/client/assets/running-whale@2x.png +0 -0
- package/src/client/chat/ApprovalCommand.tsx +42 -0
- package/src/client/chat/AssistantMarkdown.module.css +88 -0
- package/src/client/chat/AssistantMarkdown.tsx +170 -0
- package/src/client/chat/AssistantNodeView.tsx +67 -0
- package/src/client/chat/ChatFlow.tsx +100 -0
- package/src/client/chat/ChatGroupSeat.module.css +166 -0
- package/src/client/chat/ChatGroupSeat.tsx +208 -0
- package/src/client/chat/ChatNodeSeat.tsx +179 -0
- package/src/client/chat/ChatView.module.css +426 -0
- package/src/client/chat/ChatView.tsx +351 -0
- package/src/client/chat/CommandNodeView.tsx +40 -0
- package/src/client/chat/CompactionCommandCard.tsx +26 -0
- package/src/client/chat/CompactionItem.tsx +76 -0
- package/src/client/chat/ContextBody.module.css +161 -0
- package/src/client/chat/ContextBody.tsx +592 -0
- package/src/client/chat/ContextInjectionRow.module.css +68 -0
- package/src/client/chat/ContextInjectionRow.tsx +94 -0
- package/src/client/chat/GenericCommandCard.module.css +49 -0
- package/src/client/chat/GenericCommandCard.tsx +75 -0
- package/src/client/chat/MessageIconActions.module.css +116 -0
- package/src/client/chat/MessageIconActions.tsx +90 -0
- package/src/client/chat/MessageItem.module.css +360 -0
- package/src/client/chat/MessageItem.tsx +410 -0
- package/src/client/chat/QuotaNoticeHost.tsx +27 -0
- package/src/client/chat/ReasoningContent.tsx +26 -0
- package/src/client/chat/ReasoningRow.module.css +77 -0
- package/src/client/chat/ReasoningRow.tsx +112 -0
- package/src/client/chat/RunningStatus.tsx +48 -0
- package/src/client/chat/RunningWhaleTail.tsx +19 -0
- package/src/client/chat/StatsPills.module.css +63 -0
- package/src/client/chat/StatsPills.tsx +348 -0
- package/src/client/chat/SystemPromptRow.tsx +50 -0
- package/src/client/chat/TurnNavigator.module.css +223 -0
- package/src/client/chat/TurnNavigator.tsx +295 -0
- package/src/client/chat/TurnProcessNodeView.module.css +62 -0
- package/src/client/chat/TurnProcessNodeView.tsx +62 -0
- package/src/client/chat/TurnTailNodeView.module.css +12 -0
- package/src/client/chat/TurnTailNodeView.tsx +81 -0
- package/src/client/chat/TurnTriggerNodeView.module.css +50 -0
- package/src/client/chat/TurnTriggerNodeView.tsx +57 -0
- package/src/client/chat/TurnUsagePanel.module.css +79 -0
- package/src/client/chat/TurnUsagePanel.tsx +110 -0
- package/src/client/chat/UserContent.tsx +60 -0
- package/src/client/chat/accessibility.module.css +8 -0
- package/src/client/chat/flow-motion.ts +556 -0
- package/src/client/chat/message-chrome.ts +100 -0
- package/src/client/chat/register-node-renderers.ts +100 -0
- package/src/client/chat/render-entry.ts +16 -0
- package/src/client/chat/searchable-hidden.ts +45 -0
- package/src/client/chat/stat-dialog.module.css +149 -0
- package/src/client/chat/stat-dialog.ts +55 -0
- package/src/client/chat/step-process.ts +28 -0
- package/src/client/chat/text-interaction.ts +298 -0
- package/src/client/chat/text-selection.ts +180 -0
- package/src/client/chat/token-format.ts +98 -0
- package/src/client/chat/turn-assistant.ts +10 -0
- package/src/client/chat/turn-rail-items.ts +89 -0
- package/src/client/chat/turn-trigger.ts +88 -0
- package/src/client/chat/use-calendar-day.ts +25 -0
- package/src/client/chat/use-chat-navigation.ts +309 -0
- package/src/client/chat/use-chat-reading.ts +283 -0
- package/src/client/chat/use-chat-scroll.ts +209 -0
- package/src/client/chat/use-chat-viewport.ts +1130 -0
- package/src/client/chat/use-disclosure.ts +35 -0
- package/src/client/chat/use-process-scroll.ts +88 -0
- package/src/client/chat/use-scroll-follow.ts +182 -0
- package/src/client/chat/use-turn-data.ts +23 -0
- package/src/client/contract/assistant-content.ts +15 -0
- package/src/client/contract/chat-nodes.ts +135 -0
- package/src/client/contract/chat-visibility.ts +20 -0
- package/src/client/contract/group-tree.ts +37 -0
- package/src/client/contract/process-groups.ts +30 -0
- package/src/client/contract/slots.ts +508 -0
- package/src/client/contract/snapshot.ts +171 -0
- package/src/client/contract/store.ts +17 -0
- package/src/client/contract/turn-metrics.ts +43 -0
- package/src/client/contract/turn-process.ts +58 -0
- package/src/client/conversation-nodes/README.i18n.yaml +64 -0
- package/src/client/conversation-nodes/README.md +338 -0
- package/src/client/conversation-nodes/README.zh.md +338 -0
- package/src/client/conversation-nodes/assistant.ts +384 -0
- package/src/client/conversation-nodes/chat-snapshot-builder.ts +1244 -0
- package/src/client/conversation-nodes/command.ts +227 -0
- package/src/client/conversation-nodes/common.ts +83 -0
- package/src/client/conversation-nodes/compaction.ts +65 -0
- package/src/client/conversation-nodes/event-projection.ts +179 -0
- package/src/client/conversation-nodes/fallback.ts +41 -0
- package/src/client/conversation-nodes/group-tree-segments.ts +91 -0
- package/src/client/conversation-nodes/inbox.ts +148 -0
- package/src/client/conversation-nodes/message.ts +182 -0
- package/src/client/conversation-nodes/process-activity.ts +170 -0
- package/src/client/conversation-nodes/process-groups.ts +303 -0
- package/src/client/conversation-nodes/register.ts +38 -0
- package/src/client/conversation-nodes/request-prompt.ts +169 -0
- package/src/client/conversation-nodes/retry.ts +97 -0
- package/src/client/conversation-nodes/tool.ts +371 -0
- package/src/client/conversation-nodes/turn-error.ts +120 -0
- package/src/client/conversation-nodes/turn-max-tokens.ts +82 -0
- package/src/client/conversation-nodes/turn-navigation.ts +97 -0
- package/src/client/conversation-nodes/turn-process-presentation.ts +149 -0
- package/src/client/conversation-nodes/turn-process.ts +374 -0
- package/src/client/conversation-nodes/turn-tail.ts +164 -0
- package/src/client/fence/FenceLayers.tsx +33 -0
- package/src/client/fence/register.ts +22 -0
- package/src/client/file-path.ts +19 -0
- package/src/client/index.ts +69 -0
- package/src/client/locale.ts +1695 -0
- package/src/client/markdown-labels.ts +16 -0
- package/src/client/model/conversation-context.ts +24 -0
- package/src/client/model/steering-history.ts +64 -0
- package/src/client/model/tool-call-tree.ts +204 -0
- package/src/client/performance-usage.ts +34 -0
- package/src/client/presentation-policy.ts +109 -0
- package/src/client/reasoning-text.ts +25 -0
- package/src/client/settings/LinkOpeningRow.tsx +47 -0
- package/src/client/settings/PerformanceUsageRow.tsx +46 -0
- package/src/client/settings/PreferenceRow.module.css +66 -0
- package/src/client/settings/PreferenceRow.tsx +59 -0
- package/src/client/settings/TranscriptViewRow.tsx +93 -0
- package/src/client/stores.ts +62 -0
- package/src/client/transcript-view.ts +81 -0
- package/src/css-modules.d.ts +6 -0
- package/src/index.ts +45 -0
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
/** Follow-tail ownership, saved-position restoration, and sampled reader movement. */
|
|
2
|
+
import { useLayoutEffect, useState } from 'react'
|
|
3
|
+
import type { ChatScrollPosition, ChatViewSlotProps } from '../contract/slots.ts'
|
|
4
|
+
import type { ChatViewport, ViewportLanding, ViewportScroll } from './use-chat-viewport.ts'
|
|
5
|
+
import { useScrollFollow, type ScrollFollow } from './use-scroll-follow.ts'
|
|
6
|
+
|
|
7
|
+
const FOLLOW_THRESHOLD = 24
|
|
8
|
+
const SCROLL_SAMPLE_INTERVAL_MS = 500
|
|
9
|
+
|
|
10
|
+
/** Reading facts that affect Chat chrome and initial rail placement. */
|
|
11
|
+
export interface ChatReadingState {
|
|
12
|
+
readonly initialized: boolean
|
|
13
|
+
readonly followingTail: boolean
|
|
14
|
+
readonly activeTurn: number | null
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Settled reader position delivered to history-navigation policy. */
|
|
18
|
+
export interface ReadingSample {
|
|
19
|
+
readonly position: ChatScrollPosition | null
|
|
20
|
+
readonly movedByReader: boolean
|
|
21
|
+
readonly followingTail: boolean
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type PositionStore = ChatViewSlotProps['chatScroll']
|
|
25
|
+
|
|
26
|
+
/** Owns reading policy and its cancellable sampling work, without DOM access. */
|
|
27
|
+
export class ChatReading {
|
|
28
|
+
private sampleTimer: number | null = null
|
|
29
|
+
private probeFrame: number | null = null
|
|
30
|
+
private sampled: ((sample: ReadingSample) => void) | null = null
|
|
31
|
+
|
|
32
|
+
constructor(
|
|
33
|
+
private readonly viewport: ChatViewport,
|
|
34
|
+
private store: PositionStore,
|
|
35
|
+
private state: ChatReadingState,
|
|
36
|
+
private readonly onChange: (state: ChatReadingState) => void,
|
|
37
|
+
private readonly follow: ScrollFollow,
|
|
38
|
+
) {}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Expose pending reader ownership to navigation and resize handlers.
|
|
42
|
+
* @returns whether reader input still awaits interval or scrollend sampling.
|
|
43
|
+
*/
|
|
44
|
+
get pending(): boolean { return this.sampleTimer !== null }
|
|
45
|
+
/**
|
|
46
|
+
* Expose the active follow policy.
|
|
47
|
+
* @returns whether content growth retains bottom-follow ownership.
|
|
48
|
+
*/
|
|
49
|
+
get followingTail(): boolean { return this.state.followingTail }
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Adopt the committed Session's scroll memory.
|
|
53
|
+
* @param store - scroll memory for the current Session.
|
|
54
|
+
*/
|
|
55
|
+
setStore(store: PositionStore): void { this.store = store }
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Connect history policy to settled reading observations.
|
|
59
|
+
* @param sampled - receives settled reader positions.
|
|
60
|
+
* @returns a disposer that disconnects only this listener.
|
|
61
|
+
*/
|
|
62
|
+
connect(sampled: (sample: ReadingSample) => void): () => void {
|
|
63
|
+
this.sampled = sampled
|
|
64
|
+
return () => { if (this.sampled === sampled) this.sampled = null }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Cancel timers and animation frames and detach the sample listener. */
|
|
68
|
+
dispose(): void {
|
|
69
|
+
this.cancelPending()
|
|
70
|
+
this.sampled = null
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Release bottom follow and pending sampling for an explicit navigation. */
|
|
74
|
+
pauseFollowing(): void {
|
|
75
|
+
this.cancelPending()
|
|
76
|
+
this.publish({ ...this.state, followingTail: false })
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Land at the current floor and clear saved reader position.
|
|
81
|
+
* @param behavior - immediate positioning, or one native animation when the reader's own input moved the tail.
|
|
82
|
+
*/
|
|
83
|
+
followTail(behavior: 'instant' | 'smooth' = 'instant'): void {
|
|
84
|
+
const landing = this.viewport.scrollToBottom(this.follow, behavior)
|
|
85
|
+
if (landing === null) return
|
|
86
|
+
this.cancelPending()
|
|
87
|
+
this.commit(landing, true, this.viewport.latestTurn)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Follow the tail on the active fold's animation clock.
|
|
92
|
+
* @param input - whether the reader's own input requests the landing rather than a content change.
|
|
93
|
+
* @returns whether a fold batch owns the tail movement instead of a separate scroll animation.
|
|
94
|
+
*/
|
|
95
|
+
followInputFold(input: boolean): boolean {
|
|
96
|
+
this.cancelPending()
|
|
97
|
+
return this.viewport.followInputFold(this.follow, input)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Let fold batches read follow intent and commit their tail landings.
|
|
102
|
+
* @returns a disposer that disconnects this reading policy from the viewport.
|
|
103
|
+
*/
|
|
104
|
+
bindFolds(): () => void {
|
|
105
|
+
return this.viewport.bindReader({
|
|
106
|
+
follow: this.follow,
|
|
107
|
+
landedAtTail: (landing) => {
|
|
108
|
+
this.cancelPending()
|
|
109
|
+
this.commit(landing, true, this.viewport.latestTurn)
|
|
110
|
+
},
|
|
111
|
+
pending: () => this.pending,
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Stop a native follow animation where it is; the next sampled position decides follow intent. */
|
|
116
|
+
interruptFollow(): void {
|
|
117
|
+
this.viewport.interruptFollow(this.follow)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Restore the Session's semantic position, or follow the tail when none is saved. */
|
|
121
|
+
restore(): void {
|
|
122
|
+
const saved = this.store.read()
|
|
123
|
+
if (saved === null) { this.followTail(); return }
|
|
124
|
+
const landing = this.viewport.restore(saved)
|
|
125
|
+
if (landing === null) return
|
|
126
|
+
this.cancelPending()
|
|
127
|
+
const following = this.follow.nearBottom(landing.metrics)
|
|
128
|
+
this.commit(landing, following, following ? this.viewport.latestTurn : this.state.activeTurn, following)
|
|
129
|
+
if (!this.state.followingTail && landing.position === null) {
|
|
130
|
+
const position = this.viewport.capturePosition()
|
|
131
|
+
if (position !== null) this.store.save(position)
|
|
132
|
+
}
|
|
133
|
+
this.refreshActiveTurn()
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Adopt a known landing without rediscovering its anchor.
|
|
138
|
+
* @param landing - measured navigation result that replaces pending reader input.
|
|
139
|
+
*/
|
|
140
|
+
acceptNavigation(landing: ViewportLanding): void {
|
|
141
|
+
this.cancelPending()
|
|
142
|
+
const following = this.follow.nearBottom(landing.metrics)
|
|
143
|
+
this.commit(landing, following, landing.turn ?? (following ? this.viewport.latestTurn : this.state.activeTurn))
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Retain reading policy while history changes the anchor's geometry.
|
|
148
|
+
* @param landing - compensated position that retains the current reading policy.
|
|
149
|
+
*/
|
|
150
|
+
preservePosition(landing: ViewportLanding): void {
|
|
151
|
+
this.cancelPending()
|
|
152
|
+
this.commit(landing, this.state.followingTail, this.state.activeTurn)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Handle pinned layout movement and reader arrivals at the floor immediately.
|
|
157
|
+
* @param scroll - attributed scroll delivery; other reader movement remains pending until sampled.
|
|
158
|
+
*/
|
|
159
|
+
readonly onScroll = (scroll: ViewportScroll): void => {
|
|
160
|
+
// Native follow animation progress is not reader movement; scrollend settles it.
|
|
161
|
+
if (this.follow.animating) return
|
|
162
|
+
if ((!scroll.movedByReader && this.state.followingTail)
|
|
163
|
+
|| (scroll.movedByReader && Math.abs(scroll.metrics.top - scroll.metrics.floor) < 1)) {
|
|
164
|
+
this.followTail()
|
|
165
|
+
this.sampled?.({ position: null, movedByReader: scroll.movedByReader, followingTail: true })
|
|
166
|
+
return
|
|
167
|
+
}
|
|
168
|
+
this.sampleTimer ??= window.setTimeout(this.flushSample, SCROLL_SAMPLE_INTERVAL_MS)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Settle pending reader movement; only the outer scroller can finish its native follow animation.
|
|
173
|
+
* @param outer - whether the event belongs to the outer scroller rather than a process body.
|
|
174
|
+
*/
|
|
175
|
+
readonly onScrollEnd = (outer = true): void => {
|
|
176
|
+
if (this.follow.animating) {
|
|
177
|
+
if (!outer) return
|
|
178
|
+
const scroll = this.viewport.readScroll()
|
|
179
|
+
if (scroll === null) return
|
|
180
|
+
if (this.follow.settle(scroll.metrics)) {
|
|
181
|
+
this.followTail()
|
|
182
|
+
return
|
|
183
|
+
}
|
|
184
|
+
this.viewport.acknowledge(scroll.metrics)
|
|
185
|
+
this.publish({ ...this.state, followingTail: false })
|
|
186
|
+
this.refreshActiveTurn()
|
|
187
|
+
return
|
|
188
|
+
}
|
|
189
|
+
this.flushSample()
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Reconcile a layout change without overriding unsampled reader input. */
|
|
193
|
+
onResize(): void {
|
|
194
|
+
if (this.pending) return
|
|
195
|
+
if (this.state.followingTail) this.followTail()
|
|
196
|
+
else this.refreshActiveTurn()
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** Resolve the active turn from tail ownership or a coalesced reading-line probe. */
|
|
200
|
+
refreshActiveTurn(): void {
|
|
201
|
+
if (this.pending) return
|
|
202
|
+
if (this.state.followingTail) {
|
|
203
|
+
this.publish({ ...this.state, initialized: true, activeTurn: this.viewport.latestTurn })
|
|
204
|
+
return
|
|
205
|
+
}
|
|
206
|
+
if (this.probeFrame !== null) return
|
|
207
|
+
if (typeof requestAnimationFrame !== 'function') this.probe()
|
|
208
|
+
else this.probeFrame = requestAnimationFrame(this.probe)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private commit(
|
|
212
|
+
landing: ViewportLanding, followingTail: boolean, activeTurn: number | null, initialized = true,
|
|
213
|
+
): void {
|
|
214
|
+
if (followingTail) this.store.save(null)
|
|
215
|
+
else if (landing.position !== null) this.store.save(landing.position)
|
|
216
|
+
this.publish({ initialized, followingTail, activeTurn })
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
private publish(state: ChatReadingState): void {
|
|
220
|
+
this.follow.setFollowing(state.followingTail)
|
|
221
|
+
if (state.initialized === this.state.initialized && state.followingTail === this.state.followingTail
|
|
222
|
+
&& state.activeTurn === this.state.activeTurn) return
|
|
223
|
+
this.state = state
|
|
224
|
+
this.onChange(state)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private cancelPending(): void {
|
|
228
|
+
if (this.sampleTimer !== null) window.clearTimeout(this.sampleTimer)
|
|
229
|
+
if (this.probeFrame !== null && typeof cancelAnimationFrame === 'function') cancelAnimationFrame(this.probeFrame)
|
|
230
|
+
this.sampleTimer = null
|
|
231
|
+
this.probeFrame = null
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
private readonly probe = (): void => {
|
|
235
|
+
this.probeFrame = null
|
|
236
|
+
if (this.pending) return
|
|
237
|
+
const scroll = this.viewport.readScroll()
|
|
238
|
+
if (scroll === null) return
|
|
239
|
+
const activeTurn = this.follow.nearBottom(scroll.metrics) ? this.viewport.latestTurn : this.viewport.readVisibleTurn(scroll.metrics)
|
|
240
|
+
this.publish({ ...this.state, initialized: true, activeTurn })
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
private readonly flushSample = (): void => {
|
|
244
|
+
if (!this.pending) return
|
|
245
|
+
this.cancelPending()
|
|
246
|
+
const scroll = this.viewport.readScroll()
|
|
247
|
+
if (scroll === null) return
|
|
248
|
+
const followingTail = this.follow.sample(scroll.metrics, scroll.movedByReader)
|
|
249
|
+
let position: ChatScrollPosition | null = null
|
|
250
|
+
if (!scroll.movedByReader && followingTail) this.followTail()
|
|
251
|
+
else {
|
|
252
|
+
position = followingTail ? null : this.viewport.capturePosition()
|
|
253
|
+
this.viewport.acknowledge(scroll.metrics)
|
|
254
|
+
if (followingTail || position !== null) this.store.save(position)
|
|
255
|
+
const activeTurn = this.follow.nearBottom(scroll.metrics) ? this.viewport.latestTurn : this.viewport.readVisibleTurn(scroll.metrics)
|
|
256
|
+
this.publish({ initialized: true, followingTail, activeTurn })
|
|
257
|
+
}
|
|
258
|
+
this.sampled?.({ position, movedByReader: scroll.movedByReader, followingTail })
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Retain reading policy and expose only changes in visible reading state.
|
|
264
|
+
* @param viewport - turn-aware DOM operations.
|
|
265
|
+
* @param store - Session-owned semantic scroll memory.
|
|
266
|
+
* @param initialTurn - latest loaded turn before the first landing.
|
|
267
|
+
* @returns the reading owner and its React-visible state.
|
|
268
|
+
*/
|
|
269
|
+
export function useChatReading(
|
|
270
|
+
viewport: ChatViewport, store: PositionStore, initialTurn: number | null,
|
|
271
|
+
): { reading: ChatReading; state: ChatReadingState } {
|
|
272
|
+
const [state, setState] = useState<ChatReadingState>(() => ({
|
|
273
|
+
initialized: false,
|
|
274
|
+
followingTail: store.read() === null,
|
|
275
|
+
activeTurn: initialTurn,
|
|
276
|
+
}))
|
|
277
|
+
const follow = useScrollFollow(state.followingTail, FOLLOW_THRESHOLD + 1)
|
|
278
|
+
const [reading] = useState(() => new ChatReading(viewport, store, state, setState, follow))
|
|
279
|
+
useLayoutEffect(() => { reading.setStore(store) }, [reading, store])
|
|
280
|
+
useLayoutEffect(() => reading.bindFolds(), [reading])
|
|
281
|
+
useLayoutEffect(() => () => { reading.dispose() }, [reading])
|
|
282
|
+
return { reading, state }
|
|
283
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/** Composes viewport operations, reading policy, and history navigation for Chat. */
|
|
2
|
+
import { useCallback, useLayoutEffect, useMemo, useRef, useState, type RefObject } from 'react'
|
|
3
|
+
import type { TranscriptViewMode } from '../../chat-settings.ts'
|
|
4
|
+
import type { ChatSnapshot } from '../contract/snapshot.ts'
|
|
5
|
+
import type { ChatViewSlotProps } from '../contract/slots.ts'
|
|
6
|
+
import { useChatNavigation, type ChatNavigation, type ChatNavigationInput } from './use-chat-navigation.ts'
|
|
7
|
+
import { useChatReading, type ChatReadingState } from './use-chat-reading.ts'
|
|
8
|
+
import { useChatViewport } from './use-chat-viewport.ts'
|
|
9
|
+
import type { FlowMotionRows } from './flow-motion.ts'
|
|
10
|
+
|
|
11
|
+
/** Committed content and Session operations used to reconcile scroll ownership. */
|
|
12
|
+
export interface ChatScrollInput extends ChatNavigationInput {
|
|
13
|
+
readonly chatScroll: ChatViewSlotProps['chatScroll']
|
|
14
|
+
readonly order: readonly string[]
|
|
15
|
+
readonly lastKey: string | null
|
|
16
|
+
readonly lastIsUser: boolean
|
|
17
|
+
readonly steeringId: string | null
|
|
18
|
+
readonly submissionId: string | null
|
|
19
|
+
/** The latest visible submission steers the running Turn instead of opening a new one. */
|
|
20
|
+
readonly submissionSteers: boolean
|
|
21
|
+
readonly running: boolean
|
|
22
|
+
/** Enable the browser-local delayed-fold experiment and its input reveal animation. */
|
|
23
|
+
readonly deferCompletedTurns: boolean
|
|
24
|
+
/** A changed work-details preference resets fold reservations after the layout settles. */
|
|
25
|
+
readonly transcriptView: TranscriptViewMode
|
|
26
|
+
readonly loadedTurns: ReturnType<ChatSnapshot['navigation']['items']>
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface ChatScrollState extends ChatReadingState {
|
|
30
|
+
readonly listRef: RefObject<HTMLDivElement>
|
|
31
|
+
readonly columnRef: RefObject<HTMLDivElement>
|
|
32
|
+
readonly busyTurn: number | null
|
|
33
|
+
readonly navigateToTurn: ChatNavigation['navigateToTurn']
|
|
34
|
+
readonly loadEarlier: ChatNavigation['loadEarlier']
|
|
35
|
+
readonly historyInputHeld: boolean
|
|
36
|
+
readonly historyProcessing: boolean
|
|
37
|
+
readonly historyPending: boolean
|
|
38
|
+
readonly historyEdgeRef: (element: HTMLDivElement | null) => void
|
|
39
|
+
readonly returnToBottom: () => void
|
|
40
|
+
readonly motion: FlowMotionRows
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Coordinate scroll policy after Chat content commits. Initial history must be available
|
|
45
|
+
* before automatic scroll or resize handling can initialize reading state and fold motion.
|
|
46
|
+
* New submitted input supersedes pending reader sampling.
|
|
47
|
+
* @param input - current Chat content, scroll memory, and history operations.
|
|
48
|
+
* @returns element refs, visible reading state, and navigation callbacks.
|
|
49
|
+
*/
|
|
50
|
+
export function useChatScroll(input: ChatScrollInput): ChatScrollState {
|
|
51
|
+
const {
|
|
52
|
+
isOpen, order, firstSeq, lastKey, lastIsUser, steeringId, submissionId, submissionSteers, running,
|
|
53
|
+
deferCompletedTurns, loadedTurns, chatScroll, hasMore, loadingOlder, historyLoadStatus,
|
|
54
|
+
loadOlder, consumeOlder, loadThrough, transcriptView,
|
|
55
|
+
} = input
|
|
56
|
+
const { viewport, listRef, columnRef } = useChatViewport()
|
|
57
|
+
const [historyInputHeld, setHistoryInputHeld] = useState(false)
|
|
58
|
+
const { reading, state } = useChatReading(viewport, chatScroll, loadedTurns.at(-1)?.turn ?? null)
|
|
59
|
+
const navigationInput = useMemo(() => ({
|
|
60
|
+
firstSeq, loadingOlder, hasMore, historyLoadStatus, isOpen, loadOlder, consumeOlder, loadThrough,
|
|
61
|
+
}), [firstSeq, loadingOlder, hasMore, historyLoadStatus, isOpen, loadOlder, consumeOlder, loadThrough])
|
|
62
|
+
const { navigation, busyTurn, historyPending, historyProcessing } = useChatNavigation(viewport, reading, navigationInput)
|
|
63
|
+
const content = useRef<{ input: ChatScrollInput; applied: ChatScrollInput | null; opened: boolean }>({
|
|
64
|
+
input, applied: null, opened: false,
|
|
65
|
+
})
|
|
66
|
+
// A fold batch owns layout and scrolling until it lands: at the tail for own input or a following
|
|
67
|
+
// reader, otherwise with the reader's content still. Growth consumes any room the landing installed.
|
|
68
|
+
const cancelPendingFollow = useCallback(() => { viewport.motion.cancelInput() }, [viewport])
|
|
69
|
+
|
|
70
|
+
const processContent = useCallback(() => {
|
|
71
|
+
const current = content.current.input
|
|
72
|
+
if (!current.isOpen && !content.current.opened) return
|
|
73
|
+
const previous = content.current.applied
|
|
74
|
+
const steeringInput = current.steeringId !== null && current.steeringId !== previous?.steeringId
|
|
75
|
+
&& current.steeringId !== previous?.submissionId
|
|
76
|
+
const submissionInput = current.submissionId !== null && current.submissionId !== previous?.submissionId
|
|
77
|
+
&& current.submissionId !== previous?.steeringId
|
|
78
|
+
const ownInput = (current.lastIsUser && current.lastKey !== previous?.lastKey) || steeringInput || submissionInput
|
|
79
|
+
if (reading.pending && !ownInput) return
|
|
80
|
+
content.current.applied = current
|
|
81
|
+
if (current.isOpen && !content.current.opened) {
|
|
82
|
+
content.current.opened = true
|
|
83
|
+
navigation.reset()
|
|
84
|
+
reading.restore()
|
|
85
|
+
return
|
|
86
|
+
}
|
|
87
|
+
if (ownInput) {
|
|
88
|
+
navigation.cancel()
|
|
89
|
+
if (current.deferCompletedTurns && reading.followInputFold(true)) return
|
|
90
|
+
// Steering lands at once: the running Turn keeps streaming above its echo, and that growth would push
|
|
91
|
+
// the echo down under a native animation.
|
|
92
|
+
const steering = steeringInput || (submissionInput && current.submissionSteers)
|
|
93
|
+
reading.followTail(current.deferCompletedTurns && !steering ? 'smooth' : 'instant')
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
if (navigation.contentCommitted()) {
|
|
97
|
+
navigation.reconcile()
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
const tipChanged = previous === null || current.isOpen !== previous.isOpen
|
|
101
|
+
|| current.firstSeq !== previous.firstSeq || current.lastKey !== previous.lastKey
|
|
102
|
+
|| current.order.length !== previous.order.length || current.running !== previous.running
|
|
103
|
+
|| current.steeringId !== previous.steeringId || current.submissionId !== previous.submissionId
|
|
104
|
+
if (tipChanged && reading.followingTail) {
|
|
105
|
+
navigation.cancel()
|
|
106
|
+
if (current.deferCompletedTurns && reading.followInputFold(false)) return
|
|
107
|
+
reading.followTail()
|
|
108
|
+
} else navigation.reconcile()
|
|
109
|
+
}, [reading, navigation])
|
|
110
|
+
|
|
111
|
+
useLayoutEffect(() => {
|
|
112
|
+
const disconnectViewport = viewport.connect({
|
|
113
|
+
scroll: (event) => {
|
|
114
|
+
if (!content.current.opened) return
|
|
115
|
+
if (!event.movedByReader && viewport.motion.foldActive()) return
|
|
116
|
+
reading.onScroll(event)
|
|
117
|
+
},
|
|
118
|
+
scrollEnd: (outer) => {
|
|
119
|
+
reading.onScrollEnd(outer)
|
|
120
|
+
navigation.requestHistoryCheck()
|
|
121
|
+
},
|
|
122
|
+
interact: () => { navigation.readerInteracted() },
|
|
123
|
+
history: () => {
|
|
124
|
+
setHistoryInputHeld(viewport.historyInputHeld)
|
|
125
|
+
if (content.current.opened) navigation.requestHistoryCheck()
|
|
126
|
+
},
|
|
127
|
+
intent: () => { cancelPendingFollow(); reading.interruptFollow() },
|
|
128
|
+
resize: () => {
|
|
129
|
+
if (!content.current.opened) return
|
|
130
|
+
navigation.requestHistoryCheck()
|
|
131
|
+
if (navigation.contentCommitted()) {
|
|
132
|
+
navigation.reconcile()
|
|
133
|
+
return
|
|
134
|
+
}
|
|
135
|
+
if (!content.current.input.deferCompletedTurns || !viewport.motion.foldActive()) reading.onResize()
|
|
136
|
+
navigation.reconcile()
|
|
137
|
+
},
|
|
138
|
+
})
|
|
139
|
+
const disconnectReading = reading.connect((sample) => {
|
|
140
|
+
navigation.readerSampled(sample)
|
|
141
|
+
processContent()
|
|
142
|
+
navigation.requestHistoryCheck()
|
|
143
|
+
})
|
|
144
|
+
return () => {
|
|
145
|
+
disconnectViewport()
|
|
146
|
+
disconnectReading()
|
|
147
|
+
content.current.opened = false
|
|
148
|
+
content.current.applied = null
|
|
149
|
+
}
|
|
150
|
+
}, [viewport, reading, navigation, processContent, cancelPendingFollow])
|
|
151
|
+
|
|
152
|
+
useLayoutEffect(() => {
|
|
153
|
+
const previous = content.current.input
|
|
154
|
+
content.current.input = {
|
|
155
|
+
order, lastKey, lastIsUser, steeringId, submissionId, submissionSteers, running, loadedTurns,
|
|
156
|
+
chatScroll, deferCompletedTurns, transcriptView, ...navigationInput,
|
|
157
|
+
}
|
|
158
|
+
if (!deferCompletedTurns) {
|
|
159
|
+
cancelPendingFollow()
|
|
160
|
+
reading.interruptFollow()
|
|
161
|
+
}
|
|
162
|
+
viewport.updateTurns(loadedTurns)
|
|
163
|
+
const layoutChanged = previous.order !== order || previous.isOpen !== isOpen
|
|
164
|
+
const historyConsumed = previous.historyLoadStatus === 'pendingConsumption' && historyLoadStatus === 'idle'
|
|
165
|
+
if (!isOpen || historyLoadStatus === 'error') viewport.cancelHistoryPrepend()
|
|
166
|
+
else if (layoutChanged || historyConsumed) {
|
|
167
|
+
const landing = viewport.finishHistoryPrepend()
|
|
168
|
+
if (landing !== null) reading.preservePosition(landing)
|
|
169
|
+
}
|
|
170
|
+
if (layoutChanged) viewport.invalidate()
|
|
171
|
+
viewport.reclaimBelow()
|
|
172
|
+
processContent()
|
|
173
|
+
if (layoutChanged && content.current.opened) reading.refreshActiveTurn()
|
|
174
|
+
if (content.current.opened) navigation.requestHistoryCheck()
|
|
175
|
+
}, [
|
|
176
|
+
viewport, reading, processContent, navigationInput, isOpen, order, lastKey, lastIsUser,
|
|
177
|
+
steeringId, submissionId, submissionSteers, running, loadedTurns, chatScroll, deferCompletedTurns, transcriptView,
|
|
178
|
+
cancelPendingFollow,
|
|
179
|
+
])
|
|
180
|
+
|
|
181
|
+
const previousView = useRef(transcriptView)
|
|
182
|
+
useLayoutEffect(() => {
|
|
183
|
+
if (previousView.current === transcriptView) return
|
|
184
|
+
previousView.current = transcriptView
|
|
185
|
+
cancelPendingFollow()
|
|
186
|
+
reading.interruptFollow()
|
|
187
|
+
return viewport.motion.onFoldIdle(() => {
|
|
188
|
+
viewport.resetBelow()
|
|
189
|
+
if (content.current.opened) reading.onResize()
|
|
190
|
+
})
|
|
191
|
+
}, [transcriptView, viewport, reading, cancelPendingFollow])
|
|
192
|
+
|
|
193
|
+
const returnToBottom = useCallback(() => {
|
|
194
|
+
cancelPendingFollow()
|
|
195
|
+
navigation.cancel()
|
|
196
|
+
reading.followTail()
|
|
197
|
+
}, [navigation, reading, cancelPendingFollow])
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
listRef, columnRef, ...state, busyTurn, motion: viewport.motion,
|
|
201
|
+
navigateToTurn: navigation.navigateToTurn,
|
|
202
|
+
loadEarlier: navigation.loadEarlier,
|
|
203
|
+
historyPending,
|
|
204
|
+
historyProcessing,
|
|
205
|
+
historyInputHeld,
|
|
206
|
+
historyEdgeRef: viewport.setHistoryEdge,
|
|
207
|
+
returnToBottom,
|
|
208
|
+
}
|
|
209
|
+
}
|