mirror of https://github.com/buster-so/buster.git
flip done tool stuff
This commit is contained in:
parent
940ab3f59f
commit
641765b430
|
@ -14,7 +14,7 @@ import {
|
|||
// Using keyof with the inferred type ensures we're using the actual schema keys
|
||||
const FINAL_RESPONSE_KEY = 'finalResponse' as const satisfies keyof DoneToolInput;
|
||||
|
||||
export function createDoneToolDelta(doneToolState: DoneToolState, context: DoneToolContext) {
|
||||
export function createDoneToolDelta(context: DoneToolContext, doneToolState: DoneToolState) {
|
||||
return async function doneToolDelta(
|
||||
options: { inputTextDelta: string } & ToolCallOptions
|
||||
): Promise<void> {
|
||||
|
|
|
@ -30,7 +30,7 @@ async function processDone(toolCallId: string, messageId: string): Promise<DoneT
|
|||
}
|
||||
|
||||
// Factory function that creates the execute function with proper context typing
|
||||
export function createDoneToolExecute(state: DoneToolState, context: DoneToolContext) {
|
||||
export function createDoneToolExecute(context: DoneToolContext, state: DoneToolState) {
|
||||
return wrapTraced(
|
||||
async (_input: DoneToolInput): Promise<DoneToolOutput> => {
|
||||
if (!state.toolCallId) {
|
||||
|
|
|
@ -6,7 +6,7 @@ import {
|
|||
createDoneToolResponseMessage,
|
||||
} from './helpers/done-tool-transform-helper';
|
||||
|
||||
export function createDoneToolFinish(doneToolState: DoneToolState, context: DoneToolContext) {
|
||||
export function createDoneToolFinish(context: DoneToolContext, doneToolState: DoneToolState) {
|
||||
return async function doneToolFinish(
|
||||
options: { input: DoneToolInput } & ToolCallOptions
|
||||
): Promise<void> {
|
||||
|
|
|
@ -12,7 +12,7 @@ import {
|
|||
} from './helpers/done-tool-transform-helper';
|
||||
|
||||
// Factory function that creates a type-safe callback for the specific agent context
|
||||
export function createDoneToolStart(doneToolState: DoneToolState, context: DoneToolContext) {
|
||||
export function createDoneToolStart(context: DoneToolContext, doneToolState: DoneToolState) {
|
||||
return async function doneToolStart(options: ToolCallOptions): Promise<void> {
|
||||
doneToolState.toolCallId = options.toolCallId;
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ describe('Done Tool Streaming Tests', () => {
|
|||
finalResponse: undefined,
|
||||
};
|
||||
|
||||
const startHandler = createDoneToolStart(state, mockContext);
|
||||
const startHandler = createDoneToolStart(mockContext, state);
|
||||
const options: ToolCallOptions = {
|
||||
toolCallId: 'tool-call-123',
|
||||
messages: [],
|
||||
|
@ -41,7 +41,7 @@ describe('Done Tool Streaming Tests', () => {
|
|||
finalResponse: undefined,
|
||||
};
|
||||
|
||||
const startHandler = createDoneToolStart(state, mockContext);
|
||||
const startHandler = createDoneToolStart(mockContext, state);
|
||||
|
||||
const messages: ModelMessage[] = [
|
||||
{
|
||||
|
@ -97,7 +97,7 @@ describe('Done Tool Streaming Tests', () => {
|
|||
finalResponse: undefined,
|
||||
};
|
||||
|
||||
const startHandler = createDoneToolStart(state, mockContext);
|
||||
const startHandler = createDoneToolStart(mockContext, state);
|
||||
const options: ToolCallOptions = {
|
||||
toolCallId: 'tool-call-456',
|
||||
messages: [],
|
||||
|
@ -119,7 +119,7 @@ describe('Done Tool Streaming Tests', () => {
|
|||
finalResponse: undefined,
|
||||
};
|
||||
|
||||
const startHandler = createDoneToolStart(state, contextWithoutMessageId);
|
||||
const startHandler = createDoneToolStart(contextWithoutMessageId, state);
|
||||
const options: ToolCallOptions = {
|
||||
toolCallId: 'tool-call-789',
|
||||
messages: [],
|
||||
|
@ -138,7 +138,7 @@ describe('Done Tool Streaming Tests', () => {
|
|||
finalResponse: undefined,
|
||||
};
|
||||
|
||||
const deltaHandler = createDoneToolDelta(state, mockContext);
|
||||
const deltaHandler = createDoneToolDelta(mockContext, state);
|
||||
|
||||
await deltaHandler({
|
||||
inputTextDelta: '{"final_',
|
||||
|
@ -164,7 +164,7 @@ describe('Done Tool Streaming Tests', () => {
|
|||
finalResponse: undefined,
|
||||
};
|
||||
|
||||
const deltaHandler = createDoneToolDelta(state, mockContext);
|
||||
const deltaHandler = createDoneToolDelta(mockContext, state);
|
||||
|
||||
await deltaHandler({
|
||||
inputTextDelta: '{"final_response": "This is a partial response that is still being',
|
||||
|
@ -183,7 +183,7 @@ describe('Done Tool Streaming Tests', () => {
|
|||
finalResponse: undefined,
|
||||
};
|
||||
|
||||
const deltaHandler = createDoneToolDelta(state, mockContext);
|
||||
const deltaHandler = createDoneToolDelta(mockContext, state);
|
||||
|
||||
await deltaHandler({
|
||||
inputTextDelta: '{"final_response": "Complete response message"}',
|
||||
|
@ -202,7 +202,7 @@ describe('Done Tool Streaming Tests', () => {
|
|||
finalResponse: undefined,
|
||||
};
|
||||
|
||||
const deltaHandler = createDoneToolDelta(state, mockContext);
|
||||
const deltaHandler = createDoneToolDelta(mockContext, state);
|
||||
|
||||
const markdownContent = `## Summary
|
||||
|
||||
|
@ -227,7 +227,7 @@ describe('Done Tool Streaming Tests', () => {
|
|||
finalResponse: undefined,
|
||||
};
|
||||
|
||||
const deltaHandler = createDoneToolDelta(state, mockContext);
|
||||
const deltaHandler = createDoneToolDelta(mockContext, state);
|
||||
|
||||
await deltaHandler({
|
||||
inputTextDelta: '{"final_response": "Line 1\\nLine 2\\n\\"Quoted text\\""}',
|
||||
|
@ -245,7 +245,7 @@ describe('Done Tool Streaming Tests', () => {
|
|||
finalResponse: undefined,
|
||||
};
|
||||
|
||||
const deltaHandler = createDoneToolDelta(state, mockContext);
|
||||
const deltaHandler = createDoneToolDelta(mockContext, state);
|
||||
|
||||
await deltaHandler({
|
||||
inputTextDelta: '{"other_field": "value"}',
|
||||
|
@ -264,7 +264,7 @@ describe('Done Tool Streaming Tests', () => {
|
|||
finalResponse: undefined,
|
||||
};
|
||||
|
||||
const deltaHandler = createDoneToolDelta(state, mockContext);
|
||||
const deltaHandler = createDoneToolDelta(mockContext, state);
|
||||
|
||||
await deltaHandler({
|
||||
inputTextDelta: '{"final_response": ""}',
|
||||
|
@ -285,7 +285,7 @@ describe('Done Tool Streaming Tests', () => {
|
|||
finalResponse: 'Final message',
|
||||
};
|
||||
|
||||
const finishHandler = createDoneToolFinish(state, mockContext);
|
||||
const finishHandler = createDoneToolFinish(mockContext, state);
|
||||
|
||||
const input: DoneToolInput = {
|
||||
finalResponse: 'This is the final response message',
|
||||
|
@ -307,7 +307,7 @@ describe('Done Tool Streaming Tests', () => {
|
|||
finalResponse: undefined,
|
||||
};
|
||||
|
||||
const finishHandler = createDoneToolFinish(state, mockContext);
|
||||
const finishHandler = createDoneToolFinish(mockContext, state);
|
||||
|
||||
const input: DoneToolInput = {
|
||||
finalResponse: 'Response without prior start',
|
||||
|
@ -329,7 +329,7 @@ describe('Done Tool Streaming Tests', () => {
|
|||
finalResponse: undefined,
|
||||
};
|
||||
|
||||
const finishHandler = createDoneToolFinish(state, mockContext);
|
||||
const finishHandler = createDoneToolFinish(mockContext, state);
|
||||
|
||||
const markdownResponse = `
|
||||
## Analysis Complete
|
||||
|
@ -378,8 +378,8 @@ The following items were processed:
|
|||
finalResponse: undefined,
|
||||
};
|
||||
|
||||
const handler1 = createDoneToolStart(state, validContext);
|
||||
const handler2 = createDoneToolStart(state, extendedContext);
|
||||
const handler1 = createDoneToolStart(validContext, state);
|
||||
const handler2 = createDoneToolStart(extendedContext, state);
|
||||
|
||||
expect(handler1).toBeDefined();
|
||||
expect(handler2).toBeDefined();
|
||||
|
@ -392,9 +392,9 @@ The following items were processed:
|
|||
finalResponse: undefined,
|
||||
};
|
||||
|
||||
const startHandler = createDoneToolStart(state, mockContext);
|
||||
const deltaHandler = createDoneToolDelta(state, mockContext);
|
||||
const finishHandler = createDoneToolFinish(state, mockContext);
|
||||
const startHandler = createDoneToolStart(mockContext, state);
|
||||
const deltaHandler = createDoneToolDelta(mockContext, state);
|
||||
const finishHandler = createDoneToolFinish(mockContext, state);
|
||||
|
||||
await startHandler({ toolCallId: 'test-123', messages: [] });
|
||||
expect(state.toolCallId).toBeTypeOf('string');
|
||||
|
@ -423,9 +423,9 @@ The following items were processed:
|
|||
finalResponse: undefined,
|
||||
};
|
||||
|
||||
const startHandler = createDoneToolStart(state, mockContext);
|
||||
const deltaHandler = createDoneToolDelta(state, mockContext);
|
||||
const finishHandler = createDoneToolFinish(state, mockContext);
|
||||
const startHandler = createDoneToolStart(mockContext, state);
|
||||
const deltaHandler = createDoneToolDelta(mockContext, state);
|
||||
const finishHandler = createDoneToolFinish(mockContext, state);
|
||||
|
||||
const toolCallId = 'streaming-test-123';
|
||||
|
||||
|
@ -471,7 +471,7 @@ The following items were processed:
|
|||
finalResponse: undefined,
|
||||
};
|
||||
|
||||
const deltaHandler = createDoneToolDelta(state, mockContext);
|
||||
const deltaHandler = createDoneToolDelta(mockContext, state);
|
||||
|
||||
const chunks = [
|
||||
'{"final_response": "',
|
||||
|
|
|
@ -49,7 +49,7 @@ describe('Done Tool Integration Tests', () => {
|
|||
finalResponse: undefined,
|
||||
};
|
||||
|
||||
const startHandler = createDoneToolStart(state, mockContext);
|
||||
const startHandler = createDoneToolStart(mockContext, state);
|
||||
const toolCallId = randomUUID();
|
||||
|
||||
await startHandler({ toolCallId, messages: [] });
|
||||
|
@ -71,8 +71,8 @@ describe('Done Tool Integration Tests', () => {
|
|||
finalResponse: undefined,
|
||||
};
|
||||
|
||||
const startHandler = createDoneToolStart(state, mockContext);
|
||||
const deltaHandler = createDoneToolDelta(state, mockContext);
|
||||
const startHandler = createDoneToolStart(mockContext, state);
|
||||
const deltaHandler = createDoneToolDelta(mockContext, state);
|
||||
const toolCallId = randomUUID();
|
||||
|
||||
await startHandler({ toolCallId, messages: [] });
|
||||
|
@ -99,8 +99,8 @@ describe('Done Tool Integration Tests', () => {
|
|||
finalResponse: undefined,
|
||||
};
|
||||
|
||||
const startHandler = createDoneToolStart(state, mockContext);
|
||||
const finishHandler = createDoneToolFinish(state, mockContext);
|
||||
const startHandler = createDoneToolStart(mockContext, state);
|
||||
const finishHandler = createDoneToolFinish(mockContext, state);
|
||||
const toolCallId = randomUUID();
|
||||
|
||||
await startHandler({ toolCallId, messages: [] });
|
||||
|
@ -129,9 +129,9 @@ describe('Done Tool Integration Tests', () => {
|
|||
finalResponse: undefined,
|
||||
};
|
||||
|
||||
const startHandler = createDoneToolStart(state, mockContext);
|
||||
const deltaHandler = createDoneToolDelta(state, mockContext);
|
||||
const finishHandler = createDoneToolFinish(state, mockContext);
|
||||
const startHandler = createDoneToolStart(mockContext, state);
|
||||
const deltaHandler = createDoneToolDelta(mockContext, state);
|
||||
const finishHandler = createDoneToolFinish(mockContext, state);
|
||||
const toolCallId = randomUUID();
|
||||
|
||||
await startHandler({ toolCallId, messages: [] });
|
||||
|
@ -194,11 +194,11 @@ All operations completed successfully.`;
|
|||
finalResponse: undefined,
|
||||
};
|
||||
|
||||
const startHandler1 = createDoneToolStart(state1, mockContext);
|
||||
const finishHandler1 = createDoneToolFinish(state1, mockContext);
|
||||
const startHandler1 = createDoneToolStart(mockContext, state1);
|
||||
const finishHandler1 = createDoneToolFinish(mockContext, state1);
|
||||
|
||||
const startHandler2 = createDoneToolStart(state2, mockContext);
|
||||
const finishHandler2 = createDoneToolFinish(state2, mockContext);
|
||||
const startHandler2 = createDoneToolStart(mockContext, state2);
|
||||
const finishHandler2 = createDoneToolFinish(mockContext, state2);
|
||||
|
||||
const toolCallId1 = randomUUID();
|
||||
const toolCallId2 = randomUUID();
|
||||
|
@ -242,7 +242,7 @@ All operations completed successfully.`;
|
|||
finalResponse: undefined,
|
||||
};
|
||||
|
||||
const startHandler = createDoneToolStart(state, invalidContext);
|
||||
const startHandler = createDoneToolStart(invalidContext, state);
|
||||
const toolCallId = randomUUID();
|
||||
|
||||
await expect(startHandler({ toolCallId, messages: [] })).resolves.not.toThrow();
|
||||
|
@ -261,7 +261,7 @@ All operations completed successfully.`;
|
|||
workflowStartTime: Date.now(),
|
||||
};
|
||||
|
||||
const deltaHandler = createDoneToolDelta(state, invalidContext);
|
||||
const deltaHandler = createDoneToolDelta(invalidContext, state);
|
||||
const toolCallId = randomUUID();
|
||||
|
||||
await expect(
|
||||
|
@ -284,7 +284,7 @@ All operations completed successfully.`;
|
|||
finalResponse: undefined,
|
||||
};
|
||||
|
||||
const startHandler = createDoneToolStart(state, mockContext);
|
||||
const startHandler = createDoneToolStart(mockContext, state);
|
||||
const toolCallId = randomUUID();
|
||||
|
||||
await startHandler({ toolCallId, messages: [] });
|
||||
|
@ -328,7 +328,7 @@ All operations completed successfully.`;
|
|||
],
|
||||
});
|
||||
|
||||
const deltaHandler = createDoneToolDelta(state, mockContext);
|
||||
const deltaHandler = createDoneToolDelta(mockContext, state);
|
||||
const toolCallId = randomUUID();
|
||||
|
||||
await deltaHandler({
|
||||
|
|
|
@ -53,10 +53,10 @@ export function createDoneTool(context: DoneToolContext) {
|
|||
finalResponse: undefined,
|
||||
};
|
||||
|
||||
const execute = createDoneToolExecute(state, context);
|
||||
const onInputStart = createDoneToolStart(state, context);
|
||||
const onInputDelta = createDoneToolDelta(state, context);
|
||||
const onInputAvailable = createDoneToolFinish(state, context);
|
||||
const execute = createDoneToolExecute(context, state);
|
||||
const onInputStart = createDoneToolStart(context, state);
|
||||
const onInputDelta = createDoneToolDelta(context, state);
|
||||
const onInputAvailable = createDoneToolFinish(context, state);
|
||||
|
||||
return tool({
|
||||
description:
|
||||
|
|
Loading…
Reference in New Issue