feat: 实现关键帧检测与成本控制

- EdgeProcessor:sampleFrame 降采样 160x120 + compareFrames 像素差异对比
- 重复画面跳过:similarity > 0.9 时不发送 query
- 混合采样策略:静默 5s / 用户说话 1s(docs/08-成本控制.md)
- 请求统计:queryCount + totalTokens 实时显示
- App 状态栏显示成本统计

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-06-13 14:38:15 +08:00
parent 8dc59d2c09
commit 2c6489b9a6
5 changed files with 157 additions and 14 deletions

View File

@@ -0,0 +1,43 @@
// ============================================================
// Sampling — 混合采样策略
// 来源docs/08-成本控制.md — "定时低频 + 事件高频"
// ============================================================
/** 静默时采样间隔ms */
const IDLE_INTERVAL = 5000;
/** 用户说话时采样间隔ms */
const ACTIVE_INTERVAL = 1000;
export class SamplingController {
private lastSampleTime = 0;
private _isUserSpeaking = false;
/** 设置用户是否正在说话 */
set speaking(value: boolean) {
this._isUserSpeaking = value;
}
get speaking(): boolean {
return this._isUserSpeaking;
}
/** 当前采样间隔 */
get interval(): number {
return this._isUserSpeaking ? ACTIVE_INTERVAL : IDLE_INTERVAL;
}
/** 是否应该采样(基于时间间隔) */
shouldSample(): boolean {
const now = Date.now();
if (now - this.lastSampleTime < this.interval) {
return false;
}
this.lastSampleTime = now;
return true;
}
/** 强制允许下次采样(如用户刚说完话时) */
resetTimer(): void {
this.lastSampleTime = 0;
}
}