From 09a7d7c5e2ab9aba67c2379de91a52ea3ab3db52 Mon Sep 17 00:00:00 2001 From: digua Date: Sun, 31 May 2026 22:00:22 +0800 Subject: [PATCH] refactor: remove unused chart plugin and NLP API shims Both shims were installed only in web-serve mode. Chart modules already use useDataService() directly and NLP components use HTTP helpers, so the window.chatApi.pluginQuery/pluginCompute/ getMemberActivity/getAvailableYears and window.nlpApi shims have zero remaining callers. Co-authored-by: Cursor --- src/services/registry.ts | 39 --------------------------------------- 1 file changed, 39 deletions(-) diff --git a/src/services/registry.ts b/src/services/registry.ts index 63731944..bf3c94d3 100644 --- a/src/services/registry.ts +++ b/src/services/registry.ts @@ -110,48 +110,9 @@ async function initWebServeAdapters(): Promise { const { FetchPreferencesAdapter } = await import('./preferences/fetch') registerAdapter('preferences', new FetchPreferencesAdapter()) - await installChartPluginShims() - await installNlpApiShim() await installAiApiShims() } -/** - * Web-serve shims: chart modules and other code that may still reference - * window.chatApi.pluginQuery / pluginCompute / getMemberActivity / getAvailableYears. - * In Electron these are no longer used (charts call useDataService() directly). - */ -async function installChartPluginShims(): Promise { - const { useDataService } = await import('./data/service') - if (!(window as any).chatApi) { - ;(window as any).chatApi = {} - } - const chatApi = (window as any).chatApi - const dataService = useDataService() - - chatApi.pluginQuery = (sid: string, sql: string, params?: unknown[]) => - dataService.pluginQuery(sid, sql, params) - chatApi.pluginCompute = (_fnString: string, input: unknown): Promise => { - const fn = new Function('return ' + _fnString)() - return Promise.resolve(fn(input)) - } - chatApi.getMemberActivity = (sid: string, f?: any) => dataService.getMemberActivity(sid, f) - chatApi.getAvailableYears = (sid: string) => dataService.getAvailableYears(sid) -} - -async function installNlpApiShim(): Promise { - const { get, post, del } = await import('./utils/http') - ;(window as any).nlpApi = { - getWordFrequency: (params: unknown) => post('/nlp/word-frequency', params), - segmentText: (text: string, locale: string, minLength?: number) => - post('/nlp/segment', { text, locale, minLength }), - getPosTags: () => get('/nlp/pos-tags'), - getDictList: () => get('/nlp/dicts'), - isDictDownloaded: (dictId: string) => get(`/nlp/dicts/${dictId}/status`), - downloadDict: (dictId: string) => post(`/nlp/dicts/${dictId}/download`), - deleteDict: (dictId: string) => del(`/nlp/dicts/${dictId}`), - } -} - const WEB_STUB = { success: false as const, error: 'Not available in web mode' } async function installAiApiShims(): Promise {