-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtranscript-candidate.js
More file actions
37 lines (30 loc) · 1.04 KB
/
transcript-candidate.js
File metadata and controls
37 lines (30 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const builder = require('./transcript-normalizer');
const parser = require('./transcript-parser');
const candidateText = {};
function isTransientChrome(presetId, text) {
if (presetId === 'codex') {
return /^Working \(/.test(text) || /^esc to interrupt$/i.test(text);
}
if (presetId === 'claude-code') {
return /^(esc to interrupt|\? for shortcuts)$/i.test(text);
}
return false;
}
function parseLatestAgent(presetId, lines, users) {
const turns = parser.parseTurns(presetId, lines, users);
return turns?.length ? turns[turns.length - 1] : parser.parseLastAgentOnly(presetId, lines);
}
function update(id, presetId, lines, users) {
const last = parseLatestAgent(presetId, lines, users);
const text = last?.role === 'agent' ? builder.cleanAgentText(presetId, last.text) : '';
if (!text || isTransientChrome(presetId, text)) return '';
candidateText[id] = text;
return text;
}
function get(id) {
return candidateText[id] || '';
}
function clear(id) {
delete candidateText[id];
}
module.exports = { update, get, clear };