@things-factory/ai-assistant 10.1.278 → 10.1.279

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 (531) hide show
  1. package/dist-client/bootstrap.d.ts +4 -4
  2. package/dist-client/bootstrap.js +4 -8
  3. package/dist-client/components/ai-model-price-table.d.ts +32 -0
  4. package/dist-client/components/ai-model-price-table.js +311 -0
  5. package/dist-client/components/ai-usage-table.d.ts +17 -0
  6. package/dist-client/components/ai-usage-table.js +151 -0
  7. package/dist-client/index.d.ts +1 -0
  8. package/dist-client/index.js +2 -0
  9. package/dist-client/pages/ai-model-price-page.d.ts +37 -0
  10. package/dist-client/pages/ai-model-price-page.js +312 -0
  11. package/dist-client/route.d.ts +1 -1
  12. package/dist-client/route.js +4 -0
  13. package/dist-client/settings/ai-agent-setting-let.js +11 -0
  14. package/dist-client/utils/model-price-model.d.ts +31 -0
  15. package/dist-client/utils/model-price-model.js +30 -0
  16. package/dist-client/utils/usage-charts.d.ts +21 -0
  17. package/dist-client/utils/usage-charts.js +45 -0
  18. package/dist-client/utils/usage-model.d.ts +44 -0
  19. package/dist-client/utils/usage-model.js +44 -0
  20. package/dist-server/service/ai-agent-resolver.d.ts +46 -0
  21. package/dist-server/service/ai-agent-resolver.js +252 -0
  22. package/package.json +25 -10
  23. package/things-factory.config.js +4 -1
  24. package/translations/en.json +46 -4
  25. package/translations/es.json +43 -1
  26. package/translations/ja.json +43 -1
  27. package/translations/ko.json +46 -4
  28. package/translations/ms.json +43 -1
  29. package/translations/zh.json +43 -1
  30. package/client/bootstrap.ts +0 -27
  31. package/client/components/assistant-chat.test.ts +0 -149
  32. package/client/components/assistant-chat.ts +0 -5599
  33. package/client/components/assistant-dock.ts +0 -1036
  34. package/client/components/assistant-invite.ts +0 -138
  35. package/client/components/assistant-mode.test.ts +0 -119
  36. package/client/components/assistant-mode.ts +0 -174
  37. package/client/components/assistant-selection-bar.test.ts +0 -167
  38. package/client/components/assistant-selection-bar.ts +0 -178
  39. package/client/components/assistant-session-manager.ts +0 -915
  40. package/client/components/assistant-session-toolbar.ts +0 -80
  41. package/client/components/chat-defaults.ts +0 -64
  42. package/client/components/chat-echo-dedup.test.ts +0 -253
  43. package/client/components/chat-echo-dedup.ts +0 -190
  44. package/client/components/chat-input-builder.test.ts +0 -86
  45. package/client/components/chat-input-builder.ts +0 -133
  46. package/client/components/chat-proposal-survival.test.ts +0 -73
  47. package/client/components/entry-review.ts +0 -346
  48. package/client/components/markdown.test.ts +0 -518
  49. package/client/components/markdown.ts +0 -508
  50. package/client/components/mention-popup-helpers.ts +0 -433
  51. package/client/components/mention-popup.test.ts +0 -588
  52. package/client/components/mention-popup.ts +0 -261
  53. package/client/components/panel-aria.test.ts +0 -59
  54. package/client/components/proposal-outcome-line.ts +0 -74
  55. package/client/components/proposal-request.test.ts +0 -73
  56. package/client/components/reply-message.test.ts +0 -15
  57. package/client/components/reply-message.ts +0 -11
  58. package/client/components/roster-identity.test.ts +0 -8
  59. package/client/components/roster-identity.ts +0 -4
  60. package/client/components/workspace-view.ts +0 -486
  61. package/client/index.ts +0 -36
  62. package/client/pages/assistant-workspace-page.ts +0 -317
  63. package/client/route.ts +0 -9
  64. package/client/settings/agent-settings-model.ts +0 -164
  65. package/client/settings/ai-agent-setting-let.ts +0 -667
  66. package/client/settings/ai-usage-setting-let.ts +0 -240
  67. package/client/settings/usage-model.ts +0 -46
  68. package/client/setup-assistant-dock.ts +0 -177
  69. package/client/tsconfig.json +0 -13
  70. package/client/utils/addressed-draft.test.ts +0 -31
  71. package/client/utils/agent-choice.ts +0 -56
  72. package/client/utils/applied-screens.ts +0 -36
  73. package/client/utils/assistant-activity.ts +0 -122
  74. package/client/utils/assistant-ask.test.ts +0 -38
  75. package/client/utils/assistant-ask.ts +0 -93
  76. package/client/utils/assistant-capability-read.ts +0 -24
  77. package/client/utils/assistant-capability.test.ts +0 -17
  78. package/client/utils/assistant-capability.ts +0 -19
  79. package/client/utils/assistant-navigation.test.ts +0 -66
  80. package/client/utils/assistant-navigation.ts +0 -11
  81. package/client/utils/assistant-proposals.ts +0 -85
  82. package/client/utils/assistant-request-context.ts +0 -63
  83. package/client/utils/assistant-selection.test.ts +0 -54
  84. package/client/utils/assistant-selection.ts +0 -75
  85. package/client/utils/assistant-session-actions.ts +0 -32
  86. package/client/utils/assistant-session-admin.ts +0 -239
  87. package/client/utils/assistant-session-controller.test.ts +0 -75
  88. package/client/utils/assistant-session-controller.ts +0 -208
  89. package/client/utils/assistant-session-transport.ts +0 -46
  90. package/client/utils/assistant-surface.ts +0 -178
  91. package/client/utils/assistant-typing.test.ts +0 -33
  92. package/client/utils/assistant-typing.ts +0 -53
  93. package/client/utils/attachment-policy.ts +0 -106
  94. package/client/utils/composer-frame.ts +0 -77
  95. package/client/utils/document-text.ts +0 -332
  96. package/client/utils/entry-hash.ts +0 -35
  97. package/client/utils/entry-proposal.ts +0 -215
  98. package/client/utils/entry-workspace.ts +0 -70
  99. package/client/utils/invite-proposal-register.ts +0 -31
  100. package/client/utils/invite-proposal.test.ts +0 -40
  101. package/client/utils/invite-proposal.ts +0 -54
  102. package/client/utils/menu-room.ts +0 -33
  103. package/client/utils/open-page.ts +0 -21
  104. package/client/utils/pasted-table.ts +0 -145
  105. package/client/utils/pdf-pages.ts +0 -25
  106. package/client/utils/spreadsheet-text.ts +0 -125
  107. package/client/utils/workspace.ts +0 -89
  108. package/dist-client/bootstrap.js.map +0 -1
  109. package/dist-client/components/assistant-chat.js.map +0 -1
  110. package/dist-client/components/assistant-chat.test.d.ts +0 -1
  111. package/dist-client/components/assistant-chat.test.js +0 -138
  112. package/dist-client/components/assistant-chat.test.js.map +0 -1
  113. package/dist-client/components/assistant-dock.js.map +0 -1
  114. package/dist-client/components/assistant-invite.js.map +0 -1
  115. package/dist-client/components/assistant-mode.js.map +0 -1
  116. package/dist-client/components/assistant-mode.test.d.ts +0 -1
  117. package/dist-client/components/assistant-mode.test.js +0 -100
  118. package/dist-client/components/assistant-mode.test.js.map +0 -1
  119. package/dist-client/components/assistant-selection-bar.js.map +0 -1
  120. package/dist-client/components/assistant-selection-bar.test.d.ts +0 -1
  121. package/dist-client/components/assistant-selection-bar.test.js +0 -148
  122. package/dist-client/components/assistant-selection-bar.test.js.map +0 -1
  123. package/dist-client/components/assistant-session-manager.js.map +0 -1
  124. package/dist-client/components/assistant-session-toolbar.js.map +0 -1
  125. package/dist-client/components/chat-defaults.js.map +0 -1
  126. package/dist-client/components/chat-echo-dedup.js.map +0 -1
  127. package/dist-client/components/chat-echo-dedup.test.d.ts +0 -1
  128. package/dist-client/components/chat-echo-dedup.test.js +0 -223
  129. package/dist-client/components/chat-echo-dedup.test.js.map +0 -1
  130. package/dist-client/components/chat-input-builder.js.map +0 -1
  131. package/dist-client/components/chat-input-builder.test.d.ts +0 -1
  132. package/dist-client/components/chat-input-builder.test.js +0 -70
  133. package/dist-client/components/chat-input-builder.test.js.map +0 -1
  134. package/dist-client/components/chat-proposal-survival.test.d.ts +0 -1
  135. package/dist-client/components/chat-proposal-survival.test.js +0 -61
  136. package/dist-client/components/chat-proposal-survival.test.js.map +0 -1
  137. package/dist-client/components/entry-review.js.map +0 -1
  138. package/dist-client/components/markdown.js.map +0 -1
  139. package/dist-client/components/markdown.test.d.ts +0 -1
  140. package/dist-client/components/markdown.test.js +0 -418
  141. package/dist-client/components/markdown.test.js.map +0 -1
  142. package/dist-client/components/mention-popup-helpers.js.map +0 -1
  143. package/dist-client/components/mention-popup.js.map +0 -1
  144. package/dist-client/components/mention-popup.test.d.ts +0 -1
  145. package/dist-client/components/mention-popup.test.js +0 -474
  146. package/dist-client/components/mention-popup.test.js.map +0 -1
  147. package/dist-client/components/panel-aria.test.d.ts +0 -1
  148. package/dist-client/components/panel-aria.test.js +0 -53
  149. package/dist-client/components/panel-aria.test.js.map +0 -1
  150. package/dist-client/components/proposal-outcome-line.js.map +0 -1
  151. package/dist-client/components/proposal-request.test.d.ts +0 -1
  152. package/dist-client/components/proposal-request.test.js +0 -63
  153. package/dist-client/components/proposal-request.test.js.map +0 -1
  154. package/dist-client/components/reply-message.js.map +0 -1
  155. package/dist-client/components/reply-message.test.d.ts +0 -1
  156. package/dist-client/components/reply-message.test.js +0 -16
  157. package/dist-client/components/reply-message.test.js.map +0 -1
  158. package/dist-client/components/roster-identity.js.map +0 -1
  159. package/dist-client/components/roster-identity.test.d.ts +0 -1
  160. package/dist-client/components/roster-identity.test.js +0 -9
  161. package/dist-client/components/roster-identity.test.js.map +0 -1
  162. package/dist-client/components/workspace-view.js.map +0 -1
  163. package/dist-client/index.js.map +0 -1
  164. package/dist-client/pages/assistant-workspace-page.js.map +0 -1
  165. package/dist-client/route.js.map +0 -1
  166. package/dist-client/settings/agent-settings-model.js.map +0 -1
  167. package/dist-client/settings/ai-agent-setting-let.js.map +0 -1
  168. package/dist-client/settings/ai-usage-setting-let.d.ts +0 -25
  169. package/dist-client/settings/ai-usage-setting-let.js +0 -258
  170. package/dist-client/settings/ai-usage-setting-let.js.map +0 -1
  171. package/dist-client/settings/usage-model.d.ts +0 -32
  172. package/dist-client/settings/usage-model.js +0 -25
  173. package/dist-client/settings/usage-model.js.map +0 -1
  174. package/dist-client/setup-assistant-dock.js.map +0 -1
  175. package/dist-client/tsconfig.tsbuildinfo +0 -1
  176. package/dist-client/utils/addressed-draft.test.d.ts +0 -1
  177. package/dist-client/utils/addressed-draft.test.js +0 -27
  178. package/dist-client/utils/addressed-draft.test.js.map +0 -1
  179. package/dist-client/utils/agent-choice.js.map +0 -1
  180. package/dist-client/utils/applied-screens.js.map +0 -1
  181. package/dist-client/utils/assistant-activity.js.map +0 -1
  182. package/dist-client/utils/assistant-ask.js.map +0 -1
  183. package/dist-client/utils/assistant-ask.test.d.ts +0 -1
  184. package/dist-client/utils/assistant-ask.test.js +0 -40
  185. package/dist-client/utils/assistant-ask.test.js.map +0 -1
  186. package/dist-client/utils/assistant-capability-read.js.map +0 -1
  187. package/dist-client/utils/assistant-capability.js.map +0 -1
  188. package/dist-client/utils/assistant-capability.test.d.ts +0 -1
  189. package/dist-client/utils/assistant-capability.test.js +0 -16
  190. package/dist-client/utils/assistant-capability.test.js.map +0 -1
  191. package/dist-client/utils/assistant-navigation.js.map +0 -1
  192. package/dist-client/utils/assistant-navigation.test.d.ts +0 -1
  193. package/dist-client/utils/assistant-navigation.test.js +0 -63
  194. package/dist-client/utils/assistant-navigation.test.js.map +0 -1
  195. package/dist-client/utils/assistant-proposals.js.map +0 -1
  196. package/dist-client/utils/assistant-request-context.js.map +0 -1
  197. package/dist-client/utils/assistant-selection.js.map +0 -1
  198. package/dist-client/utils/assistant-selection.test.d.ts +0 -1
  199. package/dist-client/utils/assistant-selection.test.js +0 -46
  200. package/dist-client/utils/assistant-selection.test.js.map +0 -1
  201. package/dist-client/utils/assistant-session-actions.js.map +0 -1
  202. package/dist-client/utils/assistant-session-admin.js.map +0 -1
  203. package/dist-client/utils/assistant-session-controller.js.map +0 -1
  204. package/dist-client/utils/assistant-session-controller.test.d.ts +0 -1
  205. package/dist-client/utils/assistant-session-controller.test.js +0 -56
  206. package/dist-client/utils/assistant-session-controller.test.js.map +0 -1
  207. package/dist-client/utils/assistant-session-transport.js.map +0 -1
  208. package/dist-client/utils/assistant-surface.js.map +0 -1
  209. package/dist-client/utils/assistant-typing.js.map +0 -1
  210. package/dist-client/utils/assistant-typing.test.d.ts +0 -1
  211. package/dist-client/utils/assistant-typing.test.js +0 -30
  212. package/dist-client/utils/assistant-typing.test.js.map +0 -1
  213. package/dist-client/utils/attachment-policy.js.map +0 -1
  214. package/dist-client/utils/composer-frame.js.map +0 -1
  215. package/dist-client/utils/document-text.js.map +0 -1
  216. package/dist-client/utils/entry-hash.js.map +0 -1
  217. package/dist-client/utils/entry-proposal.js.map +0 -1
  218. package/dist-client/utils/entry-workspace.js.map +0 -1
  219. package/dist-client/utils/invite-proposal-register.js.map +0 -1
  220. package/dist-client/utils/invite-proposal.js.map +0 -1
  221. package/dist-client/utils/invite-proposal.test.d.ts +0 -1
  222. package/dist-client/utils/invite-proposal.test.js +0 -35
  223. package/dist-client/utils/invite-proposal.test.js.map +0 -1
  224. package/dist-client/utils/menu-room.js.map +0 -1
  225. package/dist-client/utils/open-page.js.map +0 -1
  226. package/dist-client/utils/pasted-table.js.map +0 -1
  227. package/dist-client/utils/pdf-pages.js.map +0 -1
  228. package/dist-client/utils/spreadsheet-text.js.map +0 -1
  229. package/dist-client/utils/workspace.js.map +0 -1
  230. package/dist-server/door-declaration-report.js.map +0 -1
  231. package/dist-server/index.js.map +0 -1
  232. package/dist-server/role-tasks.js.map +0 -1
  233. package/dist-server/service/ai-agent-resolver.js.map +0 -1
  234. package/dist-server/service/assistant-capability-resolver.js.map +0 -1
  235. package/dist-server/service/assistant-chat-resolver.js.map +0 -1
  236. package/dist-server/service/assistant-mode/assistant-mode-resolver.js.map +0 -1
  237. package/dist-server/service/assistant-mode/fallback-subjects.js.map +0 -1
  238. package/dist-server/service/assistant-mode/index.js.map +0 -1
  239. package/dist-server/service/assistant-mode/mode-categories.js.map +0 -1
  240. package/dist-server/service/assistant-mode/record-subject.js.map +0 -1
  241. package/dist-server/service/assistant-mode/registry.js.map +0 -1
  242. package/dist-server/service/assistant-mode/resolve.js.map +0 -1
  243. package/dist-server/service/assistant-mode/screen-rules.js.map +0 -1
  244. package/dist-server/service/assistant-mode/turn-lines.js.map +0 -1
  245. package/dist-server/service/assistant-mode/types.js.map +0 -1
  246. package/dist-server/service/chat-message/carried-turns.js.map +0 -1
  247. package/dist-server/service/chat-message/chat-message-broadcast.js.map +0 -1
  248. package/dist-server/service/chat-message/chat-message-publish.js.map +0 -1
  249. package/dist-server/service/chat-message/chat-message-room.js.map +0 -1
  250. package/dist-server/service/chat-message/chat-message-subscription.js.map +0 -1
  251. package/dist-server/service/chat-message/chat-message.js.map +0 -1
  252. package/dist-server/service/chat-message/chat-typing-subscription.js.map +0 -1
  253. package/dist-server/service/chat-message/chat-typing.js.map +0 -1
  254. package/dist-server/service/chat-message/door-access.js.map +0 -1
  255. package/dist-server/service/chat-message/fold-history.js.map +0 -1
  256. package/dist-server/service/chat-message/fold-session-history.js.map +0 -1
  257. package/dist-server/service/chat-message/history-summary.js.map +0 -1
  258. package/dist-server/service/chat-message/index.js.map +0 -1
  259. package/dist-server/service/chat-message/llm-history.js.map +0 -1
  260. package/dist-server/service/chat-message/message-doors.js.map +0 -1
  261. package/dist-server/service/chat-message/proposal-outcome.js.map +0 -1
  262. package/dist-server/service/chat-message/reader-gate.js.map +0 -1
  263. package/dist-server/service/chat-message/room-message.js.map +0 -1
  264. package/dist-server/service/chat-message/room-turn.js.map +0 -1
  265. package/dist-server/service/chat-message/used-tools.js.map +0 -1
  266. package/dist-server/service/chat-session/attachment-policy.js.map +0 -1
  267. package/dist-server/service/chat-session/attachment-route.js.map +0 -1
  268. package/dist-server/service/chat-session/attachment-tool-result.js.map +0 -1
  269. package/dist-server/service/chat-session/attachment-tools.js.map +0 -1
  270. package/dist-server/service/chat-session/chat-session.js.map +0 -1
  271. package/dist-server/service/chat-session/index.js.map +0 -1
  272. package/dist-server/service/chat-session/session-activity-broadcast.js.map +0 -1
  273. package/dist-server/service/chat-session/session-activity-publish.js.map +0 -1
  274. package/dist-server/service/chat-session/session-activity-subscription.js.map +0 -1
  275. package/dist-server/service/chat-session/session-anchor.js.map +0 -1
  276. package/dist-server/service/chat-session/session-attachments.js.map +0 -1
  277. package/dist-server/service/chat-session/session-cleanup.js.map +0 -1
  278. package/dist-server/service/chat-session/session-inbox.js.map +0 -1
  279. package/dist-server/service/chat-session/session-kind.js.map +0 -1
  280. package/dist-server/service/chat-session/session-name.js.map +0 -1
  281. package/dist-server/service/chat-session/session-purge.js.map +0 -1
  282. package/dist-server/service/chat-session/session-retention.js.map +0 -1
  283. package/dist-server/service/chat-session/session-visibility.js.map +0 -1
  284. package/dist-server/service/chat-session/session-write-gate.js.map +0 -1
  285. package/dist-server/service/chat-session/station-session-guard.js.map +0 -1
  286. package/dist-server/service/chat-session/turn-attachments.js.map +0 -1
  287. package/dist-server/service/chat-session-participant/chat-session-participant.js.map +0 -1
  288. package/dist-server/service/chat-session-participant/index.js.map +0 -1
  289. package/dist-server/service/chat-session-participant/invite-notification.js.map +0 -1
  290. package/dist-server/service/chat-session-participant/mention-invite.js.map +0 -1
  291. package/dist-server/service/chat-session-participant/participant-lookup-roles.js.map +0 -1
  292. package/dist-server/service/chat-session-participant/participant-lookup.js.map +0 -1
  293. package/dist-server/service/chat-session-participant/presence.js.map +0 -1
  294. package/dist-server/service/chat-session-participant/read-roster.js.map +0 -1
  295. package/dist-server/service/chat-session-resolver.js.map +0 -1
  296. package/dist-server/service/data-entry/entry-apply.js.map +0 -1
  297. package/dist-server/service/data-entry/entry-hash.js.map +0 -1
  298. package/dist-server/service/data-entry/entry-refusal.js.map +0 -1
  299. package/dist-server/service/data-entry/entry-resolver.js.map +0 -1
  300. package/dist-server/service/data-entry/entry-screen.js.map +0 -1
  301. package/dist-server/service/data-entry/entry-sources.js.map +0 -1
  302. package/dist-server/service/data-entry/entry-target.js.map +0 -1
  303. package/dist-server/service/data-entry/entry-tools.js.map +0 -1
  304. package/dist-server/service/data-entry/entry-update.js.map +0 -1
  305. package/dist-server/service/data-read/list-read.js.map +0 -1
  306. package/dist-server/service/data-read/read-target.js.map +0 -1
  307. package/dist-server/service/data-read/read-tools.js.map +0 -1
  308. package/dist-server/service/grounding-sources.js.map +0 -1
  309. package/dist-server/service/help-documents/help-keys.js.map +0 -1
  310. package/dist-server/service/help-documents/help-tools.js.map +0 -1
  311. package/dist-server/service/index.js.map +0 -1
  312. package/dist-server/service/people/index.js.map +0 -1
  313. package/dist-server/service/people/invite-tools.js.map +0 -1
  314. package/dist-server/service/people/people-keys.js.map +0 -1
  315. package/dist-server/service/people/people-read.js.map +0 -1
  316. package/dist-server/service/people/person-subject.js.map +0 -1
  317. package/dist-server/service/request-translator.js.map +0 -1
  318. package/dist-server/service/testing/conversation-script.js.map +0 -1
  319. package/dist-server/service/testing/mode-conformance.js.map +0 -1
  320. package/dist-server/service/tool-access.js.map +0 -1
  321. package/dist-server/service/types.js.map +0 -1
  322. package/dist-server/service/unattended-run/assistant-run.js.map +0 -1
  323. package/dist-server/service/unattended-run/index.js.map +0 -1
  324. package/dist-server/service/unattended-run/limits.js.map +0 -1
  325. package/dist-server/service/unattended-run/run-as.js.map +0 -1
  326. package/dist-server/service/unattended-run/run-budget.js.map +0 -1
  327. package/dist-server/service/unattended-run/run-ledger.js.map +0 -1
  328. package/dist-server/service/unattended-run/run-outcome.js.map +0 -1
  329. package/dist-server/service/unattended-run/run-store.js.map +0 -1
  330. package/dist-server/service/unattended-run/run-unattended.js.map +0 -1
  331. package/dist-server/service/unattended-run/unattended-prompt.js.map +0 -1
  332. package/dist-server/service/workspace/workspace-blocks.js.map +0 -1
  333. package/dist-server/service/workspace/workspace-tools.js.map +0 -1
  334. package/dist-server/tool-registry-boot-report.js.map +0 -1
  335. package/dist-server/tsconfig.tsbuildinfo +0 -1
  336. package/docs/session-controller.md +0 -52
  337. package/server/door-declaration-report.test.ts +0 -53
  338. package/server/door-declaration-report.ts +0 -61
  339. package/server/explicit-graphql-types.test.ts +0 -56
  340. package/server/index.ts +0 -36
  341. package/server/role-tasks.ts +0 -14
  342. package/server/service/ai-agent-resolver.ts +0 -330
  343. package/server/service/assistant-capability-resolver.ts +0 -66
  344. package/server/service/assistant-chat-resolver.ts +0 -640
  345. package/server/service/assistant-mode/assistant-mode-resolver.ts +0 -101
  346. package/server/service/assistant-mode/conversation-category.test.ts +0 -48
  347. package/server/service/assistant-mode/fallback-subjects.ts +0 -36
  348. package/server/service/assistant-mode/index.ts +0 -22
  349. package/server/service/assistant-mode/mode-categories.ts +0 -178
  350. package/server/service/assistant-mode/mode-front.test.ts +0 -183
  351. package/server/service/assistant-mode/one-conversation-per-subject.test.ts +0 -37
  352. package/server/service/assistant-mode/open-subject-door.test.ts +0 -52
  353. package/server/service/assistant-mode/record-subject.test.ts +0 -41
  354. package/server/service/assistant-mode/record-subject.ts +0 -44
  355. package/server/service/assistant-mode/registry.test.ts +0 -171
  356. package/server/service/assistant-mode/registry.ts +0 -139
  357. package/server/service/assistant-mode/resolve.test.ts +0 -129
  358. package/server/service/assistant-mode/resolve.ts +0 -113
  359. package/server/service/assistant-mode/screen-rules.test.ts +0 -99
  360. package/server/service/assistant-mode/screen-rules.ts +0 -103
  361. package/server/service/assistant-mode/turn-lines.ts +0 -43
  362. package/server/service/assistant-mode/types.ts +0 -138
  363. package/server/service/chat-message/carried-turns.test.ts +0 -80
  364. package/server/service/chat-message/carried-turns.ts +0 -112
  365. package/server/service/chat-message/chat-message-broadcast.integration.test.ts +0 -73
  366. package/server/service/chat-message/chat-message-broadcast.test.ts +0 -40
  367. package/server/service/chat-message/chat-message-broadcast.ts +0 -70
  368. package/server/service/chat-message/chat-message-publish.ts +0 -22
  369. package/server/service/chat-message/chat-message-room.test.ts +0 -145
  370. package/server/service/chat-message/chat-message-room.ts +0 -50
  371. package/server/service/chat-message/chat-message-subscription.ts +0 -77
  372. package/server/service/chat-message/chat-message.ts +0 -289
  373. package/server/service/chat-message/chat-typing-subscription.ts +0 -52
  374. package/server/service/chat-message/chat-typing.test.ts +0 -45
  375. package/server/service/chat-message/chat-typing.ts +0 -48
  376. package/server/service/chat-message/door-access.test.ts +0 -72
  377. package/server/service/chat-message/door-access.ts +0 -65
  378. package/server/service/chat-message/fold-history-window.test.ts +0 -184
  379. package/server/service/chat-message/fold-history.test.ts +0 -98
  380. package/server/service/chat-message/fold-history.ts +0 -77
  381. package/server/service/chat-message/fold-session-history.test.ts +0 -116
  382. package/server/service/chat-message/fold-session-history.ts +0 -115
  383. package/server/service/chat-message/history-summary.test.ts +0 -127
  384. package/server/service/chat-message/history-summary.ts +0 -100
  385. package/server/service/chat-message/index.ts +0 -13
  386. package/server/service/chat-message/llm-history.test.ts +0 -245
  387. package/server/service/chat-message/llm-history.ts +0 -182
  388. package/server/service/chat-message/message-doors.test.ts +0 -124
  389. package/server/service/chat-message/message-doors.ts +0 -132
  390. package/server/service/chat-message/proposal-outcome.test.ts +0 -111
  391. package/server/service/chat-message/proposal-outcome.ts +0 -99
  392. package/server/service/chat-message/reader-gate.ts +0 -44
  393. package/server/service/chat-message/room-message.test.ts +0 -21
  394. package/server/service/chat-message/room-message.ts +0 -22
  395. package/server/service/chat-message/room-turn.ts +0 -42
  396. package/server/service/chat-message/used-tools.test.ts +0 -19
  397. package/server/service/chat-message/used-tools.ts +0 -25
  398. package/server/service/chat-session/attachment-policy.test.ts +0 -42
  399. package/server/service/chat-session/attachment-policy.ts +0 -91
  400. package/server/service/chat-session/attachment-route.ts +0 -45
  401. package/server/service/chat-session/attachment-tool-result.test.ts +0 -63
  402. package/server/service/chat-session/attachment-tool-result.ts +0 -37
  403. package/server/service/chat-session/attachment-tools.ts +0 -66
  404. package/server/service/chat-session/chat-session.ts +0 -244
  405. package/server/service/chat-session/group-room.test.ts +0 -233
  406. package/server/service/chat-session/index.ts +0 -5
  407. package/server/service/chat-session/session-activity-broadcast.ts +0 -77
  408. package/server/service/chat-session/session-activity-publish.ts +0 -49
  409. package/server/service/chat-session/session-activity-receivers.test.ts +0 -26
  410. package/server/service/chat-session/session-activity-subscription.ts +0 -66
  411. package/server/service/chat-session/session-anchor.ts +0 -142
  412. package/server/service/chat-session/session-attachments.ts +0 -90
  413. package/server/service/chat-session/session-cleanup.test.ts +0 -83
  414. package/server/service/chat-session/session-cleanup.ts +0 -69
  415. package/server/service/chat-session/session-inbox.test.ts +0 -273
  416. package/server/service/chat-session/session-inbox.ts +0 -240
  417. package/server/service/chat-session/session-kind.test.ts +0 -24
  418. package/server/service/chat-session/session-kind.ts +0 -32
  419. package/server/service/chat-session/session-name.ts +0 -32
  420. package/server/service/chat-session/session-purge.test.ts +0 -24
  421. package/server/service/chat-session/session-purge.ts +0 -117
  422. package/server/service/chat-session/session-retention.ts +0 -17
  423. package/server/service/chat-session/session-visibility.test.ts +0 -130
  424. package/server/service/chat-session/session-visibility.ts +0 -68
  425. package/server/service/chat-session/session-write-gate.test.ts +0 -59
  426. package/server/service/chat-session/session-write-gate.ts +0 -31
  427. package/server/service/chat-session/station-session-guard.ts +0 -25
  428. package/server/service/chat-session/turn-attachments.test.ts +0 -106
  429. package/server/service/chat-session/turn-attachments.ts +0 -45
  430. package/server/service/chat-session-participant/chat-session-participant.ts +0 -135
  431. package/server/service/chat-session-participant/index.ts +0 -8
  432. package/server/service/chat-session-participant/invite-notification.test.ts +0 -80
  433. package/server/service/chat-session-participant/invite-notification.ts +0 -118
  434. package/server/service/chat-session-participant/mention-invite.test.ts +0 -173
  435. package/server/service/chat-session-participant/mention-invite.ts +0 -180
  436. package/server/service/chat-session-participant/participant-lookup-roles.ts +0 -6
  437. package/server/service/chat-session-participant/participant-lookup.ts +0 -22
  438. package/server/service/chat-session-participant/presence.test.ts +0 -39
  439. package/server/service/chat-session-participant/presence.ts +0 -21
  440. package/server/service/chat-session-participant/read-roster.test.ts +0 -27
  441. package/server/service/chat-session-participant/read-roster.ts +0 -17
  442. package/server/service/chat-session-resolver.ts +0 -1455
  443. package/server/service/data-entry/data-entry-update.test.ts +0 -378
  444. package/server/service/data-entry/data-entry.test.ts +0 -494
  445. package/server/service/data-entry/entry-apply.ts +0 -247
  446. package/server/service/data-entry/entry-hash.ts +0 -35
  447. package/server/service/data-entry/entry-refusal.test.ts +0 -73
  448. package/server/service/data-entry/entry-refusal.ts +0 -20
  449. package/server/service/data-entry/entry-resolver.ts +0 -74
  450. package/server/service/data-entry/entry-screen.ts +0 -14
  451. package/server/service/data-entry/entry-sources.ts +0 -39
  452. package/server/service/data-entry/entry-target.ts +0 -774
  453. package/server/service/data-entry/entry-tools.ts +0 -282
  454. package/server/service/data-entry/entry-update.ts +0 -238
  455. package/server/service/data-read/data-read.test.ts +0 -395
  456. package/server/service/data-read/detail-lists.test.ts +0 -61
  457. package/server/service/data-read/list-missing.test.ts +0 -49
  458. package/server/service/data-read/list-read.ts +0 -146
  459. package/server/service/data-read/list-status.test.ts +0 -46
  460. package/server/service/data-read/read-target.ts +0 -509
  461. package/server/service/data-read/read-tools.ts +0 -334
  462. package/server/service/data-read/read-words.test.ts +0 -99
  463. package/server/service/data-read/record-keys.test.ts +0 -42
  464. package/server/service/grounding-sources.test.ts +0 -55
  465. package/server/service/grounding-sources.ts +0 -46
  466. package/server/service/help-documents/help-keys.ts +0 -2
  467. package/server/service/help-documents/help-tools.test.ts +0 -40
  468. package/server/service/help-documents/help-tools.ts +0 -88
  469. package/server/service/index.ts +0 -99
  470. package/server/service/people/index.ts +0 -15
  471. package/server/service/people/invite-tools.ts +0 -159
  472. package/server/service/people/invite.test.ts +0 -159
  473. package/server/service/people/people-keys.ts +0 -16
  474. package/server/service/people/people-read.test.ts +0 -82
  475. package/server/service/people/people-read.ts +0 -56
  476. package/server/service/people/person-subject.test.ts +0 -161
  477. package/server/service/people/person-subject.ts +0 -83
  478. package/server/service/request-translator.test.ts +0 -45
  479. package/server/service/request-translator.ts +0 -33
  480. package/server/service/session-anchor.test.ts +0 -198
  481. package/server/service/station-session-guard.test.ts +0 -31
  482. package/server/service/testing/conversation-scenario.test.ts +0 -164
  483. package/server/service/testing/conversation-script.test.ts +0 -133
  484. package/server/service/testing/conversation-script.ts +0 -296
  485. package/server/service/testing/mode-conformance.test.ts +0 -61
  486. package/server/service/testing/mode-conformance.ts +0 -165
  487. package/server/service/tool-access.test.ts +0 -96
  488. package/server/service/tool-access.ts +0 -36
  489. package/server/service/types.ts +0 -15
  490. package/server/service/unattended-run/assistant-run.ts +0 -199
  491. package/server/service/unattended-run/index.ts +0 -10
  492. package/server/service/unattended-run/limits.ts +0 -24
  493. package/server/service/unattended-run/run-as.ts +0 -38
  494. package/server/service/unattended-run/run-budget.ts +0 -58
  495. package/server/service/unattended-run/run-ledger.ts +0 -31
  496. package/server/service/unattended-run/run-outcome.ts +0 -43
  497. package/server/service/unattended-run/run-store-race.pg.test.ts +0 -83
  498. package/server/service/unattended-run/run-store.ts +0 -162
  499. package/server/service/unattended-run/run-unattended.test.ts +0 -478
  500. package/server/service/unattended-run/run-unattended.ts +0 -248
  501. package/server/service/unattended-run/unattended-prompt.ts +0 -24
  502. package/server/service/workspace/workspace-blocks.ts +0 -134
  503. package/server/service/workspace/workspace-tools.ts +0 -108
  504. package/server/service/workspace/workspace.test.ts +0 -74
  505. package/server/tool-registry-boot-report.test.ts +0 -41
  506. package/server/tool-registry-boot-report.ts +0 -63
  507. package/test/ai-agent-settings.test.ts +0 -123
  508. package/test/applied-screens.test.ts +0 -65
  509. package/test/assistant-chat-call-sites.test.ts +0 -92
  510. package/test/assistant-dock.test.ts +0 -294
  511. package/test/assistant-request-context.test.ts +0 -72
  512. package/test/assistant-session-controller.test.ts +0 -87
  513. package/test/assistant-session-manager.test.ts +0 -186
  514. package/test/assistant-session-toolbar.test.ts +0 -43
  515. package/test/attachment-one-rule.test.ts +0 -46
  516. package/test/attachment-policy-agree.test.ts +0 -38
  517. package/test/composer-frame.test.ts +0 -173
  518. package/test/document-text.test.ts +0 -175
  519. package/test/entry-card-styles.test.ts +0 -18
  520. package/test/entry-proposal.test.ts +0 -186
  521. package/test/entry-workspace.test.ts +0 -89
  522. package/test/menu-room.test.ts +0 -33
  523. package/test/open-doors.test.ts +0 -164
  524. package/test/open-page.test.ts +0 -31
  525. package/test/pasted-table.test.ts +0 -147
  526. package/test/refusals-in-korean.test.ts +0 -80
  527. package/test/session-discovery.test.ts +0 -43
  528. package/test/spreadsheet-text.test.ts +0 -92
  529. package/test/translations.test.ts +0 -80
  530. package/test/workspace.test.ts +0 -54
  531. package/tsconfig.json +0 -9
