mirror of https://github.com/buster-so/buster.git
todos cleanedup
This commit is contained in:
parent
6b171aae2e
commit
6d1a0b6c86
|
@ -257,18 +257,18 @@ export class FallbackModel implements LanguageModelV2 {
|
|||
} catch (error) {
|
||||
// Check if this is a normal stream termination
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
const isNormalTermination =
|
||||
errorMessage === 'terminated' ||
|
||||
const isNormalTermination =
|
||||
errorMessage === 'terminated' ||
|
||||
errorMessage.includes('terminated') ||
|
||||
errorMessage === 'aborted' ||
|
||||
errorMessage.includes('aborted');
|
||||
|
||||
|
||||
// If it's a normal termination and we've already streamed content, just close normally
|
||||
if (isNormalTermination && hasStreamedAny) {
|
||||
controller.close();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (self.settings.onError) {
|
||||
try {
|
||||
await self.settings.onError(error as RetryableError, self.modelId);
|
||||
|
|
|
@ -17,14 +17,14 @@ export function createTodosStepFinish(todosState: CreateTodosState, context: Cre
|
|||
|
||||
// Create final reasoning message with completed status
|
||||
const todosReasoningEntry = createTodosReasoningMessage(todosState);
|
||||
const todosRawMessage = createTodosRawLlmMessageEntry(todosState);
|
||||
const todosRawMessages = createTodosRawLlmMessageEntry(todosState);
|
||||
|
||||
try {
|
||||
if (todosReasoningEntry && todosRawMessage) {
|
||||
if (todosReasoningEntry && todosRawMessages) {
|
||||
await updateMessageEntries({
|
||||
messageId: context.messageId,
|
||||
reasoningMessages: [todosReasoningEntry],
|
||||
rawLlmMessages: [todosRawMessage],
|
||||
rawLlmMessages: todosRawMessages,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
|
|
|
@ -18,14 +18,14 @@ export function createTodosStepStart(todosState: CreateTodosState, context: Crea
|
|||
|
||||
// Create initial reasoning message with loading status
|
||||
const todosReasoningEntry = createTodosReasoningMessage(todosState, toolCallId);
|
||||
const todosRawMessage = createTodosRawLlmMessageEntry(todosState, toolCallId);
|
||||
const todosRawMessages = createTodosRawLlmMessageEntry(todosState, toolCallId);
|
||||
|
||||
try {
|
||||
if (todosReasoningEntry && todosRawMessage) {
|
||||
if (todosReasoningEntry && todosRawMessages) {
|
||||
await updateMessageEntries({
|
||||
messageId: context.messageId,
|
||||
reasoningMessages: [todosReasoningEntry],
|
||||
rawLlmMessages: [todosRawMessage],
|
||||
rawLlmMessages: todosRawMessages,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
|
|
|
@ -171,14 +171,6 @@ export async function runCreateTodosStep(params: CreateTodosParams): Promise<Cre
|
|||
],
|
||||
});
|
||||
|
||||
// Add the todos as a user message (for backward compatibility)
|
||||
if (todos) {
|
||||
resultMessages.push({
|
||||
role: 'user',
|
||||
content: `<todo_list>\n- Below are the items on your TODO list:\n${todos}\n</todo_list>`,
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
todos,
|
||||
messages: resultMessages,
|
||||
|
|
|
@ -50,28 +50,51 @@ export function createTodosReasoningMessage(
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates a raw LLM message entry for TODOs
|
||||
* This is stored as a raw user message in the database
|
||||
* Creates raw LLM message entries for TODOs as tool call and result
|
||||
* This is stored as tool messages in the database to preserve the original user message
|
||||
*/
|
||||
export function createTodosRawLlmMessageEntry(
|
||||
todosState: CreateTodosState,
|
||||
toolCallId?: string
|
||||
): ModelMessage | null {
|
||||
): ModelMessage[] | null {
|
||||
const id = todosState.entry_id || toolCallId;
|
||||
|
||||
if (!id || !todosState.todos) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
role: 'user',
|
||||
const messages: ModelMessage[] = [];
|
||||
|
||||
// Add assistant message with tool call
|
||||
messages.push({
|
||||
role: 'assistant',
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: `<todo_list>\n- Below are the items on your TODO list:\n${todosState.todos}\n</todo_list>`,
|
||||
type: 'tool-call',
|
||||
toolCallId: id,
|
||||
toolName: 'createTodos',
|
||||
input: {},
|
||||
},
|
||||
],
|
||||
};
|
||||
});
|
||||
|
||||
// Add tool result message
|
||||
messages.push({
|
||||
role: 'tool',
|
||||
content: [
|
||||
{
|
||||
type: 'tool-result',
|
||||
toolCallId: id,
|
||||
toolName: 'createTodos',
|
||||
output: {
|
||||
type: 'text',
|
||||
value: todosState.todos,
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
return messages;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue