@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.
Files changed (355) hide show
  1. package/README.i18n.yaml +16 -16
  2. package/README.md +17 -5
  3. package/README.zh.md +17 -5
  4. package/lib/client.js +18 -15587
  5. package/lib/client.js.map +1 -0
  6. package/lib/types/chat-settings.d.ts.map +1 -0
  7. package/lib/types/chat-settings.js.map +1 -0
  8. package/lib/types/client/apply.d.ts.map +1 -0
  9. package/lib/types/client/apply.js.map +1 -0
  10. package/lib/types/client/chat/ApprovalCommand.d.ts +4 -3
  11. package/lib/types/client/chat/ApprovalCommand.d.ts.map +1 -0
  12. package/lib/types/client/chat/ApprovalCommand.js.map +1 -0
  13. package/lib/types/client/chat/AssistantMarkdown.d.ts.map +1 -0
  14. package/lib/types/client/chat/AssistantMarkdown.js.map +1 -0
  15. package/lib/types/client/chat/AssistantNodeView.d.ts.map +1 -0
  16. package/lib/types/client/chat/AssistantNodeView.js.map +1 -0
  17. package/lib/types/client/chat/ChatFlow.d.ts.map +1 -0
  18. package/lib/types/client/chat/ChatFlow.js.map +1 -0
  19. package/lib/types/client/chat/ChatGroupSeat.d.ts.map +1 -0
  20. package/lib/types/client/chat/ChatGroupSeat.js.map +1 -0
  21. package/lib/types/client/chat/ChatNodeSeat.d.ts.map +1 -0
  22. package/lib/types/client/chat/ChatNodeSeat.js.map +1 -0
  23. package/lib/types/client/chat/ChatView.d.ts +1 -1
  24. package/lib/types/client/chat/ChatView.d.ts.map +1 -0
  25. package/lib/types/client/chat/ChatView.js.map +1 -0
  26. package/lib/types/client/chat/CommandNodeView.d.ts.map +1 -0
  27. package/lib/types/client/chat/CommandNodeView.js.map +1 -0
  28. package/lib/types/client/chat/CompactionCommandCard.d.ts.map +1 -0
  29. package/lib/types/client/chat/CompactionCommandCard.js.map +1 -0
  30. package/lib/types/client/chat/CompactionItem.d.ts.map +1 -0
  31. package/lib/types/client/chat/CompactionItem.js.map +1 -0
  32. package/lib/types/client/chat/ContextBody.d.ts.map +1 -0
  33. package/lib/types/client/chat/ContextBody.js.map +1 -0
  34. package/lib/types/client/chat/ContextInjectionRow.d.ts.map +1 -0
  35. package/lib/types/client/chat/ContextInjectionRow.js.map +1 -0
  36. package/lib/types/client/chat/GenericCommandCard.d.ts.map +1 -0
  37. package/lib/types/client/chat/GenericCommandCard.js.map +1 -0
  38. package/lib/types/client/chat/MessageIconActions.d.ts.map +1 -0
  39. package/lib/types/client/chat/MessageIconActions.js.map +1 -0
  40. package/lib/types/client/chat/MessageItem.d.ts.map +1 -0
  41. package/lib/types/client/chat/MessageItem.js.map +1 -0
  42. package/lib/types/client/chat/QuotaNoticeHost.d.ts.map +1 -0
  43. package/lib/types/client/chat/QuotaNoticeHost.js.map +1 -0
  44. package/lib/types/client/chat/ReasoningContent.d.ts.map +1 -0
  45. package/lib/types/client/chat/ReasoningContent.js.map +1 -0
  46. package/lib/types/client/chat/ReasoningRow.d.ts.map +1 -0
  47. package/lib/types/client/chat/ReasoningRow.js.map +1 -0
  48. package/lib/types/client/chat/RunningStatus.d.ts.map +1 -0
  49. package/lib/types/client/chat/RunningStatus.js.map +1 -0
  50. package/lib/types/client/chat/RunningWhaleTail.d.ts.map +1 -0
  51. package/lib/types/client/chat/RunningWhaleTail.js.map +1 -0
  52. package/lib/types/client/chat/StatsPills.d.ts.map +1 -0
  53. package/lib/types/client/chat/StatsPills.js.map +1 -0
  54. package/lib/types/client/chat/SystemPromptRow.d.ts.map +1 -0
  55. package/lib/types/client/chat/SystemPromptRow.js.map +1 -0
  56. package/lib/types/client/chat/TurnNavigator.d.ts.map +1 -0
  57. package/lib/types/client/chat/TurnNavigator.js.map +1 -0
  58. package/lib/types/client/chat/TurnProcessNodeView.d.ts.map +1 -0
  59. package/lib/types/client/chat/TurnProcessNodeView.js.map +1 -0
  60. package/lib/types/client/chat/TurnTailNodeView.d.ts.map +1 -0
  61. package/lib/types/client/chat/TurnTailNodeView.js.map +1 -0
  62. package/lib/types/client/chat/TurnTriggerNodeView.d.ts.map +1 -0
  63. package/lib/types/client/chat/TurnTriggerNodeView.js.map +1 -0
  64. package/lib/types/client/chat/TurnUsagePanel.d.ts.map +1 -0
  65. package/lib/types/client/chat/TurnUsagePanel.js.map +1 -0
  66. package/lib/types/client/chat/UserContent.d.ts.map +1 -0
  67. package/lib/types/client/chat/UserContent.js.map +1 -0
  68. package/lib/types/client/chat/flow-motion.d.ts +2 -0
  69. package/lib/types/client/chat/flow-motion.d.ts.map +1 -0
  70. package/lib/types/client/chat/flow-motion.js.map +1 -0
  71. package/lib/types/client/chat/message-chrome.d.ts.map +1 -0
  72. package/lib/types/client/chat/message-chrome.js.map +1 -0
  73. package/lib/types/client/chat/register-node-renderers.d.ts.map +1 -0
  74. package/lib/types/client/chat/register-node-renderers.js.map +1 -0
  75. package/lib/types/client/chat/render-entry.d.ts.map +1 -0
  76. package/lib/types/client/chat/render-entry.js.map +1 -0
  77. package/lib/types/client/chat/searchable-hidden.d.ts.map +1 -0
  78. package/lib/types/client/chat/searchable-hidden.js.map +1 -0
  79. package/lib/types/client/chat/stat-dialog.d.ts +5 -10
  80. package/lib/types/client/chat/stat-dialog.d.ts.map +1 -0
  81. package/lib/types/client/chat/stat-dialog.js.map +1 -0
  82. package/lib/types/client/chat/step-process.d.ts.map +1 -0
  83. package/lib/types/client/chat/step-process.js.map +1 -0
  84. package/lib/types/client/chat/text-interaction.d.ts.map +1 -0
  85. package/lib/types/client/chat/text-interaction.js.map +1 -0
  86. package/lib/types/client/chat/text-selection.d.ts.map +1 -0
  87. package/lib/types/client/chat/text-selection.js.map +1 -0
  88. package/lib/types/client/chat/token-format.d.ts.map +1 -0
  89. package/lib/types/client/chat/token-format.js.map +1 -0
  90. package/lib/types/client/chat/turn-assistant.d.ts.map +1 -0
  91. package/lib/types/client/chat/turn-assistant.js.map +1 -0
  92. package/lib/types/client/chat/turn-rail-items.d.ts.map +1 -0
  93. package/lib/types/client/chat/turn-rail-items.js.map +1 -0
  94. package/lib/types/client/chat/turn-trigger.d.ts +3 -2
  95. package/lib/types/client/chat/turn-trigger.d.ts.map +1 -0
  96. package/lib/types/client/chat/turn-trigger.js.map +1 -0
  97. package/lib/types/client/chat/use-calendar-day.d.ts.map +1 -0
  98. package/lib/types/client/chat/use-calendar-day.js.map +1 -0
  99. package/lib/types/client/chat/use-chat-navigation.d.ts +21 -5
  100. package/lib/types/client/chat/use-chat-navigation.d.ts.map +1 -0
  101. package/lib/types/client/chat/use-chat-navigation.js.map +1 -0
  102. package/lib/types/client/chat/use-chat-reading.d.ts.map +1 -0
  103. package/lib/types/client/chat/use-chat-reading.js.map +1 -0
  104. package/lib/types/client/chat/use-chat-scroll.d.ts +5 -2
  105. package/lib/types/client/chat/use-chat-scroll.d.ts.map +1 -0
  106. package/lib/types/client/chat/use-chat-scroll.js.map +1 -0
  107. package/lib/types/client/chat/use-chat-viewport.d.ts +53 -0
  108. package/lib/types/client/chat/use-chat-viewport.d.ts.map +1 -0
  109. package/lib/types/client/chat/use-chat-viewport.js.map +1 -0
  110. package/lib/types/client/chat/use-disclosure.d.ts.map +1 -0
  111. package/lib/types/client/chat/use-disclosure.js.map +1 -0
  112. package/lib/types/client/chat/use-process-scroll.d.ts.map +1 -0
  113. package/lib/types/client/chat/use-process-scroll.js.map +1 -0
  114. package/lib/types/client/chat/use-scroll-follow.d.ts.map +1 -0
  115. package/lib/types/client/chat/use-scroll-follow.js.map +1 -0
  116. package/lib/types/client/chat/use-turn-data.d.ts.map +1 -0
  117. package/lib/types/client/chat/use-turn-data.js.map +1 -0
  118. package/lib/types/client/contract/assistant-content.d.ts.map +1 -0
  119. package/lib/types/client/contract/assistant-content.js.map +1 -0
  120. package/lib/types/client/contract/chat-nodes.d.ts.map +1 -0
  121. package/lib/types/client/contract/chat-nodes.js.map +1 -0
  122. package/lib/types/client/contract/chat-visibility.d.ts +2 -2
  123. package/lib/types/client/contract/chat-visibility.d.ts.map +1 -0
  124. package/lib/types/client/contract/chat-visibility.js.map +1 -0
  125. package/lib/types/client/contract/group-tree.d.ts.map +1 -0
  126. package/lib/types/client/contract/group-tree.js.map +1 -0
  127. package/lib/types/client/contract/process-groups.d.ts +6 -3
  128. package/lib/types/client/contract/process-groups.d.ts.map +1 -0
  129. package/lib/types/client/contract/process-groups.js.map +1 -0
  130. package/lib/types/client/contract/slots.d.ts +11 -2
  131. package/lib/types/client/contract/slots.d.ts.map +1 -0
  132. package/lib/types/client/contract/slots.js.map +1 -0
  133. package/lib/types/client/contract/snapshot.d.ts.map +1 -0
  134. package/lib/types/client/contract/snapshot.js.map +1 -0
  135. package/lib/types/client/contract/store.d.ts.map +1 -0
  136. package/lib/types/client/contract/store.js.map +1 -0
  137. package/lib/types/client/contract/turn-metrics.d.ts.map +1 -0
  138. package/lib/types/client/contract/turn-metrics.js.map +1 -0
  139. package/lib/types/client/contract/turn-process.d.ts.map +1 -0
  140. package/lib/types/client/contract/turn-process.js.map +1 -0
  141. package/lib/types/client/conversation-nodes/assistant.d.ts.map +1 -0
  142. package/lib/types/client/conversation-nodes/assistant.js.map +1 -0
  143. package/lib/types/client/conversation-nodes/chat-snapshot-builder.d.ts.map +1 -0
  144. package/lib/types/client/conversation-nodes/chat-snapshot-builder.js.map +1 -0
  145. package/lib/types/client/conversation-nodes/command.d.ts.map +1 -0
  146. package/lib/types/client/conversation-nodes/command.js.map +1 -0
  147. package/lib/types/client/conversation-nodes/common.d.ts.map +1 -0
  148. package/lib/types/client/conversation-nodes/common.js.map +1 -0
  149. package/lib/types/client/conversation-nodes/compaction.d.ts.map +1 -0
  150. package/lib/types/client/conversation-nodes/compaction.js.map +1 -0
  151. package/lib/types/client/conversation-nodes/event-projection.d.ts.map +1 -0
  152. package/lib/types/client/conversation-nodes/event-projection.js.map +1 -0
  153. package/lib/types/client/conversation-nodes/fallback.d.ts.map +1 -0
  154. package/lib/types/client/conversation-nodes/fallback.js.map +1 -0
  155. package/lib/types/client/conversation-nodes/group-tree-segments.d.ts.map +1 -0
  156. package/lib/types/client/conversation-nodes/group-tree-segments.js.map +1 -0
  157. package/lib/types/client/conversation-nodes/inbox.d.ts.map +1 -0
  158. package/lib/types/client/conversation-nodes/inbox.js.map +1 -0
  159. package/lib/types/client/conversation-nodes/message.d.ts +1 -1
  160. package/lib/types/client/conversation-nodes/message.d.ts.map +1 -0
  161. package/lib/types/client/conversation-nodes/message.js.map +1 -0
  162. package/lib/types/client/conversation-nodes/process-activity.d.ts +1 -0
  163. package/lib/types/client/conversation-nodes/process-activity.d.ts.map +1 -0
  164. package/lib/types/client/conversation-nodes/process-activity.js.map +1 -0
  165. package/lib/types/client/conversation-nodes/process-groups.d.ts.map +1 -0
  166. package/lib/types/client/conversation-nodes/process-groups.js.map +1 -0
  167. package/lib/types/client/conversation-nodes/register.d.ts.map +1 -0
  168. package/lib/types/client/conversation-nodes/register.js.map +1 -0
  169. package/lib/types/client/conversation-nodes/request-prompt.d.ts.map +1 -0
  170. package/lib/types/client/conversation-nodes/request-prompt.js.map +1 -0
  171. package/lib/types/client/conversation-nodes/retry.d.ts.map +1 -0
  172. package/lib/types/client/conversation-nodes/retry.js.map +1 -0
  173. package/lib/types/client/conversation-nodes/tool.d.ts.map +1 -0
  174. package/lib/types/client/conversation-nodes/tool.js.map +1 -0
  175. package/lib/types/client/conversation-nodes/turn-error.d.ts.map +1 -0
  176. package/lib/types/client/conversation-nodes/turn-error.js.map +1 -0
  177. package/lib/types/client/conversation-nodes/turn-max-tokens.d.ts.map +1 -0
  178. package/lib/types/client/conversation-nodes/turn-max-tokens.js.map +1 -0
  179. package/lib/types/client/conversation-nodes/turn-navigation.d.ts.map +1 -0
  180. package/lib/types/client/conversation-nodes/turn-navigation.js.map +1 -0
  181. package/lib/types/client/conversation-nodes/turn-process-presentation.d.ts.map +1 -0
  182. package/lib/types/client/conversation-nodes/turn-process-presentation.js.map +1 -0
  183. package/lib/types/client/conversation-nodes/turn-process.d.ts.map +1 -0
  184. package/lib/types/client/conversation-nodes/turn-process.js.map +1 -0
  185. package/lib/types/client/conversation-nodes/turn-tail.d.ts.map +1 -0
  186. package/lib/types/client/conversation-nodes/turn-tail.js.map +1 -0
  187. package/lib/types/client/fence/FenceLayers.d.ts +21 -0
  188. package/lib/types/client/fence/FenceLayers.d.ts.map +1 -0
  189. package/lib/types/client/fence/FenceLayers.js.map +1 -0
  190. package/lib/types/client/fence/register.d.ts +10 -0
  191. package/lib/types/client/fence/register.d.ts.map +1 -0
  192. package/lib/types/client/fence/register.js.map +1 -0
  193. package/lib/types/client/file-path.d.ts.map +1 -0
  194. package/lib/types/client/file-path.js.map +1 -0
  195. package/lib/types/client/index.d.ts +1 -1
  196. package/lib/types/client/index.d.ts.map +1 -0
  197. package/lib/types/client/index.js.map +1 -0
  198. package/lib/types/client/locale.d.ts +96 -0
  199. package/lib/types/client/locale.d.ts.map +1 -0
  200. package/lib/types/client/locale.js.map +1 -0
  201. package/lib/types/client/markdown-labels.d.ts.map +1 -0
  202. package/lib/types/client/markdown-labels.js.map +1 -0
  203. package/lib/types/client/model/conversation-context.d.ts.map +1 -0
  204. package/lib/types/client/model/conversation-context.js.map +1 -0
  205. package/lib/types/client/model/steering-history.d.ts.map +1 -0
  206. package/lib/types/client/model/steering-history.js.map +1 -0
  207. package/lib/types/client/model/tool-call-tree.d.ts.map +1 -0
  208. package/lib/types/client/model/tool-call-tree.js.map +1 -0
  209. package/lib/types/client/performance-usage.d.ts.map +1 -0
  210. package/lib/types/client/performance-usage.js.map +1 -0
  211. package/lib/types/client/presentation-policy.d.ts.map +1 -0
  212. package/lib/types/client/presentation-policy.js.map +1 -0
  213. package/lib/types/client/reasoning-text.d.ts.map +1 -0
  214. package/lib/types/client/reasoning-text.js.map +1 -0
  215. package/lib/types/client/settings/LinkOpeningRow.d.ts.map +1 -0
  216. package/lib/types/client/settings/LinkOpeningRow.js.map +1 -0
  217. package/lib/types/client/settings/PerformanceUsageRow.d.ts.map +1 -0
  218. package/lib/types/client/settings/PerformanceUsageRow.js.map +1 -0
  219. package/lib/types/client/settings/PreferenceRow.d.ts.map +1 -0
  220. package/lib/types/client/settings/PreferenceRow.js.map +1 -0
  221. package/lib/types/client/settings/TranscriptViewRow.d.ts.map +1 -0
  222. package/lib/types/client/settings/TranscriptViewRow.js.map +1 -0
  223. package/lib/types/client/stores.d.ts.map +1 -0
  224. package/lib/types/client/stores.js.map +1 -0
  225. package/lib/types/client/transcript-view.d.ts.map +1 -0
  226. package/lib/types/client/transcript-view.js.map +1 -0
  227. package/lib/types/index.d.ts.map +1 -0
  228. package/lib/types/index.js.map +1 -0
  229. package/package.json +47 -44
  230. package/src/chat-settings.ts +98 -0
  231. package/src/client/apply.ts +355 -0
  232. package/src/client/assets/running-whale@2x.png +0 -0
  233. package/src/client/chat/ApprovalCommand.tsx +42 -0
  234. package/src/client/chat/AssistantMarkdown.module.css +88 -0
  235. package/src/client/chat/AssistantMarkdown.tsx +170 -0
  236. package/src/client/chat/AssistantNodeView.tsx +67 -0
  237. package/src/client/chat/ChatFlow.tsx +100 -0
  238. package/src/client/chat/ChatGroupSeat.module.css +166 -0
  239. package/src/client/chat/ChatGroupSeat.tsx +208 -0
  240. package/src/client/chat/ChatNodeSeat.tsx +179 -0
  241. package/src/client/chat/ChatView.module.css +426 -0
  242. package/src/client/chat/ChatView.tsx +351 -0
  243. package/src/client/chat/CommandNodeView.tsx +40 -0
  244. package/src/client/chat/CompactionCommandCard.tsx +26 -0
  245. package/src/client/chat/CompactionItem.tsx +76 -0
  246. package/src/client/chat/ContextBody.module.css +161 -0
  247. package/src/client/chat/ContextBody.tsx +592 -0
  248. package/src/client/chat/ContextInjectionRow.module.css +68 -0
  249. package/src/client/chat/ContextInjectionRow.tsx +94 -0
  250. package/src/client/chat/GenericCommandCard.module.css +49 -0
  251. package/src/client/chat/GenericCommandCard.tsx +75 -0
  252. package/src/client/chat/MessageIconActions.module.css +116 -0
  253. package/src/client/chat/MessageIconActions.tsx +90 -0
  254. package/src/client/chat/MessageItem.module.css +360 -0
  255. package/src/client/chat/MessageItem.tsx +410 -0
  256. package/src/client/chat/QuotaNoticeHost.tsx +27 -0
  257. package/src/client/chat/ReasoningContent.tsx +26 -0
  258. package/src/client/chat/ReasoningRow.module.css +77 -0
  259. package/src/client/chat/ReasoningRow.tsx +112 -0
  260. package/src/client/chat/RunningStatus.tsx +48 -0
  261. package/src/client/chat/RunningWhaleTail.tsx +19 -0
  262. package/src/client/chat/StatsPills.module.css +63 -0
  263. package/src/client/chat/StatsPills.tsx +348 -0
  264. package/src/client/chat/SystemPromptRow.tsx +50 -0
  265. package/src/client/chat/TurnNavigator.module.css +223 -0
  266. package/src/client/chat/TurnNavigator.tsx +295 -0
  267. package/src/client/chat/TurnProcessNodeView.module.css +62 -0
  268. package/src/client/chat/TurnProcessNodeView.tsx +62 -0
  269. package/src/client/chat/TurnTailNodeView.module.css +12 -0
  270. package/src/client/chat/TurnTailNodeView.tsx +81 -0
  271. package/src/client/chat/TurnTriggerNodeView.module.css +50 -0
  272. package/src/client/chat/TurnTriggerNodeView.tsx +57 -0
  273. package/src/client/chat/TurnUsagePanel.module.css +79 -0
  274. package/src/client/chat/TurnUsagePanel.tsx +110 -0
  275. package/src/client/chat/UserContent.tsx +60 -0
  276. package/src/client/chat/accessibility.module.css +8 -0
  277. package/src/client/chat/flow-motion.ts +556 -0
  278. package/src/client/chat/message-chrome.ts +100 -0
  279. package/src/client/chat/register-node-renderers.ts +100 -0
  280. package/src/client/chat/render-entry.ts +16 -0
  281. package/src/client/chat/searchable-hidden.ts +45 -0
  282. package/src/client/chat/stat-dialog.module.css +149 -0
  283. package/src/client/chat/stat-dialog.ts +55 -0
  284. package/src/client/chat/step-process.ts +28 -0
  285. package/src/client/chat/text-interaction.ts +298 -0
  286. package/src/client/chat/text-selection.ts +180 -0
  287. package/src/client/chat/token-format.ts +98 -0
  288. package/src/client/chat/turn-assistant.ts +10 -0
  289. package/src/client/chat/turn-rail-items.ts +89 -0
  290. package/src/client/chat/turn-trigger.ts +88 -0
  291. package/src/client/chat/use-calendar-day.ts +25 -0
  292. package/src/client/chat/use-chat-navigation.ts +309 -0
  293. package/src/client/chat/use-chat-reading.ts +283 -0
  294. package/src/client/chat/use-chat-scroll.ts +209 -0
  295. package/src/client/chat/use-chat-viewport.ts +1130 -0
  296. package/src/client/chat/use-disclosure.ts +35 -0
  297. package/src/client/chat/use-process-scroll.ts +88 -0
  298. package/src/client/chat/use-scroll-follow.ts +182 -0
  299. package/src/client/chat/use-turn-data.ts +23 -0
  300. package/src/client/contract/assistant-content.ts +15 -0
  301. package/src/client/contract/chat-nodes.ts +135 -0
  302. package/src/client/contract/chat-visibility.ts +20 -0
  303. package/src/client/contract/group-tree.ts +37 -0
  304. package/src/client/contract/process-groups.ts +30 -0
  305. package/src/client/contract/slots.ts +508 -0
  306. package/src/client/contract/snapshot.ts +171 -0
  307. package/src/client/contract/store.ts +17 -0
  308. package/src/client/contract/turn-metrics.ts +43 -0
  309. package/src/client/contract/turn-process.ts +58 -0
  310. package/src/client/conversation-nodes/README.i18n.yaml +64 -0
  311. package/src/client/conversation-nodes/README.md +338 -0
  312. package/src/client/conversation-nodes/README.zh.md +338 -0
  313. package/src/client/conversation-nodes/assistant.ts +384 -0
  314. package/src/client/conversation-nodes/chat-snapshot-builder.ts +1244 -0
  315. package/src/client/conversation-nodes/command.ts +227 -0
  316. package/src/client/conversation-nodes/common.ts +83 -0
  317. package/src/client/conversation-nodes/compaction.ts +65 -0
  318. package/src/client/conversation-nodes/event-projection.ts +179 -0
  319. package/src/client/conversation-nodes/fallback.ts +41 -0
  320. package/src/client/conversation-nodes/group-tree-segments.ts +91 -0
  321. package/src/client/conversation-nodes/inbox.ts +148 -0
  322. package/src/client/conversation-nodes/message.ts +182 -0
  323. package/src/client/conversation-nodes/process-activity.ts +170 -0
  324. package/src/client/conversation-nodes/process-groups.ts +303 -0
  325. package/src/client/conversation-nodes/register.ts +38 -0
  326. package/src/client/conversation-nodes/request-prompt.ts +169 -0
  327. package/src/client/conversation-nodes/retry.ts +97 -0
  328. package/src/client/conversation-nodes/tool.ts +371 -0
  329. package/src/client/conversation-nodes/turn-error.ts +120 -0
  330. package/src/client/conversation-nodes/turn-max-tokens.ts +82 -0
  331. package/src/client/conversation-nodes/turn-navigation.ts +97 -0
  332. package/src/client/conversation-nodes/turn-process-presentation.ts +149 -0
  333. package/src/client/conversation-nodes/turn-process.ts +374 -0
  334. package/src/client/conversation-nodes/turn-tail.ts +164 -0
  335. package/src/client/fence/FenceLayers.tsx +33 -0
  336. package/src/client/fence/register.ts +22 -0
  337. package/src/client/file-path.ts +19 -0
  338. package/src/client/index.ts +69 -0
  339. package/src/client/locale.ts +1695 -0
  340. package/src/client/markdown-labels.ts +16 -0
  341. package/src/client/model/conversation-context.ts +24 -0
  342. package/src/client/model/steering-history.ts +64 -0
  343. package/src/client/model/tool-call-tree.ts +204 -0
  344. package/src/client/performance-usage.ts +34 -0
  345. package/src/client/presentation-policy.ts +109 -0
  346. package/src/client/reasoning-text.ts +25 -0
  347. package/src/client/settings/LinkOpeningRow.tsx +47 -0
  348. package/src/client/settings/PerformanceUsageRow.tsx +46 -0
  349. package/src/client/settings/PreferenceRow.module.css +66 -0
  350. package/src/client/settings/PreferenceRow.tsx +59 -0
  351. package/src/client/settings/TranscriptViewRow.tsx +93 -0
  352. package/src/client/stores.ts +62 -0
  353. package/src/client/transcript-view.ts +81 -0
  354. package/src/css-modules.d.ts +6 -0
  355. package/src/index.ts +45 -0
