One shot per chat, fired at the first turn's onFinish: the session's topic (its only typed message) is embedded as an EmbeddingGemma retrieval query; the semantically closest graph propositions are selected under the session's token budget (pure budget, no similarity threshold — the decided doctrine) and delivered as a marker-only steer through the wake pipeline, queuing behind pending questions like every sub-agent result. - contracts: ChatSettings.graphContextTokens (default 1024, max 4096, step 128, 0 = off); GraphContextData + graphContextText; the graph-context JobKind + buildGraphContextSteer (id steer_ctx_<chatId>) - core/graph-context.ts: brute-force cosine top-K, greedy chars/4 fill under budget, most-recent UnderstandingLevel fold, count cap 64, parse-don't-cast at the marker seam - server: embedQuery (role-asymmetric query format, same warm singleton — vector-space parity by construction); the runner (startGraphContext- Injection one-shot gates; runGraphContextJob validates ledger parity); wake branches (chatIdOf/jobIdOf, finalizeJob done, recoverStaleJobs re-deliver or contextRespawn); abortJob kills context jobs SILENTLY (nothing was promised in the lesson); turn-service trigger seam - adapter: data-graph-context flattens to the canonical block (malformed parts have no model face) - UI: the budget slider (home dock + /chat/new draft, the session-data strip); the quiet SystemLine "~537 · 10 propositions"; dock kind "Knowledge context"; model-picker PUT now spreads settings (a model pick can no longer clear the sibling override) Live-smoked end to end on the real embedder + real GLM: seeded ledger (10 propositions), session on "modal logic: possible worlds and the necessity box" — job in the dock, queued behind the prober's question, delivered on the answer, SystemLine in the transcript, wake turn reads the block and continues the probe. Gates: tsc, lint, 459/459, build.
78 lines
2.9 KiB
TypeScript
78 lines
2.9 KiB
TypeScript
"use client";
|
|
|
|
import { useContext } from "react";
|
|
import { CheckIcon, XIcon } from "lucide-react";
|
|
import { JobsContext } from "@/components/jobs-context";
|
|
import type { JobKind, JobRecord } from "@/src/core";
|
|
|
|
/**
|
|
* The dispatch card (contracts.ts "THE ASYNC PROTOCOL" §4): the tool-call
|
|
* box for a background sub-agent. The tool part's output is the FIRE-AND-
|
|
* FORGET ACK (a string) — never the result. Live status comes from the
|
|
* central jobs poll via JobsContext, matched by toolCallId:
|
|
*
|
|
* job unknown → "dispatched" pulse (the poll hasn't seen it yet)
|
|
* running → live activity card (activity line + elapsed)
|
|
* done/error → quiet one-liner ("delivered" / "failed") — the artifact
|
|
* itself arrives in the steer message right below, so the
|
|
* box must not duplicate it.
|
|
*/
|
|
const KIND_LABEL: Record<JobKind, string> = {
|
|
research: "Research agent",
|
|
demo: "Demo agent",
|
|
visual: "Figure agent",
|
|
// The injection is server-initiated — it has no tool part, so never a
|
|
// dispatch card. The entry exists only for the exhaustive record.
|
|
"graph-context": "Knowledge context",
|
|
};
|
|
|
|
export function DispatchCard({ toolCallId, kind }: { toolCallId: string; kind: JobKind }) {
|
|
const jobs = useContext(JobsContext);
|
|
const job = jobs.find((j) => j.toolCallId === toolCallId) ?? null;
|
|
const label = KIND_LABEL[kind];
|
|
|
|
if (!job || job.status === "running") {
|
|
return <DispatchActivityCard job={job} label={label} />;
|
|
}
|
|
const failed = job.status === "error";
|
|
return (
|
|
<div
|
|
className="flex items-center gap-2 text-xs text-muted-foreground"
|
|
data-testid="dispatch-settled"
|
|
>
|
|
{failed ? <XIcon className="size-3.5 text-red-500" /> : <CheckIcon className="size-3.5" />}
|
|
<span className="font-medium uppercase tracking-wide">{label}</span>
|
|
<span>{failed ? "failed" : "delivered"}</span>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function DispatchActivityCard({ job, label }: { job: JobRecord | null; label: string }) {
|
|
// Elapsed from createdAt — jobs appear here only via the poll (post-mount),
|
|
// so no SSR/hydration mismatch.
|
|
const elapsed =
|
|
job && job.createdAt ? Math.max(0, Math.round((Date.now() - Date.parse(job.createdAt)) / 1000)) : null;
|
|
return (
|
|
<div
|
|
className="rounded-xl border bg-card p-4 text-card-foreground"
|
|
data-testid="dispatch-card"
|
|
>
|
|
<div className="flex items-center gap-2 text-xs font-medium uppercase tracking-wide text-muted-foreground">
|
|
<span className="inline-block size-2 animate-pulse rounded-full bg-primary" />
|
|
{label}
|
|
{elapsed !== null && <span className="font-normal">· {elapsed}s</span>}
|
|
</div>
|
|
{job?.activity && (
|
|
<div className="mt-1 truncate text-sm text-muted-foreground" data-testid="dispatch-activity-line">
|
|
{job.activity}
|
|
</div>
|
|
)}
|
|
{!job && (
|
|
<div className="mt-1 text-sm text-muted-foreground" data-testid="dispatch-pending">
|
|
Dispatched…
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|