@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,1391 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createEffect,
|
|
3
|
+
createMemo,
|
|
4
|
+
createSignal,
|
|
5
|
+
For,
|
|
6
|
+
Index,
|
|
7
|
+
Match,
|
|
8
|
+
on,
|
|
9
|
+
onCleanup,
|
|
10
|
+
onMount,
|
|
11
|
+
Show,
|
|
12
|
+
Switch,
|
|
13
|
+
untrack,
|
|
14
|
+
type ComponentProps,
|
|
15
|
+
type JSX,
|
|
16
|
+
} from "solid-js"
|
|
17
|
+
import { createStore } from "solid-js/store"
|
|
18
|
+
import { createMediaQuery } from "@solid-primitives/media"
|
|
19
|
+
import { useData } from "../context"
|
|
20
|
+
import { useDialog } from "@zyro-sec/ui/context/dialog"
|
|
21
|
+
import { useI18n } from "@zyro-sec/ui/context/i18n"
|
|
22
|
+
import { Markdown } from "../components/markdown"
|
|
23
|
+
import { linkSegments } from "../components/link-segments"
|
|
24
|
+
import { LinkedText } from "../components/linked-text"
|
|
25
|
+
import {
|
|
26
|
+
sessionReferenceClipboardText,
|
|
27
|
+
sessionReferenceText,
|
|
28
|
+
setupSessionLinks,
|
|
29
|
+
} from "../components/markdown-session-links"
|
|
30
|
+
import { useMarkdown } from "../context/markdown"
|
|
31
|
+
import { useSources } from "../context/sources"
|
|
32
|
+
import { SourcesChip } from "../sources/sources-chip"
|
|
33
|
+
import type { TurnSources } from "../sources/sources"
|
|
34
|
+
import { ImagePreview } from "@zyro-sec/ui/image-preview"
|
|
35
|
+
import { getFilename } from "@zyro-sec/util/path"
|
|
36
|
+
import { AttachmentCard } from "./attachment-card"
|
|
37
|
+
import { CommentCard, commentCardTarget, quoteTooltip } from "./comment-card"
|
|
38
|
+
import { UserMessageQuotes } from "./user-message-quotes"
|
|
39
|
+
import { TimelineSeparator } from "../components/timeline-separator"
|
|
40
|
+
import { Tooltip } from "@zyro-sec/ui/tooltip"
|
|
41
|
+
import { IconButton } from "@zyro-sec/ui/icon-button"
|
|
42
|
+
import { Menu } from "@zyro-sec/ui/menu"
|
|
43
|
+
import { Icon } from "@zyro-sec/ui/icon"
|
|
44
|
+
import { Button } from "@zyro-sec/ui/button"
|
|
45
|
+
import { TextReveal } from "@zyro-sec/ui/text-reveal"
|
|
46
|
+
import { TextShimmer } from "@zyro-sec/ui/text-shimmer"
|
|
47
|
+
import { BasicTool } from "../components/basic-tool"
|
|
48
|
+
import { createDisclosure } from "../components/disclosure"
|
|
49
|
+
import { reasoningHeading } from "../timeline/projection"
|
|
50
|
+
import { Card } from "@zyro-sec/ui/card"
|
|
51
|
+
import { springStyle } from "@zyro-sec/ui/motion/solid"
|
|
52
|
+
import { userRunSpring, type UserRun } from "../timeline/user-runs"
|
|
53
|
+
import type {
|
|
54
|
+
PromptAgentAttachment,
|
|
55
|
+
PromptAttachment,
|
|
56
|
+
SessionMessageAssistant,
|
|
57
|
+
SessionMessageAssistantReasoning,
|
|
58
|
+
SessionMessageCompaction,
|
|
59
|
+
SessionMessageUser,
|
|
60
|
+
} from "@zyro-sec/client/promise"
|
|
61
|
+
import type { SessionUserActions, SessionUserAttachmentReference, SessionUserComment } from "../actions"
|
|
62
|
+
import { agentLabel } from "./agent-label"
|
|
63
|
+
import { isInterruptedError } from "../timeline/turn-phase-machine"
|
|
64
|
+
import { attached, typeLabel } from "../components/message-file"
|
|
65
|
+
import {
|
|
66
|
+
DISPOSED_ATTACHMENT_MEDIA_EVENT,
|
|
67
|
+
INITIAL_ATTACHMENT_MEDIA_STATE,
|
|
68
|
+
resolveAttachmentMediaTarget,
|
|
69
|
+
transitionAttachmentMedia,
|
|
70
|
+
viewAttachmentMedia,
|
|
71
|
+
type AttachmentMediaEvent,
|
|
72
|
+
} from "./attachment-media-machine"
|
|
73
|
+
import {
|
|
74
|
+
createCompactionEntranceState,
|
|
75
|
+
DISPOSED_COMPACTION_ENTRANCE_EVENT,
|
|
76
|
+
GRACE_ELAPSED_EVENT,
|
|
77
|
+
selectCompactionEnter,
|
|
78
|
+
transitionCompactionEntrance,
|
|
79
|
+
type CompactionEntranceEffect,
|
|
80
|
+
type CompactionEntranceEvent,
|
|
81
|
+
} from "./compaction-entrance-machine"
|
|
82
|
+
import {
|
|
83
|
+
createMessageActionState,
|
|
84
|
+
transitionMessageAction,
|
|
85
|
+
viewMessageActions,
|
|
86
|
+
type MessageAction,
|
|
87
|
+
type MessageActionCapabilities,
|
|
88
|
+
type MessageActionEvent,
|
|
89
|
+
} from "./action-machine"
|
|
90
|
+
import {
|
|
91
|
+
createPacedTextState,
|
|
92
|
+
DISPOSED_PACED_TEXT_EVENT,
|
|
93
|
+
TEXT_RENDER_PACE_MS,
|
|
94
|
+
transitionPacedText,
|
|
95
|
+
type PacedTextEvent,
|
|
96
|
+
} from "./paced-text-machine"
|
|
97
|
+
import { createCopyFeedback, writeClipboard } from "../components/copy"
|
|
98
|
+
|
|
99
|
+
type MetaItem = { label: string; variant?: boolean }
|
|
100
|
+
|
|
101
|
+
// The variant follows the model name without a separator, so the model leads.
|
|
102
|
+
function modelItems(data: ReturnType<typeof useData>, model: SessionMessageAssistant["model"]): MetaItem[] {
|
|
103
|
+
const name = data.store.provider?.all?.get(model.providerID)?.models?.[model.id]?.name ?? model.id
|
|
104
|
+
|
|
105
|
+
// A prompt held for its Location's catalog names no model yet.
|
|
106
|
+
if (!name) return []
|
|
107
|
+
|
|
108
|
+
if (!model.variant || model.variant === "default") return [{ label: name }]
|
|
109
|
+
|
|
110
|
+
return [{ label: name }, { label: model.variant[0]?.toUpperCase() + model.variant.slice(1), variant: true }]
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function MetaItems(props: { items: MetaItem[]; slot: "user-message" | "text-part" }) {
|
|
114
|
+
return (
|
|
115
|
+
<For each={props.items}>
|
|
116
|
+
{(item, index) => (
|
|
117
|
+
<>
|
|
118
|
+
<Show when={index() > 0 && !item.variant}>
|
|
119
|
+
<span data-slot={`${props.slot}-meta-separator`} aria-hidden="true">
|
|
120
|
+
{"\u00B7"}
|
|
121
|
+
</span>
|
|
122
|
+
</Show>
|
|
123
|
+
<span
|
|
124
|
+
data-slot={`${props.slot}-meta-item`}
|
|
125
|
+
data-variant={item.variant ? "" : undefined}
|
|
126
|
+
dir={props.slot === "text-part" ? "auto" : undefined}
|
|
127
|
+
>
|
|
128
|
+
{item.label}
|
|
129
|
+
</span>
|
|
130
|
+
</>
|
|
131
|
+
)}
|
|
132
|
+
</For>
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function MessageActionButton(
|
|
137
|
+
props: Pick<ComponentProps<"button">, "disabled" | "onMouseDown" | "onClick" | "aria-label"> & {
|
|
138
|
+
copied: boolean
|
|
139
|
+
label: JSX.Element
|
|
140
|
+
size?: "small" | "normal"
|
|
141
|
+
},
|
|
142
|
+
) {
|
|
143
|
+
return (
|
|
144
|
+
<Tooltip appearance="compact" value={props.label} placement="top" gutter={4} forceOpen={props.copied || undefined}>
|
|
145
|
+
<IconButton
|
|
146
|
+
icon={<Icon name={props.copied ? "check" : "copy"} />}
|
|
147
|
+
size={props.size ?? "normal"}
|
|
148
|
+
variant="ghost-muted"
|
|
149
|
+
disabled={props.disabled}
|
|
150
|
+
onMouseDown={props.onMouseDown}
|
|
151
|
+
onClick={props.onClick}
|
|
152
|
+
aria-label={props["aria-label"]}
|
|
153
|
+
/>
|
|
154
|
+
</Tooltip>
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function UserMessageTransition(props: { active: boolean; children: JSX.Element }) {
|
|
159
|
+
return (
|
|
160
|
+
<span
|
|
161
|
+
data-slot="user-message-transition"
|
|
162
|
+
data-active={props.active}
|
|
163
|
+
inert={!props.active}
|
|
164
|
+
aria-hidden={!props.active}
|
|
165
|
+
>
|
|
166
|
+
<span data-slot="user-message-transition-inner">{props.children}</span>
|
|
167
|
+
</span>
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Token streaming dispatches here on every delta: the driver reuses one sync and one tick event, and the machine
|
|
172
|
+
// returns the same state when a delta changes nothing.
|
|
173
|
+
function createPacedValue(getValue: () => string, live?: () => boolean) {
|
|
174
|
+
let state = createPacedTextState(untrack(getValue))
|
|
175
|
+
const [value, setValue] = createSignal(untrack(getValue))
|
|
176
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
177
|
+
const syncEvent = { type: "sync" as const, text: "", live: false }
|
|
178
|
+
const tickEvent = { type: "tick" as const, attempt: 0 }
|
|
179
|
+
|
|
180
|
+
const tick = () => {
|
|
181
|
+
timer = undefined
|
|
182
|
+
dispatch(tickEvent)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const dispatch = (event: PacedTextEvent) => {
|
|
186
|
+
const previous = state
|
|
187
|
+
state = transitionPacedText(previous, event)
|
|
188
|
+
|
|
189
|
+
if (state === previous) return
|
|
190
|
+
|
|
191
|
+
if (state.status !== "pacing") {
|
|
192
|
+
clearTimeout(timer)
|
|
193
|
+
timer = undefined
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (state.status === "disposed" || previous.status === "disposed") return
|
|
197
|
+
|
|
198
|
+
if (state.shown !== previous.shown) setValue(state.shown)
|
|
199
|
+
|
|
200
|
+
if (state.status !== "pacing" || (previous.status === "pacing" && previous.attempt === state.attempt)) return
|
|
201
|
+
tickEvent.attempt = state.attempt
|
|
202
|
+
timer = setTimeout(tick, TEXT_RENDER_PACE_MS)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
createEffect(() => {
|
|
206
|
+
syncEvent.text = getValue()
|
|
207
|
+
syncEvent.live = live?.() ?? false
|
|
208
|
+
dispatch(syncEvent)
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
onCleanup(() => dispatch(DISPOSED_PACED_TEXT_EVENT))
|
|
212
|
+
|
|
213
|
+
return value
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export function PacedMarkdown(props: { text: string; cacheKey: string; streaming: boolean }) {
|
|
217
|
+
const value = createPacedValue(
|
|
218
|
+
() => props.text,
|
|
219
|
+
() => props.streaming,
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
return (
|
|
223
|
+
<Show when={value()}>
|
|
224
|
+
<Markdown text={value()} cacheKey={props.cacheKey} streaming={props.streaming} deferUntilReady />
|
|
225
|
+
</Show>
|
|
226
|
+
)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function UserMessageComments(props: { comments: SessionUserComment[]; bounded: boolean }) {
|
|
230
|
+
const i18n = useI18n()
|
|
231
|
+
const [state, setState] = createStore({ expanded: false })
|
|
232
|
+
const comments = createMemo(() => (props.bounded && !state.expanded ? props.comments.slice(0, 5) : props.comments))
|
|
233
|
+
|
|
234
|
+
return (
|
|
235
|
+
<div data-slot="user-message-comments" data-bounded={props.bounded ? "true" : undefined}>
|
|
236
|
+
<For each={comments()}>
|
|
237
|
+
{(comment) => (
|
|
238
|
+
<CommentCard
|
|
239
|
+
comment={comment.comment ?? ""}
|
|
240
|
+
target={commentCardTarget(comment)}
|
|
241
|
+
title={comment.type === "quote" ? quoteTooltip(comment) : comment.comment || undefined}
|
|
242
|
+
tooltip
|
|
243
|
+
wide
|
|
244
|
+
/>
|
|
245
|
+
)}
|
|
246
|
+
</For>
|
|
247
|
+
<Show when={props.bounded && props.comments.length > 5 && !state.expanded}>
|
|
248
|
+
<Button size="small" variant="ghost-muted" onClick={() => setState("expanded", true)}>
|
|
249
|
+
{i18n.t("ui.common.showMore")}
|
|
250
|
+
</Button>
|
|
251
|
+
</Show>
|
|
252
|
+
</div>
|
|
253
|
+
)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export function CurrentUserMessageDisplay(props: {
|
|
257
|
+
sessionID: string
|
|
258
|
+
message: SessionMessageUser
|
|
259
|
+
text: string
|
|
260
|
+
agent: string
|
|
261
|
+
model: SessionMessageAssistant["model"]
|
|
262
|
+
actions?: SessionUserActions
|
|
263
|
+
comments?: SessionUserComment[]
|
|
264
|
+
references?: SessionUserAttachmentReference[]
|
|
265
|
+
voice?: boolean
|
|
266
|
+
run?: UserRun
|
|
267
|
+
/** The newest delivered prompt, whose revert undoes the last turn. */
|
|
268
|
+
latest?: boolean
|
|
269
|
+
/** Whether run changes snap now, while a message arrives, rather than spring. Omitted, folding always snaps. */
|
|
270
|
+
runSnaps?: () => boolean
|
|
271
|
+
/** The pointer is somewhere in this message's run, so its last bubble shows the run's meta line. */
|
|
272
|
+
runHovered?: boolean
|
|
273
|
+
/** An open menu keeps its run's meta line in view while the pointer is on the menu. */
|
|
274
|
+
onMenuOpenChange?: (open: boolean) => void
|
|
275
|
+
/** Folds a long message to its first lines with a Read more toggle. Omitted, the message always shows in full. */
|
|
276
|
+
fold?: boolean
|
|
277
|
+
/** Whether a folded message is open. The timeline owns it so it survives row recycling. */
|
|
278
|
+
expanded?: boolean
|
|
279
|
+
onExpandedChange?: (expanded: boolean) => void
|
|
280
|
+
/** Shows quotes and comments inside the bubble, after the text, instead of as cards. */
|
|
281
|
+
inlineQuotes?: boolean
|
|
282
|
+
}) {
|
|
283
|
+
const data = useData()
|
|
284
|
+
const dialog = useDialog()
|
|
285
|
+
const i18n = useI18n()
|
|
286
|
+
|
|
287
|
+
const fold = createDisclosure({
|
|
288
|
+
open: () => props.expanded,
|
|
289
|
+
onOpenChange: (expanded) => props.onExpandedChange?.(expanded),
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
const expanded = fold.open
|
|
293
|
+
const setExpanded = fold.setOpen
|
|
294
|
+
|
|
295
|
+
const status = createMemo(() => props.actions?.pending?.status(props.message.id))
|
|
296
|
+
// A prompt still `sending` has no server row yet, so nothing can move, delete, revert or fork it.
|
|
297
|
+
const sending = createMemo(() => status() === "sending")
|
|
298
|
+
const pending = createMemo(() => status() !== undefined && status() !== "queued" && !sending())
|
|
299
|
+
const waiting = createMemo(() => status() === "steering" || status() === "stranded" || sending())
|
|
300
|
+
// SAFETY: opted-in reads leave stored files as `media:` refs, a PromptAttachment variant the generated message type does not list.
|
|
301
|
+
const files = createMemo(() => (props.message.files ?? []) as PromptAttachment[])
|
|
302
|
+
const attachments = createMemo(() => files().filter(attached))
|
|
303
|
+
const references = createMemo(() => props.references ?? [])
|
|
304
|
+
const inlineFiles = createMemo(() => files().filter((file) => !!file.mention))
|
|
305
|
+
const agents = createMemo(() => props.message.agents ?? [])
|
|
306
|
+
const comments = createMemo(() => props.comments ?? [])
|
|
307
|
+
const inline = createMemo(() => !!props.inlineQuotes && comments().length > 0)
|
|
308
|
+
// Inline quotes give a message without text a bubble of its own.
|
|
309
|
+
const bubble = createMemo(() => !!props.text || inline())
|
|
310
|
+
const copyText = () => (props.voice ? props.text : props.message.text)
|
|
311
|
+
|
|
312
|
+
// Mobile shows the current agent and model in the composer and switch notices, so repeating them per message is noise.
|
|
313
|
+
const mobile = createMediaQuery("(max-width: 767px)")
|
|
314
|
+
|
|
315
|
+
const agentItems = createMemo<MetaItem[]>(() => {
|
|
316
|
+
const agent = agentLabel(props.agent, data.agents)
|
|
317
|
+
|
|
318
|
+
return agent ? [{ label: agent }] : []
|
|
319
|
+
})
|
|
320
|
+
|
|
321
|
+
// The menu names the day relatively: Today and Yesterday, then the date this year, then the date with its year.
|
|
322
|
+
// A plain function, not a memo, so each menu open compares against the current day.
|
|
323
|
+
const sent = () => {
|
|
324
|
+
const created = new Date(props.message.time.created)
|
|
325
|
+
const now = new Date()
|
|
326
|
+
const midnight = (date: Date) => new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime()
|
|
327
|
+
const days = Math.round((midnight(now) - midnight(created)) / 86_400_000)
|
|
328
|
+
const time = new Intl.DateTimeFormat(i18n.locale(), { timeStyle: "short" }).format(created)
|
|
329
|
+
|
|
330
|
+
if (days === 0 || days === 1) {
|
|
331
|
+
const day = new Intl.RelativeTimeFormat(i18n.locale(), { numeric: "auto" }).format(-days, "day")
|
|
332
|
+
|
|
333
|
+
return `${day[0]?.toLocaleUpperCase(i18n.locale())}${day.slice(1)}, ${time}`
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (created.getFullYear() === now.getFullYear())
|
|
337
|
+
return new Intl.DateTimeFormat(i18n.locale(), {
|
|
338
|
+
month: "short",
|
|
339
|
+
day: "numeric",
|
|
340
|
+
hour: "numeric",
|
|
341
|
+
minute: "2-digit",
|
|
342
|
+
}).format(created)
|
|
343
|
+
|
|
344
|
+
return new Intl.DateTimeFormat(i18n.locale(), { dateStyle: "medium", timeStyle: "short" }).format(created)
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// A waiting steer reads agent · model · Pending; mobile shows the agent and model in the composer instead.
|
|
348
|
+
const metaLabels = createMemo(() => (mobile() ? [] : [...agentItems(), ...modelItems(data, props.model)]))
|
|
349
|
+
|
|
350
|
+
// In a run, only the last message keeps the meta line; every bubble offers its actions from its own chevron.
|
|
351
|
+
// Bubble corners tighten where two bubbles meet, as in the iOS app's grouped corners.
|
|
352
|
+
const folded = createMemo(() => !!props.run?.below && bubble())
|
|
353
|
+
|
|
354
|
+
const meetsAbove = createMemo(
|
|
355
|
+
() => !!props.run?.above && bubble() && attachments().length === 0 && references().length === 0,
|
|
356
|
+
)
|
|
357
|
+
|
|
358
|
+
const runPose = () => ({
|
|
359
|
+
meta: folded() ? 0 : 1,
|
|
360
|
+
top: meetsAbove() ? 1 : 0,
|
|
361
|
+
bottom: folded() ? 1 : 0,
|
|
362
|
+
})
|
|
363
|
+
|
|
364
|
+
// The first paint is the resting pose; the spring's first write lands a frame later.
|
|
365
|
+
const restingPose = untrack(runPose)
|
|
366
|
+
|
|
367
|
+
let root: HTMLDivElement | undefined
|
|
368
|
+
springStyle(
|
|
369
|
+
() => root,
|
|
370
|
+
runPose,
|
|
371
|
+
(el, value) => {
|
|
372
|
+
el.style.setProperty("--user-run-meta", `${value.meta}`)
|
|
373
|
+
el.style.setProperty("--user-run-top", `${value.top}`)
|
|
374
|
+
el.style.setProperty("--user-run-bottom", `${value.bottom}`)
|
|
375
|
+
el.toggleAttribute("data-run-meta-hidden", value.meta === 0)
|
|
376
|
+
},
|
|
377
|
+
// Folding a meta line away is instant while the next message grows in to take its place; otherwise it springs in step
|
|
378
|
+
// with the line that replaces it.
|
|
379
|
+
{ ...userRunSpring, snap: () => folded() && (props.runSnaps?.() ?? true) },
|
|
380
|
+
)
|
|
381
|
+
|
|
382
|
+
// Delivery drops the Pending footer at once rather than fading it like the hover reveal.
|
|
383
|
+
createEffect(
|
|
384
|
+
on(
|
|
385
|
+
waiting,
|
|
386
|
+
(now, before) => {
|
|
387
|
+
if (now || !before || !root) return
|
|
388
|
+
const element = root
|
|
389
|
+
element.toggleAttribute("data-delivering", true)
|
|
390
|
+
requestAnimationFrame(() => element.toggleAttribute("data-delivering", false))
|
|
391
|
+
},
|
|
392
|
+
{ defer: true },
|
|
393
|
+
),
|
|
394
|
+
)
|
|
395
|
+
|
|
396
|
+
const [action, setAction] = createSignal(createMessageActionState())
|
|
397
|
+
|
|
398
|
+
const capabilities = createMemo<MessageActionCapabilities>(() => ({
|
|
399
|
+
pending: pending(),
|
|
400
|
+
canPending: !!props.actions?.pending,
|
|
401
|
+
canRevert: !!props.actions?.revert,
|
|
402
|
+
canFork: !!props.actions?.fork,
|
|
403
|
+
}))
|
|
404
|
+
|
|
405
|
+
const actionView = createMemo(() => viewMessageActions(action(), capabilities()))
|
|
406
|
+
|
|
407
|
+
const runAction = (kind: MessageAction) => {
|
|
408
|
+
const input = { sessionID: props.sessionID, messageID: props.message.id }
|
|
409
|
+
|
|
410
|
+
if (kind === "queue") return props.actions?.pending?.queue(input)
|
|
411
|
+
|
|
412
|
+
if (kind === "remove") return props.actions?.pending?.remove(input)
|
|
413
|
+
|
|
414
|
+
if (kind === "revert") return props.actions?.revert?.(input)
|
|
415
|
+
|
|
416
|
+
return props.actions?.fork?.(input)
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
const dispatch = (event: MessageActionEvent) => {
|
|
420
|
+
const next = transitionMessageAction(action(), event)
|
|
421
|
+
setAction(next.state)
|
|
422
|
+
next.effects.forEach((effect) => {
|
|
423
|
+
// The executor turns a synchronous throw into a rejection, so every outcome settles the attempt.
|
|
424
|
+
void new Promise<void>((resolve) => resolve(runAction(effect.action))).then(
|
|
425
|
+
() => dispatch({ type: "succeeded", attempt: effect.attempt }),
|
|
426
|
+
() => dispatch({ type: "failed", attempt: effect.attempt }),
|
|
427
|
+
)
|
|
428
|
+
})
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
const request = (kind: MessageAction) => dispatch({ type: "requested", action: kind, capabilities: capabilities() })
|
|
432
|
+
|
|
433
|
+
onCleanup(() => dispatch({ type: "disposed" }))
|
|
434
|
+
|
|
435
|
+
const renderMenu = () => (
|
|
436
|
+
<Show when={!sending()}>
|
|
437
|
+
<span data-slot="user-message-menu">
|
|
438
|
+
<Menu gutter={4} placement="top-end" onOpenChange={(open) => props.onMenuOpenChange?.(open)}>
|
|
439
|
+
{/* The chevron explains itself, so it carries only an accessible name, no tooltip. */}
|
|
440
|
+
<Menu.Trigger
|
|
441
|
+
as={IconButton}
|
|
442
|
+
icon={<Icon name="chevron-down" />}
|
|
443
|
+
size="small"
|
|
444
|
+
variant="ghost-muted"
|
|
445
|
+
onMouseDown={(event: MouseEvent) => event.preventDefault()}
|
|
446
|
+
onClick={(event: MouseEvent) => event.stopPropagation()}
|
|
447
|
+
aria-label={i18n.t("ui.message.moreActions")}
|
|
448
|
+
/>
|
|
449
|
+
<Menu.Portal>
|
|
450
|
+
<Menu.Content>
|
|
451
|
+
<Menu.Group>
|
|
452
|
+
<Menu.GroupLabel>
|
|
453
|
+
<Show when={!waiting()} fallback={i18n.t("ui.message.pending")}>
|
|
454
|
+
<time dateTime={new Date(props.message.time.created).toISOString()}>{sent()}</time>
|
|
455
|
+
</Show>
|
|
456
|
+
</Menu.GroupLabel>
|
|
457
|
+
</Menu.Group>
|
|
458
|
+
<Menu.Separator />
|
|
459
|
+
<Show when={pending() && props.actions?.pending}>
|
|
460
|
+
<Menu.Item disabled={actionView().disabled.queue} onSelect={() => request("queue")}>
|
|
461
|
+
<Icon name="bullet-list" />
|
|
462
|
+
{i18n.t("ui.message.moveToQueue")}
|
|
463
|
+
</Menu.Item>
|
|
464
|
+
</Show>
|
|
465
|
+
<Menu.Item disabled={!copyText()} onSelect={() => void writeClipboard(copyText())}>
|
|
466
|
+
<Icon name="copy" />
|
|
467
|
+
|
|
468
|
+
{i18n.t("ui.message.copyMessage")}
|
|
469
|
+
</Menu.Item>
|
|
470
|
+
{/* Like the iOS app, a Voice message also offers the full prompt the session received. */}
|
|
471
|
+
<Show when={props.voice}>
|
|
472
|
+
<Menu.Item onSelect={() => void writeClipboard(props.message.text)}>
|
|
473
|
+
<Icon name="copy" />
|
|
474
|
+
{i18n.t("ui.message.copyFullMessage")}
|
|
475
|
+
</Menu.Item>
|
|
476
|
+
</Show>
|
|
477
|
+
{/* A pending steer has no history to fork from yet. */}
|
|
478
|
+
<Show when={!pending()}>
|
|
479
|
+
<Menu.Item disabled={actionView().disabled.fork} onSelect={() => request("fork")}>
|
|
480
|
+
<Icon name="fork" />
|
|
481
|
+
{i18n.t("ui.message.forkMessage")}
|
|
482
|
+
</Menu.Item>
|
|
483
|
+
</Show>
|
|
484
|
+
{/* A pending steer is withdrawn rather than reverted; a sent message reverts only where the host allows it. */}
|
|
485
|
+
<Show
|
|
486
|
+
when={pending() && props.actions?.pending}
|
|
487
|
+
fallback={
|
|
488
|
+
<Show when={props.actions?.revert}>
|
|
489
|
+
<Menu.Separator />
|
|
490
|
+
<Menu.Item disabled={actionView().disabled.revert} onSelect={() => request("revert")}>
|
|
491
|
+
<Icon name="reset" />
|
|
492
|
+
{props.latest ? i18n.t("ui.message.undoMessage") : i18n.t("ui.message.revertMessage")}
|
|
493
|
+
</Menu.Item>
|
|
494
|
+
</Show>
|
|
495
|
+
}
|
|
496
|
+
>
|
|
497
|
+
<Menu.Separator />
|
|
498
|
+
<Menu.Item
|
|
499
|
+
data-variant="critical"
|
|
500
|
+
disabled={actionView().disabled.remove}
|
|
501
|
+
onSelect={() => request("remove")}
|
|
502
|
+
>
|
|
503
|
+
<Icon name="trash" />
|
|
504
|
+
{i18n.t("ui.message.deletePending")}
|
|
505
|
+
</Menu.Item>
|
|
506
|
+
</Show>
|
|
507
|
+
</Menu.Content>
|
|
508
|
+
</Menu.Portal>
|
|
509
|
+
</Menu>
|
|
510
|
+
</span>
|
|
511
|
+
</Show>
|
|
512
|
+
)
|
|
513
|
+
|
|
514
|
+
const renderAttachments = () => (
|
|
515
|
+
<Show when={attachments().length > 0 || references().length > 0}>
|
|
516
|
+
<div data-slot="user-message-attachments">
|
|
517
|
+
<For each={references()}>
|
|
518
|
+
{(file) => (
|
|
519
|
+
<AttachmentCard title={file.name} hover={file.path}>
|
|
520
|
+
{typeLabel(file.name, file.mime, i18n.t("ui.common.file"))}
|
|
521
|
+
</AttachmentCard>
|
|
522
|
+
)}
|
|
523
|
+
</For>
|
|
524
|
+
<Index each={attachments()}>
|
|
525
|
+
{(file) => {
|
|
526
|
+
const mediaTarget = createMemo(() =>
|
|
527
|
+
resolveAttachmentMediaTarget(file(), { peekMedia: data.peekMedia, hasReader: !!data.readMedia }),
|
|
528
|
+
)
|
|
529
|
+
|
|
530
|
+
const [mediaState, setMediaState] = createSignal(INITIAL_ATTACHMENT_MEDIA_STATE)
|
|
531
|
+
let mediaController: AbortController | undefined
|
|
532
|
+
let mediaTimer: ReturnType<typeof setTimeout> | undefined
|
|
533
|
+
|
|
534
|
+
const dispatchMedia = (event: AttachmentMediaEvent) => {
|
|
535
|
+
const step = transitionAttachmentMedia(untrack(mediaState), event)
|
|
536
|
+
setMediaState(step.state)
|
|
537
|
+
step.effects.forEach((effect) => {
|
|
538
|
+
if (effect.type === "cancel") {
|
|
539
|
+
clearTimeout(mediaTimer)
|
|
540
|
+
mediaTimer = undefined
|
|
541
|
+
mediaController?.abort()
|
|
542
|
+
mediaController = undefined
|
|
543
|
+
|
|
544
|
+
return
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
const controller = new AbortController()
|
|
548
|
+
const readMedia = data.readMedia
|
|
549
|
+
mediaController = controller
|
|
550
|
+
mediaTimer = setTimeout(
|
|
551
|
+
() => dispatchMedia({ type: "read.timed-out", attempt: effect.attempt }),
|
|
552
|
+
effect.timeoutMs,
|
|
553
|
+
)
|
|
554
|
+
// A read that resolves, rejects or throws settles its attempt.
|
|
555
|
+
void Promise.resolve()
|
|
556
|
+
.then(() => readMedia?.(effect.uri, effect.mime, controller.signal))
|
|
557
|
+
.then(
|
|
558
|
+
(loaded) =>
|
|
559
|
+
dispatchMedia(
|
|
560
|
+
loaded
|
|
561
|
+
? { type: "read.succeeded", attempt: effect.attempt, src: loaded }
|
|
562
|
+
: { type: "read.failed", attempt: effect.attempt },
|
|
563
|
+
),
|
|
564
|
+
() => dispatchMedia({ type: "read.failed", attempt: effect.attempt }),
|
|
565
|
+
)
|
|
566
|
+
})
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
createEffect(() => dispatchMedia({ type: "target.synced", target: mediaTarget() }))
|
|
570
|
+
onCleanup(() => dispatchMedia(DISPOSED_ATTACHMENT_MEDIA_EVENT))
|
|
571
|
+
|
|
572
|
+
const mediaView = createMemo(() => viewAttachmentMedia(mediaState(), mediaTarget()))
|
|
573
|
+
const name = () => file().name ?? i18n.t("ui.message.attachment.alt")
|
|
574
|
+
const image = () => file().mime.startsWith("image/")
|
|
575
|
+
|
|
576
|
+
const width = () => {
|
|
577
|
+
const current = file()
|
|
578
|
+
|
|
579
|
+
return "width" in current ? current.width : undefined
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
const height = () => {
|
|
583
|
+
const current = file()
|
|
584
|
+
|
|
585
|
+
return "height" in current ? current.height : undefined
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
return (
|
|
589
|
+
<Show
|
|
590
|
+
when={!image()}
|
|
591
|
+
fallback={
|
|
592
|
+
<div
|
|
593
|
+
data-slot="user-message-attachment"
|
|
594
|
+
data-type="image"
|
|
595
|
+
data-clickable={mediaView().clickable ? "true" : undefined}
|
|
596
|
+
data-placeholder={mediaView().placeholder ? "true" : undefined}
|
|
597
|
+
data-width={width()}
|
|
598
|
+
data-height={height()}
|
|
599
|
+
onClick={(event) => {
|
|
600
|
+
const src = mediaView().src
|
|
601
|
+
const origin = event.currentTarget
|
|
602
|
+
|
|
603
|
+
if (src) return dialog.show(() => <ImagePreview src={src} alt={name()} origin={origin} />)
|
|
604
|
+
|
|
605
|
+
if (mediaView().canRetry) dispatchMedia({ type: "retry.requested", target: mediaTarget() })
|
|
606
|
+
}}
|
|
607
|
+
>
|
|
608
|
+
<Switch>
|
|
609
|
+
<Match when={mediaView().src}>
|
|
610
|
+
{(src) => (
|
|
611
|
+
<img
|
|
612
|
+
data-slot="user-message-attachment-image"
|
|
613
|
+
src={src()}
|
|
614
|
+
width={width()}
|
|
615
|
+
height={height()}
|
|
616
|
+
alt={name()}
|
|
617
|
+
/>
|
|
618
|
+
)}
|
|
619
|
+
</Match>
|
|
620
|
+
<Match when={mediaView().status === "failed"}>
|
|
621
|
+
<div
|
|
622
|
+
data-slot="user-message-attachment-icon"
|
|
623
|
+
role="img"
|
|
624
|
+
aria-label={i18n.t("ui.fileMedia.state.error", {
|
|
625
|
+
kind: i18n.t("ui.fileMedia.kind.image"),
|
|
626
|
+
})}
|
|
627
|
+
>
|
|
628
|
+
<Icon name="outline-photo" size="small" />
|
|
629
|
+
</div>
|
|
630
|
+
</Match>
|
|
631
|
+
</Switch>
|
|
632
|
+
</div>
|
|
633
|
+
}
|
|
634
|
+
>
|
|
635
|
+
<AttachmentCard
|
|
636
|
+
title={getFilename(name())}
|
|
637
|
+
hover={name()}
|
|
638
|
+
clickable={!!props.actions?.openAttachment}
|
|
639
|
+
onClick={() => props.actions?.openAttachment?.(file())}
|
|
640
|
+
>
|
|
641
|
+
{typeLabel(name(), file().mime, i18n.t("ui.common.file"))}
|
|
642
|
+
</AttachmentCard>
|
|
643
|
+
</Show>
|
|
644
|
+
)
|
|
645
|
+
}}
|
|
646
|
+
</Index>
|
|
647
|
+
</div>
|
|
648
|
+
</Show>
|
|
649
|
+
)
|
|
650
|
+
|
|
651
|
+
// Inline quotes follow the text inside the fold, so Collapse long messages folds the whole bubble.
|
|
652
|
+
const renderBody = () => (
|
|
653
|
+
<>
|
|
654
|
+
<Show when={props.text}>
|
|
655
|
+
<CurrentHighlightedText text={props.text} files={inlineFiles()} agents={agents()} />
|
|
656
|
+
</Show>
|
|
657
|
+
<Show when={inline()}>
|
|
658
|
+
<UserMessageQuotes comments={comments()} />
|
|
659
|
+
</Show>
|
|
660
|
+
</>
|
|
661
|
+
)
|
|
662
|
+
|
|
663
|
+
return (
|
|
664
|
+
<div
|
|
665
|
+
ref={root}
|
|
666
|
+
data-component="user-message"
|
|
667
|
+
data-pending={waiting() ? "true" : undefined}
|
|
668
|
+
data-run-folded={folded() ? "" : undefined}
|
|
669
|
+
data-run-above={meetsAbove() ? "" : undefined}
|
|
670
|
+
data-run-hovered={props.runHovered ? "" : undefined}
|
|
671
|
+
data-run-meta-hidden={restingPose.meta === 0 ? "" : undefined}
|
|
672
|
+
style={{
|
|
673
|
+
"--user-run-meta": `${restingPose.meta}`,
|
|
674
|
+
"--user-run-top": `${restingPose.top}`,
|
|
675
|
+
"--user-run-bottom": `${restingPose.bottom}`,
|
|
676
|
+
}}
|
|
677
|
+
data-timeline-part-id={props.text ? `${props.message.id}:text:0` : undefined}
|
|
678
|
+
>
|
|
679
|
+
{renderAttachments()}
|
|
680
|
+
<Show
|
|
681
|
+
when={bubble()}
|
|
682
|
+
fallback={
|
|
683
|
+
<Show when={comments().length > 0}>
|
|
684
|
+
<UserMessageComments comments={comments()} bounded={false} />
|
|
685
|
+
</Show>
|
|
686
|
+
}
|
|
687
|
+
>
|
|
688
|
+
<div data-slot="user-message-body" data-voice={props.voice ? "true" : undefined}>
|
|
689
|
+
<Show when={props.voice}>
|
|
690
|
+
<div data-slot="user-message-voice" role="img" aria-label={i18n.t("ui.message.voice")}>
|
|
691
|
+
<Tooltip appearance="compact" value={i18n.t("ui.message.voice")} placement="top" gutter={4}>
|
|
692
|
+
<Icon name="outline-wave-audio" size="small" />
|
|
693
|
+
</Tooltip>
|
|
694
|
+
</div>
|
|
695
|
+
</Show>
|
|
696
|
+
<div
|
|
697
|
+
data-slot="user-message-text"
|
|
698
|
+
dir="auto"
|
|
699
|
+
data-comments={comments().length > 0 && !inline() ? "true" : undefined}
|
|
700
|
+
onCopy={copySessionReferences}
|
|
701
|
+
>
|
|
702
|
+
<Show when={props.fold} fallback={renderBody()}>
|
|
703
|
+
<UserMessageFold
|
|
704
|
+
id={`${props.message.id}-text`}
|
|
705
|
+
text={props.text}
|
|
706
|
+
expanded={expanded()}
|
|
707
|
+
onExpandedChange={setExpanded}
|
|
708
|
+
>
|
|
709
|
+
{renderBody()}
|
|
710
|
+
</UserMessageFold>
|
|
711
|
+
</Show>
|
|
712
|
+
<Show when={comments().length > 0 && !inline()}>
|
|
713
|
+
<UserMessageComments comments={comments()} bounded />
|
|
714
|
+
</Show>
|
|
715
|
+
{renderMenu()}
|
|
716
|
+
</div>
|
|
717
|
+
</div>
|
|
718
|
+
</Show>
|
|
719
|
+
{/* Like the TUI, a pending steer of only attachments still offers its actions. */}
|
|
720
|
+
<Show when={bubble() || comments().length > 0 || pending()}>
|
|
721
|
+
<div data-slot="user-message-copy-wrapper">
|
|
722
|
+
<span data-slot="user-message-meta-wrap">
|
|
723
|
+
<span data-slot="user-message-meta">
|
|
724
|
+
<Show when={metaLabels().length > 0}>
|
|
725
|
+
<span data-slot="user-message-meta-label">
|
|
726
|
+
<MetaItems items={metaLabels()} slot="user-message" />
|
|
727
|
+
</span>
|
|
728
|
+
</Show>
|
|
729
|
+
{/* Pending closes the line and stays in view; the agent and model before it show on hover. */}
|
|
730
|
+
<UserMessageTransition active={waiting()}>
|
|
731
|
+
<Show when={metaLabels().length > 0}>
|
|
732
|
+
<span data-slot="user-message-pending-separator" aria-hidden="true">
|
|
733
|
+
{"\u00B7"}
|
|
734
|
+
</span>
|
|
735
|
+
</Show>
|
|
736
|
+
<span data-slot="user-message-pending">{i18n.t("ui.message.pending")}</span>
|
|
737
|
+
</UserMessageTransition>
|
|
738
|
+
</span>
|
|
739
|
+
</span>
|
|
740
|
+
<Show when={!bubble()}>{renderMenu()}</Show>
|
|
741
|
+
</div>
|
|
742
|
+
</Show>
|
|
743
|
+
</div>
|
|
744
|
+
)
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// The OpenCode iOS app's fold (UserBubbleFold): a message past 12 lines shows its first 8, so a fold always hides at
|
|
748
|
+
// least 5 lines and a message just past the limit never folds away a line or two.
|
|
749
|
+
const USER_MESSAGE_FOLD = { over: 12, show: 8 }
|
|
750
|
+
|
|
751
|
+
function UserMessageFold(props: {
|
|
752
|
+
id: string
|
|
753
|
+
text: string
|
|
754
|
+
expanded: boolean
|
|
755
|
+
onExpandedChange: (expanded: boolean) => void
|
|
756
|
+
children: JSX.Element
|
|
757
|
+
}) {
|
|
758
|
+
const i18n = useI18n()
|
|
759
|
+
// Hard line breaks are a floor on the laid-out lines, so most long messages fold before the row is first measured.
|
|
760
|
+
const [lines, setLines] = createSignal(props.text.trimEnd().split("\n").length)
|
|
761
|
+
const long = () => lines() > USER_MESSAGE_FOLD.over
|
|
762
|
+
const folded = () => long() && !props.expanded
|
|
763
|
+
|
|
764
|
+
let content: HTMLDivElement | undefined
|
|
765
|
+
let toggle: HTMLButtonElement | undefined
|
|
766
|
+
|
|
767
|
+
// The text is laid out whole and clipped, so its own height is the measure at any width.
|
|
768
|
+
const measure = () => {
|
|
769
|
+
// A cached tab's timeline is detached while hidden and measures 0.
|
|
770
|
+
if (!content?.isConnected || content.offsetHeight === 0) return
|
|
771
|
+
const lineHeight = parseFloat(getComputedStyle(content).lineHeight) || 20
|
|
772
|
+
setLines(Math.round(content.offsetHeight / lineHeight))
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
onMount(() => {
|
|
776
|
+
// The bubble gets its wrapping width after the surrounding view mounts.
|
|
777
|
+
queueMicrotask(measure)
|
|
778
|
+
const observer = new ResizeObserver(measure)
|
|
779
|
+
observer.observe(content!)
|
|
780
|
+
onCleanup(() => observer.disconnect())
|
|
781
|
+
})
|
|
782
|
+
|
|
783
|
+
// Opening grows the row downward, so its top stays put. Closing a message whose top is scrolled above the screen
|
|
784
|
+
// would leave the reader past its end, so then the toggle stays where it was pressed.
|
|
785
|
+
const flip = () => {
|
|
786
|
+
const opening = !props.expanded
|
|
787
|
+
const scroller = toggle ? scrollParent(toggle) : undefined
|
|
788
|
+
const above = !!content && !!scroller && content.getBoundingClientRect().top < viewportTop(scroller)
|
|
789
|
+
const before = toggle?.getBoundingClientRect().top
|
|
790
|
+
props.onExpandedChange(opening)
|
|
791
|
+
|
|
792
|
+
if (opening || !above || before === undefined || !toggle || !scroller) return
|
|
793
|
+
const moved = before - toggle.getBoundingClientRect().top
|
|
794
|
+
|
|
795
|
+
if (moved > 1) scroller.scrollTop -= moved
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
return (
|
|
799
|
+
<>
|
|
800
|
+
<div
|
|
801
|
+
id={props.id}
|
|
802
|
+
data-slot="user-message-fold"
|
|
803
|
+
data-folded={folded() ? "" : undefined}
|
|
804
|
+
style={{ "max-height": folded() ? `${USER_MESSAGE_FOLD.show}lh` : undefined }}
|
|
805
|
+
>
|
|
806
|
+
<div ref={content}>{props.children}</div>
|
|
807
|
+
</div>
|
|
808
|
+
<Show when={long()}>
|
|
809
|
+
<button
|
|
810
|
+
ref={toggle}
|
|
811
|
+
type="button"
|
|
812
|
+
data-slot="user-message-fold-toggle"
|
|
813
|
+
aria-expanded={props.expanded}
|
|
814
|
+
aria-controls={props.id}
|
|
815
|
+
onClick={flip}
|
|
816
|
+
>
|
|
817
|
+
<span>{props.expanded ? i18n.t("ui.message.showLess") : i18n.t("ui.message.readMore")}</span>
|
|
818
|
+
<Icon name="chevron-down" />
|
|
819
|
+
</button>
|
|
820
|
+
</Show>
|
|
821
|
+
</>
|
|
822
|
+
)
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
function viewportTop(scroller: Element) {
|
|
826
|
+
return scroller === document.scrollingElement ? 0 : scroller.getBoundingClientRect().top
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
function scrollParent(element: HTMLElement) {
|
|
830
|
+
for (let node = element.parentElement; node; node = node.parentElement) {
|
|
831
|
+
const overflow = getComputedStyle(node).overflowY
|
|
832
|
+
|
|
833
|
+
if ((overflow === "auto" || overflow === "scroll") && node.scrollHeight > node.clientHeight) return node
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
return document.scrollingElement
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
function CurrentHighlightedText(props: { text: string; files: PromptAttachment[]; agents: PromptAgentAttachment[] }) {
|
|
840
|
+
const segments = createMemo(() => {
|
|
841
|
+
const references = [
|
|
842
|
+
...props.files.flatMap((file) =>
|
|
843
|
+
file.mention ? [{ start: file.mention.start, end: file.mention.end, type: "file" as const }] : [],
|
|
844
|
+
),
|
|
845
|
+
...props.agents.flatMap((agent) =>
|
|
846
|
+
agent.mention ? [{ start: agent.mention.start, end: agent.mention.end, type: "agent" as const }] : [],
|
|
847
|
+
),
|
|
848
|
+
].sort((a, b) => a.start - b.start)
|
|
849
|
+
|
|
850
|
+
const result: HighlightSegment[] = []
|
|
851
|
+
|
|
852
|
+
// Plain text between references may contain URLs, which become links.
|
|
853
|
+
const pushText = (text: string) =>
|
|
854
|
+
result.push(
|
|
855
|
+
...linkSegments(text).map(
|
|
856
|
+
(segment): HighlightSegment => ({
|
|
857
|
+
text: segment.text,
|
|
858
|
+
type: segment.href ? "link" : undefined,
|
|
859
|
+
}),
|
|
860
|
+
),
|
|
861
|
+
)
|
|
862
|
+
|
|
863
|
+
let last = 0
|
|
864
|
+
references.forEach((reference) => {
|
|
865
|
+
if (reference.start < last) return
|
|
866
|
+
|
|
867
|
+
if (reference.start > last) pushText(props.text.slice(last, reference.start))
|
|
868
|
+
result.push({ text: props.text.slice(reference.start, reference.end), type: reference.type })
|
|
869
|
+
last = reference.end
|
|
870
|
+
})
|
|
871
|
+
|
|
872
|
+
if (last < props.text.length) pushText(props.text.slice(last))
|
|
873
|
+
|
|
874
|
+
return result
|
|
875
|
+
})
|
|
876
|
+
|
|
877
|
+
return (
|
|
878
|
+
<For each={segments()}>
|
|
879
|
+
{(segment) => (
|
|
880
|
+
<Show
|
|
881
|
+
when={segment.type === "link"}
|
|
882
|
+
fallback={
|
|
883
|
+
<span data-highlight={segment.type}>
|
|
884
|
+
<Show
|
|
885
|
+
when={segment.type && segment.text.startsWith("@")}
|
|
886
|
+
fallback={<SessionReferenceText text={segment.text} />}
|
|
887
|
+
>
|
|
888
|
+
<span data-slot="user-message-mention-prefix">@</span>
|
|
889
|
+
{segment.text.slice(1)}
|
|
890
|
+
</Show>
|
|
891
|
+
</span>
|
|
892
|
+
}
|
|
893
|
+
>
|
|
894
|
+
<a data-slot="user-message-link" href={segment.text} target="_blank" rel="noopener noreferrer">
|
|
895
|
+
{segment.text}
|
|
896
|
+
</a>
|
|
897
|
+
</Show>
|
|
898
|
+
)}
|
|
899
|
+
</For>
|
|
900
|
+
)
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
type HighlightSegment = { text: string; type?: "file" | "agent" | "link" }
|
|
904
|
+
|
|
905
|
+
function copySessionReferences(event: ClipboardEvent & { currentTarget: HTMLDivElement }) {
|
|
906
|
+
const selection = window.getSelection()
|
|
907
|
+
|
|
908
|
+
if (event.defaultPrevented || !event.clipboardData || !selection || selection.isCollapsed) return
|
|
909
|
+
const ranges = Array.from({ length: selection.rangeCount }, (_, index) => selection.getRangeAt(index))
|
|
910
|
+
|
|
911
|
+
if (!ranges.every((range) => event.currentTarget.contains(range.commonAncestorContainer))) return
|
|
912
|
+
const text = sessionReferenceClipboardText(event.currentTarget, ranges)
|
|
913
|
+
|
|
914
|
+
if (text === undefined) return
|
|
915
|
+
event.preventDefault()
|
|
916
|
+
event.clipboardData.setData("text/plain", text)
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
function SessionReferenceText(props: { text: string }) {
|
|
920
|
+
const markdown = useMarkdown()
|
|
921
|
+
const root = document.createElement("span")
|
|
922
|
+
createEffect(() => root.replaceChildren(sessionReferenceText(props.text, (id) => markdown?.sessionTitle?.(id))))
|
|
923
|
+
onCleanup(
|
|
924
|
+
setupSessionLinks(
|
|
925
|
+
root,
|
|
926
|
+
() => markdown?.openSession,
|
|
927
|
+
() => markdown?.sessionMenu,
|
|
928
|
+
),
|
|
929
|
+
)
|
|
930
|
+
|
|
931
|
+
return root
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
/** A compaction the server admitted but has not started, drawn as the divider a started one opens with. */
|
|
935
|
+
export function SessionCompactionQueued() {
|
|
936
|
+
const i18n = useI18n()
|
|
937
|
+
|
|
938
|
+
return (
|
|
939
|
+
<div data-component="session-compaction-message">
|
|
940
|
+
<CompactionDivider label={i18n.t("ui.messagePart.compaction.queued")} />
|
|
941
|
+
</div>
|
|
942
|
+
)
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
function CompactionDivider(props: { label: string }) {
|
|
946
|
+
return (
|
|
947
|
+
<div class="py-2">
|
|
948
|
+
<TimelineSeparator label={props.label} />
|
|
949
|
+
</div>
|
|
950
|
+
)
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
export function SessionCompactionMessage(props: { message: SessionMessageCompaction; error: string }) {
|
|
954
|
+
const i18n = useI18n()
|
|
955
|
+
const summary = () => (props.message.status === "failed" ? "" : props.message.summary)
|
|
956
|
+
|
|
957
|
+
const error = () => {
|
|
958
|
+
if (props.message.status !== "failed") return ""
|
|
959
|
+
|
|
960
|
+
if (props.message.error.type === "aborted" || props.message.error.type === "compaction.interrupted") return ""
|
|
961
|
+
|
|
962
|
+
return props.error
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
const compact = createMemo(
|
|
966
|
+
() => new Intl.NumberFormat(i18n.locale(), { notation: "compact", maximumFractionDigits: 1 }),
|
|
967
|
+
)
|
|
968
|
+
|
|
969
|
+
// Usage of the compaction request itself; the resulting context size only shows on the next assistant step.
|
|
970
|
+
const usage = () => {
|
|
971
|
+
if (props.message.status === "running" || !props.message.tokens) return ""
|
|
972
|
+
const tokens = props.message.tokens
|
|
973
|
+
const input = tokens.input + tokens.cache.read + tokens.cache.write
|
|
974
|
+
const output = tokens.output + tokens.reasoning
|
|
975
|
+
|
|
976
|
+
if (input + output <= 0) return ""
|
|
977
|
+
|
|
978
|
+
return i18n.t("ui.messagePart.compaction.usage", {
|
|
979
|
+
input: compact().format(input),
|
|
980
|
+
output: compact().format(output),
|
|
981
|
+
})
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
const outcome = () => {
|
|
985
|
+
if (props.message.status !== "failed")
|
|
986
|
+
return props.message.status === "completed" && props.message.native?.messages
|
|
987
|
+
? "ui.messagePart.providerCompaction"
|
|
988
|
+
: "ui.messagePart.compaction"
|
|
989
|
+
|
|
990
|
+
if (props.message.error.type === "aborted") return "ui.messagePart.compaction.cancelled"
|
|
991
|
+
|
|
992
|
+
if (props.message.error.type === "compaction.interrupted") return "ui.messagePart.compaction.interrupted"
|
|
993
|
+
|
|
994
|
+
return "ui.messagePart.compaction.failed"
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
const label = createMemo(() => [i18n.t(outcome()), usage()].filter(Boolean).join(" · "))
|
|
998
|
+
|
|
999
|
+
return (
|
|
1000
|
+
<Show
|
|
1001
|
+
when={props.message.reason === "manual" || props.message.status === "failed"}
|
|
1002
|
+
fallback={
|
|
1003
|
+
<QuietCompaction
|
|
1004
|
+
id={props.message.id}
|
|
1005
|
+
created={props.message.time.created}
|
|
1006
|
+
running={props.message.status === "running"}
|
|
1007
|
+
summary={summary()}
|
|
1008
|
+
usage={usage()}
|
|
1009
|
+
/>
|
|
1010
|
+
}
|
|
1011
|
+
>
|
|
1012
|
+
<div data-component="session-compaction-message">
|
|
1013
|
+
<CompactionDivider label={i18n.t("ui.messagePart.compaction.started")} />
|
|
1014
|
+
<Show when={summary().trim()}>
|
|
1015
|
+
<div data-component="text-part" data-timeline-part-id={props.message.id}>
|
|
1016
|
+
<div data-slot="text-part-body">
|
|
1017
|
+
<PacedMarkdown
|
|
1018
|
+
text={summary()}
|
|
1019
|
+
cacheKey={props.message.id}
|
|
1020
|
+
streaming={props.message.status === "running"}
|
|
1021
|
+
/>
|
|
1022
|
+
</div>
|
|
1023
|
+
</div>
|
|
1024
|
+
</Show>
|
|
1025
|
+
<Show when={props.message.status === "running"}>
|
|
1026
|
+
<div role="status" class="py-2">
|
|
1027
|
+
<BasicTool
|
|
1028
|
+
icon="archive"
|
|
1029
|
+
trigger={{ title: i18n.t("ui.messagePart.compaction.running") }}
|
|
1030
|
+
status="running"
|
|
1031
|
+
locked
|
|
1032
|
+
hideDetails
|
|
1033
|
+
/>
|
|
1034
|
+
</div>
|
|
1035
|
+
</Show>
|
|
1036
|
+
<Show when={props.message.status !== "running"}>
|
|
1037
|
+
<div class="py-2">
|
|
1038
|
+
<TimelineSeparator label={label()} />
|
|
1039
|
+
</div>
|
|
1040
|
+
</Show>
|
|
1041
|
+
<Show when={error()}>
|
|
1042
|
+
<Card variant="error" class="error-card">
|
|
1043
|
+
<LinkedText text={error()} />
|
|
1044
|
+
</Card>
|
|
1045
|
+
</Show>
|
|
1046
|
+
</div>
|
|
1047
|
+
</Show>
|
|
1048
|
+
)
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
/**
|
|
1052
|
+
* An automatic compaction, drawn as one divider that reads Compacting, then Compacted. Its height never changes, and
|
|
1053
|
+
* clicking it opens the summary.
|
|
1054
|
+
*/
|
|
1055
|
+
function QuietCompaction(props: { id: string; created: number; running: boolean; summary: string; usage: string }) {
|
|
1056
|
+
const i18n = useI18n()
|
|
1057
|
+
const [open, setOpen] = createSignal(false)
|
|
1058
|
+
// A new one waits out the grace before showing Compacting; one that ends inside it, as a precomputed summary does,
|
|
1059
|
+
// only fades in as Compacted. One already running or finished when the history loads shows without an entrance.
|
|
1060
|
+
const initial = createCompactionEntranceState({ ageMs: Date.now() - props.created, running: props.running })
|
|
1061
|
+
const [entrance, setEntrance] = createSignal(initial.state)
|
|
1062
|
+
const enter = createMemo(() => selectCompactionEnter(entrance()))
|
|
1063
|
+
let graceTimer: ReturnType<typeof setTimeout> | undefined
|
|
1064
|
+
|
|
1065
|
+
const runEntrance = (effect: CompactionEntranceEffect) => {
|
|
1066
|
+
clearTimeout(graceTimer)
|
|
1067
|
+
graceTimer = undefined
|
|
1068
|
+
|
|
1069
|
+
if (effect.type === "schedule-grace")
|
|
1070
|
+
graceTimer = setTimeout(() => dispatchEntrance(GRACE_ELAPSED_EVENT), effect.delayMs)
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
const dispatchEntrance = (event: CompactionEntranceEvent) => {
|
|
1074
|
+
const result = transitionCompactionEntrance(untrack(entrance), event)
|
|
1075
|
+
setEntrance(result.state)
|
|
1076
|
+
result.effects.forEach(runEntrance)
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
initial.effects.forEach(runEntrance)
|
|
1080
|
+
createEffect(() => dispatchEntrance({ type: "running.changed", running: props.running }))
|
|
1081
|
+
onCleanup(() => dispatchEntrance(DISPOSED_COMPACTION_ENTRANCE_EVENT))
|
|
1082
|
+
|
|
1083
|
+
const expandable = () => !props.running && !!props.summary.trim()
|
|
1084
|
+
|
|
1085
|
+
const label = createMemo(() =>
|
|
1086
|
+
splitEnding(i18n.t("ui.messagePart.compaction.running"), i18n.t("ui.messagePart.compaction.done")),
|
|
1087
|
+
)
|
|
1088
|
+
|
|
1089
|
+
return (
|
|
1090
|
+
<div data-component="session-compaction-message" data-quiet="" data-enter={enter()}>
|
|
1091
|
+
<div class="py-2">
|
|
1092
|
+
<button
|
|
1093
|
+
type="button"
|
|
1094
|
+
data-slot="session-compaction-divider"
|
|
1095
|
+
data-state={props.running ? "running" : "done"}
|
|
1096
|
+
class="flex h-8 w-full items-center gap-3 text-v2-text-text-faint"
|
|
1097
|
+
disabled={!expandable()}
|
|
1098
|
+
aria-busy={props.running}
|
|
1099
|
+
aria-expanded={expandable() ? open() : undefined}
|
|
1100
|
+
aria-controls={expandable() && open() ? `${props.id}-summary` : undefined}
|
|
1101
|
+
aria-label={props.running ? label().running : label().done}
|
|
1102
|
+
onClick={() => setOpen((value) => !value)}
|
|
1103
|
+
>
|
|
1104
|
+
<span data-slot="session-compaction-line" data-side="start" class="h-px min-w-0 flex-1">
|
|
1105
|
+
<span data-slot="session-compaction-light" />
|
|
1106
|
+
</span>
|
|
1107
|
+
<span
|
|
1108
|
+
data-slot="session-compaction-label"
|
|
1109
|
+
class="relative flex shrink-0 whitespace-pre text-[13px] font-[440] leading-text-compact tracking-[-0.04px]"
|
|
1110
|
+
>
|
|
1111
|
+
<span>{label().stem}</span>
|
|
1112
|
+
<span data-slot="session-compaction-ending" class="grid justify-items-start">
|
|
1113
|
+
<span data-slot="session-compaction-running">{label().ending.running}</span>
|
|
1114
|
+
<span data-slot="session-compaction-done">{label().ending.done}</span>
|
|
1115
|
+
</span>
|
|
1116
|
+
<span data-slot="session-compaction-glint" aria-hidden="true">
|
|
1117
|
+
<span data-slot="session-compaction-glint-stem">{label().stem}</span>
|
|
1118
|
+
<span data-slot="session-compaction-glint-ending">{label().ending.running}</span>
|
|
1119
|
+
</span>
|
|
1120
|
+
</span>
|
|
1121
|
+
<span data-slot="session-compaction-line" data-side="end" class="h-px min-w-0 flex-1">
|
|
1122
|
+
<span data-slot="session-compaction-light" />
|
|
1123
|
+
</span>
|
|
1124
|
+
</button>
|
|
1125
|
+
</div>
|
|
1126
|
+
<Show when={expandable() && open()}>
|
|
1127
|
+
<div id={`${props.id}-summary`} data-slot="session-compaction-summary">
|
|
1128
|
+
<div data-component="text-part" data-timeline-part-id={props.id}>
|
|
1129
|
+
<div data-slot="text-part-body">
|
|
1130
|
+
<PacedMarkdown text={props.summary} cacheKey={props.id} streaming={false} />
|
|
1131
|
+
</div>
|
|
1132
|
+
</div>
|
|
1133
|
+
<Show when={props.usage}>
|
|
1134
|
+
<div class="mt-2 text-[13px] leading-text-compact text-v2-text-text-faint tabular-nums">{props.usage}</div>
|
|
1135
|
+
</Show>
|
|
1136
|
+
</div>
|
|
1137
|
+
</Show>
|
|
1138
|
+
</div>
|
|
1139
|
+
)
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
/**
|
|
1143
|
+
* Splits Compacting and Compacted at their shared stem, so only the ending changes when the compaction ends. It splits
|
|
1144
|
+
* between whole characters as they are read, so a vowel sign stays with its consonant.
|
|
1145
|
+
*/
|
|
1146
|
+
function splitEnding(running: string, done: string) {
|
|
1147
|
+
const graphemes = new Intl.Segmenter(undefined, { granularity: "grapheme" })
|
|
1148
|
+
const chars = Array.from(graphemes.segment(running), (part) => part.segment)
|
|
1149
|
+
const others = Array.from(graphemes.segment(done), (part) => part.segment)
|
|
1150
|
+
const at = chars.findIndex((char, index) => char !== others[index])
|
|
1151
|
+
const stem = chars.slice(0, at === -1 ? chars.length : at).join("")
|
|
1152
|
+
|
|
1153
|
+
return { running, done, stem, ending: { running: running.slice(stem.length), done: done.slice(stem.length) } }
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
export function AssistantTextContent(props: {
|
|
1157
|
+
id: string
|
|
1158
|
+
text: string
|
|
1159
|
+
message: SessionMessageAssistant
|
|
1160
|
+
showCopy: boolean
|
|
1161
|
+
keepCopyVisible?: boolean
|
|
1162
|
+
turnDurationMs?: number | null
|
|
1163
|
+
turnTokensPerSecond?: number
|
|
1164
|
+
/** The finished turn's web searches and fetches, shown as a chip in its footer. */
|
|
1165
|
+
sources?: TurnSources
|
|
1166
|
+
onOpenSources?: () => void
|
|
1167
|
+
}) {
|
|
1168
|
+
const data = useData()
|
|
1169
|
+
const i18n = useI18n()
|
|
1170
|
+
const sourcesHost = useSources()
|
|
1171
|
+
const numfmt = createMemo(() => new Intl.NumberFormat(i18n.locale()))
|
|
1172
|
+
// A footer that arrives after the reply rendered belongs to a turn that just finished, so its chip fades in.
|
|
1173
|
+
let rendered = false
|
|
1174
|
+
onMount(() => (rendered = true))
|
|
1175
|
+
const sources = () => (props.showCopy && sourcesHost?.enabled ? props.sources : undefined)
|
|
1176
|
+
|
|
1177
|
+
const interrupted = () => isInterruptedError(props.message.error)
|
|
1178
|
+
|
|
1179
|
+
const labels = createMemo<MetaItem[]>(() => {
|
|
1180
|
+
const agent = agentLabel(props.message.agent, data.agents)
|
|
1181
|
+
|
|
1182
|
+
return [...(agent ? [{ label: agent }] : []), ...modelItems(data, props.message.model)]
|
|
1183
|
+
})
|
|
1184
|
+
|
|
1185
|
+
const duration = createMemo(() => {
|
|
1186
|
+
const completed = props.message.time.completed
|
|
1187
|
+
|
|
1188
|
+
const ms =
|
|
1189
|
+
props.turnDurationMs === null
|
|
1190
|
+
? -1
|
|
1191
|
+
: props.turnDurationMs !== undefined
|
|
1192
|
+
? props.turnDurationMs
|
|
1193
|
+
: completed !== undefined
|
|
1194
|
+
? completed - props.message.time.created
|
|
1195
|
+
: -1
|
|
1196
|
+
|
|
1197
|
+
if (!(ms >= 0)) return ""
|
|
1198
|
+
const total = Math.round(ms / 1000)
|
|
1199
|
+
|
|
1200
|
+
if (total < 60) return i18n.t("ui.message.duration.seconds", { count: numfmt().format(total) })
|
|
1201
|
+
|
|
1202
|
+
return i18n.t("ui.message.duration.minutesSeconds", {
|
|
1203
|
+
minutes: numfmt().format(Math.floor(total / 60)),
|
|
1204
|
+
seconds: numfmt().format(total % 60),
|
|
1205
|
+
})
|
|
1206
|
+
})
|
|
1207
|
+
|
|
1208
|
+
// Mobile omits the per-response agent and model; see CurrentUserMessageDisplay.
|
|
1209
|
+
const mobile = createMediaQuery("(max-width: 767px)")
|
|
1210
|
+
|
|
1211
|
+
const meta = createMemo<MetaItem[]>(() => [
|
|
1212
|
+
...(mobile() ? [] : labels()),
|
|
1213
|
+
...[duration(), interrupted() ? i18n.t("ui.message.interrupted") : ""].flatMap((label) =>
|
|
1214
|
+
label ? [{ label }] : [],
|
|
1215
|
+
),
|
|
1216
|
+
])
|
|
1217
|
+
|
|
1218
|
+
const speed = createMemo(() => {
|
|
1219
|
+
if (props.turnTokensPerSecond === undefined) return undefined
|
|
1220
|
+
|
|
1221
|
+
return i18n.t("ui.message.tokensPerSecond", {
|
|
1222
|
+
value: new Intl.NumberFormat(i18n.locale(), {
|
|
1223
|
+
minimumFractionDigits: 1,
|
|
1224
|
+
maximumFractionDigits: 1,
|
|
1225
|
+
}).format(props.turnTokensPerSecond),
|
|
1226
|
+
})
|
|
1227
|
+
})
|
|
1228
|
+
|
|
1229
|
+
const copy = createCopyFeedback()
|
|
1230
|
+
|
|
1231
|
+
return (
|
|
1232
|
+
<Show when={props.text}>
|
|
1233
|
+
<div data-component="text-part" data-timeline-part-id={props.id}>
|
|
1234
|
+
<div data-slot="text-part-body">
|
|
1235
|
+
<PacedMarkdown text={props.text} cacheKey={props.id} streaming={props.message.time.completed === undefined} />
|
|
1236
|
+
</div>
|
|
1237
|
+
<Show when={sources()} fallback={<Show when={props.showCopy}>{copyFooter()}</Show>}>
|
|
1238
|
+
{(value) => (
|
|
1239
|
+
<div data-slot="text-part-footer">
|
|
1240
|
+
<SourcesChip
|
|
1241
|
+
sources={value()}
|
|
1242
|
+
icons={sourcesHost?.icons ?? "letters"}
|
|
1243
|
+
appear={rendered}
|
|
1244
|
+
onOpen={() => props.onOpenSources?.()}
|
|
1245
|
+
/>
|
|
1246
|
+
{copyFooter()}
|
|
1247
|
+
</div>
|
|
1248
|
+
)}
|
|
1249
|
+
</Show>
|
|
1250
|
+
</div>
|
|
1251
|
+
</Show>
|
|
1252
|
+
)
|
|
1253
|
+
|
|
1254
|
+
function copyFooter() {
|
|
1255
|
+
return (
|
|
1256
|
+
<div
|
|
1257
|
+
data-slot="text-part-copy-wrapper"
|
|
1258
|
+
data-keep-copy-visible={props.keepCopyVisible ? "" : undefined}
|
|
1259
|
+
data-interrupted={interrupted() ? "" : undefined}
|
|
1260
|
+
>
|
|
1261
|
+
<MessageActionButton
|
|
1262
|
+
copied={copy.copied()}
|
|
1263
|
+
size="small"
|
|
1264
|
+
label={copy.copied() ? i18n.t("ui.message.copied") : i18n.t("ui.message.copyResponse")}
|
|
1265
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
1266
|
+
onClick={() => copy.copy(props.text)}
|
|
1267
|
+
aria-label={copy.copied() ? i18n.t("ui.message.copied") : i18n.t("ui.message.copyResponse")}
|
|
1268
|
+
/>
|
|
1269
|
+
<Show when={meta().length > 0}>
|
|
1270
|
+
<span data-slot="text-part-meta">
|
|
1271
|
+
<MetaItems items={meta()} slot="text-part" />
|
|
1272
|
+
<Show when={speed()}>
|
|
1273
|
+
{(label) => (
|
|
1274
|
+
<span data-slot="text-part-meta-speed">
|
|
1275
|
+
<span aria-hidden="true">{"\u00B7"}</span>
|
|
1276
|
+
<span dir="auto">{label()}</span>
|
|
1277
|
+
</span>
|
|
1278
|
+
)}
|
|
1279
|
+
</Show>
|
|
1280
|
+
</span>
|
|
1281
|
+
</Show>
|
|
1282
|
+
</div>
|
|
1283
|
+
)
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
export function AssistantReasoningContent(props: {
|
|
1288
|
+
id: string
|
|
1289
|
+
content: SessionMessageAssistantReasoning
|
|
1290
|
+
/** Finished thoughts that follow this one with nothing between, shown and timed with it. */
|
|
1291
|
+
more?: { id: string; content: SessionMessageAssistantReasoning }[]
|
|
1292
|
+
streaming: boolean
|
|
1293
|
+
defaultOpen?: boolean
|
|
1294
|
+
open?: boolean
|
|
1295
|
+
onOpenChange?: (open: boolean) => void
|
|
1296
|
+
onContentRendered?: () => void
|
|
1297
|
+
}) {
|
|
1298
|
+
const i18n = useI18n()
|
|
1299
|
+
const heading = createMemo(() => (props.streaming ? reasoningHeading(props.content.text) : ""))
|
|
1300
|
+
|
|
1301
|
+
const parts = createMemo(() => [{ id: props.id, content: props.content }, ...(props.more ?? [])])
|
|
1302
|
+
|
|
1303
|
+
const duration = createMemo(() => {
|
|
1304
|
+
const times = parts().flatMap((part) => {
|
|
1305
|
+
const time = part.content.time
|
|
1306
|
+
|
|
1307
|
+
return time?.completed === undefined ? [] : [Math.max(0, time.completed - time.created)]
|
|
1308
|
+
})
|
|
1309
|
+
|
|
1310
|
+
if (times.length < parts().length) return undefined
|
|
1311
|
+
const total = Math.round(times.reduce((sum, time) => sum + time, 0) / 1000)
|
|
1312
|
+
const numfmt = new Intl.NumberFormat(i18n.locale())
|
|
1313
|
+
|
|
1314
|
+
if (total < 60) return i18n.t("ui.message.duration.seconds", { count: numfmt.format(total) })
|
|
1315
|
+
|
|
1316
|
+
return i18n.t("ui.message.duration.minutesSeconds", {
|
|
1317
|
+
minutes: numfmt.format(Math.floor(total / 60)),
|
|
1318
|
+
seconds: numfmt.format(total % 60),
|
|
1319
|
+
})
|
|
1320
|
+
})
|
|
1321
|
+
|
|
1322
|
+
return (
|
|
1323
|
+
<div
|
|
1324
|
+
data-component="reasoning-part"
|
|
1325
|
+
data-timeline-part-id={props.more?.length ? undefined : props.id}
|
|
1326
|
+
data-timeline-part-ids={
|
|
1327
|
+
props.more?.length
|
|
1328
|
+
? parts()
|
|
1329
|
+
.map((part) => part.id)
|
|
1330
|
+
.join(",")
|
|
1331
|
+
: undefined
|
|
1332
|
+
}
|
|
1333
|
+
>
|
|
1334
|
+
<BasicTool
|
|
1335
|
+
icon="mcp"
|
|
1336
|
+
status={props.streaming ? "running" : "completed"}
|
|
1337
|
+
compact
|
|
1338
|
+
hasContent
|
|
1339
|
+
allowOpenWhilePending
|
|
1340
|
+
hideDetails={parts().every((part) => !part.content.text.trim())}
|
|
1341
|
+
open={props.open}
|
|
1342
|
+
defaultOpen={props.defaultOpen}
|
|
1343
|
+
onOpenChange={(value) => {
|
|
1344
|
+
props.onOpenChange?.(value)
|
|
1345
|
+
props.onContentRendered?.()
|
|
1346
|
+
}}
|
|
1347
|
+
trigger={(open) => (
|
|
1348
|
+
<div data-slot="basic-tool-tool-info-structured">
|
|
1349
|
+
<div data-slot="basic-tool-tool-info-main">
|
|
1350
|
+
<span data-slot="basic-tool-tool-title">
|
|
1351
|
+
<TextShimmer
|
|
1352
|
+
text={i18n.t(props.streaming ? "ui.sessionTurn.status.thinking" : "ui.message.thought")}
|
|
1353
|
+
active={props.streaming}
|
|
1354
|
+
/>
|
|
1355
|
+
</span>
|
|
1356
|
+
<Show
|
|
1357
|
+
when={props.streaming && !open()}
|
|
1358
|
+
fallback={
|
|
1359
|
+
<Show when={!props.streaming && duration()}>
|
|
1360
|
+
{(value) => <span data-slot="basic-tool-tool-subtitle">{value()}</span>}
|
|
1361
|
+
</Show>
|
|
1362
|
+
}
|
|
1363
|
+
>
|
|
1364
|
+
<span data-slot="basic-tool-tool-subtitle">
|
|
1365
|
+
<TextReveal text={heading()} />
|
|
1366
|
+
</span>
|
|
1367
|
+
</Show>
|
|
1368
|
+
</div>
|
|
1369
|
+
</div>
|
|
1370
|
+
)}
|
|
1371
|
+
>
|
|
1372
|
+
<Show
|
|
1373
|
+
when={props.more?.length}
|
|
1374
|
+
fallback={<PacedMarkdown text={props.content.text} cacheKey={props.id} streaming={props.streaming} />}
|
|
1375
|
+
>
|
|
1376
|
+
<div data-slot="reasoning-part-run">
|
|
1377
|
+
<Index each={parts()}>
|
|
1378
|
+
{(part) => (
|
|
1379
|
+
<Show when={part().content.text.trim()}>
|
|
1380
|
+
<div data-timeline-part-id={part().id}>
|
|
1381
|
+
<PacedMarkdown text={part().content.text} cacheKey={part().id} streaming={false} />
|
|
1382
|
+
</div>
|
|
1383
|
+
</Show>
|
|
1384
|
+
)}
|
|
1385
|
+
</Index>
|
|
1386
|
+
</div>
|
|
1387
|
+
</Show>
|
|
1388
|
+
</BasicTool>
|
|
1389
|
+
</div>
|
|
1390
|
+
)
|
|
1391
|
+
}
|