mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-06 01:15:29 +08:00
feat: implement DS2API_HISTORY.txt transcript parser to merge history into chat messages
This commit is contained in:
@@ -58,3 +58,47 @@ test('chat history strict parser inserts history after system messages', async (
|
||||
{ role: 'user', content: 'latest' },
|
||||
]);
|
||||
});
|
||||
|
||||
test('chat history transcript parser replaces current input file placeholder', async () => {
|
||||
const {
|
||||
buildListModeMessages,
|
||||
} = await loadUtils();
|
||||
const t = (key) => key;
|
||||
const item = {
|
||||
messages: [{
|
||||
role: 'user',
|
||||
content: 'Continue from the latest state in the attached DS2API_HISTORY.txt context. Treat it as the current working state and answer the latest user request directly.',
|
||||
}],
|
||||
history_text: [
|
||||
'# DS2API_HISTORY.txt',
|
||||
'Prior conversation history and tool progress.',
|
||||
'',
|
||||
'=== 1. SYSTEM ===',
|
||||
'policy',
|
||||
'',
|
||||
'=== 2. USER ===',
|
||||
'hello',
|
||||
'',
|
||||
'=== 3. ASSISTANT ===',
|
||||
'hi',
|
||||
'',
|
||||
'=== 4. TOOL ===',
|
||||
'[name=search_web tool_call_id=call_1]',
|
||||
'{"ok":true}',
|
||||
'',
|
||||
'=== 5. USER ===',
|
||||
'latest',
|
||||
'',
|
||||
].join('\n'),
|
||||
};
|
||||
|
||||
const result = buildListModeMessages(item, t);
|
||||
assert.equal(result.historyMerged, true);
|
||||
assert.deepEqual(result.messages, [
|
||||
{ role: 'system', content: 'policy' },
|
||||
{ role: 'user', content: 'hello' },
|
||||
{ role: 'assistant', content: 'hi' },
|
||||
{ role: 'tool', content: '[name=search_web tool_call_id=call_1]\n{"ok":true}' },
|
||||
{ role: 'user', content: 'latest' },
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user