Fixed timestamp breaking api calls
All checks were successful
Publish Library / Build NPM Project (push) Successful in 34s
Publish Library / Tag Version (push) Successful in 8s

This commit is contained in:
2025-12-16 12:56:56 -05:00
parent 1a0351aeef
commit 0730f5f3f9
5 changed files with 26 additions and 28 deletions

View File

@@ -39,13 +39,13 @@ export class Anthropic extends LLMProvider {
if(history[i].role == 'tool') {
const h: any = history[i];
history.splice(i, 1,
{role: 'assistant', content: [{type: 'tool_use', id: h.id, name: h.name, input: h.args}], timestamp: h.timestamp},
{role: 'user', content: [{type: 'tool_result', tool_use_id: h.id, is_error: !!h.error, content: h.error || h.content}], timestamp: Date.now()}
{role: 'assistant', content: [{type: 'tool_use', id: h.id, name: h.name, input: h.args}]},
{role: 'user', content: [{type: 'tool_result', tool_use_id: h.id, is_error: !!h.error, content: h.error || h.content}]}
)
i++;
}
}
return history;
return history.map(({timestamp, ...h}) => h);
}
ask(message: string, options: LLMRequest = {}): AbortablePromise<LLMMessage[]> {
@@ -107,7 +107,7 @@ export class Anthropic extends LLMProvider {
loopMessages.push({role: 'assistant', content: resp.content, timestamp: Date.now()});
const toolCalls = resp.content.filter((c: any) => c.type === 'tool_use');
if(toolCalls.length && !controller.signal.aborted) {
history.push({role: 'assistant', content: resp.content, timestamp: Date.now()});
history.push({role: 'assistant', content: resp.content});
const results = await Promise.all(toolCalls.map(async (toolCall: any) => {
const tool = options.tools?.find(findByProp('name', toolCall.name));
if(!tool) return {tool_use_id: toolCall.id, is_error: true, content: 'Tool not found'};
@@ -118,9 +118,9 @@ export class Anthropic extends LLMProvider {
return {type: 'tool_result', tool_use_id: toolCall.id, is_error: true, content: err?.message || err?.toString() || 'Unknown'};
}
}));
const userMsg = {role: 'user', content: results, timestamp: Date.now()};
const userMsg = {role: 'user', content: results};
history.push(userMsg);
loopMessages.push(userMsg);
loopMessages.push({...userMsg, timestamp: Date.now()});
requestParams.messages = history;
}
} while (!controller.signal.aborted && resp.content.some((c: any) => c.type === 'tool_use'));