From dfccbac353f0cdcb9e1a98e974ab6e5884eaa6b9 Mon Sep 17 00:00:00 2001 From: Siddharth Ganesan Date: Fri, 14 Aug 2026 11:52:21 -0700 Subject: [PATCH] Persist resource side effects for in-band tool execution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Files/tables created through the internal execute route now register on the chat's resources exactly like the resume driver's executions — the route runs the same handleResourceSideEffects pass (persistence only; an out-of-band route has no live event sink, so mid-turn chip pushes are a follow-up). --- .../app/api/copilot/tools/execute/route.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/apps/sim/app/api/copilot/tools/execute/route.ts b/apps/sim/app/api/copilot/tools/execute/route.ts index 4aadb90aee..82c4392984 100644 --- a/apps/sim/app/api/copilot/tools/execute/route.ts +++ b/apps/sim/app/api/copilot/tools/execute/route.ts @@ -7,6 +7,8 @@ import { TraceAttr } from '@/lib/copilot/generated/trace-attributes-v1' import { TraceSpan } from '@/lib/copilot/generated/trace-spans-v1' import { checkInternalApiKey } from '@/lib/copilot/request/http' import { withIncomingGoSpan } from '@/lib/copilot/request/otel' +import { handleResourceSideEffects } from '@/lib/copilot/request/tools/resources' +import type { ToolCallResult } from '@/lib/copilot/request/types' import { createServerToolHandler } from '@/lib/copilot/tools/registry/server-tool-adapter' import { withRouteHandler } from '@/lib/core/utils/with-route-handler' @@ -77,6 +79,28 @@ export const POST = withRouteHandler((request: NextRequest) => error: result.error, }) } + if (result.success && chatId) { + // Persist created/deleted resources on the chat (file chips, table + // links) exactly like the resume driver does. No live event sink + // exists for an out-of-band route, so chips surface from the + // persisted chat resources rather than a mid-turn push. + const asToolResult = { success: result.success, output: result.output } as ToolCallResult + await handleResourceSideEffects( + toolName, + params, + asToolResult, + asToolResult, + chatId, + undefined, + () => false + ).catch((err) => { + logger.warn('In-band resource side effects failed', { + toolName, + toolCallId, + error: getErrorMessage(err), + }) + }) + } return NextResponse.json({ success: result.success, ...(result.output !== undefined ? { output: result.output } : {}),