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
2 changes: 1 addition & 1 deletion apps/fe/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,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. 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`.
- 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). **Check it in TEE Explorer (#277, `ExplorerLink` in `ProofDialog.tsx`):** pasting "Copy the proof" into proof.t16z.com answered "The quote is invalid", and the Explorer has no prefill URL and no CORS, so the click opens a blank tab at once (popup blockers allow only that), calls `POST /runs/{runId}/proof/tee-explorer` (the backend uploads the quote, #279) and sends the tab to the report, which already reads VERIFIED; only a `https://proof.t16z.com/reports/` link is followed (`explorerReportUrl`), anything else or a failure lands on the Explorer's paste page with a line to paste the Intel quote. Checked in Chrome on a local stack (12 Nov): one click, one tab, a VERIFIED report. Built by Axel's request while Ancung owns the FE. 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
3 changes: 2 additions & 1 deletion apps/fe/src/modules/chat/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +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"
import type { ExplorerReports, 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 @@ -24,6 +24,7 @@ export const chatApi = {
/** 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`),
teeExplorer: (runId: string) => api<ExplorerReports>(`/runs/${enc(runId)}/proof/tee-explorer`, { method: "POST", body: {} }),
cancel: (runId: string) => api<unknown>(`/runs/${enc(runId)}/cancel`, { method: "POST", body: {} }),
resume: (
runId: string,
Expand Down
46 changes: 38 additions & 8 deletions apps/fe/src/modules/runs/components/ProofDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { useQuery } from "@tanstack/react-query"
import { ArrowUpRightIcon, CheckIcon, CircleAlertIcon } from "lucide-react"
import type { ReactNode } from "react"
import { useState, type ReactNode } from "react"
import { cn } from "cn"
import { CopyButton } from "@/components/elements/CopyButton"
import { ResponsiveDialog } from "@/components/elements/ResponsiveDialog"
Expand All @@ -11,7 +11,7 @@ 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"
import { checkedSteps, explorerReportUrl, replyProof, shortHex, tcbText, TEE_EXPLORER_URL, type Proof } from "@/modules/runs/data/proof"

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

Expand Down Expand Up @@ -57,14 +57,14 @@ export function ProofDialog({ runId, open, onOpenChange }: { runId: string; open
: "Could not load the proof. Please try again later."}
</p>
) : entry ? (
<ProofBody proof={entry.proof} model={entry.model} />
<ProofBody runId={runId} proof={entry.proof} model={entry.model} />
) : null}
</div>
</ResponsiveDialog>
)
}

function ProofBody({ proof, model }: { proof: Proof; model: string | null }) {
function ProofBody({ runId, proof, model }: { runId: string; 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)
Expand Down Expand Up @@ -128,10 +128,7 @@ function ProofBody({ proof, model }: { proof: Proof; model: string | null }) {
</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>
<ExplorerLink runId={runId} />
<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" />
Expand All @@ -142,6 +139,39 @@ function ProofBody({ proof, model }: { proof: Proof; model: string | null }) {
)
}

/**
* "Check it in TEE Explorer" (#277): opens the run's report on proof.t16z.com, already verified, so
* nobody pastes a quote (pasting the whole proof answered "The quote is invalid"). The tab opens
* on the click itself, or popup blockers stop it, and goes to the report once the backend has
* uploaded the quote. If that fails, the tab shows the Explorer's paste page as before.
*/
function ExplorerLink({ runId }: { runId: string }) {
const [state, setState] = useState<"idle" | "opening" | "failed">("idle")
const open = async () => {
const tab = window.open("", "_blank")
if (tab) tab.opener = null
setState("opening")
let url: string | null = null
try {
url = explorerReportUrl(await chatApi.teeExplorer(runId))
} catch {
url = null
}
if (tab) tab.location.href = url ?? TEE_EXPLORER_URL
else window.open(url ?? TEE_EXPLORER_URL, "_blank", "noopener,noreferrer")
setState(url ? "idle" : "failed")
}
return (
<span className="flex flex-col gap-0.5">
<button type="button" onClick={open} disabled={state === "opening"} className="flex items-center gap-1 text-foreground hover:underline disabled:opacity-60">
{state === "opening" ? "Opening TEE Explorer…" : "Check it in TEE Explorer"}
<ArrowUpRightIcon className="size-3.5" />
</button>
{state === "failed" && <span className="text-xs font-normal text-muted-foreground">Could not check it automatically. Paste the Intel quote there.</span>}
</span>
)
}

function Section({ title, children }: { title: string; children: ReactNode }) {
return (
<section className="flex flex-col gap-2">
Expand Down
12 changes: 12 additions & 0 deletions apps/fe/src/modules/runs/data/proof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ export type RunProofs = { runId: string; proofs: { seq: number; model: string |

export const TEE_EXPLORER_URL = "https://proof.t16z.com"

/**
* The run's Intel quote(s) checked by Phala's TEE Explorer (#277): the backend uploads them
* (`POST /runs/{runId}/proof/tee-explorer`), since the Explorer has no prefill URL and no CORS.
*/
export type ExplorerReports = { runId: string; reports: { attestation: string; kind: string; url: string; verified: boolean }[] }

/** The report to open: the gateway's first (the one the badge rests on), only a link on the Explorer itself. */
export function explorerReportUrl(r: ExplorerReports | undefined): string | null {
const url = r?.reports[0]?.url
return url && url.startsWith(`${TEE_EXPLORER_URL}/reports/`) ? url : null
}

/** The reply's proof: a run paused for approval has one per part, and the last is the reply's. */
export const replyProof = (r: RunProofs | undefined) => r?.proofs.at(-1) ?? null

Expand Down
13 changes: 13 additions & 0 deletions apps/fe/tests/proof.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,16 @@ describe("the proof behind the badge (#254)", () => {
expect(shortHex("0x1234567890abcdef1234")).toBe("0x1234…ef1234")
})
})

describe("TEE Explorer report (#277)", () => {
const report = (url: string) => ({ runId: "r", reports: [{ attestation: "gateway:0xabc", kind: "gateway", url, verified: true }] })

it("opens the report the backend uploaded, and only a link on the Explorer itself", async () => {
const { explorerReportUrl } = await import("@/modules/runs/data/proof")
expect(explorerReportUrl(report("https://proof.t16z.com/reports/9618de8a"))).toBe("https://proof.t16z.com/reports/9618de8a")
expect(explorerReportUrl(report("https://evil.example/reports/9618de8a"))).toBeNull()
expect(explorerReportUrl(report("https://proof.t16z.com.evil.example/reports/x"))).toBeNull()
expect(explorerReportUrl({ runId: "r", reports: [] })).toBeNull()
expect(explorerReportUrl(undefined)).toBeNull()
})
})
Loading