@things-factory/ai-assistant 10.1.277 → 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 (537) 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/dist-server/service/assistant-mode/mode-categories.js +2 -2
  23. package/dist-server/service/chat-message/message-doors.d.ts +6 -10
  24. package/dist-server/service/chat-message/message-doors.js +5 -12
  25. package/dist-server/service/data-read/read-target.d.ts +3 -4
  26. package/dist-server/service/people/person-subject.d.ts +9 -5
  27. package/dist-server/service/people/person-subject.js +14 -19
  28. package/package.json +25 -10
  29. package/things-factory.config.js +4 -1
  30. package/translations/en.json +46 -4
  31. package/translations/es.json +43 -1
  32. package/translations/ja.json +43 -1
  33. package/translations/ko.json +46 -4
  34. package/translations/ms.json +43 -1
  35. package/translations/zh.json +43 -1
  36. package/client/bootstrap.ts +0 -27
  37. package/client/components/assistant-chat.test.ts +0 -149
  38. package/client/components/assistant-chat.ts +0 -5599
  39. package/client/components/assistant-dock.ts +0 -1036
  40. package/client/components/assistant-invite.ts +0 -138
  41. package/client/components/assistant-mode.test.ts +0 -119
  42. package/client/components/assistant-mode.ts +0 -174
  43. package/client/components/assistant-selection-bar.test.ts +0 -167
  44. package/client/components/assistant-selection-bar.ts +0 -178
  45. package/client/components/assistant-session-manager.ts +0 -915
  46. package/client/components/assistant-session-toolbar.ts +0 -80
  47. package/client/components/chat-defaults.ts +0 -64
  48. package/client/components/chat-echo-dedup.test.ts +0 -253
  49. package/client/components/chat-echo-dedup.ts +0 -190
  50. package/client/components/chat-input-builder.test.ts +0 -86
  51. package/client/components/chat-input-builder.ts +0 -133
  52. package/client/components/chat-proposal-survival.test.ts +0 -73
  53. package/client/components/entry-review.ts +0 -346
  54. package/client/components/markdown.test.ts +0 -518
  55. package/client/components/markdown.ts +0 -508
  56. package/client/components/mention-popup-helpers.ts +0 -433
  57. package/client/components/mention-popup.test.ts +0 -588
  58. package/client/components/mention-popup.ts +0 -261
  59. package/client/components/panel-aria.test.ts +0 -59
  60. package/client/components/proposal-outcome-line.ts +0 -74
  61. package/client/components/proposal-request.test.ts +0 -73
  62. package/client/components/reply-message.test.ts +0 -15
  63. package/client/components/reply-message.ts +0 -11
  64. package/client/components/roster-identity.test.ts +0 -8
  65. package/client/components/roster-identity.ts +0 -4
  66. package/client/components/workspace-view.ts +0 -486
  67. package/client/index.ts +0 -36
  68. package/client/pages/assistant-workspace-page.ts +0 -317
  69. package/client/route.ts +0 -9
  70. package/client/settings/agent-settings-model.ts +0 -164
  71. package/client/settings/ai-agent-setting-let.ts +0 -667
  72. package/client/settings/ai-usage-setting-let.ts +0 -240
  73. package/client/settings/usage-model.ts +0 -46
  74. package/client/setup-assistant-dock.ts +0 -177
  75. package/client/tsconfig.json +0 -13
  76. package/client/utils/addressed-draft.test.ts +0 -31
  77. package/client/utils/agent-choice.ts +0 -56
  78. package/client/utils/applied-screens.ts +0 -36
  79. package/client/utils/assistant-activity.ts +0 -122
  80. package/client/utils/assistant-ask.test.ts +0 -38
  81. package/client/utils/assistant-ask.ts +0 -93
  82. package/client/utils/assistant-capability-read.ts +0 -24
  83. package/client/utils/assistant-capability.test.ts +0 -17
  84. package/client/utils/assistant-capability.ts +0 -19
  85. package/client/utils/assistant-navigation.test.ts +0 -66
  86. package/client/utils/assistant-navigation.ts +0 -11
  87. package/client/utils/assistant-proposals.ts +0 -85
  88. package/client/utils/assistant-request-context.ts +0 -63
  89. package/client/utils/assistant-selection.test.ts +0 -54
  90. package/client/utils/assistant-selection.ts +0 -75
  91. package/client/utils/assistant-session-actions.ts +0 -32
  92. package/client/utils/assistant-session-admin.ts +0 -239
  93. package/client/utils/assistant-session-controller.test.ts +0 -75
  94. package/client/utils/assistant-session-controller.ts +0 -208
  95. package/client/utils/assistant-session-transport.ts +0 -46
  96. package/client/utils/assistant-surface.ts +0 -178
  97. package/client/utils/assistant-typing.test.ts +0 -33
  98. package/client/utils/assistant-typing.ts +0 -53
  99. package/client/utils/attachment-policy.ts +0 -106
  100. package/client/utils/composer-frame.ts +0 -77
  101. package/client/utils/document-text.ts +0 -332
  102. package/client/utils/entry-hash.ts +0 -35
  103. package/client/utils/entry-proposal.ts +0 -215
  104. package/client/utils/entry-workspace.ts +0 -70
  105. package/client/utils/invite-proposal-register.ts +0 -31
  106. package/client/utils/invite-proposal.test.ts +0 -40
  107. package/client/utils/invite-proposal.ts +0 -54
  108. package/client/utils/menu-room.ts +0 -33
  109. package/client/utils/open-page.ts +0 -21
  110. package/client/utils/pasted-table.ts +0 -145
  111. package/client/utils/pdf-pages.ts +0 -25
  112. package/client/utils/spreadsheet-text.ts +0 -125
  113. package/client/utils/workspace.ts +0 -89
  114. package/dist-client/bootstrap.js.map +0 -1
  115. package/dist-client/components/assistant-chat.js.map +0 -1
  116. package/dist-client/components/assistant-chat.test.d.ts +0 -1
  117. package/dist-client/components/assistant-chat.test.js +0 -138
  118. package/dist-client/components/assistant-chat.test.js.map +0 -1
  119. package/dist-client/components/assistant-dock.js.map +0 -1
  120. package/dist-client/components/assistant-invite.js.map +0 -1
  121. package/dist-client/components/assistant-mode.js.map +0 -1
  122. package/dist-client/components/assistant-mode.test.d.ts +0 -1
  123. package/dist-client/components/assistant-mode.test.js +0 -100
  124. package/dist-client/components/assistant-mode.test.js.map +0 -1
  125. package/dist-client/components/assistant-selection-bar.js.map +0 -1
  126. package/dist-client/components/assistant-selection-bar.test.d.ts +0 -1
  127. package/dist-client/components/assistant-selection-bar.test.js +0 -148
  128. package/dist-client/components/assistant-selection-bar.test.js.map +0 -1
  129. package/dist-client/components/assistant-session-manager.js.map +0 -1
  130. package/dist-client/components/assistant-session-toolbar.js.map +0 -1
  131. package/dist-client/components/chat-defaults.js.map +0 -1
  132. package/dist-client/components/chat-echo-dedup.js.map +0 -1
  133. package/dist-client/components/chat-echo-dedup.test.d.ts +0 -1
  134. package/dist-client/components/chat-echo-dedup.test.js +0 -223
  135. package/dist-client/components/chat-echo-dedup.test.js.map +0 -1
  136. package/dist-client/components/chat-input-builder.js.map +0 -1
  137. package/dist-client/components/chat-input-builder.test.d.ts +0 -1
  138. package/dist-client/components/chat-input-builder.test.js +0 -70
  139. package/dist-client/components/chat-input-builder.test.js.map +0 -1
  140. package/dist-client/components/chat-proposal-survival.test.d.ts +0 -1
  141. package/dist-client/components/chat-proposal-survival.test.js +0 -61
  142. package/dist-client/components/chat-proposal-survival.test.js.map +0 -1
  143. package/dist-client/components/entry-review.js.map +0 -1
  144. package/dist-client/components/markdown.js.map +0 -1
  145. package/dist-client/components/markdown.test.d.ts +0 -1
  146. package/dist-client/components/markdown.test.js +0 -418
  147. package/dist-client/components/markdown.test.js.map +0 -1
  148. package/dist-client/components/mention-popup-helpers.js.map +0 -1
  149. package/dist-client/components/mention-popup.js.map +0 -1
  150. package/dist-client/components/mention-popup.test.d.ts +0 -1
  151. package/dist-client/components/mention-popup.test.js +0 -474
  152. package/dist-client/components/mention-popup.test.js.map +0 -1
  153. package/dist-client/components/panel-aria.test.d.ts +0 -1
  154. package/dist-client/components/panel-aria.test.js +0 -53
  155. package/dist-client/components/panel-aria.test.js.map +0 -1
  156. package/dist-client/components/proposal-outcome-line.js.map +0 -1
  157. package/dist-client/components/proposal-request.test.d.ts +0 -1
  158. package/dist-client/components/proposal-request.test.js +0 -63
  159. package/dist-client/components/proposal-request.test.js.map +0 -1
  160. package/dist-client/components/reply-message.js.map +0 -1
  161. package/dist-client/components/reply-message.test.d.ts +0 -1
  162. package/dist-client/components/reply-message.test.js +0 -16
  163. package/dist-client/components/reply-message.test.js.map +0 -1
  164. package/dist-client/components/roster-identity.js.map +0 -1
  165. package/dist-client/components/roster-identity.test.d.ts +0 -1
  166. package/dist-client/components/roster-identity.test.js +0 -9
  167. package/dist-client/components/roster-identity.test.js.map +0 -1
  168. package/dist-client/components/workspace-view.js.map +0 -1
  169. package/dist-client/index.js.map +0 -1
  170. package/dist-client/pages/assistant-workspace-page.js.map +0 -1
  171. package/dist-client/route.js.map +0 -1
  172. package/dist-client/settings/agent-settings-model.js.map +0 -1
  173. package/dist-client/settings/ai-agent-setting-let.js.map +0 -1
  174. package/dist-client/settings/ai-usage-setting-let.d.ts +0 -25
  175. package/dist-client/settings/ai-usage-setting-let.js +0 -258
  176. package/dist-client/settings/ai-usage-setting-let.js.map +0 -1
  177. package/dist-client/settings/usage-model.d.ts +0 -32
  178. package/dist-client/settings/usage-model.js +0 -25
  179. package/dist-client/settings/usage-model.js.map +0 -1
  180. package/dist-client/setup-assistant-dock.js.map +0 -1
  181. package/dist-client/tsconfig.tsbuildinfo +0 -1
  182. package/dist-client/utils/addressed-draft.test.d.ts +0 -1
  183. package/dist-client/utils/addressed-draft.test.js +0 -27
  184. package/dist-client/utils/addressed-draft.test.js.map +0 -1
  185. package/dist-client/utils/agent-choice.js.map +0 -1
  186. package/dist-client/utils/applied-screens.js.map +0 -1
  187. package/dist-client/utils/assistant-activity.js.map +0 -1
  188. package/dist-client/utils/assistant-ask.js.map +0 -1
  189. package/dist-client/utils/assistant-ask.test.d.ts +0 -1
  190. package/dist-client/utils/assistant-ask.test.js +0 -40
  191. package/dist-client/utils/assistant-ask.test.js.map +0 -1
  192. package/dist-client/utils/assistant-capability-read.js.map +0 -1
  193. package/dist-client/utils/assistant-capability.js.map +0 -1
  194. package/dist-client/utils/assistant-capability.test.d.ts +0 -1
  195. package/dist-client/utils/assistant-capability.test.js +0 -16
  196. package/dist-client/utils/assistant-capability.test.js.map +0 -1
  197. package/dist-client/utils/assistant-navigation.js.map +0 -1
  198. package/dist-client/utils/assistant-navigation.test.d.ts +0 -1
  199. package/dist-client/utils/assistant-navigation.test.js +0 -63
  200. package/dist-client/utils/assistant-navigation.test.js.map +0 -1
  201. package/dist-client/utils/assistant-proposals.js.map +0 -1
  202. package/dist-client/utils/assistant-request-context.js.map +0 -1
  203. package/dist-client/utils/assistant-selection.js.map +0 -1
  204. package/dist-client/utils/assistant-selection.test.d.ts +0 -1
  205. package/dist-client/utils/assistant-selection.test.js +0 -46
  206. package/dist-client/utils/assistant-selection.test.js.map +0 -1
  207. package/dist-client/utils/assistant-session-actions.js.map +0 -1
  208. package/dist-client/utils/assistant-session-admin.js.map +0 -1
  209. package/dist-client/utils/assistant-session-controller.js.map +0 -1
  210. package/dist-client/utils/assistant-session-controller.test.d.ts +0 -1
  211. package/dist-client/utils/assistant-session-controller.test.js +0 -56
  212. package/dist-client/utils/assistant-session-controller.test.js.map +0 -1
  213. package/dist-client/utils/assistant-session-transport.js.map +0 -1
  214. package/dist-client/utils/assistant-surface.js.map +0 -1
  215. package/dist-client/utils/assistant-typing.js.map +0 -1
  216. package/dist-client/utils/assistant-typing.test.d.ts +0 -1
  217. package/dist-client/utils/assistant-typing.test.js +0 -30
  218. package/dist-client/utils/assistant-typing.test.js.map +0 -1
  219. package/dist-client/utils/attachment-policy.js.map +0 -1
  220. package/dist-client/utils/composer-frame.js.map +0 -1
  221. package/dist-client/utils/document-text.js.map +0 -1
  222. package/dist-client/utils/entry-hash.js.map +0 -1
  223. package/dist-client/utils/entry-proposal.js.map +0 -1
  224. package/dist-client/utils/entry-workspace.js.map +0 -1
  225. package/dist-client/utils/invite-proposal-register.js.map +0 -1
  226. package/dist-client/utils/invite-proposal.js.map +0 -1
  227. package/dist-client/utils/invite-proposal.test.d.ts +0 -1
  228. package/dist-client/utils/invite-proposal.test.js +0 -35
  229. package/dist-client/utils/invite-proposal.test.js.map +0 -1
  230. package/dist-client/utils/menu-room.js.map +0 -1
  231. package/dist-client/utils/open-page.js.map +0 -1
  232. package/dist-client/utils/pasted-table.js.map +0 -1
  233. package/dist-client/utils/pdf-pages.js.map +0 -1
  234. package/dist-client/utils/spreadsheet-text.js.map +0 -1
  235. package/dist-client/utils/workspace.js.map +0 -1
  236. package/dist-server/door-declaration-report.js.map +0 -1
  237. package/dist-server/index.js.map +0 -1
  238. package/dist-server/role-tasks.js.map +0 -1
  239. package/dist-server/service/ai-agent-resolver.js.map +0 -1
  240. package/dist-server/service/assistant-capability-resolver.js.map +0 -1
  241. package/dist-server/service/assistant-chat-resolver.js.map +0 -1
  242. package/dist-server/service/assistant-mode/assistant-mode-resolver.js.map +0 -1
  243. package/dist-server/service/assistant-mode/fallback-subjects.js.map +0 -1
  244. package/dist-server/service/assistant-mode/index.js.map +0 -1
  245. package/dist-server/service/assistant-mode/mode-categories.js.map +0 -1
  246. package/dist-server/service/assistant-mode/record-subject.js.map +0 -1
  247. package/dist-server/service/assistant-mode/registry.js.map +0 -1
  248. package/dist-server/service/assistant-mode/resolve.js.map +0 -1
  249. package/dist-server/service/assistant-mode/screen-rules.js.map +0 -1
  250. package/dist-server/service/assistant-mode/turn-lines.js.map +0 -1
  251. package/dist-server/service/assistant-mode/types.js.map +0 -1
  252. package/dist-server/service/chat-message/carried-turns.js.map +0 -1
  253. package/dist-server/service/chat-message/chat-message-broadcast.js.map +0 -1
  254. package/dist-server/service/chat-message/chat-message-publish.js.map +0 -1
  255. package/dist-server/service/chat-message/chat-message-room.js.map +0 -1
  256. package/dist-server/service/chat-message/chat-message-subscription.js.map +0 -1
  257. package/dist-server/service/chat-message/chat-message.js.map +0 -1
  258. package/dist-server/service/chat-message/chat-typing-subscription.js.map +0 -1
  259. package/dist-server/service/chat-message/chat-typing.js.map +0 -1
  260. package/dist-server/service/chat-message/door-access.js.map +0 -1
  261. package/dist-server/service/chat-message/fold-history.js.map +0 -1
  262. package/dist-server/service/chat-message/fold-session-history.js.map +0 -1
  263. package/dist-server/service/chat-message/history-summary.js.map +0 -1
  264. package/dist-server/service/chat-message/index.js.map +0 -1
  265. package/dist-server/service/chat-message/llm-history.js.map +0 -1
  266. package/dist-server/service/chat-message/message-doors.js.map +0 -1
  267. package/dist-server/service/chat-message/proposal-outcome.js.map +0 -1
  268. package/dist-server/service/chat-message/reader-gate.js.map +0 -1
  269. package/dist-server/service/chat-message/room-message.js.map +0 -1
  270. package/dist-server/service/chat-message/room-turn.js.map +0 -1
  271. package/dist-server/service/chat-message/used-tools.js.map +0 -1
  272. package/dist-server/service/chat-session/attachment-policy.js.map +0 -1
  273. package/dist-server/service/chat-session/attachment-route.js.map +0 -1
  274. package/dist-server/service/chat-session/attachment-tool-result.js.map +0 -1
  275. package/dist-server/service/chat-session/attachment-tools.js.map +0 -1
  276. package/dist-server/service/chat-session/chat-session.js.map +0 -1
  277. package/dist-server/service/chat-session/index.js.map +0 -1
  278. package/dist-server/service/chat-session/session-activity-broadcast.js.map +0 -1
  279. package/dist-server/service/chat-session/session-activity-publish.js.map +0 -1
  280. package/dist-server/service/chat-session/session-activity-subscription.js.map +0 -1
  281. package/dist-server/service/chat-session/session-anchor.js.map +0 -1
  282. package/dist-server/service/chat-session/session-attachments.js.map +0 -1
  283. package/dist-server/service/chat-session/session-cleanup.js.map +0 -1
  284. package/dist-server/service/chat-session/session-inbox.js.map +0 -1
  285. package/dist-server/service/chat-session/session-kind.js.map +0 -1
  286. package/dist-server/service/chat-session/session-name.js.map +0 -1
  287. package/dist-server/service/chat-session/session-purge.js.map +0 -1
  288. package/dist-server/service/chat-session/session-retention.js.map +0 -1
  289. package/dist-server/service/chat-session/session-visibility.js.map +0 -1
  290. package/dist-server/service/chat-session/session-write-gate.js.map +0 -1
  291. package/dist-server/service/chat-session/station-session-guard.js.map +0 -1
  292. package/dist-server/service/chat-session/turn-attachments.js.map +0 -1
  293. package/dist-server/service/chat-session-participant/chat-session-participant.js.map +0 -1
  294. package/dist-server/service/chat-session-participant/index.js.map +0 -1
  295. package/dist-server/service/chat-session-participant/invite-notification.js.map +0 -1
  296. package/dist-server/service/chat-session-participant/mention-invite.js.map +0 -1
  297. package/dist-server/service/chat-session-participant/participant-lookup-roles.js.map +0 -1
  298. package/dist-server/service/chat-session-participant/participant-lookup.js.map +0 -1
  299. package/dist-server/service/chat-session-participant/presence.js.map +0 -1
  300. package/dist-server/service/chat-session-participant/read-roster.js.map +0 -1
  301. package/dist-server/service/chat-session-resolver.js.map +0 -1
  302. package/dist-server/service/data-entry/entry-apply.js.map +0 -1
  303. package/dist-server/service/data-entry/entry-hash.js.map +0 -1
  304. package/dist-server/service/data-entry/entry-refusal.js.map +0 -1
  305. package/dist-server/service/data-entry/entry-resolver.js.map +0 -1
  306. package/dist-server/service/data-entry/entry-screen.js.map +0 -1
  307. package/dist-server/service/data-entry/entry-sources.js.map +0 -1
  308. package/dist-server/service/data-entry/entry-target.js.map +0 -1
  309. package/dist-server/service/data-entry/entry-tools.js.map +0 -1
  310. package/dist-server/service/data-entry/entry-update.js.map +0 -1
  311. package/dist-server/service/data-read/list-read.js.map +0 -1
  312. package/dist-server/service/data-read/read-target.js.map +0 -1
  313. package/dist-server/service/data-read/read-tools.js.map +0 -1
  314. package/dist-server/service/grounding-sources.js.map +0 -1
  315. package/dist-server/service/help-documents/help-keys.js.map +0 -1
  316. package/dist-server/service/help-documents/help-tools.js.map +0 -1
  317. package/dist-server/service/index.js.map +0 -1
  318. package/dist-server/service/people/index.js.map +0 -1
  319. package/dist-server/service/people/invite-tools.js.map +0 -1
  320. package/dist-server/service/people/people-keys.js.map +0 -1
  321. package/dist-server/service/people/people-read.js.map +0 -1
  322. package/dist-server/service/people/person-subject.js.map +0 -1
  323. package/dist-server/service/request-translator.js.map +0 -1
  324. package/dist-server/service/testing/conversation-script.js.map +0 -1
  325. package/dist-server/service/testing/mode-conformance.js.map +0 -1
  326. package/dist-server/service/tool-access.js.map +0 -1
  327. package/dist-server/service/types.js.map +0 -1
  328. package/dist-server/service/unattended-run/assistant-run.js.map +0 -1
  329. package/dist-server/service/unattended-run/index.js.map +0 -1
  330. package/dist-server/service/unattended-run/limits.js.map +0 -1
  331. package/dist-server/service/unattended-run/run-as.js.map +0 -1
  332. package/dist-server/service/unattended-run/run-budget.js.map +0 -1
  333. package/dist-server/service/unattended-run/run-ledger.js.map +0 -1
  334. package/dist-server/service/unattended-run/run-outcome.js.map +0 -1
  335. package/dist-server/service/unattended-run/run-store.js.map +0 -1
  336. package/dist-server/service/unattended-run/run-unattended.js.map +0 -1
  337. package/dist-server/service/unattended-run/unattended-prompt.js.map +0 -1
  338. package/dist-server/service/workspace/workspace-blocks.js.map +0 -1
  339. package/dist-server/service/workspace/workspace-tools.js.map +0 -1
  340. package/dist-server/tool-registry-boot-report.js.map +0 -1
  341. package/dist-server/tsconfig.tsbuildinfo +0 -1
  342. package/docs/session-controller.md +0 -52
  343. package/server/door-declaration-report.test.ts +0 -53
  344. package/server/door-declaration-report.ts +0 -61
  345. package/server/explicit-graphql-types.test.ts +0 -56
  346. package/server/index.ts +0 -36
  347. package/server/role-tasks.ts +0 -14
  348. package/server/service/ai-agent-resolver.ts +0 -330
  349. package/server/service/assistant-capability-resolver.ts +0 -66
  350. package/server/service/assistant-chat-resolver.ts +0 -640
  351. package/server/service/assistant-mode/assistant-mode-resolver.ts +0 -101
  352. package/server/service/assistant-mode/conversation-category.test.ts +0 -48
  353. package/server/service/assistant-mode/fallback-subjects.ts +0 -36
  354. package/server/service/assistant-mode/index.ts +0 -22
  355. package/server/service/assistant-mode/mode-categories.ts +0 -178
  356. package/server/service/assistant-mode/mode-front.test.ts +0 -181
  357. package/server/service/assistant-mode/one-conversation-per-subject.test.ts +0 -37
  358. package/server/service/assistant-mode/open-subject-door.test.ts +0 -52
  359. package/server/service/assistant-mode/record-subject.test.ts +0 -41
  360. package/server/service/assistant-mode/record-subject.ts +0 -44
  361. package/server/service/assistant-mode/registry.test.ts +0 -171
  362. package/server/service/assistant-mode/registry.ts +0 -139
  363. package/server/service/assistant-mode/resolve.test.ts +0 -129
  364. package/server/service/assistant-mode/resolve.ts +0 -113
  365. package/server/service/assistant-mode/screen-rules.test.ts +0 -99
  366. package/server/service/assistant-mode/screen-rules.ts +0 -103
  367. package/server/service/assistant-mode/turn-lines.ts +0 -43
  368. package/server/service/assistant-mode/types.ts +0 -138
  369. package/server/service/chat-message/carried-turns.test.ts +0 -80
  370. package/server/service/chat-message/carried-turns.ts +0 -112
  371. package/server/service/chat-message/chat-message-broadcast.integration.test.ts +0 -73
  372. package/server/service/chat-message/chat-message-broadcast.test.ts +0 -40
  373. package/server/service/chat-message/chat-message-broadcast.ts +0 -70
  374. package/server/service/chat-message/chat-message-publish.ts +0 -22
  375. package/server/service/chat-message/chat-message-room.test.ts +0 -145
  376. package/server/service/chat-message/chat-message-room.ts +0 -50
  377. package/server/service/chat-message/chat-message-subscription.ts +0 -77
  378. package/server/service/chat-message/chat-message.ts +0 -289
  379. package/server/service/chat-message/chat-typing-subscription.ts +0 -52
  380. package/server/service/chat-message/chat-typing.test.ts +0 -45
  381. package/server/service/chat-message/chat-typing.ts +0 -48
  382. package/server/service/chat-message/door-access.test.ts +0 -72
  383. package/server/service/chat-message/door-access.ts +0 -65
  384. package/server/service/chat-message/fold-history-window.test.ts +0 -184
  385. package/server/service/chat-message/fold-history.test.ts +0 -98
  386. package/server/service/chat-message/fold-history.ts +0 -77
  387. package/server/service/chat-message/fold-session-history.test.ts +0 -116
  388. package/server/service/chat-message/fold-session-history.ts +0 -115
  389. package/server/service/chat-message/history-summary.test.ts +0 -127
  390. package/server/service/chat-message/history-summary.ts +0 -100
  391. package/server/service/chat-message/index.ts +0 -13
  392. package/server/service/chat-message/llm-history.test.ts +0 -245
  393. package/server/service/chat-message/llm-history.ts +0 -182
  394. package/server/service/chat-message/message-doors.test.ts +0 -124
  395. package/server/service/chat-message/message-doors.ts +0 -137
  396. package/server/service/chat-message/proposal-outcome.test.ts +0 -111
  397. package/server/service/chat-message/proposal-outcome.ts +0 -99
  398. package/server/service/chat-message/reader-gate.ts +0 -44
  399. package/server/service/chat-message/room-message.test.ts +0 -21
  400. package/server/service/chat-message/room-message.ts +0 -22
  401. package/server/service/chat-message/room-turn.ts +0 -42
  402. package/server/service/chat-message/used-tools.test.ts +0 -19
  403. package/server/service/chat-message/used-tools.ts +0 -25
  404. package/server/service/chat-session/attachment-policy.test.ts +0 -42
  405. package/server/service/chat-session/attachment-policy.ts +0 -91
  406. package/server/service/chat-session/attachment-route.ts +0 -45
  407. package/server/service/chat-session/attachment-tool-result.test.ts +0 -63
  408. package/server/service/chat-session/attachment-tool-result.ts +0 -37
  409. package/server/service/chat-session/attachment-tools.ts +0 -66
  410. package/server/service/chat-session/chat-session.ts +0 -244
  411. package/server/service/chat-session/group-room.test.ts +0 -233
  412. package/server/service/chat-session/index.ts +0 -5
  413. package/server/service/chat-session/session-activity-broadcast.ts +0 -77
  414. package/server/service/chat-session/session-activity-publish.ts +0 -49
  415. package/server/service/chat-session/session-activity-receivers.test.ts +0 -26
  416. package/server/service/chat-session/session-activity-subscription.ts +0 -66
  417. package/server/service/chat-session/session-anchor.ts +0 -142
  418. package/server/service/chat-session/session-attachments.ts +0 -90
  419. package/server/service/chat-session/session-cleanup.test.ts +0 -83
  420. package/server/service/chat-session/session-cleanup.ts +0 -69
  421. package/server/service/chat-session/session-inbox.test.ts +0 -273
  422. package/server/service/chat-session/session-inbox.ts +0 -240
  423. package/server/service/chat-session/session-kind.test.ts +0 -24
  424. package/server/service/chat-session/session-kind.ts +0 -32
  425. package/server/service/chat-session/session-name.ts +0 -32
  426. package/server/service/chat-session/session-purge.test.ts +0 -24
  427. package/server/service/chat-session/session-purge.ts +0 -117
  428. package/server/service/chat-session/session-retention.ts +0 -17
  429. package/server/service/chat-session/session-visibility.test.ts +0 -130
  430. package/server/service/chat-session/session-visibility.ts +0 -68
  431. package/server/service/chat-session/session-write-gate.test.ts +0 -59
  432. package/server/service/chat-session/session-write-gate.ts +0 -31
  433. package/server/service/chat-session/station-session-guard.ts +0 -25
  434. package/server/service/chat-session/turn-attachments.test.ts +0 -106
  435. package/server/service/chat-session/turn-attachments.ts +0 -45
  436. package/server/service/chat-session-participant/chat-session-participant.ts +0 -135
  437. package/server/service/chat-session-participant/index.ts +0 -8
  438. package/server/service/chat-session-participant/invite-notification.test.ts +0 -80
  439. package/server/service/chat-session-participant/invite-notification.ts +0 -118
  440. package/server/service/chat-session-participant/mention-invite.test.ts +0 -173
  441. package/server/service/chat-session-participant/mention-invite.ts +0 -180
  442. package/server/service/chat-session-participant/participant-lookup-roles.ts +0 -6
  443. package/server/service/chat-session-participant/participant-lookup.ts +0 -22
  444. package/server/service/chat-session-participant/presence.test.ts +0 -39
  445. package/server/service/chat-session-participant/presence.ts +0 -21
  446. package/server/service/chat-session-participant/read-roster.test.ts +0 -27
  447. package/server/service/chat-session-participant/read-roster.ts +0 -17
  448. package/server/service/chat-session-resolver.ts +0 -1455
  449. package/server/service/data-entry/data-entry-update.test.ts +0 -378
  450. package/server/service/data-entry/data-entry.test.ts +0 -494
  451. package/server/service/data-entry/entry-apply.ts +0 -247
  452. package/server/service/data-entry/entry-hash.ts +0 -35
  453. package/server/service/data-entry/entry-refusal.test.ts +0 -73
  454. package/server/service/data-entry/entry-refusal.ts +0 -20
  455. package/server/service/data-entry/entry-resolver.ts +0 -74
  456. package/server/service/data-entry/entry-screen.ts +0 -14
  457. package/server/service/data-entry/entry-sources.ts +0 -39
  458. package/server/service/data-entry/entry-target.ts +0 -774
  459. package/server/service/data-entry/entry-tools.ts +0 -282
  460. package/server/service/data-entry/entry-update.ts +0 -238
  461. package/server/service/data-read/data-read.test.ts +0 -395
  462. package/server/service/data-read/detail-lists.test.ts +0 -61
  463. package/server/service/data-read/list-missing.test.ts +0 -49
  464. package/server/service/data-read/list-read.ts +0 -146
  465. package/server/service/data-read/list-status.test.ts +0 -46
  466. package/server/service/data-read/read-target.ts +0 -510
  467. package/server/service/data-read/read-tools.ts +0 -334
  468. package/server/service/data-read/read-words.test.ts +0 -99
  469. package/server/service/data-read/record-keys.test.ts +0 -42
  470. package/server/service/grounding-sources.test.ts +0 -55
  471. package/server/service/grounding-sources.ts +0 -46
  472. package/server/service/help-documents/help-keys.ts +0 -2
  473. package/server/service/help-documents/help-tools.test.ts +0 -40
  474. package/server/service/help-documents/help-tools.ts +0 -88
  475. package/server/service/index.ts +0 -99
  476. package/server/service/people/index.ts +0 -15
  477. package/server/service/people/invite-tools.ts +0 -159
  478. package/server/service/people/invite.test.ts +0 -159
  479. package/server/service/people/people-keys.ts +0 -16
  480. package/server/service/people/people-read.test.ts +0 -82
  481. package/server/service/people/people-read.ts +0 -56
  482. package/server/service/people/person-subject.test.ts +0 -163
  483. package/server/service/people/person-subject.ts +0 -88
  484. package/server/service/request-translator.test.ts +0 -45
  485. package/server/service/request-translator.ts +0 -33
  486. package/server/service/session-anchor.test.ts +0 -198
  487. package/server/service/station-session-guard.test.ts +0 -31
  488. package/server/service/testing/conversation-scenario.test.ts +0 -164
  489. package/server/service/testing/conversation-script.test.ts +0 -133
  490. package/server/service/testing/conversation-script.ts +0 -296
  491. package/server/service/testing/mode-conformance.test.ts +0 -61
  492. package/server/service/testing/mode-conformance.ts +0 -165
  493. package/server/service/tool-access.test.ts +0 -96
  494. package/server/service/tool-access.ts +0 -36
  495. package/server/service/types.ts +0 -15
  496. package/server/service/unattended-run/assistant-run.ts +0 -199
  497. package/server/service/unattended-run/index.ts +0 -10
  498. package/server/service/unattended-run/limits.ts +0 -24
  499. package/server/service/unattended-run/run-as.ts +0 -38
  500. package/server/service/unattended-run/run-budget.ts +0 -58
  501. package/server/service/unattended-run/run-ledger.ts +0 -31
  502. package/server/service/unattended-run/run-outcome.ts +0 -43
  503. package/server/service/unattended-run/run-store-race.pg.test.ts +0 -83
  504. package/server/service/unattended-run/run-store.ts +0 -162
  505. package/server/service/unattended-run/run-unattended.test.ts +0 -478
  506. package/server/service/unattended-run/run-unattended.ts +0 -248
  507. package/server/service/unattended-run/unattended-prompt.ts +0 -24
  508. package/server/service/workspace/workspace-blocks.ts +0 -134
  509. package/server/service/workspace/workspace-tools.ts +0 -108
  510. package/server/service/workspace/workspace.test.ts +0 -74
  511. package/server/tool-registry-boot-report.test.ts +0 -41
  512. package/server/tool-registry-boot-report.ts +0 -63
  513. package/test/ai-agent-settings.test.ts +0 -123
  514. package/test/applied-screens.test.ts +0 -65
  515. package/test/assistant-chat-call-sites.test.ts +0 -92
  516. package/test/assistant-dock.test.ts +0 -294
  517. package/test/assistant-request-context.test.ts +0 -72
  518. package/test/assistant-session-controller.test.ts +0 -87
  519. package/test/assistant-session-manager.test.ts +0 -186
  520. package/test/assistant-session-toolbar.test.ts +0 -43
  521. package/test/attachment-one-rule.test.ts +0 -46
  522. package/test/attachment-policy-agree.test.ts +0 -38
  523. package/test/composer-frame.test.ts +0 -173
  524. package/test/document-text.test.ts +0 -175
  525. package/test/entry-card-styles.test.ts +0 -18
  526. package/test/entry-proposal.test.ts +0 -186
  527. package/test/entry-workspace.test.ts +0 -89
  528. package/test/menu-room.test.ts +0 -33
  529. package/test/open-doors.test.ts +0 -164
  530. package/test/open-page.test.ts +0 -31
  531. package/test/pasted-table.test.ts +0 -147
  532. package/test/refusals-in-korean.test.ts +0 -80
  533. package/test/session-discovery.test.ts +0 -43
  534. package/test/spreadsheet-text.test.ts +0 -92
  535. package/test/translations.test.ts +0 -80
  536. package/test/workspace.test.ts +0 -54
  537. package/tsconfig.json +0 -9
