Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/session-ui/src/components/message-part.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,7 @@ PART_MAPPING["tool"] = function ToolPartDisplay(props) {
onOpenChange={props.onToolOpenChange ? handleToolOpenChange : undefined}
subtitle={taskSubtitle()}
href={taskHref()}
input={input()}
onSubtitleClick={(event) => {
if (!data.navigateToSession) return
if (event.button !== 0 || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return
Expand Down
44 changes: 40 additions & 4 deletions packages/session-ui/src/components/tool-error-card.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
color: var(--v2-text-text-muted);
}

[data-slot="collapsible-arrow"],
[data-slot="collapsible-arrow-icon"] {
[data-slot="collapsible-arrow"], [data-slot="collapsible-arrow-icon"] {
color: var(--v2-text-text-faint);
}

Expand All @@ -35,6 +34,32 @@
user-select: text;
}

[data-slot="tool-error-card-context"] {
display: flex;
align-items: baseline;
gap: 6px;
margin-bottom: 4px;
font-size: 12px;
line-height: 1.4;
}

[data-slot="tool-error-card-context-label"] {
color: var(--v2-text-text-muted);
flex-shrink: 0;
font-weight: 500;
}

[data-slot="tool-error-card-context-value"] {
color: var(--v2-text-text-base);
font-family: var(--v2-font-family-mono);
font-size: 11px;
word-break: break-all;
white-space: pre-wrap;
max-height: 60px;
overflow: hidden;
text-overflow: ellipsis;
}

> [data-component="collapsible"].tool-collapsible[data-open="true"] [data-slot="tool-error-card-content"] {
padding-right: 40px;
}
Expand All @@ -49,8 +74,7 @@
will-change: opacity;
}

&:hover [data-slot="tool-error-card-copy"],
&:focus-within [data-slot="tool-error-card-copy"] {
&:hover [data-slot="tool-error-card-copy"], &:focus-within [data-slot="tool-error-card-copy"] {
opacity: 1;
pointer-events: auto;
}
Expand Down Expand Up @@ -83,6 +107,18 @@ body:not([data-new-layout]) [data-component="card"][data-kind="tool-error-card"]
color: var(--icon-weaker);
}

[data-slot="tool-error-card-context"] {
color: var(--text-base);
}

[data-slot="tool-error-card-context-label"] {
color: var(--text-weak);
}

[data-slot="tool-error-card-context-value"] {
color: var(--text-base);
}

[data-slot="tool-error-card-content"] :where(*)::selection,
[data-slot="tool-error-card-content"] :where(*)::-moz-selection {
background: var(--surface-critical-base);
Expand Down
84 changes: 84 additions & 0 deletions packages/session-ui/src/components/tool-error-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,74 @@ import { IconButton } from "@opencode-ai/ui/icon-button"
import { Tooltip } from "@opencode-ai/ui/tooltip"
import { useI18n } from "@opencode-ai/ui/context/i18n"

function getToolContextLabel(tool: string, input: Record<string, unknown>, t: (key: string) => string): { label: string; value: string } | undefined {
switch (tool) {
case "bash":
case "shell": {
const command = typeof input.command === "string" ? input.command : undefined
if (command) return { label: t("ui.toolErrorCard.context.command"), value: command }
break
}
case "read": {
const filePath = typeof input.filePath === "string" ? input.filePath : undefined
if (filePath) return { label: t("ui.toolErrorCard.context.file"), value: filePath }
break
}
case "edit": {
const filePath = typeof input.filePath === "string" ? input.filePath : undefined
if (filePath) return { label: t("ui.toolErrorCard.context.file"), value: filePath }
break
}
case "write": {
const filePath = typeof input.filePath === "string" ? input.filePath : undefined
if (filePath) return { label: t("ui.toolErrorCard.context.file"), value: filePath }
break
}
case "webfetch": {
const url = typeof input.url === "string" ? input.url : undefined
if (url) return { label: t("ui.toolErrorCard.context.url"), value: url }
break
}
case "websearch": {
const query = typeof input.query === "string" ? input.query : undefined
if (query) return { label: t("ui.toolErrorCard.context.query"), value: query }
break
}
case "glob": {
const pattern = typeof input.pattern === "string" ? input.pattern : undefined
const path = typeof input.path === "string" ? input.path : undefined
if (pattern) return { label: t("ui.toolErrorCard.context.pattern"), value: path ? `${pattern} (${path})` : pattern }
break
}
case "grep": {
const pattern = typeof input.pattern === "string" ? input.pattern : undefined
const path = typeof input.path === "string" ? input.path : undefined
if (pattern) return { label: t("ui.toolErrorCard.context.pattern"), value: path ? `${pattern} (${path})` : pattern }
break
}
case "list": {
const path = typeof input.path === "string" ? input.path : undefined
if (path) return { label: t("ui.toolErrorCard.context.directory"), value: path }
break
}
case "task": {
const description = typeof input.description === "string" ? input.description : undefined
if (description) return { label: t("ui.toolErrorCard.context.task"), value: description }
break
}
case "patch":
case "apply_patch": {
const files = Array.isArray(input.files) ? input.files : undefined
if (files?.length) {
const fileNames = files.map((f: any) => typeof f === "string" ? f : f?.path).filter(Boolean)
if (fileNames.length) return { label: t("ui.toolErrorCard.context.files"), value: fileNames.join(", ") }
}
break
}
}
return undefined
}

export interface ToolErrorCardProps extends Omit<ComponentProps<typeof Card>, "children" | "variant"> {
tool: string
error: string
Expand All @@ -17,6 +85,7 @@ export interface ToolErrorCardProps extends Omit<ComponentProps<typeof Card>, "c
subtitle?: string
href?: string
onSubtitleClick?: (event: MouseEvent) => void
input?: Record<string, unknown>
}

export function ToolErrorCard(props: ToolErrorCardProps) {
Expand All @@ -37,6 +106,7 @@ export function ToolErrorCard(props: ToolErrorCardProps) {
"subtitle",
"href",
"onSubtitleClick",
"input",
])
const setOpen = (value: boolean) => {
if (props.open === undefined) setState("open", value)
Expand Down Expand Up @@ -86,6 +156,12 @@ export function ToolErrorCard(props: ToolErrorCardProps) {
return parts.slice(1).join(": ").trim() || cleaned()
})

const context = createMemo(() => {
const input = split.input as Record<string, unknown> | undefined
if (!input) return undefined
return getToolContextLabel(split.tool, input, i18n.t)
})

const copy = async () => {
const text = cleaned()
if (!text) return
Expand Down Expand Up @@ -153,6 +229,14 @@ export function ToolErrorCard(props: ToolErrorCardProps) {
</Tooltip>
</div>
</Show>
<Show when={context()}>
{(ctx) => (
<div data-slot="tool-error-card-context">
<span data-slot="tool-error-card-context-label">{ctx().label}</span>
<span data-slot="tool-error-card-context-value">{ctx().value}</span>
</div>
)}
</Show>
<Show when={body()}>{(value) => <CardDescription>{value()}</CardDescription>}</Show>
</div>
</Collapsible.Content>
Expand Down
8 changes: 8 additions & 0 deletions packages/ui/src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ export const dict: Record<string, string> = {
"ui.basicTool.called": "Called `{{tool}}`",
"ui.toolErrorCard.failed": "Failed",
"ui.toolErrorCard.copyError": "Copy error",
"ui.toolErrorCard.context.command": "Command",
"ui.toolErrorCard.context.file": "File",
"ui.toolErrorCard.context.url": "URL",
"ui.toolErrorCard.context.query": "Query",
"ui.toolErrorCard.context.pattern": "Pattern",
"ui.toolErrorCard.context.directory": "Directory",
"ui.toolErrorCard.context.task": "Task",
"ui.toolErrorCard.context.files": "Files",

"ui.common.file.one": "file",
"ui.common.file.other": "files",
Expand Down
Loading