Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions apps/sim/app/api/desktop/tool/authorize/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,25 @@ describe('desktop tool authorization', () => {
expect(claimPendingAsyncToolCall).toHaveBeenCalledWith('browser-tool', 'desktop-browser')
})

it('never returns presentation activity as an executable browser argument', async () => {
const fields = [{ elementId: 1, kind: 'text', text: 'a' }]
getAsyncToolCall.mockResolvedValueOnce({
toolCallId: 'form-tool',
runId: 'run-1',
status: 'pending',
toolName: 'browser_fill_form',
args: { activity: { description: 'Filling the form' }, fields },
})

const response = await POST(request('form-tool'))
expect(response.status).toBe(200)
expect(await response.json()).toEqual({
chatId: 'chat-1',
toolName: 'browser_fill_form',
args: { fields },
})
})

it('rejects retired browser tools retained only for history', async () => {
getAsyncToolCall.mockResolvedValueOnce({
toolCallId: 'retired-browser-tool',
Expand Down
7 changes: 4 additions & 3 deletions apps/sim/app/api/desktop/tool/authorize/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isCurrentBrowserToolName } from '@sim/browser-protocol'
import { isTerminalToolName } from '@sim/terminal-protocol'
import { isRecordLike } from '@sim/utils/object'
import { isRecordLike, omit } from '@sim/utils/object'
import { type NextRequest, NextResponse } from 'next/server'
import { authorizeDesktopToolContract } from '@/lib/api/contracts/desktop-tool-authorization'
import { parseRequest } from '@/lib/api/server'
Expand All @@ -24,7 +24,8 @@ import { isUserLocalVfsToolCall } from '@/lib/mothership/tools/local-filesystem'
* Electron calls this endpoint from the main process before every privileged
* native model action. It returns only server-persisted canonical tool args;
* Electron validates local-file requests against them and uses them directly
* for browser and terminal tools.
* for browser and terminal tools. The presentation-only `activity` field is
* dropped: desktop actions reject arguments they do not declare.
*/
export const POST = withRouteHandler(async (request: NextRequest) => {
const { userId, isAuthenticated } = await authenticateCopilotRequestSessionOnly()
Expand Down Expand Up @@ -117,7 +118,7 @@ export const POST = withRouteHandler(async (request: NextRequest) => {

return NextResponse.json({
toolName: toolCall.toolName,
args,
args: omit(args, ['activity']),
chatId: run.chatId,
})
})
Loading