API Reference

AgentHTTP

Agent 的 HTTP 传输层 — 通过 HTTP 暴露会话访问

AgentHTTP

AgentHTTP 是本地 Agent 的 HTTP 传输层,暴露 RemoteAgent 所需的 Session API、plugin action 和 Shell 审批端点。

需要额外安装 @downcity/server

pnpm add @downcity/server

最小示例

import { AgentHTTP } from "@downcity/server";
import { Agent } from "@downcity/agent";

const agent = new Agent({ id: "demo", path: process.cwd() });
const http = new AgentHTTP(agent);

const binding = await http.server().listen({ host: "127.0.0.1", port: 5314 });
// HTTP 服务监听在 http://127.0.0.1:5314

构造参数

new AgentHTTP(agent: Agent)
参数类型说明
agentAgent已构造好的本地 Agent 实例

方法

listen(options)

启动 HTTP 服务。

const binding = await http.server().listen({
  host: "127.0.0.1",
  port: 5314,
});

close()

停止 HTTP 服务。

await http.close();

另见:AgentRPC 轻量 RPC 传输层。