@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,509 +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
- * Application routes that prioritize this tool through ConversationCategory.frontPages. Single-record
212
- * readers may have no list page of their own.
213
- */
214
- frontPages?: string[]
215
- /**
216
- * The lists the answer holds, each a table of typed columns - what a dashboard card may draw from a one-answer read
217
- * (ADR-0160 decision 2). The card keeps only `key`; where the rows are and what their columns are is read here.
218
- */
219
- lists?: DetailList[]
220
- /** The answer is the person's own, whoever asks (나의 전략 업무, 내 급여) - ReadTarget.mine. */
221
- mine?: boolean
222
- }
223
-
224
- /** A list inside a detail read's answer. */
225
- export interface DetailList {
226
- /** A name stable within the read (`by-contract`) - what a card keeps. */
227
- key: string
228
- /** A dotted path inside the value of the query's root field (`rows`); '' when the root field is the list. */
229
- at: string
230
- labelKey?: string
231
- /** What the rows are, for the model. */
232
- description?: string
233
- columns: ReadColumn[]
234
- }
235
-
236
- /** Characters of an answer handed to the model - a longer one is refused, and the model narrows it. */
237
- export const MAX_DETAIL_CHARS = 60_000
238
-
239
- const details = new Map<string, DetailRead>()
240
-
241
- export const detailToolName = (key: string) => `read${pascalOf(key)}`
242
-
243
- /** The variables a query declares, and whether each is required (`!`). */
244
- function variablesOf(document: string): { name: string; required: boolean }[] {
245
- const operation: any = parse(document).definitions.find((one: any) => one.kind === 'OperationDefinition')
246
- return (operation?.variableDefinitions ?? []).map((one: any) => ({ name: one.variable.name.value, required: one.type.kind === 'NonNullType' && !one.defaultValue }))
247
- }
248
-
249
- export function declareDetailRead(target: DetailRead): void {
250
- if (!/^[a-z0-9-]+\.[a-z0-9-]+$/.test(target.key)) throw new Error(`detail read key '${target.key}' is not <app>.<thing>`)
251
- if (details.has(target.key) || registry.has(target.key)) throw new Error(`read target '${target.key}' is declared twice`)
252
- rootFieldOf(target.query, 'query')
253
- const args = target.args ?? []
254
- for (const variable of variablesOf(target.query)) {
255
- const arg = args.find(one => one.name === variable.name)
256
- if (!arg) throw new Error(`detail read '${target.key}' takes $${variable.name}, which is no argument`)
257
- if (variable.required && !arg.required) throw new Error(`detail read '${target.key}': $${variable.name} is required by the query - declare it required`)
258
- }
259
- for (const arg of args) {
260
- 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`)
261
- if (arg.type === 'enum' && !arg.values?.length) throw new Error(`argument '${arg.name}' of '${target.key}' lists no values`)
262
- }
263
- const lists = new Set<string>()
264
- for (const list of target.lists ?? []) {
265
- if (!/^[a-z0-9-]+$/.test(list.key)) throw new Error(`list '${list.key}' of '${target.key}' is not a lowercase key`)
266
- if (lists.has(list.key)) throw new Error(`detail read '${target.key}' names the list '${list.key}' twice`)
267
- lists.add(list.key)
268
- 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`)
269
- checkColumns(`${target.key}/${list.key}`, list.columns)
270
- }
271
- details.set(target.key, target)
272
- }
273
-
274
- export function detailReadOf(key: string | undefined): DetailRead | undefined {
275
- return key ? details.get(key) : undefined
276
- }
277
-
278
- /** A month as a `month` condition holds it. */
279
- const MONTH = /^\d{4}-(0[1-9]|1[0-2])$/
280
-
281
- /*
282
- * The id a key `<axis>:<id>` names - a uuid, or a row's own composite id (a training standing is `<kind>:<year>:<employee>`,
283
- * 2026-11-08). Another axis's key is not this record's: it stays as written and finds nothing.
284
- */
285
- const idOfKey = (axis: string, text: string): string => recordIdOfKey(axis, text) ?? (text.startsWith(`${axis}:`) ? text.slice(axis.length + 1) : text)
286
-
287
- /** The conditions the model set, read by their declared types; a value that does not fit is said, never guessed at. */
288
- export function readCriteria(target: ReadTarget, args: any): { criteria: Record<string, unknown>; refused: { name: string; code: string }[] } {
289
- const criteria: Record<string, unknown> = {}
290
- const refused: { name: string; code: string }[] = []
291
- /* 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). */
292
- if (typeof args?.id === 'string' && args.id.trim()) criteria.id = idOfKey(target.key.split('.').pop()!, args.id.trim())
293
- if (target.search && typeof args?.text === 'string' && args.text.trim()) criteria.text = args.text.trim()
294
- for (const criterion of target.criteria) {
295
- const value = args?.[criterion.name]
296
- if (value === undefined || value === null || value === '' || (Array.isArray(value) && !value.length)) continue
297
- if (criterion.many && Array.isArray(value)) {
298
- const each = value.map(one => readFieldValue(criterion as EntryField, one))
299
- const wrong = each.find(one => one.read === undefined)
300
- if (wrong) refused.push({ name: criterion.name, code: wrong.code ?? 'unreadable' })
301
- else criteria[criterion.name] = [...new Set(each.map(one => one.read))]
302
- continue
303
- }
304
- if (Array.isArray(value)) {
305
- refused.push({ name: criterion.name, code: 'one-value' })
306
- continue
307
- }
308
- const { read, code } = readFieldValue(criterion as EntryField, value)
309
- if (read === undefined) refused.push({ name: criterion.name, code: code ?? 'unreadable' })
310
- else if (criterion.format === 'month' && !MONTH.test(String(read))) refused.push({ name: criterion.name, code: 'not-a-month' })
311
- else criteria[criterion.name] = read
312
- }
313
- return { criteria, refused }
314
- }
315
-
316
- export function filtersOf(target: ReadTarget, criteria: Record<string, unknown>): ReadFilter[] {
317
- return [
318
- ...(typeof criteria.id === 'string' ? [{ name: 'id', operator: 'eq', value: criteria.id }] : []),
319
- ...target.criteria.flatMap(criterion =>
320
- criterion.name in criteria ? [criterion.filter(criteria[criterion.name])].flat() : []
321
- )
322
- ]
323
- }
324
-
325
- /** A dotted path's value - through a list, each one's (an invention's inventors' names). */
326
- export const valueAt = (row: any, path: string) =>
327
- path.split('.').reduce((at, part) => (at === null || at === undefined ? undefined : Array.isArray(at) ? at.map(one => one?.[part]) : at[part]), row)
328
-
329
- /**
330
- * 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
331
- * month stays as it is; anything that is not a moment is left alone. Still ordered as text, so a card's comparison
332
- * with a day keeps working.
333
- */
334
- export function localDateTime(value: string, timeZone?: string): string {
335
- if (!/^\d{4}-\d{2}-\d{2}T/.test(value)) return value
336
- const moment = new Date(value)
337
- if (Number.isNaN(moment.getTime())) return value
338
- try {
339
- const parts = Object.fromEntries(
340
- new Intl.DateTimeFormat('en-CA', { timeZone: timeZone || undefined, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', hourCycle: 'h23' })
341
- .formatToParts(moment)
342
- .map(part => [part.type, part.value])
343
- )
344
- return `${parts.year}-${parts.month}-${parts.day} ${parts.hour}:${parts.minute}`
345
- } catch {
346
- return value
347
- }
348
- }
349
-
350
- /** How the reader's words are asked - `(key, fallback)`, the fallback when the key has no word. */
351
- export type SayWord = (key: string | undefined, fallback: string) => string
352
-
353
- /** The word a coded value is read as, in the reader's language - the value itself when its column has no words. */
354
- export function wordOf(column: Pick<ReadColumn, 'words'> | undefined, value: unknown, say: SayWord): unknown {
355
- if (!column?.words || value === null || value === undefined || value === '') return value
356
- return say(`${column.words}${value}`, String(value))
357
- }
358
-
359
- /** The words of the coded values the rows hold, column by column - what the model reads the codes by. */
360
- export function legendOf(columns: readonly Pick<ReadColumn, 'name' | 'words'>[], rows: Record<string, any>[], say: SayWord): Record<string, Record<string, string>> {
361
- const legend: Record<string, Record<string, string>> = {}
362
- for (const column of columns) {
363
- if (!column.words) continue
364
- for (const row of rows) {
365
- const code = row[column.name]
366
- if (code === null || code === undefined || code === '') continue
367
- ;(legend[column.name] ??= {})[String(code)] = String(wordOf(column, code, say))
368
- }
369
- }
370
- return legend
371
- }
372
-
373
- /** What shapes a row besides its columns - the domain's time zone, for a moment. */
374
- export type RowOptions = { timeZone?: string }
375
-
376
- /** 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. */
377
- export function rowOf(target: Pick<ReadTarget, 'columns'>, item: any, options: RowOptions = {}): Record<string, string | number | null> {
378
- return Object.fromEntries([
379
- /* The id names the record to the model - for one record's detail, a change, or its screen. */
380
- ...(item?.id ? [['id', String(item.id)] as [string, string]] : []),
381
- ...target.columns.map(column => {
382
- const found = valueAt(item, column.path ?? column.name)
383
- /* A list of values reads as one, comma-separated. */
384
- const raw = Array.isArray(found) ? found.filter(one => one !== undefined && one !== null && one !== '').join(', ') : found
385
- if (raw === undefined || raw === null || raw === '') return [column.name, null]
386
- if (column.type === 'number') {
387
- const number = Number(raw)
388
- return [column.name, Number.isFinite(number) ? number : null]
389
- }
390
- return [column.name, column.type === 'date' ? localDateTime(String(raw), options.timeZone) : String(raw)]
391
- })
392
- ])
393
- }
394
-
395
- /**
396
- * Reads the rows through the application's query, page by page, up to MAX_READ_ROWS. `complete` is false when the
397
- * list holds more - a sum of the rows read is then not the sum of the list, and is never said as one.
398
- */
399
- export async function readRows(
400
- target: ReadTarget,
401
- filters: ReadFilter[],
402
- run: GraphqlRunner,
403
- search?: string,
404
- options: RowOptions = {}
405
- ): Promise<{ rows: Record<string, any>[]; total: number; complete: boolean }> {
406
- const rows: Record<string, any>[] = []
407
- let total = 0
408
- for (let page = 1; rows.length < MAX_READ_ROWS; page++) {
409
- const answer = await run(target.query, {
410
- filters: [...filters, ...(target.fixedFilters ?? [])],
411
- ...(search ? { search } : {}),
412
- pagination: { page, limit: READ_PAGE },
413
- ...(target.sortings ? { sortings: target.sortings } : {})
414
- })
415
- if (answer.errors?.length) throw new Error(answer.errors.map(one => one.message).join('; '))
416
- const read = target.rowsOf(answer.data)
417
- total = Number(read?.total) || 0
418
- const items = read?.rows ?? []
419
- rows.push(...items.slice(0, MAX_READ_ROWS - rows.length).map(item => rowOf(target, item, options)))
420
- if (items.length < READ_PAGE || rows.length >= total) break
421
- }
422
- return { rows, total, complete: rows.length >= total }
423
- }
424
-
425
- /** A column's sum - one number, or one per currency when the column names its currency (`{ KRW: 1000, USD: 100 }`). */
426
- export type ReadSum = number | Record<string, number>
427
-
428
- export interface ReadGroup {
429
- key: string
430
- count: number
431
- sums: Record<string, ReadSum>
432
- }
433
-
434
- /** The currency a row without one is summed under - said as it is, never taken for the domain's own. */
435
- export const UNKNOWN_CURRENCY = 'unknown'
436
-
437
- 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
438
-
439
- /** The sums of the number columns marked total - the server's, never the model's; a column with a currency per currency. */
440
- export function sumsOf(target: Pick<ReadTarget, 'columns'>, rows: Record<string, any>[]): Record<string, ReadSum> {
441
- const sums: Record<string, ReadSum> = {}
442
- for (const column of target.columns.filter(one => one.total && one.type === 'number')) {
443
- if (!column.currency) {
444
- sums[column.name] = sumOf(rows, column.name)
445
- continue
446
- }
447
- const byCurrency = new Map<string, Record<string, any>[]>()
448
- for (const row of rows) {
449
- const code = typeof row[column.currency] === 'string' && row[column.currency] ? row[column.currency] : UNKNOWN_CURRENCY
450
- byCurrency.set(code, [...(byCurrency.get(code) ?? []), row])
451
- }
452
- sums[column.name] = Object.fromEntries([...byCurrency].sort(([a], [b]) => a.localeCompare(b)).map(([code, members]) => [code, sumOf(members, column.name)]))
453
- }
454
- return sums
455
- }
456
-
457
- /** The currencies a set of sums holds for one column - none for a column summed as one number. */
458
- export function currenciesOf(sums: Record<string, ReadSum>[], column: string): string[] {
459
- const codes = new Set<string>()
460
- 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)
461
- return [...codes].sort()
462
- }
463
-
464
- /** The rows grouped by one column - a date column by its month - each with its count and sums, largest first. */
465
- export function groupsOf(target: Pick<ReadTarget, 'columns'>, rows: Record<string, any>[], by: string): ReadGroup[] | undefined {
466
- const column = target.columns.find(one => one.name === by)
467
- if (!column) return undefined
468
- const groups = new Map<string, Record<string, any>[]>()
469
- for (const row of rows) {
470
- const value = row[by]
471
- const key = value === null || value === undefined ? '' : column.type === 'date' ? String(value).slice(0, 7) : String(value)
472
- groups.set(key, [...(groups.get(key) ?? []), row])
473
- }
474
- const list = [...groups].map(([key, members]) => ({ key, count: members.length, sums: sumsOf(target, members) }))
475
- if (column.type === 'date') return list.sort((a, b) => a.key.localeCompare(b.key))
476
- /* Largest first by the first sum - in its one currency; groups in two currencies have no common size, so by count. */
477
- const first = target.columns.find(one => one.total)?.name
478
- const codes = first ? currenciesOf(list.map(group => group.sums), first) : []
479
- const size = (group: ReadGroup) => {
480
- const sum = first ? group.sums[first] : undefined
481
- return typeof sum === 'number' ? Math.abs(sum) : codes.length === 1 && sum ? Math.abs(sum[codes[0]] ?? 0) : undefined
482
- }
483
- return list.sort((a, b) => {
484
- const [x, y] = [size(a), size(b)]
485
- return x !== undefined && y !== undefined && codes.length <= 1 ? y - x : b.count - a.count
486
- })
487
- }
488
-
489
- /** The address of the target's list screen with the conditions it takes, and the conditions it does not. */
490
- export function screenAddress(target: ReadTarget, criteria: Record<string, unknown>): { href: string; applied: string[]; notApplied: string[] } | undefined {
491
- const screen = target.screen
492
- if (!screen) return undefined
493
- const params = new URLSearchParams()
494
- for (const [name, value] of Object.entries(screen.params(criteria))) if (value !== undefined && value !== null && value !== '') params.set(name, String(value))
495
- const given = Object.keys(criteria)
496
- const applicable = Object.fromEntries(Object.entries(criteria).filter(([name]) => screen.takes.includes(name)))
497
- const query = screen.queryState
498
- ? encodeListQuery({
499
- filters: filtersOf(target, applicable),
500
- search: typeof applicable.text === 'string' ? applicable.text : undefined,
501
- sorters: target.sortings
502
- })
503
- : params.toString()
504
- return {
505
- href: query ? `${screen.route}?${query}` : screen.route,
506
- applied: given.filter(name => screen.takes.includes(name)),
507
- notApplied: given.filter(name => !screen.takes.includes(name))
508
- }
509
- }