aps-agent/scripts/pi-probe.mjs

29 lines
1.3 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env node
/**
* Pi 子进程接线探测(开发用)。
*
* 拉起 Pi、发一句话、把映射后的事件打出来。没有配置密钥时也能跑:
* 它会走到"模型不可用",正好用来验证进程、协议与错误映射这三段接线。
*
* 用法:node scripts/pi-probe.mjs [提问]
*/
import { createPiRuntime } from '@aps/server/agent/pi/runtime';
const prompt = process.argv[2] ?? '用一句话回答:1+1 等于几';
const runtime = createPiRuntime({ provider: process.env.APS_LLM_PROVIDER ?? 'deepseek', model: process.env.APS_LLM_MODEL ?? 'deepseek-chat', apiKey: process.env.APS_LLM_API_KEY ?? '', turnTimeoutMs: 30_000 });
console.log(`引擎:${runtime.name}`);
const session = await runtime.createSession({ sessionId: 'probe-1', subject: { userId: 'probe', tenantId: 'probe' }, projectId: null, tools: [] });
console.log(`会话已创建:${session.id}`);
const controller = new AbortController();
const started = Date.now();
try {
for await (const event of session.send(prompt, { signal: controller.signal })) {
console.log(`[${String(Date.now() - started).padStart(5)}ms] ${event.type}`, JSON.stringify(event).slice(0, 260));
if (event.type === 'turn_end') break;
}
} finally {
await session.dispose();
console.log('子进程已停止');
}