import { useSyncExternalStore } from "react"; import type { Decision } from "../../shared/ipc"; import { remainingSeconds, riskLabel, type ApprovalStore } from "../lib/store"; type Props = { store: ApprovalStore }; export function ApprovalReact({ store }: Props) { const state = useSyncExternalStore(store.subscribe, store.getState); const current = state.pending[0]; const queue = state.pending.slice(1); const remaining = current ? remainingSeconds(current.expiresAt, state.now) : 0; const decide = (decision: Decision): void => { if (current) void store.decide(current.id, decision); }; return (
当前请求

{current ? current.tool : "没有待审批请求"}

{current && (
{remaining}s
)}
{current ? ( <>
{riskLabel(current.risk)} {current.detail}
) : (

队列已清空。用上方按钮模拟新的工具调用。

)}
排队 {queue.length}
    {queue.map((item) => (
  • {item.tool} {riskLabel(item.risk)}
  • ))}
永久允许{" "} {state.policies.length}
    {state.policies.map((tool) => (
  • {tool}
  • ))}
最近决定
); }