#!/usr/bin/env node /** * 向 agent-node-lj-test 分批发短问题(长问题容器会处理失败) */ import { readFileSync } from 'node:fs'; import { homedir } from 'node:os'; import { join } from 'node:path'; const F = 'https://server.fmode.cn/api/functions'; const TARGET = 'agent-node-lj-test'; // 🔴 只问这个,不是 app-lj-test-v1 const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); const t = JSON.parse(readFileSync(join(homedir(), '.fmode/config/user.json'), 'utf8'))?.sessionToken; async function provision(id) { const r = await fetch(F, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ id: 'RP5Ht55NeX', token: t, params: { agentId: id } }) }); const j = await r.json(); const d = j.result ?? j; if (!d?.accessToken) throw new Error('provision 失败'); return d; } /** 分批发:每条都很短,避免容器处理不了长消息 */ const QUESTIONS = [ '你的回复是分几条消息发,还是攒成一整段才发?简短回答。', '你的回复会挂 Matrix thread 吗?就是 m.relates_to 里的 rel_type=m.thread。会还是不会?', 'display.tool_progress 和 display.interim_assistant_messages 现在是什么值?', ]; async function main() { const prov = await provision(TARGET); const agent = await provision(TARGET); console.log('目标容器:', TARGET, '| agentMxId:', agent.agentMxId); console.log('用户:', prov.userMxId); const mx = await import('matrix-js-sdk'); const c = mx.createClient({ baseUrl: prov.homeserver, accessToken: prov.accessToken, userId: prov.userMxId }); const room = (await c.createRoom({ invite: [agent.agentMxId], name: `ask-${Date.now()}`, preset: mx.Preset.TrustedPrivateChat })).room_id; console.log('房间:', room); const hs = prov.homeserver.replace(/\/$/, ''); const auth = { Authorization: `Bearer ${prov.accessToken}` }; for (let i = 0; i < 30; i++) { await sleep(3000); const r = await fetch(`${hs}/_matrix/client/v3/rooms/${encodeURIComponent(room)}/joined_members`, { headers: auth }).catch(() => null); const j = r ? await r.json().catch(() => ({})) : {}; if ((j.joined ?? {})[agent.agentMxId]) { console.log('容器已进房'); break; } } const seen = new Set(); for (const [i, q] of QUESTIONS.entries()) { console.log(`\n===== 问题 ${i + 1} =====`); console.log(q); const sent = await c.sendEvent(room, 'm.room.message', { msgtype: 'm.text', body: q, 'm.mentions': { user_ids: [agent.agentMxId] } }); seen.add(sent.event_id); const deadline = Date.now() + 180_000; let got = false; while (Date.now() < deadline && !got) { await sleep(6000); try { const r = await fetch(`${hs}/_matrix/client/v3/rooms/${encodeURIComponent(room)}/messages?dir=b&limit=30`, { headers: auth }); const j = await r.json(); for (const ev of (j.chunk ?? []).reverse()) { if (ev.type !== 'm.room.message' || seen.has(ev.event_id) || ev.sender === prov.userMxId) continue; seen.add(ev.event_id); const b = String(ev.content?.body ?? ''); console.log(` → 容器(${b.length}字):`, b.slice(0, 500).replace(/\n/g, ' ')); if (!/^[*·•]?\s*(🐍|💻|🔎|📖|✍️)/.test(b.trim())) got = true; } } catch { /* ignore */ } } if (!got) console.log(' ⚠️ 180 秒内无文字回复'); } console.log('\n房间保留:', room); c.stopClient(); } main().catch((e) => { console.error('失败:', e.message); process.exit(1); });