豆包复刻:原生安卓(Compose + 内嵌 Termux)+ Web / Windows
一个界面照着豆包抠的 AI 助手。主力是安卓端,完全离线自主:不依赖电脑、 不需要另外装 Termux。 安卓端 - 原生 Jetpack Compose,7 个页面,配色/圆角/间距对着真机截图量出来的 - 完整动效:抽屉滑入、页面切换、气泡淡入上移、面板底部升起、typing 三点、按钮回弹 - 内置 Termux:bash/apt/pkg 388 个命令、真 pty 终端; pty 不可用的 ROM 上自动降级成命令控制台 - APK 内嵌 CPython 3.13(Chaquopy),AI 内核跑在手机上 - 设备能力:定位 / 陀螺仪 / 加速度计 / 光线 / 电量 / 剪贴板 - 语音:朗读 + 语音输入,火山豆包音色 / OpenAI 兼容 / 设备自带三级引擎 AI 能力 - 10 家 OpenAI 兼容提供商:方舟 / OpenAI / DeepSeek / Kimi / 智谱 / 通义 / 硅基流动 / OpenRouter / 本地 Ollama / 自定义 - 思考强度按各家支持情况发不同字段(thinking / reasoning_effort / 不发), 认不出来的一律不发,避免给不支持的厂商发字段直接 400 - MCP 三种传输(http / stdio / inproc)、工具热加载、文件上传、权限模式 跨端 - 安卓走原生 Compose,Web / Windows 走 Lynx - Node 与 Python 两份内核接口逐字段一致,关键路径都有对拍脚本 自检脚本(都不需要真 Key) - verify-phone.mjs 设备端 24 项验收 - verify-speech.mjs 语音链路 31 项,两份内核各跑一遍 - parity-thinking.mjs 思考强度映射对拍 - probe-settings-wipe.mjs 设置防清空攻击测试 - mock-llm.mjs 假的 OpenAI + 火山语音服务 许可 MIT;第三方组件(Termux Apache-2.0、Chaquopy、Compose、LynxJS、Electron) 的授权见 LICENSE。
This commit is contained in:
79
scripts/probe-poll-cursor.mjs
Normal file
79
scripts/probe-poll-cursor.mjs
Normal file
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* 精确定位"轮询会不会重复投递事件"(不走 adb,直接 HTTP)。
|
||||
* 用法: node scripts/probe-poll-cursor.mjs [base]
|
||||
*/
|
||||
const BASE = process.argv[2] || 'http://127.0.0.1:5403';
|
||||
|
||||
const post = async (p, body) =>
|
||||
(await fetch(BASE + p, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
})).json();
|
||||
|
||||
const get = async (p) => (await fetch(BASE + p)).json();
|
||||
|
||||
console.log('起任务…');
|
||||
const started = await post('/api/chat', {
|
||||
conversationId: 'c_main',
|
||||
message: '用一句话解释什么是流式输出',
|
||||
history: [],
|
||||
transport: 'poll',
|
||||
});
|
||||
console.log(' runId =', started.runId);
|
||||
|
||||
let cursor = 0;
|
||||
let text = '';
|
||||
let reasoning = '';
|
||||
let done = false;
|
||||
const perPoll = [];
|
||||
let seq = 0;
|
||||
|
||||
while (!done && seq < 300) {
|
||||
const r = await get(`/api/chat/poll?runId=${started.runId}&cursor=${cursor}`);
|
||||
if (!r.ok) {
|
||||
console.log('轮询失败', r);
|
||||
break;
|
||||
}
|
||||
let addedText = 0;
|
||||
let addedEvents = 0;
|
||||
for (const e of r.events || []) {
|
||||
addedEvents += 1;
|
||||
if (e.type === 'delta') {
|
||||
text += e.text;
|
||||
addedText += e.text.length;
|
||||
}
|
||||
if (e.type === 'reasoning') reasoning += e.text;
|
||||
}
|
||||
perPoll.push({ seq, from: cursor, to: r.cursor, events: addedEvents, addedText });
|
||||
// 关键:游标必须由服务端给的 cursor 推进,且不能回退
|
||||
if (r.cursor < cursor) {
|
||||
console.log('❌ 服务端 cursor 回退了!', cursor, '→', r.cursor);
|
||||
break;
|
||||
}
|
||||
cursor = r.cursor;
|
||||
done = Boolean(r.done);
|
||||
seq += 1;
|
||||
if (!done) await new Promise((x) => setTimeout(x, 120));
|
||||
}
|
||||
|
||||
console.log(`\n轮询 ${perPoll.length} 次,正文累计 ${text.length} 字,思维链 ${reasoning.length} 字`);
|
||||
console.log('每次拉到的增量:');
|
||||
for (const p of perPoll.slice(0, 20)) {
|
||||
console.log(` #${p.seq} cursor ${p.from}→${p.to} 事件 ${p.events} 正文 +${p.addedText}`);
|
||||
}
|
||||
|
||||
// 和落库内容对比:这才是"真值"
|
||||
const conv = await get('/api/conversations/c_main');
|
||||
const stored = (conv.conversation.messages || []).filter((m) => m.role === 'assistant').pop();
|
||||
const storedText = stored?.content || '';
|
||||
console.log(`\n落库正文 ${storedText.length} 字`);
|
||||
console.log(`轮询累计 ${text.length} 字`);
|
||||
console.log(storedText.length === text.length
|
||||
? '✅ 完全一致:轮询没有重复投递'
|
||||
: `❌ 对不上:差 ${text.length - storedText.length} 字`);
|
||||
|
||||
if (storedText.length !== text.length) {
|
||||
console.log('\n落库:', storedText.slice(0, 100));
|
||||
console.log('累计:', text.slice(0, 100));
|
||||
}
|
||||
Reference in New Issue
Block a user