Merge branch 'main' into worktree-agent-a6a4a1df2423fa389
This commit is contained in:
46 files changed
+2695
-818
No files matched your search
@@ -8,6 +8,7 @@ import { ReadError } from "@/components/ui/read-error";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { DataTable, type DataTableColumn } from "@/components/ui/data-table";
|
||||
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
@@ -15,7 +16,7 @@ import { useDenialsStore } from "@/stores/denials";
|
||||
import { denialResource, type Denial } from "./denials";
|
||||
|
||||
const store = useDenialsStore();
|
||||
const { denials, loading, error } = storeToRefs(store);
|
||||
const { denials, filters, more, loading, error } = storeToRefs(store);
|
||||
|
||||
const columns: DataTableColumn<Denial>[] = [
|
||||
{ id: "at", label: "When", fixed: true, width: "9rem", sort: (d) => d.at },
|
||||
@@ -39,6 +40,15 @@ onMounted(() => void store.load());
|
||||
<ReadError v-if="error" :message="error" retry-label="Retry" class="mb-4" @retry="store.load()" />
|
||||
|
||||
<Section>
|
||||
<form class="mb-3 flex flex-wrap items-center gap-2" @submit.prevent="store.load()">
|
||||
<Input v-model="filters.principal" class="w-48" aria-label="Principal" placeholder="Principal" />
|
||||
<Input v-model="filters.action" class="w-36" aria-label="Action" placeholder="Action" />
|
||||
<Input v-model="filters.kind" class="w-36" aria-label="Resource kind" placeholder="Resource kind" />
|
||||
<Input v-model="filters.since" type="datetime-local" class="w-52" aria-label="From" />
|
||||
<Input v-model="filters.until" type="datetime-local" class="w-52" aria-label="Until" />
|
||||
<Button type="submit" size="sm" :disabled="loading">Filter</Button>
|
||||
<Button type="button" variant="outline" size="sm" :disabled="loading" @click="store.clear()">Clear</Button>
|
||||
</form>
|
||||
<div class="flex flex-col gap-3">
|
||||
<p v-if="loading && !denials.length" class="flex items-center gap-2 text-label text-fg-muted">
|
||||
<Spinner />Loading denials…
|
||||
@@ -57,6 +67,7 @@ onMounted(() => void store.load());
|
||||
<Empty><EmptyHeader><EmptyTitle>No denials recorded</EmptyTitle></EmptyHeader></Empty>
|
||||
</template>
|
||||
<template #cell-at="{ row }"><Timestamp :at="row.at" /></template>
|
||||
<template #cell-action="{ row }"><span class="font-mono text-caption">{{ row.action }}</span></template>
|
||||
<template #cell-principal="{ row }"><span class="font-mono text-caption">{{ row.principal }}</span></template>
|
||||
<template #cell-resource="{ row }"><span class="font-mono text-caption">{{ denialResource(row) }}</span></template>
|
||||
<template #cell-level="{ row }"><Badge variant="idle">{{ row.level }}</Badge></template>
|
||||
@@ -65,6 +76,7 @@ onMounted(() => void store.load());
|
||||
</template>
|
||||
<template #cell-count="{ row }"><span class="tabular-nums">{{ row.count }}</span></template>
|
||||
</DataTable>
|
||||
<Button v-if="more" variant="outline" size="sm" class="self-start" :disabled="loading" @click="store.load(true)">Load older</Button>
|
||||
</div>
|
||||
</Section>
|
||||
</div>
|
||||
|
||||
@@ -14,6 +14,8 @@ export interface Denial {
|
||||
|
||||
export interface DenialsResponse {
|
||||
denials: Denial[];
|
||||
/** Whether older refusals match beyond this page. */
|
||||
more: boolean;
|
||||
}
|
||||
|
||||
/** The resource column: the kind and id together, or just the kind. */
|
||||
|
||||
@@ -1,35 +1,19 @@
|
||||
<script setup lang="ts">
|
||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed } from "vue";
|
||||
import { useSystemHealth } from "@/lib/system-health";
|
||||
|
||||
import { useTasksStore } from "@/stores/tasks";
|
||||
|
||||
import LiveActivityCard from "./LiveActivityCard.vue";
|
||||
import HealthCard from "./HealthCard.vue";
|
||||
import NeedsAttentionCard from "./NeedsAttentionCard.vue";
|
||||
import QuickTask from "./QuickTask.vue";
|
||||
import SetupPanel from "./SetupPanel.vue";
|
||||
import { setupPanelState } from "./setup-preference";
|
||||
import { useDashboard } from "./state";
|
||||
import RecentRunsCard from "./RecentRunsCard.vue";
|
||||
|
||||
/** Start work, then see what needs you and what is happening. Setup takes a
|
||||
* rail only while it is incomplete. */
|
||||
const { error, setup, summary } = storeToRefs(useTasksStore());
|
||||
useDashboard();
|
||||
|
||||
const setupIncomplete = computed(() => setupPanelState(setup.value).kind === "incomplete");
|
||||
/** What is wrong, what waits on you, then what ran. */
|
||||
const { data: health, error, reload } = useSystemHealth();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<h1 class="sr-only">Dashboard</h1>
|
||||
<Alert v-if="error" variant="destructive" class="mb-4"><AlertDescription>{{ errors.dashboard.page.unresponsive(error) }}</AlertDescription></Alert>
|
||||
<div :class="setupIncomplete ? 'grid items-start gap-4 @3xl:grid-cols-[minmax(0,1fr)_320px]' : 'mx-auto max-w-5xl'">
|
||||
<div class="grid min-w-0 gap-4">
|
||||
<QuickTask class="mb-2" />
|
||||
<NeedsAttentionCard />
|
||||
<LiveActivityCard v-if="summary" />
|
||||
</div>
|
||||
<SetupPanel v-if="setupIncomplete" class="@max-3xl:-order-1" />
|
||||
<h1 class="sr-only">Home</h1>
|
||||
<div class="mx-auto grid max-w-5xl min-w-0 gap-4">
|
||||
<HealthCard :health="health" :error="error" @retry="reload" />
|
||||
<NeedsAttentionCard />
|
||||
<RecentRunsCard />
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,60 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
import { RouterLink } from "vue-router";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Item, ItemGroup } from "@/components/ui/item";
|
||||
import { ReadError } from "@/components/ui/read-error";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { StatusDot } from "@/components/ui/status-dot";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
import type { SystemHealth } from "@/lib/api";
|
||||
|
||||
const props = defineProps<{ health?: SystemHealth; error: string }>();
|
||||
defineEmits<{ retry: [] }>();
|
||||
|
||||
interface Problem {
|
||||
key: string;
|
||||
label: string;
|
||||
cause: string;
|
||||
at?: string;
|
||||
}
|
||||
|
||||
// Only what is wrong is listed; a healthy part is the absence of a row.
|
||||
const problems = computed<Problem[]>(() => {
|
||||
const h = props.health;
|
||||
if (!h) return [];
|
||||
return [
|
||||
...h.checks.filter((c) => !c.healthy).map((c) => ({ key: `check:${c.name}`, label: c.name, cause: c.error ?? "" })),
|
||||
...h.connectors
|
||||
.filter((c) => !c.healthy)
|
||||
.map((c) => ({ key: `connector:${c.name}`, label: c.name, cause: c.error ?? "", at: c.failed_at })),
|
||||
...(h.runner.healthy ? [] : [{ key: "runner", label: "runner", cause: h.runner.error ?? "", at: h.runner.error_at }]),
|
||||
];
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ReadError v-if="error && !health" :message="error" retry-label="Retry" @retry="$emit('retry')" />
|
||||
<Section v-else-if="health" title="Health" class="mb-0">
|
||||
<template #action>
|
||||
<Button variant="ghost" size="sm" as-child><RouterLink to="/settings/status">Status</RouterLink></Button>
|
||||
</template>
|
||||
<p v-if="!problems.length" class="flex items-center gap-2 text-label">
|
||||
<StatusDot tone="ok" />Everything is working
|
||||
<span class="font-mono text-caption text-fg-muted">{{ health.version }}</span>
|
||||
</p>
|
||||
<ItemGroup v-else>
|
||||
<Item v-for="problem in problems" :key="problem.key" as="li" variant="outline" size="xs">
|
||||
<Badge variant="danger">unhealthy</Badge>
|
||||
<div class="min-w-0 flex-1">
|
||||
<p class="truncate font-medium font-mono">{{ problem.label }}</p>
|
||||
<p class="break-words text-caption text-fg-muted" :title="problem.cause">
|
||||
{{ problem.cause.split("\n")[0] }}<template v-if="problem.at"> · <Timestamp :at="problem.at" /></template>
|
||||
</p>
|
||||
</div>
|
||||
</Item>
|
||||
</ItemGroup>
|
||||
</Section>
|
||||
</template>
|
||||
@@ -1,243 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed, reactive, ref } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
|
||||
import { ChevronDown, ChevronRight } from "@lucide/vue";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { StatusDot } from "@/components/ui/status-dot";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import { useSessionStore } from "@/stores/session";
|
||||
import { useTasksStore } from "@/stores/tasks";
|
||||
import { useAlerts } from "@/alerts/use-alerts";
|
||||
import ActivityRow from "./ActivityRow.vue";
|
||||
import { useOrgStore } from "@/stores/org";
|
||||
import { activityDetail } from "./activity-detail";
|
||||
import {
|
||||
ACTIVITY_FILTERS,
|
||||
activityEmptyTitle,
|
||||
filterActivity,
|
||||
type ActivityFilter,
|
||||
} from "./activity-filter";
|
||||
import { groupActivity, type ActivityGroup } from "./activity-group";
|
||||
import { describeTimelineEvent } from "@/tasks/timeline-event";
|
||||
|
||||
const identities = useOrgStore();
|
||||
identities.watchIdentities();
|
||||
|
||||
/**
|
||||
* The last 50 events, newest first, with the stream's own state on the card and
|
||||
* the All / Tasks / System filter over it. The filter and the grouping rules
|
||||
* live in activity-filter.ts and activity-group.ts and are tested there; this
|
||||
* card only renders their result.
|
||||
*/
|
||||
|
||||
const router = useRouter();
|
||||
const { summary } = storeToRefs(useTasksStore());
|
||||
const running = computed(() => summary.value?.statuses?.running || 0);
|
||||
|
||||
// Open alerts lead the feed until resolved: a stream event scrolls away, the
|
||||
// condition it reported does not.
|
||||
const { alerts } = useAlerts();
|
||||
|
||||
const { activity } = storeToRefs(
|
||||
useSessionStore(),
|
||||
);
|
||||
|
||||
/** Which view of the feed is showing: everything, task runs, or the daemon's
|
||||
* own background work. */
|
||||
const filter = ref<ActivityFilter>("tasks");
|
||||
const shown = computed(() => filterActivity(activity.value, filter.value));
|
||||
// A blocked task already leads the page under Needs attention.
|
||||
const pinned = computed(() =>
|
||||
filter.value === "tasks"
|
||||
? []
|
||||
: alerts.value.filter((alert) => alert.kind !== "task.needs_decision"),
|
||||
);
|
||||
const emptyTitle = computed(() =>
|
||||
activityEmptyTitle(shown.value.length, filter.value),
|
||||
);
|
||||
|
||||
// Expansion is keyed on label:taskID, so a live run stays open as its events
|
||||
// arrive, and a collapsed group re-collapses only when the run breaks.
|
||||
const expanded = reactive(new Set<string>());
|
||||
const groups = computed(() => groupActivity(shown.value));
|
||||
|
||||
function toggle(key: string) {
|
||||
if (expanded.has(key)) expanded.delete(key);
|
||||
else expanded.add(key);
|
||||
}
|
||||
|
||||
function isOpen(group: ActivityGroup): boolean {
|
||||
return expanded.has(group.key);
|
||||
}
|
||||
|
||||
// The collapsed group row shows what its newest event would have shown, so
|
||||
// expanding and collapsing moves no information.
|
||||
function groupDetail(group: ActivityGroup) {
|
||||
return activityDetail(group.representative, identities.identityName);
|
||||
}
|
||||
|
||||
function openTask(taskID: number) {
|
||||
void router.push(`/tasks?task=${encodeURIComponent(taskID)}`);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Section :title="running ? `Activity · ${running} running` : 'Activity'" class="mb-0">
|
||||
<template #action>
|
||||
<ToggleGroup type="single" variant="outline" size="sm" :model-value="filter" aria-label="Filter activity" @update:model-value="(value) => { if (value) filter = value as typeof filter; }">
|
||||
<ToggleGroupItem v-for="option in ACTIVITY_FILTERS" :key="option.value" :value="option.value">{{ option.label }}</ToggleGroupItem>
|
||||
</ToggleGroup>
|
||||
</template>
|
||||
<!--
|
||||
role="region" names the table for landmark navigation; aria-live is
|
||||
polite, not assertive, because rows arrive constantly while the stream
|
||||
is live and an assertive region would talk over the operator. The live
|
||||
region is the table's wrapper, so new rows are announced as they
|
||||
appear without a second hidden summary to keep in sync.
|
||||
-->
|
||||
<div role="region" aria-label="Activity" aria-live="polite">
|
||||
<!--
|
||||
The feed's height is bounded to the card, not the page: group rows
|
||||
multiply with the number of interleaved tasks, so an unbounded table
|
||||
would push the rest of the dashboard off screen. The newest events
|
||||
stay visible at the top; the rest scroll inside the card. The header
|
||||
stays put via sticky so the columns keep their labels while scrolling.
|
||||
-->
|
||||
<div class="max-h-[28rem] overflow-y-auto">
|
||||
<Table>
|
||||
<TableHeader class="sticky top-0 z-10 bg-card">
|
||||
<TableRow>
|
||||
<TableHead>Event</TableHead>
|
||||
<TableHead>Task</TableHead>
|
||||
<TableHead>Detail</TableHead>
|
||||
<TableHead>When</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<TableRow v-for="alert in pinned" :key="`alert:${alert.id}`">
|
||||
<TableCell class="font-medium">
|
||||
<span class="inline-flex items-center gap-1.5">
|
||||
<StatusDot tone="warn" />Alert
|
||||
<Badge v-if="alert.count > 1" variant="idle">×{{ alert.count }}</Badge>
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell class="font-mono">–</TableCell>
|
||||
<TableCell class="w-[55%] max-w-0">
|
||||
<span class="flex items-center gap-3">
|
||||
<Tooltip>
|
||||
<TooltipTrigger as-child>
|
||||
<span tabindex="0" class="min-w-0 flex-1 truncate">{{ alert.title }}</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent v-if="alert.body">{{ alert.body }}</TooltipContent>
|
||||
</Tooltip>
|
||||
<RouterLink v-if="alert.link" :to="alert.link" class="shrink-0 text-warn hover:underline">Fix →</RouterLink>
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell><Timestamp :at="alert.last_seen" /></TableCell>
|
||||
</TableRow>
|
||||
<TableRow v-if="!shown.length && !pinned.length">
|
||||
<TableCell colspan="4">
|
||||
<Empty>
|
||||
<EmptyHeader>
|
||||
<EmptyTitle>{{ emptyTitle }}</EmptyTitle>
|
||||
</EmptyHeader>
|
||||
</Empty>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
<template v-if="shown.length">
|
||||
<template v-for="group in groups" :key="group.key">
|
||||
<!-- A singleton is exactly the row the raw feed would show. -->
|
||||
<ActivityRow
|
||||
v-if="group.count === 1"
|
||||
:event="group.representative"
|
||||
@open="openTask"
|
||||
/>
|
||||
<template v-else>
|
||||
<!--
|
||||
The row stays a row: mouse clicks open the task via the
|
||||
row handler, and the first cell holds the two real focus
|
||||
targets -- the disclosure button and, when the group
|
||||
resolves to a task, an open button carrying its title.
|
||||
-->
|
||||
<TableRow
|
||||
:class="group.taskID > 0 ? 'cursor-pointer' : ''"
|
||||
@click="group.taskID > 0 && openTask(group.taskID)"
|
||||
>
|
||||
<TableCell class="font-medium">
|
||||
<div class="flex items-center gap-1">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center rounded hover:opacity-80 focus-visible:outline-2 focus-visible:outline-ring"
|
||||
:aria-expanded="isOpen(group)"
|
||||
:aria-label="`${isOpen(group) ? 'Hide' : 'Show'} ${group.count} ${group.label} events`"
|
||||
@click.stop="toggle(group.key)"
|
||||
>
|
||||
<ChevronDown
|
||||
v-if="isOpen(group)"
|
||||
class="size-3.5 shrink-0 text-fg-subtle"
|
||||
/>
|
||||
<ChevronRight
|
||||
v-else
|
||||
class="size-3.5 shrink-0 text-fg-subtle"
|
||||
/>
|
||||
</button>
|
||||
<button
|
||||
v-if="group.taskID > 0"
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded hover:opacity-80 focus-visible:outline-2 focus-visible:outline-ring"
|
||||
aria-label="Open task details"
|
||||
@click.stop="openTask(group.taskID)"
|
||||
>
|
||||
{{ describeTimelineEvent({ ...group.representative, at: undefined, detail: undefined }).title }}
|
||||
<Badge variant="idle">×{{ group.count }}</Badge>
|
||||
</button>
|
||||
<template v-else>
|
||||
{{ describeTimelineEvent({ ...group.representative, at: undefined, detail: undefined }).title }}
|
||||
<Badge variant="idle">×{{ group.count }}</Badge>
|
||||
</template>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell class="font-mono">{{
|
||||
group.taskID > 0 ? `#${group.taskID}` : "–"
|
||||
}}</TableCell>
|
||||
<TableCell class="w-[55%] max-w-0">
|
||||
<Tooltip>
|
||||
<TooltipTrigger as-child>
|
||||
<span tabindex="0" class="block truncate">{{ groupDetail(group).text }}</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent v-if="groupDetail(group).truncated">{{ groupDetail(group).full }}</TooltipContent>
|
||||
</Tooltip>
|
||||
</TableCell>
|
||||
<TableCell><Timestamp :at="group.representative.at" /></TableCell>
|
||||
</TableRow>
|
||||
<template v-if="isOpen(group)">
|
||||
<ActivityRow
|
||||
v-for="(event, i) in group.events"
|
||||
:key="`${group.key}:${i}`"
|
||||
:event="event"
|
||||
@open="openTask"
|
||||
/>
|
||||
</template>
|
||||
</template>
|
||||
</template>
|
||||
</template>
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
</div>
|
||||
</Section>
|
||||
</template>
|
||||
@@ -1,64 +1,83 @@
|
||||
<script setup lang="ts">
|
||||
import { Item, ItemGroup } from "@/components/ui/item";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed } from "vue";
|
||||
import { computed, onMounted } from "vue";
|
||||
import { RouterLink } from "vue-router";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Item, ItemGroup } from "@/components/ui/item";
|
||||
import { ReadError } from "@/components/ui/read-error";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { attentionStatusIds, statusLabel } from "@/lib/task-meta";
|
||||
import TaskRowActions from "@/tasks/TaskRowActions.vue";
|
||||
import type { Task } from "@/tasks/task";
|
||||
import { useTasksStore } from "@/stores/tasks";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
import { api } from "@/lib/api";
|
||||
import { usePoll, useRead } from "@/lib/use-read";
|
||||
import { useLiveResource } from "@/stores/session";
|
||||
|
||||
const { tasks } = storeToRefs(useTasksStore());
|
||||
const loadDashboard = useTasksStore().load;
|
||||
/** What waits on a person: approval requests, and runs a step parked. Each
|
||||
* links to the run that needs the answer. */
|
||||
const approvals = useRead(() => api.approvals());
|
||||
const runs = useRead(() => api.runs());
|
||||
function reload(): void {
|
||||
void approvals.reload();
|
||||
void runs.reload();
|
||||
}
|
||||
onMounted(reload);
|
||||
useLiveResource(null, reload);
|
||||
usePoll(reload);
|
||||
|
||||
/** Tasks needing attention, each with the reason and the next action. */
|
||||
type AttentionTask = Task & { park_reason?: string; plan?: string };
|
||||
interface Waiting {
|
||||
key: string;
|
||||
badge: string;
|
||||
title: string;
|
||||
caption: string;
|
||||
run: string;
|
||||
at?: string;
|
||||
}
|
||||
|
||||
const waiting = computed(() => {
|
||||
const ids = attentionStatusIds();
|
||||
return ((tasks.value ?? []) as AttentionTask[]).filter((t) => t.status && ids.has(t.status));
|
||||
});
|
||||
const waiting = computed<Waiting[]>(() => [
|
||||
...(approvals.data.value ?? [])
|
||||
.filter((a) => a.state === "pending")
|
||||
.map((a) => ({
|
||||
key: `approval:${a.id}`,
|
||||
badge: "Approval",
|
||||
title: a.summary || a.action,
|
||||
caption: [a.action, a.target].filter(Boolean).join(" on "),
|
||||
run: a.run_id,
|
||||
at: a.requested_at,
|
||||
})),
|
||||
...(runs.data.value ?? [])
|
||||
.filter((r) => r.state === "parked")
|
||||
.map((r) => ({
|
||||
key: `run:${r.id}`,
|
||||
badge: "Parked",
|
||||
title: r.workflow,
|
||||
caption: r.detail || r.error || "",
|
||||
run: r.id,
|
||||
at: r.created_at,
|
||||
})),
|
||||
]);
|
||||
|
||||
// Each row mounts its own action menu, so an unbounded list freezes the page
|
||||
// when many tasks park at once; the rest are one click away on the tasks page.
|
||||
// Each row is cheap, but the full list is one click away on the runs page.
|
||||
const shown = computed(() => waiting.value.slice(0, 5));
|
||||
|
||||
function meta(task: AttentionTask): string {
|
||||
const where = task.owner && task.repo ? `${task.owner}/${task.repo}${task.issue_url && task.issue_number ? ` #${task.issue_number}` : ""}` : "";
|
||||
return [where, task.workflow].filter(Boolean).join(" · ");
|
||||
}
|
||||
|
||||
// A blocker's summary says what is missing; the raw reason stays on hover and
|
||||
// on the task page.
|
||||
function reason(task: AttentionTask): string {
|
||||
return task.recovery?.summary || task.park_reason || task.plan || "";
|
||||
}
|
||||
const error = computed(() => approvals.error.value || runs.error.value);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Section v-if="waiting.length" title="Needs attention" class="mb-0">
|
||||
<ReadError v-if="error" :message="error" retry-label="Retry" @retry="reload" />
|
||||
<Section v-else-if="waiting.length" title="Needs attention" class="mb-0">
|
||||
<template #action>
|
||||
<Button variant="ghost" size="sm" as-child><RouterLink to="/tasks?status=needs_attention">{{ waiting.length > shown.length ? `All ${waiting.length}` : "All tasks" }}</RouterLink></Button>
|
||||
<Button variant="ghost" size="sm" as-child><RouterLink to="/runs">{{ waiting.length > shown.length ? `All ${waiting.length}` : "All runs" }}</RouterLink></Button>
|
||||
</template>
|
||||
<ItemGroup>
|
||||
<Item v-for="task in shown" :key="task.id" as="li" variant="outline" size="xs">
|
||||
<Badge variant="warn">{{ statusLabel(task.status ?? "") }}</Badge>
|
||||
<div class="min-w-0 flex-1">
|
||||
<RouterLink :to="`/tasks/${task.id}`" class="block truncate font-medium hover:underline">{{
|
||||
task.title || `Task ${task.id}`
|
||||
}}</RouterLink>
|
||||
<p class="truncate text-caption text-fg-muted" :title="task.park_reason || undefined">
|
||||
{{ [meta(task), reason(task)].filter(Boolean).join(" · ") }}
|
||||
</p>
|
||||
</div>
|
||||
<Button v-if="task.recovery" as-child size="sm">
|
||||
<RouterLink :to="task.recovery.link">{{ task.recovery.label }}</RouterLink>
|
||||
</Button>
|
||||
<TaskRowActions :task="task" :secondary="!!task.recovery" @done="loadDashboard" />
|
||||
</Item>
|
||||
<Item v-for="item in shown" :key="item.key" as="li" variant="outline" size="xs">
|
||||
<Badge variant="warn">{{ item.badge }}</Badge>
|
||||
<div class="min-w-0 flex-1">
|
||||
<RouterLink :to="`/runs/${item.run}`" class="block truncate font-medium hover:underline">{{ item.title }}</RouterLink>
|
||||
<p class="truncate text-caption text-fg-muted">
|
||||
{{ item.caption }}<template v-if="item.at"> · <Timestamp :at="item.at" /></template>
|
||||
</p>
|
||||
</div>
|
||||
<Button as-child size="sm"><RouterLink :to="`/runs/${item.run}`">Review</RouterLink></Button>
|
||||
</Item>
|
||||
</ItemGroup>
|
||||
</Section>
|
||||
</template>
|
||||
@@ -0,0 +1,80 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||
import { ReadError } from "@/components/ui/read-error";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
|
||||
import { api } from "@/lib/api";
|
||||
import { usePoll, useRead } from "@/lib/use-read";
|
||||
import { ended, stateTone } from "@/runs/state";
|
||||
import { useLiveResource } from "@/stores/session";
|
||||
|
||||
/** The latest runs, newest first, filtered to all, those still going, or
|
||||
* those that failed. */
|
||||
const router = useRouter();
|
||||
const { data, error, reload } = useRead(() => api.runs(50));
|
||||
onMounted(reload);
|
||||
useLiveResource(null, () => void reload());
|
||||
usePoll(reload);
|
||||
|
||||
const FILTERS = [
|
||||
{ value: "all", label: "All" },
|
||||
{ value: "active", label: "Active" },
|
||||
{ value: "failed", label: "Failed" },
|
||||
] as const;
|
||||
const filter = ref<(typeof FILTERS)[number]["value"]>("all");
|
||||
|
||||
const shown = computed(() =>
|
||||
(data.value ?? []).filter((r) => {
|
||||
if (filter.value === "active") return !ended(r.state);
|
||||
if (filter.value === "failed") return r.state === "failed";
|
||||
return true;
|
||||
}),
|
||||
);
|
||||
const running = computed(() => (data.value ?? []).filter((r) => r.state === "running").length);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ReadError v-if="error && !data" :message="error" retry-label="Retry" @retry="reload" />
|
||||
<Section v-else :title="running ? `Runs · ${running} running` : 'Runs'" class="mb-0">
|
||||
<template #action>
|
||||
<ToggleGroup type="single" variant="outline" size="sm" :model-value="filter" aria-label="Filter runs" @update:model-value="(value) => { if (value) filter = value as typeof filter; }">
|
||||
<ToggleGroupItem v-for="option in FILTERS" :key="option.value" :value="option.value">{{ option.label }}</ToggleGroupItem>
|
||||
</ToggleGroup>
|
||||
</template>
|
||||
<div v-if="!data" role="status" aria-label="Loading runs" class="space-y-2"><Skeleton class="h-8 w-full" /><Skeleton class="h-8 w-full" /></div>
|
||||
<div v-else class="max-h-[28rem] overflow-y-auto">
|
||||
<Table>
|
||||
<TableHeader class="sticky top-0 z-10 bg-card">
|
||||
<TableRow>
|
||||
<TableHead>Workflow</TableHead>
|
||||
<TableHead>State</TableHead>
|
||||
<TableHead>Detail</TableHead>
|
||||
<TableHead>Started</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<TableRow v-if="!shown.length">
|
||||
<TableCell colspan="4">
|
||||
<Empty><EmptyHeader><EmptyTitle>{{ filter === "all" ? "No runs yet" : `No ${filter} runs` }}</EmptyTitle></EmptyHeader></Empty>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
<TableRow v-for="run in shown" :key="run.id" class="cursor-pointer" @click="router.push(`/runs/${run.id}`)">
|
||||
<TableCell class="font-medium">
|
||||
<RouterLink :to="`/runs/${run.id}`" class="rounded-sm hover:underline focus-visible:outline-2 focus-visible:outline-ring" @click.stop>{{ run.workflow }}</RouterLink>
|
||||
</TableCell>
|
||||
<TableCell><Badge :variant="stateTone(run.state)">{{ run.state }}</Badge></TableCell>
|
||||
<TableCell class="w-[55%] max-w-0"><span class="block truncate" :title="run.error || run.detail || undefined">{{ run.error || run.detail }}</span></TableCell>
|
||||
<TableCell><Timestamp :at="run.created_at" /></TableCell>
|
||||
</TableRow>
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
</Section>
|
||||
</template>
|
||||
+60
-3
@@ -279,10 +279,11 @@ export const api = {
|
||||
publishProposal: (id: string) =>
|
||||
request<MemoryNote>(`/api/memory/proposals/${encodeURIComponent(id)}/publish`, { method: "POST", body: {} }),
|
||||
health: <T = unknown>() => request<T>("/health/detailed"),
|
||||
services: <T = unknown>() => request<T>("/api/services"),
|
||||
systemHealth: () => request<SystemHealth>("/api/system/health"),
|
||||
bootstrap: () => request<Bootstrap>("/api/system/bootstrap"),
|
||||
policies: <T = unknown>() => request<T>("/api/access/policies"),
|
||||
denials: <T = unknown>(limit?: number) =>
|
||||
request<T>(`/api/access/denials${limit ? `?limit=${limit}` : ""}`),
|
||||
denials: <T = unknown>(params: QueryParams = {}) =>
|
||||
request<T>("/api/access/denials" + qs(params)),
|
||||
putPolicy: (policy: unknown) =>
|
||||
request<{ version: number }>("/api/access/policies", { method: "PUT", body: policy }),
|
||||
deletePolicy: (policy: unknown) =>
|
||||
@@ -359,6 +360,17 @@ export const api = {
|
||||
qs({ workspace }),
|
||||
{ method: "DELETE", parse: false },
|
||||
),
|
||||
/** Suspending stops a member acting at once; their memberships stay. */
|
||||
suspendOrgMember: (id: string, identity: string) =>
|
||||
request<void>(
|
||||
`/api/orgs/${encodeURIComponent(id)}/members/${encodeURIComponent(identity)}/suspend`,
|
||||
{ method: "POST", parse: false },
|
||||
),
|
||||
reactivateOrgMember: (id: string, identity: string) =>
|
||||
request<void>(
|
||||
`/api/orgs/${encodeURIComponent(id)}/members/${encodeURIComponent(identity)}/reactivate`,
|
||||
{ method: "POST", parse: false },
|
||||
),
|
||||
assignOrgAgent: <T = unknown>(id: string, identity: string) =>
|
||||
request<T>(
|
||||
`/api/orgs/${encodeURIComponent(id)}/agents/${encodeURIComponent(identity)}`,
|
||||
@@ -715,6 +727,51 @@ export interface ApprovalAssertion {
|
||||
credential: unknown;
|
||||
}
|
||||
|
||||
/** One module's or dependency's readiness. */
|
||||
export interface HealthCheck {
|
||||
name: string;
|
||||
healthy: boolean;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
/** One accepted package: a connector, secret engine, guard or MCP server. */
|
||||
export interface ConnectorHealth {
|
||||
name: string;
|
||||
contract: string;
|
||||
healthy: boolean;
|
||||
error?: string;
|
||||
failed_at?: string;
|
||||
}
|
||||
|
||||
export interface RunCounts {
|
||||
queued: number;
|
||||
running: number;
|
||||
waiting: number;
|
||||
waiting_approval: number;
|
||||
parked: number;
|
||||
}
|
||||
|
||||
/** What the binary reports about itself: GET /api/system/health. */
|
||||
export interface SystemHealth {
|
||||
version: string;
|
||||
healthy: boolean;
|
||||
checked_at: string;
|
||||
checks: HealthCheck[];
|
||||
connectors: ConnectorHealth[];
|
||||
runner: { healthy: boolean; workers: number; error?: string; error_at?: string };
|
||||
waiting?: { approvals: number; runs: RunCounts };
|
||||
last_failure?: { source: string; cause: string; at: string; run_id?: string };
|
||||
}
|
||||
|
||||
/** The values only the config file sets: GET /api/system/bootstrap. */
|
||||
export interface Bootstrap {
|
||||
listen: string;
|
||||
database_host: string;
|
||||
schemas: number;
|
||||
admin_token_set: boolean;
|
||||
sealing_identity_set: boolean;
|
||||
}
|
||||
|
||||
export interface ApprovalConfirmation {
|
||||
token: string;
|
||||
options: { publicKey: Record<string, unknown> };
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { onMounted } from "vue";
|
||||
|
||||
import { api } from "@/lib/api";
|
||||
import { usePoll, useRead } from "@/lib/use-read";
|
||||
|
||||
/** The binary's health, read on mount and every 15 seconds. The Home page and
|
||||
* the Status page share it. */
|
||||
export function useSystemHealth() {
|
||||
const read = useRead(() => api.systemHealth());
|
||||
onMounted(read.reload);
|
||||
usePoll(read.reload, 15_000);
|
||||
return read;
|
||||
}
|
||||
@@ -7,7 +7,10 @@ import CreateAccount from "@/accounts/CreateAccount.vue";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { Plus, Trash2 } from "@lucide/vue";
|
||||
import { Pause, Play, Plus, Trash2 } from "@lucide/vue";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
@@ -128,6 +131,16 @@ const setRole = (member: Member, role: unknown) =>
|
||||
await load();
|
||||
});
|
||||
|
||||
const toggleStatus = (member: Member) =>
|
||||
run(member.identity_id + "status", async () => {
|
||||
if (!org.value) return;
|
||||
await (member.status === "suspended" ? api.reactivateOrgMember : api.suspendOrgMember)(
|
||||
org.value.id,
|
||||
member.identity_id,
|
||||
);
|
||||
await load();
|
||||
});
|
||||
|
||||
const pending = ref<Member | null>(null);
|
||||
const remove = (member: Member) =>
|
||||
run(member.identity_id + (member.workspace_id ?? ""), async () => {
|
||||
@@ -151,7 +164,9 @@ const remove = (member: Member) =>
|
||||
<TableHead class="w-28">Kind</TableHead>
|
||||
<TableHead class="w-44">Workspace</TableHead>
|
||||
<TableHead class="w-44">Role</TableHead>
|
||||
<TableHead class="w-24 text-right">Actions</TableHead>
|
||||
<TableHead class="w-28">Status</TableHead>
|
||||
<TableHead class="w-40">Last sign-in</TableHead>
|
||||
<TableHead class="w-28 text-right">Actions</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
@@ -169,7 +184,22 @@ const remove = (member: Member) =>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</TableCell>
|
||||
<TableCell><Badge :variant="member.status === 'active' ? 'ok' : 'idle'">{{ member.status }}</Badge></TableCell>
|
||||
<TableCell class="text-label text-fg-subtle"><Timestamp v-if="member.last_sign_in" :at="member.last_sign_in" /><template v-else>–</template></TableCell>
|
||||
<TableCell class="text-right">
|
||||
<Tooltip v-if="!member.workspace_id && member.kind !== 'system'">
|
||||
<TooltipTrigger as-child>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
:aria-label="`${member.status === 'suspended' ? 'Reactivate' : 'Suspend'} ${member.display_name}`"
|
||||
:disabled="busy !== ''"
|
||||
@click="toggleStatus(member)"
|
||||
><Play v-if="member.status === 'suspended'" /><Pause v-else
|
||||
/></Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{{ member.status === "suspended" ? "Reactivate" : "Suspend" }}</TooltipContent>
|
||||
</Tooltip>
|
||||
<Tooltip>
|
||||
<TooltipTrigger as-child>
|
||||
<Button
|
||||
@@ -177,7 +207,7 @@ const remove = (member: Member) =>
|
||||
size="icon"
|
||||
:aria-label="`Remove ${member.display_name}`"
|
||||
:disabled="busy !== ''"
|
||||
@click="remove(member)"
|
||||
@click="pending = member"
|
||||
><Trash2
|
||||
/></Button>
|
||||
</TooltipTrigger>
|
||||
@@ -186,10 +216,10 @@ const remove = (member: Member) =>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
<TableRow v-if="loading">
|
||||
<TableCell colspan="5" class="text-label text-fg-muted" role="status">Loading members…</TableCell>
|
||||
<TableCell colspan="7" class="text-label text-fg-muted" role="status">Loading members…</TableCell>
|
||||
</TableRow>
|
||||
<TableRow v-else-if="!members.length && !error">
|
||||
<TableCell colspan="5">
|
||||
<TableCell colspan="7">
|
||||
<Empty class="py-6">
|
||||
<EmptyHeader>
|
||||
<EmptyTitle>No members yet</EmptyTitle>
|
||||
@@ -202,8 +232,8 @@ const remove = (member: Member) =>
|
||||
</Section>
|
||||
|
||||
<CreateAccount v-if="org?.id===identities.homeOrg" @created="load" />
|
||||
<div class="grid gap-4 lg:grid-cols-2">
|
||||
<Section title="Add an identity" class="mb-0">
|
||||
<div class="grid gap-4" :class="candidates.length ? 'lg:grid-cols-2' : ''">
|
||||
<Section v-if="candidates.length" title="Add an identity" class="mb-0">
|
||||
<form class="flex flex-wrap items-center gap-2" @submit.prevent="add">
|
||||
<Select v-model="picked">
|
||||
<SelectTrigger class="w-64" aria-label="Identity">
|
||||
|
||||
@@ -47,4 +47,7 @@ export interface Member {
|
||||
display_name: string;
|
||||
workspace_id?: string;
|
||||
role: Role;
|
||||
/** The identity's lifecycle; a suspended member keeps the role but cannot act. */
|
||||
status: "active" | "suspended" | "retired";
|
||||
last_sign_in?: string;
|
||||
}
|
||||
@@ -52,7 +52,7 @@ export const routes: RouteRecordRaw[] = [
|
||||
meta: {
|
||||
label: "Dashboard",
|
||||
description:
|
||||
"Running work, work needing attention, token spend.",
|
||||
"Health, what waits on a person, and recent runs.",
|
||||
section: "home",
|
||||
},
|
||||
},
|
||||
@@ -185,7 +185,7 @@ export const routes: RouteRecordRaw[] = [
|
||||
settings: true,
|
||||
label: "Status",
|
||||
description:
|
||||
"Service presence, dependency health, and build versions.",
|
||||
"Module, connector and runner health, and the running version.",
|
||||
section: "system_status",
|
||||
},
|
||||
},
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
<script setup lang="ts">
|
||||
import { ChevronDown } from "@lucide/vue";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { DataTable, type DataTableColumn } from "@/components/ui/data-table";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
import type { ConnectorHealth, HealthCheck } from "@/lib/api";
|
||||
|
||||
defineProps<{ checks: HealthCheck[]; connectors: ConnectorHealth[] }>();
|
||||
|
||||
const contract: Record<string, string> = {
|
||||
connector: "Connector",
|
||||
secretengine: "Secret engine",
|
||||
guard: "Guard",
|
||||
mcp: "MCP server",
|
||||
};
|
||||
|
||||
const moduleColumns: DataTableColumn<HealthCheck>[] = [
|
||||
{ id: "name", label: "Module", fixed: true },
|
||||
{ id: "state", label: "State" },
|
||||
];
|
||||
const connectorColumns: DataTableColumn<ConnectorHealth>[] = [
|
||||
{ id: "name", label: "Connector", fixed: true },
|
||||
{ id: "kind", label: "Kind" },
|
||||
{ id: "failed", label: "Failed", hidden: true },
|
||||
{ id: "state", label: "State" },
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Section title="Modules">
|
||||
<DataTable :columns="moduleColumns" :rows="checks" :row-key="(row) => row.name" storage-key="status.modules">
|
||||
<template #cell-name="{ row }"><span class="font-mono">{{ row.name }}</span></template>
|
||||
<template #cell-state="{ row }">
|
||||
<Popover v-if="!row.healthy">
|
||||
<PopoverTrigger as-child>
|
||||
<Button type="button" variant="ghost" class="h-auto rounded-sm p-0" :aria-label="`Why ${row.name} is unhealthy`">
|
||||
<Badge variant="danger">unhealthy<ChevronDown data-icon="inline-end" /></Badge>
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent align="start" class="w-96 max-w-[calc(100vw-2rem)] space-y-1 text-label">
|
||||
<p class="whitespace-pre-line break-words">{{ row.error }}</p>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</template>
|
||||
</DataTable>
|
||||
</Section>
|
||||
<Section v-if="connectors.length" title="Connectors">
|
||||
<DataTable :columns="connectorColumns" :rows="connectors" :row-key="(row) => row.name" storage-key="status.connectors">
|
||||
<template #cell-name="{ row }"><span class="font-mono">{{ row.name }}</span></template>
|
||||
<template #cell-kind="{ row }"><span class="text-fg-muted">{{ contract[row.contract] ?? row.contract }}</span></template>
|
||||
<template #cell-failed="{ row }"><Timestamp v-if="row.failed_at" :at="row.failed_at" class="text-fg-muted" /></template>
|
||||
<template #cell-state="{ row }">
|
||||
<Popover v-if="!row.healthy">
|
||||
<PopoverTrigger as-child>
|
||||
<Button type="button" variant="ghost" class="h-auto rounded-sm p-0" :aria-label="`Why ${row.name} failed`">
|
||||
<Badge variant="danger">failed<ChevronDown data-icon="inline-end" /></Badge>
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent align="start" class="w-96 max-w-[calc(100vw-2rem)] space-y-1 text-label">
|
||||
<p class="whitespace-pre-line break-words">{{ row.error }}</p>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</template>
|
||||
</DataTable>
|
||||
</Section>
|
||||
</template>
|
||||
@@ -0,0 +1,44 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
import { RouterLink } from "vue-router";
|
||||
|
||||
import { MetadataList } from "@/components/ui/metadata-list";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
import type { SystemHealth } from "@/lib/api";
|
||||
|
||||
const props = defineProps<{ health: SystemHealth }>();
|
||||
|
||||
const rows = computed(() => {
|
||||
const h = props.health;
|
||||
const runs = h.waiting?.runs;
|
||||
return [
|
||||
{ label: "Version", value: h.version, mono: true },
|
||||
{ label: "Workers", value: String(h.runner.workers) },
|
||||
...(h.waiting
|
||||
? [
|
||||
{ label: "Approvals waiting", value: String(h.waiting.approvals) },
|
||||
{ label: "Runs parked", value: String(runs?.parked ?? 0) },
|
||||
{ label: "Runs waiting", value: String((runs?.waiting ?? 0) + (runs?.waiting_approval ?? 0)) },
|
||||
{ label: "Runs queued", value: String(runs?.queued ?? 0) },
|
||||
{ label: "Runs running", value: String(runs?.running ?? 0) },
|
||||
]
|
||||
: []),
|
||||
];
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Section title="Instance">
|
||||
<p v-if="health.runner.error" role="alert" class="mb-3 flex flex-wrap items-center gap-x-2 text-label text-danger">
|
||||
Runner: {{ health.runner.error }}
|
||||
<Timestamp v-if="health.runner.error_at" :at="health.runner.error_at" />
|
||||
</p>
|
||||
<p v-if="health.last_failure" class="mb-3 flex flex-wrap items-center gap-x-2 text-label text-danger">
|
||||
<Timestamp :at="health.last_failure.at" />
|
||||
<span class="font-mono">{{ health.last_failure.source }}</span><span class="min-w-0 break-words" :title="health.last_failure.cause">{{ health.last_failure.cause.split("\n")[0] }}</span>
|
||||
<RouterLink v-if="health.last_failure.run_id" :to="`/runs/${health.last_failure.run_id}`" class="underline">Run</RouterLink>
|
||||
</p>
|
||||
<MetadataList :rows="rows" />
|
||||
</Section>
|
||||
</template>
|
||||
@@ -1,144 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ReadError } from "@/components/ui/read-error";
|
||||
import { computed, onMounted, onUnmounted, ref } from "vue";
|
||||
import { ChevronDown } from "@lucide/vue";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { DataTable, type DataTableColumn } from "@/components/ui/data-table";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
import { api, describeError } from "@/lib/api";
|
||||
import { errors } from "@/copy/errors";
|
||||
|
||||
interface AppliedRecord {
|
||||
kind: string;
|
||||
applied_version: number;
|
||||
error?: string;
|
||||
state: "current" | "failed" | "unknown";
|
||||
}
|
||||
|
||||
interface Service {
|
||||
service: string;
|
||||
instance_id: string;
|
||||
state: "up" | "degraded" | "down" | "unknown";
|
||||
version: string;
|
||||
install_type: string;
|
||||
started_at: string;
|
||||
reported_at: string;
|
||||
detail?: string;
|
||||
applied: AppliedRecord[];
|
||||
checks?: { name: string; status: "ok" | "degraded"; detail?: string }[];
|
||||
}
|
||||
|
||||
const services = ref<Service[]>([]);
|
||||
const error = ref<string | null>(null);
|
||||
let timer: ReturnType<typeof setInterval> | undefined;
|
||||
|
||||
const tone = { up: "ok", degraded: "warn", down: "danger", unknown: "idle" } as const;
|
||||
|
||||
const columns = (agent: boolean): DataTableColumn<Service>[] => [
|
||||
{ id: "name", label: agent ? "Task" : "Service", fixed: true },
|
||||
{ id: "version", label: "Version" },
|
||||
{ id: "install", label: "Runs as", hidden: true },
|
||||
{ id: "uptime", label: "Uptime" },
|
||||
{ id: "seen", label: "Last seen", hidden: true },
|
||||
{ id: "state", label: "State" },
|
||||
];
|
||||
|
||||
// An agent reports for one task, so agents get their own table keyed by task.
|
||||
const tables = computed(() => {
|
||||
const agents = services.value.filter((s) => s.service === "archie-agent");
|
||||
return [
|
||||
{ title: "Services", key: "services", agent: false, rows: services.value.filter((s) => s.service !== "archie-agent") },
|
||||
...(agents.length ? [{ title: "Agents", key: "agents", agent: true, rows: agents }] : []),
|
||||
];
|
||||
});
|
||||
const rowKey = (service: Service) => `${service.service}/${service.instance_id}`;
|
||||
|
||||
function uptime(service: Service): string {
|
||||
if (!service.started_at || service.state === "down") return "";
|
||||
const seconds = Math.max(
|
||||
0,
|
||||
Math.round((Date.now() - Date.parse(service.started_at)) / 1000),
|
||||
);
|
||||
const days = Math.floor(seconds / 86400);
|
||||
const hours = Math.floor((seconds % 86400) / 3600);
|
||||
const minutes = Math.floor((seconds % 3600) / 60);
|
||||
if (days) return `${days}d ${hours}h`;
|
||||
if (hours) return `${hours}h ${minutes}m`;
|
||||
return `${minutes}m`;
|
||||
}
|
||||
|
||||
// A row names what is wrong with a service and nothing else: passing checks
|
||||
// and applied versions that match are noise here.
|
||||
function problems(service: Service): { key: string; text: string }[] {
|
||||
return [
|
||||
...(service.checks ?? [])
|
||||
.filter((check) => check.status !== "ok")
|
||||
.map((check) => ({
|
||||
key: `check:${check.name}`,
|
||||
text: [check.name, check.detail].filter(Boolean).join(": "),
|
||||
})),
|
||||
...service.applied
|
||||
.filter((record) => record.error)
|
||||
.map((record) => ({ key: `applied:${record.kind}`, text: `${record.kind}: ${record.error}` })),
|
||||
];
|
||||
}
|
||||
|
||||
const reasons = (service: Service) => {
|
||||
const found = problems(service).map((problem) => problem.text);
|
||||
return found.length || !service.detail ? found : [service.detail];
|
||||
};
|
||||
|
||||
let loadGeneration = 0;
|
||||
async function load(): Promise<void> {
|
||||
const current = ++loadGeneration;
|
||||
try {
|
||||
services.value = await api.services<Service[]>();
|
||||
if (current !== loadGeneration) return;
|
||||
error.value = null;
|
||||
} catch (err) {
|
||||
if (current !== loadGeneration) return;
|
||||
error.value = describeError(err, errors.common.unknown);
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void load();
|
||||
timer = setInterval(() => void load(), 15_000);
|
||||
});
|
||||
onUnmounted(() => clearInterval(timer));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ReadError v-if="error" :message="error" retry-label="Retry" class="mb-4" @retry="load" />
|
||||
<Section v-for="table in tables" v-else :key="table.key" :title="table.title">
|
||||
<DataTable :columns="columns(table.agent)" :rows="table.rows" :row-key="rowKey" :storage-key="`status.${table.key}`">
|
||||
<template #cell-name="{ row }">
|
||||
<RouterLink v-if="table.agent" :to="`/tasks/${row.instance_id}`" class="hover:underline">#{{ row.instance_id }}</RouterLink>
|
||||
<span v-else class="font-mono">{{ row.service }}</span>
|
||||
</template>
|
||||
<template #cell-version="{ row }"><span class="font-mono text-fg-muted">{{ row.version }}</span></template>
|
||||
<template #cell-install="{ row }"><span class="text-fg-muted">{{ row.install_type }}</span></template>
|
||||
<template #cell-uptime="{ row }"><span class="tabular-nums">{{ uptime(row) }}</span></template>
|
||||
<template #cell-seen="{ row }"><Timestamp :at="row.reported_at" class="text-fg-muted" /></template>
|
||||
<template #cell-state="{ row }">
|
||||
<template v-if="row.state !== 'up'">
|
||||
<Popover v-if="reasons(row).length">
|
||||
<PopoverTrigger as-child>
|
||||
<Button type="button" variant="ghost" class="h-auto rounded-sm p-0" :aria-label="`Why ${row.service} is ${row.state}`">
|
||||
<Badge :variant="tone[row.state]">{{ row.state }}<ChevronDown data-icon="inline-end" /></Badge>
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent align="start" class="w-96 max-w-[calc(100vw-2rem)] space-y-1 text-label">
|
||||
<p v-for="reason in reasons(row)" :key="reason" class="break-words">{{ reason }}</p>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<Badge v-else :variant="tone[row.state]">{{ row.state }}</Badge>
|
||||
</template>
|
||||
</template>
|
||||
</DataTable>
|
||||
</Section>
|
||||
</template>
|
||||
@@ -1,45 +1,38 @@
|
||||
<script setup lang="ts">
|
||||
import { storeToRefs } from "pinia";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { computed, onMounted, onUnmounted } from "vue";
|
||||
import { computed, onMounted } from "vue";
|
||||
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
import { ReadError } from "@/components/ui/read-error";
|
||||
import { MetadataList } from "@/components/ui/metadata-list";
|
||||
import { ReadError } from "@/components/ui/read-error";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import ServicesCard from "./ServicesCard.vue";
|
||||
import UpdateSettingsCard from "./UpdateSettingsCard.vue";
|
||||
import VersionsCard from "./VersionsCard.vue";
|
||||
import { useSettingsStore } from "@/stores/settings";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { api } from "@/lib/api";
|
||||
import { useSystemHealth } from "@/lib/system-health";
|
||||
import { useRead } from "@/lib/use-read";
|
||||
import HealthTables from "./HealthTables.vue";
|
||||
import InstanceCard from "./InstanceCard.vue";
|
||||
|
||||
const { data: health, error, reload } = useSystemHealth();
|
||||
const startup = useRead(() => api.bootstrap());
|
||||
onMounted(startup.reload);
|
||||
|
||||
const store = useSettingsStore();
|
||||
const { config, catalogError } = storeToRefs(store);
|
||||
const bootstrapRows = computed(() =>
|
||||
Object.entries(config.value?.bootstrap ?? {}).map(([label, value]) => ({ label, value, mono: true })),
|
||||
Object.entries(startup.data.value ?? {}).map(([label, value]) => ({ label, value: String(value), mono: true })),
|
||||
);
|
||||
|
||||
let timer: ReturnType<typeof setInterval>;
|
||||
onMounted(() => {
|
||||
void store.loadConfig();
|
||||
timer = setInterval(() => void store.loadConfig(), 15_000);
|
||||
});
|
||||
onUnmounted(() => clearInterval(timer));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PageHeader title="Status" />
|
||||
<div>
|
||||
<ReadError v-if="catalogError" :message="catalogError" retry-label="Retry" class="mb-4" @retry="store.load()" />
|
||||
<Alert v-if="config?.reload?.last_error" variant="destructive" class="mb-4">
|
||||
<AlertTitle>{{ errors.settings.status.reload }}</AlertTitle>
|
||||
<AlertDescription>{{ config.reload.last_error }}</AlertDescription>
|
||||
</Alert>
|
||||
<ServicesCard />
|
||||
<VersionsCard />
|
||||
<UpdateSettingsCard />
|
||||
<Section v-if="config?.bootstrap && Object.keys(config.bootstrap).length" title="Startup settings">
|
||||
<MetadataList :rows="bootstrapRows" />
|
||||
<ReadError v-if="error && !health" :message="error" retry-label="Retry" class="mb-4" @retry="reload" />
|
||||
<div v-else-if="!health" role="status" aria-label="Loading status" class="space-y-2"><Skeleton class="h-8 w-full" /><Skeleton class="h-8 w-full" /></div>
|
||||
<template v-else>
|
||||
<ReadError v-if="error" :message="error" retry-label="Retry" class="mb-4" @retry="reload" />
|
||||
<InstanceCard :health="health" />
|
||||
<HealthTables :checks="health.checks" :connectors="health.connectors" />
|
||||
</template>
|
||||
<Section v-if="bootstrapRows.length" title="Startup settings">
|
||||
<MetadataList :rows="bootstrapRows" />
|
||||
</Section>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,70 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import { computed, onMounted } from "vue";
|
||||
|
||||
import { Field, FieldContent, FieldGroup, FieldLabel } from "@/components/ui/field";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
|
||||
import { useSettingsStore } from "@/stores/settings";
|
||||
import { fieldInvalid } from "./settings-form";
|
||||
import KindGate from "./KindGate.vue";
|
||||
|
||||
const KIND = "update-settings";
|
||||
type UpdateSettings = { channel: string; pin: string };
|
||||
|
||||
const store = useSettingsStore();
|
||||
onMounted(store.load);
|
||||
|
||||
const form = computed(() => store.formFor(KIND));
|
||||
const channel = computed(() => (store.draftValue(KIND) as UpdateSettings | undefined)?.channel || "stable");
|
||||
const error = computed(() => store.pageErrorFor(KIND));
|
||||
|
||||
const channels = [
|
||||
{ value: "stable", label: "Stable" },
|
||||
{ value: "next", label: "Prereleases" },
|
||||
{ value: "exact-pin", label: "Pinned" },
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<KindGate v-if="!form" :kind="KIND" />
|
||||
<Section v-if="form" title="Updates">
|
||||
<Alert v-if="error" variant="destructive" class="mb-2"><AlertDescription>{{ error }}</AlertDescription></Alert>
|
||||
<FieldGroup class="@container/field-group">
|
||||
<form.Field v-slot="{ field }" name="channel">
|
||||
<Field orientation="responsive">
|
||||
<FieldContent><FieldLabel>Release channel</FieldLabel></FieldContent>
|
||||
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
||||
<ToggleGroup
|
||||
type="single"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
:model-value="channel"
|
||||
aria-label="Release channel"
|
||||
@update:model-value="(value) => { if (value) field.handleChange(value); }"
|
||||
>
|
||||
<ToggleGroupItem v-for="option in channels" :key="option.value" :value="option.value">{{ option.label }}</ToggleGroupItem>
|
||||
</ToggleGroup>
|
||||
</div>
|
||||
</Field>
|
||||
</form.Field>
|
||||
<form.Field v-if="channel === 'exact-pin'" v-slot="{ field }" name="pin">
|
||||
<Field orientation="responsive" :data-invalid="fieldInvalid(field)">
|
||||
<FieldContent><FieldLabel for="update-pin">Version</FieldLabel></FieldContent>
|
||||
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
||||
<Input
|
||||
id="update-pin"
|
||||
:model-value="field.state.value"
|
||||
class="max-w-40 font-mono"
|
||||
placeholder="1.48.0"
|
||||
:aria-invalid="fieldInvalid(field)"
|
||||
@blur="field.handleBlur"
|
||||
@update:model-value="field.handleChange"
|
||||
/>
|
||||
</div>
|
||||
</Field>
|
||||
</form.Field>
|
||||
</FieldGroup>
|
||||
</Section>
|
||||
</template>
|
||||
@@ -1,214 +0,0 @@
|
||||
<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, describeError } from "@/lib/api";
|
||||
import { errors } from "@/copy/errors";
|
||||
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 = describeError(err, errors.common.unknown);
|
||||
} 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 = describeError(err, errors.common.unknown);
|
||||
}
|
||||
}
|
||||
|
||||
// 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 = describeError(err, errors.common.unknown);
|
||||
} 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>
|
||||
+48
-11
@@ -1,31 +1,68 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
import { reactive, ref } from "vue";
|
||||
|
||||
import type { Denial, DenialsResponse } from "@/audit/denials";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { ApiError, api, describeError } from "@/lib/api";
|
||||
|
||||
/** The caller's org's recorded access denials, newest first. */
|
||||
const PAGE = 100;
|
||||
|
||||
/** What narrows the list; an empty field matches everything. `since` and
|
||||
* `until` are datetime-local values, read in the browser's time zone. */
|
||||
export interface DenialFilters {
|
||||
principal: string;
|
||||
action: string;
|
||||
kind: string;
|
||||
since: string;
|
||||
until: string;
|
||||
}
|
||||
|
||||
const noFilters = (): DenialFilters => ({ principal: "", action: "", kind: "", since: "", until: "" });
|
||||
|
||||
const toISO = (local: string): string => (local ? new Date(local).toISOString() : "");
|
||||
|
||||
/** The caller's org's recorded access denials, newest first, a page at a time. */
|
||||
export const useDenialsStore = defineStore("denials", () => {
|
||||
const denials = ref<Denial[]>([]);
|
||||
const filters = reactive<DenialFilters>(noFilters());
|
||||
const more = ref(false);
|
||||
const loading = ref(false);
|
||||
const error = ref("");
|
||||
// A response for filters or a page the operator has since replaced is dropped.
|
||||
let attempt = 0;
|
||||
|
||||
async function load(): Promise<void> {
|
||||
/** load reads the first page, or the next one after those already shown. */
|
||||
async function load(next = false): Promise<void> {
|
||||
const mine = ++attempt;
|
||||
loading.value = true;
|
||||
try {
|
||||
denials.value = (await api.denials<DenialsResponse>()).denials ?? [];
|
||||
const response = await api.denials<DenialsResponse>({
|
||||
principal: filters.principal.trim(),
|
||||
action: filters.action.trim(),
|
||||
kind: filters.kind.trim(),
|
||||
since: toISO(filters.since),
|
||||
until: toISO(filters.until),
|
||||
limit: PAGE,
|
||||
offset: next ? denials.value.length : 0,
|
||||
});
|
||||
if (mine !== attempt) return;
|
||||
denials.value = next ? [...denials.value, ...(response.denials ?? [])] : (response.denials ?? []);
|
||||
more.value = response.more;
|
||||
error.value = "";
|
||||
} catch (err) {
|
||||
if (err instanceof ApiError && err.status === 503) {
|
||||
error.value = errors.stores.denials.unavailable;
|
||||
} else {
|
||||
error.value = describeError(err, errors.common.unknown);
|
||||
}
|
||||
if (mine !== attempt) return;
|
||||
error.value = err instanceof ApiError && err.status === 503
|
||||
? errors.stores.denials.unavailable
|
||||
: describeError(err, errors.common.unknown);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
if (mine === attempt) loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
return { denials, loading, error, load };
|
||||
function clear(): void {
|
||||
Object.assign(filters, noFilters());
|
||||
void load();
|
||||
}
|
||||
|
||||
return { denials, filters, more, loading, error, load, clear };
|
||||
});
|
||||
Reference in new issue
Block a user