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

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,147 @@
1
+ import { Badge } from "@zyro-sec/ui/badge"
2
+ import { Card, CardDescription } from "@zyro-sec/ui/card"
3
+ import { Collapsible } from "@zyro-sec/ui/collapsible"
4
+ import { useI18n } from "@zyro-sec/ui/context/i18n"
5
+ import { type ComponentProps, createMemo, onMount, Show, splitProps } from "solid-js"
6
+ import { createStore } from "solid-js/store"
7
+ import { createDisclosure } from "../../components/disclosure"
8
+
9
+ export interface ErrorCardProps extends Omit<ComponentProps<typeof Card>, "children" | "variant"> {
10
+ tool: string
11
+ error: string
12
+ title?: string
13
+ defaultOpen?: boolean
14
+ open?: boolean
15
+ onOpenChange?: (open: boolean) => void
16
+ subtitle?: string
17
+ href?: string
18
+ onSubtitleClick?: (event: MouseEvent) => void
19
+ }
20
+
21
+ // Tools named by what they did rather than the provider or the raw tool name.
22
+ const titles = new Map([
23
+ ["read", "ui.tool.read"],
24
+ ["list", "ui.tool.list"],
25
+ ["glob", "ui.tool.glob"],
26
+ ["grep", "ui.tool.grep"],
27
+ ["browser", "ui.tool.browser"],
28
+ ["subagent", "ui.tool.agent.default"],
29
+ ["webfetch", "ui.tool.fetch"],
30
+ ["websearch", "ui.tool.searchWeb"],
31
+ ["shell", "ui.tool.shell"],
32
+ ["execute", "ui.tool.execute"],
33
+ ["edit", "ui.messagePart.title.edit"],
34
+ ["write", "ui.messagePart.title.write"],
35
+ ["skill", "ui.tool.skill"],
36
+ ["patch", "ui.tool.patch"],
37
+ ["question", "ui.tool.questions"],
38
+ ])
39
+
40
+ /** A call that failed: the tool tagged Failed, open or closed; opening it shows the error itself. */
41
+ export function ErrorCard(props: ErrorCardProps) {
42
+ const i18n = useI18n()
43
+ const [state, setState] = createStore({ clipped: false })
44
+
45
+ const disclosure = createDisclosure({
46
+ open: () => props.open,
47
+ defaultOpen: () => props.defaultOpen ?? false,
48
+ onOpenChange: (open) => props.onOpenChange?.(open),
49
+ })
50
+
51
+ const open = disclosure.open
52
+ let subtitle: HTMLSpanElement | undefined
53
+
54
+ // Measured in the collapsed layout: a clipped subtitle moves from the one-line header into the open body.
55
+ const measure = () => {
56
+ if (!subtitle) return
57
+ setState("clipped", subtitle.textContent!.includes("\n") || subtitle.scrollWidth > subtitle.clientWidth)
58
+ }
59
+
60
+ onMount(() => {
61
+ if (open()) measure()
62
+ })
63
+
64
+ const [split, rest] = splitProps(props, [
65
+ "tool",
66
+ "error",
67
+ "title",
68
+ "defaultOpen",
69
+ "open",
70
+ "onOpenChange",
71
+ "subtitle",
72
+ "href",
73
+ "onSubtitleClick",
74
+ ])
75
+
76
+ const setOpen = (value: boolean) => {
77
+ if (value) measure()
78
+ disclosure.setOpen(value)
79
+ }
80
+
81
+ const name = createMemo(() => {
82
+ if (split.title) return split.title
83
+ const key = titles.get(split.tool)
84
+
85
+ return key ? i18n.t(key) : split.tool
86
+ })
87
+
88
+ return (
89
+ <Card
90
+ {...rest}
91
+ data-kind="tool-error-card"
92
+ data-tool={split.tool}
93
+ data-open={open() ? "true" : "false"}
94
+ variant="error"
95
+ >
96
+ <Collapsible class="tool-collapsible" data-open={open() ? "true" : "false"} open={open()} onOpenChange={setOpen}>
97
+ <Collapsible.Trigger>
98
+ <div data-component="tool-trigger">
99
+ <div data-slot="basic-tool-tool-trigger-content">
100
+ <div data-slot="basic-tool-tool-info">
101
+ <div data-slot="basic-tool-tool-info-structured">
102
+ <div data-slot="basic-tool-tool-info-main">
103
+ <span data-slot="basic-tool-tool-title">{name()}</span>
104
+ <Show when={split.subtitle && (split.href || !(open() && state.clipped))}>
105
+ <Show
106
+ when={split.href}
107
+ fallback={
108
+ <span ref={subtitle} data-slot="basic-tool-tool-subtitle">
109
+ {split.subtitle}
110
+ </span>
111
+ }
112
+ >
113
+ <a
114
+ data-slot="basic-tool-tool-subtitle"
115
+ class="clickable subagent-link"
116
+ href={split.href!}
117
+ onClick={(event) => {
118
+ event.stopPropagation()
119
+ split.onSubtitleClick?.(event)
120
+ }}
121
+ >
122
+ {split.subtitle}
123
+ </a>
124
+ </Show>
125
+ </Show>
126
+ <Badge data-slot="tool-error-card-failed" variant="danger">
127
+ {i18n.t("ui.toolErrorCard.failed")}
128
+ </Badge>
129
+ </div>
130
+ </div>
131
+ </div>
132
+ </div>
133
+ <Collapsible.Arrow />
134
+ </div>
135
+ </Collapsible.Trigger>
136
+ <Collapsible.Content>
137
+ <div data-slot="tool-error-card-content">
138
+ <Show when={state.clipped && split.subtitle}>
139
+ {(text) => <p data-slot="tool-error-card-subtitle">{text()}</p>}
140
+ </Show>
141
+ <CardDescription>{split.error.replace(/^Error:\s*/, "").trim()}</CardDescription>
142
+ </div>
143
+ </Collapsible.Content>
144
+ </Collapsible>
145
+ </Card>
146
+ )
147
+ }
@@ -0,0 +1,119 @@
1
+ import { useI18n } from "@zyro-sec/ui/context/i18n"
2
+ import { Icon } from "@zyro-sec/ui/icon"
3
+ import { TextShimmer } from "@zyro-sec/ui/text-shimmer"
4
+ import { createMemo, Show } from "solid-js"
5
+ import { BasicTool } from "../../components/basic-tool"
6
+ import { displayFolder, ExaOutput, toolInput, urls, type ToolProps } from "../../tools/tool-renderer"
7
+
8
+ /**
9
+ * The New timeline's exploring tools. A search shows what was searched, never the raw list it returned, so it has
10
+ * nothing to open; the web tools are named by what they did rather than the provider.
11
+ */
12
+
13
+ export function ListTool(props: ToolProps) {
14
+ const i18n = useI18n()
15
+
16
+ return (
17
+ <BasicTool
18
+ {...props}
19
+ icon="bullet-list"
20
+ hasContent={false}
21
+ trigger={{ title: i18n.t("ui.tool.list"), subtitle: displayFolder(toolInput(props.input).path) }}
22
+ />
23
+ )
24
+ }
25
+
26
+ export function GlobTool(props: ToolProps) {
27
+ const i18n = useI18n()
28
+ const input = createMemo(() => toolInput(props.input))
29
+
30
+ return (
31
+ <BasicTool
32
+ {...props}
33
+ icon="magnifying-glass-menu"
34
+ hasContent={false}
35
+ trigger={{
36
+ title: i18n.t("ui.tool.glob"),
37
+ subtitle: displayFolder(input().path),
38
+ args: input().pattern === undefined ? [] : ["pattern=" + input().pattern],
39
+ }}
40
+ />
41
+ )
42
+ }
43
+
44
+ export function GrepTool(props: ToolProps) {
45
+ const i18n = useI18n()
46
+ const input = createMemo(() => toolInput(props.input))
47
+
48
+ return (
49
+ <BasicTool
50
+ {...props}
51
+ icon="magnifying-glass-menu"
52
+ hasContent={false}
53
+ trigger={{
54
+ title: i18n.t("ui.tool.grep"),
55
+ subtitle: displayFolder(input().path),
56
+ args: [
57
+ ...(input().pattern === undefined ? [] : ["pattern=" + input().pattern]),
58
+ ...(input().include === undefined ? [] : ["include=" + input().include]),
59
+ ],
60
+ }}
61
+ />
62
+ )
63
+ }
64
+
65
+ export function WebFetchTool(props: ToolProps) {
66
+ const i18n = useI18n()
67
+ const pending = createMemo(() => props.status === "streaming" || props.status === "running")
68
+ const url = createMemo(() => toolInput(props.input).url ?? "")
69
+
70
+ return (
71
+ <BasicTool
72
+ {...props}
73
+ hideDetails
74
+ icon="select-element"
75
+ trigger={
76
+ <div data-slot="basic-tool-tool-info-structured">
77
+ <div data-slot="basic-tool-tool-info-main">
78
+ <span data-slot="basic-tool-tool-title">
79
+ <TextShimmer text={i18n.t("ui.tool.fetch")} active={pending()} />
80
+ </span>
81
+ <Show when={props.status !== "streaming" && url()}>
82
+ <a
83
+ data-slot="basic-tool-tool-subtitle"
84
+ class="webfetch-link"
85
+ href={url()}
86
+ target="_blank"
87
+ rel="noopener noreferrer"
88
+ onClick={(event) => event.stopPropagation()}
89
+ >
90
+ <span data-slot="webfetch-link-text">{url()}</span>
91
+ <Icon name="outline-square-arrow" class="webfetch-link-icon" />
92
+ </a>
93
+ </Show>
94
+ </div>
95
+ </div>
96
+ }
97
+ />
98
+ )
99
+ }
100
+
101
+ // The body lists the result links, so a search that returned none has nothing to open.
102
+ export function WebSearchTool(props: ToolProps) {
103
+ const i18n = useI18n()
104
+
105
+ return (
106
+ <BasicTool
107
+ {...props}
108
+ icon="select-element"
109
+ hasContent={urls(props.output).length > 0}
110
+ trigger={{
111
+ title: i18n.t("ui.tool.searchWeb"),
112
+ subtitle: toolInput(props.input).query ?? "",
113
+ subtitleClass: "exa-tool-query",
114
+ }}
115
+ >
116
+ <ExaOutput output={props.output} />
117
+ </BasicTool>
118
+ )
119
+ }
@@ -0,0 +1,128 @@
1
+ import type { FileDiffInfo, SessionMessageAssistantTool } from "@zyro-sec/client/promise"
2
+ import { createTwoFilesPatch, diffLines } from "diff"
3
+ import { createMemo } from "solid-js"
4
+ import { changedFileDiff } from "../../components/apply-patch-file"
5
+ import { currentToolInput, currentToolMetadata } from "../../message/current-tool-state"
6
+ import { samePatchFile, toolInput, toolMetadata } from "../../tools/tool-renderer"
7
+ import { PatchTool } from "./patch"
8
+
9
+ /** Calls that changed files, one after another, as one list of files. An edit or a write still in progress shows the change it is making. */
10
+ export function FileGroup(props: {
11
+ tools: SessionMessageAssistantTool[]
12
+ fileOpen?: (path: string) => boolean | undefined
13
+ onFileOpenChange?: (path: string, open: boolean) => void
14
+ onSizeChange?: () => void
15
+ }) {
16
+ const files = createMemo((previous: { key: string; toolID: string; value: FileDiffInfo }[]) => {
17
+ const next = props.tools.flatMap((tool) => {
18
+ const files = toolMetadata(currentToolMetadata(tool)).files ?? []
19
+
20
+ // Invalid entries render nothing, but metadata files still replace the input-derived preview.
21
+ if (files.length > 0)
22
+ return files.flatMap((value, index) =>
23
+ changedFileDiff(value) ? [{ key: `${tool.id}:${index}`, toolID: tool.id, value }] : [],
24
+ )
25
+ const input = toolInput(currentToolInput(tool))
26
+
27
+ if (input.path === undefined) return []
28
+
29
+ if (tool.name === "edit" && input.oldString !== undefined && input.newString !== undefined) {
30
+ const changes = diffLines(input.oldString, input.newString)
31
+
32
+ const additions = changes
33
+ .filter((change) => change.added)
34
+ .reduce((total, change) => total + (change.count ?? 0), 0)
35
+
36
+ const deletions = changes
37
+ .filter((change) => change.removed)
38
+ .reduce((total, change) => total + (change.count ?? 0), 0)
39
+
40
+ if (additions === 0 && deletions === 0) return []
41
+
42
+ return [
43
+ {
44
+ key: `${tool.id}:0`,
45
+ toolID: tool.id,
46
+ value: {
47
+ file: input.path,
48
+ patch: createTwoFilesPatch(input.path, input.path, input.oldString, input.newString),
49
+ additions,
50
+ deletions,
51
+ status: "modified" as const,
52
+ },
53
+ },
54
+ ]
55
+ }
56
+
57
+ if (tool.name !== "write" || !input.content) return []
58
+
59
+ return [
60
+ {
61
+ key: `${tool.id}:0`,
62
+ toolID: tool.id,
63
+ value: {
64
+ file: input.path,
65
+ patch: createTwoFilesPatch(input.path, input.path, "", input.content),
66
+ additions: input.content.split("\n").length - Number(input.content.endsWith("\n")),
67
+ deletions: 0,
68
+ status: "modified" as const,
69
+ },
70
+ },
71
+ ]
72
+ })
73
+
74
+ const updates = new Map(next.map((entry) => [entry.key, entry.value]))
75
+ const existing = new Set(previous.map((entry) => entry.key))
76
+ const owners = new Set(props.tools.map((tool) => tool.id))
77
+
78
+ const result = [
79
+ ...previous.flatMap((entry) => {
80
+ if (!owners.has(entry.toolID)) return []
81
+ const value = updates.get(entry.key)
82
+
83
+ if (!value || samePatchFile(value, entry.value)) return [entry]
84
+
85
+ return [{ ...entry, value }]
86
+ }),
87
+ ...next.filter((entry) => !existing.has(entry.key)),
88
+ ]
89
+
90
+ return result.length === previous.length && result.every((entry, index) => entry === previous[index])
91
+ ? previous
92
+ : result
93
+ }, [])
94
+
95
+ const metadata = createMemo(() => ({
96
+ files: files().map((entry) => entry.value),
97
+ }))
98
+
99
+ const pending = createMemo(() =>
100
+ props.tools.some((tool) => tool.state.status === "streaming" || tool.state.status === "running"),
101
+ )
102
+
103
+ const tool = createMemo(() => {
104
+ const name = props.tools[0]?.name
105
+
106
+ return name === "edit" || name === "write" ? name : "patch"
107
+ })
108
+
109
+ return (
110
+ <div
111
+ data-component="tool-part-wrapper"
112
+ data-timeline-part-id={props.tools.length === 1 ? props.tools[0]?.id : undefined}
113
+ data-timeline-part-ids={props.tools.length > 1 ? props.tools.map((tool) => tool.id).join(",") : undefined}
114
+ >
115
+ <PatchTool
116
+ tool={tool()}
117
+ input={{}}
118
+ metadata={metadata()}
119
+ status={pending() ? "running" : "completed"}
120
+ fileOpen={props.fileOpen}
121
+ onFileOpenChange={props.onFileOpenChange}
122
+ deferContent
123
+ virtualizeDiff={false}
124
+ onContentRendered={props.onSizeChange}
125
+ />
126
+ </div>
127
+ )
128
+ }
@@ -0,0 +1,174 @@
1
+ import { useFileComponent } from "@zyro-sec/ui/context/file"
2
+ import { useI18n } from "@zyro-sec/ui/context/i18n"
3
+ import { DiffChanges } from "@zyro-sec/ui/diff-changes"
4
+ import { FileIcon } from "@zyro-sec/ui/file-icon"
5
+ import { Icon } from "@zyro-sec/ui/icon"
6
+ import { getFilename } from "@zyro-sec/util/path"
7
+ import { batch, createMemo, createUniqueId, For, Index, Match, Show, Switch, type JSX } from "solid-js"
8
+ import { Dynamic } from "solid-js/web"
9
+ import { patchFileGroups } from "../../components/apply-patch-file"
10
+ import { createDisclosure } from "../../components/disclosure"
11
+ import { displayDirectory, FileAccordionGroup, FileTool, type ToolProps } from "../../tools/tool-renderer"
12
+
13
+ // One unchanged line around each change places it without a wall of context.
14
+ const context = 1
15
+
16
+ /**
17
+ * A file change: each file says what happened to it beside its name, in the change colors, and opens to its whole diff.
18
+ * A diff here is read, not acted on line by line, so its lines stay still.
19
+ */
20
+ export function PatchTool(props: ToolProps) {
21
+ const i18n = useI18n()
22
+ const fileComponent = useFileComponent()
23
+
24
+ const files = createMemo(
25
+ () =>
26
+ props.pendingFiles?.map((path) => ({
27
+ path,
28
+ type: "update" as const,
29
+ additions: 0,
30
+ deletions: 0,
31
+ views: [],
32
+ })) ?? patchFileGroups(props.metadata.files, context),
33
+ )
34
+
35
+ const title = createMemo(() => {
36
+ if (props.tool === "edit") return i18n.t("ui.messagePart.title.edit")
37
+
38
+ if (props.tool === "write") return i18n.t("ui.messagePart.title.write")
39
+
40
+ return i18n.t("ui.tool.patch")
41
+ })
42
+
43
+ return (
44
+ <div data-component="apply-patch-tool">
45
+ <Show when={files().length > 0} fallback={<FileTool {...props} title={title()} count={0} />}>
46
+ <FileAccordionGroup>
47
+ <Index each={files()}>
48
+ {(file) => {
49
+ // Each file opens on its own: the owner's `fileOpen` controls it, otherwise it keeps its own state.
50
+ const disclosure = createDisclosure({
51
+ open: () => (props.fileOpen ? props.fileOpen(file().path) === true : undefined),
52
+ defer: () => props.deferContent !== false,
53
+ onOpenChange: (open) => props.onFileOpenChange?.(file().path, open),
54
+ })
55
+
56
+ const views = () => (
57
+ <For each={file().views}>
58
+ {(view) => (
59
+ <div data-component="apply-patch-file-diff">
60
+ <Dynamic
61
+ component={fileComponent}
62
+ mode="diff"
63
+ virtualize={props.virtualizeDiff}
64
+ fileDiff={view.fileDiff}
65
+ hunkSeparators={view.fileDiff.isPartial ? "simple" : "line-info-basic"}
66
+ onRendered={props.onContentRendered}
67
+ lineHoverHighlight="disabled"
68
+ />
69
+ </div>
70
+ )}
71
+ </For>
72
+ )
73
+
74
+ return (
75
+ <FileAccordionItem
76
+ open={disclosure.open()}
77
+ onOpenChange={disclosure.setOpen}
78
+ type={file().type}
79
+ header={
80
+ <div data-slot="apply-patch-trigger-content">
81
+ <div data-slot="apply-patch-file-info">
82
+ <FileIcon node={{ path: file().path, type: "file" }} />
83
+ <div data-slot="apply-patch-file-name-container">
84
+ <Show when={file().path.includes("/")}>
85
+ <span data-slot="apply-patch-directory">{`\u202A${displayDirectory(file().path)}\u202C`}</span>
86
+ </Show>
87
+ <span data-slot="apply-patch-filename">{getFilename(file().path)}</span>
88
+ </div>
89
+ <Switch>
90
+ <Match when={file().type === "add"}>
91
+ <span data-component="diff-changes" data-appearance="standard">
92
+ <span data-slot="diff-changes-additions">{i18n.t("ui.patch.action.created")}</span>
93
+ </span>
94
+ </Match>
95
+ <Match when={file().type === "delete"}>
96
+ <span data-component="diff-changes" data-appearance="standard">
97
+ <span data-slot="diff-changes-deletions">{i18n.t("ui.patch.action.deleted")}</span>
98
+ </span>
99
+ </Match>
100
+ <Match when={true}>
101
+ <DiffChanges
102
+ appearance="standard"
103
+ markEmpty
104
+ changes={{ additions: file().additions, deletions: file().deletions }}
105
+ />
106
+ </Match>
107
+ </Switch>
108
+ </div>
109
+ <div data-slot="apply-patch-trigger-actions">
110
+ <Icon name="chevron-grabber-vertical" />
111
+ </div>
112
+ </div>
113
+ }
114
+ >
115
+ <Show when={disclosure.mounted()}>{views()}</Show>
116
+ </FileAccordionItem>
117
+ )
118
+ }}
119
+ </Index>
120
+ </FileAccordionGroup>
121
+ </Show>
122
+ </div>
123
+ )
124
+ }
125
+
126
+ function FileAccordionItem(props: {
127
+ open: boolean
128
+ onOpenChange: (open: boolean) => void
129
+ type?: string
130
+ header: JSX.Element
131
+ children: JSX.Element
132
+ }) {
133
+ const id = createUniqueId()
134
+
135
+ return (
136
+ <div
137
+ data-slot="accordion-item"
138
+ data-type={props.type}
139
+ data-expanded={props.open ? "" : undefined}
140
+ data-closed={!props.open ? "" : undefined}
141
+ >
142
+ <h3
143
+ data-slot="accordion-header"
144
+ data-component="sticky-accordion-header"
145
+ data-expanded={props.open ? "" : undefined}
146
+ data-closed={!props.open ? "" : undefined}
147
+ >
148
+ <button
149
+ type="button"
150
+ id={`${id}-trigger`}
151
+ data-slot="accordion-trigger"
152
+ data-expanded={props.open ? "" : undefined}
153
+ data-closed={!props.open ? "" : undefined}
154
+ aria-expanded={props.open}
155
+ aria-controls={props.open ? `${id}-content` : undefined}
156
+ onClick={() => batch(() => props.onOpenChange(!props.open))}
157
+ >
158
+ {props.header}
159
+ </button>
160
+ </h3>
161
+ <Show when={props.open}>
162
+ <div
163
+ id={`${id}-content`}
164
+ role="region"
165
+ aria-labelledby={`${id}-trigger`}
166
+ data-slot="accordion-content"
167
+ data-expanded=""
168
+ >
169
+ {props.children}
170
+ </div>
171
+ </Show>
172
+ </div>
173
+ )
174
+ }