Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix: custom fetch for all providers (#6538)
Louis568ee857d59d
diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.jsonindex dd960fa5c..6aaa66bb7 100644--- a/src-tauri/tauri.conf.json+++ b/src-tauri/tauri.conf.json@@ -6,7 +6,7 @@"build": {"frontendDist": "../web-app/dist","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"},"app": {diff --git a/web-app/src/lib/completion.ts b/web-app/src/lib/completion.tsindex 023c39481..32f1bdc57 100644--- a/web-app/src/lib/completion.ts+++ b/web-app/src/lib/completion.ts@@ -169,11 +169,12 @@ export const sendCompletion = async (providerName = 'openai-compatible'const tokenJS = new TokenJS({- apiKey: provider.api_key ?? (await getServiceHub().core().getAppToken()) ?? '',+ apiKey:+ provider.api_key ?? (await getServiceHub().core().getAppToken()) ?? '',// TODO: Retrieve from extension settingsbaseURL: provider.base_url,// 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// ref: https://openrouter.ai/docs/api-reference/overview#headers...(provider.provider === 'openrouter' && {@@ -183,10 +184,11 @@ export const sendCompletion = async (},}),// 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(),defaultHeaders: {- 'Origin': 'tauri://localhost',+ Origin: 'tauri://localhost',},}),} as ExtendedConfigOptions)@@ -402,7 +404,10 @@ export const postMessageProcessing = async (console.log('Parsed tool parameters:', toolParameters)} catch (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 =@@ -416,10 +421,12 @@ export const postMessageProcessing = async (): true)- const { promise, cancel } = getServiceHub().mcp().callToolWithCancellation({- toolName: toolCall.function.name,- arguments: toolCall.function.arguments.length ? toolParameters : {},- })+ const { promise, cancel } = getServiceHub()+ .mcp()+ .callToolWithCancellation({+ toolName: toolCall.function.name,+ arguments: toolCall.function.arguments.length ? toolParameters : {},+ })useAppState.getState().setCancelToolCall(cancel)diff --git a/web-app/src/types/global.d.ts b/web-app/src/types/global.d.tsindex 9f0f30dff..c22539146 100644--- a/web-app/src/types/global.d.ts+++ b/web-app/src/types/global.d.ts@@ -22,6 +22,7 @@ declare global {declare const MODEL_CATALOG_URL: stringdeclare const AUTO_UPDATER_DISABLED: booleandeclare const GA_MEASUREMENT_ID: string+ declare const IS_DEV: booleaninterface Window {core: AppCore | undefinedgtag?: (...args: unknown[]) => voiddiff --git a/web-app/vite.config.ts b/web-app/vite.config.tsindex efd3f8647..317f219e2 100644--- a/web-app/vite.config.ts+++ b/web-app/vite.config.ts@@ -40,6 +40,7 @@ export default defineConfig(({ mode }) => {},define: {IS_TAURI: JSON.stringify(process.env.IS_TAURI),+ IS_DEV: JSON.stringify(process.env.IS_DEV),IS_WEB_APP: JSON.stringify(false),IS_MACOS: JSON.stringify(process.env.TAURI_ENV_PLATFORM?.includes('darwin') ?? false