@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,298 @@
1
+ /** Area-local text gestures, action ownership, dismissal, and content-relative placement. */
2
+ import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react'
3
+ import type { RefObject } from 'react'
4
+ import { readTextSelection, selectedText } from './text-selection.ts'
5
+ import type { TextSelection } from './text-selection.ts'
6
+
7
+ import type {
8
+ TextInteractionGesture, TextInteractionSurface, TextInteractionTrigger,
9
+ } from '@deepseek-ai/dsh-client-ui-conversation/client'
10
+
11
+ /** Current area-owned surface and its actions. */
12
+ export interface TextInteractionBinding extends Omit<TextInteractionSurface, 'trigger'> {
13
+ readonly active: { readonly id: string; readonly trigger: TextInteractionTrigger } | null
14
+ }
15
+
16
+ interface Target {
17
+ readonly source: HTMLElement
18
+ readonly selection: TextSelection | null
19
+ readonly text: string | null
20
+ readonly point: { readonly x: number; readonly y: number } | null
21
+ }
22
+
23
+ interface Bounds { left: number; top: number; right: number; bottom: number }
24
+
25
+ function rectBounds(rect: DOMRect): Bounds {
26
+ return { left: rect.left, top: rect.top, right: rect.left + rect.width, bottom: rect.top + rect.height }
27
+ }
28
+
29
+ function intersects(a: Bounds, b: Bounds): boolean {
30
+ return a.right > b.left && a.left < b.right && a.bottom > b.top && a.top < b.bottom
31
+ }
32
+
33
+ function sameRange(a: Range | null, b: Range | null): boolean {
34
+ return a === b || (a !== null && b !== null && a.startContainer === b.startContainer
35
+ && a.startOffset === b.startOffset && a.endContainer === b.endContainer && a.endOffset === b.endOffset)
36
+ }
37
+
38
+ function available(root: HTMLElement, target: Target): boolean {
39
+ if (!root.isConnected || !root.contains(target.source) || !target.source.hasAttribute('data-text-interaction-source')) return false
40
+ const view = root.ownerDocument.defaultView
41
+ /* v8 ignore if -- Mounted browser content always has an owner window. */
42
+ if (view === null) return false
43
+ for (let node: HTMLElement | null = target.source; node !== null; node = node.parentElement) {
44
+ const style = view.getComputedStyle(node)
45
+ if (node.hidden || node.inert || node.hasAttribute('data-text-interaction-exclude')
46
+ || style.display === 'none' || style.visibility === 'hidden') return false
47
+ }
48
+ return target.selection === null || (target.source.contains(target.selection.range.startContainer)
49
+ && target.source.contains(target.selection.range.endContainer) && selectedText(target.selection) === target.text)
50
+ }
51
+
52
+ function composerSeat(root: HTMLElement): HTMLElement | null {
53
+ return root.closest('[data-conversation-scroll]')?.querySelector<HTMLElement>('[data-composer-seat]') ?? null
54
+ }
55
+
56
+ function visibleBounds(root: HTMLElement, source: HTMLElement, view: Window): Bounds {
57
+ const rootRect = rectBounds(root.getBoundingClientRect())
58
+ const bounds: Bounds = {
59
+ left: Math.max(0, rootRect.left), right: Math.min(view.innerWidth, rootRect.right), top: 0, bottom: view.innerHeight,
60
+ }
61
+ for (let node: HTMLElement | null = source; node !== null; node = node.parentElement) {
62
+ const style = view.getComputedStyle(node)
63
+ const rect = rectBounds(node.getBoundingClientRect())
64
+ if (/(auto|scroll|hidden|clip)/u.test(style.overflowX)) {
65
+ bounds.left = Math.max(bounds.left, rect.left)
66
+ bounds.right = Math.min(bounds.right, rect.right)
67
+ }
68
+ if (/(auto|scroll|hidden|clip)/u.test(style.overflowY)) {
69
+ bounds.top = Math.max(bounds.top, rect.top)
70
+ bounds.bottom = Math.min(bounds.bottom, rect.bottom)
71
+ }
72
+ }
73
+ const composer = composerSeat(root)?.getBoundingClientRect()
74
+ if (composer !== undefined && composer.height > 0
75
+ && composer.right > bounds.left && composer.left < bounds.right) {
76
+ bounds.bottom = Math.min(bounds.bottom, composer.top)
77
+ }
78
+ return bounds
79
+ }
80
+
81
+ /**
82
+ * Own text interactions for one positioned content area and its local surface.
83
+ * @param rootRef - existing content element with position: relative.
84
+ * @param surfaceRef - absolute surface inside that element; only the selected Slot consumer is mounted.
85
+ * @param dispatchInteraction - framework-injected plugin gesture dispatch.
86
+ * @param registeredIds - live registered owners used to dismiss removed plugins.
87
+ * @returns current owner and area-local selection actions.
88
+ */
89
+ export function useTextInteraction(
90
+ rootRef: RefObject<HTMLElement>, surfaceRef: RefObject<HTMLElement>,
91
+ dispatchInteraction: (gesture: TextInteractionGesture) => string | null,
92
+ registeredIds: readonly string[],
93
+ ): TextInteractionBinding {
94
+ const target = useRef<Target | null>(null)
95
+ const [active, setActive] = useState<TextInteractionBinding['active']>(null)
96
+ const dismiss = useCallback(() => {
97
+ target.current = null
98
+ if (surfaceRef.current !== null) surfaceRef.current.style.visibility = 'hidden'
99
+ setActive(null)
100
+ }, [surfaceRef])
101
+ useEffect(dismiss, [registeredIds, dispatchInteraction, dismiss])
102
+ const readText = useCallback(() => {
103
+ const root = rootRef.current
104
+ const current = target.current
105
+ if (root === null || current === null || !available(root, current)) return null
106
+ return current.selection === null ? null : selectedText(current.selection)
107
+ }, [rootRef])
108
+ const clearSelection = useCallback(() => { rootRef.current?.ownerDocument.getSelection()?.removeAllRanges() }, [rootRef])
109
+
110
+ const place = useCallback(() => {
111
+ const root = rootRef.current
112
+ const surface = surfaceRef.current
113
+ const current = target.current
114
+ if (root === null || surface === null || current === null) return
115
+ if (!available(root, current)) { dismiss(); return }
116
+ const view = root.ownerDocument.defaultView
117
+ /* v8 ignore if -- Mounted browser content always has an owner window. */
118
+ if (view === null) return
119
+ const visible = visibleBounds(root, current.source, view)
120
+ const selectionRects = current.selection === null ? [] : [...current.selection.range.getClientRects()]
121
+ const fallback = current.selection?.range.getBoundingClientRect() ?? current.source.getBoundingClientRect()
122
+ const rects = selectionRects.length === 0 ? [fallback] : selectionRects
123
+ const sourceRect = current.source.getBoundingClientRect()
124
+ const pointX = current.point === null ? 0 : sourceRect.left + current.point.x - current.source.scrollLeft
125
+ const pointY = current.point === null ? 0 : sourceRect.top + current.point.y - current.source.scrollTop
126
+ const anchor = current.point === null
127
+ ? rects.map(rectBounds).find(rect => intersects(rect, visible))
128
+ : { left: pointX, right: pointX + 1, top: pointY, bottom: pointY + 1 }
129
+ if (anchor === undefined || !intersects(anchor, visible) || visible.right <= visible.left || visible.bottom <= visible.top) {
130
+ surface.style.visibility = 'hidden'
131
+ return
132
+ }
133
+ const gap = 8
134
+ surface.style.maxWidth = `${visible.right - visible.left}px`
135
+ surface.style.maxHeight = `${visible.bottom - visible.top}px`
136
+ const size = surface.getBoundingClientRect()
137
+ const x = current.point === null
138
+ ? (Math.max(anchor.left, visible.left) + Math.min(anchor.right, visible.right) - size.width) / 2
139
+ : anchor.left
140
+ const above = anchor.top - gap - size.height
141
+ const below = anchor.bottom + gap
142
+ const preferredY = current.point === null && above >= visible.top ? above : below
143
+ const left = Math.max(visible.left, Math.min(x, visible.right - size.width))
144
+ const top = Math.max(visible.top, Math.min(preferredY, visible.bottom - size.height))
145
+ const rootRect = root.getBoundingClientRect()
146
+ const scaleX = root.offsetWidth === 0 ? 1 : rootRect.width / root.offsetWidth
147
+ const scaleY = root.offsetHeight === 0 ? 1 : rootRect.height / root.offsetHeight
148
+ surface.style.left = `${(left - rootRect.left) / scaleX - root.clientLeft + root.scrollLeft}px`
149
+ surface.style.top = `${(top - rootRect.top) / scaleY - root.clientTop + root.scrollTop}px`
150
+ surface.style.visibility = 'visible'
151
+ }, [dismiss, rootRef, surfaceRef])
152
+
153
+ // The surface's measured dimensions are needed after its Slot owner renders, before paint.
154
+ useLayoutEffect(place, [active, place])
155
+ useEffect(() => {
156
+ const root = rootRef.current
157
+ const surface = surfaceRef.current
158
+ if (root === null || surface === null) return
159
+ const document = root.ownerDocument
160
+ const view = document.defaultView
161
+ /* v8 ignore if -- Mounted browser content always has an owner window. */
162
+ if (view === null) return
163
+ let pointerSelecting = false
164
+ let keyboardSelecting = false
165
+ let selectionChangedDuringGesture = false
166
+ let previousRange: Range | null = null
167
+ let frame: number | undefined
168
+ const schedulePlacement = (): void => {
169
+ if (target.current === null || frame !== undefined) return
170
+ frame = view.requestAnimationFrame(() => { frame = undefined; place() })
171
+ }
172
+ const dispatch = (trigger: TextInteractionTrigger, next: Target, event: Event): void => {
173
+ if (!available(root, next)) return
174
+ const id = dispatchInteraction({
175
+ trigger, hasSelection: next.selection !== null,
176
+ readText: () => next.text,
177
+ preventDefault: () => { event.preventDefault() },
178
+ })
179
+ if (id === null) return
180
+ target.current = next
181
+ setActive({ id, trigger })
182
+ }
183
+ const updateSelection = (event: Event): void => {
184
+ if (pointerSelecting || keyboardSelecting) { selectionChangedDuringGesture = true; return }
185
+ if (target.current !== null && target.current.point !== null) return
186
+ if (target.current !== null && surface.contains(document.activeElement)) return
187
+ const selection = readTextSelection(root, document.getSelection())
188
+ const range = selection?.range ?? null
189
+ if (!selectionChangedDuringGesture && sameRange(previousRange, range)) return
190
+ selectionChangedDuringGesture = false
191
+ previousRange = range?.cloneRange() ?? null
192
+ dismiss()
193
+ if (selection === null) return
194
+ const text = selectedText(selection)
195
+ if (text === null) return
196
+ dispatch('selection', { source: selection.source, selection: { ...selection, range: selection.range.cloneRange() }, text, point: null }, event)
197
+ }
198
+ const insideSurface = (event: Event): boolean => event.composedPath().includes(surface)
199
+ const pointerDown = (event: PointerEvent): void => {
200
+ if (insideSurface(event)) return
201
+ const selection = document.getSelection()
202
+ previousRange = selection?.rangeCount === 1 ? selection.getRangeAt(0).cloneRange() : null
203
+ dismiss()
204
+ selectionChangedDuringGesture = false
205
+ pointerSelecting = event.button === 0 && event.target instanceof Node && root.contains(event.target)
206
+ }
207
+ const pointerUp = (event: PointerEvent): void => {
208
+ if (!pointerSelecting) return
209
+ pointerSelecting = false
210
+ updateSelection(event)
211
+ }
212
+ const cancel = (): void => { pointerSelecting = false; keyboardSelecting = false; dismiss() }
213
+ const keyDown = (event: KeyboardEvent): void => {
214
+ if (event.key === 'Escape') { cancel(); return }
215
+ if (insideSurface(event) || !(event.target instanceof Node) || !root.contains(event.target)) return
216
+ if (event.key === 'Shift' || event.shiftKey) { keyboardSelecting = true; dismiss() }
217
+ }
218
+ const keyUp = (event: KeyboardEvent): void => {
219
+ if (!keyboardSelecting || (event.key !== 'Shift' && event.shiftKey)) return
220
+ keyboardSelecting = false
221
+ updateSelection(event)
222
+ }
223
+ const contextMenu = (event: MouseEvent): void => {
224
+ if (insideSurface(event)) return
225
+ const element = event.target instanceof Element ? event.target : null
226
+ const source = element?.closest<HTMLElement>('[data-text-interaction-source]')
227
+ if (source === undefined || source === null || !root.contains(source)
228
+ || element?.closest('[data-text-interaction-exclude], button, input, textarea, [contenteditable="true"]')) return
229
+ pointerSelecting = false
230
+ dismiss()
231
+ const selected = readTextSelection(root, document.getSelection())
232
+ const keyboard = event.clientX === 0 && event.clientY === 0
233
+ const inSelection = selected?.source === source && (keyboard || [...selected.range.getClientRects()].some(rect =>
234
+ event.clientX >= rect.left && event.clientX <= rect.right && event.clientY >= rect.top && event.clientY <= rect.bottom))
235
+ const selection = inSelection ? selected : null
236
+ const bounds = source.getBoundingClientRect()
237
+ dispatch('contextmenu', {
238
+ source, selection: selection === null ? null : { ...selection, range: selection.range.cloneRange() },
239
+ text: selection === null ? null : selectedText(selection),
240
+ point: {
241
+ x: (keyboard ? 0 : event.clientX - bounds.left) + source.scrollLeft,
242
+ y: (keyboard ? 0 : event.clientY - bounds.top) + source.scrollTop,
243
+ },
244
+ }, event)
245
+ }
246
+ document.addEventListener('selectionchange', updateSelection)
247
+ document.addEventListener('pointerdown', pointerDown, true)
248
+ document.addEventListener('pointerup', pointerUp)
249
+ document.addEventListener('pointercancel', cancel)
250
+ document.addEventListener('keydown', keyDown)
251
+ document.addEventListener('keyup', keyUp)
252
+ document.addEventListener('scroll', schedulePlacement, true)
253
+ root.addEventListener('contextmenu', contextMenu)
254
+ view.addEventListener('resize', schedulePlacement)
255
+ view.addEventListener('blur', cancel)
256
+ return () => {
257
+ document.removeEventListener('selectionchange', updateSelection)
258
+ document.removeEventListener('pointerdown', pointerDown, true)
259
+ document.removeEventListener('pointerup', pointerUp)
260
+ document.removeEventListener('pointercancel', cancel)
261
+ document.removeEventListener('keydown', keyDown)
262
+ document.removeEventListener('keyup', keyUp)
263
+ document.removeEventListener('scroll', schedulePlacement, true)
264
+ root.removeEventListener('contextmenu', contextMenu)
265
+ view.removeEventListener('resize', schedulePlacement)
266
+ view.removeEventListener('blur', cancel)
267
+ if (frame !== undefined) view.cancelAnimationFrame(frame)
268
+ }
269
+ }, [dismiss, place, rootRef, surfaceRef, dispatchInteraction])
270
+ useEffect(() => {
271
+ const root = rootRef.current
272
+ const surface = surfaceRef.current
273
+ if (active === null || root === null || surface === null) return
274
+ const view = root.ownerDocument.defaultView
275
+ /* v8 ignore if -- Mounted browser content always has an owner window. */
276
+ if (view === null) return
277
+ let frame: number | undefined
278
+ const schedule = (): void => {
279
+ if (frame !== undefined) return
280
+ frame = view.requestAnimationFrame(() => { frame = undefined; place() })
281
+ }
282
+ const resize = new ResizeObserver(schedule)
283
+ resize.observe(root)
284
+ resize.observe(surface)
285
+ const composer = composerSeat(root)
286
+ if (composer !== null) resize.observe(composer)
287
+ const mutations = new MutationObserver((records) => {
288
+ if (records.some(record => !surface.contains(record.target))) schedule()
289
+ })
290
+ mutations.observe(root, { childList: true, subtree: true, characterData: true, attributes: true })
291
+ return () => {
292
+ resize.disconnect()
293
+ mutations.disconnect()
294
+ if (frame !== undefined) view.cancelAnimationFrame(frame)
295
+ }
296
+ }, [active, place, rootRef, surfaceRef])
297
+ return { active, dismiss, readText, clearSelection }
298
+ }
@@ -0,0 +1,180 @@
1
+ /** DOM selection validation and visible-text projection, independent of business actions. */
2
+
3
+ const PROJECTED_BLOCK_TAGS = new Set([
4
+ 'ADDRESS', 'ARTICLE', 'ASIDE', 'BLOCKQUOTE', 'DD', 'DIV', 'DL', 'DT', 'FIGCAPTION',
5
+ 'FIGURE', 'FOOTER', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'HEADER', 'LI', 'MAIN',
6
+ 'NAV', 'OL', 'P', 'PRE', 'SECTION', 'TABLE', 'TBODY', 'TFOOT', 'THEAD', 'TR', 'UL',
7
+ ])
8
+ const PROJECTED_CELL_TAGS = new Set(['TD', 'TH'])
9
+
10
+ function excluded(element: Element): boolean {
11
+ if (element.matches('.katex-mathml, [data-text-interaction-exclude], [hidden], .sr-only')) return true
12
+ if (element.matches('[aria-hidden="true"]') && !element.matches('.katex-html')) return true
13
+ return element.tagName === 'BUTTON' && element.parentElement?.tagName !== 'CODE'
14
+ }
15
+
16
+ function projectedBoundary(node: Node): '\n' | '\t' | '' {
17
+ if (!(node instanceof Element)) return ''
18
+ if (PROJECTED_CELL_TAGS.has(node.tagName)) return '\t'
19
+ return PROJECTED_BLOCK_TAGS.has(node.tagName) ? '\n' : ''
20
+ }
21
+
22
+ function projectedSeparator(previous: Node, current: Node): '\n' | '\t' | '' {
23
+ const left = projectedBoundary(previous)
24
+ const right = projectedBoundary(current)
25
+ if (left === '\n' || right === '\n') return '\n'
26
+ return left === '\t' || right === '\t' ? '\t' : ''
27
+ }
28
+
29
+ interface ProjectedText {
30
+ readonly text: string
31
+ readonly offsets: readonly number[]
32
+ }
33
+
34
+ function projectedText(node: Text): ProjectedText {
35
+ const source = node.data
36
+ const parent = node.parentElement
37
+ const view = node.ownerDocument.defaultView
38
+ const whiteSpace = parent === null || view === null ? '' : view.getComputedStyle(parent).whiteSpace
39
+ const preservesBreaks = whiteSpace === 'pre' || whiteSpace === 'pre-wrap'
40
+ || whiteSpace === 'pre-line' || whiteSpace === 'break-spaces'
41
+ const offsets = new Array<number>(source.length + 1).fill(0)
42
+ const structuralWhitespace = !preservesBreaks
43
+ && /^[\t\n\f\r ]*$/u.test(source)
44
+ && [node.previousSibling, node.nextSibling].some(
45
+ sibling => sibling !== null && projectedBoundary(sibling) !== '',
46
+ )
47
+ if (structuralWhitespace) return { text: '', offsets }
48
+ let text = ''
49
+ let cursor = 0
50
+ if (!preservesBreaks && node.previousSibling instanceof HTMLElement
51
+ && node.previousSibling.tagName === 'BR' && source.startsWith('\n')) {
52
+ cursor = 1
53
+ }
54
+ while (cursor < source.length) {
55
+ const softBreak = preservesBreaks ? null : /^[ \t]*[\r\n]+[ \t]*/u.exec(source.slice(cursor))
56
+ if (softBreak !== null) {
57
+ const end = cursor + softBreak[0].length
58
+ for (let index = cursor; index < end; index++) offsets[index] = text.length
59
+ text += ' '
60
+ offsets[end] = text.length
61
+ cursor = end
62
+ continue
63
+ }
64
+ offsets[cursor] = text.length
65
+ text += source.charAt(cursor)
66
+ cursor += 1
67
+ offsets[cursor] = text.length
68
+ }
69
+ return { text, offsets }
70
+ }
71
+
72
+ interface ProjectedTextSpan {
73
+ readonly node: Text
74
+ readonly start: number
75
+ readonly offsets: readonly number[]
76
+ }
77
+
78
+ interface ProjectedFragment {
79
+ readonly text: string
80
+ readonly spans: readonly ProjectedTextSpan[]
81
+ readonly boundaries: readonly (readonly [Node, readonly number[]])[]
82
+ }
83
+
84
+ function projectedFragment(node: Node): ProjectedFragment {
85
+ if (node.nodeType === Node.TEXT_NODE) {
86
+ const projected = projectedText(node as Text)
87
+ return {
88
+ text: projected.text,
89
+ spans: projected.offsets.length <= 1
90
+ ? []
91
+ : [{ node: node as Text, start: 0, offsets: projected.offsets }],
92
+ boundaries: [],
93
+ }
94
+ }
95
+ if (!(node instanceof Element)) {
96
+ return { text: '', spans: [], boundaries: [] }
97
+ }
98
+ if (excluded(node)) return { text: '', spans: [], boundaries: [] }
99
+ if (node.tagName === 'BR') return { text: '\n', spans: [], boundaries: [] }
100
+ let text = ''
101
+ let previous: Node | null = null
102
+ const spans: ProjectedTextSpan[] = []
103
+ const boundaries: Array<readonly [Node, readonly number[]]> = []
104
+ const offsets = new Array<number>(node.childNodes.length + 1).fill(0)
105
+ for (const [index, child] of [...node.childNodes].entries()) {
106
+ const fragment = projectedFragment(child)
107
+ if (fragment.text !== '' && previous !== null) {
108
+ const separator = projectedSeparator(previous, child)
109
+ const needsSeparator = separator === '\n'
110
+ ? !text.endsWith('\n') && !fragment.text.startsWith('\n')
111
+ : separator === '\t' && !/[\t\n]$/u.test(text) && !/^[\t\n]/u.test(fragment.text)
112
+ if (needsSeparator) text += separator
113
+ }
114
+ offsets[index] = text.length
115
+ const base = text.length
116
+ text += fragment.text
117
+ for (const span of fragment.spans) {
118
+ spans.push({ node: span.node, start: base + span.start, offsets: span.offsets })
119
+ }
120
+ for (const [owner, childOffsets] of fragment.boundaries) {
121
+ boundaries.push([owner, childOffsets.map(offset => base + offset)])
122
+ }
123
+ if (fragment.text !== '') previous = child
124
+ offsets[index + 1] = text.length
125
+ }
126
+ boundaries.push([node, offsets])
127
+ return { text, spans, boundaries }
128
+ }
129
+
130
+ function projectedOffset(
131
+ projection: ProjectedFragment,
132
+ container: Node,
133
+ offset: number,
134
+ ): number | null {
135
+ if (container.nodeType === Node.TEXT_NODE) {
136
+ const span = projection.spans.find(candidate => candidate.node === container)
137
+ const projected = span?.offsets[offset]
138
+ return span === undefined || projected === undefined ? null : span.start + projected
139
+ }
140
+ const boundaries = projection.boundaries.find(([owner]) => owner === container)?.[1]
141
+ return boundaries?.[offset] ?? null
142
+ }
143
+
144
+ /** One browser range contained by an enabled text source. */
145
+ export interface TextSelection {
146
+ readonly source: HTMLElement
147
+ readonly range: Range
148
+ }
149
+
150
+ /**
151
+ * Find a single noncollapsed selection inside one enabled source.
152
+ * @param root - mounted interaction area.
153
+ * @param selection - browser selection in that area's document.
154
+ * @returns the selected source and range, or null across sources and excluded content.
155
+ */
156
+ export function readTextSelection(root: HTMLElement, selection: Selection | null): TextSelection | null {
157
+ if (selection === null || selection.rangeCount !== 1 || selection.isCollapsed) return null
158
+ const range = selection.getRangeAt(0)
159
+ const sourceOf = (node: Node): HTMLElement | null =>
160
+ (node instanceof Element ? node : node.parentElement)?.closest<HTMLElement>('[data-text-interaction-source]') ?? null
161
+ const source = sourceOf(range.startContainer)
162
+ if (source === null || source !== sourceOf(range.endContainer) || !root.contains(source)
163
+ || source.closest('[hidden], [inert], [data-text-interaction-exclude]') !== null) return null
164
+ return { source, range }
165
+ }
166
+
167
+ /**
168
+ * Project selected DOM text with visible block boundaries and without renderer chrome.
169
+ * @param selection - range and its source, obtained through readTextSelection.
170
+ * @returns trimmed visible text; empty or excluded selections return null.
171
+ */
172
+ export function selectedText(selection: TextSelection): string | null {
173
+ const { source, range } = selection
174
+ const projection = projectedFragment(source)
175
+ const start = projectedOffset(projection, range.startContainer, range.startOffset)
176
+ const end = projectedOffset(projection, range.endContainer, range.endOffset)
177
+ if (start === null || end === null) return null
178
+ const text = projection.text.slice(start, end).trim()
179
+ return text === '' ? null : text
180
+ }
@@ -0,0 +1,98 @@
1
+ import type { ChatViewSlotProps } from '../contract/slots.ts'
2
+
3
+ /**
4
+ * Compact token count: 517 / 12.2K / 517K / 1.2M.
5
+ * @param value - non-negative token count.
6
+ * @param t - Chat locale seat.
7
+ * @returns locale-owned compact display string.
8
+ */
9
+ export function formatTokens(value: number, t: ChatViewSlotProps['t']): string {
10
+ const scaled = (candidate: number): string =>
11
+ candidate >= 100 ? String(Math.round(candidate)) : String(Math.round(candidate * 10) / 10)
12
+ if (value < 1_000) return String(value)
13
+ if (value < 1_000_000) return t('number.thousand', { value: scaled(value / 1_000) })
14
+ return t('number.million', { value: scaled(value / 1_000_000) })
15
+ }
16
+
17
+ /**
18
+ * Exact integer token count with locale-owned digit grouping.
19
+ * @param value - non-negative safe integer token count.
20
+ * @param t - Chat locale seat.
21
+ * @returns an unrounded display string.
22
+ */
23
+ export function formatExactTokens(value: number, t: ChatViewSlotProps['t']): string {
24
+ const digits = String(value)
25
+ const groups: string[] = []
26
+ for (let end = digits.length; end > 0; end -= 3) {
27
+ groups.unshift(digits.slice(Math.max(0, end - 3), end))
28
+ }
29
+ return groups.join(t('number.groupSeparator'))
30
+ }
31
+
32
+ /** Round a cache-read ratio to exact percentage units, with positive ties rounded up. */
33
+ function roundedPercentUnits(cacheReadTokens: number, denominator: number, decimalPlaces: 0 | 1): number {
34
+ const unitsPerPercent = decimalPlaces === 0 ? 1 : 10
35
+ const scale = unitsPerPercent * 100
36
+ const doubledScale = scale * 2
37
+ const denominatorQuotient = Math.floor(denominator / doubledScale)
38
+ const denominatorRemainder = denominator % doubledScale
39
+ let lower = 0
40
+ let upper = scale
41
+ while (lower < upper) {
42
+ const candidate = Math.floor((lower + upper + 1) / 2)
43
+ const factor = candidate * 2 - 1
44
+ const threshold = factor * denominatorQuotient
45
+ + Math.ceil(factor * denominatorRemainder / doubledScale)
46
+ if (cacheReadTokens >= threshold) lower = candidate
47
+ else upper = candidate - 1
48
+ }
49
+ return lower
50
+ }
51
+
52
+ function displayPercentUnits(units: number, decimalPlaces: 0 | 1): string {
53
+ if (decimalPlaces === 0) return String(units)
54
+ const whole = Math.floor(units / 10)
55
+ const tenths = units % 10
56
+ return tenths === 0 ? String(whole) : `${whole}.${tenths}`
57
+ }
58
+
59
+ /**
60
+ * Display-ready cache-hit share without rounding a partial hit to 100%.
61
+ * @param cacheReadTokens - exact prompt tokens served from cache.
62
+ * @param promptTokens - exact aggregate prompt tokens.
63
+ * @param decimalPlaces - ordinary-ratio precision; partial hits that would
64
+ * round to 100 automatically use enough additional precision to stay honest.
65
+ * @returns percentage text, or null when there was no prompt input.
66
+ */
67
+ export function formatCacheHitPercent(
68
+ cacheReadTokens: number,
69
+ promptTokens: number,
70
+ decimalPlaces: 0 | 1 = 0,
71
+ ): string | null {
72
+ if (promptTokens === 0) return null
73
+ const missedInputTokens = promptTokens - cacheReadTokens
74
+ if (missedInputTokens === 0) return '100'
75
+
76
+ const roundedUnits = roundedPercentUnits(cacheReadTokens, promptTokens, decimalPlaces)
77
+ const fullHitUnits = decimalPlaces === 0 ? 100 : 1_000
78
+ if (roundedUnits < fullHitUnits) return displayPercentUnits(roundedUnits, decimalPlaces)
79
+
80
+ let distinguishingPlaces = 1
81
+ let scaledDoubleGap = missedInputTokens * 200
82
+ const denominatorTens = Math.floor(promptTokens / 10)
83
+ while (scaledDoubleGap <= denominatorTens) {
84
+ scaledDoubleGap *= 10
85
+ distinguishingPlaces += 1
86
+ }
87
+ const denominatorOnes = promptTokens % 10
88
+ let roundedLoss = 5
89
+ for (let loss = 1; loss < 5; loss += 1) {
90
+ const factor = loss * 2 + 1
91
+ const threshold = factor * denominatorTens + Math.floor(factor * denominatorOnes / 10)
92
+ if (scaledDoubleGap <= threshold) {
93
+ roundedLoss = loss
94
+ break
95
+ }
96
+ }
97
+ return `99.${'9'.repeat(distinguishingPlaces - 1)}${10 - roundedLoss}`
98
+ }
@@ -0,0 +1,10 @@
1
+ import type { AssistantBlock } from '../contract/snapshot.ts'
2
+
3
+ /**
4
+ * Collect visible prose from one Assistant lifecycle.
5
+ * @param blocks - Assistant content blocks.
6
+ * @returns concatenated text blocks.
7
+ */
8
+ export function assistantText(blocks: readonly AssistantBlock[]): string {
9
+ return blocks.flatMap(block => block.kind === 'text' ? [block.text] : []).join('')
10
+ }
@@ -0,0 +1,89 @@
1
+ /**
2
+ * View-layer union of the host turn outline and the loaded rail items. The
3
+ * conversation snapshot never carries projection values, so this merge is the
4
+ * one place the rail's two sources meet: the `turnOutline` projection names
5
+ * every turn of the session, and the loaded window supplies anchors and
6
+ * richer previews for the turns it holds.
7
+ */
8
+
9
+ import type {} from '@deepseek-ai/dsh-session-turn-outline/client'
10
+ import { SessionSeq } from '@deepseek-ai/dsh-session/types'
11
+ import type { TurnNavigationItem } from '../contract/snapshot.ts'
12
+
13
+ /** One rail mark: a loaded Turn scrolls to its row; an unloaded one pages history through its seq first. */
14
+ export interface TurnRailItem {
15
+ readonly turn: number
16
+ /** Bounded prompt preview (loaded window first, outline fallback). */
17
+ readonly prompt: string
18
+ /** Bounded response preview (loaded window first, outline fallback). */
19
+ readonly response: string
20
+ /** How the rail reaches the Turn. */
21
+ readonly anchor:
22
+ | { readonly kind: 'loaded'; readonly key: string }
23
+ | { readonly kind: 'unloaded'; readonly seq: SessionSeq }
24
+ }
25
+
26
+ const EMPTY_ITEMS: readonly TurnRailItem[] = []
27
+
28
+ /**
29
+ * Structurally narrow one wire outline entry (projection values cross the
30
+ * wire). `turn` and `seq` are the load-bearing fields — a mark cannot exist
31
+ * or jump without them — so their damage drops the entry; the previews are
32
+ * decorative, so a malformed one degrades to `''` and the turn stays
33
+ * navigable by number.
34
+ */
35
+ function outlineEntry(value: unknown): { turn: number; seq: SessionSeq; prompt: string; response: string } | undefined {
36
+ if (typeof value !== 'object' || value === null) return undefined
37
+ const entry = value as { turn?: unknown; seq?: unknown; prompt?: unknown; response?: unknown }
38
+ if (typeof entry.turn !== 'number' || !Number.isSafeInteger(entry.turn) || entry.turn < 0) return undefined
39
+ if (typeof entry.seq !== 'number' || !Number.isSafeInteger(entry.seq) || entry.seq < 0 || Object.is(entry.seq, -0)) return undefined
40
+ return {
41
+ turn: entry.turn,
42
+ seq: SessionSeq(entry.seq),
43
+ prompt: typeof entry.prompt === 'string' ? entry.prompt : '',
44
+ response: typeof entry.response === 'string' ? entry.response : '',
45
+ }
46
+ }
47
+
48
+ /** Wire outline entries, or none when the projection is absent or malformed. */
49
+ function outlineEntries(outline: unknown): readonly unknown[] {
50
+ return Array.isArray(outline) ? outline : EMPTY_ITEMS
51
+ }
52
+
53
+ /**
54
+ * Merge the host outline with the loaded rail items into the full ladder.
55
+ * A turn present in both sides keeps the loaded anchor, taking an outline
56
+ * preview only where the window's own is empty (a mid-Turn window head, or a
57
+ * turn whose loaded nodes carry no text); turns on one side only pass
58
+ * through. Result ascends by turn.
59
+ * @param loaded - loaded-window rail items (timeline order).
60
+ * @param outline - `turnOutline` projection value, treated as wire data.
61
+ * @returns every known turn, ascending; a stable empty array when none.
62
+ */
63
+ export function mergeTurnRailItems(
64
+ loaded: readonly TurnNavigationItem[],
65
+ outline: unknown,
66
+ ): readonly TurnRailItem[] {
67
+ const byTurn = new Map<number, TurnRailItem>()
68
+ for (const raw of outlineEntries(outline)) {
69
+ const entry = outlineEntry(raw)
70
+ if (entry === undefined) continue
71
+ byTurn.set(entry.turn, {
72
+ turn: entry.turn,
73
+ prompt: entry.prompt,
74
+ response: entry.response,
75
+ anchor: { kind: 'unloaded', seq: entry.seq },
76
+ })
77
+ }
78
+ for (const item of loaded) {
79
+ const preview = byTurn.get(item.turn)
80
+ byTurn.set(item.turn, {
81
+ turn: item.turn,
82
+ prompt: item.prompt !== '' ? item.prompt : preview?.prompt ?? '',
83
+ response: item.response !== '' ? item.response : preview?.response ?? '',
84
+ anchor: { kind: 'loaded', key: item.anchorKey },
85
+ })
86
+ }
87
+ if (byTurn.size === 0) return EMPTY_ITEMS
88
+ return [...byTurn.values()].sort((left, right) => left.turn - right.turn)
89
+ }