Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
464 changes: 464 additions & 0 deletions dashboard/e2e/knowledge-import.spec.ts

Large diffs are not rendered by default.

22 changes: 19 additions & 3 deletions dashboard/src/app/knowledge/base-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
import { useState } from "react";
import { Select } from "@/components/select";
import { inputClass, primaryButton, secondaryButton } from "@/components/ui";
import { ReadersEditor } from "@/components/knowledge/readers";
import type { BaseInput, KnowledgeLimits } from "@/lib/knowledge";

// A knowledge base's settings: its name and description, who may read it,
// which agents search it, and whether it is a source of truth.
// A knowledge base's settings: its name and description, who may read it
// (a role, and optionally only some people or roles within it), which agents
// search it (and who gets its results through them), and whether it is a
// source of truth.

/** Said when a base is attached to agents and the page hasn't said who reaches it through them. */
export const AGENT_NOTE = "Everyone who can start an agent run gets results from this base when the agent searches it.";

const ROLE_WORDS: Record<string, string> = {
viewer: "Everyone on the team",
Expand All @@ -30,15 +36,19 @@ export function BaseForm({
submitLabel,
onSubmit,
onCancel,
agentNote,
}: {
initial: BaseInput;
/** Who reaches the base through agents, as the gateway words it. */
agentNote?: string;
limits: KnowledgeLimits | null;
saving: boolean;
submitLabel: string;
onSubmit: (v: BaseInput) => void;
onCancel?: () => void;
}) {
const [v, setV] = useState<BaseInput>(initial);
const [v, setV] = useState<BaseInput>({ ...initial, readers: initial.readers ?? [] });
const attached = v.attach_team || v.agents.length > 0;
const agents = limits?.agents ?? [];
const toggleAgent = (k: string) => setV((x) => ({ ...x, agents: x.agents.includes(k) ? x.agents.filter((a) => a !== k) : [...x.agents, k] }));
return (
Expand Down Expand Up @@ -74,6 +84,7 @@ export function BaseForm({
options={(limits?.read_roles ?? ["viewer", "member", "admin"]).map((r) => ({ value: r, label: ROLE_WORDS[r] ?? r }))}
/>
</label>
<ReadersEditor value={v.readers ?? []} onChange={(readers) => setV({ ...v, readers })} />
<fieldset className="space-y-2">
<legend className="mb-1 text-xs font-medium text-zinc-400">Agents that search it</legend>
<label className="flex items-center gap-2 text-sm text-zinc-200">
Expand All @@ -91,6 +102,11 @@ export function BaseForm({
</div>
)}
<p className="text-xs text-zinc-400">Chat can always use it for people who may read it.</p>
{attached && (
<p className="rounded-lg border border-zinc-800 bg-zinc-950/40 px-3 py-2 text-xs leading-relaxed text-zinc-300" data-testid="agent-access-form-note">
{agentNote || AGENT_NOTE}
</p>
)}
</fieldset>
<label className="flex items-start gap-2 text-sm text-zinc-200">
<input type="checkbox" className="mt-0.5 accent-emerald-500" checked={v.authoritative} onChange={(e) => setV({ ...v, authoritative: e.target.checked })} />
Expand Down
131 changes: 117 additions & 14 deletions dashboard/src/app/knowledge/base/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
fileSize,
itemWord,
knowledge,
readerWords,
rememberReturn,
signInWindow,
uploadProblem,
Expand All @@ -38,6 +39,7 @@ import {
type SourceKind,
} from "@/lib/knowledge";
import { BaseForm } from "../base-form";
import { ARCHIVE_WARNING, archiveProblem } from "@/components/knowledge/import-steps";

// One knowledge base: the apps it stays in sync with (each with whether it
// is up to date and the one thing to do when it isn't), its uploaded files,
Expand Down Expand Up @@ -91,6 +93,8 @@ function BaseView() {
const fileRef = useRef<HTMLInputElement>(null);
const replaceRef = useRef<HTMLInputElement>(null);
const replacing = useRef<string | null>(null);
const archiveRef = useRef<HTMLInputElement>(null);
const archiveFor = useRef<Source | null>(null);

const load = useCallback(() => {
if (!id) return;
Expand Down Expand Up @@ -216,6 +220,32 @@ function BaseView() {
}
};

// A newer export of an archive source: warned first, then the same source
// reads it (unchanged pages kept, changed read again, missing removed).
const pickArchive = async (s: Source) => {
const ok = await confirm({ title: "Upload a newer export?", message: ARCHIVE_WARNING, confirmLabel: "Choose the archive" });
if (!ok) return;
archiveFor.current = s;
archiveRef.current?.click();
};
const replaceArchive = async (s: Source, f: File) => {
const bad = archiveProblem(f, limits);
if (bad) {
toast(bad, "error");
return;
}
try {
const r = await knowledge.startArchive(id, { name: f.name, size: f.size, replace: s.id });
setSources((cur) => cur.map((x) => (x.id === s.id ? r.source : x)));
await uploadToSignedUrl(r.upload, f, () => {});
const done = await knowledge.finishArchive(id, s.id);
setSources((cur) => cur.map((x) => (x.id === s.id ? done.source : x)));
toast("Uploaded. Reading the newer export now.");
} catch (e) {
toast(errorMessage(e, "The archive didn't upload."), "error");
}
};

const sync = async (s: Source) => {
try {
const r = await knowledge.syncSource(id, s.id);
Expand Down Expand Up @@ -413,16 +443,39 @@ function BaseView() {
{base && (
<p className="mt-3 text-sm text-zinc-400" data-testid="read-line">
{READ_SENTENCE[base.read_role] ?? ""}{" "}
{!!base.readers?.length && (
<span data-testid="readers-line">Only {base.readers.map(readerWords).join(", ")}. </span>
)}
{canManage && (
<button type="button" className={linkButton} onClick={() => setSettings(true)}>
Change
</button>
)}
</p>
)}
{base?.agent_access_note && (
<p className="mt-1.5 text-sm text-zinc-400" data-testid="agent-access-note">
{base.agent_access_note}
</p>
)}

{!inPlace && (
<>
<input
ref={archiveRef}
type="file"
className="hidden"
aria-label="Upload a newer export"
data-testid="archive-replace-input"
accept=".zip,application/zip"
onChange={(e) => {
const f = e.target.files?.[0];
e.target.value = "";
const s = archiveFor.current;
archiveFor.current = null;
if (f && s) void replaceArchive(s, f);
}}
/>
<input
ref={fileRef}
type="file"
Expand Down Expand Up @@ -479,14 +532,18 @@ function BaseView() {
key={s.id}
source={s}
canManage={canManage}
limits={limits}
onNewExport={() => pickArchive(s)}
onSync={() => sync(s)}
onFix={() =>
s.error?.action === "sign_in"
? signInAgain(s)
: s.error?.action === "reconnect"
? reconnect(s)
: s.error?.action === "edit"
? setEditing({ source: s, picked: s.selection })
? s.kind === "archive"
? pickArchive(s)
: setEditing({ source: s, picked: s.selection })
: sync(s)
}
onEdit={() => setEditing({ source: s, picked: s.selection })}
Expand Down Expand Up @@ -647,7 +704,9 @@ function BaseView() {
attach_team: base.attach_team,
agents: base.agents,
authoritative: base.authoritative,
readers: base.readers ?? [],
}}
agentNote={base.agent_access_note}
limits={limits}
saving={saving}
submitLabel="Save"
Expand Down Expand Up @@ -701,6 +760,62 @@ function ConnectedCard({
onCheck: () => void;
}) {
const b = base.backend;
const check = canManage && (
<div className="mt-4 space-y-3">
<button type="button" className={buttonClass("secondary", "sm")} onClick={onCheck} disabled={checking} data-testid="check-connection">
{checking ? "Checking…" : "Check connection"}
</button>
{checked?.ok && (
<p className="text-sm text-emerald-300" role="status" data-testid="check-ok">
Searched it just now. The connection works.
</p>
)}
{checked && !checked.ok && <ConnectProblemNote problem={checked.problem} />}
</div>
);
if (b.provider === "mcp") {
return (
<div className="min-w-0 rounded-2xl border border-zinc-800 bg-zinc-900/50 p-5" data-testid="connected-in-place" data-provider="mcp">
<div className="flex items-start gap-3">
<SourceLogo kind="mcp" size="md" />
<div className="min-w-0">
<h3 className="text-sm font-semibold text-zinc-100">{b.label}</h3>
<p className="mt-0.5 text-sm text-emerald-300" data-testid="connected-line">
Connected in place: searched live through {b.server_name}, nothing copied
</p>
</div>
</div>
<dl className="mt-4 grid min-w-0 gap-x-6 gap-y-2 text-sm sm:grid-cols-[auto_1fr]">
<dt className="text-zinc-500">Server</dt>
<dd className="min-w-0 text-zinc-300">{b.server_name}</dd>
<dt className="text-zinc-500">Searches with</dt>
<dd className="min-w-0 text-xs leading-5">
<Code>{b.search_tool}</Code>
{b.fetch_tool && (
<>
{" "}
and reads results with <Code>{b.fetch_tool}</Code>
</>
)}
</dd>
<dt className="text-zinc-500">Whose access</dt>
<dd className="text-zinc-300" data-testid="connected-access">
{b.per_person ? "Each person's own sign-in" : "The team's one connection"}
</dd>
</dl>
{b.per_person ? (
<p className="mt-4 text-sm leading-relaxed text-zinc-400" data-testid="per-person-note">
Each person&apos;s search uses their own sign-in, so they only see what that tool lets them see. Agent runs search as the person who started them; runs nobody started skip it.
</p>
) : (
<p className="mt-4 text-sm leading-relaxed text-zinc-400">
Chat and the agents it is attached to search it whenever they need it, through the team&apos;s connection. Nothing is stored here, and deleting it here changes nothing in the tool.
</p>
)}
{check}
</div>
);
}
return (
<div className="min-w-0 rounded-2xl border border-zinc-800 bg-zinc-900/50 p-5" data-testid="connected-in-place">
<div className="flex items-start gap-3">
Expand Down Expand Up @@ -733,19 +848,7 @@ function ConnectedCard({
<p className="mt-4 text-sm leading-relaxed text-zinc-400">
Chat and the agents it is attached to search it whenever they need it, so documents you add in Bedrock count as soon as Bedrock has them. Nothing is stored here, and deleting it here changes nothing in AWS.
</p>
{canManage && (
<div className="mt-4 space-y-3">
<button type="button" className={buttonClass("secondary", "sm")} onClick={onCheck} disabled={checking} data-testid="check-connection">
{checking ? "Checking…" : "Check connection"}
</button>
{checked?.ok && (
<p className="text-sm text-emerald-300" role="status" data-testid="check-ok">
Searched it just now. The connection works.
</p>
)}
{checked && !checked.ok && <ConnectProblemNote problem={checked.problem} />}
</div>
)}
{check}
</div>
);
}
Expand Down
4 changes: 2 additions & 2 deletions dashboard/src/app/knowledge/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function BaseCard({ b }: { b: Base }) {
const health = baseHealth(b);
const inPlace = connectedInPlace(b);
// Apps first, uploads last; a base connected in place shows where it lives.
const kinds = inPlace ? ["bedrock_kb"] : b.kinds?.length ? [...b.kinds.filter((k) => k !== "upload"), ...b.kinds.filter((k) => k === "upload")] : ["upload"];
const kinds = inPlace ? [b.backend.provider] : b.kinds?.length ? [...b.kinds.filter((k) => k !== "upload"), ...b.kinds.filter((k) => k === "upload")] : ["upload"];
const apps = kinds.filter((k) => k !== "upload");
const size = [(b.synced ?? 0) ? itemWord(apps.length === 1 ? apps[0] : "page", b.synced) : "", b.uploads ? itemWord("upload", b.uploads) : ""].filter(Boolean).join(" and ");
return (
Expand All @@ -180,7 +180,7 @@ function BaseCard({ b }: { b: Base }) {
<h3 className="mt-4 text-base font-semibold text-zinc-100 [overflow-wrap:anywhere]">{b.name}</h3>
{b.description && <p className="mt-1 line-clamp-2 text-sm text-zinc-400">{b.description}</p>}
<div className="mt-auto pt-5">
<p className="text-sm text-zinc-300" data-testid="knowledge-size">{inPlace ? "Connected in place, searched live in AWS" : size || "Nothing in it yet"}</p>
<p className="text-sm text-zinc-300" data-testid="knowledge-size">{inPlace ? (b.backend.provider === "mcp" ? `Connected in place, searched live through ${b.backend.server_name}` : "Connected in place, searched live in AWS") : size || "Nothing in it yet"}</p>
{health && (
<p className="mt-1.5 flex min-w-0 items-center gap-2 text-sm" data-testid="knowledge-health" data-tone={health.tone}>
<StatusDot tone={health.tone === "attention" ? "attention" : health.tone === "success" ? "success" : "live"} live={health.tone === "live"} />
Expand Down
Loading
Loading