import { h } from "preact";
import { useState, useEffect } from "preact/hooks";
import "./settings.css";
import { api } from "../base/api.jsx";
import { statusKind, statusLabel } from "../base/task-meta.jsx";
import { Pill } from "../base/pill.jsx";
import { Row } from "./config-row.jsx";
import { UpdateStatusCard } from "./update-status.jsx";
import { UpdateActionsCard, DangerousActionsCard } from "./operator-cards.jsx";
function Empty({ title, detail }) {
return (
{title}
{detail &&
{detail}
}
);
}
function Section({ title, sub, children }) {
return (
);
}
function ProvenanceCard({ origins }) {
if (!origins?.length) return (
);
return (
{origins.map((origin, i) => (
))}
);
}
function roleButtonClass(kind) {
return kind === "quiet" ? "btn-quiet" : kind === "danger" ? "btn-danger" : "";
}
function LifecycleCard({ data, error }) {
if (error) {
return (
);
}
const statuses = data?.statuses || [];
const actions = data?.actions || [];
return (
Statuses
{statuses.length ? (
{statuses.map(s => {
const label = s.label ?? statusLabel(s.id);
const kind = s.kind ?? statusKind(s.id);
return (
);
})}
) : (
)}
Actions
{actions.length ? (
{actions.map(a => {
const label = a.label ?? a.id;
const cls = roleButtonClass(a.kind);
return (
{a.id}
{label}
);
})}
) : (
)}
);
}
function RepoBoolCell({ r, field, onSaved, editable = true }) {
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);
const [checked, setChecked] = useState(!!r[field]);
const handleChange = async (e) => {
const next = e.target.checked;
setChecked(next);
setLoading(true);
setError(null);
try {
await api.configRepoUpdate(r.owner, r.name, field, next);
onSaved?.();
} catch (err) {
setChecked(!next);
setError(String(err.message || err));
} finally {
setLoading(false);
}
};
if (!editable) {
return {checked ? "yes" : "no"} ;
}
return (
{error && {error} }
);
}
function RepoIntCell({ r, field, onSaved, editable = true }) {
const [val, setVal] = useState(String(r[field] ?? 0));
const [error, setError] = useState(null);
const [loading, setLoading] = useState(false);
const commit = async () => {
const n = parseInt(val, 10);
if (Number.isNaN(n)) {
setError("Enter a whole number");
return;
}
setLoading(true);
setError(null);
try {
await api.configRepoUpdate(r.owner, r.name, field, n);
onSaved?.();
} catch (err) {
setError(String(err.message || err));
} finally {
setLoading(false);
}
};
const handleKeyDown = (e) => {
if (e.key === "Enter") {
e.preventDefault();
e.target.blur();
}
};
if (!editable) {
return {val} ;
}
return (
setVal(e.target.value)}
onBlur={commit}
onKeyDown={handleKeyDown}
disabled={loading}
/>
{error && {error} }
);
}
// editable is false in a process that only renders a published
// configuration snapshot: its PATCH routes answer 503, so the cells are
// values rather than controls (archie-core-ymut).
export function RepositoriesCard({ repos, onSaved, editable = true }) {
if (!repos?.length) {
return (
);
}
const gateSummary = (gate) => {
if (!gate?.length) return "—";
return gate.map((cmd) => cmd.join(" ")).join(" → ");
};
return (
Repository Base branch Ecosystem Quality gate Protected paths Concurrent Max retries Self-review
{repos.map((r, i) => (
{r.owner}/{r.name}
{r.base}
{r.ecosystem || "go"}
{gateSummary(r.gate)}
{r.protect?.length ? r.protect.join(", ") : "—"}
))}
);
}
function roleLabel(role) {
if (!role) return "Unknown role";
return role.charAt(0).toUpperCase() + role.slice(1).replace(/_/g, " ");
}
function ModelsAndProvidersCard({ models, providers }) {
const modelEntries = Object.entries(models || {});
const providerEntries = Object.entries(providers || {});
return (
Model roles
{modelEntries.length ? (
{modelEntries.map(([role, ref]) => (
))}
) : (
)}
Providers
{providerEntries.length ? (
Provider Class Base URL API key env var Status
{providerEntries.map(([name, p]) => (
{name}
{p.class}
{p.base_url || "default"}
{p.api_key_env || "—"}
{p.configured ? : }
))}
) : (
)}
);
}
function SettingsApp() {
const [cfg, setCfg] = useState(null);
const [cfgError, setCfgError] = useState(null);
const [versionData, setVersionData] = useState(null);
const [versionError, setVersionError] = useState(null);
const [versionMissing, setVersionMissing] = useState(false);
const [lifecycleData, setLifecycleData] = useState(null);
const [lifecycleError, setLifecycleError] = useState(null);
// Update actions and dangerous-action approvals, rehomed from the chat panel
// (archie-core-tf20). Both degrade to absent rather than to an error banner:
// a deployment that does not wire them should show nothing, not a failure.
const [updateData, setUpdateData] = useState(null);
const [dangerousData, setDangerousData] = useState(null);
const loadAll = () => {
loadCfg();
loadVersion();
loadLifecycle();
loadUpdate();
loadDangerous();
};
const loadUpdate = async () => {
try {
setUpdateData(await api.chatUpdate());
} catch (err) {
setUpdateData(err?.status === 501 ? null : { error: String(err.message || err) });
}
};
const loadDangerous = async () => {
try {
setDangerousData(await api.chatDangerous());
} catch (err) {
setDangerousData(err?.status === 501 ? null : { error: String(err.message || err) });
}
};
const deferUpdate = async (snapshot) => {
await api.chatUpdateDefer(snapshot);
await loadUpdate();
};
const installUpdate = async (snapshot) => {
await api.chatUpdateInstall(snapshot);
await loadUpdate();
};
const requestDangerous = async (kind, spec) => {
await api.chatDangerousRequest(kind, spec);
await loadDangerous();
};
const decideDangerous = async (id, decision) => {
await api.chatDangerousDecision(id, decision);
await loadDangerous();
};
const loadCfg = async () => {
try {
const data = await api.config();
setCfg(data);
setCfgError(null);
} catch (err) {
setCfgError(String(err.message || err));
}
};
const loadVersion = async () => {
try {
const data = await api.version();
setVersionData(data?.components || []);
setVersionError(null);
setVersionMissing(false);
} catch (err) {
if (err?.status === 501) {
setVersionMissing(true);
} else {
setVersionError(String(err.message || err));
}
}
};
const loadLifecycle = async () => {
try {
const data = await api.taskMeta();
setLifecycleData(data);
setLifecycleError(null);
} catch (err) {
setLifecycleError(String(err.message || err));
}
};
useEffect(() => {
loadAll();
}, []);
return (
Configuration
What archied is actually running with right now.
Refresh
{/* A 501 is a deployment that did not wire update checking, which is a
legitimate state and a different thing from a broken one. Saying so
once here covers the absent UpdateActionsCard below too. */}
{versionMissing ? (
Update status
Not configured on this deployment, so there is nothing to check against.
) : versionError ? (
) : versionData ? (
) : null}
{updateData && (
)}
{dangerousData && (
)}
{cfgError ? (
) : !cfg || Object.keys(cfg).length === 0 ? (
) : (
<>
{cfg.reload?.overlay_unavailable && (
The runtime config overlay is not in effect: {cfg.reload.overlay_unavailable}
)}
{cfg.reload?.last_error && (
The last config reload failed; the running config is unchanged: {cfg.reload.last_error}
)}
{(cfg.schema || []).map((s, i) => {
const rows = s.fields.filter(f => f.type !== "structured");
if (!rows.length) return null;
return (
);
})}
>
)}
);
}
export function settingsPage(query) {
return ;
}