Skip to content

Commit 9bb9404

Browse files
committed
fix: custom fetch for all providers
1 parent 361c9ee commit 9bb9404

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

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: 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

0 commit comments

Comments
 (0)