@things-factory/ai-assistant 10.1.278 → 10.1.279

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (531) hide show
  1. package/dist-client/bootstrap.d.ts +4 -4
  2. package/dist-client/bootstrap.js +4 -8
  3. package/dist-client/components/ai-model-price-table.d.ts +32 -0
  4. package/dist-client/components/ai-model-price-table.js +311 -0
  5. package/dist-client/components/ai-usage-table.d.ts +17 -0
  6. package/dist-client/components/ai-usage-table.js +151 -0
  7. package/dist-client/index.d.ts +1 -0
  8. package/dist-client/index.js +2 -0
  9. package/dist-client/pages/ai-model-price-page.d.ts +37 -0
  10. package/dist-client/pages/ai-model-price-page.js +312 -0
  11. package/dist-client/route.d.ts +1 -1
  12. package/dist-client/route.js +4 -0
  13. package/dist-client/settings/ai-agent-setting-let.js +11 -0
  14. package/dist-client/utils/model-price-model.d.ts +31 -0
  15. package/dist-client/utils/model-price-model.js +30 -0
  16. package/dist-client/utils/usage-charts.d.ts +21 -0
  17. package/dist-client/utils/usage-charts.js +45 -0
  18. package/dist-client/utils/usage-model.d.ts +44 -0
  19. package/dist-client/utils/usage-model.js +44 -0
  20. package/dist-server/service/ai-agent-resolver.d.ts +46 -0
  21. package/dist-server/service/ai-agent-resolver.js +252 -0
  22. package/package.json +25 -10
  23. package/things-factory.config.js +4 -1
  24. package/translations/en.json +46 -4
  25. package/translations/es.json +43 -1
  26. package/translations/ja.json +43 -1
  27. package/translations/ko.json +46 -4
  28. package/translations/ms.json +43 -1
  29. package/translations/zh.json +43 -1
  30. package/client/bootstrap.ts +0 -27
  31. package/client/components/assistant-chat.test.ts +0 -149
  32. package/client/components/assistant-chat.ts +0 -5599
  33. package/client/components/assistant-dock.ts +0 -1036
  34. package/client/components/assistant-invite.ts +0 -138
  35. package/client/components/assistant-mode.test.ts +0 -119
  36. package/client/components/assistant-mode.ts +0 -174
  37. package/client/components/assistant-selection-bar.test.ts +0 -167
  38. package/client/components/assistant-selection-bar.ts +0 -178
  39. package/client/components/assistant-session-manager.ts +0 -915
  40. package/client/components/assistant-session-toolbar.ts +0 -80
  41. package/client/components/chat-defaults.ts +0 -64
  42. package/client/components/chat-echo-dedup.test.ts +0 -253
  43. package/client/components/chat-echo-dedup.ts +0 -190
  44. package/client/components/chat-input-builder.test.ts +0 -86
  45. package/client/components/chat-input-builder.ts +0 -133
  46. package/client/components/chat-proposal-survival.test.ts +0 -73
  47. package/client/components/entry-review.ts +0 -346
  48. package/client/components/markdown.test.ts +0 -518
  49. package/client/components/markdown.ts +0 -508
  50. package/client/components/mention-popup-helpers.ts +0 -433
  51. package/client/components/mention-popup.test.ts +0 -588
  52. package/client/components/mention-popup.ts +0 -261
  53. package/client/components/panel-aria.test.ts +0 -59
  54. package/client/components/proposal-outcome-line.ts +0 -74
  55. package/client/components/proposal-request.test.ts +0 -73
  56. package/client/components/reply-message.test.ts +0 -15
  57. package/client/components/reply-message.ts +0 -11
  58. package/client/components/roster-identity.test.ts +0 -8
  59. package/client/components/roster-identity.ts +0 -4
  60. package/client/components/workspace-view.ts +0 -486
  61. package/client/index.ts +0 -36
  62. package/client/pages/assistant-workspace-page.ts +0 -317
  63. package/client/route.ts +0 -9
  64. package/client/settings/agent-settings-model.ts +0 -164
  65. package/client/settings/ai-agent-setting-let.ts +0 -667
  66. package/client/settings/ai-usage-setting-let.ts +0 -240
  67. package/client/settings/usage-model.ts +0 -46
  68. package/client/setup-assistant-dock.ts +0 -177
  69. package/client/tsconfig.json +0 -13
  70. package/client/utils/addressed-draft.test.ts +0 -31
  71. package/client/utils/agent-choice.ts +0 -56
  72. package/client/utils/applied-screens.ts +0 -36
  73. package/client/utils/assistant-activity.ts +0 -122
  74. package/client/utils/assistant-ask.test.ts +0 -38
  75. package/client/utils/assistant-ask.ts +0 -93
  76. package/client/utils/assistant-capability-read.ts +0 -24
  77. package/client/utils/assistant-capability.test.ts +0 -17
  78. package/client/utils/assistant-capability.ts +0 -19
  79. package/client/utils/assistant-navigation.test.ts +0 -66
  80. package/client/utils/assistant-navigation.ts +0 -11
  81. package/client/utils/assistant-proposals.ts +0 -85
  82. package/client/utils/assistant-request-context.ts +0 -63
  83. package/client/utils/assistant-selection.test.ts +0 -54
  84. package/client/utils/assistant-selection.ts +0 -75
  85. package/client/utils/assistant-session-actions.ts +0 -32
  86. package/client/utils/assistant-session-admin.ts +0 -239
  87. package/client/utils/assistant-session-controller.test.ts +0 -75
  88. package/client/utils/assistant-session-controller.ts +0 -208
  89. package/client/utils/assistant-session-transport.ts +0 -46
  90. package/client/utils/assistant-surface.ts +0 -178
  91. package/client/utils/assistant-typing.test.ts +0 -33
  92. package/client/utils/assistant-typing.ts +0 -53
  93. package/client/utils/attachment-policy.ts +0 -106
  94. package/client/utils/composer-frame.ts +0 -77
  95. package/client/utils/document-text.ts +0 -332
  96. package/client/utils/entry-hash.ts +0 -35
  97. package/client/utils/entry-proposal.ts +0 -215
  98. package/client/utils/entry-workspace.ts +0 -70
  99. package/client/utils/invite-proposal-register.ts +0 -31
  100. package/client/utils/invite-proposal.test.ts +0 -40
  101. package/client/utils/invite-proposal.ts +0 -54
  102. package/client/utils/menu-room.ts +0 -33
  103. package/client/utils/open-page.ts +0 -21
  104. package/client/utils/pasted-table.ts +0 -145
  105. package/client/utils/pdf-pages.ts +0 -25
  106. package/client/utils/spreadsheet-text.ts +0 -125
  107. package/client/utils/workspace.ts +0 -89
  108. package/dist-client/bootstrap.js.map +0 -1
  109. package/dist-client/components/assistant-chat.js.map +0 -1
  110. package/dist-client/components/assistant-chat.test.d.ts +0 -1
  111. package/dist-client/components/assistant-chat.test.js +0 -138
  112. package/dist-client/components/assistant-chat.test.js.map +0 -1
  113. package/dist-client/components/assistant-dock.js.map +0 -1
  114. package/dist-client/components/assistant-invite.js.map +0 -1
  115. package/dist-client/components/assistant-mode.js.map +0 -1
  116. package/dist-client/components/assistant-mode.test.d.ts +0 -1
  117. package/dist-client/components/assistant-mode.test.js +0 -100
  118. package/dist-client/components/assistant-mode.test.js.map +0 -1
  119. package/dist-client/components/assistant-selection-bar.js.map +0 -1
  120. package/dist-client/components/assistant-selection-bar.test.d.ts +0 -1
  121. package/dist-client/components/assistant-selection-bar.test.js +0 -148
  122. package/dist-client/components/assistant-selection-bar.test.js.map +0 -1
  123. package/dist-client/components/assistant-session-manager.js.map +0 -1
  124. package/dist-client/components/assistant-session-toolbar.js.map +0 -1
  125. package/dist-client/components/chat-defaults.js.map +0 -1
  126. package/dist-client/components/chat-echo-dedup.js.map +0 -1
  127. package/dist-client/components/chat-echo-dedup.test.d.ts +0 -1
  128. package/dist-client/components/chat-echo-dedup.test.js +0 -223
  129. package/dist-client/components/chat-echo-dedup.test.js.map +0 -1
  130. package/dist-client/components/chat-input-builder.js.map +0 -1
  131. package/dist-client/components/chat-input-builder.test.d.ts +0 -1
  132. package/dist-client/components/chat-input-builder.test.js +0 -70
  133. package/dist-client/components/chat-input-builder.test.js.map +0 -1
  134. package/dist-client/components/chat-proposal-survival.test.d.ts +0 -1
  135. package/dist-client/components/chat-proposal-survival.test.js +0 -61
  136. package/dist-client/components/chat-proposal-survival.test.js.map +0 -1
  137. package/dist-client/components/entry-review.js.map +0 -1
  138. package/dist-client/components/markdown.js.map +0 -1
  139. package/dist-client/components/markdown.test.d.ts +0 -1
  140. package/dist-client/components/markdown.test.js +0 -418
  141. package/dist-client/components/markdown.test.js.map +0 -1
  142. package/dist-client/components/mention-popup-helpers.js.map +0 -1
  143. package/dist-client/components/mention-popup.js.map +0 -1
  144. package/dist-client/components/mention-popup.test.d.ts +0 -1
  145. package/dist-client/components/mention-popup.test.js +0 -474
  146. package/dist-client/components/mention-popup.test.js.map +0 -1
  147. package/dist-client/components/panel-aria.test.d.ts +0 -1
  148. package/dist-client/components/panel-aria.test.js +0 -53
  149. package/dist-client/components/panel-aria.test.js.map +0 -1
  150. package/dist-client/components/proposal-outcome-line.js.map +0 -1
  151. package/dist-client/components/proposal-request.test.d.ts +0 -1
  152. package/dist-client/components/proposal-request.test.js +0 -63
  153. package/dist-client/components/proposal-request.test.js.map +0 -1
  154. package/dist-client/components/reply-message.js.map +0 -1
  155. package/dist-client/components/reply-message.test.d.ts +0 -1
  156. package/dist-client/components/reply-message.test.js +0 -16
  157. package/dist-client/components/reply-message.test.js.map +0 -1
  158. package/dist-client/components/roster-identity.js.map +0 -1
  159. package/dist-client/components/roster-identity.test.d.ts +0 -1
  160. package/dist-client/components/roster-identity.test.js +0 -9
  161. package/dist-client/components/roster-identity.test.js.map +0 -1
  162. package/dist-client/components/workspace-view.js.map +0 -1
  163. package/dist-client/index.js.map +0 -1
  164. package/dist-client/pages/assistant-workspace-page.js.map +0 -1
  165. package/dist-client/route.js.map +0 -1
  166. package/dist-client/settings/agent-settings-model.js.map +0 -1
  167. package/dist-client/settings/ai-agent-setting-let.js.map +0 -1
  168. package/dist-client/settings/ai-usage-setting-let.d.ts +0 -25
  169. package/dist-client/settings/ai-usage-setting-let.js +0 -258
  170. package/dist-client/settings/ai-usage-setting-let.js.map +0 -1
  171. package/dist-client/settings/usage-model.d.ts +0 -32
  172. package/dist-client/settings/usage-model.js +0 -25
  173. package/dist-client/settings/usage-model.js.map +0 -1
  174. package/dist-client/setup-assistant-dock.js.map +0 -1
  175. package/dist-client/tsconfig.tsbuildinfo +0 -1
  176. package/dist-client/utils/addressed-draft.test.d.ts +0 -1
  177. package/dist-client/utils/addressed-draft.test.js +0 -27
  178. package/dist-client/utils/addressed-draft.test.js.map +0 -1
  179. package/dist-client/utils/agent-choice.js.map +0 -1
  180. package/dist-client/utils/applied-screens.js.map +0 -1
  181. package/dist-client/utils/assistant-activity.js.map +0 -1
  182. package/dist-client/utils/assistant-ask.js.map +0 -1
  183. package/dist-client/utils/assistant-ask.test.d.ts +0 -1
  184. package/dist-client/utils/assistant-ask.test.js +0 -40
  185. package/dist-client/utils/assistant-ask.test.js.map +0 -1
  186. package/dist-client/utils/assistant-capability-read.js.map +0 -1
  187. package/dist-client/utils/assistant-capability.js.map +0 -1
  188. package/dist-client/utils/assistant-capability.test.d.ts +0 -1
  189. package/dist-client/utils/assistant-capability.test.js +0 -16
  190. package/dist-client/utils/assistant-capability.test.js.map +0 -1
  191. package/dist-client/utils/assistant-navigation.js.map +0 -1
  192. package/dist-client/utils/assistant-navigation.test.d.ts +0 -1
  193. package/dist-client/utils/assistant-navigation.test.js +0 -63
  194. package/dist-client/utils/assistant-navigation.test.js.map +0 -1
  195. package/dist-client/utils/assistant-proposals.js.map +0 -1
  196. package/dist-client/utils/assistant-request-context.js.map +0 -1
  197. package/dist-client/utils/assistant-selection.js.map +0 -1
  198. package/dist-client/utils/assistant-selection.test.d.ts +0 -1
  199. package/dist-client/utils/assistant-selection.test.js +0 -46
  200. package/dist-client/utils/assistant-selection.test.js.map +0 -1
  201. package/dist-client/utils/assistant-session-actions.js.map +0 -1
  202. package/dist-client/utils/assistant-session-admin.js.map +0 -1
  203. package/dist-client/utils/assistant-session-controller.js.map +0 -1
  204. package/dist-client/utils/assistant-session-controller.test.d.ts +0 -1
  205. package/dist-client/utils/assistant-session-controller.test.js +0 -56
  206. package/dist-client/utils/assistant-session-controller.test.js.map +0 -1
  207. package/dist-client/utils/assistant-session-transport.js.map +0 -1
  208. package/dist-client/utils/assistant-surface.js.map +0 -1
  209. package/dist-client/utils/assistant-typing.js.map +0 -1
  210. package/dist-client/utils/assistant-typing.test.d.ts +0 -1
  211. package/dist-client/utils/assistant-typing.test.js +0 -30
  212. package/dist-client/utils/assistant-typing.test.js.map +0 -1
  213. package/dist-client/utils/attachment-policy.js.map +0 -1
  214. package/dist-client/utils/composer-frame.js.map +0 -1
  215. package/dist-client/utils/document-text.js.map +0 -1
  216. package/dist-client/utils/entry-hash.js.map +0 -1
  217. package/dist-client/utils/entry-proposal.js.map +0 -1
  218. package/dist-client/utils/entry-workspace.js.map +0 -1
  219. package/dist-client/utils/invite-proposal-register.js.map +0 -1
  220. package/dist-client/utils/invite-proposal.js.map +0 -1
  221. package/dist-client/utils/invite-proposal.test.d.ts +0 -1
  222. package/dist-client/utils/invite-proposal.test.js +0 -35
  223. package/dist-client/utils/invite-proposal.test.js.map +0 -1
  224. package/dist-client/utils/menu-room.js.map +0 -1
  225. package/dist-client/utils/open-page.js.map +0 -1
  226. package/dist-client/utils/pasted-table.js.map +0 -1
  227. package/dist-client/utils/pdf-pages.js.map +0 -1
  228. package/dist-client/utils/spreadsheet-text.js.map +0 -1
  229. package/dist-client/utils/workspace.js.map +0 -1
  230. package/dist-server/door-declaration-report.js.map +0 -1
  231. package/dist-server/index.js.map +0 -1
  232. package/dist-server/role-tasks.js.map +0 -1
  233. package/dist-server/service/ai-agent-resolver.js.map +0 -1
  234. package/dist-server/service/assistant-capability-resolver.js.map +0 -1
  235. package/dist-server/service/assistant-chat-resolver.js.map +0 -1
  236. package/dist-server/service/assistant-mode/assistant-mode-resolver.js.map +0 -1
  237. package/dist-server/service/assistant-mode/fallback-subjects.js.map +0 -1
  238. package/dist-server/service/assistant-mode/index.js.map +0 -1
  239. package/dist-server/service/assistant-mode/mode-categories.js.map +0 -1
  240. package/dist-server/service/assistant-mode/record-subject.js.map +0 -1
  241. package/dist-server/service/assistant-mode/registry.js.map +0 -1
  242. package/dist-server/service/assistant-mode/resolve.js.map +0 -1
  243. package/dist-server/service/assistant-mode/screen-rules.js.map +0 -1
  244. package/dist-server/service/assistant-mode/turn-lines.js.map +0 -1
  245. package/dist-server/service/assistant-mode/types.js.map +0 -1
  246. package/dist-server/service/chat-message/carried-turns.js.map +0 -1
  247. package/dist-server/service/chat-message/chat-message-broadcast.js.map +0 -1
  248. package/dist-server/service/chat-message/chat-message-publish.js.map +0 -1
  249. package/dist-server/service/chat-message/chat-message-room.js.map +0 -1
  250. package/dist-server/service/chat-message/chat-message-subscription.js.map +0 -1
  251. package/dist-server/service/chat-message/chat-message.js.map +0 -1
  252. package/dist-server/service/chat-message/chat-typing-subscription.js.map +0 -1
  253. package/dist-server/service/chat-message/chat-typing.js.map +0 -1
  254. package/dist-server/service/chat-message/door-access.js.map +0 -1
  255. package/dist-server/service/chat-message/fold-history.js.map +0 -1
  256. package/dist-server/service/chat-message/fold-session-history.js.map +0 -1
  257. package/dist-server/service/chat-message/history-summary.js.map +0 -1
  258. package/dist-server/service/chat-message/index.js.map +0 -1
  259. package/dist-server/service/chat-message/llm-history.js.map +0 -1
  260. package/dist-server/service/chat-message/message-doors.js.map +0 -1
  261. package/dist-server/service/chat-message/proposal-outcome.js.map +0 -1
  262. package/dist-server/service/chat-message/reader-gate.js.map +0 -1
  263. package/dist-server/service/chat-message/room-message.js.map +0 -1
  264. package/dist-server/service/chat-message/room-turn.js.map +0 -1
  265. package/dist-server/service/chat-message/used-tools.js.map +0 -1
  266. package/dist-server/service/chat-session/attachment-policy.js.map +0 -1
  267. package/dist-server/service/chat-session/attachment-route.js.map +0 -1
  268. package/dist-server/service/chat-session/attachment-tool-result.js.map +0 -1
  269. package/dist-server/service/chat-session/attachment-tools.js.map +0 -1
  270. package/dist-server/service/chat-session/chat-session.js.map +0 -1
  271. package/dist-server/service/chat-session/index.js.map +0 -1
  272. package/dist-server/service/chat-session/session-activity-broadcast.js.map +0 -1
  273. package/dist-server/service/chat-session/session-activity-publish.js.map +0 -1
  274. package/dist-server/service/chat-session/session-activity-subscription.js.map +0 -1
  275. package/dist-server/service/chat-session/session-anchor.js.map +0 -1
  276. package/dist-server/service/chat-session/session-attachments.js.map +0 -1
  277. package/dist-server/service/chat-session/session-cleanup.js.map +0 -1
  278. package/dist-server/service/chat-session/session-inbox.js.map +0 -1
  279. package/dist-server/service/chat-session/session-kind.js.map +0 -1
  280. package/dist-server/service/chat-session/session-name.js.map +0 -1
  281. package/dist-server/service/chat-session/session-purge.js.map +0 -1
  282. package/dist-server/service/chat-session/session-retention.js.map +0 -1
  283. package/dist-server/service/chat-session/session-visibility.js.map +0 -1
  284. package/dist-server/service/chat-session/session-write-gate.js.map +0 -1
  285. package/dist-server/service/chat-session/station-session-guard.js.map +0 -1
  286. package/dist-server/service/chat-session/turn-attachments.js.map +0 -1
  287. package/dist-server/service/chat-session-participant/chat-session-participant.js.map +0 -1
  288. package/dist-server/service/chat-session-participant/index.js.map +0 -1
  289. package/dist-server/service/chat-session-participant/invite-notification.js.map +0 -1
  290. package/dist-server/service/chat-session-participant/mention-invite.js.map +0 -1
  291. package/dist-server/service/chat-session-participant/participant-lookup-roles.js.map +0 -1
  292. package/dist-server/service/chat-session-participant/participant-lookup.js.map +0 -1
  293. package/dist-server/service/chat-session-participant/presence.js.map +0 -1
  294. package/dist-server/service/chat-session-participant/read-roster.js.map +0 -1
  295. package/dist-server/service/chat-session-resolver.js.map +0 -1
  296. package/dist-server/service/data-entry/entry-apply.js.map +0 -1
  297. package/dist-server/service/data-entry/entry-hash.js.map +0 -1
  298. package/dist-server/service/data-entry/entry-refusal.js.map +0 -1
  299. package/dist-server/service/data-entry/entry-resolver.js.map +0 -1
  300. package/dist-server/service/data-entry/entry-screen.js.map +0 -1
  301. package/dist-server/service/data-entry/entry-sources.js.map +0 -1
  302. package/dist-server/service/data-entry/entry-target.js.map +0 -1
  303. package/dist-server/service/data-entry/entry-tools.js.map +0 -1
  304. package/dist-server/service/data-entry/entry-update.js.map +0 -1
  305. package/dist-server/service/data-read/list-read.js.map +0 -1
  306. package/dist-server/service/data-read/read-target.js.map +0 -1
  307. package/dist-server/service/data-read/read-tools.js.map +0 -1
  308. package/dist-server/service/grounding-sources.js.map +0 -1
  309. package/dist-server/service/help-documents/help-keys.js.map +0 -1
  310. package/dist-server/service/help-documents/help-tools.js.map +0 -1
  311. package/dist-server/service/index.js.map +0 -1
  312. package/dist-server/service/people/index.js.map +0 -1
  313. package/dist-server/service/people/invite-tools.js.map +0 -1
  314. package/dist-server/service/people/people-keys.js.map +0 -1
  315. package/dist-server/service/people/people-read.js.map +0 -1
  316. package/dist-server/service/people/person-subject.js.map +0 -1
  317. package/dist-server/service/request-translator.js.map +0 -1
  318. package/dist-server/service/testing/conversation-script.js.map +0 -1
  319. package/dist-server/service/testing/mode-conformance.js.map +0 -1
  320. package/dist-server/service/tool-access.js.map +0 -1
  321. package/dist-server/service/types.js.map +0 -1
  322. package/dist-server/service/unattended-run/assistant-run.js.map +0 -1
  323. package/dist-server/service/unattended-run/index.js.map +0 -1
  324. package/dist-server/service/unattended-run/limits.js.map +0 -1
  325. package/dist-server/service/unattended-run/run-as.js.map +0 -1
  326. package/dist-server/service/unattended-run/run-budget.js.map +0 -1
  327. package/dist-server/service/unattended-run/run-ledger.js.map +0 -1
  328. package/dist-server/service/unattended-run/run-outcome.js.map +0 -1
  329. package/dist-server/service/unattended-run/run-store.js.map +0 -1
  330. package/dist-server/service/unattended-run/run-unattended.js.map +0 -1
  331. package/dist-server/service/unattended-run/unattended-prompt.js.map +0 -1
  332. package/dist-server/service/workspace/workspace-blocks.js.map +0 -1
  333. package/dist-server/service/workspace/workspace-tools.js.map +0 -1
  334. package/dist-server/tool-registry-boot-report.js.map +0 -1
  335. package/dist-server/tsconfig.tsbuildinfo +0 -1
  336. package/docs/session-controller.md +0 -52
  337. package/server/door-declaration-report.test.ts +0 -53
  338. package/server/door-declaration-report.ts +0 -61
  339. package/server/explicit-graphql-types.test.ts +0 -56
  340. package/server/index.ts +0 -36
  341. package/server/role-tasks.ts +0 -14
  342. package/server/service/ai-agent-resolver.ts +0 -330
  343. package/server/service/assistant-capability-resolver.ts +0 -66
  344. package/server/service/assistant-chat-resolver.ts +0 -640
  345. package/server/service/assistant-mode/assistant-mode-resolver.ts +0 -101
  346. package/server/service/assistant-mode/conversation-category.test.ts +0 -48
  347. package/server/service/assistant-mode/fallback-subjects.ts +0 -36
  348. package/server/service/assistant-mode/index.ts +0 -22
  349. package/server/service/assistant-mode/mode-categories.ts +0 -178
  350. package/server/service/assistant-mode/mode-front.test.ts +0 -183
  351. package/server/service/assistant-mode/one-conversation-per-subject.test.ts +0 -37
  352. package/server/service/assistant-mode/open-subject-door.test.ts +0 -52
  353. package/server/service/assistant-mode/record-subject.test.ts +0 -41
  354. package/server/service/assistant-mode/record-subject.ts +0 -44
  355. package/server/service/assistant-mode/registry.test.ts +0 -171
  356. package/server/service/assistant-mode/registry.ts +0 -139
  357. package/server/service/assistant-mode/resolve.test.ts +0 -129
  358. package/server/service/assistant-mode/resolve.ts +0 -113
  359. package/server/service/assistant-mode/screen-rules.test.ts +0 -99
  360. package/server/service/assistant-mode/screen-rules.ts +0 -103
  361. package/server/service/assistant-mode/turn-lines.ts +0 -43
  362. package/server/service/assistant-mode/types.ts +0 -138
  363. package/server/service/chat-message/carried-turns.test.ts +0 -80
  364. package/server/service/chat-message/carried-turns.ts +0 -112
  365. package/server/service/chat-message/chat-message-broadcast.integration.test.ts +0 -73
  366. package/server/service/chat-message/chat-message-broadcast.test.ts +0 -40
  367. package/server/service/chat-message/chat-message-broadcast.ts +0 -70
  368. package/server/service/chat-message/chat-message-publish.ts +0 -22
  369. package/server/service/chat-message/chat-message-room.test.ts +0 -145
  370. package/server/service/chat-message/chat-message-room.ts +0 -50
  371. package/server/service/chat-message/chat-message-subscription.ts +0 -77
  372. package/server/service/chat-message/chat-message.ts +0 -289
  373. package/server/service/chat-message/chat-typing-subscription.ts +0 -52
  374. package/server/service/chat-message/chat-typing.test.ts +0 -45
  375. package/server/service/chat-message/chat-typing.ts +0 -48
  376. package/server/service/chat-message/door-access.test.ts +0 -72
  377. package/server/service/chat-message/door-access.ts +0 -65
  378. package/server/service/chat-message/fold-history-window.test.ts +0 -184
  379. package/server/service/chat-message/fold-history.test.ts +0 -98
  380. package/server/service/chat-message/fold-history.ts +0 -77
  381. package/server/service/chat-message/fold-session-history.test.ts +0 -116
  382. package/server/service/chat-message/fold-session-history.ts +0 -115
  383. package/server/service/chat-message/history-summary.test.ts +0 -127
  384. package/server/service/chat-message/history-summary.ts +0 -100
  385. package/server/service/chat-message/index.ts +0 -13
  386. package/server/service/chat-message/llm-history.test.ts +0 -245
  387. package/server/service/chat-message/llm-history.ts +0 -182
  388. package/server/service/chat-message/message-doors.test.ts +0 -124
  389. package/server/service/chat-message/message-doors.ts +0 -132
  390. package/server/service/chat-message/proposal-outcome.test.ts +0 -111
  391. package/server/service/chat-message/proposal-outcome.ts +0 -99
  392. package/server/service/chat-message/reader-gate.ts +0 -44
  393. package/server/service/chat-message/room-message.test.ts +0 -21
  394. package/server/service/chat-message/room-message.ts +0 -22
  395. package/server/service/chat-message/room-turn.ts +0 -42
  396. package/server/service/chat-message/used-tools.test.ts +0 -19
  397. package/server/service/chat-message/used-tools.ts +0 -25
  398. package/server/service/chat-session/attachment-policy.test.ts +0 -42
  399. package/server/service/chat-session/attachment-policy.ts +0 -91
  400. package/server/service/chat-session/attachment-route.ts +0 -45
  401. package/server/service/chat-session/attachment-tool-result.test.ts +0 -63
  402. package/server/service/chat-session/attachment-tool-result.ts +0 -37
  403. package/server/service/chat-session/attachment-tools.ts +0 -66
  404. package/server/service/chat-session/chat-session.ts +0 -244
  405. package/server/service/chat-session/group-room.test.ts +0 -233
  406. package/server/service/chat-session/index.ts +0 -5
  407. package/server/service/chat-session/session-activity-broadcast.ts +0 -77
  408. package/server/service/chat-session/session-activity-publish.ts +0 -49
  409. package/server/service/chat-session/session-activity-receivers.test.ts +0 -26
  410. package/server/service/chat-session/session-activity-subscription.ts +0 -66
  411. package/server/service/chat-session/session-anchor.ts +0 -142
  412. package/server/service/chat-session/session-attachments.ts +0 -90
  413. package/server/service/chat-session/session-cleanup.test.ts +0 -83
  414. package/server/service/chat-session/session-cleanup.ts +0 -69
  415. package/server/service/chat-session/session-inbox.test.ts +0 -273
  416. package/server/service/chat-session/session-inbox.ts +0 -240
  417. package/server/service/chat-session/session-kind.test.ts +0 -24
  418. package/server/service/chat-session/session-kind.ts +0 -32
  419. package/server/service/chat-session/session-name.ts +0 -32
  420. package/server/service/chat-session/session-purge.test.ts +0 -24
  421. package/server/service/chat-session/session-purge.ts +0 -117
  422. package/server/service/chat-session/session-retention.ts +0 -17
  423. package/server/service/chat-session/session-visibility.test.ts +0 -130
  424. package/server/service/chat-session/session-visibility.ts +0 -68
  425. package/server/service/chat-session/session-write-gate.test.ts +0 -59
  426. package/server/service/chat-session/session-write-gate.ts +0 -31
  427. package/server/service/chat-session/station-session-guard.ts +0 -25
  428. package/server/service/chat-session/turn-attachments.test.ts +0 -106
  429. package/server/service/chat-session/turn-attachments.ts +0 -45
  430. package/server/service/chat-session-participant/chat-session-participant.ts +0 -135
  431. package/server/service/chat-session-participant/index.ts +0 -8
  432. package/server/service/chat-session-participant/invite-notification.test.ts +0 -80
  433. package/server/service/chat-session-participant/invite-notification.ts +0 -118
  434. package/server/service/chat-session-participant/mention-invite.test.ts +0 -173
  435. package/server/service/chat-session-participant/mention-invite.ts +0 -180
  436. package/server/service/chat-session-participant/participant-lookup-roles.ts +0 -6
  437. package/server/service/chat-session-participant/participant-lookup.ts +0 -22
  438. package/server/service/chat-session-participant/presence.test.ts +0 -39
  439. package/server/service/chat-session-participant/presence.ts +0 -21
  440. package/server/service/chat-session-participant/read-roster.test.ts +0 -27
  441. package/server/service/chat-session-participant/read-roster.ts +0 -17
  442. package/server/service/chat-session-resolver.ts +0 -1455
  443. package/server/service/data-entry/data-entry-update.test.ts +0 -378
  444. package/server/service/data-entry/data-entry.test.ts +0 -494
  445. package/server/service/data-entry/entry-apply.ts +0 -247
  446. package/server/service/data-entry/entry-hash.ts +0 -35
  447. package/server/service/data-entry/entry-refusal.test.ts +0 -73
  448. package/server/service/data-entry/entry-refusal.ts +0 -20
  449. package/server/service/data-entry/entry-resolver.ts +0 -74
  450. package/server/service/data-entry/entry-screen.ts +0 -14
  451. package/server/service/data-entry/entry-sources.ts +0 -39
  452. package/server/service/data-entry/entry-target.ts +0 -774
  453. package/server/service/data-entry/entry-tools.ts +0 -282
  454. package/server/service/data-entry/entry-update.ts +0 -238
  455. package/server/service/data-read/data-read.test.ts +0 -395
  456. package/server/service/data-read/detail-lists.test.ts +0 -61
  457. package/server/service/data-read/list-missing.test.ts +0 -49
  458. package/server/service/data-read/list-read.ts +0 -146
  459. package/server/service/data-read/list-status.test.ts +0 -46
  460. package/server/service/data-read/read-target.ts +0 -509
  461. package/server/service/data-read/read-tools.ts +0 -334
  462. package/server/service/data-read/read-words.test.ts +0 -99
  463. package/server/service/data-read/record-keys.test.ts +0 -42
  464. package/server/service/grounding-sources.test.ts +0 -55
  465. package/server/service/grounding-sources.ts +0 -46
  466. package/server/service/help-documents/help-keys.ts +0 -2
  467. package/server/service/help-documents/help-tools.test.ts +0 -40
  468. package/server/service/help-documents/help-tools.ts +0 -88
  469. package/server/service/index.ts +0 -99
  470. package/server/service/people/index.ts +0 -15
  471. package/server/service/people/invite-tools.ts +0 -159
  472. package/server/service/people/invite.test.ts +0 -159
  473. package/server/service/people/people-keys.ts +0 -16
  474. package/server/service/people/people-read.test.ts +0 -82
  475. package/server/service/people/people-read.ts +0 -56
  476. package/server/service/people/person-subject.test.ts +0 -161
  477. package/server/service/people/person-subject.ts +0 -83
  478. package/server/service/request-translator.test.ts +0 -45
  479. package/server/service/request-translator.ts +0 -33
  480. package/server/service/session-anchor.test.ts +0 -198
  481. package/server/service/station-session-guard.test.ts +0 -31
  482. package/server/service/testing/conversation-scenario.test.ts +0 -164
  483. package/server/service/testing/conversation-script.test.ts +0 -133
  484. package/server/service/testing/conversation-script.ts +0 -296
  485. package/server/service/testing/mode-conformance.test.ts +0 -61
  486. package/server/service/testing/mode-conformance.ts +0 -165
  487. package/server/service/tool-access.test.ts +0 -96
  488. package/server/service/tool-access.ts +0 -36
  489. package/server/service/types.ts +0 -15
  490. package/server/service/unattended-run/assistant-run.ts +0 -199
  491. package/server/service/unattended-run/index.ts +0 -10
  492. package/server/service/unattended-run/limits.ts +0 -24
  493. package/server/service/unattended-run/run-as.ts +0 -38
  494. package/server/service/unattended-run/run-budget.ts +0 -58
  495. package/server/service/unattended-run/run-ledger.ts +0 -31
  496. package/server/service/unattended-run/run-outcome.ts +0 -43
  497. package/server/service/unattended-run/run-store-race.pg.test.ts +0 -83
  498. package/server/service/unattended-run/run-store.ts +0 -162
  499. package/server/service/unattended-run/run-unattended.test.ts +0 -478
  500. package/server/service/unattended-run/run-unattended.ts +0 -248
  501. package/server/service/unattended-run/unattended-prompt.ts +0 -24
  502. package/server/service/workspace/workspace-blocks.ts +0 -134
  503. package/server/service/workspace/workspace-tools.ts +0 -108
  504. package/server/service/workspace/workspace.test.ts +0 -74
  505. package/server/tool-registry-boot-report.test.ts +0 -41
  506. package/server/tool-registry-boot-report.ts +0 -63
  507. package/test/ai-agent-settings.test.ts +0 -123
  508. package/test/applied-screens.test.ts +0 -65
  509. package/test/assistant-chat-call-sites.test.ts +0 -92
  510. package/test/assistant-dock.test.ts +0 -294
  511. package/test/assistant-request-context.test.ts +0 -72
  512. package/test/assistant-session-controller.test.ts +0 -87
  513. package/test/assistant-session-manager.test.ts +0 -186
  514. package/test/assistant-session-toolbar.test.ts +0 -43
  515. package/test/attachment-one-rule.test.ts +0 -46
  516. package/test/attachment-policy-agree.test.ts +0 -38
  517. package/test/composer-frame.test.ts +0 -173
  518. package/test/document-text.test.ts +0 -175
  519. package/test/entry-card-styles.test.ts +0 -18
  520. package/test/entry-proposal.test.ts +0 -186
  521. package/test/entry-workspace.test.ts +0 -89
  522. package/test/menu-room.test.ts +0 -33
  523. package/test/open-doors.test.ts +0 -164
  524. package/test/open-page.test.ts +0 -31
  525. package/test/pasted-table.test.ts +0 -147
  526. package/test/refusals-in-korean.test.ts +0 -80
  527. package/test/session-discovery.test.ts +0 -43
  528. package/test/spreadsheet-text.test.ts +0 -92
  529. package/test/translations.test.ts +0 -80
  530. package/test/workspace.test.ts +0 -54
  531. package/tsconfig.json +0 -9
