Files
archie/ui/src/chat/ChatToolCall.vue
T

79 lines
2.5 KiB
Vue

<script setup lang="ts">
import { Wrench } from "@lucide/vue";
import { computed } from "vue";
import { CodeBlock, CodeBlockContent } from "@/components/ui/code-block";
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 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><Wrench /></TraceIcon>
<TraceTitle>{{ name }}</TraceTitle>
</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><Wrench /></TraceIcon>
<TraceTitle>{{ name }}</TraceTitle>
</TraceLine>
</template>