@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,371 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
2
|
+
import type {
|
|
3
|
+
ConversationMatch, ConversationNodeContext, ConversationNodeDefinition, PreparingToolCall, StartedToolCall,
|
|
4
|
+
ToolCallBlock, ToolResultNode,
|
|
5
|
+
} from '@deepseek-ai/dsh-client-ui-conversation/client'
|
|
6
|
+
import { isAppendSurfaceEvent } from '@deepseek-ai/dsh-session/surface'
|
|
7
|
+
import type {} from '@deepseek-ai/dsh-tool-executor-ptc/client'
|
|
8
|
+
import { PartialArguments } from '@deepseek-ai/dsh-util-values'
|
|
9
|
+
import type { ChatNode, ToolChatData } from '../contract/chat-nodes.ts'
|
|
10
|
+
import { CHAT_SYNTHETIC_SEQ_OFFSETS, chatNode, contextLocation } from './common.ts'
|
|
11
|
+
|
|
12
|
+
declare module '../contract/chat-nodes.ts' {
|
|
13
|
+
interface ChatNodeDataMap {
|
|
14
|
+
/** Root Tool lifecycle with recursively nested subcalls. */
|
|
15
|
+
'tool-call': ToolChatData
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const MAX_DEPTH = 256
|
|
20
|
+
|
|
21
|
+
interface ToolState {
|
|
22
|
+
/** Absent until a named delta or `tool/call` identifies the call. */
|
|
23
|
+
readonly root: ToolCallBlock | undefined
|
|
24
|
+
readonly children: ReadonlyMap<string, readonly ToolCallBlock[]>
|
|
25
|
+
readonly parents: ReadonlyMap<string, string>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface ProjectedBlockCache {
|
|
29
|
+
readonly children: readonly ToolCallBlock[]
|
|
30
|
+
readonly interruptionSeq: number | undefined
|
|
31
|
+
readonly interruptionTime: number | undefined
|
|
32
|
+
readonly value: ToolCallBlock
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const projectedBlocks = new WeakMap<ToolCallBlock, ProjectedBlockCache>()
|
|
36
|
+
|
|
37
|
+
function jsonArguments(value: unknown): string {
|
|
38
|
+
return JSON.stringify(value)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function rootCall(match: ConversationMatch, previous?: ToolCallBlock): StartedToolCall {
|
|
42
|
+
if (match.event.type !== 'tool/call') throw new Error('tool-call start requires tool/call')
|
|
43
|
+
return {
|
|
44
|
+
phase: 'start',
|
|
45
|
+
callId: String(match.event.data.callId),
|
|
46
|
+
name: match.event.data.name,
|
|
47
|
+
argsRaw: match.event.data.arguments,
|
|
48
|
+
args: previous === undefined
|
|
49
|
+
? PartialArguments.fromText(match.event.data.arguments)
|
|
50
|
+
: previous.args.settle(match.event.data.arguments),
|
|
51
|
+
turn: match.event.data.turn,
|
|
52
|
+
step: match.event.data.step,
|
|
53
|
+
time: match.event.time,
|
|
54
|
+
subCalls: [],
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Retain argument fragments in the named call's lazy view. Root replacement
|
|
60
|
+
* belongs to publication, after all pending fragments can be observed together.
|
|
61
|
+
*/
|
|
62
|
+
function applyDelta(state: ToolState, match: ConversationMatch): ToolState {
|
|
63
|
+
const event = match.event
|
|
64
|
+
if (event.type !== 'assistant/live-chunk') return state
|
|
65
|
+
const chunk = event.data.chunk
|
|
66
|
+
const root = state.root
|
|
67
|
+
if (chunk.type === 'block-end' && chunk.block.type === 'tool-call') {
|
|
68
|
+
if (root === undefined || 'kind' in root || root.phase !== 'preparing') return state
|
|
69
|
+
return { ...state, root: { ...root, name: chunk.block.name, args: root.args.settle(chunk.block.arguments) } }
|
|
70
|
+
}
|
|
71
|
+
if (chunk.type !== 'tool-call-delta') return state
|
|
72
|
+
if (root === undefined) {
|
|
73
|
+
// An unnamed delta before the name is skipped; a view opened late sees a non-object prefix and reports nothing.
|
|
74
|
+
if (!chunk.name) return state
|
|
75
|
+
const args = new PartialArguments()
|
|
76
|
+
args.append(chunk.argumentsDelta)
|
|
77
|
+
return {
|
|
78
|
+
...state,
|
|
79
|
+
root: {
|
|
80
|
+
phase: 'preparing',
|
|
81
|
+
callId: String(chunk.id), name: chunk.name,
|
|
82
|
+
turn: event.data.turn, step: event.data.step, time: event.time,
|
|
83
|
+
subCalls: [],
|
|
84
|
+
args,
|
|
85
|
+
},
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if ('kind' in root || root.phase !== 'preparing' || root.args.isSealed) return state
|
|
89
|
+
root.args.append(chunk.argumentsDelta)
|
|
90
|
+
return state
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function preparingBlock(root: PreparingToolCall, current: ToolCallBlock | undefined): PreparingToolCall {
|
|
94
|
+
const changed = root.args.refresh()
|
|
95
|
+
if (!changed && current !== undefined && !('kind' in current)
|
|
96
|
+
&& current.phase === 'preparing' && current.name === root.name && current.args === root.args) return current
|
|
97
|
+
return changed ? { ...root } : root
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function rootResult(match: ConversationMatch, previous?: StartedToolCall): ToolResultNode | undefined {
|
|
101
|
+
if (match.event.type !== 'tool/result') return undefined
|
|
102
|
+
const message = match.event.data.message
|
|
103
|
+
return {
|
|
104
|
+
kind: 'tool-result',
|
|
105
|
+
seq: match.event.seq,
|
|
106
|
+
time: match.event.time,
|
|
107
|
+
callId: String(message.source.callId),
|
|
108
|
+
name: previous?.name ?? '',
|
|
109
|
+
args: previous?.args ?? PartialArguments.EMPTY,
|
|
110
|
+
call: previous === undefined ? null : { name: previous.name, argsRaw: previous.argsRaw },
|
|
111
|
+
callTime: previous?.time ?? null,
|
|
112
|
+
content: message.content,
|
|
113
|
+
isError: message.isError === true,
|
|
114
|
+
...match.event.data.error === undefined ? {} : { error: match.event.data.error },
|
|
115
|
+
meta: match.event.data.meta,
|
|
116
|
+
subCalls: [],
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
interface DispatchData {
|
|
121
|
+
readonly parentCallId: string
|
|
122
|
+
readonly subCallId: string
|
|
123
|
+
readonly name: string
|
|
124
|
+
readonly arguments: unknown
|
|
125
|
+
readonly isError?: boolean
|
|
126
|
+
readonly error?: { name: string; code: string; reason?: string }
|
|
127
|
+
readonly content?: ToolResultNode['content']
|
|
128
|
+
readonly meta?: ToolResultNode['meta']
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function childCall(match: ConversationMatch, data: DispatchData): StartedToolCall {
|
|
132
|
+
return {
|
|
133
|
+
phase: 'start',
|
|
134
|
+
callId: data.subCallId,
|
|
135
|
+
parentCallId: data.parentCallId,
|
|
136
|
+
name: data.name,
|
|
137
|
+
argsRaw: jsonArguments(data.arguments),
|
|
138
|
+
args: PartialArguments.fromObject(data.arguments),
|
|
139
|
+
turn: locationTurn(match),
|
|
140
|
+
step: locationStep(match),
|
|
141
|
+
time: match.event.time,
|
|
142
|
+
subCalls: [],
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function childResult(match: ConversationMatch, data: DispatchData, previous?: ToolCallBlock): ToolResultNode {
|
|
147
|
+
return {
|
|
148
|
+
kind: 'tool-result',
|
|
149
|
+
seq: match.event.seq,
|
|
150
|
+
time: match.event.time,
|
|
151
|
+
callId: data.subCallId,
|
|
152
|
+
parentCallId: data.parentCallId,
|
|
153
|
+
name: data.name,
|
|
154
|
+
args: previous !== undefined && !('kind' in previous) ? previous.args : PartialArguments.fromObject(data.arguments),
|
|
155
|
+
call: { name: data.name, argsRaw: jsonArguments(data.arguments) },
|
|
156
|
+
callTime: previous?.time ?? null,
|
|
157
|
+
content: data.content ?? [],
|
|
158
|
+
meta: data.meta,
|
|
159
|
+
isError: data.isError === true,
|
|
160
|
+
...data.error === undefined ? {} : { error: data.error },
|
|
161
|
+
subCalls: [],
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function locationTurn(match: ConversationMatch): number {
|
|
166
|
+
return match.location.kind === 'step' || match.location.kind === 'turn' ? match.location.turn.turn : 0
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function locationStep(match: ConversationMatch): number {
|
|
170
|
+
return match.location.kind === 'step' ? match.location.step.step : 0
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function acceptsEdge(state: ToolState, parent: string, child: string): boolean {
|
|
174
|
+
if (parent === child || state.parents.has(child)) return false
|
|
175
|
+
let cursor: string | undefined = parent
|
|
176
|
+
let parentDepth = 0
|
|
177
|
+
const ancestors = new Set<string>()
|
|
178
|
+
while (cursor !== undefined) {
|
|
179
|
+
if (cursor === child || ancestors.has(cursor)) return false
|
|
180
|
+
ancestors.add(cursor)
|
|
181
|
+
parentDepth++
|
|
182
|
+
cursor = state.parents.get(cursor)
|
|
183
|
+
}
|
|
184
|
+
const pending = [{ callId: child, depth: 1 }]
|
|
185
|
+
const descendants = new Set<string>()
|
|
186
|
+
let subtreeDepth = 0
|
|
187
|
+
for (const candidate of pending) {
|
|
188
|
+
if (descendants.has(candidate.callId)) return false
|
|
189
|
+
descendants.add(candidate.callId)
|
|
190
|
+
subtreeDepth = Math.max(subtreeDepth, candidate.depth)
|
|
191
|
+
for (const nested of state.children.get(candidate.callId) ?? []) {
|
|
192
|
+
pending.push({ callId: nested.callId, depth: candidate.depth + 1 })
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return parentDepth + subtreeDepth <= MAX_DEPTH
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function updateDispatch(state: ToolState, match: ConversationMatch): ToolState {
|
|
199
|
+
const event = match.event
|
|
200
|
+
if (event.type !== 'tool/ptc-dispatch-start' && event.type !== 'tool/ptc-dispatch') return state
|
|
201
|
+
const data = event.data
|
|
202
|
+
const parentCallId = String(data.parentCallId)
|
|
203
|
+
const subCallId = String(data.subCallId)
|
|
204
|
+
const siblings = state.children.get(parentCallId) ?? []
|
|
205
|
+
const index = siblings.findIndex(candidate => candidate.callId === subCallId)
|
|
206
|
+
if (event.type === 'tool/ptc-dispatch-start') {
|
|
207
|
+
if (index >= 0 || !acceptsEdge(state, parentCallId, subCallId)) return state
|
|
208
|
+
const children = new Map(state.children)
|
|
209
|
+
children.set(parentCallId, [...siblings, childCall(match, data)])
|
|
210
|
+
const parents = new Map(state.parents)
|
|
211
|
+
parents.set(subCallId, parentCallId)
|
|
212
|
+
return { ...state, children, parents }
|
|
213
|
+
}
|
|
214
|
+
if (index < 0 && !acceptsEdge(state, parentCallId, subCallId)) return state
|
|
215
|
+
const previous = index < 0 ? undefined : siblings[index]
|
|
216
|
+
const settled = childResult(match, data, previous)
|
|
217
|
+
const children = new Map(state.children)
|
|
218
|
+
children.set(parentCallId, index < 0
|
|
219
|
+
? [...siblings, settled]
|
|
220
|
+
: siblings.map((child, at) => at === index ? settled : child))
|
|
221
|
+
const parents = new Map(state.parents)
|
|
222
|
+
if (index < 0) parents.set(subCallId, parentCallId)
|
|
223
|
+
return { ...state, children, parents }
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function projectBlock(
|
|
227
|
+
block: ToolCallBlock,
|
|
228
|
+
state: ToolState,
|
|
229
|
+
interruptedAt: { seq: number; time: number } | undefined,
|
|
230
|
+
visited = new Set<string>(),
|
|
231
|
+
depth = 1,
|
|
232
|
+
): ToolCallBlock {
|
|
233
|
+
if (!('kind' in block) && block.phase === 'preparing') return block
|
|
234
|
+
if (visited.has(block.callId) || depth > MAX_DEPTH) return { ...block, subCalls: [] }
|
|
235
|
+
const nextVisited = new Set(visited)
|
|
236
|
+
nextVisited.add(block.callId)
|
|
237
|
+
const children = (state.children.get(block.callId) ?? block.subCalls)
|
|
238
|
+
.map(child => projectBlock(child, state, interruptedAt, nextVisited, depth + 1))
|
|
239
|
+
const interruptionSeq = 'kind' in block ? undefined : interruptedAt?.seq
|
|
240
|
+
const interruptionTime = 'kind' in block ? undefined : interruptedAt?.time
|
|
241
|
+
const cached = projectedBlocks.get(block)
|
|
242
|
+
if (cached !== undefined
|
|
243
|
+
&& cached.interruptionSeq === interruptionSeq
|
|
244
|
+
&& cached.interruptionTime === interruptionTime
|
|
245
|
+
&& sameReferences(cached.children, children)) {
|
|
246
|
+
return cached.value
|
|
247
|
+
}
|
|
248
|
+
const projected: ToolCallBlock = 'kind' in block || interruptedAt === undefined
|
|
249
|
+
? sameReferences(block.subCalls, children) ? block : { ...block, subCalls: children }
|
|
250
|
+
: {
|
|
251
|
+
kind: 'tool-result',
|
|
252
|
+
seq: interruptedAt.seq + CHAT_SYNTHETIC_SEQ_OFFSETS.interruptedFollowup,
|
|
253
|
+
time: interruptedAt.time,
|
|
254
|
+
callId: block.callId,
|
|
255
|
+
...block.parentCallId === undefined ? {} : { parentCallId: block.parentCallId },
|
|
256
|
+
name: block.name,
|
|
257
|
+
args: block.args,
|
|
258
|
+
call: { name: block.name, argsRaw: block.argsRaw },
|
|
259
|
+
callTime: block.time,
|
|
260
|
+
content: [],
|
|
261
|
+
isError: true,
|
|
262
|
+
error: { name: 'Interrupted', code: 'interrupted' },
|
|
263
|
+
subCalls: children,
|
|
264
|
+
}
|
|
265
|
+
projectedBlocks.set(block, { children, interruptionSeq, interruptionTime, value: projected })
|
|
266
|
+
return projected
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function sameReferences<T>(left: readonly T[], right: readonly T[]): boolean {
|
|
270
|
+
return left.length === right.length && left.every((value, index) => value === right[index])
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function interruption(context: ConversationNodeContext<ToolState>): { seq: number; time: number } | undefined {
|
|
274
|
+
const location = context.start?.location
|
|
275
|
+
if (location?.kind === 'step' && location.step.status === 'closed') return location.step.end
|
|
276
|
+
if ((location?.kind === 'step' || location?.kind === 'turn') && location.turn.status === 'closed') {
|
|
277
|
+
return location.turn.end
|
|
278
|
+
}
|
|
279
|
+
return undefined
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function fallbackState(context: ConversationNodeContext<ToolState>): ToolState | undefined {
|
|
283
|
+
const match = context.matches.find(candidate => candidate.event.type === 'tool/result')
|
|
284
|
+
const root = match === undefined ? undefined : rootResult(match)
|
|
285
|
+
if (root === undefined) return undefined
|
|
286
|
+
let state: ToolState = { root, children: new Map(), parents: new Map() }
|
|
287
|
+
for (const candidate of context.matches) state = updateDispatch(state, candidate)
|
|
288
|
+
return state
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** Root Tool preparation, dispatch, result, and nested PTC calls. */
|
|
292
|
+
export const toolDefinition: ConversationNodeDefinition<ToolState> = {
|
|
293
|
+
kind: 'tool-call',
|
|
294
|
+
target: 'chat',
|
|
295
|
+
match: (event) => {
|
|
296
|
+
if (event.type === 'assistant/live-chunk') {
|
|
297
|
+
// Every delta of a call is a start candidate: the earliest opens the Context, later ones fold as updates.
|
|
298
|
+
const chunk = event.data.chunk
|
|
299
|
+
if (chunk.type === 'block-end' && chunk.block.type === 'tool-call') {
|
|
300
|
+
return { id: String(chunk.block.id), role: 'start' }
|
|
301
|
+
}
|
|
302
|
+
return chunk.type === 'tool-call-delta' ? { id: String(chunk.id), role: 'start' } : null
|
|
303
|
+
}
|
|
304
|
+
if (event.type === 'tool/call') return { id: String(event.data.callId), role: 'start' }
|
|
305
|
+
if (event.type === 'tool/result' && isAppendSurfaceEvent(event)) {
|
|
306
|
+
return { id: String(event.data.message.source.callId), role: 'update' }
|
|
307
|
+
}
|
|
308
|
+
if (event.type === 'tool/ptc-dispatch-start' || event.type === 'tool/ptc-dispatch') {
|
|
309
|
+
const rootCallId: unknown = event.data.rootCallId
|
|
310
|
+
return typeof rootCallId === 'string' && rootCallId !== ''
|
|
311
|
+
? { id: rootCallId, role: 'update' }
|
|
312
|
+
: null
|
|
313
|
+
}
|
|
314
|
+
return null
|
|
315
|
+
},
|
|
316
|
+
start: (_context, match) => {
|
|
317
|
+
const state: ToolState = { root: undefined, children: new Map(), parents: new Map() }
|
|
318
|
+
return match.event.type === 'tool/call' ? { ...state, root: rootCall(match) } : applyDelta(state, match)
|
|
319
|
+
},
|
|
320
|
+
update: (context, match) => {
|
|
321
|
+
if (match.event.type === 'assistant/live-chunk') return applyDelta(context.state, match)
|
|
322
|
+
if (match.event.type === 'tool/call') return { ...context.state, root: rootCall(match, context.state.root) }
|
|
323
|
+
if (match.event.type === 'tool/result') {
|
|
324
|
+
const root = context.state.root
|
|
325
|
+
const running = root !== undefined && !('kind' in root) && root.phase === 'start' ? root : undefined
|
|
326
|
+
const result = rootResult(match, running)
|
|
327
|
+
return result === undefined ? context.state : { ...context.state, root: result }
|
|
328
|
+
}
|
|
329
|
+
return updateDispatch(context.state, match)
|
|
330
|
+
},
|
|
331
|
+
publication: match => match.event.type === 'assistant/live-chunk' ? 'animation-frame' : 'immediate',
|
|
332
|
+
buildViewNode: (context) => {
|
|
333
|
+
const current = context.current.get('chat') as ChatNode<'tool-call'> | null | undefined
|
|
334
|
+
const state = context.state ?? fallbackState(context)
|
|
335
|
+
if (state?.root === undefined) {
|
|
336
|
+
return current == null ? null : current.visibility === 'hidden' ? current : { ...current, visibility: 'hidden' }
|
|
337
|
+
}
|
|
338
|
+
const interruptedAt = interruption(context)
|
|
339
|
+
const root = !('kind' in state.root) && state.root.phase === 'preparing'
|
|
340
|
+
? preparingBlock(state.root, current?.data.root)
|
|
341
|
+
: state.root
|
|
342
|
+
const projected = projectBlock(root, state, interruptedAt)
|
|
343
|
+
const anchor = context.start?.event.seq
|
|
344
|
+
?? ('kind' in state.root ? state.root.seq : context.matches[0]?.event.seq ?? 0)
|
|
345
|
+
const preparing = !('kind' in projected) && projected.phase === 'preparing'
|
|
346
|
+
const visibility = preparing && interruptedAt !== undefined ? 'hidden' : 'visible'
|
|
347
|
+
const location = contextLocation(context)
|
|
348
|
+
const data = current?.data.root === projected ? current.data : { root: projected } satisfies ToolChatData
|
|
349
|
+
if (current?.data === data && current.anchorSeq === anchor
|
|
350
|
+
&& current.visibility === visibility && current.location === location) return current
|
|
351
|
+
return chatNode(context, 'tool-call', anchor, data, { visibility, location })
|
|
352
|
+
},
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Register the root Tool lifecycle and nested-subcall contribution.
|
|
357
|
+
* @param ctx - owning UI Conversation context.
|
|
358
|
+
*/
|
|
359
|
+
export function registerToolConversationNode(ctx: Context): void {
|
|
360
|
+
const match = toolDefinition.match.bind(toolDefinition)
|
|
361
|
+
ctx.uiConversation.events.register({
|
|
362
|
+
...toolDefinition,
|
|
363
|
+
match: {
|
|
364
|
+
'assistant/live-chunk': match,
|
|
365
|
+
'tool/call': match,
|
|
366
|
+
'tool/result': match,
|
|
367
|
+
'tool/ptc-dispatch-start': match,
|
|
368
|
+
'tool/ptc-dispatch': match,
|
|
369
|
+
},
|
|
370
|
+
})
|
|
371
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
2
|
+
import type {
|
|
3
|
+
ConversationMatch, ConversationNodeContext, ConversationNodeDefinition, TurnErrorNode,
|
|
4
|
+
} from '@deepseek-ai/dsh-client-ui-conversation/client'
|
|
5
|
+
import type { TurnEndReason } from '@deepseek-ai/dsh-session/types'
|
|
6
|
+
import { chatNode } from './common.ts'
|
|
7
|
+
import { displayFailure } from './event-projection.ts'
|
|
8
|
+
|
|
9
|
+
declare module '../contract/chat-nodes.ts' {
|
|
10
|
+
interface ChatNodeDataMap {
|
|
11
|
+
/** Terminal turn failure recorded on the turn's end reason. */
|
|
12
|
+
'turn-error': TurnErrorNode
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface TurnErrorState {
|
|
17
|
+
readonly turn: number
|
|
18
|
+
readonly failure?: {
|
|
19
|
+
readonly seq: number
|
|
20
|
+
readonly time: number
|
|
21
|
+
readonly message: string
|
|
22
|
+
readonly code?: string
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function lastStep(context: ConversationNodeContext<TurnErrorState>): number {
|
|
27
|
+
const location = context.start?.location ?? context.matches[0]?.location
|
|
28
|
+
if (location?.kind !== 'turn' && location?.kind !== 'step') return 0
|
|
29
|
+
return location.turn.steps.at(-1)?.step ?? 0
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Failure shown for a turn ending: a recorded error, a sign-out cancellation,
|
|
34
|
+
* or a turn that restart recovery closed because the DSH process exited mid-turn.
|
|
35
|
+
*/
|
|
36
|
+
function endFailure(reason: TurnEndReason): { readonly message: string; readonly code?: string } | undefined {
|
|
37
|
+
switch (reason.kind) {
|
|
38
|
+
case 'error':
|
|
39
|
+
return reason.error
|
|
40
|
+
case 'aborted':
|
|
41
|
+
// User and parent cancellations show only the stopped turn summary.
|
|
42
|
+
return reason.reason.kind === 'hook' && reason.reason.reason === 'deepseek-account/signed-out'
|
|
43
|
+
? { message: 'Stopped because you signed out of DeepSeek.', code: 'ACCOUNT_SIGNED_OUT' }
|
|
44
|
+
: undefined
|
|
45
|
+
case 'interrupted':
|
|
46
|
+
return { message: 'The DSH process exited before this turn finished.', code: 'INTERRUPTED' }
|
|
47
|
+
default:
|
|
48
|
+
// Completed, blocked, max-tokens, forked, and plugin-merged endings have no failure row.
|
|
49
|
+
return undefined
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function failureFrom(match: ConversationMatch): TurnErrorState['failure'] | undefined {
|
|
54
|
+
if (match.event.type !== 'turn/end') return undefined
|
|
55
|
+
const failure = endFailure(match.event.data.reason)
|
|
56
|
+
if (failure === undefined) return undefined
|
|
57
|
+
const display = displayFailure(failure)
|
|
58
|
+
return {
|
|
59
|
+
seq: match.event.seq,
|
|
60
|
+
time: match.event.time,
|
|
61
|
+
message: display.message,
|
|
62
|
+
...(display.code === undefined ? {} : { code: display.code }),
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function fallbackState(context: ConversationNodeContext<TurnErrorState>): TurnErrorState | undefined {
|
|
67
|
+
const end = context.matches.find(match => failureFrom(match) !== undefined)
|
|
68
|
+
if (end?.event.type !== 'turn/end') return undefined
|
|
69
|
+
const failure = failureFrom(end)
|
|
70
|
+
if (failure === undefined) return undefined
|
|
71
|
+
return { turn: end.event.data.turn, failure }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Terminal turn failure Definition. Retries run inside the failing turn, so the
|
|
76
|
+
* turn's `llm/retry` history never suppresses this terminal row; the model-retry
|
|
77
|
+
* node renders that history separately.
|
|
78
|
+
*/
|
|
79
|
+
export const turnErrorDefinition: ConversationNodeDefinition<TurnErrorState> = {
|
|
80
|
+
kind: 'turn-error',
|
|
81
|
+
target: 'chat',
|
|
82
|
+
match: (event) => {
|
|
83
|
+
if (event.type === 'turn/start') return { id: String(event.data.turn), role: 'start' }
|
|
84
|
+
if (event.type === 'turn/end' && endFailure(event.data.reason) !== undefined) {
|
|
85
|
+
return { id: String(event.data.turn), role: 'update' }
|
|
86
|
+
}
|
|
87
|
+
return null
|
|
88
|
+
},
|
|
89
|
+
start: (_context, match) => {
|
|
90
|
+
if (match.event.type !== 'turn/start') throw new Error('turn-error start requires turn/start')
|
|
91
|
+
return { turn: match.event.data.turn }
|
|
92
|
+
},
|
|
93
|
+
update: (context, match) => {
|
|
94
|
+
const failure = failureFrom(match)
|
|
95
|
+
return failure === undefined ? context.state : { ...context.state, failure }
|
|
96
|
+
},
|
|
97
|
+
buildViewNode: (context) => {
|
|
98
|
+
const state = context.state ?? fallbackState(context)
|
|
99
|
+
if (state?.failure === undefined) return null
|
|
100
|
+
const failure = state.failure
|
|
101
|
+
const node: TurnErrorNode = {
|
|
102
|
+
kind: 'turn-error',
|
|
103
|
+
seq: failure.seq,
|
|
104
|
+
time: failure.time,
|
|
105
|
+
turn: state.turn,
|
|
106
|
+
step: lastStep(context),
|
|
107
|
+
message: failure.message,
|
|
108
|
+
...failure.code === undefined ? {} : { code: failure.code },
|
|
109
|
+
}
|
|
110
|
+
return chatNode(context, 'turn-error', node.seq, node, { groupTree: 'turn' })
|
|
111
|
+
},
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Register the terminal Turn-error business contribution.
|
|
116
|
+
* @param ctx - owning UI Conversation context.
|
|
117
|
+
*/
|
|
118
|
+
export function registerTurnErrorConversationNode(ctx: Context): void {
|
|
119
|
+
ctx.uiConversation.events.register(turnErrorDefinition)
|
|
120
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
2
|
+
import type {
|
|
3
|
+
ConversationMatch, ConversationNodeContext, ConversationNodeDefinition, TurnMaxTokensNode,
|
|
4
|
+
} from '@deepseek-ai/dsh-client-ui-conversation/client'
|
|
5
|
+
import { CHAT_SYNTHETIC_SEQ_OFFSETS, chatNode } from './common.ts'
|
|
6
|
+
|
|
7
|
+
declare module '../contract/chat-nodes.ts' {
|
|
8
|
+
interface ChatNodeDataMap {
|
|
9
|
+
/** Turn ended by the per-request output-token cap. */
|
|
10
|
+
'turn-max-tokens': TurnMaxTokensNode
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface TurnMaxTokensState {
|
|
15
|
+
readonly turn: number
|
|
16
|
+
readonly seq: number
|
|
17
|
+
readonly time: number
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function lastStep(context: ConversationNodeContext<TurnMaxTokensState>): number {
|
|
21
|
+
const location = context.start?.location ?? context.matches[0]?.location
|
|
22
|
+
if (location?.kind !== 'turn' && location?.kind !== 'step') return 0
|
|
23
|
+
return location.turn.steps.at(-1)?.step ?? 0
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Anchor the notice between the closing Assistant and the turn-tail so the
|
|
28
|
+
* tail stays the turn's last Chat node and keeps its branch action enabled.
|
|
29
|
+
* Without a closing text Assistant there is no branch action to protect, and
|
|
30
|
+
* the turn/end seq keeps the notice at the truncation point.
|
|
31
|
+
*/
|
|
32
|
+
function noticeAnchor(context: ConversationNodeContext<TurnMaxTokensState>, seq: number): number {
|
|
33
|
+
const location = context.start?.location ?? context.matches[0]?.location
|
|
34
|
+
if (location?.kind !== 'turn' && location?.kind !== 'step') return seq
|
|
35
|
+
const closing = location.turn.data.get('turn-tail')?.closing
|
|
36
|
+
return closing === null || closing === undefined
|
|
37
|
+
? seq
|
|
38
|
+
: closing.finalNode.seq + CHAT_SYNTHETIC_SEQ_OFFSETS.maxTokensNotice
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function stateFrom(match: ConversationMatch): TurnMaxTokensState | undefined {
|
|
42
|
+
if (match.event.type !== 'turn/end' || match.event.data.reason.kind !== 'max-tokens') return undefined
|
|
43
|
+
return { turn: match.event.data.turn, seq: match.event.seq, time: match.event.time }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Notice Definition for a turn the provider ended at its output-token cap. */
|
|
47
|
+
export const turnMaxTokensDefinition: ConversationNodeDefinition<TurnMaxTokensState> = {
|
|
48
|
+
kind: 'turn-max-tokens',
|
|
49
|
+
target: 'chat',
|
|
50
|
+
match: (event) => {
|
|
51
|
+
if (event.type === 'turn/end' && event.data.reason.kind === 'max-tokens') {
|
|
52
|
+
return { id: String(event.data.turn), role: 'start' }
|
|
53
|
+
}
|
|
54
|
+
return null
|
|
55
|
+
},
|
|
56
|
+
start: (_context, match) => {
|
|
57
|
+
const state = stateFrom(match)
|
|
58
|
+
if (state === undefined) throw new Error('turn-max-tokens start requires a max-tokens turn/end')
|
|
59
|
+
return state
|
|
60
|
+
},
|
|
61
|
+
update: context => context.state,
|
|
62
|
+
buildViewNode: (context) => {
|
|
63
|
+
const state = context.state
|
|
64
|
+
if (state === undefined) return null
|
|
65
|
+
const node: TurnMaxTokensNode = {
|
|
66
|
+
kind: 'turn-max-tokens',
|
|
67
|
+
seq: state.seq,
|
|
68
|
+
time: state.time,
|
|
69
|
+
turn: state.turn,
|
|
70
|
+
step: lastStep(context),
|
|
71
|
+
}
|
|
72
|
+
return chatNode(context, 'turn-max-tokens', noticeAnchor(context, state.seq), node, { groupTree: 'turn' })
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Register the max-tokens turn-end notice contribution.
|
|
78
|
+
* @param ctx - owning UI Conversation context.
|
|
79
|
+
*/
|
|
80
|
+
export function registerTurnMaxTokensConversationNode(ctx: Context): void {
|
|
81
|
+
ctx.uiConversation.events.register(turnMaxTokensDefinition)
|
|
82
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { isVisibleChatNode } from '../contract/chat-visibility.ts'
|
|
2
|
+
import type { ChatNode } from '../contract/chat-nodes.ts'
|
|
3
|
+
import type { ChatLocationNodeIndex, ChatNodeStore, TurnNavigationItem } from '../contract/snapshot.ts'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Preview budgets, sized to the rail card's clamps (one prompt line, up to
|
|
7
|
+
* three response lines) and mirrored by the turnOutline projection so a turn
|
|
8
|
+
* shows the same words before and after its events load. Anything past a
|
|
9
|
+
* budget is invisible; copying whole transcripts into navigation state would
|
|
10
|
+
* otherwise grow with the loaded window on every structural update.
|
|
11
|
+
*/
|
|
12
|
+
const PROMPT_PREVIEW_LIMIT = 50
|
|
13
|
+
const RESPONSE_PREVIEW_LIMIT = 120
|
|
14
|
+
|
|
15
|
+
/** Join rendered text, collapse whitespace, and cap at `limit` with a trailing ellipsis when clipped. */
|
|
16
|
+
// Deliberate mirror of the turnOutline projection's preview(): the wire
|
|
17
|
+
// boundary forbids sharing code with the host package.
|
|
18
|
+
/* jscpd:ignore-start */
|
|
19
|
+
function preview(parts: Iterable<string>, limit: number): string {
|
|
20
|
+
let text = ''
|
|
21
|
+
let unread = false
|
|
22
|
+
for (const part of parts) {
|
|
23
|
+
if (text.length >= limit * 2) {
|
|
24
|
+
unread = true
|
|
25
|
+
break
|
|
26
|
+
}
|
|
27
|
+
// Per-part bound: this runs on every structural rail update, so one huge
|
|
28
|
+
// text block must not be concatenated (and regex-normalized) whole for a
|
|
29
|
+
// preview this short.
|
|
30
|
+
const clipped = part.length > limit * 2
|
|
31
|
+
const chunk = clipped ? part.slice(0, limit * 2) : part
|
|
32
|
+
text += text === '' ? chunk : ` ${chunk}`
|
|
33
|
+
if (clipped) {
|
|
34
|
+
unread = true
|
|
35
|
+
break
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const normalized = text.replace(/\s+/g, ' ').trim()
|
|
39
|
+
if (normalized.length > limit - 1) return `${normalized.slice(0, limit - 1).trimEnd()}…`
|
|
40
|
+
return unread ? `${normalized}…` : normalized
|
|
41
|
+
}
|
|
42
|
+
/* jscpd:ignore-end */
|
|
43
|
+
|
|
44
|
+
function promptText(node: ChatNode): string {
|
|
45
|
+
if (node.kind !== 'user') return ''
|
|
46
|
+
return preview(node.data.content.flatMap(block => block.type === 'text' ? [block.text] : []), PROMPT_PREVIEW_LIMIT)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function responseText(node: ChatNode): string {
|
|
50
|
+
if (node.kind !== 'assistant-step') return ''
|
|
51
|
+
return preview(
|
|
52
|
+
node.data.blocks.flatMap(block => block.kind === 'text' ? [block.text] : []),
|
|
53
|
+
RESPONSE_PREVIEW_LIMIT,
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Whether two items carry the same rail state, so the reader can keep its array.
|
|
59
|
+
* @param left - previously published item, when the Turn had one.
|
|
60
|
+
* @param right - freshly derived item, when the Turn still has one.
|
|
61
|
+
* @returns whether both sides describe the same mark.
|
|
62
|
+
*/
|
|
63
|
+
export function sameTurnNavigationItem(
|
|
64
|
+
left: TurnNavigationItem | undefined,
|
|
65
|
+
right: TurnNavigationItem | undefined,
|
|
66
|
+
): boolean {
|
|
67
|
+
if (left === undefined || right === undefined) return left === right
|
|
68
|
+
return left.turn === right.turn && left.anchorKey === right.anchorKey
|
|
69
|
+
&& left.prompt === right.prompt && left.response === right.response
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Project one loaded Turn into its rail item.
|
|
74
|
+
* @param turn - Turn number the item addresses.
|
|
75
|
+
* @param locations - live Location index supplying the Turn's node keys.
|
|
76
|
+
* @param nodes - live Chat node store.
|
|
77
|
+
* @returns the item, or undefined when the Turn has no visible loaded node.
|
|
78
|
+
*/
|
|
79
|
+
export function turnNavigationItem(
|
|
80
|
+
turn: number,
|
|
81
|
+
locations: ChatLocationNodeIndex,
|
|
82
|
+
nodes: ChatNodeStore,
|
|
83
|
+
): TurnNavigationItem | undefined {
|
|
84
|
+
const loaded = locations.getTurn(turn)
|
|
85
|
+
.map(key => nodes.get(key))
|
|
86
|
+
.filter((node): node is ChatNode => node !== undefined && isVisibleChatNode(node as ChatNode))
|
|
87
|
+
const user = loaded.find(node => node.kind === 'user')
|
|
88
|
+
const anchor = user ?? loaded[0]
|
|
89
|
+
if (anchor === undefined) return undefined
|
|
90
|
+
const response = loaded.findLast(node => responseText(node) !== '')
|
|
91
|
+
return {
|
|
92
|
+
turn,
|
|
93
|
+
anchorKey: anchor.key,
|
|
94
|
+
prompt: user === undefined ? '' : promptText(user),
|
|
95
|
+
response: response === undefined ? '' : responseText(response),
|
|
96
|
+
}
|
|
97
|
+
}
|