@@ -1,1036 +0,0 @@
1
- import { findMenu, foldForDock, unfoldAfterDock } from '../utils/menu-room.js'
2
- import '@material/web/icon/icon.js'
3
- import './assistant-chat.js'
4
- import './assistant-session-toolbar.js'
5
- import './assistant-session-manager.js'
6
-
7
- import gql from 'graphql-tag'
8
- import { LitElement, css, html, nothing, type TemplateResult } from 'lit'
9
- import { customElement, property, state } from 'lit/decorators.js'
10
- import { keyed } from 'lit/directives/keyed.js'
11
-
12
- import { client } from '@operato/graphql'
13
- import { i18next, localize } from '@operato/i18n'
14
- import { closeOverlay, notify, refreshEntity360 } from '@operato/layout'
15
- import { OxPrompt } from '@operato/popup'
16
- import { AppController, navigate, store } from '@operato/shell'
17
- import { ScrollbarStyles } from '@operato/styles'
18
-
19
- import type { AssistantMode } from './assistant-mode.js'
20
- import { AssistantSessionController, type AssistantSession, type AssistantSessionTarget } from '../utils/assistant-session-controller.js'
21
- import { assistantSessionTransport } from '../utils/assistant-session-transport.js'
22
- import { readAiCapability } from '../utils/assistant-capability-read.js'
23
- import type { AiCapability } from '../utils/assistant-capability.js'
24
- import { setOpenSession, subscribeSessionActivity } from '../utils/assistant-activity.js'
25
- import {
26
- assistantHomeSurface,
27
- currentAssistantSurface,
28
- isAnchor,
29
- subscribeAssistantSurface,
30
- type AnchorResult,
31
- type AssistantSurface
32
- } from '../utils/assistant-surface.js'
33
- import { runProposal, setEntryProposalHandler, type ProposalContext, type ProposalOutcome } from '../utils/assistant-proposals.js'
34
- import { refreshAppliedScreens, type AppliedScreensDeps } from '../utils/applied-screens.js'
35
- /* The invite card's handler - ai-assistant's own tool, registered by its own module (design/ai/shared-dock.md §4). */
36
- import '../utils/invite-proposal-register.js'
37
- import { entryProposalHandler, type EntryApplyAnswer } from '../utils/entry-proposal.js'
38
- import { holdAssistantAsk, peekAssistantAsk, settleAssistantAsk, subscribeAssistantAsk, takeAssistantAsk, type AssistantAsk } from '../utils/assistant-ask.js'
39
- import { selectionNote } from '../utils/assistant-selection.js'
40
- import { surfaceTransition } from '../utils/assistant-navigation.js'
41
-
42
- export const ASSISTANT_DOCK_VIEWPART = 'assistant-dock'
43
-
44
- const t = (key: string, defaultValue: string, options: Record<string, unknown> = {}) =>
45
- i18next.t(`ai-assistant.dock.${key}`, { defaultValue, ...options })
46
-
47
- /* Pressing a data entry card asks the server to enter the rows it stored - the screen sends none (design/ai/data-entry.md §4). */
48
- setEntryProposalHandler(
49
- entryProposalHandler(
50
- async (sessionId, proposalKey, reviewedHash) => {
51
- const result = await client.mutate({
52
- mutation: gql`
53
- mutation ($id: String!, $key: String!, $reviewed: String) {
54
- applyEntryProposal(sessionId: $id, proposalKey: $key, reviewedHash: $reviewed)
55
- }
56
- `,
57
- variables: { id: sessionId, key: proposalKey, reviewed: reviewedHash ?? null }
58
- })
59
- if (result.errors?.length) throw new Error(result.errors[0].message)
60
- return result.data?.applyEntryProposal as EntryApplyAnswer
61
- },
62
- (key, options) => String(i18next.t(key, options))
63
- )
64
- )
65
-
66
- /* The page on screen and the shown 360 - what an applied card's records may be shown on. */
67
- const APPLIED_SCREENS: AppliedScreensDeps = {
68
- page: () => {
69
- const route = (store.getState() as any)?.route ?? {}
70
- return { name: route.page, element: route.activePage }
71
- },
72
- refresh360: refreshEntity360
73
- }
74
-
75
- const MODE_QUERY = gql`
76
- query ($subject: String!) {
77
- assistantModeFor(subject: $subject) {
78
- kind
79
- label
80
- }
81
- }
82
- `
83
-
84
- /** The one conversation for what the screen shows (design/ai/screen-pattern.md §3). */
85
- async function modeFor(subject: string): Promise<{ kind: string; label?: string } | null> {
86
- const response = await client.query({ query: MODE_QUERY, variables: { subject }, fetchPolicy: 'network-only' })
87
- if (response.errors?.length) throw new Error(response.errors[0].message)
88
- return response.data?.assistantModeFor ?? null
89
- }
90
-
91
- /**
92
- * The AI dock - the same in every operato application (design/ai/shared-dock.md).
93
- *
94
- * ── What is here and what is not ────────────────────────────────────────────────
95
- * here where it stands, whether an AI answers, which surface and anchor, which conversation (mode),
96
- * sessions and their management, unread, proposals and their outcome, asks from other screens
97
- * the app what its screens show (surfaces, assistant-surface.ts), how its proposal kinds apply
98
- * (assistant-proposals.ts), and on the server its modes and tools
99
- *
100
- * Nothing in this file names an application or a proposal kind. A behaviour one app needs and another does
101
- * not is a surface field or a handler, never a branch here.
102
- */
103
- @customElement('ox-assistant-dock')
104
- export class AssistantDock extends localize(i18next)(LitElement) {
105
- static styles = [
106
- ScrollbarStyles,
107
- css`
108
- :host {
109
- display: flex;
110
- flex-direction: column;
111
- width: 420px;
112
- max-width: 100vw;
113
- box-sizing: border-box;
114
- height: 100%;
115
- min-height: 0;
116
- background: var(--md-sys-color-surface-container-lowest);
117
- border-left: 1px solid var(--md-sys-color-outline-variant);
118
- color: var(--md-sys-color-on-surface);
119
- font-size: 13px;
120
- }
121
-
122
- /*
123
- * The dock opens in one place on every screen and takes its room beside the page, so it covers no page's controls
124
- * and no screen needs its own exception (2026-10-12). Only a screen too narrow to share floats it over the page.
125
- * The DOM stays - the chat does not reconnect.
126
- */
127
- @media (max-width: 1023.98px) {
128
- :host {
129
- position: fixed;
130
- inset: 0 0 0 auto;
131
- height: 100vh;
132
- height: 100dvh;
133
- z-index: 10;
134
- box-shadow: var(--md-sys-elevation-shadow-3, -4px 0 16px rgb(0 0 0 / 20%));
135
- }
136
- }
137
-
138
- @media (max-width: 599.98px) {
139
- :host {
140
- width: 100vw;
141
- }
142
- }
143
-
144
- .scope {
145
- display: flex;
146
- align-items: center;
147
- gap: 6px;
148
- min-height: 40px;
149
- padding: 5px 8px;
150
- border-bottom: 1px solid var(--md-sys-color-outline-variant);
151
- }
152
-
153
- .scope > md-icon {
154
- --md-icon-size: 18px;
155
- flex: none;
156
- color: var(--md-sys-color-primary);
157
- }
158
-
159
- .what {
160
- display: grid;
161
- flex: 1;
162
- min-width: 0;
163
- font-size: 12px;
164
- font-weight: 650;
165
- line-height: 1.25;
166
- }
167
-
168
- .what span {
169
- overflow: hidden;
170
- text-overflow: ellipsis;
171
- white-space: nowrap;
172
- }
173
-
174
- .detail {
175
- color: var(--md-sys-color-on-surface-variant);
176
- font-size: 10.5px;
177
- font-weight: 400;
178
- }
179
-
180
- .sbtn {
181
- display: inline-flex;
182
- align-items: center;
183
- flex: none;
184
- padding: 4px;
185
- border: none;
186
- border-radius: 8px;
187
- background: none;
188
- color: var(--md-sys-color-on-surface-variant);
189
- cursor: pointer;
190
- }
191
-
192
- .sbtn:hover {
193
- background: var(--md-sys-color-surface-container-high);
194
- color: var(--md-sys-color-on-surface);
195
- }
196
-
197
- .sbtn md-icon {
198
- --md-icon-size: 18px;
199
- }
200
-
201
- /*
202
- * An open conversation is read by everyone in the domain - the dock says so on every screen of it, not
203
- * only in the list (2026-09-30: open and private were one grey word apart, and an owner's question about
204
- * the books sat in every employee's list). A private one draws nothing extra: it is the default.
205
- */
206
- /*
207
- * One warning colour in every application (2026-09-30, product owner): the theme's tertiary was a pale
208
- * lavender in figure and something else in each app, so "everyone reads this" was as loud as the theme
209
- * happened to be. Amber with near-black ink reads on light and dark themes alike - ink on amber 8.2:1, the edge 3.3:1 on white and 5.1:1 on a dark surface.
210
- */
211
- :host {
212
- --assistant-open-edge: #c47f00;
213
- --assistant-open-surface: #f2b01e;
214
- --assistant-open-ink: #2e2100;
215
- }
216
-
217
- :host([audience='open']) {
218
- border-left: 4px solid var(--assistant-open-edge);
219
- }
220
-
221
- .audience {
222
- display: flex;
223
- align-items: center;
224
- gap: 6px;
225
- flex: none;
226
- padding: 6px 10px;
227
- background: var(--assistant-open-surface);
228
- color: var(--assistant-open-ink);
229
- border-bottom: 1px solid var(--assistant-open-edge);
230
- font-size: 12px;
231
- font-weight: 600;
232
- line-height: 1.35;
233
- }
234
-
235
- .audience md-icon {
236
- --md-icon-size: 16px;
237
- flex: none;
238
- }
239
-
240
- ox-assistant-session-toolbar {
241
- flex: none;
242
- min-width: 0;
243
- padding: 3px 8px;
244
- border-bottom: 1px solid var(--md-sys-color-outline-variant);
245
- --border-color: var(--md-sys-color-outline-variant);
246
- --main-section-background-color: var(--md-sys-color-surface-container);
247
- --primary-color: var(--md-sys-color-primary);
248
- font: inherit;
249
- font-size: 12px;
250
- }
251
-
252
- ox-assistant-chat,
253
- ox-assistant-session-manager {
254
- flex: 1;
255
- min-height: 0;
256
- }
257
-
258
- /* No conversation could stand - say what stopped it, never an empty panel. */
259
- .stuck {
260
- margin: auto;
261
- padding: 20px;
262
- text-align: center;
263
- line-height: 1.7;
264
- color: var(--md-sys-color-on-surface-variant);
265
- }
266
-
267
- .stuck .sbtn {
268
- margin-top: 6px;
269
- gap: 4px;
270
- font: inherit;
271
- }
272
-
273
- .next-step {
274
- display: flex;
275
- align-items: center;
276
- justify-content: space-between;
277
- gap: 10px;
278
- padding: 8px 12px;
279
- border-bottom: 1px solid var(--md-sys-color-outline-variant);
280
- background: var(--md-sys-color-surface-container-low);
281
- color: var(--md-sys-color-on-surface-variant);
282
- font-size: 12px;
283
- line-height: 1.4;
284
- }
285
-
286
- .next-step a {
287
- display: inline-flex;
288
- align-items: center;
289
- gap: 3px;
290
- flex: none;
291
- color: var(--md-sys-color-primary);
292
- font-weight: 650;
293
- text-decoration: none;
294
- }
295
-
296
- .next-step a:hover { text-decoration: underline; }
297
- .next-step md-icon { --md-icon-size: 16px; }
298
- ox-assistant-chat[hidden] { display: none; }
299
- `
300
- ]
301
-
302
- /** The viewpart this dock lives in - for closing it. */
303
- @property({ type: String }) viewpart = ASSISTANT_DOCK_VIEWPART
304
-
305
- @state() private capability: AiCapability = 'unknown'
306
- @state() private asked = false
307
- @state() private surface?: AssistantSurface
308
- @state() private anchor?: AnchorResult
309
- @state() private kind = ''
310
- /** kind → its label, for the manager's rows. */
311
- @state() private sessions: AssistantSession[] = []
312
- @state() private sessionId = ''
313
- @state() private loading = false
314
- @state() private failure = ''
315
- @state() private showingHistory = false
316
- @state() private conversationView = 0
317
- @state() private asking?: { ask?: string; draft?: string; to?: { id: string; name: string }; requestId: string }
318
- private openedIdentity = ''
319
-
320
- private app = new AppController(this)
321
- private revision = 0
322
- /** What the conversation was opened for - a send is refused when the screen moved on. */
323
- private openedFor = ''
324
- private unsubscribers: (() => void)[] = []
325
- private controller = new AssistantSessionController(
326
- assistantSessionTransport,
327
- next => {
328
- if (next.sessionId !== this.sessionId) {
329
- setOpenSession(next.sessionId)
330
- this.surface?.sessionChanged?.(next.sessionId)
331
- }
332
- this.sessions = next.sessions
333
- this.sessionId = next.sessionId
334
- this.loading = next.loading
335
- this.failure = next.error
336
- },
337
- { getItem: key => sessionStorage.getItem(key), setItem: (key, value) => sessionStorage.setItem(key, value) },
338
- { lazy: true }
339
- )
340
-
341
- private onStartNewSession = () => void this.newConversation()
342
-
343
-
344
- /* A card asks for a page of this application - the AI 작업 패널. The dock stays open beside it. */
345
- private onOpenPage = (event: CustomEvent) => {
346
- const href = event.detail?.href
347
- if (typeof href === 'string' && href) navigate(href)
348
- }
349
-
350
- /** Who reads the open conversation - absent until the list or the create answer says. */
351
- private get audience(): string | undefined {
352
- return this.sessions.find(session => session.id === this.sessionId)?.visibility || undefined
353
- }
354
-
355
- protected updated(changed: Map<PropertyKey, unknown>) {
356
- super.updated?.(changed as any)
357
- const audience = !this.showingHistory && this.audience === 'open' ? 'open' : null
358
- if (audience) this.setAttribute('audience', audience)
359
- else this.removeAttribute('audience')
360
- }
361
-
362
- /* Whether the left menu was folded by this dock's opening - only then does closing open it again. */
363
- private menuFoldedByDock = false
364
-
365
- connectedCallback() {
366
- super.connectedCallback()
367
- this.menuFoldedByDock = foldForDock(findMenu())
368
- if (this.menuFoldedByDock) window.dispatchEvent(new Event('resize'))
369
- this.addEventListener('assistant-start-new-session', this.onStartNewSession)
370
- this.addEventListener('assistant-open-page', this.onOpenPage as EventListener)
371
- this.unsubscribers.push(
372
- subscribeAssistantSurface(() => this.follow()),
373
- store.subscribe(() => { if (this.openedIdentity !== this.identityKey()) this.follow() }),
374
- subscribeAssistantAsk(() => void this.takeAsk()),
375
- subscribeSessionActivity(activity => {
376
- /* A rename or a new conversation elsewhere on this anchor - the tabs read again. */
377
- if (activity.kind === 'meta' && isAnchor(this.anchor) && activity.anchorId === this.anchor.anchorId) void this.reloadSessions()
378
- })
379
- )
380
- if (!this.openedIdentity) return this.follow(true)
381
- /*
382
- * The same dock opened again - the aside bar takes it out while it is closed. The conversation and what was
383
- * being written in it are still here; only what moved while it was closed (the screen, the person) is followed.
384
- */
385
- setOpenSession(this.sessionId)
386
- this.follow()
387
- }
388
-
389
- /* Closing keeps the conversation: the dock comes back as it was left (design/ai/shared-dock.md §2-1, §2-7). */
390
- disconnectedCallback() {
391
- unfoldAfterDock(findMenu(), this.menuFoldedByDock)
392
- if (this.menuFoldedByDock) window.dispatchEvent(new Event('resize'))
393
- this.menuFoldedByDock = false
394
- this.removeEventListener('assistant-start-new-session', this.onStartNewSession)
395
- this.removeEventListener('assistant-open-page', this.onOpenPage as EventListener)
396
- this.unsubscribers.splice(0).forEach(unsubscribe => unsubscribe())
397
- clearTimeout(this.takeTimer)
398
- setOpenSession('')
399
- super.disconnectedCallback()
400
- }
401
-
402
- private scopeKey(surface: AssistantSurface | undefined) {
403
- return JSON.stringify([this.app.contextPath, surface?.key ?? ''])
404
- }
405
-
406
- private identityKey() {
407
- const user = (store.getState() as any).auth?.user
408
- return JSON.stringify([this.app.contextPath, user?.id || user?.email || ''])
409
- }
410
-
411
- private get navigationState() {
412
- return (this.renderRoot.querySelector('ox-assistant-chat') as any)?.navigationState ?? { busy: false, draft: false }
413
- }
414
-
415
- private async mayLeaveConversation(): Promise<boolean> {
416
- if (this.navigationState.busy) {
417
- notify({ level: 'info', message: t('wait-before-switch', 'Wait for the current response before changing conversations.') })
418
- return false
419
- }
420
- if (!this.navigationState.draft) return true
421
- const identity = this.identityKey()
422
- const accepted = await OxPrompt.open({
423
- type: 'warning', title: t('switch-title', 'Change conversation?'),
424
- text: t('switch-draft', 'Your unsent text and attachments will not move to the other conversation.'),
425
- confirmButton: { text: t('switch-confirm', 'Discard draft and switch') },
426
- cancelButton: { text: t('stay', 'Keep writing') }
427
- })
428
- return !!accepted && identity === this.identityKey()
429
- }
430
-
431
- private async requestSurface(surface: AssistantSurface | undefined) {
432
- if (!(await this.mayLeaveConversation())) return
433
- this.surface = surface
434
- await this.open()
435
- }
436
-
437
- /** The screen changed - a different surface or domain is a different conversation. */
438
- private follow(force = false) {
439
- const next = currentAssistantSurface()
440
- const transition = surfaceTransition({
441
- identityChanged: this.openedIdentity !== this.identityKey(),
442
- sameSubject: this.scopeKey(next) === this.openedFor,
443
- busy: this.navigationState.busy
444
- })
445
- if (!force && transition === 'refresh') {
446
- this.surface = next
447
- this.requestUpdate()
448
- return
449
- }
450
- if (!force && transition === 'wait') {
451
- /* The answer lands in the conversation it was asked in; then the dock follows the page. */
452
- this.followWhenIdle()
453
- return
454
- }
455
- if (transition !== 'reset') this.keepDraft()
456
- if (transition === 'reset') {
457
- this.asking = undefined
458
- this.capability = 'unknown'
459
- if (this.openedIdentity) {
460
- const dropped = takeAssistantAsk()
461
- /* Another account or domain - the request was not this one's to send; the screen is told. */
462
- if (dropped) settleAssistantAsk(dropped, { sent: false, reason: 'identity-changed' })
463
- }
464
- }
465
- this.surface = next
466
- void this.open()
467
- }
468
-
469
- private followTimer?: ReturnType<typeof setTimeout>
470
-
471
- private followWhenIdle() {
472
- clearTimeout(this.followTimer)
473
- this.followTimer = setTimeout(() => (this.navigationState.busy ? this.followWhenIdle() : this.follow()), 300)
474
- }
475
-
476
- /* What was being written, per subject - it goes back to its conversation when the page returns there. */
477
- private drafts = new Map<string, unknown>()
478
-
479
- private keepDraft() {
480
- const chat = this.renderRoot.querySelector('ox-assistant-chat') as any
481
- const draft = this.openedFor ? chat?.takeDraft?.() : undefined
482
- if (draft) this.drafts.set(this.openedFor!, draft)
483
- }
484
-
485
- private async restoreDraft() {
486
- const draft = this.openedFor ? this.drafts.get(this.openedFor) : undefined
487
- if (!draft) return
488
- await this.updateComplete
489
- const chat = this.renderRoot.querySelector('ox-assistant-chat') as any
490
- if (!chat?.restoreDraft) return
491
- this.drafts.delete(this.openedFor!)
492
- chat.restoreDraft(draft)
493
- }
494
-
495
- private async open(): Promise<void> {
496
- this.openedIdentity = this.identityKey()
497
- const ticket = ++this.revision
498
- this.conversationView++
499
- this.showingHistory = false
500
- void this.controller.open(undefined)
501
- this.loading = true
502
- this.failure = ''
503
- this.anchor = undefined
504
- this.openedFor = this.scopeKey(this.surface)
505
-
506
- try {
507
- if (this.capability !== 'configured') {
508
- this.capability = await readAiCapability()
509
- this.asked = true
510
- }
511
- if (ticket !== this.revision || this.capability !== 'configured') return
512
-
513
- const surface = this.surface
514
- if (!surface) return
515
-
516
- const anchor = await surface.anchor()
517
- if (ticket !== this.revision) return
518
- this.anchor = anchor
519
- if (!isAnchor(anchor)) return
520
-
521
- const mode = await modeFor(surface.subject)
522
- if (ticket !== this.revision) return
523
- this.kind = mode?.kind ?? ''
524
- if (!this.kind) {
525
- this.anchor = { stuck: 'no-conversation', message: t('no-conversation', 'there is no conversation for this screen.') }
526
- return
527
- }
528
-
529
- const user = (store.getState() as any).auth?.user
530
- const userId = user?.id || user?.email
531
- if (!userId) throw new Error(t('no-user', 'your sign-in could not be read. sign in again.'))
532
-
533
- await this.controller.open(this.target(userId, anchor))
534
- } catch (error) {
535
- if (ticket === this.revision) this.failure = (error as Error).message
536
- } finally {
537
- if (ticket === this.revision) {
538
- this.loading = false
539
- /*
540
- * The ask waiting is taken once the opening is done - takeAsk passes while loading, so taking it inside the
541
- * opening left it waiting for good: a card's 「AI로 고치기」 reopened this screen's conversation and was never sent
542
- * (2026-10-25). With no conversation possible here, it is answered now, not sent later somewhere else.
543
- */
544
- if (this.anchor) void this.takeAsk()
545
- /* What was being written on this subject before the page moved away comes back here. */
546
- void this.restoreDraft()
547
- }
548
- }
549
- }
550
-
551
- private target(userId: string, anchor: { anchorType: string; anchorId: string }): AssistantSessionTarget {
552
- /* The conversation kind is part of the key: two conversations on one anchor never share a session (ADR-0072 decision 3). */
553
- return { scope: JSON.stringify([this.app.contextPath, userId, this.kind]), anchorType: anchor.anchorType, anchorId: anchor.anchorId, kind: this.kind }
554
- }
555
-
556
- private async reloadSessions() {
557
- const target = this.controller.state.target
558
- if (target) await this.controller.open(target, true)
559
- }
560
-
561
- private async newConversation() {
562
- if (this.loading || !isAnchor(this.anchor)) return
563
- if (!(await this.mayLeaveConversation())) return
564
- this.showingHistory = false
565
- const revision = this.controller.state.revision
566
- await this.controller.reset()
567
- if (revision !== this.controller.state.revision) this.conversationView++
568
- }
569
-
570
- private async selectSession(id: string) {
571
- if (id !== this.sessionId && !(await this.mayLeaveConversation())) return
572
- this.showingHistory = false
573
- const previous = this.sessionId
574
- if (this.controller.select(id) && previous !== id) this.conversationView++
575
- }
576
-
577
- /* ── asks from other screens ────────────────────────────────────────────────────── */
578
-
579
- private async takeAsk() {
580
- if (this.loading || !this.anchor) return
581
- /* A request made on the screen with what was picked there (「AI와 작업」) has rules of its own (§2-11-1). */
582
- if (peekAssistantAsk()?.selection) return this.takeScreenRequest()
583
- /*
584
- * A request the person made on this screen is never dropped for what the dock is doing (2026-10-24: 「AI와 작업」
585
- * pressed again was thrown away because the input still held the first press's draft). An answer being written
586
- * finishes first, then the request is taken. Unsent words are asked about - the person keeps writing or lets them go.
587
- */
588
- if (this.navigationState.busy) {
589
- this.takeWhenIdle()
590
- return
591
- }
592
- if (this.navigationState.draft && !(await this.mayLeaveConversation())) {
593
- const waiting = takeAssistantAsk()
594
- if (waiting) notify({ level: 'info', message: t('ask-kept-current', 'The current conversation was kept. Switch to the intended subject before asking again.') })
595
- return
596
- }
597
- if (!isAnchor(this.anchor)) {
598
- /*
599
- A question is not sent later on its own, once some conversation happens to stand - by then the person is looking
600
- at something else. It is said now why it was not sent. A draft only fills the input, so it waits.
601
- */
602
- const waiting = takeAssistantAsk()
603
- if (!waiting) return
604
- if (waiting.ask) notify({ level: 'info', message: `${t('ask-needs-conversation', 'the question was not sent.')} ${this.anchor.message}` })
605
- else holdAssistantAsk(waiting)
606
- return
607
- }
608
- const ask: AssistantAsk | undefined = takeAssistantAsk()
609
- if (!ask) return
610
-
611
- /*
612
- * A request for one conversation - a to-do that came from it (ADR-0200 decision 3). It is listed on its subject's
613
- * screen; until the dock stands there the request waits, and the conversation is opened when it does.
614
- */
615
- if (ask.sessionId) {
616
- if (!this.sessions.some(one => one.id === ask.sessionId)) await this.reloadSessions()
617
- if (!this.controller.select(ask.sessionId)) return holdAssistantAsk(ask)
618
- this.conversationView++
619
- this.asking = ask.ask || ask.draft || ask.to ? { ask: ask.ask, draft: ask.draft, to: ask.to, requestId: String(Date.now()) } : undefined
620
- settleAssistantAsk(ask, { sent: true })
621
- return
622
- }
623
-
624
- if (!ask.continueCurrent && (ask.name || ask.context || ask.transcript?.length)) {
625
- const id = await this.startCarried(ask).catch(() => {
626
- notify({ level: 'error', message: t('carry-failed', 'The selected context could not be attached. Nothing was sent. Try again from the original screen.') })
627
- return undefined
628
- })
629
- // Never send a context-dependent request into the previous conversation after a failed handoff.
630
- if (!id) return
631
- if (id) {
632
- await this.reloadSessions()
633
- this.controller.select(id)
634
- }
635
- } else if (!ask.continueCurrent) {
636
- await this.newConversation()
637
- }
638
- this.conversationView++
639
- this.asking = { ask: ask.ask, draft: ask.draft, requestId: String(Date.now()) }
640
- }
641
-
642
- private takeTimer?: ReturnType<typeof setTimeout>
643
-
644
- /**
645
- * This person's own conversation on this screen - the most recent they sit in; none, a new one made on sending. What
646
- * they were writing comes along.
647
- */
648
- private async goToOwnConversation() {
649
- const kept = (this.renderRoot.querySelector('ox-assistant-chat') as any)?.takeDraft?.()
650
- const own = this.sessions.find(one => one.participant !== false && one.id !== this.sessionId)
651
- const revision = this.controller.state.revision
652
- if (own) {
653
- if (this.controller.select(own.id)) this.conversationView++
654
- } else {
655
- await this.controller.reset()
656
- if (revision !== this.controller.state.revision) this.conversationView++
657
- }
658
- await this.updateComplete
659
- if (kept) (this.renderRoot.querySelector('ox-assistant-chat') as any)?.restoreDraft?.(kept)
660
- }
661
-
662
- /*
663
- * ── A screen request (「AI와 작업」) - design/ai/shared-dock.md §2-11-1 ─────────────────────────────────────────
664
- * The user (2026-10-24): 「"AI와 작업" 기능이 unstable 하다. 작동 방식을 신뢰할 수 있도록 새로운 세션을 여는지, 기존 세션을
665
- * 활용하는지 등등을 명확하게 하라.」 One way, every time:
666
- * 1. this screen's conversation - the one the dock opens for this screen; none yet, one is made on sending. The dock
667
- * showing another screen's conversation, or its list, comes back here. Never a new conversation per press.
668
- * 2. the selection at the press is noted for that turn - a line the person reads, the ids for the model; a later
669
- * press's note replaces it (SELECTION_RULE).
670
- * 3. the request is sent, always - never left as a draft.
671
- * 4. what the person was writing in the box is set aside while the request goes, and put back.
672
- * 5. not sent: said in a notice, and the screen is told so it keeps the request on its bar.
673
- * 6. an answer being written: said, and the request goes right after it - never dropped.
674
- */
675
- private waitingNoticeFor?: AssistantAsk
676
-
677
- private async takeScreenRequest() {
678
- const waiting = peekAssistantAsk()
679
- if (!waiting?.selection) return
680
- if (this.navigationState.busy) {
681
- if (this.waitingNoticeFor !== waiting) {
682
- this.waitingNoticeFor = waiting
683
- notify({ level: 'info', message: t('screen-request-waits', 'An answer is being written - your request goes right after it.') })
684
- }
685
- this.takeWhenIdle()
686
- return
687
- }
688
- const here = currentAssistantSurface()
689
- if (this.scopeKey(here) !== this.openedFor || this.openedIdentity !== this.identityKey()) {
690
- /* Another screen's conversation is open - back to this screen's; open() takes the request again when it stands. */
691
- this.keepDraft()
692
- this.surface = here
693
- await this.open()
694
- return
695
- }
696
- const ask = takeAssistantAsk()!
697
- this.waitingNoticeFor = undefined
698
- const fail = (reason: string) => {
699
- notify({ level: 'error', message: reason })
700
- settleAssistantAsk(ask, { sent: false, reason })
701
- }
702
- if (!isAnchor(this.anchor)) return fail(this.anchor?.message || t('no-conversation', 'there is no conversation for this screen.'))
703
- this.showingHistory = false
704
- /*
705
- * The dock opens the first conversation it can read when this person has none here yet - someone else's open one,
706
- * found 2026-10-24: the request went into Admin's public 「회사가치를 제시해보라」. A screen request is the person's own
707
- * work: a conversation they do not sit in is not this screen's conversation for them. Their own on this screen is
708
- * used - the most recent one; none yet, one is started (made on sending).
709
- */
710
- if (this.sessions.find(one => one.id === this.sessionId)?.participant === false) await this.goToOwnConversation()
711
- await this.updateComplete
712
- const chat = this.renderRoot.querySelector('ox-assistant-chat') as any
713
- if (!chat?.sendScreenRequest) return fail(t('screen-request-not-ready', 'The conversation is not ready yet. Try again in a moment.'))
714
- const request = ask.ask?.trim() || t('screen-request-default', 'Read the selected records and suggest what can be done with them now.')
715
- const outcome = await chat.sendScreenRequest(request, selectionNote(ask.selection!, t))
716
- if (!outcome?.sent) return fail(outcome?.reason || t('screen-request-failed', 'The request was not sent. Try again.'))
717
- settleAssistantAsk(ask, { sent: true })
718
- }
719
-
720
- /** The request waits (it is still pending) while an answer is written, then is taken. */
721
- private takeWhenIdle() {
722
- clearTimeout(this.takeTimer)
723
- this.takeTimer = setTimeout(() => (this.navigationState.busy ? this.takeWhenIdle() : void this.takeAsk()), 300)
724
- }
725
-
726
- /** A new conversation carrying what the other screen had - its name, a note, earlier turns. */
727
- private async startCarried(ask: AssistantAsk): Promise<string | undefined> {
728
- const anchor = this.anchor as { anchorType: string; anchorId: string }
729
- const created = await client.mutate({
730
- mutation: gql`
731
- mutation ($t: String!, $i: String!, $n: String) {
732
- createAISession(anchorType: $t, anchorId: $i, name: $n) {
733
- id
734
- }
735
- }
736
- `,
737
- variables: { t: anchor.anchorType, i: anchor.anchorId, n: ask.name || null }
738
- })
739
- if (created.errors?.length) throw new Error(created.errors[0].message)
740
- const id = created.data?.createAISession?.id
741
- if (!id) throw new Error('Session was not created')
742
- if (ask.context) {
743
- const attached = await client.mutate({
744
- mutation: gql`
745
- mutation ($id: String!, $c: String!) {
746
- appendSessionNote(sessionId: $id, content: $c)
747
- }
748
- `,
749
- variables: { id, c: ask.context }
750
- })
751
- if (attached.errors?.length) throw new Error(attached.errors[0].message)
752
- }
753
- if (ask.transcript?.length) {
754
- await client.mutate({
755
- mutation: gql`
756
- mutation ($id: String!, $turns: JSON!) {
757
- appendSessionTurns(sessionId: $id, turns: $turns)
758
- }
759
- `,
760
- variables: { id, turns: ask.transcript.map(turn => ({ role: turn.role === 'ai' ? 'assistant' : 'user', content: turn.content })) }
761
- })
762
- }
763
- return id
764
- }
765
-
766
- /* ── proposals ───────────────────────────────────────────────────────────────────── */
767
-
768
- private proposalContext(sessionId?: string): ProposalContext {
769
- const identity = this.identityKey()
770
- const scope = this.openedFor
771
- return {
772
- sessionId,
773
- surface: this.surface,
774
- confirm: async ({ title, text, confirmText, cancelText, type }) =>
775
- !!(await OxPrompt.open({
776
- type: type ?? 'warning',
777
- title,
778
- text,
779
- confirmButton: { text: confirmText ?? t('confirm', 'OK') },
780
- cancelButton: { text: cancelText ?? t('cancel', 'Cancel') }
781
- })) && identity === this.identityKey() && scope === this.scopeKey(currentAssistantSurface()),
782
- notify: (level, message) => notify({ level, message })
783
- }
784
- }
785
-
786
- private async report(sessionId: string | undefined, proposalKey: string | undefined, outcome: ProposalOutcome) {
787
- if (!sessionId || !proposalKey) return
788
- try {
789
- await client.mutate({
790
- mutation: gql`
791
- mutation ($id: String!, $key: String!, $outcome: JSON!) {
792
- reportProposalOutcome(sessionId: $id, proposalKey: $key, outcome: $outcome)
793
- }
794
- `,
795
- variables: { id: sessionId, key: proposalKey, outcome }
796
- })
797
- } catch {
798
- /* the card then says it heard nothing - never "done" */
799
- }
800
- }
801
-
802
- /** Every proposal ends in exactly one reported outcome - a kind nobody handles is `unavailable`. */
803
- private onProposal = async (event: CustomEvent) => {
804
- const { proposal, sessionId, proposalKey } = event.detail ?? {}
805
- const outcome: ProposalOutcome = this.openedFor !== this.scopeKey(currentAssistantSurface()) || this.openedIdentity !== this.identityKey()
806
- ? { verdict: 'unavailable', errorCode: 'conversation-screen-changed', note: t('return-to-subject', 'Return to the conversation subject before applying this proposal.') }
807
- : await runProposal(proposal, this.proposalContext(sessionId))
808
- if (outcome.verdict === 'unavailable' && outcome.errorCode === 'unknown-proposal-kind') {
809
- notify({ level: 'error', message: t('proposal-not-runnable', 'this proposal cannot be run on this screen.') })
810
- }
811
- const { records, ...reported } = outcome
812
- await this.report(sessionId, proposalKey, reported)
813
- /* What the handler did, in the person's words, stays in the conversation - what was created, why it did not run. */
814
- if (outcome.note && sessionId) await this.appendNote(sessionId, outcome.note)
815
- /* The list or 360 behind the dock shows what went in, without the person refreshing it. */
816
- if (outcome.verdict === 'accepted' && (outcome.applied ?? 1) > 0)
817
- void refreshAppliedScreens(proposal, records, APPLIED_SCREENS).then(kept => {
818
- if (kept) notify({ level: 'info', message: t('screen-kept-edits', 'the list was not read again - it has unsaved edits. save them, then refresh it to see what went in.') })
819
- })
820
- }
821
-
822
- /**
823
- * "Check result" - asks the surface what became of a requested proposal and reports only what it learns.
824
- * Nothing is run: a lost answer never turns into a second application (ADR-0097 Q-D4 ④).
825
- */
826
- private onProposalCheck = async (event: CustomEvent) => {
827
- const { proposal, sessionId, proposalKey } = event.detail ?? {}
828
- const ask = this.surface?.proposalOutcome
829
- if (!ask) {
830
- notify({ level: 'info', message: t('proposal-result-uncheckable', 'this screen cannot check that result. open the screen where it was applied.') })
831
- return
832
- }
833
-
834
- let outcome: ProposalOutcome | undefined
835
- try {
836
- outcome = await ask.call(this.surface, proposalKey, proposal)
837
- } catch {
838
- outcome = undefined
839
- }
840
- if (!outcome?.verdict) {
841
- notify({ level: 'info', message: t('proposal-result-unknown', 'the result is still unknown. it was not applied again.') })
842
- return
843
- }
844
-
845
- await this.report(sessionId, proposalKey, outcome)
846
- if (outcome.note && sessionId) await this.appendNote(sessionId, outcome.note)
847
- }
848
-
849
- private async appendNote(sessionId: string, note: string) {
850
- try {
851
- await client.mutate({
852
- mutation: gql`
853
- mutation ($id: String!, $c: String!) {
854
- appendSessionNote(sessionId: $id, content: $c)
855
- }
856
- `,
857
- variables: { id: sessionId, c: note }
858
- })
859
- } catch {
860
- /* the outcome is already reported; a lost note is not a lost outcome */
861
- }
862
- }
863
-
864
- /* ── board surfaces: the chat's scene edits land on the open board ───────────────── */
865
-
866
- private onScenePatch = async (event: CustomEvent) => {
867
- if (!this.mayApplyOnScreen()) return
868
- const board = this.surface?.board
869
- if (!board) return
870
- const result = await board.applyPatch(event.detail)
871
- if (result?.missed) notify({ level: 'info', message: t('patch-missed', '{missed} of the changes could not be applied.', { missed: result.missed }) })
872
- }
873
-
874
- private mayApplyOnScreen() {
875
- if (this.openedFor === this.scopeKey(currentAssistantSurface()) && this.openedIdentity === this.identityKey()) return true
876
- notify({ level: 'info', message: t('return-to-subject', 'Return to the conversation subject before applying this proposal.') })
877
- return false
878
- }
879
-
880
- private onBoardRevert = (event: CustomEvent) => { if (this.mayApplyOnScreen()) void this.surface?.board?.revertPatch?.(event.detail?.patchId) }
881
-
882
- private onSceneAction = (event: CustomEvent) => { if (this.mayApplyOnScreen()) void this.surface?.board?.applyAction?.(event.detail) }
883
-
884
- /* ── drawing ─────────────────────────────────────────────────────────────────────── */
885
-
886
- private stuckLine(): string {
887
- if (this.capability === 'not-configured') return t('not-configured', 'no AI is set up for this site. an administrator can set one up in the AI settings.')
888
- if (this.capability === 'unknown' && this.asked && !this.loading && !this.failure) return t('capability-unknown', 'whether AI is set up here could not be read.')
889
- if (this.capability === 'configured' && !this.surface && !this.loading) return t('no-surface', 'this screen has no conversation.')
890
- const anchor = this.anchor
891
- if (anchor && !isAnchor(anchor)) return anchor.message
892
- return ''
893
- }
894
-
895
- private header(): TemplateResult {
896
- const surface = this.surface
897
- const home = assistantHomeSurface()
898
- const ready = this.capability === 'configured' && isAnchor(this.anchor)
899
- return html`
900
- <div class="scope">
901
- <md-icon>${surface?.icon || 'forum'}</md-icon>
902
- <span class="what">
903
- <span>${surface?.label() || t('title', 'Assistant')}</span>
904
- ${surface?.detail ? html`<span class="detail">${surface.detail()}</span>` : nothing}
905
- </span>
906
- ${home && surface && home !== surface
907
- ? html`<button class="sbtn" title=${t('to-home', "back to this application's conversation")} @click=${() => this.useSurface(home)}>
908
- <md-icon>home</md-icon>
909
- </button>`
910
- : nothing}
911
- ${ready && this.showingHistory
912
- ? html`<button
913
- class="sbtn"
914
- title=${this.showingHistory ? t('back-to-conversation', 'back to the conversation') : t('conversations', 'conversations')}
915
- @click=${() => (this.showingHistory = !this.showingHistory)}
916
- >
917
- <md-icon>arrow_back</md-icon>${t('back-to-conversation', 'back to the conversation')}
918
- </button>`
919
- : nothing}
920
- <button class="sbtn" title=${t('rebind', 'follow this screen again')} @click=${() => this.requestSurface(currentAssistantSurface())}>
921
- <md-icon>refresh</md-icon>
922
- </button>
923
- <button class="sbtn" title=${t('close', 'close')} @click=${() => closeOverlay(this.viewpart)}>
924
- <md-icon>close</md-icon>
925
- </button>
926
- </div>
927
- `
928
- }
929
-
930
- /** The home button: talk about the application instead of this screen, until the screen changes. */
931
- private useSurface(surface: AssistantSurface) {
932
- void this.requestSurface(surface)
933
- }
934
-
935
- render(): TemplateResult {
936
- const anchor = this.anchor
937
- const ready = this.capability === 'configured' && isAnchor(anchor)
938
- const stuck = this.stuckLine()
939
- const surface = this.surface
940
- const openedFor = this.openedFor
941
- const board = surface?.board
942
-
943
- const mode: AssistantMode | undefined = ready ? { kind: this.kind, target: (anchor as any).anchorId, hostContext: {} } : undefined
944
-
945
- return html`
946
- ${this.header()}
947
- ${surface?.nextStep ? html`<div class="next-step" role="status">
948
- <span>${surface.nextStep.description?.() || ''}</span>
949
- <a href=${surface.nextStep.href}>${surface.nextStep.label()}<md-icon>arrow_forward</md-icon></a>
950
- </div>` : nothing}
951
-
952
- ${ready && this.showingHistory
953
- ? html`<ox-assistant-session-manager
954
- .anchorType=${(anchor as any).anchorType}
955
- .anchorId=${(anchor as any).anchorId}
956
- .sessionId=${this.sessionId}
957
- .kind=${this.kind}
958
- @assistant-session-select=${(event: CustomEvent) => this.selectSession(event.detail.sessionId)}
959
- @assistant-session-reset=${() => this.newConversation()}
960
- @assistant-session-changed=${() => this.reloadSessions()}
961
- ></ox-assistant-session-manager>`
962
- : nothing}
963
- ${ready && !this.showingHistory
964
- ? html`<ox-assistant-session-toolbar
965
- .sessions=${this.sessions}
966
- .sessionId=${this.sessionId}
967
- .loading=${this.loading}
968
- .error=${this.failure}
969
- historyEnabled
970
- singleConversation
971
- @assistant-session-select=${(event: CustomEvent) => this.selectSession(event.detail.sessionId)}
972
- @assistant-session-reset=${() => this.newConversation()}
973
- @assistant-session-history=${() => (this.showingHistory = true)}
974
- @assistant-session-retry=${() => this.open()}
975
- ></ox-assistant-session-toolbar>`
976
- : nothing}
977
- ${ready && !this.showingHistory && this.audience === 'open'
978
- ? html`<div class="audience" role="status">
979
- <md-icon>public</md-icon>
980
- <span>${t('audience-open-band', 'Public conversation - everyone in this domain can read and write here.')}</span>
981
- </div>`
982
- : nothing}
983
- ${ready && !this.loading && !this.failure
984
- ? keyed(
985
- this.conversationView,
986
- html`<ox-assistant-chat
987
- ?hidden=${this.showingHistory}
988
- .sessionId=${this.sessionId}
989
- .visibility=${this.audience}
990
- .prepareSession=${(adopt: (id: string) => void) => this.controller.prepareSession(adopt)}
991
- .contextProvider=${() => {
992
- /* The screen moved on between writing and sending - do not answer about the old one. */
993
- if (openedFor !== this.scopeKey(currentAssistantSurface()) || this.openedIdentity !== this.identityKey()) throw new Error(t('return-to-subject', 'Return to the conversation subject before applying this proposal.'))
994
- return { hostContext: surface?.hostContext?.() ?? {} }
995
- }}
996
- .mode=${mode}
997
- .subject=${surface?.subject}
998
- .chatEndpoint=${board?.chatEndpoint ?? 'assistantChat'}
999
- ?board-tools=${!!board}
1000
- .currentBoard=${board?.currentBoard?.()}
1001
- .boardProvider=${board?.boardProvider}
1002
- .selectedRefids=${board?.selectedRefids?.() ?? []}
1003
- .knownTypes=${board?.knownTypes?.()}
1004
- .categories=${board?.categories?.()}
1005
- .componentSchemas=${board?.componentSchemas?.()}
1006
- .searchProvider=${board?.searchProvider}
1007
- .autoAsk=${this.asking?.ask}
1008
- .autoAskRequestId=${this.asking?.requestId}
1009
- .draft=${this.asking?.draft}
1010
- .draftTo=${this.asking?.to}
1011
- .draftRequestId=${this.asking?.requestId}
1012
- @assistant-proposal-execute=${this.onProposal}
1013
- @assistant-proposal-check=${this.onProposalCheck}
1014
- @scene-edit-patch=${this.onScenePatch}
1015
- @board-edit-revert=${this.onBoardRevert}
1016
- @scene-action-execute=${this.onSceneAction}
1017
- ></ox-assistant-chat>`
1018
- )
1019
- : nothing}
1020
- ${stuck
1021
- ? html`<div class="stuck">
1022
- ${stuck}
1023
- ${this.capability === 'unknown'
1024
- ? html`<div><button class="sbtn" @click=${() => this.open()}><md-icon>refresh</md-icon>${t('retry', 'try again')}</button></div>`
1025
- : nothing}
1026
- </div>`
1027
- : nothing}
1028
- ${this.failure && !stuck && !ready
1029
- ? html`<div class="stuck">
1030
- ${this.failure}
1031
- <div><button class="sbtn" @click=${() => this.open()}><md-icon>refresh</md-icon>${t('retry', 'try again')}</button></div>
1032
- </div>`
1033
- : nothing}
1034
- `
1035
- }
1036
- }