Skip to content

Commit 568ee85

Browse files
authored
fix: custom fetch for all providers (#6538)
* fix: custom fetch for all providers * fix: run in development should use built-in fetch
1 parent 885da29 commit 568ee85

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"build": {
77
"frontendDist": "../web-app/dist",
88
"devUrl": "http://localhost:1420",
9-
"beforeDevCommand": "cross-env IS_TAURI=true yarn dev:web",
9+
"beforeDevCommand": "cross-env IS_TAURI=true IS_DEV=true yarn dev:web",
1010
"beforeBuildCommand": "cross-env IS_TAURI=true yarn build:web"
1111
},
1212
"app": {

web-app/src/lib/completion.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,12 @@ export const sendCompletion = async (
169169
providerName = 'openai-compatible'
170170

171171
const tokenJS = new TokenJS({
172-
apiKey: provider.api_key ?? (await getServiceHub().core().getAppToken()) ?? '',
172+
apiKey:
173+
provider.api_key ?? (await getServiceHub().core().getAppToken()) ?? '',
173174
// TODO: Retrieve from extension settings
174175
baseURL: provider.base_url,
175176
// Use Tauri's fetch to avoid CORS issues only for openai-compatible provider
176-
...(providerName === 'openai-compatible' && { fetch: getServiceHub().providers().fetch() }),
177+
fetch: IS_DEV ? fetch : getServiceHub().providers().fetch(),
177178
// OpenRouter identification headers for Jan
178179
// ref: https://openrouter.ai/docs/api-reference/overview#headers
179180
...(provider.provider === 'openrouter' && {
@@ -183,10 +184,11 @@ export const sendCompletion = async (
183184
},
184185
}),
185186
// Add Origin header for local providers to avoid CORS issues
186-
...((provider.base_url?.includes('localhost:') || provider.base_url?.includes('127.0.0.1:')) && {
187+
...((provider.base_url?.includes('localhost:') ||
188+
provider.base_url?.includes('127.0.0.1:')) && {
187189
fetch: getServiceHub().providers().fetch(),
188190
defaultHeaders: {
189-
'Origin': 'tauri://localhost',
191+
Origin: 'tauri://localhost',
190192
},
191193
}),
192194
} as ExtendedConfigOptions)
@@ -402,7 +404,10 @@ export const postMessageProcessing = async (
402404
console.log('Parsed tool parameters:', toolParameters)
403405
} catch (error) {
404406
console.error('Failed to parse tool arguments:', error)
405-
console.error('Raw arguments that failed:', toolCall.function.arguments)
407+
console.error(
408+
'Raw arguments that failed:',
409+
toolCall.function.arguments
410+
)
406411
}
407412
}
408413
const approved =
@@ -416,10 +421,12 @@ export const postMessageProcessing = async (
416421
)
417422
: true)
418423

419-
const { promise, cancel } = getServiceHub().mcp().callToolWithCancellation({
420-
toolName: toolCall.function.name,
421-
arguments: toolCall.function.arguments.length ? toolParameters : {},
422-
})
424+
const { promise, cancel } = getServiceHub()
425+
.mcp()
426+
.callToolWithCancellation({
427+
toolName: toolCall.function.name,
428+
arguments: toolCall.function.arguments.length ? toolParameters : {},
429+
})
423430

424431
useAppState.getState().setCancelToolCall(cancel)
425432

web-app/src/types/global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ declare global {
2222
declare const MODEL_CATALOG_URL: string
2323
declare const AUTO_UPDATER_DISABLED: boolean
2424
declare const GA_MEASUREMENT_ID: string
25+
declare const IS_DEV: boolean
2526
interface Window {
2627
core: AppCore | undefined
2728
gtag?: (...args: unknown[]) => void

web-app/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export default defineConfig(({ mode }) => {
4040
},
4141
define: {
4242
IS_TAURI: JSON.stringify(process.env.IS_TAURI),
43+
IS_DEV: JSON.stringify(process.env.IS_DEV),
4344
IS_WEB_APP: JSON.stringify(false),
4445
IS_MACOS: JSON.stringify(
4546
process.env.TAURI_ENV_PLATFORM?.includes('darwin') ?? false

0 commit comments

Comments
 (0)