buster/packages/ai/src/tools/communication-tools/respond-without-asset-creation/respond-without-asset-creat...

64 lines
2.1 KiB
TypeScript
Raw Normal View History

2025-08-16 04:58:46 +08:00
import { updateMessageEntries } from '@buster/database';
2025-08-08 07:10:24 +08:00
import { wrapTraced } from 'braintrust';
2025-08-16 04:58:46 +08:00
import { createRawToolResultEntry } from '../../shared/create-raw-llm-tool-result-entry';
import { createRespondWithoutAssetCreationRawLlmMessageEntry } from './helpers/respond-without-asset-creation-transform-helper';
2025-08-16 04:58:46 +08:00
import {
RESPOND_WITHOUT_ASSET_CREATION_TOOL_NAME,
type RespondWithoutAssetCreationContext,
type RespondWithoutAssetCreationInput,
type RespondWithoutAssetCreationOutput,
type RespondWithoutAssetCreationState,
2025-08-08 07:10:24 +08:00
} from './respond-without-asset-creation-tool';
2025-08-16 04:58:46 +08:00
async function processRespondWithoutAssetCreation(
state: RespondWithoutAssetCreationState,
2025-08-16 04:58:46 +08:00
toolCallId: string,
messageId: string
): Promise<RespondWithoutAssetCreationOutput> {
const output: RespondWithoutAssetCreationOutput = {
success: true,
};
// Create both the tool call and result messages to maintain proper ordering
const rawLlmMessage = createRespondWithoutAssetCreationRawLlmMessageEntry(state, toolCallId);
2025-08-16 04:58:46 +08:00
const rawToolResultEntry = createRawToolResultEntry(
toolCallId,
RESPOND_WITHOUT_ASSET_CREATION_TOOL_NAME,
output
);
try {
// Send both messages together: tool call followed by result
const rawLlmMessages = rawLlmMessage
? [rawLlmMessage, rawToolResultEntry]
: [rawToolResultEntry];
2025-08-16 04:58:46 +08:00
await updateMessageEntries({
messageId,
rawLlmMessages,
2025-08-16 04:58:46 +08:00
});
} catch (error) {
console.error('[respond-without-asset-creation] Error updating message entries:', error);
}
return output;
2025-08-08 07:10:24 +08:00
}
2025-08-16 04:58:46 +08:00
export function createRespondWithoutAssetCreationExecute(
context: RespondWithoutAssetCreationContext,
state: RespondWithoutAssetCreationState
) {
2025-08-08 07:10:24 +08:00
return wrapTraced(
2025-08-08 11:38:43 +08:00
async (
_input: RespondWithoutAssetCreationInput
): Promise<RespondWithoutAssetCreationOutput> => {
2025-08-16 04:58:46 +08:00
if (!state.toolCallId) {
throw new Error('Tool call ID is required');
}
return await processRespondWithoutAssetCreation(state, state.toolCallId, context.messageId);
2025-08-08 07:10:24 +08:00
},
2025-08-08 11:38:43 +08:00
{ name: 'Respond Without Asset Creation' }
2025-08-08 07:10:24 +08:00
);
}