@zyro-sec/session-ui 0.0.0-stage → 1.0.4

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 (261) hide show
  1. package/AGENTS.md +25 -0
  2. package/bunfig.toml +2 -0
  3. package/component-tests/basic-tool.fixture.tsx +46 -0
  4. package/component-tests/basic-tool.spec.ts +63 -0
  5. package/component-tests/file-media.fixture.tsx +39 -0
  6. package/component-tests/file-media.spec.ts +13 -0
  7. package/component-tests/file-tool.spec.ts +62 -0
  8. package/component-tests/file-viewer.fixture.tsx +109 -0
  9. package/component-tests/file-viewer.spec.ts +134 -0
  10. package/component-tests/file.spec.ts +33 -0
  11. package/component-tests/line-comment-v2.spec.ts +15 -0
  12. package/component-tests/markdown-code-wrap.spec.ts +94 -0
  13. package/component-tests/markdown-readiness.spec.ts +95 -0
  14. package/component-tests/markdown.fixture.tsx +104 -0
  15. package/component-tests/markdown.spec.ts +1564 -0
  16. package/component-tests/mermaid-preview.spec.ts +43 -0
  17. package/component-tests/patch-group.spec.ts +79 -0
  18. package/component-tests/read-group.spec.ts +72 -0
  19. package/component-tests/read-image.fixture.tsx +66 -0
  20. package/component-tests/read-image.spec.ts +154 -0
  21. package/component-tests/session-compaction.spec.ts +254 -0
  22. package/component-tests/session-lifecycle.spec.ts +190 -0
  23. package/component-tests/session-message-projection.spec.ts +639 -0
  24. package/component-tests/session-notice-projection.spec.ts +20 -0
  25. package/component-tests/session-review-comments.spec.ts +179 -0
  26. package/component-tests/session-shell.spec.ts +93 -0
  27. package/component-tests/session-timeline-mobile.spec.ts +201 -0
  28. package/component-tests/session-timeline-notices.spec.ts +38 -0
  29. package/component-tests/session-timeline-reasoning.spec.ts +107 -0
  30. package/component-tests/session-timeline.spec.ts +157 -0
  31. package/component-tests/session-tool-projection.spec.ts +323 -0
  32. package/component-tests/text-lifecycle.fixture.tsx +26 -0
  33. package/component-tests/text-lifecycle.spec.ts +42 -0
  34. package/component-tests/timeline-subagent-rows.spec.ts +33 -0
  35. package/component-tests/tool-disclosure.spec.ts +48 -0
  36. package/component-tests/tool-group-sticky.spec.ts +37 -0
  37. package/component-tests/tool-group.spec.ts +290 -0
  38. package/component-tests/tool-status-title.fixture.tsx +22 -0
  39. package/component-tests/tool-status-title.spec.ts +30 -0
  40. package/component-tests/user-message-quotes.spec.ts +111 -0
  41. package/package.json +91 -4
  42. package/playwright.components.config.ts +4 -0
  43. package/playwright.local.config.ts +2 -0
  44. package/src/actions.ts +54 -0
  45. package/src/components/apply-patch-file.ts +122 -0
  46. package/src/components/basic-tool.css +487 -0
  47. package/src/components/basic-tool.tsx +258 -0
  48. package/src/components/copy-machine.ts +78 -0
  49. package/src/components/copy.ts +85 -0
  50. package/src/components/diagram-preview.tsx +28 -0
  51. package/src/components/disclosure-machine.ts +188 -0
  52. package/src/components/disclosure.ts +129 -0
  53. package/src/components/dock-prompt.stories.tsx +73 -0
  54. package/src/components/dock-prompt.tsx +29 -0
  55. package/src/components/file-comment-selection.tsx +146 -0
  56. package/src/components/file-media-machine.ts +165 -0
  57. package/src/components/file-media.stories.tsx +112 -0
  58. package/src/components/file-media.tsx +323 -0
  59. package/src/components/file-search.tsx +73 -0
  60. package/src/components/file.css +59 -0
  61. package/src/components/file.tsx +1300 -0
  62. package/src/components/image-preview.tsx +35 -0
  63. package/src/components/line-comment-annotations.tsx +580 -0
  64. package/src/components/line-comment-machine.ts +262 -0
  65. package/src/components/line-comment-styles.ts +293 -0
  66. package/src/components/line-comment.stories.tsx +152 -0
  67. package/src/components/line-comment.tsx +448 -0
  68. package/src/components/link-segments.ts +20 -0
  69. package/src/components/linked-text.tsx +21 -0
  70. package/src/components/markdown-cache-machine.ts +257 -0
  71. package/src/components/markdown-cache.tsx +556 -0
  72. package/src/components/markdown-clipboard.ts +101 -0
  73. package/src/components/markdown-code-machine.ts +200 -0
  74. package/src/components/markdown-code-state.ts +22 -0
  75. package/src/components/markdown-fragment-links.ts +74 -0
  76. package/src/components/markdown-github.svg +3 -0
  77. package/src/components/markdown-globe.svg +5 -0
  78. package/src/components/markdown-image-machine.ts +170 -0
  79. package/src/components/markdown-image.ts +156 -0
  80. package/src/components/markdown-inline-code-kind.ts +39 -0
  81. package/src/components/markdown-mermaid.ts +18 -0
  82. package/src/components/markdown-phase-machine.ts +102 -0
  83. package/src/components/markdown-projection.ts +13 -0
  84. package/src/components/markdown-session-links.ts +183 -0
  85. package/src/components/markdown-solid.test.tsx +92 -0
  86. package/src/components/markdown-solid.tsx +113 -0
  87. package/src/components/markdown-stream.ts +95 -0
  88. package/src/components/markdown-worker-machine.ts +516 -0
  89. package/src/components/markdown-worker-protocol.ts +73 -0
  90. package/src/components/markdown-worker.ts +250 -0
  91. package/src/components/markdown.css +672 -0
  92. package/src/components/markdown.stories.tsx +199 -0
  93. package/src/components/markdown.tsx +1612 -0
  94. package/src/components/markdown.worker.ts +188 -0
  95. package/src/components/message-file.ts +102 -0
  96. package/src/components/message-nav.css +134 -0
  97. package/src/components/message-nav.tsx +159 -0
  98. package/src/components/message-part.css +2109 -0
  99. package/src/components/message-part.tsx +3 -0
  100. package/src/components/question-prompt-experimental.css +576 -0
  101. package/src/components/question-prompt.css +527 -0
  102. package/src/components/quote-highlight.css +59 -0
  103. package/src/components/review-focus-driver.ts +142 -0
  104. package/src/components/review-focus-machine.ts +95 -0
  105. package/src/components/session-compaction.css +270 -0
  106. package/src/components/session-diff.ts +358 -0
  107. package/src/components/session-error.tsx +41 -0
  108. package/src/components/session-retry.tsx +92 -0
  109. package/src/components/session-review-machine.ts +241 -0
  110. package/src/components/session-review.css +264 -0
  111. package/src/components/session-review.stories.tsx +232 -0
  112. package/src/components/session-review.tsx +733 -0
  113. package/src/components/session-turn.css +282 -0
  114. package/src/components/shell-submessage.css +24 -0
  115. package/src/components/timeline-separator.tsx +69 -0
  116. package/src/components/tool-count-label.css +57 -0
  117. package/src/components/tool-count-label.tsx +76 -0
  118. package/src/components/tool-count-summary.css +102 -0
  119. package/src/components/tool-count-summary.stories.tsx +99 -0
  120. package/src/components/tool-count-summary.tsx +44 -0
  121. package/src/components/tool-error-card.css +178 -0
  122. package/src/components/tool-error-card.stories.tsx +113 -0
  123. package/src/components/tool-error-card.tsx +202 -0
  124. package/src/components/tool-status-title-machine.ts +128 -0
  125. package/src/components/tool-status-title.css +89 -0
  126. package/src/components/tool-status-title.tsx +163 -0
  127. package/src/context/data.tsx +107 -0
  128. package/src/context/index.ts +1 -0
  129. package/src/context/markdown.tsx +129 -0
  130. package/src/context/sources.tsx +34 -0
  131. package/src/document.ts +8 -0
  132. package/src/file-presentation.ts +34 -0
  133. package/src/message/action-machine.ts +72 -0
  134. package/src/message/agent-label.ts +3 -0
  135. package/src/message/attachment-card.css +119 -0
  136. package/src/message/attachment-card.tsx +40 -0
  137. package/src/message/attachment-media-machine.ts +213 -0
  138. package/src/message/comment-card.tsx +155 -0
  139. package/src/message/compaction-entrance-machine.ts +93 -0
  140. package/src/message/current-message.tsx +157 -0
  141. package/src/message/current-tool-state.ts +161 -0
  142. package/src/message/message-content.tsx +1391 -0
  143. package/src/message/paced-text-machine.ts +73 -0
  144. package/src/message/prompt-message.stories.tsx +149 -0
  145. package/src/message/relative-time.ts +45 -0
  146. package/src/message/user-message-quote-parts.ts +16 -0
  147. package/src/message/user-message-quotes.stories.tsx +797 -0
  148. package/src/message/user-message-quotes.tsx +135 -0
  149. package/src/pierre/comment-hover-machine.ts +53 -0
  150. package/src/pierre/comment-hover.ts +131 -0
  151. package/src/pierre/comment-selection-machine.ts +257 -0
  152. package/src/pierre/commented-lines.ts +106 -0
  153. package/src/pierre/diff-selection.ts +91 -0
  154. package/src/pierre/file-find-machine.ts +323 -0
  155. package/src/pierre/file-find.ts +537 -0
  156. package/src/pierre/file-runtime.ts +42 -0
  157. package/src/pierre/file-selection.ts +140 -0
  158. package/src/pierre/index.ts +344 -0
  159. package/src/pierre/media.ts +140 -0
  160. package/src/pierre/render-machine.ts +381 -0
  161. package/src/pierre/selection-bridge.ts +82 -0
  162. package/src/pierre/selection-machine.ts +198 -0
  163. package/src/pierre/virtualizer.ts +114 -0
  164. package/src/pierre/worker.ts +46 -0
  165. package/src/sources/experiment.ts +59 -0
  166. package/src/sources/site-icon.tsx +53 -0
  167. package/src/sources/sources-chip.tsx +57 -0
  168. package/src/sources/sources-expand-machine.ts +101 -0
  169. package/src/sources/sources-panel.tsx +249 -0
  170. package/src/sources/sources-title.tsx +21 -0
  171. package/src/sources/sources.css +266 -0
  172. package/src/sources/sources.ts +141 -0
  173. package/src/storybook/current-session-fixtures.ts +1492 -0
  174. package/src/storybook/current-session-scenarios.ts +76 -0
  175. package/src/storybook/current-session-story.tsx +154 -0
  176. package/src/storybook/index.ts +43 -0
  177. package/src/styles/index.css +19 -0
  178. package/src/timeline/__snapshots__/group-labels.test.ts.snap +110 -0
  179. package/src/timeline/__snapshots__/placement.test.ts.snap +1041 -0
  180. package/src/timeline/code-blocks.stories.tsx +105 -0
  181. package/src/timeline/commentary.stories.tsx +70 -0
  182. package/src/timeline/commentary.ts +38 -0
  183. package/src/timeline/detail.ts +111 -0
  184. package/src/timeline/error-card.stories.tsx +134 -0
  185. package/src/timeline/error-spacing.stories.tsx +71 -0
  186. package/src/timeline/facts.ts +493 -0
  187. package/src/timeline/file-changes.stories.tsx +436 -0
  188. package/src/timeline/group-label-fixtures.ts +97 -0
  189. package/src/timeline/mermaid.stories.tsx +131 -0
  190. package/src/timeline/place.ts +280 -0
  191. package/src/timeline/placement-fixtures.ts +365 -0
  192. package/src/timeline/placement-reactivity.ts +133 -0
  193. package/src/timeline/projection.ts +1261 -0
  194. package/src/timeline/research-and-agents.stories.tsx +461 -0
  195. package/src/timeline/session-timeline-row.tsx +1675 -0
  196. package/src/timeline/session-timeline.tsx +68 -0
  197. package/src/timeline/steer-arrival-machine.ts +134 -0
  198. package/src/timeline/terminal-work.stories.tsx +464 -0
  199. package/src/timeline/timeline-row.stories.tsx +1069 -0
  200. package/src/timeline/timeline-row.ts +238 -0
  201. package/src/timeline/turn-phase-machine.ts +112 -0
  202. package/src/timeline/user-message-fold.stories.tsx +194 -0
  203. package/src/timeline/user-runs.ts +87 -0
  204. package/src/timeline-next/__snapshots__/placement.test.ts.snap +990 -0
  205. package/src/timeline-next/compaction.tsx +236 -0
  206. package/src/timeline-next/errors.ts +101 -0
  207. package/src/timeline-next/event-row.tsx +168 -0
  208. package/src/timeline-next/events.ts +103 -0
  209. package/src/timeline-next/index.ts +10 -0
  210. package/src/timeline-next/nested-rail.ts +125 -0
  211. package/src/timeline-next/projection.ts +1028 -0
  212. package/src/timeline-next/row.tsx +1728 -0
  213. package/src/timeline-next/rules.ts +89 -0
  214. package/src/timeline-next/separator.tsx +73 -0
  215. package/src/timeline-next/spacing.ts +127 -0
  216. package/src/timeline-next/status-line.tsx +41 -0
  217. package/src/timeline-next/status.ts +33 -0
  218. package/src/timeline-next/stories/compare-renderer.stories.tsx +190 -0
  219. package/src/timeline-next/stories/compare-sessions/.gitignore +3 -0
  220. package/src/timeline-next/stories/compare.stories.tsx +486 -0
  221. package/src/timeline-next/stories/playground.stories.tsx +297 -0
  222. package/src/timeline-next/stories/session-replay.ts +1156 -0
  223. package/src/timeline-next/stories/session-timeline.tsx +50 -0
  224. package/src/timeline-next/stories/subagent-status.stories.tsx +132 -0
  225. package/src/timeline-next/timeline-next.css +649 -0
  226. package/src/timeline-next/tools/__snapshots__/activity-label.test.ts.snap +39 -0
  227. package/src/timeline-next/tools/activity-label.ts +166 -0
  228. package/src/timeline-next/tools/assistant-content.tsx +84 -0
  229. package/src/timeline-next/tools/context-group.tsx +619 -0
  230. package/src/timeline-next/tools/error-card.tsx +147 -0
  231. package/src/timeline-next/tools/explore.tsx +119 -0
  232. package/src/timeline-next/tools/file-group.tsx +128 -0
  233. package/src/timeline-next/tools/patch.tsx +174 -0
  234. package/src/timeline-next/tools/shell.tsx +186 -0
  235. package/src/timeline-next/tools/thought.tsx +87 -0
  236. package/src/timeline-next/tools/tool-display.tsx +119 -0
  237. package/src/tools/ansi.ts +8 -0
  238. package/src/tools/context-group-label.ts +123 -0
  239. package/src/tools/file-runs.ts +35 -0
  240. package/src/tools/project-path.ts +18 -0
  241. package/src/tools/read-group.stories.tsx +159 -0
  242. package/src/tools/run-machine.ts +185 -0
  243. package/src/tools/shell-output-machine.ts +233 -0
  244. package/src/tools/shell-output.ts +91 -0
  245. package/src/tools/subagent-row-variants.stories.tsx +129 -0
  246. package/src/tools/tool-group.stories.tsx +345 -0
  247. package/src/tools/tool-renderer.tsx +2876 -0
  248. package/src/v2/components/line-comment-annotations-v2.tsx +215 -0
  249. package/src/v2/components/session-file-panel-v2.tsx +149 -0
  250. package/src/v2/components/session-progress-indicator-v2.css +5 -0
  251. package/src/v2/components/session-progress-indicator-v2.stories.tsx +86 -0
  252. package/src/v2/components/session-progress-indicator-v2.tsx +16 -0
  253. package/src/v2/components/session-review-empty-changes-v2.tsx +17 -0
  254. package/src/v2/components/session-review-empty-no-git-v2.tsx +28 -0
  255. package/src/v2/components/session-review-file-preview-v2-virtualize.ts +5 -0
  256. package/src/v2/components/session-review-file-preview-v2.tsx +266 -0
  257. package/src/v2/components/session-review-v2.css +653 -0
  258. package/src/v2/components/session-review-v2.tsx +422 -0
  259. package/src/v2/components/sidebar-presence-machine.ts +69 -0
  260. package/tsconfig.json +20 -0
  261. package/README.md +0 -3