@@ -1,510 +0,0 @@
1
- /*
2
- * AI 조회 - an application's list, read through its own query as the person (operato-application/design/ai/read-targets.md).
3
- *
4
- * The application declares what it lets the assistant read: its list query, the conditions the model may set and
5
- * how each becomes one of the query's filters, the columns to show, and the screen that lists the same records.
6
- * The framework reads the rows through that query with the person's request state - the same @privilege and
7
- * domain as the screen - counts and sums them itself, and puts a long result on the AI 작업 패널 as the query returned
8
- * it. The model is told the count, the sums and a few rows; it never copies a table.
9
- *
10
- * Pure but for the GraphQL runner, which comes in as an argument - the rules are tested without a server.
11
- */
12
- import { readFieldValue, recordIdOfKey, rootFieldOf, type EntryField } from '../data-entry/entry-target.js'
13
- import { encodeListQuery } from '@operato/utils/list-query.js'
14
- import type { GraphqlRunner } from '../data-entry/entry-update.js'
15
- import { parse } from 'graphql'
16
-
17
- export interface ReadFilter {
18
- name: string
19
- operator: string
20
- value: unknown
21
- }
22
-
23
- /** A condition the model may set - read with the entry fields' rules, turned into the query's filters by the application. */
24
- export interface ReadCriterion extends Omit<EntryField, 'required' | 'reference' | 'total'> {
25
- filter: (value: any) => ReadFilter | ReadFilter[]
26
- /** A string condition holding a month as YYYY-MM - a value of another shape is refused (`not-a-month`). */
27
- format?: 'month'
28
- /**
29
- * The condition takes several values at once - its filter is given the list. Asked for the expenditure requests not
30
- * approved, rejected or withdrawn, the model read the list once per status and stopped (2026-10-25).
31
- */
32
- many?: boolean
33
- }
34
-
35
- export interface ReadColumn {
36
- /** The key in the workspace table. */
37
- name: string
38
- /** Where the value is in a row - a dotted path into the query's item (`account.name`). Defaults to `name`. */
39
- path?: string
40
- type: 'string' | 'number' | 'date'
41
- labelKey?: string
42
- /** A number column the server sums. */
43
- total?: boolean
44
- /**
45
- * The column that holds this amount's currency (ISO 4217, `KRW`). Its sums are kept per currency - amounts of two
46
- * currencies are never added into one number.
47
- */
48
- currency?: string
49
- /**
50
- * The i18n prefix that names this column's codes - `<words><code>` (`announcement.category.` reads `HR` as
51
- * `announcement.category.HR`). The rows keep the code, so a filter or a card's match means the same in every
52
- * language; the model is given the words (`legendOf`) and a table or chart shows them (`wordOf`).
53
- */
54
- words?: string
55
- }
56
-
57
- export interface ReadScreen {
58
- /** A URL-bound grid accepts the same predicates used by readRows, including conditions outside its form. */
59
- queryState?: boolean
60
- /** The application's route of the list screen (`cash-transaction-list`). */
61
- route: string
62
- /** The conditions the screen takes, as its address's query arguments. A condition left out is said on the card. */
63
- params: (criteria: Record<string, any>) => Record<string, string | number | undefined>
64
- /** The conditions `params` carries - the card names the others as not applied on the screen. */
65
- takes: string[]
66
- labelKey?: string
67
- }
68
-
69
- export interface ReadTarget {
70
- /** `<app>.<record>` - the tools are named after it. */
71
- key: string
72
- /** i18n key naming the records (「은행 입출금」). */
73
- labelKey?: string
74
- /** What the records are, for the model. */
75
- description: string
76
- /**
77
- * The list query - takes `$filters: [Filter!]`, `$pagination: Pagination` and `$sortings: [Sorting!]`, and
78
- * `$search: String` when `search` is declared.
79
- */
80
- query: string
81
- /**
82
- * The list takes ListParam's free-text term, matched by the resolver across its own searchable fields - the
83
- * condition `text`. Say what it finds in, for the model.
84
- */
85
- search?: { description: string }
86
- criteria: ReadCriterion[]
87
- /**
88
- * Filters every read of this list applies - the records it is of (a book's confirmed lines, not its forecasts). Not
89
- * a condition: the model neither sees nor sets them, so a read can narrow the list but never widen it.
90
- */
91
- fixedFilters?: ReadFilter[]
92
- columns: ReadColumn[]
93
- rowsOf: (data: any) => { rows: any[]; total: number }
94
- /** Orders the rows; the query's own order when left out. */
95
- sortings?: { name: string; desc?: boolean }[]
96
- screen?: ReadScreen
97
- /**
98
- * The rows are the person's own, whoever reads them (내 지출결의) - the query answers for the one asking. A dashboard
99
- * card of it shows each viewer their own rows and takes no filter on a person (ADR-0160).
100
- */
101
- mine?: boolean
102
- }
103
-
104
- /** At most this many rows are read - the AI 작업 패널 table's own limit (workspace-blocks MAX_TABLE_ROWS). */
105
- export const MAX_READ_ROWS = 1000
106
- /** Rows the model is shown; the rest stay on the card. */
107
- export const ROWS_FOR_MODEL = 20
108
- /** A page of the list query. */
109
- export const READ_PAGE = 200
110
-
111
- const registry = new Map<string, ReadTarget>()
112
-
113
- const pascalOf = (key: string) =>
114
- key
115
- .split(/[^a-zA-Z0-9]+/)
116
- .filter(Boolean)
117
- .map(part => part[0].toUpperCase() + part.slice(1))
118
- .join('')
119
-
120
- export const queryToolName = (key: string) => `query${pascalOf(key)}`
121
- export const screenToolName = (key: string) => `open${pascalOf(key)}Screen`
122
- export const readCategoryName = (key: string) => `data-read:${key}`
123
-
124
- /** The columns of a list - shown, each named once, a currency only on a summed number and taken from a string column. */
125
- function checkColumns(of: string, columns: ReadColumn[]): void {
126
- if (!columns.length) throw new Error(`read target '${of}' shows no column`)
127
- const names = new Set<string>()
128
- for (const column of columns) {
129
- if (names.has(column.name)) throw new Error(`read target '${of}' names the column '${column.name}' twice`)
130
- names.add(column.name)
131
- }
132
- for (const column of columns.filter(one => one.currency)) {
133
- if (!column.total || column.type !== 'number') throw new Error(`column '${column.name}' of '${of}' names a currency but is not a summed number`)
134
- if (columns.find(one => one.name === column.currency)?.type !== 'string') throw new Error(`column '${column.name}' of '${of}' takes its currency from '${column.currency}', which is no string column`)
135
- }
136
- }
137
-
138
- export function declareReadTarget(target: ReadTarget): void {
139
- if (!/^[a-z0-9-]+\.[a-z0-9-]+$/.test(target.key)) throw new Error(`read target key '${target.key}' is not <app>.<record>`)
140
- if (registry.has(target.key) || details.has(target.key)) throw new Error(`read target '${target.key}' is declared twice`)
141
- rootFieldOf(target.query, 'query')
142
- checkColumns(target.key, target.columns)
143
- const names = new Set<string>(['id'])
144
- for (const criterion of target.criteria) {
145
- if (criterion.name === 'id') throw new Error(`read target '${target.key}' declares 'id' - every target takes it`)
146
- if (criterion.name === 'text' && target.search) throw new Error(`read target '${target.key}' declares 'text' and search - search is the text condition`)
147
- if (names.has(criterion.name)) throw new Error(`read target '${target.key}' names the condition '${criterion.name}' twice`)
148
- names.add(criterion.name)
149
- if (criterion.type === 'enum' && !criterion.values?.length) throw new Error(`condition '${criterion.name}' of '${target.key}' lists no values`)
150
- }
151
- if (target.search) names.add('text')
152
- for (const taken of target.screen?.takes ?? []) if (!names.has(taken)) throw new Error(`the screen of '${target.key}' takes '${taken}', which is no condition`)
153
- registry.set(target.key, target)
154
- }
155
-
156
- export function readTargetOf(key: string | undefined): ReadTarget | undefined {
157
- return key ? registry.get(key) : undefined
158
- }
159
-
160
- /** Every list read target declared - what else reads the declarations (a dashboard card, ADR-0160) lists them by key. */
161
- export function readTargetKeys(): string[] {
162
- return [...registry.keys()]
163
- }
164
-
165
- /** Every detail read declared. */
166
- export function detailReadKeys(): string[] {
167
- return [...details.keys()]
168
- }
169
-
170
- export function clearReadTargets(): void {
171
- registry.clear()
172
- details.clear()
173
- }
174
-
175
- /* ── One answer of a query ──────────────────────────────────────────────────────────────────────────────────── */
176
-
177
- /** An argument of a detail read - one variable of its query, read with the entry fields' rules. */
178
- export interface DetailArg {
179
- name: string
180
- type: 'string' | 'integer' | 'number' | 'boolean' | 'date' | 'enum'
181
- values?: string[]
182
- description?: string
183
- required?: boolean
184
- /** A record's id: the axis (or axes) of the record, whose key `<axis>:<id>` the model may have been shown (EntryField.axis). */
185
- axis?: string | readonly string[]
186
- /** A string argument holding a month as YYYY-MM. */
187
- format?: 'month'
188
- }
189
-
190
- /**
191
- * A query whose answer is one thing, not a list - a 360's summary, the receivables, a statement (design/ai/read-targets.md
192
- * §9). The application declares the query with the fields its screen reads; the framework runs it as the person, with
193
- * the arguments the model set, and hands the answer over as the query returned it. Nothing is summed or cut here: the
194
- * selection is the projection, and an answer too long to hand over is refused, never cut.
195
- */
196
- export interface DetailRead {
197
- /** `<app>.<thing>` - the tool is named after it. */
198
- key: string
199
- labelKey?: string
200
- /** What it answers, for the model. */
201
- description: string
202
- /** One query with one root field. Its variables are the arguments - each declared in `args`. */
203
- query: string
204
- args?: DetailArg[]
205
- /**
206
- * The records the answer is about, whose screens put it in front (EntryTarget.axes) - the management check answers
207
- * for any ledger record; asked on a deposit's 360 why it was in the check, the model never opened it (2026-10-24).
208
- */
209
- axes?: string[]
210
- /**
211
- * The application routes whose conversations put it in front (ConversationCategory.frontPages) - a read of one record
212
- * has no list screen to name its page. Asked 「AI로 초안 작성」 on 내 주간업무보고, the week's read was not in front, and the
213
- * model looked for it in the help first (2026-11-12).
214
- */
215
- frontPages?: string[]
216
- /**
217
- * The lists the answer holds, each a table of typed columns - what a dashboard card may draw from a one-answer read
218
- * (ADR-0160 decision 2). The card keeps only `key`; where the rows are and what their columns are is read here.
219
- */
220
- lists?: DetailList[]
221
- /** The answer is the person's own, whoever asks (나의 전략 업무, 내 급여) - ReadTarget.mine. */
222
- mine?: boolean
223
- }
224
-
225
- /** A list inside a detail read's answer. */
226
- export interface DetailList {
227
- /** A name stable within the read (`by-contract`) - what a card keeps. */
228
- key: string
229
- /** A dotted path inside the value of the query's root field (`rows`); '' when the root field is the list. */
230
- at: string
231
- labelKey?: string
232
- /** What the rows are, for the model. */
233
- description?: string
234
- columns: ReadColumn[]
235
- }
236
-
237
- /** Characters of an answer handed to the model - a longer one is refused, and the model narrows it. */
238
- export const MAX_DETAIL_CHARS = 60_000
239
-
240
- const details = new Map<string, DetailRead>()
241
-
242
- export const detailToolName = (key: string) => `read${pascalOf(key)}`
243
-
244
- /** The variables a query declares, and whether each is required (`!`). */
245
- function variablesOf(document: string): { name: string; required: boolean }[] {
246
- const operation: any = parse(document).definitions.find((one: any) => one.kind === 'OperationDefinition')
247
- return (operation?.variableDefinitions ?? []).map((one: any) => ({ name: one.variable.name.value, required: one.type.kind === 'NonNullType' && !one.defaultValue }))
248
- }
249
-
250
- export function declareDetailRead(target: DetailRead): void {
251
- if (!/^[a-z0-9-]+\.[a-z0-9-]+$/.test(target.key)) throw new Error(`detail read key '${target.key}' is not <app>.<thing>`)
252
- if (details.has(target.key) || registry.has(target.key)) throw new Error(`read target '${target.key}' is declared twice`)
253
- rootFieldOf(target.query, 'query')
254
- const args = target.args ?? []
255
- for (const variable of variablesOf(target.query)) {
256
- const arg = args.find(one => one.name === variable.name)
257
- if (!arg) throw new Error(`detail read '${target.key}' takes $${variable.name}, which is no argument`)
258
- if (variable.required && !arg.required) throw new Error(`detail read '${target.key}': $${variable.name} is required by the query - declare it required`)
259
- }
260
- for (const arg of args) {
261
- if (!variablesOf(target.query).some(one => one.name === arg.name)) throw new Error(`detail read '${target.key}' declares '${arg.name}', which its query does not take`)
262
- if (arg.type === 'enum' && !arg.values?.length) throw new Error(`argument '${arg.name}' of '${target.key}' lists no values`)
263
- }
264
- const lists = new Set<string>()
265
- for (const list of target.lists ?? []) {
266
- if (!/^[a-z0-9-]+$/.test(list.key)) throw new Error(`list '${list.key}' of '${target.key}' is not a lowercase key`)
267
- if (lists.has(list.key)) throw new Error(`detail read '${target.key}' names the list '${list.key}' twice`)
268
- lists.add(list.key)
269
- if (!/^([A-Za-z0-9_]+(\.[A-Za-z0-9_]+)*)?$/.test(list.at)) throw new Error(`list '${list.key}' of '${target.key}' is at '${list.at}', which is no dotted path`)
270
- checkColumns(`${target.key}/${list.key}`, list.columns)
271
- }
272
- details.set(target.key, target)
273
- }
274
-
275
- export function detailReadOf(key: string | undefined): DetailRead | undefined {
276
- return key ? details.get(key) : undefined
277
- }
278
-
279
- /** A month as a `month` condition holds it. */
280
- const MONTH = /^\d{4}-(0[1-9]|1[0-2])$/
281
-
282
- /*
283
- * The id a key `<axis>:<id>` names - a uuid, or a row's own composite id (a training standing is `<kind>:<year>:<employee>`,
284
- * 2026-11-08). Another axis's key is not this record's: it stays as written and finds nothing.
285
- */
286
- const idOfKey = (axis: string, text: string): string => recordIdOfKey(axis, text) ?? (text.startsWith(`${axis}:`) ? text.slice(axis.length + 1) : text)
287
-
288
- /** The conditions the model set, read by their declared types; a value that does not fit is said, never guessed at. */
289
- export function readCriteria(target: ReadTarget, args: any): { criteria: Record<string, unknown>; refused: { name: string; code: string }[] } {
290
- const criteria: Record<string, unknown> = {}
291
- const refused: { name: string; code: string }[] = []
292
- /* One record by its id - every target takes it (the id a list answer or a find tool gave, or the key `<axis>:<id>` an open record is shown by, the axis being the key's last part). */
293
- if (typeof args?.id === 'string' && args.id.trim()) criteria.id = idOfKey(target.key.split('.').pop()!, args.id.trim())
294
- if (target.search && typeof args?.text === 'string' && args.text.trim()) criteria.text = args.text.trim()
295
- for (const criterion of target.criteria) {
296
- const value = args?.[criterion.name]
297
- if (value === undefined || value === null || value === '' || (Array.isArray(value) && !value.length)) continue
298
- if (criterion.many && Array.isArray(value)) {
299
- const each = value.map(one => readFieldValue(criterion as EntryField, one))
300
- const wrong = each.find(one => one.read === undefined)
301
- if (wrong) refused.push({ name: criterion.name, code: wrong.code ?? 'unreadable' })
302
- else criteria[criterion.name] = [...new Set(each.map(one => one.read))]
303
- continue
304
- }
305
- if (Array.isArray(value)) {
306
- refused.push({ name: criterion.name, code: 'one-value' })
307
- continue
308
- }
309
- const { read, code } = readFieldValue(criterion as EntryField, value)
310
- if (read === undefined) refused.push({ name: criterion.name, code: code ?? 'unreadable' })
311
- else if (criterion.format === 'month' && !MONTH.test(String(read))) refused.push({ name: criterion.name, code: 'not-a-month' })
312
- else criteria[criterion.name] = read
313
- }
314
- return { criteria, refused }
315
- }
316
-
317
- export function filtersOf(target: ReadTarget, criteria: Record<string, unknown>): ReadFilter[] {
318
- return [
319
- ...(typeof criteria.id === 'string' ? [{ name: 'id', operator: 'eq', value: criteria.id }] : []),
320
- ...target.criteria.flatMap(criterion =>
321
- criterion.name in criteria ? [criterion.filter(criteria[criterion.name])].flat() : []
322
- )
323
- ]
324
- }
325
-
326
- /** A dotted path's value - through a list, each one's (an invention's inventors' names). */
327
- export const valueAt = (row: any, path: string) =>
328
- path.split('.').reduce((at, part) => (at === null || at === undefined ? undefined : Array.isArray(at) ? at.map(one => one?.[part]) : at[part]), row)
329
-
330
- /**
331
- * A date column's moment as people read it - `YYYY-MM-DD HH:mm` in the domain's time zone. A day (`YYYY-MM-DD`) or
332
- * month stays as it is; anything that is not a moment is left alone. Still ordered as text, so a card's comparison
333
- * with a day keeps working.
334
- */
335
- export function localDateTime(value: string, timeZone?: string): string {
336
- if (!/^\d{4}-\d{2}-\d{2}T/.test(value)) return value
337
- const moment = new Date(value)
338
- if (Number.isNaN(moment.getTime())) return value
339
- try {
340
- const parts = Object.fromEntries(
341
- new Intl.DateTimeFormat('en-CA', { timeZone: timeZone || undefined, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', hourCycle: 'h23' })
342
- .formatToParts(moment)
343
- .map(part => [part.type, part.value])
344
- )
345
- return `${parts.year}-${parts.month}-${parts.day} ${parts.hour}:${parts.minute}`
346
- } catch {
347
- return value
348
- }
349
- }
350
-
351
- /** How the reader's words are asked - `(key, fallback)`, the fallback when the key has no word. */
352
- export type SayWord = (key: string | undefined, fallback: string) => string
353
-
354
- /** The word a coded value is read as, in the reader's language - the value itself when its column has no words. */
355
- export function wordOf(column: Pick<ReadColumn, 'words'> | undefined, value: unknown, say: SayWord): unknown {
356
- if (!column?.words || value === null || value === undefined || value === '') return value
357
- return say(`${column.words}${value}`, String(value))
358
- }
359
-
360
- /** The words of the coded values the rows hold, column by column - what the model reads the codes by. */
361
- export function legendOf(columns: readonly Pick<ReadColumn, 'name' | 'words'>[], rows: Record<string, any>[], say: SayWord): Record<string, Record<string, string>> {
362
- const legend: Record<string, Record<string, string>> = {}
363
- for (const column of columns) {
364
- if (!column.words) continue
365
- for (const row of rows) {
366
- const code = row[column.name]
367
- if (code === null || code === undefined || code === '') continue
368
- ;(legend[column.name] ??= {})[String(code)] = String(wordOf(column, code, say))
369
- }
370
- }
371
- return legend
372
- }
373
-
374
- /** What shapes a row besides its columns - the domain's time zone, for a moment. */
375
- export type RowOptions = { timeZone?: string }
376
-
377
- /** One row as the columns say - a number column as a number, a moment in the domain's time zone, a missing value as null. */
378
- export function rowOf(target: Pick<ReadTarget, 'columns'>, item: any, options: RowOptions = {}): Record<string, string | number | null> {
379
- return Object.fromEntries([
380
- /* The id names the record to the model - for one record's detail, a change, or its screen. */
381
- ...(item?.id ? [['id', String(item.id)] as [string, string]] : []),
382
- ...target.columns.map(column => {
383
- const found = valueAt(item, column.path ?? column.name)
384
- /* A list of values reads as one, comma-separated. */
385
- const raw = Array.isArray(found) ? found.filter(one => one !== undefined && one !== null && one !== '').join(', ') : found
386
- if (raw === undefined || raw === null || raw === '') return [column.name, null]
387
- if (column.type === 'number') {
388
- const number = Number(raw)
389
- return [column.name, Number.isFinite(number) ? number : null]
390
- }
391
- return [column.name, column.type === 'date' ? localDateTime(String(raw), options.timeZone) : String(raw)]
392
- })
393
- ])
394
- }
395
-
396
- /**
397
- * Reads the rows through the application's query, page by page, up to MAX_READ_ROWS. `complete` is false when the
398
- * list holds more - a sum of the rows read is then not the sum of the list, and is never said as one.
399
- */
400
- export async function readRows(
401
- target: ReadTarget,
402
- filters: ReadFilter[],
403
- run: GraphqlRunner,
404
- search?: string,
405
- options: RowOptions = {}
406
- ): Promise<{ rows: Record<string, any>[]; total: number; complete: boolean }> {
407
- const rows: Record<string, any>[] = []
408
- let total = 0
409
- for (let page = 1; rows.length < MAX_READ_ROWS; page++) {
410
- const answer = await run(target.query, {
411
- filters: [...filters, ...(target.fixedFilters ?? [])],
412
- ...(search ? { search } : {}),
413
- pagination: { page, limit: READ_PAGE },
414
- ...(target.sortings ? { sortings: target.sortings } : {})
415
- })
416
- if (answer.errors?.length) throw new Error(answer.errors.map(one => one.message).join('; '))
417
- const read = target.rowsOf(answer.data)
418
- total = Number(read?.total) || 0
419
- const items = read?.rows ?? []
420
- rows.push(...items.slice(0, MAX_READ_ROWS - rows.length).map(item => rowOf(target, item, options)))
421
- if (items.length < READ_PAGE || rows.length >= total) break
422
- }
423
- return { rows, total, complete: rows.length >= total }
424
- }
425
-
426
- /** A column's sum - one number, or one per currency when the column names its currency (`{ KRW: 1000, USD: 100 }`). */
427
- export type ReadSum = number | Record<string, number>
428
-
429
- export interface ReadGroup {
430
- key: string
431
- count: number
432
- sums: Record<string, ReadSum>
433
- }
434
-
435
- /** The currency a row without one is summed under - said as it is, never taken for the domain's own. */
436
- export const UNKNOWN_CURRENCY = 'unknown'
437
-
438
- const sumOf = (rows: Record<string, any>[], name: string) => Math.round(rows.reduce((sum, row) => sum + (typeof row[name] === 'number' ? row[name] : 0), 0) * 100) / 100
439
-
440
- /** The sums of the number columns marked total - the server's, never the model's; a column with a currency per currency. */
441
- export function sumsOf(target: Pick<ReadTarget, 'columns'>, rows: Record<string, any>[]): Record<string, ReadSum> {
442
- const sums: Record<string, ReadSum> = {}
443
- for (const column of target.columns.filter(one => one.total && one.type === 'number')) {
444
- if (!column.currency) {
445
- sums[column.name] = sumOf(rows, column.name)
446
- continue
447
- }
448
- const byCurrency = new Map<string, Record<string, any>[]>()
449
- for (const row of rows) {
450
- const code = typeof row[column.currency] === 'string' && row[column.currency] ? row[column.currency] : UNKNOWN_CURRENCY
451
- byCurrency.set(code, [...(byCurrency.get(code) ?? []), row])
452
- }
453
- sums[column.name] = Object.fromEntries([...byCurrency].sort(([a], [b]) => a.localeCompare(b)).map(([code, members]) => [code, sumOf(members, column.name)]))
454
- }
455
- return sums
456
- }
457
-
458
- /** The currencies a set of sums holds for one column - none for a column summed as one number. */
459
- export function currenciesOf(sums: Record<string, ReadSum>[], column: string): string[] {
460
- const codes = new Set<string>()
461
- for (const one of sums) if (one[column] && typeof one[column] === 'object') for (const code of Object.keys(one[column] as object)) codes.add(code)
462
- return [...codes].sort()
463
- }
464
-
465
- /** The rows grouped by one column - a date column by its month - each with its count and sums, largest first. */
466
- export function groupsOf(target: Pick<ReadTarget, 'columns'>, rows: Record<string, any>[], by: string): ReadGroup[] | undefined {
467
- const column = target.columns.find(one => one.name === by)
468
- if (!column) return undefined
469
- const groups = new Map<string, Record<string, any>[]>()
470
- for (const row of rows) {
471
- const value = row[by]
472
- const key = value === null || value === undefined ? '' : column.type === 'date' ? String(value).slice(0, 7) : String(value)
473
- groups.set(key, [...(groups.get(key) ?? []), row])
474
- }
475
- const list = [...groups].map(([key, members]) => ({ key, count: members.length, sums: sumsOf(target, members) }))
476
- if (column.type === 'date') return list.sort((a, b) => a.key.localeCompare(b.key))
477
- /* Largest first by the first sum - in its one currency; groups in two currencies have no common size, so by count. */
478
- const first = target.columns.find(one => one.total)?.name
479
- const codes = first ? currenciesOf(list.map(group => group.sums), first) : []
480
- const size = (group: ReadGroup) => {
481
- const sum = first ? group.sums[first] : undefined
482
- return typeof sum === 'number' ? Math.abs(sum) : codes.length === 1 && sum ? Math.abs(sum[codes[0]] ?? 0) : undefined
483
- }
484
- return list.sort((a, b) => {
485
- const [x, y] = [size(a), size(b)]
486
- return x !== undefined && y !== undefined && codes.length <= 1 ? y - x : b.count - a.count
487
- })
488
- }
489
-
490
- /** The address of the target's list screen with the conditions it takes, and the conditions it does not. */
491
- export function screenAddress(target: ReadTarget, criteria: Record<string, unknown>): { href: string; applied: string[]; notApplied: string[] } | undefined {
492
- const screen = target.screen
493
- if (!screen) return undefined
494
- const params = new URLSearchParams()
495
- for (const [name, value] of Object.entries(screen.params(criteria))) if (value !== undefined && value !== null && value !== '') params.set(name, String(value))
496
- const given = Object.keys(criteria)
497
- const applicable = Object.fromEntries(Object.entries(criteria).filter(([name]) => screen.takes.includes(name)))
498
- const query = screen.queryState
499
- ? encodeListQuery({
500
- filters: filtersOf(target, applicable),
501
- search: typeof applicable.text === 'string' ? applicable.text : undefined,
502
- sorters: target.sortings
503
- })
504
- : params.toString()
505
- return {
506
- href: query ? `${screen.route}?${query}` : screen.route,
507
- applied: given.filter(name => screen.takes.includes(name)),
508
- notApplied: given.filter(name => !screen.takes.includes(name))
509
- }
510
- }