@@ -0,0 +1,149 @@
1
+ import { isVisibleChatNode } from '../contract/chat-visibility.ts'
2
+ import type { ChatNode } from '../contract/chat-nodes.ts'
3
+ import type {
4
+ ChatLocationNodeIndex, ChatNodeStore, ChatTurnProcessPresentation,
5
+ } from '../contract/snapshot.ts'
6
+ import { isAtOrOutside } from '../contract/group-tree.ts'
7
+
8
+ function nodeTurn(node: ChatNode | undefined): number | undefined {
9
+ const location = node?.location
10
+ return location?.kind === 'turn' || location?.kind === 'step' ? location.turn.turn : undefined
11
+ }
12
+
13
+ function samePresentation(
14
+ left: ChatTurnProcessPresentation | undefined,
15
+ right: ChatTurnProcessPresentation | undefined,
16
+ ): boolean {
17
+ return left === right || (left !== undefined && right !== undefined
18
+ && left.spec === right.spec
19
+ && left.turn === right.turn
20
+ && left.turnStarted === right.turnStarted
21
+ && left.turnClosed === right.turnClosed
22
+ && left.hasExternalProcess === right.hasExternalProcess
23
+ && left.hasNonReplyProcess === right.hasNonReplyProcess
24
+ && left.hasInterleavedInput === right.hasInterleavedInput)
25
+ }
26
+
27
+ function derivePresentation(
28
+ turn: number,
29
+ locations: ChatLocationNodeIndex,
30
+ nodes: ChatNodeStore,
31
+ ): ChatTurnProcessPresentation | undefined {
32
+ const keys = locations.getTurn(turn)
33
+ const control = keys
34
+ .map(key => nodes.get(key) as ChatNode | undefined)
35
+ .find((node): node is ChatNode<'turn-process'> => node?.kind === 'turn-process')
36
+ if (control === undefined) return undefined
37
+
38
+ const spec = control.data
39
+ const location = control.location
40
+ if (location.kind !== 'turn' && location.kind !== 'step') return undefined
41
+ let openingHumanAnchor: number | undefined
42
+ for (const key of keys) {
43
+ const node = nodes.get(key) as ChatNode | undefined
44
+ if (node !== undefined && isAtOrOutside(node, 'input')
45
+ && (spec.controlAnchorSeq === location.turn.start?.seq || node.anchorSeq < spec.controlAnchorSeq)) {
46
+ openingHumanAnchor = Math.max(openingHumanAnchor ?? node.anchorSeq, node.anchorSeq)
47
+ }
48
+ }
49
+
50
+ let hasExternalProcess = false
51
+ let hasNonReplyProcess = false
52
+ let hasInterleavedInput = false
53
+ for (const key of keys) {
54
+ const node = nodes.get(key) as ChatNode | undefined
55
+ if (node === undefined || !isVisibleChatNode(node) || node.kind === 'turn-process') continue
56
+ if (isAtOrOutside(node, 'input')
57
+ && (openingHumanAnchor === undefined || node.anchorSeq > openingHumanAnchor)) {
58
+ hasInterleavedInput = true
59
+ }
60
+ if (isAtOrOutside(node, 'turn')
61
+ || node.anchorSeq < spec.processStartSeq
62
+ || (spec.answerAnchorSeq !== null && node.anchorSeq >= spec.answerAnchorSeq)) continue
63
+ if (node.kind !== 'assistant-step' || spec.answerStep === null || node.data.step !== spec.answerStep) {
64
+ hasExternalProcess = true
65
+ // When every reply stays visible, another Step's reply folds only its reasoning.
66
+ if (node.kind !== 'assistant-step'
67
+ || node.data.blocks.some(block => block.kind === 'reasoning' && block.text.trim() !== '')) {
68
+ hasNonReplyProcess = true
69
+ }
70
+ }
71
+ }
72
+ return {
73
+ turn,
74
+ spec,
75
+ turnStarted: location.turn.start !== undefined,
76
+ turnClosed: location.turn.status === 'closed',
77
+ hasExternalProcess,
78
+ hasNonReplyProcess,
79
+ hasInterleavedInput,
80
+ }
81
+ }
82
+
83
+ /** Mutable projection of cross-Node process layout facts by Turn. */
84
+ export class ChatTurnProcessProjector {
85
+ private presentations = new Map<number, ChatTurnProcessPresentation>()
86
+
87
+ /**
88
+ * Read the retained process presentation for a Node's Turn.
89
+ * @param node - Current Chat Node.
90
+ * @returns The Turn's process presentation, when present.
91
+ */
92
+ get(node: ChatNode | undefined): ChatTurnProcessPresentation | undefined {
93
+ const turn = nodeTurn(node)
94
+ return turn === undefined ? undefined : this.presentations.get(turn)
95
+ }
96
+
97
+ /**
98
+ * Replace every projected Turn.
99
+ * @param order - visible Chat Node order.
100
+ * @param locations - current Chat Location index.
101
+ * @param nodes - current Chat Node store.
102
+ * @returns Turns whose process presentation changed.
103
+ */
104
+ replace(
105
+ order: readonly string[],
106
+ locations: ChatLocationNodeIndex,
107
+ nodes: ChatNodeStore,
108
+ ): ReadonlySet<number> {
109
+ const turns = new Set<number>()
110
+ for (const key of order) {
111
+ const turn = nodeTurn(nodes.get(key) as ChatNode | undefined)
112
+ if (turn !== undefined) turns.add(turn)
113
+ }
114
+ const changed = new Set<number>()
115
+ for (const turn of new Set([...this.presentations.keys(), ...turns])) {
116
+ if (this.set(turn, turns.has(turn) ? derivePresentation(turn, locations, nodes) : undefined)) {
117
+ changed.add(turn)
118
+ }
119
+ }
120
+ return changed
121
+ }
122
+
123
+ /**
124
+ * Recompute selected Turns after incremental Node changes.
125
+ * @param turns - affected Turn numbers.
126
+ * @param locations - current Chat Location index.
127
+ * @param nodes - current Chat Node store.
128
+ * @returns Turns whose process presentation changed.
129
+ */
130
+ update(
131
+ turns: ReadonlySet<number>,
132
+ locations: ChatLocationNodeIndex,
133
+ nodes: ChatNodeStore,
134
+ ): ReadonlySet<number> {
135
+ const changed = new Set<number>()
136
+ for (const turn of turns) {
137
+ if (this.set(turn, derivePresentation(turn, locations, nodes))) changed.add(turn)
138
+ }
139
+ return changed
140
+ }
141
+
142
+ private set(turn: number, next: ChatTurnProcessPresentation | undefined): boolean {
143
+ const current = this.presentations.get(turn)
144
+ if (samePresentation(current, next)) return false
145
+ if (next === undefined) this.presentations.delete(turn)
146
+ else this.presentations.set(turn, next)
147
+ return true
148
+ }
149
+ }
@@ -0,0 +1,374 @@
1
+ import type { Context } from '@deepseek-ai/cordis'
2
+ import type {
3
+ ConversationLocation, ConversationNodeContext, ConversationNodeDefinition, TurnLocation,
4
+ } from '@deepseek-ai/dsh-client-ui-conversation/client'
5
+ import type {} from '@deepseek-ai/dsh-llm-retry/types'
6
+ import type { StreamChunk } from '@deepseek-ai/dsh-llm'
7
+ import type {} from '@deepseek-ai/dsh-tool-executor-ptc/client'
8
+ import { hasAssistantReplyContent } from '../contract/assistant-content.ts'
9
+ import type { AssistantChatData, ChatNode, FinalAssistantChatData } from '../contract/chat-nodes.ts'
10
+ import {
11
+ isSubagentDelegationTool, sameTurnProcessSpec, type TurnProcessSpec,
12
+ } from '../contract/turn-process.ts'
13
+ import { CHAT_SYNTHETIC_SEQ_OFFSETS, chatNode } from './common.ts'
14
+ import { toAssistantBlocks } from './event-projection.ts'
15
+
16
+ declare module '../contract/chat-nodes.ts' {
17
+ interface ChatNodeDataMap {
18
+ /** Turn-level disclosure controlling process rows before the finalized answer. */
19
+ 'turn-process': import('../contract/chat-nodes.ts').TurnProcessChatData
20
+ }
21
+ }
22
+
23
+ declare module '@deepseek-ai/dsh-client-ui-conversation/client' {
24
+ interface ConversationTurnDataMap {
25
+ /** Process range and finalized answer boundary for this Turn. */
26
+ 'turn-process': TurnProcessSpec
27
+ }
28
+ }
29
+
30
+ interface TurnProcessState {
31
+ readonly turn: number
32
+ readonly assistantStartByStep: ReadonlyMap<number, number>
33
+ readonly messageCountByStep: ReadonlyMap<number, number>
34
+ readonly otherStartSeq?: number
35
+ readonly controlAnchorSeq?: number
36
+ readonly messageCount: number
37
+ readonly toolCallCount: number
38
+ readonly subagentCount: number
39
+ }
40
+
41
+ type ConversationEvent = Parameters<ConversationNodeDefinition['match']>[0]
42
+
43
+ function eventTurn(event: ConversationEvent): number | undefined {
44
+ const data = event.data as unknown as { turn?: unknown }
45
+ return typeof data.turn === 'number' ? data.turn : undefined
46
+ }
47
+
48
+ function visibleChunk(chunk: StreamChunk): boolean {
49
+ if (chunk.type === 'text-delta' || chunk.type === 'reasoning-delta') return chunk.text.trim() !== ''
50
+ if (chunk.type === 'block-start') {
51
+ return chunk.blockType !== 'text'
52
+ && chunk.blockType !== 'reasoning'
53
+ && chunk.blockType !== 'tool-call'
54
+ }
55
+ if (chunk.type !== 'block-end') return false
56
+ const block = chunk.block
57
+ if (block.type === 'tool-call') return false
58
+ if (block.type === 'text' || block.type === 'reasoning') return block.text.trim() !== ''
59
+ return true
60
+ }
61
+
62
+ function visibleAssistantEvent(event: ConversationEvent): boolean {
63
+ if (event.type === 'assistant/live-chunk') return visibleChunk(event.data.chunk)
64
+ if (event.type === 'assistant/attempt') return false
65
+ return event.type === 'assistant/message'
66
+ && event.surfaceOp === 'append'
67
+ && toAssistantBlocks(event.data.message.content).some((block) => {
68
+ if (block.kind === 'tool-call') return false
69
+ if (block.kind === 'text' || block.kind === 'reasoning') return block.text.trim() !== ''
70
+ return true
71
+ })
72
+ }
73
+
74
+ type ProcessEvidence =
75
+ | { readonly kind: 'assistant'; readonly seq: number; readonly step: number }
76
+ | { readonly kind: 'other'; readonly seq: number }
77
+
78
+ function processEvidence(event: ConversationEvent): ProcessEvidence | undefined {
79
+ if (visibleAssistantEvent(event)) {
80
+ if (event.type !== 'assistant/live-chunk'
81
+ && event.type !== 'assistant/message'
82
+ && event.type !== 'assistant/attempt') return undefined
83
+ return { kind: 'assistant', seq: event.seq, step: event.data.step }
84
+ }
85
+ if (event.type === 'tool/call'
86
+ || (event.type === 'tool/result' && event.surfaceOp === 'append')
87
+ || event.type === 'llm/retry') return { kind: 'other', seq: event.seq }
88
+ return undefined
89
+ }
90
+
91
+ /** Turn of one Step that recorded durable process evidence. */
92
+ export interface ProcessEvidenceState {
93
+ readonly turn: number
94
+ }
95
+
96
+ function durableEvidenceStep(event: ConversationEvent): { readonly turn: number; readonly step: number } | undefined {
97
+ if (processEvidence(event) === undefined) return undefined
98
+ switch (event.type) {
99
+ case 'assistant/message':
100
+ case 'tool/call':
101
+ case 'tool/result':
102
+ case 'llm/retry':
103
+ return { turn: event.data.turn, step: event.data.step }
104
+ default:
105
+ return undefined
106
+ }
107
+ }
108
+
109
+ /**
110
+ * State-only record of each Step whose durable events include process evidence, keyed by Turn and Step.
111
+ * An input follows its Turn's process control exactly when its Turn recorded evidence before it, so an
112
+ * input reads the nearest earlier record through `reader.previous`. A Step's evidence is logged before
113
+ * a later Step admits input, so the record a later input reads no longer changes; transient live chunks
114
+ * are not needed because a Step's durable settlement precedes the next Step's input.
115
+ */
116
+ export const processEvidenceDefinition: ConversationNodeDefinition<ProcessEvidenceState> = {
117
+ kind: 'process-evidence',
118
+ match: (event) => {
119
+ const coordinates = durableEvidenceStep(event)
120
+ return coordinates === undefined ? null : { id: `${coordinates.turn}:${coordinates.step}`, role: 'start' }
121
+ },
122
+ start: (_context, match) => {
123
+ const coordinates = durableEvidenceStep(match.event)
124
+ if (coordinates === undefined) throw new Error('process-evidence start requires durable process evidence')
125
+ return { turn: coordinates.turn }
126
+ },
127
+ update: context => context.state,
128
+ publication: () => 'none',
129
+ }
130
+
131
+ function turnLocation(context: ConversationNodeContext<TurnProcessState>): TurnLocation | undefined {
132
+ const location: ConversationLocation | undefined = context.start?.location ?? context.matches.at(-1)?.location
133
+ return location?.kind === 'turn' || location?.kind === 'step' ? location.turn : undefined
134
+ }
135
+
136
+ function fallbackState(context: ConversationNodeContext<TurnProcessState>): TurnProcessState | undefined {
137
+ const turn = context.matches.map(match => eventTurn(match.event)).find(candidate => candidate !== undefined)
138
+ if (turn === undefined) return undefined
139
+ let state: TurnProcessState = {
140
+ turn,
141
+ assistantStartByStep: new Map(),
142
+ messageCountByStep: new Map(),
143
+ messageCount: 0,
144
+ toolCallCount: 0,
145
+ subagentCount: 0,
146
+ }
147
+ for (const match of context.matches) state = updateProcessState(state, match.event)
148
+ return state
149
+ }
150
+
151
+ function isFinalAssistant(
152
+ data: Readonly<AssistantChatData> | undefined,
153
+ ): data is Readonly<FinalAssistantChatData> {
154
+ return data?.finalNode !== undefined
155
+ }
156
+
157
+ function latestAnswer(turn: TurnLocation): Readonly<FinalAssistantChatData> | null {
158
+ const latestStep = turn.steps.at(-1)
159
+ const data: Readonly<AssistantChatData> | undefined = latestStep?.data.get('assistant-step')
160
+ if (!isFinalAssistant(data) || !hasAssistantReplyContent(data.blocks)) return null
161
+ return data.blocks.some(block => block.kind === 'tool-call') ? null : data
162
+ }
163
+
164
+ function processSpec(state: TurnProcessState, turn: TurnLocation): TurnProcessSpec | null {
165
+ const controlAnchorSeq = state.controlAnchorSeq ?? turn.start?.seq
166
+ if (controlAnchorSeq === undefined) return null
167
+ const answer = latestAnswer(turn)
168
+ const counts = {
169
+ messageCount: answer === null
170
+ ? state.messageCount
171
+ : [...state.messageCountByStep]
172
+ .filter(([step]) => step < answer.step)
173
+ .reduce((total, [, count]) => total + count, 0),
174
+ toolCallCount: state.toolCallCount,
175
+ subagentCount: state.subagentCount,
176
+ }
177
+ if (answer === null) {
178
+ return {
179
+ turn: turn.turn,
180
+ controlAnchorSeq,
181
+ processStartSeq: controlAnchorSeq,
182
+ answerAnchorSeq: null,
183
+ answerStep: null,
184
+ inlineReasoning: false,
185
+ ...counts,
186
+ }
187
+ }
188
+ const inlineReasoning = answer.blocks.some(block => block.kind === 'reasoning' && block.text.trim() !== '')
189
+ const earlierAssistantSeq = Math.min(
190
+ ...[...state.assistantStartByStep]
191
+ .filter(([step]) => step < answer.step)
192
+ .map(([, seq]) => seq),
193
+ )
194
+ const externalProcessSeq = Math.min(
195
+ state.otherStartSeq ?? Number.POSITIVE_INFINITY,
196
+ earlierAssistantSeq,
197
+ )
198
+ return {
199
+ turn: turn.turn,
200
+ controlAnchorSeq,
201
+ processStartSeq: turn.start?.seq
202
+ ?? (Number.isFinite(externalProcessSeq) ? externalProcessSeq : answer.finalNode.seq),
203
+ answerAnchorSeq: answer.finalNode.seq,
204
+ answerStep: answer.step,
205
+ inlineReasoning,
206
+ ...counts,
207
+ }
208
+ }
209
+
210
+ function updateProcessState(state: TurnProcessState, event: ConversationEvent): TurnProcessState {
211
+ let current = state
212
+ if (event.type === 'assistant/message'
213
+ && event.surfaceOp === 'append'
214
+ && hasAssistantReplyContent(toAssistantBlocks(event.data.message.content))) {
215
+ const messageCountByStep = new Map(current.messageCountByStep)
216
+ messageCountByStep.set(event.data.step, (messageCountByStep.get(event.data.step) ?? 0) + 1)
217
+ current = { ...current, messageCountByStep, messageCount: current.messageCount + 1 }
218
+ }
219
+ if (event.type === 'tool/call') {
220
+ const subagent = isSubagentDelegationTool(event.data.name)
221
+ current = {
222
+ ...current,
223
+ toolCallCount: current.toolCallCount + (subagent ? 0 : 1),
224
+ subagentCount: current.subagentCount + (subagent ? 1 : 0),
225
+ }
226
+ }
227
+ const evidence = processEvidence(event)
228
+ if (evidence === undefined) return current
229
+ if (evidence.kind === 'other') {
230
+ return current.otherStartSeq === undefined
231
+ ? {
232
+ ...current,
233
+ otherStartSeq: evidence.seq,
234
+ controlAnchorSeq: Math.min(current.controlAnchorSeq ?? Number.POSITIVE_INFINITY, evidence.seq),
235
+ }
236
+ : current
237
+ }
238
+ if (current.assistantStartByStep.has(evidence.step)) return current
239
+ const assistantStartByStep = new Map(current.assistantStartByStep)
240
+ assistantStartByStep.set(evidence.step, evidence.seq)
241
+ return {
242
+ ...current,
243
+ assistantStartByStep,
244
+ controlAnchorSeq: Math.min(current.controlAnchorSeq ?? Number.POSITIVE_INFINITY, evidence.seq),
245
+ }
246
+ }
247
+
248
+ /** Turn-scoped process range and answer-boundary Definition. */
249
+ export const turnProcessDefinition: ConversationNodeDefinition<TurnProcessState> = {
250
+ kind: 'turn-process',
251
+ target: 'chat',
252
+ match: (event) => {
253
+ if (event.type === 'turn/start') return { id: String(event.data.turn), role: 'start' }
254
+ const turn = eventTurn(event)
255
+ if (turn === undefined) return null
256
+ if (event.type === 'assistant/live-chunk'
257
+ || event.type === 'assistant/message'
258
+ || event.type === 'tool/call'
259
+ || event.type === 'tool/result'
260
+ || event.type === 'llm/retry'
261
+ || event.type === 'step/start'
262
+ || event.type === 'step/end'
263
+ || event.type === 'turn/end') {
264
+ return { id: String(turn), role: 'update' }
265
+ }
266
+ return null
267
+ },
268
+ start: (_context, match) => {
269
+ if (match.event.type !== 'turn/start') throw new Error('turn-process start requires turn/start')
270
+ return {
271
+ turn: match.event.data.turn,
272
+ assistantStartByStep: new Map(),
273
+ messageCountByStep: new Map(),
274
+ messageCount: 0,
275
+ toolCallCount: 0,
276
+ subagentCount: 0,
277
+ }
278
+ },
279
+ update: (context, match) => updateProcessState(context.state, match.event),
280
+ publication: (match) => {
281
+ if (match.event.type === 'assistant/live-chunk') {
282
+ const type = match.event.data.chunk.type
283
+ return type === 'usage' || type === 'finish' ? 'none' : 'animation-frame'
284
+ }
285
+ return 'immediate'
286
+ },
287
+ buildLocationData: (context, scope, previous) => {
288
+ if (scope !== 'turn') return null
289
+ const state = context.state ?? fallbackState(context)
290
+ if (state === undefined) return null
291
+ const turn = turnLocation(context)
292
+ if (turn === undefined) return null
293
+ const current = context.current.get('chat') as ChatNode | null | undefined
294
+ const latestStep = turn.steps.at(-1)
295
+ if (previous?.kind === 'turn'
296
+ && previous.key === 'turn-process'
297
+ && current?.kind === 'turn-process'
298
+ && current.data.answerAnchorSeq === null
299
+ && current.data.controlAnchorSeq === state.controlAnchorSeq
300
+ && current.data.messageCount === state.messageCount
301
+ && current.data.toolCallCount === state.toolCallCount
302
+ && current.data.subagentCount === state.subagentCount
303
+ && turn.status !== 'closed'
304
+ && latestStep?.status !== 'closed') return previous
305
+ const spec = processSpec(state, turn)
306
+ if (spec === null) return null
307
+ if (previous?.kind === 'turn'
308
+ && previous.turn === spec.turn
309
+ && previous.key === 'turn-process'
310
+ && sameTurnProcessSpec(previous.value, spec)) return previous
311
+ return {
312
+ kind: 'turn',
313
+ turn: turn.turn,
314
+ key: 'turn-process',
315
+ value: spec,
316
+ }
317
+ },
318
+ buildViewNode: (context) => {
319
+ const turn = turnLocation(context)
320
+ const data = turn?.data.get('turn-process')
321
+ if (turn === undefined || data === undefined) return null
322
+ const current = context.current.get('chat') as ChatNode | null | undefined
323
+ const state = context.state
324
+ if (current?.kind === 'turn-process'
325
+ && state !== undefined
326
+ && current.data.answerAnchorSeq === null
327
+ && current.data.controlAnchorSeq === state.controlAnchorSeq
328
+ && current.data.messageCount === state.messageCount
329
+ && current.data.toolCallCount === state.toolCallCount
330
+ && current.data.subagentCount === state.subagentCount
331
+ && turn.status !== 'closed'
332
+ && turn.steps.at(-1)?.status !== 'closed'
333
+ && current.location === (context.start?.location ?? context.matches[0]?.location)) return current
334
+ return chatNode(
335
+ context,
336
+ 'turn-process',
337
+ data.controlAnchorSeq + CHAT_SYNTHETIC_SEQ_OFFSETS.processControl,
338
+ data,
339
+ { groupTree: 'turn' },
340
+ )
341
+ },
342
+ }
343
+
344
+ /**
345
+ * Register the Turn-scoped process disclosure projection and its per-Step evidence record.
346
+ * @param ctx - owning UI Conversation context.
347
+ */
348
+ export function registerTurnProcess(ctx: Context): void {
349
+ const match = turnProcessDefinition.match.bind(turnProcessDefinition)
350
+ ctx.uiConversation.events.register({
351
+ ...turnProcessDefinition,
352
+ match: {
353
+ 'turn/start': match,
354
+ 'assistant/live-chunk': match,
355
+ 'assistant/message': match,
356
+ 'tool/call': match,
357
+ 'tool/result': match,
358
+ 'llm/retry': match,
359
+ 'step/start': match,
360
+ 'step/end': match,
361
+ 'turn/end': match,
362
+ },
363
+ })
364
+ const evidence = processEvidenceDefinition.match.bind(processEvidenceDefinition)
365
+ ctx.uiConversation.events.register({
366
+ ...processEvidenceDefinition,
367
+ match: {
368
+ 'assistant/message': evidence,
369
+ 'tool/call': evidence,
370
+ 'tool/result': evidence,
371
+ 'llm/retry': evidence,
372
+ },
373
+ })
374
+ }
@@ -0,0 +1,164 @@
1
+ import type { Context } from '@deepseek-ai/cordis'
2
+ import type {
3
+ ConversationMatch, ConversationNodeContext, ConversationNodeDefinition, TurnLocation,
4
+ } from '@deepseek-ai/dsh-client-ui-conversation/client'
5
+ import type {} from '@deepseek-ai/dsh-llm-retry/types'
6
+ import type { SessionEvent } from '@deepseek-ai/dsh-session/types'
7
+ import { deriveTurnTokenUsage } from '@deepseek-ai/dsh-token-meter/client'
8
+ import type {
9
+ AssistantChatData, FinalAssistantChatData, TurnTailChatData,
10
+ } from '../contract/chat-nodes.ts'
11
+ import { CHAT_SYNTHETIC_SEQ_OFFSETS, chatNode } from './common.ts'
12
+
13
+ declare module '../contract/chat-nodes.ts' {
14
+ interface ChatNodeDataMap {
15
+ /** Completed-turn actions and extension tail. */
16
+ 'turn-tail': TurnTailChatData
17
+ }
18
+ }
19
+
20
+ declare module '@deepseek-ai/dsh-client-ui-conversation/client' {
21
+ interface ConversationTurnDataMap {
22
+ /** Closing Assistant and footer facts derived for this completed Turn. */
23
+ 'turn-tail': TurnTailChatData
24
+ }
25
+ }
26
+
27
+ interface TurnTailState {
28
+ readonly turn: number
29
+ readonly end?: ConversationMatch
30
+ }
31
+
32
+ function isSessionEvent(event: ConversationMatch['event']): event is SessionEvent {
33
+ return event.type !== 'assistant/live-chunk'
34
+ }
35
+
36
+ function turnCoordinates(event: Parameters<ConversationNodeDefinition['match']>[0]): {
37
+ readonly turn: number
38
+ readonly step?: number
39
+ } | undefined {
40
+ if (event.type === 'assistant/message'
41
+ || event.type === 'assistant/attempt'
42
+ || event.type === 'assistant/live-chunk'
43
+ || event.type === 'step/start'
44
+ || event.type === 'step/end') {
45
+ return { turn: event.data.turn, step: event.data.step }
46
+ }
47
+ if (event.type === 'llm/retry' || event.type === 'llm/retry-started') {
48
+ return { turn: event.data.turn, step: event.data.step }
49
+ }
50
+ return undefined
51
+ }
52
+
53
+ function turnLocation(context: ConversationNodeContext<TurnTailState>): TurnLocation | undefined {
54
+ const location = context.start?.location ?? context.matches[0]?.location
55
+ return location?.kind === 'turn' || location?.kind === 'step' ? location.turn : undefined
56
+ }
57
+
58
+ function hasText(data: AssistantChatData): data is FinalAssistantChatData {
59
+ return data.finalNode !== undefined
60
+ && data.blocks.some(block => block.kind === 'text' && block.text.trim() !== '')
61
+ }
62
+
63
+ function tailData(context: ConversationNodeContext<TurnTailState>): TurnTailChatData | null {
64
+ const end = context.state === undefined
65
+ ? context.matches.find(match => match.event.type === 'turn/end')
66
+ : context.state.end
67
+ if (end?.event.type !== 'turn/end') return null
68
+ const turn = turnLocation(context)
69
+ if (turn === undefined) return null
70
+ const assistants = turn.steps
71
+ .map(step => step.data.get('assistant-step'))
72
+ .filter((candidate): candidate is Readonly<AssistantChatData> => candidate !== undefined)
73
+ const finalized = assistants
74
+ .filter((candidate): candidate is Readonly<FinalAssistantChatData> => candidate.finalNode !== undefined)
75
+ .sort((left, right) => left.finalNode.seq - right.finalNode.seq)
76
+ const closing = finalized.findLast(hasText) ?? null
77
+ let latestTranscriptSeq = finalized.at(-1)?.finalNode.seq
78
+ for (const match of context.matches) {
79
+ const event = match.event
80
+ const candidate = event.type === 'tool/call'
81
+ || (event.type === 'tool/result' && event.surfaceOp === 'append')
82
+ || (event.type === 'turn/end' && event.data.reason.kind === 'error')
83
+ || event.type === 'llm/retry'
84
+ ? event.seq
85
+ : undefined
86
+ if (candidate !== undefined && (latestTranscriptSeq === undefined || candidate > latestTranscriptSeq)) {
87
+ latestTranscriptSeq = candidate
88
+ }
89
+ }
90
+ const tokenUsage = context.start?.event.type === 'turn/start'
91
+ ? deriveTurnTokenUsage(context.matches.map(match => match.event).filter(isSessionEvent))
92
+ : undefined
93
+ return {
94
+ turn: end.event.data.turn,
95
+ seq: end.event.seq,
96
+ time: end.event.time,
97
+ closing,
98
+ branchUnavailable: closing === null || latestTranscriptSeq !== closing.finalNode.seq,
99
+ ...tokenUsage === undefined ? {} : { tokenUsage },
100
+ }
101
+ }
102
+
103
+ /** Completed-turn footer Definition independent of any Assistant row. */
104
+ export const turnTailDefinition: ConversationNodeDefinition<TurnTailState> = {
105
+ kind: 'turn-tail',
106
+ target: 'chat',
107
+ match: (event) => {
108
+ if (event.type === 'turn/start') return { id: String(event.data.turn), role: 'start' }
109
+ if (event.type === 'turn/end') return { id: String(event.data.turn), role: 'update' }
110
+ if (event.type === 'tool/call' || event.type === 'tool/result') {
111
+ return { id: String(event.data.turn), role: 'update' }
112
+ }
113
+ const coordinates = turnCoordinates(event)
114
+ if (coordinates !== undefined) return { id: String(coordinates.turn), role: 'update' }
115
+ return null
116
+ },
117
+ start: (_context, match) => {
118
+ if (match.event.type !== 'turn/start') throw new Error('turn-tail start requires turn/start')
119
+ return { turn: match.event.data.turn }
120
+ },
121
+ update: (context, match) => match.event.type === 'turn/end'
122
+ ? { ...context.state, end: match }
123
+ : context.state,
124
+ publication: match => match.event.type === 'turn/end' ? 'immediate' : 'none',
125
+ buildLocationData: (context, scope) => {
126
+ if (scope !== 'turn') return null
127
+ const value = tailData(context)
128
+ return value === null ? null : {
129
+ kind: 'turn',
130
+ turn: value.turn,
131
+ key: 'turn-tail',
132
+ value,
133
+ }
134
+ },
135
+ buildViewNode: (context) => {
136
+ const turn = turnLocation(context)
137
+ const data = turn?.data.get('turn-tail')
138
+ return data === undefined ? null : chatNode(context, 'turn-tail', data.seq + CHAT_SYNTHETIC_SEQ_OFFSETS.finalizedFollowup, data, { groupTree: 'turn' })
139
+ },
140
+ }
141
+
142
+ /**
143
+ * Register completed-Turn footer data and its Chat node contribution.
144
+ * @param ctx - owning UI Conversation context.
145
+ */
146
+ export function registerTurnTailConversationNode(ctx: Context): void {
147
+ const match = turnTailDefinition.match.bind(turnTailDefinition)
148
+ ctx.uiConversation.events.register({
149
+ ...turnTailDefinition,
150
+ match: {
151
+ 'turn/start': match,
152
+ 'turn/end': match,
153
+ 'tool/call': match,
154
+ 'tool/result': match,
155
+ 'assistant/message': match,
156
+ 'assistant/attempt': match,
157
+ 'assistant/live-chunk': match,
158
+ 'step/start': match,
159
+ 'step/end': match,
160
+ 'llm/retry': match,
161
+ 'llm/retry-started': match,
162
+ },
163
+ })
164
+ }