From 80a98f1d7b5e40c404b41211ff98d4167a9c244f Mon Sep 17 00:00:00 2001 From: ramnique <30795890+ramnique@users.noreply.github.com> Date: Wed, 5 Feb 2025 16:22:06 +0530 Subject: [PATCH] send msgs in webhook tool calls --- apps/rowboat/app/actions.ts | 3 ++- apps/rowboat/app/api/widget/v1/chats/[chatId]/turn/route.ts | 6 +++++- apps/rowboat/app/lib/utils.ts | 2 ++ .../app/projects/[projectId]/playground/messages.tsx | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/rowboat/app/actions.ts b/apps/rowboat/app/actions.ts index 7f5d6fde..fef6f4ab 100644 --- a/apps/rowboat/app/actions.ts +++ b/apps/rowboat/app/actions.ts @@ -1054,11 +1054,12 @@ export async function updateWebhookUrl(projectId: string, url: string) { export async function executeClientTool( toolCall: z.infer['tool_calls'][number], + messages: z.infer[], projectId: string, ): Promise { await projectAuthCheck(projectId); - const result = await callClientToolWebhook(toolCall, projectId); + const result = await callClientToolWebhook(toolCall, messages, projectId); return result; } diff --git a/apps/rowboat/app/api/widget/v1/chats/[chatId]/turn/route.ts b/apps/rowboat/app/api/widget/v1/chats/[chatId]/turn/route.ts index ee6f1633..99abed42 100644 --- a/apps/rowboat/app/api/widget/v1/chats/[chatId]/turn/route.ts +++ b/apps/rowboat/app/api/widget/v1/chats/[chatId]/turn/route.ts @@ -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" }; diff --git a/apps/rowboat/app/lib/utils.ts b/apps/rowboat/app/lib/utils.ts index cfa2efaa..e754d488 100644 --- a/apps/rowboat/app/lib/utils.ts +++ b/apps/rowboat/app/lib/utils.ts @@ -7,6 +7,7 @@ import crypto from "crypto"; export async function callClientToolWebhook( toolCall: z.infer['tool_calls'][number], + messages: z.infer[], projectId: string, ): Promise { 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); const requestId = crypto.randomUUID(); const bodyHash = crypto diff --git a/apps/rowboat/app/projects/[projectId]/playground/messages.tsx b/apps/rowboat/app/projects/[projectId]/playground/messages.tsx index 13035bbe..41f8f118 100644 --- a/apps/rowboat/app/projects/[projectId]/playground/messages.tsx +++ b/apps/rowboat/app/projects/[projectId]/playground/messages.tsx @@ -443,6 +443,7 @@ function ClientToolCall({ try { response = await executeClientTool( toolCall, + messages, projectId, ); } catch (e) {