Files
BridgeSwarm/native-host/qvac/events.js
T
snxraven b711ba0447
CI / Build & Test (push) Failing after 53s
Add QVAC
2026-09-02 14:17:10 -04:00

39 lines
1.1 KiB
JavaScript

/**
* Normalize QVAC completion stream events for cap-chunk (keep under NMH ~1 MB).
*/
const MAX_DELTA = 64 * 1024;
function clip(s) {
const t = s == null ? '' : String(s);
if (t.length <= MAX_DELTA) return t;
return t.slice(0, MAX_DELTA);
}
function normalizeCompletionEvent(ev) {
if (!ev || !ev.type) return null;
if (ev.type === 'contentDelta') {
return { type: 'contentDelta', delta: clip(ev.delta || ev.text || ev.content || '') };
}
if (ev.type === 'thinkingDelta') {
return { type: 'thinkingDelta', delta: clip(ev.delta || ev.text || ev.content || '') };
}
if (ev.type === 'toolCall') {
const call = ev.call || ev.toolCall || ev;
return {
type: 'toolCall',
call: {
id: call.id,
name: call.name,
arguments: call.arguments != null ? call.arguments : call.args,
},
};
}
if (ev.type === 'rawDelta') {
return { type: 'rawDelta', delta: clip(ev.delta) };
}
return { type: ev.type, delta: ev.delta != null ? clip(ev.delta) : undefined, call: ev.call };
}
module.exports = { normalizeCompletionEvent, MAX_DELTA };