Skip to content

World's first open-source enterprise world model.

The tokens page becomes a table, and administration navigates from the rail (#468)

WaylandYange56049fda04b
diff --git a/web/src/i18n/en.ts b/web/src/i18n/en.ts
index a8c7b9b8..28bc93dd 100644
--- a/web/src/i18n/en.ts
+++ b/web/src/i18n/en.ts
@@ -93,6 +93,10 @@ export const en = {
/* 网页标题用的短名:`Utopia | Persona` */
titleTag: "Persona",
profile: "Profile",
+ cancel: "Cancel",
+ colLastUsed: "Last used",
+ colCreated: "Created",
+ pickBases: "Search bases…",
administration: "Administration",
adminChip: "Admin",
backToApp: "← Back to app",
@@ -130,8 +134,7 @@ export const en = {
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.",
+ scopeHint: "A ceiling, not a grant — a token never does more than you can.",
tokenKbs: "Knowledge bases",
kbsAllHint: "Nothing selected means every base you can open.",
tokenExpires: "Expires",
diff --git a/web/src/i18n/zh.ts b/web/src/i18n/zh.ts
index bc6a9cf8..f48f600e 100644
--- a/web/src/i18n/zh.ts
+++ b/web/src/i18n/zh.ts
@@ -82,6 +82,10 @@ export const zh: Strings = {
brand: "Utopia Persona",
titleTag: "Persona",
profile: "个人资料",
+ cancel: "取消",
+ colLastUsed: "上次使用",
+ colCreated: "创建于",
+ pickBases: "搜索知识库…",
administration: "管理",
adminChip: "管理员",
backToApp: "← 返回",
@@ -118,8 +122,7 @@ export const zh: Strings = {
tokenScope: "范围",
scopeRead: "只读",
scopeWrite: "可写",
- scopeHint:
- "有效权限 = 你自己的角色 ∩ 这个范围。可写是上限不是授权:只读成员的可写令牌照样写不了。",
+ scopeHint: "是上限,不是授权——令牌永远不会比你自己能做的更多。",
tokenKbs: "知识库",
kbsAllHint: "一个都不选 = 你能进的全部库。",
tokenExpires: "过期",
diff --git a/web/src/pages/AccountShell.tsx b/web/src/pages/AccountShell.tsx
index a31fceb0..4d404535 100644
--- a/web/src/pages/AccountShell.tsx
+++ b/web/src/pages/AccountShell.tsx
@@ -1,7 +1,7 @@
/* 账户层壳:Profile / Administration 的宿主。
与 KB 无关,所以没有 KB 切换器、没有 tab 导航——只有字标、返回、用户菜单。 */
import { useQuery } from "@tanstack/react-query";
-import { Link, Outlet, useNavigate } from "@tanstack/react-router";
+import { Link, Outlet, useLocation, useNavigate } from "@tanstack/react-router";
import { usePageTitle } from "../useTitle";
import {
KeyRound,
@@ -16,11 +16,25 @@ import {
rowClass,
SectionMark,
} from "../ui";
+
+/** 管理页的五节。**它们是左栏的第二层,不是正文顶上的一条 tab 带**——
+ 与上面四项是同一种东西(去哪儿),只是矮一级;地址里是 `?tab=`,
+ 刷新、回退、分享链接都落回同一节 */
+const ADMIN_TABS = [
+ ["models", () => S.settings.tabModels],
+ ["members", () => S.settings.tabMembers],
+ ["kbs", () => S.settings.tabKbs],
+ ["datasources", () => S.settings.datasources.tab],
+ ["deployment", () => S.settings.tabDeployment],
+] as const;
import { ServerDown } from "./ServerDown";
import { HeaderActions } from "./HeaderActions";
export function AccountShell() {
const navigate = useNavigate();
+ const loc = useLocation();
+ const onAdmin = loc.pathname === "/admin";
+ const adminTab = (loc.search as { tab?: string }).tab ?? "models";
const me = useQuery({ queryKey: ["me"], queryFn: api.me });
const health = useQuery({ queryKey: ["health"], queryFn: api.health, staleTime: Infinity });
// 标题:`Utopia | Persona`——账户区整体一个名字,不逐页细分
@@ -79,10 +93,29 @@ export function AccountShell() {
{S.account.tokensNav}
</Link>
{me.data.is_admin && (
- <Link to="/admin" className={rail} activeProps={{ className: railActive }}>
- <ShieldCheck size={14} />
- {S.account.administration}
- </Link>
+ <>
+ {/* 在管理页时父行不再反白:下面已经有一条亮着,两条一起亮反而
+ 说不清人在哪儿 */}
+ <Link
+ to="/admin"
+ className={rail}
+ activeProps={onAdmin ? {} : { className: railActive }}
+ >
+ <ShieldCheck size={14} />
+ {S.account.administration}
+ </Link>
+ {onAdmin &&
+ ADMIN_TABS.map(([key, label]) => (
+ <Link
+ key={key}
+ to="/admin"
+ search={{ tab: key }}
+ className={rowClass(adminTab === key, "nav", undefined, true)}
+ >
+ {label()}
+ </Link>
+ ))}
+ </>
)}
</aside>
<main className="flex-1 min-w-0 overflow-y-auto u-scroll">
diff --git a/web/src/pages/Settings.tsx b/web/src/pages/Settings.tsx
index f3765a4c..89fdf101 100644
--- a/web/src/pages/Settings.tsx
+++ b/web/src/pages/Settings.tsx
@@ -713,10 +713,11 @@ const PRESETS: Record<
export function Settings() {
const { workspace } = useKb();
+ /* 人在哪一节,**地址说了算**:左栏第二层是一组 Link(见 AccountShell),
+ 刷新、回退、把链接发给同事都落回同一节。从前这里另存一份 state,
+ 于是地址与页面各说各的 */
const { tab: tabParam, create } = useSearch({ from: "/account/admin" });
- const [tab, setTab] = useState<
- "models" | "members" | "kbs" | "datasources" | "deployment"
- >(tabParam ?? "models");
+ const tab = tabParam ?? "models";
const queryClient = useQueryClient();
const settings = useQuery({
queryKey: ["settings", workspace?.id],
@@ -785,21 +786,7 @@ export function Settings() {
<div className="h-full overflow-y-auto u-scroll px-8 py-6">
{/* 同 KbSettings:设置是读一列字段,居中限宽,行长不随窗口拉长 */}
<div className="mx-auto w-full max-w-4xl">
- <PageHeader className="mb-3" title={S.settings.title} />
- <Segmented
- className="mb-6 w-fit"
- value={tab}
- onChange={setTab}
- options={(
- [
- ["models", S.settings.tabModels],
- ["members", S.settings.tabMembers],
- ["kbs", S.settings.tabKbs],
- ["datasources", S.settings.datasources.tab],
- ["deployment", S.settings.tabDeployment],
- ] as const
- ).map(([key, tabLabel]) => ({ value: key, label: tabLabel }))}
- />
+ <PageHeader title={S.settings.title} />
{tab === "members" && <Members workspaceId={workspace.id} />}
{tab === "kbs" && <KbsAdmin autoCreate={!!create} />}
diff --git a/web/src/pages/Tokens.tsx b/web/src/pages/Tokens.tsx
index ce1a0e10..e5bdc7ae 100644
--- a/web/src/pages/Tokens.tsx
+++ b/web/src/pages/Tokens.tsx
@@ -6,17 +6,28 @@
客户端配置一起端出来,人复制完点「完成」,之后列表里只剩前缀。 */
import { useMemo, useState } from "react";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
-import { Check, Copy, KeyRound } from "lucide-react";
+import { Check, Copy, KeyRound, Plus } from "lucide-react";
import { api, type TokenView } from "../api";
import { S } from "../i18n";
import { useKb } from "../kb";
import {
Button,
Chip,
+ Dialog,
+ Dropdown,
+ Field,
Input,
Loading,
+ MultiSearchSelect,
NativeSelect,
PageHeader,
+ Radio,
+ Table,
+ TBody,
+ Td,
+ Th,
+ THead,
+ Tr,
} from "../ui";
import { toast } from "../toast";
@@ -66,17 +77,16 @@ function CopyButton({ text, small }: { text: string; small?: boolean }) {
);
}
-/** 刚发出来的那一枚:明文 + 配置片段,关掉就再也看不到 */
-function IssuedPanel({
+/** 刚发出来的那一枚:明文 + 配置片段,关掉就再也看不到。
+ 住在发令牌那个弹窗里——发放的下一秒就是"把它抄走",中间不该有一次关窗 */
+function IssuedBody({
token,
info,
kbs,
- onDone,
}: {
token: string;
info: TokenView;
kbs: { id: string; name: string }[];
- onDone: () => void;
}) {
// 片段默认指向令牌限定的第一个库;没限定就取列表第一个
const candidates = info.kb_ids?.length
@@ -86,11 +96,9 @@ function IssuedPanel({
const kb = kbs.find((k) => k.id === kbId);
const snippet = kb ? mcpSnippet(kb.id, kb.name, token) : "";
return (
- <div className="glass rounded-panel p-6 mb-4 border border-warn/40">
- <div className="text-body font-medium text-ink">{S.account.issuedTitle}</div>
- <p className="mt-1 text-small text-ink-2">{S.account.issuedHint}</p>
- <div className="mt-3 flex items-center gap-2">
- <code className="flex-1 min-w-0 truncate rounded-cell bg-well px-3 py-2 font-mono text-small text-ink">
+ <div>
+ <div className="flex items-center gap-2">
+ <code className="min-w-0 flex-1 truncate rounded-cell bg-well px-3 py-2 font-mono text-small text-ink">
{token}
</code>
<CopyButton text={token} />
@@ -123,12 +131,6 @@ function IssuedPanel({
<CopyButton text={snippet} small />
</div>
</div>
-
- <div className="mt-4 flex justify-end">
- <Button variant="primary" size="sm" onClick={onDone}>
- {S.account.tokenDone}
- </Button>
- </div>
</div>
);
}
@@ -151,50 +153,52 @@ function TokenRow({
? t.kb_ids.map(kbName).join(" · ")
: S.account.allBases;
return (
- <div className={`glass rounded-panel px-4 py-3 ${revoked ? "opacity-55" : ""}`}>
- <div className="flex items-center gap-2 flex-wrap">
- <KeyRound size={13} className="text-ink-2 shrink-0" />
- <span className="text-body font-medium text-ink">{t.name}</span>
- <code className="font-mono text-fine text-ink-2">{t.token_prefix}…</code>
+ <Tr className={revoked ? "opacity-55" : undefined}>
+ <Td>
+ <div className="flex items-center gap-2">
+ <KeyRound size={13} className="shrink-0 text-ink-2" />
+ <span className="truncate text-body text-ink">{t.name}</span>
+ <code className="shrink-0 font-mono text-fine text-ink-2">
+ {t.token_prefix}…
+ </code>
+ </div>
+ </Td>
+ <Td>
<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 variant="danger" size="sm"
- disabled={busy}
- onClick={onRevoke}
- onBlur={() => setArm(false)}
- >
- {S.account.revokeConfirm}
- </Button>
- ) : (
- <Button variant="secondary" size="sm"
- disabled={busy}
- onClick={() => setArm(true)}
- >
- {S.account.revoke}
- </Button>
- )}
- </div>
+ </Td>
+ <Td className="text-small text-ink-2" title={bases}>
+ {t.kb_ids?.length ? S.account.nBases(t.kb_ids.length) : S.account.allBases}
+ </Td>
+ <Td className="u-num text-small text-ink-2">
+ {t.last_used_at ? ymd(t.last_used_at) : S.account.neverUsed}
+ </Td>
+ <Td className="u-num text-small text-ink-2">
+ {t.expires_at ? ymd(t.expires_at) : S.account.noExpiry}
+ </Td>
+ <Td className="u-num text-small text-ink-2">{ymd(t.created_at)}</Td>
+ <Td className="text-right">
+ {revoked ? (
+ <Chip tone="danger">{S.account.revokedOn(ymd(t.revoked_at!))}</Chip>
+ ) : arm ? (
+ <Button variant="danger" size="sm"
+ disabled={busy}
+ onClick={onRevoke}
+ onBlur={() => setArm(false)}
+ >
+ {S.account.revokeConfirm}
+ </Button>
+ ) : (
+ <Button variant="secondary" size="sm"
+ disabled={busy}
+ onClick={() => setArm(true)}
+ >
+ {S.account.revoke}
+ </Button>
)}
- </div>
- <div className="mt-2 text-small text-ink-2 flex gap-x-3 gap-y-1 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>
+ </Td>
+ </Tr>
);
}
@@ -203,6 +207,8 @@ export function Tokens() {
const { kbs } = useKb();
const list = useQuery({ queryKey: ["tokens"], queryFn: api.tokens });
+ // 发令牌是个动作,不是这一页的常驻内容:表单住在弹窗里,页面上只有名单
+ const [creating, setCreating] = useState(false);
const [name, setName] = useState("");
const [scope, setScope] = useState<"read" | "write">("read");
const [picked, setPicked] = useState<Set<string>>(new Set());
@@ -218,6 +224,7 @@ export function Tokens() {
expires_in_days: days,
}),
onSuccess: (res) => {
+ // 同一个窗口换一副内容:发完立刻是"把它抄走",明文只有这一次
setIssued(res);
setName("");
setPicked(new Set());
@@ -243,120 +250,149 @@ export function Tokens() {
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-fine font-medium text-ink-2">{label}</div>
- {node}
- {hint && <p className="mt-1 text-fine text-ink-2">{hint}</p>}
- </div>
- );
+ const close = () => {
+ setCreating(false);
+ setIssued(null);
+ };
return (
<div className="px-8 py-6">
- <PageHeader title={S.account.tokensTitle} sub={S.account.tokensHint} />
-
- {issued && (
- <IssuedPanel
- token={issued.token}
- info={issued.info}
- kbs={kbs}
- onDone={() => setIssued(null)}
- />
- )}
+ <PageHeader
+ title={S.account.tokensTitle}
+ sub={S.account.tokensHint}
+ actions={
+ <Button variant="primary" size="sm" onClick={() => setCreating(true)}>
+ <Plus size={12} />
+ {S.account.newToken}
+ </Button>
+ }
+ />
- <div className="glass rounded-panel p-6 mb-6">
- <div className="max-w-xl">
- <h2 className="text-body font-medium text-ink mb-4">{S.account.newToken}</h2>
- {field(
- S.account.tokenName,
- <Input className="w-full"
- 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 variant="secondary" size="sm"
- key={s}
- className={`u-btn px-3 py-2 text-small ${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 variant="secondary" size="sm"
- key={k.id}
- className={`u-btn px-3 py-1 text-small ${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 variant="secondary" size="sm"
- key={d}
- className={`u-btn px-3 py-1 text-small 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 variant="primary" size="sm"
- disabled={!name.trim() || issue.isPending}
- onClick={() => issue.mutate()}
- >
- {S.account.issueToken}
- </Button>
- </div>
- </div>
- </div>
-
- <h2 className="text-body font-medium text-ink mb-3">{S.account.yourTokens}</h2>
{rows.length === 0 ? (
<div className="glass rounded-panel p-8 text-center text-body text-ink-2">
{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 className="glass rounded-panel overflow-hidden">
+ <Table>
+ <THead>
+ <Tr>
+ <Th>{S.account.tokenName}</Th>
+ <Th>{S.account.tokenScope}</Th>
+ <Th>{S.account.tokenKbs}</Th>
+ <Th>{S.account.colLastUsed}</Th>
+ <Th>{S.account.tokenExpires}</Th>
+ <Th>{S.account.colCreated}</Th>
+ <Th />
+ </Tr>
+ </THead>
+ <TBody>
+ {rows.map((t) => (
+ <TokenRow
+ key={t.id}
+ t={t}
+ kbName={kbName}
+ busy={revoke.isPending && revoke.variables === t.id}
+ onRevoke={() => revoke.mutate(t.id)}
+ />
+ ))}
+ </TBody>
+ </Table>
</div>
)}
+
+ {/* 一个窗口两副内容:先是表单,发出来之后是那一枚明文。中间不关窗——
+ 关掉就再也看不到它了 */}
+ <Dialog
+ open={creating || !!issued}
+ onOpenChange={(o) => !o && close()}
+ width={issued ? "lg" : "md"}
+ closeLabel={S.ui.close}
+ title={issued ? S.account.issuedTitle : S.account.newToken}
+ description={issued ? S.account.issuedHint : undefined}
+ footer={
+ issued ? (
+ <Button variant="primary" size="sm" onClick={close}>
+ {S.account.tokenDone}
+ </Button>
+ ) : (
+ <>
+ <Button variant="secondary" size="sm" onClick={close}>
+ {S.account.cancel}
+ </Button>
+ <Button variant="primary" size="sm"
+ disabled={!name.trim() || issue.isPending}
+ onClick={() => issue.mutate()}
+ >
+ {S.account.issueToken}
+ </Button>
+ </>
+ )
+ }
+ >
+ {issued ? (
+ <IssuedBody token={issued.token} info={issued.info} kbs={kbs} />
+ ) : (
+ <div>
+ <Field label={S.account.tokenName}>
+ <Input className="w-full"
+ autoFocus
+ placeholder={S.account.tokenNamePlaceholder}
+ value={name}
+ maxLength={64}
+ onChange={(e) => setName(e.target.value)}
+ />
+ </Field>
+ {/* 范围与有效期并排:两个都是一眼扫过去就定下来的小选择,
+ 各占一整行只是把这张表拉长 */}
+ <div className="grid grid-cols-2 gap-4">
+ {/* 二选一,且两个选项都要读得到——单选按钮,不是一排按钮 */}
+ <Field label={S.account.tokenScope} hint={S.account.scopeHint}>
+ <div className="flex h-8 items-center gap-4">
+ {(["read", "write"] as const).map((s) => (
+ <Radio
+ key={s}
+ name="token-scope"
+ checked={scope === s}
+ onChange={() => setScope(s)}
+ label={s === "read" ? S.account.scopeRead : S.account.scopeWrite}
+ />
+ ))}
+ </div>
+ </Field>
+ <Field label={S.account.tokenExpires}>
+ <Dropdown
+ className="w-full"
+ value={String(days)}
+ onChange={(v) => setDays(Number(v))}
+ options={EXPIRY_CHOICES.map((d) => ({
+ value: String(d),
+ label: d === 0 ? S.account.expiresNever : S.account.expiresDays(d),
+ }))}
+ />
+ </Field>
+ </div>
+ {/* 库可以很多:搜着选,选中的堆在框上面。芯片墙的高度随库数长,
+ 这个不随。**不再另写一句「不选就是全部」**——控件自己就写着
+ 「All bases」,同一件事说两遍只是把表单拉长 */}
+ <Field label={S.account.tokenKbs} className="mb-0">
+ <MultiSearchSelect
+ className="w-full"
+ values={Array.from(picked)}
+ options={kbs.map((k) => ({ value: k.id, label: k.name }))}
+ placeholder={S.account.pickBases}
+ emptyHint={S.account.allBases}
+ onToggle={(id) => {
+ const next = new Set(picked);
+ if (next.has(id)) next.delete(id);
+ else next.add(id);
+ setPicked(next);
+ }}
+ />
+ </Field>
+ </div>
+ )}
+ </Dialog>
</div>
);
}
diff --git a/web/src/ui/index.tsx b/web/src/ui/index.tsx
index bfb72b7b..b3ffc4ac 100644
--- a/web/src/ui/index.tsx
+++ b/web/src/ui/index.tsx
@@ -1078,12 +1078,15 @@ export function PageHeader({
className?: string;
}) {
return (
- <div className={cn(className ?? "mb-6", "flex items-center justify-between gap-4")}>
- <div className="min-w-0">
- <h1 className="u-title text-display break-words">{title}</h1>
- {sub && <p className="mt-1 text-body text-ink-2">{sub}</p>}
+ <div className={cn(className ?? "mb-6")}>
+ {/* 动作跟**标题那一行**走,不跟「标题 + 副标题」这一整块走:整块居中的话,
+ 有副标题时按钮就浮在两行中间,看着既不属于标题也不属于说明。
+ items-baseline:按钮上的字与标题坐在同一条基线上 */}
+ <div className="flex items-baseline justify-between gap-4">
+ <h1 className="u-title min-w-0 text-display break-words">{title}</h1>
+ {actions && <div className="flex shrink-0 items-center gap-2">{actions}</div>}
</div>
- {actions && <div className="flex shrink-0 items-center gap-2">{actions}</div>}
+ {sub && <p className="mt-1 text-body text-ink-2">{sub}</p>}
</div>
);
}
@@ -1140,10 +1143,15 @@ export function rowClass(
active?: boolean,
density: RowDensity = "list",
tone?: RowTone,
+ /** 二级:左栏里挂在某一项下面的那几条。文字缩到父行标签的位置
+ (内距 12 + 图标 14 + 间距 8 = 34),底色仍然铺满整行——
+ 缩的是字,不是那一格 */
+ sub?: boolean,
): string {
return cn(
"group flex w-full items-center gap-2 text-left transition-colors duration-fast",
density === "menu" ? "rounded-none" : "rounded-cell",
+ sub && "pl-[34px]",
// 左栏导航项 32 高(py 6):36 在一列十几条里显得松
density === "nav"
? "px-3 py-1.5 text-body font-medium"