test(web): refresh plan-review and seeded-history goldens after master merge
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: auto;
|
||||
container: trajectory-table / inline-size;
|
||||
}
|
||||
|
||||
.table {
|
||||
@@ -235,6 +236,18 @@
|
||||
width: 3px;
|
||||
}
|
||||
|
||||
.table tbody tr[data-error='true'] .turnRail {
|
||||
background: color-mix(
|
||||
in srgb,
|
||||
var(--dsw-alias-state-error-primary) 22%,
|
||||
var(--dsw-alias-bg-layer-1)
|
||||
);
|
||||
}
|
||||
|
||||
.table tbody tr[data-error='true'] .selectionRail {
|
||||
background: var(--dsw-alias-state-error-primary);
|
||||
}
|
||||
|
||||
.table tbody tr[data-turn-start='true'] td {
|
||||
position: relative;
|
||||
overflow: visible;
|
||||
@@ -279,6 +292,10 @@
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.turnLabelCompact {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.turnLabelActive {
|
||||
color: color-mix(
|
||||
in srgb,
|
||||
@@ -325,11 +342,66 @@
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.kindTagIcon {
|
||||
display: none;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 13px;
|
||||
height: 13px;
|
||||
}
|
||||
|
||||
.kindTagLabel {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.table .kindSlot .message {
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@container trajectory-table (max-width: 620px) {
|
||||
.eventColumn {
|
||||
width: 50px;
|
||||
}
|
||||
|
||||
.event {
|
||||
padding-right: 3px !important;
|
||||
padding-left: 28px !important;
|
||||
}
|
||||
|
||||
.requestBoundaryControl {
|
||||
left: 6px;
|
||||
}
|
||||
|
||||
.kindSlot {
|
||||
width: 19px;
|
||||
}
|
||||
|
||||
.kindTag,
|
||||
.table .kindSlot .message {
|
||||
justify-content: center;
|
||||
width: 19px;
|
||||
padding-right: 0;
|
||||
padding-left: 0;
|
||||
}
|
||||
|
||||
.kindTagIcon {
|
||||
display: inline-flex;
|
||||
}
|
||||
|
||||
.kindTagLabel {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.turnLabelFull {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.turnLabelCompact {
|
||||
display: inline;
|
||||
}
|
||||
}
|
||||
|
||||
.user {
|
||||
color: var(--dsw-alias-state-business-primary);
|
||||
background: var(--dsw-alias-state-business-tertiary);
|
||||
@@ -576,6 +648,28 @@
|
||||
color: var(--dsw-alias-state-error-primary);
|
||||
}
|
||||
|
||||
.overview dd.error {
|
||||
color: var(--dsw-alias-state-error-primary);
|
||||
}
|
||||
|
||||
.details .errorPayload {
|
||||
color: var(--dsw-alias-state-error-primary);
|
||||
}
|
||||
|
||||
.details .errorPayload .resultBlockText {
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.details .jsonPayload.errorPayload,
|
||||
.details .jsonPreview.errorPayload {
|
||||
--json-tree-property: var(--dsw-alias-state-error-primary);
|
||||
--json-tree-string: var(--dsw-alias-state-error-primary);
|
||||
--json-tree-number: var(--dsw-alias-state-error-primary);
|
||||
--json-tree-keyword: var(--dsw-alias-state-error-primary);
|
||||
--json-tree-punctuation: var(--dsw-alias-state-error-primary);
|
||||
--json-tree-icon: var(--dsw-alias-state-error-primary);
|
||||
}
|
||||
|
||||
.details {
|
||||
position: relative;
|
||||
display: flex;
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
/** Turn-aware trajectory event ledger with a local record inspector. */
|
||||
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import type { CSSProperties, ReactNode } from 'react'
|
||||
import {
|
||||
extractMarkdownPlainText, IconChevronRightOutline14, JsonTree, MarkdownText,
|
||||
IconChevronRightOutline14,
|
||||
IconSettingsOutline16,
|
||||
IconSparkle16,
|
||||
IconUserOutline16,
|
||||
JsonTree,
|
||||
MarkdownText,
|
||||
Tooltip,
|
||||
} from '@deepseek-ai/dsh-client-ui-primitives'
|
||||
import { structuredPatch } from 'diff'
|
||||
import type {
|
||||
@@ -13,7 +19,7 @@ import type {
|
||||
AssistantMetricDetail, TrajectoryCellKind, TrajectoryCellProps, TrajectorySourceBlock,
|
||||
} from './trajectory-record.ts'
|
||||
import { formatElapsedSeconds } from './trajectory-record.ts'
|
||||
import type { TrajectoryTurnModel } from './layout.ts'
|
||||
import { trajectoryPreviewText, type TrajectoryTurnModel } from './layout.ts'
|
||||
import css from './TrajectoryTable.module.css'
|
||||
|
||||
const KIND_LABEL: Record<TrajectoryCellKind, string> = {
|
||||
@@ -26,6 +32,77 @@ const KIND_LABEL: Record<TrajectoryCellKind, string> = {
|
||||
subtool: 'SUBTOOL',
|
||||
}
|
||||
|
||||
function ToolWrenchIcon(): ReactNode {
|
||||
return (
|
||||
<svg
|
||||
width="13"
|
||||
height="13"
|
||||
viewBox="0 0 16 16"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
data-role-icon="wrench"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path d="M14 3.3a3.8 3.8 0 0 1-4.8 4.8l-5.1 5.1a1.6 1.6 0 1 1-2.3-2.3l5.1-5.1A3.8 3.8 0 0 1 11.7 1l-2.3 2.3 2.3 2.3L14 3.3Z" />
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
|
||||
function InformationIcon(): ReactNode {
|
||||
return (
|
||||
<svg
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 16 16"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.4"
|
||||
strokeLinecap="round"
|
||||
data-role-icon="information"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<circle cx="8" cy="8" r="6.7" />
|
||||
<circle cx="8" cy="5.5" r=".85" fill="currentColor" stroke="none" />
|
||||
<path d="M8 7.75v3.4" strokeWidth="1.8" />
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
|
||||
function CompactedIcon(): ReactNode {
|
||||
return (
|
||||
<svg
|
||||
width="13"
|
||||
height="13"
|
||||
viewBox="0 0 16 16"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
data-role-icon="compacted"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path d="m2.5 2.5 3.75 3.75M3 6.25h3.25V3" />
|
||||
<path d="m13.5 2.5-3.75 3.75M13 6.25H9.75V3" />
|
||||
<path d="m2.5 13.5 3.75-3.75M3 9.75h3.25V13" />
|
||||
<path d="m13.5 13.5-3.75-3.75M13 9.75H9.75V13" />
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
|
||||
const KIND_ICON: Record<TrajectoryCellKind, ReactNode> = {
|
||||
system: <IconSettingsOutline16 size={13} />,
|
||||
user: <IconUserOutline16 size={13} />,
|
||||
context: <InformationIcon />,
|
||||
compacted: <CompactedIcon />,
|
||||
message: <IconSparkle16 size={13} />,
|
||||
tool: <ToolWrenchIcon />,
|
||||
subtool: <ToolWrenchIcon />,
|
||||
}
|
||||
|
||||
interface TableRecord {
|
||||
turn: number
|
||||
group: string
|
||||
@@ -225,6 +302,8 @@ export interface TrajectoryTableProps {
|
||||
onSelectedIndexChange?: (index: number | null) => void
|
||||
/** Report a direct user selection from a ledger row. */
|
||||
onRecordSelect?: (index: number) => void
|
||||
/** One externally requested record selection; a new object repeats the request. */
|
||||
recordSelection?: { readonly index: number } | null
|
||||
/** Clear selection state owned by the ledger host. */
|
||||
onClearSelection?: () => void
|
||||
/** Turn ids whose rows after the first are folded into a summary. */
|
||||
@@ -725,13 +804,13 @@ function detailTabs(record: TableRecord): readonly DetailTabItem[] {
|
||||
|
||||
function recordDisplayText(cell: TrajectoryCellProps): string {
|
||||
if (isToolCallOnly(cell)) return ''
|
||||
if (cell.text !== '') return cell.text
|
||||
const markdown = cell.kind === 'user' || cell.kind === 'context'
|
||||
? cell.inputDetail
|
||||
: cell.kind === 'message'
|
||||
? cell.outputDetail ?? cell.thinkingDetail
|
||||
: undefined
|
||||
if (!markdown) return cell.text
|
||||
return extractMarkdownPlainText(markdown).replace(/\s+/g, ' ').trim()
|
||||
return markdown === undefined ? '' : trajectoryPreviewText(markdown)
|
||||
}
|
||||
|
||||
function toolCallTextParts(
|
||||
@@ -1047,13 +1126,20 @@ function SystemPromptDiff({
|
||||
|
||||
function ToolOutputBlocks({
|
||||
blocks,
|
||||
error,
|
||||
preview,
|
||||
}: {
|
||||
blocks: readonly TrajectorySourceBlock[]
|
||||
error: boolean
|
||||
preview: boolean
|
||||
}) {
|
||||
return (
|
||||
<div className={preview ? `${css.resultBlocks} ${css.resultBlocksPreview}` : css.resultBlocks}>
|
||||
<div className={[
|
||||
css.resultBlocks,
|
||||
preview ? css.resultBlocksPreview : undefined,
|
||||
error ? css.errorPayload : undefined,
|
||||
].filter((value): value is string => value !== undefined).join(' ')}
|
||||
>
|
||||
{blocks.map((block, index) => (
|
||||
block.imageSrc !== undefined
|
||||
? <PanelImage block={block} preview={preview} key={index} />
|
||||
@@ -1226,6 +1312,9 @@ function RecordPayload({
|
||||
? 'No payload captured'
|
||||
: 'No result captured'
|
||||
if (!value) return <p className={css.noPayload}>{missing}</p>
|
||||
const error = direction === 'output' && record.cell.isError === true
|
||||
const payloadClass = preview ? css.jsonPreview : css.jsonPayload
|
||||
const payloadClassName = error ? `${payloadClass} ${css.errorPayload}` : payloadClass
|
||||
|
||||
const json = parseJsonContainer(value)
|
||||
const singleTextResult = direction === 'output'
|
||||
@@ -1236,7 +1325,7 @@ function RecordPayload({
|
||||
<JsonTree
|
||||
data={json}
|
||||
label="Result JSON"
|
||||
className={preview ? css.jsonPreview : css.jsonPayload}
|
||||
className={payloadClassName}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -1249,6 +1338,7 @@ function RecordPayload({
|
||||
return (
|
||||
<ToolOutputBlocks
|
||||
blocks={record.cell.outputBlocks}
|
||||
error={error}
|
||||
preview={preview}
|
||||
/>
|
||||
)
|
||||
@@ -1262,7 +1352,11 @@ function RecordPayload({
|
||||
)
|
||||
if (markdown) {
|
||||
return (
|
||||
<div className={preview ? css.markdownPreview : css.markdownPayload}>
|
||||
<div className={[
|
||||
preview ? css.markdownPreview : css.markdownPayload,
|
||||
error ? css.errorPayload : undefined,
|
||||
].filter((className): className is string => className !== undefined).join(' ')}
|
||||
>
|
||||
<MarkdownText text={value} />
|
||||
</div>
|
||||
)
|
||||
@@ -1272,7 +1366,7 @@ function RecordPayload({
|
||||
<JsonTree
|
||||
data={json}
|
||||
label={`${direction === 'input' ? 'Payload' : 'Result'} JSON`}
|
||||
className={preview ? css.jsonPreview : css.jsonPayload}
|
||||
className={payloadClassName}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -1280,7 +1374,7 @@ function RecordPayload({
|
||||
<pre className={[
|
||||
css.payload,
|
||||
preview ? css.payloadPreview : undefined,
|
||||
record.cell.isError ? css.error : undefined,
|
||||
error ? css.errorPayload : undefined,
|
||||
value === 'No output' ? css.noOutputText : undefined,
|
||||
].filter((value): value is string => value !== undefined).join(' ')}
|
||||
>
|
||||
@@ -1401,6 +1495,7 @@ export function TrajectoryTable({
|
||||
searchMatchIndexes = null,
|
||||
onSelectedIndexChange,
|
||||
onRecordSelect,
|
||||
recordSelection = null,
|
||||
onClearSelection,
|
||||
collapsedTurns,
|
||||
onToggleTurn,
|
||||
@@ -1412,15 +1507,16 @@ export function TrajectoryTable({
|
||||
const [selectedIndex, setSelectedIndex] = useState<number | null>(null)
|
||||
const [selectedRequest, setSelectedRequest] = useState<SelectedRequest | null>(null)
|
||||
const [activeTab, setActiveTab] = useState<DetailTab>('overview')
|
||||
const [thinkingExpanded, setThinkingExpanded] = useState(true)
|
||||
const [thinkingExpanded, setThinkingExpanded] = useState(false)
|
||||
const [detailsWidth, setDetailsWidth] = useState<number | null>(null)
|
||||
const [toolRequestOffset, setToolRequestOffset] = useState<number | null>(null)
|
||||
const detailsResizeDrag = useRef<DetailsResizeDrag | null>(null)
|
||||
const appliedRecordSelection = useRef<TrajectoryTableProps['recordSelection']>(null)
|
||||
const tabHistory = useRef<Set<DetailTab>>(new Set(['overview']))
|
||||
useEffect(() => {
|
||||
onSelectedIndexChange?.(selectedIndex)
|
||||
}, [onSelectedIndexChange, selectedIndex])
|
||||
const allRecords = flattenRecords(turns)
|
||||
const allRecords = useMemo(() => flattenRecords(turns), [turns])
|
||||
const requestNumbers = indexRequestNumbers(allRecords, sessionRequestNumbers)
|
||||
const records = searchMatchIndexes === null
|
||||
? collapseAssistantRecords(
|
||||
@@ -1537,7 +1633,7 @@ export function TrajectoryTable({
|
||||
onClearSelection?.()
|
||||
}
|
||||
|
||||
const selectRecord = (index: number) => {
|
||||
const selectRecord = useCallback((index: number) => {
|
||||
const record = allRecords.find(candidate => candidate.cell.index === index)
|
||||
onRecordSelect?.(index)
|
||||
setSelectedRequest(null)
|
||||
@@ -1547,7 +1643,15 @@ export function TrajectoryTable({
|
||||
const available = new Set(tabs.map(tab => tab.id))
|
||||
const recent = [...tabHistory.current].reverse().find(tab => available.has(tab))
|
||||
setActiveTab(recent ?? tabs[0]?.id ?? 'overview')
|
||||
}
|
||||
}, [allRecords, onRecordSelect])
|
||||
useEffect(() => {
|
||||
if (
|
||||
recordSelection === null
|
||||
|| appliedRecordSelection.current === recordSelection
|
||||
) return
|
||||
appliedRecordSelection.current = recordSelection
|
||||
selectRecord(recordSelection.index)
|
||||
}, [recordSelection, selectRecord])
|
||||
|
||||
const selectRequest = (
|
||||
request: SelectedRequest,
|
||||
@@ -1749,8 +1853,14 @@ export function TrajectoryTable({
|
||||
className={activeTurn === record.turn
|
||||
? `${css.turnLabel} ${css.turnLabelActive}`
|
||||
: css.turnLabel}
|
||||
aria-label={`Turn ${record.turn}`}
|
||||
>
|
||||
Turn {record.turn}
|
||||
<span className={css.turnLabelFull} aria-hidden="true">
|
||||
Turn {record.turn}
|
||||
</span>
|
||||
<span className={css.turnLabelCompact} aria-hidden="true">
|
||||
#{record.turn}
|
||||
</span>
|
||||
</span>
|
||||
)}
|
||||
<div className={css.eventInner}>
|
||||
@@ -1758,24 +1868,33 @@ export function TrajectoryTable({
|
||||
<span
|
||||
className={css.kindSlot}
|
||||
>
|
||||
<span className={`${css.kindTag} ${
|
||||
record.cell.kind === 'system'
|
||||
? css.systemNeutral
|
||||
: record.cell.kind === 'context'
|
||||
? css.contextGreen
|
||||
: record.cell.kind === 'compacted'
|
||||
? css.compacted
|
||||
: record.cell.kind === 'tool'
|
||||
? css.toolAmber
|
||||
: record.cell.kind === 'message'
|
||||
? css.assistantVioletBright
|
||||
: record.cell.kind === 'subtool'
|
||||
? css.subtoolAmber
|
||||
: css[record.cell.kind]
|
||||
}`}
|
||||
>
|
||||
{KIND_LABEL[record.cell.kind]}
|
||||
</span>
|
||||
<Tooltip label={KIND_LABEL[record.cell.kind]} side="bottom">
|
||||
<span
|
||||
className={`${css.kindTag} ${
|
||||
record.cell.kind === 'system'
|
||||
? css.systemNeutral
|
||||
: record.cell.kind === 'context'
|
||||
? css.contextGreen
|
||||
: record.cell.kind === 'compacted'
|
||||
? css.compacted
|
||||
: record.cell.kind === 'tool'
|
||||
? css.toolAmber
|
||||
: record.cell.kind === 'message'
|
||||
? css.assistantVioletBright
|
||||
: record.cell.kind === 'subtool'
|
||||
? css.subtoolAmber
|
||||
: css[record.cell.kind]
|
||||
}`}
|
||||
data-role-kind={record.cell.kind}
|
||||
>
|
||||
<span className={css.kindTagIcon} aria-hidden="true">
|
||||
{KIND_ICON[record.cell.kind]}
|
||||
</span>
|
||||
<span className={css.kindTagLabel}>
|
||||
{KIND_LABEL[record.cell.kind]}
|
||||
</span>
|
||||
</span>
|
||||
</Tooltip>
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
@@ -2008,7 +2127,9 @@ export function TrajectoryTable({
|
||||
<dl className={css.overview}>
|
||||
<div>
|
||||
<dt>Status</dt>
|
||||
<dd>{statusLabel(selectedRequestState)}</dd>
|
||||
<dd className={selectedRequestState === 'error' ? css.error : undefined}>
|
||||
{statusLabel(selectedRequestState)}
|
||||
</dd>
|
||||
</div>
|
||||
{selectedRequestInfo?.purpose === 'compaction' && (
|
||||
<div>
|
||||
@@ -2049,7 +2170,7 @@ export function TrajectoryTable({
|
||||
{selectedRequestInfo?.error !== undefined && (
|
||||
<div>
|
||||
<dt>Error</dt>
|
||||
<dd>{selectedRequestInfo.error}</dd>
|
||||
<dd className={css.error}>{selectedRequestInfo.error}</dd>
|
||||
</div>
|
||||
)}
|
||||
{selectedRequestInfo?.retry !== undefined && (
|
||||
@@ -2157,7 +2278,9 @@ export function TrajectoryTable({
|
||||
<dl className={css.overview}>
|
||||
<div>
|
||||
<dt>Status</dt>
|
||||
<dd>{statusLabel(selectedState)}</dd>
|
||||
<dd className={selectedState === 'error' ? css.error : undefined}>
|
||||
{statusLabel(selectedState)}
|
||||
</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Duration</dt>
|
||||
@@ -2260,7 +2383,9 @@ export function TrajectoryTable({
|
||||
)}
|
||||
<div>
|
||||
<dt>Status</dt>
|
||||
<dd>{statusLabel(selectedState)}</dd>
|
||||
<dd className={selectedState === 'error' ? css.error : undefined}>
|
||||
{statusLabel(selectedState)}
|
||||
</dd>
|
||||
</div>
|
||||
{selected.cell.kind === 'message' && (
|
||||
<TokenRows cell={selected.cell} />
|
||||
|
||||
@@ -70,16 +70,29 @@
|
||||
.lanes {
|
||||
position: absolute;
|
||||
z-index: 2;
|
||||
inset: 7px 0;
|
||||
top: 7px;
|
||||
bottom: 7px;
|
||||
left: var(--trajectory-domain-left);
|
||||
width: var(--trajectory-domain-width);
|
||||
}
|
||||
|
||||
.turnBoundaries {
|
||||
position: absolute;
|
||||
z-index: 3;
|
||||
inset: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: var(--trajectory-domain-left);
|
||||
width: var(--trajectory-domain-width);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: no-preference) {
|
||||
.lanes[data-animate-viewport='true'],
|
||||
.turnBoundaries[data-animate-viewport='true'] {
|
||||
transition: left 180ms ease-out;
|
||||
}
|
||||
}
|
||||
|
||||
.turnBoundary {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
@@ -133,6 +146,10 @@
|
||||
);
|
||||
}
|
||||
|
||||
.span[data-error='true'] {
|
||||
background: var(--dsw-alias-state-error-primary);
|
||||
}
|
||||
|
||||
.span[data-equal-duration='true'] {
|
||||
width: 8px;
|
||||
min-width: 8px;
|
||||
@@ -142,6 +159,18 @@
|
||||
opacity: 0.2;
|
||||
}
|
||||
|
||||
.span[data-hovered='true']:not([data-current='true']) {
|
||||
z-index: 1;
|
||||
opacity: 0.78;
|
||||
box-shadow:
|
||||
0 0 0 1px var(--dsw-alias-bg-layer-2),
|
||||
0 0 0 2px color-mix(
|
||||
in srgb,
|
||||
var(--dsw-alias-state-business-primary) 80%,
|
||||
transparent
|
||||
);
|
||||
}
|
||||
|
||||
.span[data-current='true'] {
|
||||
z-index: 1;
|
||||
opacity: 1;
|
||||
|
||||
@@ -15,12 +15,20 @@ import css from './TrajectoryTimeline.module.css'
|
||||
|
||||
const MINIMUM_DRAG_PX = 3
|
||||
const MINIMUM_ZOOM_OPERATIONS = 4
|
||||
const EDGE_PAN_ZONE_FRACTION = 0.08
|
||||
const EDGE_PAN_STEP_FRACTION = 0.025
|
||||
const MAXIMUM_EDGE_PAN_PX = 32
|
||||
|
||||
interface FractionRange {
|
||||
start: number
|
||||
end: number
|
||||
}
|
||||
|
||||
interface HoverPoint {
|
||||
fraction: number
|
||||
recordIndex: number | null
|
||||
}
|
||||
|
||||
/** Props for the fixed full-domain overview above the trajectory ledger. */
|
||||
export interface TrajectoryTimelineProps {
|
||||
turns: readonly TrajectoryTurnModel[]
|
||||
@@ -30,6 +38,9 @@ export interface TrajectoryTimelineProps {
|
||||
/** Record indexes matching the active ledger search, or null without a query. */
|
||||
searchMatchIndexes?: ReadonlySet<number> | null
|
||||
onRangeChange: (range: TrajectoryTimeRange | null) => void
|
||||
/** Select a directly clicked timeline block. */
|
||||
onRecordSelect?: (index: number) => void
|
||||
/** Bring the nearest record into view after clicking timeline whitespace. */
|
||||
onRecordFocus?: (index: number) => void
|
||||
}
|
||||
|
||||
@@ -41,11 +52,16 @@ function clampFraction(value: number): number {
|
||||
return Math.min(1, Math.max(0, value))
|
||||
}
|
||||
|
||||
function centeredRange(center: number, width: number): FractionRange {
|
||||
const clampedWidth = Math.min(1, Math.max(0, width))
|
||||
function centeredRange(
|
||||
center: number,
|
||||
width: number,
|
||||
minimum: number,
|
||||
maximum: number,
|
||||
): FractionRange {
|
||||
const clampedWidth = Math.min(maximum - minimum, Math.max(0, width))
|
||||
const start = Math.min(
|
||||
Math.max(center - clampedWidth / 2, 0),
|
||||
1 - clampedWidth,
|
||||
Math.max(center - clampedWidth / 2, minimum),
|
||||
maximum - clampedWidth,
|
||||
)
|
||||
return { start, end: start + clampedWidth }
|
||||
}
|
||||
@@ -79,6 +95,7 @@ export const TrajectoryTimeline = memo(function TrajectoryTimeline({
|
||||
selectedIndex = null,
|
||||
searchMatchIndexes = null,
|
||||
onRangeChange,
|
||||
onRecordSelect,
|
||||
onRecordFocus,
|
||||
}: TrajectoryTimelineProps) {
|
||||
const model = useMemo(() => deriveTrajectoryTimeline(turns, mode), [mode, turns])
|
||||
@@ -94,10 +111,16 @@ export const TrajectoryTimeline = memo(function TrajectoryTimeline({
|
||||
)),
|
||||
[turns],
|
||||
)
|
||||
const dragRef = useRef<{ pointerId: number; anchor: number; width: number } | null>(null)
|
||||
const [draft, setDraft] = useState<FractionRange | null>(null)
|
||||
const [hover, setHover] = useState<number | null>(null)
|
||||
const dragRef = useRef<{
|
||||
pointerId: number
|
||||
anchorTime: number
|
||||
anchorClientX: number
|
||||
recordIndex: number | null
|
||||
} | null>(null)
|
||||
const [draft, setDraft] = useState<TrajectoryTimeRange | null>(null)
|
||||
const [hover, setHover] = useState<HoverPoint | null>(null)
|
||||
const [viewport, setViewport] = useState<TrajectoryTimeRange | null>(null)
|
||||
const [animateViewport, setAnimateViewport] = useState(false)
|
||||
useEffect(() => {
|
||||
if (
|
||||
model !== null
|
||||
@@ -109,11 +132,35 @@ export const TrajectoryTimeline = memo(function TrajectoryTimeline({
|
||||
}, [model, onRangeChange, range])
|
||||
useEffect(() => {
|
||||
if (model === null) return
|
||||
setAnimateViewport(false)
|
||||
setViewport(current =>
|
||||
current !== null && (current.end < model.start || current.start > model.end)
|
||||
? null
|
||||
: current)
|
||||
}, [model])
|
||||
useEffect(() => {
|
||||
if (model === null || selectedIndex === null) return
|
||||
const selectedSpan = model.spans.find(span => span.index === selectedIndex)
|
||||
if (selectedSpan === undefined) return
|
||||
setAnimateViewport(true)
|
||||
setViewport((current) => {
|
||||
if (current === null) return current
|
||||
if (
|
||||
selectedSpan.end > current.start
|
||||
&& selectedSpan.start < current.end
|
||||
) return current
|
||||
const duration = Math.max(1, current.end - current.start)
|
||||
const desiredStart = selectedSpan.end <= current.start
|
||||
? selectedSpan.start
|
||||
: selectedSpan.end - duration
|
||||
const nextStart = Math.min(
|
||||
Math.max(desiredStart, model.start),
|
||||
Math.max(model.start, model.end - duration),
|
||||
)
|
||||
if (nextStart === current.start) return current
|
||||
return { start: nextStart, end: nextStart + duration }
|
||||
})
|
||||
}, [model, selectedIndex])
|
||||
const fullDuration = Math.max(1, (model?.end ?? 0) - (model?.start ?? 0))
|
||||
const viewportDuration = Math.min(
|
||||
fullDuration,
|
||||
@@ -127,16 +174,21 @@ export const TrajectoryTimeline = memo(function TrajectoryTimeline({
|
||||
)
|
||||
const domainDuration = viewport === null ? fullDuration : viewportDuration
|
||||
const domainStart = viewport === null ? model?.start ?? 0 : viewportStart
|
||||
const projectedDomainStyle = model === null
|
||||
? undefined
|
||||
: {
|
||||
'--trajectory-domain-left':
|
||||
`${-(domainStart - model.start) / domainDuration * 100}%`,
|
||||
'--trajectory-domain-width': `${fullDuration / domainDuration * 100}%`,
|
||||
} as CSSProperties
|
||||
const committed = model === null || range === null
|
||||
? null
|
||||
: rangeFraction(range, domainStart, domainDuration)
|
||||
const visibleRange = draft ?? committed
|
||||
const activeRange = draft === null
|
||||
? range
|
||||
: {
|
||||
start: domainStart + draft.start * domainDuration,
|
||||
end: domainStart + draft.end * domainDuration,
|
||||
}
|
||||
const draftFraction = model === null || draft === null
|
||||
? null
|
||||
: rangeFraction(draft, domainStart, domainDuration)
|
||||
const visibleRange = draftFraction ?? committed
|
||||
const activeRange = draft ?? range
|
||||
|
||||
if (model === null) {
|
||||
return (
|
||||
@@ -151,9 +203,9 @@ export const TrajectoryTimeline = memo(function TrajectoryTimeline({
|
||||
)
|
||||
}
|
||||
|
||||
const minimumSelectionFraction = Math.min(
|
||||
1,
|
||||
fullDuration / domainDuration / model.spans.length,
|
||||
const minimumSelectionDuration = Math.min(
|
||||
domainDuration,
|
||||
fullDuration / model.spans.length,
|
||||
)
|
||||
|
||||
const fractionAt = (event: PointerEvent<HTMLDivElement>): number => {
|
||||
@@ -161,51 +213,107 @@ export const TrajectoryTimeline = memo(function TrajectoryTimeline({
|
||||
return clampFraction((event.clientX - rect.left) / Math.max(1, rect.width))
|
||||
}
|
||||
|
||||
const commit = (fraction: FractionRange) => {
|
||||
onRangeChange({
|
||||
start: domainStart + fraction.start * domainDuration,
|
||||
end: domainStart + fraction.end * domainDuration,
|
||||
})
|
||||
const recordIndexAt = (event: PointerEvent<HTMLDivElement>): number | null => {
|
||||
const target = event.target instanceof HTMLElement ? event.target : null
|
||||
const value = target?.closest<HTMLElement>('[data-timeline-record-index]')
|
||||
?.dataset.timelineRecordIndex
|
||||
if (value === undefined) return null
|
||||
const index = Number(value)
|
||||
return Number.isFinite(index) ? index : null
|
||||
}
|
||||
|
||||
const commit = (nextRange: TrajectoryTimeRange) => {
|
||||
onRangeChange(nextRange)
|
||||
}
|
||||
|
||||
const onPointerDown = (event: PointerEvent<HTMLDivElement>) => {
|
||||
if (event.button !== 0) return
|
||||
const rect = event.currentTarget.getBoundingClientRect()
|
||||
const anchor = fractionAt(event)
|
||||
setHover(anchor)
|
||||
dragRef.current = { pointerId: event.pointerId, anchor, width: Math.max(1, rect.width) }
|
||||
const anchorTime = domainStart + anchor * domainDuration
|
||||
const recordIndex = recordIndexAt(event)
|
||||
setHover({ fraction: anchor, recordIndex })
|
||||
dragRef.current = {
|
||||
pointerId: event.pointerId,
|
||||
anchorTime,
|
||||
anchorClientX: event.clientX,
|
||||
recordIndex,
|
||||
}
|
||||
if (typeof event.currentTarget.setPointerCapture === 'function') {
|
||||
event.currentTarget.setPointerCapture(event.pointerId)
|
||||
}
|
||||
setDraft({ start: anchor, end: anchor })
|
||||
setDraft({ start: anchorTime, end: anchorTime })
|
||||
}
|
||||
|
||||
const onPointerMove = (event: PointerEvent<HTMLDivElement>) => {
|
||||
const drag = dragRef.current
|
||||
const rect = event.currentTarget.getBoundingClientRect()
|
||||
const fraction = fractionAt(event)
|
||||
setHover(fraction)
|
||||
setHover({ fraction, recordIndex: recordIndexAt(event) })
|
||||
if (drag === null || drag.pointerId !== event.pointerId) return
|
||||
setDraft(orderedRange(drag.anchor, fraction))
|
||||
let nextDomainStart = domainStart
|
||||
if (viewport !== null) {
|
||||
const localX = event.clientX - rect.left
|
||||
const edgeWidth = Math.min(
|
||||
MAXIMUM_EDGE_PAN_PX,
|
||||
Math.max(1, rect.width * EDGE_PAN_ZONE_FRACTION),
|
||||
)
|
||||
const direction = localX < edgeWidth
|
||||
? -1
|
||||
: localX > rect.width - edgeWidth ? 1 : 0
|
||||
if (direction !== 0) {
|
||||
const edgeDistance = direction < 0
|
||||
? edgeWidth - localX
|
||||
: localX - (rect.width - edgeWidth)
|
||||
const strength = clampFraction(edgeDistance / edgeWidth)
|
||||
const desiredStart = domainStart
|
||||
+ direction * domainDuration * EDGE_PAN_STEP_FRACTION
|
||||
* Math.max(0.2, strength)
|
||||
nextDomainStart = Math.min(
|
||||
Math.max(desiredStart, model.start),
|
||||
model.end - domainDuration,
|
||||
)
|
||||
if (nextDomainStart !== domainStart) {
|
||||
setAnimateViewport(false)
|
||||
setViewport({
|
||||
start: nextDomainStart,
|
||||
end: nextDomainStart + domainDuration,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
const pointTime = nextDomainStart + fraction * domainDuration
|
||||
setDraft(orderedRange(drag.anchorTime, pointTime))
|
||||
}
|
||||
|
||||
const onPointerEnd = (event: PointerEvent<HTMLDivElement>) => {
|
||||
const drag = dragRef.current
|
||||
if (drag === null || drag.pointerId !== event.pointerId) return
|
||||
const point = fractionAt(event)
|
||||
const selected = orderedRange(drag.anchor, point)
|
||||
setHover(point)
|
||||
const pointFraction = fractionAt(event)
|
||||
const pointTime = domainStart + pointFraction * domainDuration
|
||||
const selected = orderedRange(drag.anchorTime, pointTime)
|
||||
setHover({ fraction: pointFraction, recordIndex: recordIndexAt(event) })
|
||||
dragRef.current = null
|
||||
setDraft(null)
|
||||
const click = (selected.end - selected.start) * drag.width < MINIMUM_DRAG_PX
|
||||
const committedRange = selected.end - selected.start < minimumSelectionFraction
|
||||
const click = Math.abs(event.clientX - drag.anchorClientX) < MINIMUM_DRAG_PX
|
||||
const clickedSpan = click && drag.recordIndex !== null
|
||||
? model.spans.find(span => span.index === drag.recordIndex)
|
||||
: undefined
|
||||
if (clickedSpan !== undefined) {
|
||||
onRangeChange(null)
|
||||
onRecordSelect?.(clickedSpan.index)
|
||||
return
|
||||
}
|
||||
const committedRange = selected.end - selected.start < minimumSelectionDuration
|
||||
? centeredRange(
|
||||
click ? selected.start : (selected.start + selected.end) / 2,
|
||||
minimumSelectionFraction,
|
||||
minimumSelectionDuration,
|
||||
model.start,
|
||||
model.end,
|
||||
)
|
||||
: selected
|
||||
commit(committedRange)
|
||||
if (click) {
|
||||
const timelinePoint = domainStart + selected.start * domainDuration
|
||||
const timelinePoint = selected.start
|
||||
const nearest = model.spans.reduce((candidate, span) => {
|
||||
const candidateDistance = timelinePoint < candidate.start
|
||||
? candidate.start - timelinePoint
|
||||
@@ -233,6 +341,7 @@ export const TrajectoryTimeline = memo(function TrajectoryTimeline({
|
||||
|
||||
const onWheel = (event: WheelEvent<HTMLDivElement>) => {
|
||||
event.preventDefault()
|
||||
setAnimateViewport(false)
|
||||
const rect = event.currentTarget.getBoundingClientRect()
|
||||
const anchorFraction =
|
||||
clampFraction((event.clientX - rect.left) / Math.max(1, rect.width))
|
||||
@@ -278,16 +387,18 @@ export const TrajectoryTimeline = memo(function TrajectoryTimeline({
|
||||
onWheel={onWheel}
|
||||
onContextMenu={(event) => {
|
||||
event.preventDefault()
|
||||
setAnimateViewport(false)
|
||||
onRangeChange(null)
|
||||
setViewport(null)
|
||||
}}
|
||||
>
|
||||
{hover !== null && draft === null && (
|
||||
{hover !== null && hover.recordIndex === null && draft === null && (
|
||||
<div
|
||||
className={css.hoverLine}
|
||||
data-timeline-hover-line
|
||||
aria-hidden="true"
|
||||
style={{
|
||||
'--trajectory-hover-left': `${hover * 100}%`,
|
||||
'--trajectory-hover-left': `${hover.fraction * 100}%`,
|
||||
} as CSSProperties}
|
||||
/>
|
||||
)}
|
||||
@@ -313,7 +424,12 @@ export const TrajectoryTimeline = memo(function TrajectoryTimeline({
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
<div className={css.turnBoundaries} aria-hidden="true">
|
||||
<div
|
||||
className={css.turnBoundaries}
|
||||
data-animate-viewport={animateViewport || undefined}
|
||||
aria-hidden="true"
|
||||
style={projectedDomainStyle}
|
||||
>
|
||||
{model.turnBoundaries
|
||||
.slice(1)
|
||||
.filter(boundary =>
|
||||
@@ -326,24 +442,35 @@ export const TrajectoryTimeline = memo(function TrajectoryTimeline({
|
||||
key={boundary.turn}
|
||||
style={{
|
||||
'--trajectory-turn-left':
|
||||
`${(boundary.time - domainStart) / domainDuration * 100}%`,
|
||||
`${(boundary.time - model.start) / fullDuration * 100}%`,
|
||||
} as CSSProperties}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<div className={css.lanes} aria-hidden="true">
|
||||
<div
|
||||
className={css.lanes}
|
||||
data-animate-viewport={animateViewport || undefined}
|
||||
data-timeline-domain
|
||||
aria-hidden="true"
|
||||
style={projectedDomainStyle}
|
||||
>
|
||||
{model.spans
|
||||
.filter(span => span.end >= domainStart && span.start <= domainStart + domainDuration)
|
||||
.filter(span =>
|
||||
span.index === selectedIndex
|
||||
|| (span.end >= domainStart && span.start <= domainStart + domainDuration))
|
||||
.map((span) => {
|
||||
const left = (span.start - domainStart) / domainDuration
|
||||
const width = (span.end - span.start) / domainDuration
|
||||
const left = (span.start - model.start) / fullDuration
|
||||
const width = (span.end - span.start) / fullDuration
|
||||
const durationMs = durationByIndex.get(span.index)
|
||||
return (
|
||||
<span
|
||||
className={css.span}
|
||||
data-timeline-span={span.kind}
|
||||
data-timeline-record-index={span.index}
|
||||
data-error={span.isError || undefined}
|
||||
data-equal-duration={mode === 'time' || undefined}
|
||||
data-current={span.index === selectedIndex || undefined}
|
||||
data-hovered={hover?.recordIndex === span.index || undefined}
|
||||
data-search-match={searchMatchIndexes === null
|
||||
? undefined
|
||||
: searchMatchIndexes.has(span.index) ? 'true' : 'false'}
|
||||
|
||||
@@ -147,6 +147,9 @@ export function TrajectoryView({
|
||||
const [actualTime, setActualTime] = useState(false)
|
||||
const [searchQuery, setSearchQuery] = useState('')
|
||||
const [selectedTimelineIndex, setSelectedTimelineIndex] = useState<number | null>(null)
|
||||
const [timelineRecordSelection, setTimelineRecordSelection] = useState<{
|
||||
readonly index: number
|
||||
} | null>(null)
|
||||
const ledgerRef = useRef<HTMLDivElement>(null)
|
||||
const inspection = useHistory(snapshot => snapshot.inspection)
|
||||
const nodes = inspection.eventNodes
|
||||
@@ -478,7 +481,20 @@ export function TrajectoryView({
|
||||
selectedIndex={selectedTimelineIndex}
|
||||
searchMatchIndexes={searchMatchIndexes}
|
||||
onRangeChange={(range) => {
|
||||
setTimelineSelection(range === null ? null : { branchId: currentBranch.id, range })
|
||||
setTimelineSelection(range === null ? null : {
|
||||
branchId: currentBranch.id,
|
||||
range,
|
||||
})
|
||||
}}
|
||||
onRecordSelect={(index) => {
|
||||
setTimelineSelection(null)
|
||||
setTimelineRecordSelection({ index })
|
||||
setSelectedTimelineIndex(index)
|
||||
const row = ledgerRef.current
|
||||
?.querySelector<HTMLElement>(`tr[data-record-index="${index}"]`)
|
||||
if (row !== undefined && row !== null && typeof row.scrollIntoView === 'function') {
|
||||
row.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
||||
}
|
||||
}}
|
||||
onRecordFocus={(index) => {
|
||||
const row = ledgerRef.current
|
||||
@@ -497,6 +513,7 @@ export function TrajectoryView({
|
||||
searchMatchIndexes={searchMatchIndexes}
|
||||
onSelectedIndexChange={setSelectedTimelineIndex}
|
||||
onRecordSelect={handleRecordSelect}
|
||||
recordSelection={timelineRecordSelection}
|
||||
onClearSelection={() => { setTimelineSelection(null) }}
|
||||
collapsedTurns={collapsedTurns}
|
||||
onToggleTurn={toggleTurn}
|
||||
|
||||
@@ -12,6 +12,7 @@ import type {
|
||||
RequestView,
|
||||
ToolResultNode,
|
||||
} from '@deepseek-ai/dsh-client-runtime/client'
|
||||
import { extractMarkdownPlainText } from '@deepseek-ai/dsh-client-ui-primitives'
|
||||
import type {
|
||||
TrajectoryCellProps,
|
||||
TrajectorySourceBlock,
|
||||
@@ -66,6 +67,9 @@ interface TurnBucket {
|
||||
groups: LaidGroup[]
|
||||
}
|
||||
|
||||
const PREVIEW_SOURCE_CHARACTERS = 2_048
|
||||
const PREVIEW_OUTPUT_CHARACTERS = 512
|
||||
|
||||
type InputNode = Extract<
|
||||
ConversationSnapshot['nodes'][number],
|
||||
{ kind: 'user' | 'steering' | 'context' }
|
||||
@@ -126,6 +130,7 @@ export function deriveTrajectoryLayout(input: TrajectoryLayoutInput): readonly T
|
||||
nodes, partial, runningCalls, requests = [], callSchemas, codeDispatches,
|
||||
} = input
|
||||
const resultByCall = indexResults(nodes)
|
||||
const emittedCallIds = indexAssistantCallIds(nodes)
|
||||
const callStartById = new Map<string, number>()
|
||||
for (const result of resultByCall.values()) {
|
||||
const startedAt = finiteTime(result.callTime)
|
||||
@@ -353,7 +358,7 @@ export function deriveTrajectoryLayout(input: TrajectoryLayoutInput): readonly T
|
||||
continue
|
||||
}
|
||||
if (node.kind === 'tool-result') {
|
||||
if (!callEmittedInAssistant(nodes, node.callId)) {
|
||||
if (!emittedCallIds.has(node.callId)) {
|
||||
const toolName = node.call?.name
|
||||
const laidList: LaidCell[] = [{
|
||||
absTime: finiteTime(node.callTime ?? node.time),
|
||||
@@ -764,12 +769,15 @@ function indexResults(nodes: ConversationSnapshot['nodes']): Map<string, ToolRes
|
||||
return map
|
||||
}
|
||||
|
||||
function callEmittedInAssistant(nodes: ConversationSnapshot['nodes'], callId: string): boolean {
|
||||
function indexAssistantCallIds(nodes: ConversationSnapshot['nodes']): ReadonlySet<string> {
|
||||
const ids = new Set<string>()
|
||||
for (const node of nodes) {
|
||||
if (node.kind !== 'assistant') continue
|
||||
if (node.blocks.some(b => b.kind === 'tool-call' && b.callId === callId)) return true
|
||||
for (const block of node.blocks) {
|
||||
if (block.kind === 'tool-call') ids.add(block.callId)
|
||||
}
|
||||
}
|
||||
return false
|
||||
return ids
|
||||
}
|
||||
|
||||
function collectCallIds(
|
||||
@@ -849,7 +857,7 @@ function expandSubCalls(
|
||||
}
|
||||
|
||||
function summarizeCall(name: string, argsRaw: string): string {
|
||||
const args = argsRaw.replace(/\s+/g, ' ').trim()
|
||||
const args = trajectoryPreviewText(argsRaw)
|
||||
if (args === '') return name
|
||||
return `${name} · ${args}`
|
||||
}
|
||||
@@ -907,5 +915,20 @@ function summarizeContent(content: readonly { type: string; text?: string }[]):
|
||||
}
|
||||
|
||||
function summarizeText(text: string): string {
|
||||
return text.replace(/\s+/g, ' ').trim()
|
||||
return trajectoryPreviewText(text)
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a bounded one-line ledger preview without parsing the complete Markdown document.
|
||||
* Full source remains on the cell for the inspector.
|
||||
* @param text - Untrusted message, reasoning, payload, or result text.
|
||||
* @returns A compact preview capped independently from the retained source.
|
||||
*/
|
||||
export function trajectoryPreviewText(text: string): string {
|
||||
const source = text.slice(0, PREVIEW_SOURCE_CHARACTERS)
|
||||
const compact = extractMarkdownPlainText(source).replace(/\s+/g, ' ').trim()
|
||||
const preview = compact.slice(0, PREVIEW_OUTPUT_CHARACTERS).trimEnd()
|
||||
return source.length < text.length || preview.length < compact.length
|
||||
? `${preview}…`
|
||||
: preview
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ export interface TrajectoryTimeRange {
|
||||
/** One ledger record projected into the active timeline domain. */
|
||||
export interface TrajectoryTimelineSpan extends TrajectoryTimeRange {
|
||||
index: number
|
||||
isError: boolean
|
||||
kind: TrajectoryCellKind
|
||||
label: string
|
||||
lane: number
|
||||
@@ -94,6 +95,7 @@ export function deriveTrajectoryTimeline(
|
||||
start: spans.length + offset,
|
||||
end: spans.length + offset + 1,
|
||||
index: cell.index,
|
||||
isError: cell.isError === true,
|
||||
kind: cell.kind,
|
||||
label: cell.text,
|
||||
lane: laneFor(cell.kind),
|
||||
@@ -129,6 +131,7 @@ function deriveTimedTimeline(
|
||||
: [{
|
||||
...range,
|
||||
index: cell.index,
|
||||
isError: cell.isError === true,
|
||||
kind: cell.kind,
|
||||
label: cell.text,
|
||||
lane: laneFor(cell.kind),
|
||||
|
||||
@@ -176,6 +176,25 @@ describe('deriveTrajectoryLayout', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('bounds a long Markdown-like thinking preview while retaining its full detail', () => {
|
||||
const thinking = `# Investigation\n\n**NAVIGATION_OK file_path** ${'- repeated detail '.repeat(1_000)}`
|
||||
const nodes = [{
|
||||
kind: 'assistant', seq: 1, time: 5_000, turn: 1, step: 0,
|
||||
blocks: [{ kind: 'reasoning', text: thinking }],
|
||||
}] as unknown as ConversationSnapshot['nodes']
|
||||
|
||||
const turns = deriveTrajectoryLayout({
|
||||
codeDispatches: new Map(), nodes, partial: null, runningCalls: [],
|
||||
})
|
||||
const message = turns[0]?.groups.flatMap(group => group.cells)
|
||||
.find(cell => cell.kind === 'message')
|
||||
|
||||
expect(message?.text.startsWith('Investigation NAVIGATION_OK file_path')).toBe(true)
|
||||
expect(message?.text.endsWith('…')).toBe(true)
|
||||
expect(message?.text.length).toBeLessThanOrEqual(513)
|
||||
expect(message?.thinkingDetail).toBe(thinking)
|
||||
})
|
||||
|
||||
it('advances the duration cursor over context nodes', () => {
|
||||
const nodes = [
|
||||
{ kind: 'user', seq: 1, time: 1_000, content: [{ type: 'text', text: 'hi' }], source: null },
|
||||
|
||||
@@ -83,6 +83,31 @@ describe('TrajectoryTable', () => {
|
||||
expect(screen.getByText('15 tok')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('keeps long thinking collapsed until the user asks to render it', () => {
|
||||
const thinking = 'private chain '.repeat(1_000)
|
||||
const turns: readonly TrajectoryTurnModel[] = [{
|
||||
turn: 1,
|
||||
groups: [{
|
||||
title: 'Step 1',
|
||||
cells: [{
|
||||
index: 1,
|
||||
kind: 'message',
|
||||
text: 'private chain…',
|
||||
thinkingDetail: thinking,
|
||||
timeSeconds: 1,
|
||||
}],
|
||||
}],
|
||||
}]
|
||||
render(<TrajectoryTable turns={turns} {...FOLD_PROPS} />)
|
||||
|
||||
fireEvent.click(screen.getByRole('row', { name: /ASSISTANT/ }))
|
||||
const toggle = screen.getByRole('button', { name: 'Thinking ...' })
|
||||
expect(screen.queryByText(thinking)).toBeNull()
|
||||
|
||||
fireEvent.click(toggle)
|
||||
expect(toggle.parentElement?.textContent?.length).toBeGreaterThan(thinking.length)
|
||||
})
|
||||
|
||||
it('keeps raw HTML tags in a Markdown-derived context preview', () => {
|
||||
const html = [
|
||||
'<background-task-complete id="trajectory-ui-watch">',
|
||||
@@ -144,8 +169,53 @@ describe('TrajectoryTable', () => {
|
||||
expect(screen.getByText('Pending')).toBeTruthy()
|
||||
fireEvent.click(screen.getByRole('row', { name: /TOOL, bash \{"command":"false"\}/ }))
|
||||
expect(screen.getByText('Failed')).toBeTruthy()
|
||||
expect(screen.getByText('Failed').className).toContain('error')
|
||||
fireEvent.click(screen.getByRole('tab', { name: 'Result' }))
|
||||
expect(screen.getByText('ToolError: non_zero_exit')).toBeTruthy()
|
||||
const errorResult = screen.getByText('ToolError: non_zero_exit')
|
||||
expect(errorResult.closest('[class*="errorPayload"]')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('renders responsive role icons with a custom tooltip', () => {
|
||||
const view = render(<TrajectoryTable turns={TURNS} {...FOLD_PROPS} />)
|
||||
const toolTag = view.container.querySelector<HTMLElement>('[data-role-kind="tool"]')
|
||||
|
||||
expect(toolTag).not.toBeNull()
|
||||
expect(toolTag?.getAttribute('title')).toBeNull()
|
||||
expect(toolTag?.querySelector('[data-role-icon="wrench"]')).toBeTruthy()
|
||||
|
||||
fireEvent.mouseEnter(toolTag as HTMLElement)
|
||||
expect(screen.getByRole('tooltip').textContent).toBe('TOOL')
|
||||
fireEvent.mouseLeave(toolTag as HTMLElement)
|
||||
expect(screen.queryByRole('tooltip')).toBeNull()
|
||||
})
|
||||
|
||||
it('uses information and compression glyphs for injected and compacted context', () => {
|
||||
const turns: readonly TrajectoryTurnModel[] = [{
|
||||
turn: 1,
|
||||
groups: [{
|
||||
title: 'Context',
|
||||
cells: [
|
||||
{ index: 1, kind: 'context', text: 'Workspace context', timeSeconds: 0 },
|
||||
{ index: 2, kind: 'compacted', text: 'Compacted history', timeSeconds: 0 },
|
||||
],
|
||||
}],
|
||||
}]
|
||||
const view = render(<TrajectoryTable turns={turns} {...FOLD_PROPS} />)
|
||||
|
||||
expect(view.container.querySelector(
|
||||
'[data-role-kind="context"] [data-role-icon="information"]',
|
||||
)).toBeTruthy()
|
||||
expect(view.container.querySelector(
|
||||
'[data-role-kind="compacted"] [data-role-icon="compacted"]',
|
||||
)).toBeTruthy()
|
||||
})
|
||||
|
||||
it('keeps a compact turn label available for narrow layouts', () => {
|
||||
render(<TrajectoryTable turns={TURNS} {...FOLD_PROPS} />)
|
||||
const turnLabel = screen.getByLabelText('Turn 1')
|
||||
|
||||
expect(turnLabel.textContent).toContain('Turn 1')
|
||||
expect(turnLabel.textContent).toContain('#1')
|
||||
})
|
||||
|
||||
it('renders a single-text JSON tool result as a JSON tree', () => {
|
||||
|
||||
@@ -25,6 +25,7 @@ import { createChatStore } from '@deepseek-ai/dsh-client-ui-conversation/src/cli
|
||||
import { apply, inject } from '@deepseek-ai/dsh-client-ui-trajectory/client'
|
||||
import { apply as nodeApply } from '@deepseek-ai/dsh-client-ui-trajectory'
|
||||
import type { TrajectoryTurnModel } from '../src/client/layout.ts'
|
||||
import { TrajectoryTimeline } from '../src/client/TrajectoryTimeline.tsx'
|
||||
import {
|
||||
TrajectoryView, type TrajectoryViewInjected,
|
||||
} from '../src/client/TrajectoryView.tsx'
|
||||
@@ -309,6 +310,44 @@ describe('tab switching in ConversationRoot', () => {
|
||||
.toBeNull()
|
||||
})
|
||||
|
||||
it('clicking a timeline block clears the range, selects the record, and opens its inspector', async () => {
|
||||
const b = await bench()
|
||||
const view = mount(b.slots)
|
||||
fireEvent.click(screen.getByRole('tab', { name: 'Trajectory' }))
|
||||
const plot = screen.getByLabelText('Timeline overview; drag horizontally to focus events')
|
||||
vi.spyOn(plot, 'getBoundingClientRect').mockReturnValue({
|
||||
x: 0, y: 0, left: 0, top: 0, right: 100, bottom: 72, width: 100, height: 72,
|
||||
toJSON: () => ({}),
|
||||
})
|
||||
const toolSpan = view.container.querySelector<HTMLElement>(
|
||||
'[data-timeline-span="tool"]',
|
||||
)
|
||||
expect(toolSpan).not.toBeNull()
|
||||
const recordIndex = toolSpan?.dataset.timelineRecordIndex
|
||||
expect(recordIndex).toBeTruthy()
|
||||
|
||||
fireEvent.pointerMove(toolSpan as HTMLElement, { clientX: 50, pointerId: 1 })
|
||||
expect(view.container.querySelector('[data-timeline-hover-line]')).toBeNull()
|
||||
expect(toolSpan?.getAttribute('data-hovered')).toBe('true')
|
||||
|
||||
fireEvent.pointerDown(plot, { button: 0, clientX: 5, pointerId: 1 })
|
||||
fireEvent.pointerMove(plot, { clientX: 95, pointerId: 1 })
|
||||
fireEvent.pointerUp(plot, { clientX: 95, pointerId: 1 })
|
||||
expect(view.container.querySelector('tr[data-timeline-focus]')).toBeTruthy()
|
||||
|
||||
fireEvent.pointerDown(toolSpan as HTMLElement, {
|
||||
button: 0, clientX: 50, pointerId: 2,
|
||||
})
|
||||
fireEvent.pointerUp(toolSpan as HTMLElement, { clientX: 50, pointerId: 2 })
|
||||
|
||||
const selectedRow = view.container.querySelector<HTMLElement>(
|
||||
`tr[data-record-index="${recordIndex}"]`,
|
||||
)
|
||||
expect(selectedRow?.getAttribute('aria-selected')).toBe('true')
|
||||
expect(view.container.querySelector('tr[data-timeline-focus]')).toBeNull()
|
||||
expect(screen.getByRole('complementary', { name: 'Event details' })).toBeTruthy()
|
||||
})
|
||||
|
||||
it('empty window keeps the toolbar and reports no timing data', async () => {
|
||||
const b = await bench(historySnapshot([]))
|
||||
mount(b.slots)
|
||||
@@ -332,6 +371,97 @@ describe('timeline projection', () => {
|
||||
],
|
||||
}],
|
||||
}] satisfies readonly TrajectoryTurnModel[]
|
||||
const longTurns = [{
|
||||
turn: 1,
|
||||
groups: [{
|
||||
title: 'Step 1',
|
||||
cells: Array.from({ length: 10 }, (_, index) => ({
|
||||
index,
|
||||
kind: 'message' as const,
|
||||
text: `record ${index}`,
|
||||
timeSeconds: 1,
|
||||
})),
|
||||
}],
|
||||
}] satisfies readonly TrajectoryTurnModel[]
|
||||
|
||||
it('pans the zoomed viewport only far enough to reveal a newly selected record', async () => {
|
||||
const onRangeChange = vi.fn()
|
||||
const view = render(
|
||||
<TrajectoryTimeline
|
||||
turns={longTurns}
|
||||
mode="sequence"
|
||||
range={null}
|
||||
onRangeChange={onRangeChange}
|
||||
/>,
|
||||
)
|
||||
const plot = screen.getByLabelText('Timeline overview; drag horizontally to focus events')
|
||||
vi.spyOn(plot, 'getBoundingClientRect').mockReturnValue({
|
||||
x: 0, y: 0, left: 0, top: 0, right: 100, bottom: 72, width: 100, height: 72,
|
||||
toJSON: () => ({}),
|
||||
})
|
||||
fireEvent.wheel(plot, { clientX: 50, deltaY: -1_000 })
|
||||
|
||||
view.rerender(
|
||||
<TrajectoryTimeline
|
||||
turns={longTurns}
|
||||
mode="sequence"
|
||||
range={null}
|
||||
selectedIndex={1}
|
||||
onRangeChange={onRangeChange}
|
||||
/>,
|
||||
)
|
||||
await vi.waitFor(() => {
|
||||
const domain = view.container.querySelector<HTMLElement>(
|
||||
'[data-timeline-domain]',
|
||||
)
|
||||
expect(domain?.style.getPropertyValue('--trajectory-domain-left')).toBe('-25%')
|
||||
})
|
||||
|
||||
view.rerender(
|
||||
<TrajectoryTimeline
|
||||
turns={longTurns}
|
||||
mode="sequence"
|
||||
range={null}
|
||||
selectedIndex={8}
|
||||
onRangeChange={onRangeChange}
|
||||
/>,
|
||||
)
|
||||
await vi.waitFor(() => {
|
||||
const domain = view.container.querySelector<HTMLElement>(
|
||||
'[data-timeline-domain]',
|
||||
)
|
||||
expect(domain?.style.getPropertyValue('--trajectory-domain-left')).toBe('-125%')
|
||||
})
|
||||
})
|
||||
|
||||
it('auto-pans a zoomed viewport while a range drag pushes against an edge', () => {
|
||||
const onRangeChange = vi.fn()
|
||||
render(
|
||||
<TrajectoryTimeline
|
||||
turns={longTurns}
|
||||
mode="sequence"
|
||||
range={null}
|
||||
onRangeChange={onRangeChange}
|
||||
/>,
|
||||
)
|
||||
const plot = screen.getByLabelText('Timeline overview; drag horizontally to focus events')
|
||||
vi.spyOn(plot, 'getBoundingClientRect').mockReturnValue({
|
||||
x: 0, y: 0, left: 0, top: 0, right: 100, bottom: 72, width: 100, height: 72,
|
||||
toJSON: () => ({}),
|
||||
})
|
||||
fireEvent.wheel(plot, { clientX: 50, deltaY: -1_000 })
|
||||
fireEvent.pointerDown(plot, { button: 0, clientX: 50, pointerId: 1 })
|
||||
for (let index = 0; index < 24; index++) {
|
||||
fireEvent.pointerMove(plot, { clientX: 99, pointerId: 1 })
|
||||
}
|
||||
fireEvent.pointerUp(plot, { clientX: 99, pointerId: 1 })
|
||||
|
||||
const selectedRange = onRangeChange.mock.calls.at(-1)?.[0] as
|
||||
| { start: number; end: number }
|
||||
| undefined
|
||||
expect(selectedRange).toBeDefined()
|
||||
expect((selectedRange?.end ?? 0) - (selectedRange?.start ?? 0)).toBeGreaterThan(4)
|
||||
})
|
||||
|
||||
it('uses equal-width operation slots and stable semantic lanes', () => {
|
||||
expect(deriveTrajectoryTimeline(turns)).toEqual({
|
||||
@@ -339,15 +469,50 @@ describe('timeline projection', () => {
|
||||
end: 3,
|
||||
spans: [
|
||||
{
|
||||
index: 1, kind: 'message', label: 'assistant', lane: 1, start: 0, end: 1,
|
||||
index: 1, isError: false, kind: 'message', label: 'assistant',
|
||||
lane: 1, start: 0, end: 1,
|
||||
},
|
||||
{
|
||||
index: 2, isError: false, kind: 'tool', label: 'bash',
|
||||
lane: 2, start: 1, end: 2,
|
||||
},
|
||||
{
|
||||
index: 3, isError: false, kind: 'user', label: 'unknown',
|
||||
lane: 0, start: 2, end: 3,
|
||||
},
|
||||
{ index: 2, kind: 'tool', label: 'bash', lane: 2, start: 1, end: 2 },
|
||||
{ index: 3, kind: 'user', label: 'unknown', lane: 0, start: 2, end: 3 },
|
||||
],
|
||||
turnBoundaries: [{ turn: 1, time: 0 }],
|
||||
})
|
||||
})
|
||||
|
||||
it('marks error records directly on timeline spans', () => {
|
||||
const errorTurns = [{
|
||||
turn: 1,
|
||||
groups: [{
|
||||
title: 'Step 1',
|
||||
cells: [{
|
||||
index: 1,
|
||||
kind: 'tool' as const,
|
||||
text: 'failed tool',
|
||||
timeSeconds: 0.1,
|
||||
isError: true,
|
||||
}],
|
||||
}],
|
||||
}] satisfies readonly TrajectoryTurnModel[]
|
||||
const view = render(
|
||||
<TrajectoryTimeline
|
||||
turns={errorTurns}
|
||||
mode="sequence"
|
||||
range={null}
|
||||
onRangeChange={() => {}}
|
||||
/>,
|
||||
)
|
||||
|
||||
expect(view.container.querySelector(
|
||||
'[data-timeline-span="tool"][data-error="true"]',
|
||||
)).toBeTruthy()
|
||||
})
|
||||
|
||||
it('ignores durations and idle gaps while retaining turn boundaries', () => {
|
||||
const separatedTurns = [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user