fix(ui): group consecutive chat tool calls and simplify the chat controls

This commit is contained in:
sam committed 2026-10-24 11:45:57 +11:00
1 parent 3af3717a90
commit 004c2b82bf
8 files changed
+139 -118

No files matched your search

+26 -7
View File
@@ -1,4 +1,6 @@
<script setup lang="ts">
import { computed } from "vue";
import { Bubble, BubbleContent } from "@/components/ui/bubble";
import { Trace } from "@/components/ui/trace";
import { CodeBlockCopyButton } from "@/components/ui/code-block";
@@ -6,6 +8,7 @@ import { Message, MessageContent, MessageFooter } from "@/components/ui/message"
import ChatAttachment from "./ChatAttachment.vue";
import ChatMarkdown from "./ChatMarkdown.vue";
import ChatToolCall from "./ChatToolCall.vue";
import ChatToolGroup from "./ChatToolGroup.vue";
import type { ChatMedia, ChatToolCall as ToolCall } from "./state";
/**
@@ -15,7 +18,7 @@ import type { ChatMedia, ChatToolCall as ToolCall } from "./state";
* transcript offers belongs to the bubble rather than beside it. A finished
* reply carries a copy action beneath it.
*/
withDefaults(
const props = withDefaults(
defineProps<{
text: string;
tools?: ToolCall[];
@@ -27,6 +30,24 @@ withDefaults(
}>(),
{ tools: () => [], media: () => [], assistant: false, streaming: false },
);
// Consecutive calls fold into one counted line. A navigation chip is an
// action for the operator, so it always stands alone and ends the run.
const runs = computed(() => {
const out: ToolCall[][] = [];
let open = false;
for (const tool of props.tools) {
if (tool.path) {
out.push([tool]);
open = false;
} else if (open) out[out.length - 1].push(tool);
else {
out.push([tool]);
open = true;
}
}
return out;
});
</script>
<template>
@@ -35,12 +56,10 @@ withDefaults(
<Bubble :variant="assistant ? 'muted' : 'tinted'" class="max-w-[min(78ch,92%)]">
<BubbleContent class="[overflow-wrap:anywhere]">
<Trace v-if="assistant && tools.length" class="mb-2">
<ChatToolCall
v-for="(tool, i) in tools"
:key="i"
:tool="tool"
:streaming="streaming"
/>
<template v-for="(run, i) in runs" :key="i">
<ChatToolGroup v-if="run.length > 1" :tools="run" :streaming="streaming" />
<ChatToolCall v-else :tool="run[0]" :streaming="streaming" />
</template>
</Trace>
<div v-if="media.length" class="mb-2 flex flex-wrap gap-1.5">
<ChatAttachment
+2
View File
@@ -208,6 +208,7 @@ function onKeydown(event: KeyboardEvent): void {
/>
<div class="flex flex-none items-center gap-2">
<slot name="actions" />
<!-- Only while a turn is arriving: a Stop with nothing to stop is a
button that lies about what the panel is doing. -->
<Button v-if="isSending" variant="outline" size="sm" @click="stopTurn"
@@ -225,6 +226,7 @@ function onKeydown(event: KeyboardEvent): void {
<Button
v-else
size="sm"
:variant="composerText.trim() ? 'default' : 'secondary'"
:disabled="!composerText.trim()"
@click="sendMessage()"
>{{ isSending ? "Queue" : "Send" }}</Button
+15 -14
View File
@@ -69,7 +69,7 @@ function usePrompt(text: string): void {
:class="
cn(
'pointer-events-auto flex w-full max-w-xl flex-col rounded-lg border transition-[border-color,background-color,box-shadow] duration-200',
expanded ? 'border-border bg-popover shadow-[var(--shadow-md)]' : 'border-transparent bg-transparent',
expanded ? 'border-border-strong bg-popover shadow-[var(--shadow-md)]' : 'border-transparent bg-transparent',
)
"
>
@@ -88,19 +88,20 @@ function usePrompt(text: string): void {
<div v-if="expanded" class="flex h-[min(28rem,55dvh)] min-h-0 flex-col">
<ChatTranscript @prompt="usePrompt" />
</div>
<div class="relative" @focusin="expanded = true">
<ChatComposer ref="composer" :open="false" :bordered="expanded" :class="!expanded && 'border-t-0!'" />
<Button
v-if="!expanded"
variant="ghost"
size="icon-sm"
class="absolute top-1.5 right-1.5"
aria-label="Show conversation"
title="Show conversation"
@click="expanded = true"
>
<ChevronUp />
</Button>
<div @focusin="expanded = true">
<ChatComposer ref="composer" :open="false" :bordered="expanded" :class="!expanded && 'border-t-0!'">
<template v-if="!expanded" #actions>
<Button
variant="ghost"
size="icon-sm"
aria-label="Show conversation"
title="Show conversation"
@click="expanded = true"
>
<ChevronUp />
</Button>
</template>
</ChatComposer>
</div>
</aside>
</div>
+1 -1
View File
@@ -28,7 +28,7 @@ import {
* The menu behind the bar's one "more" button: the commands that act on the
* conversation itself rather than on what is being said (retry the last turn,
* undo it, rename the conversation, branch it, or look at what compressing it
* would drop), then the provider and model it runs on.
* would drop), then the model it runs on.
*
* Each one is the same command the server accepts from any other channel, so
* this is a set of buttons over the slash surface rather than a second way to
+29 -64
View File
@@ -1,28 +1,21 @@
<script setup lang="ts">
import { computed } from "vue";
import { Field, FieldLabel } from "@/components/ui/field";
import {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectLabel,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import {
currentModels,
selectedModel,
selectedProvider,
selectorData,
setModel,
setProvider,
statusText,
} from "./state";
import { selectedModel, selectorData, setModel, statusText } from "./state";
/**
* The chat's own settings: what the panel is doing right now, and the
* selectors the server offers. It sits in the session menu.
* The chat's own settings: what the panel is doing right now, and the model it
* runs on. A model id already names its provider, so there is one control. It
* sits in the session menu.
*
* reka-ui refuses an empty string as an item value (that is how it spells
* "nothing selected") while the wire reads an absent value as "use the
@@ -31,63 +24,35 @@ import {
*/
const DEFAULT = "__default__";
const providerValue = computed(() => selectedProvider.value || DEFAULT);
const modelValue = computed(() => selectedModel.value || DEFAULT);
function clear(value: unknown): string {
return value === DEFAULT ? "" : String(value ?? "");
}
// The server groups models by provider; one flat list stands in when it does not.
const groups = computed(() => {
const grouped = selectorData.value.models_by_provider || {};
const entries = Object.entries(grouped).filter(([, models]) => models.length);
return entries.length
? entries
: [["", selectorData.value.models || []] as [string, string[]]];
});
</script>
<template>
<div class="grid gap-3 p-2">
<div class="grid gap-1 p-1">
<span v-if="statusText !== 'Ready'" class="text-xs text-fg-subtle">{{ statusText }}</span>
<Field v-if="(selectorData.providers || []).length" class="gap-1">
<FieldLabel class="text-xs text-fg-muted">Provider</FieldLabel>
<Select
:model-value="providerValue"
@update:model-value="setProvider(clear($event))"
>
<SelectTrigger size="sm" class="w-full" aria-label="Provider">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectItem :value="DEFAULT">Default</SelectItem>
<SelectItem
v-for="provider in selectorData.providers || []"
:key="provider"
:value="provider"
>
{{ provider }}
</SelectItem>
</SelectGroup>
</SelectContent>
</Select>
</Field>
<Field class="gap-1">
<FieldLabel class="text-xs text-fg-muted">Model</FieldLabel>
<Select
:model-value="modelValue"
@update:model-value="setModel(clear($event))"
>
<SelectTrigger size="sm" class="w-full" aria-label="Model">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectItem :value="DEFAULT">Default</SelectItem>
<SelectItem
v-for="model in currentModels"
:key="model"
:value="model"
>{{ model }}</SelectItem
>
</SelectGroup>
</SelectContent>
</Select>
</Field>
<Select
:model-value="modelValue"
@update:model-value="setModel($event === DEFAULT ? '' : String($event ?? ''))"
>
<SelectTrigger size="sm" class="w-full" aria-label="Model">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem :value="DEFAULT">Default</SelectItem>
<SelectGroup v-for="[provider, models] in groups" :key="provider">
<SelectLabel v-if="provider">{{ provider }}</SelectLabel>
<SelectItem v-for="model in models" :key="model" :value="model">{{ model }}</SelectItem>
</SelectGroup>
</SelectContent>
</Select>
</div>
</template>
+52
View File
@@ -0,0 +1,52 @@
<script setup lang="ts">
import { Wrench } from "@lucide/vue";
import { computed } from "vue";
import {
TraceCollapsible,
TraceCollapsibleContent,
TraceCollapsibleTrigger,
TraceIcon,
TraceLine,
TraceTitle,
} from "@/components/ui/trace";
import ChatToolCall from "./ChatToolCall.vue";
import type { ChatToolCall as ToolCall } from "./state";
/**
* A run of consecutive tool calls as one counted line, "shell ×12, find ×1",
* opened to the individual calls. A failure anywhere in the run opens it.
*/
const props = defineProps<{ tools: ToolCall[]; streaming?: boolean }>();
const toolName = (tool: ToolCall) => tool.name || tool.Name || tool.tool || "tool";
const failed = (tool: ToolCall) => Boolean(tool.err || tool.Err || tool.failed);
const title = computed(() => {
const counts = new Map<string, number>();
for (const tool of props.tools) counts.set(toolName(tool), (counts.get(toolName(tool)) ?? 0) + 1);
return [...counts].map(([name, n]) => `${name} ×${n}`).join(", ");
});
const anyFailed = computed(() => props.tools.some(failed));
</script>
<template>
<TraceCollapsible :default-open="anyFailed">
<TraceCollapsibleTrigger>
<TraceLine :status="anyFailed ? 'error' : undefined">
<TraceIcon><Wrench /></TraceIcon>
<TraceTitle class="truncate">{{ title }}</TraceTitle>
</TraceLine>
</TraceCollapsibleTrigger>
<TraceCollapsibleContent>
<div class="flex flex-col gap-2">
<ChatToolCall
v-for="(tool, i) in tools"
:key="i"
:tool="tool"
:streaming="streaming && i === tools.length - 1"
/>
</div>
</TraceCollapsibleContent>
</TraceCollapsible>
</template>
+12 -5
View File
@@ -1,9 +1,16 @@
import type { ChatSession } from "./state";
const started = new Intl.DateTimeFormat(undefined, {
month: "short",
day: "numeric",
hour: "numeric",
minute: "2-digit",
});
// An untitled conversation is named by when it began, which tells two apart
// where a raw id cannot.
export function sessionTitle(session: ChatSession): string {
return (
session.title ||
session.branch_name ||
`Conversation ${session.session_id.slice(0, 8)}`
);
const named = session.title || session.branch_name;
if (named) return named;
return session.created_at ? started.format(new Date(session.created_at)) : "New chat";
}
+2 -27
View File
@@ -1,4 +1,4 @@
import { computed, onMounted, onUnmounted, ref, watch, type Ref } from "vue";
import { onMounted, onUnmounted, ref, watch, type Ref } from "vue";
import { api } from "@/lib/api";
import { channelID } from "./channel";
@@ -24,6 +24,7 @@ export interface ChatSession {
session_id: string;
title?: string;
branch_name?: string;
created_at?: string;
}
/** One slash command the server will accept. */
@@ -182,7 +183,6 @@ export const isLoadingSession = ref(false);
export const streamingTurn = ref<StreamingTurn | null>(null);
export const selectorData = ref<ChatSelectorData>({});
export const selectedProvider = ref("");
export const selectedModel = ref("");
export const commandSpecs = ref<ChatCommandSpec[]>([]);
@@ -190,14 +190,6 @@ export const commandMatches = ref<ChatCommandSpec[]>([]);
export const commandSelection = ref(0);
export const isCommandMenuOpen = ref(false);
export const currentModels = computed(() => {
const grouped = selectorData.value.models_by_provider || {};
const provider = selectedProvider.value;
return provider && grouped[provider]
? grouped[provider]
: selectorData.value.models || [];
});
/**
* How many layers inside the panel currently own Escape -- an open popover, a
* select inside one.
@@ -238,8 +230,6 @@ export async function refreshSessions(): Promise<void> {
sessions.value = sessionList;
selectorData.value = data;
const providers = data.providers || [];
selectedProvider.value = data.active_provider || providers[0] || "";
selectedModel.value = data.active_model || "";
commandSpecs.value = (data.commands || []).map((item) =>
@@ -335,21 +325,6 @@ export function promptSessionCommand(command: string, message: string): void {
if (value?.trim()) void runSessionCommand(`${command} ${value.trim()}`);
}
export async function setProvider(provider: string): Promise<void> {
selectedProvider.value = provider;
if (!provider) return;
try {
const result = await api.chatMessage<{ reply?: string }>(
channelID(),
`/model --provider ${provider}`,
);
statusText.value = result.reply || "Provider updated";
await refreshSessions();
} catch (err) {
statusText.value = `Provider update failed: ${(err as Error).message || err}`;
}
}
export async function setModel(model: string): Promise<void> {
selectedModel.value = model;
if (!model) return;