fix: custom fetch for all providers (#6538)
* fix: custom fetch for all providers * fix: run in development should use built-in fetch
This commit is contained in:
parent
885da29f28
commit
568ee857d5
@ -6,7 +6,7 @@
|
|||||||
"build": {
|
"build": {
|
||||||
"frontendDist": "../web-app/dist",
|
"frontendDist": "../web-app/dist",
|
||||||
"devUrl": "http://localhost:1420",
|
"devUrl": "http://localhost:1420",
|
||||||
"beforeDevCommand": "cross-env IS_TAURI=true yarn dev:web",
|
"beforeDevCommand": "cross-env IS_TAURI=true IS_DEV=true yarn dev:web",
|
||||||
"beforeBuildCommand": "cross-env IS_TAURI=true yarn build:web"
|
"beforeBuildCommand": "cross-env IS_TAURI=true yarn build:web"
|
||||||
},
|
},
|
||||||
"app": {
|
"app": {
|
||||||
|
|||||||
@ -169,11 +169,12 @@ export const sendCompletion = async (
|
|||||||
providerName = 'openai-compatible'
|
providerName = 'openai-compatible'
|
||||||
|
|
||||||
const tokenJS = new TokenJS({
|
const tokenJS = new TokenJS({
|
||||||
apiKey: provider.api_key ?? (await getServiceHub().core().getAppToken()) ?? '',
|
apiKey:
|
||||||
|
provider.api_key ?? (await getServiceHub().core().getAppToken()) ?? '',
|
||||||
// TODO: Retrieve from extension settings
|
// TODO: Retrieve from extension settings
|
||||||
baseURL: provider.base_url,
|
baseURL: provider.base_url,
|
||||||
// Use Tauri's fetch to avoid CORS issues only for openai-compatible provider
|
// Use Tauri's fetch to avoid CORS issues only for openai-compatible provider
|
||||||
...(providerName === 'openai-compatible' && { fetch: getServiceHub().providers().fetch() }),
|
fetch: IS_DEV ? fetch : getServiceHub().providers().fetch(),
|
||||||
// OpenRouter identification headers for Jan
|
// OpenRouter identification headers for Jan
|
||||||
// ref: https://openrouter.ai/docs/api-reference/overview#headers
|
// ref: https://openrouter.ai/docs/api-reference/overview#headers
|
||||||
...(provider.provider === 'openrouter' && {
|
...(provider.provider === 'openrouter' && {
|
||||||
@ -183,10 +184,11 @@ export const sendCompletion = async (
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
// Add Origin header for local providers to avoid CORS issues
|
// Add Origin header for local providers to avoid CORS issues
|
||||||
...((provider.base_url?.includes('localhost:') || provider.base_url?.includes('127.0.0.1:')) && {
|
...((provider.base_url?.includes('localhost:') ||
|
||||||
|
provider.base_url?.includes('127.0.0.1:')) && {
|
||||||
fetch: getServiceHub().providers().fetch(),
|
fetch: getServiceHub().providers().fetch(),
|
||||||
defaultHeaders: {
|
defaultHeaders: {
|
||||||
'Origin': 'tauri://localhost',
|
Origin: 'tauri://localhost',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
} as ExtendedConfigOptions)
|
} as ExtendedConfigOptions)
|
||||||
@ -402,7 +404,10 @@ export const postMessageProcessing = async (
|
|||||||
console.log('Parsed tool parameters:', toolParameters)
|
console.log('Parsed tool parameters:', toolParameters)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to parse tool arguments:', error)
|
console.error('Failed to parse tool arguments:', error)
|
||||||
console.error('Raw arguments that failed:', toolCall.function.arguments)
|
console.error(
|
||||||
|
'Raw arguments that failed:',
|
||||||
|
toolCall.function.arguments
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const approved =
|
const approved =
|
||||||
@ -416,7 +421,9 @@ export const postMessageProcessing = async (
|
|||||||
)
|
)
|
||||||
: true)
|
: true)
|
||||||
|
|
||||||
const { promise, cancel } = getServiceHub().mcp().callToolWithCancellation({
|
const { promise, cancel } = getServiceHub()
|
||||||
|
.mcp()
|
||||||
|
.callToolWithCancellation({
|
||||||
toolName: toolCall.function.name,
|
toolName: toolCall.function.name,
|
||||||
arguments: toolCall.function.arguments.length ? toolParameters : {},
|
arguments: toolCall.function.arguments.length ? toolParameters : {},
|
||||||
})
|
})
|
||||||
|
|||||||
1
web-app/src/types/global.d.ts
vendored
1
web-app/src/types/global.d.ts
vendored
@ -22,6 +22,7 @@ declare global {
|
|||||||
declare const MODEL_CATALOG_URL: string
|
declare const MODEL_CATALOG_URL: string
|
||||||
declare const AUTO_UPDATER_DISABLED: boolean
|
declare const AUTO_UPDATER_DISABLED: boolean
|
||||||
declare const GA_MEASUREMENT_ID: string
|
declare const GA_MEASUREMENT_ID: string
|
||||||
|
declare const IS_DEV: boolean
|
||||||
interface Window {
|
interface Window {
|
||||||
core: AppCore | undefined
|
core: AppCore | undefined
|
||||||
gtag?: (...args: unknown[]) => void
|
gtag?: (...args: unknown[]) => void
|
||||||
|
|||||||
@ -40,6 +40,7 @@ export default defineConfig(({ mode }) => {
|
|||||||
},
|
},
|
||||||
define: {
|
define: {
|
||||||
IS_TAURI: JSON.stringify(process.env.IS_TAURI),
|
IS_TAURI: JSON.stringify(process.env.IS_TAURI),
|
||||||
|
IS_DEV: JSON.stringify(process.env.IS_DEV),
|
||||||
IS_WEB_APP: JSON.stringify(false),
|
IS_WEB_APP: JSON.stringify(false),
|
||||||
IS_MACOS: JSON.stringify(
|
IS_MACOS: JSON.stringify(
|
||||||
process.env.TAURI_ENV_PLATFORM?.includes('darwin') ?? false
|
process.env.TAURI_ENV_PLATFORM?.includes('darwin') ?? false
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user