mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
fix(session-ui): keep Code Mode executions separate and open by default
Each execute row lists its own calls, so its code and output can be reached from that row. Execute rows now start expanded, matching the TUI, which always lists nested calls.
This commit is contained in:
parent
64d61ed8fa
commit
7a1482abbe
8 changed files with 166 additions and 350 deletions
|
|
@ -47,22 +47,22 @@ story("renders every tool error outcome without leaking hidden tools", async ({
|
|||
for (const name of names) await expect(timeline.locator(`[data-timeline-part-id="tool_error_${name}"]`)).toBeVisible()
|
||||
})
|
||||
|
||||
story("keeps a failed execute inline with its neighbours' calls", async ({ mount }) => {
|
||||
story("lists a failed execute's calls and keeps its error under the failed call", async ({ mount }) => {
|
||||
const timeline = await mount("current-session-terminal-work--execute-failed")
|
||||
// Adjacent executions merge into one list, so each merged run counts once.
|
||||
await timeline.getByRole("button", { name: /^Used 3 / }).click()
|
||||
const merged = timeline.locator('[data-timeline-part-ids="tool_execute_search,tool_execute_failed_url"]')
|
||||
const call = merged.locator('[data-slot="execute-tool-call"]')
|
||||
await timeline.getByRole("button", { name: /^Used 5 / }).click()
|
||||
const failed = timeline.locator('[data-timeline-part-id="tool_execute_failed_url"]')
|
||||
const call = failed.locator('[data-slot="execute-tool-call"]')
|
||||
// Executions open by default, so the calls show without expanding the row.
|
||||
await expect(call).toHaveText([/browser\.tabs\.open/])
|
||||
await expect(call).toHaveAttribute("data-status", "error")
|
||||
await expect(timeline.locator('[data-kind="tool-error-card"]')).toHaveCount(0)
|
||||
|
||||
// The runtime error stays collapsed under the failed call until it is expanded.
|
||||
const error = merged.locator('[data-slot="execute-tool-error"]')
|
||||
const error = failed.locator('[data-slot="execute-tool-error"]')
|
||||
await expect(error).toHaveCount(0)
|
||||
await call.click()
|
||||
await expect(call).toHaveAttribute("aria-expanded", "true")
|
||||
await expect(merged.locator('[data-slot="execute-tool-call-input"]')).toContainText(
|
||||
await expect(failed.locator('[data-slot="execute-tool-call-input"]')).toContainText(
|
||||
"url:file:///C:/tmp/opencode/throne-of-glass-luke.html",
|
||||
)
|
||||
await expect(error).toContainText(
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import type { SessionUserActions, SessionUserAttachmentReference, SessionUserCom
|
|||
import { AssistantReasoningContent, AssistantTextContent, CurrentUserMessageDisplay } from "./message-content"
|
||||
import {
|
||||
CurrentContextToolGroup,
|
||||
CurrentExecuteToolGroup,
|
||||
CurrentFileToolGroup,
|
||||
CurrentReadToolGroup,
|
||||
ToolDisplay,
|
||||
|
|
@ -108,10 +107,6 @@ export function SessionContextToolGroup(props: ComponentProps<typeof CurrentCont
|
|||
return <CurrentContextToolGroup {...props} />
|
||||
}
|
||||
|
||||
export function SessionExecuteToolGroup(props: ComponentProps<typeof CurrentExecuteToolGroup>) {
|
||||
return <CurrentExecuteToolGroup {...props} />
|
||||
}
|
||||
|
||||
export function SessionReadToolGroup(props: ComponentProps<typeof CurrentReadToolGroup>) {
|
||||
return <CurrentReadToolGroup {...props} />
|
||||
}
|
||||
|
|
|
|||
|
|
@ -856,7 +856,7 @@ function groupContent(
|
|||
detail?: TimelineDetail,
|
||||
): PartGroup[] {
|
||||
const groups: PartGroup[] = []
|
||||
let adjacent: { type: "context" | "file" | "read" | "execute"; refs: PartRef[]; tools: boolean } | undefined
|
||||
let adjacent: { type: "context" | "file" | "read"; refs: PartRef[]; tools: boolean } | undefined
|
||||
|
||||
const flush = () => {
|
||||
const current = adjacent
|
||||
|
|
@ -864,8 +864,7 @@ function groupContent(
|
|||
|
||||
if (!first) return
|
||||
|
||||
// A lone execution keeps its part row so a following one merges into the same group key.
|
||||
if ((!current.tools && !detail) || (current.type === "execute" && current.refs.length === 1)) {
|
||||
if (!current.tools && !detail) {
|
||||
groups.push(
|
||||
...current.refs.map((ref) => ({ type: "part" as const, key: `part:${ref.messageID}:${ref.partID}`, ref })),
|
||||
)
|
||||
|
|
@ -935,20 +934,6 @@ function toolGroupType(
|
|||
editExpanded: boolean,
|
||||
hasContextGroup: boolean,
|
||||
detail?: TimelineDetail,
|
||||
) {
|
||||
const type = separateToolGroupType(content, shellExpanded, editExpanded, hasContextGroup, detail)
|
||||
|
||||
if (type || content.name !== "execute") return type
|
||||
|
||||
return "execute"
|
||||
}
|
||||
|
||||
function separateToolGroupType(
|
||||
content: Extract<Content, { type: "tool" }>,
|
||||
shellExpanded: boolean,
|
||||
editExpanded: boolean,
|
||||
hasContextGroup: boolean,
|
||||
detail?: TimelineDetail,
|
||||
) {
|
||||
if (detail) {
|
||||
if (content.name === "question" && !currentToolFailed(content)) return undefined
|
||||
|
|
|
|||
|
|
@ -1176,43 +1176,6 @@ describe("current session timeline rows", () => {
|
|||
])
|
||||
})
|
||||
|
||||
test("merges consecutive executions, including failures, into one group keyed by the first", () => {
|
||||
const groups = (detail?: (typeof timelinePresets)[number]["value"]) =>
|
||||
Timeline.constructSessionMessageRows(
|
||||
storyDocument([
|
||||
storyTool("first", "execute", "completed", {}),
|
||||
storyTool("second", "execute", "completed", {}),
|
||||
storyTool("failed", "execute", "completed", {}, { metadata: { error: true } }),
|
||||
storyTool("third", "execute", "running", {}),
|
||||
{ type: "text", text: "Boundary" },
|
||||
storyTool("alone", "execute", "completed", {}),
|
||||
]).messages,
|
||||
false,
|
||||
{ type: "busy" },
|
||||
undefined,
|
||||
true,
|
||||
false,
|
||||
undefined,
|
||||
detail,
|
||||
).rows.flatMap((row) =>
|
||||
Predicate.isTagged(row, "AssistantPart")
|
||||
? [
|
||||
[
|
||||
row.group.type,
|
||||
...(row.group.type === "part" ? [row.group.ref] : row.group.refs).map((ref) => ref.partID),
|
||||
],
|
||||
]
|
||||
: [],
|
||||
)
|
||||
|
||||
expect(groups()).toEqual([
|
||||
["execute", "first", "second", "failed", "third"],
|
||||
["part", expect.stringContaining("text")],
|
||||
["part", "alone"],
|
||||
])
|
||||
expect(groups(timelinePresets[0]!.value)).toEqual(groups())
|
||||
})
|
||||
|
||||
test("keeps active and background work standalone when no group precedes them", () => {
|
||||
const source: SessionMessageInfo[] = [
|
||||
{ id: "msg_user", type: "user", text: "work", time: { created: 1 } },
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import { TimelineSeparator } from "../components/timeline-separator"
|
|||
import {
|
||||
SessionAssistantContent,
|
||||
SessionContextToolGroup,
|
||||
SessionExecuteToolGroup,
|
||||
SessionFileToolGroup,
|
||||
SessionReadToolGroup,
|
||||
SessionShellMessage,
|
||||
|
|
@ -244,7 +243,7 @@ export function createSessionTimelineRowRenderer(input: {
|
|||
}
|
||||
reasoningOpen={(id) => input.disclosure.value(id)}
|
||||
onReasoningOpenChange={(id, open) => input.disclosure.set(id, open)}
|
||||
toolDefaultOpen={(tool) => (input.timelineDetail ? contentDefaultOpen(tool) : false)}
|
||||
toolDefaultOpen={(tool) => (input.timelineDetail || tool.name === "execute" ? contentDefaultOpen(tool) : false)}
|
||||
toolOpen={(id) => input.disclosure.value(`${row().group.key}:tool:${id}`)}
|
||||
onToolOpenChange={(id, open) => input.disclosure.set(`${row().group.key}:tool:${id}`, open)}
|
||||
fileOpen={(path) =>
|
||||
|
|
@ -287,37 +286,6 @@ export function createSessionTimelineRowRenderer(input: {
|
|||
)
|
||||
}
|
||||
|
||||
if (row().group.type === "execute") {
|
||||
const tools = createMemo(() => {
|
||||
const group = row().group
|
||||
|
||||
if (group.type !== "execute") return []
|
||||
const contents = indexGroupContents(group.refs)
|
||||
|
||||
return group.refs.flatMap((ref) => {
|
||||
const content = contents.get(ref.messageID)?.get(ref.partID)
|
||||
|
||||
return content?.type === "tool" ? [content] : []
|
||||
})
|
||||
})
|
||||
|
||||
const defaultOpen = createMemo(() => {
|
||||
const tool = tools()[0]
|
||||
|
||||
return tool ? contentDefaultOpen(tool) : undefined
|
||||
})
|
||||
|
||||
return (
|
||||
<SessionExecuteToolGroup
|
||||
tools={tools()}
|
||||
defaultOpen={defaultOpen()}
|
||||
open={input.disclosure.value(row().group.key) ?? defaultOpen()}
|
||||
onOpenChange={(open) => input.disclosure.set(row().group.key, open)}
|
||||
onSizeChange={onSizeChange}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
if (row().group.type === "file") {
|
||||
const tools = createMemo(() => {
|
||||
const group = row().group
|
||||
|
|
@ -414,6 +382,8 @@ export function createSessionTimelineRowRenderer(input: {
|
|||
}
|
||||
|
||||
function contentDefaultOpen(item: SessionMessageAssistant["content"][number]) {
|
||||
if (item.type === "tool" && item.name === "execute") return true
|
||||
|
||||
if (input.timelineDetail) {
|
||||
const category = timelineCategory(item)
|
||||
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ export const ExecuteCode = {
|
|||
render: () => (
|
||||
<CurrentSessionTimelineStory
|
||||
title="Execute code"
|
||||
description="Consecutive Code Mode executions merge into one list of the tools their scripts called."
|
||||
description="Each Code Mode execution lists the tools its script called."
|
||||
document={executeCodeDocument}
|
||||
width="786px"
|
||||
shellToolDefaultOpen
|
||||
|
|
@ -196,7 +196,7 @@ export const ExecuteGrouped = {
|
|||
render: () => (
|
||||
<CurrentSessionTimelineStory
|
||||
title="Execute grouped"
|
||||
description="Collapsed executions inside a tool group still merge into one list of the tools their scripts called."
|
||||
description="Executions inside a tool group open by default to the tools their scripts called."
|
||||
document={executeCodeDocument}
|
||||
width="786px"
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ export type PartGroup =
|
|||
}
|
||||
| {
|
||||
key: string
|
||||
type: "file" | "read" | "execute"
|
||||
type: "file" | "read"
|
||||
refs: PartRef[]
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import { Dynamic } from "solid-js/web"
|
|||
import { type SessionSummary, useData } from "../context"
|
||||
import { useFileComponent } from "@opencode/ui/context/file"
|
||||
import { type UiI18n, useI18n } from "@opencode/ui/context/i18n"
|
||||
import { BasicTool, GenericTool, type BasicToolProps } from "../components/basic-tool"
|
||||
import { BasicTool, GenericTool } from "../components/basic-tool"
|
||||
import { FileIcon } from "@opencode/ui/file-icon"
|
||||
import { Icon } from "@opencode/ui/icon"
|
||||
import { ToolErrorCard } from "../components/tool-error-card"
|
||||
|
|
@ -504,15 +504,7 @@ export function CurrentContextToolGroup(props: {
|
|||
}
|
||||
|
||||
const title = names() || i18n.plural("ui.messagePart.context.thought", thoughts)
|
||||
|
||||
// Adjacent executions render as one merged list, so they count once.
|
||||
const count =
|
||||
props.parts.filter(
|
||||
(part, index) =>
|
||||
(part.type === "tool" || part.type === "shell") &&
|
||||
!(part.type === "tool" && part.name === "execute" && isExecute(props.parts[index - 1])),
|
||||
).length || thoughts
|
||||
|
||||
const count = props.parts.filter((part) => part.type === "tool" || part.type === "shell").length || thoughts
|
||||
const text = i18n.plural("ui.messagePart.tools.used", count, { tools: title })
|
||||
const index = text.indexOf(title)
|
||||
const before = text.slice(0, index).trim()
|
||||
|
|
@ -561,12 +553,6 @@ export function CurrentContextToolGroup(props: {
|
|||
return groups
|
||||
}
|
||||
|
||||
if (tool.name === "execute" && Array.isArray(previous) && previous[0] && previous[0].name === "execute") {
|
||||
previous.push(tool)
|
||||
|
||||
return groups
|
||||
}
|
||||
|
||||
if (
|
||||
tool.name === "skill" &&
|
||||
tool.state.status !== "error" &&
|
||||
|
|
@ -719,142 +705,129 @@ export function CurrentContextToolGroup(props: {
|
|||
return (
|
||||
<div data-slot="context-tool-group-item">
|
||||
<Show
|
||||
when={tool().name !== "execute"}
|
||||
when={!currentToolGroupedRead(tool())}
|
||||
fallback={
|
||||
<CurrentExecuteToolGroup
|
||||
<CurrentReadToolGroup
|
||||
tools={group()}
|
||||
defaultOpen
|
||||
open={props.toolOpen?.(tool().id) ?? true}
|
||||
open={props.toolOpen?.(tool().id)}
|
||||
onOpenChange={(open) => props.onToolOpenChange?.(tool().id, open)}
|
||||
onSizeChange={props.onSizeChange}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<Show
|
||||
when={!currentToolGroupedRead(tool())}
|
||||
when={tool().state.status !== "error" && ["glob", "grep", "list"].includes(tool().name)}
|
||||
fallback={
|
||||
<CurrentReadToolGroup
|
||||
tools={group()}
|
||||
open={props.toolOpen?.(tool().id)}
|
||||
onOpenChange={(open) => props.onToolOpenChange?.(tool().id, open)}
|
||||
onSizeChange={props.onSizeChange}
|
||||
/>
|
||||
<Show
|
||||
when={
|
||||
tool().name === "skill" && group().length > 1 && skills().length === group().length
|
||||
}
|
||||
fallback={
|
||||
<Show
|
||||
when={isFileChangeTool(tool())}
|
||||
fallback={
|
||||
<ToolDisplay
|
||||
id={tool().id}
|
||||
tool={tool().name}
|
||||
input={currentToolInput(tool())}
|
||||
metadata={currentToolMetadata(tool())}
|
||||
output={currentToolOutput(tool())}
|
||||
error={currentToolError(tool())}
|
||||
status={tool().state.status}
|
||||
defaultOpen={props.toolDefaultOpen?.(tool()) ?? false}
|
||||
open={props.toolOpen?.(tool().id) ?? props.toolDefaultOpen?.(tool())}
|
||||
onOpenChange={(open) => props.onToolOpenChange?.(tool().id, open)}
|
||||
deferContent
|
||||
virtualizeDiff={false}
|
||||
onContentRendered={props.onSizeChange}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<CurrentFileToolGroup
|
||||
tools={group()}
|
||||
fileOpen={
|
||||
props.fileOpen &&
|
||||
((path) => props.fileOpen?.(`${patchKeys().get(tool())}:${path}`))
|
||||
}
|
||||
onFileOpenChange={
|
||||
props.onFileOpenChange &&
|
||||
((path, open) =>
|
||||
props.onFileOpenChange?.(`${patchKeys().get(tool())}:${path}`, open))
|
||||
}
|
||||
onSizeChange={props.onSizeChange}
|
||||
/>
|
||||
</Show>
|
||||
}
|
||||
>
|
||||
<div
|
||||
data-component="tool-loaded-item"
|
||||
data-timeline-part-ids={group()
|
||||
.map((item) => item.id)
|
||||
.join(",")}
|
||||
aria-label={i18n.plural("ui.tool.loadedSkills", skills().length, {
|
||||
name: skills().join(", "),
|
||||
})}
|
||||
>
|
||||
<span data-slot="tool-loaded-label" aria-hidden="true">
|
||||
{loaded().split(marker)[0]?.trim()}
|
||||
</span>
|
||||
<span data-slot="tool-loaded-value" aria-hidden="true">
|
||||
<For each={skills()}>
|
||||
{(name, index) => (
|
||||
<>
|
||||
<Show when={index() > 0}>, </Show>
|
||||
<TextShimmer
|
||||
as="span"
|
||||
text={name}
|
||||
active={["streaming", "running"].includes(group()[index()]!.state.status)}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</For>
|
||||
</span>
|
||||
<Show when={loaded().split(marker)[1]?.trim()}>
|
||||
{(suffix) => (
|
||||
<span data-slot="tool-loaded-kind" aria-hidden="true">
|
||||
{suffix()}
|
||||
</span>
|
||||
)}
|
||||
</Show>
|
||||
</div>
|
||||
</Show>
|
||||
}
|
||||
>
|
||||
<Show
|
||||
when={tool().state.status !== "error" && ["glob", "grep", "list"].includes(tool().name)}
|
||||
fallback={
|
||||
<Show
|
||||
when={
|
||||
tool().name === "skill" && group().length > 1 && skills().length === group().length
|
||||
}
|
||||
fallback={
|
||||
<Show
|
||||
when={isFileChangeTool(tool())}
|
||||
fallback={
|
||||
<ToolDisplay
|
||||
id={tool().id}
|
||||
tool={tool().name}
|
||||
input={currentToolInput(tool())}
|
||||
metadata={currentToolMetadata(tool())}
|
||||
output={currentToolOutput(tool())}
|
||||
error={currentToolError(tool())}
|
||||
status={tool().state.status}
|
||||
defaultOpen={props.toolDefaultOpen?.(tool()) ?? false}
|
||||
open={props.toolOpen?.(tool().id) ?? props.toolDefaultOpen?.(tool())}
|
||||
onOpenChange={(open) => props.onToolOpenChange?.(tool().id, open)}
|
||||
deferContent
|
||||
virtualizeDiff={false}
|
||||
onContentRendered={props.onSizeChange}
|
||||
<div data-component="tool-trigger">
|
||||
<div data-slot="basic-tool-tool-trigger-content">
|
||||
<div data-slot="basic-tool-tool-info">
|
||||
<div data-slot="basic-tool-tool-info-structured">
|
||||
<div data-slot="basic-tool-tool-info-main">
|
||||
<span data-slot="basic-tool-tool-title">
|
||||
<TextShimmer
|
||||
text={trigger().title}
|
||||
active={
|
||||
tool().state.status === "streaming" || tool().state.status === "running"
|
||||
}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<CurrentFileToolGroup
|
||||
tools={group()}
|
||||
fileOpen={
|
||||
props.fileOpen &&
|
||||
((path) => props.fileOpen?.(`${patchKeys().get(tool())}:${path}`))
|
||||
}
|
||||
onFileOpenChange={
|
||||
props.onFileOpenChange &&
|
||||
((path, open) =>
|
||||
props.onFileOpenChange?.(`${patchKeys().get(tool())}:${path}`, open))
|
||||
}
|
||||
onSizeChange={props.onSizeChange}
|
||||
/>
|
||||
</Show>
|
||||
}
|
||||
>
|
||||
<div
|
||||
data-component="tool-loaded-item"
|
||||
data-timeline-part-ids={group()
|
||||
.map((item) => item.id)
|
||||
.join(",")}
|
||||
aria-label={i18n.plural("ui.tool.loadedSkills", skills().length, {
|
||||
name: skills().join(", "),
|
||||
})}
|
||||
>
|
||||
<span data-slot="tool-loaded-label" aria-hidden="true">
|
||||
{loaded().split(marker)[0]?.trim()}
|
||||
</span>
|
||||
<span data-slot="tool-loaded-value" aria-hidden="true">
|
||||
<For each={skills()}>
|
||||
{(name, index) => (
|
||||
<>
|
||||
<Show when={index() > 0}>, </Show>
|
||||
<TextShimmer
|
||||
as="span"
|
||||
text={name}
|
||||
active={["streaming", "running"].includes(group()[index()]!.state.status)}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</span>
|
||||
<Show when={trigger().subtitle}>
|
||||
{(subtitle) => <span data-slot="basic-tool-tool-subtitle">{subtitle()}</span>}
|
||||
</Show>
|
||||
<For each={trigger().args}>
|
||||
{(arg) => <span data-slot="basic-tool-tool-arg">{arg}</span>}
|
||||
</For>
|
||||
</span>
|
||||
<Show when={loaded().split(marker)[1]?.trim()}>
|
||||
{(suffix) => (
|
||||
<span data-slot="tool-loaded-kind" aria-hidden="true">
|
||||
{suffix()}
|
||||
</span>
|
||||
</div>
|
||||
<Show when={trigger().matches}>
|
||||
{(matches) => (
|
||||
<>
|
||||
<span data-slot="context-tool-group-dot" />
|
||||
<span data-slot="context-tool-group-matches">{matches()}</span>
|
||||
</>
|
||||
)}
|
||||
</Show>
|
||||
</div>
|
||||
</Show>
|
||||
}
|
||||
>
|
||||
<div data-component="tool-trigger">
|
||||
<div data-slot="basic-tool-tool-trigger-content">
|
||||
<div data-slot="basic-tool-tool-info">
|
||||
<div data-slot="basic-tool-tool-info-structured">
|
||||
<div data-slot="basic-tool-tool-info-main">
|
||||
<span data-slot="basic-tool-tool-title">
|
||||
<TextShimmer
|
||||
text={trigger().title}
|
||||
active={
|
||||
tool().state.status === "streaming" || tool().state.status === "running"
|
||||
}
|
||||
/>
|
||||
</span>
|
||||
<Show when={trigger().subtitle}>
|
||||
{(subtitle) => <span data-slot="basic-tool-tool-subtitle">{subtitle()}</span>}
|
||||
</Show>
|
||||
<For each={trigger().args}>
|
||||
{(arg) => <span data-slot="basic-tool-tool-arg">{arg}</span>}
|
||||
</For>
|
||||
</div>
|
||||
<Show when={trigger().matches}>
|
||||
{(matches) => (
|
||||
<>
|
||||
<span data-slot="context-tool-group-dot" />
|
||||
<span data-slot="context-tool-group-matches">{matches()}</span>
|
||||
</>
|
||||
)}
|
||||
</Show>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Show>
|
||||
</div>
|
||||
</Show>
|
||||
</Show>
|
||||
</div>
|
||||
|
|
@ -870,10 +843,6 @@ export function CurrentContextToolGroup(props: {
|
|||
)
|
||||
}
|
||||
|
||||
function isExecute(part: ContextGroupPart | undefined) {
|
||||
return part?.type === "tool" && part.name === "execute"
|
||||
}
|
||||
|
||||
export function CurrentReadToolGroup(props: {
|
||||
tools: SessionMessageAssistantTool[]
|
||||
open?: boolean
|
||||
|
|
@ -1947,120 +1916,54 @@ ToolRegistry.register({
|
|||
name: "execute",
|
||||
render(props) {
|
||||
const i18n = useI18n()
|
||||
const pending = () => props.status === "streaming" || props.status === "running"
|
||||
const calls = createMemo(() => executeToolCalls(props.metadata))
|
||||
const subtitle = createMemo(() => executeToolSubtitle(calls()))
|
||||
|
||||
return <ExecuteTool {...props} runs={[executeRun(props, i18n.t("ui.toolErrorCard.failed"))]} />
|
||||
// Like the TUI, only a runtime failure shows its output; a failed nested call is marked on its row.
|
||||
const error = createMemo(() => {
|
||||
if (props.status !== "error" && props.metadata.error !== true) return undefined
|
||||
const fallback = i18n.t("ui.toolErrorCard.failed")
|
||||
const text = stripAnsi((props.status === "error" ? props.error : undefined) || props.output || fallback)
|
||||
|
||||
return text.replace(/^Error:\s*/, "").trim() || fallback
|
||||
})
|
||||
|
||||
// A runtime failure belongs to the call that raised it; scripts can also fail outside any call.
|
||||
const owner = createMemo(() => calls().findLastIndex((call) => call.status === "error"))
|
||||
|
||||
const sawPending = pending()
|
||||
|
||||
return (
|
||||
<BasicTool
|
||||
{...props}
|
||||
icon="console"
|
||||
rail={false}
|
||||
hasContent={calls().length > 0 || !!error()}
|
||||
compact
|
||||
allowOpenWhilePending
|
||||
trigger={(open) => (
|
||||
<div data-slot="basic-tool-tool-info-structured">
|
||||
<div data-slot="basic-tool-tool-info-main">
|
||||
<span data-slot="basic-tool-tool-title">
|
||||
<TextShimmer text={i18n.t("ui.tool.execute")} active={pending()} />
|
||||
</span>
|
||||
<Show when={!open() && subtitle()}>{(text) => <ShellSubmessage text={text()} animate={sawPending} />}</Show>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
>
|
||||
<div data-component="execute-tool-calls">
|
||||
<Index each={calls()}>
|
||||
{(call, index) => <ExecuteCallRow call={call()} error={index === owner() ? error() : undefined} />}
|
||||
</Index>
|
||||
<Show when={owner() === -1 && error()}>{(text) => <ExecuteCallRow error={text()} />}</Show>
|
||||
</div>
|
||||
</BasicTool>
|
||||
)
|
||||
},
|
||||
})
|
||||
|
||||
// Consecutive Code Mode executions read as one list of the tools their scripts called.
|
||||
export function CurrentExecuteToolGroup(props: {
|
||||
tools: SessionMessageAssistantTool[]
|
||||
defaultOpen?: boolean
|
||||
open?: boolean
|
||||
onOpenChange?: (open: boolean) => void
|
||||
onSizeChange?: () => void
|
||||
}) {
|
||||
const i18n = useI18n()
|
||||
|
||||
const status = createMemo(
|
||||
() =>
|
||||
props.tools.find((tool) => tool.state.status === "streaming" || tool.state.status === "running")?.state.status ??
|
||||
"completed",
|
||||
)
|
||||
|
||||
return (
|
||||
<div
|
||||
data-component="tool-part-wrapper"
|
||||
data-timeline-part-id={props.tools.length === 1 ? props.tools[0]!.id : undefined}
|
||||
data-timeline-part-ids={props.tools.length > 1 ? props.tools.map((tool) => tool.id).join(",") : undefined}
|
||||
>
|
||||
<ExecuteTool
|
||||
runs={props.tools.map((tool) =>
|
||||
executeRun(
|
||||
{
|
||||
status: tool.state.status,
|
||||
metadata: currentToolMetadata(tool),
|
||||
output: currentToolOutput(tool),
|
||||
error: currentToolError(tool),
|
||||
},
|
||||
i18n.t("ui.toolErrorCard.failed"),
|
||||
),
|
||||
)}
|
||||
status={status()}
|
||||
defaultOpen={props.defaultOpen}
|
||||
open={props.open}
|
||||
onOpenChange={(open) => {
|
||||
props.onOpenChange?.(open)
|
||||
props.onSizeChange?.()
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
type ExecuteRun = { calls: ExecuteToolCall[]; error?: string }
|
||||
|
||||
// Like the TUI, only a runtime failure shows its output; a failed nested call is marked on its row.
|
||||
function executeRun(
|
||||
props: { status?: string; metadata: Record<string, unknown>; output?: string; error?: string },
|
||||
fallback: string,
|
||||
): ExecuteRun {
|
||||
const calls = executeToolCalls(props.metadata)
|
||||
|
||||
if (props.status !== "error" && props.metadata.error !== true) return { calls }
|
||||
const error = stripAnsi((props.status === "error" ? props.error : undefined) || props.output || fallback)
|
||||
|
||||
return { calls, error: error.replace(/^Error:\s*/, "").trim() || fallback }
|
||||
}
|
||||
|
||||
function ExecuteTool(props: Omit<BasicToolProps, "icon" | "trigger" | "children"> & { runs: ExecuteRun[] }) {
|
||||
const i18n = useI18n()
|
||||
const pending = () => props.status === "streaming" || props.status === "running"
|
||||
const calls = createMemo(() => props.runs.flatMap((run) => run.calls))
|
||||
const subtitle = createMemo(() => executeToolSubtitle(calls()))
|
||||
|
||||
const sawPending = pending()
|
||||
|
||||
return (
|
||||
<BasicTool
|
||||
{...props}
|
||||
icon="console"
|
||||
rail={false}
|
||||
hasContent={props.runs.some((run) => run.calls.length > 0 || run.error)}
|
||||
compact
|
||||
allowOpenWhilePending
|
||||
trigger={(open) => (
|
||||
<div data-slot="basic-tool-tool-info-structured">
|
||||
<div data-slot="basic-tool-tool-info-main">
|
||||
<span data-slot="basic-tool-tool-title">
|
||||
<TextShimmer text={i18n.t("ui.tool.execute")} active={pending()} />
|
||||
</span>
|
||||
<Show when={!open() && subtitle()}>{(text) => <ShellSubmessage text={text()} animate={sawPending} />}</Show>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
>
|
||||
<div data-component="execute-tool-calls">
|
||||
<Index each={props.runs}>
|
||||
{(run) => {
|
||||
// A runtime failure belongs to the call that raised it; scripts can also fail outside any call.
|
||||
const owner = createMemo(() => run().calls.findLastIndex((call) => call.status === "error"))
|
||||
|
||||
return (
|
||||
<>
|
||||
<Index each={run().calls}>
|
||||
{(call, index) => <ExecuteCallRow call={call()} error={index === owner() ? run().error : undefined} />}
|
||||
</Index>
|
||||
<Show when={owner() === -1 && run().error}>{(error) => <ExecuteCallRow error={error()} />}</Show>
|
||||
</>
|
||||
)
|
||||
}}
|
||||
</Index>
|
||||
</div>
|
||||
</BasicTool>
|
||||
)
|
||||
}
|
||||
|
||||
function ExecuteCallRow(props: { call?: ExecuteToolCall; error?: string }) {
|
||||
const [open, setOpen] = createSignal(false)
|
||||
const args = createMemo(() => (props.call ? executeToolCallArgs(props.call) : []))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue