feat(telegram): /stop stops the chat agent, else the tasks it created, or one task; delete the dead approval actions
This commit is contained in:
1 parent
399098329b
commit
b0f1ad7cdc
52 files changed
+2385
-2781
No files matched your search
@@ -377,17 +377,6 @@ export const api = {
|
||||
method: "POST",
|
||||
body: { session_id: sessionID, name },
|
||||
}),
|
||||
chatDangerous: <T = unknown>() => request<T>("/api/chat/dangerous"),
|
||||
chatDangerousRequest: <T = unknown>(kind: string, spec: unknown) =>
|
||||
request<T>(`/api/chat/dangerous/${encodeURIComponent(kind)}`, {
|
||||
method: "POST",
|
||||
body: { spec },
|
||||
}),
|
||||
chatDangerousDecision: <T = unknown>(id: string, decision: string) =>
|
||||
request<T>(`/api/chat/dangerous/${encodeURIComponent(id)}/decision`, {
|
||||
method: "POST",
|
||||
body: { decision },
|
||||
}),
|
||||
// A server-sent event stream cannot be parsed as JSON and outlives a normal
|
||||
// request, so the caller owns the abort controller and the timeout, and
|
||||
// reads the body itself. Only the URL, headers, and failure shape are shared.
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Field, FieldLabel } from "@/components/ui/field";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectGroup,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { requestDangerous } from "./state";
|
||||
import type { DangerCheckpoint } from "./types";
|
||||
|
||||
/**
|
||||
* Queues a rollback to a checkpoint. The request only asks: an approval has to
|
||||
* be granted in the list below before anything runs.
|
||||
*
|
||||
* A checkpoint's number and label arrive under either casing depending on the
|
||||
* source, so both are read.
|
||||
*/
|
||||
const props = defineProps<{ checkpoints: DangerCheckpoint[] }>();
|
||||
|
||||
const checkpoint = ref("");
|
||||
|
||||
const number = (cp: DangerCheckpoint): number | undefined =>
|
||||
cp.Number ?? cp.number;
|
||||
const label = (cp: DangerCheckpoint): string =>
|
||||
cp.Label ?? cp.label ?? "checkpoint";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Field orientation="horizontal">
|
||||
<FieldLabel class="sr-only" for="danger-checkpoint">Checkpoint</FieldLabel>
|
||||
<Select v-model="checkpoint">
|
||||
<SelectTrigger id="danger-checkpoint" class="w-full md:max-w-80">
|
||||
<SelectValue placeholder="Select checkpoint" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
<SelectItem
|
||||
v-for="cp in props.checkpoints"
|
||||
:key="String(number(cp))"
|
||||
:value="String(number(cp))"
|
||||
>
|
||||
{{ number(cp) }} — {{ label(cp) }}
|
||||
</SelectItem>
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Button
|
||||
variant="outline"
|
||||
:disabled="!checkpoint"
|
||||
@click="requestDangerous('rollback', checkpoint)"
|
||||
>
|
||||
Request rollback
|
||||
</Button>
|
||||
</Field>
|
||||
</template>
|
||||
@@ -1,36 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from "vue";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Field, FieldLabel } from "@/components/ui/field";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { requestDangerous } from "./state";
|
||||
|
||||
/**
|
||||
* Queues a stop for a named process. Like every request here it only asks:
|
||||
* the approval decides whether it runs.
|
||||
*/
|
||||
const spec = ref("");
|
||||
const requested = computed(() => spec.value.trim().length > 0);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Field orientation="horizontal">
|
||||
<FieldLabel class="sr-only" for="danger-stop"
|
||||
>Process name or id</FieldLabel
|
||||
>
|
||||
<Input
|
||||
id="danger-stop"
|
||||
v-model="spec"
|
||||
placeholder="Process name or id"
|
||||
autocomplete="off"
|
||||
class="w-full md:max-w-80"
|
||||
/>
|
||||
<Button
|
||||
variant="outline"
|
||||
:disabled="!requested"
|
||||
@click="requestDangerous('stop', spec)"
|
||||
>Request stop</Button
|
||||
>
|
||||
</Field>
|
||||
</template>
|
||||
@@ -1,91 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from "vue";
|
||||
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { decideDangerous } from "./state";
|
||||
import type { DangerousAction } from "./types";
|
||||
|
||||
/**
|
||||
* One queued request: what it would do, and the decisions open on it. Approve
|
||||
* runs it once, "Approve for 24h" runs it for a day, and Deny drops it.
|
||||
*
|
||||
* Both approves are destructive-weighted and confirmed first, because they
|
||||
* grant authority: approve for the one run, the 24h option for every future
|
||||
* request of the same family. Deny takes nothing away, so it stays plain.
|
||||
*/
|
||||
const props = defineProps<{ action: DangerousAction }>();
|
||||
|
||||
// Which approve decision is awaiting its confirmation, if any: one dialog
|
||||
// driven by the decision it will run, rather than two copies of the same
|
||||
// footer. The decision kinds are fixed by the endpoint ('approve' |
|
||||
// 'permanent' | 'deny') and must not be reworded here.
|
||||
const confirming = ref<"approve" | "permanent" | null>(null);
|
||||
|
||||
const description = computed(() => props.action.description || "this action");
|
||||
|
||||
function decide(decision: "approve" | "permanent" | "deny"): void {
|
||||
void decideDangerous(props.action.id, decision);
|
||||
}
|
||||
|
||||
function onConfirmationOpen(open: boolean): void {
|
||||
if (!open) confirming.value = null;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="flex flex-wrap items-center justify-between gap-3 border-t border-hairline py-3"
|
||||
>
|
||||
<span class="text-sm">{{ props.action.description }}</span>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<Button variant="destructive" @click="confirming = 'approve'"
|
||||
>Approve</Button
|
||||
>
|
||||
<Button variant="destructive" @click="confirming = 'permanent'"
|
||||
>Approve for 24h</Button
|
||||
>
|
||||
<Button variant="default" @click="decide('deny')">Deny</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<AlertDialog :open="confirming !== null" @update:open="onConfirmationOpen">
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
{{
|
||||
confirming === "permanent"
|
||||
? "Approve for 24 hours?"
|
||||
: "Approve this action?"
|
||||
}}
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
<template v-if="confirming === 'permanent'">
|
||||
This runs "{{ description }}" now, and approves its action family
|
||||
for 24 hours — further requests of the same kind run without asking
|
||||
again.
|
||||
</template>
|
||||
<template v-else> This runs "{{ description }}" once, now. </template>
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
variant="destructive"
|
||||
@click="confirming && decide(confirming)"
|
||||
>
|
||||
{{ confirming === "permanent" ? "Approve for 24h" : "Approve" }}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</template>
|
||||
@@ -1,58 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
|
||||
import ConfigCard from "./ConfigCard.vue";
|
||||
import DangerRollbackRequest from "./DangerRollbackRequest.vue";
|
||||
import DangerStopRequest from "./DangerStopRequest.vue";
|
||||
import DangerousActionRow from "./DangerousActionRow.vue";
|
||||
import { dangerous } from "./state";
|
||||
|
||||
/**
|
||||
* Requests and adjudicates the actions that need approval.
|
||||
*
|
||||
* These controls used to sit in the chat panel, which is where they were first
|
||||
* built; installing an update and approving a dangerous action are things you
|
||||
* do to the deployment, not things you say to Archie, so they moved here with
|
||||
* Configuration's other operator controls (archie-core-tf20).
|
||||
*
|
||||
* Nothing here acts on its own: a request only queues an approval, and the
|
||||
* decision buttons are the only thing that lets one run. A deployment that did
|
||||
* not wire the capability answers 501, which leaves `dangerous` null and the
|
||||
* card absent rather than in an error state.
|
||||
*/
|
||||
const pending = computed(() => dangerous.value?.pending ?? []);
|
||||
const checkpoints = computed(() => dangerous.value?.checkpoints ?? []);
|
||||
const error = computed(() => dangerous.value?.error ?? "");
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ConfigCard
|
||||
v-if="dangerous"
|
||||
title="Dangerous actions"
|
||||
:description="
|
||||
error
|
||||
? 'Actions that need explicit approval before they run.'
|
||||
: 'Actions that need explicit approval before they run. Requesting one only queues it.'
|
||||
"
|
||||
>
|
||||
<p v-if="error" class="text-sm text-fg-muted">{{ error }}</p>
|
||||
<template v-else>
|
||||
<!-- Each request is its own row with its own input: they queue
|
||||
different kinds of approval and share nothing but the card. -->
|
||||
<div class="flex flex-col gap-3">
|
||||
<DangerRollbackRequest :checkpoints="checkpoints" />
|
||||
<DangerStopRequest />
|
||||
</div>
|
||||
<p v-if="!pending.length" class="mt-3 text-sm text-fg-muted">
|
||||
No pending dangerous actions.
|
||||
</p>
|
||||
<div v-else class="mt-3">
|
||||
<DangerousActionRow
|
||||
v-for="action in pending"
|
||||
:key="action.id"
|
||||
:action="action"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</ConfigCard>
|
||||
</template>
|
||||
@@ -1,16 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted } from "vue";
|
||||
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import DangerousActionsCard from "./DangerousActionsCard.vue";
|
||||
import { loadDangerous } from "./state";
|
||||
|
||||
onMounted(loadDangerous);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<PageHeader title="Advanced" />
|
||||
<DangerousActionsCard />
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,7 +1,7 @@
|
||||
import { computed, ref } from "vue";
|
||||
|
||||
import { ApiError, api } from "@/lib/api";
|
||||
import type { ConfigView, DangerousActions } from "./types";
|
||||
import { api } from "@/lib/api";
|
||||
import type { ConfigView } from "./types";
|
||||
|
||||
/**
|
||||
* The System pages' shared state.
|
||||
@@ -18,12 +18,6 @@ export function errorText(err: unknown): string {
|
||||
return String((err as Error).message || err);
|
||||
}
|
||||
|
||||
function isMissing(err: unknown): boolean {
|
||||
// 501 is a deployment that did not wire the capability, which is a
|
||||
// legitimate state and a different thing from a broken one.
|
||||
return err instanceof ApiError && err.status === 501;
|
||||
}
|
||||
|
||||
// ── The configuration projection ────────────────────────────────────────────
|
||||
|
||||
export const config = ref<ConfigView | null>(null);
|
||||
@@ -45,30 +39,3 @@ export async function loadConfig(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
// ── Dangerous actions ───────────────────────────────────────────────────────
|
||||
|
||||
export const dangerous = ref<DangerousActions | null>(null);
|
||||
|
||||
export async function loadDangerous(): Promise<void> {
|
||||
try {
|
||||
dangerous.value = await api.chatDangerous<DangerousActions>();
|
||||
} catch (err) {
|
||||
dangerous.value = isMissing(err) ? null : { error: errorText(err) };
|
||||
}
|
||||
}
|
||||
|
||||
export async function requestDangerous(
|
||||
kind: string,
|
||||
spec: unknown,
|
||||
): Promise<void> {
|
||||
await api.chatDangerousRequest(kind, spec);
|
||||
await loadDangerous();
|
||||
}
|
||||
|
||||
export async function decideDangerous(
|
||||
id: string,
|
||||
decision: string,
|
||||
): Promise<void> {
|
||||
await api.chatDangerousDecision(id, decision);
|
||||
await loadDangerous();
|
||||
}
|
||||
@@ -95,23 +95,3 @@ export interface ConfigView {
|
||||
schema?: ConfigSection[];
|
||||
}
|
||||
|
||||
/** A rollback point a dangerous action can target. Number and Label arrive in
|
||||
* either case depending on the source, so both are carried. */
|
||||
export interface DangerCheckpoint {
|
||||
Number?: number;
|
||||
number?: number;
|
||||
Label?: string;
|
||||
label?: string;
|
||||
}
|
||||
|
||||
export interface DangerousAction {
|
||||
id: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
export interface DangerousActions {
|
||||
pending?: DangerousAction[];
|
||||
checkpoints?: DangerCheckpoint[];
|
||||
/** Set when the read failed rather than being unwired. */
|
||||
error?: string;
|
||||
}
|
||||
Reference in new issue
Block a user