@skillcdn/console 0.5.0 → 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 (345) hide show
  1. package/README.md +68 -11
  2. package/SKILLCDN.md +3 -3
  3. package/dist/agent-page.d.ts.map +1 -1
  4. package/dist/agent-page.js +3 -2
  5. package/dist/agent-page.js.map +1 -1
  6. package/dist/api.d.ts +7 -6
  7. package/dist/api.d.ts.map +1 -1
  8. package/dist/api.js +6 -5
  9. package/dist/api.js.map +1 -1
  10. package/dist/charts.d.ts +103 -0
  11. package/dist/charts.d.ts.map +1 -0
  12. package/dist/charts.js +182 -0
  13. package/dist/charts.js.map +1 -0
  14. package/dist/cli/cli.d.ts +26 -2
  15. package/dist/cli/cli.d.ts.map +1 -1
  16. package/dist/cli/cli.js +1304 -383
  17. package/dist/cli/cli.js.map +1 -1
  18. package/dist/cli/command-words.d.ts +20 -0
  19. package/dist/cli/command-words.d.ts.map +1 -0
  20. package/dist/cli/command-words.js +51 -0
  21. package/dist/cli/command-words.js.map +1 -0
  22. package/dist/cli/credentials.d.ts +54 -5
  23. package/dist/cli/credentials.d.ts.map +1 -1
  24. package/dist/cli/credentials.js +126 -20
  25. package/dist/cli/credentials.js.map +1 -1
  26. package/dist/cli/directory.d.ts +19 -4
  27. package/dist/cli/directory.d.ts.map +1 -1
  28. package/dist/cli/directory.js +16 -8
  29. package/dist/cli/directory.js.map +1 -1
  30. package/dist/cli/format.d.ts +65 -8
  31. package/dist/cli/format.d.ts.map +1 -1
  32. package/dist/cli/format.js +242 -37
  33. package/dist/cli/format.js.map +1 -1
  34. package/dist/cli/help.d.ts +13 -4
  35. package/dist/cli/help.d.ts.map +1 -1
  36. package/dist/cli/help.js +92 -54
  37. package/dist/cli/help.js.map +1 -1
  38. package/dist/cli/main.js +76 -2
  39. package/dist/cli/main.js.map +1 -1
  40. package/dist/cli/pack.d.ts +69 -60
  41. package/dist/cli/pack.d.ts.map +1 -1
  42. package/dist/cli/pack.js +241 -270
  43. package/dist/cli/pack.js.map +1 -1
  44. package/dist/cli/plugin-check.d.ts +42 -0
  45. package/dist/cli/plugin-check.d.ts.map +1 -1
  46. package/dist/cli/plugin-check.js +221 -36
  47. package/dist/cli/plugin-check.js.map +1 -1
  48. package/dist/cli/plugin-cli.d.ts +6 -1
  49. package/dist/cli/plugin-cli.d.ts.map +1 -1
  50. package/dist/cli/plugin-cli.js +21 -4
  51. package/dist/cli/plugin-cli.js.map +1 -1
  52. package/dist/cli/plugin-main.js +1 -0
  53. package/dist/cli/plugin-main.js.map +1 -1
  54. package/dist/cli/serve.d.ts +33 -1
  55. package/dist/cli/serve.d.ts.map +1 -1
  56. package/dist/cli/serve.js +252 -3
  57. package/dist/cli/serve.js.map +1 -1
  58. package/dist/client.d.ts +48 -9
  59. package/dist/client.d.ts.map +1 -1
  60. package/dist/client.js +72 -80
  61. package/dist/client.js.map +1 -1
  62. package/dist/components/agent-page.d.ts +64 -1
  63. package/dist/components/agent-page.d.ts.map +1 -1
  64. package/dist/components/agent-page.js +244 -96
  65. package/dist/components/agent-page.js.map +1 -1
  66. package/dist/components/charts.d.ts +157 -0
  67. package/dist/components/charts.d.ts.map +1 -0
  68. package/dist/components/charts.js +182 -0
  69. package/dist/components/charts.js.map +1 -0
  70. package/dist/components/desk-records.d.ts +102 -0
  71. package/dist/components/desk-records.d.ts.map +1 -0
  72. package/dist/components/desk-records.js +221 -0
  73. package/dist/components/desk-records.js.map +1 -0
  74. package/dist/components/desk.d.ts +85 -0
  75. package/dist/components/desk.d.ts.map +1 -0
  76. package/dist/components/desk.js +135 -0
  77. package/dist/components/desk.js.map +1 -0
  78. package/dist/components/event-feed.d.ts.map +1 -1
  79. package/dist/components/event-feed.js +4 -1
  80. package/dist/components/event-feed.js.map +1 -1
  81. package/dist/components/home.d.ts.map +1 -1
  82. package/dist/components/home.js +4 -2
  83. package/dist/components/home.js.map +1 -1
  84. package/dist/components/plugin-settings.d.ts.map +1 -1
  85. package/dist/components/plugin-settings.js +54 -3
  86. package/dist/components/plugin-settings.js.map +1 -1
  87. package/dist/components/projects.d.ts.map +1 -1
  88. package/dist/components/projects.js +27 -7
  89. package/dist/components/projects.js.map +1 -1
  90. package/dist/components/rules.d.ts +8 -10
  91. package/dist/components/rules.d.ts.map +1 -1
  92. package/dist/components/rules.js +35 -13
  93. package/dist/components/rules.js.map +1 -1
  94. package/dist/components/setup.d.ts +9 -3
  95. package/dist/components/setup.d.ts.map +1 -1
  96. package/dist/components/setup.js +10 -4
  97. package/dist/components/setup.js.map +1 -1
  98. package/dist/console.css +677 -7
  99. package/dist/console.d.ts +5 -0
  100. package/dist/console.d.ts.map +1 -1
  101. package/dist/console.js +14 -8
  102. package/dist/console.js.map +1 -1
  103. package/dist/data.d.ts.map +1 -1
  104. package/dist/data.js +32 -33
  105. package/dist/data.js.map +1 -1
  106. package/dist/desk-page.d.ts +38 -0
  107. package/dist/desk-page.d.ts.map +1 -0
  108. package/dist/desk-page.js +184 -0
  109. package/dist/desk-page.js.map +1 -0
  110. package/dist/desk-records-page.d.ts +18 -0
  111. package/dist/desk-records-page.d.ts.map +1 -0
  112. package/dist/desk-records-page.js +130 -0
  113. package/dist/desk-records-page.js.map +1 -0
  114. package/dist/desk-records.d.ts +247 -0
  115. package/dist/desk-records.d.ts.map +1 -0
  116. package/dist/desk-records.js +543 -0
  117. package/dist/desk-records.js.map +1 -0
  118. package/dist/desk.d.ts +122 -0
  119. package/dist/desk.d.ts.map +1 -0
  120. package/dist/desk.js +211 -0
  121. package/dist/desk.js.map +1 -0
  122. package/dist/feed-stream.d.ts +39 -0
  123. package/dist/feed-stream.d.ts.map +1 -0
  124. package/dist/feed-stream.js +117 -0
  125. package/dist/feed-stream.js.map +1 -0
  126. package/dist/home-tiles.d.ts +10 -3
  127. package/dist/home-tiles.d.ts.map +1 -1
  128. package/dist/home-tiles.js +54 -31
  129. package/dist/home-tiles.js.map +1 -1
  130. package/dist/i18n/en.d.ts +180 -5
  131. package/dist/i18n/en.d.ts.map +1 -1
  132. package/dist/i18n/en.js +184 -7
  133. package/dist/i18n/en.js.map +1 -1
  134. package/dist/i18n/ko.d.ts.map +1 -1
  135. package/dist/i18n/ko.js +169 -6
  136. package/dist/i18n/ko.js.map +1 -1
  137. package/dist/index.d.ts +8 -0
  138. package/dist/index.d.ts.map +1 -1
  139. package/dist/index.js +8 -0
  140. package/dist/index.js.map +1 -1
  141. package/dist/limits.d.ts +11 -0
  142. package/dist/limits.d.ts.map +1 -1
  143. package/dist/limits.js +11 -0
  144. package/dist/limits.js.map +1 -1
  145. package/dist/onboarding.d.ts +6 -0
  146. package/dist/onboarding.d.ts.map +1 -1
  147. package/dist/onboarding.js +3 -3
  148. package/dist/onboarding.js.map +1 -1
  149. package/dist/plugin/context.d.ts +42 -11
  150. package/dist/plugin/context.d.ts.map +1 -1
  151. package/dist/plugin/limits.d.ts +2 -0
  152. package/dist/plugin/limits.d.ts.map +1 -1
  153. package/dist/plugin/limits.js +2 -0
  154. package/dist/plugin/limits.js.map +1 -1
  155. package/dist/plugin/manifest.d.ts +13 -0
  156. package/dist/plugin/manifest.d.ts.map +1 -1
  157. package/dist/plugin/manifest.js +30 -3
  158. package/dist/plugin/manifest.js.map +1 -1
  159. package/dist/plugin/rest-schemas.d.ts +55 -0
  160. package/dist/plugin/rest-schemas.d.ts.map +1 -1
  161. package/dist/plugin/rest-schemas.js +37 -0
  162. package/dist/plugin/rest-schemas.js.map +1 -1
  163. package/dist/plugin/sandbox.d.ts.map +1 -1
  164. package/dist/plugin/sandbox.js +4 -1
  165. package/dist/plugin/sandbox.js.map +1 -1
  166. package/dist/plugin/testing.d.ts +6 -2
  167. package/dist/plugin/testing.d.ts.map +1 -1
  168. package/dist/plugin/testing.js +52 -10
  169. package/dist/plugin/testing.js.map +1 -1
  170. package/dist/plugin.d.ts +1 -1
  171. package/dist/plugin.d.ts.map +1 -1
  172. package/dist/plugin.js +1 -1
  173. package/dist/plugin.js.map +1 -1
  174. package/dist/records.d.ts +283 -0
  175. package/dist/records.d.ts.map +1 -0
  176. package/dist/records.js +543 -0
  177. package/dist/records.js.map +1 -0
  178. package/dist/routes.d.ts +3 -1
  179. package/dist/routes.d.ts.map +1 -1
  180. package/dist/routes.js +3 -1
  181. package/dist/routes.js.map +1 -1
  182. package/dist/rules.d.ts +30 -11
  183. package/dist/rules.d.ts.map +1 -1
  184. package/dist/rules.js +98 -45
  185. package/dist/rules.js.map +1 -1
  186. package/dist/runner/acp.d.ts +1 -1
  187. package/dist/runner/acp.d.ts.map +1 -1
  188. package/dist/runner/acp.js +31 -20
  189. package/dist/runner/acp.js.map +1 -1
  190. package/dist/runner/claude.d.ts +1 -1
  191. package/dist/runner/claude.d.ts.map +1 -1
  192. package/dist/runner/claude.js +85 -15
  193. package/dist/runner/claude.js.map +1 -1
  194. package/dist/runner/codex.d.ts +1 -1
  195. package/dist/runner/codex.d.ts.map +1 -1
  196. package/dist/runner/codex.js +19 -16
  197. package/dist/runner/codex.js.map +1 -1
  198. package/dist/runner/desk.d.ts +43 -2
  199. package/dist/runner/desk.d.ts.map +1 -1
  200. package/dist/runner/desk.js +166 -10
  201. package/dist/runner/desk.js.map +1 -1
  202. package/dist/runner/process.d.ts.map +1 -1
  203. package/dist/runner/process.js +11 -4
  204. package/dist/runner/process.js.map +1 -1
  205. package/dist/runner/redact.d.ts +39 -4
  206. package/dist/runner/redact.d.ts.map +1 -1
  207. package/dist/runner/redact.js +81 -5
  208. package/dist/runner/redact.js.map +1 -1
  209. package/dist/runner/runner.d.ts +15 -1
  210. package/dist/runner/runner.d.ts.map +1 -1
  211. package/dist/runner/runner.js +231 -33
  212. package/dist/runner/runner.js.map +1 -1
  213. package/dist/runner/task-scheduler.d.ts +20 -0
  214. package/dist/runner/task-scheduler.d.ts.map +1 -1
  215. package/dist/runner/task-scheduler.js +34 -4
  216. package/dist/runner/task-scheduler.js.map +1 -1
  217. package/dist/runner/types.d.ts +36 -1
  218. package/dist/runner/types.d.ts.map +1 -1
  219. package/dist/runner/types.js +17 -0
  220. package/dist/runner/types.js.map +1 -1
  221. package/dist/runner.d.ts +6 -6
  222. package/dist/runner.d.ts.map +1 -1
  223. package/dist/runner.js +5 -5
  224. package/dist/runner.js.map +1 -1
  225. package/dist/schemas.d.ts +509 -5
  226. package/dist/schemas.d.ts.map +1 -1
  227. package/dist/schemas.js +76 -16
  228. package/dist/schemas.js.map +1 -1
  229. package/dist/services.d.ts +22 -5
  230. package/dist/services.d.ts.map +1 -1
  231. package/dist/services.js +35 -15
  232. package/dist/services.js.map +1 -1
  233. package/dist/setup-guide.d.ts +3 -1
  234. package/dist/setup-guide.d.ts.map +1 -1
  235. package/dist/setup-guide.js +7 -4
  236. package/dist/setup-guide.js.map +1 -1
  237. package/dist/vocabulary.d.ts +14 -3
  238. package/dist/vocabulary.d.ts.map +1 -1
  239. package/dist/vocabulary.js +13 -3
  240. package/dist/vocabulary.js.map +1 -1
  241. package/docs/specs/cli.md +64 -38
  242. package/docs/specs/plugins.md +27 -20
  243. package/docs/specs/records.md +113 -0
  244. package/docs/specs/rest.md +20 -13
  245. package/docs/specs/runner.md +23 -17
  246. package/package.json +7 -2
  247. package/skills/building-a-console/SKILL.md +4 -4
  248. package/skills/building-a-plugin/SKILL.md +6 -6
  249. package/skills/deploying-a-console/SKILL.md +4 -4
  250. package/skills/deploying-a-console/references/resources.md +41 -4
  251. package/skills/deploying-a-console/references/running-it-again.md +3 -2
  252. package/skills/keeping-a-desk/SKILL.md +133 -0
  253. package/skills/keeping-a-desk/collections.md +96 -0
  254. package/skills/planning-the-board/SKILL.md +14 -18
  255. package/skills/planning-the-board/references/a-task.md +2 -2
  256. package/skills/planning-the-board/references/project-rules.md +13 -14
  257. package/skills/planning-the-board/references/setting-up.md +15 -13
  258. package/skills/running-an-agent/SKILL.md +10 -9
  259. package/skills/working-the-board/SKILL.md +62 -44
  260. package/skills/working-the-board/references/terms.md +9 -5
  261. package/skills/working-the-board/references/the-pack.md +12 -10
  262. package/skills/working-the-board/references/the-sentence.md +2 -2
  263. package/src/agent-page.tsx +3 -1
  264. package/src/api.ts +77 -2
  265. package/src/charts.ts +250 -0
  266. package/src/cli/cli.ts +1698 -476
  267. package/src/cli/command-words.ts +56 -0
  268. package/src/cli/credentials.ts +181 -20
  269. package/src/cli/directory.ts +28 -10
  270. package/src/cli/format.ts +301 -46
  271. package/src/cli/help.ts +102 -54
  272. package/src/cli/main.ts +72 -2
  273. package/src/cli/pack.ts +333 -372
  274. package/src/cli/plugin-check.ts +275 -34
  275. package/src/cli/plugin-cli.ts +28 -4
  276. package/src/cli/plugin-main.ts +1 -0
  277. package/src/cli/serve.ts +295 -2
  278. package/src/client.ts +192 -177
  279. package/src/components/agent-page.tsx +489 -243
  280. package/src/components/charts.tsx +680 -0
  281. package/src/components/desk-records.tsx +724 -0
  282. package/src/components/desk.tsx +471 -0
  283. package/src/components/event-feed.tsx +5 -1
  284. package/src/components/home.tsx +12 -0
  285. package/src/components/plugin-settings.tsx +171 -12
  286. package/src/components/projects.tsx +29 -12
  287. package/src/components/rules.tsx +94 -34
  288. package/src/components/setup.tsx +18 -3
  289. package/src/console.tsx +17 -9
  290. package/src/data.ts +37 -34
  291. package/src/desk-page.tsx +332 -0
  292. package/src/desk-records-page.tsx +256 -0
  293. package/src/desk-records.ts +808 -0
  294. package/src/desk.ts +329 -0
  295. package/src/feed-stream.ts +144 -0
  296. package/src/home-tiles.ts +55 -35
  297. package/src/i18n/en.ts +196 -9
  298. package/src/i18n/ko.ts +178 -8
  299. package/src/index.ts +118 -0
  300. package/src/limits.ts +11 -0
  301. package/src/onboarding.ts +12 -4
  302. package/src/plugin/context.ts +55 -12
  303. package/src/plugin/limits.ts +2 -0
  304. package/src/plugin/manifest.ts +38 -2
  305. package/src/plugin/rest-schemas.ts +41 -0
  306. package/src/plugin/sandbox.ts +4 -1
  307. package/src/plugin/testing.ts +63 -12
  308. package/src/plugin.ts +2 -0
  309. package/src/records.ts +702 -0
  310. package/src/routes.ts +3 -1
  311. package/src/rules.ts +108 -47
  312. package/src/runner/acp.ts +47 -29
  313. package/src/runner/claude.ts +113 -23
  314. package/src/runner/codex.ts +35 -25
  315. package/src/runner/desk.ts +198 -12
  316. package/src/runner/process.ts +11 -4
  317. package/src/runner/redact.ts +92 -6
  318. package/src/runner/runner.ts +275 -34
  319. package/src/runner/task-scheduler.ts +36 -4
  320. package/src/runner/types.ts +47 -1
  321. package/src/runner.ts +27 -2
  322. package/src/schemas.ts +83 -15
  323. package/src/services.ts +49 -14
  324. package/src/setup-guide.ts +6 -2
  325. package/src/styles/README.md +11 -1
  326. package/src/styles/console.css +9 -0
  327. package/src/styles/pages/desk.css +126 -0
  328. package/src/styles/pages/documents.css +5 -0
  329. package/src/styles/parts/bars.css +80 -0
  330. package/src/styles/parts/chart.css +173 -0
  331. package/src/styles/parts/figures.css +65 -0
  332. package/src/styles/parts/legend.css +48 -0
  333. package/src/styles/parts/series.css +32 -0
  334. package/src/styles/parts/share.css +25 -0
  335. package/src/styles/parts/spark.css +23 -0
  336. package/src/styles/parts/stat.css +69 -0
  337. package/src/styles/tokens.css +13 -7
  338. package/src/vocabulary.ts +16 -3
  339. package/template/desk-web/README.md +8 -0
  340. package/template/desk-web/index.html +13 -0
  341. package/template/desk-web/package.json +25 -0
  342. package/template/desk-web/src/main.tsx +24 -0
  343. package/template/desk-web/src/page.tsx +51 -0
  344. package/template/desk-web/tsconfig.json +16 -0
  345. package/template/desk-web/vite.config.ts +15 -0
