@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.
- 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,1675 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SessionMessageAssistant,
|
|
3
|
+
SessionMessageInfo,
|
|
4
|
+
SessionMessageUser,
|
|
5
|
+
SessionStatus,
|
|
6
|
+
} from "@zyro-sec/client/promise"
|
|
7
|
+
import { useI18n } from "@zyro-sec/ui/context/i18n"
|
|
8
|
+
import { SessionTurn } from "@zyro-sec/util/session-turn"
|
|
9
|
+
import { Option, Predicate, Schema } from "effect"
|
|
10
|
+
import {
|
|
11
|
+
For,
|
|
12
|
+
Match,
|
|
13
|
+
Show,
|
|
14
|
+
Switch,
|
|
15
|
+
createComputed,
|
|
16
|
+
createEffect,
|
|
17
|
+
createMemo,
|
|
18
|
+
createSignal,
|
|
19
|
+
onCleanup,
|
|
20
|
+
untrack,
|
|
21
|
+
type Accessor,
|
|
22
|
+
type JSX,
|
|
23
|
+
} from "solid-js"
|
|
24
|
+
import { DiffChanges } from "@zyro-sec/ui/diff-changes"
|
|
25
|
+
import { Icon } from "@zyro-sec/ui/icon"
|
|
26
|
+
import { Spring, frameLoop, prefersReducedMotion } from "@zyro-sec/ui/motion"
|
|
27
|
+
import { springStyle } from "@zyro-sec/ui/motion/solid"
|
|
28
|
+
import { Dynamic } from "solid-js/web"
|
|
29
|
+
import type { SessionUserActions, SessionUserAttachmentReference, SessionUserComment } from "../actions"
|
|
30
|
+
import { useData } from "../context"
|
|
31
|
+
import { useSources } from "../context/sources"
|
|
32
|
+
import { turnSources } from "../sources/sources"
|
|
33
|
+
import { TimelineSeparator } from "../components/timeline-separator"
|
|
34
|
+
import {
|
|
35
|
+
SessionAssistantContent,
|
|
36
|
+
SessionContextToolGroup,
|
|
37
|
+
SessionFileToolGroup,
|
|
38
|
+
SessionReadToolGroup,
|
|
39
|
+
SessionShellMessage,
|
|
40
|
+
SessionUserMessage,
|
|
41
|
+
currentContentDefaultOpen,
|
|
42
|
+
} from "../message/current-message"
|
|
43
|
+
import {
|
|
44
|
+
AssistantReasoningContent,
|
|
45
|
+
SessionCompactionMessage,
|
|
46
|
+
SessionCompactionQueued,
|
|
47
|
+
} from "../message/message-content"
|
|
48
|
+
import {
|
|
49
|
+
FileChangeRuns,
|
|
50
|
+
fileRuns,
|
|
51
|
+
runDisclosureKey,
|
|
52
|
+
ScriptChanges,
|
|
53
|
+
taskAgentName,
|
|
54
|
+
ToolRegistry,
|
|
55
|
+
type ContextGroupPart,
|
|
56
|
+
} from "../tools/tool-renderer"
|
|
57
|
+
import { GenericTool } from "../components/basic-tool"
|
|
58
|
+
import { SessionRetry } from "../components/session-retry"
|
|
59
|
+
import { SessionError } from "../components/session-error"
|
|
60
|
+
import type { TimelineDetail } from "./detail"
|
|
61
|
+
import { scriptFileFact, type FileFact } from "./facts"
|
|
62
|
+
import { diffOpens, placeContent } from "./place"
|
|
63
|
+
import { userMessageRuns, userRunSpring } from "./user-runs"
|
|
64
|
+
import { attached } from "../components/message-file"
|
|
65
|
+
import {
|
|
66
|
+
createReactiveTimelineProjection,
|
|
67
|
+
Timeline,
|
|
68
|
+
TimelineRow,
|
|
69
|
+
unwrapErrorMessage,
|
|
70
|
+
type PartRef,
|
|
71
|
+
type ReasoningMode,
|
|
72
|
+
} from "./projection"
|
|
73
|
+
import { IDLE_TURN_PHASE, sameRef, viewTurnPhase } from "./turn-phase-machine"
|
|
74
|
+
import {
|
|
75
|
+
DISPOSED_STEER_ARRIVAL_EVENT,
|
|
76
|
+
INITIAL_STEER_ARRIVAL_STATE,
|
|
77
|
+
shouldGrowUserMessage,
|
|
78
|
+
shouldSnapUserRun,
|
|
79
|
+
transitionSteerArrival,
|
|
80
|
+
} from "./steer-arrival-machine"
|
|
81
|
+
|
|
82
|
+
const emptyAssistantMessages: SessionMessageAssistant[] = []
|
|
83
|
+
|
|
84
|
+
// Past this many files, the rest of a turn's changes wait behind "Show all".
|
|
85
|
+
const turnDiffFileLimit = 5
|
|
86
|
+
|
|
87
|
+
const decodeMetadataFile = Schema.decodeUnknownOption(Schema.Struct({ file: Schema.String }))
|
|
88
|
+
|
|
89
|
+
type Projection = ReturnType<typeof createReactiveTimelineProjection>
|
|
90
|
+
|
|
91
|
+
type FramedTimelineRow = Exclude<TimelineRow.TimelineRow, TimelineRow.TurnGap>
|
|
92
|
+
|
|
93
|
+
type Outcome = "completed" | "error" | "cancelled"
|
|
94
|
+
|
|
95
|
+
export type SessionUserPresentation = {
|
|
96
|
+
displayText?: string
|
|
97
|
+
comments?: SessionUserComment[]
|
|
98
|
+
references?: SessionUserAttachmentReference[]
|
|
99
|
+
/** A voice call's agent sent it on the user's behalf. */
|
|
100
|
+
voice?: boolean
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function createSessionTimelineRowRenderer(input: {
|
|
104
|
+
sessionID: Accessor<string>
|
|
105
|
+
status: Accessor<SessionStatus>
|
|
106
|
+
projection: Projection
|
|
107
|
+
presentation: (message: SessionMessageUser) => SessionUserPresentation | undefined
|
|
108
|
+
actions?: SessionUserActions
|
|
109
|
+
reasoningMode: Accessor<ReasoningMode>
|
|
110
|
+
shellToolDefaultOpen: Accessor<boolean>
|
|
111
|
+
editToolDefaultOpen: Accessor<boolean>
|
|
112
|
+
timelineDetail?: Accessor<TimelineDetail>
|
|
113
|
+
foldUserMessages?: Accessor<boolean>
|
|
114
|
+
inlineQuotes?: Accessor<boolean>
|
|
115
|
+
disclosure: {
|
|
116
|
+
value: (key: string) => boolean | undefined
|
|
117
|
+
set: (key: string, open: boolean) => void
|
|
118
|
+
patchGroupKeys?: Map<string, string>
|
|
119
|
+
}
|
|
120
|
+
centered?: Accessor<boolean>
|
|
121
|
+
padding?: Accessor<string>
|
|
122
|
+
anchor?: (messageID: string) => string | undefined
|
|
123
|
+
/** Scrolls to and expands the tool call named by its ID or by the shell ID a backgrounded shell call reports. */
|
|
124
|
+
revealPart?: (target: string) => boolean
|
|
125
|
+
}) {
|
|
126
|
+
const i18n = useI18n()
|
|
127
|
+
const data = useData()
|
|
128
|
+
const sourcesHost = useSources()
|
|
129
|
+
// Cached timelines retain file-change subgroup identities alongside their disclosure choices.
|
|
130
|
+
const patchGroupKeys = input.disclosure.patchGroupKeys ?? new Map<string, string>()
|
|
131
|
+
const patchPartKeys = new WeakMap<SessionMessageAssistant["content"][number], string>()
|
|
132
|
+
|
|
133
|
+
const turns = createMemo(() => {
|
|
134
|
+
const messages = [...input.projection.messageByID().values()]
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
messages,
|
|
138
|
+
legacy: SessionTurn.legacy(messages),
|
|
139
|
+
indexes: new Map(messages.map((message, index) => [message.id, index])),
|
|
140
|
+
}
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
const patchOwners = createMemo(() => {
|
|
144
|
+
const owners = new Map<string, string>()
|
|
145
|
+
const rows = input.projection.rows()
|
|
146
|
+
// Track status changes before a group is first opened: a failed file change can
|
|
147
|
+
// split an existing group without changing the projection's row identities.
|
|
148
|
+
rows.forEach((row) => {
|
|
149
|
+
if (!Predicate.isTagged(row, "AssistantPart") || row.group.type !== "context") return
|
|
150
|
+
row.group.refs.forEach((ref) => {
|
|
151
|
+
const content = Timeline.resolveContent(input.projection.messageByID().get(ref.messageID), ref.partID)
|
|
152
|
+
|
|
153
|
+
if (
|
|
154
|
+
content?.type !== "tool" ||
|
|
155
|
+
!["edit", "write", "patch"].includes(content.name) ||
|
|
156
|
+
content.state.status === "error"
|
|
157
|
+
)
|
|
158
|
+
return
|
|
159
|
+
const part = `${ref.messageID}:${ref.partID}`
|
|
160
|
+
const key = patchGroupKeys.get(part)
|
|
161
|
+
|
|
162
|
+
if (key && !owners.has(key)) owners.set(key, part)
|
|
163
|
+
})
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
return owners
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
const runs = createMemo(() => {
|
|
170
|
+
const messages = input.projection.messageByID()
|
|
171
|
+
const context = input.projection.userContextByID()
|
|
172
|
+
|
|
173
|
+
return userMessageRuns(input.projection.rows(), [...messages.values()], (id) => {
|
|
174
|
+
const message = messages.get(id)
|
|
175
|
+
const user = context.get(id)
|
|
176
|
+
|
|
177
|
+
if (message?.type !== "user" || !user) return undefined
|
|
178
|
+
const status = input.actions?.pending?.status(id)
|
|
179
|
+
const presentation = input.presentation(message)
|
|
180
|
+
|
|
181
|
+
return {
|
|
182
|
+
kind: status === "steering" || status === "stranded" || status === "sending" ? "pending" : "sent",
|
|
183
|
+
agent: user.agent,
|
|
184
|
+
model: user.model,
|
|
185
|
+
text: !!(presentation?.displayText ?? message.text),
|
|
186
|
+
attachments: (message.files ?? []).some(attached) || !!presentation?.references?.length,
|
|
187
|
+
}
|
|
188
|
+
})
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
// A steer sent while the timeline is open grows in. Messages already there when a session loads, history loaded
|
|
192
|
+
// above them, and rows the virtualizer remounts appear as they are. Every row change syncs here, so the driver reuses
|
|
193
|
+
// its events and skips a sync whose inputs did not change.
|
|
194
|
+
let arrivals = INITIAL_STEER_ARRIVAL_STATE
|
|
195
|
+
const arrivalRendered = { type: "rendered" as const, messageID: "" }
|
|
196
|
+
|
|
197
|
+
const noRows: readonly TimelineRow.TimelineRow[] = []
|
|
198
|
+
const arrivalSync = { type: "sync" as const, sessionID: "", rows: noRows, busy: false }
|
|
199
|
+
const arrivalGrown = { type: "grown" as const, messageID: "" }
|
|
200
|
+
|
|
201
|
+
const syncArrivals = () => {
|
|
202
|
+
const sessionID = input.sessionID()
|
|
203
|
+
const rows = input.projection.rows()
|
|
204
|
+
// The input's pending status lands after its row, so a message sent while the session works counts as a steer.
|
|
205
|
+
const busy = input.status().type !== "idle"
|
|
206
|
+
|
|
207
|
+
if (sessionID === arrivalSync.sessionID && rows === arrivalSync.rows && busy === arrivalSync.busy) return
|
|
208
|
+
arrivalSync.sessionID = sessionID
|
|
209
|
+
arrivalSync.rows = rows
|
|
210
|
+
arrivalSync.busy = busy
|
|
211
|
+
arrivals = transitionSteerArrival(arrivals, arrivalSync)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
createComputed(syncArrivals)
|
|
215
|
+
onCleanup(() => {
|
|
216
|
+
arrivals = transitionSteerArrival(arrivals, DISPOSED_STEER_ARRIVAL_EVENT)
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
// A row can render before the sync for the rows that hold it, so it syncs first.
|
|
220
|
+
const arriving = (messageID: string) =>
|
|
221
|
+
untrack(() => {
|
|
222
|
+
syncArrivals()
|
|
223
|
+
|
|
224
|
+
if (!shouldGrowUserMessage(arrivals, messageID)) return false
|
|
225
|
+
arrivalRendered.messageID = messageID
|
|
226
|
+
arrivals = transitionSteerArrival(arrivals, arrivalRendered)
|
|
227
|
+
|
|
228
|
+
return true
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
const grown = (messageID: string) => {
|
|
232
|
+
arrivalGrown.messageID = messageID
|
|
233
|
+
arrivals = transitionSteerArrival(arrivals, arrivalGrown)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// A run's gaps and meta lines snap while a steer arrives, because the arriving row grows in. Any other change, such
|
|
237
|
+
// as a steer delivered into the run above, springs every gap and meta line together, so the bubbles below hold still.
|
|
238
|
+
// Springs read this on every frame, so it holds for exactly as long as the grow runs.
|
|
239
|
+
const runSnaps = () =>
|
|
240
|
+
untrack(() => {
|
|
241
|
+
syncArrivals()
|
|
242
|
+
|
|
243
|
+
return shouldSnapUserRun(arrivals)
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
// The newest delivered prompt; reverting it undoes the last turn, so its menu calls the action Undo.
|
|
247
|
+
const latestSent = createMemo(
|
|
248
|
+
() =>
|
|
249
|
+
[...input.projection.messageByID().values()].findLast(
|
|
250
|
+
(message) => message.type === "user" && input.actions?.pending?.status(message.id) === undefined,
|
|
251
|
+
)?.id,
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
// Hovering a run's bubbles, or the gaps between them, shows the meta line its last bubble carries. Each bubble's
|
|
255
|
+
// body bridges the gaps to its neighbors, so moving between bubbles never hides the line, and an open menu keeps it
|
|
256
|
+
// while the pointer is on the menu.
|
|
257
|
+
const [hoveredMessage, setHoveredMessage] = createSignal<string>()
|
|
258
|
+
const [menuMessage, setMenuMessage] = createSignal<string>()
|
|
259
|
+
|
|
260
|
+
const runEnds = createMemo(() => {
|
|
261
|
+
const ends = new Map<string, string>()
|
|
262
|
+
const group: string[] = []
|
|
263
|
+
input.projection.rows().forEach((row) => {
|
|
264
|
+
if (!Predicate.isTagged(row, "UserMessage")) return
|
|
265
|
+
group.push(row.userMessageID)
|
|
266
|
+
|
|
267
|
+
if (runs().get(row.userMessageID)?.below) return
|
|
268
|
+
group.splice(0).forEach((id) => ends.set(id, row.userMessageID))
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
return ends
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
const runHovered = (messageID: string) => {
|
|
275
|
+
const ends = runEnds()
|
|
276
|
+
|
|
277
|
+
return [hoveredMessage(), menuMessage()].some((id) => !!id && ends.get(id) === messageID)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const bubble = (target: EventTarget | null) =>
|
|
281
|
+
target instanceof Element ? target.closest('[data-slot="user-message-body"]') : null
|
|
282
|
+
|
|
283
|
+
const hoverZone = (messageID: string) => ({
|
|
284
|
+
onPointerOver: (event: PointerEvent) => {
|
|
285
|
+
if (bubble(event.target)) setHoveredMessage(messageID)
|
|
286
|
+
},
|
|
287
|
+
onPointerOut: (event: PointerEvent) => {
|
|
288
|
+
const next = bubble(event.relatedTarget)
|
|
289
|
+
|
|
290
|
+
if (next && event.currentTarget instanceof Element && event.currentTarget.contains(next)) return
|
|
291
|
+
setHoveredMessage((current) => (current === messageID ? undefined : current))
|
|
292
|
+
},
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
const run = (messageID: string) =>
|
|
296
|
+
createMemo(() => runs().get(messageID), undefined, {
|
|
297
|
+
equals: (a, b) => a?.above === b?.above && a?.below === b?.below,
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
const phase = (messageID: string) => viewTurnPhase(input.projection.turnPhaseByID().get(messageID) ?? IDLE_TURN_PHASE)
|
|
301
|
+
|
|
302
|
+
const duration = (messageID: string) => {
|
|
303
|
+
const user = input.projection.messageByID().get(messageID)
|
|
304
|
+
|
|
305
|
+
if (user?.type !== "user") return null
|
|
306
|
+
|
|
307
|
+
const message = input.projection
|
|
308
|
+
.assistantMessagesByParent()
|
|
309
|
+
.get(messageID)
|
|
310
|
+
?.findLast((message) => message.time.completed !== undefined)
|
|
311
|
+
|
|
312
|
+
if (message?.time.completed === undefined || message.time.completed < user.time.created) return undefined
|
|
313
|
+
|
|
314
|
+
return SessionTurn.duration(turns().messages, message, {
|
|
315
|
+
index: turns().indexes.get(message.id),
|
|
316
|
+
legacy: turns().legacy,
|
|
317
|
+
})
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const copyContentID = (messageID: string) => {
|
|
321
|
+
if (phase(messageID).hideCopy) return null
|
|
322
|
+
|
|
323
|
+
const message = input.projection
|
|
324
|
+
.assistantMessagesByParent()
|
|
325
|
+
.get(messageID)
|
|
326
|
+
?.findLast((message) => message.content.some((content) => content.type === "text" && !!content.text.trim()))
|
|
327
|
+
|
|
328
|
+
return message
|
|
329
|
+
? Timeline.contentEntries(message).findLast(
|
|
330
|
+
(entry) => entry.content.type === "text" && !!entry.content.text.trim(),
|
|
331
|
+
)?.id
|
|
332
|
+
: undefined
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const latestCopyTurn = createMemo(() =>
|
|
336
|
+
Array.from(input.projection.assistantMessagesByParent().keys()).findLast((id) => !!copyContentID(id)),
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
const padding = () => input.padding?.() ?? "px-4 md:px-6"
|
|
340
|
+
|
|
341
|
+
const indexGroupContents = (refs: PartRef[]) => {
|
|
342
|
+
const result = new Map<string, Map<string, SessionMessageAssistant["content"][number]>>()
|
|
343
|
+
refs.forEach((ref) => {
|
|
344
|
+
if (result.has(ref.messageID)) return
|
|
345
|
+
const contents = new Map<string, SessionMessageAssistant["content"][number]>()
|
|
346
|
+
const message = input.projection.messageByID().get(ref.messageID)
|
|
347
|
+
|
|
348
|
+
if (message?.type === "assistant") {
|
|
349
|
+
Timeline.contentEntries(message).forEach((entry) => {
|
|
350
|
+
// Match resolveContent's first entry when content IDs repeat.
|
|
351
|
+
if (!contents.has(entry.id)) contents.set(entry.id, entry.content)
|
|
352
|
+
})
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
result.set(ref.messageID, contents)
|
|
356
|
+
})
|
|
357
|
+
|
|
358
|
+
return result
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
const renderAssistant = (row: Accessor<TimelineRow.AssistantPart>, onSizeChange?: () => void) => {
|
|
362
|
+
if (row().group.type === "context") {
|
|
363
|
+
const parts = createMemo(() => {
|
|
364
|
+
const group = row().group
|
|
365
|
+
|
|
366
|
+
if (group.type !== "context") return []
|
|
367
|
+
const contents = indexGroupContents(group.refs)
|
|
368
|
+
const streaming = phase(row().userMessageID).streamingReasoningRef
|
|
369
|
+
|
|
370
|
+
return group.refs.flatMap<ContextGroupPart>((ref) => {
|
|
371
|
+
const content = contents.get(ref.messageID)?.get(ref.partID)
|
|
372
|
+
|
|
373
|
+
if (content?.type === "tool") {
|
|
374
|
+
patchPartKeys.set(content, `${ref.messageID}:${ref.partID}`)
|
|
375
|
+
|
|
376
|
+
return [content]
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (content?.type === "reasoning")
|
|
380
|
+
return [
|
|
381
|
+
{
|
|
382
|
+
...content,
|
|
383
|
+
id: ref.partID,
|
|
384
|
+
streaming: sameRef(streaming, ref),
|
|
385
|
+
},
|
|
386
|
+
]
|
|
387
|
+
const message = input.projection.messageByID().get(ref.messageID)
|
|
388
|
+
|
|
389
|
+
if (content?.type === "text" && message?.type === "assistant")
|
|
390
|
+
return [
|
|
391
|
+
{
|
|
392
|
+
type: "text",
|
|
393
|
+
id: ref.partID,
|
|
394
|
+
render: () => <SessionAssistantContent message={message} content={content} contentID={ref.partID} />,
|
|
395
|
+
},
|
|
396
|
+
]
|
|
397
|
+
|
|
398
|
+
const script =
|
|
399
|
+
message?.type === "assistant" ? scriptFileFact(message.content, ref.messageID, ref.partID) : undefined
|
|
400
|
+
|
|
401
|
+
if (script)
|
|
402
|
+
return [
|
|
403
|
+
{
|
|
404
|
+
type: "file",
|
|
405
|
+
id: ref.partID,
|
|
406
|
+
file: script,
|
|
407
|
+
render: () => (
|
|
408
|
+
<ScriptChanges
|
|
409
|
+
files={[script]}
|
|
410
|
+
render={ToolRegistry.render("patch") ?? GenericTool}
|
|
411
|
+
fileOpen={(path) =>
|
|
412
|
+
input.disclosure.value(`patch:${path}`) ?? input.timelineDetail?.().edit.details === "expanded"
|
|
413
|
+
}
|
|
414
|
+
onFileOpenChange={(path, open) => input.disclosure.set(`patch:${path}`, open)}
|
|
415
|
+
onSizeChange={onSizeChange}
|
|
416
|
+
/>
|
|
417
|
+
),
|
|
418
|
+
},
|
|
419
|
+
]
|
|
420
|
+
|
|
421
|
+
if (ref.messageID !== ref.partID || !message) return []
|
|
422
|
+
|
|
423
|
+
if (message.type === "shell")
|
|
424
|
+
return [{ type: "shell", id: ref.partID, render: () => <Shell messageID={ref.messageID} grouped /> }]
|
|
425
|
+
|
|
426
|
+
if (message.type !== "assistant" && message.type !== "user")
|
|
427
|
+
return [{ type: "notice", id: ref.partID, render: () => <Notice messageID={ref.messageID} grouped /> }]
|
|
428
|
+
|
|
429
|
+
return []
|
|
430
|
+
})
|
|
431
|
+
})
|
|
432
|
+
|
|
433
|
+
const key = () => `context:${row().group.key}`
|
|
434
|
+
|
|
435
|
+
return (
|
|
436
|
+
<div class="contents" data-notices-only={parts().every((part) => part.type === "notice") ? "" : undefined}>
|
|
437
|
+
<SessionContextToolGroup
|
|
438
|
+
parts={parts()}
|
|
439
|
+
patchGroupKey={(tools) => {
|
|
440
|
+
const parts = tools.map((tool) => patchPartKeys.get(tool)!)
|
|
441
|
+
|
|
442
|
+
// After a split, only the subgroup with the earliest surviving member keeps the old anchor.
|
|
443
|
+
const key =
|
|
444
|
+
parts
|
|
445
|
+
.map((part) => patchGroupKeys.get(part))
|
|
446
|
+
.find((key) => key !== undefined && parts.includes(patchOwners().get(key)!)) ?? parts[0]!
|
|
447
|
+
|
|
448
|
+
parts.forEach((part) => patchGroupKeys.set(part, key))
|
|
449
|
+
|
|
450
|
+
return key
|
|
451
|
+
}}
|
|
452
|
+
reasoningDefaultOpen={
|
|
453
|
+
input.timelineDetail
|
|
454
|
+
? input.timelineDetail().thinking.details === "expanded"
|
|
455
|
+
: input.reasoningMode() === "full"
|
|
456
|
+
}
|
|
457
|
+
reasoningOpen={(id) => input.disclosure.value(id)}
|
|
458
|
+
onReasoningOpenChange={(id, open) => input.disclosure.set(id, open)}
|
|
459
|
+
toolDefaultOpen={(tool) =>
|
|
460
|
+
input.timelineDetail || tool.name === "execute" ? contentDefaultOpen(tool) : false
|
|
461
|
+
}
|
|
462
|
+
toolOpen={(id) => input.disclosure.value(`${row().group.key}:tool:${id}`)}
|
|
463
|
+
onToolOpenChange={(id, open) => input.disclosure.set(`${row().group.key}:tool:${id}`, open)}
|
|
464
|
+
fileOpen={(path) =>
|
|
465
|
+
input.disclosure.value(`patch:${path}`) ?? (!!input.timelineDetail && diffOpens(input.timelineDetail()))
|
|
466
|
+
}
|
|
467
|
+
onFileOpenChange={(path, open) => input.disclosure.set(`patch:${path}`, open)}
|
|
468
|
+
open={input.disclosure.value(key()) === true}
|
|
469
|
+
busy={
|
|
470
|
+
phase(row().userMessageID).live &&
|
|
471
|
+
input.projection.lastAssistantGroupKey().get(row().userMessageID) === row().group.key
|
|
472
|
+
}
|
|
473
|
+
onOpenChange={(open) => input.disclosure.set(key(), open)}
|
|
474
|
+
onSizeChange={onSizeChange}
|
|
475
|
+
/>
|
|
476
|
+
</div>
|
|
477
|
+
)
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
if (row().group.type === "read") {
|
|
481
|
+
const tools = createMemo(() => {
|
|
482
|
+
const group = row().group
|
|
483
|
+
|
|
484
|
+
if (group.type !== "read") return []
|
|
485
|
+
const contents = indexGroupContents(group.refs)
|
|
486
|
+
|
|
487
|
+
return group.refs.flatMap((ref) => {
|
|
488
|
+
const content = contents.get(ref.messageID)?.get(ref.partID)
|
|
489
|
+
|
|
490
|
+
return content?.type === "tool" ? [content] : []
|
|
491
|
+
})
|
|
492
|
+
})
|
|
493
|
+
|
|
494
|
+
return (
|
|
495
|
+
<SessionReadToolGroup
|
|
496
|
+
tools={tools()}
|
|
497
|
+
open={input.disclosure.value(row().group.key)}
|
|
498
|
+
onOpenChange={(open) => input.disclosure.set(row().group.key, open)}
|
|
499
|
+
onSizeChange={onSizeChange}
|
|
500
|
+
/>
|
|
501
|
+
)
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
if (row().group.type === "file") {
|
|
505
|
+
const tools = createMemo(() => {
|
|
506
|
+
const group = row().group
|
|
507
|
+
|
|
508
|
+
if (group.type !== "file") return []
|
|
509
|
+
const contents = indexGroupContents(group.refs)
|
|
510
|
+
|
|
511
|
+
return group.refs.flatMap((ref) => {
|
|
512
|
+
const content = contents.get(ref.messageID)?.get(ref.partID)
|
|
513
|
+
|
|
514
|
+
return content?.type === "tool" ? [content] : []
|
|
515
|
+
})
|
|
516
|
+
})
|
|
517
|
+
|
|
518
|
+
const firstPath = createMemo(() => {
|
|
519
|
+
const tool = tools()[0]
|
|
520
|
+
|
|
521
|
+
if (!tool || !("metadata" in tool.state)) return undefined
|
|
522
|
+
const files = tool.state.metadata?.files
|
|
523
|
+
|
|
524
|
+
if (!Array.isArray(files)) return undefined
|
|
525
|
+
|
|
526
|
+
return Option.getOrUndefined(decodeMetadataFile(files[0]))?.file
|
|
527
|
+
})
|
|
528
|
+
|
|
529
|
+
// Direct changes and a script's changes in the order they happened.
|
|
530
|
+
const runs = createMemo(() => {
|
|
531
|
+
const group = row().group
|
|
532
|
+
|
|
533
|
+
if (group.type !== "file") return []
|
|
534
|
+
const contents = indexGroupContents(group.refs)
|
|
535
|
+
|
|
536
|
+
return fileRuns(
|
|
537
|
+
group.refs.flatMap<Extract<SessionMessageAssistant["content"][number], { type: "tool" }> | FileFact>(
|
|
538
|
+
(ref) => {
|
|
539
|
+
const content = contents.get(ref.messageID)?.get(ref.partID)
|
|
540
|
+
|
|
541
|
+
if (content?.type === "tool") return [content]
|
|
542
|
+
const message = input.projection.messageByID().get(ref.messageID)
|
|
543
|
+
|
|
544
|
+
const file =
|
|
545
|
+
message?.type === "assistant" ? scriptFileFact(message.content, ref.messageID, ref.partID) : undefined
|
|
546
|
+
|
|
547
|
+
return file ? [file] : []
|
|
548
|
+
},
|
|
549
|
+
),
|
|
550
|
+
)
|
|
551
|
+
})
|
|
552
|
+
|
|
553
|
+
return (
|
|
554
|
+
<Show
|
|
555
|
+
when={runs().some((run) => run.type === "script")}
|
|
556
|
+
fallback={
|
|
557
|
+
<SessionFileToolGroup
|
|
558
|
+
tools={tools()}
|
|
559
|
+
fileOpen={(path) => {
|
|
560
|
+
const open = input.disclosure.value(`${row().group.key}:file:${path}`)
|
|
561
|
+
|
|
562
|
+
if (open !== undefined) return open
|
|
563
|
+
|
|
564
|
+
if (input.timelineDetail) return diffOpens(input.timelineDetail())
|
|
565
|
+
|
|
566
|
+
if (tools()[0]?.name !== "edit" || path !== firstPath()) return false
|
|
567
|
+
|
|
568
|
+
return input.disclosure.value(row().group.key) ?? input.editToolDefaultOpen()
|
|
569
|
+
}}
|
|
570
|
+
onFileOpenChange={(path, open) => input.disclosure.set(`${row().group.key}:file:${path}`, open)}
|
|
571
|
+
onSizeChange={onSizeChange}
|
|
572
|
+
/>
|
|
573
|
+
}
|
|
574
|
+
>
|
|
575
|
+
<FileChangeRuns
|
|
576
|
+
runs={runs()}
|
|
577
|
+
render={ToolRegistry.render("patch") ?? GenericTool}
|
|
578
|
+
tools={(run) => (
|
|
579
|
+
<SessionFileToolGroup
|
|
580
|
+
tools={run()}
|
|
581
|
+
fileOpen={(path) => {
|
|
582
|
+
const open = input.disclosure.value(
|
|
583
|
+
`${runDisclosureKey(row().group.key, run(), tools()[0])}:file:${path}`,
|
|
584
|
+
)
|
|
585
|
+
|
|
586
|
+
if (open !== undefined) return open
|
|
587
|
+
|
|
588
|
+
if (input.timelineDetail) return diffOpens(input.timelineDetail())
|
|
589
|
+
|
|
590
|
+
if (run()[0]?.name !== "edit" || path !== firstPath()) return false
|
|
591
|
+
|
|
592
|
+
return (
|
|
593
|
+
input.disclosure.value(runDisclosureKey(row().group.key, run(), tools()[0])) ??
|
|
594
|
+
input.editToolDefaultOpen()
|
|
595
|
+
)
|
|
596
|
+
}}
|
|
597
|
+
onFileOpenChange={(path, open) =>
|
|
598
|
+
input.disclosure.set(`${runDisclosureKey(row().group.key, run(), tools()[0])}:file:${path}`, open)
|
|
599
|
+
}
|
|
600
|
+
onSizeChange={onSizeChange}
|
|
601
|
+
/>
|
|
602
|
+
)}
|
|
603
|
+
fileOpen={(path) => {
|
|
604
|
+
const open = input.disclosure.value(`${row().group.key}:file:${path}`)
|
|
605
|
+
|
|
606
|
+
if (open !== undefined) return open
|
|
607
|
+
|
|
608
|
+
if (input.timelineDetail) return diffOpens(input.timelineDetail())
|
|
609
|
+
|
|
610
|
+
if (tools()[0]?.name !== "edit" || path !== firstPath()) return false
|
|
611
|
+
|
|
612
|
+
return input.disclosure.value(row().group.key) ?? input.editToolDefaultOpen()
|
|
613
|
+
}}
|
|
614
|
+
onFileOpenChange={(path, open) => input.disclosure.set(`${row().group.key}:file:${path}`, open)}
|
|
615
|
+
onSizeChange={onSizeChange}
|
|
616
|
+
/>
|
|
617
|
+
</Show>
|
|
618
|
+
)
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
const ref = createMemo(() => {
|
|
622
|
+
const group = row().group
|
|
623
|
+
|
|
624
|
+
return group.type === "part" ? group.ref : undefined
|
|
625
|
+
})
|
|
626
|
+
|
|
627
|
+
const message = createMemo(() => {
|
|
628
|
+
const current = ref()
|
|
629
|
+
const message = current ? input.projection.messageByID().get(current.messageID) : undefined
|
|
630
|
+
|
|
631
|
+
return message?.type === "assistant" ? message : undefined
|
|
632
|
+
})
|
|
633
|
+
|
|
634
|
+
const content = createMemo(() => {
|
|
635
|
+
const current = ref()
|
|
636
|
+
|
|
637
|
+
return current ? Timeline.resolveContent(message(), current.partID) : undefined
|
|
638
|
+
})
|
|
639
|
+
|
|
640
|
+
const defaultOpen = createMemo(() => {
|
|
641
|
+
const item = content()
|
|
642
|
+
|
|
643
|
+
return item ? contentDefaultOpen(item) : undefined
|
|
644
|
+
})
|
|
645
|
+
|
|
646
|
+
// Only the finished turn's footer part derives them, and only while the host shows sources.
|
|
647
|
+
const turnSourcesValue = createMemo(() => {
|
|
648
|
+
const current = ref()
|
|
649
|
+
|
|
650
|
+
if (!sourcesHost?.enabled || !current || copyContentID(row().userMessageID) !== current.partID) return undefined
|
|
651
|
+
|
|
652
|
+
const value = turnSources(
|
|
653
|
+
input.projection.assistantMessagesByParent().get(row().userMessageID) ?? emptyAssistantMessages,
|
|
654
|
+
)
|
|
655
|
+
|
|
656
|
+
return value.steps.length > 0 ? value : undefined
|
|
657
|
+
})
|
|
658
|
+
|
|
659
|
+
const turnTokensPerSecond = createMemo(() => {
|
|
660
|
+
const current = ref()
|
|
661
|
+
|
|
662
|
+
if (!current || copyContentID(row().userMessageID) !== current.partID) return undefined
|
|
663
|
+
|
|
664
|
+
const messages = input.projection.assistantMessagesByParent().get(row().userMessageID) ?? emptyAssistantMessages
|
|
665
|
+
|
|
666
|
+
const last = messages.at(-1)
|
|
667
|
+
|
|
668
|
+
if (!last) return undefined
|
|
669
|
+
|
|
670
|
+
return SessionTurn.tokensPerSecond(turns().messages, last, {
|
|
671
|
+
index: turns().indexes.get(last.id),
|
|
672
|
+
legacy: turns().legacy,
|
|
673
|
+
})
|
|
674
|
+
})
|
|
675
|
+
|
|
676
|
+
const disclosureKey = () => (content()?.type === "reasoning" ? ref()!.partID : row().group.key)
|
|
677
|
+
|
|
678
|
+
return (
|
|
679
|
+
<Show when={message()}>
|
|
680
|
+
{(message) => (
|
|
681
|
+
<Show when={content()}>
|
|
682
|
+
{(content) => (
|
|
683
|
+
<SessionAssistantContent
|
|
684
|
+
message={message()}
|
|
685
|
+
content={content()}
|
|
686
|
+
contentID={ref()!.partID}
|
|
687
|
+
showAssistantCopyPartID={copyContentID(row().userMessageID)}
|
|
688
|
+
keepCopyVisible={latestCopyTurn() === row().userMessageID}
|
|
689
|
+
turnDurationMs={duration(row().userMessageID)}
|
|
690
|
+
turnTokensPerSecond={turnTokensPerSecond()}
|
|
691
|
+
sources={turnSourcesValue()}
|
|
692
|
+
onOpenSources={() => sourcesHost?.open(row().userMessageID)}
|
|
693
|
+
defaultOpen={defaultOpen()}
|
|
694
|
+
toolOpen={input.disclosure.value(disclosureKey()) ?? defaultOpen()}
|
|
695
|
+
onToolOpenChange={(open) => input.disclosure.set(disclosureKey(), open)}
|
|
696
|
+
onContentRendered={onSizeChange}
|
|
697
|
+
/>
|
|
698
|
+
)}
|
|
699
|
+
</Show>
|
|
700
|
+
)}
|
|
701
|
+
</Show>
|
|
702
|
+
)
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
function contentDefaultOpen(item: SessionMessageAssistant["content"][number]) {
|
|
706
|
+
if (item.type === "tool" && item.name === "execute") return true
|
|
707
|
+
|
|
708
|
+
if (input.timelineDetail) return placeContent(item, input.timelineDetail(), "current").opens
|
|
709
|
+
|
|
710
|
+
if (item.type === "reasoning") return input.reasoningMode() === "full"
|
|
711
|
+
|
|
712
|
+
return currentContentDefaultOpen(item, input.shellToolDefaultOpen(), input.editToolDefaultOpen())
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
const notice = (message: SessionMessageInfo) => {
|
|
716
|
+
if (message.type === "agent-switched")
|
|
717
|
+
return {
|
|
718
|
+
label: i18n.t("ui.sessionTimeline.notice.agentChanged"),
|
|
719
|
+
data: message.previous
|
|
720
|
+
? `${capitalizeAgent(message.previous)} → ${capitalizeAgent(message.agent)}`
|
|
721
|
+
: capitalizeAgent(message.agent),
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
if (message.type === "model-switched") return undefined
|
|
725
|
+
|
|
726
|
+
if (message.type === "skill") return { label: i18n.t("ui.tool.skill"), data: message.name }
|
|
727
|
+
|
|
728
|
+
if (message.type === "system") {
|
|
729
|
+
const sources = Array.isArray(message.metadata?.instructionSources)
|
|
730
|
+
? message.metadata.instructionSources.filter(Predicate.isString)
|
|
731
|
+
: undefined
|
|
732
|
+
|
|
733
|
+
if (message.metadata?.notice === "instructions" && sources?.length)
|
|
734
|
+
return { label: i18n.t("ui.sessionTimeline.notice.instructionsUpdated"), items: sources }
|
|
735
|
+
const prefix = "Instructions updated: "
|
|
736
|
+
|
|
737
|
+
if (message.description?.startsWith(prefix)) {
|
|
738
|
+
const keys = message.description
|
|
739
|
+
.slice(prefix.length)
|
|
740
|
+
.split(",")
|
|
741
|
+
.map((s) => s.trim())
|
|
742
|
+
.filter(Boolean)
|
|
743
|
+
|
|
744
|
+
return {
|
|
745
|
+
label: i18n.t("ui.sessionTimeline.notice.instructionsUpdated"),
|
|
746
|
+
items: keys,
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
return { label: message.description ?? message.text }
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
if (message.type !== "synthetic") return undefined
|
|
754
|
+
|
|
755
|
+
if (message.metadata?.notice === "restart") return { label: i18n.t("ui.sessionTimeline.notice.restart") }
|
|
756
|
+
|
|
757
|
+
if (message.description === "Continuing after restart")
|
|
758
|
+
return { label: i18n.t("ui.sessionTimeline.notice.restart") }
|
|
759
|
+
const source = message.metadata?.source
|
|
760
|
+
|
|
761
|
+
if (source === "subagent" || source === "shell") {
|
|
762
|
+
const agent = message.metadata?.agent
|
|
763
|
+
|
|
764
|
+
const actor =
|
|
765
|
+
source === "shell"
|
|
766
|
+
? i18n.t("ui.tool.shell")
|
|
767
|
+
: ((Predicate.isString(agent) ? taskAgentName(agent, data.store.agent) : undefined) ??
|
|
768
|
+
i18n.t("ui.tool.agent.default"))
|
|
769
|
+
|
|
770
|
+
const state = message.metadata?.state
|
|
771
|
+
const outcome: Outcome = state === "error" || state === "cancelled" ? state : "completed"
|
|
772
|
+
|
|
773
|
+
return {
|
|
774
|
+
label: i18n.t(outcomeNoticeKey(outcome), { actor }),
|
|
775
|
+
data: message.description,
|
|
776
|
+
outcome,
|
|
777
|
+
icon: outcomeNoticeIcon(outcome),
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
if (source === "codemode") {
|
|
782
|
+
const state = message.metadata?.state
|
|
783
|
+
const outcome: Outcome = state === "error" || state === "cancelled" ? state : "completed"
|
|
784
|
+
const jobID = message.metadata?.jobID
|
|
785
|
+
|
|
786
|
+
return {
|
|
787
|
+
label: i18n.t(outcomeNoticeKey(outcome), { actor: "Script" }),
|
|
788
|
+
data: Predicate.isString(jobID) ? jobID : undefined,
|
|
789
|
+
outcome,
|
|
790
|
+
icon: outcomeNoticeIcon(outcome),
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
return { label: message.description ?? message.text }
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
const Frame = (props: { row: FramedTimelineRow; grow?: boolean; children: JSX.Element }) => (
|
|
798
|
+
<div
|
|
799
|
+
ref={(el) => {
|
|
800
|
+
if (props.grow) growIn(el, () => grown(props.row.userMessageID))
|
|
801
|
+
}}
|
|
802
|
+
id={Predicate.isTagged(props.row, "UserMessage") ? input.anchor?.(props.row.userMessageID) : undefined}
|
|
803
|
+
data-message-id={props.row.userMessageID}
|
|
804
|
+
data-timeline-row={props.row._tag}
|
|
805
|
+
data-timeline-spacing={Predicate.isTagged(props.row, "AssistantPart") ? props.row.spacing : undefined}
|
|
806
|
+
classList={{
|
|
807
|
+
"min-w-0 w-full max-w-full": true,
|
|
808
|
+
"md:max-w-session md:mx-auto": input.centered?.(),
|
|
809
|
+
"pt-2": Predicate.isTagged(props.row, "AssistantPart") && props.row.spacing === "tool",
|
|
810
|
+
"pt-4": Predicate.isTagged(props.row, "AssistantPart") && props.row.spacing === "content",
|
|
811
|
+
"pt-6": Predicate.isTagged(props.row, "Error"),
|
|
812
|
+
}}
|
|
813
|
+
>
|
|
814
|
+
<div data-component="session-turn" class="min-w-0 w-full relative" style={{ height: "auto" }}>
|
|
815
|
+
{props.children}
|
|
816
|
+
</div>
|
|
817
|
+
</div>
|
|
818
|
+
)
|
|
819
|
+
|
|
820
|
+
function Notice(props: { messageID: string; grouped?: boolean }) {
|
|
821
|
+
const inset = () => (props.grouped ? "" : padding())
|
|
822
|
+
const message = createMemo(() => input.projection.messageByID().get(props.messageID))
|
|
823
|
+
|
|
824
|
+
const compaction = createMemo(() => {
|
|
825
|
+
const value = message()
|
|
826
|
+
|
|
827
|
+
return value?.type === "compaction" ? value : undefined
|
|
828
|
+
})
|
|
829
|
+
|
|
830
|
+
const compactionError = createMemo(() => {
|
|
831
|
+
const value = compaction()
|
|
832
|
+
|
|
833
|
+
if (value?.status !== "failed") return ""
|
|
834
|
+
|
|
835
|
+
return unwrapErrorMessage(value.error.message)
|
|
836
|
+
})
|
|
837
|
+
|
|
838
|
+
const moved = createMemo(() => {
|
|
839
|
+
const value = message()
|
|
840
|
+
|
|
841
|
+
return value?.type === "location-switched" ? value : undefined
|
|
842
|
+
})
|
|
843
|
+
|
|
844
|
+
const model = createMemo(() => {
|
|
845
|
+
const value = message()
|
|
846
|
+
|
|
847
|
+
if (value?.type !== "model-switched") return undefined
|
|
848
|
+
const match = data.store.provider?.all?.get(value.model.providerID)
|
|
849
|
+
const variantOnly = value.previous?.providerID === value.model.providerID && value.previous.id === value.model.id
|
|
850
|
+
const variant = value.model.variant ?? "default"
|
|
851
|
+
|
|
852
|
+
// A model's faster and slower speeds are models of their own ("gpt-5.5-fast"), so moving between them is a
|
|
853
|
+
// change of speed.
|
|
854
|
+
const info = match?.models?.[value.model.id]
|
|
855
|
+
const before = value.previous?.providerID === value.model.providerID && match?.models?.[value.previous.id]
|
|
856
|
+
|
|
857
|
+
if (
|
|
858
|
+
info &&
|
|
859
|
+
before &&
|
|
860
|
+
!variantOnly &&
|
|
861
|
+
(before.speed?.base ?? value.previous?.id) === (info.speed?.base ?? value.model.id)
|
|
862
|
+
)
|
|
863
|
+
return {
|
|
864
|
+
providerID: value.model.providerID,
|
|
865
|
+
variant: undefined,
|
|
866
|
+
label: info.speed
|
|
867
|
+
? i18n.t("ui.sessionTimeline.notice.speedSwitched", { speed: info.speed.id })
|
|
868
|
+
: i18n.t("ui.sessionTimeline.notice.speedStandard"),
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
return {
|
|
872
|
+
providerID: value.model.providerID,
|
|
873
|
+
variant: variantOnly ? undefined : value.model.variant,
|
|
874
|
+
label: variantOnly
|
|
875
|
+
? variant === "default"
|
|
876
|
+
? i18n.t("ui.sessionTimeline.notice.variantDefault")
|
|
877
|
+
: i18n.t("ui.sessionTimeline.notice.variantSwitched", { variant })
|
|
878
|
+
: i18n.t("ui.sessionTimeline.notice.modelSwitched", {
|
|
879
|
+
model: match?.models?.[value.model.id]?.name ?? value.model.id,
|
|
880
|
+
}),
|
|
881
|
+
}
|
|
882
|
+
})
|
|
883
|
+
|
|
884
|
+
const content = createMemo(() => {
|
|
885
|
+
const value = message()
|
|
886
|
+
|
|
887
|
+
return value ? notice(value) : undefined
|
|
888
|
+
})
|
|
889
|
+
|
|
890
|
+
const childID = createMemo(() => {
|
|
891
|
+
const value = message()
|
|
892
|
+
|
|
893
|
+
if (value?.type !== "synthetic" || value.metadata?.source !== "subagent") return
|
|
894
|
+
const id = value.metadata.childID
|
|
895
|
+
|
|
896
|
+
if (Predicate.isString(id) && id) return id
|
|
897
|
+
})
|
|
898
|
+
|
|
899
|
+
const href = createMemo(() => {
|
|
900
|
+
const id = childID()
|
|
901
|
+
|
|
902
|
+
if (id) return data.sessionHref?.(id)
|
|
903
|
+
})
|
|
904
|
+
|
|
905
|
+
// A finished background shell jumps to its call, as its activity pill does.
|
|
906
|
+
const shellID = createMemo(() => {
|
|
907
|
+
const value = message()
|
|
908
|
+
|
|
909
|
+
if (!input.revealPart || value?.type !== "synthetic" || value.metadata?.source !== "shell") return
|
|
910
|
+
const id = value.metadata.shellID
|
|
911
|
+
|
|
912
|
+
if (Predicate.isString(id) && id) return id
|
|
913
|
+
})
|
|
914
|
+
|
|
915
|
+
const clickable = createMemo(() => !!shellID() || !!(childID() && (data.navigateToSession || href())))
|
|
916
|
+
|
|
917
|
+
const open = () => {
|
|
918
|
+
const shell = shellID()
|
|
919
|
+
|
|
920
|
+
if (shell) return void input.revealPart?.(shell)
|
|
921
|
+
const id = childID()
|
|
922
|
+
|
|
923
|
+
if (id) data.navigateToSession?.(id)
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
const navigate = (event: MouseEvent) => {
|
|
927
|
+
if (!shellID() && (!childID() || !data.navigateToSession)) return
|
|
928
|
+
|
|
929
|
+
if (event.button !== 0 || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return
|
|
930
|
+
event.preventDefault()
|
|
931
|
+
open()
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
const navigateKey = (event: KeyboardEvent) => {
|
|
935
|
+
if (!clickable() || href()) return
|
|
936
|
+
|
|
937
|
+
if (event.key !== "Enter" && event.key !== " ") return
|
|
938
|
+
event.preventDefault()
|
|
939
|
+
open()
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
return (
|
|
943
|
+
<>
|
|
944
|
+
<Show when={compaction()}>
|
|
945
|
+
{(message) => (
|
|
946
|
+
<div data-slot="session-turn-message-container" class={`w-full ${inset()}`}>
|
|
947
|
+
<div data-slot="session-turn-compaction">
|
|
948
|
+
<SessionCompactionMessage message={message()} error={compactionError()} />
|
|
949
|
+
</div>
|
|
950
|
+
</div>
|
|
951
|
+
)}
|
|
952
|
+
</Show>
|
|
953
|
+
<Show
|
|
954
|
+
when={moved()}
|
|
955
|
+
fallback={
|
|
956
|
+
<Show
|
|
957
|
+
when={model()}
|
|
958
|
+
fallback={
|
|
959
|
+
<Show when={content()}>
|
|
960
|
+
{(content) => (
|
|
961
|
+
<Show
|
|
962
|
+
when={content().items?.length}
|
|
963
|
+
fallback={
|
|
964
|
+
<Dynamic
|
|
965
|
+
component={href() ? "a" : "div"}
|
|
966
|
+
data-slot="session-timeline-notice"
|
|
967
|
+
data-outcome={content().outcome}
|
|
968
|
+
class={`block w-full truncate ${props.grouped ? "py-1" : "pt-3 pb-1"} text-13-regular leading-text-compact text-v2-text-text-faint ${inset()}`}
|
|
969
|
+
classList={{ "cursor-pointer hover:text-v2-text-text-base": clickable() }}
|
|
970
|
+
href={href()}
|
|
971
|
+
role={clickable() && !href() ? (shellID() ? "button" : "link") : undefined}
|
|
972
|
+
tabIndex={clickable() && !href() ? 0 : undefined}
|
|
973
|
+
onClick={navigate}
|
|
974
|
+
onKeyDown={navigateKey}
|
|
975
|
+
>
|
|
976
|
+
<Show when={content().icon}>
|
|
977
|
+
{(icon) => (
|
|
978
|
+
<Icon
|
|
979
|
+
name={icon()}
|
|
980
|
+
size="normal"
|
|
981
|
+
class={`inline-block align-top me-1.5 ${outcomeNoticeColor(content().outcome)}`}
|
|
982
|
+
/>
|
|
983
|
+
)}
|
|
984
|
+
</Show>
|
|
985
|
+
<bdi
|
|
986
|
+
dir="auto"
|
|
987
|
+
class={`font-[530] ${outcomeNoticeColor(content().outcome)}`}
|
|
988
|
+
classList={{ "text-v2-text-text-faint": message()?.type === "agent-switched" }}
|
|
989
|
+
>
|
|
990
|
+
{content().label}
|
|
991
|
+
</bdi>
|
|
992
|
+
<Show when={content().data}>
|
|
993
|
+
{(data) => (
|
|
994
|
+
<span classList={{ "ms-2": message()?.type === "agent-switched" }}>
|
|
995
|
+
<Show when={message()?.type !== "agent-switched"}>{" · "}</Show>
|
|
996
|
+
<bdi dir="auto">{data()}</bdi>
|
|
997
|
+
</span>
|
|
998
|
+
)}
|
|
999
|
+
</Show>
|
|
1000
|
+
</Dynamic>
|
|
1001
|
+
}
|
|
1002
|
+
>
|
|
1003
|
+
<div data-slot="session-timeline-notice" class={`w-full py-1 ${inset()}`}>
|
|
1004
|
+
<div class="flex min-h-5 min-w-0 items-center gap-2 overflow-hidden">
|
|
1005
|
+
<bdi
|
|
1006
|
+
dir="auto"
|
|
1007
|
+
class="shrink-0 text-[13px] font-[530] leading-text-compact tracking-[-0.04px] text-v2-text-text-faint"
|
|
1008
|
+
>
|
|
1009
|
+
{content().label}
|
|
1010
|
+
</bdi>
|
|
1011
|
+
<For each={content().items}>
|
|
1012
|
+
{(item) => (
|
|
1013
|
+
<bdi
|
|
1014
|
+
dir="auto"
|
|
1015
|
+
class="min-w-0 truncate text-[13px] font-[440] leading-text-compact tracking-[-0.04px] text-v2-text-text-faint"
|
|
1016
|
+
>
|
|
1017
|
+
{item}
|
|
1018
|
+
</bdi>
|
|
1019
|
+
)}
|
|
1020
|
+
</For>
|
|
1021
|
+
</div>
|
|
1022
|
+
</div>
|
|
1023
|
+
</Show>
|
|
1024
|
+
)}
|
|
1025
|
+
</Show>
|
|
1026
|
+
}
|
|
1027
|
+
>
|
|
1028
|
+
{(model) => (
|
|
1029
|
+
<div data-slot="session-timeline-notice" data-type="model-switched" class={`w-full py-2 ${inset()}`}>
|
|
1030
|
+
<TimelineSeparator label={model().label} providerID={model().providerID} variant={model().variant} />
|
|
1031
|
+
</div>
|
|
1032
|
+
)}
|
|
1033
|
+
</Show>
|
|
1034
|
+
}
|
|
1035
|
+
>
|
|
1036
|
+
{(message) => (
|
|
1037
|
+
<div data-slot="session-timeline-notice" data-type="location-switched" class={`w-full py-2 ${inset()}`}>
|
|
1038
|
+
<TimelineSeparator
|
|
1039
|
+
label={i18n.t("ui.sessionTimeline.notice.movedTo")}
|
|
1040
|
+
value={message().location.directory}
|
|
1041
|
+
tooltip={i18n.t("ui.sessionTimeline.notice.movedTooltip")}
|
|
1042
|
+
/>
|
|
1043
|
+
</div>
|
|
1044
|
+
)}
|
|
1045
|
+
</Show>
|
|
1046
|
+
</>
|
|
1047
|
+
)
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
function Shell(props: { messageID: string; grouped?: boolean }) {
|
|
1051
|
+
const message = createMemo(() => {
|
|
1052
|
+
const value = input.projection.messageByID().get(props.messageID)
|
|
1053
|
+
|
|
1054
|
+
return value?.type === "shell" ? value : undefined
|
|
1055
|
+
})
|
|
1056
|
+
|
|
1057
|
+
const defaultOpen = createMemo(() => {
|
|
1058
|
+
if (!input.timelineDetail) return input.shellToolDefaultOpen()
|
|
1059
|
+
const value = message()
|
|
1060
|
+
|
|
1061
|
+
return (
|
|
1062
|
+
input.timelineDetail().shell.details === "expanded" ||
|
|
1063
|
+
(input.timelineDetail().shell.placement === "hidden" &&
|
|
1064
|
+
(value?.status === "timeout" || (value?.status === "exited" && value.exit !== undefined && value.exit !== 0)))
|
|
1065
|
+
)
|
|
1066
|
+
})
|
|
1067
|
+
|
|
1068
|
+
return (
|
|
1069
|
+
<Show when={message()}>
|
|
1070
|
+
{(message) => (
|
|
1071
|
+
<div data-slot="session-turn-message-container" class={`w-full ${props.grouped ? "" : padding()}`}>
|
|
1072
|
+
<SessionShellMessage
|
|
1073
|
+
message={message()}
|
|
1074
|
+
defaultOpen={defaultOpen()}
|
|
1075
|
+
open={input.disclosure.value(message().id) ?? (input.timelineDetail ? defaultOpen() : undefined)}
|
|
1076
|
+
onOpenChange={(open) => input.disclosure.set(message().id, open)}
|
|
1077
|
+
/>
|
|
1078
|
+
</div>
|
|
1079
|
+
)}
|
|
1080
|
+
</Show>
|
|
1081
|
+
)
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
function TurnDiff(props: { row: TimelineRow.TurnDiff; onSizeChange?: () => void }) {
|
|
1085
|
+
const render = ToolRegistry.render("patch") ?? GenericTool
|
|
1086
|
+
// Until the diff loads, and if it fails, list the paths the turn's steps recorded, without change counts.
|
|
1087
|
+
const turn = () => ({ sessionID: input.sessionID(), from: props.row.from })
|
|
1088
|
+
const state = createMemo(() => data.turnDiff?.state(turn()))
|
|
1089
|
+
|
|
1090
|
+
const diffs = () => {
|
|
1091
|
+
const current = state()
|
|
1092
|
+
|
|
1093
|
+
return current?.status === "ready" ? current.diffs : undefined
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
const failed = () => state()?.status === "failed"
|
|
1097
|
+
const paths = () => diffs()?.map((diff) => diff.file) ?? props.row.files
|
|
1098
|
+
const showAllKey = () => `turn-diff:${props.row.messageID}`
|
|
1099
|
+
const showAll = () => input.disclosure.value(showAllKey()) === true
|
|
1100
|
+
const limit = <T,>(items: readonly T[]) => (showAll() ? items : items.slice(0, turnDiffFileLimit))
|
|
1101
|
+
const overflow = () => paths().length > turnDiffFileLimit
|
|
1102
|
+
const fileKey = (path: string) => `turn-diff:${props.row.messageID}:file:${path}`
|
|
1103
|
+
|
|
1104
|
+
// Loads once per turn. A failure settles until the row remounts or the reader retries.
|
|
1105
|
+
createEffect(() => data.turnDiff?.load(turn()))
|
|
1106
|
+
|
|
1107
|
+
return (
|
|
1108
|
+
<Show when={data.turnDiff && paths().length > 0}>
|
|
1109
|
+
<div data-slot="session-turn-diffs" class="flex flex-col gap-2 pt-4">
|
|
1110
|
+
<div class="flex h-6 min-w-0 items-center gap-2">
|
|
1111
|
+
<span class="shrink-0 text-14-medium text-v2-text-text-base tabular-nums">
|
|
1112
|
+
{i18n.plural("ui.sessionTurn.diffs.changed", paths().length)}
|
|
1113
|
+
</span>
|
|
1114
|
+
<DiffChanges changes={[...(diffs() ?? [])]} />
|
|
1115
|
+
<Show when={failed()}>
|
|
1116
|
+
<span
|
|
1117
|
+
data-slot="session-turn-diffs-error"
|
|
1118
|
+
class="min-w-0 truncate text-13-regular leading-text-compact text-v2-text-text-faint"
|
|
1119
|
+
>
|
|
1120
|
+
{i18n.t("ui.sessionTurn.diffs.failed")}
|
|
1121
|
+
</span>
|
|
1122
|
+
</Show>
|
|
1123
|
+
<Show when={failed() || overflow()}>
|
|
1124
|
+
<div class="ms-auto flex shrink-0 items-center gap-3">
|
|
1125
|
+
<Show when={failed()}>
|
|
1126
|
+
<button
|
|
1127
|
+
type="button"
|
|
1128
|
+
data-slot="session-turn-diffs-retry"
|
|
1129
|
+
class="text-14-regular text-v2-text-text-accent"
|
|
1130
|
+
onClick={() => data.turnDiff?.load(turn())}
|
|
1131
|
+
>
|
|
1132
|
+
{i18n.t("ui.sessionTurn.diffs.retry")}
|
|
1133
|
+
</button>
|
|
1134
|
+
</Show>
|
|
1135
|
+
<Show when={overflow()}>
|
|
1136
|
+
<button
|
|
1137
|
+
type="button"
|
|
1138
|
+
class="text-14-regular text-v2-text-text-accent"
|
|
1139
|
+
onClick={() => input.disclosure.set(showAllKey(), !showAll())}
|
|
1140
|
+
>
|
|
1141
|
+
{showAll() ? i18n.t("ui.sessionTurn.diffs.showLess") : i18n.t("ui.sessionTurn.diffs.showAll")}
|
|
1142
|
+
</button>
|
|
1143
|
+
</Show>
|
|
1144
|
+
</div>
|
|
1145
|
+
</Show>
|
|
1146
|
+
</div>
|
|
1147
|
+
<Dynamic
|
|
1148
|
+
component={render}
|
|
1149
|
+
tool="patch"
|
|
1150
|
+
input={{}}
|
|
1151
|
+
metadata={{ files: limit(diffs() ?? []) }}
|
|
1152
|
+
pendingFiles={diffs() ? undefined : limit(props.row.files)}
|
|
1153
|
+
status="completed"
|
|
1154
|
+
fileOpen={(path: string) => input.disclosure.value(fileKey(path))}
|
|
1155
|
+
onFileOpenChange={(path: string, open: boolean) => input.disclosure.set(fileKey(path), open)}
|
|
1156
|
+
deferContent
|
|
1157
|
+
virtualizeDiff={false}
|
|
1158
|
+
onContentRendered={props.onSizeChange}
|
|
1159
|
+
/>
|
|
1160
|
+
</div>
|
|
1161
|
+
</Show>
|
|
1162
|
+
)
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
// A run's messages sit as close as the iOS app's (4 px); the gap springs as a message joins or leaves.
|
|
1166
|
+
function TurnGap(props: { messageID: string }) {
|
|
1167
|
+
let element: HTMLDivElement | undefined
|
|
1168
|
+
const joined = run(props.messageID)
|
|
1169
|
+
springStyle(
|
|
1170
|
+
() => element,
|
|
1171
|
+
() => ({ height: joined()?.above ? 4 : 16 }),
|
|
1172
|
+
(el, value) => {
|
|
1173
|
+
el.style.height = `${value.height}px`
|
|
1174
|
+
},
|
|
1175
|
+
// Closing up as a message joins is instant; the joining message grows in instead.
|
|
1176
|
+
{ ...userRunSpring, snap: () => !!joined()?.above && runSnaps() },
|
|
1177
|
+
)
|
|
1178
|
+
|
|
1179
|
+
return (
|
|
1180
|
+
<div
|
|
1181
|
+
ref={element}
|
|
1182
|
+
data-timeline-row="TurnGap"
|
|
1183
|
+
aria-hidden="true"
|
|
1184
|
+
style={{ height: untrack(joined)?.above ? "4px" : "16px" }}
|
|
1185
|
+
/>
|
|
1186
|
+
)
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
const render = (row: Accessor<TimelineRow.TimelineRow>, onSizeChange?: () => void) => {
|
|
1190
|
+
if (Predicate.isTagged(row(), "TurnGap")) return <TurnGap messageID={row().userMessageID} />
|
|
1191
|
+
|
|
1192
|
+
// The host owns live status and renders this slot itself.
|
|
1193
|
+
if (Predicate.isTagged(row(), "Activity")) return null
|
|
1194
|
+
|
|
1195
|
+
if (Predicate.isTagged(row(), "UserMessage")) {
|
|
1196
|
+
const current = () => {
|
|
1197
|
+
const value = row()
|
|
1198
|
+
|
|
1199
|
+
if (!Predicate.isTagged(value, "UserMessage")) throw new Error("Expected a user-message timeline row")
|
|
1200
|
+
|
|
1201
|
+
return value
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
const message = createMemo(() => {
|
|
1205
|
+
const value = input.projection.messageByID().get(current().userMessageID)
|
|
1206
|
+
|
|
1207
|
+
return value?.type === "user" ? value : undefined
|
|
1208
|
+
})
|
|
1209
|
+
|
|
1210
|
+
const context = createMemo(() => input.projection.userContextByID().get(current().userMessageID))
|
|
1211
|
+
const joined = run(current().userMessageID)
|
|
1212
|
+
const grow = arriving(current().userMessageID)
|
|
1213
|
+
|
|
1214
|
+
return (
|
|
1215
|
+
<Frame row={current()} grow={grow}>
|
|
1216
|
+
<Show when={message()}>
|
|
1217
|
+
{(message) => {
|
|
1218
|
+
const presentation = () => input.presentation(message())
|
|
1219
|
+
|
|
1220
|
+
return (
|
|
1221
|
+
<div
|
|
1222
|
+
data-slot="session-turn-message-container"
|
|
1223
|
+
class={`w-full ${padding()}`}
|
|
1224
|
+
{...hoverZone(message().id)}
|
|
1225
|
+
>
|
|
1226
|
+
<div data-slot="session-turn-message-content" aria-live="off">
|
|
1227
|
+
<SessionUserMessage
|
|
1228
|
+
sessionID={input.sessionID()}
|
|
1229
|
+
message={message()}
|
|
1230
|
+
displayText={presentation()?.displayText}
|
|
1231
|
+
comments={presentation()?.comments}
|
|
1232
|
+
references={presentation()?.references}
|
|
1233
|
+
voice={presentation()?.voice}
|
|
1234
|
+
historicalAgent={context()?.agent ?? ""}
|
|
1235
|
+
historicalModel={context()?.model ?? { id: "", providerID: "" }}
|
|
1236
|
+
actions={input.actions}
|
|
1237
|
+
run={joined()}
|
|
1238
|
+
latest={latestSent() === message().id}
|
|
1239
|
+
runSnaps={runSnaps}
|
|
1240
|
+
runHovered={runHovered(message().id)}
|
|
1241
|
+
onMenuOpenChange={(open) =>
|
|
1242
|
+
setMenuMessage((current) =>
|
|
1243
|
+
open ? message().id : current === message().id ? undefined : current,
|
|
1244
|
+
)
|
|
1245
|
+
}
|
|
1246
|
+
fold={input.foldUserMessages?.()}
|
|
1247
|
+
inlineQuotes={input.inlineQuotes?.()}
|
|
1248
|
+
expanded={input.disclosure.value(`user-expanded:${message().id}`)}
|
|
1249
|
+
onExpandedChange={(open) => input.disclosure.set(`user-expanded:${message().id}`, open)}
|
|
1250
|
+
/>
|
|
1251
|
+
</div>
|
|
1252
|
+
</div>
|
|
1253
|
+
)
|
|
1254
|
+
}}
|
|
1255
|
+
</Show>
|
|
1256
|
+
</Frame>
|
|
1257
|
+
)
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
if (Predicate.isTagged(row(), "Shell")) {
|
|
1261
|
+
const current = () => {
|
|
1262
|
+
const value = row()
|
|
1263
|
+
|
|
1264
|
+
if (!Predicate.isTagged(value, "Shell")) throw new Error("Expected a shell timeline row")
|
|
1265
|
+
|
|
1266
|
+
return value
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
return (
|
|
1270
|
+
<Frame row={current()}>
|
|
1271
|
+
<Shell messageID={current().messageID} />
|
|
1272
|
+
</Frame>
|
|
1273
|
+
)
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
if (Predicate.isTagged(row(), "Notice")) {
|
|
1277
|
+
const current = () => {
|
|
1278
|
+
const value = row()
|
|
1279
|
+
|
|
1280
|
+
if (!Predicate.isTagged(value, "Notice")) throw new Error("Expected a notice timeline row")
|
|
1281
|
+
|
|
1282
|
+
return value
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
return (
|
|
1286
|
+
<Frame row={current()}>
|
|
1287
|
+
<Notice messageID={current().messageID} />
|
|
1288
|
+
</Frame>
|
|
1289
|
+
)
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
if (Predicate.isTagged(row(), "TurnDivider")) {
|
|
1293
|
+
const current = () => {
|
|
1294
|
+
const value = row()
|
|
1295
|
+
|
|
1296
|
+
if (!Predicate.isTagged(value, "TurnDivider")) throw new Error("Expected a turn-divider timeline row")
|
|
1297
|
+
|
|
1298
|
+
return value
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
return (
|
|
1302
|
+
<Frame row={current()}>
|
|
1303
|
+
<div data-slot="session-turn-message-container" class={`w-full ${padding()}`}>
|
|
1304
|
+
<div data-slot="session-turn-compaction">
|
|
1305
|
+
<div class="py-2">
|
|
1306
|
+
<TimelineSeparator label={i18n.t("ui.message.interrupted")} />
|
|
1307
|
+
</div>
|
|
1308
|
+
</div>
|
|
1309
|
+
</div>
|
|
1310
|
+
</Frame>
|
|
1311
|
+
)
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
if (Predicate.isTagged(row(), "CompactionQueued")) {
|
|
1315
|
+
const current = () => {
|
|
1316
|
+
const value = row()
|
|
1317
|
+
|
|
1318
|
+
if (!Predicate.isTagged(value, "CompactionQueued")) throw new Error("Expected a queued-compaction timeline row")
|
|
1319
|
+
|
|
1320
|
+
return value
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
return (
|
|
1324
|
+
<Frame row={current()}>
|
|
1325
|
+
<div data-slot="session-turn-message-container" class={`w-full ${padding()}`}>
|
|
1326
|
+
<div data-slot="session-turn-compaction">
|
|
1327
|
+
<SessionCompactionQueued />
|
|
1328
|
+
</div>
|
|
1329
|
+
</div>
|
|
1330
|
+
</Frame>
|
|
1331
|
+
)
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
if (Predicate.isTagged(row(), "AssistantPart")) {
|
|
1335
|
+
const current = () => {
|
|
1336
|
+
const value = row()
|
|
1337
|
+
|
|
1338
|
+
if (!Predicate.isTagged(value, "AssistantPart")) throw new Error("Expected an assistant-part timeline row")
|
|
1339
|
+
|
|
1340
|
+
return value
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
// Construct once per row key, not inside JSX that reruns when group refs change.
|
|
1344
|
+
const content = renderAssistant(current, onSizeChange)
|
|
1345
|
+
|
|
1346
|
+
return (
|
|
1347
|
+
<Frame row={current()}>
|
|
1348
|
+
<div data-slot="session-turn-message-container" class={`w-full ${padding()}`}>
|
|
1349
|
+
<div data-slot="session-turn-assistant-content">{content}</div>
|
|
1350
|
+
</div>
|
|
1351
|
+
</Frame>
|
|
1352
|
+
)
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
if (Predicate.isTagged(row(), "Thinking")) {
|
|
1356
|
+
const current = () => {
|
|
1357
|
+
const value = row()
|
|
1358
|
+
|
|
1359
|
+
if (!Predicate.isTagged(value, "Thinking")) throw new Error("Expected a thinking timeline row")
|
|
1360
|
+
|
|
1361
|
+
return value
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
const content = createMemo(() => {
|
|
1365
|
+
const ref = current().ref
|
|
1366
|
+
const content = Timeline.resolveContent(input.projection.messageByID().get(ref.messageID), ref.partID)
|
|
1367
|
+
|
|
1368
|
+
return content?.type === "reasoning" ? content : undefined
|
|
1369
|
+
})
|
|
1370
|
+
|
|
1371
|
+
return (
|
|
1372
|
+
<Frame row={current()}>
|
|
1373
|
+
<div data-slot="session-turn-message-container" class={`w-full ${padding()}`}>
|
|
1374
|
+
<div data-slot="session-turn-thinking-row">
|
|
1375
|
+
<Show when={content()}>
|
|
1376
|
+
{(content) => (
|
|
1377
|
+
<AssistantReasoningContent
|
|
1378
|
+
id={current().ref.partID}
|
|
1379
|
+
content={content()}
|
|
1380
|
+
streaming
|
|
1381
|
+
defaultOpen={
|
|
1382
|
+
input.timelineDetail
|
|
1383
|
+
? input.timelineDetail().thinking.details === "expanded"
|
|
1384
|
+
: input.reasoningMode() === "full"
|
|
1385
|
+
}
|
|
1386
|
+
open={
|
|
1387
|
+
input.disclosure.value(current().ref.partID) ??
|
|
1388
|
+
(input.timelineDetail ? input.timelineDetail().thinking.details === "expanded" : undefined)
|
|
1389
|
+
}
|
|
1390
|
+
onOpenChange={(open) => input.disclosure.set(current().ref.partID, open)}
|
|
1391
|
+
onContentRendered={onSizeChange}
|
|
1392
|
+
/>
|
|
1393
|
+
)}
|
|
1394
|
+
</Show>
|
|
1395
|
+
</div>
|
|
1396
|
+
</div>
|
|
1397
|
+
</Frame>
|
|
1398
|
+
)
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
if (Predicate.isTagged(row(), "TurnDiff")) {
|
|
1402
|
+
const current = () => {
|
|
1403
|
+
const value = row()
|
|
1404
|
+
|
|
1405
|
+
if (!Predicate.isTagged(value, "TurnDiff")) throw new Error("Expected a turn-diff timeline row")
|
|
1406
|
+
|
|
1407
|
+
return value
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
return (
|
|
1411
|
+
<Frame row={current()}>
|
|
1412
|
+
<div data-slot="session-turn-message-container" class={`w-full ${padding()}`}>
|
|
1413
|
+
<TurnDiff row={current()} onSizeChange={onSizeChange} />
|
|
1414
|
+
</div>
|
|
1415
|
+
</Frame>
|
|
1416
|
+
)
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
if (Predicate.isTagged(row(), "Retry")) {
|
|
1420
|
+
const current = () => {
|
|
1421
|
+
const value = row()
|
|
1422
|
+
|
|
1423
|
+
if (!Predicate.isTagged(value, "Retry")) throw new Error("Expected a retry timeline row")
|
|
1424
|
+
|
|
1425
|
+
return value
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
return (
|
|
1429
|
+
<Frame row={current()}>
|
|
1430
|
+
<div data-slot="session-turn-message-container" class={`w-full ${padding()}`}>
|
|
1431
|
+
<SessionRetry
|
|
1432
|
+
status={{ type: "retry", attempt: current().attempt, message: current().message, next: current().next }}
|
|
1433
|
+
show={input.projection.activeMessageID() === current().userMessageID}
|
|
1434
|
+
/>
|
|
1435
|
+
</div>
|
|
1436
|
+
</Frame>
|
|
1437
|
+
)
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1440
|
+
const current = () => {
|
|
1441
|
+
const value = row()
|
|
1442
|
+
|
|
1443
|
+
if (!Predicate.isTagged(value, "Error")) throw new Error("Expected an error timeline row")
|
|
1444
|
+
|
|
1445
|
+
return value
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
const usageLimit = createMemo(() => {
|
|
1449
|
+
const kind = current().kind
|
|
1450
|
+
|
|
1451
|
+
if (kind !== "free-limit" && kind !== "go-limit") return
|
|
1452
|
+
|
|
1453
|
+
const keys =
|
|
1454
|
+
kind === "go-limit"
|
|
1455
|
+
? ({ title: "ui.sessionTurn.goLimit.title", lineReset: "ui.sessionTurn.goLimit.lineReset" } as const)
|
|
1456
|
+
: ({ title: "ui.sessionTurn.freeLimit.title", lineReset: "ui.sessionTurn.freeLimit.lineReset" } as const)
|
|
1457
|
+
|
|
1458
|
+
const at = current().resetAt
|
|
1459
|
+
|
|
1460
|
+
if (at === undefined || !Number.isFinite(at) || Number.isNaN(new Date(at).getTime())) return i18n.t(keys.title)
|
|
1461
|
+
|
|
1462
|
+
const now = Date.now()
|
|
1463
|
+
const sameDay = new Date(at).toDateString() === new Date(now).toDateString() && at - now < 86_400_000
|
|
1464
|
+
|
|
1465
|
+
const time = new Intl.DateTimeFormat(
|
|
1466
|
+
i18n.locale(),
|
|
1467
|
+
sameDay ? { timeStyle: "short" } : { dateStyle: "medium", timeStyle: "short" },
|
|
1468
|
+
).format(at)
|
|
1469
|
+
|
|
1470
|
+
return i18n.t(keys.lineReset, { time })
|
|
1471
|
+
})
|
|
1472
|
+
|
|
1473
|
+
// A budget pauses paid models, or only the ones it covers, until it resets at the start of a month.
|
|
1474
|
+
const budgetLimit = createMemo(() => {
|
|
1475
|
+
const kind = current().kind
|
|
1476
|
+
|
|
1477
|
+
if (kind !== "budget-limit" && kind !== "model-budget-limit") return
|
|
1478
|
+
const at = current().resetAt
|
|
1479
|
+
|
|
1480
|
+
const time =
|
|
1481
|
+
at === undefined
|
|
1482
|
+
? undefined
|
|
1483
|
+
: new Intl.DateTimeFormat(i18n.locale(), {
|
|
1484
|
+
month: "short",
|
|
1485
|
+
day: "numeric",
|
|
1486
|
+
hour: "numeric",
|
|
1487
|
+
minute: "2-digit",
|
|
1488
|
+
timeZoneName: "shortOffset",
|
|
1489
|
+
}).format(at)
|
|
1490
|
+
|
|
1491
|
+
if (kind === "budget-limit")
|
|
1492
|
+
return {
|
|
1493
|
+
text: time
|
|
1494
|
+
? i18n.t("ui.sessionTurn.budgetLimit.all", { time })
|
|
1495
|
+
: i18n.t("ui.sessionTurn.budgetLimit.allUntilReset"),
|
|
1496
|
+
action: i18n.t("ui.sessionTurn.budgetLimit.useFreeModel"),
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
return {
|
|
1500
|
+
text: time
|
|
1501
|
+
? i18n.t("ui.sessionTurn.budgetLimit.models", { time })
|
|
1502
|
+
: i18n.t("ui.sessionTurn.budgetLimit.modelsUntilReset"),
|
|
1503
|
+
action: i18n.t("ui.sessionTurn.budgetLimit.switchModel"),
|
|
1504
|
+
}
|
|
1505
|
+
})
|
|
1506
|
+
|
|
1507
|
+
return (
|
|
1508
|
+
<Frame row={current()}>
|
|
1509
|
+
<div data-slot="session-turn-message-container" class={`w-full ${padding()}`}>
|
|
1510
|
+
<Switch fallback={<SessionError message={current().text} />}>
|
|
1511
|
+
<Match when={budgetLimit()}>
|
|
1512
|
+
{(notice) => (
|
|
1513
|
+
<div
|
|
1514
|
+
role="status"
|
|
1515
|
+
class="text-[13px] font-[440] leading-text-compact tracking-[-0.04px] text-v2-text-text-muted"
|
|
1516
|
+
>
|
|
1517
|
+
{notice().text}
|
|
1518
|
+
<Show when={input.actions?.chooseModel}>
|
|
1519
|
+
{(choose) => (
|
|
1520
|
+
<>
|
|
1521
|
+
<span aria-hidden="true">{" · "}</span>
|
|
1522
|
+
<button
|
|
1523
|
+
type="button"
|
|
1524
|
+
class="font-[530] text-v2-text-text-base hover:underline focus-visible:underline focus-visible:outline-none"
|
|
1525
|
+
onClick={() => choose()()}
|
|
1526
|
+
>
|
|
1527
|
+
{notice().action}
|
|
1528
|
+
</button>
|
|
1529
|
+
</>
|
|
1530
|
+
)}
|
|
1531
|
+
</Show>
|
|
1532
|
+
</div>
|
|
1533
|
+
)}
|
|
1534
|
+
</Match>
|
|
1535
|
+
<Match when={usageLimit()}>
|
|
1536
|
+
{(text) => (
|
|
1537
|
+
<div
|
|
1538
|
+
role="status"
|
|
1539
|
+
class="text-[13px] font-[440] leading-text-compact tracking-[-0.04px] text-v2-text-text-muted"
|
|
1540
|
+
>
|
|
1541
|
+
{text()}
|
|
1542
|
+
</div>
|
|
1543
|
+
)}
|
|
1544
|
+
</Match>
|
|
1545
|
+
</Switch>
|
|
1546
|
+
</div>
|
|
1547
|
+
</Frame>
|
|
1548
|
+
)
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
function Row(props: { row: Accessor<TimelineRow.TimelineRow>; onSizeChange?: () => void }) {
|
|
1552
|
+
return (
|
|
1553
|
+
<Show when={TimelineRow.key(props.row())} keyed>
|
|
1554
|
+
{(_key) => render(props.row, props.onSizeChange)}
|
|
1555
|
+
</Show>
|
|
1556
|
+
)
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1559
|
+
return { Row }
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
function capitalizeAgent(agent: string) {
|
|
1563
|
+
return agent.slice(0, 1).toUpperCase() + agent.slice(1)
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
function outcomeNoticeIcon(outcome: Outcome) {
|
|
1567
|
+
if (outcome === "error") return "warning"
|
|
1568
|
+
|
|
1569
|
+
if (outcome === "cancelled") return "circle-ban-sign"
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
function outcomeNoticeColor(outcome: Outcome | undefined) {
|
|
1573
|
+
if (!outcome) return ""
|
|
1574
|
+
|
|
1575
|
+
if (outcome === "error") return "text-v2-state-fg-danger"
|
|
1576
|
+
|
|
1577
|
+
if (outcome === "cancelled")
|
|
1578
|
+
return "text-[var(--v2-yellow-900)] [[data-color-scheme=dark]_&]:text-v2-state-fg-warning"
|
|
1579
|
+
|
|
1580
|
+
return "text-v2-text-text-code-accent"
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
function outcomeNoticeKey(state: string | undefined) {
|
|
1584
|
+
if (state === "error") return "ui.sessionTimeline.notice.failed"
|
|
1585
|
+
|
|
1586
|
+
if (state === "cancelled") return "ui.sessionTimeline.notice.cancelled"
|
|
1587
|
+
|
|
1588
|
+
return "ui.sessionTimeline.notice.finished"
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
/**
|
|
1592
|
+
* Grows a row from nothing to its natural height while its bubble fades in; rows below follow its edge. A pending
|
|
1593
|
+
* steer's meta line stays in view: a steer that starts a pending run shows its line once the row has settled, and one
|
|
1594
|
+
* that joins a pending run carries the run's line down along the growing edge while the bubble fades into the space.
|
|
1595
|
+
*/
|
|
1596
|
+
function growIn(el: HTMLElement, onDone: () => void) {
|
|
1597
|
+
if (prefersReducedMotion()) return onDone()
|
|
1598
|
+
const height = Spring.fromDuration(0, { duration: 0.2, bounce: 0 })
|
|
1599
|
+
const opacity = Spring.fromDuration(0, { duration: 0.3, bounce: 0 }).set(1)
|
|
1600
|
+
const content = el.firstElementChild instanceof HTMLElement ? el.firstElementChild : undefined
|
|
1601
|
+
// The row's children mount after its ref runs, so the whole row starts hidden and hands its fade to the bubble on the
|
|
1602
|
+
// first frame.
|
|
1603
|
+
let faded = content ? [content] : []
|
|
1604
|
+
let meta: HTMLElement | undefined
|
|
1605
|
+
let carried = false
|
|
1606
|
+
let natural = 0
|
|
1607
|
+
let line = 0
|
|
1608
|
+
el.style.height = "0px"
|
|
1609
|
+
el.toggleAttribute("data-timeline-grow", true)
|
|
1610
|
+
faded.forEach((element) => (element.style.opacity = "0"))
|
|
1611
|
+
|
|
1612
|
+
const remove = frameLoop.addMeasured(
|
|
1613
|
+
() => {
|
|
1614
|
+
if (content && !meta) {
|
|
1615
|
+
meta = content.querySelector<HTMLElement>('[data-slot="user-message-copy-wrapper"]') ?? undefined
|
|
1616
|
+
|
|
1617
|
+
const bubbles = [
|
|
1618
|
+
...content.querySelectorAll<HTMLElement>(
|
|
1619
|
+
'[data-slot="user-message-attachments"], [data-slot="user-message-body"]',
|
|
1620
|
+
),
|
|
1621
|
+
]
|
|
1622
|
+
|
|
1623
|
+
if (meta && bubbles.length > 0) {
|
|
1624
|
+
carried = !!content.querySelector('[data-component="user-message"][data-pending][data-run-above]')
|
|
1625
|
+
|
|
1626
|
+
if (!carried) meta.style.visibility = "hidden"
|
|
1627
|
+
content.style.opacity = ""
|
|
1628
|
+
faded = bubbles
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
natural = content ? content.offsetHeight : 0
|
|
1633
|
+
line = meta ? meta.offsetHeight + parseFloat(getComputedStyle(meta).marginTop) : 0
|
|
1634
|
+
},
|
|
1635
|
+
(dt) => {
|
|
1636
|
+
if (!el.isConnected) return true
|
|
1637
|
+
|
|
1638
|
+
height.set(natural)
|
|
1639
|
+
const value = height.step(dt)
|
|
1640
|
+
const progress = natural > 0 ? value / natural : 1
|
|
1641
|
+
const shown = Math.min(1, Math.max(0, opacity.step(dt)))
|
|
1642
|
+
|
|
1643
|
+
// A carried line passes over the bubble's place, so the bubble shows only as the line clears it.
|
|
1644
|
+
faded.forEach((element) => (element.style.opacity = `${carried ? shown * progress : shown}`))
|
|
1645
|
+
|
|
1646
|
+
// The line starts exactly where the run's line just was, just above this row, and settles below the bubble.
|
|
1647
|
+
if (meta && carried) meta.style.transform = `translateY(${-(natural - line + 8) * (1 - progress)}px)`
|
|
1648
|
+
|
|
1649
|
+
if (!height.resting || !opacity.resting) {
|
|
1650
|
+
el.style.height = height.resting ? "" : `${value}px`
|
|
1651
|
+
|
|
1652
|
+
return true
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
el.style.height = ""
|
|
1656
|
+
faded.forEach((element) => (element.style.opacity = ""))
|
|
1657
|
+
|
|
1658
|
+
if (meta) {
|
|
1659
|
+
meta.style.visibility = ""
|
|
1660
|
+
meta.style.transform = ""
|
|
1661
|
+
}
|
|
1662
|
+
|
|
1663
|
+
el.toggleAttribute("data-timeline-grow", false)
|
|
1664
|
+
onDone()
|
|
1665
|
+
|
|
1666
|
+
return false
|
|
1667
|
+
},
|
|
1668
|
+
)
|
|
1669
|
+
|
|
1670
|
+
// A row that unmounts mid-grow, as the virtualizer recycles it, ends its grow too; a second report is a no-op.
|
|
1671
|
+
onCleanup(() => {
|
|
1672
|
+
remove()
|
|
1673
|
+
onDone()
|
|
1674
|
+
})
|
|
1675
|
+
}
|