New components/ui ReadError (destructive Alert + message + optional Retry) is now the single read-error presentation, used by Versions, Services, Canary, OrgAccess, Denials, Tokens, Audit, Extensions, Harness and the Status page (one page-level error instead of one per card). PanelError is the same alert for task panels, and TasksState's error kind, the attempts panel and the task-log pane all offer Retry. Org policy save errors sit beside the Save button instead of at the page top.
214 lines
7.1 KiB
Vue
214 lines
7.1 KiB
Vue
<script setup lang="ts">
|
|
import { computed, onMounted, ref } from "vue";
|
|
|
|
import { Badge } from "@/components/ui/badge";
|
|
import { ReadError } from "@/components/ui/read-error";
|
|
import { Button } from "@/components/ui/button";
|
|
import CodeView from "@/base/CodeView.vue";
|
|
import { Section } from "@/components/ui/section";
|
|
import {
|
|
Table,
|
|
TableBody,
|
|
TableCell,
|
|
TableHead,
|
|
TableHeader,
|
|
TableRow,
|
|
} from "@/components/ui/table";
|
|
import { Timestamp } from "@/components/ui/timestamp";
|
|
import { ApiError, api } from "@/lib/api";
|
|
import { useLiveResource } from "@/stores/session";
|
|
|
|
/**
|
|
* Per-component versions and the update that applies them: /api/version reports
|
|
* what is running, what the check command claims, what is available and the
|
|
* status between those (ok, update_available, drift, unknown).
|
|
*/
|
|
|
|
interface ComponentVersion {
|
|
id: string;
|
|
label: string;
|
|
install_type?: string;
|
|
reference?: string;
|
|
running_version?: string;
|
|
installed_claim?: string;
|
|
latest_available?: string;
|
|
status: "ok" | "update_available" | "drift" | "unknown";
|
|
}
|
|
|
|
const components = ref<ComponentVersion[]>([]);
|
|
const snapshot = ref<unknown>(null);
|
|
const available = ref<unknown[]>([]);
|
|
const canInstall = ref(false);
|
|
const notConfigured = ref(false);
|
|
const loading = ref(true);
|
|
const loadError = ref<string | null>(null);
|
|
const installing = ref(false);
|
|
const installProgress = ref<string[]>([]);
|
|
const installResult = ref<string | null>(null);
|
|
const installError = ref<string | null>(null);
|
|
const outcome = ref<{ at: string; summary: string; failed: boolean } | null>(null);
|
|
const outcomeError = ref<string | null>(null);
|
|
|
|
const updateable = computed(() =>
|
|
components.value.filter((c) => c.status === "update_available"),
|
|
);
|
|
|
|
const statusKind: Record<
|
|
ComponentVersion["status"],
|
|
"ok" | "warn" | "danger" | "idle"
|
|
> = {
|
|
ok: "ok",
|
|
update_available: "warn",
|
|
drift: "danger",
|
|
unknown: "idle",
|
|
};
|
|
|
|
const statusLabel: Record<ComponentVersion["status"], string> = {
|
|
ok: "",
|
|
update_available: "Update available",
|
|
drift: "Version drift",
|
|
unknown: "Unknown",
|
|
};
|
|
|
|
async function load(): Promise<void> {
|
|
loading.value = true;
|
|
loadError.value = null;
|
|
try {
|
|
const [report, update] = await Promise.all([
|
|
api.version<{ components: ComponentVersion[] }>(),
|
|
api
|
|
.updateSnapshot<{ snapshot: unknown; available: unknown[] | null; can_install: boolean }>()
|
|
.catch((err) => {
|
|
if (err instanceof ApiError && err.status === 501) {
|
|
notConfigured.value = true;
|
|
return null;
|
|
}
|
|
throw err;
|
|
}),
|
|
]);
|
|
components.value = report.components;
|
|
if (update) {
|
|
snapshot.value = update.snapshot;
|
|
available.value = update.available ?? [];
|
|
canInstall.value = update.can_install;
|
|
}
|
|
} catch (err) {
|
|
loadError.value = err instanceof Error ? err.message : String(err);
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
}
|
|
|
|
// The last update's outcome is the update_report event the watchdog records
|
|
// after it restarts and health-checks the daemon.
|
|
async function loadOutcome(): Promise<void> {
|
|
try {
|
|
const page = await api.audit<{
|
|
records: {
|
|
at: string;
|
|
summary: string;
|
|
detail: { data: { health_check?: string; rolled_back?: boolean } | null };
|
|
}[];
|
|
}>({ actions: "update_report", limit: 1 });
|
|
const last = page.records[0];
|
|
const data = last?.detail.data;
|
|
outcome.value = last
|
|
? {
|
|
at: last.at,
|
|
summary: last.summary,
|
|
failed: !!data?.rolled_back || data?.health_check !== "passed",
|
|
}
|
|
: null;
|
|
outcomeError.value = null;
|
|
} catch (err) {
|
|
outcomeError.value = err instanceof Error ? err.message : String(err);
|
|
}
|
|
}
|
|
|
|
// 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(): unknown {
|
|
return snapshot.value && available.value.length ? snapshot.value : null;
|
|
}
|
|
|
|
async function install(): Promise<void> {
|
|
const snap = installableSnapshot();
|
|
if (!snap || installing.value) return;
|
|
installing.value = true;
|
|
installError.value = null;
|
|
installProgress.value = [];
|
|
installResult.value = null;
|
|
try {
|
|
const result = await api.updateInstall<{
|
|
progress?: string[];
|
|
result?: { installed?: Record<string, string> };
|
|
}>(snap);
|
|
installProgress.value = result.progress ?? [];
|
|
const installed = result.result?.installed;
|
|
installResult.value = installed
|
|
? Object.entries(installed)
|
|
.map(([id, version]) => `${id} → ${version}`)
|
|
.join(", ")
|
|
: "update finished";
|
|
installResult.value = `Staged: ${installResult.value}. The outcome appears below after the restart.`;
|
|
await load();
|
|
} catch (err) {
|
|
installError.value = err instanceof Error ? err.message : String(err);
|
|
} finally {
|
|
installing.value = false;
|
|
}
|
|
}
|
|
|
|
onMounted(() => {
|
|
void load();
|
|
void loadOutcome();
|
|
});
|
|
useLiveResource("updates", () => void loadOutcome());
|
|
</script>
|
|
|
|
<template>
|
|
<p v-if="notConfigured" class="text-label text-fg-muted">Update checks not configured.</p>
|
|
<Section v-else title="Versions">
|
|
<ReadError v-if="loadError" :message="loadError" retry-label="Retry" class="mb-3" @retry="load" />
|
|
<p v-else-if="loading" class="text-label text-fg-muted">Checking…</p>
|
|
<template v-else>
|
|
<Table>
|
|
<TableHeader>
|
|
<TableRow>
|
|
<TableHead>Component</TableHead>
|
|
<TableHead>Running</TableHead>
|
|
<TableHead>Available</TableHead>
|
|
<TableHead class="w-full"></TableHead>
|
|
</TableRow>
|
|
</TableHeader>
|
|
<TableBody>
|
|
<TableRow v-for="component in components" :key="component.id">
|
|
<TableCell>{{ component.label || component.id }}</TableCell>
|
|
<TableCell class="font-mono text-fg-muted">{{
|
|
component.running_version || component.installed_claim
|
|
}}</TableCell>
|
|
<TableCell class="font-mono text-fg-muted">{{ component.latest_available }}</TableCell>
|
|
<TableCell>
|
|
<Badge v-if="component.status !== 'ok'" :variant="statusKind[component.status]">{{
|
|
statusLabel[component.status]
|
|
}}</Badge>
|
|
</TableCell>
|
|
</TableRow>
|
|
</TableBody>
|
|
</Table>
|
|
|
|
<Button class="mt-4 self-start" :disabled="installing || !installableSnapshot()" @click="install">{{ installing ? "Installing…" : `Install ${updateable.map((c) => c.label || c.id).join(", ")}`.trim() }}</Button>
|
|
|
|
<CodeView v-if="installProgress.length" :code="installProgress.join('\n')" class="mt-3" />
|
|
<p v-if="installResult" class="mt-2 text-label text-ok">
|
|
{{ installResult }}
|
|
</p>
|
|
<p v-if="outcome" class="mt-2 text-label" :class="outcome.failed ? 'text-danger' : 'text-ok'">
|
|
<Timestamp :at="outcome.at" /> {{ outcome.summary }}
|
|
</p>
|
|
<ReadError v-if="outcomeError" :message="outcomeError" class="mt-2" />
|
|
<ReadError v-if="installError" :message="installError" class="mt-2" />
|
|
</template>
|
|
</Section>
|
|
</template>
|