@things-factory/ai-assistant 10.1.278 → 10.1.280

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,44 +0,0 @@
1
- /*
2
- * 읽는 사람의 관문 — ADR-0073 판정 1·2 를 요청 하나에 세운다.
3
- *
4
- * 리졸버는 이것을 한 번 만들고 행 목록을 통과시킨다. 문 판정은 (사람, 문) 별로 한 번만 일어나고,
5
- * 세션이 private 인지도 여기서 함께 답한다. 리졸버마다 같은 판정을 다시 적으면 한 곳이 빠진 날
6
- * 그 문으로 샌다.
7
- */
8
- import { checkPermission, privilegeOfField } from '@things-factory/auth-base'
9
-
10
- import { doorCheck } from './door-access.js'
11
- import { doorGate, redactByDoors, type DoorReadableRow } from './message-doors.js'
12
- import { requestTranslator } from '../request-translator.js'
13
-
14
- /** 이 요청에서 행을 가려 내보내는 함수. 같은 요청 안에서 계속 쓴다. */
15
- export function readerGate(context: any): <T extends DoorReadableRow>(rows: readonly T[]) => Promise<T[]> {
16
- const { domain, user } = context.state
17
- const t = requestTranslator(context)
18
-
19
- const { unsafeIP, prohibitedPrivileges } = context.state
20
-
21
- const gate = doorGate(
22
- /* 문에서 쓰는 판정을 그대로 쓴다 — 같은 인자, 같은 함수(ADR-0072 결정 5). */
23
- doorCheck({
24
- lookup: privilegeOfField,
25
- permits: fieldGate => checkPermission(fieldGate as any, user, domain, unsafeIP, prohibitedPrivileges)
26
- })
27
- )
28
-
29
- /*
30
- * 문 이름(`Query.productionReports`)은 이 문장에 넣지 않는다.
31
- *
32
- * 현장에서 읽는 사람에게 GraphQL 이름은 아무 말도 아니다. 문 이름을 사람의 말로 바꿀 표는 AUTH 의
33
- * 필드→권한 표와 같은 자리에서 나와야 하고, 그것은 아직 없다(ADR-0072 결정 2 (b)). 없는 표를 흉내
34
- * 내느니 문장은 사실만 말하고, 목록은 `ChatMessage.doors` 로 따로 나간다 — 관리자에게 무엇을
35
- * 청할지 알아야 하는 화면은 거기서 읽는다. 문구는 UX 레인이 정한다.
36
- */
37
- return rows =>
38
- redactByDoors(rows, gate, () =>
39
- t('ai-assistant.text.answer-needs-permission', {
40
- /* 구독에는 요청 번역기가 없다 — `request-translator.ts` 참조. */
41
- defaultValue: 'you do not have permission to see this answer. ask an administrator for access.'
42
- })
43
- )
44
- }
@@ -1,21 +0,0 @@
1
- /*
2
- * What this guards: the people's door keeps what was said, and refuses what was not.
3
- *
4
- * An empty turn stored as a message is a blank line in a shared conversation and a blank line in
5
- * what the model reads — both mean "someone said something" when nobody did.
6
- */
7
- import { ROOM_MESSAGE_LIMIT, roomMessageBody } from './room-message'
8
-
9
- it('keeps what was said, without the whitespace around it', () => {
10
- expect(roomMessageBody(' 3 라인이 멈춘 것 같아요 ')).toBe('3 라인이 멈춘 것 같아요')
11
- })
12
-
13
- it('★ an empty turn is nothing to store', () => {
14
- expect(roomMessageBody(' ')).toBeUndefined()
15
- expect(roomMessageBody('')).toBeUndefined()
16
- expect(roomMessageBody(undefined)).toBeUndefined()
17
- })
18
-
19
- it('a very long turn is capped — this is a conversation, not an archive', () => {
20
- expect(roomMessageBody('가'.repeat(ROOM_MESSAGE_LIMIT + 100))?.length).toBe(ROOM_MESSAGE_LIMIT)
21
- })
@@ -1,22 +0,0 @@
1
- /*
2
- * A person saying something to the room (ADR-0070 A15).
3
- *
4
- * The addressee column has two values and, until this door, a screen could only produce one of
5
- * them: every turn a person typed went through `assistantChat`, which means every turn was for the
6
- * assistant. `room` existed only on turns carried in from somewhere else. So the half of the design
7
- * that says "people also talk to each other here, and the assistant reads it as context" had no way
8
- * to happen.
9
- *
10
- * The rule the door follows is the same one: the addressee comes from **which door was called**,
11
- * never from an argument. This one is the people's door — it stores the turn and does not call the
12
- * model. Nobody is answered, and that silence is the point (A15 decision ⑦).
13
- */
14
-
15
- /** How much of one turn is kept — the same cap the carried turns use. */
16
- export const ROOM_MESSAGE_LIMIT = 4000
17
-
18
- /** Trimmed and capped, or nothing when there is no message. */
19
- export function roomMessageBody(content: string | undefined | null): string | undefined {
20
- const body = (content ?? '').trim().slice(0, ROOM_MESSAGE_LIMIT)
21
- return body || undefined
22
- }
@@ -1,42 +0,0 @@
1
- /*
2
- * A person spoke to the people of a conversation - told to the modules that wait for it. worklist closes a question it
3
- * handed to that person once they answer in the conversation it came from (ADR-0200 decision 3).
4
- *
5
- * Only the door that stores words to the room tells (`sendRoomMessage`): what the person asks the assistant - polish
6
- * my draft - is not their answer.
7
- */
8
- import { logger } from '@things-factory/env'
9
-
10
- export interface RoomTurn {
11
- domain: { id: string }
12
- /** Who spoke. */
13
- user: { id: string; name?: string; email?: string }
14
- session: { id: string; anchorType?: string | null; anchorId?: string | null }
15
- /** The message as stored. */
16
- message: { id: string; content: string }
17
- /** The request's transaction - a listener writes in it, so the turn and what it closed stand or fall together. */
18
- tx?: any
19
- /** The request's translator. */
20
- t?: (key: string, options?: any) => string
21
- }
22
-
23
- type Listener = (turn: RoomTurn) => void | Promise<void>
24
-
25
- const listeners = new Set<Listener>()
26
-
27
- /** A module waits for people's words in conversations. Answers the way to stop. */
28
- export function onRoomTurn(listener: Listener): () => void {
29
- listeners.add(listener)
30
- return () => listeners.delete(listener)
31
- }
32
-
33
- /** Every listener hears the turn; one that fails is logged and does not stop the person's words. */
34
- export async function tellRoomTurn(turn: RoomTurn): Promise<void> {
35
- for (const listener of listeners) {
36
- try {
37
- await listener(turn)
38
- } catch (error: any) {
39
- logger.error(`[ai-assistant/room-turn] a listener failed for session ${turn.session.id}: ${error?.message ?? error}`)
40
- }
41
- }
42
- }
@@ -1,19 +0,0 @@
1
- import { usedToolNames } from './used-tools'
2
-
3
- const answer = (...names: string[]) => ({ role: 'assistant', toolUsages: JSON.stringify(names.map(name => ({ name, arguments: {}, kind: 'read' }))) })
4
-
5
- describe('the tools a conversation used, for the front of the next turn (ADR-0061 decision 9)', () => {
6
- it('★ the latest answer first, the latest call of it first, each once', () => {
7
- const rows = [answer('readA', 'readB'), { role: 'user', toolUsages: undefined }, answer('readC', 'readA')]
8
- expect(usedToolNames(rows)).toEqual(['readA', 'readC', 'readB'])
9
- })
10
-
11
- it('★ the opening tool is not a tool to put in front', () => {
12
- expect(usedToolNames([answer('openTools', 'readA')], ['openTools'])).toEqual(['readA'])
13
- })
14
-
15
- it('a person\'s line and a trace that does not read are skipped', () => {
16
- const rows = [{ role: 'user', toolUsages: JSON.stringify([{ name: 'readX' }]) }, { role: 'assistant', toolUsages: '{broken' }, answer('readA')]
17
- expect(usedToolNames(rows)).toEqual(['readA'])
18
- })
19
- })
@@ -1,25 +0,0 @@
1
- /**
2
- * The tools the earlier answers of a conversation called, the latest first (ADR-0061 decision 9).
3
- *
4
- * A turn puts them in front after the open screen's records, so a question that follows on from the last one finds the
5
- * tool it needs without opening it again. Read from the stored trace (`ChatMessage.toolUsages`); a trace that does not
6
- * read is skipped, as the dock's tool panel skips it.
7
- */
8
- export function usedToolNames(rows: ReadonlyArray<{ role?: string; toolUsages?: string | null }>, skip: ReadonlyArray<string> = []): string[] {
9
- const out: string[] = []
10
- for (const row of [...rows].reverse()) {
11
- if (row.role !== 'assistant' || !row.toolUsages) continue
12
- let usages: unknown
13
- try {
14
- usages = JSON.parse(row.toolUsages)
15
- } catch {
16
- continue
17
- }
18
- if (!Array.isArray(usages)) continue
19
- for (const usage of [...usages].reverse()) {
20
- const name = typeof usage?.name === 'string' ? usage.name : undefined
21
- if (name && !skip.includes(name) && !out.includes(name)) out.push(name)
22
- }
23
- }
24
- return out
25
- }
@@ -1,42 +0,0 @@
1
- /* What a conversation accepts as attachments - design/ai/shared-dock.md §9-1. */
2
- import { attachmentHistoryLine, attachmentKindOf, refuseAttachments } from './attachment-policy'
3
-
4
- describe('attachment policy', () => {
5
- const policy = { kinds: ['image', 'text'] as any, maxBytes: 1000, maxFiles: 2 }
6
-
7
- it('a mode that declares nothing takes nothing - no file the model would never see', () => {
8
- expect(refuseAttachments(undefined, [{ name: 'a.png', type: 'image/png', size: 1 }])).toEqual({ code: 'attachments-not-accepted' })
9
- expect(refuseAttachments({ kinds: [] }, [{ name: 'a.png', type: 'image/png' }])).toEqual({ code: 'attachments-not-accepted' })
10
- })
11
-
12
- it('no files is no refusal', () => {
13
- expect(refuseAttachments(undefined, [])).toBeNull()
14
- })
15
-
16
- it('kinds come from the type, or the name when the browser did not know the type', () => {
17
- expect(attachmentKindOf({ type: 'image/jpeg' })).toBe('image')
18
- expect(attachmentKindOf({ type: 'text/csv' })).toBe('text')
19
- expect(attachmentKindOf({ type: '', name: 'report.CSV' })).toBe('text')
20
- expect(attachmentKindOf({ type: 'application/pdf', name: 'a.pdf' })).toBeNull()
21
- })
22
-
23
- it('each limit refuses by name, before sending', () => {
24
- expect(refuseAttachments(policy, [{ name: 'a.pdf', type: 'application/pdf', size: 1 }])).toMatchObject({ code: 'attachment-kind-not-accepted', name: 'a.pdf' })
25
- expect(refuseAttachments(policy, [{ name: 'big.png', type: 'image/png', size: 1001 }])).toMatchObject({ code: 'attachment-too-large', name: 'big.png', maxBytes: 1000 })
26
- expect(refuseAttachments(policy, [{ name: 'a.png', type: 'image/png', size: 1 }, { name: 'b.png', type: 'image/png', size: 1 }, { name: 'c.png', type: 'image/png', size: 1 }])).toEqual({ code: 'too-many-attachments', maxFiles: 2 })
27
- })
28
-
29
- it('a kind outside the declared ones is refused', () => {
30
- expect(refuseAttachments({ kinds: ['image'] }, [{ name: 'a.csv', type: 'text/csv', size: 1 }])).toMatchObject({ code: 'attachment-kind-not-accepted' })
31
- })
32
-
33
- it('files within the policy go', () => {
34
- expect(refuseAttachments(policy, [{ name: 'a.png', type: 'image/png', size: 10 }, { name: 'b.csv', type: 'text/csv', size: 10 }])).toBeNull()
35
- })
36
-
37
- it('the line an earlier turn keeps names the file and how to open it', () => {
38
- expect(attachmentHistoryLine({ id: 'f1', name: 'press.csv', mimetype: 'text/csv', size: 120 })).toBe(
39
- '[attachment f1: press.csv (text/csv, 120 bytes) - readChatAttachment to open it]'
40
- )
41
- })
42
- })
@@ -1,91 +0,0 @@
1
- /*
2
- * What a conversation accepts as attachments - declared by its mode (design/ai/shared-dock.md §9-1).
3
- *
4
- * Pure, so the rule is tested alone and the screen can say "no" before anything is sent. A mode that
5
- * declares nothing accepts nothing: the chat once took .csv and .json, carried them, and no code ever
6
- * showed them to the model - the person got an answer about a file it had never seen (AI standard §7).
7
- */
8
-
9
- /*
10
- * 'spreadsheet' and 'document' are kinds a mode opens, never files the door receives: the screen reads each .xlsx sheet
11
- * into CSV text (client/utils/spreadsheet-text.ts), and each PDF, .docx and .pptx into text with its page and slide
12
- * numbers (client/utils/document-text.ts) before sending, so a mode that takes them takes that text. A scanned PDF
13
- * page arrives as an image, which the mode takes as 'image'.
14
- */
15
- export type AttachmentKind = 'image' | 'text' | 'spreadsheet' | 'document'
16
-
17
- export interface AttachmentPolicy {
18
- kinds: AttachmentKind[]
19
- /** Per file. */
20
- maxBytes?: number
21
- /** Per message. */
22
- maxFiles?: number
23
- /** Per text file, the characters the model reads - a sheet read into text longer than this is refused, not cut. */
24
- maxChars?: number
25
- }
26
-
27
- export const DEFAULT_MAX_BYTES = 5 * 1024 * 1024
28
- export const DEFAULT_MAX_FILES = 5
29
- /** How much of a text file reaches the model in the turn it was sent. */
30
- export const TEXT_CHARS_FOR_MODEL = 20_000
31
-
32
- const TEXT_TYPES = ['text/plain', 'text/csv', 'text/markdown', 'application/json']
33
- const TEXT_EXTENSIONS = ['.txt', '.csv', '.md', '.json']
34
-
35
- /** Which kind a file is, from its type - and its name when the browser did not know the type. */
36
- export function attachmentKindOf(file: { type?: string; name?: string }): AttachmentKind | null {
37
- const type = (file.type || '').toLowerCase()
38
- if (type.startsWith('image/')) return 'image'
39
- if (TEXT_TYPES.includes(type)) return 'text'
40
- const name = (file.name || '').toLowerCase()
41
- if (TEXT_EXTENSIONS.some(ext => name.endsWith(ext))) return 'text'
42
- return null
43
- }
44
-
45
- export type AttachmentRefusal =
46
- | { code: 'attachments-not-accepted' }
47
- | { code: 'attachment-kind-not-accepted'; name: string; kinds: AttachmentKind[] }
48
- | { code: 'attachment-too-large'; name: string; maxBytes: number }
49
- | { code: 'too-many-attachments'; maxFiles: number }
50
-
51
- /** `null` when every file may go; otherwise the first reason, by name - said before sending, never cut silently. */
52
- /** A kind the policy takes - text also when it takes spreadsheets or documents, which arrive as their text. */
53
- function takes(policy: AttachmentPolicy, kind: AttachmentKind): boolean {
54
- return policy.kinds.includes(kind) || (kind === 'text' && (policy.kinds.includes('spreadsheet') || policy.kinds.includes('document')))
55
- }
56
-
57
- /** The characters of a text file the model reads under this policy. */
58
- export function textCharsOf(policy: AttachmentPolicy | null | undefined): number {
59
- return policy?.maxChars ?? TEXT_CHARS_FOR_MODEL
60
- }
61
-
62
- export function refuseAttachments(
63
- policy: AttachmentPolicy | null | undefined,
64
- files: { name?: string; type?: string; size?: number }[]
65
- ): AttachmentRefusal | null {
66
- if (!files.length) return null
67
- if (!policy || !policy.kinds?.length) return { code: 'attachments-not-accepted' }
68
-
69
- /*
70
- * File by file, in the order sent: its kind, then its size, then whether it is one too many. The screen's picking
71
- * rule (@operato/utils sortPickedFiles) says them in this order, so the same batch hears the same "no" from both.
72
- */
73
- const maxFiles = policy.maxFiles ?? DEFAULT_MAX_FILES
74
- const maxBytes = policy.maxBytes ?? DEFAULT_MAX_BYTES
75
- let taken = 0
76
- for (const file of files) {
77
- const kind = attachmentKindOf(file)
78
- if (!kind || !takes(policy, kind)) {
79
- return { code: 'attachment-kind-not-accepted', name: file.name || '', kinds: policy.kinds }
80
- }
81
- if ((file.size ?? 0) > maxBytes) return { code: 'attachment-too-large', name: file.name || '', maxBytes }
82
- if (taken >= maxFiles) return { code: 'too-many-attachments', maxFiles }
83
- taken++
84
- }
85
- return null
86
- }
87
-
88
- /** The line history keeps for a file once its turn is past - the model reads the file again only by asking. */
89
- export function attachmentHistoryLine(file: { id: string; name?: string; mimetype?: string; size?: number | string }): string {
90
- return `[attachment ${file.id}: ${file.name || 'unnamed'} (${file.mimetype || 'unknown type'}, ${file.size ?? '?'} bytes) - readChatAttachment to open it]`
91
- }
@@ -1,45 +0,0 @@
1
- /*
2
- * Where a person opens a conversation's file - GET /chat-attachments/:sessionId/:attachmentId.
3
- *
4
- * Domain-private (sign-in and tenancy required), and the conversation's own read gate on top: a private
5
- * conversation's file opens for its participants only, a deleted conversation's for nobody (design/ai/
6
- * shared-dock.md §9-3). attachment-base's own route is public and unauthenticated, so chat files are
7
- * never linked through it. `private` caching - a shared cache must not keep a private conversation's file.
8
- */
9
- import { STORAGE } from '@things-factory/attachment-base'
10
- import { getRepository } from '@things-factory/shell'
11
-
12
- import { ChatSession } from './chat-session.js'
13
- import { mayReadSession } from './session-visibility.js'
14
- import { findChatAttachment } from './session-attachments.js'
15
- import { isSessionParticipant } from '../chat-session-participant/participant-lookup.js'
16
-
17
- export const CHAT_ATTACHMENT_ROUTE = 'chat-attachments'
18
-
19
- /** The address a screen uses for one file of a conversation. */
20
- export function chatAttachmentUrl(sessionId: string, attachmentId: string): string {
21
- return `/${CHAT_ATTACHMENT_ROUTE}/${encodeURIComponent(sessionId)}/${encodeURIComponent(attachmentId)}`
22
- }
23
-
24
- process.on('bootstrap-module-domain-private-route' as any, (_app: any, routes: any) => {
25
- routes.get(`/${CHAT_ATTACHMENT_ROUTE}/:sessionId/:attachmentId`, async (context: any, next: any) => {
26
- const { domain, user } = context.state
27
- const { sessionId, attachmentId } = context.params
28
-
29
- /* A soft-deleted conversation is not found here - its files close with it (§9-5). */
30
- const session: any = await getRepository(ChatSession).findOne({ where: { id: sessionId, domain: { id: domain.id } } as any })
31
- const readable = !!session && mayReadSession(session.visibility, await isSessionParticipant(domain.id, sessionId, user?.id))
32
- const row: any = readable ? await findChatAttachment(domain.id, sessionId, attachmentId) : undefined
33
-
34
- if (!row) {
35
- /* One answer for "none", "not yours" and "deleted" - telling them apart would say what exists. */
36
- context.status = 404
37
- return
38
- }
39
-
40
- context.set('Cache-Control', 'private, max-age=3600')
41
- context.set('Content-Disposition', `inline; filename*=UTF-8''${encodeURIComponent(row.name)}`)
42
- if (row.mimetype) context.type = row.mimetype
43
- await STORAGE.sendFile(context, row.path, next)
44
- })
45
- })
@@ -1,63 +0,0 @@
1
- /*
2
- * readChatAttachment's answer (design/ai/shared-dock.md §9-4) - a picture of an earlier turn comes back as the picture.
3
- */
4
- /* The source, not the built package - the two land together and the test must see the change before a build. */
5
- import { takeToolImages } from '../../../../ai-client-base/server/service/agentic-loop/agentic-loop'
6
-
7
- import { readFileSync } from 'fs'
8
- import { join } from 'path'
9
-
10
- import { attachmentIdOf, attachmentToolResult, NO_SUCH_ATTACHMENT } from './attachment-tool-result'
11
-
12
- describe('a file opened again in a later turn', () => {
13
- const png = Buffer.from([0x89, 0x50, 0x4e, 0x47, 9])
14
-
15
- it('★ a picture comes back as the picture - not as a request to send it again', () => {
16
- const answer: any = attachmentToolResult('a1', { type: 'image', data: png, mediaType: 'image/png', name: '영수증.png' })
17
- expect(answer.images).toEqual([{ data: png, mediaType: 'image/png' }])
18
- expect(answer.note).not.toMatch(/send it again/)
19
- /* What the loop makes of it: the picture as an image part, the rest as the JSON the model reads. */
20
- const { value, images } = takeToolImages(answer)
21
- expect(images).toHaveLength(1)
22
- expect(value).toEqual({ attachmentId: 'a1', name: '영수증.png', type: 'image', note: answer.note, imagesAttached: 1 })
23
- })
24
-
25
- it('a text file comes back as its text, and a cut one says so', () => {
26
- expect(attachmentToolResult('t1', { type: 'text', text: 'a,b', name: 'x.csv', truncated: false })).toEqual({ attachmentId: 't1', name: 'x.csv', type: 'text', text: 'a,b' })
27
- expect(attachmentToolResult('t1', { type: 'text', text: 'a', name: 'x.csv', truncated: true })).toMatchObject({ note: 'the file is longer; this is its beginning.' })
28
- })
29
- })
30
-
31
- /* 2026-10-24: a deposit's id was asked for as a file eight times in one turn. */
32
- describe('an id that names no file', () => {
33
- it('★ is told it is no attachment and not to ask again', () => {
34
- expect(NO_SUCH_ATTACHMENT).toMatch(/it is not an attachment/)
35
- expect(NO_SUCH_ATTACHMENT).toMatch(/Do not ask for it again/)
36
- })
37
- })
38
-
39
- describe('the file id in what the model wrote', () => {
40
- const ID = '0f3c2a9e-1b2d-4c5e-8f90-a1b2c3d4e5f6'
41
-
42
- it('★ the whole history line is read as the id it begins with (office.hatiolab.com, 2026-10-29: postgres 22P02)', () => {
43
- expect(attachmentIdOf(`${ID}: 기술개발인력 이력서.pdf.txt (text/plain, 6429 bytes) - readChatAttachment to open it`)).toBe(ID)
44
- expect(attachmentIdOf(`[attachment ${ID}: 영수증.png]`)).toBe(ID)
45
- expect(attachmentIdOf(` ${ID.toUpperCase()} `)).toBe(ID.toUpperCase())
46
- })
47
-
48
- it('★ anything else names no file - a record key, a cut id, words', () => {
49
- expect(attachmentIdOf(`contract:${ID}`)).toBeUndefined()
50
- expect(attachmentIdOf(ID.slice(0, 33))).toBeUndefined()
51
- expect(attachmentIdOf(`${ID}0`)).toBeUndefined()
52
- expect(attachmentIdOf('unknown')).toBeUndefined()
53
- expect(attachmentIdOf(undefined)).toBeUndefined()
54
- })
55
-
56
- it('★ both readers ask the database only for the id read out of it', () => {
57
- const tool = readFileSync(join(__dirname, 'attachment-tools.ts'), 'utf8')
58
- expect(tool).toMatch(/const id = attachmentIdOf\(given\)\n\s+if \(!id\) return \{ absent: 'not-found'/)
59
- expect(tool.indexOf('attachmentIdOf(given)')).toBeLessThan(tool.indexOf('getRepository(Attachment).findOne'))
60
- const sources = readFileSync(join(__dirname, '..', 'data-entry', 'entry-sources.ts'), 'utf8')
61
- expect(sources).toMatch(/const fileId = attachmentIdOf\(id\)\n\s+if \(!fileId\) continue\n\s+const row: any = await getRepository\(Attachment\)\.findOne\(\{ where: \{ id: fileId,/)
62
- })
63
- })
@@ -1,37 +0,0 @@
1
- /*
2
- * What readChatAttachment answers for a file of the conversation (design/ai/shared-dock.md §9-4).
3
- *
4
- * A text file comes back as its text. A picture comes back as the picture: the reserved `images` field is taken out
5
- * of the JSON by the loop (ai-client-base takeToolImages) and sent as an image part of the same turn - so a receipt
6
- * sent three turns ago can be read again without asking the person to send it again.
7
- *
8
- * Pure, so it is tested without storage or the shell.
9
- */
10
- export type FileForModel =
11
- | { type: 'image'; data: Buffer; mediaType: string; name: string }
12
- | { type: 'text'; text: string; name: string; truncated: boolean }
13
-
14
- export function attachmentToolResult(attachmentId: string, file: FileForModel) {
15
- return file.type === 'image'
16
- ? { attachmentId, name: file.name, type: 'image', images: [{ data: file.data, mediaType: file.mediaType }], note: 'the picture is attached right after this result - look at it.' }
17
- : { attachmentId, name: file.name, type: 'text', text: file.text, ...(file.truncated ? { note: 'the file is longer; this is its beginning.' } : {}) }
18
- }
19
-
20
- /*
21
- * What an id that names no file of the conversation gets (2026-10-24): given a deposit's id, the model asked for it as a
22
- * file eight times in one turn. The answer says the id is no file and where a record is read instead.
23
- */
24
- export const NO_SUCH_ATTACHMENT =
25
- 'there is no file with this id in a conversation here - it is not an attachment. Do not ask for it again; a record is read with its own read tool.'
26
-
27
- /*
28
- * The file's id in what the model wrote (2026-10-29, office.hatiolab.com): it passed the whole history line -
29
- * 「<id>: 이력서.pdf.txt (text/plain, 1547 bytes) - readChatAttachment to open it」 - and postgres refused the text as a
30
- * uuid (22P02). The id is the uuid the text begins with, after an optional "[attachment "; anything else - a record's
31
- * key, a cut id - names no file and is not asked of the database.
32
- */
33
- const LEADING_ID = /^\[?(?:attachment\s+)?([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?![0-9a-f-])/i
34
-
35
- export function attachmentIdOf(text: unknown): string | undefined {
36
- return typeof text === 'string' ? LEADING_ID.exec(text.trim())?.[1] : undefined
37
- }
@@ -1,66 +0,0 @@
1
- /*
2
- * readChatAttachment - the model opens a file sent in an earlier turn (design/ai/shared-dock.md §9-4).
3
- *
4
- * A file reaches the model in full only in the turn it was sent; later turns carry one line naming it.
5
- * When the model needs it again it asks here - a text file comes back as its text, a picture as the picture itself. The caller must be able to read the conversation the file
6
- * belongs to - the same gate as reading its messages (ADR-0073 decision 1) - so a file id from elsewhere
7
- * opens nothing.
8
- *
9
- * The category is opened for every mode that declares an attachment policy (resolve.ts).
10
- */
11
- import { registerToolCategory, type ToolCategory, type ToolSpec } from '@things-factory/ai-client-base'
12
- import { Attachment } from '@things-factory/attachment-base'
13
- import { getRepository } from '@things-factory/shell'
14
-
15
- import { ChatSession } from './chat-session.js'
16
- import { mayReadSession } from './session-visibility.js'
17
- import { isSessionParticipant } from '../chat-session-participant/participant-lookup.js'
18
- import { attachmentForModel, CHAT_ATTACHMENT_REF } from './session-attachments.js'
19
- import { textCharsOf } from './attachment-policy.js'
20
- import { getAssistantMode } from '../assistant-mode/registry.js'
21
- import { attachmentIdOf, attachmentToolResult, NO_SUCH_ATTACHMENT } from './attachment-tool-result.js'
22
-
23
- export const CHAT_ATTACHMENT_CATEGORY = 'chat-attachments'
24
-
25
- const readChatAttachment: ToolSpec = {
26
- kind: 'read',
27
- name: 'readChatAttachment',
28
- doors: ['Query.chatMessages'],
29
- description:
30
- 'Open a file that was sent earlier in this conversation. History names such files as "[attachment <id>: <name> ...]"; ' +
31
- 'pass that id. An image comes back as the picture itself, a text file as its text (cut when long - the answer says so).',
32
- schema: {
33
- type: 'object',
34
- properties: { attachmentId: { type: 'string', description: 'The id from the "[attachment <id>: ...]" line.' } },
35
- required: ['attachmentId']
36
- },
37
- builder: async (args: any, context: any) => {
38
- const { domain, user } = context?.state ?? {}
39
- const given = typeof args?.attachmentId === 'string' ? args.attachmentId.trim() : ''
40
- if (!domain?.id || !given) return { absent: 'no-attachment', message: 'no attachment id was given.' }
41
- const id = attachmentIdOf(given)
42
- if (!id) return { absent: 'not-found', attachmentId: given, message: NO_SUCH_ATTACHMENT }
43
-
44
- const row: any = await getRepository(Attachment).findOne({ where: { id, domain: { id: domain.id }, refType: CHAT_ATTACHMENT_REF } as any })
45
- const session: any = row && (await getRepository(ChatSession).findOne({ where: { id: row.refBy, domain: { id: domain.id } } as any }))
46
- if (!row || !session) return { absent: 'not-found', attachmentId: id, message: NO_SUCH_ATTACHMENT }
47
-
48
- const participant = await isSessionParticipant(domain.id, session.id, user?.id)
49
- if (!mayReadSession(session.visibility, participant)) {
50
- /* Same answer as absent - saying "it exists but is private" would itself leak. */
51
- return { absent: 'not-found', attachmentId: id, message: NO_SUCH_ATTACHMENT }
52
- }
53
-
54
- const file = await attachmentForModel(row, textCharsOf(getAssistantMode(session.kind || '')?.attachments))
55
- return attachmentToolResult(id, file)
56
- }
57
- } as ToolSpec
58
-
59
- export const chatAttachmentCategory: ToolCategory = {
60
- name: CHAT_ATTACHMENT_CATEGORY,
61
- guidance:
62
- '- A line "[attachment <id>: <name> ...]" names a file sent in an earlier turn. Call readChatAttachment with that id before answering about its contents; never guess what a file says.',
63
- specs: [readChatAttachment]
64
- }
65
-
66
- registerToolCategory(chatAttachmentCategory)