@skillcdn/console 0.4.7 → 0.5.1

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 (599) hide show
  1. package/README.md +74 -14
  2. package/SKILLCDN.md +5 -3
  3. package/dist/agent-page.d.ts +44 -0
  4. package/dist/agent-page.d.ts.map +1 -0
  5. package/dist/agent-page.js +415 -0
  6. package/dist/agent-page.js.map +1 -0
  7. package/dist/agent-stream.d.ts +52 -0
  8. package/dist/agent-stream.d.ts.map +1 -0
  9. package/dist/agent-stream.js +155 -0
  10. package/dist/agent-stream.js.map +1 -0
  11. package/dist/api.d.ts +12 -6
  12. package/dist/api.d.ts.map +1 -1
  13. package/dist/api.js +11 -5
  14. package/dist/api.js.map +1 -1
  15. package/dist/avatar.d.ts +137 -0
  16. package/dist/avatar.d.ts.map +1 -0
  17. package/dist/avatar.js +1216 -0
  18. package/dist/avatar.js.map +1 -0
  19. package/dist/charts.d.ts +103 -0
  20. package/dist/charts.d.ts.map +1 -0
  21. package/dist/charts.js +182 -0
  22. package/dist/charts.js.map +1 -0
  23. package/dist/cli/cli.d.ts +39 -1
  24. package/dist/cli/cli.d.ts.map +1 -1
  25. package/dist/cli/cli.js +2424 -296
  26. package/dist/cli/cli.js.map +1 -1
  27. package/dist/cli/command-words.d.ts +20 -0
  28. package/dist/cli/command-words.d.ts.map +1 -0
  29. package/dist/cli/command-words.js +51 -0
  30. package/dist/cli/command-words.js.map +1 -0
  31. package/dist/cli/credentials.d.ts +59 -5
  32. package/dist/cli/credentials.d.ts.map +1 -1
  33. package/dist/cli/credentials.js +128 -16
  34. package/dist/cli/credentials.js.map +1 -1
  35. package/dist/cli/directory.d.ts +19 -4
  36. package/dist/cli/directory.d.ts.map +1 -1
  37. package/dist/cli/directory.js +16 -8
  38. package/dist/cli/directory.js.map +1 -1
  39. package/dist/cli/format.d.ts +91 -8
  40. package/dist/cli/format.d.ts.map +1 -1
  41. package/dist/cli/format.js +386 -57
  42. package/dist/cli/format.js.map +1 -1
  43. package/dist/cli/help.d.ts +13 -4
  44. package/dist/cli/help.d.ts.map +1 -1
  45. package/dist/cli/help.js +202 -62
  46. package/dist/cli/help.js.map +1 -1
  47. package/dist/cli/main.js +94 -0
  48. package/dist/cli/main.js.map +1 -1
  49. package/dist/cli/pack.d.ts +69 -36
  50. package/dist/cli/pack.d.ts.map +1 -1
  51. package/dist/cli/pack.js +241 -188
  52. package/dist/cli/pack.js.map +1 -1
  53. package/dist/cli/plugin-check.d.ts +42 -0
  54. package/dist/cli/plugin-check.d.ts.map +1 -1
  55. package/dist/cli/plugin-check.js +221 -36
  56. package/dist/cli/plugin-check.js.map +1 -1
  57. package/dist/cli/plugin-cli.d.ts +6 -1
  58. package/dist/cli/plugin-cli.d.ts.map +1 -1
  59. package/dist/cli/plugin-cli.js +21 -4
  60. package/dist/cli/plugin-cli.js.map +1 -1
  61. package/dist/cli/plugin-main.js +1 -0
  62. package/dist/cli/plugin-main.js.map +1 -1
  63. package/dist/cli/runner-host.d.ts +36 -0
  64. package/dist/cli/runner-host.d.ts.map +1 -0
  65. package/dist/cli/runner-host.js +154 -0
  66. package/dist/cli/runner-host.js.map +1 -0
  67. package/dist/cli/serve.d.ts +33 -1
  68. package/dist/cli/serve.d.ts.map +1 -1
  69. package/dist/cli/serve.js +275 -6
  70. package/dist/cli/serve.js.map +1 -1
  71. package/dist/cli/setup-machine.d.ts +36 -0
  72. package/dist/cli/setup-machine.d.ts.map +1 -0
  73. package/dist/cli/setup-machine.js +109 -0
  74. package/dist/cli/setup-machine.js.map +1 -0
  75. package/dist/client.d.ts +189 -10
  76. package/dist/client.d.ts.map +1 -1
  77. package/dist/client.js +192 -57
  78. package/dist/client.js.map +1 -1
  79. package/dist/compat.d.ts +1 -1
  80. package/dist/compat.js +2 -2
  81. package/dist/components/agent-page.d.ts +384 -0
  82. package/dist/components/agent-page.d.ts.map +1 -0
  83. package/dist/components/agent-page.js +985 -0
  84. package/dist/components/agent-page.js.map +1 -0
  85. package/dist/components/agents.d.ts +102 -0
  86. package/dist/components/agents.d.ts.map +1 -0
  87. package/dist/components/agents.js +246 -0
  88. package/dist/components/agents.js.map +1 -0
  89. package/dist/components/calendar.d.ts +17 -17
  90. package/dist/components/calendar.d.ts.map +1 -1
  91. package/dist/components/calendar.js +7 -2
  92. package/dist/components/calendar.js.map +1 -1
  93. package/dist/components/charts.d.ts +157 -0
  94. package/dist/components/charts.d.ts.map +1 -0
  95. package/dist/components/charts.js +182 -0
  96. package/dist/components/charts.js.map +1 -0
  97. package/dist/components/comments.d.ts +2 -0
  98. package/dist/components/comments.d.ts.map +1 -1
  99. package/dist/components/comments.js +1 -1
  100. package/dist/components/comments.js.map +1 -1
  101. package/dist/components/connect.d.ts.map +1 -1
  102. package/dist/components/connect.js +7 -2
  103. package/dist/components/connect.js.map +1 -1
  104. package/dist/components/decision-form.d.ts +21 -0
  105. package/dist/components/decision-form.d.ts.map +1 -1
  106. package/dist/components/decision-form.js +20 -6
  107. package/dist/components/decision-form.js.map +1 -1
  108. package/dist/components/decision-list.d.ts +24 -0
  109. package/dist/components/decision-list.d.ts.map +1 -1
  110. package/dist/components/decision-list.js +54 -5
  111. package/dist/components/decision-list.js.map +1 -1
  112. package/dist/components/desk-records.d.ts +102 -0
  113. package/dist/components/desk-records.d.ts.map +1 -0
  114. package/dist/components/desk-records.js +221 -0
  115. package/dist/components/desk-records.js.map +1 -0
  116. package/dist/components/desk.d.ts +85 -0
  117. package/dist/components/desk.d.ts.map +1 -0
  118. package/dist/components/desk.js +135 -0
  119. package/dist/components/desk.js.map +1 -0
  120. package/dist/components/event-feed.d.ts.map +1 -1
  121. package/dist/components/event-feed.js +26 -1
  122. package/dist/components/event-feed.js.map +1 -1
  123. package/dist/components/home.d.ts +12 -1
  124. package/dist/components/home.d.ts.map +1 -1
  125. package/dist/components/home.js +175 -16
  126. package/dist/components/home.js.map +1 -1
  127. package/dist/components/my-decisions.d.ts +5 -0
  128. package/dist/components/my-decisions.d.ts.map +1 -1
  129. package/dist/components/my-decisions.js +3 -3
  130. package/dist/components/my-decisions.js.map +1 -1
  131. package/dist/components/people.d.ts +17 -0
  132. package/dist/components/people.d.ts.map +1 -1
  133. package/dist/components/people.js +55 -19
  134. package/dist/components/people.js.map +1 -1
  135. package/dist/components/picker.d.ts +2 -0
  136. package/dist/components/picker.d.ts.map +1 -1
  137. package/dist/components/picker.js +1 -1
  138. package/dist/components/picker.js.map +1 -1
  139. package/dist/components/pictures.d.ts +38 -10
  140. package/dist/components/pictures.d.ts.map +1 -1
  141. package/dist/components/pictures.js +195 -40
  142. package/dist/components/pictures.js.map +1 -1
  143. package/dist/components/plugin-events.d.ts +29 -0
  144. package/dist/components/plugin-events.d.ts.map +1 -0
  145. package/dist/components/plugin-events.js +139 -0
  146. package/dist/components/plugin-events.js.map +1 -0
  147. package/dist/components/plugin-frame.d.ts.map +1 -1
  148. package/dist/components/plugin-frame.js +14 -37
  149. package/dist/components/plugin-frame.js.map +1 -1
  150. package/dist/components/plugin-settings.d.ts.map +1 -1
  151. package/dist/components/plugin-settings.js +58 -7
  152. package/dist/components/plugin-settings.js.map +1 -1
  153. package/dist/components/projects.d.ts.map +1 -1
  154. package/dist/components/projects.js +30 -10
  155. package/dist/components/projects.js.map +1 -1
  156. package/dist/components/rules.d.ts +8 -10
  157. package/dist/components/rules.d.ts.map +1 -1
  158. package/dist/components/rules.js +36 -14
  159. package/dist/components/rules.js.map +1 -1
  160. package/dist/components/sessions.d.ts.map +1 -1
  161. package/dist/components/sessions.js +8 -4
  162. package/dist/components/sessions.js.map +1 -1
  163. package/dist/components/setup.d.ts +59 -0
  164. package/dist/components/setup.d.ts.map +1 -0
  165. package/dist/components/setup.js +93 -0
  166. package/dist/components/setup.js.map +1 -0
  167. package/dist/components/sign-in.js +1 -1
  168. package/dist/components/sign-in.js.map +1 -1
  169. package/dist/components/task-form.d.ts.map +1 -1
  170. package/dist/components/task-form.js +2 -2
  171. package/dist/components/task-form.js.map +1 -1
  172. package/dist/components/task-list.d.ts +7 -6
  173. package/dist/components/task-list.d.ts.map +1 -1
  174. package/dist/components/task-list.js.map +1 -1
  175. package/dist/components/task-view.d.ts +3 -0
  176. package/dist/components/task-view.d.ts.map +1 -1
  177. package/dist/components/task-view.js +1 -1
  178. package/dist/components/task-view.js.map +1 -1
  179. package/dist/components/ui.d.ts +78 -8
  180. package/dist/components/ui.d.ts.map +1 -1
  181. package/dist/components/ui.js +88 -9
  182. package/dist/components/ui.js.map +1 -1
  183. package/dist/components/work.d.ts +5 -5
  184. package/dist/components/work.d.ts.map +1 -1
  185. package/dist/components/work.js.map +1 -1
  186. package/dist/components/workspace.d.ts +17 -0
  187. package/dist/components/workspace.d.ts.map +1 -1
  188. package/dist/components/workspace.js +129 -2
  189. package/dist/components/workspace.js.map +1 -1
  190. package/dist/connect-page.d.ts.map +1 -1
  191. package/dist/connect-page.js +5 -2
  192. package/dist/connect-page.js.map +1 -1
  193. package/dist/console.css +7551 -4580
  194. package/dist/console.d.ts +20 -0
  195. package/dist/console.d.ts.map +1 -1
  196. package/dist/console.js +331 -57
  197. package/dist/console.js.map +1 -1
  198. package/dist/data.d.ts +22 -1
  199. package/dist/data.d.ts.map +1 -1
  200. package/dist/data.js +62 -34
  201. package/dist/data.js.map +1 -1
  202. package/dist/desk-page.d.ts +38 -0
  203. package/dist/desk-page.d.ts.map +1 -0
  204. package/dist/desk-page.js +184 -0
  205. package/dist/desk-page.js.map +1 -0
  206. package/dist/desk-records-page.d.ts +18 -0
  207. package/dist/desk-records-page.d.ts.map +1 -0
  208. package/dist/desk-records-page.js +130 -0
  209. package/dist/desk-records-page.js.map +1 -0
  210. package/dist/desk-records.d.ts +247 -0
  211. package/dist/desk-records.d.ts.map +1 -0
  212. package/dist/desk-records.js +543 -0
  213. package/dist/desk-records.js.map +1 -0
  214. package/dist/desk.d.ts +122 -0
  215. package/dist/desk.d.ts.map +1 -0
  216. package/dist/desk.js +211 -0
  217. package/dist/desk.js.map +1 -0
  218. package/dist/feed-stream.d.ts +39 -0
  219. package/dist/feed-stream.d.ts.map +1 -0
  220. package/dist/feed-stream.js +117 -0
  221. package/dist/feed-stream.js.map +1 -0
  222. package/dist/glances.d.ts +39 -0
  223. package/dist/glances.d.ts.map +1 -0
  224. package/dist/glances.js +94 -0
  225. package/dist/glances.js.map +1 -0
  226. package/dist/home-tiles.d.ts +69 -5
  227. package/dist/home-tiles.d.ts.map +1 -1
  228. package/dist/home-tiles.js +347 -9
  229. package/dist/home-tiles.js.map +1 -1
  230. package/dist/i18n/en.d.ts +773 -3
  231. package/dist/i18n/en.d.ts.map +1 -1
  232. package/dist/i18n/en.js +770 -9
  233. package/dist/i18n/en.js.map +1 -1
  234. package/dist/i18n/ko.d.ts.map +1 -1
  235. package/dist/i18n/ko.js +736 -9
  236. package/dist/i18n/ko.js.map +1 -1
  237. package/dist/index.d.ts +19 -7
  238. package/dist/index.d.ts.map +1 -1
  239. package/dist/index.js +17 -5
  240. package/dist/index.js.map +1 -1
  241. package/dist/limits.d.ts +67 -0
  242. package/dist/limits.d.ts.map +1 -1
  243. package/dist/limits.js +67 -0
  244. package/dist/limits.js.map +1 -1
  245. package/dist/onboarding.d.ts +21 -0
  246. package/dist/onboarding.d.ts.map +1 -0
  247. package/dist/onboarding.js +43 -0
  248. package/dist/onboarding.js.map +1 -0
  249. package/dist/persona.d.ts +34 -0
  250. package/dist/persona.d.ts.map +1 -0
  251. package/dist/persona.js +71 -0
  252. package/dist/persona.js.map +1 -0
  253. package/dist/plugin/context.d.ts +42 -11
  254. package/dist/plugin/context.d.ts.map +1 -1
  255. package/dist/plugin/limits.d.ts +2 -0
  256. package/dist/plugin/limits.d.ts.map +1 -1
  257. package/dist/plugin/limits.js +2 -0
  258. package/dist/plugin/limits.js.map +1 -1
  259. package/dist/plugin/manifest.d.ts +13 -0
  260. package/dist/plugin/manifest.d.ts.map +1 -1
  261. package/dist/plugin/manifest.js +34 -4
  262. package/dist/plugin/manifest.js.map +1 -1
  263. package/dist/plugin/rest-schemas.d.ts +56 -0
  264. package/dist/plugin/rest-schemas.d.ts.map +1 -1
  265. package/dist/plugin/rest-schemas.js +42 -0
  266. package/dist/plugin/rest-schemas.js.map +1 -1
  267. package/dist/plugin/sandbox.d.ts.map +1 -1
  268. package/dist/plugin/sandbox.js +4 -1
  269. package/dist/plugin/sandbox.js.map +1 -1
  270. package/dist/plugin/testing.d.ts +6 -2
  271. package/dist/plugin/testing.d.ts.map +1 -1
  272. package/dist/plugin/testing.js +52 -10
  273. package/dist/plugin/testing.js.map +1 -1
  274. package/dist/plugin.d.ts +1 -1
  275. package/dist/plugin.d.ts.map +1 -1
  276. package/dist/plugin.js +1 -1
  277. package/dist/plugin.js.map +1 -1
  278. package/dist/records.d.ts +283 -0
  279. package/dist/records.d.ts.map +1 -0
  280. package/dist/records.js +543 -0
  281. package/dist/records.js.map +1 -0
  282. package/dist/router.d.ts +50 -3
  283. package/dist/router.d.ts.map +1 -1
  284. package/dist/router.js +78 -7
  285. package/dist/router.js.map +1 -1
  286. package/dist/routes.d.ts +12 -2
  287. package/dist/routes.d.ts.map +1 -1
  288. package/dist/routes.js +14 -1
  289. package/dist/routes.js.map +1 -1
  290. package/dist/rules.d.ts +30 -11
  291. package/dist/rules.d.ts.map +1 -1
  292. package/dist/rules.js +99 -42
  293. package/dist/rules.js.map +1 -1
  294. package/dist/runner/acp.d.ts +20 -0
  295. package/dist/runner/acp.d.ts.map +1 -0
  296. package/dist/runner/acp.js +1132 -0
  297. package/dist/runner/acp.js.map +1 -0
  298. package/dist/runner/claude.d.ts +13 -0
  299. package/dist/runner/claude.d.ts.map +1 -0
  300. package/dist/runner/claude.js +615 -0
  301. package/dist/runner/claude.js.map +1 -0
  302. package/dist/runner/codex.d.ts +19 -0
  303. package/dist/runner/codex.d.ts.map +1 -0
  304. package/dist/runner/codex.js +597 -0
  305. package/dist/runner/codex.js.map +1 -0
  306. package/dist/runner/config.d.ts +35 -0
  307. package/dist/runner/config.d.ts.map +1 -0
  308. package/dist/runner/config.js +74 -0
  309. package/dist/runner/config.js.map +1 -0
  310. package/dist/runner/desk.d.ts +81 -0
  311. package/dist/runner/desk.d.ts.map +1 -0
  312. package/dist/runner/desk.js +303 -0
  313. package/dist/runner/desk.js.map +1 -0
  314. package/dist/runner/launchd.d.ts +7 -0
  315. package/dist/runner/launchd.d.ts.map +1 -0
  316. package/dist/runner/launchd.js +78 -0
  317. package/dist/runner/launchd.js.map +1 -0
  318. package/dist/runner/message.d.ts +66 -0
  319. package/dist/runner/message.d.ts.map +1 -0
  320. package/dist/runner/message.js +181 -0
  321. package/dist/runner/message.js.map +1 -0
  322. package/dist/runner/modules.d.ts +13 -0
  323. package/dist/runner/modules.d.ts.map +1 -0
  324. package/dist/runner/modules.js +30 -0
  325. package/dist/runner/modules.js.map +1 -0
  326. package/dist/runner/process.d.ts +7 -0
  327. package/dist/runner/process.d.ts.map +1 -0
  328. package/dist/runner/process.js +65 -0
  329. package/dist/runner/process.js.map +1 -0
  330. package/dist/runner/redact.d.ts +48 -0
  331. package/dist/runner/redact.d.ts.map +1 -0
  332. package/dist/runner/redact.js +214 -0
  333. package/dist/runner/redact.js.map +1 -0
  334. package/dist/runner/registry.d.ts +37 -0
  335. package/dist/runner/registry.d.ts.map +1 -0
  336. package/dist/runner/registry.js +26 -0
  337. package/dist/runner/registry.js.map +1 -0
  338. package/dist/runner/runner.d.ts +130 -0
  339. package/dist/runner/runner.d.ts.map +1 -0
  340. package/dist/runner/runner.js +1551 -0
  341. package/dist/runner/runner.js.map +1 -0
  342. package/dist/runner/slack.d.ts +16 -0
  343. package/dist/runner/slack.d.ts.map +1 -0
  344. package/dist/runner/slack.js +157 -0
  345. package/dist/runner/slack.js.map +1 -0
  346. package/dist/runner/systemd-user.d.ts +7 -0
  347. package/dist/runner/systemd-user.d.ts.map +1 -0
  348. package/dist/runner/systemd-user.js +93 -0
  349. package/dist/runner/systemd-user.js.map +1 -0
  350. package/dist/runner/task-scheduler.d.ts +38 -0
  351. package/dist/runner/task-scheduler.d.ts.map +1 -0
  352. package/dist/runner/task-scheduler.js +216 -0
  353. package/dist/runner/task-scheduler.js.map +1 -0
  354. package/dist/runner/types.d.ts +315 -0
  355. package/dist/runner/types.d.ts.map +1 -0
  356. package/dist/runner/types.js +24 -0
  357. package/dist/runner/types.js.map +1 -0
  358. package/dist/runner.d.ts +18 -0
  359. package/dist/runner.d.ts.map +1 -0
  360. package/dist/runner.js +20 -0
  361. package/dist/runner.js.map +1 -0
  362. package/dist/schemas.d.ts +6082 -1295
  363. package/dist/schemas.d.ts.map +1 -1
  364. package/dist/schemas.js +930 -31
  365. package/dist/schemas.js.map +1 -1
  366. package/dist/services.d.ts +110 -0
  367. package/dist/services.d.ts.map +1 -0
  368. package/dist/services.js +305 -0
  369. package/dist/services.js.map +1 -0
  370. package/dist/setup-guide.d.ts +64 -0
  371. package/dist/setup-guide.d.ts.map +1 -0
  372. package/dist/setup-guide.js +256 -0
  373. package/dist/setup-guide.js.map +1 -0
  374. package/dist/setup-page.d.ts +6 -0
  375. package/dist/setup-page.d.ts.map +1 -0
  376. package/dist/setup-page.js +29 -0
  377. package/dist/setup-page.js.map +1 -0
  378. package/dist/sse.d.ts +15 -0
  379. package/dist/sse.d.ts.map +1 -0
  380. package/dist/sse.js +73 -0
  381. package/dist/sse.js.map +1 -0
  382. package/dist/tab-title.d.ts +6 -0
  383. package/dist/tab-title.d.ts.map +1 -0
  384. package/dist/tab-title.js +22 -0
  385. package/dist/tab-title.js.map +1 -0
  386. package/dist/tokens.d.ts.map +1 -1
  387. package/dist/tokens.js +3 -0
  388. package/dist/tokens.js.map +1 -1
  389. package/dist/use-action.d.ts +5 -2
  390. package/dist/use-action.d.ts.map +1 -1
  391. package/dist/use-action.js +6 -1
  392. package/dist/use-action.js.map +1 -1
  393. package/dist/vocabulary.d.ts +84 -4
  394. package/dist/vocabulary.d.ts.map +1 -1
  395. package/dist/vocabulary.js +115 -3
  396. package/dist/vocabulary.js.map +1 -1
  397. package/docs/specs/cli.md +147 -41
  398. package/docs/specs/plugins.md +37 -27
  399. package/docs/specs/records.md +113 -0
  400. package/docs/specs/rest.md +155 -20
  401. package/docs/specs/runner.md +347 -0
  402. package/package.json +12 -3
  403. package/skills/building-a-console/SKILL.md +4 -4
  404. package/skills/building-a-console/references/configuring.md +1 -0
  405. package/skills/building-a-plugin/SKILL.md +7 -7
  406. package/skills/deploying-a-console/SKILL.md +4 -4
  407. package/skills/deploying-a-console/references/resources.md +48 -8
  408. package/skills/deploying-a-console/references/running-it-again.md +3 -2
  409. package/skills/keeping-a-desk/SKILL.md +133 -0
  410. package/skills/keeping-a-desk/collections.md +96 -0
  411. package/skills/planning-the-board/SKILL.md +14 -18
  412. package/skills/planning-the-board/references/a-task.md +2 -2
  413. package/skills/planning-the-board/references/project-rules.md +13 -14
  414. package/skills/planning-the-board/references/setting-up.md +22 -9
  415. package/skills/running-an-agent/SKILL.md +107 -0
  416. package/skills/running-an-agent/references/slack-app.md +61 -0
  417. package/skills/working-the-board/SKILL.md +66 -39
  418. package/skills/working-the-board/references/terms.md +9 -5
  419. package/skills/working-the-board/references/the-pack.md +14 -9
  420. package/skills/working-the-board/references/the-sentence.md +2 -2
  421. package/src/agent-page.tsx +1039 -0
  422. package/src/agent-stream.ts +199 -0
  423. package/src/api.ts +317 -2
  424. package/src/avatar.ts +1506 -0
  425. package/src/charts.ts +250 -0
  426. package/src/cli/cli.ts +3210 -503
  427. package/src/cli/command-words.ts +56 -0
  428. package/src/cli/credentials.ts +188 -16
  429. package/src/cli/directory.ts +28 -10
  430. package/src/cli/format.ts +470 -67
  431. package/src/cli/help.ts +233 -61
  432. package/src/cli/main.ts +89 -0
  433. package/src/cli/pack.ts +332 -263
  434. package/src/cli/plugin-check.ts +275 -34
  435. package/src/cli/plugin-cli.ts +28 -4
  436. package/src/cli/plugin-main.ts +1 -0
  437. package/src/cli/runner-host.ts +188 -0
  438. package/src/cli/serve.ts +320 -5
  439. package/src/cli/setup-machine.ts +153 -0
  440. package/src/client.ts +711 -126
  441. package/src/compat.ts +2 -2
  442. package/src/components/agent-page.tsx +1946 -0
  443. package/src/components/agents.tsx +638 -0
  444. package/src/components/calendar.tsx +74 -53
  445. package/src/components/charts.tsx +680 -0
  446. package/src/components/comments.tsx +3 -0
  447. package/src/components/connect.tsx +37 -2
  448. package/src/components/decision-form.tsx +89 -51
  449. package/src/components/decision-list.tsx +140 -4
  450. package/src/components/desk-records.tsx +724 -0
  451. package/src/components/desk.tsx +471 -0
  452. package/src/components/event-feed.tsx +30 -1
  453. package/src/components/home.tsx +353 -12
  454. package/src/components/my-decisions.tsx +8 -2
  455. package/src/components/people.tsx +300 -203
  456. package/src/components/picker.tsx +3 -1
  457. package/src/components/pictures.tsx +256 -44
  458. package/src/components/plugin-events.ts +159 -0
  459. package/src/components/plugin-frame.tsx +14 -38
  460. package/src/components/plugin-settings.tsx +178 -22
  461. package/src/components/projects.tsx +33 -15
  462. package/src/components/rules.tsx +96 -36
  463. package/src/components/sessions.tsx +7 -4
  464. package/src/components/setup.tsx +252 -0
  465. package/src/components/sign-in.tsx +1 -1
  466. package/src/components/task-form.tsx +11 -2
  467. package/src/components/task-list.tsx +7 -6
  468. package/src/components/task-view.tsx +4 -0
  469. package/src/components/ui.tsx +169 -25
  470. package/src/components/work.tsx +9 -9
  471. package/src/components/workspace.tsx +345 -4
  472. package/src/connect-page.tsx +15 -2
  473. package/src/console.tsx +657 -83
  474. package/src/data.ts +109 -43
  475. package/src/desk-page.tsx +332 -0
  476. package/src/desk-records-page.tsx +256 -0
  477. package/src/desk-records.ts +808 -0
  478. package/src/desk.ts +329 -0
  479. package/src/feed-stream.ts +144 -0
  480. package/src/glances.ts +132 -0
  481. package/src/home-tiles.ts +411 -9
  482. package/src/i18n/en.ts +828 -10
  483. package/src/i18n/ko.ts +792 -10
  484. package/src/index.ts +172 -3
  485. package/src/limits.ts +67 -0
  486. package/src/onboarding.ts +84 -0
  487. package/src/persona.ts +100 -0
  488. package/src/plugin/context.ts +55 -12
  489. package/src/plugin/limits.ts +2 -0
  490. package/src/plugin/manifest.ts +42 -3
  491. package/src/plugin/rest-schemas.ts +46 -0
  492. package/src/plugin/sandbox.ts +4 -1
  493. package/src/plugin/testing.ts +63 -12
  494. package/src/plugin.ts +2 -0
  495. package/src/records.ts +702 -0
  496. package/src/router.ts +120 -10
  497. package/src/routes.ts +17 -1
  498. package/src/rules.ts +109 -44
  499. package/src/runner/acp.ts +1267 -0
  500. package/src/runner/claude.ts +695 -0
  501. package/src/runner/codex.ts +691 -0
  502. package/src/runner/config.ts +97 -0
  503. package/src/runner/desk.ts +377 -0
  504. package/src/runner/launchd.ts +86 -0
  505. package/src/runner/message.ts +232 -0
  506. package/src/runner/modules.ts +30 -0
  507. package/src/runner/process.ts +72 -0
  508. package/src/runner/redact.ts +242 -0
  509. package/src/runner/registry.ts +67 -0
  510. package/src/runner/runner.ts +1879 -0
  511. package/src/runner/slack.ts +180 -0
  512. package/src/runner/systemd-user.ts +103 -0
  513. package/src/runner/task-scheduler.ts +236 -0
  514. package/src/runner/types.ts +334 -0
  515. package/src/runner.ts +110 -0
  516. package/src/schemas.ts +1183 -30
  517. package/src/services.ts +424 -0
  518. package/src/setup-guide.ts +336 -0
  519. package/src/setup-page.tsx +46 -0
  520. package/src/sse.ts +84 -0
  521. package/src/styles/README.md +111 -0
  522. package/src/styles/base.css +130 -0
  523. package/src/styles/console.css +85 -7095
  524. package/src/styles/drawn-by-pages.json +256 -0
  525. package/src/styles/pages/agents.css +1195 -0
  526. package/src/styles/pages/board.css +380 -0
  527. package/src/styles/pages/calendar.css +214 -0
  528. package/src/styles/pages/connect.css +182 -0
  529. package/src/styles/pages/decisions.css +370 -0
  530. package/src/styles/pages/desk.css +126 -0
  531. package/src/styles/pages/documents.css +273 -0
  532. package/src/styles/pages/feed.css +118 -0
  533. package/src/styles/pages/home.css +718 -0
  534. package/src/styles/pages/people.css +90 -0
  535. package/src/styles/pages/plugins.css +212 -0
  536. package/src/styles/pages/roadmap.css +377 -0
  537. package/src/styles/pages/settings.css +171 -0
  538. package/src/styles/pages/shell.css +208 -0
  539. package/src/styles/pages/sign-in.css +178 -0
  540. package/src/styles/pages/task.css +108 -0
  541. package/src/styles/pages/thread.css +331 -0
  542. package/src/styles/pages/work.css +68 -0
  543. package/src/styles/parts/avatar.css +82 -0
  544. package/src/styles/parts/badge.css +227 -0
  545. package/src/styles/parts/bars.css +80 -0
  546. package/src/styles/parts/button.css +99 -0
  547. package/src/styles/parts/calendar.css +547 -0
  548. package/src/styles/parts/callout.css +41 -0
  549. package/src/styles/parts/category.css +8 -0
  550. package/src/styles/parts/chart.css +173 -0
  551. package/src/styles/parts/chip.css +90 -0
  552. package/src/styles/parts/code.css +48 -0
  553. package/src/styles/parts/count.css +27 -0
  554. package/src/styles/parts/crumbs.css +61 -0
  555. package/src/styles/parts/detail.css +110 -0
  556. package/src/styles/parts/empty.css +21 -0
  557. package/src/styles/parts/eyebrow.css +9 -0
  558. package/src/styles/parts/facts.css +147 -0
  559. package/src/styles/parts/figures.css +65 -0
  560. package/src/styles/parts/files.css +38 -0
  561. package/src/styles/parts/filters.css +42 -0
  562. package/src/styles/parts/form.css +109 -0
  563. package/src/styles/parts/frame.css +45 -0
  564. package/src/styles/parts/input.css +243 -0
  565. package/src/styles/parts/legend.css +48 -0
  566. package/src/styles/parts/links.css +37 -0
  567. package/src/styles/parts/mark.css +79 -0
  568. package/src/styles/parts/menu.css +147 -0
  569. package/src/styles/parts/page.css +174 -0
  570. package/src/styles/parts/pager.css +19 -0
  571. package/src/styles/parts/panel.css +33 -0
  572. package/src/styles/parts/person.css +257 -0
  573. package/src/styles/parts/picker.css +185 -0
  574. package/src/styles/parts/progress.css +25 -0
  575. package/src/styles/parts/prose.css +128 -0
  576. package/src/styles/parts/rows.css +63 -0
  577. package/src/styles/parts/series.css +32 -0
  578. package/src/styles/parts/settings.css +101 -0
  579. package/src/styles/parts/share.css +25 -0
  580. package/src/styles/parts/spark.css +23 -0
  581. package/src/styles/parts/spinner.css +29 -0
  582. package/src/styles/parts/stat.css +69 -0
  583. package/src/styles/parts/steps.css +68 -0
  584. package/src/styles/parts/tabs.css +175 -0
  585. package/src/styles/parts/text.css +61 -0
  586. package/src/styles/parts/toggle.css +71 -0
  587. package/src/styles/parts/workers.css +37 -0
  588. package/src/styles/tokens.css +295 -0
  589. package/src/tab-title.ts +25 -0
  590. package/src/tokens.ts +3 -0
  591. package/src/use-action.ts +7 -2
  592. package/src/vocabulary.ts +151 -3
  593. package/template/desk-web/README.md +8 -0
  594. package/template/desk-web/index.html +13 -0
  595. package/template/desk-web/package.json +25 -0
  596. package/template/desk-web/src/main.tsx +24 -0
  597. package/template/desk-web/src/page.tsx +51 -0
  598. package/template/desk-web/tsconfig.json +16 -0
  599. package/template/desk-web/vite.config.ts +15 -0
