mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-20 18:57:17 +03:00
fix(app): show subagents in grouped activity as events in the New timeline (#63685)
This commit is contained in:
committed by
GitHub
Unverified
parent
688b60c078
commit
f2156d79c9
@@ -70,7 +70,8 @@ export function TimelineEventRow(props: {
|
||||
)
|
||||
}
|
||||
|
||||
function TimelineEventItem(props: { event: TimelineEvent; onRevealShell?: (shellID: string) => void }) {
|
||||
/** One subagent or shell an events row or an opened activity group lists: who did it and what it was. */
|
||||
export function TimelineEventItem(props: { event: TimelineEvent; onRevealShell?: (shellID: string) => void }) {
|
||||
const i18n = useI18n()
|
||||
const data = useData()
|
||||
|
||||
|
||||
@@ -35,10 +35,12 @@ export const kindKeys = {
|
||||
shell: "ui.timeline.event.shells",
|
||||
} as const
|
||||
|
||||
/** How a group's label counts work it started, beside its other calls: "1 command, started 1 shell". */
|
||||
/** How a group's label counts work that runs on, beside its other calls: "1 command, started 1 shell". */
|
||||
export const launchKeys = {
|
||||
started: { shell: "ui.timeline.activity.startedShells", subagent: "ui.timeline.activity.startedSubagents" },
|
||||
ran: { shell: "ui.timeline.activity.commands", subagent: "ui.timeline.activity.subagents" },
|
||||
finished: { shell: "ui.timeline.activity.finishedShells", subagent: "ui.timeline.activity.finishedSubagents" },
|
||||
stopped: { shell: "ui.timeline.activity.stoppedShells", subagent: "ui.timeline.activity.stoppedSubagents" },
|
||||
} as const
|
||||
|
||||
// Text a call or notice carries, where it is not empty.
|
||||
@@ -99,6 +101,13 @@ export function noticeEvent(message: SessionMessageInfo): TimelineEvent | undefi
|
||||
return { ...item, verb: "finished", failed: state === "error" }
|
||||
}
|
||||
|
||||
/** Which subagent or shell an event is about, where it says. */
|
||||
export function workKey(event: TimelineEvent) {
|
||||
const id = event.kind === "shell" ? event.shellID : event.sessionID
|
||||
|
||||
return id ? `${event.kind}:${id}` : undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* A run of events as one label: each verb once, in the order it first happened, with how many of each kind, and how
|
||||
* many failed overall. Two finishes in a row read "Finished 2 subagents".
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { SessionMessageAssistant, SessionMessageInfo, SessionMessageUser }
|
||||
import { Predicate } from "effect"
|
||||
import { createRoot } from "solid-js"
|
||||
import { subagentReport } from "../storybook/current-session-fixtures"
|
||||
import { timelinePresets } from "../timeline/detail"
|
||||
import { timelinePresets, type TimelineDetail } from "../timeline/detail"
|
||||
import { createNextTimelineProjection, workedDuration } from "./projection"
|
||||
import { replayScript, scenarios } from "./stories/session-replay"
|
||||
|
||||
@@ -149,6 +149,71 @@ describe("New timeline projection", () => {
|
||||
"UserMessage",
|
||||
])
|
||||
})
|
||||
|
||||
test("a subagent finishes in the group that started it only when nothing comes between; otherwise it reports in its own row", () => {
|
||||
const launched: SessionMessageInfo[] = [
|
||||
{ id: "user", type: "user", text: "Go", time: { created: 0 } },
|
||||
step("launch", 1, {
|
||||
finish: "tool-calls",
|
||||
content: [
|
||||
{
|
||||
id: "call",
|
||||
type: "tool",
|
||||
name: "subagent",
|
||||
state: {
|
||||
status: "completed",
|
||||
input: { description: "Review the diff", agent: "review" },
|
||||
content: [{ type: "text", text: "" }],
|
||||
metadata: { sessionID: "child", status: "running" },
|
||||
},
|
||||
time: { created: 1, completed: 2 },
|
||||
},
|
||||
],
|
||||
time: { created: 1, completed: 2 },
|
||||
}),
|
||||
]
|
||||
|
||||
const report = subagentReport("report", 4, {
|
||||
childID: "child",
|
||||
agent: "review",
|
||||
state: "completed",
|
||||
description: "Review the diff",
|
||||
body: "Looks good.",
|
||||
})
|
||||
|
||||
const said = step("said", 3, {
|
||||
finish: "stop",
|
||||
content: [{ type: "text", text: "Started a review." }],
|
||||
time: { created: 3, completed: 3 },
|
||||
})
|
||||
|
||||
const groups = (messages: SessionMessageInfo[], detail: TimelineDetail) =>
|
||||
createRoot((dispose) => {
|
||||
const projection = createNextTimelineProjection({
|
||||
sessionMessages: () => messages,
|
||||
status: () => ({ type: "idle" }),
|
||||
timelineDetail: () => detail,
|
||||
})
|
||||
|
||||
const result = projection
|
||||
.rows()
|
||||
.flatMap((row) =>
|
||||
Predicate.isTagged(row, "AssistantPart") && row.group.type !== "part"
|
||||
? [`${row.group.type}:${row.group.refs.map((ref) => ref.messageID).join("+")}`]
|
||||
: [],
|
||||
)
|
||||
|
||||
dispose()
|
||||
|
||||
return result
|
||||
})
|
||||
|
||||
const grouped = { ...detailed, subagents: { placement: "grouped" as const } }
|
||||
|
||||
expect(groups([...launched, report], grouped)).toEqual(["context:launch+report"])
|
||||
expect(groups([...launched, said, report], grouped)).toEqual(["context:launch", "events:report"])
|
||||
expect(groups([...launched, report], detailed)).toEqual(["events:launch", "events:report"])
|
||||
})
|
||||
})
|
||||
|
||||
describe("workedDuration", () => {
|
||||
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
type TurnThinkingPlacement,
|
||||
} from "../timeline/turn-phase-machine"
|
||||
import { errorInfo } from "./errors"
|
||||
import { noticeEvent } from "./events"
|
||||
import { noticeEvent, toolEvent, workKey, type TimelineEvent } from "./events"
|
||||
import {
|
||||
contentGroup,
|
||||
contentShows,
|
||||
@@ -31,6 +31,7 @@ import {
|
||||
liveThinkingShows,
|
||||
noticePlacement,
|
||||
textShows,
|
||||
toolRule,
|
||||
} from "./rules"
|
||||
|
||||
type Notice = Exclude<SessionMessageInfo, { type: "user" | "assistant" | "shell" | "idle" }>
|
||||
@@ -651,6 +652,25 @@ function groupNotices(
|
||||
// Live status renders nothing while other feedback shows, so a group below it spaces from the content above it.
|
||||
const above = Predicate.isTagged(previous, "Activity") ? result.at(-2) : previous
|
||||
const message = Predicate.isTagged(row, "Notice") ? messageByID.get(row.messageID) : undefined
|
||||
const event = message && noticeEvent(message)
|
||||
|
||||
// Work that reports back right after the activity group that started it, with nothing between, finishes there.
|
||||
if (
|
||||
event &&
|
||||
!event.failed &&
|
||||
Predicate.isTagged(previous, "AssistantPart") &&
|
||||
previous.group.type === "context" &&
|
||||
previous.userMessageID === row.userMessageID &&
|
||||
launches(previous.group, event, messageByID)
|
||||
) {
|
||||
result[result.length - 1] = new TimelineRow.AssistantPart({
|
||||
...previous,
|
||||
group: { ...previous.group, refs: [...previous.group.refs, { messageID: message.id, partID: message.id }] },
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
const type = message ? noticeGroup(detail, message) : undefined
|
||||
|
||||
const current =
|
||||
@@ -710,6 +730,25 @@ function joins(
|
||||
return previous.type === "events" && current.type === "events" && notices(previous) && notices(current)
|
||||
}
|
||||
|
||||
// Whether an activity group started the work an event is about.
|
||||
function launches(
|
||||
group: Exclude<PartGroup, { type: "part" }>,
|
||||
event: TimelineEvent,
|
||||
messageByID: ReadonlyMap<string, SessionMessageInfo>,
|
||||
) {
|
||||
const key = workKey(event)
|
||||
|
||||
return (
|
||||
key !== undefined &&
|
||||
group.refs.some((ref) => {
|
||||
const content = resolveContent(messageByID.get(ref.messageID), ref.partID)
|
||||
const launch = content?.type === "tool" && toolRule(content).layout === "event" ? toolEvent(content) : undefined
|
||||
|
||||
return launch !== undefined && workKey(launch) === key
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
function noticeGroup(detail: TimelineDetail, message: SessionMessageInfo) {
|
||||
if (noticeEvent(message)) return "events" as const
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ import { useSources } from "../context/sources"
|
||||
import { turnSources } from "../sources/sources"
|
||||
import { SessionReadToolGroup, SessionUserMessage } from "../message/current-message"
|
||||
import { SessionCompactionMessage, SessionCompactionQueued } from "../message/message-content"
|
||||
import { taskAgentName, type ContextGroupPart } from "../tools/tool-renderer"
|
||||
import { taskAgentName } from "../tools/tool-renderer"
|
||||
import { SessionRetry } from "../components/session-retry"
|
||||
import { SessionError } from "../components/session-error"
|
||||
import type { TimelineDetail } from "../timeline/detail"
|
||||
@@ -57,7 +57,7 @@ import { contentOpens, diffOpens, goal as goalMessage, thoughtOpens, toolRule, u
|
||||
import { Separator } from "./separator"
|
||||
import { timelineGaps } from "./spacing"
|
||||
import { AssistantContent } from "./tools/assistant-content"
|
||||
import { ContextGroup } from "./tools/context-group"
|
||||
import { ContextGroup, type ActivityGroupPart } from "./tools/context-group"
|
||||
import { FileGroup } from "./tools/file-group"
|
||||
import { PatchTool } from "./tools/patch"
|
||||
import { ShellMessage } from "./tools/shell"
|
||||
@@ -335,7 +335,7 @@ export function createNextTimelineRowRenderer(input: {
|
||||
const contents = indexGroupContents(group.refs)
|
||||
const streaming = phase(row().userMessageID).streamingReasoningRef
|
||||
|
||||
return group.refs.flatMap<ContextGroupPart>((ref) => {
|
||||
return group.refs.flatMap<ActivityGroupPart>((ref) => {
|
||||
const content = contents.get(ref.messageID)?.get(ref.partID)
|
||||
|
||||
if (content?.type === "tool") {
|
||||
@@ -364,6 +364,9 @@ export function createNextTimelineRowRenderer(input: {
|
||||
]
|
||||
|
||||
if (ref.messageID !== ref.partID || !message) return []
|
||||
const event = noticeEvent(message)
|
||||
|
||||
if (event) return [{ type: "event", id: ref.partID, event }]
|
||||
|
||||
if (message.type !== "assistant" && message.type !== "user")
|
||||
return [{ type: "notice", id: ref.partID, render: () => <Notice messageID={ref.messageID} grouped /> }]
|
||||
@@ -402,6 +405,7 @@ export function createNextTimelineRowRenderer(input: {
|
||||
open={input.disclosure.value(key()) === true}
|
||||
onOpenChange={(open) => input.disclosure.set(key(), open)}
|
||||
onSizeChange={onSizeChange}
|
||||
onRevealShell={input.revealPart}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -208,7 +208,7 @@ export function echoesUserShell(message: SessionMessageInfo, userShellIDs: Reado
|
||||
|
||||
/**
|
||||
* Where a notice shows. What the user did and what changed the session always stands on its own. Background work
|
||||
* reports its outcome as its own row, following the setting its launch follows: a subagent's the subagent setting, a
|
||||
* reports its outcome as an event, following the setting its launch follows: a subagent's the subagent setting, a
|
||||
* shell's the shell setting.
|
||||
*/
|
||||
export function noticePlacement(detail: TimelineDetail, message: SessionMessageInfo): TimelinePlacement {
|
||||
|
||||
@@ -323,13 +323,15 @@
|
||||
}
|
||||
|
||||
/* An event row opens to the subagents and shells it counts, each read like a nested row and leading to its session or
|
||||
to the call that ran it. */
|
||||
to the call that ran it. An opened activity group lists the ones it started or heard back from the same way. */
|
||||
[data-timeline="next"] [data-component="timeline-event-list"] {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
padding-top: 4px;
|
||||
}
|
||||
|
||||
[data-timeline="next"] :is([data-component="timeline-event-list"], [data-slot="context-tool-group-item"]) {
|
||||
[data-slot="timeline-event-item"] {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -376,7 +378,7 @@
|
||||
color: var(--v2-text-text-base);
|
||||
}
|
||||
|
||||
[data-component="tag"] {
|
||||
[data-slot="timeline-event-item"] [data-component="tag"] {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
@@ -517,6 +519,7 @@
|
||||
}
|
||||
|
||||
[data-component="context-tool-group-list"] [data-slot="context-tool-group-item"],
|
||||
[data-component="context-tool-group-list"] [data-slot="timeline-event-item"],
|
||||
[data-component="timeline-event-list"] [data-slot="timeline-event-item"] {
|
||||
min-height: var(--line-height-compact);
|
||||
}
|
||||
|
||||
@@ -24,19 +24,26 @@ import {
|
||||
toolMetadata,
|
||||
type ContextGroupPart,
|
||||
} from "../../tools/tool-renderer"
|
||||
import { kindKeys, launchKeys, summarizeEvents, toolEvent, verbKeys } from "../events"
|
||||
import { TimelineEventRow } from "../event-row"
|
||||
import { kindKeys, launchKeys, summarizeEvents, toolEvent, verbKeys, workKey, type TimelineEvent } from "../events"
|
||||
import { toolRule, toolStopped, type ToolMode } from "../rules"
|
||||
import { FileGroup } from "./file-group"
|
||||
import { ThoughtRow } from "./thought"
|
||||
import { ToolDisplay } from "./tool-display"
|
||||
|
||||
/** A part of an activity group: a call, a thought, a notice, or background work reporting back. */
|
||||
export type ActivityGroupPart = ContextGroupPart | { type: "event"; id: string; event: TimelineEvent }
|
||||
|
||||
// Subagents and background work listed one after another in an opened group, as one nested events row.
|
||||
type WorkRun = { type: "work"; id: string; events: TimelineEvent[] }
|
||||
|
||||
/**
|
||||
* A stretch of the agent's work folded into one row, named by what it did: "Explored 3 files · 2 commands". It only
|
||||
* records what happened; the status line below the turn says what is live. A stretch of thoughts alone is those
|
||||
* thoughts, without a group around them.
|
||||
*/
|
||||
export function ContextGroup(props: {
|
||||
parts: ContextGroupPart[]
|
||||
parts: ActivityGroupPart[]
|
||||
open: boolean
|
||||
onOpenChange: (open: boolean) => void
|
||||
onSizeChange?: () => void
|
||||
@@ -49,12 +56,24 @@ export function ContextGroup(props: {
|
||||
fileOpen?: (path: string) => boolean | undefined
|
||||
onFileOpenChange?: (path: string, open: boolean) => void
|
||||
patchGroupKey?: (tools: SessionMessageAssistantTool[]) => string
|
||||
onRevealShell?: (shellID: string) => void
|
||||
}) {
|
||||
const i18n = useI18n()
|
||||
const tools = createMemo(() => props.parts.filter((part) => part.type === "tool"))
|
||||
const reasoning = createMemo(() => props.parts.flatMap((part) => (part.type === "reasoning" ? [part] : [])))
|
||||
const thoughtsOnly = createMemo(() => reasoning().length > 0 && reasoning().length === props.parts.length)
|
||||
const activity = createMemo(() => activityLabel(tools(), i18n))
|
||||
const partEvents = createMemo(() => workEvents(props.parts))
|
||||
const events = createMemo(() => [...partEvents().values()])
|
||||
|
||||
// A group of only subagents and work reporting back reads as the events row it is, not a group around one. Until a
|
||||
// call has anything to count, it stays a group, so the row never renders empty.
|
||||
const workOnly = createMemo(
|
||||
() =>
|
||||
events().length > 0 &&
|
||||
props.parts.every((part) => part.type === "event" || (part.type === "tool" && toolRule(part).name === "subagent")),
|
||||
)
|
||||
|
||||
const activity = createMemo(() => activityLabel(tools(), events(), i18n))
|
||||
|
||||
const label = createMemo(() => {
|
||||
const value = activity()
|
||||
@@ -69,16 +88,40 @@ export function ContextGroup(props: {
|
||||
|
||||
const items = createMemo(() =>
|
||||
(props.open ? props.parts : []).reduce<
|
||||
(SessionMessageAssistantTool[] | Exclude<ContextGroupPart, SessionMessageAssistantTool>)[]
|
||||
(
|
||||
| SessionMessageAssistantTool[]
|
||||
| Exclude<ActivityGroupPart, SessionMessageAssistantTool | { type: "event" }>
|
||||
| WorkRun
|
||||
)[]
|
||||
>((groups, tool) => {
|
||||
const previous = groups.at(-1)
|
||||
|
||||
// Subagents started one after another, and work reporting back, read as one events row nested in the group:
|
||||
// "Started 3 subagents".
|
||||
if (tool.type === "event" || (tool.type === "tool" && toolRule(tool).name === "subagent")) {
|
||||
// A subagent still being asked for has nothing to list yet, and a report its launch already says is not
|
||||
// listed twice.
|
||||
const event = partEvents().get(tool)
|
||||
|
||||
if (!event) return groups
|
||||
|
||||
if (previous && !Array.isArray(previous) && previous.type === "work") {
|
||||
previous.events.push(event)
|
||||
|
||||
return groups
|
||||
}
|
||||
|
||||
groups.push({ type: "work", id: tool.id, events: [event] })
|
||||
|
||||
return groups
|
||||
}
|
||||
|
||||
if (tool.type !== "tool") {
|
||||
groups.push(tool)
|
||||
|
||||
return groups
|
||||
}
|
||||
|
||||
const previous = groups.at(-1)
|
||||
|
||||
if (Array.isArray(previous) && previous[0] && joins(previous[0], tool)) {
|
||||
previous.push(tool)
|
||||
|
||||
@@ -136,113 +179,152 @@ export function ContextGroup(props: {
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div
|
||||
ref={root}
|
||||
data-component="collapsed-tool-group"
|
||||
data-timeline-part-ids={props.parts.map((part) => part.id).join(",")}
|
||||
>
|
||||
<BasicTool
|
||||
icon="glasses"
|
||||
status="completed"
|
||||
compact
|
||||
hasContent
|
||||
allowOpenWhilePending
|
||||
open={props.open}
|
||||
onOpenChange={change}
|
||||
trigger={
|
||||
<div data-component="context-tool-group-trigger" aria-label={label().text}>
|
||||
<Show when={activity()} fallback={<UsedTitle label={usedLabel(props.parts, i18n)} />}>
|
||||
{(value) => (
|
||||
<span data-slot="context-tool-group-title" data-activity="">
|
||||
<span data-slot="context-tool-group-verb">{value().verb}</span>
|
||||
<Show when={value().main}>
|
||||
<span data-slot="context-tool-group-detail">{value().main}</span>
|
||||
</Show>
|
||||
<Show when={value().others.length > 0}>
|
||||
<span data-slot="context-tool-group-separator" aria-hidden="true">
|
||||
·
|
||||
</span>
|
||||
<span data-slot="context-tool-group-detail">{value().others.join(", ")}</span>
|
||||
</Show>
|
||||
</span>
|
||||
)}
|
||||
</Show>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div data-component="context-tool-group-list">
|
||||
<Index each={items()}>
|
||||
{(item) => {
|
||||
const group = createMemo(() => {
|
||||
const value = item()
|
||||
|
||||
return Array.isArray(value) ? value : undefined
|
||||
})
|
||||
|
||||
const reasoning = createMemo(() => {
|
||||
const value = item()
|
||||
|
||||
return !Array.isArray(value) && value.type === "reasoning" ? value : undefined
|
||||
})
|
||||
|
||||
const callback = createMemo(() => {
|
||||
const value = item()
|
||||
|
||||
return !Array.isArray(value) &&
|
||||
(value.type === "notice" || value.type === "shell" || value.type === "text")
|
||||
? value
|
||||
: undefined
|
||||
})
|
||||
|
||||
return (
|
||||
<Show
|
||||
when={group()}
|
||||
fallback={
|
||||
<Show
|
||||
when={reasoning()}
|
||||
fallback={
|
||||
<Show when={callback()}>
|
||||
{(part) => <div data-slot="context-tool-group-item">{part().render()}</div>}
|
||||
</Show>
|
||||
}
|
||||
>
|
||||
{(part) => (
|
||||
<div data-slot="context-tool-group-item">
|
||||
<AssistantReasoningContent
|
||||
id={part().id}
|
||||
content={part()}
|
||||
streaming={part().streaming ?? false}
|
||||
defaultOpen={props.reasoningDefaultOpen}
|
||||
open={props.reasoningOpen?.(part().id)}
|
||||
onOpenChange={(open) => props.onReasoningOpenChange?.(part().id, open)}
|
||||
onContentRendered={props.onSizeChange}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</Show>
|
||||
}
|
||||
>
|
||||
{(group) => (
|
||||
<div data-slot="context-tool-group-item">
|
||||
<GroupItem
|
||||
tools={group()}
|
||||
patchKey={patchKeys().get(group()[0]!)}
|
||||
onSizeChange={props.onSizeChange}
|
||||
toolDefaultOpen={props.toolDefaultOpen}
|
||||
toolOpen={props.toolOpen}
|
||||
onToolOpenChange={props.onToolOpenChange}
|
||||
fileOpen={props.fileOpen}
|
||||
onFileOpenChange={props.onFileOpenChange}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</Show>
|
||||
)
|
||||
}}
|
||||
</Index>
|
||||
<Show
|
||||
when={!workOnly()}
|
||||
fallback={
|
||||
<div data-timeline-part-ids={props.parts.map((part) => part.id).join(",")}>
|
||||
<TimelineEventRow
|
||||
events={events()}
|
||||
open={props.open}
|
||||
onOpenChange={change}
|
||||
onRevealShell={props.onRevealShell}
|
||||
/>
|
||||
</div>
|
||||
</BasicTool>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div
|
||||
ref={root}
|
||||
data-component="collapsed-tool-group"
|
||||
data-timeline-part-ids={props.parts.map((part) => part.id).join(",")}
|
||||
>
|
||||
<BasicTool
|
||||
icon="glasses"
|
||||
status="completed"
|
||||
compact
|
||||
hasContent
|
||||
allowOpenWhilePending
|
||||
open={props.open}
|
||||
onOpenChange={change}
|
||||
trigger={
|
||||
<div data-component="context-tool-group-trigger" aria-label={label().text}>
|
||||
<Show when={activity()} fallback={<UsedTitle label={usedLabel(props.parts, i18n)} />}>
|
||||
{(value) => (
|
||||
<span data-slot="context-tool-group-title" data-activity="">
|
||||
<span data-slot="context-tool-group-verb">{value().verb}</span>
|
||||
<Show when={value().main}>
|
||||
<span data-slot="context-tool-group-detail">{value().main}</span>
|
||||
</Show>
|
||||
<Show when={value().others.length > 0}>
|
||||
<span data-slot="context-tool-group-separator" aria-hidden="true">
|
||||
·
|
||||
</span>
|
||||
<span data-slot="context-tool-group-detail">{value().others.join(", ")}</span>
|
||||
</Show>
|
||||
</span>
|
||||
)}
|
||||
</Show>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div data-component="context-tool-group-list">
|
||||
<Index each={items()}>
|
||||
{(item) => {
|
||||
const group = createMemo(() => {
|
||||
const value = item()
|
||||
|
||||
return Array.isArray(value) ? value : undefined
|
||||
})
|
||||
|
||||
const reasoning = createMemo(() => {
|
||||
const value = item()
|
||||
|
||||
return !Array.isArray(value) && value.type === "reasoning" ? value : undefined
|
||||
})
|
||||
|
||||
const callback = createMemo(() => {
|
||||
const value = item()
|
||||
|
||||
return !Array.isArray(value) &&
|
||||
(value.type === "notice" || value.type === "shell" || value.type === "text")
|
||||
? value
|
||||
: undefined
|
||||
})
|
||||
|
||||
const work = createMemo(() => {
|
||||
const value = item()
|
||||
|
||||
return !Array.isArray(value) && value.type === "work" ? value : undefined
|
||||
})
|
||||
|
||||
return (
|
||||
<Show
|
||||
when={group()}
|
||||
fallback={
|
||||
<Show
|
||||
when={reasoning()}
|
||||
fallback={
|
||||
<Show
|
||||
when={work()}
|
||||
fallback={
|
||||
<Show when={callback()}>
|
||||
{(part) => <div data-slot="context-tool-group-item">{part().render()}</div>}
|
||||
</Show>
|
||||
}
|
||||
>
|
||||
{(work) => (
|
||||
<div data-slot="context-tool-group-item">
|
||||
<TimelineEventRow
|
||||
events={work().events}
|
||||
open={props.toolOpen?.(`events:${work().id}`) === true}
|
||||
onOpenChange={(open) => {
|
||||
props.onToolOpenChange?.(`events:${work().id}`, open)
|
||||
props.onSizeChange?.()
|
||||
}}
|
||||
onRevealShell={props.onRevealShell}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</Show>
|
||||
}
|
||||
>
|
||||
{(part) => (
|
||||
<div data-slot="context-tool-group-item">
|
||||
<AssistantReasoningContent
|
||||
id={part().id}
|
||||
content={part()}
|
||||
streaming={part().streaming ?? false}
|
||||
defaultOpen={props.reasoningDefaultOpen}
|
||||
open={props.reasoningOpen?.(part().id)}
|
||||
onOpenChange={(open) => props.onReasoningOpenChange?.(part().id, open)}
|
||||
onContentRendered={props.onSizeChange}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</Show>
|
||||
}
|
||||
>
|
||||
{(group) => (
|
||||
<div data-slot="context-tool-group-item">
|
||||
<GroupItem
|
||||
tools={group()}
|
||||
patchKey={patchKeys().get(group()[0]!)}
|
||||
onSizeChange={props.onSizeChange}
|
||||
toolDefaultOpen={props.toolDefaultOpen}
|
||||
toolOpen={props.toolOpen}
|
||||
onToolOpenChange={props.onToolOpenChange}
|
||||
fileOpen={props.fileOpen}
|
||||
onFileOpenChange={props.onFileOpenChange}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</Show>
|
||||
)
|
||||
}}
|
||||
</Index>
|
||||
</div>
|
||||
</BasicTool>
|
||||
</div>
|
||||
</Show>
|
||||
</Show>
|
||||
)
|
||||
}
|
||||
@@ -422,7 +504,7 @@ function UsedTitle(props: { label: ReturnType<typeof usedLabel> }) {
|
||||
)
|
||||
}
|
||||
|
||||
function usedLabel(parts: ContextGroupPart[], i18n: UiI18n) {
|
||||
function usedLabel(parts: ActivityGroupPart[], i18n: UiI18n) {
|
||||
const count = parts.filter((part) => part.type === "reasoning").length
|
||||
|
||||
if (!count) {
|
||||
@@ -451,6 +533,52 @@ function usedLabel(parts: ContextGroupPart[], i18n: UiI18n) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* What each subagent or background shell in a group did, in order. Work that reports back in the group that started
|
||||
* it reads once, as how it ended: the launch says "Finished" and the report is not counted again.
|
||||
*/
|
||||
function workEvents(parts: ActivityGroupPart[]) {
|
||||
const launch = (part: ActivityGroupPart) =>
|
||||
part.type === "tool" && toolRule(part).layout === "event" ? toolEvent(part) : undefined
|
||||
|
||||
const launched = new Set(
|
||||
parts.flatMap((part) => {
|
||||
const event = launch(part)
|
||||
const key = event && workKey(event)
|
||||
|
||||
return key ? [key] : []
|
||||
}),
|
||||
)
|
||||
|
||||
const reports = new Map(
|
||||
parts.flatMap((part) => {
|
||||
const key = part.type === "event" ? workKey(part.event) : undefined
|
||||
|
||||
return key && part.type === "event" ? [[key, part.event] as const] : []
|
||||
}),
|
||||
)
|
||||
|
||||
return new Map(
|
||||
parts.flatMap((part): [ActivityGroupPart, TimelineEvent][] => {
|
||||
if (part.type === "event") {
|
||||
const key = workKey(part.event)
|
||||
|
||||
return key && launched.has(key) ? [] : [[part, part.event]]
|
||||
}
|
||||
|
||||
const event = launch(part)
|
||||
|
||||
if (!event) return []
|
||||
const key = workKey(event)
|
||||
const outcome = key ? reports.get(key) : undefined
|
||||
|
||||
return [
|
||||
[part, outcome && event.verb === "started" ? { ...event, verb: outcome.verb, failed: outcome.failed } : event],
|
||||
]
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
// The most consequential work names a group: changing files over running commands, and both over reading.
|
||||
const modePriority: ToolMode[] = ["edit", "run", "tool", "explore"]
|
||||
|
||||
@@ -465,25 +593,16 @@ const decodeChangedPath = Schema.decodeUnknownOption(Schema.Struct({ file: Schem
|
||||
|
||||
/**
|
||||
* Names a stretch of the agent's work by its main mode, then what its other calls did: "Edited 4 files · 2 commands,
|
||||
* started 1 shell". Work that runs on is counted by what was started, not among the calls that started it; a stretch of
|
||||
* only that reads like an events row: "Started 2 subagents".
|
||||
* started 1 shell". Work that runs on is counted by what happened to it, not among the calls that started it; a
|
||||
* stretch of only that reads like an events row: "Started 2 subagents · finished 2 subagents".
|
||||
*/
|
||||
function activityLabel(group: SessionMessageAssistantTool[], i18n: UiI18n) {
|
||||
function activityLabel(group: SessionMessageAssistantTool[], events: TimelineEvent[], i18n: UiI18n) {
|
||||
const tools = group.filter((tool) => toolRule(tool).layout !== "event")
|
||||
const launches = summarizeEvents(events).verbs
|
||||
|
||||
const launches = summarizeEvents(
|
||||
group.flatMap((tool) => {
|
||||
const event = toolRule(tool).layout === "event" ? toolEvent(tool) : undefined
|
||||
|
||||
return event ? [event] : []
|
||||
}),
|
||||
).verbs
|
||||
|
||||
const launched = launches.flatMap((bucket) => {
|
||||
const keys = bucket.verb === "started" || bucket.verb === "ran" ? launchKeys[bucket.verb] : undefined
|
||||
|
||||
return keys ? bucket.kinds.map((item) => i18n.plural(keys[item.kind], item.count)) : []
|
||||
})
|
||||
const launched = launches.flatMap((bucket) =>
|
||||
bucket.kinds.map((item) => i18n.plural(launchKeys[bucket.verb][item.kind], item.count)),
|
||||
)
|
||||
|
||||
const modes = new Set(tools.map((tool) => toolRule(tool).mode))
|
||||
const mode = modePriority.find((item) => modes.has(item))
|
||||
|
||||
@@ -180,6 +180,14 @@ const source = {
|
||||
"ui.timeline.activity.startedShells.other": "started {{count}} shells",
|
||||
"ui.timeline.activity.startedSubagents.one": "started {{count}} subagent",
|
||||
"ui.timeline.activity.startedSubagents.other": "started {{count}} subagents",
|
||||
"ui.timeline.activity.finishedShells.one": "finished {{count}} shell",
|
||||
"ui.timeline.activity.finishedShells.other": "finished {{count}} shells",
|
||||
"ui.timeline.activity.finishedSubagents.one": "finished {{count}} subagent",
|
||||
"ui.timeline.activity.finishedSubagents.other": "finished {{count}} subagents",
|
||||
"ui.timeline.activity.stoppedShells.one": "stopped {{count}} shell",
|
||||
"ui.timeline.activity.stoppedShells.other": "stopped {{count}} shells",
|
||||
"ui.timeline.activity.stoppedSubagents.one": "stopped {{count}} subagent",
|
||||
"ui.timeline.activity.stoppedSubagents.other": "stopped {{count}} subagents",
|
||||
"ui.timeline.event.started": "Started",
|
||||
"ui.timeline.event.finished": "Finished",
|
||||
"ui.timeline.event.stopped": "Stopped",
|
||||
|
||||
Reference in New Issue
Block a user