send msgs in webhook tool calls

This commit is contained in:
ramnique 2025-02-05 16:22:06 +05:30
parent 39282907d4
commit 80a98f1d7b
4 changed files with 10 additions and 2 deletions

View file

@ -1054,11 +1054,12 @@ export async function updateWebhookUrl(projectId: string, url: string) {
export async function executeClientTool(
toolCall: z.infer<typeof apiV1.AssistantMessageWithToolCalls>['tool_calls'][number],
messages: z.infer<typeof apiV1.ChatMessage>[],
projectId: string,
): Promise<unknown> {
await projectAuthCheck(projectId);
const result = await callClientToolWebhook(toolCall, projectId);
const result = await callClientToolWebhook(toolCall, messages, projectId);
return result;
}

View file

@ -118,7 +118,11 @@ export async function POST(
const toolCallResults = await Promise.all(lastMessage.tool_calls.map(async toolCall => {
console.log('executing tool call', toolCall);
try {
return await callClientToolWebhook(toolCall, session.projectId);
return await callClientToolWebhook(
toolCall,
[...messages, ...unsavedMessages],
session.projectId,
);
} catch (error) {
console.error(`Error executing tool call ${toolCall.id}:`, error);
return { error: "Tool execution failed" };

View file

@ -7,6 +7,7 @@ import crypto from "crypto";
export async function callClientToolWebhook(
toolCall: z.infer<typeof apiV1.AssistantMessageWithToolCalls>['tool_calls'][number],
messages: z.infer<typeof apiV1.ChatMessage>[],
projectId: string,
): Promise<unknown> {
const project = await projectsCollection.findOne({
@ -23,6 +24,7 @@ export async function callClientToolWebhook(
// prepare request body
const content = JSON.stringify({
toolCall,
messages,
} as z.infer<typeof ClientToolCallRequestBody>);
const requestId = crypto.randomUUID();
const bodyHash = crypto

View file

@ -443,6 +443,7 @@ function ClientToolCall({
try {
response = await executeClientTool(
toolCall,
messages,
projectId,
);
} catch (e) {