@@ -0,0 +1,93 @@
1
+ /** How long a new compaction waits before showing Compacting; session-compaction.css delays its fade by the same. */
2
+ export const COMPACTION_GRACE_MS = 400
3
+
4
+ /** A compaction that finished at most this long ago when it mounts still fades in. */
5
+ export const COMPACTION_RECENT_DONE_MS = 1_000
6
+
7
+ /**
8
+ * How a quiet compaction divider enters.
9
+ * - `grace`: new and running; CSS holds it hidden for the grace, and finishing inside it switches to `instant`.
10
+ * - `revealed`: the grace passed while it ran. It keeps the grace styling so its animations do not restart, and a
11
+ * later finish rolls Compacting to Compacted in place.
12
+ * - `instant`: it finished inside the grace, or had just finished when it mounted; it fades in as Compacted only.
13
+ * - `settled`: it was already running or finished when the history loaded; no entrance.
14
+ */
15
+ export type CompactionEntranceState =
16
+ | { readonly status: "grace" }
17
+ | { readonly status: "revealed" }
18
+ | { readonly status: "instant" }
19
+ | { readonly status: "settled" }
20
+ | { readonly status: "disposed" }
21
+
22
+ export type CompactionEntranceEvent =
23
+ | { readonly type: "running.changed"; readonly running: boolean }
24
+ | { readonly type: "grace.elapsed" }
25
+ | { readonly type: "disposed" }
26
+
27
+ export type CompactionEntranceEffect =
28
+ | { readonly type: "schedule-grace"; readonly delayMs: number }
29
+ | { readonly type: "cancel-grace" }
30
+
31
+ export type CompactionEntranceTransition = {
32
+ readonly state: CompactionEntranceState
33
+ readonly effects: readonly CompactionEntranceEffect[]
34
+ }
35
+
36
+ const GRACE: CompactionEntranceState = Object.freeze({ status: "grace" })
37
+
38
+ const REVEALED: CompactionEntranceState = Object.freeze({ status: "revealed" })
39
+
40
+ const INSTANT: CompactionEntranceState = Object.freeze({ status: "instant" })
41
+
42
+ const SETTLED: CompactionEntranceState = Object.freeze({ status: "settled" })
43
+
44
+ const DISPOSED: CompactionEntranceState = Object.freeze({ status: "disposed" })
45
+
46
+ const NO_EFFECTS: readonly CompactionEntranceEffect[] = Object.freeze([])
47
+
48
+ const SCHEDULE_GRACE: readonly CompactionEntranceEffect[] = Object.freeze([
49
+ Object.freeze({ type: "schedule-grace", delayMs: COMPACTION_GRACE_MS }),
50
+ ])
51
+
52
+ const CANCEL_GRACE: readonly CompactionEntranceEffect[] = Object.freeze([Object.freeze({ type: "cancel-grace" })])
53
+
54
+ export const GRACE_ELAPSED_EVENT: CompactionEntranceEvent = Object.freeze({ type: "grace.elapsed" })
55
+
56
+ export const DISPOSED_COMPACTION_ENTRANCE_EVENT: CompactionEntranceEvent = Object.freeze({ type: "disposed" })
57
+
58
+ /** `ageMs` is how long ago the compaction started, when the divider mounts. */
59
+ export function createCompactionEntranceState(input: {
60
+ ageMs: number
61
+ running: boolean
62
+ }): CompactionEntranceTransition {
63
+ if (input.running && input.ageMs < COMPACTION_GRACE_MS) return { state: GRACE, effects: SCHEDULE_GRACE }
64
+
65
+ if (!input.running && input.ageMs < COMPACTION_RECENT_DONE_MS) return { state: INSTANT, effects: NO_EFFECTS }
66
+
67
+ return { state: SETTLED, effects: NO_EFFECTS }
68
+ }
69
+
70
+ export function transitionCompactionEntrance(
71
+ state: CompactionEntranceState,
72
+ event: CompactionEntranceEvent,
73
+ ): CompactionEntranceTransition {
74
+ if (state.status === "disposed") return { state, effects: NO_EFFECTS }
75
+
76
+ if (event.type === "disposed")
77
+ return { state: DISPOSED, effects: state.status === "grace" ? CANCEL_GRACE : NO_EFFECTS }
78
+
79
+ if (state.status !== "grace") return { state, effects: NO_EFFECTS }
80
+
81
+ if (event.type === "grace.elapsed") return { state: REVEALED, effects: NO_EFFECTS }
82
+
83
+ return event.running ? { state, effects: NO_EFFECTS } : { state: INSTANT, effects: CANCEL_GRACE }
84
+ }
85
+
86
+ /** The divider's `data-enter`: `revealed` keeps `grace` so its delayed animations do not restart. */
87
+ export function selectCompactionEnter(state: CompactionEntranceState) {
88
+ if (state.status === "grace" || state.status === "revealed") return "grace"
89
+
90
+ if (state.status === "instant") return "now"
91
+
92
+ return undefined
93
+ }
@@ -0,0 +1,157 @@
1
+ import type { SessionMessageAssistant, SessionMessageAssistantTool, SessionMessageUser } from "@zyro-sec/client/promise"
2
+ import { Match, Switch, type ComponentProps } from "solid-js"
3
+ import type { SessionUserActions, SessionUserAttachmentReference, SessionUserComment } from "../actions"
4
+ import { AssistantReasoningContent, AssistantTextContent, CurrentUserMessageDisplay } from "./message-content"
5
+ import {
6
+ CurrentContextToolGroup,
7
+ CurrentFileToolGroup,
8
+ CurrentReadToolGroup,
9
+ ToolDisplay,
10
+ } from "../tools/tool-renderer"
11
+ import { currentToolError, currentToolInput, currentToolMetadata, currentToolOutput } from "./current-tool-state"
12
+ import type { UserRun } from "../timeline/user-runs"
13
+ import type { TurnSources } from "../sources/sources"
14
+
15
+ export type { SessionUserActions, SessionUserAttachmentReference, SessionUserComment } from "../actions"
16
+
17
+ export { SessionShellMessage } from "../tools/tool-renderer"
18
+
19
+ export { currentContentDefaultOpen } from "./current-tool-state"
20
+
21
+ export function SessionUserMessage(props: {
22
+ sessionID: string
23
+ message: SessionMessageUser
24
+ displayText?: string
25
+ comments?: SessionUserComment[]
26
+ references?: SessionUserAttachmentReference[]
27
+ voice?: boolean
28
+ historicalAgent: string
29
+ historicalModel: SessionMessageAssistant["model"]
30
+ actions?: SessionUserActions
31
+ run?: UserRun
32
+ /** The newest delivered prompt, whose revert undoes the last turn. */
33
+ latest?: boolean
34
+ runSnaps?: () => boolean
35
+ runHovered?: boolean
36
+ onMenuOpenChange?: (open: boolean) => void
37
+ fold?: boolean
38
+ expanded?: boolean
39
+ onExpandedChange?: (expanded: boolean) => void
40
+ inlineQuotes?: boolean
41
+ }) {
42
+ return (
43
+ <CurrentUserMessageDisplay
44
+ sessionID={props.sessionID}
45
+ message={props.message}
46
+ text={props.displayText ?? props.message.text}
47
+ comments={props.comments}
48
+ references={props.references}
49
+ voice={props.voice}
50
+ agent={props.historicalAgent}
51
+ model={props.historicalModel}
52
+ actions={props.actions}
53
+ run={props.run}
54
+ latest={props.latest}
55
+ runSnaps={props.runSnaps}
56
+ runHovered={props.runHovered}
57
+ onMenuOpenChange={props.onMenuOpenChange}
58
+ fold={props.fold}
59
+ expanded={props.expanded}
60
+ onExpandedChange={props.onExpandedChange}
61
+ inlineQuotes={props.inlineQuotes}
62
+ />
63
+ )
64
+ }
65
+
66
+ export function SessionAssistantContent(props: {
67
+ message: SessionMessageAssistant
68
+ content: SessionMessageAssistant["content"][number]
69
+ contentID: string
70
+ showAssistantCopyPartID?: string | null
71
+ keepCopyVisible?: boolean
72
+ turnDurationMs?: number | null
73
+ turnTokensPerSecond?: number
74
+ sources?: TurnSources
75
+ onOpenSources?: () => void
76
+ defaultOpen?: boolean
77
+ reasoningDefaultOpen?: boolean
78
+ toolOpen?: boolean
79
+ onToolOpenChange?: (open: boolean) => void
80
+ onContentRendered?: () => void
81
+ }) {
82
+ return (
83
+ <Switch>
84
+ <Match when={props.content.type === "text" ? props.content : undefined}>
85
+ {(content) => (
86
+ <AssistantTextContent
87
+ id={props.contentID}
88
+ text={content().text}
89
+ message={props.message}
90
+ showCopy={props.showAssistantCopyPartID === props.contentID}
91
+ keepCopyVisible={props.keepCopyVisible}
92
+ turnDurationMs={props.turnDurationMs}
93
+ turnTokensPerSecond={props.turnTokensPerSecond}
94
+ sources={props.sources}
95
+ onOpenSources={props.onOpenSources}
96
+ />
97
+ )}
98
+ </Match>
99
+ <Match when={props.content.type === "reasoning" ? props.content : undefined}>
100
+ {(content) => (
101
+ <AssistantReasoningContent
102
+ id={props.contentID}
103
+ content={content()}
104
+ streaming={false}
105
+ defaultOpen={props.reasoningDefaultOpen}
106
+ open={props.toolOpen}
107
+ onOpenChange={props.onToolOpenChange}
108
+ onContentRendered={props.onContentRendered}
109
+ />
110
+ )}
111
+ </Match>
112
+ <Match when={props.content.type === "tool" ? props.content : undefined}>
113
+ {(tool) => (
114
+ <ToolDisplay
115
+ id={props.contentID}
116
+ tool={tool().name}
117
+ input={currentToolInput(tool())}
118
+ metadata={currentToolMetadata(tool())}
119
+ output={currentToolOutput(tool())}
120
+ status={tool().state.status}
121
+ error={currentToolError(tool())}
122
+ defaultOpen={props.defaultOpen}
123
+ open={props.toolOpen}
124
+ onOpenChange={props.onToolOpenChange}
125
+ deferContent
126
+ virtualizeDiff={false}
127
+ onContentRendered={props.onContentRendered}
128
+ />
129
+ )}
130
+ </Match>
131
+ </Switch>
132
+ )
133
+ }
134
+
135
+ export function SessionContextToolGroup(props: ComponentProps<typeof CurrentContextToolGroup>) {
136
+ return <CurrentContextToolGroup {...props} />
137
+ }
138
+
139
+ export function SessionReadToolGroup(props: ComponentProps<typeof CurrentReadToolGroup>) {
140
+ return <CurrentReadToolGroup {...props} />
141
+ }
142
+
143
+ export function SessionFileToolGroup(props: {
144
+ tools: SessionMessageAssistantTool[]
145
+ fileOpen: (path: string) => boolean | undefined
146
+ onFileOpenChange: (path: string, open: boolean) => void
147
+ onSizeChange?: () => void
148
+ }) {
149
+ return (
150
+ <CurrentFileToolGroup
151
+ tools={props.tools}
152
+ fileOpen={props.fileOpen}
153
+ onFileOpenChange={props.onFileOpenChange}
154
+ onSizeChange={props.onSizeChange}
155
+ />
156
+ )
157
+ }
@@ -0,0 +1,161 @@
1
+ import type { SessionMessageAssistant, SessionMessageAssistantTool } from "@zyro-sec/client/promise"
2
+ import { Option, Predicate, Schema } from "effect"
3
+ import type { ToolProps } from "../tools/tool-renderer"
4
+
5
+ const decodeInput = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.JsonObject))
6
+
7
+ const empty: Schema.JsonObject = {}
8
+
9
+ export function currentToolInput(tool: SessionMessageAssistantTool) {
10
+ if (tool.state.status !== "streaming") return tool.state.input
11
+
12
+ return Option.getOrElse(decodeInput(tool.state.input), () => empty)
13
+ }
14
+
15
+ export function currentToolMetadata(tool: SessionMessageAssistantTool) {
16
+ if (!("metadata" in tool.state)) return empty
17
+
18
+ return tool.state.metadata ?? empty
19
+ }
20
+
21
+ export function currentToolOutput(tool: SessionMessageAssistantTool) {
22
+ if (tool.state.status === "running") {
23
+ const output = tool.state.metadata.output
24
+
25
+ return Predicate.isString(output) ? output : undefined
26
+ }
27
+
28
+ if (!("content" in tool.state) || !tool.state.content) return undefined
29
+ const text = tool.state.content.flatMap((item) => (item.type === "text" ? [item.text] : [])).join("\n")
30
+
31
+ return text || undefined
32
+ }
33
+
34
+ export function currentToolError(tool: SessionMessageAssistantTool) {
35
+ if (tool.state.status !== "error") return undefined
36
+
37
+ return tool.state.error.message
38
+ }
39
+
40
+ export function currentToolFailed(tool: SessionMessageAssistantTool) {
41
+ return (
42
+ tool.state.status === "error" ||
43
+ (tool.name === "execute" && executeToolFailed(currentToolMetadata(tool))) ||
44
+ (tool.name === "shell" && tool.state.status === "completed" && shellResultFailed(currentToolMetadata(tool)))
45
+ )
46
+ }
47
+
48
+ export function shellResultFailed(metadata: Schema.JsonObject) {
49
+ // Shell completion reports the process outcome in metadata, not the tool status.
50
+ return metadata.timeout === true || (Predicate.isNumber(metadata.exit) && metadata.exit !== 0)
51
+ }
52
+
53
+ function executeToolFailed(metadata: Schema.JsonObject) {
54
+ return metadata.error === true || executeToolErrorIndex(metadata) >= 0
55
+ }
56
+
57
+ const decodeExecuteCall = Schema.decodeUnknownOption(
58
+ Schema.Struct({
59
+ tool: Schema.String,
60
+ status: Schema.Literals(["running", "completed", "error"]),
61
+ input: Schema.optionalKey(Schema.Record(Schema.String, Schema.Unknown)),
62
+ }),
63
+ )
64
+
65
+ export type ExecuteToolCall = Option.Option.Value<ReturnType<typeof decodeExecuteCall>>
66
+
67
+ // Code Mode streams the tools a script calls through metadata rather than child tool parts. A script can make thousands
68
+ // of calls, so readers count and search them as they are and decode only the calls they show.
69
+ function executeToolCallList(metadata: ToolProps["metadata"]): readonly unknown[] {
70
+ const calls = metadata.toolCalls
71
+
72
+ return Array.isArray(calls) ? calls : []
73
+ }
74
+
75
+ export function executeToolCallCount(metadata: ToolProps["metadata"]) {
76
+ return executeToolCallList(metadata).length
77
+ }
78
+
79
+ /** The position of the last call that failed, or -1. */
80
+ export function executeToolErrorIndex(metadata: ToolProps["metadata"]) {
81
+ return executeToolCallList(metadata).findLastIndex(callFailed)
82
+ }
83
+
84
+ /** The calls from `start` on, each with its position among all of them. */
85
+ export function executeToolCalls(metadata: ToolProps["metadata"], start = 0) {
86
+ return executeToolCallList(metadata)
87
+ .slice(start)
88
+ .flatMap((call, offset) =>
89
+ Option.toArray(decodeExecuteCall(call)).map((value) => ({ index: start + offset, call: value })),
90
+ )
91
+ }
92
+
93
+ // Matches only calls the rows can decode, so a failure is never counted on a call that shows nowhere.
94
+ const callFailed = Schema.is(Schema.Struct({ tool: Schema.String, status: Schema.Literal("error") }))
95
+
96
+ const isCallArg = Schema.is(Schema.Union([Schema.String, Schema.Number, Schema.Boolean]))
97
+
98
+ export function executeToolCallArgs(call: ExecuteToolCall) {
99
+ return Object.entries(call.input ?? {})
100
+ .filter(([, value]) => isCallArg(value))
101
+ .map(([key, value]) => `${key}=${String(value).replace(/\s+/g, " ")}`)
102
+ }
103
+
104
+ // Collapsed rows name the failed call, or else the latest one.
105
+ export function executeToolSubtitle(metadata: ToolProps["metadata"]) {
106
+ const calls = executeToolCallList(metadata)
107
+ const failed = calls.findIndex(callFailed)
108
+ const call = Option.getOrUndefined(decodeExecuteCall(calls[failed >= 0 ? failed : calls.length - 1]))
109
+
110
+ if (!call) return undefined
111
+ const args = executeToolCallArgs(call)
112
+
113
+ return args.length ? `${call.tool} [${args.join(", ")}]` : call.tool
114
+ }
115
+
116
+ export function currentToolHasLoadedFiles(tool: SessionMessageAssistantTool) {
117
+ if (tool.name !== "read" || tool.state.status !== "completed") return false
118
+ const loaded = tool.state.metadata?.loaded
119
+
120
+ return Array.isArray(loaded) && loaded.some(Predicate.isString)
121
+ }
122
+
123
+ export function readImagePath(input: ToolProps["input"]) {
124
+ if (!Predicate.isString(input.path) || !/\.(png|jpe?g|gif|webp|svg|avif|bmp|ico)$/i.test(input.path)) return
125
+
126
+ return input.path.replaceAll("\\", "/")
127
+ }
128
+
129
+ // Plain file reads render as one comma-separated row; images and loaded instructions keep their own rows.
130
+ export function currentToolGroupedRead(tool: SessionMessageAssistantTool) {
131
+ return (
132
+ tool.name === "read" &&
133
+ tool.state.status !== "error" &&
134
+ !readImagePath(currentToolInput(tool)) &&
135
+ !currentToolHasLoadedFiles(tool)
136
+ )
137
+ }
138
+
139
+ export function currentContentDefaultOpen(
140
+ content: SessionMessageAssistant["content"][number],
141
+ shellExpanded: boolean,
142
+ editExpanded: boolean,
143
+ ) {
144
+ if (content.type !== "tool") return undefined
145
+
146
+ // Errored tools render the error card, which starts collapsed.
147
+ if (content.state.status === "error") return false
148
+
149
+ if (content.name === "shell" || content.name === "execute") return shellExpanded
150
+
151
+ if (content.name === "patch") return editExpanded
152
+
153
+ if (content.name !== "edit" && content.name !== "write") return undefined
154
+
155
+ if (!editExpanded) return false
156
+ const files = currentToolMetadata(content).files
157
+
158
+ if (!Array.isArray(files) || files.length === 0) return true
159
+
160
+ return !files.every((file) => Predicate.hasProperty(file, "status") && file.status === "deleted")
161
+ }