@@ -0,0 +1,1946 @@
1
+ import {
2
+ type FormEvent,
3
+ memo,
4
+ type ReactNode,
5
+ useCallback,
6
+ useEffect,
7
+ useMemo,
8
+ useRef,
9
+ useState,
10
+ } from "react";
11
+ import {
12
+ type AgentState,
13
+ type FileUpload,
14
+ MAX_FILE_BYTES,
15
+ MAX_SIGNAL_ATTACHMENTS,
16
+ MAX_SIGNAL_LENGTH,
17
+ type RestAgent,
18
+ type RestAgentRunner,
19
+ type RestAgentSecret,
20
+ type RestAgentSession,
21
+ type RestPerson,
22
+ type RestSignal,
23
+ type RestTranscriptEvent,
24
+ } from "../api.js";
25
+ import { today } from "../dates.js";
26
+ import { useWords } from "../i18n/index.js";
27
+ import { isPicture } from "./files.js";
28
+ import { Lightbox, type PictureState, PictureThumb, usePicture } from "./pictures.js";
29
+ import { Avatar, Badge, Button, Callout, cx, formatBytes, personName, Time } from "./ui.js";
30
+
31
+ // The parts of an agent account's page (ADR-0085, ADR-0086): how it stands, what it is doing as
32
+ // it happens, read as a conversation in a pane that follows its end, what a supervisor says to
33
+ // it, shown as waiting until the agent takes it, what changes how it stands, its sessions, and
34
+ // what its runner said of itself. Everything an agent's product printed is shown as text, in a
35
+ // block that keeps its spaces and its lines, and is never made markup; a picture is shown by its
36
+ // address at the console, and any other file is offered to save.
37
+
38
+ /** How an agent stands, in a word, with the tone of it. */
39
+ const STATE_TONES: Readonly<Record<AgentState, "success" | "neutral" | "warning" | "danger">> = {
40
+ running: "success",
41
+ stopped: "neutral",
42
+ refused: "warning",
43
+ failed: "danger",
44
+ unheard: "warning",
45
+ };
46
+
47
+ /** The state of an agent account as a badge: the word, and why and since when where there is room. */
48
+ export function AgentStateBadge(props: {
49
+ readonly state: RestAgent["state"];
50
+ /** With why it stands so, since when, and when its runner was last heard from. */
51
+ readonly full?: boolean | undefined;
52
+ }) {
53
+ const words = useWords().agents.page.state;
54
+ const state = props.state ?? null;
55
+ if (state === null) {
56
+ // Where there is room, an account no runner has spoken for says so as the others say how they
57
+ // stand: a word in a badge, and why beside it.
58
+ return props.full === true ? (
59
+ <span className="sc-agent-state">
60
+ <Badge tone="neutral" kind="state">
61
+ {words.unset}
62
+ </Badge>
63
+ <span className="sc-agent-state-why">{words.none}</span>
64
+ </span>
65
+ ) : null;
66
+ }
67
+ const reasons: Readonly<Record<string, string>> = words.reasons;
68
+ const reason = state.reason === null ? undefined : (reasons[state.reason] ?? state.reason);
69
+ const badge = (
70
+ <Badge
71
+ tone={STATE_TONES[state.state]}
72
+ kind="state"
73
+ live={state.state === "running"}
74
+ title={reason}
75
+ >
76
+ {words[state.state]}
77
+ </Badge>
78
+ );
79
+ if (props.full !== true) {
80
+ return badge;
81
+ }
82
+ return (
83
+ <span className="sc-agent-state">
84
+ {badge}
85
+ <span className="sc-agent-state-why">
86
+ {reason !== undefined && `${reason} · `}
87
+ {words.since.before}
88
+ <Time iso={state.since} precision="clock" />
89
+ {words.since.after}
90
+ {state.heardAt !== null && (
91
+ <>
92
+ {" · "}
93
+ {words.heard} <Time iso={state.heardAt} precision="clock" />
94
+ </>
95
+ )}
96
+ </span>
97
+ </span>
98
+ );
99
+ }
100
+
101
+ export interface TranscriptViewProps {
102
+ readonly events: readonly RestTranscriptEvent[];
103
+ /**
104
+ * What the events are of: the session's id. A text read whole is kept under it, so that it is
105
+ * never shown for the event of the same number in another session. Left out where a view shows
106
+ * one list of events and no other.
107
+ */
108
+ readonly of?: string | undefined;
109
+ /** Where the bytes of a picture of the session are read. */
110
+ readonly fileHref: (fileId: string) => string;
111
+ /** Reads the whole text of an event whose row keeps its beginning alone. */
112
+ readonly onReadWhole?: ((n: number) => Promise<string>) | undefined;
113
+ /** The account whose session this is: its picture stands beside what it said. */
114
+ readonly agent?: RestPerson | undefined;
115
+ /**
116
+ * The files that came with a signal, by its number, where the page has read the account's
117
+ * record: what a supervisor sent that is no picture is offered to save from there.
118
+ */
119
+ readonly signalFiles?: ((number: number) => readonly SignalFile[] | undefined) | undefined;
120
+ /** Where the bytes of a file of a signal are read. */
121
+ readonly signalFileHref?: ((number: number, fileId: string) => string) | undefined;
122
+ readonly empty?: ReactNode;
123
+ /**
124
+ * What stands at the conversation's foot, rows of its list: the words that wait to be taken,
125
+ * and the sign that the agent is at work.
126
+ */
127
+ readonly foot?: ReactNode;
128
+ }
129
+
130
+ /** A file that came with a signal, as the account's record names it. */
131
+ export interface SignalFile {
132
+ readonly id: string;
133
+ readonly name: string;
134
+ readonly size: number;
135
+ readonly contentType: string;
136
+ }
137
+
138
+ /** What a runner says of an event that is said apart from the rest: the tool it names. */
139
+ const TOOL = "tool";
140
+
141
+ /**
142
+ * One thing of a session as a person reads it: what the agent was told, what woke it, what it
143
+ * said and thought, a tool's call with what it answered and what was asked of it, and a note for
144
+ * everything else, a status, an error, an event that was sealed.
145
+ */
146
+ export type TalkItem =
147
+ | {
148
+ readonly type: "told" | "wake" | "said" | "thought" | "note";
149
+ readonly event: RestTranscriptEvent;
150
+ }
151
+ | {
152
+ readonly type: "tool";
153
+ /** The call, its answer and what was asked before it ran, each where the session has it. */
154
+ readonly call: RestTranscriptEvent | undefined;
155
+ readonly result: RestTranscriptEvent | undefined;
156
+ readonly permission: RestTranscriptEvent | undefined;
157
+ };
158
+
159
+ /** The most characters of a sub-agent's name that a label shows. */
160
+ const MAX_SUBAGENT_LABEL = 40;
161
+
162
+ /**
163
+ * Whose an event is, where a sub-agent made it (ADR-0131): what the call that started the
164
+ * sub-agent called it, an empty name where the runner knew only that call, and nothing for an
165
+ * event of the session's own, which is every event of a runner that does not say.
166
+ */
167
+ export function subagentOf(event: RestTranscriptEvent | undefined): string | undefined {
168
+ const parent = event?.data.parent;
169
+ if (typeof parent !== "string" || parent.length === 0) {
170
+ return undefined;
171
+ }
172
+ const name = event?.data.subagent;
173
+ return typeof name === "string" ? name.trim().slice(0, MAX_SUBAGENT_LABEL) : "";
174
+ }
175
+
176
+ const idOf = (event: RestTranscriptEvent): string | undefined => {
177
+ const id = event.data.id;
178
+ return typeof id === "string" && id.length > 0 ? id : undefined;
179
+ };
180
+
181
+ /**
182
+ * The events of a session as the things a person reads, in order. A tool's call, what it
183
+ * answered and what was asked before it ran are one thing, joined by the id the product gave
184
+ * them; a call under an id whose call is done is another call, as an agent that numbers its
185
+ * calls anew at every turn has it. What carries no id joins the call before it that waits.
186
+ */
187
+ export function talkOf(events: readonly RestTranscriptEvent[]): TalkItem[] {
188
+ const items: TalkItem[] = [];
189
+ type Tool = Extract<TalkItem, { type: "tool" }>;
190
+ /** The tool things by the id they are open under, as places among the items. */
191
+ const open = new Map<string, number>();
192
+ const toolAt = (at: number | undefined): Tool | undefined => {
193
+ const item = at === undefined ? undefined : items[at];
194
+ return item !== undefined && item.type === "tool" ? item : undefined;
195
+ };
196
+ /** The last tool thing that still waits for what `field` names, where nothing names an id. */
197
+ const waiting = (field: "call" | "result"): number | undefined => {
198
+ for (let at = items.length - 1; at >= 0; at -= 1) {
199
+ const item = items[at];
200
+ if (item === undefined || item.type !== "tool") {
201
+ return undefined;
202
+ }
203
+ if (item[field] === undefined) {
204
+ return at;
205
+ }
206
+ }
207
+ return undefined;
208
+ };
209
+ const put = (id: string | undefined, tool: Tool, at: number | undefined): void => {
210
+ if (at === undefined) {
211
+ items.push(tool);
212
+ if (id !== undefined) {
213
+ open.set(id, items.length - 1);
214
+ }
215
+ } else {
216
+ items[at] = tool;
217
+ }
218
+ };
219
+ for (const event of events) {
220
+ // A sealed event says who sealed it and why, wherever it stood.
221
+ if (event.sealed !== null) {
222
+ items.push({ type: "note", event });
223
+ continue;
224
+ }
225
+ if (event.kind === "person") {
226
+ items.push({ type: "told", event });
227
+ } else if (event.kind === "wake") {
228
+ items.push({ type: "wake", event });
229
+ } else if (event.kind === "assistant") {
230
+ items.push({ type: "said", event });
231
+ } else if (event.kind === "thinking") {
232
+ items.push({ type: "thought", event });
233
+ } else if (event.kind === "tool_call") {
234
+ const id = idOf(event);
235
+ const at = id === undefined ? undefined : open.get(id);
236
+ const held = toolAt(at);
237
+ if (held !== undefined && held.call === undefined) {
238
+ put(id, { ...held, call: event }, at);
239
+ } else {
240
+ put(id, { type: "tool", call: event, result: undefined, permission: undefined }, undefined);
241
+ }
242
+ } else if (event.kind === "tool_result") {
243
+ const id = idOf(event);
244
+ const at = id === undefined ? waiting("result") : open.get(id);
245
+ const held = toolAt(at);
246
+ if (held !== undefined && held.result === undefined) {
247
+ put(id, { ...held, result: event }, at);
248
+ if (id !== undefined) {
249
+ open.delete(id);
250
+ }
251
+ } else {
252
+ items.push({ type: "tool", call: undefined, result: event, permission: undefined });
253
+ }
254
+ } else if (event.kind === "permission") {
255
+ const id = idOf(event);
256
+ const at = id === undefined ? undefined : open.get(id);
257
+ const held = toolAt(at);
258
+ if (held !== undefined && held.permission === undefined && held.result === undefined) {
259
+ put(id, { ...held, permission: event }, at);
260
+ } else {
261
+ put(id, { type: "tool", call: undefined, result: undefined, permission: event }, undefined);
262
+ }
263
+ } else {
264
+ items.push({ type: "note", event });
265
+ }
266
+ }
267
+ return items;
268
+ }
269
+
270
+ /** What the agent is at while a turn is under way: thinking, at a tool, or at work between the two. */
271
+ export type Working =
272
+ | { readonly at: "thinking" | "working" }
273
+ | { readonly at: "tool"; readonly tool: string | undefined };
274
+
275
+ /**
276
+ * Whether a turn is under way, and what the agent is at, read off a session's events alone:
277
+ * the record says where a turn ends (`turn: "completed"` on a status) and where the session
278
+ * does, so whatever follows the last of those is a turn that is not done. Nothing where the
279
+ * session has no event yet, or its last turn is over.
280
+ */
281
+ export function workingOf(events: readonly RestTranscriptEvent[]): Working | undefined {
282
+ /** The calls that were answered, by the id the product gave them. */
283
+ const answered = new Set<string>();
284
+ for (let at = events.length - 1; at >= 0; at -= 1) {
285
+ const event = events[at];
286
+ if (event === undefined || event.sealed !== null) {
287
+ continue;
288
+ }
289
+ if (event.kind === "status") {
290
+ if (event.data.turn === "completed" || typeof event.data.ended === "string") {
291
+ return undefined;
292
+ }
293
+ continue;
294
+ }
295
+ if (event.kind === "tool_result") {
296
+ const id = idOf(event);
297
+ if (id === undefined) {
298
+ return { at: "working" };
299
+ }
300
+ answered.add(id);
301
+ continue;
302
+ }
303
+ if (event.kind === "tool_call") {
304
+ const id = idOf(event);
305
+ return id !== undefined && answered.has(id)
306
+ ? { at: "working" }
307
+ : { at: "tool", tool: word(event.data[TOOL]) };
308
+ }
309
+ if (event.kind === "permission") {
310
+ continue;
311
+ }
312
+ if (event.kind === "error") {
313
+ return undefined;
314
+ }
315
+ if (answered.size > 0) {
316
+ return { at: "working" };
317
+ }
318
+ return event.kind === "assistant" ? { at: "working" } : { at: "thinking" };
319
+ }
320
+ return undefined;
321
+ }
322
+
323
+ /** The number of the last signal a session's events say the agent took, or nothing where none says. */
324
+ export function takenOf(events: readonly RestTranscriptEvent[]): number | undefined {
325
+ let most: number | undefined;
326
+ for (const event of events) {
327
+ const number = event.data.signal;
328
+ if (
329
+ (event.kind === "person" || event.kind === "wake") &&
330
+ typeof number === "number" &&
331
+ (most === undefined || number > most)
332
+ ) {
333
+ most = number;
334
+ }
335
+ }
336
+ return most;
337
+ }
338
+
339
+ /**
340
+ * The words supervisors sent that the agent has not taken: the tells, and the interrupts that
341
+ * carry words or files, after the last signal the record says it took, the oldest first. A
342
+ * signal is taken in order, so everything up to that one was.
343
+ */
344
+ export function waitingOf(signals: readonly RestSignal[], taken: number): readonly RestSignal[] {
345
+ return signals
346
+ .filter(
347
+ (signal) =>
348
+ signal.number > taken &&
349
+ signal.source === "person" &&
350
+ (signal.kind === "tell" || signal.kind === "interrupt") &&
351
+ (signal.text.trim().length > 0 || signal.attachments.length > 0),
352
+ )
353
+ .slice()
354
+ .sort((a, b) => a.number - b.number);
355
+ }
356
+
357
+ /** The texts read whole in a session: the session they were read in, and each by its event's number. */
358
+ export interface WholeTexts {
359
+ readonly of: string | undefined;
360
+ readonly texts: Readonly<Record<number, string>>;
361
+ }
362
+
363
+ /** Nothing read whole yet. */
364
+ export const NO_WHOLE: WholeTexts = { of: undefined, texts: {} };
365
+
366
+ /**
367
+ * The whole text of an event, where it was read whole in the session shown. Every session
368
+ * numbers its events from one, so a text read in another session is another event's, and is
369
+ * never answered for this one.
370
+ */
371
+ export function wholeOf(kept: WholeTexts, of: string | undefined, n: number): string | undefined {
372
+ return kept.of === of ? kept.texts[n] : undefined;
373
+ }
374
+
375
+ /** What is kept once a text was read whole in a session: with the others read in it, without those of another. */
376
+ export function withWhole(
377
+ kept: WholeTexts,
378
+ of: string | undefined,
379
+ n: number,
380
+ text: string,
381
+ ): WholeTexts {
382
+ return { of, texts: { ...(kept.of === of ? kept.texts : {}), [n]: text } };
383
+ }
384
+
385
+ /**
386
+ * A session's events with the ones before them put first: those up to where the events shown
387
+ * begin, and none that is shown already, so that a page read twice adds its events once.
388
+ */
389
+ export function withEarlier(
390
+ current: readonly RestTranscriptEvent[],
391
+ earlier: readonly RestTranscriptEvent[],
392
+ from: number,
393
+ ): readonly RestTranscriptEvent[] {
394
+ const shown = new Set(current.map((event) => event.n));
395
+ return [...earlier.filter((event) => event.n <= from && !shown.has(event.n)), ...current];
396
+ }
397
+
398
+ /** How far from its end a conversation may stand and still be followed, in pixels. */
399
+ export const FOLLOW_SLACK = 72;
400
+
401
+ /** Whether whoever reads a pane is at its end, give or take a line: there the pane follows what arrives. */
402
+ export function followsEnd(pane: {
403
+ readonly scrollHeight: number;
404
+ readonly scrollTop: number;
405
+ readonly clientHeight: number;
406
+ }): boolean {
407
+ return pane.scrollHeight - pane.scrollTop - pane.clientHeight <= FOLLOW_SLACK;
408
+ }
409
+
410
+ /**
411
+ * Whether a pane goes on following its end once it scrolled: at its end it does; away from it
412
+ * by the hand of whoever reads, a wheel, a finger, a key or the bar, it does not; and away from
413
+ * it by itself it goes on as it was. A pane moves by itself whenever the conversation changes
414
+ * how tall it is, taller by what arrives and shorter while it is read again, and it is told so
415
+ * after the fact, when the conversation may have changed once more: where the pane stands says
416
+ * nothing then of who moved it.
417
+ */
418
+ export function followsAfter(
419
+ following: boolean,
420
+ byHand: boolean,
421
+ pane: {
422
+ readonly scrollHeight: number;
423
+ readonly scrollTop: number;
424
+ readonly clientHeight: number;
425
+ },
426
+ ): boolean {
427
+ if (followsEnd(pane)) {
428
+ return true;
429
+ }
430
+ return byHand ? false : following;
431
+ }
432
+
433
+ /** How long after a wheel, a touch, a key or a press on the pane a scroll is taken for the reader's own, in milliseconds. */
434
+ export const HAND_MS = 1200;
435
+
436
+ /** The first line of a text, for a row that shows one: cut where it is long. */
437
+ function firstLine(text: string, most = 160): string {
438
+ const line = text.split("\n").find((one) => one.trim().length > 0) ?? "";
439
+ return line.length > most ? `${line.slice(0, most)}…` : line;
440
+ }
441
+
442
+ /** A fact of an event as a word, or nothing where it is none. */
443
+ const word = (value: unknown): string | undefined =>
444
+ typeof value === "string" && value.length > 0 ? value : undefined;
445
+
446
+ /**
447
+ * What the record names in a word of its own, a signal's kind, an answer, a fact's name, in the
448
+ * page's words: the pack's word for it, or the word as it came where the pack has none, as for
449
+ * what a newer runner writes. Only a word the pack itself holds counts: what a runner sends is
450
+ * data, and a name every object has is no word of the pack.
451
+ */
452
+ export function wordOf(words: Readonly<Record<string, string>>, name: string): string {
453
+ return Object.hasOwn(words, name) ? (words[name] ?? name) : name;
454
+ }
455
+
456
+ /**
457
+ * What every line of a conversation is handed, the same from one render of the view to the
458
+ * next, so that a line is drawn again only when what it shows changed.
459
+ */
460
+ export interface TalkHands {
461
+ /** Where the bytes of a picture of the session are read. */
462
+ readonly fileHref: (fileId: string) => string;
463
+ /** Where the bytes of a file of a signal are read, where the view was told. */
464
+ readonly signalFileHref: ((number: number, fileId: string) => string) | undefined;
465
+ /** Reads the whole text of an event, where the view can. */
466
+ readonly readWhole: ((n: number) => void) | undefined;
467
+ readonly openPicture: PictureState["open"];
468
+ }
469
+
470
+ export interface TalkLineProps {
471
+ readonly one: TalkItem;
472
+ readonly hands: TalkHands;
473
+ /** The account's picture, beside what it said. */
474
+ readonly agent: RestPerson | undefined;
475
+ /** When the turn the line ends began, for a line that ends one. */
476
+ readonly began: string | undefined;
477
+ /** The files that came with what the agent was told, as the account's record names them. */
478
+ readonly files: readonly SignalFile[] | undefined;
479
+ /** The line's text read whole: its own, or its call's for a tool. */
480
+ readonly whole: string | undefined;
481
+ /** A tool's answer read whole. */
482
+ readonly wholeAnswer: string | undefined;
483
+ /** The event of the line whose whole text is being read, by its number. */
484
+ readonly reading: number | undefined;
485
+ /** The day it is: a moment of today is said by its hour alone, so a new day draws the lines again. */
486
+ readonly today: string;
487
+ }
488
+
489
+ /** Whether two things of a session are the same events: a thing is made anew each time the events are read through. */
490
+ function sameItem(a: TalkItem, b: TalkItem): boolean {
491
+ if (a.type === "tool" || b.type === "tool") {
492
+ return (
493
+ a.type === "tool" &&
494
+ b.type === "tool" &&
495
+ a.call === b.call &&
496
+ a.result === b.result &&
497
+ a.permission === b.permission
498
+ );
499
+ }
500
+ return a.type === b.type && a.event === b.event;
501
+ }
502
+
503
+ /** Whether two lists of a signal's files name the same files: the record is read again every few seconds. */
504
+ function sameFiles(
505
+ a: readonly SignalFile[] | undefined,
506
+ b: readonly SignalFile[] | undefined,
507
+ ): boolean {
508
+ if (a === b) {
509
+ return true;
510
+ }
511
+ return (
512
+ a !== undefined &&
513
+ b !== undefined &&
514
+ a.length === b.length &&
515
+ a.every((file, index) => {
516
+ const other = b[index];
517
+ return (
518
+ other !== undefined &&
519
+ file.id === other.id &&
520
+ file.name === other.name &&
521
+ file.size === other.size &&
522
+ file.contentType === other.contentType
523
+ );
524
+ })
525
+ );
526
+ }
527
+
528
+ /** Whether a line would be drawn the same: then it is not drawn again. */
529
+ export function sameLine(a: TalkLineProps, b: TalkLineProps): boolean {
530
+ return (
531
+ sameItem(a.one, b.one) &&
532
+ a.hands === b.hands &&
533
+ a.agent === b.agent &&
534
+ a.began === b.began &&
535
+ sameFiles(a.files, b.files) &&
536
+ a.whole === b.whole &&
537
+ a.wholeAnswer === b.wholeAnswer &&
538
+ a.reading === b.reading &&
539
+ a.today === b.today
540
+ );
541
+ }
542
+
543
+ /** When the turn an event ends began, by the event's number: the first thing the agent was sent after the turn before. */
544
+ export function turnStarts(events: readonly RestTranscriptEvent[]): ReadonlyMap<number, string> {
545
+ const starts = new Map<number, string>();
546
+ let since: string | undefined;
547
+ for (const event of events) {
548
+ if (event.kind === "status" && event.data.turn === "completed") {
549
+ if (since !== undefined) {
550
+ starts.set(event.n, since);
551
+ }
552
+ since = undefined;
553
+ } else if ((event.kind === "person" || event.kind === "wake") && since === undefined) {
554
+ since = event.at;
555
+ }
556
+ }
557
+ return starts;
558
+ }
559
+
560
+ /**
561
+ * What each line of a conversation is given, in order, with the number it is told apart by:
562
+ * its own events, and of everything the view holds only what the line itself shows, so that a
563
+ * line's props say the same until the line would be drawn otherwise.
564
+ */
565
+ export function talkLinesOf(input: {
566
+ readonly items: readonly TalkItem[];
567
+ readonly hands: TalkHands;
568
+ readonly agent: RestPerson | undefined;
569
+ readonly began: ReadonlyMap<number, string>;
570
+ readonly signalFiles: TranscriptViewProps["signalFiles"];
571
+ readonly whole: WholeTexts;
572
+ /** The session the events are of. */
573
+ readonly of: string | undefined;
574
+ /** The event whose whole text is being read, by its number. */
575
+ readonly reading: number | undefined;
576
+ readonly today: string;
577
+ }): readonly (TalkLineProps & { readonly key: number })[] {
578
+ const { whole, of, reading } = input;
579
+ return input.items.flatMap((one) => {
580
+ const main = one.type === "tool" ? one.call : one.event;
581
+ const answer = one.type === "tool" ? one.result : undefined;
582
+ const first = one.type === "tool" ? (main ?? one.permission ?? answer) : one.event;
583
+ if (first === undefined) {
584
+ return [];
585
+ }
586
+ const signal = one.type === "told" ? one.event.data.signal : undefined;
587
+ return [
588
+ {
589
+ key: first.n,
590
+ one,
591
+ hands: input.hands,
592
+ // The account's picture stands beside what it said, and nowhere else: what a
593
+ // sub-agent said is a step, with no picture, and is not drawn again for one.
594
+ agent: one.type === "said" && subagentOf(one.event) === undefined ? input.agent : undefined,
595
+ began: one.type === "tool" ? undefined : input.began.get(one.event.n),
596
+ files: typeof signal === "number" ? input.signalFiles?.(signal) : undefined,
597
+ whole: main === undefined ? undefined : wholeOf(whole, of, main.n),
598
+ wholeAnswer: answer === undefined ? undefined : wholeOf(whole, of, answer.n),
599
+ reading:
600
+ reading !== undefined && (reading === main?.n || reading === answer?.n)
601
+ ? reading
602
+ : undefined,
603
+ today: input.today,
604
+ },
605
+ ];
606
+ });
607
+ }
608
+
609
+ /**
610
+ * One line of a conversation. It is drawn again only when its own events, its own texts read
611
+ * whole or what it is handed changed: a session of thousands of events draws one line for an
612
+ * event that arrives, not all of them.
613
+ */
614
+ const TalkLine = memo(function TalkLine(props: TalkLineProps): ReactNode {
615
+ const all = useWords();
616
+ const words = all.agents.page.live;
617
+ const { one, hands } = props;
618
+ const kinds: Readonly<Record<string, string>> = words.kinds;
619
+ /** The words of an event, whole where they were read whole, with the way to read the rest. */
620
+ const text = (
621
+ event: RestTranscriptEvent,
622
+ className: string,
623
+ read: string | undefined,
624
+ ): ReactNode => {
625
+ const shown = read ?? event.text;
626
+ const readWhole = hands.readWhole;
627
+ return (
628
+ <>
629
+ {shown.length > 0 && <pre className={className}>{shown}</pre>}
630
+ {event.whole !== null && read === undefined && (
631
+ <p className="sc-talk-cut">
632
+ {words.cutAt(formatBytes(event.whole))}{" "}
633
+ {readWhole !== undefined && (
634
+ <Button
635
+ variant="ghost"
636
+ size="sm"
637
+ disabled={props.reading === event.n}
638
+ onClick={() => readWhole(event.n)}
639
+ >
640
+ {words.whole}
641
+ </Button>
642
+ )}
643
+ </p>
644
+ )}
645
+ </>
646
+ );
647
+ };
648
+ const pictures = (event: RestTranscriptEvent | undefined): ReactNode =>
649
+ event === undefined || event.files.length === 0 ? null : (
650
+ <ul className="sc-talk-pictures">
651
+ {event.files.map((file) => (
652
+ <li key={file.id}>
653
+ <PictureThumb
654
+ picture={{
655
+ src: hands.fileHref(file.id),
656
+ alt: file.name,
657
+ name: file.name,
658
+ size: file.size,
659
+ }}
660
+ onOpen={hands.openPicture}
661
+ />
662
+ </li>
663
+ ))}
664
+ </ul>
665
+ );
666
+ const when = (event: RestTranscriptEvent): ReactNode => <Time iso={event.at} precision="clock" />;
667
+ if (one.type === "tool") {
668
+ const first = one.call ?? one.permission ?? one.result;
669
+ if (first === undefined) {
670
+ return null;
671
+ }
672
+ const name = word(one.call?.data[TOOL]) ?? word(one.permission?.data[TOOL]);
673
+ const failed = one.result?.data.error === true;
674
+ const answer = word(one.permission?.data.answer);
675
+ const refused = answer !== undefined && answer !== "allowed";
676
+ const line = firstLine(one.call?.text ?? one.permission?.text ?? one.result?.text ?? "");
677
+ // Whose the call is, where a sub-agent made it: read off the line's own events, as
678
+ // everything a line shows is, so that it is drawn again only when they are others.
679
+ const sub = subagentOf(first);
680
+ return (
681
+ <li
682
+ className={cx(
683
+ "sc-talk-item",
684
+ "sc-talk-step",
685
+ "sc-talk-tool",
686
+ (failed || refused) && "sc-talk-tool-failed",
687
+ )}
688
+ data-n={first.n}
689
+ >
690
+ <details className="sc-talk-tool-fold">
691
+ <summary className="sc-talk-tool-head">
692
+ <code className="sc-talk-tool-name">{name ?? kinds.tool_call}</code>
693
+ <span className="sc-talk-tool-line">{line}</span>
694
+ {sub !== undefined && <Badge>{words.subagent(sub)}</Badge>}
695
+ {failed && <Badge tone="danger">{words.toolFailed}</Badge>}
696
+ {refused && <Badge tone="warning">{words.toolRefused}</Badge>}
697
+ {one.result === undefined && one.call !== undefined && !refused && (
698
+ <span className="sc-muted">{words.toolRunning}</span>
699
+ )}
700
+ {when(first)}
701
+ </summary>
702
+ <div className="sc-talk-tool-body">
703
+ {one.permission !== undefined && (
704
+ <p className="sc-talk-note-line">
705
+ {kinds.permission}
706
+ {answer === undefined ? "" : ` · ${wordOf(words.answers, answer)}`}
707
+ {one.permission.text.length > 0 && ` · ${one.permission.text}`}
708
+ </p>
709
+ )}
710
+ {one.call !== undefined && text(one.call, "sc-talk-code", props.whole)}
711
+ {one.result !== undefined &&
712
+ text(one.result, "sc-talk-code sc-talk-code-answer", props.wholeAnswer)}
713
+ </div>
714
+ </details>
715
+ {pictures(one.result)}
716
+ </li>
717
+ );
718
+ }
719
+ const { event } = one;
720
+ if (event.sealed !== null) {
721
+ return (
722
+ <li className="sc-talk-item sc-talk-note" data-n={event.n}>
723
+ <span className="sc-talk-note-line">
724
+ {words.sealed(
725
+ event.sealed.by === null ? "?" : (event.sealed.by.name ?? event.sealed.by.login),
726
+ event.sealed.reason,
727
+ )}
728
+ </span>
729
+ {when(event)}
730
+ </li>
731
+ );
732
+ }
733
+ if (one.type === "told") {
734
+ const number = typeof event.data.signal === "number" ? event.data.signal : undefined;
735
+ const kind = word(event.data.kind);
736
+ const through = word(event.data.agent);
737
+ const unseen = word(event.data.unseen);
738
+ const others = word(event.data.files);
739
+ const listed =
740
+ number === undefined
741
+ ? undefined
742
+ : props.files?.filter((file) => !isPicture(file.contentType));
743
+ const who = word(event.data.by) ?? words.kinds.person;
744
+ // An interrupt with no words of its own stopped the turn so that what waited is read: a
745
+ // note of who did, and no message.
746
+ if (
747
+ kind === "interrupt" &&
748
+ event.text.length === 0 &&
749
+ event.files.length === 0 &&
750
+ others === undefined
751
+ ) {
752
+ return (
753
+ <li className="sc-talk-item sc-talk-note" data-n={event.n}>
754
+ <span className="sc-talk-note-line">
755
+ {words.interrupted(who)}
756
+ {when(event)}
757
+ </span>
758
+ </li>
759
+ );
760
+ }
761
+ const signalFileHref = hands.signalFileHref;
762
+ return (
763
+ <li className="sc-talk-item sc-talk-told" data-n={event.n}>
764
+ <div className="sc-talk-bubble">
765
+ {text(event, "sc-talk-text", props.whole)}
766
+ {pictures(event)}
767
+ {listed !== undefined && listed.length > 0 ? (
768
+ <ul className="sc-chosen-files" aria-label={words.files}>
769
+ {listed.map((file) => (
770
+ <li key={file.id} className="sc-chosen-file">
771
+ {signalFileHref === undefined || number === undefined ? (
772
+ <span>{file.name}</span>
773
+ ) : (
774
+ <a href={signalFileHref(number, file.id)} download={file.name}>
775
+ {file.name}
776
+ </a>
777
+ )}{" "}
778
+ <span className="sc-muted">{formatBytes(file.size)}</span>
779
+ </li>
780
+ ))}
781
+ </ul>
782
+ ) : (
783
+ others !== undefined && (
784
+ <p className="sc-talk-note-line">
785
+ {words.files}: {others}
786
+ </p>
787
+ )
788
+ )}
789
+ {unseen !== undefined && (
790
+ <p className="sc-talk-note-line sc-talk-unseen">{words.unseen(unseen)}</p>
791
+ )}
792
+ </div>
793
+ <div className="sc-talk-meta">
794
+ <span className="sc-talk-who">{who}</span>
795
+ {through !== undefined && <span>{words.through(through)}</span>}
796
+ {kind !== undefined && kind !== "tell" && (
797
+ <Badge>{wordOf(words.signalKinds, kind)}</Badge>
798
+ )}
799
+ {when(event)}
800
+ </div>
801
+ {event.data.unread === true && (
802
+ <p className="sc-talk-note-line sc-talk-unread">{words.unread}</p>
803
+ )}
804
+ </li>
805
+ );
806
+ }
807
+ if (one.type === "said") {
808
+ const sub = subagentOf(event);
809
+ // What a sub-agent said is a step of the work, and not the agent's word to whoever reads:
810
+ // folded as a thought is, under the sub-agent's name.
811
+ if (sub !== undefined) {
812
+ return (
813
+ <li className="sc-talk-item sc-talk-step sc-talk-thought" data-n={event.n}>
814
+ <details className="sc-talk-tool-fold">
815
+ <summary className="sc-talk-tool-head">
816
+ <span className="sc-talk-kind">{kinds.assistant}</span>
817
+ <span className="sc-talk-tool-line">{firstLine(event.text)}</span>
818
+ <Badge>{words.subagent(sub)}</Badge>
819
+ {when(event)}
820
+ </summary>
821
+ <div className="sc-talk-tool-body">
822
+ {text(event, "sc-talk-text", props.whole)}
823
+ {pictures(event)}
824
+ </div>
825
+ </details>
826
+ </li>
827
+ );
828
+ }
829
+ return (
830
+ <li className="sc-talk-item sc-talk-said" data-n={event.n}>
831
+ {props.agent !== undefined && <Avatar person={props.agent} size="sm" />}
832
+ <div className="sc-talk-prose">
833
+ {text(event, "sc-talk-text", props.whole)}
834
+ {pictures(event)}
835
+ </div>
836
+ {when(event)}
837
+ </li>
838
+ );
839
+ }
840
+ if (one.type === "thought") {
841
+ const sub = subagentOf(event);
842
+ return (
843
+ <li className="sc-talk-item sc-talk-step sc-talk-thought" data-n={event.n}>
844
+ <details className="sc-talk-tool-fold">
845
+ <summary className="sc-talk-tool-head">
846
+ <span className="sc-talk-kind">{kinds.thinking}</span>
847
+ <span className="sc-talk-tool-line">{firstLine(event.text)}</span>
848
+ {sub !== undefined && <Badge>{words.subagent(sub)}</Badge>}
849
+ {when(event)}
850
+ </summary>
851
+ <div className="sc-talk-tool-body">{text(event, "sc-talk-text", props.whole)}</div>
852
+ </details>
853
+ </li>
854
+ );
855
+ }
856
+ // Where a turn ended: a line, with how long the agent was at it where the record says when it began.
857
+ if (event.kind === "status" && event.data.turn === "completed") {
858
+ const from = props.began;
859
+ const seconds =
860
+ from === undefined
861
+ ? undefined
862
+ : Math.max(0, Math.round((Date.parse(event.at) - Date.parse(from)) / 1000));
863
+ return (
864
+ <li className="sc-talk-item sc-talk-turn" data-n={event.n}>
865
+ <span className="sc-talk-note-line">
866
+ {words.turnDone(Number.isFinite(seconds) ? seconds : undefined)}
867
+ {when(event)}
868
+ </span>
869
+ </li>
870
+ );
871
+ }
872
+ // A wake, a status, an error, and whatever a newer runner calls otherwise: a note between.
873
+ // What the note's own words say already, how a session ended, is not said twice as a fact.
874
+ // The id of the call that started a sub-agent is for joining, and says nothing to a reader.
875
+ const facts = Object.entries(event.data).filter(
876
+ ([name, fact]) =>
877
+ fact !== null &&
878
+ name !== "signal" &&
879
+ name !== "kind" &&
880
+ name !== "ended" &&
881
+ name !== "parent",
882
+ );
883
+ const lines = event.text.split("\n").filter((line) => line.trim().length > 0);
884
+ return (
885
+ <li
886
+ className={cx("sc-talk-item", "sc-talk-note", event.kind === "error" && "sc-talk-note-error")}
887
+ data-n={event.n}
888
+ >
889
+ <span className="sc-talk-note-line">
890
+ <span className="sc-talk-kind">{kinds[event.kind] ?? event.kind}</span>
891
+ {facts.map(([name, fact]) => (
892
+ <span key={name} className="sc-talk-fact">
893
+ {wordOf(words.facts, name)} {String(fact)}
894
+ </span>
895
+ ))}
896
+ {lines.length === 1 && <span>{lines[0]}</span>}
897
+ {when(event)}
898
+ </span>
899
+ {lines.length > 1 && text(event, "sc-talk-text sc-talk-text-note", props.whole)}
900
+ {pictures(event)}
901
+ </li>
902
+ );
903
+ }, sameLine);
904
+
905
+ /**
906
+ * A session as a conversation: what the agent was told at the right, as whoever said it wrote
907
+ * it, with the files that came with it; what the agent said at the left, beside its picture; its
908
+ * thoughts folded; a tool's call and what it answered as one row that opens, the steps of a turn
909
+ * close together; a wake, a status and an error as notes between, and a line where a turn
910
+ * ended, with how long it took. A picture opens large over the page. Everything an agent's
911
+ * product printed is text, never markup. Each line is drawn once and again only when it
912
+ * changed, however long the session is.
913
+ */
914
+ export function TranscriptView(props: TranscriptViewProps) {
915
+ const words = useWords().agents.page.live;
916
+ const shown = usePicture();
917
+ // What was read whole belongs to the session it was read in: the events of another carry the
918
+ // same numbers, and a view that goes on to show them must show none of this.
919
+ const [whole, setWhole] = useState<WholeTexts>(NO_WHOLE);
920
+ const [reading, setReading] = useState<
921
+ { readonly of: string | undefined; readonly n: number } | undefined
922
+ >(undefined);
923
+ const of = props.of;
924
+ const showing = useRef(of);
925
+ showing.current = of;
926
+ // What the view is given may be made anew by whoever renders it; the lines are handed the
927
+ // same hands each time, which reach for what was given last.
928
+ const given = useRef(props);
929
+ given.current = props;
930
+ const readWhole = useCallback(
931
+ (n: number) => {
932
+ const load = given.current.onReadWhole;
933
+ if (load === undefined) {
934
+ return;
935
+ }
936
+ setReading({ of, n });
937
+ void load(n)
938
+ .then((text) => {
939
+ // An answer that arrives once another session is shown is that session's no more.
940
+ if (showing.current === of) {
941
+ setWhole((current) => withWhole(current, of, n, text));
942
+ }
943
+ })
944
+ .catch(() => undefined)
945
+ .finally(() =>
946
+ setReading((current) =>
947
+ current !== undefined && current.of === of && current.n === n ? undefined : current,
948
+ ),
949
+ );
950
+ },
951
+ [of],
952
+ );
953
+ const reads = props.onReadWhole !== undefined;
954
+ const hasSignalFiles = props.signalFileHref !== undefined;
955
+ const openPicture = shown.open;
956
+ const hands = useMemo<TalkHands>(
957
+ () => ({
958
+ fileHref: (fileId) => given.current.fileHref(fileId),
959
+ signalFileHref: hasSignalFiles
960
+ ? (number, fileId) => given.current.signalFileHref?.(number, fileId) ?? ""
961
+ : undefined,
962
+ readWhole: reads ? readWhole : undefined,
963
+ openPicture,
964
+ }),
965
+ [hasSignalFiles, reads, readWhole, openPicture],
966
+ );
967
+ const events = props.events;
968
+ const items = useMemo(() => talkOf(events), [events]);
969
+ const began = useMemo(() => turnStarts(events), [events]);
970
+ if (events.length === 0) {
971
+ return (
972
+ <>
973
+ {props.empty ?? null}
974
+ {props.foot !== undefined && props.foot !== null && (
975
+ <ol className="sc-talk" aria-label={words.transcript}>
976
+ {props.foot}
977
+ </ol>
978
+ )}
979
+ </>
980
+ );
981
+ }
982
+ const lines = talkLinesOf({
983
+ items,
984
+ hands,
985
+ agent: props.agent,
986
+ began,
987
+ signalFiles: props.signalFiles,
988
+ whole,
989
+ of,
990
+ reading: reading !== undefined && reading.of === of ? reading.n : undefined,
991
+ today: today(),
992
+ });
993
+ return (
994
+ <>
995
+ <ol className="sc-talk" aria-label={words.transcript}>
996
+ {lines.map(({ key, ...line }) => (
997
+ <TalkLine key={key} {...line} />
998
+ ))}
999
+ {props.foot}
1000
+ </ol>
1001
+ <Lightbox picture={shown.shown} onClose={shown.close} />
1002
+ </>
1003
+ );
1004
+ }
1005
+
1006
+ export interface TalkWaitingProps {
1007
+ /** The words that wait, the oldest first: `waitingOf` says which. */
1008
+ readonly signals: readonly RestSignal[];
1009
+ /**
1010
+ * Why they wait, which says when they are read: a turn under way that the product takes a
1011
+ * message in (`call`) or takes none in (`turn`), an agent that is stopped, a runner not heard
1012
+ * from, or nothing but the moment it takes to hand them over (`soon`).
1013
+ */
1014
+ readonly why: "call" | "turn" | "stopped" | "unheard" | "soon";
1015
+ /** Where the bytes of a file of a signal are read. */
1016
+ readonly fileHref?: ((number: number, fileId: string) => string) | undefined;
1017
+ readonly busy?: boolean | undefined;
1018
+ /**
1019
+ * Stops the turn under way so that what waits is read now. Left out, or with no turn to
1020
+ * stop, there is no such way.
1021
+ */
1022
+ readonly onInterrupt?: (() => void) | undefined;
1023
+ }
1024
+
1025
+ /**
1026
+ * What supervisors said and the agent has not taken yet, at the foot of the conversation: each
1027
+ * as it will stand there, quieter, with when it is read; and under the last, while a turn is
1028
+ * under way, the way to have them read now. Rows of the conversation's list.
1029
+ */
1030
+ export function TalkWaiting(props: TalkWaitingProps) {
1031
+ const words = useWords().agents.page.live;
1032
+ const waits = words.waiting;
1033
+ if (props.signals.length === 0) {
1034
+ return null;
1035
+ }
1036
+ const stops = props.onInterrupt !== undefined && (props.why === "call" || props.why === "turn");
1037
+ return (
1038
+ <>
1039
+ {props.signals.map((signal, index) => {
1040
+ const last = index === props.signals.length - 1;
1041
+ const pictures = signal.attachments.filter((file) => isPicture(file.contentType));
1042
+ const others = signal.attachments.filter((file) => !isPicture(file.contentType));
1043
+ return (
1044
+ <li
1045
+ key={signal.number}
1046
+ className="sc-talk-item sc-talk-told sc-talk-waiting"
1047
+ data-signal={signal.number}
1048
+ >
1049
+ <div className="sc-talk-bubble">
1050
+ {signal.text.length > 0 && <pre className="sc-talk-text">{signal.text}</pre>}
1051
+ {pictures.length > 0 && props.fileHref !== undefined && (
1052
+ <ul className="sc-talk-pictures">
1053
+ {pictures.map((file) => (
1054
+ <li key={file.id}>
1055
+ <img
1056
+ src={props.fileHref?.(signal.number, file.id)}
1057
+ alt={file.name}
1058
+ title={`${file.name} · ${formatBytes(file.size)}`}
1059
+ loading="lazy"
1060
+ />
1061
+ </li>
1062
+ ))}
1063
+ </ul>
1064
+ )}
1065
+ {others.length > 0 && (
1066
+ <ul className="sc-chosen-files" aria-label={words.files}>
1067
+ {others.map((file) => (
1068
+ <li key={file.id} className="sc-chosen-file">
1069
+ <span>{file.name}</span>{" "}
1070
+ <span className="sc-muted">{formatBytes(file.size)}</span>
1071
+ </li>
1072
+ ))}
1073
+ </ul>
1074
+ )}
1075
+ </div>
1076
+ <div className="sc-talk-meta">
1077
+ <span className="sc-talk-who">
1078
+ {signal.by === null ? words.kinds.person : personName(signal.by)}
1079
+ </span>
1080
+ <Time iso={signal.at} precision="clock" />
1081
+ </div>
1082
+ {last && (
1083
+ <p className="sc-talk-wait" role="status">
1084
+ <span>{waits[props.why]}</span>
1085
+ {stops && (
1086
+ <Button
1087
+ size="sm"
1088
+ disabled={props.busy === true}
1089
+ title={waits.interruptHint}
1090
+ onClick={props.onInterrupt}
1091
+ >
1092
+ {waits.interrupt}
1093
+ </Button>
1094
+ )}
1095
+ </p>
1096
+ )}
1097
+ </li>
1098
+ );
1099
+ })}
1100
+ </>
1101
+ );
1102
+ }
1103
+
1104
+ /**
1105
+ * The sign that the agent is at work while a turn is under way: its picture, three dots, and
1106
+ * what it is at, a thought, a tool by its name, or the work between. A row of the
1107
+ * conversation's list; nothing where no turn is under way.
1108
+ */
1109
+ export function TalkWorking(props: {
1110
+ readonly working: Working | undefined;
1111
+ readonly agent?: RestPerson | undefined;
1112
+ }) {
1113
+ const words = useWords().agents.page.live.working;
1114
+ const { working } = props;
1115
+ if (working === undefined) {
1116
+ return null;
1117
+ }
1118
+ return (
1119
+ <li className="sc-talk-item sc-talk-working" role="status">
1120
+ {props.agent !== undefined && <Avatar person={props.agent} size="sm" />}
1121
+ <span className="sc-talk-dots" aria-hidden="true">
1122
+ <span />
1123
+ <span />
1124
+ <span />
1125
+ </span>
1126
+ <span>
1127
+ {working.at === "tool"
1128
+ ? working.tool === undefined
1129
+ ? words.working
1130
+ : words.tool(working.tool)
1131
+ : words[working.at]}
1132
+ </span>
1133
+ </li>
1134
+ );
1135
+ }
1136
+
1137
+ export interface ChatPaneProps {
1138
+ /** What the pane is called to a screen reader. */
1139
+ readonly label: string;
1140
+ /** The conversation: whatever is read in the pane, which scrolls by itself. */
1141
+ readonly children: ReactNode;
1142
+ /** The box to speak in, at the pane's foot, always in sight. */
1143
+ readonly composer?: ReactNode;
1144
+ /**
1145
+ * Changes when whoever reads said something: the pane goes to its end and follows from
1146
+ * there, wherever they had scrolled to.
1147
+ */
1148
+ readonly said?: number | undefined;
1149
+ }
1150
+
1151
+ /**
1152
+ * A conversation in a pane of its own, as a chat is read: it scrolls within the pane, with the
1153
+ * box to speak in at its foot. The pane follows the conversation's end while whoever reads is
1154
+ * there, leaves them where they are once they scrolled up to read, and then offers the way
1155
+ * back to the latest, saying when something arrived meanwhile.
1156
+ */
1157
+ export function ChatPane(props: ChatPaneProps) {
1158
+ const words = useWords().agents.page.live;
1159
+ const scroller = useRef<HTMLDivElement>(null);
1160
+ const content = useRef<HTMLDivElement>(null);
1161
+ const whole = useRef<HTMLElement>(null);
1162
+ /** Whether the pane follows its end: true until whoever reads scrolls away from it. */
1163
+ const follows = useRef(true);
1164
+ /** Until when a scroll is taken for the reader's own: set by what a hand does to the pane. */
1165
+ const hand = useRef(0);
1166
+ const [away, setAway] = useState(false);
1167
+ const [fresh, setFresh] = useState(false);
1168
+ const toEnd = () => {
1169
+ const pane = scroller.current;
1170
+ if (pane !== null) {
1171
+ follows.current = true;
1172
+ pane.scrollTop = pane.scrollHeight;
1173
+ setAway(false);
1174
+ setFresh(false);
1175
+ }
1176
+ };
1177
+ // The pane is as tall as the window leaves under what stands over it on the page, so that
1178
+ // the box to speak in is in sight without scrolling: where it begins is measured, here and
1179
+ // whenever the page is drawn again or the window changes, and the stylesheet takes it from there.
1180
+ useEffect(() => {
1181
+ const measure = () => {
1182
+ const pane = whole.current;
1183
+ if (pane !== null) {
1184
+ const top = Math.round(pane.getBoundingClientRect().top + window.scrollY);
1185
+ pane.style.setProperty("--sc-chat-top", `${top}px`);
1186
+ }
1187
+ };
1188
+ measure();
1189
+ window.addEventListener("resize", measure);
1190
+ return () => window.removeEventListener("resize", measure);
1191
+ });
1192
+ useEffect(() => {
1193
+ const pane = scroller.current;
1194
+ const inner = content.current;
1195
+ if (pane === null || inner === null) {
1196
+ return;
1197
+ }
1198
+ const now = () => (typeof performance === "undefined" ? Date.now() : performance.now());
1199
+ const onHand = () => {
1200
+ hand.current = now() + HAND_MS;
1201
+ };
1202
+ const onScroll = () => {
1203
+ const byHand = now() < hand.current;
1204
+ const goes = followsAfter(follows.current, byHand, pane);
1205
+ follows.current = goes;
1206
+ setAway(!goes);
1207
+ if (goes) {
1208
+ setFresh(false);
1209
+ // Moved by itself while it follows: the conversation changed under it, so back to its end.
1210
+ if (!byHand && !followsEnd(pane)) {
1211
+ pane.scrollTop = pane.scrollHeight;
1212
+ }
1213
+ } else if (byHand) {
1214
+ // A finger let go goes on scrolling for a while: each step of it is still the reader's.
1215
+ hand.current = now() + HAND_MS;
1216
+ }
1217
+ };
1218
+ pane.addEventListener("scroll", onScroll, { passive: true });
1219
+ const hands = ["wheel", "touchstart", "touchmove", "pointerdown", "keydown"] as const;
1220
+ for (const name of hands) {
1221
+ pane.addEventListener(name, onHand, { passive: true });
1222
+ }
1223
+ // What arrives, and a picture that loads late, change how tall the conversation is: the
1224
+ // pane goes with it while it is followed, and says that there is more where it is not.
1225
+ const observer =
1226
+ typeof ResizeObserver === "undefined"
1227
+ ? undefined
1228
+ : new ResizeObserver(() => {
1229
+ if (follows.current) {
1230
+ pane.scrollTop = pane.scrollHeight;
1231
+ } else {
1232
+ setFresh(true);
1233
+ }
1234
+ });
1235
+ observer?.observe(inner);
1236
+ pane.scrollTop = pane.scrollHeight;
1237
+ return () => {
1238
+ pane.removeEventListener("scroll", onScroll);
1239
+ for (const name of hands) {
1240
+ pane.removeEventListener(name, onHand);
1241
+ }
1242
+ observer?.disconnect();
1243
+ };
1244
+ }, []);
1245
+ // biome-ignore lint/correctness/useExhaustiveDependencies: `said` is the trigger
1246
+ useEffect(() => {
1247
+ if (props.said !== undefined && props.said > 0) {
1248
+ toEnd();
1249
+ }
1250
+ }, [props.said]);
1251
+ return (
1252
+ <section className="sc-panel sc-chat" aria-label={props.label} ref={whole}>
1253
+ <div className="sc-chat-scroll" ref={scroller}>
1254
+ <div className="sc-chat-content" ref={content}>
1255
+ {props.children}
1256
+ </div>
1257
+ </div>
1258
+ {away && (
1259
+ <div className="sc-chat-latest">
1260
+ <Button size="sm" onClick={toEnd}>
1261
+ {fresh ? words.latestNew : words.latest}
1262
+ </Button>
1263
+ </div>
1264
+ )}
1265
+ {props.composer !== undefined && props.composer !== null && (
1266
+ <div className="sc-chat-foot">{props.composer}</div>
1267
+ )}
1268
+ </section>
1269
+ );
1270
+ }
1271
+
1272
+ /**
1273
+ * The files of a tell with the ones just chosen added: a file that is there already is not
1274
+ * added again, so that nothing is sent twice.
1275
+ */
1276
+ export function withChosen(current: readonly File[], chosen: readonly File[]): readonly File[] {
1277
+ const same = (one: File, other: File): boolean =>
1278
+ one.name === other.name && one.size === other.size && one.lastModified === other.lastModified;
1279
+ const added: File[] = [];
1280
+ for (const file of chosen) {
1281
+ if (![...current, ...added].some((one) => same(one, file))) {
1282
+ added.push(file);
1283
+ }
1284
+ }
1285
+ return [...current, ...added];
1286
+ }
1287
+
1288
+ /** The files of a tell without the one at a place: what the way out of its chip leaves. */
1289
+ export function withoutChosen(current: readonly File[], at: number): readonly File[] {
1290
+ return current.filter((_, index) => index !== at);
1291
+ }
1292
+
1293
+ /**
1294
+ * Whether a key pressed in the box tells what is written: Enter alone, as the boxes of agent
1295
+ * products have it, with Shift for a new line; and never while a word is still being composed,
1296
+ * as Korean is, where Enter ends the composing and not the message.
1297
+ */
1298
+ export function tellsWith(event: {
1299
+ readonly key: string;
1300
+ readonly shiftKey?: boolean;
1301
+ readonly isComposing?: boolean;
1302
+ readonly keyCode?: number;
1303
+ }): boolean {
1304
+ // 229 is what a browser says of a key pressed while composing, where it says nothing else.
1305
+ return (
1306
+ event.key === "Enter" &&
1307
+ event.shiftKey !== true &&
1308
+ event.isComposing !== true &&
1309
+ event.keyCode !== 229
1310
+ );
1311
+ }
1312
+
1313
+ /** A picture pasted from a clipboard is called `image.png` by every browser: a name of its own, by the moment. */
1314
+ export function pastedName(file: File, at: Date): string {
1315
+ if (file.name !== "image.png" && file.name.length > 0) {
1316
+ return file.name;
1317
+ }
1318
+ const two = (value: number): string => String(value).padStart(2, "0");
1319
+ const stamp = `${at.getFullYear()}${two(at.getMonth() + 1)}${two(at.getDate())}-${two(at.getHours())}${two(at.getMinutes())}${two(at.getSeconds())}`;
1320
+ const ending = file.type === "image/jpeg" ? "jpg" : (file.type.split("/")[1] ?? "png");
1321
+ return `pasted-${stamp}.${ending}`;
1322
+ }
1323
+
1324
+ /**
1325
+ * Whether what was told was taken, by what whoever tells answered: `false`, or a request that
1326
+ * failed, says it was not, and the box keeps what was written; anything else, nothing among it,
1327
+ * says it was, so that a handler that answers nothing is taken at its word.
1328
+ */
1329
+ export async function takenBy(answer: unknown): Promise<boolean> {
1330
+ try {
1331
+ return (await answer) !== false;
1332
+ } catch {
1333
+ return false;
1334
+ }
1335
+ }
1336
+
1337
+ /**
1338
+ * What stands in the box once what was sent from it was taken: nothing, or what was written
1339
+ * after it while the console was asked; words changed meanwhile are another message, and stay.
1340
+ */
1341
+ export function afterTold(current: string, sent: string): string {
1342
+ return current.startsWith(sent) ? current.slice(sent.length).trimStart() : current;
1343
+ }
1344
+
1345
+ /** How tall the box grows with what is written in it, before it scrolls. */
1346
+ const MAX_BOX_PIXELS = 280;
1347
+
1348
+ /** A picture is shown small beside its name where it is no larger than this: a larger one is named alone. */
1349
+ const MAX_PREVIEW_BYTES = 4 * 1024 * 1024;
1350
+
1351
+ export interface SignalComposerProps {
1352
+ /** How the agent stands: a stopped agent is told nothing until it is started again, and the box says so. */
1353
+ readonly state: AgentState | undefined;
1354
+ /**
1355
+ * Whether the agent's product takes a picture (`offers.images`): where it takes none, a
1356
+ * picture is handed over as a file in its desk, and the box says so before it is sent.
1357
+ */
1358
+ readonly images?: boolean | undefined;
1359
+ readonly busy?: boolean | undefined;
1360
+ /** What went wrong with what was sent last, as a line under the box. */
1361
+ readonly note?: ReactNode;
1362
+ /**
1363
+ * Tells the agent what was written, with the files chosen. Where it answers whether the tell
1364
+ * was taken, itself or as a promise, `false` or a failure keeps the words and the files in the
1365
+ * box, to be sent again, and the box is emptied only once the tell was taken; where it answers
1366
+ * nothing, the box is emptied as it is sent.
1367
+ */
1368
+ readonly onSend: (text: string, files: readonly FileUpload[]) => unknown;
1369
+ }
1370
+
1371
+ /**
1372
+ * What a supervisor says to the agent, as the box of a chat is: one box with the words, the
1373
+ * files chosen, pasted or dropped on it above them, a picture shown small and any other file by
1374
+ * its name, each taken out again from its chip, and under the words the way to choose files and
1375
+ * the way to send. Enter tells; Shift with Enter is a new line. What is told stands in the
1376
+ * conversation at once, as waiting until the agent takes it, and the way to have it read now is
1377
+ * there, beside it: the box has none. What changes how the agent stands, a stop, a restart, a
1378
+ * reset, is not said here: `AgentControls` has it.
1379
+ */
1380
+ export function SignalComposer(props: SignalComposerProps) {
1381
+ const words = useWords().agents.page.tell;
1382
+ const [text, setText] = useState("");
1383
+ const [files, setFiles] = useState<readonly File[]>([]);
1384
+ const [previews, setPreviews] = useState<Readonly<Record<string, string>>>({});
1385
+ const [over, setOver] = useState(false);
1386
+ /** Whether a tell is on its way: nothing more is sent until the console answered. */
1387
+ const [sending, setSending] = useState(false);
1388
+ const box = useRef<HTMLTextAreaElement>(null);
1389
+ // The box grows with what is written in it, lines that wrap among them, up to a bound.
1390
+ // biome-ignore lint/correctness/useExhaustiveDependencies: `text` is the trigger
1391
+ useEffect(() => {
1392
+ const area = box.current;
1393
+ if (area !== null) {
1394
+ area.style.height = "auto";
1395
+ area.style.height = `${Math.min(area.scrollHeight + 2, MAX_BOX_PIXELS)}px`;
1396
+ }
1397
+ }, [text]);
1398
+ const said = text.trim();
1399
+ const busy = props.busy === true;
1400
+ const tooMany = files.length > MAX_SIGNAL_ATTACHMENTS;
1401
+ const tooLarge = files.reduce((total, file) => total + file.size, 0) > MAX_FILE_BYTES;
1402
+ const keyOf = (file: File): string => `${file.name}-${file.size}-${file.lastModified}`;
1403
+ const add = (chosen: readonly File[]) => {
1404
+ if (chosen.length === 0) {
1405
+ return;
1406
+ }
1407
+ setFiles((current) => withChosen(current, chosen));
1408
+ // A picture is read here to be shown small: the page's policy takes a picture as data.
1409
+ for (const file of chosen) {
1410
+ if (
1411
+ isPicture(file.type) &&
1412
+ file.size <= MAX_PREVIEW_BYTES &&
1413
+ typeof FileReader !== "undefined"
1414
+ ) {
1415
+ const reader = new FileReader();
1416
+ reader.onload = () => {
1417
+ const read = reader.result;
1418
+ if (typeof read === "string") {
1419
+ setPreviews((current) => ({ ...current, [keyOf(file)]: read }));
1420
+ }
1421
+ };
1422
+ reader.readAsDataURL(file);
1423
+ }
1424
+ }
1425
+ };
1426
+ const send = () => {
1427
+ const written = text;
1428
+ const sent = files;
1429
+ const answer = props.onSend(
1430
+ said,
1431
+ sent.map((file) => ({ name: file.name, bytes: file, contentType: file.type })),
1432
+ );
1433
+ setSending(true);
1434
+ // What was written stays until the console took it: a refusal, or a request that failed,
1435
+ // leaves the words and the files where they are, with what went wrong said under them.
1436
+ void takenBy(answer).then((taken) => {
1437
+ setSending(false);
1438
+ if (!taken) {
1439
+ return;
1440
+ }
1441
+ setText((current) => afterTold(current, written));
1442
+ setFiles((current) => current.filter((file) => !sent.includes(file)));
1443
+ setPreviews((current) =>
1444
+ Object.fromEntries(
1445
+ Object.entries(current).filter(([key]) => !sent.some((file) => keyOf(file) === key)),
1446
+ ),
1447
+ );
1448
+ });
1449
+ };
1450
+ const ready = said.length > 0 && !tooMany && !tooLarge && !busy && !sending;
1451
+ const submit = (event: FormEvent) => {
1452
+ event.preventDefault();
1453
+ if (ready) {
1454
+ send();
1455
+ }
1456
+ };
1457
+ const stopped = props.state === "stopped";
1458
+ const unseen = props.images === false && files.some((file) => isPicture(file.type));
1459
+ return (
1460
+ <form
1461
+ className={cx("sc-signal-composer", over && "sc-signal-composer-over")}
1462
+ aria-label={words.aria}
1463
+ onSubmit={submit}
1464
+ onDragOver={(event) => {
1465
+ if (event.dataTransfer.types.includes("Files")) {
1466
+ event.preventDefault();
1467
+ setOver(true);
1468
+ }
1469
+ }}
1470
+ onDragLeave={() => setOver(false)}
1471
+ onDrop={(event) => {
1472
+ if (event.dataTransfer.files.length > 0) {
1473
+ event.preventDefault();
1474
+ add([...event.dataTransfer.files]);
1475
+ }
1476
+ setOver(false);
1477
+ }}
1478
+ >
1479
+ <div className="sc-signal-box">
1480
+ {files.length > 0 && (
1481
+ <ul className="sc-chosen-files sc-signal-files" aria-label={words.files}>
1482
+ {files.map((file, index) => {
1483
+ const preview = previews[keyOf(file)];
1484
+ return (
1485
+ <li key={keyOf(file)} className="sc-chosen-file">
1486
+ {preview !== undefined && (
1487
+ <img className="sc-signal-thumb" src={preview} alt="" />
1488
+ )}
1489
+ <span className="sc-signal-file-name">{file.name}</span>{" "}
1490
+ <span className="sc-muted">{formatBytes(file.size)}</span>{" "}
1491
+ <Button
1492
+ variant="ghost"
1493
+ size="sm"
1494
+ aria-label={words.removeFile(file.name)}
1495
+ onClick={() => setFiles((current) => withoutChosen(current, index))}
1496
+ >
1497
+ ×
1498
+ </Button>
1499
+ </li>
1500
+ );
1501
+ })}
1502
+ </ul>
1503
+ )}
1504
+ <textarea
1505
+ ref={box}
1506
+ className="sc-signal-text"
1507
+ aria-label={words.placeholder}
1508
+ placeholder={stopped ? words.placeholderStopped : words.placeholder}
1509
+ value={text}
1510
+ maxLength={MAX_SIGNAL_LENGTH}
1511
+ rows={1}
1512
+ onChange={(event) => setText(event.target.value)}
1513
+ onPaste={(event) => {
1514
+ const pasted = [...event.clipboardData.files];
1515
+ if (pasted.length > 0) {
1516
+ event.preventDefault();
1517
+ const now = new Date();
1518
+ add(
1519
+ pasted.map((file) => new File([file], pastedName(file, now), { type: file.type })),
1520
+ );
1521
+ }
1522
+ }}
1523
+ onKeyDown={(event) => {
1524
+ // On a screen that is touched, Enter is the keyboard's new line: the button tells.
1525
+ if (
1526
+ typeof window !== "undefined" &&
1527
+ window.matchMedia?.("(pointer: coarse)").matches === true
1528
+ ) {
1529
+ return;
1530
+ }
1531
+ if (
1532
+ tellsWith({
1533
+ key: event.key,
1534
+ shiftKey: event.shiftKey,
1535
+ isComposing: event.nativeEvent.isComposing,
1536
+ keyCode: event.keyCode,
1537
+ })
1538
+ ) {
1539
+ event.preventDefault();
1540
+ if (ready) {
1541
+ send();
1542
+ }
1543
+ }
1544
+ }}
1545
+ />
1546
+ <div className="sc-signal-row">
1547
+ <label className="sc-button sc-button-ghost sc-button-sm sc-file-choice">
1548
+ {words.attach}
1549
+ <input
1550
+ className="sc-file-input"
1551
+ type="file"
1552
+ multiple
1553
+ onChange={(event) => {
1554
+ add([...(event.target.files ?? [])]);
1555
+ // The box is emptied, so that a file taken out can be chosen again.
1556
+ event.target.value = "";
1557
+ }}
1558
+ />
1559
+ </label>
1560
+ <Button type="submit" variant="primary" size="sm" disabled={!ready}>
1561
+ {words.send}
1562
+ </Button>
1563
+ </div>
1564
+ </div>
1565
+ {tooMany && (
1566
+ <p className="sc-form-error" role="alert">
1567
+ {words.tooMany(MAX_SIGNAL_ATTACHMENTS)}
1568
+ </p>
1569
+ )}
1570
+ {tooLarge && (
1571
+ <p className="sc-form-error" role="alert">
1572
+ {words.tooLarge(formatBytes(MAX_FILE_BYTES))}
1573
+ </p>
1574
+ )}
1575
+ {files.length > 0 && said.length === 0 && <p className="sc-field-hint">{words.needsWords}</p>}
1576
+ {unseen && <p className="sc-field-hint">{words.unseen}</p>}
1577
+ {props.note !== undefined && <p className="sc-field-hint">{props.note}</p>}
1578
+ </form>
1579
+ );
1580
+ }
1581
+
1582
+ export interface AgentControlsProps {
1583
+ /** How the agent stands, by which what is offered is chosen: a running agent is stopped, one that is not is started again. */
1584
+ readonly state: AgentState | undefined;
1585
+ readonly busy?: boolean | undefined;
1586
+ /**
1587
+ * Sends a stop, a restart or a reset, with the words for the agent where any were written.
1588
+ * What it answers says whether the signal was taken, as the box to speak in is answered:
1589
+ * `false`, or a request that failed, leaves the words where they are.
1590
+ */
1591
+ readonly onSend: (kind: "stop" | "restart" | "reset", text: string) => unknown;
1592
+ /** What was sent last, as a line under the ways. */
1593
+ readonly note?: ReactNode;
1594
+ }
1595
+
1596
+ /**
1597
+ * What changes how the agent stands, apart from what is said to it: a stop, which holds until
1598
+ * it is started again; a restart, which goes on with the same conversation; a reset, which
1599
+ * begins a new one and is asked twice. Each with words for the agent, where its supervisor has
1600
+ * any, and with what it does said under it.
1601
+ */
1602
+ export function AgentControls(props: AgentControlsProps) {
1603
+ const words = useWords().agents.page.tell;
1604
+ const [text, setText] = useState("");
1605
+ const [resetting, setResetting] = useState(false);
1606
+ const busy = props.busy === true;
1607
+ const send = (kind: "stop" | "restart" | "reset") => {
1608
+ const answer = props.onSend(kind, text.trim());
1609
+ setResetting(false);
1610
+ // The words stay until the console took the signal, as what is told does.
1611
+ void takenBy(answer).then((taken) => {
1612
+ if (taken) {
1613
+ setText("");
1614
+ }
1615
+ });
1616
+ };
1617
+ const running = props.state === "running";
1618
+ const stopped = props.state === "stopped";
1619
+ return (
1620
+ <div className="sc-agent-controls">
1621
+ <label className="sc-field">
1622
+ <span className="sc-field-label">{words.controlWords}</span>
1623
+ <input
1624
+ className="sc-input"
1625
+ value={text}
1626
+ maxLength={MAX_SIGNAL_LENGTH}
1627
+ placeholder={words.controlWordsPlaceholder}
1628
+ onChange={(event) => setText(event.target.value)}
1629
+ />
1630
+ </label>
1631
+ <div className="sc-agent-controls-ways">
1632
+ {!running && (
1633
+ <Button size="sm" disabled={busy} onClick={() => send("restart")}>
1634
+ {words.restart}
1635
+ </Button>
1636
+ )}
1637
+ {!stopped && (
1638
+ <Button size="sm" disabled={busy} onClick={() => send("stop")}>
1639
+ {words.stop}
1640
+ </Button>
1641
+ )}
1642
+ {resetting ? (
1643
+ <>
1644
+ <Button variant="danger" size="sm" disabled={busy} onClick={() => send("reset")}>
1645
+ {words.resetConfirm}
1646
+ </Button>
1647
+ <Button variant="ghost" size="sm" disabled={busy} onClick={() => setResetting(false)}>
1648
+ {words.cancel}
1649
+ </Button>
1650
+ </>
1651
+ ) : (
1652
+ <Button variant="ghost" size="sm" disabled={busy} onClick={() => setResetting(true)}>
1653
+ {words.reset}
1654
+ </Button>
1655
+ )}
1656
+ </div>
1657
+ {props.note !== undefined && props.note !== null && (
1658
+ <p className="sc-field-hint" role="status">
1659
+ {props.note}
1660
+ </p>
1661
+ )}
1662
+ {resetting ? (
1663
+ <Callout tone="warning">{words.resetWarning}</Callout>
1664
+ ) : (
1665
+ <ul className="sc-agent-controls-says">
1666
+ {!running && (
1667
+ <li>
1668
+ <b>{words.restart}</b> {words.restartHint}
1669
+ </li>
1670
+ )}
1671
+ {!stopped && (
1672
+ <li>
1673
+ <b>{words.stop}</b> {words.stopHint}
1674
+ </li>
1675
+ )}
1676
+ <li>
1677
+ <b>{words.reset}</b> {words.resetHint}
1678
+ </li>
1679
+ </ul>
1680
+ )}
1681
+ </div>
1682
+ );
1683
+ }
1684
+
1685
+ export interface AgentChoiceProps {
1686
+ readonly runner: RestAgentRunner | null | undefined;
1687
+ readonly busy?: boolean | undefined;
1688
+ /** Sets what is named; `null` for the product's own again. */
1689
+ readonly onSet: (choice: { model?: string | null; effort?: string | null }) => void;
1690
+ }
1691
+
1692
+ /** The model and the level of effort an agent runs with, chosen from what its product offers. */
1693
+ export function AgentChoice(props: AgentChoiceProps) {
1694
+ const words = useWords().agents.page.choice;
1695
+ const runner = props.runner ?? null;
1696
+ const offers = runner?.offers ?? null;
1697
+ if (
1698
+ runner === null ||
1699
+ offers === null ||
1700
+ (offers.models.length === 0 && offers.efforts.length === 0)
1701
+ ) {
1702
+ return <p className="sc-field-hint">{words.none}</p>;
1703
+ }
1704
+ const select = (
1705
+ label: string,
1706
+ name: "model" | "effort",
1707
+ offered: readonly string[],
1708
+ chosen: string | null,
1709
+ ) =>
1710
+ offered.length === 0 ? null : (
1711
+ <label className="sc-field sc-agent-choice-field">
1712
+ <span className="sc-field-label">{label}</span>
1713
+ <select
1714
+ className="sc-input"
1715
+ value={chosen ?? ""}
1716
+ disabled={props.busy === true}
1717
+ onChange={(event) =>
1718
+ props.onSet({ [name]: event.target.value === "" ? null : event.target.value })
1719
+ }
1720
+ >
1721
+ <option value="">{words.own}</option>
1722
+ {/* What is chosen stays choosable when the product offers it no more. */}
1723
+ {[...new Set([...offered, ...(chosen === null ? [] : [chosen])])].map((value) => (
1724
+ <option key={value} value={value}>
1725
+ {value}
1726
+ </option>
1727
+ ))}
1728
+ </select>
1729
+ </label>
1730
+ );
1731
+ const running = runner.running;
1732
+ return (
1733
+ <div className="sc-agent-choice">
1734
+ {select(words.model, "model", offers.models, runner.settings.model)}
1735
+ {select(words.effort, "effort", offers.efforts, runner.settings.effort)}
1736
+ {running !== null && (running.model !== null || running.effort !== null) && (
1737
+ <p className="sc-field-hint">
1738
+ {words.runsWith(running.model ?? words.own, running.effort ?? words.own)}
1739
+ </p>
1740
+ )}
1741
+ </div>
1742
+ );
1743
+ }
1744
+
1745
+ export interface AgentSessionListProps {
1746
+ readonly sessions: readonly RestAgentSession[];
1747
+ readonly href: (session: RestAgentSession) => string;
1748
+ readonly empty?: ReactNode;
1749
+ }
1750
+
1751
+ /**
1752
+ * An agent account's sessions, the newest first, a row each that leads to it: when it began and
1753
+ * ended, how it ended, what it ran and where, and how much it holds.
1754
+ */
1755
+ export function AgentSessionList(props: AgentSessionListProps) {
1756
+ const words = useWords().agents.page.sessions;
1757
+ if (props.sessions.length === 0) {
1758
+ return <>{props.empty ?? null}</>;
1759
+ }
1760
+ const ends: Readonly<Record<string, string>> = words.ends;
1761
+ return (
1762
+ <ul className="sc-agent-sessions" aria-label={words.title}>
1763
+ {props.sessions.map((session) => (
1764
+ <li key={session.id} className="sc-agent-session">
1765
+ <span className="sc-agent-session-when">
1766
+ <a className="sc-agent-session-link" href={props.href(session)}>
1767
+ <Time iso={session.startedAt} />
1768
+ </a>
1769
+ {session.endedAt !== null && (
1770
+ <span className="sc-agent-session-until">
1771
+ {" – "}
1772
+ <Time iso={session.endedAt} precision="clock" against={session.startedAt} />
1773
+ </span>
1774
+ )}
1775
+ </span>
1776
+ <span className="sc-agent-session-badges">
1777
+ {session.ended === null ? (
1778
+ <Badge tone="success" kind="state">
1779
+ {words.open}
1780
+ </Badge>
1781
+ ) : (
1782
+ <Badge tone={session.ended === "crashed" ? "danger" : "neutral"}>
1783
+ {ends[session.ended] ?? session.ended}
1784
+ </Badge>
1785
+ )}
1786
+ {session.away && <Badge tone="warning">{words.away}</Badge>}
1787
+ </span>
1788
+ <span className="sc-agent-session-facts">
1789
+ {[
1790
+ `${session.product.name}${session.product.version === null ? "" : ` ${session.product.version}`}`,
1791
+ ...(session.model === null ? [] : [session.model]),
1792
+ ...(session.resumed ? [words.resumed] : []),
1793
+ session.machine.name,
1794
+ ].join(" · ")}
1795
+ </span>
1796
+ <span className="sc-agent-session-count">{words.events(session.events)}</span>
1797
+ </li>
1798
+ ))}
1799
+ </ul>
1800
+ );
1801
+ }
1802
+
1803
+ /** What an agent's runner last said of itself: where it runs, with what, and where its record stands. */
1804
+ export function AgentRunnerFacts(props: { readonly runner: RestAgentRunner | null | undefined }) {
1805
+ const words = useWords().agents.page.settings.runner;
1806
+ const runner = props.runner ?? null;
1807
+ if (runner === null || (runner.machine === null && runner.product === null)) {
1808
+ return <p className="sc-field-hint">{words.none}</p>;
1809
+ }
1810
+ const facts: [string, ReactNode][] = [
1811
+ ...(runner.machine === null
1812
+ ? []
1813
+ : ([
1814
+ [words.machine, `${runner.machine.name} · ${runner.machine.os}`],
1815
+ [words.user, runner.machine.user],
1816
+ ] as [string, ReactNode][])),
1817
+ ...(runner.runner === null ? [] : ([[words.version, runner.runner]] as [string, ReactNode][])),
1818
+ ...(runner.product === null
1819
+ ? []
1820
+ : ([
1821
+ [
1822
+ words.product,
1823
+ <span key="product" className="sc-agent-product">
1824
+ {runner.product.name}
1825
+ {runner.product.version !== null && ` ${runner.product.version}`}
1826
+ {!runner.product.tried && <Badge tone="warning">{words.untried}</Badge>}
1827
+ </span>,
1828
+ ],
1829
+ ] as [string, ReactNode][])),
1830
+ [words.signals, words.delivered(runner.delivered, runner.latest)],
1831
+ ];
1832
+ return (
1833
+ <dl className="sc-person-facts sc-agent-runner-facts">
1834
+ {facts.map(([name, value]) => (
1835
+ <div key={name} className="sc-person-fact">
1836
+ <dt>{name}</dt>
1837
+ <dd>{value}</dd>
1838
+ </div>
1839
+ ))}
1840
+ </dl>
1841
+ );
1842
+ }
1843
+
1844
+ /**
1845
+ * The accounts an agent account holds elsewhere (ADR-0089): what it is called at each service,
1846
+ * as it or a supervisor recorded them, and no secret. What to close when the account is taken out.
1847
+ */
1848
+ export function AgentElsewhereList(props: {
1849
+ readonly accounts: Readonly<Record<string, string>> | undefined;
1850
+ }) {
1851
+ const words = useWords().agents.page.settings.elsewhere;
1852
+ const held = Object.entries(props.accounts ?? {});
1853
+ return (
1854
+ <div>
1855
+ {held.length === 0 ? (
1856
+ <p className="sc-field-hint">{words.empty}</p>
1857
+ ) : (
1858
+ <dl className="sc-person-facts sc-agent-runner-facts" aria-label={words.title}>
1859
+ {held.map(([service, name]) => (
1860
+ <div key={service} className="sc-person-fact">
1861
+ <dt>{service}</dt>
1862
+ <dd>{name}</dd>
1863
+ </div>
1864
+ ))}
1865
+ </dl>
1866
+ )}
1867
+ <p className="sc-field-hint">{words.intro}</p>
1868
+ </div>
1869
+ );
1870
+ }
1871
+
1872
+ export interface AgentSecretListProps {
1873
+ readonly secrets: readonly RestAgentSecret[];
1874
+ readonly busy?: boolean | undefined;
1875
+ /** Seeds a secret, write-only: only the account reads the value back. */
1876
+ readonly onSeed: (name: string, value: string) => void;
1877
+ readonly onRemove: (name: string) => void;
1878
+ }
1879
+
1880
+ /** The names of an agent account's secrets, and the way a supervisor seeds one or removes one. Never a value. */
1881
+ export function AgentSecretList(props: AgentSecretListProps) {
1882
+ const words = useWords().agents.page.settings.secrets;
1883
+ const [name, setName] = useState("");
1884
+ const [value, setValue] = useState("");
1885
+ const busy = props.busy === true;
1886
+ const submit = (event: FormEvent) => {
1887
+ event.preventDefault();
1888
+ if (name.trim().length === 0 || value.length === 0 || busy) {
1889
+ return;
1890
+ }
1891
+ props.onSeed(name.trim(), value);
1892
+ setName("");
1893
+ setValue("");
1894
+ };
1895
+ return (
1896
+ <div>
1897
+ {props.secrets.length === 0 ? (
1898
+ <p className="sc-field-hint">{words.empty}</p>
1899
+ ) : (
1900
+ <ul className="sc-agent-secret-list" aria-label={words.title}>
1901
+ {props.secrets.map((secret) => (
1902
+ <li key={secret.name} className="sc-agent-secret">
1903
+ <code>{secret.name}</code>
1904
+ <span className="sc-muted">
1905
+ <Time iso={secret.setAt} precision="day" />
1906
+ {secret.seeded && ` · ${words.seeded}`}
1907
+ {secret.expiresOn !== null && ` · ${words.expires(secret.expiresOn)}`}
1908
+ </span>
1909
+ <Button
1910
+ variant="ghost"
1911
+ size="sm"
1912
+ disabled={busy}
1913
+ onClick={() => props.onRemove(secret.name)}
1914
+ >
1915
+ {words.remove}
1916
+ </Button>
1917
+ </li>
1918
+ ))}
1919
+ </ul>
1920
+ )}
1921
+ <form className="sc-agent-secret-form" aria-label={words.seedAria} onSubmit={submit}>
1922
+ <input
1923
+ className="sc-input"
1924
+ aria-label={words.name}
1925
+ placeholder={words.namePlaceholder}
1926
+ value={name}
1927
+ autoComplete="off"
1928
+ onChange={(event) => setName(event.target.value)}
1929
+ />
1930
+ <input
1931
+ className="sc-input"
1932
+ type="password"
1933
+ aria-label={words.value}
1934
+ placeholder={words.value}
1935
+ value={value}
1936
+ autoComplete="new-password"
1937
+ onChange={(event) => setValue(event.target.value)}
1938
+ />
1939
+ <Button type="submit" disabled={busy || name.trim().length === 0 || value.length === 0}>
1940
+ {words.seed}
1941
+ </Button>
1942
+ </form>
1943
+ <p className="sc-field-hint">{words.intro}</p>
1944
+ </div>
1945
+ );
1946
+ }