World's first open-source enterprise world model.
Rust agent-memorybitemporalgraphragknowledge-baseknowledge-graphllmontologypgvectorpostgresqlragrustself-hostedsemantic-searchtemporal-knowledge-graphworld-model
A token gets a page, and the agent gets the config to use it (#211)
WaylandYang1e7eba3beb47
diff --git a/docs/decisions/0014-identity-from-the-person-scope-from-the-token.md b/docs/decisions/0014-identity-from-the-person-scope-from-the-token.mdindex 5b89926b..14dd5db7 100644--- a/docs/decisions/0014-identity-from-the-person-scope-from-the-token.md+++ b/docs/decisions/0014-identity-from-the-person-scope-from-the-token.md@@ -1,6 +1,6 @@# 0014 · 身份跟着人,范围跟着令牌-- **状态**:已实施(#161 记录、#180 落地)· `personal_tokens` + Streamable HTTP 的 MCP 服务端已上线,暴露五个只读工具;**尚无前端界面**——令牌的发放 / 列表 / 撤销与 MCP 配置提示今天都只有 API(2026-09-02 核,修订见文末)+- **状态**:已实施(#161 记录、#180 落地)· `personal_tokens` + Streamable HTTP 的 MCP 服务端已上线,暴露五个只读工具;界面在 `feat/tokens-have-a-page`(0016 A2):账户层「Agents & tokens」页,发放时明文与 MCP 客户端配置片段一起只显示一次,列表只剩前缀,撤销留痕(2026-09-02 核,修订见文末)- **成文**:2026-09-01(约定见 [README](README.md))- **相关**:迁移 `0014_data_source_grants` 刚给数据源补上授权层——本篇是同一个问题换到「机器来敲门」这一侧;[0004](0004-language-and-localization.md) 定下服务端只说英文,@@ -136,4 +136,4 @@ MCP 的对应形态是:握手时校验一次,然后整条连接生命周期和 Utopia 已经是个服务端相称)。这个选择不影响本篇的结论,两种都要认令牌。〔**已答:Streamable HTTP**,一条路由 `POST /api/v1/kbs/{kb_id}/mcp`,响应用 `application/json` 不用 SSE——工具一问一答,没有服务端主动推的东西。〕- **令牌能不能跨工作区。** 现在的 `kb_ids` 是库级白名单;如果将来要按工作区发,和数据源授权那张表会长得很像,届时看要不要合并概念。〔仍未做。〕-- **(2026-09-02 补)没有界面。** 「UI 默认给 90 天」的 90 天在服务端,而前端根本没有令牌那一页。这是 MCP 今天对用户不可用的直接原因。+- **(2026-09-02 补)没有界面。** 「UI 默认给 90 天」的 90 天在服务端,而前端根本没有令牌那一页。这是 MCP 今天对用户不可用的直接原因。〔**已做**,同日:`/account/tokens`。三个决定落在界面上——scope 缺省只读、库多选、过期缺省 90 天且「不过期」要显式选;配置片段按库出端点(令牌限定到库,端点也按库分),写法取 Claude Code / Claude Desktop 一族的 Streamable HTTP 键名,别的客户端要自己改键。〕diff --git a/docs/decisions/0016-close-the-open-seams-before-cutting-new-ones.md b/docs/decisions/0016-close-the-open-seams-before-cutting-new-ones.mdindex 346b671f..9652f971 100644--- a/docs/decisions/0016-close-the-open-seams-before-cutting-new-ones.md+++ b/docs/decisions/0016-close-the-open-seams-before-cutting-new-ones.md@@ -56,7 +56,7 @@ Review 加 `pending` 一档,界面**原句在上、三元组在下**;确认**验收**:那条实测(「Acme 把总部搬到深圳」)跑一遍,图上不出现空谓词活边,Review 里出现一条带原句的待确认项。做完这一条,MCP 可以放 `remember`(scope = write,令牌以人的身份提议,人自己确认)——0014 未决的答案由此成立。-**A2 · 令牌有界面。** Account 页:列表(前缀、名字、scope、库、最后使用、过期)、发放(明文只显示一次)、撤销;旁边给一段可复制的 MCP 客户端配置(URL + Authorization 头)。+**A2 · 令牌有界面。**〔已做,`feat/tokens-have-a-page`〕Account 页:列表(前缀、名字、scope、库、最后使用、过期)、发放(明文只显示一次)、撤销;旁边给一段可复制的 MCP 客户端配置(URL + Authorization 头)。三个占位 crate **删掉**(已做,与 A3 同一刀):`utopia-mcp` 宣称的三个工具从未存在,服务端住在 `utopia-server/src/api/mcp.rs`;`utopia-graph` 没有对应物;`utopia-connectors` 的意图是对的,但两个连接器看不出边界该划在哪,[0013](0013-a-source-should-hand-over-its-history.md) 说等第三个来了再看抽象,crate 是同一个判断。占位是对读者的承诺,兑现不了就别留,需要时 `cargo new` 是几分钟的事。**A3 · 清死代码与陈旧注释。** 上表最后一行那五处,加上 `resolution.rs` 里 `CONFUSABLE_TYPE_KEYS` 上方停留在旧世界的注释。一个 PR。diff --git a/docs/decisions/README.md b/docs/decisions/README.mdindex eea954ed..bd39a52a 100644--- a/docs/decisions/README.md+++ b/docs/decisions/README.md@@ -39,7 +39,7 @@| 0011 | [「怎么算」不是「有什么」](0011-a-mapping-is-not-a-fact.md) | 已实施(#126 / #140 / #148)· 证据链未做 · 多源选法未做 || 0012 | [本体是一份契约,不只是一份建议](0012-the-ontology-is-a-contract-not-a-suggestion.md) | 已实施 · 违反率 57%→4%、反向 39→0 · 三条待做全未做 || 0013 | [一个来源该交出它的历史,不是它的现状](0013-a-source-should-hand-over-its-history.md) | 已实施两个(GitHub / Jira)· 文档协作类未开工 |-| 0014 | [身份跟着人,范围跟着令牌](0014-identity-from-the-person-scope-from-the-token.md) | 已实施(#180)· MCP 只读五工具 · **没有令牌界面** · 误导性的占位 crate 已删 |+| 0014 | [身份跟着人,范围跟着令牌](0014-identity-from-the-person-scope-from-the-token.md) | 已实施(#180)· MCP 只读五工具 · 令牌页在账户层(A2)· 误导性的占位 crate 已删 || 0015 | [记下一句话,不等于断言一个事实](0015-recording-a-sentence-is-not-asserting-a-fact.md) | 已实施 · 记忆抽出的事实进 `pending_facts`,Review 新档 + 跟在 remember 步骤后的确认卡 · `remember` 重新打开 · MCP 放开写是下一刀 || 0016 | [先把开着的口子收上,再开新的](0016-close-the-open-seams-before-cutting-new-ones.md) | 规划中 · v0.1.0 之后的排期:A 收口 → B 推理机 ∥ C 尺子与本体 → D 语义层 → E 企业交付;模拟引擎后置 |diff --git a/web/src/api.ts b/web/src/api.tsindex a196674e..6db228da 100644--- a/web/src/api.ts+++ b/web/src/api.ts@@ -57,6 +57,22 @@ export interface User {created_at: string;}+/** 个人访问令牌(0014):给 MCP 客户端的长命钥匙,以发它的人的身份行事。+ * 有效权限 = 这个人的角色 ∩ scope;`kb_ids` 为空 = 这个人能进的全部库。 */+export interface TokenView {+ id: string;+ name: string;+ /** 给人认的那一小截(`utp_pat_ab12`),够对上配置文件里那一串,又不足以复原 */+ token_prefix: string;+ scope: "read" | "write";+ kb_ids: string[] | null;+ expires_at: string | null;+ last_used_at: string | null;+ /** 撤销打戳不删行 */+ revoked_at: string | null;+ created_at: string;+}+export interface Workspace {id: string;org_id: string;@@ -914,6 +930,23 @@ export const api = {new_password: newPassword,}),}),+ /** 我发过的个人令牌(0014)。撤销过的也在——撤过这件事本身要看得见 */+ tokens: () => request<{ tokens: TokenView[] }>("/api/v1/me/tokens"),+ /** 发一枚。**明文只在这一次的响应里**,列表永远给不出它 */+ issueToken: (body: {+ name: string;+ scope: "read" | "write";+ /** 缺省 = 这个人能进的全部库 */+ kb_ids?: string[] | null;+ /** 0 = 不过期 */+ expires_in_days: number;+ }) =>+ request<{ token: string; info: TokenView }>("/api/v1/me/tokens", {+ method: "POST",+ body: JSON.stringify(body),+ }),+ revokeToken: (tokenId: string) =>+ request<{ ok: boolean }>(`/api/v1/me/tokens/${tokenId}`, { method: "DELETE" }),workspaces: () => request<Workspace[]>("/api/v1/workspaces"),kbs: (workspaceId: string) =>diff --git a/web/src/i18n/en.ts b/web/src/i18n/en.tsindex 1f31932d..dc585c9c 100644--- a/web/src/i18n/en.ts+++ b/web/src/i18n/en.ts@@ -119,6 +119,47 @@ export const en = {deploymentAdmin: "Deployment admin",openKb: "Open",kbSettingsBtn: "Settings",+ /* 个人令牌页(0014 / 0016 A2):给 agent 的钥匙,以这个人的身份行事 */+ tokensNav: "Agents & tokens",+ tokensTitle: "Personal access tokens",+ tokensHint:+ "A token lets an agent reach Utopia over MCP as you, never with more than you can do yourself. Read-only by default, limited to the bases you pick, revocable here at any time.",+ newToken: "New token",+ tokenName: "Name",+ tokenNamePlaceholder: "My laptop",+ tokenScope: "Scope",+ scopeRead: "Read",+ scopeWrite: "Write",+ scopeHint:+ "Effective rights are your own role ∩ this scope. Write is a ceiling, not a grant: a viewer's write token still cannot write.",+ tokenKbs: "Knowledge bases",+ kbsAllHint: "Nothing selected means every base you can open.",+ tokenExpires: "Expires",+ expiresDays: (n: number) => `${n} days`,+ expiresNever: "Never",+ issueToken: "Create token",+ issuedTitle: "Copy it now. It will not be shown again.",+ issuedHint:+ "Utopia keeps only a hash of it. If you lose it, revoke it here and create another.",+ copy: "Copy",+ copied: "Copied",+ mcpTitle: "MCP client configuration",+ mcpHint:+ "For Claude Code, Claude Desktop and other Streamable HTTP clients. Each base has its own endpoint, so pick the one the agent should talk to. Other clients spell the keys differently.",+ mcpBase: "Base",+ yourTokens: "Your tokens",+ noTokens: "No tokens yet.",+ allBases: "All bases",+ nBases: (n: number) => `${n} base${n === 1 ? "" : "s"}`,+ lastUsed: (d: string) => `last used ${d}`,+ neverUsed: "never used",+ expiresOn: (d: string) => `expires ${d}`,+ noExpiry: "no expiry",+ createdOn: (d: string) => `created ${d}`,+ revoke: "Revoke",+ revokeConfirm: "Revoke?",+ revokedOn: (d: string) => `revoked ${d}`,+ tokenDone: "Done",roleNames: {owner: "Owner",admin: "Admin",diff --git a/web/src/i18n/zh.ts b/web/src/i18n/zh.tsindex 8e7f3bb0..9bacd6a8 100644--- a/web/src/i18n/zh.ts+++ b/web/src/i18n/zh.ts@@ -108,6 +108,45 @@ export const zh: Strings = {deploymentAdmin: "部署管理员",openKb: "打开",kbSettingsBtn: "设置",+ tokensNav: "Agent 与令牌",+ tokensTitle: "个人访问令牌",+ tokensHint:+ "令牌让 agent 经 MCP 以你的身份使用 Utopia,权限永远不超过你自己。缺省只读,限定到你选的库,随时可在这里撤销。",+ newToken: "新令牌",+ tokenName: "名字",+ tokenNamePlaceholder: "我的笔记本",+ tokenScope: "范围",+ scopeRead: "只读",+ scopeWrite: "可写",+ scopeHint:+ "有效权限 = 你自己的角色 ∩ 这个范围。可写是上限不是授权:只读成员的可写令牌照样写不了。",+ tokenKbs: "知识库",+ kbsAllHint: "一个都不选 = 你能进的全部库。",+ tokenExpires: "过期",+ expiresDays: (n: number) => `${n} 天`,+ expiresNever: "不过期",+ issueToken: "创建令牌",+ issuedTitle: "现在就复制,之后不会再显示。",+ issuedHint: "Utopia 只保存它的哈希。丢了就在这里撤销,再建一枚。",+ copy: "复制",+ copied: "已复制",+ mcpTitle: "MCP 客户端配置",+ mcpHint:+ "适用于 Claude Code、Claude Desktop 及其它 Streamable HTTP 客户端。每个库有自己的端点,选 agent 要对话的那个库。别的客户端键名可能不同。",+ mcpBase: "库",+ yourTokens: "你的令牌",+ noTokens: "还没有令牌。",+ allBases: "全部库",+ nBases: (n: number) => `${n} 个库`,+ lastUsed: (d: string) => `最近使用 ${d}`,+ neverUsed: "从未使用",+ expiresOn: (d: string) => `${d} 过期`,+ noExpiry: "不过期",+ createdOn: (d: string) => `${d} 创建`,+ revoke: "撤销",+ revokeConfirm: "确认撤销?",+ revokedOn: (d: string) => `${d} 已撤销`,+ tokenDone: "完成",roleNames: {owner: "所有者",admin: "管理员",diff --git a/web/src/pages/AccountShell.tsx b/web/src/pages/AccountShell.tsxindex 0828ac72..a0cbdae1 100644--- a/web/src/pages/AccountShell.tsx+++ b/web/src/pages/AccountShell.tsx@@ -3,7 +3,7 @@import { useQuery } from "@tanstack/react-query";import { Link, Outlet, useNavigate } from "@tanstack/react-router";import { usePageTitle } from "../useTitle";-import { BookMarked, ShieldCheck, UserRound } from "lucide-react";+import { BookMarked, KeyRound, ShieldCheck, UserRound } from "lucide-react";import { api, ApiError } from "../api";import { S } from "../i18n";import { GithubMark, RAIL_CLS, SectionMark } from "../ui";@@ -81,6 +81,10 @@ export function AccountShell() {<BookMarked size={14} />{S.account.kbsNav}</Link>+ <Link to="/account/tokens" className={rail} activeProps={{ className: railActive }}>+ <KeyRound size={14} />+ {S.account.tokensNav}+ </Link>{me.data.is_admin && (<Link to="/admin" className={rail} activeProps={{ className: railActive }}><ShieldCheck size={14} />diff --git a/web/src/pages/Tokens.tsx b/web/src/pages/Tokens.tsxnew file mode 100644index 00000000..47fb8801--- /dev/null+++ b/web/src/pages/Tokens.tsx@@ -0,0 +1,359 @@+/* 个人访问令牌页(docs/decisions/0014,0016 的 A2)。+ 令牌属于人、以人的身份行事:有效权限 = 角色 ∩ scope,`kb_ids` 只收窄不授权。+ 服务端三个端点早就在(发放 / 列表 / 撤销),缺的只是这一页——没有它,+ MCP 对用户就是「有 API、配不了」。+ 明文只在发放那一次的响应里出现,所以这一页的重心是那一刻:把令牌和一段可复制的+ 客户端配置一起端出来,人复制完点「完成」,之后列表里只剩前缀。 */+import { useMemo, useState } from "react";+import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";+import { Check, Copy, KeyRound } from "lucide-react";+import { api, type TokenView } from "../api";+import { S } from "../i18n";+import { useKb } from "../kb";+import { Chip, Loading } from "../ui";+import { toast } from "../toast";++const ymd = (iso: string) => iso.slice(0, 10);+const EXPIRY_CHOICES = [30, 90, 365, 0] as const;++function copyText(text: string) {+ navigator.clipboard+ ?.writeText(text)+ .then(() => toast.success(S.account.copied))+ .catch(() => {});+}++/** Claude Code / Claude Desktop 一族的 Streamable HTTP 写法。每个库一个端点(0014:+ * 令牌限定到库,端点也按库分),所以片段里要把库选出来 */+function mcpSnippet(kbId: string, kbName: string, token: string): string {+ const slug = kbName+ .toLowerCase()+ .replace(/[^a-z0-9]+/g, "-")+ .replace(/^-+|-+$/g, "") || "kb";+ const cfg = {+ mcpServers: {+ [`utopia-${slug}`]: {+ type: "http",+ url: `${window.location.origin}/api/v1/kbs/${kbId}/mcp`,+ headers: { Authorization: `Bearer ${token}` },+ },+ },+ };+ return JSON.stringify(cfg, null, 2);+}++function CopyButton({ text, small }: { text: string; small?: boolean }) {+ const [done, setDone] = useState(false);+ return (+ <button+ className={`u-btn u-btn-ghost ${small ? "px-2 py-1 text-[11px]" : "px-3 py-1.5 text-xs"} flex items-center gap-1.5`}+ onClick={() => {+ copyText(text);+ setDone(true);+ setTimeout(() => setDone(false), 1500);+ }}+ >+ {done ? <Check size={12} /> : <Copy size={12} />}+ {done ? S.account.copied : S.account.copy}+ </button>+ );+}++/** 刚发出来的那一枚:明文 + 配置片段,关掉就再也看不到 */+function IssuedPanel({+ token,+ info,+ kbs,+ onDone,+}: {+ token: string;+ info: TokenView;+ kbs: { id: string; name: string }[];+ onDone: () => void;+}) {+ // 片段默认指向令牌限定的第一个库;没限定就取列表第一个+ const candidates = info.kb_ids?.length+ ? kbs.filter((k) => info.kb_ids!.includes(k.id))+ : kbs;+ const [kbId, setKbId] = useState(candidates[0]?.id ?? kbs[0]?.id ?? "");+ const kb = kbs.find((k) => k.id === kbId);+ const snippet = kb ? mcpSnippet(kb.id, kb.name, token) : "";+ return (+ <div className="glass rounded-2xl p-5 mb-4 border border-[var(--u-warn)]/40">+ <div className="text-[13px] font-medium text-neutral-100">{S.account.issuedTitle}</div>+ <p className="mt-1 text-xs text-neutral-500">{S.account.issuedHint}</p>+ <div className="mt-3 flex items-center gap-2">+ <code className="flex-1 min-w-0 truncate rounded-lg bg-black/40 px-3 py-2 font-mono text-[12px] text-neutral-200">+ {token}+ </code>+ <CopyButton text={token} />+ </div>++ <div className="mt-5 flex items-baseline justify-between gap-3 flex-wrap">+ <div className="text-[13px] font-medium text-neutral-200">{S.account.mcpTitle}</div>+ {candidates.length > 1 && (+ <label className="flex items-center gap-2 text-xs text-neutral-500">+ {S.account.mcpBase}+ <select+ className="input-dark px-2 py-1 text-xs"+ value={kbId}+ onChange={(e) => setKbId(e.target.value)}+ >+ {candidates.map((k) => (+ <option key={k.id} value={k.id}>+ {k.name}+ </option>+ ))}+ </select>+ </label>+ )}+ </div>+ <p className="mt-1 text-xs text-neutral-500">{S.account.mcpHint}</p>+ <div className="mt-2 relative">+ <pre className="rounded-lg bg-black/40 px-3 py-2 font-mono text-[11.5px] text-neutral-300 overflow-x-auto u-scroll">+ {snippet}+ </pre>+ <div className="absolute top-1.5 right-1.5">+ <CopyButton text={snippet} small />+ </div>+ </div>++ <div className="mt-4 flex justify-end">+ <button className="u-btn u-btn-primary px-3.5 py-1.5 text-xs" onClick={onDone}>+ {S.account.tokenDone}+ </button>+ </div>+ </div>+ );+}++function TokenRow({+ t,+ kbName,+ busy,+ onRevoke,+}: {+ t: TokenView;+ kbName: (id: string) => string;+ busy: boolean;+ onRevoke: () => void;+}) {+ // 撤销不可撤回,但代价只是重发一枚——轻确认(二次点击),不做打字解锁+ const [arm, setArm] = useState(false);+ const revoked = !!t.revoked_at;+ const bases = t.kb_ids?.length+ ? t.kb_ids.map(kbName).join(" · ")+ : S.account.allBases;+ return (+ <div className={`glass rounded-xl px-4 py-3 ${revoked ? "opacity-55" : ""}`}>+ <div className="flex items-center gap-2 flex-wrap">+ <KeyRound size={13} className="text-neutral-500 shrink-0" />+ <span className="text-sm font-medium text-neutral-100">{t.name}</span>+ <code className="font-mono text-[11px] text-neutral-500">{t.token_prefix}…</code>+ <Chip tone={t.scope === "write" ? "warn" : "neutral"}>+ {t.scope === "write" ? S.account.scopeWrite : S.account.scopeRead}+ </Chip>+ {revoked && <Chip tone="danger">{S.account.revokedOn(ymd(t.revoked_at!))}</Chip>}+ {!revoked && (+ <div className="ml-auto flex gap-2">+ {arm ? (+ <button+ className="u-btn u-btn-ghost px-3 py-1.5 text-xs text-[var(--u-danger)]"+ disabled={busy}+ onClick={onRevoke}+ onBlur={() => setArm(false)}+ >+ {S.account.revokeConfirm}+ </button>+ ) : (+ <button+ className="u-btn u-btn-ghost px-3 py-1.5 text-xs"+ disabled={busy}+ onClick={() => setArm(true)}+ >+ {S.account.revoke}+ </button>+ )}+ </div>+ )}+ </div>+ <div className="mt-1.5 text-[11.5px] text-neutral-500 flex gap-x-3 gap-y-0.5 flex-wrap u-num">+ <span title={t.kb_ids?.length ? bases : undefined}>+ {t.kb_ids?.length ? S.account.nBases(t.kb_ids.length) : S.account.allBases}+ </span>+ <span>·</span>+ <span>+ {t.last_used_at ? S.account.lastUsed(ymd(t.last_used_at)) : S.account.neverUsed}+ </span>+ <span>·</span>+ <span>{t.expires_at ? S.account.expiresOn(ymd(t.expires_at)) : S.account.noExpiry}</span>+ <span>·</span>+ <span>{S.account.createdOn(ymd(t.created_at))}</span>+ </div>+ </div>+ );+}++export function Tokens() {+ const queryClient = useQueryClient();+ const { kbs } = useKb();+ const list = useQuery({ queryKey: ["tokens"], queryFn: api.tokens });++ const [name, setName] = useState("");+ const [scope, setScope] = useState<"read" | "write">("read");+ const [picked, setPicked] = useState<Set<string>>(new Set());+ const [days, setDays] = useState<number>(90);+ const [issued, setIssued] = useState<{ token: string; info: TokenView } | null>(null);++ const issue = useMutation({+ mutationFn: () =>+ api.issueToken({+ name: name.trim(),+ scope,+ kb_ids: picked.size ? Array.from(picked) : null,+ expires_in_days: days,+ }),+ onSuccess: (res) => {+ setIssued(res);+ setName("");+ setPicked(new Set());+ queryClient.invalidateQueries({ queryKey: ["tokens"] });+ },+ onError: (e) => toast.error((e as Error).message),+ });+ const revoke = useMutation({+ mutationFn: (id: string) => api.revokeToken(id),+ onSettled: () => queryClient.invalidateQueries({ queryKey: ["tokens"] }),+ onError: (e) => toast.error((e as Error).message),+ });++ const kbName = useMemo(() => {+ const m = new Map(kbs.map((k) => [k.id, k.name]));+ return (id: string) => m.get(id) ?? id.slice(0, 8);+ }, [kbs]);++ if (list.isPending) return <Loading>{S.nav.loading}</Loading>;+ // 活的在前、按新到旧;撤销过的沉底但仍然列着——撤过这件事本身要看得见+ const rows = [...(list.data?.tokens ?? [])].sort((a, b) => {+ if (!!a.revoked_at !== !!b.revoked_at) return a.revoked_at ? 1 : -1;+ return b.created_at.localeCompare(a.created_at);+ });++ const field = (label: string, node: React.ReactNode, hint?: string) => (+ <div className="mb-4">+ <div className="mb-1 text-[11px] font-medium text-neutral-500">{label}</div>+ {node}+ {hint && <p className="mt-1 text-[11px] text-neutral-600">{hint}</p>}+ </div>+ );++ return (+ <div className="max-w-2xl p-8">+ <h1 className="u-title text-lg">{S.account.tokensTitle}</h1>+ <p className="mt-1 mb-6 text-xs text-neutral-500 max-w-lg">{S.account.tokensHint}</p>++ {issued && (+ <IssuedPanel+ token={issued.token}+ info={issued.info}+ kbs={kbs}+ onDone={() => setIssued(null)}+ />+ )}++ <div className="glass rounded-2xl p-5 mb-6">+ <h2 className="text-[13px] font-medium text-neutral-200 mb-4">{S.account.newToken}</h2>+ {field(+ S.account.tokenName,+ <input+ className="input-dark w-full px-3 py-2 text-sm"+ placeholder={S.account.tokenNamePlaceholder}+ value={name}+ maxLength={64}+ onChange={(e) => setName(e.target.value)}+ />,+ )}+ {field(+ S.account.tokenScope,+ <div className="flex gap-2">+ {(["read", "write"] as const).map((s) => (+ <button+ key={s}+ className={`u-btn px-3 py-1.5 text-xs ${scope === s ? "u-btn-primary" : "u-btn-ghost"}`}+ onClick={() => setScope(s)}+ >+ {s === "read" ? S.account.scopeRead : S.account.scopeWrite}+ </button>+ ))}+ </div>,+ S.account.scopeHint,+ )}+ {field(+ S.account.tokenKbs,+ <div className="flex gap-2 flex-wrap">+ {kbs.map((k) => {+ const on = picked.has(k.id);+ return (+ <button+ key={k.id}+ className={`u-btn px-2.5 py-1 text-xs ${on ? "u-btn-primary" : "u-btn-ghost"}`}+ onClick={() => {+ const next = new Set(picked);+ if (on) next.delete(k.id);+ else next.add(k.id);+ setPicked(next);+ }}+ >+ {k.name}+ </button>+ );+ })}+ </div>,+ S.account.kbsAllHint,+ )}+ {field(+ S.account.tokenExpires,+ <div className="flex gap-2">+ {EXPIRY_CHOICES.map((d) => (+ <button+ key={d}+ className={`u-btn px-2.5 py-1 text-xs u-num ${days === d ? "u-btn-primary" : "u-btn-ghost"}`}+ onClick={() => setDays(d)}+ >+ {d === 0 ? S.account.expiresNever : S.account.expiresDays(d)}+ </button>+ ))}+ </div>,+ )}+ <div className="flex justify-end">+ <button+ className="u-btn u-btn-primary px-3.5 py-1.5 text-xs"+ disabled={!name.trim() || issue.isPending}+ onClick={() => issue.mutate()}+ >+ {S.account.issueToken}+ </button>+ </div>+ </div>++ <h2 className="text-[13px] font-medium text-neutral-200 mb-3">{S.account.yourTokens}</h2>+ {rows.length === 0 ? (+ <div className="glass rounded-xl p-8 text-center text-sm text-neutral-500">+ {S.account.noTokens}+ </div>+ ) : (+ <div className="space-y-2">+ {rows.map((t) => (+ <TokenRow+ key={t.id}+ t={t}+ kbName={kbName}+ busy={revoke.isPending && revoke.variables === t.id}+ onRevoke={() => revoke.mutate(t.id)}+ />+ ))}+ </div>+ )}+ </div>+ );+}diff --git a/web/src/router.tsx b/web/src/router.tsxindex 06414382..6de3acee 100644--- a/web/src/router.tsx+++ b/web/src/router.tsx@@ -6,6 +6,7 @@ import {} from "@tanstack/react-router";import { Account } from "./pages/Account";import { AccountShell } from "./pages/AccountShell";+import { Tokens } from "./pages/Tokens";import { Chat } from "./pages/Chat";import { DocViewer } from "./pages/DocViewer";import { DocsPage } from "./pages/Docs";@@ -179,6 +180,13 @@ const myKbsRoute = createRoute({component: MyKbs,});+// 个人令牌(0014):给 agent 的钥匙属于人,所以在账户层,不在库里+const tokensRoute = createRoute({+ getParentRoute: () => accountShellRoute,+ path: "/account/tokens",+ component: Tokens,+});+const adminRoute = createRoute({getParentRoute: () => accountShellRoute,path: "/admin",@@ -266,7 +274,7 @@ const routeTree = rootRoute.addChildren([settingsRoute,docsIndexRoute,docsRoute,- accountShellRoute.addChildren([accountRoute, myKbsRoute, adminRoute]),+ accountShellRoute.addChildren([accountRoute, myKbsRoute, tokensRoute, adminRoute]),appRoute.addChildren([indexRoute,legacyGraphRoute,