@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.
- package/AGENTS.md +25 -0
- package/bunfig.toml +2 -0
- package/component-tests/basic-tool.fixture.tsx +46 -0
- package/component-tests/basic-tool.spec.ts +63 -0
- package/component-tests/file-media.fixture.tsx +39 -0
- package/component-tests/file-media.spec.ts +13 -0
- package/component-tests/file-tool.spec.ts +62 -0
- package/component-tests/file-viewer.fixture.tsx +109 -0
- package/component-tests/file-viewer.spec.ts +134 -0
- package/component-tests/file.spec.ts +33 -0
- package/component-tests/line-comment-v2.spec.ts +15 -0
- package/component-tests/markdown-code-wrap.spec.ts +94 -0
- package/component-tests/markdown-readiness.spec.ts +95 -0
- package/component-tests/markdown.fixture.tsx +104 -0
- package/component-tests/markdown.spec.ts +1564 -0
- package/component-tests/mermaid-preview.spec.ts +43 -0
- package/component-tests/patch-group.spec.ts +79 -0
- package/component-tests/read-group.spec.ts +72 -0
- package/component-tests/read-image.fixture.tsx +66 -0
- package/component-tests/read-image.spec.ts +154 -0
- package/component-tests/session-compaction.spec.ts +254 -0
- package/component-tests/session-lifecycle.spec.ts +190 -0
- package/component-tests/session-message-projection.spec.ts +639 -0
- package/component-tests/session-notice-projection.spec.ts +20 -0
- package/component-tests/session-review-comments.spec.ts +179 -0
- package/component-tests/session-shell.spec.ts +93 -0
- package/component-tests/session-timeline-mobile.spec.ts +201 -0
- package/component-tests/session-timeline-notices.spec.ts +38 -0
- package/component-tests/session-timeline-reasoning.spec.ts +107 -0
- package/component-tests/session-timeline.spec.ts +157 -0
- package/component-tests/session-tool-projection.spec.ts +323 -0
- package/component-tests/text-lifecycle.fixture.tsx +26 -0
- package/component-tests/text-lifecycle.spec.ts +42 -0
- package/component-tests/timeline-subagent-rows.spec.ts +33 -0
- package/component-tests/tool-disclosure.spec.ts +48 -0
- package/component-tests/tool-group-sticky.spec.ts +37 -0
- package/component-tests/tool-group.spec.ts +290 -0
- package/component-tests/tool-status-title.fixture.tsx +22 -0
- package/component-tests/tool-status-title.spec.ts +30 -0
- package/component-tests/user-message-quotes.spec.ts +111 -0
- package/package.json +91 -4
- package/playwright.components.config.ts +4 -0
- package/playwright.local.config.ts +2 -0
- package/src/actions.ts +54 -0
- package/src/components/apply-patch-file.ts +122 -0
- package/src/components/basic-tool.css +487 -0
- package/src/components/basic-tool.tsx +258 -0
- package/src/components/copy-machine.ts +78 -0
- package/src/components/copy.ts +85 -0
- package/src/components/diagram-preview.tsx +28 -0
- package/src/components/disclosure-machine.ts +188 -0
- package/src/components/disclosure.ts +129 -0
- package/src/components/dock-prompt.stories.tsx +73 -0
- package/src/components/dock-prompt.tsx +29 -0
- package/src/components/file-comment-selection.tsx +146 -0
- package/src/components/file-media-machine.ts +165 -0
- package/src/components/file-media.stories.tsx +112 -0
- package/src/components/file-media.tsx +323 -0
- package/src/components/file-search.tsx +73 -0
- package/src/components/file.css +59 -0
- package/src/components/file.tsx +1300 -0
- package/src/components/image-preview.tsx +35 -0
- package/src/components/line-comment-annotations.tsx +580 -0
- package/src/components/line-comment-machine.ts +262 -0
- package/src/components/line-comment-styles.ts +293 -0
- package/src/components/line-comment.stories.tsx +152 -0
- package/src/components/line-comment.tsx +448 -0
- package/src/components/link-segments.ts +20 -0
- package/src/components/linked-text.tsx +21 -0
- package/src/components/markdown-cache-machine.ts +257 -0
- package/src/components/markdown-cache.tsx +556 -0
- package/src/components/markdown-clipboard.ts +101 -0
- package/src/components/markdown-code-machine.ts +200 -0
- package/src/components/markdown-code-state.ts +22 -0
- package/src/components/markdown-fragment-links.ts +74 -0
- package/src/components/markdown-github.svg +3 -0
- package/src/components/markdown-globe.svg +5 -0
- package/src/components/markdown-image-machine.ts +170 -0
- package/src/components/markdown-image.ts +156 -0
- package/src/components/markdown-inline-code-kind.ts +39 -0
- package/src/components/markdown-mermaid.ts +18 -0
- package/src/components/markdown-phase-machine.ts +102 -0
- package/src/components/markdown-projection.ts +13 -0
- package/src/components/markdown-session-links.ts +183 -0
- package/src/components/markdown-solid.test.tsx +92 -0
- package/src/components/markdown-solid.tsx +113 -0
- package/src/components/markdown-stream.ts +95 -0
- package/src/components/markdown-worker-machine.ts +516 -0
- package/src/components/markdown-worker-protocol.ts +73 -0
- package/src/components/markdown-worker.ts +250 -0
- package/src/components/markdown.css +672 -0
- package/src/components/markdown.stories.tsx +199 -0
- package/src/components/markdown.tsx +1612 -0
- package/src/components/markdown.worker.ts +188 -0
- package/src/components/message-file.ts +102 -0
- package/src/components/message-nav.css +134 -0
- package/src/components/message-nav.tsx +159 -0
- package/src/components/message-part.css +2109 -0
- package/src/components/message-part.tsx +3 -0
- package/src/components/question-prompt-experimental.css +576 -0
- package/src/components/question-prompt.css +527 -0
- package/src/components/quote-highlight.css +59 -0
- package/src/components/review-focus-driver.ts +142 -0
- package/src/components/review-focus-machine.ts +95 -0
- package/src/components/session-compaction.css +270 -0
- package/src/components/session-diff.ts +358 -0
- package/src/components/session-error.tsx +41 -0
- package/src/components/session-retry.tsx +92 -0
- package/src/components/session-review-machine.ts +241 -0
- package/src/components/session-review.css +264 -0
- package/src/components/session-review.stories.tsx +232 -0
- package/src/components/session-review.tsx +733 -0
- package/src/components/session-turn.css +282 -0
- package/src/components/shell-submessage.css +24 -0
- package/src/components/timeline-separator.tsx +69 -0
- package/src/components/tool-count-label.css +57 -0
- package/src/components/tool-count-label.tsx +76 -0
- package/src/components/tool-count-summary.css +102 -0
- package/src/components/tool-count-summary.stories.tsx +99 -0
- package/src/components/tool-count-summary.tsx +44 -0
- package/src/components/tool-error-card.css +178 -0
- package/src/components/tool-error-card.stories.tsx +113 -0
- package/src/components/tool-error-card.tsx +202 -0
- package/src/components/tool-status-title-machine.ts +128 -0
- package/src/components/tool-status-title.css +89 -0
- package/src/components/tool-status-title.tsx +163 -0
- package/src/context/data.tsx +107 -0
- package/src/context/index.ts +1 -0
- package/src/context/markdown.tsx +129 -0
- package/src/context/sources.tsx +34 -0
- package/src/document.ts +8 -0
- package/src/file-presentation.ts +34 -0
- package/src/message/action-machine.ts +72 -0
- package/src/message/agent-label.ts +3 -0
- package/src/message/attachment-card.css +119 -0
- package/src/message/attachment-card.tsx +40 -0
- package/src/message/attachment-media-machine.ts +213 -0
- package/src/message/comment-card.tsx +155 -0
- package/src/message/compaction-entrance-machine.ts +93 -0
- package/src/message/current-message.tsx +157 -0
- package/src/message/current-tool-state.ts +161 -0
- package/src/message/message-content.tsx +1391 -0
- package/src/message/paced-text-machine.ts +73 -0
- package/src/message/prompt-message.stories.tsx +149 -0
- package/src/message/relative-time.ts +45 -0
- package/src/message/user-message-quote-parts.ts +16 -0
- package/src/message/user-message-quotes.stories.tsx +797 -0
- package/src/message/user-message-quotes.tsx +135 -0
- package/src/pierre/comment-hover-machine.ts +53 -0
- package/src/pierre/comment-hover.ts +131 -0
- package/src/pierre/comment-selection-machine.ts +257 -0
- package/src/pierre/commented-lines.ts +106 -0
- package/src/pierre/diff-selection.ts +91 -0
- package/src/pierre/file-find-machine.ts +323 -0
- package/src/pierre/file-find.ts +537 -0
- package/src/pierre/file-runtime.ts +42 -0
- package/src/pierre/file-selection.ts +140 -0
- package/src/pierre/index.ts +344 -0
- package/src/pierre/media.ts +140 -0
- package/src/pierre/render-machine.ts +381 -0
- package/src/pierre/selection-bridge.ts +82 -0
- package/src/pierre/selection-machine.ts +198 -0
- package/src/pierre/virtualizer.ts +114 -0
- package/src/pierre/worker.ts +46 -0
- package/src/sources/experiment.ts +59 -0
- package/src/sources/site-icon.tsx +53 -0
- package/src/sources/sources-chip.tsx +57 -0
- package/src/sources/sources-expand-machine.ts +101 -0
- package/src/sources/sources-panel.tsx +249 -0
- package/src/sources/sources-title.tsx +21 -0
- package/src/sources/sources.css +266 -0
- package/src/sources/sources.ts +141 -0
- package/src/storybook/current-session-fixtures.ts +1492 -0
- package/src/storybook/current-session-scenarios.ts +76 -0
- package/src/storybook/current-session-story.tsx +154 -0
- package/src/storybook/index.ts +43 -0
- package/src/styles/index.css +19 -0
- package/src/timeline/__snapshots__/group-labels.test.ts.snap +110 -0
- package/src/timeline/__snapshots__/placement.test.ts.snap +1041 -0
- package/src/timeline/code-blocks.stories.tsx +105 -0
- package/src/timeline/commentary.stories.tsx +70 -0
- package/src/timeline/commentary.ts +38 -0
- package/src/timeline/detail.ts +111 -0
- package/src/timeline/error-card.stories.tsx +134 -0
- package/src/timeline/error-spacing.stories.tsx +71 -0
- package/src/timeline/facts.ts +493 -0
- package/src/timeline/file-changes.stories.tsx +436 -0
- package/src/timeline/group-label-fixtures.ts +97 -0
- package/src/timeline/mermaid.stories.tsx +131 -0
- package/src/timeline/place.ts +280 -0
- package/src/timeline/placement-fixtures.ts +365 -0
- package/src/timeline/placement-reactivity.ts +133 -0
- package/src/timeline/projection.ts +1261 -0
- package/src/timeline/research-and-agents.stories.tsx +461 -0
- package/src/timeline/session-timeline-row.tsx +1675 -0
- package/src/timeline/session-timeline.tsx +68 -0
- package/src/timeline/steer-arrival-machine.ts +134 -0
- package/src/timeline/terminal-work.stories.tsx +464 -0
- package/src/timeline/timeline-row.stories.tsx +1069 -0
- package/src/timeline/timeline-row.ts +238 -0
- package/src/timeline/turn-phase-machine.ts +112 -0
- package/src/timeline/user-message-fold.stories.tsx +194 -0
- package/src/timeline/user-runs.ts +87 -0
- package/src/timeline-next/__snapshots__/placement.test.ts.snap +990 -0
- package/src/timeline-next/compaction.tsx +236 -0
- package/src/timeline-next/errors.ts +101 -0
- package/src/timeline-next/event-row.tsx +168 -0
- package/src/timeline-next/events.ts +103 -0
- package/src/timeline-next/index.ts +10 -0
- package/src/timeline-next/nested-rail.ts +125 -0
- package/src/timeline-next/projection.ts +1028 -0
- package/src/timeline-next/row.tsx +1728 -0
- package/src/timeline-next/rules.ts +89 -0
- package/src/timeline-next/separator.tsx +73 -0
- package/src/timeline-next/spacing.ts +127 -0
- package/src/timeline-next/status-line.tsx +41 -0
- package/src/timeline-next/status.ts +33 -0
- package/src/timeline-next/stories/compare-renderer.stories.tsx +190 -0
- package/src/timeline-next/stories/compare-sessions/.gitignore +3 -0
- package/src/timeline-next/stories/compare.stories.tsx +486 -0
- package/src/timeline-next/stories/playground.stories.tsx +297 -0
- package/src/timeline-next/stories/session-replay.ts +1156 -0
- package/src/timeline-next/stories/session-timeline.tsx +50 -0
- package/src/timeline-next/stories/subagent-status.stories.tsx +132 -0
- package/src/timeline-next/timeline-next.css +649 -0
- package/src/timeline-next/tools/__snapshots__/activity-label.test.ts.snap +39 -0
- package/src/timeline-next/tools/activity-label.ts +166 -0
- package/src/timeline-next/tools/assistant-content.tsx +84 -0
- package/src/timeline-next/tools/context-group.tsx +619 -0
- package/src/timeline-next/tools/error-card.tsx +147 -0
- package/src/timeline-next/tools/explore.tsx +119 -0
- package/src/timeline-next/tools/file-group.tsx +128 -0
- package/src/timeline-next/tools/patch.tsx +174 -0
- package/src/timeline-next/tools/shell.tsx +186 -0
- package/src/timeline-next/tools/thought.tsx +87 -0
- package/src/timeline-next/tools/tool-display.tsx +119 -0
- package/src/tools/ansi.ts +8 -0
- package/src/tools/context-group-label.ts +123 -0
- package/src/tools/file-runs.ts +35 -0
- package/src/tools/project-path.ts +18 -0
- package/src/tools/read-group.stories.tsx +159 -0
- package/src/tools/run-machine.ts +185 -0
- package/src/tools/shell-output-machine.ts +233 -0
- package/src/tools/shell-output.ts +91 -0
- package/src/tools/subagent-row-variants.stories.tsx +129 -0
- package/src/tools/tool-group.stories.tsx +345 -0
- package/src/tools/tool-renderer.tsx +2876 -0
- package/src/v2/components/line-comment-annotations-v2.tsx +215 -0
- package/src/v2/components/session-file-panel-v2.tsx +149 -0
- package/src/v2/components/session-progress-indicator-v2.css +5 -0
- package/src/v2/components/session-progress-indicator-v2.stories.tsx +86 -0
- package/src/v2/components/session-progress-indicator-v2.tsx +16 -0
- package/src/v2/components/session-review-empty-changes-v2.tsx +17 -0
- package/src/v2/components/session-review-empty-no-git-v2.tsx +28 -0
- package/src/v2/components/session-review-file-preview-v2-virtualize.ts +5 -0
- package/src/v2/components/session-review-file-preview-v2.tsx +266 -0
- package/src/v2/components/session-review-v2.css +653 -0
- package/src/v2/components/session-review-v2.tsx +422 -0
- package/src/v2/components/sidebar-presence-machine.ts +69 -0
- package/tsconfig.json +20 -0
- package/README.md +0 -3
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/// <reference lib="webworker" />
|
|
2
|
+
|
|
3
|
+
import { codeToTokens, isSupportedLanguage, LiveTokenizer, type ThemedToken } from "@pierre/highlights"
|
|
4
|
+
import { createMarkdownParser } from "@zyro-sec/ui/context/marked-parser"
|
|
5
|
+
import { OpenCodeTheme } from "@zyro-sec/ui/context/highlight-theme"
|
|
6
|
+
import {
|
|
7
|
+
diffProjectionBlocks,
|
|
8
|
+
type MarkdownToken,
|
|
9
|
+
type MarkdownWorkerRequest,
|
|
10
|
+
type MarkdownWorkerResponse,
|
|
11
|
+
} from "./markdown-worker-protocol"
|
|
12
|
+
import { project, type Projection } from "./markdown-stream"
|
|
13
|
+
|
|
14
|
+
type Stream = {
|
|
15
|
+
language: string
|
|
16
|
+
source: string
|
|
17
|
+
tokenizer: LiveTokenizer
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const streams = new Map<string, Stream>()
|
|
21
|
+
|
|
22
|
+
const projections = new Map<string, Projection>()
|
|
23
|
+
|
|
24
|
+
const fragments = new Map<string, string>()
|
|
25
|
+
|
|
26
|
+
const parser = createMarkdownParser((html, block, display) => {
|
|
27
|
+
const key = Array.from(crypto.getRandomValues(new Uint32Array(4)), (n) => n.toString(16).padStart(8, "0")).join("")
|
|
28
|
+
fragments.set(key, html)
|
|
29
|
+
const tag = block ? "pre" : "span"
|
|
30
|
+
|
|
31
|
+
// A display formula is a block up to its maximum size wherever it sits in a line. The sanitizer reads the mark
|
|
32
|
+
// to keep such a block out of an application link's label, and drops it like every authored data attribute.
|
|
33
|
+
return `<${tag} id="${key}"${display ? " data-display" : ""}></${tag}>`
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
// Requests run in arrival order. The main thread's lanes already keep at most one request per key in flight and drop
|
|
37
|
+
// superseded snapshots before posting, so the worker needs no queue of its own.
|
|
38
|
+
self.onmessage = (event: MessageEvent<MarkdownWorkerRequest>) => {
|
|
39
|
+
if (event.data.type === "dispose") {
|
|
40
|
+
if (event.data.target === "project") projections.delete(event.data.key)
|
|
41
|
+
|
|
42
|
+
if (event.data.target === "highlight") closeStream(event.data.key)
|
|
43
|
+
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (event.data.type === "parse") {
|
|
48
|
+
void parse(event.data)
|
|
49
|
+
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (event.data.type === "project") {
|
|
54
|
+
runProject(event.data)
|
|
55
|
+
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
highlight(event.data)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function parse(request: Extract<MarkdownWorkerRequest, { type: "parse" }>) {
|
|
63
|
+
try {
|
|
64
|
+
const html = parser.parse(request.text, { async: false })
|
|
65
|
+
// postMessage clones synchronously. No fragment or token survives into the next request.
|
|
66
|
+
post({ type: "parse", id: request.id, html: fragments.size ? { html, fragments } : html })
|
|
67
|
+
} catch (error) {
|
|
68
|
+
post({ type: "error", id: request.id, message: error instanceof Error ? error.message : String(error) })
|
|
69
|
+
} finally {
|
|
70
|
+
fragments.clear()
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function runProject(request: Extract<MarkdownWorkerRequest, { type: "project" }>) {
|
|
75
|
+
try {
|
|
76
|
+
const previous = projections.get(request.key)
|
|
77
|
+
const projection = project(previous, request.text, request.live)
|
|
78
|
+
post({
|
|
79
|
+
type: "project",
|
|
80
|
+
id: request.id,
|
|
81
|
+
key: request.key,
|
|
82
|
+
...diffProjectionBlocks(previous?.blocks, projection.blocks),
|
|
83
|
+
})
|
|
84
|
+
// Kept only once posted: the main thread applies the next diff to the blocks it last received.
|
|
85
|
+
projections.set(request.key, projection)
|
|
86
|
+
} catch (error) {
|
|
87
|
+
projections.delete(request.key)
|
|
88
|
+
post({
|
|
89
|
+
type: "error",
|
|
90
|
+
id: request.id,
|
|
91
|
+
key: request.key,
|
|
92
|
+
message: error instanceof Error ? error.message : String(error),
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function highlight(request: Extract<MarkdownWorkerRequest, { type: "highlight" }>) {
|
|
98
|
+
try {
|
|
99
|
+
// Report the requested language so the viewer can label the block and spot Mermaid; lex unknown ones as text.
|
|
100
|
+
const language = request.language
|
|
101
|
+
const lang = isSupportedLanguage(language) ? language : "text"
|
|
102
|
+
|
|
103
|
+
if (request.complete) {
|
|
104
|
+
const result = codeToTokens(request.text, { lang, theme: OpenCodeTheme })
|
|
105
|
+
closeStream(request.key)
|
|
106
|
+
post({
|
|
107
|
+
type: "highlight",
|
|
108
|
+
id: request.id,
|
|
109
|
+
key: request.key,
|
|
110
|
+
language,
|
|
111
|
+
reset: true,
|
|
112
|
+
stable: result.tokens
|
|
113
|
+
.flatMap((line, index) =>
|
|
114
|
+
index === result.tokens.length - 1 ? line : [...line, { content: "\n", offset: 0 }],
|
|
115
|
+
)
|
|
116
|
+
.map(token),
|
|
117
|
+
unstable: [],
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const previous = streams.get(request.key)
|
|
124
|
+
const reset = !previous || previous.language !== language || !request.text.startsWith(previous.source)
|
|
125
|
+
|
|
126
|
+
if (reset) closeStream(request.key)
|
|
127
|
+
|
|
128
|
+
const stream =
|
|
129
|
+
reset || !previous
|
|
130
|
+
? { language, source: "", tokenizer: new LiveTokenizer({ lang, theme: OpenCodeTheme }) }
|
|
131
|
+
: previous
|
|
132
|
+
|
|
133
|
+
// Lines before the last are final because a lexer only carries state forward; the last line can still grow.
|
|
134
|
+
const start = stream.tokenizer.lineCount - 1
|
|
135
|
+
const end = { line: start, character: stream.tokenizer.getLineLength(start) }
|
|
136
|
+
stream.tokenizer.applyEdits([{ range: { start: end, end }, newText: request.text.slice(stream.source.length) }])
|
|
137
|
+
stream.source = request.text
|
|
138
|
+
streams.set(request.key, stream)
|
|
139
|
+
|
|
140
|
+
const last = stream.tokenizer.lineCount - 1
|
|
141
|
+
|
|
142
|
+
post({
|
|
143
|
+
type: "highlight",
|
|
144
|
+
id: request.id,
|
|
145
|
+
key: request.key,
|
|
146
|
+
language,
|
|
147
|
+
reset,
|
|
148
|
+
stable: Array.from({ length: last - start }, (_, index) => [
|
|
149
|
+
...stream.tokenizer.getLineTokens(start + index).tokens,
|
|
150
|
+
{ content: "\n", offset: 0 },
|
|
151
|
+
])
|
|
152
|
+
.flat()
|
|
153
|
+
.filter((token) => token.content.length > 0)
|
|
154
|
+
.map(token),
|
|
155
|
+
unstable: stream.tokenizer
|
|
156
|
+
.getLineTokens(last)
|
|
157
|
+
.tokens.filter((token) => token.content.length > 0)
|
|
158
|
+
.map(token),
|
|
159
|
+
})
|
|
160
|
+
} catch (error) {
|
|
161
|
+
post({
|
|
162
|
+
type: "error",
|
|
163
|
+
id: request.id,
|
|
164
|
+
key: request.key,
|
|
165
|
+
message: error instanceof Error ? error.message : String(error),
|
|
166
|
+
})
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function closeStream(key: string) {
|
|
171
|
+
streams.get(key)?.tokenizer.dispose()
|
|
172
|
+
streams.delete(key)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function post(response: MarkdownWorkerResponse) {
|
|
176
|
+
self.postMessage(response)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function token(value: ThemedToken): MarkdownToken {
|
|
180
|
+
const fontStyle = value.fontStyle ?? 0
|
|
181
|
+
|
|
182
|
+
return [
|
|
183
|
+
value.content,
|
|
184
|
+
[value.color && `color:${value.color}`, fontStyle & 1 && "font-style:italic", fontStyle & 2 && "font-weight:bold"]
|
|
185
|
+
.filter(Boolean)
|
|
186
|
+
.join(";"),
|
|
187
|
+
]
|
|
188
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { getFilename } from "@zyro-sec/util/path"
|
|
2
|
+
import type { PromptAttachment } from "@zyro-sec/client/promise"
|
|
3
|
+
|
|
4
|
+
export function attached(file: PromptAttachment) {
|
|
5
|
+
if (file.mention) return false
|
|
6
|
+
|
|
7
|
+
const source = file.source
|
|
8
|
+
|
|
9
|
+
if (!source || source.type === "inline") return true
|
|
10
|
+
|
|
11
|
+
return source.uri.startsWith("data:") || source.uri.startsWith("blob:")
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Display names for common source extensions; any other extension is shown in upper case.
|
|
15
|
+
const LANGUAGE_NAMES = new Map(
|
|
16
|
+
Object.entries({
|
|
17
|
+
Assembly: ["asm", "s"],
|
|
18
|
+
Astro: ["astro"],
|
|
19
|
+
"Batch File": ["bat", "cmd"],
|
|
20
|
+
C: ["c", "h"],
|
|
21
|
+
"C#": ["cs"],
|
|
22
|
+
"C++": ["cpp", "cc", "cxx", "hpp", "hh", "hxx"],
|
|
23
|
+
Clojure: ["clj", "cljs", "cljc", "edn"],
|
|
24
|
+
CSS: ["css"],
|
|
25
|
+
CUDA: ["cu", "cuh"],
|
|
26
|
+
Dart: ["dart"],
|
|
27
|
+
Diff: ["diff", "patch"],
|
|
28
|
+
Elixir: ["ex", "exs"],
|
|
29
|
+
Elm: ["elm"],
|
|
30
|
+
Erlang: ["erl", "hrl"],
|
|
31
|
+
"F#": ["fs", "fsi", "fsx"],
|
|
32
|
+
Fortran: ["f", "f77", "f90", "f95", "f03", "f08", "for"],
|
|
33
|
+
GDScript: ["gd"],
|
|
34
|
+
Gleam: ["gleam"],
|
|
35
|
+
GLSL: ["glsl", "vert", "frag", "geom", "comp"],
|
|
36
|
+
Go: ["go"],
|
|
37
|
+
GraphQL: ["graphql", "gql"],
|
|
38
|
+
Groovy: ["groovy", "gradle"],
|
|
39
|
+
Haskell: ["hs"],
|
|
40
|
+
HCL: ["hcl"],
|
|
41
|
+
HLSL: ["hlsl"],
|
|
42
|
+
HTML: ["html", "htm"],
|
|
43
|
+
Java: ["java"],
|
|
44
|
+
JavaScript: ["js", "cjs", "mjs"],
|
|
45
|
+
JSON: ["json"],
|
|
46
|
+
"JSON Lines": ["jsonl"],
|
|
47
|
+
"JSON with Comments": ["jsonc"],
|
|
48
|
+
JSON5: ["json5"],
|
|
49
|
+
JSX: ["jsx"],
|
|
50
|
+
Julia: ["jl"],
|
|
51
|
+
Kotlin: ["kt", "kts"],
|
|
52
|
+
LaTeX: ["tex", "latex"],
|
|
53
|
+
Less: ["less"],
|
|
54
|
+
Lua: ["lua"],
|
|
55
|
+
Markdown: ["md", "markdown"],
|
|
56
|
+
MDX: ["mdx"],
|
|
57
|
+
Nim: ["nim"],
|
|
58
|
+
Nix: ["nix"],
|
|
59
|
+
OCaml: ["ml", "mli"],
|
|
60
|
+
Perl: ["pl", "pm"],
|
|
61
|
+
PHP: ["php"],
|
|
62
|
+
PowerShell: ["ps1", "psm1"],
|
|
63
|
+
"Protocol Buffer": ["proto"],
|
|
64
|
+
Python: ["py", "pyi"],
|
|
65
|
+
R: ["r"],
|
|
66
|
+
Ruby: ["rb"],
|
|
67
|
+
Rust: ["rs"],
|
|
68
|
+
Sass: ["sass"],
|
|
69
|
+
Scala: ["scala", "sbt"],
|
|
70
|
+
SCSS: ["scss"],
|
|
71
|
+
Shell: ["sh", "bash", "zsh"],
|
|
72
|
+
Solidity: ["sol"],
|
|
73
|
+
SQL: ["sql"],
|
|
74
|
+
Svelte: ["svelte"],
|
|
75
|
+
SVG: ["svg"],
|
|
76
|
+
Swift: ["swift"],
|
|
77
|
+
Terraform: ["tf", "tfvars"],
|
|
78
|
+
TOML: ["toml"],
|
|
79
|
+
TSX: ["tsx"],
|
|
80
|
+
TypeScript: ["ts", "cts", "mts"],
|
|
81
|
+
Vue: ["vue"],
|
|
82
|
+
WebAssembly: ["wat", "wasm"],
|
|
83
|
+
WGSL: ["wgsl"],
|
|
84
|
+
XML: ["xml"],
|
|
85
|
+
YAML: ["yaml", "yml"],
|
|
86
|
+
Zig: ["zig"],
|
|
87
|
+
}).flatMap(([name, extensions]) => extensions.map((extension) => [extension, name] as const)),
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
// attachments carry text/plain for all text files, so the label comes from the extension;
|
|
91
|
+
// filename may be an absolute path, so extract the basename before looking for one
|
|
92
|
+
export function typeLabel(filename: string, mime: string, fallback: string) {
|
|
93
|
+
if (mime === "application/pdf") return "PDF"
|
|
94
|
+
const base = getFilename(filename)
|
|
95
|
+
// idx 0 is a dotfile like .gitignore, not an extension
|
|
96
|
+
const idx = base.lastIndexOf(".")
|
|
97
|
+
const suffix = idx <= 0 ? "" : base.slice(idx + 1).toLowerCase()
|
|
98
|
+
|
|
99
|
+
if (!suffix) return fallback
|
|
100
|
+
|
|
101
|
+
return LANGUAGE_NAMES.get(suffix) ?? suffix.toUpperCase()
|
|
102
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
[data-component="message-nav"] {
|
|
2
|
+
flex-shrink: 0;
|
|
3
|
+
display: flex;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
align-items: flex-start;
|
|
6
|
+
padding-left: 0;
|
|
7
|
+
list-style: none;
|
|
8
|
+
|
|
9
|
+
&[data-size="normal"] {
|
|
10
|
+
width: 200px;
|
|
11
|
+
gap: 4px;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
&[data-size="compact"] {
|
|
15
|
+
width: 24px;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
[data-slot="message-nav-item"] {
|
|
20
|
+
display: flex;
|
|
21
|
+
align-items: center;
|
|
22
|
+
align-self: stretch;
|
|
23
|
+
justify-content: flex-end;
|
|
24
|
+
|
|
25
|
+
[data-component="message-nav"][data-size="normal"] & {
|
|
26
|
+
justify-content: flex-start;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
[data-slot="message-nav-tick-button"] {
|
|
31
|
+
display: flex;
|
|
32
|
+
align-items: center;
|
|
33
|
+
justify-content: flex-start;
|
|
34
|
+
height: 12px;
|
|
35
|
+
width: 24px;
|
|
36
|
+
border: none;
|
|
37
|
+
background: none;
|
|
38
|
+
padding: 0;
|
|
39
|
+
|
|
40
|
+
&[data-active] [data-slot="message-nav-tick-line"] {
|
|
41
|
+
background-color: var(--icon-strong-base);
|
|
42
|
+
height: 2px;
|
|
43
|
+
width: 100%;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
[data-slot="message-nav-tick-line"] {
|
|
48
|
+
height: 1px;
|
|
49
|
+
width: 16px;
|
|
50
|
+
background-color: var(--icon-base);
|
|
51
|
+
transition:
|
|
52
|
+
width 0.2s,
|
|
53
|
+
background-color 0.2s;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
[data-slot="message-nav-tick-button"]:hover [data-slot="message-nav-tick-line"] {
|
|
57
|
+
width: 100%;
|
|
58
|
+
background-color: var(--icon-strong-base);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
[data-slot="message-nav-message-button"] {
|
|
62
|
+
display: flex;
|
|
63
|
+
align-items: center;
|
|
64
|
+
align-self: stretch;
|
|
65
|
+
width: 100%;
|
|
66
|
+
column-gap: 10px;
|
|
67
|
+
cursor: default;
|
|
68
|
+
border: none;
|
|
69
|
+
background: none;
|
|
70
|
+
padding: 4px 10px;
|
|
71
|
+
border-radius: var(--radius-sm);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
[data-slot="message-nav-diff-bars"] {
|
|
75
|
+
display: block;
|
|
76
|
+
width: 18px;
|
|
77
|
+
height: 14px;
|
|
78
|
+
flex-shrink: 0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
[data-slot="message-nav-title-preview"] {
|
|
82
|
+
font-size: 14px; /* text-14-regular */
|
|
83
|
+
color: var(--v2-text-text-muted);
|
|
84
|
+
white-space: nowrap;
|
|
85
|
+
overflow: hidden;
|
|
86
|
+
text-overflow: ellipsis;
|
|
87
|
+
min-width: 0;
|
|
88
|
+
text-align: left;
|
|
89
|
+
|
|
90
|
+
&[data-active] {
|
|
91
|
+
color: var(--v2-text-text-base);
|
|
92
|
+
font-weight: 500;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
[data-slot="message-nav-item"]:has([data-slot="message-nav-title-preview"][data-active])
|
|
97
|
+
[data-slot="message-nav-message-button"] {
|
|
98
|
+
background-color: var(--surface-base-active);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
[data-slot="message-nav-item"]:hover [data-slot="message-nav-message-button"] {
|
|
102
|
+
background-color: var(--surface-base);
|
|
103
|
+
}
|
|
104
|
+
[data-slot="message-nav-item"]:active [data-slot="message-nav-message-button"] {
|
|
105
|
+
background-color: var(--surface-base-active);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
[data-slot="message-nav-item"]:active [data-slot="message-nav-title-preview"] {
|
|
109
|
+
color: var(--v2-text-text-muted);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
[data-slot="message-nav-hovercard-content"] {
|
|
113
|
+
z-index: 1000;
|
|
114
|
+
display: flex;
|
|
115
|
+
padding: 4px 4px 6px 4px;
|
|
116
|
+
justify-content: center;
|
|
117
|
+
align-items: start;
|
|
118
|
+
border-radius: var(--radius-md);
|
|
119
|
+
background: var(--surface-raised-stronger-non-alpha);
|
|
120
|
+
max-height: min(480px, calc(100vh - 6rem));
|
|
121
|
+
overflow-y: auto;
|
|
122
|
+
overflow-x: hidden;
|
|
123
|
+
|
|
124
|
+
/* border/shadow-xs/base */
|
|
125
|
+
box-shadow:
|
|
126
|
+
0 0 0 1px var(--v2-border-border-base),
|
|
127
|
+
0 1px 2px -1px rgba(19, 16, 16, 0.04),
|
|
128
|
+
0 1px 2px 0 rgba(19, 16, 16, 0.06),
|
|
129
|
+
0 1px 3px 0 rgba(19, 16, 16, 0.08);
|
|
130
|
+
|
|
131
|
+
* {
|
|
132
|
+
margin: 0 !important;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import type { FileDiffInfo, SessionMessageUser } from "@zyro-sec/client/promise"
|
|
2
|
+
import { HoverCard } from "@kobalte/core/hover-card"
|
|
3
|
+
import { ComponentProps, For, Match, Show, createMemo, createSignal, splitProps, Switch } from "solid-js"
|
|
4
|
+
import { useI18n } from "@zyro-sec/ui/context/i18n"
|
|
5
|
+
|
|
6
|
+
export function MessageNav(
|
|
7
|
+
props: ComponentProps<"ul"> & {
|
|
8
|
+
messages: SessionMessageUser[]
|
|
9
|
+
current?: SessionMessageUser
|
|
10
|
+
size: "normal" | "compact"
|
|
11
|
+
onMessageSelect: (message: SessionMessageUser) => void
|
|
12
|
+
getLabel?: (message: SessionMessageUser) => string | undefined
|
|
13
|
+
getChanges?: (message: SessionMessageUser) => FileDiffInfo[] | undefined
|
|
14
|
+
},
|
|
15
|
+
) {
|
|
16
|
+
const i18n = useI18n()
|
|
17
|
+
|
|
18
|
+
const [local, others] = splitProps(props, [
|
|
19
|
+
"messages",
|
|
20
|
+
"current",
|
|
21
|
+
"size",
|
|
22
|
+
"onMessageSelect",
|
|
23
|
+
"getLabel",
|
|
24
|
+
"getChanges",
|
|
25
|
+
"class",
|
|
26
|
+
])
|
|
27
|
+
|
|
28
|
+
const [hovercardOpen, setHovercardOpen] = createSignal(false)
|
|
29
|
+
|
|
30
|
+
const selectMessage = (message: SessionMessageUser) => {
|
|
31
|
+
setHovercardOpen(false)
|
|
32
|
+
local.onMessageSelect(message)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const content = (className?: string) => (
|
|
36
|
+
<ul role="list" data-component="message-nav" data-size={local.size} class={className} {...others}>
|
|
37
|
+
<For each={local.messages}>
|
|
38
|
+
{(message) => {
|
|
39
|
+
const handleClick = () => selectMessage(message)
|
|
40
|
+
|
|
41
|
+
const handleKeyPress = (event: KeyboardEvent) => {
|
|
42
|
+
if (event.key !== "Enter" && event.key !== " ") return
|
|
43
|
+
event.preventDefault()
|
|
44
|
+
selectMessage(message)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<li data-slot="message-nav-item">
|
|
49
|
+
<Switch>
|
|
50
|
+
<Match when={local.size === "compact"}>
|
|
51
|
+
<div
|
|
52
|
+
data-slot="message-nav-tick-button"
|
|
53
|
+
data-active={message.id === local.current?.id || undefined}
|
|
54
|
+
role="button"
|
|
55
|
+
tabindex={0}
|
|
56
|
+
onClick={handleClick}
|
|
57
|
+
onKeyDown={handleKeyPress}
|
|
58
|
+
>
|
|
59
|
+
<div data-slot="message-nav-tick-line" />
|
|
60
|
+
</div>
|
|
61
|
+
</Match>
|
|
62
|
+
<Match when={local.size === "normal"}>
|
|
63
|
+
<button data-slot="message-nav-message-button" onClick={handleClick} onKeyDown={handleKeyPress}>
|
|
64
|
+
<MessageDiffBars changes={local.getChanges?.(message) ?? []} />
|
|
65
|
+
<div
|
|
66
|
+
data-slot="message-nav-title-preview"
|
|
67
|
+
data-active={message.id === local.current?.id || undefined}
|
|
68
|
+
>
|
|
69
|
+
<Show when={local.getLabel?.(message)} fallback={i18n.t("ui.messageNav.newMessage")}>
|
|
70
|
+
{local.getLabel?.(message)}
|
|
71
|
+
</Show>
|
|
72
|
+
</div>
|
|
73
|
+
</button>
|
|
74
|
+
</Match>
|
|
75
|
+
</Switch>
|
|
76
|
+
</li>
|
|
77
|
+
)
|
|
78
|
+
}}
|
|
79
|
+
</For>
|
|
80
|
+
</ul>
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<Switch>
|
|
85
|
+
<Match when={local.size === "compact"}>
|
|
86
|
+
<HoverCard
|
|
87
|
+
open={hovercardOpen()}
|
|
88
|
+
onOpenChange={setHovercardOpen}
|
|
89
|
+
openDelay={0}
|
|
90
|
+
closeDelay={120}
|
|
91
|
+
placement="right-start"
|
|
92
|
+
gutter={8}
|
|
93
|
+
overflowPadding={24}
|
|
94
|
+
fitViewport
|
|
95
|
+
>
|
|
96
|
+
<HoverCard.Trigger as="div" data-component="message-nav-hovercard" class={local.class}>
|
|
97
|
+
{content()}
|
|
98
|
+
</HoverCard.Trigger>
|
|
99
|
+
<HoverCard.Portal>
|
|
100
|
+
<HoverCard.Content data-slot="message-nav-hovercard-content">
|
|
101
|
+
<MessageNav {...props} size="normal" class="" onMessageSelect={selectMessage} />
|
|
102
|
+
</HoverCard.Content>
|
|
103
|
+
</HoverCard.Portal>
|
|
104
|
+
</HoverCard>
|
|
105
|
+
</Match>
|
|
106
|
+
<Match when={local.size === "normal"}>{content(local.class)}</Match>
|
|
107
|
+
</Switch>
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function MessageDiffBars(props: { changes: { additions: number; deletions: number }[] }) {
|
|
112
|
+
const additions = createMemo(() => props.changes.reduce((total, diff) => total + diff.additions, 0))
|
|
113
|
+
const deletions = createMemo(() => props.changes.reduce((total, diff) => total + diff.deletions, 0))
|
|
114
|
+
|
|
115
|
+
const colors = createMemo(() => {
|
|
116
|
+
const added = additions()
|
|
117
|
+
const deleted = deletions()
|
|
118
|
+
|
|
119
|
+
if (added === 0 && deleted === 0) return Array(5).fill("var(--icon-weak-base)")
|
|
120
|
+
|
|
121
|
+
if (added + deleted < 5) {
|
|
122
|
+
return [
|
|
123
|
+
...Array(added > 0 ? 1 : 0).fill("var(--icon-diff-add-base)"),
|
|
124
|
+
...Array(deleted > 0 ? 1 : 0).fill("var(--icon-diff-delete-base)"),
|
|
125
|
+
...Array(5 - (added > 0 ? 1 : 0) - (deleted > 0 ? 1 : 0)).fill("var(--icon-weak-base)"),
|
|
126
|
+
]
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const total = added + deleted
|
|
130
|
+
const ratio = added > deleted ? added / deleted : deleted / added
|
|
131
|
+
const colored = total < 20 || ratio < 4 ? 4 : 5
|
|
132
|
+
const addedRaw = (added / total) * colored
|
|
133
|
+
const deletedRaw = (deleted / total) * colored
|
|
134
|
+
|
|
135
|
+
const addedBars =
|
|
136
|
+
added === 0 ? 0 : Math.min(added <= 5 ? 1 : added <= 10 ? 2 : colored, Math.max(1, Math.round(addedRaw)))
|
|
137
|
+
|
|
138
|
+
const deletedBars =
|
|
139
|
+
deleted === 0 ? 0 : Math.min(deleted <= 5 ? 1 : deleted <= 10 ? 2 : colored, Math.max(1, Math.round(deletedRaw)))
|
|
140
|
+
|
|
141
|
+
const overflow = Math.max(0, addedBars + deletedBars - colored)
|
|
142
|
+
const adjustedAdded = overflow > 0 && addedRaw > deletedRaw ? addedBars - overflow : addedBars
|
|
143
|
+
const adjustedDeleted = overflow > 0 && addedRaw <= deletedRaw ? deletedBars - overflow : deletedBars
|
|
144
|
+
|
|
145
|
+
return [
|
|
146
|
+
...Array(adjustedAdded).fill("var(--icon-diff-add-base)"),
|
|
147
|
+
...Array(adjustedDeleted).fill("var(--icon-diff-delete-base)"),
|
|
148
|
+
...Array(5 - adjustedAdded - adjustedDeleted).fill("var(--icon-weak-base)"),
|
|
149
|
+
]
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<svg data-slot="message-nav-diff-bars" viewBox="0 0 18 14" aria-hidden="true">
|
|
154
|
+
<For each={colors().slice(0, 5)}>
|
|
155
|
+
{(color, index) => <rect x={index() * 4} width="2" height="14" rx="1" fill={color} />}
|
|
156
|
+
</For>
|
|
157
|
+
</svg>
|
|
158
|
+
)
|
|
159
|
+
}
|