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: use lightweight browser entry for page bash (#20318)

Inneib6198d9b340b
diff --git a/packages/builtin-tool-page-agent/src/bash/index.test.ts b/packages/builtin-tool-page-agent/src/bash/index.test.ts
new file mode 100644
index 00000000000..f34d4f1d424
--- /dev/null
+++ b/packages/builtin-tool-page-agent/src/bash/index.test.ts
@@ -0,0 +1,34 @@
+import { fileURLToPath } from 'node:url';
+
+import { build } from 'esbuild';
+import { describe, expect, it } from 'vitest';
+
+describe('page bash bundle', () => {
+ it('does not pull optional language runtimes into the server bundle', async () => {
+ const optionalRuntimes = ['sql.js', 'typescript', 'quickjs-emscripten', 'run'];
+ const result = await build({
+ bundle: true,
+ entryPoints: [fileURLToPath(new URL('./index.ts', import.meta.url))],
+ external: [
+ '@lobechat/editor-runtime',
+ '@mongodb-js/zstd',
+ 'node-liblzma',
+ ...optionalRuntimes,
+ ],
+ format: 'esm',
+ metafile: true,
+ platform: 'node',
+ write: false,
+ });
+
+ const imports = Object.values(result.metafile.outputs).flatMap((output) =>
+ output.imports.map((dependency) => dependency.path),
+ );
+ expect(imports.filter((dependency) => optionalRuntimes.includes(dependency))).toEqual([]);
+ expect(
+ Object.keys(result.metafile.inputs).filter((path) =>
+ /cpython|sqlite3-worker|js-exec-worker/.test(path),
+ ),
+ ).toEqual([]);
+ });
+});
diff --git a/packages/builtin-tool-page-agent/src/bash/index.ts b/packages/builtin-tool-page-agent/src/bash/index.ts
index 012b0a413fe..538aa3dd105 100644
--- a/packages/builtin-tool-page-agent/src/bash/index.ts
+++ b/packages/builtin-tool-page-agent/src/bash/index.ts
@@ -4,7 +4,7 @@ import {
formatModifyNodesResult,
parseLiteXMLBlocks,
} from '@lobechat/editor-runtime';
-import type { CommandName } from 'just-bash';
+import type { CommandName } from 'just-bash/browser';
import type { BashState } from '../types';
@@ -133,7 +133,9 @@ export const runPageBash = async (
runtime: EditorRuntime,
command: string,
): Promise<{ content: string; state: BashState }> => {
- const { Bash, defineCommand } = await import('just-bash');
+ // The browser build keeps the virtual shell without tracing optional SQL,
+ // Python, or JavaScript runtimes into serverless functions.
+ const { Bash, defineCommand } = await import('just-bash/browser');
const {
metadata: { title },