uni-flow 公开 API(中文注解) / HttpAdapter
Class: HttpAdapter
Defined in: adapters/http-adapter.ts:49
通过 HTTP 调用远程 Unit 的 RuntimeAdapter。
适用于跨项目 / Workflow-as-Unit:本进程发 POST,对端返回标准 AgentOutput。 steer / followUp 在此适配器中为空操作(需靠后续 execute 传递)。
Example
const adapter = createHttpAdapter({
endpoint: 'http://127.0.0.1:3100/execute',
fetchFn: async () =>
new Response(
JSON.stringify({
content: 'remote-ok',
toolCalls: [],
stopReason: 'stop',
metadata: {},
}),
{ status: 200, headers: { 'Content-Type': 'application/json' } },
),
});Implements
Constructors
Constructor
new HttpAdapter(
config):HttpAdapter
Defined in: adapters/http-adapter.ts:57
Parameters
config
端点、头与可选 fetchFn
Returns
HttpAdapter
Properties
type
readonlytype:"http"
Defined in: adapters/http-adapter.ts:50
适配器类型标签。
Implementation of
Methods
cancel()
cancel():
void
Defined in: adapters/http-adapter.ts:108
标记本地取消意图(进行中的 fetch 仍依赖 abortSignal)。
Returns
void
Implementation of
execute()
execute(
input,ctx):Promise<AgentOutput>
Defined in: adapters/http-adapter.ts:67
POST config.endpoint,将 { input, context: ctx } 发往远端并解析为 AgentOutput。
Parameters
input
标准 Agent 输入(含可选 params)
ctx
执行上下文;abortSignal 会传给 fetch
Returns
Promise<AgentOutput>
远端返回的 AgentOutput
Throws
当 HTTP 状态非 2xx 时抛出错误
Implementation of
followUp()
followUp(
_content):void
Defined in: adapters/http-adapter.ts:94
HTTP 适配器不缓冲追问;需在后续 execute 中自行携带。
Parameters
_content
string
Returns
void
Implementation of
frameworkInfo()
frameworkInfo():
object
Defined in: adapters/http-adapter.ts:115
Returns
object
固定为 { name: 'http', version: '1.0.0' }
name
name:
string
version
version:
string
Implementation of
steer()
steer(
_content):void
Defined in: adapters/http-adapter.ts:89
HTTP 适配器不缓冲转向;需在后续 execute 中自行携带。
Parameters
_content
string
Returns
void
Implementation of
subscribe()
subscribe(
handler):Unsubscribe
Defined in: adapters/http-adapter.ts:100
Parameters
handler
运行时事件回调
Returns
取消订阅函数