feat: 接入 pi 原生能力——Usage Card、思考等级切换、压缩与分支摘要

This commit is contained in:
Rick Ye
2026-09-08 17:21:27 +08:00
parent adf3c3e118
commit e7da0f912e
12 changed files with 1378 additions and 159 deletions
+37
View File
@@ -141,6 +141,43 @@ export function registerIpc(): AgentService {
return pass(() => service.logoutProvider(providerId))
})
// ---- 思考等级 / 压缩 / 分支摘要(pi 原生能力) ----
ipcMain.handle('thinking:set', (_event, level: unknown) => {
if (typeof level !== 'string') throw new Error('invalid thinking level')
return pass(() => service.setThinkingLevel(level as never))
})
ipcMain.handle('session:compact', (_event, instructions: unknown) => {
if (instructions !== undefined && instructions !== null && typeof instructions !== 'string') {
throw new Error('invalid compaction instructions')
}
return pass(() => service.compactSession(instructions || undefined))
})
ipcMain.handle('session:compact:abort', () => pass(() => service.abortCompaction()))
ipcMain.handle('session:autoCompact', (_event, enabled: unknown) => {
if (typeof enabled !== 'boolean') throw new Error('invalid flag')
return pass(() => service.setAutoCompactionEnabled(enabled))
})
ipcMain.handle('session:forkPoints', () => pass(() => service.listForkPoints()))
ipcMain.handle('session:navigate', (_event, entryId: unknown, options: unknown) => {
if (typeof entryId !== 'string' || !entryId.trim()) throw new Error('invalid entry id')
const o = (options ?? {}) as { summarize?: unknown; customInstructions?: unknown }
if (o.summarize !== undefined && typeof o.summarize !== 'boolean') throw new Error('invalid navigate options')
if (o.customInstructions !== undefined && typeof o.customInstructions !== 'string') {
throw new Error('invalid navigate options')
}
return pass(() =>
service.navigateTree(entryId, {
...(o.summarize === true ? { summarize: true } : {}),
...(typeof o.customInstructions === 'string' ? { customInstructions: o.customInstructions } : {})
})
)
})
// ---- 应用设置 ----
ipcMain.handle('settings:get', () => service.getSettings())