feat(ai): upgrade pi-ai from @mariozechner 0.54 to @earendil-works 0.74

- Replace @mariozechner/pi-ai and pi-agent-core with @earendil-works scope
- Adapt to AgentTool.execute() params type change (Record → unknown)
- Migrate Agent constructor to use initialState for systemPrompt/tools/messages
- Update onPayload callback signature to include model parameter
- Filter finalMessages with isPiMessage() for new AgentMessage union type
- Use state.errorMessage instead of deprecated state.error

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
diguaandCursor authored and digua committed 2026-05-26 23:19:47 +08:00
1 parent 0ba9ae04a6
commit 6c3d36e7df
17 files changed
+388 -1211

No files matched your search

+3 -2
View File
@@ -2,6 +2,7 @@
"name": "chatlab-cli",
"version": "0.0.0",
"description": "ChatLab CLI & Service - Chat history analysis tool",
"type": "module",
"bin": {
"chatlab": "bin/chatlab.mjs"
},
@@ -46,8 +47,8 @@
"dependencies": {
"@fastify/multipart": "^10.0.0",
"@fastify/static": "^9.1.3",
"@mariozechner/pi-agent-core": "0.54.2",
"@mariozechner/pi-ai": "0.54.2",
"@earendil-works/pi-agent-core": "0.74.2",
"@earendil-works/pi-ai": "0.74.2",
"@modelcontextprotocol/sdk": "^1.12.1",
"better-sqlite3": "^12.4.6",
"commander": "^13.1.0",
+4 -3
View File
@@ -1,7 +1,7 @@
/**
* 工具适配层
*
* 将 @openchatlab/tools 的 ToolDefinition 适配为 @mariozechner/pi-agent-core 的 AgentTool 格式。
* 将 @openchatlab/tools 的 ToolDefinition 适配为 @earendil-works/pi-agent-core 的 AgentTool 格式。
* 消息类工具返回 rawMessages 时自动执行预处理管道(清洗、去噪、脱敏、截断、格式化)。
*/
@@ -63,7 +63,8 @@ export function adaptToolsForAgent(
label: tool.name,
description: tool.description,
parameters: convertJsonSchemaToParameters(tool.inputSchema) as any,
async execute(_toolCallId: string, params: Record<string, unknown>): Promise<AgentToolResult<unknown>> {
async execute(_toolCallId: string, params: unknown): Promise<AgentToolResult<unknown>> {
const toolParams = (params && typeof params === 'object' ? params : {}) as Record<string, unknown>
const ctx = getContext()
const execCtx: ToolExecutionContext = {
db: ctx.db,
@@ -73,7 +74,7 @@ export function adaptToolsForAgent(
segmentText: (texts, locale, options) => batchSegmentWithFrequency(texts, locale as any, options as any),
}
try {
const result = await tool.handler(params, execCtx)
const result = await tool.handler(toolParams, execCtx)
if (result.rawMessages && result.rawMessages.length > 0) {
const pipelineResult = applyPreprocessingPipeline({