message user clarifying

This commit is contained in:
dal 2025-08-15 14:48:41 -06:00
parent 641765b430
commit cdb7e4f17e
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
2 changed files with 40 additions and 6 deletions

View File

@ -1,24 +1,56 @@
import { updateMessageEntries } from '@buster/database';
import { wrapTraced } from 'braintrust'; import { wrapTraced } from 'braintrust';
import { createRawToolResultEntry } from '../../shared/create-raw-llm-tool-result-entry';
import type { import type {
MessageUserClarifyingQuestionContext, MessageUserClarifyingQuestionContext,
MessageUserClarifyingQuestionInput, MessageUserClarifyingQuestionInput,
MessageUserClarifyingQuestionOutput, MessageUserClarifyingQuestionOutput,
MessageUserClarifyingQuestionState, MessageUserClarifyingQuestionState,
} from './message-user-clarifying-question'; } from './message-user-clarifying-question';
import { MESSAGE_USER_CLARIFYING_QUESTION_TOOL_NAME } from './message-user-clarifying-question';
// Process message user clarifying question tool execution // Process message user clarifying question tool execution
async function processMessageUserClarifyingQuestion(): Promise<MessageUserClarifyingQuestionOutput> { async function processMessageUserClarifyingQuestion(
return {}; toolCallId: string,
messageId: string
): Promise<MessageUserClarifyingQuestionOutput> {
const output: MessageUserClarifyingQuestionOutput = {
success: true,
};
const rawToolResultEntry = createRawToolResultEntry(
toolCallId,
MESSAGE_USER_CLARIFYING_QUESTION_TOOL_NAME,
output
);
try {
await updateMessageEntries({
messageId,
rawLlmMessages: [rawToolResultEntry],
});
} catch (error) {
console.error('[message-user-clarifying-question] Error updating message entries:', error);
}
return output;
} }
// Factory function for execute callback // Factory function for execute callback
export function createMessageUserClarifyingQuestionExecute() { export function createMessageUserClarifyingQuestionExecute(
context: MessageUserClarifyingQuestionContext,
state: MessageUserClarifyingQuestionState
) {
// Wrap the execution with tracing // Wrap the execution with tracing
const executeMessageUserClarifyingQuestion = wrapTraced( const executeMessageUserClarifyingQuestion = wrapTraced(
async ( async (
_input: MessageUserClarifyingQuestionInput _input: MessageUserClarifyingQuestionInput
): Promise<MessageUserClarifyingQuestionOutput> => { ): Promise<MessageUserClarifyingQuestionOutput> => {
return processMessageUserClarifyingQuestion(); if (!state.toolCallId) {
throw new Error('Tool call ID is required');
}
return processMessageUserClarifyingQuestion(state.toolCallId, context.messageId);
}, },
{ name: 'Message User Clarifying Question' } { name: 'Message User Clarifying Question' }
); );

View File

@ -17,7 +17,9 @@ const MessageUserClarifyingQuestionInputSchema = z.object({
), ),
}); });
const MessageUserClarifyingQuestionOutputSchema = z.object({}); const MessageUserClarifyingQuestionOutputSchema = z.object({
success: z.boolean().describe('Whether the operation was successful'),
});
const MessageUserClarifyingQuestionContextSchema = z.object({ const MessageUserClarifyingQuestionContextSchema = z.object({
messageId: z.string().describe('The message ID of the message that triggered the tool'), messageId: z.string().describe('The message ID of the message that triggered the tool'),
@ -59,7 +61,7 @@ export function createMessageUserClarifyingQuestionTool(
}; };
// Create all functions with the context and state passed // Create all functions with the context and state passed
const execute = createMessageUserClarifyingQuestionExecute(); const execute = createMessageUserClarifyingQuestionExecute(context, state);
const onInputStart = createMessageUserClarifyingQuestionStart(context, state); const onInputStart = createMessageUserClarifyingQuestionStart(context, state);
const onInputDelta = createMessageUserClarifyingQuestionDelta(context, state); const onInputDelta = createMessageUserClarifyingQuestionDelta(context, state);
const onInputAvailable = createMessageUserClarifyingQuestionFinish(context, state); const onInputAvailable = createMessageUserClarifyingQuestionFinish(context, state);