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
4 changes: 2 additions & 2 deletions apps/fe/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Web app (Next.js App Router + NEAR Connect). Owner: Ancung. Design comes from Na
- Data and state: `@tanstack/react-query` 5.106.1 for all server data (cache, polling, refresh after approve or freeze). **No global state library.** The current Mind's id lives in the URL (`/minds/[mindId]/…`), every screen reads the Mind through the same React Query hook (one fetch, shared cache), and the last used Mind is kept in `localStorage`. One React context holds the chat run in progress so the chat, the live view and the Approvals badge read the same events. Add `zustand` only if that context gets heavy.
- Streams: chat, approve/decline and builder runs are POST + SSE, so `EventSource` can't be used; read the `fetch` body with `eventsource-parser` 4.1.3.
- Forms: `react-hook-form` 7.91.0 + `zod` 4.6.7 + `@hookform/resolvers` 7.0.3 (validate as you type, as in the design).
- Bottom drawers on phones (`ResponsiveDialog`, "Add a block", a Builder block's settings, the live view) share one roomy spacing (Ancung, 11 Nov, after Welcome). `DrawerContent`'s classes go on the outer popup while its children sit in an inner element with no gap, so the spacing between parts lives on a wrapper inside it (`ResponsiveDialog`) or as margins ("Add a block"); a header there is left-aligned (the drawer centres it by default), except Welcome (`centered`). The sizes: 20 px sides, 20 px between parts, 8 px between a title and its text, 12 px between stacked buttons, and at least 24 px at the bottom (more with a home indicator).
- Bottom drawers on phones (`ResponsiveDialog`, "Add a block", a Builder block's settings, the live view) share one roomy spacing (Ancung, 11 Nov, after Welcome). `DrawerContent`'s classes go on the outer popup while its children sit in an inner element with no gap, so the spacing between parts lives on a wrapper inside it (`ResponsiveDialog`) or as margins ("Add a block"); the side padding lives inside too, since that inner element clips, and padding on the outer popup cut the left edge of a title's first letter (Ancung, 11 Nov); a header there is left-aligned (the drawer centres it by default), except Welcome (`centered`). The sizes: 20 px sides, 20 px between parts, 8 px between a title and its text, 12 px between stacked buttons, and at least 24 px at the bottom (more with a home indicator).
- Toasts: `sonner` 2.0.8 (shadcn's). Theme: `next-themes` 0.4.6 (System, Light, Dark from the account menu). Mind replies: `react-markdown` 10.1.0 with `remark-gfm` 4.0.1 (tables, strikethrough, task lists, bare links; added 9 Nov when a reply's table showed as pipes). Wide tables scroll sideways inside the reply. Springs (Penny is ready, freeze, Builder drag): `motion` 14.10.0; everything else is CSS. Thinking indicators (Thinking... and every running step row, by kind of work: `orb` in `TOOLS` (`runs/data/tools.ts`, every tool's words in one list), read by `stepOrb`, reading searching, websites connecting, writing composing, acting working, time and sums solving, memory breathing, waiting for the owner listening): `thinking-orbs` 0.3.2 (MIT, no runtime dependencies; Axel's pick, 10 Nov): `<ThinkingOrb state size={20|64} />`, a dotted canvas orb that follows the `dark` class, freezes with reduced motion and pauses off screen by itself. Only the free states and the 20 and 64 sizes (libraries.dev marks some as Pro).
- Tests: `vitest` 5.1.0 (unit, `tests/*.test.ts`, config `vitest.config.mts`) with a 15 s test timeout (a few tests that import inside themselves timed out at 5 s on Windows beside the dev server), `@playwright/test` 1.65.0 (flows).
- Motion: easing tokens are in `src/styles/globals.css` (`ease-out`, `ease-in-out`, `ease-drawer` utilities; Tailwind only emits them once used). Rules, durations and chat streaming: `design/CLAUDE.md` "Motion (v0.3)". shadcn components keep their own animation classes; set menus and popovers to grow from `--transform-origin` (Base UI provides it) and make exits faster than entries.
Expand Down Expand Up @@ -210,7 +210,7 @@ Imports: `@/*` → `src/*`, `@app/*` → `app/*`. Keep route files in `app/` thi
- **System messages are formal and plain** (Ancung, 10 Nov: toasts and errors sounded too chatty). Toasts get a short standard title ("Key saved", "Funds added", "Could not send your answer") with any detail in the description line. Errors say what failed and what to do: "Could not load the payments. Please try again later.", "No changes were made.", "Check your connection and try again."; no "Couldn't", "Try again in a moment", "Nothing changed; try again" or "Something went wrong on the way". Empty states are plain ("No transactions yet", "No pending approvals"). Product copy from the design (headlines, skill cards, chat intros) keeps its voice. No "·" separators anywhere on screen.
- Never hold or send the backend's API keys or grant tokens in the browser; the FE only talks to `apps/be`.
- Wording: say "policy stored on-chain, enforced in a TEE". A rejected transfer shows `policy_denied` and the rule, never a tx link.
- Verification badge follows `docs/api-contract.md` §4: `gateway_tee` (a normal chat run) shows "Verified via NEAR AI TEE gateway", `model_tee` shows "Verified private (model TEE)", anything else no badge. The badge opens a popover (`runs/components/VerifiedBadge.tsx`, Ancung, 11 Nov, like near.ai/models' "Private TEE" note): what was checked in plain words (a `gateway_tee` step is checked against the gateway TEE's Intel TDX attestation only; NVIDIA (GPU) and Intel (CPU) are named only for `model_tee`, Axel on #255), the model, how many steps with their completion ids to copy (`RunView.proof`, from `run.verified`'s `model` and `completionIds`), and links to docs.near.ai/cloud/verification and the open-source verifier. The signatures and attestation reports themselves need a NEAR AI key the browser doesn't have, so they aren't shown.
- Verification badge follows `docs/api-contract.md` §4: `gateway_tee` (a normal chat run) shows "Verified via NEAR AI TEE gateway", `model_tee` shows "Verified private (model TEE)", anything else no badge. The badge opens a popover (`runs/components/VerifiedBadge.tsx`, Ancung, 11 Nov, like near.ai/models' "Private TEE" note): what was checked in plain words (a `gateway_tee` step is checked against the gateway TEE's Intel TDX attestation only; NVIDIA (GPU) and Intel (CPU) are named only for `model_tee`, Axel on #255), the model, how many steps with their completion ids to copy (`RunView.proof`, from `run.verified`'s `model` and `completionIds`), and links to docs.near.ai/cloud/verification and the open-source verifier. Its actions are one row (Ancung, 11 Nov: a button and two links stacked read as clutter): View proof and "How it's verified"; "Check it yourself" moved into the dialog, and shows in the popover only for a reply without a run id. "View proof" opens `ProofDialog` (#254): `GET /runs/{runId}/proof` (#257), the last entry being the reply's, read when opened; in plain words first: "Signed inside the TEE" (each step's signer against its attestation's, `checkedSteps`), "Hardware checked" (Intel's TCB status in words, NVIDIA's GPU evidence only where it exists, the nonce, when), then "Check it yourself" (copy the Intel quote or the whole proof, TEE Explorer, NEAR AI's verifier). Raw quotes and signatures are only copied, never laid out; signer addresses keep the address font, hashes don't. `404 no_proof` (replies from before #256) says so plainly. Types and helpers in `runs/data/proof.ts`.
- Redacted secrets render as `••••`; never try to unredact.
- Use the event shapes in `docs/api-contract.md` (#7); do not invent fields.
- Visual Builder (#20): save the React Flow `{ nodes, edges }` in the canvas format of `docs/api-contract.md` §2 "Visual Builder workflows" (node types `trigger`, `agent`, `tool`, `http`, `condition`; condition edges use `sourceHandle: "then" | "else"`). Show the engine's `issues` on a 400. Light nodes up from `node.started` / `node.finished` (`node` = your canvas node id).
Expand Down
8 changes: 5 additions & 3 deletions apps/fe/src/components/elements/ResponsiveDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ export function ResponsiveDialog({
return (
<Drawer open={open} onOpenChange={change} showSwipeHandle>
{/* Roomy on phones (Ancung, 11 Nov: the drawers felt cramped), the same spacing as Welcome. */}
<DrawerContent className="gap-5 px-5 pt-2 pb-[max(1.5rem,env(safe-area-inset-bottom))]">
<DrawerContent className="gap-5 pt-2 pb-[max(1.5rem,env(safe-area-inset-bottom))]">
{/* The spacing lives on this wrapper: DrawerContent's own classes go on the outer popup,
and its children sit in an inner element with no gap, so a header touched what came
after it (Telegram's steps, found in the phone check, 11 Nov). */}
<div className="flex min-h-0 flex-col gap-5">
after it (Telegram's steps, found in the phone check, 11 Nov). The side padding is here
too, inside that element's overflow-hidden: on the outer popup it cut off the left edge
of a title's first letter (the "T" of "The proof…", Ancung, 11 Nov). */}
<div className="flex min-h-0 flex-col gap-5 px-5">
{top}
<DrawerHeader
className={cn(
Expand Down
1 change: 1 addition & 0 deletions apps/fe/src/lib/queryKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const mindKeys = {
export const chatKeys = {
thread: (mindId: string, threadId: string) => ["minds", mindId, "threads", threadId] as const,
run: (runId: string) => ["runs", runId] as const,
proof: (runId: string) => ["runs", runId, "proof"] as const,
/** The user message that started a run (Approvals' "You asked"). */
asked: (runId: string) => ["runs", runId, "asked"] as const,
}
Expand Down
7 changes: 4 additions & 3 deletions apps/fe/src/modules/builder/components/AddBlockSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ export function AddBlockSheet({ at, line, onClose, onPick }: { at: Place | null;
return (
// A drawer from the bottom you can swipe away, like the live view on phones (Ancung, 10 Nov).
<Drawer open={at !== null} onOpenChange={(open) => !open && onClose()} showSwipeHandle>
<DrawerContent className="gap-4 px-5 pt-2 pb-[max(1.5rem,env(safe-area-inset-bottom))]">
<DrawerContent className="gap-4 pt-2 pb-[max(1.5rem,env(safe-area-inset-bottom))]">
{/* A margin, not the drawer's gap: its children sit in an inner element without one. */}
<DrawerHeader className="mb-4 gap-1.5 p-0 text-left group-data-[swipe-axis=y]/drawer-popup:text-left">
<DrawerHeader className="mb-4 gap-1.5 px-5 py-0 text-left group-data-[swipe-axis=y]/drawer-popup:text-left">
<DrawerTitle>Add a block</DrawerTitle>
<DrawerDescription>{where}</DrawerDescription>
</DrawerHeader>
<ul className="flex flex-col gap-2 overflow-y-auto">
{/* Side padding inside the drawer's clipped content, not on its outer popup (it cut letters). */}
<ul className="flex flex-col gap-2 overflow-y-auto px-5">
{ADD_KINDS.map((kind) => {
const { tone, Icon, title, long } = KIND_META[kind]
const why = off(kind)
Expand Down
3 changes: 3 additions & 0 deletions apps/fe/src/modules/chat/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { api } from "@/lib/api"
import { ownerTimeZone, stream } from "@/lib/stream"
import type { RunEvent } from "@/modules/runs/data/events"
import type { RunProofs } from "@/modules/runs/data/proof"

// Chat, runs and approvals: docs/api-contract.md §7. Chat and approve/decline answer with an SSE
// stream of §3 events (`stream` in src/lib/stream.ts).
Expand All @@ -21,6 +22,8 @@ export const chatApi = {
send: (mindId: string, body: { message: string; threadId?: string }, onEvent: (e: RunEvent) => void, signal?: AbortSignal) =>
stream<RunEvent>(`/minds/${enc(mindId)}/chat`, { ...body, ...ownerTimeZone() }, onEvent, signal),
/** Stop a run that is still streaming (#121). Its stream then ends with run.finished "canceled". */
/** The proof behind a reply's verified badge (#254, #257); `404 no_proof` when none was kept. */
runProof: (runId: string) => api<RunProofs>(`/runs/${enc(runId)}/proof`),
cancel: (runId: string) => api<unknown>(`/runs/${enc(runId)}/cancel`, { method: "POST", body: {} }),
resume: (
runId: string,
Expand Down
2 changes: 1 addition & 1 deletion apps/fe/src/modules/chat/components/TurnView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export function TurnView({
{working && <Working name={name} />}
{!live && view.text && (
<div className="flex flex-wrap items-center gap-2">
{view.verified && <VerifiedBadge level={view.verified} proof={view.proof} />}
{view.verified && <VerifiedBadge level={view.verified} proof={view.proof} runId={view.runId} />}
{view.at && <span className="text-xs text-muted-foreground">{clockTime(view.at)}</span>}
{/* Actions under a finished reply, like Claude (Ancung, 10 Nov). */}
<span className="flex items-center gap-0.5">
Expand Down
170 changes: 170 additions & 0 deletions apps/fe/src/modules/runs/components/ProofDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
"use client"

import { useQuery } from "@tanstack/react-query"
import { ArrowUpRightIcon, CheckIcon, CircleAlertIcon } from "lucide-react"
import type { ReactNode } from "react"
import { cn } from "cn"
import { CopyButton } from "@/components/elements/CopyButton"
import { ResponsiveDialog } from "@/components/elements/ResponsiveDialog"
import { Button } from "@/components/ui/button"
import { Skeleton } from "@/components/ui/skeleton"
import { isApiCode } from "@/lib/api"
import { chatKeys } from "@/lib/queryKeys"
import { chatApi } from "@/modules/chat/api"
import { checkedSteps, replyProof, shortHex, tcbText, TEE_EXPLORER_URL, type Proof } from "@/modules/runs/data/proof"

const VERIFIER_URL = "https://github.com/nearai/nearai-cloud-verifier"

/**
* "View proof" (#254): the evidence behind a reply's verified badge, in plain words first. Each
* step was signed by the attested key; the hardware's own report (Intel, and NVIDIA where the
* model itself runs in the TEE); then the raw pieces to copy and the public checkers. Raw quotes
* and signatures are never laid out on screen, only copied. Read when opened
* (`GET /runs/{runId}/proof`, #257); the last entry is the reply's.
*/
export function ProofDialog({ runId, open, onOpenChange }: { runId: string; open: boolean; onOpenChange: (open: boolean) => void }) {
const proofs = useQuery({
queryKey: chatKeys.proof(runId),
queryFn: () => chatApi.runProof(runId),
enabled: open,
staleTime: Infinity,
retry: (count, err) => !isApiCode(err, "no_proof") && !isApiCode(err, "run_not_found") && count < 2,
})
const entry = replyProof(proofs.data)

return (
<ResponsiveDialog
open={open}
onOpenChange={onOpenChange}
title="The proof behind this reply"
description="What HelloNear checked before showing the badge. You can check the same evidence yourself."
footer={
<Button variant="outline" onClick={() => onOpenChange(false)}>
Close
</Button>
}
>
<div className="flex max-h-[60dvh] flex-col gap-5 overflow-y-auto md:max-h-[65vh]">
{proofs.isPending ? (
<div className="flex flex-col gap-2">
<Skeleton className="h-16 w-full rounded-md" />
<Skeleton className="h-24 w-full rounded-md" />
</div>
) : proofs.error ? (
<p className="text-[13px] text-muted-foreground">
{isApiCode(proofs.error, "no_proof")
? "No proof was kept for this reply. Replies from before 11 Nov don't have one."
: "Could not load the proof. Please try again later."}
</p>
) : entry ? (
<ProofBody proof={entry.proof} model={entry.model} />
) : null}
</div>
</ResponsiveDialog>
)
}

function ProofBody({ proof, model }: { proof: Proof; model: string | null }) {
const steps = checkedSteps(proof)
const attestations = Object.values(proof.attestations)
const allMatch = steps.length > 0 && steps.every((s) => s.matches)
const checkedAt = new Date(proof.checkedAt)
const raw = JSON.stringify(proof, null, 2)

return (
<>
<Section title="Signed inside the TEE">
<Line ok={allMatch}>
{allMatch
? `All ${steps.length} ${steps.length === 1 ? "step was" : "steps were"} signed by the key the hardware vouches for.`
: "A step's signer doesn't match the attested key."}
</Line>
<ul className="flex flex-col gap-1.5">
{steps.map(({ step, matches }) => (
<li key={step.id} className="flex items-center justify-between gap-3 text-[13px]">
<span className="min-w-0 truncate text-muted-foreground">
{step.signatureKind === "provider_tee" ? "Model step" : "Gateway step"}, signed by{" "}
<span className="font-mono text-foreground">{shortHex(step.signer.address)}</span>
</span>
{matches ? <CheckIcon aria-label="Matches" className="size-4 shrink-0 text-success" /> : <CircleAlertIcon aria-label="Doesn't match" className="size-4 shrink-0 text-danger" />}
</li>
))}
</ul>
<p className="text-xs text-muted-foreground">
Only hashes of the messages were signed, never the conversation.{model ? ` Model: ${model.split("/").pop()}.` : ""}
</p>
</Section>

<Section title="Hardware checked">
{attestations.map((a) => {
const tcb = tcbText(a.tcbStatus)
return (
<div key={`${a.kind}:${a.signer.address}`} className="flex flex-col gap-1.5">
<p className="text-[13px] font-medium text-foreground">{a.kind === "model" ? "The model's TEE" : "NEAR AI's gateway TEE"}</p>
<Line ok={tcb.ok}>Intel TDX report: {tcb.text.toLowerCase()}</Line>
{a.gpuEvidence && <Line ok>NVIDIA GPU evidence included</Line>}
<p className="text-xs text-muted-foreground">
Fresh for this check (nonce {shortHex(a.nonce)})
</p>
</div>
)
})}
{!Number.isNaN(checkedAt.getTime()) && (
<p className="text-xs text-muted-foreground">
Checked {checkedAt.toLocaleString("en-GB", { day: "numeric", month: "short", hour: "2-digit", minute: "2-digit" })}
</p>
)}
</Section>

<Section title="Check it yourself">
<div className="flex flex-col gap-2">
{attestations[0] && (
<Row label="Intel quote">
<CopyButton text={() => attestations[0].intelQuote} label="Copy the Intel quote" showLabel />
</Row>
)}
<Row label="The whole proof">
<CopyButton text={() => raw} label="Copy the proof" showLabel />
</Row>
</div>
<div className="flex flex-wrap gap-x-4 gap-y-1.5 text-[13px] font-medium">
<a href={TEE_EXPLORER_URL} target="_blank" rel="noopener noreferrer" className="flex items-center gap-1 text-foreground hover:underline">
Paste the quote in TEE Explorer
<ArrowUpRightIcon className="size-3.5" />
</a>
<a href={VERIFIER_URL} target="_blank" rel="noopener noreferrer" className="flex items-center gap-1 text-foreground hover:underline">
NEAR AI&apos;s verifier
<ArrowUpRightIcon className="size-3.5" />
</a>
</div>
</Section>
</>
)
}

function Section({ title, children }: { title: string; children: ReactNode }) {
return (
<section className="flex flex-col gap-2">
<h3 className="text-sm font-semibold text-foreground">{title}</h3>
{children}
</section>
)
}

function Line({ ok, children }: { ok: boolean; children: ReactNode }) {
return (
<p className={cn("flex items-start gap-2 text-[13px]", ok ? "text-foreground" : "text-danger")}>
{ok ? <CheckIcon className="mt-0.5 size-4 shrink-0 text-success" /> : <CircleAlertIcon className="mt-0.5 size-4 shrink-0" />}
{children}
</p>
)
}

function Row({ label, children }: { label: string; children: ReactNode }) {
return (
<div className="flex items-center justify-between gap-3 text-[13px]">
<span className="text-muted-foreground">{label}</span>
{children}
</div>
)
}
Loading
Loading