@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,556 @@
1
+ /**
2
+ * Fold transitions owned by one Chat viewport. Every batch containing a closing row moves its boxes and
3
+ * the scrollport on one frame clock; a batch that only reveals rows, or a viewport without a reading
4
+ * policy, uses CSS transitions. Motion is opt-in under `[data-chat-motion]`, respects reduced motion,
5
+ * and clears temporary styles.
6
+ */
7
+ import { useCallback, useLayoutEffect, useRef, type RefObject } from 'react'
8
+ import { useSearchableHidden, type HiddenTransition } from './searchable-hidden.ts'
9
+
10
+ const FADE_OUT_MS = 70
11
+ /** The box starts closing while the fade finishes; by then the row is nearly transparent. */
12
+ const CLOSE_DELAY_MS = 50
13
+ const CLOSE_MS = 110
14
+ const SETTLE_SLACK_MS = 80
15
+ const MOTION_SCOPE = '[data-chat-motion]'
16
+ const EASING = 'cubic-bezier(0.4, 0, 0.2, 1)'
17
+
18
+ /** Row-local operations supplied by the containing viewport. */
19
+ export interface FlowMotionRows {
20
+ /** @param element - visible row. @param done - commits hidden state before idle callbacks run. */
21
+ collapse(element: HTMLElement, done: () => void): void
22
+ /** @param element - newly visible row to grow to its natural size. */
23
+ reveal(element: HTMLElement): void
24
+ /** @param element - row whose active transition should be cancelled without hiding it. */
25
+ cancelMotion(element: HTMLElement): void
26
+ /**
27
+ * Hide a row at once, outside a motion scope; the owning viewport measures the layout first.
28
+ * @param element - visible row.
29
+ * @param commit - applies the hidden state.
30
+ */
31
+ hideNow?(element: HTMLElement, commit: () => void): void
32
+ }
33
+
34
+ /** Geometry captured before one fold batch changes its boxes. */
35
+ export interface InputFoldBox {
36
+ readonly element: HTMLElement
37
+ readonly height: number
38
+ readonly marginTop: number
39
+ readonly closing: boolean
40
+ }
41
+
42
+ /** The viewport moves on the same progress that changes the folded boxes. */
43
+ export interface InputFoldDriver {
44
+ /**
45
+ * Capture geometry and choose the landing before the frame clock changes the boxes.
46
+ * @param boxes - non-nested boxes whose layout changes on this clock.
47
+ * @returns closing boxes that scroll with the content and stay opaque; the rest fade in place. The driver
48
+ * may add boxes while the batch runs, when a newer tail request takes it over.
49
+ */
50
+ begin(boxes: readonly InputFoldBox[]): ReadonlySet<HTMLElement>
51
+ /**
52
+ * Reserve scroll range before box writes.
53
+ * @param progress - shared eased progress from zero to one.
54
+ * @param cancelled - a reading gesture stopped a tail landing's automatic target; a landing that keeps
55
+ * the reader's content still continues and includes the reader's own movement.
56
+ */
57
+ prepare(progress: number, cancelled: boolean): void
58
+ /**
59
+ * Apply viewport geometry after box writes.
60
+ * @param progress - shared eased progress from zero to one.
61
+ * @param cancelled - a reading gesture stopped a tail landing's automatic target.
62
+ * @returns actual scrollTop displacement from the batch start, for closing-content visual compensation.
63
+ */
64
+ frame(progress: number, cancelled: boolean): number
65
+ /**
66
+ * Install the final geometry after the last frame or cancellation.
67
+ * @param cancelled - a reading gesture stopped the automatic target, every closing row reopened, or the
68
+ * viewport detached; the driver commits no obsolete landing.
69
+ */
70
+ finish(cancelled: boolean): void
71
+ }
72
+
73
+ /** Animation lifetime and fold coordination for one viewport. */
74
+ export interface FlowMotion extends FlowMotionRows {
75
+ /** @returns whether owned transitions or a scheduled, running, or settling batch remain active. */
76
+ active(): boolean
77
+ /** @returns whether a row owned by this viewport is closing. */
78
+ foldActive(): boolean
79
+ /** @param listener - callback after the last fold. @returns cancellation for a pending callback. */
80
+ onFoldIdle(listener: () => void): () => void
81
+ /** Stop the running batch's automatic target while letting its boxes finish. */
82
+ cancelInput(): void
83
+ /** Restore the running batch's automatic target after a newer request takes it over. */
84
+ resumeInput(): void
85
+ /** @returns whether a fold batch runs, or one is scheduled for this commit's closing rows. */
86
+ inputActive(): boolean
87
+ /** Cancel owned animations and pending work when the viewport detaches. */
88
+ clear(): void
89
+ }
90
+
91
+ /**
92
+ * Decide whether a row may animate: inside a live scope and not under reduced motion.
93
+ * @param element - row about to be hidden.
94
+ * @returns whether the fade-then-close transition applies.
95
+ */
96
+ export function motionEnabled(element: HTMLElement): boolean {
97
+ if (element.closest(MOTION_SCOPE) === null) return false
98
+ return typeof matchMedia !== 'function' || !matchMedia('(prefers-reduced-motion: reduce)').matches
99
+ }
100
+
101
+ /**
102
+ * Whether a row is already hidden or on its way there.
103
+ * @param element - row under Turn-level visibility control.
104
+ * @returns hidden attribute present or a collapse transition outstanding.
105
+ */
106
+ export function hiddenOrCollapsing(element: HTMLElement): boolean {
107
+ return element.hasAttribute('hidden') || element.dataset.chatMotion === 'collapse'
108
+ }
109
+
110
+ /**
111
+ * Opacity of a revealing box at batch progress, continuing from the share its own transition reached.
112
+ * @param box - revealing box.
113
+ * @param progress - shared eased progress from zero to one.
114
+ * @returns opacity from zero to one.
115
+ */
116
+ function revealedShare(box: OwnedBox, progress: number): number {
117
+ const start = box.height === 0 ? 0 : box.fromHeight / box.height
118
+ return start + (1 - start) * progress
119
+ }
120
+
121
+ /** A box this viewport owns until it finishes or is cancelled. */
122
+ interface OwnedBox {
123
+ readonly element: HTMLElement
124
+ /**
125
+ * Full size: a closing box shrinks from it, a revealing box grows to it. A batch re-measures a closing
126
+ * box's current size when it takes the box over.
127
+ */
128
+ height: number
129
+ marginTop: number
130
+ /** Size a revealing box had already reached on its own transition when a batch took it over. */
131
+ fromHeight: number
132
+ fromMarginTop: number
133
+ readonly closing: boolean
134
+ /** The box changed while a batch ran; it waits without a CSS transition until the next batch. */
135
+ held: boolean
136
+ /** Start a held revealing box's own transition when no batch will drive it. */
137
+ release(): void
138
+ /** Stop the box's own transition and fallback timer before a batch drives it. */
139
+ take(): void
140
+ finish(): void
141
+ }
142
+
143
+ /**
144
+ * Create animation coordination without cross-viewport broadcasts.
145
+ * @param driver - the viewport's driver for the next batch; null while detached.
146
+ * @param foldingChanged - disable or restore this viewport's native scroll anchoring.
147
+ * @param beforeInstantHide - measures the layout before a row hides at once outside a motion scope.
148
+ * @returns stable callbacks and cleanup for this viewport's animations.
149
+ */
150
+ export function createFlowMotion(
151
+ driver: () => InputFoldDriver | null, foldingChanged: (active: boolean) => void,
152
+ beforeInstantHide?: (element: HTMLElement) => void,
153
+ ): FlowMotion {
154
+ const running = new Map<HTMLElement, () => void>()
155
+ let folding = 0
156
+ const foldIdleListeners = new Set<() => void>()
157
+ let batchScheduled = false
158
+ const boxes = new Map<HTMLElement, OwnedBox>()
159
+ let frameRequest: number | null = null
160
+ let batch = false
161
+ let cancelled = false
162
+ let clearEpoch = 0
163
+ let batchCleanup: (() => void) | null = null
164
+ let cancelEmptyBatch: (() => void) | null = null
165
+ /** The batch is committing hidden rows and its final geometry; idle listeners wait until both land. */
166
+ let settling = false
167
+ let anchoringDisabled = false
168
+
169
+ function cancelInput(): void {
170
+ if (batch) cancelled = true
171
+ }
172
+
173
+ function resumeInput(): void {
174
+ if (batch) cancelled = false
175
+ }
176
+
177
+ /** Rows inside a closing ancestor change with it and never join a batch on their own. */
178
+ function batchMember(box: InputFoldBox): boolean {
179
+ return box.element.parentElement?.closest('[data-chat-motion="collapse"]') === null
180
+ }
181
+
182
+ /** @returns whether a batch started; without a closing member the caller settles held rows itself. */
183
+ function runBatch(current: InputFoldDriver): boolean {
184
+ // Every member continues from the size it has now, so the driver's measured layout and its change
185
+ // amounts describe the same boxes: a closing box may have moved on its own transition, and a revealing
186
+ // box may have grown part of the way on its own transition.
187
+ for (const box of [...boxes.values()]) {
188
+ if (!batchMember(box)) continue
189
+ // A row that finished closing is `hidden="until-found"`, which skips its contents without removing
190
+ // their boxes: a box under it still reports its own size but contributes nothing to the flow.
191
+ if (box.element.parentElement?.closest('[hidden]') != null) {
192
+ box.finish()
193
+ continue
194
+ }
195
+ const height = box.element.offsetHeight
196
+ const marginTop = Number.parseFloat(getComputedStyle(box.element).marginTop) || 0
197
+ if (!box.closing) {
198
+ box.fromHeight = Math.min(height, box.height)
199
+ box.fromMarginTop = Math.min(marginTop, box.marginTop)
200
+ continue
201
+ }
202
+ box.height = height
203
+ box.marginTop = marginTop
204
+ if (height === 0 && marginTop === 0) box.finish()
205
+ }
206
+ const owned = [...boxes.values()]
207
+ const members = owned.filter(batchMember)
208
+ .sort((left, right) => left.element.compareDocumentPosition(right.element) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1)
209
+ if (!members.some(box => box.closing)) return false
210
+ batch = true
211
+ cancelled = false
212
+ const travelling = current.begin(members.map(box => box.closing ? box : {
213
+ element: box.element,
214
+ height: box.height - box.fromHeight,
215
+ marginTop: box.marginTop - box.fromMarginTop,
216
+ closing: false,
217
+ }))
218
+ batchCleanup = () => { current.finish(true) }
219
+ for (const box of owned) box.take()
220
+ for (const box of members) {
221
+ box.element.style.transition = 'none'
222
+ box.element.style.height = `${box.closing ? box.height : box.fromHeight}px`
223
+ box.element.style.marginTop = `${box.closing ? box.marginTop : box.fromMarginTop}px`
224
+ box.element.style.opacity = box.closing ? '1' : String(revealedShare(box, 0))
225
+ }
226
+ const memberSet = new Set(members)
227
+ const settledTravel = new Set<HTMLElement>()
228
+ // A travelling box clips its content as it shrinks, so nested closing rows keep their size until it ends.
229
+ const freezeTravelling = (): void => {
230
+ for (const element of travelling) {
231
+ if (settledTravel.has(element)) continue
232
+ settledTravel.add(element)
233
+ element.style.translate = ''
234
+ for (const box of owned) {
235
+ if (memberSet.has(box) || !element.contains(box.element)) continue
236
+ box.element.style.transition = 'none'
237
+ box.element.style.height = `${box.height}px`
238
+ box.element.style.marginTop = `${box.marginTop}px`
239
+ box.element.style.opacity = '1'
240
+ }
241
+ }
242
+ }
243
+ freezeTravelling()
244
+ const reduced = typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches
245
+ let started: number | undefined
246
+ let displacement = 0
247
+ const settle = (finishCancelled: boolean): void => {
248
+ batch = false
249
+ batchCleanup = null
250
+ cancelEmptyBatch = null
251
+ settling = true
252
+ try {
253
+ for (const box of owned) if (boxes.get(box.element) === box) box.finish()
254
+ current.finish(finishCancelled)
255
+ } finally {
256
+ settling = false
257
+ }
258
+ if (folding === 0) notifyIdle()
259
+ // Rows that changed while this batch ran wait in place; the next flush drives or releases them.
260
+ if ([...boxes.values()].some(box => box.held)) flushBatch()
261
+ }
262
+ cancelEmptyBatch = () => {
263
+ if (members.some(box => box.closing && boxes.get(box.element) === box)) return
264
+ if (frameRequest !== null) cancelAnimationFrame(frameRequest)
265
+ frameRequest = null
266
+ settle(true)
267
+ }
268
+ const tick = (now: number): void => {
269
+ frameRequest = null
270
+ started ??= now
271
+ const elapsed = reduced ? CLOSE_DELAY_MS + CLOSE_MS : now - started
272
+ const linear = Math.min(1, Math.max(0, (elapsed - CLOSE_DELAY_MS) / CLOSE_MS))
273
+ const progress = linear * linear * (3 - 2 * linear)
274
+ current.prepare(progress, cancelled)
275
+ freezeTravelling()
276
+ for (const box of members) {
277
+ if (boxes.get(box.element) !== box) continue
278
+ if (box.closing) {
279
+ box.element.style.height = `${box.height * (1 - progress)}px`
280
+ box.element.style.marginTop = `${box.marginTop * (1 - progress)}px`
281
+ box.element.style.opacity = travelling.has(box.element) ? '1' : String(Math.max(0, 1 - elapsed / FADE_OUT_MS))
282
+ } else {
283
+ box.element.style.height = `${box.fromHeight + (box.height - box.fromHeight) * progress}px`
284
+ box.element.style.marginTop = `${box.fromMarginTop + (box.marginTop - box.fromMarginTop) * progress}px`
285
+ box.element.style.opacity = String(revealedShare(box, progress))
286
+ }
287
+ }
288
+ displacement = current.frame(progress, cancelled)
289
+ let removedBefore = 0
290
+ for (const box of members) {
291
+ if (boxes.get(box.element) !== box) continue
292
+ if (box.closing) {
293
+ // Transforming the closing box changes its pixels, not its flow contribution.
294
+ if (!travelling.has(box.element)) box.element.style.translate = `0 ${displacement + removedBefore}px`
295
+ removedBefore += (box.height + box.marginTop) * progress
296
+ } else removedBefore -= (box.height - box.fromHeight + box.marginTop - box.fromMarginTop) * progress
297
+ }
298
+ if (linear < 1) {
299
+ frameRequest = requestAnimationFrame(tick)
300
+ return
301
+ }
302
+ settle(cancelled)
303
+ }
304
+ if (reduced) tick(0)
305
+ else frameRequest = requestAnimationFrame(tick)
306
+ return true
307
+ }
308
+
309
+ function foldActive(): boolean { return folding > 0 }
310
+
311
+ function onFoldIdle(listener: () => void): () => void {
312
+ if (folding === 0) listener()
313
+ else foldIdleListeners.add(listener)
314
+ return () => { foldIdleListeners.delete(listener) }
315
+ }
316
+
317
+ function flushBatch(): void {
318
+ batchScheduled = false
319
+ // Rows that change during a batch are held until it settles, which flushes again.
320
+ if (batch) return
321
+ const current = [...boxes.values()].some(box => box.closing) ? driver() : null
322
+ if (current !== null && runBatch(current)) return
323
+ const reduced = typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches
324
+ // Without a batch, a held closing row finishes at once and a held revealing row starts its own transition.
325
+ for (const box of [...boxes.values()]) {
326
+ if (reduced || (box.held && box.closing)) box.finish()
327
+ else if (box.held) box.release()
328
+ }
329
+ }
330
+
331
+ function scheduleBatch(): void {
332
+ if (batchScheduled) return
333
+ batchScheduled = true
334
+ // After the whole commit's collapses and reveals have started, before any box changes size.
335
+ const epoch = clearEpoch
336
+ queueMicrotask(() => { if (epoch === clearEpoch) flushBatch() })
337
+ }
338
+
339
+ function foldStarted(): void {
340
+ folding += 1
341
+ if (folding !== 1 || anchoringDisabled) return
342
+ anchoringDisabled = true
343
+ foldingChanged(true)
344
+ }
345
+
346
+ function foldEnded(): void {
347
+ folding = Math.max(0, folding - 1)
348
+ if (folding === 0 && !settling) notifyIdle()
349
+ }
350
+
351
+ function notifyIdle(): void {
352
+ if (anchoringDisabled) {
353
+ anchoringDisabled = false
354
+ foldingChanged(false)
355
+ }
356
+ const listeners = [...foldIdleListeners]
357
+ foldIdleListeners.clear()
358
+ for (const listener of listeners) listener()
359
+ }
360
+
361
+ function clearMotion(
362
+ element: HTMLElement,
363
+ onEnd: (event: TransitionEvent) => void,
364
+ timer: ReturnType<typeof setTimeout> | undefined,
365
+ ): void {
366
+ element.removeEventListener('transitionend', onEnd)
367
+ clearTimeout(timer)
368
+ running.delete(element)
369
+ boxes.delete(element)
370
+ const { style } = element
371
+ style.height = ''
372
+ style.marginTop = ''
373
+ style.opacity = ''
374
+ style.overflow = ''
375
+ style.transition = ''
376
+ style.translate = ''
377
+ delete element.dataset.chatMotion
378
+ }
379
+
380
+ function cancelMotion(element: HTMLElement): void {
381
+ running.get(element)?.()
382
+ cancelEmptyBatch?.()
383
+ }
384
+
385
+ function collapse(element: HTMLElement, done: () => void): void {
386
+ cancelMotion(element)
387
+ const height = element.offsetHeight
388
+ const marginTop = Number.parseFloat(getComputedStyle(element).marginTop) || 0
389
+ if (height === 0 && marginTop === 0) {
390
+ done()
391
+ return
392
+ }
393
+ const { style } = element
394
+ // A running batch owns the scrollport; a row closing now keeps its size until the next batch drives it.
395
+ const held = batch
396
+ element.dataset.chatMotion = 'collapse'
397
+ foldStarted()
398
+ scheduleBatch()
399
+ style.transition = 'none'
400
+ style.overflow = 'hidden'
401
+ style.height = `${height}px`
402
+ style.marginTop = `${marginTop}px`
403
+ if (!held) {
404
+ void element.offsetHeight
405
+ style.transition = `opacity ${FADE_OUT_MS}ms ${EASING}, `
406
+ + `height ${CLOSE_MS}ms ${EASING} ${CLOSE_DELAY_MS}ms, margin-top ${CLOSE_MS}ms ${EASING} ${CLOSE_DELAY_MS}ms`
407
+ style.opacity = '0'
408
+ style.height = '0px'
409
+ style.marginTop = '0px'
410
+ }
411
+
412
+ // The hidden state must land before fold-idle listeners measure the flow.
413
+ const finish = (): void => {
414
+ if (running.get(element) !== cancel) return
415
+ clearMotion(element, onEnd, timer)
416
+ done()
417
+ foldEnded()
418
+ }
419
+ const onEnd = (event: TransitionEvent): void => {
420
+ if (event.target === element && event.propertyName === 'height') finish()
421
+ }
422
+ const timer = held ? undefined : setTimeout(finish, CLOSE_DELAY_MS + CLOSE_MS + SETTLE_SLACK_MS)
423
+ const cancel = (): void => {
424
+ clearMotion(element, onEnd, timer)
425
+ foldEnded()
426
+ }
427
+ if (!held) element.addEventListener('transitionend', onEnd)
428
+ running.set(element, cancel)
429
+ boxes.set(element, { element, height, marginTop, fromHeight: height, fromMarginTop: marginTop, closing: true, held, finish,
430
+ release: () => {},
431
+ take: () => { element.removeEventListener('transitionend', onEnd); clearTimeout(timer) } })
432
+ }
433
+
434
+ function reveal(element: HTMLElement): void {
435
+ cancelMotion(element)
436
+ const height = element.offsetHeight
437
+ if (height === 0) return
438
+ const marginTop = Number.parseFloat(getComputedStyle(element).marginTop) || 0
439
+ scheduleBatch()
440
+ const { style } = element
441
+ element.dataset.chatMotion = 'reveal'
442
+ style.transition = 'none'
443
+ style.overflow = 'hidden'
444
+ style.opacity = '0'
445
+ style.height = '0px'
446
+ style.marginTop = '0px'
447
+ const finish = (): void => {
448
+ if (running.get(element) !== finish) return
449
+ clearMotion(element, onEnd, timer)
450
+ }
451
+ const onEnd = (event: TransitionEvent): void => {
452
+ if (event.target === element && event.propertyName === 'height') finish()
453
+ }
454
+ let timer: ReturnType<typeof setTimeout> | undefined
455
+ const startTransition = (): void => {
456
+ void element.offsetHeight
457
+ style.transition = `height ${CLOSE_MS}ms ${EASING} ${CLOSE_DELAY_MS}ms, margin-top ${CLOSE_MS}ms ${EASING} ${CLOSE_DELAY_MS}ms, `
458
+ + `opacity ${CLOSE_MS}ms ${EASING} ${CLOSE_DELAY_MS}ms`
459
+ style.height = `${height}px`
460
+ style.marginTop = `${marginTop}px`
461
+ style.opacity = '1'
462
+ timer = setTimeout(finish, CLOSE_DELAY_MS + CLOSE_MS + SETTLE_SLACK_MS)
463
+ element.addEventListener('transitionend', onEnd)
464
+ }
465
+ // A running batch owns the scrollport; a row revealed now waits at zero size until the next flush.
466
+ const held = batch
467
+ if (!held) startTransition()
468
+ running.set(element, finish)
469
+ const box: OwnedBox = { element, height, marginTop, fromHeight: 0, fromMarginTop: 0, closing: false, held, finish,
470
+ release: () => {
471
+ box.held = false
472
+ startTransition()
473
+ },
474
+ take: () => { element.removeEventListener('transitionend', onEnd); clearTimeout(timer) } }
475
+ boxes.set(element, box)
476
+ }
477
+
478
+ function clear(): void {
479
+ clearEpoch++
480
+ batchScheduled = false
481
+ batch = false
482
+ cancelled = false
483
+ if (frameRequest !== null) cancelAnimationFrame(frameRequest)
484
+ frameRequest = null
485
+ batchCleanup?.()
486
+ batchCleanup = null
487
+ cancelEmptyBatch = null
488
+ foldIdleListeners.clear()
489
+ for (const cancel of [...running.values()]) cancel()
490
+ }
491
+
492
+ function hideNow(element: HTMLElement, commit: () => void): void {
493
+ beforeInstantHide?.(element)
494
+ commit()
495
+ }
496
+
497
+ return {
498
+ collapse, reveal, cancelMotion, foldActive, onFoldIdle, cancelInput, resumeInput, clear, hideNow,
499
+ active: () => running.size > 0 || batchScheduled || batch || settling,
500
+ inputActive: () => batch || (batchScheduled && [...boxes.values()].some(box => box.closing && batchMember(box))),
501
+ }
502
+ }
503
+
504
+ function useFlowTransition(motion: FlowMotionRows | undefined, grow: boolean): HiddenTransition | undefined {
505
+ const current = useRef<HTMLElement | null>(null)
506
+ useLayoutEffect(() => () => {
507
+ if (current.current !== null) motion?.cancelMotion(current.current)
508
+ current.current = null
509
+ }, [motion])
510
+ const transition = useCallback<HiddenTransition>((element, hidden, commit) => {
511
+ const mounted = current.current === element
512
+ const animate = mounted && motionEnabled(element)
513
+ current.current = element
514
+ if (hidden) {
515
+ if (hiddenOrCollapsing(element)) return
516
+ if (mounted && element.closest(MOTION_SCOPE) !== null && motion !== undefined) motion.collapse(element, commit)
517
+ else if (mounted && motion?.hideNow !== undefined) motion.hideNow(element, commit)
518
+ else commit()
519
+ return
520
+ }
521
+ motion?.cancelMotion(element)
522
+ const wasHidden = element.hasAttribute('hidden')
523
+ commit()
524
+ if (wasHidden && animate && grow) motion?.reveal(element)
525
+ }, [motion, grow])
526
+ return motion === undefined ? undefined : transition
527
+ }
528
+
529
+ /**
530
+ * Apply searchable hiding with the containing Chat viewport's optional fold animation.
531
+ * @param hidden - desired visibility.
532
+ * @param reveal - browser-find and focus-protection callback.
533
+ * @param motion - owning viewport's row callbacks; undefined applies visibility synchronously.
534
+ * @returns the stable subtree ref.
535
+ */
536
+ export function useFlowHidden(hidden: boolean, reveal: () => void, motion: FlowMotionRows | undefined): RefObject<HTMLDivElement> {
537
+ return useSearchableHidden(hidden, reveal, useFlowTransition(motion, false))
538
+ }
539
+
540
+ /**
541
+ * Toggle a plain hidden attribute on the fold clock, growing newly revealed headers.
542
+ * @param ref - element whose visibility follows hidden.
543
+ * @param hidden - desired hidden state.
544
+ * @param motion - containing viewport's row callbacks.
545
+ */
546
+ export function useMotionHidden(ref: RefObject<HTMLElement | null>, hidden: boolean, motion: FlowMotionRows): void {
547
+ const transition = useFlowTransition(motion, true)
548
+ useLayoutEffect(() => {
549
+ const element = ref.current
550
+ if (element === null) return
551
+ transition?.(element, hidden, () => {
552
+ if (hidden) element.setAttribute('hidden', '')
553
+ else element.removeAttribute('hidden')
554
+ })
555
+ }, [ref, hidden, transition])
556
+ }
@@ -0,0 +1,100 @@
1
+ // Shared time-label helpers for user/assistant IconActions rows.
2
+
3
+ import type { Translate } from '@deepseek-ai/dsh-client-ui-slots'
4
+
5
+ /** The date-template share of the conversation dictionary the clock consumes. */
6
+ export type ClockTranslate = Translate<'clock.md' | 'clock.ymd'>
7
+
8
+ /** The elapsed-duration share of the conversation dictionary. */
9
+ export type RunDurationTranslate =
10
+ Translate<'duration.secondUnit' | 'duration.minuteUnit' | 'duration.hourUnit'>
11
+
12
+ /** Refresh interval for whole-second live run clocks. */
13
+ export const LIVE_RUN_CLOCK_INTERVAL_MS = 1000
14
+
15
+ function pad2(n: number): string {
16
+ return String(n).padStart(2, '0')
17
+ }
18
+
19
+ /**
20
+ * Local calendar-day epoch (ms at local midnight) for an instant.
21
+ * @param ms - Unix epoch ms.
22
+ * @returns Midnight of that local calendar day.
23
+ */
24
+ export function startOfLocalDay(ms: number): number {
25
+ const d = new Date(ms)
26
+ d.setHours(0, 0, 0, 0)
27
+ return d.getTime()
28
+ }
29
+
30
+ /**
31
+ * Delay until the next local midnight after `ms` (at least 1ms).
32
+ * @param ms - Unix epoch ms.
33
+ * @returns Milliseconds until the following local midnight.
34
+ */
35
+ export function msUntilNextLocalMidnight(ms: number): number {
36
+ const next = new Date(ms)
37
+ next.setHours(24, 0, 0, 0)
38
+ return Math.max(next.getTime() - ms, 1)
39
+ }
40
+
41
+ /** One numeric value or localized unit in an elapsed-time label. */
42
+ export interface RunDurationPart {
43
+ readonly text: string
44
+ readonly numeric: boolean
45
+ }
46
+
47
+ /**
48
+ * Build elapsed-time fragments for both live and completed Turn labels.
49
+ * @param ms - elapsed milliseconds; negatives clamp to zero and fractions floor.
50
+ * @param t - translate seat supplying units and their trailing spacing.
51
+ * @returns numbers and localized units in display order, without leading zeros;
52
+ * minutes start at 60 seconds and hours at 60 minutes.
53
+ */
54
+ export function formatRunDuration(ms: number, t: RunDurationTranslate): RunDurationPart[] {
55
+ const total = Math.max(0, Math.floor(ms / 1000))
56
+ const hours = Math.floor(total / 3600)
57
+ const minutes = Math.floor(total / 60) % 60
58
+ const seconds = total % 60
59
+ const parts: RunDurationPart[] = []
60
+ if (hours > 0) parts.push({ text: String(hours), numeric: true }, { text: t('duration.hourUnit'), numeric: false })
61
+ if (total >= 60) parts.push({ text: String(minutes), numeric: true }, { text: t('duration.minuteUnit'), numeric: false })
62
+ parts.push({ text: String(seconds), numeric: true }, { text: t('duration.secondUnit'), numeric: false })
63
+ return parts
64
+ }
65
+
66
+ /**
67
+ * Decode-throughput figure: whole tokens from ten up, one decimal below.
68
+ * @param tps - Tokens per second.
69
+ * @returns Display number without unit.
70
+ */
71
+ export function formatTokensPerSecond(tps: number): string {
72
+ const clamped = Math.max(0, tps)
73
+ return clamped >= 10 ? String(Math.round(clamped)) : String(Math.round(clamped * 10) / 10)
74
+ }
75
+
76
+ /**
77
+ * Compact local timestamp for message IconActions. Same calendar day →
78
+ * `HH:mm`; earlier this year → the `clock.md` date template + clock; other
79
+ * years → the `clock.ymd` template + clock. Pure: the date templates arrive
80
+ * through the caller's locale seat.
81
+ * @param time - Unix epoch ms from the source session event.
82
+ * @param t - translate seat supplying the `clock.md` / `clock.ymd` templates.
83
+ * @param now - Reference instant for the day/year cut (defaults to wall clock).
84
+ * @returns Date-aware clock string (24-hour, zero-padded time).
85
+ */
86
+ export function formatMessageClock(time: number, t: ClockTranslate, now: number = Date.now()): string {
87
+ const d = new Date(time)
88
+ const n = new Date(now)
89
+ const clock = `${pad2(d.getHours())}:${pad2(d.getMinutes())}`
90
+ if (
91
+ d.getFullYear() === n.getFullYear()
92
+ && d.getMonth() === n.getMonth()
93
+ && d.getDate() === n.getDate()
94
+ ) {
95
+ return clock
96
+ }
97
+ const params = { y: d.getFullYear(), m: d.getMonth() + 1, d: d.getDate() }
98
+ const md = d.getFullYear() === n.getFullYear() ? t('clock.md', params) : t('clock.ymd', params)
99
+ return `${md} ${clock}`
100
+ }