@@ -1,640 +0,0 @@
1
- /*
2
- * The neutral door into a conversation.
3
- *
4
- * ── Why this exists (2026-09-11) ───────────────────────────────────────────────
5
- * The chat component moved here from `board-ai`, but the only mutation it could call stayed
6
- * behind. operato-figure mounted the dock, registered four tools, and got
7
- * `Cannot query field "boardAIChat" on type "Mutation"` — it does not load board-ai. The twin has
8
- * the same shape and it does not show: its space deliberation runs through board-ai's door purely
9
- * because the board authoring half of the same product already loaded that package.
10
- *
11
- * ── Why the board resolver was not moved ───────────────────────────────────────
12
- * `board-ai-resolver.ts` is 692 lines and the larger part of it is board authoring itself:
13
- * `currentBoard` as a BoardModel, PatchEntry, board patch broadcasts, refid injection for
14
- * component mentions. Moving that here would teach this package the board document, which is the
15
- * dependency we just cut, pointing the other way.
16
- *
17
- * So the door moved and the editor did not. `boardAIChat` stays in board-ai for board authoring;
18
- * this one is for a surface that asks questions and runs registered tools.
19
- *
20
- * ── What this is not ───────────────────────────────────────────────────────────
21
- * It has no document, so it takes no document and returns no patch. Tools that write to a
22
- * document are not offered here — `registryAssistantChat` enforces that, and it decides what may
23
- * be dispatched from the same list it offers, so the two cannot drift apart.
24
- */
25
- import { Arg, Ctx, Directive, Field, InputType, Mutation, ObjectType, Resolver } from 'type-graphql'
26
- import { GraphQLJSON } from 'graphql-scalars'
27
- import '@things-factory/auth-base'
28
-
29
- import { getRepository, rethrowSpoken } from '@things-factory/shell'
30
- import { aiClientFor, findToolSpec, openSubjectLine, OPEN_TOOLS, registryAssistantChat, type AgentClient } from '@things-factory/ai-client-base'
31
-
32
- import { turnLinesOf } from './assistant-mode/turn-lines.js'
33
- import { ChatSession } from './chat-session/chat-session.js'
34
- import { assertStationSession } from './chat-session/station-session-guard.js'
35
- import { ChatMessage } from './chat-message/chat-message.js'
36
- import { buildLlmHistory } from './chat-message/llm-history.js'
37
- import { offeredCardLines } from './chat-message/proposal-outcome.js'
38
- import { splitByCap } from './chat-message/history-summary.js'
39
- import { foldSessionHistory } from './chat-message/fold-session-history.js'
40
- import { groundingSourcesFor } from './grounding-sources.js'
41
- import { publishChatMessage } from './chat-message/chat-message-publish.js'
42
- import { publishSessionActivity } from './chat-session/session-activity-publish.js'
43
- import { activityPatch, autoSessionName } from './chat-session/session-inbox.js'
44
- import { toolAccessFor } from './tool-access.js'
45
- import { ChatSessionParticipant } from './chat-session-participant/chat-session-participant.js'
46
- import { doorsForAnswer } from './chat-message/message-doors.js'
47
- import { judgeSessionKind } from './chat-session/session-kind.js'
48
- import { readerGate } from './chat-message/reader-gate.js'
49
- import { seatTurn } from './chat-session-participant/mention-invite.js'
50
- import { sendInviteNotification } from './chat-session-participant/invite-notification.js'
51
- import { isSessionParticipant } from './chat-session-participant/participant-lookup.js'
52
- import { assertMayWriteSession } from './chat-session/session-write-gate.js'
53
- import { attachmentHistoryLine, refuseAttachments, textCharsOf } from './chat-session/attachment-policy.js'
54
- import { attachmentForModel, describeAttachment, findChatAttachment } from './chat-session/session-attachments.js'
55
- import { readTurnAttachments } from './chat-session/turn-attachments.js'
56
- import { getAssistantMode } from './assistant-mode/registry.js'
57
- import { resolveModeSettings } from './assistant-mode/resolve.js'
58
- import { modeFrontCategories, selectionAxesOf, turnSystemPrompt } from './assistant-mode/mode-categories.js'
59
- import { usedToolNames } from './chat-message/used-tools.js'
60
- import { splitNextRequest } from './assistant-mode/screen-rules.js'
61
- import { requestTranslator } from './request-translator.js'
62
-
63
- /**
64
- * How many stored messages reach the model.
65
- *
66
- * A deliberation runs for days. Without a cap the prompt grows without bound and the oldest turns
67
- * bury the recent ones. Kept the same as the board conversation's cap so the two surfaces of one
68
- * product do not remember differently.
69
- */
70
- const LLM_HISTORY_MAX_TURNS = 40
71
-
72
- @InputType()
73
- class AssistantMessageInput {
74
- @Field({ description: "Role: 'user' or 'assistant'" })
75
- role: string
76
-
77
- @Field({ description: 'Message content' })
78
- content: string
79
- }
80
-
81
- @InputType({ description: 'Which conversation this is, and what it is about.' })
82
- class AssistantModeInput {
83
- @Field({ description: 'A mode kind the app server registered — `<app>.<surface>`, e.g. "twin.space".' })
84
- kind: string
85
-
86
- @Field({
87
- nullable: true,
88
- description:
89
- 'What this conversation is about — the space, the station, the model being edited. With `kind` it is the conversation\'s lifetime: when either changes the screen closes the conversation and starts another.'
90
- })
91
- target?: string
92
- }
93
-
94
- @InputType({ description: 'One turn of a conversation that has no document of its own.' })
95
- class AssistantChatInput {
96
- @Field({
97
- nullable: true,
98
- description: 'ChatSession id. Omit for a one-off question with no persistence.'
99
- })
100
- sessionId?: string
101
-
102
- @Field(() => [AssistantMessageInput], {
103
- description:
104
- 'Conversation, newest last. For a persisted session only the last user message is appended; the rest is read from storage.'
105
- })
106
- messages: AssistantMessageInput[]
107
-
108
- @Field(() => AssistantModeInput, {
109
- description:
110
- 'Which conversation this is. The persona, the tool categories, the model and the limits come from the mode the app server registered (ADR-0061 decision 7) — a caller choosing its own tool categories would be a caller choosing its own authority.'
111
- })
112
- mode: AssistantModeInput
113
-
114
- @Field(() => GraphQLJSON, {
115
- nullable: true,
116
- description:
117
- 'What this surface is looking at (e.g. { figureId } while modelling). Tools read it so the model never has to ask the user for identifiers. Client-supplied — never used for authorization; a tool verifies the scope belongs to the caller tenant.'
118
- })
119
- hostContext?: any
120
-
121
- @Field({
122
- nullable: true,
123
- description:
124
- 'Last message to keep from the stored history. The client keeps its own truncation when a user edits a message, so pass the last kept id to hide the retracted span from the model.'
125
- })
126
- truncateAfterMessageId?: string
127
-
128
- @Field(() => [String], {
129
- nullable: true,
130
- description: 'Files stored with this conversation by attachToConversation, sent with this turn.'
131
- })
132
- attachmentIds?: string[]
133
-
134
- @Field({
135
- nullable: true,
136
- description:
137
- 'The AI agent the person picked for this turn, from aiAgentChoices. Omitted takes the domain default. An agent this domain cannot use is refused - the provider, the model and the key are always the server\'s.'
138
- })
139
- agentId?: string
140
-
141
- @Field({
142
- nullable: true,
143
- description:
144
- 'The route of the page the dock is on (cash-transaction-list). It decides which tools the model is offered first; what a person may use is decided as without it.'
145
- })
146
- page?: string
147
- }
148
-
149
- @ObjectType()
150
- class AssistantChatOutput {
151
- @Field({ description: 'The reply, including the notice when the loop stopped early.' })
152
- reply: string
153
-
154
- @Field(() => String, {
155
- nullable: true,
156
- description:
157
- 'The request the person is likely to make next, as the reply named it. The input shows it and Tab writes it in. Not stored with the reply.'
158
- })
159
- suggestion?: string | null
160
-
161
- @Field({ description: 'AI client identifier (provider:model).' })
162
- clientId: string
163
-
164
- @Field({ nullable: true, description: 'The AI agent that answered.' })
165
- agentId?: string
166
-
167
- @Field({ nullable: true, description: 'Echo of the session id, when persisted.' })
168
- sessionId?: string
169
-
170
- @Field({ nullable: true, description: 'Stored ChatMessage id of the user input.' })
171
- userMessageId?: string
172
-
173
- @Field({ nullable: true, description: 'Stored ChatMessage id of the reply.' })
174
- assistantMessageId?: string
175
-
176
- @Field(() => GraphQLJSON, {
177
- nullable: true,
178
- description:
179
- 'Set when this turn did not fit: { omitted, summarized } — how many earlier messages the model did not see, and whether a summary stood in for them. Without it the person watches the conversation lose its beginning in silence, while the model is told.'
180
- })
181
- historyFolded?: any
182
-
183
- @Field(() => GraphQLJSON, {
184
- nullable: true,
185
- description: 'Tool usages during the turn — {name, arguments, result, kind}. The surface shows them foldably.'
186
- })
187
- toolUsages?: any
188
-
189
- @Field(() => [String], {
190
- nullable: true,
191
- description:
192
- 'Tool names offered to the model this turn. A surface that expected a category and sees it missing here knows the registration did not happen, rather than reading a vague answer as a refusal.'
193
- })
194
- offeredTools?: string[]
195
-
196
- @Field(() => GraphQLJSON, {
197
- nullable: true,
198
- description:
199
- 'Actions a tool recorded without executing — each carries what the tool returned alongside `proposed: true`. The surface renders a confirm button; executing is the user\'s act.'
200
- })
201
- proposals?: any
202
-
203
- @Field(() => GraphQLJSON, {
204
- nullable: true,
205
- description:
206
- 'Identifiers in the reply that appear in nothing the model received. Hallucination candidates surfaced to the user; the reply itself is not altered. Null when the answer is grounded.'
207
- })
208
- groundingWarnings?: any
209
- }
210
-
211
- @Resolver()
212
- export class AssistantChatResolver {
213
- /*
214
- * No `@transaction`, for the same reason the board conversation has none: a model call takes
215
- * seconds to tens of seconds, and holding a write lock for that long collides with everything
216
- * else on SQLite. Writes are short and around the call. For a conversation, a partly stored
217
- * history is safer than a lost one.
218
- */
219
- @Mutation(() => AssistantChatOutput, {
220
- description:
221
- 'Ask the assistant a question on a surface that has no document of its own. Tools come from the registry; with a sessionId the conversation is persisted.'
222
- })
223
- /*
224
- * `ai-assistant:mutation` — the same door as the board conversation's, which moved here on
225
- * 2026-09-10. No `legacy` alias: this operation is new, so no one was ever passing under an old
226
- * name, and declaring an alias would open a second name that nothing needs.
227
- */
228
- @Directive('@privilege(category: "ai-assistant", privilege: "mutation", domainOwnerGranted: true)')
229
- async assistantChat(@Arg('input') input: AssistantChatInput, @Ctx() context: any): Promise<AssistantChatOutput> {
230
- const { domain, user } = context.state
231
-
232
- /*
233
- * The domain's agent - the one picked, or the default (design/ai/agent-settings.md §4). Asked before anything is
234
- * stored: a domain with no AI, or an agent it cannot use, is refused as itself.
235
- */
236
- let client: AgentClient
237
- try {
238
- client = await aiClientFor({
239
- domain,
240
- user,
241
- agentId: input.agentId,
242
- modeKind: input.mode.kind,
243
- sessionId: input.sessionId
244
- })
245
- } catch (error) {
246
- rethrowSpoken(error, context)
247
- }
248
- /* A tool that asks a model of its own within this turn answers with the same agent (ToolCallContext.state). */
249
- context.state.aiAgentId = client.agent.id
250
-
251
- /*
252
- * Read the declaration before anything is stored. A kind this server does not have is a
253
- * mismatched deployment, and the person should see that instead of a conversation with no
254
- * persona and no tools.
255
- */
256
- const t = requestTranslator(context)
257
- const settings = resolveModeSettings(input.mode, t)
258
-
259
- const sessionRepo = getRepository(ChatSession)
260
- const messageRepo = getRepository(ChatMessage)
261
-
262
- let session: ChatSession | undefined
263
- if (input.sessionId) {
264
- const found = await sessionRepo.findOneBy({ id: input.sessionId, domain: { id: domain.id } as any })
265
- if (!found) throw new Error(t('ai-assistant.text.session-not-found', { defaultValue: 'this conversation is not here any more. reload the list.' }))
266
- /*
267
- * A private conversation is written by its people only - and here more than anywhere: the answer is
268
- * built on this conversation's history, so an outsider's question would read it back to them.
269
- */
270
- await assertMayWriteSession({
271
- session: found as any,
272
- userId: user?.id,
273
- isParticipant: () => isSessionParticipant(domain.id, found.id!, user?.id),
274
- t: (key, options) => t(key, options as any)
275
- })
276
- if (found.anchorType === 'figure' && input.hostContext?.figureId !== found.anchorId) {
277
- throw new Error(
278
- context.t('ai-assistant.text.other-figure-history', {
279
- defaultValue: 'this conversation belongs to another figure. open the conversation of the model you have open.'
280
- })
281
- )
282
- }
283
- if (found.anchorType === 'application' && (input.hostContext?.app !== found.anchorId || input.hostContext?.figureId)) {
284
- throw new Error(
285
- context.t('ai-assistant.text.application-vs-model-history', {
286
- defaultValue: 'this conversation is about the application, not about a model. open the one you want.'
287
- })
288
- )
289
- }
290
- /*
291
- * 이 세션이 **이 대화의** 세션인가 — ADR-0072 결정 3. 다른 대화의 세션에 말을 붙이면 그 이력이
292
- * 이 대화의 프롬프트로 들어가고, 화면은 줄이 사라져 새 대화처럼 보이므로 보낸 사람은 모른다.
293
- */
294
- const verdict = judgeSessionKind((found as any).kind, input.mode.kind)
295
- if (verdict.action === 'refuse') {
296
- throw new Error(
297
- t('ai-assistant.text.session-kind-mismatch', {
298
- ...verdict.params,
299
- defaultValue: 'this conversation is {sessionKind}, and you are writing as {requested}. open the conversation you mean.'
300
- })
301
- )
302
- }
303
- if (verdict.action === 'stamp') {
304
- /* 칸이 서기 전에 난 세션 — 요청한 대화로 한 번 찍는다. 다음부터는 위 규칙 하나만 남는다. */
305
- await sessionRepo.update(found.id!, { kind: verdict.kind } as any)
306
- ;(found as any).kind = verdict.kind
307
- }
308
- session = found
309
- }
310
-
311
- assertStationSession(session, input.hostContext, t)
312
-
313
- /*
314
- * 열린 대상 — 서버가 저장한 앵커에서 턴마다 한 줄(design/ai/screen-pattern.md §2-1). 화면이 보낸 hostContext 는
315
- * 쓰지 않는다. 대상이 바뀌면 다음 턴의 줄도 바뀌므로 옛 대상이 대화에 남지 않는다.
316
- */
317
- const subjectLine = session
318
- ? await openSubjectLine({
319
- anchorType: (session as any).anchorType,
320
- anchorId: (session as any).anchorId,
321
- domain,
322
- state: context.state
323
- })
324
- : undefined
325
- /* What the person has in front of them besides the subject - the screen's unread notices (ADR-0199 amendment 1). */
326
- const screenLines = await turnLinesOf({ page: input.page, state: context.state })
327
- const systemPrompt = turnSystemPrompt(settings.systemPrompt, { subjectLine: [subjectLine, ...screenLines].filter(Boolean).join('\n\n') || undefined, page: input.page })
328
-
329
- const lastUserMessage = input.messages[input.messages.length - 1]
330
- let userMessageId: string | undefined
331
-
332
- /*
333
- * Files sent with this turn (design/ai/shared-dock.md §9). They were stored with this conversation by
334
- * attachToConversation; one that is not this conversation's is refused, never read. The policy is the
335
- * mode's - checked again here, since the door is the authority, not the screen.
336
- */
337
- const attachmentRows: any[] = []
338
- if (input.attachmentIds?.length) {
339
- if (!session) throw new Error(t('ai-assistant.text.attachments-need-session', { defaultValue: 'attachments need a saved conversation.' }))
340
- for (const id of input.attachmentIds) {
341
- const row = await findChatAttachment(domain.id, session.id!, id)
342
- if (!row) throw new Error(t('ai-assistant.text.attachment-not-in-session', { defaultValue: 'an attachment does not belong to this conversation.' }))
343
- attachmentRows.push(row)
344
- }
345
- const refusal = refuseAttachments(
346
- getAssistantMode(input.mode.kind)?.attachments,
347
- attachmentRows.map(row => ({ name: row.name, type: row.mimetype, size: Number(row.size) }))
348
- )
349
- if (refusal) throw new Error(t(`ai-assistant.text.${refusal.code}`, { ...(refusal as any), defaultValue: refusal.code }))
350
- }
351
-
352
- if (session && lastUserMessage?.role === 'user') {
353
- const previousLast = await messageRepo.findOne({
354
- where: { session: { id: session.id } as any },
355
- order: { createdAt: 'DESC' }
356
- })
357
- const saved = await messageRepo.save({
358
- session: { id: session.id } as any,
359
- role: 'user',
360
- content: lastUserMessage.content,
361
- /*
362
- * This door is the one people call to ask the assistant, so a turn stored here was for the
363
- * assistant (ADR-0070 A15 decision ①). The value comes from which door was called, never
364
- * from the request — two sources for one fact can disagree.
365
- */
366
- addressee: 'assistant',
367
- attachments: attachmentRows.length ? JSON.stringify(attachmentRows.map(describeAttachment)) : undefined,
368
- creator: user,
369
- updater: user,
370
- parentMessage: previousLast ? ({ id: previousLast.id } as any) : undefined
371
- } as any)
372
- userMessageId = saved.id
373
-
374
- /*
375
- * Session activity is denormalised for the list: most-recent ordering and another
376
- * participant's unread badge read it. Best effort — a conversation must not fail because a
377
- * list sorts one position late.
378
- */
379
- try {
380
- const patch: any = activityPatch(lastUserMessage.content)
381
- if (!session.name) patch.name = autoSessionName(lastUserMessage.content)
382
- await sessionRepo.update(session.id!, patch)
383
- } catch {
384
- /* noop */
385
- }
386
-
387
- /*
388
- * 사람이 `@이름` 으로 부른 사람은 이 대화에 들어온다(ADR-0071 결정 1). 이 문은 **사람의 턴**을
389
- * 저장하는 문이라 그 일을 한다 — 모델의 답이나 도구 결과는 아무도 초대하지 않는다. 공개 방에서 말한 사람도
390
- * 이때 자리에 앉는다(`seatTurn`) — 참여자 줄 · 접속 표시 · 안 읽음이 실제로 말한 사람과 맞도록.
391
- */
392
- const invite = await seatTurn({
393
- content: lastUserMessage.content,
394
- sessionId: session.id!,
395
- domainId: domain.id,
396
- inviter: user,
397
- participants: getRepository(ChatSessionParticipant),
398
- visibility: (session as any).visibility
399
- })
400
- /* 편지가 못 갔다고 방에 들어온 사실이 취소되지는 않는다(`sendInviteNotification`). */
401
- await sendInviteNotification((context.state as any)?.sendNotice, invite.invited, user, (session as any)?.name, undefined, requestTranslator(context))
402
-
403
- publishChatMessage({ domainId: domain.id, sessionId: session.id, message: saved } as any)
404
- publishSessionActivity({
405
- domainId: domain.id,
406
- sessionId: session.id!,
407
- kind: 'message',
408
- anchorType: (session as any).anchorType,
409
- anchorId: (session as any).anchorId,
410
- preview: lastUserMessage.content,
411
- actorId: user?.id
412
- })
413
- }
414
-
415
- /*
416
- * 이번 턴에 상한 밖으로 밀려난 것이 있는가 — 화면이 「대화가 길어졌다」를 알릴 근거다.
417
- *
418
- * 이 문은 그 사실을 내지 않았다. 대화창에는 그 안내를 그리는 자리가 있고(`historyFolded`), 보드
419
- * 문만 그 값을 채웠다. 그래서 앱의 대화는 앞부분이 잘려 나가도 **사람에게는 아무 말도 하지 않았다** —
420
- * 모델에게는 「N 개 생략」을 적어 보내면서.
421
- */
422
- const readRows = session
423
- ? await messageRepo.find({
424
- where: { session: { id: session.id } as any },
425
- order: { createdAt: 'ASC' },
426
- relations: ['creator']
427
- })
428
- : []
429
- /*
430
- * 모델이 읽는 이력도 **부른 사람** 기준으로 가린다 — ADR-0073 판정 1. 가리지 않으면, 문을 한 번도
431
- * 안 지난 사람이 "아까 그 수 다시 말해 줘" 한 마디로 값을 가져간다. 모델이 옮겨 적는 순간 그 값은
432
- * 문 없는 새 답이 된다. 가린 자리를 지우지 않고 한 줄로 남기는 이유도 같다 — 지우면 모델이 그런
433
- * 말이 없었다고 답하고, 그것은 거짓말이다.
434
- */
435
- const storedRows = await readerGate(context)(readRows)
436
- const capped = splitByCap(
437
- storedRows.map(row => ({ id: row.id, role: row.role, content: row.content ?? '' })),
438
- LLM_HISTORY_MAX_TURNS
439
- )
440
- const historyFolded =
441
- capped.dropped.length > 0
442
- ? { omitted: capped.dropped.length, summarized: Boolean((session as any)?.lastSummary) }
443
- : undefined
444
-
445
- const conversation = session
446
- ? buildLlmHistory(
447
- /*
448
- * The model reads who spoke and who they spoke to. The entity carries the speaker as a
449
- * relation and the addressee as a column; the history wants them as plain fields, and
450
- * without this mapping every line arrived unattributed — a room of people read as one
451
- * voice (ADR-0070 A15 decision ②).
452
- */
453
- storedRows.map(message => ({
454
- id: message.id,
455
- role: message.role,
456
- /*
457
- * A file sent in an earlier turn is not sent again - one line names it, and the model opens it
458
- * with readChatAttachment when it needs to (cost is a usage axis, ADR-0061 decision 6).
459
- */
460
- content: [
461
- message.content,
462
- ...(message.id !== userMessageId && Array.isArray((message as any).attachmentsJson) ? (message as any).attachmentsJson.map(attachmentHistoryLine) : []),
463
- /* An answer that offered cards names them, so a later outcome row reads as about one of them (audit N7). */
464
- ...(message.role === 'assistant' ? offeredCardLines((message as any).proposals) : [])
465
- ].join('\n'),
466
- senderId: (message as any).creator?.id,
467
- senderName: (message as any).creator?.name,
468
- addressee: (message as any).addressee
469
- })),
470
- {
471
- maxTurns: LLM_HISTORY_MAX_TURNS,
472
- truncateAfterMessageId: input.truncateAfterMessageId,
473
- /* The message just stored is this turn's question — truncation must never drop it. */
474
- keepMessageIds: userMessageId ? [userMessageId] : undefined,
475
- summary: (session as any).lastSummary
476
- ? { text: (session as any).lastSummary, upToMessageId: (session as any).summaryUpToMessageId }
477
- : undefined
478
- }
479
- )
480
- : input.messages.map(message => ({ role: message.role as any, content: message.content }))
481
-
482
- /*
483
- * The files checked above, read once: the model reads them on this turn's question, and the tools get the same
484
- * files as `context.attachments` (ADR-0061, 2026-10-16 decision 2) - figure's step generator draws from the
485
- * picture the person sent. Never mixed into `hostContext`, which the client fills.
486
- */
487
- const turnFiles = await readTurnAttachments(
488
- attachmentRows,
489
- textCharsOf(getAssistantMode(input.mode?.kind ?? '')?.attachments),
490
- attachmentForModel
491
- )
492
- if (attachmentRows.length && conversation.length > 0) {
493
- const last = conversation[conversation.length - 1]
494
- if (last.role === 'user' && typeof last.content === 'string') {
495
- last.content = [{ type: 'text', text: last.content }, ...turnFiles.parts] as any
496
- }
497
- } else if (input.hostContext?.image?.data && conversation.length > 0) {
498
- /* The screen-image path (figure's rendered view) - not a file of the conversation. */
499
- const last = conversation[conversation.length - 1]
500
- if (last.role === 'user' && typeof last.content === 'string') {
501
- const raw = input.hostContext.image
502
- const rawData = typeof raw.data === 'string' ? raw.data.replace(/^data:image\/[a-zA-Z]+;base64,/, '') : raw.data
503
- const buf = typeof rawData === 'string' ? Buffer.from(rawData, 'base64') : Buffer.from(rawData)
504
- last.content = [
505
- { type: 'text', text: last.content },
506
- { type: 'image', source: { kind: 'base64', data: buf, mediaType: raw.mediaType || 'image/png' } }
507
- ] as any
508
- }
509
- }
510
-
511
- const result = await registryAssistantChat({
512
- client,
513
- messages: conversation as any,
514
- systemPrompt,
515
- toolCategories: settings.toolCategories,
516
- /*
517
- * What goes in front when the mode's tools do not fit in one call (ADR-0061 decision 9): the open page's, the
518
- * anchored record's and the latest selection's, then what this conversation used. The anchor and the selection are
519
- * the stored ones, never the client's.
520
- */
521
- front: {
522
- categories: modeFrontCategories(getAssistantMode(input.mode.kind) ?? {}, {
523
- page: input.page,
524
- subjectAxis: (session as any)?.anchorType === 'subject' ? String((session as any).anchorId ?? '').split(':')[0] || undefined : undefined,
525
- selectionAxes: selectionAxesOf(storedRows as any)
526
- }),
527
- tools: usedToolNames(storedRows as any, [OPEN_TOOLS])
528
- },
529
- /* 도구가 「어느 대화에서 불렸나」를 안다 — 서버의 값이다(ADR-0061 결정 3). */
530
- mode: { kind: input.mode.kind, ...(input.mode.target ? { target: input.mode.target } : {}) },
531
- /* And which stored conversation - the room a tool like the invite card acts on. The server's session, never the client's. */
532
- ...(session?.id ? { conversation: { id: session.id } } : {}),
533
- toolAccess: toolAccessFor(context),
534
- /* The stop notice is a sentence a person reads — the server writes it in their language (ADR-0054). */
535
- t,
536
- hostContext: input.hostContext,
537
- attachments: turnFiles.forTools,
538
- /*
539
- * 근거는 도구 결과만이 아니다 — 시스템 프롬프트 · 이 대화의 말 · 화면이 보낸 스냅숏도 근거다
540
- * (`ai-client-base/utils/grounding`). 이 문은 그 셋을 넘기지 않아, **사람이 방금 타이핑한
541
- * 식별자**를 되받아 적은 답이 「근거 없음」으로 표시됐다. 그런 경고가 몇 번 나오면 사람이 경고
542
- * 자체를 안 보게 된다.
543
- */
544
- groundingSources: groundingSourcesFor({
545
- systemPrompt,
546
- messages: conversation as any,
547
- hostContext: input.hostContext
548
- }),
549
- state: context.state,
550
- temperature: settings.temperature,
551
- maxTokens: settings.maxTokens,
552
- requireToolOnFirstTurn: settings.requireToolOnFirstTurn
553
- })
554
-
555
- /*
556
- * 이 답이 지나온 문 — ADR-0073 판정 1. 행에도, 목록 미리보기에도 같은 값이 간다. 한쪽만 적으면
557
- * 가려진 답이 목록에는 그대로 뜬다.
558
- */
559
- /* The reply ends with the next request when one is natural; the input offers it and the stored answer does not keep it (§4-1). */
560
- const { reply, suggestion } = splitNextRequest(result.reply)
561
-
562
- const answerDoors = doorsForAnswer(
563
- result.loop.toolUsages ?? [],
564
- name => (findToolSpec(name, settings.toolCategories) as any)?.doors
565
- )
566
-
567
- let assistantMessageId: string | undefined
568
- if (session) {
569
- const stored = await messageRepo.save({
570
- session: { id: session.id } as any,
571
- role: 'assistant',
572
- content: reply,
573
- /*
574
- * 이 답이 지나온 문을 함께 적는다 — ADR-0073 판정 1. 방은 도메인 안에서 공개이므로, 이 문장이
575
- * 실어 나르는 값을 나중에 읽는 사람이 열 수 있는지 판정할 근거가 행에 있어야 한다. 적지 않으면
576
- * 빈 목록이 되고, 빈 목록은 누구나 읽는다는 뜻이다.
577
- */
578
- doors: answerDoors,
579
- toolUsages: result.loop.toolUsages?.length ? JSON.stringify(result.loop.toolUsages) : undefined,
580
- proposals: result.loop.proposals?.length ? JSON.stringify(result.loop.proposals) : undefined,
581
- groundingWarnings: result.groundingWarnings?.length ? JSON.stringify(result.groundingWarnings) : undefined,
582
- creator: user,
583
- updater: user,
584
- parentMessage: userMessageId ? ({ id: userMessageId } as any) : undefined
585
- })
586
- assistantMessageId = stored.id
587
-
588
- publishChatMessage({ domainId: domain.id, sessionId: session.id, message: stored } as any)
589
- /* The reply is session activity too. Leaving it out shows other participants "nothing new". */
590
- publishSessionActivity({
591
- domainId: domain.id,
592
- sessionId: session.id!,
593
- kind: 'message',
594
- anchorType: (session as any).anchorType,
595
- anchorId: (session as any).anchorId,
596
- preview: reply,
597
- actorId: user?.id
598
- })
599
-
600
- await sessionRepo.update(session.id!, {
601
- aiClientId: client.id,
602
- agentId: client.agent.id,
603
- updater: user,
604
- ...activityPatch(reply, new Date(), answerDoors)
605
- } as any)
606
-
607
- /*
608
- * 상한 밖으로 밀려난 앞부분을 요약으로 접는다 — **답을 돌려준 뒤**에 한다(사용자 대기 시간에
609
- * 요약 호출을 얹지 않는다). 기다리지 않으므로 실패해도 대화에는 영향이 없다: 요약이 없으면 다음
610
- * 턴이 「N 개 생략」으로 정직하게 알린다.
611
- *
612
- * 이 문에는 이 호출이 없었다. 조각은 다 있었는데(상한 · 생략 알림 · `lastSummary` · 순수 규칙)
613
- * 부르는 쪽이 보드 제품 하나뿐이어서, 앱의 대화는 며칠이 지나도 앞부분을 요약하지 않고 매 턴
614
- * 「생략했다」고만 말했다 — 협의가 길어질수록 처음에 합의한 것이 먼저 사라진다.
615
- */
616
- void foldSessionHistory({
617
- sessionId: session.id!,
618
- domainId: domain.id,
619
- client,
620
- maxTurns: LLM_HISTORY_MAX_TURNS,
621
- locale: context.state?.lng
622
- })
623
- }
624
-
625
- return {
626
- reply,
627
- suggestion: suggestion ?? null,
628
- clientId: client.id,
629
- agentId: client.agent.id,
630
- sessionId: session?.id,
631
- userMessageId,
632
- assistantMessageId,
633
- toolUsages: result.loop.toolUsages?.length ? result.loop.toolUsages : null,
634
- offeredTools: result.offeredTools,
635
- proposals: result.loop.proposals?.length ? result.loop.proposals : null,
636
- groundingWarnings: result.groundingWarnings?.length ? result.groundingWarnings : null,
637
- historyFolded: historyFolded ?? null
638
- }
639
- }
640
- }