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) {
|
} catch (error) {
|
||||||
// Check if this is a normal stream termination
|
// Check if this is a normal stream termination
|
||||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||||
const isNormalTermination =
|
const isNormalTermination =
|
||||||
errorMessage === 'terminated' ||
|
errorMessage === 'terminated' ||
|
||||||
errorMessage.includes('terminated') ||
|
errorMessage.includes('terminated') ||
|
||||||
errorMessage === 'aborted' ||
|
errorMessage === 'aborted' ||
|
||||||
errorMessage.includes('aborted');
|
errorMessage.includes('aborted');
|
||||||
|
|
||||||
// If it's a normal termination and we've already streamed content, just close normally
|
// If it's a normal termination and we've already streamed content, just close normally
|
||||||
if (isNormalTermination && hasStreamedAny) {
|
if (isNormalTermination && hasStreamedAny) {
|
||||||
controller.close();
|
controller.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.settings.onError) {
|
if (self.settings.onError) {
|
||||||
try {
|
try {
|
||||||
await self.settings.onError(error as RetryableError, self.modelId);
|
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
|
// Create final reasoning message with completed status
|
||||||
const todosReasoningEntry = createTodosReasoningMessage(todosState);
|
const todosReasoningEntry = createTodosReasoningMessage(todosState);
|
||||||
const todosRawMessage = createTodosRawLlmMessageEntry(todosState);
|
const todosRawMessages = createTodosRawLlmMessageEntry(todosState);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (todosReasoningEntry && todosRawMessage) {
|
if (todosReasoningEntry && todosRawMessages) {
|
||||||
await updateMessageEntries({
|
await updateMessageEntries({
|
||||||
messageId: context.messageId,
|
messageId: context.messageId,
|
||||||
reasoningMessages: [todosReasoningEntry],
|
reasoningMessages: [todosReasoningEntry],
|
||||||
rawLlmMessages: [todosRawMessage],
|
rawLlmMessages: todosRawMessages,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -18,14 +18,14 @@ export function createTodosStepStart(todosState: CreateTodosState, context: Crea
|
||||||
|
|
||||||
// Create initial reasoning message with loading status
|
// Create initial reasoning message with loading status
|
||||||
const todosReasoningEntry = createTodosReasoningMessage(todosState, toolCallId);
|
const todosReasoningEntry = createTodosReasoningMessage(todosState, toolCallId);
|
||||||
const todosRawMessage = createTodosRawLlmMessageEntry(todosState, toolCallId);
|
const todosRawMessages = createTodosRawLlmMessageEntry(todosState, toolCallId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (todosReasoningEntry && todosRawMessage) {
|
if (todosReasoningEntry && todosRawMessages) {
|
||||||
await updateMessageEntries({
|
await updateMessageEntries({
|
||||||
messageId: context.messageId,
|
messageId: context.messageId,
|
||||||
reasoningMessages: [todosReasoningEntry],
|
reasoningMessages: [todosReasoningEntry],
|
||||||
rawLlmMessages: [todosRawMessage],
|
rawLlmMessages: todosRawMessages,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} 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 {
|
return {
|
||||||
todos,
|
todos,
|
||||||
messages: resultMessages,
|
messages: resultMessages,
|
||||||
|
|
|
@ -50,28 +50,51 @@ export function createTodosReasoningMessage(
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a raw LLM message entry for TODOs
|
* Creates raw LLM message entries for TODOs as tool call and result
|
||||||
* This is stored as a raw user message in the database
|
* This is stored as tool messages in the database to preserve the original user message
|
||||||
*/
|
*/
|
||||||
export function createTodosRawLlmMessageEntry(
|
export function createTodosRawLlmMessageEntry(
|
||||||
todosState: CreateTodosState,
|
todosState: CreateTodosState,
|
||||||
toolCallId?: string
|
toolCallId?: string
|
||||||
): ModelMessage | null {
|
): ModelMessage[] | null {
|
||||||
const id = todosState.entry_id || toolCallId;
|
const id = todosState.entry_id || toolCallId;
|
||||||
|
|
||||||
if (!id || !todosState.todos) {
|
if (!id || !todosState.todos) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
const messages: ModelMessage[] = [];
|
||||||
role: 'user',
|
|
||||||
|
// Add assistant message with tool call
|
||||||
|
messages.push({
|
||||||
|
role: 'assistant',
|
||||||
content: [
|
content: [
|
||||||
{
|
{
|
||||||
type: 'text',
|
type: 'tool-call',
|
||||||
text: `<todo_list>\n- Below are the items on your TODO list:\n${todosState.todos}\n</todo_list>`,
|
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