Fix Electron resolution for optional chromadb dependency
Replace dynamic ESM import with require() for chromadb to ensure Electron can resolve the package against the plugin's node_modules. Also wrap default fetch fallback in an arrow function to avoid potential strict mode issues with global fetch.
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
"use strict";
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
// If the importer is in node compatibility mode or this is not an ESM
|
||||
// file that has been converted to a CommonJS file using a Babel-
|
||||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||
mod
|
||||
));
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
|
||||
// src/main.ts
|
||||
@@ -194,7 +184,8 @@ var SemanticCacheService = class _SemanticCacheService {
|
||||
async initialize() {
|
||||
if (!this.config.enabled) return;
|
||||
try {
|
||||
const { ChromaClient } = await import("chromadb");
|
||||
const chromadb = require("chromadb");
|
||||
const { ChromaClient } = chromadb;
|
||||
const chromaURL = this.config.chromaURL || "http://localhost:8000";
|
||||
this.client = new ChromaClient({ path: chromaURL });
|
||||
this.collection = await this.client.getOrCreateCollection({
|
||||
@@ -285,7 +276,7 @@ var OllamaClient = class {
|
||||
this.currentStreamController = null;
|
||||
this.baseURL = baseURL;
|
||||
this.model = model;
|
||||
this.fetchFn = fetchFn ?? fetch;
|
||||
this.fetchFn = fetchFn ?? ((url, init) => fetch(url, init));
|
||||
if (cacheConfig?.enabled) {
|
||||
this.cacheService = new SemanticCacheService(baseURL, cacheConfig);
|
||||
void this.cacheService.initialize();
|
||||
|
||||
@@ -19,7 +19,7 @@ export class ContentVectorizer {
|
||||
constructor(config: VectorizationConfig, fetchFn?: typeof fetch) {
|
||||
this.model = config.model;
|
||||
this.ollamaUrl = config.ollamaUrl;
|
||||
this.fetchFn = fetchFn ?? fetch;
|
||||
this.fetchFn = fetchFn ?? ((url, init) => fetch(url, init));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,7 +22,7 @@ export class OllamaClient {
|
||||
constructor(baseURL: string, model: string, fetchFn?: typeof fetch, cacheConfig?: CacheConfig) {
|
||||
this.baseURL = baseURL;
|
||||
this.model = model;
|
||||
this.fetchFn = fetchFn ?? fetch;
|
||||
this.fetchFn = fetchFn ?? ((url, init) => fetch(url, init));
|
||||
|
||||
if (cacheConfig?.enabled) {
|
||||
this.cacheService = new SemanticCacheService(baseURL, cacheConfig);
|
||||
|
||||
@@ -20,9 +20,12 @@ export class SemanticCacheService {
|
||||
if (!this.config.enabled) return;
|
||||
|
||||
try {
|
||||
// Dynamic import — chromadb is optional and may not be installed.
|
||||
// This prevents the plugin from crashing at load time if chromadb is absent.
|
||||
const { ChromaClient } = await import('chromadb');
|
||||
// Dynamic require — chromadb is optional and may not be installed.
|
||||
// Using Node's require() instead of ESM import() so Electron can resolve
|
||||
// the external chromadb package against the plugin's node_modules.
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const chromadb = require('chromadb');
|
||||
const { ChromaClient } = chromadb;
|
||||
const chromaURL = this.config.chromaURL || 'http://localhost:8000';
|
||||
this.client = new ChromaClient({ path: chromaURL });
|
||||
this.collection = await this.client.getOrCreateCollection({
|
||||
|
||||
Reference in New Issue
Block a user