Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 7 additions & 0 deletions apps/sim/app/api/copilot/checkpoints/revert/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ describe('Copilot Checkpoints Revert API Route', () => {
setupCommonApiMocks()
mockCryptoUuid()

// Mock getBaseUrl to return localhost for tests
vi.doMock('@/lib/urls/utils', () => ({
getBaseUrl: vi.fn(() => 'http://localhost:3000'),
getBaseDomain: vi.fn(() => 'localhost:3000'),
getEmailDomain: vi.fn(() => 'localhost:3000'),
}))

mockSelect.mockReturnValue({ from: mockFrom })
mockFrom.mockReturnValue({ where: mockWhere })
mockWhere.mockReturnValue({ then: mockThen })
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/app/api/copilot/checkpoints/revert/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '@/lib/copilot/auth'
import { createLogger } from '@/lib/logs/console/logger'
import { validateUUID } from '@/lib/security/input-validation'
import { getBaseUrl } from '@/lib/urls/utils'

const logger = createLogger('CheckpointRevertAPI')

Expand Down Expand Up @@ -93,7 +94,7 @@ export async function POST(request: NextRequest) {
}

const stateResponse = await fetch(
`${request.nextUrl.origin}/api/workflows/${checkpoint.workflowId}/state`,
`${getBaseUrl()}/api/workflows/${checkpoint.workflowId}/state`,
{
method: 'PUT',
headers: {
Expand Down
11 changes: 10 additions & 1 deletion apps/sim/lib/knowledge/documents/document-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,20 @@ async function parseWithMistralOCR(fileUrl: string, filename: string, mimeType:
url = `${getBaseUrl()}${url}`
}

const headers =
let headers =
typeof mistralParserTool.request!.headers === 'function'
? mistralParserTool.request!.headers(params)
: mistralParserTool.request!.headers

if (url.includes('/api/tools/mistral/parse')) {
const { generateInternalToken } = await import('@/lib/auth/internal')
const internalToken = await generateInternalToken()
headers = {
...headers,
Authorization: `Bearer ${internalToken}`,
}
}

const requestBody = mistralParserTool.request!.body!(params) as OCRRequestBody
return makeOCRRequest(url, headers as Record<string, string>, requestBody)
},
Expand Down
17 changes: 11 additions & 6 deletions apps/sim/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,13 +451,18 @@ async function handleInternalRequest(
}

const headers = new Headers(requestParams.headers)
const isInternalRoute = endpointUrl.startsWith('/api/')
if (typeof window === 'undefined') {
try {
const internalToken = await generateInternalToken()
headers.set('Authorization', `Bearer ${internalToken}`)
logger.info(`[${requestId}] Added internal auth token for ${toolId}`)
} catch (error) {
logger.error(`[${requestId}] Failed to generate internal token for ${toolId}:`, error)
if (isInternalRoute) {
try {
const internalToken = await generateInternalToken()
headers.set('Authorization', `Bearer ${internalToken}`)
logger.info(`[${requestId}] Added internal auth token for ${toolId}`)
} catch (error) {
logger.error(`[${requestId}] Failed to generate internal token for ${toolId}:`, error)
}
} else {
logger.info(`[${requestId}] Skipping internal auth token for external URL: ${endpointUrl}`)
}
}

Expand Down
Loading