import { Fragment } from "react"; import { App, Button, Input, Tooltip } from "antd"; import copyToClipboard from "copy-to-clipboard"; import { Copy, KeyRound, Link2, PlugZap } from "lucide-react"; import { canvasThemes } from "@/lib/canvas-theme"; const AGENT_CONNECT_STEPS = [ { title: "方式一:在 Codex 中使用插件", text: "在 Codex app 安装 Infinite Canvas 插件后,通过插件启动画布,插件会自动启动本地 Agent 并带上连接信息。" }, { title: "方式二:直接运行 Agent", text: "不使用 Codex 插件时,在终端运行下面命令,再回到网页里连接或手动填入 Local URL 和 Connect token。", command: "npx -y @basketikun/canvas-agent" }, ]; const AGENT_PLUGIN_REMOVE_COMMAND = "codex plugin remove infinite-canvas"; const AGENT_MCP_REMOVE_COMMAND = "codex mcp remove infinite-canvas"; export function AgentConnectView({ theme, url, token, enabled, connected, activity, connectError, onUrlChange, onTokenChange, onToggleEnabled, }: { theme: (typeof canvasThemes)[keyof typeof canvasThemes]; url: string; token: string; enabled: boolean; connected: boolean; activity: string; connectError: string; onUrlChange: (value: string) => void; onTokenChange: (value: string) => void; onToggleEnabled: () => void; }) { const { message } = App.useApp(); const statusText = connectError ? "连接失败" : connected ? activity : enabled ? "连接中" : "未连接"; const statusColor = connectError ? "#dc2626" : connected ? "#16a34a" : enabled ? "#d97706" : theme.node.muted; const copyCommand = (command: string) => { copyToClipboard(command); message.success("命令已复制"); }; const codexPluginReminder = (
Codex 插件提醒
只有安装 Codex 插件或手动添加 MCP 后,工具列表才会进入 Codex 上下文并增加 token 消耗;仅运行 `npx -y @basketikun/canvas-agent` 启动本地 Agent 不会安装 MCP。
{[ ["移除插件", AGENT_PLUGIN_REMOVE_COMMAND], ["移除手动 MCP", AGENT_MCP_REMOVE_COMMAND], ].map(([label, command]) => (
{label} {command}
))}
); return (
连接本地 Agent
按使用场景选择一种连接方式。
{AGENT_CONNECT_STEPS.map((step, index) => { const command = "command" in step ? step.command : ""; return (
{step.title}
{step.text}
{command ? (
{command}
) : null}
{index === 0 ? codexPluginReminder : null}
); })}
网页连接 {statusText}
默认自动读取 Local URL 和 Connect token,失败时再手动填写。
{connectError ? (
{connectError}
) : null}
); }