refactor: format markdown files using prettier, fix spelling concerns, reduce Taskfile bloat
This commit is contained in:
608 files changed
+63317
-10219
No files matched your search
@@ -33,7 +33,12 @@ withDefaults(
|
||||
"
|
||||
>
|
||||
<div v-if="assistant && tools.length" class="mb-2 grid gap-0.5 text-xs">
|
||||
<ChatToolCall v-for="(tool, i) in tools" :key="i" :tool="tool" :streaming="streaming" />
|
||||
<ChatToolCall
|
||||
v-for="(tool, i) in tools"
|
||||
:key="i"
|
||||
:tool="tool"
|
||||
:streaming="streaming"
|
||||
/>
|
||||
</div>
|
||||
<ChatMarkdown v-if="assistant" :text="text" />
|
||||
<div v-else class="whitespace-pre-wrap">{{ text }}</div>
|
||||
|
||||
@@ -69,7 +69,11 @@ function choose(index: number): void {
|
||||
if (!spec || !input) return;
|
||||
// Completing the command replaces the token the caret sits in, which is
|
||||
// decided by the same rule that found the matches.
|
||||
const { text, cursor } = applyCommand(input.value, input.selectionStart ?? input.value.length, spec.command);
|
||||
const { text, cursor } = applyCommand(
|
||||
input.value,
|
||||
input.selectionStart ?? input.value.length,
|
||||
spec.command,
|
||||
);
|
||||
composerText.value = text;
|
||||
closeCommandMenu();
|
||||
void nextTick(() => {
|
||||
@@ -83,7 +87,11 @@ function onKeydown(event: KeyboardEvent): void {
|
||||
if (isCommandMenuOpen.value && commandMatches.value.length) {
|
||||
// A command typed in full is sent rather than completed, so Enter never
|
||||
// re-enters the command the palette was offering.
|
||||
if (event.key === "Enter" && plain && isExactCommand(commandSpecs.value, composerText.value)) {
|
||||
if (
|
||||
event.key === "Enter" &&
|
||||
plain &&
|
||||
isExactCommand(commandSpecs.value, composerText.value)
|
||||
) {
|
||||
event.preventDefault();
|
||||
closeCommandMenu();
|
||||
void sendMessage();
|
||||
@@ -120,7 +128,9 @@ function onKeydown(event: KeyboardEvent): void {
|
||||
|
||||
<template>
|
||||
<div class="border-t p-3">
|
||||
<div class="relative flex items-end gap-2 rounded-xl border border-border-strong bg-muted px-3 py-2.5">
|
||||
<div
|
||||
class="relative flex items-end gap-2 rounded-xl border border-border-strong bg-muted px-3 py-2.5"
|
||||
>
|
||||
<Textarea
|
||||
ref="field"
|
||||
:model-value="composerText"
|
||||
@@ -142,8 +152,15 @@ function onKeydown(event: KeyboardEvent): void {
|
||||
<div class="flex flex-none items-center gap-2">
|
||||
<!-- 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">Stop</Button>
|
||||
<Button size="sm" :disabled="isSending || !composerText.trim()" @click="sendMessage()">Send</Button>
|
||||
<Button v-if="isSending" variant="outline" size="sm" @click="stopTurn"
|
||||
>Stop</Button
|
||||
>
|
||||
<Button
|
||||
size="sm"
|
||||
:disabled="isSending || !composerText.trim()"
|
||||
@click="sendMessage()"
|
||||
>Send</Button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -8,7 +8,11 @@ const emit = defineEmits<{ prompt: [text: string] }>();
|
||||
|
||||
// Prompts an operator might actually ask, rather than demonstrations of the
|
||||
// feature.
|
||||
const PROMPTS = ["Summarise active tasks", "Show running agents", "Check system status"];
|
||||
const PROMPTS = [
|
||||
"Summarise active tasks",
|
||||
"Show running agents",
|
||||
"Check system status",
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -18,8 +22,12 @@ const PROMPTS = ["Summarise active tasks", "Show running agents", "Check system
|
||||
class="mx-auto mb-3 grid size-9 place-items-center rounded-xl border border-border-strong font-bold text-link"
|
||||
>A</span
|
||||
>
|
||||
<h2 class="text-lg font-semibold tracking-[-0.02em]">What are we working on?</h2>
|
||||
<p class="mt-2 mb-4 text-sm text-fg-muted">Ask Archie anything, or start with one of these prompts.</p>
|
||||
<h2 class="text-lg font-semibold tracking-[-0.02em]">
|
||||
What are we working on?
|
||||
</h2>
|
||||
<p class="mt-2 mb-4 text-sm text-fg-muted">
|
||||
Ask Archie anything, or start with one of these prompts.
|
||||
</p>
|
||||
<div class="grid gap-2">
|
||||
<button
|
||||
v-for="prompt in PROMPTS"
|
||||
|
||||
@@ -17,8 +17,17 @@ import { currentSession, newChat, sessions } from "./state";
|
||||
|
||||
<template>
|
||||
<div class="flex items-center justify-between gap-2 border-b px-4 py-3">
|
||||
<strong class="truncate text-sm font-semibold">{{ panelTitle(sessions, currentSession) }}</strong>
|
||||
<Button variant="ghost" size="icon-sm" class="flex-none" title="New chat" aria-label="New chat" @click="newChat">
|
||||
<strong class="truncate text-sm font-semibold">{{
|
||||
panelTitle(sessions, currentSession)
|
||||
}}</strong>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
class="flex-none"
|
||||
title="New chat"
|
||||
aria-label="New chat"
|
||||
@click="newChat"
|
||||
>
|
||||
<MessageCirclePlus />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -23,7 +23,10 @@ const blocks = computed(() => parseMarkdown(props.text));
|
||||
class="my-2 overflow-auto rounded-md border border-border bg-background/60 p-3"
|
||||
><code class="font-mono text-[0.85em]">{{ block.code }}</code></pre>
|
||||
|
||||
<table v-else-if="block.kind === 'table'" class="my-3 w-full border-collapse text-[0.92em]">
|
||||
<table
|
||||
v-else-if="block.kind === 'table'"
|
||||
class="my-3 w-full border-collapse text-[0.92em]"
|
||||
>
|
||||
<thead>
|
||||
<tr>
|
||||
<th
|
||||
@@ -37,7 +40,11 @@ const blocks = computed(() => parseMarkdown(props.text));
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(row, r) in block.rows" :key="r">
|
||||
<td v-for="(cell, c) in row" :key="c" class="border border-border px-2 py-1.5 text-left">
|
||||
<td
|
||||
v-for="(cell, c) in row"
|
||||
:key="c"
|
||||
class="border border-border px-2 py-1.5 text-left"
|
||||
>
|
||||
<ChatInline :inline="cell" />
|
||||
</td>
|
||||
</tr>
|
||||
@@ -51,24 +58,45 @@ const blocks = computed(() => parseMarkdown(props.text));
|
||||
<ChatInline :inline="block.inline" />
|
||||
</blockquote>
|
||||
|
||||
<h1 v-else-if="block.kind === 'h1'" class="mt-1 mb-2 text-xl leading-tight font-semibold tracking-[-0.02em]">
|
||||
<h1
|
||||
v-else-if="block.kind === 'h1'"
|
||||
class="mt-1 mb-2 text-xl leading-tight font-semibold tracking-[-0.02em]"
|
||||
>
|
||||
<ChatInline :inline="block.inline" />
|
||||
</h1>
|
||||
<h2 v-else-if="block.kind === 'h2'" class="mt-1 mb-2 text-lg leading-tight font-semibold tracking-[-0.02em]">
|
||||
<h2
|
||||
v-else-if="block.kind === 'h2'"
|
||||
class="mt-1 mb-2 text-lg leading-tight font-semibold tracking-[-0.02em]"
|
||||
>
|
||||
<ChatInline :inline="block.inline" />
|
||||
</h2>
|
||||
<h3 v-else-if="block.kind === 'h3'" class="mt-1 mb-2 text-base leading-tight font-semibold tracking-[-0.02em]">
|
||||
<h3
|
||||
v-else-if="block.kind === 'h3'"
|
||||
class="mt-1 mb-2 text-base leading-tight font-semibold tracking-[-0.02em]"
|
||||
>
|
||||
<ChatInline :inline="block.inline" />
|
||||
</h3>
|
||||
|
||||
<ul v-else-if="block.kind === 'ul'" class="my-2.5 flex list-disc flex-col gap-1 pl-5">
|
||||
<li v-for="(item, n) in block.items" :key="n"><ChatInline :inline="item" /></li>
|
||||
<ul
|
||||
v-else-if="block.kind === 'ul'"
|
||||
class="my-2.5 flex list-disc flex-col gap-1 pl-5"
|
||||
>
|
||||
<li v-for="(item, n) in block.items" :key="n">
|
||||
<ChatInline :inline="item" />
|
||||
</li>
|
||||
</ul>
|
||||
<ol v-else-if="block.kind === 'ol'" class="my-2.5 flex list-decimal flex-col gap-1 pl-5">
|
||||
<li v-for="(item, n) in block.items" :key="n"><ChatInline :inline="item" /></li>
|
||||
<ol
|
||||
v-else-if="block.kind === 'ol'"
|
||||
class="my-2.5 flex list-decimal flex-col gap-1 pl-5"
|
||||
>
|
||||
<li v-for="(item, n) in block.items" :key="n">
|
||||
<ChatInline :inline="item" />
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
<p v-else-if="block.kind === 'p'" class="mb-2.5 last:mb-0"><ChatInline :inline="block.inline" /></p>
|
||||
<p v-else-if="block.kind === 'p'" class="mb-2.5 last:mb-0">
|
||||
<ChatInline :inline="block.inline" />
|
||||
</p>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@@ -76,7 +76,9 @@ function usePrompt(text: string): void {
|
||||
<!-- The conversation takes the rest of the column: without `min-h-0` on
|
||||
the transcript it sizes to its content instead, and the composer
|
||||
floats above dead space. -->
|
||||
<div :class="contentFade + ' flex h-full min-h-0 flex-col overflow-hidden'">
|
||||
<div
|
||||
:class="contentFade + ' flex h-full min-h-0 flex-col overflow-hidden'"
|
||||
>
|
||||
<ChatHeader />
|
||||
<ChatBar />
|
||||
<ChatSessionActions v-if="currentSession" />
|
||||
|
||||
@@ -2,8 +2,16 @@
|
||||
import { ref } from "vue";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
import { promptSessionCommand, runSessionCommand, useEscapeLayer } from "./state";
|
||||
import {
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
} from "@/components/ui/popover";
|
||||
import {
|
||||
promptSessionCommand,
|
||||
runSessionCommand,
|
||||
useEscapeLayer,
|
||||
} from "./state";
|
||||
|
||||
/**
|
||||
* The commands that act on the conversation itself rather than on what is being
|
||||
@@ -33,14 +41,33 @@ function prompt(command: string, message: string): void {
|
||||
<div class="flex items-center border-b px-3 py-1.5 text-xs">
|
||||
<Popover v-model:open="open">
|
||||
<PopoverTrigger as-child>
|
||||
<Button variant="ghost" size="xs" class="text-fg-muted">Session actions</Button>
|
||||
<Button variant="ghost" size="xs" class="text-fg-muted"
|
||||
>Session actions</Button
|
||||
>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent align="start" class="flex w-[min(22rem,72vw)] flex-wrap gap-1.5">
|
||||
<Button variant="outline" size="sm" @click="run('/retry')">Retry</Button>
|
||||
<PopoverContent
|
||||
align="start"
|
||||
class="flex w-[min(22rem,72vw)] flex-wrap gap-1.5"
|
||||
>
|
||||
<Button variant="outline" size="sm" @click="run('/retry')"
|
||||
>Retry</Button
|
||||
>
|
||||
<Button variant="outline" size="sm" @click="run('/undo')">Undo</Button>
|
||||
<Button variant="outline" size="sm" @click="prompt('/title', 'Session title')">Rename</Button>
|
||||
<Button variant="outline" size="sm" @click="prompt('/branch', 'Branch name (optional)')">Branch</Button>
|
||||
<Button variant="outline" size="sm" @click="run('/compress --preview')">Preview compression</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
@click="prompt('/title', 'Session title')"
|
||||
>Rename</Button
|
||||
>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
@click="prompt('/branch', 'Branch name (optional)')"
|
||||
>Branch</Button
|
||||
>
|
||||
<Button variant="outline" size="sm" @click="run('/compress --preview')"
|
||||
>Preview compression</Button
|
||||
>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectGroup,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { sessionTitle } from "./session";
|
||||
import { currentSession, selectSession, sessions } from "./state";
|
||||
|
||||
@@ -26,7 +33,11 @@ import { currentSession, selectSession, sessions } from "./state";
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
<SelectItem v-for="session in sessions" :key="session.session_id" :value="session.session_id">
|
||||
<SelectItem
|
||||
v-for="session in sessions"
|
||||
:key="session.session_id"
|
||||
:value="session.session_id"
|
||||
>
|
||||
{{ sessionTitle(session) }}
|
||||
</SelectItem>
|
||||
</SelectGroup>
|
||||
|
||||
@@ -4,8 +4,19 @@ import { computed, ref } from "vue";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Field, FieldLabel } from "@/components/ui/field";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import {
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
} from "@/components/ui/popover";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectGroup,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import {
|
||||
currentModels,
|
||||
selectedModel,
|
||||
@@ -50,7 +61,12 @@ function clear(value: unknown): string {
|
||||
<template>
|
||||
<Popover v-model:open="open">
|
||||
<PopoverTrigger as-child>
|
||||
<Button variant="ghost" size="icon-sm" aria-label="Chat settings" title="Chat settings">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
aria-label="Chat settings"
|
||||
title="Chat settings"
|
||||
>
|
||||
<Settings />
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
@@ -59,14 +75,22 @@ function clear(value: unknown): string {
|
||||
|
||||
<Field class="gap-1">
|
||||
<FieldLabel class="text-xs text-fg-muted">Personality</FieldLabel>
|
||||
<Select :model-value="personaValue" @update:model-value="setPersona(clear($event))">
|
||||
<Select
|
||||
:model-value="personaValue"
|
||||
@update:model-value="setPersona(clear($event))"
|
||||
>
|
||||
<SelectTrigger size="sm" class="w-full" aria-label="Personality">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
<SelectItem :value="DEFAULT">Default</SelectItem>
|
||||
<SelectItem v-for="name in selectorData.personas || []" :key="name" :value="name">{{ name }}</SelectItem>
|
||||
<SelectItem
|
||||
v-for="name in selectorData.personas || []"
|
||||
:key="name"
|
||||
:value="name"
|
||||
>{{ name }}</SelectItem
|
||||
>
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
@@ -74,14 +98,21 @@ function clear(value: unknown): string {
|
||||
|
||||
<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))">
|
||||
<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">
|
||||
<SelectItem
|
||||
v-for="provider in selectorData.providers || []"
|
||||
:key="provider"
|
||||
:value="provider"
|
||||
>
|
||||
{{ provider }}
|
||||
</SelectItem>
|
||||
</SelectGroup>
|
||||
@@ -91,14 +122,22 @@ function clear(value: unknown): string {
|
||||
|
||||
<Field class="gap-1">
|
||||
<FieldLabel class="text-xs text-fg-muted">Model</FieldLabel>
|
||||
<Select :model-value="modelValue" @update:model-value="setModel(clear($event))">
|
||||
<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>
|
||||
<SelectItem
|
||||
v-for="model in currentModels"
|
||||
:key="model"
|
||||
:value="model"
|
||||
>{{ model }}</SelectItem
|
||||
>
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
@@ -20,15 +20,26 @@ const props = defineProps<{
|
||||
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));
|
||||
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. Which words stand in for silence depends on
|
||||
// whether the turn is still going: "running…" is true mid-turn and a lie after.
|
||||
const summary = computed(() => {
|
||||
const reported = props.tool.summary || props.tool.Summary || props.tool.text || props.tool.err || props.tool.Err;
|
||||
const reported =
|
||||
props.tool.summary ||
|
||||
props.tool.Summary ||
|
||||
props.tool.text ||
|
||||
props.tool.err ||
|
||||
props.tool.Err;
|
||||
if (reported) return reported;
|
||||
if (!props.streaming) return "done";
|
||||
return failed.value ? "failed" : "running…";
|
||||
@@ -38,9 +49,16 @@ const summary = computed(() => {
|
||||
<template>
|
||||
<ChatNavChip v-if="tool.path" :path="tool.path" :label="tool.label" />
|
||||
<div v-else class="flex items-baseline gap-1.5 [overflow-wrap:anywhere]">
|
||||
<Wrench aria-hidden="true" class="size-3.5 shrink-0 self-center text-fg-subtle" />
|
||||
<Wrench
|
||||
aria-hidden="true"
|
||||
class="size-3.5 shrink-0 self-center text-fg-subtle"
|
||||
/>
|
||||
<span class="font-semibold text-foreground">{{ name }}</span>
|
||||
<code v-if="parameters" class="font-mono text-[0.95em] text-fg-subtle">{{ parameters }}</code>
|
||||
<span :class="cn('text-fg-muted', failed && 'text-danger')">{{ summary }}</span>
|
||||
<code v-if="parameters" class="font-mono text-[0.95em] text-fg-subtle">{{
|
||||
parameters
|
||||
}}</code>
|
||||
<span :class="cn('text-fg-muted', failed && 'text-danger')">{{
|
||||
summary
|
||||
}}</span>
|
||||
</div>
|
||||
</template>
|
||||
@@ -12,7 +12,12 @@ import {
|
||||
} from "@/components/ui/message-scroller";
|
||||
import ChatBubble from "./ChatBubble.vue";
|
||||
import ChatEmptyState from "./ChatEmptyState.vue";
|
||||
import { messages, sendMessage, streamingTurn, type ChatMessage } from "./state";
|
||||
import {
|
||||
messages,
|
||||
sendMessage,
|
||||
streamingTurn,
|
||||
type ChatMessage,
|
||||
} from "./state";
|
||||
|
||||
/**
|
||||
* The conversation: the messages so far, the turn still arriving, and what the
|
||||
@@ -44,17 +49,32 @@ const bubbles = computed(() => messages.value.map(parts));
|
||||
<MessageScroller class="min-h-0 flex-1">
|
||||
<MessageScrollerViewport>
|
||||
<MessageScrollerContent class="gap-4 p-4">
|
||||
<ChatEmptyState v-if="!bubbles.length && !streamingTurn" @prompt="emit('prompt', $event)" />
|
||||
<ChatEmptyState
|
||||
v-if="!bubbles.length && !streamingTurn"
|
||||
@prompt="emit('prompt', $event)"
|
||||
/>
|
||||
|
||||
<template v-else>
|
||||
<MessageScrollerItem v-for="(bubble, i) in bubbles" :key="i" :message-id="`m${i}`">
|
||||
<ChatBubble :text="bubble.text" :tools="bubble.tools" :assistant="bubble.assistant" />
|
||||
<MessageScrollerItem
|
||||
v-for="(bubble, i) in bubbles"
|
||||
:key="i"
|
||||
:message-id="`m${i}`"
|
||||
>
|
||||
<ChatBubble
|
||||
:text="bubble.text"
|
||||
:tools="bubble.tools"
|
||||
:assistant="bubble.assistant"
|
||||
/>
|
||||
</MessageScrollerItem>
|
||||
|
||||
<!-- The live turn is a bubble like any other, so what arrives is
|
||||
rendered by the same rules as what was already there. It is the
|
||||
scroll anchor while it streams. -->
|
||||
<MessageScrollerItem v-if="streamingTurn" message-id="streaming" scroll-anchor>
|
||||
<MessageScrollerItem
|
||||
v-if="streamingTurn"
|
||||
message-id="streaming"
|
||||
scroll-anchor
|
||||
>
|
||||
<ChatBubble
|
||||
:text="streamingTurn.text || '…'"
|
||||
:tools="streamingTurn.tools"
|
||||
|
||||
+19
-5
@@ -17,12 +17,18 @@ const MAX_MATCHES = 8;
|
||||
* caret, matched on the command and its description together so a word from
|
||||
* either finds it.
|
||||
*/
|
||||
export function matchesFor(specs: ChatCommandSpec[], value: string, caret: number): ChatCommandSpec[] {
|
||||
export function matchesFor(
|
||||
specs: ChatCommandSpec[],
|
||||
value: string,
|
||||
caret: number,
|
||||
): ChatCommandSpec[] {
|
||||
const match = value.slice(0, caret).match(OPEN_TOKEN);
|
||||
if (!match) return [];
|
||||
const query = match[1].toLowerCase();
|
||||
return specs
|
||||
.filter((spec) => `${spec.command} ${spec.description ?? ""}`.toLowerCase().includes(query))
|
||||
.filter((spec) =>
|
||||
`${spec.command} ${spec.description ?? ""}`.toLowerCase().includes(query),
|
||||
)
|
||||
.slice(0, MAX_MATCHES);
|
||||
}
|
||||
|
||||
@@ -30,11 +36,16 @@ export function matchesFor(specs: ChatCommandSpec[], value: string, caret: numbe
|
||||
* applyCommand replaces the token being completed with the chosen command and
|
||||
* returns the cursor position just after it, ready for the next word.
|
||||
*/
|
||||
export function applyCommand(value: string, caret: number, command: string): { text: string; cursor: number } {
|
||||
export function applyCommand(
|
||||
value: string,
|
||||
caret: number,
|
||||
command: string,
|
||||
): { text: string; cursor: number } {
|
||||
const before = value.slice(0, caret);
|
||||
const after = value.slice(caret);
|
||||
const start = before.search(ANY_TOKEN);
|
||||
const tokenStart = start < 0 ? before.length : start + (before[start] === " " ? 1 : 0);
|
||||
const tokenStart =
|
||||
start < 0 ? before.length : start + (before[start] === " " ? 1 : 0);
|
||||
return {
|
||||
text: `${before.slice(0, tokenStart)}${command} ${after}`,
|
||||
cursor: tokenStart + command.length + 1,
|
||||
@@ -46,7 +57,10 @@ export function applyCommand(value: string, caret: number, command: string): { t
|
||||
* nothing else. Enter then sends it rather than completing it, so a command
|
||||
* typed in full is never re-entered by the palette that was offering it.
|
||||
*/
|
||||
export function isExactCommand(specs: ChatCommandSpec[], value: string): boolean {
|
||||
export function isExactCommand(
|
||||
specs: ChatCommandSpec[],
|
||||
value: string,
|
||||
): boolean {
|
||||
const trimmed = value.trim();
|
||||
return specs.some((spec) => spec.command === trimmed);
|
||||
}
|
||||
+23
-8
@@ -33,11 +33,13 @@ function inlineMarkdown(text: string): ChatInline[] {
|
||||
const children: ChatInline[] = [];
|
||||
let cursor = 0;
|
||||
for (const match of String(text).matchAll(INLINE)) {
|
||||
if (match.index > cursor) children.push({ kind: "text", text: text.slice(cursor, match.index) });
|
||||
if (match.index > cursor)
|
||||
children.push({ kind: "text", text: text.slice(cursor, match.index) });
|
||||
const value = match[0];
|
||||
if (value.startsWith("![")) {
|
||||
const img = value.match(/^!\[([^\]]*)\]\((.+)\)$/);
|
||||
if (img) children.push({ kind: "image", alt: img[1] || "Image", src: img[2] });
|
||||
if (img)
|
||||
children.push({ kind: "image", alt: img[1] || "Image", src: img[2] });
|
||||
} else if (value.startsWith("~~")) {
|
||||
children.push({ kind: "del", text: value.slice(2, -2) });
|
||||
} else if (value.startsWith("**") || value.startsWith("__")) {
|
||||
@@ -45,14 +47,17 @@ function inlineMarkdown(text: string): ChatInline[] {
|
||||
} else if (value.startsWith("`")) {
|
||||
children.push({ kind: "code", text: value.slice(1, -1) });
|
||||
} else if (value.startsWith("[")) {
|
||||
const link = value.match(/^\[([^\]]+)\]\((https?:\/\/[^\s)]+|\/[^\s)]+)\)$/);
|
||||
const link = value.match(
|
||||
/^\[([^\]]+)\]\((https?:\/\/[^\s)]+|\/[^\s)]+)\)$/,
|
||||
);
|
||||
if (link) children.push({ kind: "link", text: link[1], href: link[2] });
|
||||
} else {
|
||||
children.push({ kind: "em", text: value.slice(1, -1) });
|
||||
}
|
||||
cursor = match.index + value.length;
|
||||
}
|
||||
if (cursor < text.length) children.push({ kind: "text", text: text.slice(cursor) });
|
||||
if (cursor < text.length)
|
||||
children.push({ kind: "text", text: text.slice(cursor) });
|
||||
return children;
|
||||
}
|
||||
|
||||
@@ -71,7 +76,10 @@ export function parseMarkdown(text: string | null | undefined): ChatBlock[] {
|
||||
};
|
||||
const flushList = () => {
|
||||
if (!list) return;
|
||||
blocks.push({ kind: list.tag, items: list.items.map((item) => inlineMarkdown(item)) });
|
||||
blocks.push({
|
||||
kind: list.tag,
|
||||
items: list.items.map((item) => inlineMarkdown(item)),
|
||||
});
|
||||
list = null;
|
||||
};
|
||||
|
||||
@@ -93,7 +101,8 @@ export function parseMarkdown(text: string | null | undefined): ChatBlock[] {
|
||||
continue;
|
||||
}
|
||||
const headerCells = tableCells(line);
|
||||
const separatorCells = index + 1 < lines.length ? tableCells(lines[index + 1]) : null;
|
||||
const separatorCells =
|
||||
index + 1 < lines.length ? tableCells(lines[index + 1]) : null;
|
||||
if (
|
||||
headerCells &&
|
||||
separatorCells &&
|
||||
@@ -127,7 +136,10 @@ export function parseMarkdown(text: string | null | undefined): ChatBlock[] {
|
||||
if (heading) {
|
||||
flushParagraph();
|
||||
flushList();
|
||||
blocks.push({ kind: `h${heading[1].length}` as "h1" | "h2" | "h3", inline: inlineMarkdown(heading[2]) });
|
||||
blocks.push({
|
||||
kind: `h${heading[1].length}` as "h1" | "h2" | "h3",
|
||||
inline: inlineMarkdown(heading[2]),
|
||||
});
|
||||
continue;
|
||||
}
|
||||
const bullet = line.match(/^\s*[-*]\s+(.+)$/);
|
||||
@@ -145,7 +157,10 @@ export function parseMarkdown(text: string | null | undefined): ChatBlock[] {
|
||||
if (line.startsWith(">")) {
|
||||
flushParagraph();
|
||||
flushList();
|
||||
blocks.push({ kind: "blockquote", inline: inlineMarkdown(line.replace(/^>\s?/, "")) });
|
||||
blocks.push({
|
||||
kind: "blockquote",
|
||||
inline: inlineMarkdown(line.replace(/^>\s?/, "")),
|
||||
});
|
||||
continue;
|
||||
}
|
||||
paragraph.push(line);
|
||||
|
||||
+12
-3
@@ -1,7 +1,11 @@
|
||||
import type { ChatSession } from "./state";
|
||||
|
||||
export function sessionTitle(session: ChatSession): string {
|
||||
return session.title || session.branch_name || `Conversation ${session.session_id.slice(0, 8)}`;
|
||||
return (
|
||||
session.title ||
|
||||
session.branch_name ||
|
||||
`Conversation ${session.session_id.slice(0, 8)}`
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -9,8 +13,13 @@ export function sessionTitle(session: ChatSession): string {
|
||||
* session switcher sits below it, so the header says which conversation is
|
||||
* open rather than repeating the product name.
|
||||
*/
|
||||
export function panelTitle(sessions: ChatSession[], currentSession: string): string {
|
||||
export function panelTitle(
|
||||
sessions: ChatSession[],
|
||||
currentSession: string,
|
||||
): string {
|
||||
if (!currentSession) return "Archie";
|
||||
const session = (sessions || []).find((item) => item.session_id === currentSession);
|
||||
const session = (sessions || []).find(
|
||||
(item) => item.session_id === currentSession,
|
||||
);
|
||||
return session ? sessionTitle(session) : "Archie";
|
||||
}
|
||||
+60
-17
@@ -3,7 +3,12 @@ import { computed, onMounted, onUnmounted, ref, watch, type Ref } from "vue";
|
||||
import { api } from "@/lib/api";
|
||||
import { channelID } from "./channel";
|
||||
import { matchesFor } from "./commands";
|
||||
import { resolveTurn, retryChatTurn, type ChatTurn, type RetryOptions } from "./turn";
|
||||
import {
|
||||
resolveTurn,
|
||||
retryChatTurn,
|
||||
type ChatTurn,
|
||||
type RetryOptions,
|
||||
} from "./turn";
|
||||
|
||||
/**
|
||||
* The chat panel's shared state.
|
||||
@@ -130,7 +135,9 @@ 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 || [];
|
||||
return provider && grouped[provider]
|
||||
? grouped[provider]
|
||||
: selectorData.value.models || [];
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -166,7 +173,9 @@ function abortActiveTurn(): void {
|
||||
}
|
||||
|
||||
export async function refreshSessions(): Promise<void> {
|
||||
const data = await api.chatSessions<ChatSelectorData & { sessions?: ChatSession[] }>();
|
||||
const data = await api.chatSessions<
|
||||
ChatSelectorData & { sessions?: ChatSession[] }
|
||||
>();
|
||||
const sessionList = data.sessions || [];
|
||||
sessions.value = sessionList;
|
||||
selectorData.value = data;
|
||||
@@ -177,7 +186,9 @@ export async function refreshSessions(): Promise<void> {
|
||||
selectedModel.value = data.active_model || "";
|
||||
|
||||
commandSpecs.value = (data.commands || []).map((item) =>
|
||||
typeof item === "string" ? { command: item, usage: item, description: "" } : item,
|
||||
typeof item === "string"
|
||||
? { command: item, usage: item, description: "" }
|
||||
: item,
|
||||
);
|
||||
|
||||
if (!currentSession.value && sessionList[0]) {
|
||||
@@ -195,13 +206,17 @@ export async function selectSession(id: string): Promise<void> {
|
||||
messages.value = [];
|
||||
streamingTurn.value = null;
|
||||
|
||||
selectedPersona.value = data.active_personas?.[id] || data.active_persona || "";
|
||||
selectedPersona.value =
|
||||
data.active_personas?.[id] || data.active_persona || "";
|
||||
|
||||
try {
|
||||
// Resuming is the server's own command, so the transcript read below is of
|
||||
// a conversation the server considers current rather than a stale one.
|
||||
await api.chatMessage(channelID(), `/resume ${id}`);
|
||||
const [msgs, turns] = await Promise.all([api.chatMessages<ChatMessage[]>(id), api.chatTurns<ChatTurnView[]>(id)]);
|
||||
const [msgs, turns] = await Promise.all([
|
||||
api.chatMessages<ChatMessage[]>(id),
|
||||
api.chatTurns<ChatTurnView[]>(id),
|
||||
]);
|
||||
const byAssistantMessage = new Map<string, ChatTurnView>();
|
||||
for (const turn of turns || []) {
|
||||
const assistantID = turn.assistant_message_id || turn.AssistantMessageID;
|
||||
@@ -212,10 +227,13 @@ export async function selectSession(id: string): Promise<void> {
|
||||
messages.value = (msgs || []).map((message) => {
|
||||
const messageID = message.message_id || message.MessageID;
|
||||
const turn = messageID ? byAssistantMessage.get(messageID) : undefined;
|
||||
return turn ? { ...message, tool_calls: turn.tool_calls || turn.ToolCalls || [] } : message;
|
||||
return turn
|
||||
? { ...message, tool_calls: turn.tool_calls || turn.ToolCalls || [] }
|
||||
: message;
|
||||
});
|
||||
} catch (err) {
|
||||
statusText.value = (err as Error).message || "Could not load session messages";
|
||||
statusText.value =
|
||||
(err as Error).message || "Could not load session messages";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,7 +249,10 @@ export async function runSessionCommand(command: string): Promise<void> {
|
||||
if (!currentSession.value) return;
|
||||
try {
|
||||
statusText.value = "Working…";
|
||||
const result = await api.chatMessage<{ session_id?: string; reply?: string }>(channelID(), command);
|
||||
const result = await api.chatMessage<{
|
||||
session_id?: string;
|
||||
reply?: string;
|
||||
}>(channelID(), command);
|
||||
if (result.session_id) currentSession.value = result.session_id;
|
||||
statusText.value = result.reply || "Session updated";
|
||||
await refreshSessions();
|
||||
@@ -274,7 +295,10 @@ 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}`);
|
||||
const result = await api.chatMessage<{ reply?: string }>(
|
||||
channelID(),
|
||||
`/model --provider ${provider}`,
|
||||
);
|
||||
statusText.value = result.reply || "Provider updated";
|
||||
await refreshSessions();
|
||||
} catch (err) {
|
||||
@@ -286,7 +310,10 @@ export async function setModel(model: string): Promise<void> {
|
||||
selectedModel.value = model;
|
||||
if (!model) return;
|
||||
try {
|
||||
const result = await api.chatMessage<{ reply?: string }>(channelID(), `/model ${model}`);
|
||||
const result = await api.chatMessage<{ reply?: string }>(
|
||||
channelID(),
|
||||
`/model ${model}`,
|
||||
);
|
||||
statusText.value = result.reply || "Model updated";
|
||||
await refreshSessions();
|
||||
} catch (err) {
|
||||
@@ -329,7 +356,8 @@ function currentPage(): string {
|
||||
|
||||
export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
|
||||
const explicitText = retryOpts?.textOverride;
|
||||
const rawValue = explicitText !== undefined ? explicitText : composerText.value;
|
||||
const rawValue =
|
||||
explicitText !== undefined ? explicitText : composerText.value;
|
||||
const { text, turn, isRetry } = resolveTurn(retryOpts, rawValue);
|
||||
if (!text || isSending.value) return;
|
||||
|
||||
@@ -384,20 +412,26 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
|
||||
const frames = buffer.split("\n\n");
|
||||
buffer = frames.pop() || "";
|
||||
for (const frame of frames) {
|
||||
const line = frame.split("\n").find((part) => part.startsWith("data: "));
|
||||
const line = frame
|
||||
.split("\n")
|
||||
.find((part) => part.startsWith("data: "));
|
||||
if (!line) continue;
|
||||
const event = JSON.parse(line.slice(6)) as ChatStreamFrame;
|
||||
if (event.session_id) currentSession.value = event.session_id;
|
||||
if (event.type === "delta") {
|
||||
streamedText += event.text;
|
||||
streamingTurn.value = streamingTurn.value ? { ...streamingTurn.value, text: streamedText } : null;
|
||||
streamingTurn.value = streamingTurn.value
|
||||
? { ...streamingTurn.value, text: streamedText }
|
||||
: null;
|
||||
}
|
||||
// A navigate result is appended to the same list as the tool calls: it
|
||||
// is one more thing the turn did, and it renders as a chip rather than
|
||||
// a tool line.
|
||||
if (event.type === "tool" || event.type === "navigate") {
|
||||
activeTools = [...activeTools, event];
|
||||
streamingTurn.value = streamingTurn.value ? { ...streamingTurn.value, tools: activeTools } : null;
|
||||
streamingTurn.value = streamingTurn.value
|
||||
? { ...streamingTurn.value, tools: activeTools }
|
||||
: null;
|
||||
}
|
||||
if (event.type === "done") {
|
||||
finished = true;
|
||||
@@ -410,14 +444,23 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
|
||||
|
||||
if (!finished) throw new Error("chat stream ended before completion");
|
||||
|
||||
messages.value = [...messages.value, { from: "assistant", text: streamedText, tool_calls: activeTools }];
|
||||
messages.value = [
|
||||
...messages.value,
|
||||
{ from: "assistant", text: streamedText, tool_calls: activeTools },
|
||||
];
|
||||
streamingTurn.value = null;
|
||||
statusText.value = "Ready";
|
||||
await refreshSessions();
|
||||
} catch (err) {
|
||||
const failed = err as Error;
|
||||
if (failed.name === "AbortError" && !timedOut) {
|
||||
streamingTurn.value = { text: "Turn stopped.", tools: activeTools, isError: false, turn, isRetry };
|
||||
streamingTurn.value = {
|
||||
text: "Turn stopped.",
|
||||
tools: activeTools,
|
||||
isError: false,
|
||||
turn,
|
||||
isRetry,
|
||||
};
|
||||
statusText.value = "Stopped";
|
||||
} else {
|
||||
streamingTurn.value = {
|
||||
|
||||
+6
-1
@@ -35,7 +35,12 @@ export function resolveTurn(
|
||||
retry: RetryOptions | null | undefined,
|
||||
composerValue: string,
|
||||
): { text: string; turn: ChatTurn; isRetry: boolean } {
|
||||
const isRetry = !!(retry && typeof retry === "object" && retry.turn && typeof retry.turn.text === "string");
|
||||
const isRetry = !!(
|
||||
retry &&
|
||||
typeof retry === "object" &&
|
||||
retry.turn &&
|
||||
typeof retry.turn.text === "string"
|
||||
);
|
||||
const text = isRetry ? retry.turn!.text : composerValue.trim();
|
||||
const turn = isRetry ? retryChatTurn(retry.turn!) : newChatTurn(text);
|
||||
return { text, turn, isRetry };
|
||||
|
||||
Reference in new issue
Block a user