Refactor channels, settings, logs, and memory to use Preact components
This commit is contained in:
1 parent
09d85149ee
commit
4e189b605e
6 files changed
+951
-837
No files matched your search
+105
-89
@@ -1,102 +1,118 @@
|
||||
import { h } from "preact";
|
||||
import { useState, useEffect } from "preact/hooks";
|
||||
import "./memory.css";
|
||||
import { api } from "../base/api.jsx";
|
||||
import { el, empty, mount, pill } from "../base/dom.jsx";
|
||||
import { icon } from "../base/icons.jsx";
|
||||
|
||||
/**
|
||||
* Memory: what Archie can recall, and with what.
|
||||
*
|
||||
* Memory is otherwise invisible -- it is a set of tools handed to the model at
|
||||
* discovery time, so without this page the only way to know what the agent can
|
||||
* remember is to read the provider source.
|
||||
*/
|
||||
export function memoryPage() {
|
||||
const root = el("div");
|
||||
const body = el("div");
|
||||
|
||||
render();
|
||||
load();
|
||||
|
||||
function render() {
|
||||
mount(
|
||||
root,
|
||||
el(
|
||||
"div.page-head",
|
||||
el(
|
||||
"div",
|
||||
el("h1.page-title", "Memory"),
|
||||
el("p.page-sub", "What Archie can recall between conversations, and the tools it uses to do it."),
|
||||
),
|
||||
el("div.page-actions", el("button.btn", { onclick: load }, icon("refresh", { size: 15 }), "Refresh")),
|
||||
),
|
||||
body,
|
||||
);
|
||||
}
|
||||
|
||||
async function load() {
|
||||
mount(body, el("div.card", el("div.mem-loading", "Loading…")));
|
||||
try {
|
||||
const res = await api.memory();
|
||||
if (!res.enabled || !res.providers?.length) {
|
||||
mount(
|
||||
body,
|
||||
el(
|
||||
"div.card",
|
||||
empty(
|
||||
"Memory is not configured",
|
||||
"Without a provider, Archie starts every conversation with no recollection of earlier ones.",
|
||||
),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
mount(body, el("div.grid.grid-2", ...res.providers.map(providerCard)));
|
||||
} catch (err) {
|
||||
mount(body, el("div.card", empty("Cannot read memory providers", String(err.message || err))));
|
||||
}
|
||||
}
|
||||
|
||||
return root;
|
||||
function Pill({ text, kind = "idle" }) {
|
||||
return <span className={`pill pill-${kind}`}>{text}</span>;
|
||||
}
|
||||
|
||||
function providerCard(p) {
|
||||
const tools = p.tools || [];
|
||||
return el(
|
||||
"div.card",
|
||||
el(
|
||||
"div.card-head",
|
||||
el(
|
||||
"div",
|
||||
el("h2.card-title", p.name || "provider"),
|
||||
el("p.card-sub", roleLabel(p.role)),
|
||||
),
|
||||
p.available
|
||||
? pill("ready", "ok")
|
||||
: pill("unavailable", "danger"),
|
||||
),
|
||||
!p.available &&
|
||||
el(
|
||||
"p.mem-warning",
|
||||
"Configured but not usable right now — a required binary or connection may be missing.",
|
||||
),
|
||||
tools.length
|
||||
? el(
|
||||
"ul.mem-tools",
|
||||
...tools.map((t) =>
|
||||
el(
|
||||
"li.mem-tool",
|
||||
el("div.mem-tool-name.mono", t.name),
|
||||
t.description && el("div.mem-tool-desc", t.description),
|
||||
),
|
||||
),
|
||||
)
|
||||
: el("p.mem-warning", "This provider exposes no tools, so the agent cannot use it."),
|
||||
function Empty({ title, detail }) {
|
||||
return (
|
||||
<div className="empty">
|
||||
<div className="empty-title">{title}</div>
|
||||
{detail && <div>{detail}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Plain language: "builtin" and "external" are implementation words.
|
||||
function roleLabel(role) {
|
||||
return role === "external"
|
||||
? "Added by you — an external store Archie was given"
|
||||
: "Built in — always available to Archie";
|
||||
}
|
||||
|
||||
function ProviderCard({ provider: p }) {
|
||||
const tools = p.tools || [];
|
||||
return (
|
||||
<div className="card">
|
||||
<div className="card-head">
|
||||
<div>
|
||||
<h2 className="card-title">{p.name || "provider"}</h2>
|
||||
<p className="card-sub">{roleLabel(p.role)}</p>
|
||||
</div>
|
||||
{p.available ? <Pill text="ready" kind="ok" /> : <Pill text="unavailable" kind="danger" />}
|
||||
</div>
|
||||
{!p.available && (
|
||||
<p className="mem-warning">
|
||||
Configured but not usable right now — a required binary or connection may be missing.
|
||||
</p>
|
||||
)}
|
||||
{tools.length ? (
|
||||
<ul className="mem-tools">
|
||||
{tools.map((t, idx) => (
|
||||
<li className="mem-tool" key={idx}>
|
||||
<div className="mem-tool-name mono">{t.name}</div>
|
||||
{t.description && <div className="mem-tool-desc">{t.description}</div>}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<p className="mem-warning">This provider exposes no tools, so the agent cannot use it.</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function MemoryApp() {
|
||||
const [providers, setProviders] = useState(null);
|
||||
const [enabled, setEnabled] = useState(true);
|
||||
const [error, setError] = useState(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
const load = async () => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const res = await api.memory();
|
||||
setEnabled(!!res.enabled);
|
||||
setProviders(res.providers || []);
|
||||
} catch (err) {
|
||||
setError(String(err.message || err));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="page-head">
|
||||
<div>
|
||||
<h1 className="page-title">Memory</h1>
|
||||
<p className="page-sub">What Archie can recall between conversations, and the tools it uses to do it.</p>
|
||||
</div>
|
||||
<div className="page-actions">
|
||||
<button className="btn" onClick={load}>Refresh</button>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
{loading ? (
|
||||
<div className="card"><div className="mem-loading">Loading…</div></div>
|
||||
) : error ? (
|
||||
<div className="card"><Empty title="Cannot read memory providers" detail={error} /></div>
|
||||
) : !enabled || !providers.length ? (
|
||||
<div className="card">
|
||||
<Empty
|
||||
title="Memory is not configured"
|
||||
detail="Without a provider, Archie starts every conversation with no recollection of earlier ones."
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-2">
|
||||
{providers.map((p, idx) => (
|
||||
<ProviderCard key={idx} provider={p} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function memoryPage(query) {
|
||||
return <MemoryApp query={query} />;
|
||||
}
|
||||
Reference in new issue
Block a user