@@ -1,4 +1,13 @@
1
- import { type FormEvent, type ReactNode, useEffect, useRef, useState } from "react";
1
+ import {
2
+ type FormEvent,
3
+ memo,
4
+ type ReactNode,
5
+ useCallback,
6
+ useEffect,
7
+ useMemo,
8
+ useRef,
9
+ useState,
10
+ } from "react";
2
11
  import {
3
12
  type AgentState,
4
13
  type FileUpload,
@@ -13,9 +22,10 @@ import {
13
22
  type RestSignal,
14
23
  type RestTranscriptEvent,
15
24
  } from "../api.js";
25
+ import { today } from "../dates.js";
16
26
  import { useWords } from "../i18n/index.js";
17
27
  import { isPicture } from "./files.js";
18
- import { Lightbox, PictureThumb, usePicture } from "./pictures.js";
28
+ import { Lightbox, type PictureState, PictureThumb, usePicture } from "./pictures.js";
19
29
  import { Avatar, Badge, Button, Callout, cx, formatBytes, personName, Time } from "./ui.js";
20
30
 
21
31
  // The parts of an agent account's page (ADR-0085, ADR-0086): how it stands, what it is doing as
@@ -146,6 +156,23 @@ export type TalkItem =
146
156
  readonly permission: RestTranscriptEvent | undefined;
147
157
  };
