fix(server): skip embedding when not configured (#12544)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## 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.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
darkskygit
2025-05-26 12:52:15 +00:00
parent c2ffcb2c2c
commit eb26e99ecd
2 changed files with 8 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
const agent = globalThis.navigator?.userAgent ?? ''; const agent = globalThis.navigator?.userAgent ?? '';
const platform = globalThis.navigator?.platform; const platform = globalThis.navigator?.platform || globalThis.process?.platform;
export const IS_WEB = export const IS_WEB =
typeof window !== 'undefined' && typeof document !== 'undefined'; typeof window !== 'undefined' && typeof document !== 'undefined';
@@ -17,13 +17,13 @@ export const IS_IOS =
IS_SAFARI && IS_SAFARI &&
(/Mobile\/\w+/.test(agent) || globalThis.navigator?.maxTouchPoints > 2); (/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 = export const IS_IPAD =
/iPad/i.test(platform) || /iPad/i.test(platform) ||
/iPad/i.test(agent) || /iPad/i.test(agent) ||
(/Macintosh/i.test(agent) && globalThis.navigator?.maxTouchPoints > 2); (/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; export const IS_MOBILE = IS_IOS || IS_IPAD || IS_ANDROID;

View File

@@ -52,9 +52,11 @@ export class CopilotContextDocJob {
private async setup() { private async setup() {
this.supportEmbedding = this.supportEmbedding =
await this.models.copilotContext.checkEmbeddingAvailable(); await this.models.copilotContext.checkEmbeddingAvailable();
this.client = new OpenAIEmbeddingClient( if (this.supportEmbedding && this.config.copilot.providers.openai.apiKey) {
this.config.copilot.providers.openai this.client = new OpenAIEmbeddingClient(
); this.config.copilot.providers.openai
);
}
} }
// public this client to allow overriding in tests // public this client to allow overriding in tests