refactor(agent): 迁移AI会话引擎至pi-agent-core库
将原有基于Anthropic/OpenAI SDK的直播聊天代理重构为使用`@earendil-works/pi-agent-core`和`@earendil-works/pi-ai`库的统一API。 新增pi-bridge、pi-model、pi-persist、pi-tools四个模块,封装Agent路由、模型配置、消息持久化和工具适配逻辑。移除`chat.ts`中大量死代码,简化WebSocket处理流程。 BREAKING CHANGE: 移除`VideoAgent`类的`getAnthropicClient`、`getOpenAIClient`、`executeTool`等方法,外部调用需迁移至新pi-bridge API。`PROJECT_ROOT`路径计算方式变更,从`../../..`变为`../../`。
This commit is contained in:
18
web/server/agent/pi-tools.ts
Normal file
18
web/server/agent/pi-tools.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { AgentTool, AgentToolResult } from '@earendil-works/pi-agent-core';
|
||||
import type { ToolDefinition } from './tools/types';
|
||||
|
||||
export function createPiTools(tools: ToolDefinition[]): AgentTool[] {
|
||||
return tools.map((t): AgentTool => ({
|
||||
name: t.name,
|
||||
description: t.description,
|
||||
parameters: t.input_schema as any,
|
||||
label: t.name,
|
||||
execute: async (_toolCallId: string, params: any): Promise<AgentToolResult<any>> => {
|
||||
const result = await t.execute(params);
|
||||
return {
|
||||
content: [{ type: 'text' as const, text: result }],
|
||||
details: null,
|
||||
};
|
||||
},
|
||||
}));
|
||||
}
|
||||
Reference in New Issue
Block a user