148
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
+
149
176
  const idOf = (event: RestTranscriptEvent): string | undefined => {
150
177
  const id = event.data.id;
151
178
  return typeof id === "string" && id.length > 0 ? id : undefined;
@@ -427,87 +454,187 @@ export function wordOf(words: Readonly<Record<string, string>>, name: string): s
427
454
  }
428
455
 
429
456
  /**
430
- * A session as a conversation: what the agent was told at the right, as whoever said it wrote
431
- * it, with the files that came with it; what the agent said at the left, beside its picture; its
432
- * thoughts folded; a tool's call and what it answered as one row that opens, the steps of a turn
433
- * close together; a wake, a status and an error as notes between, and a line where a turn
434
- * ended, with how long it took. A picture opens large over the page. Everything an agent's
435
- * product printed is text, never markup.
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.
436
459
  */
437
- export function TranscriptView(props: TranscriptViewProps) {
438
- const all = useWords();
439
- const words = all.agents.page.live;
440
- const shown = usePicture();
441
- // What was read whole belongs to the session it was read in: the events of another carry the
442
- // same numbers, and a view that goes on to show them must show none of this.
443
- const [whole, setWhole] = useState<WholeTexts>(NO_WHOLE);
444
- const [reading, setReading] = useState<
445
- { readonly of: string | undefined; readonly n: number } | undefined
446
- >(undefined);
447
- const of = props.of;
448
- const showing = useRef(of);
449
- showing.current = of;
450
- if (props.events.length === 0) {
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") {
451
492
  return (
452
- <>
453
- {props.empty ?? null}
454
- {props.foot !== undefined && props.foot !== null && (
455
- <ol className="sc-talk" aria-label={words.transcript}>
456
- {props.foot}
457
- </ol>
458
- )}
459
- </>
493
+ a.type === "tool" &&
494
+ b.type === "tool" &&
495
+ a.call === b.call &&
496
+ a.result === b.result &&
497
+ a.permission === b.permission
460
498
  );
461
499
  }
462
- /** When the turn an event ends began: the first thing the agent was sent after the turn before. */
463
- const began = new Map<number, string>();
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>();
464
546
  let since: string | undefined;
465
- for (const event of props.events) {
547
+ for (const event of events) {
466
548
  if (event.kind === "status" && event.data.turn === "completed") {
467
549
  if (since !== undefined) {
468
- began.set(event.n, since);
550
+ starts.set(event.n, since);
469
551
  }
470
552
  since = undefined;
471
553
  } else if ((event.kind === "person" || event.kind === "wake") && since === undefined) {
472
554
  since = event.at;
473
555
  }
474
556
  }
475
- const kinds: Readonly<Record<string, string>> = words.kinds;
476
- const readWhole = (n: number) => {
477
- const load = props.onReadWhole;
478
- if (load === undefined) {
479
- return;
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 [];
480
585
  }
481
- setReading({ of, n });
482
- void load(n)
483
- .then((text) => {
484
- // An answer that arrives once another session is shown is that session's no more.
485
- if (showing.current === of) {
486
- setWhole((current) => withWhole(current, of, n, text));
487
- }
488
- })
489
- .catch(() => undefined)
490
- .finally(() =>
491
- setReading((current) =>
492
- current !== undefined && current.of === of && current.n === n ? undefined : current,
493
- ),
494
- );
495
- };
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;
496
619
  /** The words of an event, whole where they were read whole, with the way to read the rest. */
497
- const text = (event: RestTranscriptEvent, className: string): ReactNode => {
498
- const read = wholeOf(whole, of, event.n);
620
+ const text = (
621
+ event: RestTranscriptEvent,
622
+ className: string,
623
+ read: string | undefined,
624
+ ): ReactNode => {
499
625
  const shown = read ?? event.text;
626
+ const readWhole = hands.readWhole;
500
627
  return (
501
628
  <>
502
629
  {shown.length > 0 && <pre className={className}>{shown}</pre>}
503
630
  {event.whole !== null && read === undefined && (
504
631
  <p className="sc-talk-cut">
505
632
  {words.cutAt(formatBytes(event.whole))}{" "}
506
- {props.onReadWhole !== undefined && (
633
+ {readWhole !== undefined && (
507
634
  <Button
508
635
  variant="ghost"
509
636
  size="sm"
510
- disabled={reading !== undefined && reading.of === of && reading.n === event.n}
637
+ disabled={props.reading === event.n}
511
638
  onClick={() => readWhole(event.n)}
512
639
  >
513
640
  {words.whole}
@@ -525,231 +652,350 @@ export function TranscriptView(props: TranscriptViewProps) {
525
652
  <li key={file.id}>
526
653
  <PictureThumb
527
654
  picture={{
528
- src: props.fileHref(file.id),
655
+ src: hands.fileHref(file.id),
529
656
  alt: file.name,
530
657
  name: file.name,
531
658
  size: file.size,
532
659
  }}
533
- onOpen={shown.open}
660
+ onOpen={hands.openPicture}
534
661
  />
535
662
  </li>
536
663
  ))}
537
664
  </ul>
538
665
  );
539
666
  const when = (event: RestTranscriptEvent): ReactNode => <Time iso={event.at} precision="clock" />;
540
- const item = (one: TalkItem): ReactNode => {
541
- if (one.type === "tool") {
542
- const first = one.call ?? one.permission ?? one.result;
543
- if (first === undefined) {
544
- return null;
545
- }
546
- const name = word(one.call?.data[TOOL]) ?? word(one.permission?.data[TOOL]);
547
- const failed = one.result?.data.error === true;
548
- const answer = word(one.permission?.data.answer);
549
- const refused = answer !== undefined && answer !== "allowed";
550
- const line = firstLine(one.call?.text ?? one.permission?.text ?? one.result?.text ?? "");
551
- return (
552
- <li
553
- key={first.n}
554
- className={cx(
555
- "sc-talk-item",
556
- "sc-talk-step",
557
- "sc-talk-tool",
558
- (failed || refused) && "sc-talk-tool-failed",
559
- )}
560
- data-n={first.n}
561
- >
562
- <details className="sc-talk-tool-fold">
563
- <summary className="sc-talk-tool-head">
564
- <code className="sc-talk-tool-name">{name ?? kinds.tool_call}</code>
565
- <span className="sc-talk-tool-line">{line}</span>
566
- {failed && <Badge tone="danger">{words.toolFailed}</Badge>}
567
- {refused && <Badge tone="warning">{words.toolRefused}</Badge>}
568
- {one.result === undefined && one.call !== undefined && !refused && (
569
- <span className="sc-muted">{words.toolRunning}</span>
570
- )}
571
- {when(first)}
572
- </summary>
573
- <div className="sc-talk-tool-body">
574
- {one.permission !== undefined && (
575
- <p className="sc-talk-note-line">
576
- {kinds.permission}
577
- {answer === undefined ? "" : ` · ${wordOf(words.answers, answer)}`}
578
- {one.permission.text.length > 0 && ` · ${one.permission.text}`}
579
- </p>
580
- )}
581
- {one.call !== undefined && text(one.call, "sc-talk-code")}
582
- {one.result !== undefined && text(one.result, "sc-talk-code sc-talk-code-answer")}
583
- </div>
584
- </details>
585
- {pictures(one.result)}
586
- </li>
587
- );
588
- }
589
- const { event } = one;
590
- if (event.sealed !== null) {
591
- return (
592
- <li key={event.n} className="sc-talk-item sc-talk-note" data-n={event.n}>
593
- <span className="sc-talk-note-line">
594
- {words.sealed(
595
- event.sealed.by === null ? "?" : (event.sealed.by.name ?? event.sealed.by.login),
596
- event.sealed.reason,
597
- )}
598
- </span>
599
- {when(event)}
600
- </li>
601
- );
667
+ if (one.type === "tool") {
668
+ const first = one.call ?? one.permission ?? one.result;
669
+ if (first === undefined) {
670
+ return null;
602
671
  }
603
- if (one.type === "told") {
604
- const number = typeof event.data.signal === "number" ? event.data.signal : undefined;
605
- const kind = word(event.data.kind);
606
- const through = word(event.data.agent);
607
- const unseen = word(event.data.unseen);
608
- const others = word(event.data.files);
609
- const listed =
610
- number === undefined
611
- ? undefined
612
- : props.signalFiles?.(number)?.filter((file) => !isPicture(file.contentType));
613
- const who = word(event.data.by) ?? words.kinds.person;
614
- // An interrupt with no words of its own stopped the turn so that what waited is read: a
615
- // note of who did, and no message.
616
- if (
617
- kind === "interrupt" &&
618
- event.text.length === 0 &&
619
- event.files.length === 0 &&
620
- others === undefined
621
- ) {
622
- return (
623
- <li key={event.n} className="sc-talk-item sc-talk-note" data-n={event.n}>
624
- <span className="sc-talk-note-line">
625
- {words.interrupted(who)}
626
- {when(event)}
627
- </span>
628
- </li>
629
- );
630
- }
631
- return (
632
- <li key={event.n} className="sc-talk-item sc-talk-told" data-n={event.n}>
633
- <div className="sc-talk-bubble">
634
- {text(event, "sc-talk-text")}
635
- {pictures(event)}
636
- {listed !== undefined && listed.length > 0 ? (
637
- <ul className="sc-chosen-files" aria-label={words.files}>
638
- {listed.map((file) => (
639
- <li key={file.id} className="sc-chosen-file">
640
- {props.signalFileHref === undefined || number === undefined ? (
641
- <span>{file.name}</span>
642
- ) : (
643
- <a href={props.signalFileHref(number, file.id)} download={file.name}>
644
- {file.name}
645
- </a>
646
- )}{" "}
647
- <span className="sc-muted">{formatBytes(file.size)}</span>
648
- </li>
649
- ))}
650
- </ul>
651
- ) : (
652
- others !== undefined && (
653
- <p className="sc-talk-note-line">
654
- {words.files}: {others}
655
- </p>
656
- )
657
- )}
658
- {unseen !== undefined && (
659
- <p className="sc-talk-note-line sc-talk-unseen">{words.unseen(unseen)}</p>
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>
660
699
  )}
661
- </div>
662
- <div className="sc-talk-meta">
663
- <span className="sc-talk-who">{who}</span>
664
- {through !== undefined && <span>{words.through(through)}</span>}
665
- {kind !== undefined && kind !== "tell" && (
666
- <Badge>{wordOf(words.signalKinds, kind)}</Badge>
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>
667
709
  )}
668
- {when(event)}
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)}
669
713
  </div>
670
- {event.data.unread === true && (
671
- <p className="sc-talk-note-line sc-talk-unread">{words.unread}</p>
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,
672
727
  )}
673
- </li>
674
- );
675
- }
676
- if (one.type === "said") {
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
+ ) {
677
752
  return (
678
- <li key={event.n} className="sc-talk-item sc-talk-said" data-n={event.n}>
679
- {props.agent !== undefined && <Avatar person={props.agent} size="sm" />}
680
- <div className="sc-talk-prose">
681
- {text(event, "sc-talk-text")}
682
- {pictures(event)}
683
- </div>
684
- {when(event)}
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>
685
758
  </li>
686
759
  );
687
760
  }
688
- if (one.type === "thought") {
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) {
689
812
  return (
690
- <li key={event.n} className="sc-talk-item sc-talk-step sc-talk-thought" data-n={event.n}>
813
+ <li className="sc-talk-item sc-talk-step sc-talk-thought" data-n={event.n}>
691
814
  <details className="sc-talk-tool-fold">
692
815
  <summary className="sc-talk-tool-head">
693
- <span className="sc-talk-kind">{kinds.thinking}</span>
816
+ <span className="sc-talk-kind">{kinds.assistant}</span>
694
817
  <span className="sc-talk-tool-line">{firstLine(event.text)}</span>
818
+ <Badge>{words.subagent(sub)}</Badge>
695
819
  {when(event)}
696
820
  </summary>
697
- <div className="sc-talk-tool-body">{text(event, "sc-talk-text")}</div>
821
+ <div className="sc-talk-tool-body">
822
+ {text(event, "sc-talk-text", props.whole)}
823
+ {pictures(event)}
824
+ </div>
698
825
  </details>
699
826
  </li>
700
827
  );
701
828
  }
702
- // Where a turn ended: a line, with how long the agent was at it where the record says when it began.
703
- if (event.kind === "status" && event.data.turn === "completed") {
704
- const from = began.get(event.n);
705
- const seconds =
706
- from === undefined
707
- ? undefined
708
- : Math.max(0, Math.round((Date.parse(event.at) - Date.parse(from)) / 1000));
709
- return (
710
- <li key={event.n} className="sc-talk-item sc-talk-turn" data-n={event.n}>
711
- <span className="sc-talk-note-line">
712
- {words.turnDone(Number.isFinite(seconds) ? seconds : undefined)}
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>}
713
849
  {when(event)}
714
- </span>
715
- </li>
716
- );
717
- }
718
- // A wake, a status, an error, and whatever a newer runner calls otherwise: a note between.
719
- // What the note's own words say already, how a session ended, is not said twice as a fact.
720
- const facts = Object.entries(event.data).filter(
721
- ([name, fact]) => fact !== null && name !== "signal" && name !== "kind" && name !== "ended",
850
+ </summary>
851
+ <div className="sc-talk-tool-body">{text(event, "sc-talk-text", props.whole)}</div>
852
+ </details>
853
+ </li>
722
854
  );
723
- const lines = event.text.split("\n").filter((line) => line.trim().length > 0);
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));
724
863
  return (
725
- <li
726
- key={event.n}
727
- className={cx(
728
- "sc-talk-item",
729
- "sc-talk-note",
730
- event.kind === "error" && "sc-talk-note-error",
731
- )}
732
- data-n={event.n}
733
- >
864
+ <li className="sc-talk-item sc-talk-turn" data-n={event.n}>
734
865
  <span className="sc-talk-note-line">
735
- <span className="sc-talk-kind">{kinds[event.kind] ?? event.kind}</span>
736
- {facts.map(([name, fact]) => (
737
- <span key={name} className="sc-talk-fact">
738
- {wordOf(words.facts, name)} {String(fact)}
739
- </span>
740
- ))}
741
- {lines.length === 1 && <span>{lines[0]}</span>}
866
+ {words.turnDone(Number.isFinite(seconds) ? seconds : undefined)}
742
867
  {when(event)}
743
868
  </span>
744
- {lines.length > 1 && text(event, "sc-talk-text sc-talk-text-note")}
745
- {pictures(event)}
746
869
  </li>
747
870
  );
748
- };
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
+ });
749
993
  return (
750
994
  <>
751
995
  <ol className="sc-talk" aria-label={words.transcript}>
752
- {talkOf(props.events).map(item)}
996
+ {lines.map(({ key, ...line }) => (
997
+ <TalkLine key={key} {...line} />
998
+ ))}
753
999
  {props.foot}
754
1000
  </ol>
755
1001
  <Lightbox picture={shown.shown} onClose={shown.close} />