Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ› fix(local-system): forward all grepContent params + move executor to /client (#14888)

Arvin Xu2d088ca6e25f
diff --git a/apps/desktop/electron.vite.config.ts b/apps/desktop/electron.vite.config.ts
index 406a9c595d7..62730ad4a11 100644
--- a/apps/desktop/electron.vite.config.ts
+++ b/apps/desktop/electron.vite.config.ts
@@ -123,12 +123,40 @@ export default defineConfig({
'utf-8-validate',
],
output: {
- // Prevent debug package from being bundled into index.js to avoid side-effect pollution
+ // Prevent shared deps from being bundled into index.js to avoid side-effect pollution.
+ // Pattern: when a module is imported by both the main bundle (statically) and a
+ // dynamic-import chunk (lazy loader), rolldown places it in main and makes the
+ // chunk back-reference `require("./index.js")`. Electron's main entry isn't in
+ // Node's CJS cache, so that require recompiles `index.js` from scratch β€” which
+ // re-runs `new App()` at top-level and triggers `protocol.registerSchemesAsPrivileged`
+ // *after* the app is ready β†’ throw.
+ //
+ // Same root cause as the original `debug` regression fixed in #11827. Isolate
+ // each shared module into its own vendor chunk so both ends reference the vendor
+ // chunk instead of back-referencing main.
manualChunks(id) {
if (id.includes('node_modules/debug')) {
return 'vendor-debug';
}
+ // Small text/binary detection utilities in file-loaders/utils. Imported by
+ // main (via `sniffBinaryFile`) and potentially by lazy loader chunks.
+ // Explicitly enumerated to avoid catching `parser-utils.ts`, which pulls in
+ // xmldom / yauzl / concat-stream β€” those belong in docx/pptx loader chunks.
+ if (
+ /packages\/file-loaders\/src\/utils\/(?:detectUtf16|isBinaryContent|isTextReadableFile)\.ts$/.test(
+ id,
+ )
+ ) {
+ return 'vendor-file-loaders-utils';
+ }
+
+ // jszip β€” imported by main (via some static path) AND by the docx loader chunk.
+ // Without this, reading a .docx file throws the protocol re-init error.
+ if (id.includes('node_modules/jszip')) {
+ return 'vendor-jszip';
+ }
+
// Split i18n json resources by namespace (ns), not by locale.
// Example: ".../resources/locales/zh-CN/common.json?import" -> "locales-common"
const normalizedId = id.replaceAll('\\', '/').split('?')[0];
diff --git a/apps/desktop/src/main/modules/contentSearch/__tests__/base.test.ts b/apps/desktop/src/main/modules/contentSearch/__tests__/base.test.ts
index d2515afdb13..8c5401e7e02 100644
--- a/apps/desktop/src/main/modules/contentSearch/__tests__/base.test.ts
+++ b/apps/desktop/src/main/modules/contentSearch/__tests__/base.test.ts
@@ -49,6 +49,10 @@ class TestContentSearch extends BaseContentSearch {
public testGetDefaultIgnorePatterns(): string[] {
return this.getDefaultIgnorePatterns();
}
+
+ public testResolveSearchPath(params: GrepContentParams): string {
+ return this.resolveSearchPath(params);
+ }
}
describe('BaseContentSearch', () => {
@@ -255,6 +259,33 @@ describe('BaseContentSearch', () => {
});
});
+ describe('resolveSearchPath', () => {
+ it('prefers scope when path is not set', () => {
+ const resolved = contentSearch.testResolveSearchPath({
+ pattern: 'x',
+ scope: '/Users/arvinxx/repo',
+ });
+
+ expect(resolved).toBe('/Users/arvinxx/repo');
+ });
+
+ it('honors legacy path over scope when both are set', () => {
+ const resolved = contentSearch.testResolveSearchPath({
+ path: '/legacy/path',
+ pattern: 'x',
+ scope: '/scope/path',
+ });
+
+ expect(resolved).toBe('/legacy/path');
+ });
+
+ it('falls back to process.cwd() when neither is provided', () => {
+ const resolved = contentSearch.testResolveSearchPath({ pattern: 'x' });
+
+ expect(resolved).toBe(process.cwd());
+ });
+ });
+
describe('getDefaultIgnorePatterns', () => {
it('should return default ignore patterns', () => {
const patterns = contentSearch.testGetDefaultIgnorePatterns();
diff --git a/apps/desktop/src/main/modules/contentSearch/base.ts b/apps/desktop/src/main/modules/contentSearch/base.ts
index c5f57e91651..cde5524cad3 100644
--- a/apps/desktop/src/main/modules/contentSearch/base.ts
+++ b/apps/desktop/src/main/modules/contentSearch/base.ts
@@ -46,6 +46,18 @@ export abstract class BaseContentSearch {
*/
abstract checkToolAvailable(tool: string): Promise<boolean>;
+ /**
+ * Resolve the directory to run the search in.
+ *
+ * The builtin-tool manifest documents `scope`, while the legacy IPC type also accepts
+ * `path`. Read both so an agent calling with `scope` (per the manifest) doesn't silently
+ * fall through to `process.cwd()` β€” which in a packaged Electron app isn't the project
+ * root and therefore has no `.gitignore` for ripgrep to honor.
+ */
+ protected resolveSearchPath(params: GrepContentParams): string {
+ return params.path ?? params.scope ?? process.cwd();
+ }
+
/**
* Build command-line arguments for grep tools
*/
@@ -141,11 +153,8 @@ export abstract class BaseContentSearch {
* Grep using Node.js native implementation (fallback)
*/
protected async grepWithNodejs(params: GrepContentParams): Promise<GrepContentResult> {
- const {
- pattern,
- path: searchPath = process.cwd(),
- output_mode = 'files_with_matches',
- } = params;
+ const { pattern, output_mode = 'files_with_matches' } = params;
+ const searchPath = this.resolveSearchPath(params);
const logPrefix = `[grepContent:nodejs]`;
const flags = `${params['-i'] ? 'i' : ''}${params.multiline ? 's' : ''}`;
diff --git a/apps/desktop/src/main/modules/contentSearch/impl/unix.ts b/apps/desktop/src/main/modules/contentSearch/impl/unix.ts
index d8c1ad825e5..050fa0d746c 100644
--- a/apps/desktop/src/main/modules/contentSearch/impl/unix.ts
+++ b/apps/desktop/src/main/modules/contentSearch/impl/unix.ts
@@ -1,4 +1,3 @@
-
import type { GrepContentParams, GrepContentResult } from '@lobechat/electron-client-ipc';
import { execa } from 'execa';
@@ -179,7 +178,8 @@ export abstract class UnixContentSearch extends BaseContentSearch {
tool: 'rg' | 'ag' | 'grep',
params: GrepContentParams,
): Promise<GrepContentResult> {
- const { path: searchPath = process.cwd(), output_mode = 'files_with_matches' } = params;
+ const { output_mode = 'files_with_matches' } = params;
+ const searchPath = this.resolveSearchPath(params);
const logPrefix = `[grepContent:${tool}]`;
try {
@@ -272,7 +272,7 @@ export abstract class UnixContentSearch extends BaseContentSearch {
try {
const { stdout } = await execa(tool, args, {
- cwd: params.path || process.cwd(),
+ cwd: this.resolveSearchPath(params),
reject: false,
});
diff --git a/apps/desktop/src/main/modules/contentSearch/impl/windows.ts b/apps/desktop/src/main/modules/contentSearch/impl/windows.ts
index a2d044abd39..4551d865125 100644
--- a/apps/desktop/src/main/modules/contentSearch/impl/windows.ts
+++ b/apps/desktop/src/main/modules/contentSearch/impl/windows.ts
@@ -1,4 +1,3 @@
-
import type { GrepContentParams, GrepContentResult } from '@lobechat/electron-client-ipc';
import { execa } from 'execa';
@@ -146,7 +145,8 @@ export class WindowsContentSearchImpl extends BaseContentSearch {
* Grep using ripgrep (rg) - cross-platform
*/
private async grepWithRipgrep(params: GrepContentParams): Promise<GrepContentResult> {
- const { path: searchPath = process.cwd(), output_mode = 'files_with_matches' } = params;
+ const { output_mode = 'files_with_matches' } = params;
+ const searchPath = this.resolveSearchPath(params);
const logPrefix = `[grepContent:rg]`;
try {
@@ -230,7 +230,7 @@ export class WindowsContentSearchImpl extends BaseContentSearch {
try {
const { stdout } = await execa('rg', args, {
- cwd: params.path || process.cwd(),
+ cwd: this.resolveSearchPath(params),
reject: false,
});
@@ -252,11 +252,8 @@ export class WindowsContentSearchImpl extends BaseContentSearch {
* Note: findstr has limited functionality compared to ripgrep
*/
private async grepWithFindstr(params: GrepContentParams): Promise<GrepContentResult> {
- const {
- pattern,
- path: searchPath = process.cwd(),
- output_mode = 'files_with_matches',
- } = params;
+ const { pattern, output_mode = 'files_with_matches' } = params;
+ const searchPath = this.resolveSearchPath(params);
const logPrefix = `[grepContent:findstr]`;
try {
diff --git a/packages/builtin-tool-local-system/package.json b/packages/builtin-tool-local-system/package.json
index 819aa96b5ed..027d95114cc 100644
--- a/packages/builtin-tool-local-system/package.json
+++ b/packages/builtin-tool-local-system/package.json
@@ -5,7 +5,6 @@
"exports": {
".": "./src/index.ts",
"./client": "./src/client/index.ts",
- "./executor": "./src/executor/index.ts",
"./executionRuntime": "./src/ExecutionRuntime/index.ts"
},
"main": "./src/index.ts",
diff --git a/packages/builtin-tool-local-system/src/ExecutionRuntime/index.ts b/packages/builtin-tool-local-system/src/ExecutionRuntime/index.ts
index c23988d588d..e5a07485a59 100644
--- a/packages/builtin-tool-local-system/src/ExecutionRuntime/index.ts
+++ b/packages/builtin-tool-local-system/src/ExecutionRuntime/index.ts
@@ -90,6 +90,7 @@ export class LocalSystemExecutionRuntime extends ComputerRuntime {
case 'listLocalFiles': {
return {
+ limit: params.limit,
path: params.directoryPath,
sortBy: params.sortBy,
sortOrder: params.sortOrder,
@@ -113,7 +114,7 @@ export class LocalSystemExecutionRuntime extends ComputerRuntime {
}
case 'getCommandOutput': {
- return { shell_id: params.commandId };
+ return { filter: params.filter, shell_id: params.commandId };
}
case 'killCommand': {
diff --git a/packages/builtin-tool-local-system/src/__tests__/grepContentForwarding.test.ts b/packages/builtin-tool-local-system/src/__tests__/grepContentForwarding.test.ts
new file mode 100644
index 00000000000..477c67335eb
--- /dev/null
+++ b/packages/builtin-tool-local-system/src/__tests__/grepContentForwarding.test.ts
@@ -0,0 +1,193 @@
+/**
+ * Regression: the local-system executor must forward ALL grepContent params
+ * (glob, output_mode, -i, -A/-B/-C, -n, multiline, head_limit, type, scope)
+ * to the runtime β€” not strip them down to {directory, pattern}.
+ *
+ * Pre-fix, agent calls with `scope` + `glob` + `output_mode` + `-i` reached the
+ * Electron IPC as `{ directory, pattern }` only. The IPC type expects `path`/`scope`
+ * (not `directory`), so cwd fell back to `process.cwd()`. With no glob/include
+ * filter, `tool.*name.*mcp` matched every dist/* bundle and tsbuildinfo.
+ *
+ * See LOBE-8666 / the agent screenshot that reported the leak.
+ */
+import { describe, expect, it, vi } from 'vitest';
+
+// The executor module pulls in @/services/electron/localFileService (renderer alias).
+// In the package's vitest env that alias doesn't resolve β€” stub it.
+vi.mock('@/services/electron/localFileService', () => ({
+ localFileService: {
+ editLocalFile: vi.fn(),
+ getCommandOutput: vi.fn(),
+ globFiles: vi.fn(),
+ grepContent: vi.fn(),
+ killCommand: vi.fn(),
+ listLocalFiles: vi.fn(),
+ moveLocalFiles: vi.fn(),
+ readLocalFile: vi.fn(),
+ readLocalFiles: vi.fn(),
+ renameLocalFile: vi.fn(),
+ runCommand: vi.fn(),
+ searchLocalFiles: vi.fn(),
+ writeFile: vi.fn(),
+ },
+}));
+
+const { localSystemExecutor } = await import('../client/executor');
+
+describe('localSystemExecutor.grepContent β€” params forwarding', () => {
+ it('forwards glob, output_mode, -i, and scope through to the runtime', async () => {
+ const runtime = (localSystemExecutor as any).runtime as {
+ grepContent: (args: any) => Promise<unknown>;
+ };
+
+ const spy = vi.spyOn(runtime, 'grepContent').mockResolvedValue({
+ content: 'Found 0 matches in 0 locations:',
+ state: { matches: [], pattern: 'tool.*name.*mcp', totalMatches: 0 },
+ success: true,
+ });
+
+ await localSystemExecutor.grepContent({
+ '-i': true,
+ 'glob': '**/*.ts',
+ 'output_mode': 'files_with_matches',
+ 'pattern': 'tool.*name.*mcp',
+ 'scope': '/Users/arvinxx/CodeProjects/LobeHub/lobehub-desktop',
+ });
+
+ expect(spy).toHaveBeenCalledTimes(1);
+ const forwarded = spy.mock.calls[0][0] as Record<string, unknown>;
+
+ // The critical fields the LLM filled in MUST reach the runtime.
+ expect(forwarded).toMatchObject({
+ '-i': true,
+ 'glob': '**/*.ts',
+ 'output_mode': 'files_with_matches',
+ 'pattern': 'tool.*name.*mcp',
+ // resolveArgsWithScope copies scope into `path` so the downstream
+ // resolveSearchPath can pick it up; either field reaching the runtime is fine.
+ 'path': '/Users/arvinxx/CodeProjects/LobeHub/lobehub-desktop',
+ });
+
+ // And it must NOT have been collapsed to the stripped {directory, pattern} shape.
+ expect(forwarded).not.toEqual({
+ directory: expect.any(String),
+ pattern: expect.any(String),
+ });
+
+ spy.mockRestore();
+ });
+
+ it('keeps optional flags intact when present', async () => {
+ const runtime = (localSystemExecutor as any).runtime as {
+ grepContent: (args: any) => Promise<unknown>;
+ };
+
+ const spy = vi.spyOn(runtime, 'grepContent').mockResolvedValue({
+ content: '',
+ state: { matches: [], pattern: 'x', totalMatches: 0 },
+ success: true,
+ });
+
+ await localSystemExecutor.grepContent({
+ '-A': 3,
+ '-B': 2,
+ '-C': 1,
+ '-i': true,
+ '-n': true,
+ 'head_limit': 50,
+ 'multiline': true,
+ 'pattern': 'x',
+ 'scope': '/repo',
+ 'type': 'ts',
+ });
+
+ expect(spy.mock.calls[0][0]).toMatchObject({
+ '-A': 3,
+ '-B': 2,
+ '-C': 1,
+ '-i': true,
+ '-n': true,
+ 'head_limit': 50,
+ 'multiline': true,
+ 'pattern': 'x',
+ 'path': '/repo',
+ 'type': 'ts',
+ });
+
+ spy.mockRestore();
+ });
+});
+
+describe('localSystemExecutor.listFiles β€” limit forwarding', () => {
+ it('forwards the manifest-exposed `limit` to the runtime', async () => {
+ const runtime = (localSystemExecutor as any).runtime as {
+ listFiles: (args: any) => Promise<unknown>;
+ };
+ const spy = vi.spyOn(runtime, 'listFiles').mockResolvedValue({
+ content: '',
+ state: { files: [], totalCount: 0 },
+ success: true,
+ });
+
+ await localSystemExecutor.listFiles({ limit: 50, path: '/tmp', sortBy: 'name' });
+
+ expect(spy.mock.calls[0][0]).toMatchObject({
+ directoryPath: '/tmp',
+ limit: 50,
+ sortBy: 'name',
+ });
+
+ spy.mockRestore();
+ });
+});
+
+describe('localSystemExecutor.getCommandOutput β€” filter forwarding', () => {
+ it('forwards the manifest-exposed `filter` to the runtime', async () => {
+ const runtime = (localSystemExecutor as any).runtime as {
+ getCommandOutput: (args: any) => Promise<unknown>;
+ };
+ const spy = vi.spyOn(runtime, 'getCommandOutput').mockResolvedValue({
+ content: '',
+ state: { newOutput: '', running: false, success: true },
+ success: true,
+ });
+
+ await localSystemExecutor.getCommandOutput({ filter: 'ERROR', shell_id: 'sh-1' });
+
+ expect(spy.mock.calls[0][0]).toMatchObject({
+ commandId: 'sh-1',
+ filter: 'ERROR',
+ });
+
+ spy.mockRestore();
+ });
+});
+
+describe('localSystemExecutor.runCommand β€” background field normalization', () => {
+ it('mirrors `run_in_background` to `background` so RunCommandState.isBackground is correct', async () => {
+ const runtime = (localSystemExecutor as any).runtime as {
+ runCommand: (args: any) => Promise<unknown>;
+ };
+ const spy = vi.spyOn(runtime, 'runCommand').mockResolvedValue({
+ content: '',
+ state: { isBackground: true, success: true },
+ success: true,
+ });
+
+ await localSystemExecutor.runCommand({
+ command: 'sleep 60',
+ description: 'sleep',
+ run_in_background: true,
+ });
+
+ const forwarded = spy.mock.calls[0][0] as Record<string, unknown>;
+ // Both fields present: `background` for ComputerRuntime state, `run_in_background` for IPC.
+ expect(forwarded).toMatchObject({
+ background: true,
+ command: 'sleep 60',
+ run_in_background: true,
+ });
+
+ spy.mockRestore();
+ });
+});
diff --git a/packages/builtin-tool-local-system/src/executor/index.test.ts b/packages/builtin-tool-local-system/src/client/executor/index.test.ts
similarity index 100%
rename from packages/builtin-tool-local-system/src/executor/index.test.ts
rename to packages/builtin-tool-local-system/src/client/executor/index.test.ts
diff --git a/packages/builtin-tool-local-system/src/executor/index.ts b/packages/builtin-tool-local-system/src/client/executor/index.ts
similarity index 84%
rename from packages/builtin-tool-local-system/src/executor/index.ts
rename to packages/builtin-tool-local-system/src/client/executor/index.ts
index 2d1e15549e0..9fd8fafa478 100644
--- a/packages/builtin-tool-local-system/src/executor/index.ts
+++ b/packages/builtin-tool-local-system/src/client/executor/index.ts
@@ -17,9 +17,9 @@ import { BaseExecutor } from '@lobechat/types';
import { localFileService } from '@/services/electron/localFileService';
-import { LocalSystemExecutionRuntime } from '../ExecutionRuntime';
-import { LocalSystemIdentifier } from '../types';
-import { resolveArgsWithScope } from '../utils/path';
+import { LocalSystemExecutionRuntime } from '../../ExecutionRuntime';
+import { LocalSystemIdentifier } from '../../types';
+import { resolveArgsWithScope } from '../../utils/path';
const LocalSystemApiEnum = {
editFile: 'editFile' as const,
@@ -87,9 +87,10 @@ class LocalSystemExecutor extends BaseExecutor<typeof LocalSystemApiEnum> {
try {
const result = await this.runtime.listFiles({
directoryPath: params.path,
+ limit: params.limit,
sortBy: params.sortBy,
sortOrder: params.sortOrder,
- });
+ } as any);
return this.toResult(result);
} catch (error) {
return this.errorResult(error);
@@ -172,7 +173,14 @@ class LocalSystemExecutor extends BaseExecutor<typeof LocalSystemApiEnum> {
runCommand = async (params: RunCommandParams): Promise<BuiltinToolResult> => {
try {
- const result = await this.runtime.runCommand(params);
+ // The manifest exposes `run_in_background`, but ComputerRuntime's RunCommandState
+ // reads `args.background` for the `isBackground` field β€” without this normalize
+ // the UI/state would always say foreground even for background commands.
+ // The IPC handler reads `run_in_background` itself, so we keep that field too.
+ const result = await this.runtime.runCommand({
+ ...params,
+ background: params.run_in_background,
+ } as any);
return this.toResult(result);
} catch (error) {
return this.errorResult(error);
@@ -183,7 +191,8 @@ class LocalSystemExecutor extends BaseExecutor<typeof LocalSystemApiEnum> {
try {
const result = await this.runtime.getCommandOutput({
commandId: params.shell_id,
- });
+ filter: params.filter,
+ } as any);
return this.toResult(result);
} catch (error) {
return this.errorResult(error);
@@ -206,10 +215,12 @@ class LocalSystemExecutor extends BaseExecutor<typeof LocalSystemApiEnum> {
grepContent = async (params: GrepContentParams): Promise<BuiltinToolResult> => {
try {
const resolvedParams = resolveArgsWithScope(params, 'path');
- const result = await this.runtime.grepContent({
- directory: resolvedParams.path || '',
- pattern: resolvedParams.pattern,
- });
+ // Forward the full IPC params (glob / output_mode / -i / -A / -B / -C / -n /
+ // multiline / head_limit / type / tool) instead of stripping to {directory, pattern}.
+ // ComputerRuntime.callService passes args through unchanged, so the runtime type
+ // narrowing was the only blocker β€” the underlying rg/grep needs these flags to
+ // honor the agent's filter and stop scanning dist/* and tsbuildinfo.
+ const result = await this.runtime.grepContent(resolvedParams as any);
return this.toResult(result);
} catch (error) {
return this.errorResult(error);
diff --git a/packages/builtin-tool-local-system/src/client/index.ts b/packages/builtin-tool-local-system/src/client/index.ts
index 8676f8e2594..1a051ec4a6e 100644
--- a/packages/builtin-tool-local-system/src/client/index.ts
+++ b/packages/builtin-tool-local-system/src/client/index.ts
@@ -1,3 +1,6 @@
+// Client-side executor (browser runtime adapter for the agent)
+export { localSystemExecutor } from './executor';
+
// Inspector components (customized tool call headers)
export { LocalSystemInspectors } from './Inspector';
diff --git a/packages/electron-client-ipc/src/types/localSystem.ts b/packages/electron-client-ipc/src/types/localSystem.ts
index f42673b60ae..ff6e1b4fb58 100644
--- a/packages/electron-client-ipc/src/types/localSystem.ts
+++ b/packages/electron-client-ipc/src/types/localSystem.ts
@@ -265,9 +265,10 @@ export interface GrepContentParams {
'head_limit'?: number;
'multiline'?: boolean;
'output_mode'?: 'content' | 'files_with_matches' | 'count';
+ /** Legacy alias for `scope`. Takes precedence when set; prefer `scope` (the manifest-documented name) for new callers. */
'path'?: string;
'pattern': string;
- /** Working directory scope. When `path` is not specified, used as the default search location. */
+ /** Working directory scope. Limits the search to this directory. Defaults to `process.cwd()`. */
'scope'?: string;
/** Preferred search tool: 'rg' | 'ag' | 'grep' */
'tool'?: 'rg' | 'ag' | 'grep';
diff --git a/packages/file-loaders/src/loaders/index.ts b/packages/file-loaders/src/loaders/index.ts
index 93b52e445a5..a7ee2532bc9 100644
--- a/packages/file-loaders/src/loaders/index.ts
+++ b/packages/file-loaders/src/loaders/index.ts
@@ -1,12 +1,20 @@
import type { FileLoaderInterface, SupportedFileType } from '../types';
+import { TextLoader } from './text';
// Lazy loader factory type - returns a Promise that resolves to the loader class
type LazyLoaderFactory = () => Promise<new () => FileLoaderInterface>;
-// Loader configuration map using lazy imports
-// This prevents pdfjs-dist from being loaded at module initialization
-// and only loads it when PDF files need to be processed
-const lazyFileLoaders: Record<SupportedFileType, LazyLoaderFactory> = {
+// Loader configuration map using lazy imports for HEAVY formats only.
+// pdf/doc/docx/excel/pptx pull in multi-MB parsers (pdfjs-dist, mammoth, xlsx, …)
+// that should stay out of the main bundle until a file of that type is opened.
+//
+// TextLoader is intentionally NOT lazy: it only depends on node:fs/promises +
+// a tiny utf-16 detect util (~10KB total). Splitting it into a dynamic chunk
+// caused the chunk to back-reference the main bundle for `detectUtf16NoBom`,
+// re-evaluating the main entry and re-running `new App()` β†’
+// `protocol.registerSchemesAsPrivileged` after app ready β†’ throw on every
+// readFile of .md / .json / .ts / etc. See LOBE-* for the regression.
+const lazyFileLoaders: Record<Exclude<SupportedFileType, 'txt'>, LazyLoaderFactory> = {
doc: async () => {
const { DocLoader } = await import('./doc');
return DocLoader;
@@ -41,26 +49,20 @@ const lazyFileLoaders: Record<SupportedFileType, LazyLoaderFactory> = {
const { PptxLoader } = await import('./pptx');
return PptxLoader;
},
- txt: async () => {
- const { TextLoader } = await import('./text');
- return TextLoader;
- },
};
/**
* Get a file loader class for the specified file type.
* Uses dynamic imports to avoid loading heavy dependencies (like pdfjs-dist) until needed.
- * Falls back to TextLoader if no specific loader is found.
+ * TextLoader is returned synchronously (statically imported) for `txt` and as the
+ * fallback for unknown types.
*/
export const getFileLoader = async (
fileType: SupportedFileType | string,
): Promise<new () => FileLoaderInterface> => {
- const loaderFactory = lazyFileLoaders[fileType as SupportedFileType];
- if (!loaderFactory) {
- // Fallback to TextLoader for unsupported file types
- const { TextLoader } = await import('./text');
- return TextLoader;
- }
+ if (fileType === 'txt') return TextLoader;
+ const loaderFactory = lazyFileLoaders[fileType as Exclude<SupportedFileType, 'txt'>];
+ if (!loaderFactory) return TextLoader;
return loaderFactory();
};
diff --git a/src/store/tool/slices/builtin/executors/index.ts b/src/store/tool/slices/builtin/executors/index.ts
index da9ef8e29a9..a5762e01d79 100644
--- a/src/store/tool/slices/builtin/executors/index.ts
+++ b/src/store/tool/slices/builtin/executors/index.ts
@@ -13,7 +13,7 @@ import { groupAgentBuilderExecutor } from '@lobechat/builtin-tool-group-agent-bu
import { groupManagementExecutor } from '@lobechat/builtin-tool-group-management/executor';
import { knowledgeBaseExecutor } from '@lobechat/builtin-tool-knowledge-base/client';
import { lobeAgentExecutor } from '@lobechat/builtin-tool-lobe-agent/client';
-import { localSystemExecutor } from '@lobechat/builtin-tool-local-system/executor';
+import { localSystemExecutor } from '@lobechat/builtin-tool-local-system/client';
import { memoryExecutor } from '@lobechat/builtin-tool-memory/executor';
import { taskExecutor } from '@lobechat/builtin-tool-task/client';