Files
archie/ui/src/chat/ChatToolCall.vue
T
sam 48e605a545
Quality / check (push) Successful in 6m33s
deploy / gate (push) Successful in 4m49s
deploy / archied-image (push) Successful in 3m22s
deploy / agent-image (push) Successful in 11s
deploy / dist-zip (push) Skipped
fix(ui): dead tokens replaced or deleted — text-ok, --radius-lg, real surface (#1740)
text-success was not a token (now text-ok) in ChatToolCall and BindEvent;
var(--radius) is undefined (now var(--radius-lg)) in input-group and Sonner;
Sonner's hsl(var(--popover) / 0.9) wrapped a hex (now a plain hex); the
undefined cn-font-heading class is deleted from the nine title components.
2026-11-07 01:06:42 +11:00

111 lines
4.1 KiB
Vue

<script setup lang="ts">
import { Spinner } from "@/components/ui/spinner";
import { CircleCheck, CircleX } from "@lucide/vue";
import { computed } from "vue";
import { CodeBlock, CodeBlockContent } from "@/components/ui/code-block";
import { duration as formatDuration } from "@/lib/format";
import {
TraceCollapsible,
TraceCollapsibleContent,
TraceCollapsibleTrigger,
TraceIcon,
TraceLine,
TraceTitle,
} from "@/components/ui/trace";
import ChatNavChip from "./ChatNavChip.vue";
import type { ChatToolCall } from "./state";
/**
* One tool call: the name, and what came back once it is opened.
*
* A quiet line rather than the point of the reply: it is evidence for the
* answer under it, so it is dim, and a failed call is the only thing here that
* raises its voice. The parameters it was given and its outcome are folded away
* until asked for. Rendered inside a Trace, which an empty list never creates,
* so a turn that called no tools looks untouched.
*/
const props = defineProps<{
tool: ChatToolCall;
/** The turn is still arriving, so a call with no outcome yet is running. */
streaming?: boolean;
}>();
const name = computed(
() => props.tool.name || props.tool.Name || props.tool.tool || "tool",
);
const parameters = computed(
() => props.tool.parameters || props.tool.Parameters || "",
);
const failed = computed(() =>
Boolean(props.tool.err || props.tool.Err || props.tool.failed),
);
// A recorded turn reports its outcome in summary, a live frame in text, and a
// failure may only carry the error.
const outcome = computed(
() =>
props.tool.summary ||
props.tool.Summary ||
props.tool.text ||
props.tool.err ||
props.tool.Err ||
"",
);
const running = computed(() => !outcome.value && !failed.value && !!props.streaming);
const duration = computed(() => formatDuration(props.tool.duration_ms));
// The row shows the call's main value, as "git diff --stat" rather than its
// JSON: the first string argument, else its arguments as key: value pairs.
const argument = computed(() => {
try {
const args: unknown = JSON.parse(parameters.value);
if (args && typeof args === "object" && !Array.isArray(args)) {
const first = Object.values(args).find((v) => typeof v === "string" && v);
if (typeof first === "string") return first.split("\n", 1)[0];
return Object.entries(args)
.map(([key, value]) => `${key}: ${typeof value === "object" ? JSON.stringify(value) : value}`)
.join(", ");
}
} catch {
// Truncated or not JSON: show it as it came.
}
return parameters.value.split("\n", 1)[0];
});
const detail = computed(() =>
[parameters.value && `> ${parameters.value}`, outcome.value].filter(Boolean).join("\n\n"),
);
</script>
<template>
<ChatNavChip v-if="tool.path" :path="tool.path" :label="tool.label" />
<TraceCollapsible v-else-if="detail" :default-open="failed">
<TraceCollapsibleTrigger>
<TraceLine :status="failed ? 'error' : running ? 'running' : undefined">
<TraceIcon>
<CircleX v-if="failed" />
<Spinner v-else-if="running" />
<CircleCheck v-else class="text-ok" />
</TraceIcon>
<span class="font-mono text-foreground">{{ name }}</span>
<TraceTitle class="font-mono text-caption">{{ argument }}</TraceTitle>
<span v-if="duration" class="shrink-0 text-caption tabular-nums">{{ duration }}</span>
</TraceLine>
</TraceCollapsibleTrigger>
<TraceCollapsibleContent>
<CodeBlock size="sm">
<CodeBlockContent wrap class="max-h-64">{{ detail }}</CodeBlockContent>
</CodeBlock>
</TraceCollapsibleContent>
</TraceCollapsible>
<TraceLine v-else :status="failed ? 'error' : running ? 'running' : undefined">
<TraceIcon>
<CircleX v-if="failed" />
<Spinner v-else-if="running" />
<CircleCheck v-else class="text-ok" />
</TraceIcon>
<span class="font-mono text-foreground">{{ name }}</span>
<TraceTitle class="font-mono text-caption">{{ argument }}</TraceTitle>
<span v-if="duration" class="shrink-0 text-caption tabular-nums">{{ duration }}</span>
</TraceLine>
</template>