feat(chat): the dashboard chat answers tool approvals and questions, and /update offers Install

This commit is contained in:
sam committed 2026-10-08 00:25:23 +11:00
1 parent 12ac6daff7
commit 12eab7683a
11 files changed
+454 -103

No files matched your search

+53
View File
@@ -0,0 +1,53 @@
<script setup lang="ts">
import { ref } from "vue";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { answerAsk, type ChatAsk } from "./state";
defineProps<{ ask: ChatAsk }>();
const reply = ref("");
function sendReply() {
const text = reply.value.trim();
if (!text) return;
reply.value = "";
void answerAsk(text);
}
</script>
<template>
<div class="mt-2 rounded-lg border border-border bg-card p-3 text-sm" role="group" :aria-label="ask.prompt">
<template v-if="ask.kind === 'approval'">
<p class="font-medium">Allow {{ ask.prompt }}?</p>
<p v-if="ask.detail" class="mt-1 font-mono text-xs break-all text-fg-muted">{{ ask.detail }}</p>
<div class="mt-3 flex flex-wrap gap-2">
<Button size="sm" @click="answerAsk('approve')">Approve</Button>
<Button size="sm" variant="outline" @click="answerAsk('always')">Always this session</Button>
<Button size="sm" variant="ghost" class="text-danger" @click="answerAsk('deny')">Deny</Button>
</div>
</template>
<template v-else-if="ask.kind === 'picker'">
<p class="font-medium">{{ ask.prompt }}</p>
<div class="mt-3 flex flex-wrap gap-2">
<Button v-for="choice in ask.choices" :key="choice.id" size="sm" variant="outline" @click="answerAsk(choice.id)">
{{ choice.label }}
</Button>
</div>
</template>
<template v-else>
<p class="font-medium">{{ ask.prompt }}</p>
<div v-if="ask.choices?.length" class="mt-3 flex flex-wrap gap-2">
<Button v-for="choice in ask.choices" :key="choice.id" size="sm" variant="outline" @click="answerAsk(choice.label)">
{{ choice.label }}
</Button>
</div>
<form class="mt-3 flex gap-2" @submit.prevent="sendReply">
<Input v-model="reply" class="flex-1" placeholder="Your answer" aria-label="Your answer" />
<Button type="submit" size="sm" :disabled="!reply.trim()">Send</Button>
</form>
</template>
</div>
</template>
+7 -1
View File
@@ -10,7 +10,9 @@ import {
MessageScrollerProvider,
MessageScrollerViewport,
} from "@/components/ui/message-scroller";
import ChatAskCard from "./ChatAskCard.vue";
import ChatBubble from "./ChatBubble.vue";
import ChatUpdateCard from "./ChatUpdateCard.vue";
import ChatEmptyState from "./ChatEmptyState.vue";
import {
messages,
@@ -41,6 +43,7 @@ function parts(message: ChatMessage) {
// metadata only -- so the bubble labels them.
media: message.media || [],
assistant: from !== "web",
update: message.update,
};
}
@@ -68,7 +71,9 @@ const bubbles = computed(() => messages.value.map(parts));
:tools="bubble.tools"
:media="bubble.media"
:assistant="bubble.assistant"
/>
>
<ChatUpdateCard v-if="bubble.update" :update="bubble.update" />
</ChatBubble>
</MessageScrollerItem>
<!-- The live turn is a bubble like any other, so what arrives is
@@ -94,6 +99,7 @@ const bubbles = computed(() => messages.value.map(parts));
>
Retry
</Button>
<ChatAskCard v-if="streamingTurn.ask" :ask="streamingTurn.ask" />
</ChatBubble>
</MessageScrollerItem>
</template>
+72
View File
@@ -0,0 +1,72 @@
<script setup lang="ts">
import { computed, ref } from "vue";
import { Button } from "@/components/ui/button";
import { api } from "@/lib/api";
import type { ChatUpdate } from "./state";
const props = defineProps<{ update: ChatUpdate }>();
interface Component {
Label?: string;
ID?: string;
Installed?: string;
Available?: string;
Changelog?: string;
}
const available = computed(() => (props.update.available ?? []) as Component[]);
const state = ref<"idle" | "installing" | "deferred" | "done" | "failed">("idle");
const result = ref("");
async function install() {
state.value = "installing";
try {
const out = await api.updateInstall<{ result?: { installed?: Record<string, string> } }>(props.update.snapshot);
const installed = out.result?.installed;
result.value = installed
? Object.entries(installed).map(([id, v]) => `${id} → ${v}`).join(", ") + ". Archie restarts to apply it."
: "Update finished.";
state.value = "done";
} catch (err) {
result.value = (err as Error).message;
state.value = "failed";
}
}
async function later() {
try {
await api.updateDefer(props.update.snapshot);
state.value = "deferred";
} catch (err) {
result.value = (err as Error).message;
state.value = "failed";
}
}
</script>
<template>
<div class="text-sm">
<p v-if="!available.length">Archie is up to date.</p>
<template v-else>
<p class="font-medium">An update is available</p>
<ul class="mt-1 space-y-0.5">
<li v-for="c in available" :key="c.ID">
{{ c.Label || c.ID }}: <span class="font-mono">{{ c.Installed || "?" }} → {{ c.Available }}</span>
<a v-if="c.Changelog" :href="c.Changelog" target="_blank" rel="noopener" class="ml-1 text-xs underline">changes</a>
</li>
</ul>
<div v-if="state === 'idle'" class="mt-3 flex gap-2">
<Button v-if="update.can_install" size="sm" @click="install">Install</Button>
<Button size="sm" variant="ghost" @click="later">Not now</Button>
</div>
<p v-else-if="state === 'installing'" class="mt-2 text-fg-muted">Installing… this can take a few minutes.</p>
<p v-else-if="state === 'deferred'" class="mt-2 text-fg-muted">Skipped until a newer release.</p>
<p v-else-if="state === 'done'" class="mt-2 text-ok">{{ result }}</p>
<p v-else class="mt-2 text-danger">{{ result }}</p>
<p v-if="state === 'idle' && !update.can_install" class="mt-2 text-xs text-fg-muted">
This host has no install script, so the update can't be installed from here.
</p>
</template>
</div>
</template>
+66 -4
View File
@@ -91,6 +91,15 @@ export interface ChatMessage {
ToolCalls?: ChatToolCall[];
message_id?: string;
MessageID?: string;
/** An update check answered in the panel, with its install actions. */
update?: ChatUpdate;
}
/** The update snapshot /update shows, and whether this host can install it. */
export interface ChatUpdate {
snapshot: unknown;
available: unknown[];
can_install: boolean;
}
/** A turn in flight: what it is showing, and what to resend if it fails. */
@@ -100,6 +109,17 @@ export interface StreamingTurn {
isError: boolean;
turn?: ChatTurn;
isRetry: boolean;
/** A question the turn waits on until the operator answers it. */
ask?: ChatAsk;
}
/** An approval, clarify or picker question from a running turn. */
export interface ChatAsk {
id: string;
kind: "approval" | "clarify" | "picker";
prompt: string;
detail?: string;
choices?: { id: string; label: string }[];
}
/** Everything the selectors on the panel read, from one sessions read. */
@@ -130,10 +150,21 @@ interface ChatStreamFrame extends ChatToolCall {
type?: string;
text: string;
session_id?: string;
ask?: ChatAsk;
}
/** A turn that never settles must not hold the composer closed forever. */
const STREAM_TIMEOUT_MS = 120000;
let rearmTimeout: (() => void) | null = null;
/** answerAsk sends the operator's answer to the question the turn waits on. */
export async function answerAsk(answer: string): Promise<void> {
const ask = streamingTurn.value?.ask;
if (!ask) return;
streamingTurn.value = streamingTurn.value ? { ...streamingTurn.value, ask: undefined } : null;
rearmTimeout?.();
await api.chatAnswer(ask.id, answer);
}
export const sessions = ref<ChatSession[]>([]);
export const currentSession = ref("");
@@ -391,6 +422,24 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
composerText.value = "";
}
// /update answers here, where the panel can offer Install like Telegram does.
if (!isRetry && text.trim() === "/update") {
try {
const update = await api.updateSnapshot<ChatUpdate>();
messages.value = [...messages.value, { from: "assistant", text: "", update }];
statusText.value = "Ready";
} catch (err) {
messages.value = [
...messages.value,
{ from: "assistant", text: `Could not check for updates: ${(err as Error).message}` },
];
statusText.value = "Ready";
} finally {
isSending.value = false;
}
return;
}
let activeTools: ChatToolCall[] = [];
streamingTurn.value = { text: "", tools: [], isError: false, turn, isRetry };
@@ -402,10 +451,16 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
try {
const controller = new AbortController();
activeController = controller;
timeoutId = setTimeout(() => {
timedOut = true;
controller.abort();
}, STREAM_TIMEOUT_MS);
const arm = () => {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
timedOut = true;
controller.abort();
}, STREAM_TIMEOUT_MS);
};
arm();
// The clock stops while a question waits on the operator.
rearmTimeout = arm;
const response = await api.chatStream(
{
@@ -454,6 +509,12 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
? { ...streamingTurn.value, tools: activeTools }
: null;
}
if (event.type === "ask" && event.ask) {
clearTimeout(timeoutId);
streamingTurn.value = streamingTurn.value
? { ...streamingTurn.value, ask: event.ask }
: null;
}
if (event.type === "done") {
finished = true;
if (!streamedText) streamedText = event.text || "";
@@ -495,6 +556,7 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
}
} finally {
clearTimeout(timeoutId);
rearmTimeout = null;
activeController = null;
isSending.value = false;
}
+4
View File
@@ -262,6 +262,8 @@ export const api = {
// not the 15s default, and the watchdog owns everything after the restart.
version: <T = unknown>() => request<T>("/api/version"),
updateSnapshot: <T = unknown>() => request<T>("/api/chat/update"),
updateDefer: (snapshot: unknown) =>
request("/api/chat/update/defer", { method: "POST", body: { snapshot } }),
updateInstall: <T = unknown>(snapshot: unknown) =>
request<T>("/api/chat/update/install", {
method: "POST",
@@ -351,6 +353,8 @@ export const api = {
method: "POST",
}),
chatSessions: <T = unknown>() => request<T>("/api/chat/sessions"),
chatAnswer: (id: string, answer: string) =>
request("/api/chat/answer", { method: "POST", body: { id, answer } }),
chatMessages: <T = unknown>(id: string) =>
request<T>(`/api/chat/sessions/${encodeURIComponent(id)}/messages`),
chatTurns: <T = unknown>(id: string) =>
+7 -25
View File
@@ -35,20 +35,9 @@ interface ComponentVersion {
status: "ok" | "update_available" | "drift" | "unknown";
}
interface ComponentSnapshot {
id?: string;
label?: string;
installed?: string;
available?: string;
}
interface UpdateSnapshot {
components?: ComponentSnapshot[];
deferred?: boolean;
}
const components = ref<ComponentVersion[]>([]);
const snapshot = ref<UpdateSnapshot | null>(null);
const snapshot = ref<unknown>(null);
const available = ref<unknown[]>([]);
const canInstall = ref(false);
const notConfigured = ref(false);
const loading = ref(true);
@@ -86,7 +75,7 @@ async function load(): Promise<void> {
const [report, update] = await Promise.all([
api.version<{ components: ComponentVersion[] }>(),
api
.updateSnapshot<{ snapshot: UpdateSnapshot; can_install: boolean }>()
.updateSnapshot<{ snapshot: unknown; available: unknown[] | null; can_install: boolean }>()
.catch((err) => {
if (err instanceof ApiError && err.status === 501) {
notConfigured.value = true;
@@ -98,6 +87,7 @@ async function load(): Promise<void> {
components.value = report.components;
if (update) {
snapshot.value = update.snapshot;
available.value = update.available ?? [];
canInstall.value = update.can_install;
}
} catch (err) {
@@ -107,18 +97,10 @@ async function load(): Promise<void> {
}
}
// The snapshot the install endpoint demands is the one the operator saw —
// The snapshot the install endpoint demands is the one the operator saw --
// the endpoint re-checks freshness and answers 409 when releases moved.
function installableSnapshot(): UpdateSnapshot | null {
if (!snapshot.value) return null;
if (
snapshot.value.components?.some(
(c) => c.available && c.available !== c.installed,
)
) {
return snapshot.value;
}
return null;
function installableSnapshot(): unknown {
return snapshot.value && available.value.length ? snapshot.value : null;
}
async function install(): Promise<void> {