feat(ui): the dashboard edits every control-plane setting (#2026)
This commit is contained in:
12 files changed
+1723
-5
No files matched your search
@@ -0,0 +1,145 @@
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, onMounted, reactive, ref } from "vue";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { ReadError } from "@/components/ui/read-error";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { SettingRow } from "@/components/ui/setting-row";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import {
|
||||
ApiError,
|
||||
getAgentModel,
|
||||
listCredentials,
|
||||
saveAgentModel,
|
||||
testAgentModel,
|
||||
Unauthorized,
|
||||
type AgentModel,
|
||||
type CredentialView,
|
||||
} from "./api";
|
||||
|
||||
/**
|
||||
* The model every agent loop asks. The key is a credential named here; the
|
||||
* value stays sealed, and Test asks the model one question.
|
||||
*/
|
||||
const emit = defineEmits<{ unauthorized: [] }>();
|
||||
|
||||
const none = "none";
|
||||
const model = reactive<AgentModel>({ class: "openai", base_url: "", model: "", api_key_credential: "" });
|
||||
const credentials = ref<CredentialView[]>([]);
|
||||
const loading = ref(true);
|
||||
const error = ref("");
|
||||
const answer = ref("");
|
||||
const saved = ref("");
|
||||
const testing = ref(false);
|
||||
const saving = ref(false);
|
||||
const unset = ref(false);
|
||||
const controller = new AbortController();
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
const [current, creds] = await Promise.all([
|
||||
getAgentModel(controller.signal).catch((err: unknown) => {
|
||||
if (err instanceof ApiError && err.status === 404) {
|
||||
unset.value = true;
|
||||
return null;
|
||||
}
|
||||
throw err;
|
||||
}),
|
||||
listCredentials(controller.signal),
|
||||
]);
|
||||
credentials.value = creds;
|
||||
if (current) Object.assign(model, current);
|
||||
} catch (err) {
|
||||
fail(err);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function test() {
|
||||
testing.value = true;
|
||||
error.value = "";
|
||||
answer.value = "";
|
||||
saved.value = "";
|
||||
try {
|
||||
const result = await testAgentModel(payload());
|
||||
answer.value = result.answer;
|
||||
} catch (err) {
|
||||
fail(err);
|
||||
} finally {
|
||||
testing.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function save() {
|
||||
saving.value = true;
|
||||
error.value = "";
|
||||
saved.value = "";
|
||||
try {
|
||||
Object.assign(model, await saveAgentModel(payload()));
|
||||
unset.value = false;
|
||||
saved.value = "Saved.";
|
||||
} catch (err) {
|
||||
fail(err);
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function payload(): AgentModel {
|
||||
return {
|
||||
class: model.class.trim(),
|
||||
base_url: model.base_url.trim(),
|
||||
model: model.model.trim(),
|
||||
api_key_credential: model.api_key_credential === none ? "" : model.api_key_credential,
|
||||
};
|
||||
}
|
||||
|
||||
function fail(err: unknown) {
|
||||
if (controller.signal.aborted) return;
|
||||
if (err instanceof Unauthorized) emit("unauthorized");
|
||||
error.value = err instanceof Error ? err.message : String(err);
|
||||
}
|
||||
|
||||
onMounted(load);
|
||||
onBeforeUnmount(() => controller.abort());
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Section title="Agent model">
|
||||
<Spinner v-if="loading" />
|
||||
<ReadError v-else-if="error && !model.model" :message="error" retry-label="Retry" @retry="load" />
|
||||
<template v-else>
|
||||
<p v-if="unset" class="mb-2 text-caption text-warn">No agent model is set, so runs that ask a model fail.</p>
|
||||
<SettingRow label="Provider class" for="agent-class" hint="The provider family, such as openai, anthropic or ollama.">
|
||||
<Input id="agent-class" v-model="model.class" placeholder="openai" />
|
||||
</SettingRow>
|
||||
<SettingRow label="Base URL" for="agent-base-url" hint="Empty takes the provider class's published default.">
|
||||
<Input id="agent-base-url" v-model="model.base_url" placeholder="https://…" />
|
||||
</SettingRow>
|
||||
<SettingRow label="Model" for="agent-model">
|
||||
<Input id="agent-model" v-model="model.model" />
|
||||
</SettingRow>
|
||||
<SettingRow label="API key" for="agent-credential" hint="A bearer credential. Its token is never shown.">
|
||||
<Select :model-value="model.api_key_credential || none" @update:model-value="(v) => (model.api_key_credential = String(v))">
|
||||
<SelectTrigger id="agent-credential" class="w-full sm:w-64"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem :value="none">No key</SelectItem>
|
||||
<SelectItem v-for="c in credentials.filter((x) => x.kind === 'bearer')" :key="c.name" :value="c.name">{{ c.name }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</SettingRow>
|
||||
<div class="mt-2 flex flex-wrap items-center gap-2">
|
||||
<Button size="sm" :disabled="saving || !model.class.trim() || !model.model.trim()" @click="save">Save</Button>
|
||||
<Button variant="outline" size="sm" :disabled="testing || !model.class.trim() || !model.model.trim()" @click="test">Test</Button>
|
||||
<span v-if="saved" class="text-caption text-muted-foreground">{{ saved }}</span>
|
||||
</div>
|
||||
<p v-if="answer" class="mt-2 text-label">The model answered: <span class="font-mono">{{ answer }}</span></p>
|
||||
<p v-if="error" class="mt-2 text-caption text-danger">{{ error }}</p>
|
||||
</template>
|
||||
</Section>
|
||||
</template>
|
||||
@@ -31,13 +31,18 @@ function signOut() {
|
||||
<div class="mx-auto flex min-h-dvh max-w-4xl flex-col gap-4 p-4">
|
||||
<header class="flex items-center gap-4">
|
||||
<span class="text-title font-semibold">Archie</span>
|
||||
<nav v-if="signedIn" class="flex flex-1 items-center gap-3 text-label">
|
||||
<nav v-if="signedIn" class="flex flex-1 flex-wrap items-center gap-x-3 gap-y-1 text-label">
|
||||
<RouterLink to="/composer" active-class="text-foreground" class="text-muted-foreground">Composer</RouterLink>
|
||||
<RouterLink to="/runs" active-class="text-foreground" class="text-muted-foreground">Runs</RouterLink>
|
||||
<RouterLink to="/unmatched" active-class="text-foreground" class="text-muted-foreground">Unmatched</RouterLink>
|
||||
<RouterLink to="/events" active-class="text-foreground" class="text-muted-foreground">Events</RouterLink>
|
||||
<RouterLink to="/classes" active-class="text-foreground" class="text-muted-foreground">Classes</RouterLink>
|
||||
<RouterLink to="/people" active-class="text-foreground" class="text-muted-foreground">People</RouterLink>
|
||||
<RouterLink to="/controls" active-class="text-foreground" class="text-muted-foreground">Controls</RouterLink>
|
||||
<RouterLink to="/extensions" active-class="text-foreground" class="text-muted-foreground">Extensions</RouterLink>
|
||||
<RouterLink to="/sources" active-class="text-foreground" class="text-muted-foreground">Sources</RouterLink>
|
||||
<RouterLink to="/triggers" active-class="text-foreground" class="text-muted-foreground">Triggers</RouterLink>
|
||||
<RouterLink to="/credentials" active-class="text-foreground" class="text-muted-foreground">Credentials</RouterLink>
|
||||
<RouterLink to="/settings" active-class="text-foreground" class="text-muted-foreground">Settings</RouterLink>
|
||||
<Button variant="ghost" size="xs" class="ml-auto" @click="signOut">Sign out</Button>
|
||||
</nav>
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, onMounted, reactive, ref } from "vue";
|
||||
import { RouterLink } from "vue-router";
|
||||
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||
import { ReadError } from "@/components/ui/read-error";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
import { getPolicies, savePolicies, Unauthorized, type PolicyKind, type PolicySet } from "./api";
|
||||
import { getPolicies, listJudges, savePolicies, Unauthorized, type JudgeControl, type PolicyKind, type PolicySet } from "./api";
|
||||
|
||||
/** Controls: Cedar hard rules run before the guards, change-request rules after. */
|
||||
/** Controls: Cedar hard rules and change-request rules, and the judge each guard asks. */
|
||||
const emit = defineEmits<{ unauthorized: [] }>();
|
||||
|
||||
interface Editor {
|
||||
@@ -26,10 +29,19 @@ const editors = reactive<Editor[]>([
|
||||
{ kind: "hard-rules", title: "Hard rules", body: "", saving: false, error: "" },
|
||||
{ kind: "change-request", title: "Change-request rules", body: "", saving: false, error: "" },
|
||||
]);
|
||||
const judges = ref<JudgeControl[]>([]);
|
||||
const loading = ref(true);
|
||||
const loadError = ref("");
|
||||
const controller = new AbortController();
|
||||
|
||||
const judgeLabels: Record<string, string> = {
|
||||
judge_api: "Judge API",
|
||||
judge_model: "Model",
|
||||
judge_base_url: "Endpoint",
|
||||
judge_api_key_ref: "API key credential",
|
||||
policy: "Policy",
|
||||
};
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
loadError.value = "";
|
||||
@@ -39,6 +51,7 @@ async function load() {
|
||||
e.current = sets[i];
|
||||
e.body = sets[i].body;
|
||||
});
|
||||
judges.value = await listJudges(controller.signal);
|
||||
} catch (err) {
|
||||
fail(err, (m) => (loadError.value = m));
|
||||
} finally {
|
||||
@@ -85,6 +98,40 @@ onBeforeUnmount(() => controller.abort());
|
||||
</span>
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
<Section title="Judges">
|
||||
<Empty v-if="!judges.length">
|
||||
<EmptyHeader><EmptyTitle>No guard is running</EmptyTitle></EmptyHeader>
|
||||
</Empty>
|
||||
<div v-else class="flex flex-col gap-4">
|
||||
<div v-for="judge in judges" :key="judge.name" class="rounded-md border border-border p-3">
|
||||
<div class="mb-2 flex flex-wrap items-center gap-2">
|
||||
<span class="font-medium">{{ judge.name }}</span>
|
||||
<Badge :variant="judge.advisory ? 'warn' : 'ok'">{{ judge.advisory ? "Advisory" : "Sets a ceiling" }}</Badge>
|
||||
<span v-if="judge.version" class="text-caption text-fg-subtle">Version {{ judge.version }}</span>
|
||||
<RouterLink :to="{ name: 'extensions' }" class="ms-auto text-caption text-link underline-offset-4 hover:underline">Edit settings</RouterLink>
|
||||
</div>
|
||||
<dl class="grid grid-cols-[minmax(6.5rem,max-content)_minmax(0,1fr)] gap-x-3 gap-y-2 text-caption">
|
||||
<template v-for="s in judge.settings_schema" :key="s.key">
|
||||
<dt class="leading-5 text-fg-subtle">{{ judgeLabels[s.key] ?? s.label }}</dt>
|
||||
<dd class="min-w-0 leading-5 [overflow-wrap:anywhere] font-mono">{{ judge.settings[s.key] || "Not set" }}</dd>
|
||||
</template>
|
||||
<dt class="leading-5 text-fg-subtle">Standing</dt>
|
||||
<dd class="min-w-0 leading-5">
|
||||
<span v-if="judge.latest">
|
||||
<Badge :variant="judge.latest.trusted ? 'ok' : 'warn'">{{ judge.latest.trusted ? "Trusted" : "Advisory" }}</Badge>
|
||||
<span class="ms-2 text-fg-subtle">{{ judge.latest.advisory_reason }}</span>
|
||||
</span>
|
||||
<span v-else class="text-fg-subtle">No judgement recorded yet</span>
|
||||
</dd>
|
||||
<dt class="leading-5 text-fg-subtle">Eval date</dt>
|
||||
<dd class="min-w-0 leading-5 font-mono">{{ judge.latest?.eval_date || "—" }}</dd>
|
||||
<dt class="leading-5 text-fg-subtle">Last judged</dt>
|
||||
<dd class="min-w-0 leading-5"><Timestamp v-if="judge.latest" :at="judge.latest.at" /><span v-else class="text-fg-subtle">—</span></dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
</Section>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,212 @@
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, onMounted, reactive, ref } from "vue";
|
||||
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
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 { ReadError } from "@/components/ui/read-error";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { SettingRow } from "@/components/ui/setting-row";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { listCredentials, saveCredential, Unauthorized, type CredentialField, type CredentialView } from "./api";
|
||||
|
||||
/**
|
||||
* Credentials are the values connectors are configured with. They are write
|
||||
* only: a saved field says where it comes from, never what it holds, and
|
||||
* replacing a credential means entering its values again.
|
||||
*/
|
||||
const emit = defineEmits<{ unauthorized: [] }>();
|
||||
|
||||
type Kind = CredentialView["kind"];
|
||||
|
||||
const fieldsOf: Record<Kind, { required: string[]; optional: string[] }> = {
|
||||
machine: { required: ["username", "private_key"], optional: ["private_key_passphrase"] },
|
||||
age: { required: ["identity"], optional: [] },
|
||||
basic: { required: ["username", "password"], optional: [] },
|
||||
bearer: { required: ["token"], optional: [] },
|
||||
};
|
||||
|
||||
const labelOf: Record<string, string> = {
|
||||
username: "Username",
|
||||
private_key: "Private key",
|
||||
private_key_passphrase: "Private key passphrase",
|
||||
identity: "Age identity",
|
||||
password: "Password",
|
||||
token: "Token",
|
||||
};
|
||||
|
||||
interface Field {
|
||||
value: string;
|
||||
engine: string;
|
||||
key: string;
|
||||
}
|
||||
|
||||
interface Form {
|
||||
name: string;
|
||||
kind: Kind;
|
||||
fields: Record<string, Field>;
|
||||
}
|
||||
|
||||
const blank = (kind: Kind = "bearer"): Form => ({
|
||||
name: "",
|
||||
kind,
|
||||
fields: Object.fromEntries([...fieldsOf[kind].required, ...fieldsOf[kind].optional].map((f) => [f, { value: "", engine: "", key: "" }])),
|
||||
});
|
||||
|
||||
const credentials = ref<CredentialView[]>([]);
|
||||
const form = reactive<Form>(blank());
|
||||
const editing = ref(false);
|
||||
const original = ref("");
|
||||
const loading = ref(true);
|
||||
const error = ref("");
|
||||
const saved = ref("");
|
||||
const saving = ref(false);
|
||||
const controller = new AbortController();
|
||||
|
||||
const columns: DataTableColumn<CredentialView>[] = [
|
||||
{ id: "name", label: "Name", fixed: true },
|
||||
{ id: "kind", label: "Kind" },
|
||||
{ id: "fields", label: "Fields" },
|
||||
];
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
credentials.value = await listCredentials(controller.signal);
|
||||
} catch (err) {
|
||||
fail(err);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function chooseKind(kind: Kind) {
|
||||
form.kind = kind;
|
||||
form.fields = blank(kind).fields;
|
||||
}
|
||||
|
||||
function start(name?: string) {
|
||||
error.value = "";
|
||||
saved.value = "";
|
||||
const found = name ? credentials.value.find((c) => c.name === name) : undefined;
|
||||
original.value = name ?? "";
|
||||
Object.assign(form, found ? fromView(found) : blank());
|
||||
editing.value = true;
|
||||
}
|
||||
|
||||
function fromView(c: CredentialView): Form {
|
||||
const out = blank(c.kind);
|
||||
out.name = c.name;
|
||||
for (const [name, origin] of Object.entries(c.fields)) {
|
||||
out.fields[name] ??= { value: "", engine: "", key: "" };
|
||||
if (origin.includes(":")) {
|
||||
const [engine, key] = origin.split(":");
|
||||
out.fields[name].engine = engine;
|
||||
out.fields[name].key = key;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
async function save() {
|
||||
saving.value = true;
|
||||
error.value = "";
|
||||
saved.value = "";
|
||||
try {
|
||||
const fields: Record<string, CredentialField> = {};
|
||||
for (const name of [...fieldsOf[form.kind].required, ...fieldsOf[form.kind].optional]) {
|
||||
const f = form.fields[name];
|
||||
if (!f) continue;
|
||||
if (f.value) fields[name] = { value: f.value };
|
||||
else if (f.engine && f.key) fields[name] = { engine: f.engine, key: f.key };
|
||||
}
|
||||
await saveCredential(form.name.trim(), form.kind, fields);
|
||||
saved.value = "Saved.";
|
||||
editing.value = false;
|
||||
Object.assign(form, blank());
|
||||
await load();
|
||||
} catch (err) {
|
||||
fail(err);
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function fail(err: unknown) {
|
||||
if (controller.signal.aborted) return;
|
||||
if (err instanceof Unauthorized) emit("unauthorized");
|
||||
error.value = err instanceof Error ? err.message : String(err);
|
||||
}
|
||||
|
||||
onMounted(load);
|
||||
onBeforeUnmount(() => controller.abort());
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<PageHeader title="Credentials">
|
||||
<Button variant="outline" @click="start()">Add credential</Button>
|
||||
</PageHeader>
|
||||
<Spinner v-if="loading" />
|
||||
<ReadError v-else-if="error && !credentials.length && !editing" :message="error" retry-label="Retry" @retry="load" />
|
||||
<template v-else>
|
||||
<Section v-if="editing" :title="form.name ? `Edit ${form.name}` : 'New credential'">
|
||||
<form class="flex flex-col gap-3" @submit.prevent="save">
|
||||
<SettingRow label="Name" for="credential-name">
|
||||
<Input id="credential-name" v-model="form.name" :disabled="original !== ''" placeholder="lowercase-name" />
|
||||
</SettingRow>
|
||||
<SettingRow label="Kind" for="credential-kind">
|
||||
<Select :model-value="form.kind" @update:model-value="(v) => chooseKind(v as Kind)">
|
||||
<SelectTrigger id="credential-kind" class="w-full sm:w-64"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="bearer">Bearer token</SelectItem>
|
||||
<SelectItem value="basic">Username and password</SelectItem>
|
||||
<SelectItem value="machine">SSH machine</SelectItem>
|
||||
<SelectItem value="age">Age identity</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</SettingRow>
|
||||
<SettingRow
|
||||
v-for="(field, name) in form.fields"
|
||||
:key="name"
|
||||
:label="labelOf[name] ?? name"
|
||||
:hint="fieldsOf[form.kind].optional.includes(name) ? 'Optional.' : 'Required.'"
|
||||
>
|
||||
<div class="flex flex-col gap-2">
|
||||
<Input v-model="field.value" type="password" autocomplete="off" :aria-label="labelOf[name] ?? name" placeholder="New value" />
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<Input v-model="field.engine" placeholder="Secret engine" class="w-40" :aria-label="`${name} engine`" />
|
||||
<Input v-model="field.key" placeholder="Key" class="w-40" :aria-label="`${name} key`" />
|
||||
</div>
|
||||
</div>
|
||||
</SettingRow>
|
||||
<p class="text-caption text-fg-subtle">A value is write only. Enter it, or name the engine and key that resolve it.</p>
|
||||
<p v-if="error" class="text-caption text-danger">{{ error }}</p>
|
||||
<div class="flex items-center gap-2">
|
||||
<Button type="submit" :disabled="saving || !form.name.trim()">Save</Button>
|
||||
<Button type="button" variant="ghost" @click="editing = false">Cancel</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Section>
|
||||
|
||||
<Empty v-if="!credentials.length">
|
||||
<EmptyHeader><EmptyTitle>No credentials yet</EmptyTitle></EmptyHeader>
|
||||
</Empty>
|
||||
<DataTable v-else :columns="columns" :rows="credentials" :row-key="(c) => c.name" storage-key="credentials">
|
||||
<template #cell-name="{ row }"><span class="font-medium">{{ row.name }}</span></template>
|
||||
<template #cell-kind="{ row }">{{ row.kind }}</template>
|
||||
<template #cell-fields="{ row }">
|
||||
<span class="font-mono text-caption">{{ Object.entries(row.fields).map(([f, origin]) => `${f}: ${origin}`).join(", ") }}</span>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<Button variant="ghost" size="sm" @click="start(row.name)">Edit</Button>
|
||||
</template>
|
||||
</DataTable>
|
||||
<p v-if="saved" class="mt-2 text-caption text-muted-foreground">{{ saved }}</p>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,163 @@
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, onMounted, ref } from "vue";
|
||||
import { RouterLink } from "vue-router";
|
||||
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
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 { ReadError } from "@/components/ui/read-error";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { SettingRow } from "@/components/ui/setting-row";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
import { getEvent, listEvents, listSources, Unauthorized, type EventDetail, type EventRow } from "./api";
|
||||
|
||||
/**
|
||||
* Events are what Archie heard, with the payload it arrived in and the runs
|
||||
* triggers started. Filters narrow by source, type and whether a trigger
|
||||
* matched.
|
||||
*/
|
||||
const emit = defineEmits<{ unauthorized: [] }>();
|
||||
|
||||
const rows = ref<EventRow[]>([]);
|
||||
const sources = ref<string[]>([]);
|
||||
const selected = ref<EventDetail | null>(null);
|
||||
const loading = ref(true);
|
||||
const loadingDetail = ref(false);
|
||||
const error = ref("");
|
||||
const detailError = ref("");
|
||||
const source = ref("all");
|
||||
const type = ref("");
|
||||
const matched = ref("all");
|
||||
const controller = new AbortController();
|
||||
|
||||
const columns: DataTableColumn<EventRow>[] = [
|
||||
{ id: "received", label: "Received", fixed: true },
|
||||
{ id: "source", label: "Source" },
|
||||
{ id: "type", label: "Type" },
|
||||
{ id: "matched", label: "Matched" },
|
||||
];
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
const [events, heard] = await Promise.all([
|
||||
listEvents(
|
||||
{
|
||||
source: source.value === "all" ? undefined : source.value,
|
||||
type: type.value.trim() || undefined,
|
||||
matched: matched.value === "all" ? undefined : matched.value === "true",
|
||||
limit: 100,
|
||||
},
|
||||
controller.signal,
|
||||
),
|
||||
sources.value.length ? Promise.resolve(sources.value) : listSources(controller.signal).then((s) => s.map((x) => x.name)),
|
||||
]);
|
||||
rows.value = events;
|
||||
sources.value = heard;
|
||||
} catch (err) {
|
||||
fail(err);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function open(row: EventRow) {
|
||||
selected.value = null;
|
||||
detailError.value = "";
|
||||
loadingDetail.value = true;
|
||||
try {
|
||||
selected.value = await getEvent(row.id, controller.signal);
|
||||
} catch (err) {
|
||||
fail(err, (message) => (detailError.value = message));
|
||||
} finally {
|
||||
loadingDetail.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function fail(err: unknown, show: (message: string) => void = (m) => (error.value = m)) {
|
||||
if (controller.signal.aborted) return;
|
||||
if (err instanceof Unauthorized) emit("unauthorized");
|
||||
show(err instanceof Error ? err.message : String(err));
|
||||
}
|
||||
|
||||
onMounted(load);
|
||||
onBeforeUnmount(() => controller.abort());
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<PageHeader title="Events" />
|
||||
<Section title="Filters">
|
||||
<SettingRow label="Source" for="event-source">
|
||||
<Select v-model="source" @update:model-value="load">
|
||||
<SelectTrigger id="event-source" class="w-full sm:w-64"><SelectValue placeholder="Every source" /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">Every source</SelectItem>
|
||||
<SelectItem v-for="s in sources" :key="s" :value="s">{{ s }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</SettingRow>
|
||||
<SettingRow label="Type" for="event-type">
|
||||
<Input id="event-type" v-model="type" placeholder="Every type" @change="load" />
|
||||
</SettingRow>
|
||||
<SettingRow label="Trigger" for="event-matched">
|
||||
<Select v-model="matched" @update:model-value="load">
|
||||
<SelectTrigger id="event-matched" class="w-full sm:w-64"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">Matched and unmatched</SelectItem>
|
||||
<SelectItem value="true">Matched a trigger</SelectItem>
|
||||
<SelectItem value="false">Unmatched</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</SettingRow>
|
||||
</Section>
|
||||
<Spinner v-if="loading" />
|
||||
<ReadError v-else-if="error && !rows.length" :message="error" retry-label="Retry" @retry="load" />
|
||||
<Empty v-else-if="!rows.length">
|
||||
<EmptyHeader><EmptyTitle>No events match these filters</EmptyTitle></EmptyHeader>
|
||||
</Empty>
|
||||
<DataTable v-else :columns="columns" :rows="rows" :row-key="(row) => row.id" storage-key="events">
|
||||
<template #cell-received="{ row }"><Timestamp :at="row.received_at" /></template>
|
||||
<template #cell-source="{ row }">{{ row.source }}</template>
|
||||
<template #cell-type="{ row }"><span class="font-mono text-caption">{{ row.type }}</span></template>
|
||||
<template #cell-matched="{ row }">
|
||||
<Badge :variant="row.matched ? 'ok' : 'idle'">{{ row.matched ? "Matched" : "Unmatched" }}</Badge>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<Button variant="ghost" size="sm" @click.stop="open(row)">Open</Button>
|
||||
</template>
|
||||
</DataTable>
|
||||
|
||||
<Section v-if="loadingDetail" title="Event"><Spinner /></Section>
|
||||
<Section v-else-if="selected" :title="selected.type" class="mt-4">
|
||||
<template #action>
|
||||
<Button variant="ghost" size="xs" @click="selected = null">Close</Button>
|
||||
</template>
|
||||
<SettingRow label="Received"><Timestamp :at="selected.received_at" /></SettingRow>
|
||||
<SettingRow label="Source"><span class="text-label">{{ selected.source }}</span></SettingRow>
|
||||
<SettingRow label="Occurred" v-if="selected.occurred_at"><Timestamp :at="selected.occurred_at" /></SettingRow>
|
||||
<SettingRow label="Payload">
|
||||
<Textarea :model-value="JSON.stringify(selected.body, null, 2)" readonly rows="12" class="font-mono" spellcheck="false" aria-label="Event payload" />
|
||||
</SettingRow>
|
||||
<SettingRow label="Runs">
|
||||
<div v-if="selected.runs.length" class="flex flex-col gap-1">
|
||||
<RouterLink
|
||||
v-for="run in selected.runs"
|
||||
:key="run.run_id"
|
||||
:to="{ name: 'run', params: { id: run.run_id } }"
|
||||
class="text-label text-link underline-offset-4 hover:underline"
|
||||
>{{ run.trigger }} → {{ run.run_id }}</RouterLink>
|
||||
</div>
|
||||
<span v-else class="text-label text-fg-subtle">No trigger started a run</span>
|
||||
</SettingRow>
|
||||
<p v-if="detailError" class="text-caption text-danger">{{ detailError }}</p>
|
||||
</Section>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,415 @@
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, onMounted, reactive, ref } from "vue";
|
||||
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
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 { MoreMenu } from "@/components/ui/more-menu";
|
||||
import { ReadError } from "@/components/ui/read-error";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { SettingRow } from "@/components/ui/setting-row";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import {
|
||||
acceptExtension,
|
||||
listCredentials,
|
||||
listExtensions,
|
||||
removeExtension,
|
||||
Unauthorized,
|
||||
type CredentialView,
|
||||
type Extension,
|
||||
type ExtensionContract,
|
||||
} from "./api";
|
||||
|
||||
/**
|
||||
* Accepted packages grouped by the contract they serve. Each one shows its
|
||||
* state, version and digest, and expands into the settings it declares and the
|
||||
* credential slots it was given. A credential is named, never read.
|
||||
*/
|
||||
const emit = defineEmits<{ unauthorized: [] }>();
|
||||
|
||||
const contracts: { id: ExtensionContract; title: string; add: string }[] = [
|
||||
{ id: "connector", title: "Connectors", add: "Accept connector" },
|
||||
{ id: "guard", title: "Guards", add: "Accept guard" },
|
||||
{ id: "secretengine", title: "Secret engines", add: "Accept secret engine" },
|
||||
{ id: "mcp", title: "MCP servers", add: "Accept MCP server" },
|
||||
];
|
||||
|
||||
const rows = reactive<Record<ExtensionContract, Extension[]>>({
|
||||
connector: [],
|
||||
guard: [],
|
||||
secretengine: [],
|
||||
mcp: [],
|
||||
});
|
||||
const credentials = ref<CredentialView[]>([]);
|
||||
const loading = ref(true);
|
||||
const error = ref("");
|
||||
const errorAt = ref("");
|
||||
const saved = ref("");
|
||||
const controller = new AbortController();
|
||||
|
||||
interface Slot {
|
||||
slot: string;
|
||||
credential: string;
|
||||
}
|
||||
|
||||
interface Form {
|
||||
name: string;
|
||||
path: string;
|
||||
sha256: string;
|
||||
url: string;
|
||||
args: string;
|
||||
egress: string;
|
||||
env: string;
|
||||
tools: string;
|
||||
settings: Record<string, string>;
|
||||
settingPairs: Paired[];
|
||||
slots: Slot[];
|
||||
}
|
||||
|
||||
interface Paired {
|
||||
key: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
const blank = (): Form => ({
|
||||
name: "", path: "", sha256: "", url: "", args: "", egress: "", env: "", tools: "",
|
||||
settings: {}, settingPairs: [], slots: [],
|
||||
});
|
||||
const adding = reactive<Record<ExtensionContract, boolean>>({
|
||||
connector: false,
|
||||
guard: false,
|
||||
secretengine: false,
|
||||
mcp: false,
|
||||
});
|
||||
const forms = reactive<Record<ExtensionContract, Form>>({
|
||||
connector: blank(),
|
||||
guard: blank(),
|
||||
secretengine: blank(),
|
||||
mcp: blank(),
|
||||
});
|
||||
const editing = ref("");
|
||||
const edit = reactive<Form>(blank());
|
||||
const saving = ref(false);
|
||||
|
||||
const columns: DataTableColumn<Extension>[] = [
|
||||
{ id: "name", label: "Name", fixed: true },
|
||||
{ id: "state", label: "State" },
|
||||
{ id: "version", label: "Version" },
|
||||
{ id: "digest", label: "Digest" },
|
||||
];
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
const [connector, guard, secretengine, mcp, creds] = await Promise.all([
|
||||
listExtensions("connector", controller.signal),
|
||||
listExtensions("guard", controller.signal),
|
||||
listExtensions("secretengine", controller.signal),
|
||||
listExtensions("mcp", controller.signal),
|
||||
listCredentials(controller.signal),
|
||||
]);
|
||||
rows.connector = connector;
|
||||
rows.guard = guard;
|
||||
rows.secretengine = secretengine;
|
||||
rows.mcp = mcp;
|
||||
credentials.value = creds;
|
||||
} catch (err) {
|
||||
fail(err);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function lists(text: string): string[] {
|
||||
return text
|
||||
.split(",")
|
||||
.map((x) => x.trim())
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
function slotsOf(form: Form): Record<string, string> {
|
||||
return Object.fromEntries(form.slots.filter((s) => s.slot.trim()).map((s) => [s.slot.trim(), s.credential]));
|
||||
}
|
||||
|
||||
function toolsOf(form: Form): unknown[] | undefined {
|
||||
if (!form.tools.trim()) return undefined;
|
||||
return JSON.parse(form.tools) as unknown[];
|
||||
}
|
||||
|
||||
function bodyOf(contract: ExtensionContract, form: Form) {
|
||||
const pairs = Object.fromEntries(form.settingPairs.filter((p) => p.key.trim()).map((p) => [p.key.trim(), p.value]));
|
||||
const base = {
|
||||
path: form.path.trim() || undefined,
|
||||
sha256: form.sha256.trim() || undefined,
|
||||
url: form.url.trim() || undefined,
|
||||
args: lists(form.args),
|
||||
egress: lists(form.egress),
|
||||
env: lists(form.env),
|
||||
settings: { ...pairs, ...form.settings },
|
||||
credentials: slotsOf(form),
|
||||
};
|
||||
if (contract === "mcp") return { ...base, tools: toolsOf(form) };
|
||||
return base;
|
||||
}
|
||||
|
||||
async function accept(contract: ExtensionContract) {
|
||||
const form = forms[contract];
|
||||
saving.value = true;
|
||||
errorAt.value = contract;
|
||||
error.value = "";
|
||||
saved.value = "";
|
||||
try {
|
||||
await acceptExtension(contract, form.name.trim(), bodyOf(contract, form));
|
||||
forms[contract] = blank();
|
||||
adding[contract] = false;
|
||||
saved.value = "Accepted.";
|
||||
await load();
|
||||
} catch (err) {
|
||||
fail(err);
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function startEdit(x: Extension) {
|
||||
errorAt.value = x.name;
|
||||
error.value = "";
|
||||
saved.value = "";
|
||||
editing.value = editing.value === x.name ? "" : x.name;
|
||||
Object.assign(edit, {
|
||||
name: x.name,
|
||||
path: x.path ?? "",
|
||||
sha256: x.digest,
|
||||
url: x.url ?? "",
|
||||
args: (x.args ?? []).join(", "),
|
||||
egress: (x.egress ?? []).join(", "),
|
||||
env: (x.env ?? []).join(", "),
|
||||
tools: x.tools ? JSON.stringify(x.tools, null, 2) : "",
|
||||
settings: { ...x.settings },
|
||||
settingPairs: [],
|
||||
slots: Object.entries(x.credentials ?? {}).map(([slot, credential]) => ({ slot, credential })),
|
||||
});
|
||||
}
|
||||
|
||||
async function save(x: Extension) {
|
||||
saving.value = true;
|
||||
errorAt.value = x.name;
|
||||
error.value = "";
|
||||
saved.value = "";
|
||||
try {
|
||||
await acceptExtension(x.contract, x.name, bodyOf(x.contract, edit));
|
||||
saved.value = "Saved.";
|
||||
editing.value = "";
|
||||
await load();
|
||||
} catch (err) {
|
||||
fail(err);
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(x: Extension) {
|
||||
if (!confirm(`Remove ${x.name}? Its process stops and its acceptance is deleted.`)) return;
|
||||
errorAt.value = x.name;
|
||||
error.value = "";
|
||||
try {
|
||||
await removeExtension(x.contract, x.name);
|
||||
await load();
|
||||
} catch (err) {
|
||||
fail(err);
|
||||
}
|
||||
}
|
||||
|
||||
function tone(state: Extension["state"]): "ok" | "warn" | "danger" | "idle" {
|
||||
if (state === "running") return "ok";
|
||||
if (state === "failed") return "danger";
|
||||
return "idle";
|
||||
}
|
||||
|
||||
function fail(err: unknown) {
|
||||
if (controller.signal.aborted) return;
|
||||
if (err instanceof Unauthorized) emit("unauthorized");
|
||||
error.value = err instanceof Error ? err.message : String(err);
|
||||
}
|
||||
|
||||
function setSetting(key: string, value: string) {
|
||||
edit.settings = { ...edit.settings, [key]: value };
|
||||
}
|
||||
|
||||
onMounted(load);
|
||||
onBeforeUnmount(() => controller.abort());
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<PageHeader title="Extensions" />
|
||||
<Spinner v-if="loading" />
|
||||
<ReadError v-else-if="error && !editing && !Object.values(adding).some(Boolean)" :message="error" retry-label="Retry" @retry="load" />
|
||||
<template v-else>
|
||||
<div v-for="c in contracts" :key="c.id">
|
||||
<Section :title="c.title">
|
||||
<template #action>
|
||||
<Button variant="outline" size="xs" @click="adding[c.id] = !adding[c.id]">Add</Button>
|
||||
</template>
|
||||
|
||||
<div v-for="items in [rows[c.id]]" :key="`${c.id}-list`">
|
||||
<Empty v-if="items.length === 0">
|
||||
<EmptyHeader><EmptyTitle>None accepted</EmptyTitle></EmptyHeader>
|
||||
</Empty>
|
||||
<DataTable v-if="items.length" :columns="columns" :rows="items" :row-key="(x) => x.name" :storage-key="`extensions-${c.id}`">
|
||||
<template #cell-name="{ row }"><span class="font-medium">{{ row.name }}</span></template>
|
||||
<template #cell-state="{ row }">
|
||||
<span class="flex items-center gap-2">
|
||||
<Badge :variant="tone(row.state)">{{ row.state }}</Badge>
|
||||
<span v-if="row.error" class="text-caption text-danger">{{ row.error }}</span>
|
||||
</span>
|
||||
</template>
|
||||
<template #cell-version="{ row }">{{ row.version || "—" }}</template>
|
||||
<template #cell-digest="{ row }"><span class="font-mono text-caption" :title="row.digest">{{ row.digest.slice(0, 12) }}</span></template>
|
||||
<template #actions="{ row }">
|
||||
<MoreMenu :label="`Actions for ${row.name}`">
|
||||
<Button variant="ghost" size="sm" class="w-full justify-start text-danger" @click="remove(row)">Remove</Button>
|
||||
</MoreMenu>
|
||||
</template>
|
||||
<template #detail="{ row }">
|
||||
<div class="flex flex-col gap-3">
|
||||
<p v-if="!row.settings_schema.length && !Object.keys(row.credentials ?? {}).length" class="text-caption text-fg-subtle">This package declares no settings.</p>
|
||||
<template v-else-if="editing === row.name">
|
||||
<SettingRow v-for="s in row.settings_schema" :key="s.key" :label="s.label" :hint="s.description" :for="`${row.name}-${s.key}`">
|
||||
<Switch
|
||||
v-if="s.type === 'boolean'"
|
||||
:id="`${row.name}-${s.key}`"
|
||||
:model-value="edit.settings[s.key] === 'true'"
|
||||
@update:model-value="(on) => setSetting(s.key, String(on))"
|
||||
/>
|
||||
<Select
|
||||
v-else-if="s.type === 'select'"
|
||||
:model-value="edit.settings[s.key] ?? ''"
|
||||
@update:model-value="(v) => setSetting(s.key, String(v))"
|
||||
>
|
||||
<SelectTrigger :id="`${row.name}-${s.key}`" class="w-full sm:w-64"><SelectValue placeholder="Choose" /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="option in s.options ?? []" :key="option" :value="option">{{ option }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Textarea
|
||||
v-else-if="s.type === 'text'"
|
||||
:id="`${row.name}-${s.key}`"
|
||||
:model-value="edit.settings[s.key] ?? ''"
|
||||
rows="5"
|
||||
spellcheck="false"
|
||||
@update:model-value="(v) => setSetting(s.key, String(v))"
|
||||
/>
|
||||
<Input
|
||||
v-else
|
||||
:id="`${row.name}-${s.key}`"
|
||||
:model-value="edit.settings[s.key] ?? ''"
|
||||
:type="s.type === 'number' ? 'number' : 'text'"
|
||||
:placeholder="s.secret ? 'engine:key' : ''"
|
||||
@update:model-value="(v) => setSetting(s.key, String(v))"
|
||||
/>
|
||||
</SettingRow>
|
||||
<SettingRow label="Credential slots" hint="The credential that fills each slot the package reads. Its value is sealed and never shown.">
|
||||
<div class="flex flex-col gap-2">
|
||||
<div v-for="(slot, index) in edit.slots" :key="index" class="flex flex-wrap items-center gap-2">
|
||||
<Input v-model="slot.slot" placeholder="slot" class="w-40" aria-label="Credential slot" />
|
||||
<Select v-model="slot.credential">
|
||||
<SelectTrigger class="w-48" aria-label="Credential"><SelectValue placeholder="Credential" /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="c in credentials" :key="c.name" :value="c.name">{{ c.name }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Button variant="ghost" size="xs" @click="edit.slots.splice(index, 1)">Remove</Button>
|
||||
</div>
|
||||
<Button variant="outline" size="xs" class="self-start" @click="edit.slots.push({ slot: '', credential: '' })">Add slot</Button>
|
||||
</div>
|
||||
</SettingRow>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<Button size="sm" :disabled="saving" @click="save(row)">Save settings</Button>
|
||||
<Button variant="ghost" size="sm" @click="editing = ''">Cancel</Button>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<SettingRow v-for="s in row.settings_schema" :key="s.key" :label="s.label" :hint="s.description">
|
||||
<span class="font-mono text-label">{{ row.settings[s.key] || "Not set" }}</span>
|
||||
</SettingRow>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<Button variant="outline" size="sm" @click="startEdit(row)">Edit</Button>
|
||||
</div>
|
||||
</template>
|
||||
<p v-if="editing !== row.name && Object.keys(row.credentials ?? {}).length" class="text-caption text-fg-subtle">
|
||||
Credential slots: {{ Object.entries(row.credentials).map(([slot, name]) => `${slot} → ${name}`).join(", ") }}
|
||||
</p>
|
||||
<p v-if="error && errorAt === row.name" class="text-caption text-danger">{{ error }}</p>
|
||||
</div>
|
||||
</template>
|
||||
</DataTable>
|
||||
</div>
|
||||
<div v-if="adding[c.id]" class="mb-4 flex flex-col gap-3 border-b border-border pb-4">
|
||||
<SettingRow label="Name" :for="`${c.id}-name`">
|
||||
<Input :id="`${c.id}-name`" v-model="forms[c.id].name" placeholder="lowercase-name" />
|
||||
</SettingRow>
|
||||
<SettingRow label="Binary" :for="`${c.id}-path`" hint="A path and its SHA-256, or an HTTP endpoint for an MCP server.">
|
||||
<div class="flex flex-col gap-2">
|
||||
<Input :id="`${c.id}-path`" v-model="forms[c.id].path" placeholder="Path" />
|
||||
<Input v-model="forms[c.id].sha256" placeholder="SHA-256" class="font-mono" />
|
||||
<Input v-if="c.id === 'mcp'" v-model="forms[c.id].url" placeholder="https://…" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Egress" :for="`${c.id}-egress`" hint="Comma-separated hosts it may reach. Empty runs it on the host network.">
|
||||
<Input :id="`${c.id}-egress`" v-model="forms[c.id].egress" />
|
||||
</SettingRow>
|
||||
<SettingRow label="Environment" :for="`${c.id}-env`" hint="Comma-separated host variables it may read.">
|
||||
<Input :id="`${c.id}-env`" v-model="forms[c.id].env" />
|
||||
</SettingRow>
|
||||
<SettingRow v-if="c.id === 'mcp'" label="Arguments" :for="`${c.id}-args`">
|
||||
<Input :id="`${c.id}-args`" v-model="forms[c.id].args" />
|
||||
</SettingRow>
|
||||
<SettingRow v-if="c.id === 'mcp'" label="Tools" :for="`${c.id}-tools`" hint="The tools the server may offer, as JSON.">
|
||||
<Textarea :id="`${c.id}-tools`" v-model="forms[c.id].tools" rows="5" class="font-mono" spellcheck="false" />
|
||||
</SettingRow>
|
||||
<SettingRow label="Credential slots" hint="A slot the extension reads, and the credential that fills it.">
|
||||
<div class="flex flex-col gap-2">
|
||||
<div v-for="(slot, index) in forms[c.id].slots" :key="index" class="flex flex-wrap items-center gap-2">
|
||||
<Input v-model="slot.slot" placeholder="slot" class="w-40" aria-label="Credential slot" />
|
||||
<Select v-model="slot.credential">
|
||||
<SelectTrigger class="w-48" aria-label="Credential"><SelectValue placeholder="Credential" /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="name in credentials.map((x) => x.name)" :key="name" :value="name">{{ name }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Button variant="ghost" size="xs" @click="forms[c.id].slots.splice(index, 1)">Remove</Button>
|
||||
</div>
|
||||
<Button variant="outline" size="xs" class="self-start" @click="forms[c.id].slots.push({ slot: '', credential: '' })">Add slot</Button>
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Settings" hint="The package's declared settings. A value it doesn't declare is refused.">
|
||||
<div class="flex flex-col gap-2">
|
||||
<div v-for="(pair, index) in forms[c.id].settingPairs" :key="index" class="flex flex-wrap items-center gap-2">
|
||||
<Input v-model="pair.key" placeholder="key" class="w-40" aria-label="Setting key" />
|
||||
<Input v-model="pair.value" placeholder="value" class="w-48" aria-label="Setting value" />
|
||||
<Button variant="ghost" size="xs" @click="forms[c.id].settingPairs.splice(index, 1)">Remove</Button>
|
||||
</div>
|
||||
<Button variant="outline" size="xs" class="self-start" @click="forms[c.id].settingPairs.push({ key: '', value: '' })">Add setting</Button>
|
||||
</div>
|
||||
</SettingRow>
|
||||
<p v-if="error && errorAt === c.id" class="text-caption text-danger">{{ error }}</p>
|
||||
<div class="flex items-center gap-2">
|
||||
<Button :disabled="saving || !forms[c.id].name.trim()" @click="accept(c.id)">{{ c.add }}</Button>
|
||||
<Button type="button" variant="ghost" @click="adding[c.id] = false">Cancel</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Section>
|
||||
</div>
|
||||
<p v-if="saved" class="text-caption text-muted-foreground">{{ saved }}</p>
|
||||
<p v-if="error && !errorAt" class="text-caption text-danger">{{ error }}</p>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@@ -13,6 +13,8 @@ import { Spinner } from "@/components/ui/spinner";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { getPeople, getSettings, saveSettings, Unauthorized, type Blackout, type EscalationStep, type Person } from "./api";
|
||||
import AgentModelEditor from "./AgentModelEditor.vue";
|
||||
import SystemSettings from "./SystemSettings.vue";
|
||||
|
||||
/**
|
||||
* Organisation settings: what Archie does when nobody has decided otherwise.
|
||||
@@ -285,5 +287,9 @@ onBeforeUnmount(() => controller.abort());
|
||||
<span v-if="saved" class="text-caption text-muted-foreground">{{ saved }}</span>
|
||||
</div>
|
||||
</Section>
|
||||
<template v-if="!loading && !error">
|
||||
<AgentModelEditor @unauthorized="emit('unauthorized')" />
|
||||
<SystemSettings @unauthorized="emit('unauthorized')" />
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,186 @@
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, onMounted, reactive, ref } from "vue";
|
||||
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { ReadError } from "@/components/ui/read-error";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { SettingRow } from "@/components/ui/setting-row";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { TagsInput, TagsInputInput, TagsInputItem, TagsInputItemDelete, TagsInputItemText } from "@/components/ui/tags-input";
|
||||
import { listExtensions, listSources, putKeyFields, putSource, Unauthorized, type Extension, type SourceView } from "./api";
|
||||
|
||||
/**
|
||||
* Sources are the places events come from. A source names the connector that
|
||||
* parses its payloads; its token is the verification, and it is shown only
|
||||
* when it is created or rotated.
|
||||
*/
|
||||
const emit = defineEmits<{ unauthorized: [] }>();
|
||||
|
||||
const sources = ref<SourceView[]>([]);
|
||||
const connectors = ref<Extension[]>([]);
|
||||
const keyFields = reactive<Record<string, string[]>>({});
|
||||
const loading = ref(true);
|
||||
const error = ref("");
|
||||
const saved = ref("");
|
||||
const name = ref("");
|
||||
const connector = ref("");
|
||||
const issued = ref<{ source: string; token: string; url: string } | null>(null);
|
||||
const copied = ref("");
|
||||
const saving = ref(false);
|
||||
const controller = new AbortController();
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
const [found, running] = await Promise.all([listSources(controller.signal), listExtensions("connector", controller.signal)]);
|
||||
sources.value = found;
|
||||
connectors.value = running.filter((c) => c.state === "running");
|
||||
for (const src of found) keyFields[src.name] = [...src.key_fields];
|
||||
if (!connector.value && connectors.value.length) connector.value = connectors.value[0].name;
|
||||
} catch (err) {
|
||||
fail(err);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function add() {
|
||||
saving.value = true;
|
||||
error.value = "";
|
||||
issued.value = null;
|
||||
try {
|
||||
issued.value = await putSource(name.value.trim(), connector.value);
|
||||
name.value = "";
|
||||
await load();
|
||||
} catch (err) {
|
||||
fail(err);
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function rotate(src: SourceView) {
|
||||
saving.value = true;
|
||||
error.value = "";
|
||||
issued.value = null;
|
||||
try {
|
||||
issued.value = await putSource(src.name, src.connector);
|
||||
await load();
|
||||
} catch (err) {
|
||||
fail(err);
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function saveKeyFields(src: SourceView) {
|
||||
saving.value = true;
|
||||
error.value = "";
|
||||
saved.value = "";
|
||||
try {
|
||||
const out = await putKeyFields(src.name, keyFields[src.name] ?? []);
|
||||
keyFields[src.name] = out.key_fields;
|
||||
saved.value = "Saved.";
|
||||
} catch (err) {
|
||||
fail(err);
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function copy(token: string) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(token);
|
||||
copied.value = token;
|
||||
} catch {
|
||||
copied.value = "";
|
||||
}
|
||||
}
|
||||
|
||||
function fail(err: unknown) {
|
||||
if (controller.signal.aborted) return;
|
||||
if (err instanceof Unauthorized) emit("unauthorized");
|
||||
error.value = err instanceof Error ? err.message : String(err);
|
||||
}
|
||||
|
||||
onMounted(load);
|
||||
onBeforeUnmount(() => controller.abort());
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<PageHeader title="Sources" />
|
||||
<Spinner v-if="loading" />
|
||||
<ReadError v-else-if="error && !sources.length" :message="error" retry-label="Retry" @retry="load" />
|
||||
<template v-else>
|
||||
<Section title="New source">
|
||||
<form class="flex flex-col gap-3" @submit.prevent="add">
|
||||
<SettingRow label="Name" for="source-name">
|
||||
<Input id="source-name" v-model="name" placeholder="lowercase-name" />
|
||||
</SettingRow>
|
||||
<SettingRow label="Connector" for="source-connector">
|
||||
<Select v-model="connector">
|
||||
<SelectTrigger id="source-connector" class="w-full sm:w-64"><SelectValue placeholder="Choose a running connector" /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="c in connectors" :key="c.name" :value="c.name">{{ c.name }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</SettingRow>
|
||||
<p class="text-caption text-fg-subtle">
|
||||
Every delivery must carry the source's token as a bearer token. A new source gets one, shown once.
|
||||
</p>
|
||||
<p v-if="!connectors.length" class="text-caption text-warn">No connector is running, so a new source has nothing to parse its events.</p>
|
||||
<div class="flex items-center gap-2">
|
||||
<Button type="submit" :disabled="saving || !name.trim() || !connector">Add source</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Section>
|
||||
|
||||
<Section v-if="issued" title="Token" description="This is the only time it is shown.">
|
||||
<div class="flex flex-col gap-2 sm:flex-row sm:items-center">
|
||||
<Input :model-value="issued.token" readonly class="font-mono" aria-label="Source token" />
|
||||
<div class="flex items-center gap-2">
|
||||
<Button variant="outline" @click="copy(issued.token)">{{ copied === issued.token ? "Copied" : "Copy" }}</Button>
|
||||
<Button variant="ghost" @click="issued = null">Done</Button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="mt-2 text-caption text-fg-subtle">Deliver to <span class="font-mono">{{ issued.url }}</span></p>
|
||||
</Section>
|
||||
|
||||
<Empty v-if="!sources.length">
|
||||
<EmptyHeader><EmptyTitle>No sources yet</EmptyTitle></EmptyHeader>
|
||||
</Empty>
|
||||
<Section v-for="src in sources" :key="src.name" :title="src.name">
|
||||
<template #action>
|
||||
<div class="flex items-center gap-2">
|
||||
<Badge :variant="src.token_set ? 'ok' : 'idle'">{{ src.token_set ? "Token set" : "No token" }}</Badge>
|
||||
<Button variant="ghost" size="xs" @click="rotate(src)">Rotate token</Button>
|
||||
</div>
|
||||
</template>
|
||||
<SettingRow label="Connector">
|
||||
<span class="text-label">{{ src.connector }}</span>
|
||||
</SettingRow>
|
||||
<SettingRow label="Key fields" hint="Events sharing these field values group as one incident. Leave empty for the connector's default.">
|
||||
<TagsInput v-model="keyFields[src.name]" class="font-mono">
|
||||
<TagsInputItem v-for="path in keyFields[src.name]" :key="path" :value="path">
|
||||
<TagsInputItemText />
|
||||
<TagsInputItemDelete />
|
||||
</TagsInputItem>
|
||||
<TagsInputInput :aria-label="`Add a key field to ${src.name}`" placeholder="resource.id" />
|
||||
</TagsInput>
|
||||
</SettingRow>
|
||||
<div class="mt-2 flex items-center gap-3">
|
||||
<Button size="sm" :disabled="saving" @click="saveKeyFields(src)">Save</Button>
|
||||
<p v-if="error" class="text-caption text-danger">{{ error }}</p>
|
||||
</div>
|
||||
</Section>
|
||||
<p v-if="saved" class="text-caption text-muted-foreground">{{ saved }}</p>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,104 @@
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, onMounted, ref } from "vue";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { MetadataList } from "@/components/ui/metadata-list";
|
||||
import { ReadError } from "@/components/ui/read-error";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { getBootstrap, rotateAdminToken, Unauthorized, type BootstrapView } from "./api";
|
||||
|
||||
/**
|
||||
* The bootstrap values the binary reads before the database is reachable. They
|
||||
* are shown read-only because they come first; the admin token is the one that
|
||||
* can be rotated here.
|
||||
*/
|
||||
const emit = defineEmits<{ unauthorized: [] }>();
|
||||
|
||||
const bootstrap = ref<BootstrapView | null>(null);
|
||||
const issued = ref("");
|
||||
const copied = ref(false);
|
||||
const loading = ref(true);
|
||||
const error = ref("");
|
||||
const saving = ref(false);
|
||||
const controller = new AbortController();
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
bootstrap.value = await getBootstrap(controller.signal);
|
||||
} catch (err) {
|
||||
fail(err);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function rotate() {
|
||||
if (!confirm("Rotate the admin token? Every browser using the old token is signed out.")) return;
|
||||
saving.value = true;
|
||||
error.value = "";
|
||||
issued.value = "";
|
||||
try {
|
||||
const result = await rotateAdminToken();
|
||||
issued.value = result.token;
|
||||
await load();
|
||||
} catch (err) {
|
||||
fail(err);
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function copy() {
|
||||
try {
|
||||
await navigator.clipboard.writeText(issued.value);
|
||||
copied.value = true;
|
||||
} catch {
|
||||
copied.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function fail(err: unknown) {
|
||||
if (controller.signal.aborted) return;
|
||||
if (err instanceof Unauthorized) emit("unauthorized");
|
||||
error.value = err instanceof Error ? err.message : String(err);
|
||||
}
|
||||
|
||||
onMounted(load);
|
||||
onBeforeUnmount(() => controller.abort());
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Section title="System" description="Bootstrap values, read-only. Changing one means editing the config file and restarting.">
|
||||
<Spinner v-if="loading" />
|
||||
<ReadError v-else-if="error && !bootstrap" :message="error" retry-label="Retry" @retry="load" />
|
||||
<template v-else-if="bootstrap">
|
||||
<MetadataList
|
||||
:rows="[
|
||||
{ label: 'Listen', value: bootstrap.listen, mono: true },
|
||||
{ label: 'Database host', value: bootstrap.database_host, mono: true },
|
||||
{ label: 'Schemas', value: String(bootstrap.schemas) },
|
||||
{ label: 'Admin token', value: bootstrap.admin_token_set ? `${bootstrap.admin_token_hash_prefix}…` : 'Not set', mono: true },
|
||||
{ label: 'Sealing identity', value: bootstrap.sealing_identity_set ? 'Set' : 'Not set' },
|
||||
]"
|
||||
/>
|
||||
<div class="mt-4 flex flex-col gap-2">
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<Button variant="outline" size="sm" :disabled="saving" @click="rotate">Rotate admin token</Button>
|
||||
<p v-if="error" class="text-caption text-danger">{{ error }}</p>
|
||||
</div>
|
||||
<div v-if="issued" class="flex flex-col gap-2 sm:flex-row sm:items-center">
|
||||
<Input :model-value="issued" readonly class="font-mono" aria-label="New admin token" />
|
||||
<div class="flex items-center gap-2">
|
||||
<Button variant="outline" @click="copy">{{ copied ? "Copied" : "Copy" }}</Button>
|
||||
<Button variant="ghost" @click="issued = ''">Done</Button>
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="issued" class="text-caption text-fg-subtle">This is the only time the token is shown.</p>
|
||||
</div>
|
||||
</template>
|
||||
</Section>
|
||||
</template>
|
||||
@@ -0,0 +1,235 @@
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, onMounted, reactive, ref } from "vue";
|
||||
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { ReadError } from "@/components/ui/read-error";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { SettingRow } from "@/components/ui/setting-row";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { listSources, listTriggers, saveTrigger, Unauthorized, type SourceView, type TriggerView } from "./api";
|
||||
|
||||
/**
|
||||
* Triggers match an event, or an interval, to a workflow. A disabled trigger
|
||||
* is kept and starts nothing.
|
||||
*/
|
||||
const emit = defineEmits<{ unauthorized: [] }>();
|
||||
|
||||
interface Pair {
|
||||
key: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
interface Draft {
|
||||
name: string;
|
||||
source: string;
|
||||
eventType: string;
|
||||
workflow: string;
|
||||
every: string;
|
||||
enabled: boolean;
|
||||
filter: Pair[];
|
||||
}
|
||||
|
||||
const blank = (): Draft => ({ name: "", source: "", eventType: "", workflow: "", every: "", enabled: true, filter: [] });
|
||||
|
||||
const triggers = ref<TriggerView[]>([]);
|
||||
const sources = ref<SourceView[]>([]);
|
||||
const drafts = reactive<Record<string, Draft>>({});
|
||||
const adding = ref(false);
|
||||
const draft = ref<Draft>(blank());
|
||||
const loading = ref(true);
|
||||
const error = ref("");
|
||||
const saved = ref("");
|
||||
const saving = ref(false);
|
||||
const controller = new AbortController();
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
const [found, heard] = await Promise.all([listTriggers(controller.signal), listSources(controller.signal)]);
|
||||
triggers.value = found;
|
||||
sources.value = heard;
|
||||
for (const t of found) {
|
||||
drafts[t.name] = {
|
||||
name: t.name,
|
||||
source: t.source,
|
||||
eventType: t.event_type,
|
||||
workflow: t.workflow,
|
||||
every: t.every ?? "",
|
||||
enabled: t.enabled,
|
||||
filter: Object.entries(t.filter).map(([key, value]) => ({ key, value })),
|
||||
};
|
||||
}
|
||||
if (!draft.value.source && heard.length) draft.value.source = heard[0].name;
|
||||
} catch (err) {
|
||||
fail(err);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function filterOf(pairs: Pair[]): Record<string, string> {
|
||||
return Object.fromEntries(pairs.filter((p) => p.key.trim()).map((p) => [p.key.trim(), p.value]));
|
||||
}
|
||||
|
||||
function bodyOf(d: Draft) {
|
||||
return {
|
||||
source: d.source,
|
||||
event_type: d.eventType,
|
||||
workflow: d.workflow.trim(),
|
||||
filter: filterOf(d.filter),
|
||||
disabled: !d.enabled,
|
||||
every: d.every.trim() || undefined,
|
||||
};
|
||||
}
|
||||
|
||||
async function add() {
|
||||
saving.value = true;
|
||||
error.value = "";
|
||||
saved.value = "";
|
||||
try {
|
||||
await saveTrigger(draft.value.name.trim(), bodyOf(draft.value));
|
||||
draft.value = blank();
|
||||
if (sources.value.length) draft.value.source = sources.value[0].name;
|
||||
adding.value = false;
|
||||
saved.value = "Saved.";
|
||||
await load();
|
||||
} catch (err) {
|
||||
fail(err);
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function save(t: TriggerView) {
|
||||
const d = drafts[t.name];
|
||||
if (!d) return;
|
||||
saving.value = true;
|
||||
error.value = "";
|
||||
saved.value = "";
|
||||
try {
|
||||
await saveTrigger(t.name, bodyOf(d));
|
||||
saved.value = "Saved.";
|
||||
await load();
|
||||
} catch (err) {
|
||||
fail(err);
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function toggle(t: TriggerView, on: boolean) {
|
||||
const d = drafts[t.name];
|
||||
if (!d) return;
|
||||
d.enabled = on;
|
||||
await save(t);
|
||||
}
|
||||
|
||||
function fail(err: unknown) {
|
||||
if (controller.signal.aborted) return;
|
||||
if (err instanceof Unauthorized) emit("unauthorized");
|
||||
error.value = err instanceof Error ? err.message : String(err);
|
||||
}
|
||||
|
||||
onMounted(load);
|
||||
onBeforeUnmount(() => controller.abort());
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<PageHeader title="Triggers">
|
||||
<Button variant="outline" @click="adding = !adding">Add trigger</Button>
|
||||
</PageHeader>
|
||||
<Spinner v-if="loading" />
|
||||
<ReadError v-else-if="error && !triggers.length" :message="error" retry-label="Retry" @retry="load" />
|
||||
<template v-else>
|
||||
<Section v-if="adding" title="New trigger">
|
||||
<form class="flex flex-col gap-3" @submit.prevent="add">
|
||||
<SettingRow label="Name" for="trigger-name">
|
||||
<Input id="trigger-name" v-model="draft.name" placeholder="lowercase-name" />
|
||||
</SettingRow>
|
||||
<SettingRow label="Source" for="trigger-source">
|
||||
<Select v-model="draft.source">
|
||||
<SelectTrigger id="trigger-source" class="w-full sm:w-64"><SelectValue placeholder="Choose a source" /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="s in sources" :key="s.name" :value="s.name">{{ s.name }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</SettingRow>
|
||||
<SettingRow label="Event type" for="trigger-event" hint="The event type the source's connector emits, such as alert.firing.">
|
||||
<Input id="trigger-event" v-model="draft.eventType" />
|
||||
</SettingRow>
|
||||
<SettingRow label="Every" for="trigger-every" hint="An interval such as 1h fires on a schedule instead of on events. Source and type are then the schedule's own.">
|
||||
<Input id="trigger-every" v-model="draft.every" placeholder="1h" />
|
||||
</SettingRow>
|
||||
<SettingRow label="Workflow" for="trigger-workflow">
|
||||
<Input id="trigger-workflow" v-model="draft.workflow" placeholder="investigate" />
|
||||
</SettingRow>
|
||||
<SettingRow label="Filter" hint="Every field must hold its value for the trigger to match.">
|
||||
<div class="flex flex-col gap-2">
|
||||
<div v-for="(pair, index) in draft.filter" :key="index" class="flex flex-wrap items-center gap-2">
|
||||
<Input v-model="pair.key" placeholder="field" class="w-40" aria-label="Filter field" />
|
||||
<Input v-model="pair.value" placeholder="value" class="w-40" aria-label="Filter value" />
|
||||
<Button variant="ghost" size="xs" @click="draft.filter.splice(index, 1)">Remove</Button>
|
||||
</div>
|
||||
<Button variant="outline" size="xs" class="self-start" @click="draft.filter.push({ key: '', value: '' })">Add filter</Button>
|
||||
</div>
|
||||
</SettingRow>
|
||||
<p v-if="error" class="text-caption text-danger">{{ error }}</p>
|
||||
<div class="flex items-center gap-2">
|
||||
<Button type="submit" :disabled="saving || !draft.name.trim() || !draft.workflow.trim()">Save</Button>
|
||||
<Button type="button" variant="ghost" @click="adding = false">Cancel</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Section>
|
||||
|
||||
<Empty v-if="!triggers.length">
|
||||
<EmptyHeader><EmptyTitle>No triggers yet</EmptyTitle></EmptyHeader>
|
||||
</Empty>
|
||||
<Section v-for="t in triggers" :key="t.name" :title="t.name">
|
||||
<template #action>
|
||||
<Switch :model-value="drafts[t.name]?.enabled ?? t.enabled" :aria-label="`Enable ${t.name}`" @update:model-value="(on) => toggle(t, on)" />
|
||||
</template>
|
||||
<template v-if="drafts[t.name]">
|
||||
<SettingRow label="Source" :for="`${t.name}-source`">
|
||||
<Select v-model="drafts[t.name].source">
|
||||
<SelectTrigger :id="`${t.name}-source`" class="w-full sm:w-64"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="s in sources" :key="s.name" :value="s.name">{{ s.name }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</SettingRow>
|
||||
<SettingRow label="Event type" :for="`${t.name}-type`">
|
||||
<Input :id="`${t.name}-type`" v-model="drafts[t.name].eventType" />
|
||||
</SettingRow>
|
||||
<SettingRow label="Every" :for="`${t.name}-every`" hint="Empty fires on events; an interval such as 1h fires on a schedule.">
|
||||
<Input :id="`${t.name}-every`" v-model="drafts[t.name].every" placeholder="1h" />
|
||||
</SettingRow>
|
||||
<SettingRow label="Workflow" :for="`${t.name}-workflow`">
|
||||
<Input :id="`${t.name}-workflow`" v-model="drafts[t.name].workflow" />
|
||||
</SettingRow>
|
||||
<SettingRow label="Filter">
|
||||
<div class="flex flex-col gap-2">
|
||||
<div v-for="(pair, index) in drafts[t.name].filter" :key="index" class="flex flex-wrap items-center gap-2">
|
||||
<Input v-model="pair.key" placeholder="field" class="w-40" aria-label="Filter field" />
|
||||
<Input v-model="pair.value" placeholder="value" class="w-40" aria-label="Filter value" />
|
||||
<Button variant="ghost" size="xs" @click="drafts[t.name].filter.splice(index, 1)">Remove</Button>
|
||||
</div>
|
||||
<Button variant="outline" size="xs" class="self-start" @click="drafts[t.name].filter.push({ key: '', value: '' })">Add filter</Button>
|
||||
</div>
|
||||
</SettingRow>
|
||||
<div class="mt-2 flex items-center gap-3">
|
||||
<Button size="sm" :disabled="saving" @click="save(t)">Save</Button>
|
||||
<p v-if="error" class="text-caption text-danger">{{ error }}</p>
|
||||
</div>
|
||||
</template>
|
||||
</Section>
|
||||
<p v-if="saved" class="text-caption text-muted-foreground">{{ saved }}</p>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
+197
-2
@@ -4,6 +4,16 @@ const TOKEN_KEY = "archie.adminToken";
|
||||
|
||||
export class Unauthorized extends Error {}
|
||||
|
||||
/** A failed request, with the status the server answered. */
|
||||
export class ApiError extends Error {
|
||||
readonly status: number;
|
||||
|
||||
constructor(message: string, status: number) {
|
||||
super(message);
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
||||
export const token = (): string => sessionStorage.getItem(TOKEN_KEY) ?? "";
|
||||
export const setToken = (value: string) => sessionStorage.setItem(TOKEN_KEY, value);
|
||||
export const clearToken = () => sessionStorage.removeItem(TOKEN_KEY);
|
||||
@@ -13,7 +23,7 @@ async function request(path: string, signal?: AbortSignal): Promise<Response> {
|
||||
if (res.status === 401) throw new Unauthorized("The admin token was refused.");
|
||||
if (!res.ok) {
|
||||
const body = (await res.json().catch(() => ({}))) as { error?: string };
|
||||
throw new Error(body.error ?? `${res.status} ${res.statusText}`);
|
||||
throw new ApiError(body.error ?? `${res.status} ${res.statusText}`, res.status);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -267,7 +277,7 @@ async function send<T>(method: string, path: string, payload?: unknown): Promise
|
||||
if (res.status === 401) throw new Unauthorized("The admin token was refused.");
|
||||
if (!res.ok) {
|
||||
const body = (await res.json().catch(() => ({}))) as { error?: string };
|
||||
throw new Error(body.error ?? `${res.status} ${res.statusText}`);
|
||||
throw new ApiError(body.error ?? `${res.status} ${res.statusText}`, res.status);
|
||||
}
|
||||
return (await res.json().catch(() => undefined)) as T;
|
||||
}
|
||||
@@ -429,6 +439,191 @@ export const dryRunDraft = (id: string) => send<Draft>("POST", `/api/drafts/${en
|
||||
export const publishDraft = (id: string) => send<Draft>("POST", `/api/drafts/${encodeURIComponent(id)}/publish`);
|
||||
|
||||
export const listRuns =(signal?: AbortSignal) => get<Run[]>("/api/runs", signal);
|
||||
|
||||
/** A setting an extension declares. Its type decides the control the form shows. */
|
||||
export interface SettingDecl {
|
||||
key: string;
|
||||
label: string;
|
||||
description?: string;
|
||||
secret?: boolean;
|
||||
required?: boolean;
|
||||
type?: "string" | "number" | "boolean" | "duration" | "list" | "select" | "text";
|
||||
options?: string[];
|
||||
}
|
||||
|
||||
export type ExtensionContract = "connector" | "secretengine" | "guard" | "mcp";
|
||||
|
||||
const extensionPath: Record<ExtensionContract, string> = {
|
||||
connector: "connectors",
|
||||
secretengine: "secret-engines",
|
||||
guard: "guards",
|
||||
mcp: "mcp-servers",
|
||||
};
|
||||
|
||||
/** An accepted package: what it is, whether it runs, and what it was given. */
|
||||
export interface Extension {
|
||||
name: string;
|
||||
contract: ExtensionContract;
|
||||
state: "running" | "failed" | "stopped";
|
||||
error?: string;
|
||||
version?: string;
|
||||
digest: string;
|
||||
path?: string;
|
||||
url?: string;
|
||||
args?: string[];
|
||||
egress: string[];
|
||||
env: string[];
|
||||
settings: Record<string, string>;
|
||||
settings_schema: SettingDecl[];
|
||||
credentials: Record<string, string>;
|
||||
tools?: unknown;
|
||||
}
|
||||
|
||||
/** What a credential field is: a stored value, or the engine and key resolving it. */
|
||||
export interface CredentialField {
|
||||
value?: string;
|
||||
engine?: string;
|
||||
key?: string;
|
||||
}
|
||||
|
||||
export interface CredentialView {
|
||||
name: string;
|
||||
kind: "machine" | "age" | "basic" | "bearer";
|
||||
fields: Record<string, string>;
|
||||
}
|
||||
|
||||
export interface AgentModel {
|
||||
class: string;
|
||||
base_url: string;
|
||||
model: string;
|
||||
/** The credential holding the token; the token itself is never returned. */
|
||||
api_key_credential?: string;
|
||||
}
|
||||
|
||||
export interface BootstrapView {
|
||||
listen: string;
|
||||
database_host: string;
|
||||
schemas: number;
|
||||
admin_token_hash_prefix: string;
|
||||
admin_token_set: boolean;
|
||||
sealing_identity_set: boolean;
|
||||
}
|
||||
|
||||
export interface SourceView {
|
||||
name: string;
|
||||
connector: string;
|
||||
key_fields: string[];
|
||||
token_set: boolean;
|
||||
}
|
||||
|
||||
export interface TriggerView {
|
||||
name: string;
|
||||
source: string;
|
||||
event_type: string;
|
||||
filter: Record<string, string>;
|
||||
workflow: string;
|
||||
enabled: boolean;
|
||||
every?: string;
|
||||
}
|
||||
|
||||
export interface EventRow {
|
||||
id: string;
|
||||
source: string;
|
||||
type: string;
|
||||
fields: unknown;
|
||||
linked_to?: string;
|
||||
occurred_at?: string;
|
||||
received_at: string;
|
||||
matched: boolean;
|
||||
dispatched_at?: string;
|
||||
}
|
||||
|
||||
export interface EventDetail extends EventRow {
|
||||
body: unknown;
|
||||
runs: { trigger: string; run_id: string }[];
|
||||
}
|
||||
|
||||
export interface JudgeControl {
|
||||
name: string;
|
||||
version?: string;
|
||||
digest?: string;
|
||||
advisory: boolean;
|
||||
settings: Record<string, string>;
|
||||
settings_schema: SettingDecl[];
|
||||
latest?: {
|
||||
model?: string;
|
||||
trusted: boolean;
|
||||
advisory_reason?: string;
|
||||
eval_date?: string;
|
||||
answer?: string;
|
||||
at: string;
|
||||
};
|
||||
}
|
||||
|
||||
export const listExtensions = (contract: ExtensionContract, signal?: AbortSignal) =>
|
||||
get<Extension[]>(`/api/${extensionPath[contract]}`, signal);
|
||||
|
||||
export interface AcceptRequest {
|
||||
path?: string;
|
||||
sha256?: string;
|
||||
url?: string;
|
||||
args?: string[];
|
||||
egress?: string[];
|
||||
env?: string[];
|
||||
settings?: Record<string, string>;
|
||||
credentials?: Record<string, string>;
|
||||
tools?: unknown[];
|
||||
}
|
||||
|
||||
export const acceptExtension = (contract: ExtensionContract, name: string, body: AcceptRequest) =>
|
||||
send<{ name: string; state: string }>("PUT", `/api/${extensionPath[contract]}/${encodeURIComponent(name)}`, body);
|
||||
|
||||
export const removeExtension = (contract: ExtensionContract, name: string) =>
|
||||
send<{ name: string; state: string }>("DELETE", `/api/${extensionPath[contract]}/${encodeURIComponent(name)}`);
|
||||
|
||||
export const listCredentials = (signal?: AbortSignal) => get<CredentialView[]>("/api/credentials", signal);
|
||||
export const getCredential = (name: string, signal?: AbortSignal) =>
|
||||
get<CredentialView>(`/api/credentials/${encodeURIComponent(name)}`, signal);
|
||||
export const saveCredential = (name: string, kind: CredentialView["kind"], fields: Record<string, CredentialField>) =>
|
||||
send<{ name: string; kind: string; restarted: string[] }>("PUT", `/api/credentials/${encodeURIComponent(name)}`, { kind, fields });
|
||||
|
||||
export const getAgentModel = (signal?: AbortSignal) => get<AgentModel>("/api/settings/agent-model", signal);
|
||||
export const saveAgentModel = (model: AgentModel) =>
|
||||
send<AgentModel>("PUT", "/api/settings/agent-model", model);
|
||||
export const testAgentModel = (model: AgentModel) =>
|
||||
send<{ model: string; answer: string }>("POST", "/api/settings/agent-model/test", model);
|
||||
|
||||
export const getBootstrap = (signal?: AbortSignal) => get<BootstrapView>("/api/system/bootstrap", signal);
|
||||
export const rotateAdminToken = () => send<{ token: string }>("POST", "/api/admin/token");
|
||||
|
||||
export const listSources = (signal?: AbortSignal) => get<SourceView[]>("/api/sources", signal);
|
||||
export const putSource = (name: string, connector: string) =>
|
||||
send<{ source: string; token: string; url: string }>("PUT", `/api/sources/${encodeURIComponent(name)}`, { connector });
|
||||
export const putKeyFields = (name: string, paths: string[]) =>
|
||||
send<{ key_fields: string[] }>("PUT", `/api/sources/${encodeURIComponent(name)}/key-fields`, { paths });
|
||||
|
||||
export const listTriggers = (signal?: AbortSignal) => get<TriggerView[]>("/api/triggers", signal);
|
||||
export const saveTrigger = (
|
||||
name: string,
|
||||
trigger: { source: string; event_type: string; filter: Record<string, string>; workflow: string; disabled: boolean; every?: string },
|
||||
) => send<{ trigger: string }>("PUT", `/api/triggers/${encodeURIComponent(name)}`, trigger);
|
||||
|
||||
export async function listEvents(
|
||||
params: { source?: string; type?: string; matched?: boolean; limit?: number },
|
||||
signal?: AbortSignal,
|
||||
): Promise<EventRow[]> {
|
||||
const query = new URLSearchParams();
|
||||
if (params.source) query.set("source", params.source);
|
||||
if (params.type) query.set("type", params.type);
|
||||
if (params.matched !== undefined) query.set("matched", String(params.matched));
|
||||
if (params.limit) query.set("limit", String(params.limit));
|
||||
return get<EventRow[]>(`/api/events?${query.toString()}`, signal);
|
||||
}
|
||||
|
||||
export const getEvent = (id: string, signal?: AbortSignal) =>
|
||||
get<EventDetail>(`/api/events/${encodeURIComponent(id)}`, signal);
|
||||
|
||||
export const listJudges = (signal?: AbortSignal) => get<JudgeControl[]>("/api/controls/judges", signal);
|
||||
export const runTrail = (id: string, signal?: AbortSignal) => get<Trail>(`/api/runs/${encodeURIComponent(id)}`, signal);
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,6 +11,11 @@ export default createRouter({
|
||||
{ path: "/classes/:id", name: "class", component: () => import("./ClassView.vue"), props: true },
|
||||
{ path: "/people", name: "people", component: () => import("./PeopleView.vue") },
|
||||
{ path: "/controls", name: "controls", component: () => import("./ControlsView.vue") },
|
||||
{ path: "/extensions", name: "extensions", component: () => import("./ExtensionsView.vue") },
|
||||
{ path: "/sources", name: "sources", component: () => import("./SourcesView.vue") },
|
||||
{ path: "/triggers", name: "triggers", component: () => import("./TriggersView.vue") },
|
||||
{ path: "/events", name: "events", component: () => import("./EventsView.vue") },
|
||||
{ path: "/credentials", name: "credentials", component: () => import("./CredentialsView.vue") },
|
||||
{ path: "/settings", name: "settings", component: () => import("./SettingsView.vue") },
|
||||
{ path: "/runs/:id", name: "run", component: () => import("./RunView.vue"), props: true },
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user