From eb26e99ecd23323c47d7d85f2f5277f8bf3adf9e Mon Sep 17 00:00:00 2001 From: darkskygit Date: Mon, 26 May 2025 12:52:15 +0000 Subject: [PATCH] fix(server): skip embedding when not configured (#12544) ## Summary by CodeRabbit - **Bug Fixes** - Improved reliability by ensuring certain features are only enabled when required support and configuration are present, reducing the risk of runtime errors. - Enhanced platform detection logic for better accuracy across different environments, including macOS and Windows systems. --- blocksuite/framework/global/src/env/index.ts | 6 +++--- .../backend/server/src/plugins/copilot/context/job.ts | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/blocksuite/framework/global/src/env/index.ts b/blocksuite/framework/global/src/env/index.ts index 98a62649f7..afbe24ecf9 100644 --- a/blocksuite/framework/global/src/env/index.ts +++ b/blocksuite/framework/global/src/env/index.ts @@ -1,5 +1,5 @@ const agent = globalThis.navigator?.userAgent ?? ''; -const platform = globalThis.navigator?.platform; +const platform = globalThis.navigator?.platform || globalThis.process?.platform; export const IS_WEB = typeof window !== 'undefined' && typeof document !== 'undefined'; @@ -17,13 +17,13 @@ export const IS_IOS = IS_SAFARI && (/Mobile\/\w+/.test(agent) || globalThis.navigator?.maxTouchPoints > 2); -export const IS_MAC = /Mac/i.test(platform); +export const IS_MAC = /Mac/i.test(platform) || /darwin/.test(platform); export const IS_IPAD = /iPad/i.test(platform) || /iPad/i.test(agent) || (/Macintosh/i.test(agent) && globalThis.navigator?.maxTouchPoints > 2); -export const IS_WINDOWS = /Win/.test(platform); +export const IS_WINDOWS = /Win/.test(platform) || /win32/.test(platform); export const IS_MOBILE = IS_IOS || IS_IPAD || IS_ANDROID; diff --git a/packages/backend/server/src/plugins/copilot/context/job.ts b/packages/backend/server/src/plugins/copilot/context/job.ts index 1e25e57e3d..05c2e3c883 100644 --- a/packages/backend/server/src/plugins/copilot/context/job.ts +++ b/packages/backend/server/src/plugins/copilot/context/job.ts @@ -52,9 +52,11 @@ export class CopilotContextDocJob { private async setup() { this.supportEmbedding = await this.models.copilotContext.checkEmbeddingAvailable(); - this.client = new OpenAIEmbeddingClient( - this.config.copilot.providers.openai - ); + if (this.supportEmbedding && this.config.copilot.providers.openai.apiKey) { + this.client = new OpenAIEmbeddingClient( + this.config.copilot.providers.openai + ); + } } // public this client to allow overriding in tests