@glodon-aiot/bot-client-sdk 3.26.0-alpha.4 → 3.26.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +105 -76
  2. package/dist/es/Config.mjs +63 -85
  3. package/dist/es/builtinTools/browserRuntime/BrowserCommandRunner.mjs +201 -0
  4. package/dist/es/builtinTools/browserRuntime/PythonRunner.mjs +356 -0
  5. package/dist/es/builtinTools/browserRuntime/WorkspaceBashFs.mjs +350 -0
  6. package/dist/es/builtinTools/browserRuntime/assets.mjs +9 -0
  7. package/dist/es/builtinTools/browserRuntime/loadBash.mjs +17 -0
  8. package/dist/es/builtinTools/browserRuntime/pyodideRunner.py.mjs +96 -0
  9. package/dist/es/builtinTools/browserRuntime/pyodideWorker.mjs +242 -0
  10. package/dist/es/builtinTools/command.mjs +56 -0
  11. package/dist/es/builtinTools/constants.mjs +10 -0
  12. package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +236 -0
  13. package/dist/es/builtinTools/overview.mjs +77 -0
  14. package/dist/es/builtinTools/paths.mjs +63 -0
  15. package/dist/es/builtinTools/schemas.mjs +216 -0
  16. package/dist/es/builtinTools/tools.mjs +471 -0
  17. package/dist/es/index.mjs +49 -48
  18. package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +193 -103
  19. package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +138 -77
  20. package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +132 -97
  21. package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +32 -28
  22. package/dist/es/localFiles/constants.mjs +1 -1
  23. package/dist/es/localFiles/host/connectHostBridge.mjs +22 -18
  24. package/dist/es/localFiles/host/protocol.mjs +6 -5
  25. package/dist/es/localFiles/schemas.mjs +45 -60
  26. package/dist/es/localFiles/validate.mjs +37 -37
  27. package/dist/es/localFiles/workspace/LocalWorkspace.mjs +71 -52
  28. package/dist/es/package.json.mjs +33 -27
  29. package/dist/lib/index.js +372 -9
  30. package/dist/src/Config.d.ts +2 -2
  31. package/dist/src/builtinTools/browserRuntime/BrowserCommandRunner.d.ts +26 -0
  32. package/dist/src/builtinTools/browserRuntime/PythonRunner.d.ts +67 -0
  33. package/dist/src/builtinTools/browserRuntime/WorkspaceBashFs.d.ts +51 -0
  34. package/dist/src/builtinTools/browserRuntime/assets.d.ts +13 -0
  35. package/dist/src/builtinTools/browserRuntime/loadBash.d.ts +3 -0
  36. package/dist/src/builtinTools/browserRuntime/pyodideWorker.d.ts +44 -0
  37. package/dist/src/builtinTools/command.d.ts +26 -0
  38. package/dist/src/builtinTools/constants.d.ts +17 -0
  39. package/dist/src/builtinTools/createBuiltinToolsPlugin.d.ts +11 -0
  40. package/dist/src/builtinTools/overview.d.ts +5 -0
  41. package/dist/src/builtinTools/paths.d.ts +15 -0
  42. package/dist/src/builtinTools/schemas.d.ts +3 -0
  43. package/dist/src/builtinTools/tools.d.ts +60 -0
  44. package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +4 -1
  45. package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +20 -1
  46. package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +4 -1
  47. package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +14 -0
  48. package/dist/src/localFiles/adapters/fsaTypes.d.ts +2 -0
  49. package/dist/src/localFiles/constants.d.ts +2 -1
  50. package/dist/src/localFiles/host/protocol.d.ts +13 -0
  51. package/dist/src/localFiles/index.d.ts +3 -2
  52. package/dist/src/localFiles/schemas.d.ts +2 -3
  53. package/dist/src/localFiles/types.d.ts +14 -1
  54. package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +12 -0
  55. package/package.json +8 -2
  56. package/dist/es/localFiles/createLocalPythonPlugin.mjs +0 -196
@@ -19,7 +19,7 @@ export interface BotClientConfig {
19
19
  loadRelatedQuesions?: boolean;
20
20
  mcp?: MCPConfig;
21
21
  stream?: boolean;
22
- /** SDK 内置插件:本地文件工具和 run_python,注册到同一个 pluginCode。 */
22
+ /** SDK 内置插件。文件、命令和技能工具注册到同一个 pluginCode。 */
23
23
  builtinPlugins?: BuiltinPluginsConfig;
24
24
  }
25
25
  export interface AgentPluginRegistor {
@@ -53,7 +53,7 @@ export declare function setActiveLocalWorkspace(workspace?: LocalWorkspace): voi
53
53
  export declare function getActiveLocalWorkspace(): LocalWorkspace | undefined;
54
54
  /** 当前已注册到 configuration.plugins 的内置文件工具编码;未注册时返回 undefined。 */
55
55
  export declare function getRegisteredLocalFilesPluginCode(): string | undefined;
56
- /** 当前已注册到 configuration.plugins 的 run_python 所在插件编码;未注册时返回 undefined。 */
56
+ /** 当前已注册到 configuration.plugins 的脚本工具所在插件编码;未注册时返回 undefined。 */
57
57
  export declare function getRegisteredLocalPythonPluginCode(): string | undefined;
58
58
  /** 显式配置优先,其次按 env 取默认值;都没有时返回 undefined。 */
59
59
  export declare function resolveLocalFilesPluginCode(config: LocalFilesConfig | undefined, env: string): string;
@@ -0,0 +1,26 @@
1
+ import { WorkspaceFileAdapter } from '../../localFiles/adapters/WorkspaceFileAdapter';
2
+ import { SensitiveFilePolicy } from '../../localFiles/security/sensitiveFiles';
3
+ import { CommandRequest, CommandResult, CommandRunner } from '../command';
4
+ import { WorkerLike } from './PythonRunner';
5
+ export declare const NO_NODE_MESSAGE = "\u5F53\u524D\u73AF\u5883\u6CA1\u6709 Node\uFF0C\u8BF7\u6539\u7528 python3 \u6216 shell \u547D\u4EE4\u3002\n";
6
+ export interface BrowserCommandRunnerOptions {
7
+ adapter: WorkspaceFileAdapter;
8
+ sensitive: SensitiveFilePolicy;
9
+ /** just-bash 浏览器构建的地址,默认 DEFAULT_BASH_MODULE_URL。 */
10
+ moduleURL?: string;
11
+ /** Pyodide 目录,默认 DEFAULT_PYODIDE_INDEX_URL。 */
12
+ pyodideIndexURL?: string;
13
+ createWorker?: (source: string) => WorkerLike;
14
+ }
15
+ /**
16
+ * 纯网页里的命令执行器:just-bash 解释 shell,文件读写落到当前工作区。
17
+ * 每条命令新建一个 shell,只有文件和 cwd 跨命令保留。
18
+ */
19
+ export declare class BrowserCommandRunner implements CommandRunner {
20
+ private readonly options;
21
+ private readonly python;
22
+ constructor(options: BrowserCommandRunnerOptions);
23
+ private load;
24
+ private create;
25
+ exec(request: CommandRequest): Promise<CommandResult>;
26
+ }
@@ -0,0 +1,67 @@
1
+ import { WorkspaceFileAdapter } from '../../localFiles/adapters/WorkspaceFileAdapter';
2
+ import { SensitiveFilePolicy } from '../../localFiles/security/sensitiveFiles';
3
+ export declare const NO_PIP_MESSAGE: string;
4
+ export declare const MAX_SYNC_FILE_BYTES: number;
5
+ export declare const MAX_SYNC_TOTAL_BYTES: number;
6
+ /** 把 shell 或工具传来的目录换成 Pyodide 里的工作区路径。 */
7
+ export declare function toMount(cwd: string): string;
8
+ /** Worker 的最小接口,测试里用 Node 的 worker_threads 实现。 */
9
+ export interface WorkerLike {
10
+ onmessage: ((event: {
11
+ data: unknown;
12
+ }) => void) | null;
13
+ onerror: ((event: unknown) => void) | null;
14
+ postMessage(message: unknown, transfer?: Transferable[]): void;
15
+ terminate(): void;
16
+ }
17
+ export interface PythonRunnerOptions {
18
+ adapter: WorkspaceFileAdapter;
19
+ sensitive: SensitiveFilePolicy;
20
+ /** Pyodide 目录,以 `/` 结尾,默认 DEFAULT_PYODIDE_INDEX_URL。 */
21
+ indexURL?: string;
22
+ createWorker?: (source: string) => WorkerLike;
23
+ }
24
+ export interface PythonRequest {
25
+ /** `python3` 后面的参数。 */
26
+ args: string[];
27
+ /** shell 里的目录。`.` 或 `/workspace` 表示工作区根。 */
28
+ cwd: string;
29
+ stdin?: Uint8Array;
30
+ signal?: AbortSignal;
31
+ }
32
+ export interface PythonResult {
33
+ exitCode: number;
34
+ stdout: string;
35
+ stderr: string;
36
+ }
37
+ type Invocation = {
38
+ mode: 'c' | 'm' | 'file';
39
+ target: string;
40
+ argv: string[];
41
+ stdin: Uint8Array;
42
+ };
43
+ /** 按 python3 命令行解析参数;不需要启动解释器的情况直接给出结果。 */
44
+ export declare function parsePythonArgs(args: string[], cwd: string, stdin: Uint8Array): Invocation | PythonResult;
45
+ /**
46
+ * 浏览器里的 python3:Pyodide 跑在专用 Worker 里,执行前把工作区文件快照同步进去,执行后把改动写回。
47
+ * 同一时间只跑一个请求;超时或取消时终止 Worker,下次重新创建。
48
+ */
49
+ export declare class PythonRunner {
50
+ private readonly options;
51
+ private state?;
52
+ private queue;
53
+ private nextId;
54
+ constructor(options: PythonRunnerOptions);
55
+ private get indexURL();
56
+ private loadError;
57
+ private dispose;
58
+ private spawn;
59
+ run(request: PythonRequest): Promise<PythonResult>;
60
+ private runNow;
61
+ /** 执行前把整个工作区读进 Pyodide。 */
62
+ private collect;
63
+ private exists;
64
+ /** 把 Python 里的改动写回工作区,返回是否有写回失败。 */
65
+ private writeBack;
66
+ }
67
+ export {};
@@ -0,0 +1,51 @@
1
+ import { BufferEncoding, CpOptions, FileContent, FsStat, IFileSystem, MkdirOptions, RmOptions } from 'just-bash/browser';
2
+ import { WorkspaceFileAdapter } from '../../localFiles/adapters/WorkspaceFileAdapter';
3
+ import { SensitiveFilePolicy } from '../../localFiles/security/sensitiveFiles';
4
+ type EncodingOption = {
5
+ encoding?: BufferEncoding | null;
6
+ } | BufferEncoding | undefined;
7
+ interface DirentEntry {
8
+ name: string;
9
+ isFile: boolean;
10
+ isDirectory: boolean;
11
+ isSymbolicLink: boolean;
12
+ }
13
+ /**
14
+ * 把工作区挂到 just-bash 的一个目录。root 为空表示整个工作区。
15
+ * 收到的路径相对挂载点,以 `/` 开头。
16
+ */
17
+ export declare class WorkspaceBashFs implements IFileSystem {
18
+ private readonly adapter;
19
+ private readonly root;
20
+ private readonly sensitive;
21
+ constructor(adapter: WorkspaceFileAdapter, root: string, sensitive: SensitiveFilePolicy);
22
+ private relative;
23
+ private shown;
24
+ private isRoot;
25
+ private guard;
26
+ private mapError;
27
+ private entry;
28
+ private ensureRoot;
29
+ readFileBuffer(path: string): Promise<Uint8Array>;
30
+ readFile(path: string, options?: EncodingOption): Promise<string>;
31
+ writeFile(path: string, content: FileContent, options?: EncodingOption): Promise<void>;
32
+ appendFile(path: string, content: FileContent, options?: EncodingOption): Promise<void>;
33
+ exists(path: string): Promise<boolean>;
34
+ stat(path: string): Promise<FsStat>;
35
+ lstat(path: string): Promise<FsStat>;
36
+ mkdir(path: string, options?: MkdirOptions): Promise<void>;
37
+ readdirWithFileTypes(path: string): Promise<DirentEntry[]>;
38
+ readdir(path: string): Promise<string[]>;
39
+ rm(path: string, options?: RmOptions): Promise<void>;
40
+ cp(src: string, dest: string, options?: CpOptions): Promise<void>;
41
+ mv(src: string, dest: string): Promise<void>;
42
+ resolvePath(base: string, path: string): string;
43
+ getAllPaths(): string[];
44
+ chmod(path: string): Promise<void>;
45
+ symlink(_target: string, linkPath: string): Promise<void>;
46
+ link(_existingPath: string, newPath: string): Promise<void>;
47
+ readlink(path: string): Promise<string>;
48
+ realpath(path: string): Promise<string>;
49
+ utimes(path: string): Promise<void>;
50
+ }
51
+ export {};
@@ -0,0 +1,13 @@
1
+ /** 公司 OBS 上的前端依赖目录,按 `<包名>/<版本>/` 存放。 */
2
+ export declare const CDN_LIBS_ROOT = "https://cv-cdn.obs.cn-north-4.myhuaweicloud.com/glodon/libs/";
3
+ /** 必须与 package.json 里 just-bash 的版本一致;升级时先上传新版本目录。 */
4
+ export declare const JUST_BASH_VERSION = "3.6.0";
5
+ export declare const DEFAULT_BASH_MODULE_URL = "https://cv-cdn.obs.cn-north-4.myhuaweicloud.com/glodon/libs/just-bash/3.6.0/just-bash.mjs";
6
+ /** 必须与 package.json 里 pyodide 的版本一致;升级时先上传新版本目录。 */
7
+ export declare const PYODIDE_VERSION = "314.0.7";
8
+ export declare const DEFAULT_PYODIDE_INDEX_URL = "https://cv-cdn.obs.cn-north-4.myhuaweicloud.com/glodon/libs/pyodide/314.0.7/";
9
+ /**
10
+ * 浏览器里可以 import 的第三方包,构建脚本按它们的依赖闭包上传 wheel 并改写 pyodide-lock.json。
11
+ * 调整后需要重新构建并上传新的 Pyodide 目录。
12
+ */
13
+ export declare const PYODIDE_PACKAGES: string[];
@@ -0,0 +1,3 @@
1
+ export type BashModule = typeof import('just-bash/browser');
2
+ /** 第一次执行命令时才从 url 加载 just-bash,不进首屏。加载失败后下次重试。 */
3
+ export declare function loadBash(url: string): Promise<BashModule>;
@@ -0,0 +1,44 @@
1
+ /** Emscripten 的 ErrnoError 不是 Error,只带 errno 和 code。 */
2
+ declare function describe(error: any): any;
3
+ declare function networkDenied(url: any): TypeError;
4
+ /** 只放行 indexURL 下的资源(Pyodide 自身和白名单 wheel),其余请求一律拒绝。 */
5
+ declare function guardNetwork(indexURL: any): void;
6
+ declare function collector(): {
7
+ write(bytes: any): void;
8
+ finish(): string;
9
+ };
10
+ declare function init({ indexURL, packages, runner }: {
11
+ indexURL: any;
12
+ packages: any;
13
+ runner: any;
14
+ }): Promise<void>;
15
+ declare function dirname(path: any): any;
16
+ /** 主脚本、`-c` 代码,以及主脚本目录和 cwd 下的 .py 文件里出现的 import。 */
17
+ declare function sourcesToScan({ files, cwd, mode, target }: {
18
+ files: any;
19
+ cwd: any;
20
+ mode: any;
21
+ target: any;
22
+ }): any[];
23
+ declare function loadPackages(sources: any, stderr: any): Promise<void>;
24
+ declare function lstat(path: any): any;
25
+ declare function removeTree(path: any): void;
26
+ declare function walk(path: any, files: any, dirs: any): void;
27
+ declare function sameBytes(a: any, b: any): boolean;
28
+ declare function execute(message: any): Promise<{
29
+ exitCode: any;
30
+ stdout: string;
31
+ stderr: string;
32
+ written: {
33
+ path: any;
34
+ data: any;
35
+ }[];
36
+ removed: any[];
37
+ createdDirs: any[];
38
+ removedDirs: string[];
39
+ }>;
40
+ declare const ROOTS: string[];
41
+ declare const OUTPUT_LIMIT: number;
42
+ declare let pyodide: null;
43
+ declare let runPython: null;
44
+ declare let sink: null;
@@ -0,0 +1,26 @@
1
+ /** 在工作区里执行命令。由端侧宿主沙箱、浏览器运行时或测试注入实现。 */
2
+ export interface CommandRequest {
3
+ /** shell 命令。与 argv 二选一。 */
4
+ command?: string;
5
+ /** 直接执行的程序和参数,不经过 shell。 */
6
+ argv?: string[];
7
+ /** 工作区相对目录。`.` 表示工作区根。 */
8
+ cwd: string;
9
+ timeoutMs?: number;
10
+ signal?: AbortSignal;
11
+ }
12
+ export interface CommandResult {
13
+ exitCode: number;
14
+ stdout: string;
15
+ stderr: string;
16
+ /** 命令结束后的工作区相对目录。shell 用来保留上次停留的目录。 */
17
+ cwd?: string;
18
+ }
19
+ export interface CommandRunner {
20
+ exec(request: CommandRequest): Promise<CommandResult>;
21
+ }
22
+ /** stdout、stderr 各自返回给模型的字符上限。 */
23
+ export declare const MAX_COMMAND_OUTPUT_CHARS = 16000;
24
+ export declare const OUTPUT_TRUNCATED_NOTE = "\n\u2026\u8F93\u51FA\u5DF2\u622A\u65AD";
25
+ export declare function limitOutput(text: string): string;
26
+ export declare function withOutputLimit(runner: CommandRunner): CommandRunner;
@@ -0,0 +1,17 @@
1
+ export declare const BUILTIN_FUNCTION_CODES: readonly ["shell", "read_file", "write_file", "append_file", "run_file", "edit_file", "grep", "find", "load_skill", "read_skill_resource", "run_skill_script"];
2
+ export type BuiltinFunctionCode = (typeof BUILTIN_FUNCTION_CODES)[number];
3
+ /** 单次 read_file 按原文返回的上限。超出后结构化文本改为概览。 */
4
+ export declare const MAX_READ_BYTES = 81920;
5
+ /** write_file 单次覆盖写入的 UTF-8 字节上限。 */
6
+ export declare const MAX_WRITE_BYTES = 81920;
7
+ export declare const MAX_COMMAND_CHARS = 20000;
8
+ /** shell 一开始停在工作区根目录。 */
9
+ export declare const SHELL_CWD = ".";
10
+ /**
11
+ * 浏览器 shell 把工作区挂在这里。命令里的工作区绝对路径会改写到这个前缀,
12
+ * 输出再换回以 / 开头的工作区路径。
13
+ */
14
+ export declare const WORKSPACE_MOUNT = "/workspace";
15
+ /** 技能目录在工作区根下。 */
16
+ export declare const SKILLS_DIR = "skills";
17
+ export declare const RUNNABLE_EXTENSIONS: readonly [".py", ".sh", ".js"];
@@ -0,0 +1,11 @@
1
+ import { LocalWorkspace } from '../localFiles/workspace/LocalWorkspace';
2
+ import { ClientPluginCallback, ToolContext } from '../localFiles/types';
3
+ import { BuiltinFunctionCode } from './constants';
4
+ export type BuiltinHandler = (params: unknown, callback: ClientPluginCallback, context?: Partial<ToolContext>) => void;
5
+ export type BuiltinPluginTable = Record<string, Record<BuiltinFunctionCode, BuiltinHandler>>;
6
+ export interface CreateBuiltinToolsPluginOptions {
7
+ pluginCode: string;
8
+ workspace: LocalWorkspace;
9
+ }
10
+ /** 组装内置工具插件:`{ [pluginCode]: { shell, read_file, ... } }`。 */
11
+ export declare function createBuiltinToolsPlugin({ pluginCode, workspace, }: CreateBuiltinToolsPluginOptions): BuiltinPluginTable;
@@ -0,0 +1,5 @@
1
+ export declare function isStructuredPath(path: string): boolean;
2
+ export declare function structureOverview(path: string, text: string): string;
3
+ export declare function extensionOf(path: string): string;
4
+ export declare function isImagePath(path: string): boolean;
5
+ export declare function isPdf(path: string, bytes?: Uint8Array): boolean;
@@ -0,0 +1,15 @@
1
+ export declare const SYNTHETIC_DIRS: readonly ["input", "output", "uploads", "tmp"];
2
+ export declare const SYNTHETIC_DIR_MESSAGE = "\u4E0D\u8981\u4F7F\u7528 input\u3001output\u3001uploads\u3001tmp\uFF0C\u4E5F\u4E0D\u8981\u65B0\u5EFA\u8FD9\u4E9B\u76EE\u5F55\u3002\u8BF7\u628A\u6587\u4EF6\u76F4\u63A5\u653E\u5728\u5DE5\u4F5C\u533A\u5DF2\u6709\u4F4D\u7F6E\u6216\u6839\u76EE\u5F55\u3002";
3
+ export declare function mentionsSyntheticDir(text: string): boolean;
4
+ export declare function isSyntheticCwd(cwd: string): boolean;
5
+ /**
6
+ * 把工作区内绝对路径转成相对工作区根的路径。`/` 表示工作区根。
7
+ * 拒绝相对路径、盘符和 .. 。
8
+ */
9
+ export declare function resolveWorkspacePath(input: string): string;
10
+ export declare function resolveFilePath(input: string): string;
11
+ export declare function resolveRunPath(input: string): string;
12
+ export declare function toVirtualPath(relative: string): string;
13
+ /** shell 回传的目录必须仍在工作区内。`.` 表示工作区根。 */
14
+ export declare function isSafeCwd(cwd: string): boolean;
15
+ export declare function skillRelative(skillName: string, relativeName: string): string;
@@ -0,0 +1,3 @@
1
+ import { BuiltinToolSchema } from '../localFiles/schemas';
2
+ import { BuiltinFunctionCode } from './constants';
3
+ export declare const BUILTIN_TOOL_SCHEMAS: Record<BuiltinFunctionCode, BuiltinToolSchema>;
@@ -0,0 +1,60 @@
1
+ import { WorkspaceFileAdapter } from '../localFiles/adapters/WorkspaceFileAdapter';
2
+ import { CommandRunner } from './command';
3
+ export interface ToolIO {
4
+ adapter: WorkspaceFileAdapter;
5
+ runner?: CommandRunner;
6
+ signal?: AbortSignal;
7
+ timeoutMs: number;
8
+ shellCwd: {
9
+ cwd: string;
10
+ };
11
+ }
12
+ interface ToolOutput {
13
+ data: Record<string, unknown>;
14
+ truncated?: boolean;
15
+ }
16
+ export declare function readFile(input: {
17
+ path: string;
18
+ start_line?: number;
19
+ end_line?: number;
20
+ }, io: ToolIO): Promise<ToolOutput>;
21
+ export declare function writeFile(input: {
22
+ path: string;
23
+ content: string;
24
+ }, io: ToolIO): Promise<ToolOutput>;
25
+ export declare function appendFile(input: {
26
+ path: string;
27
+ content: string;
28
+ }, io: ToolIO): Promise<ToolOutput>;
29
+ export declare function editFile(input: {
30
+ path: string;
31
+ old_text: string;
32
+ new_text: string;
33
+ }, io: ToolIO): Promise<ToolOutput>;
34
+ export declare function grep(input: {
35
+ path: string;
36
+ pattern: string;
37
+ }, io: ToolIO): Promise<ToolOutput>;
38
+ export declare function find(input: {
39
+ path: string;
40
+ name: string;
41
+ }, io: ToolIO): Promise<ToolOutput>;
42
+ export declare function runFile(input: {
43
+ path: string;
44
+ }, io: ToolIO): Promise<ToolOutput>;
45
+ export declare function shell(input: {
46
+ command: string;
47
+ }, io: ToolIO): Promise<ToolOutput>;
48
+ export declare function loadSkill(input: {
49
+ skill_name: string;
50
+ }, io: ToolIO): Promise<ToolOutput>;
51
+ export declare function readSkillResource(input: {
52
+ skill_name: string;
53
+ resource_name: string;
54
+ }, io: ToolIO): Promise<ToolOutput>;
55
+ export declare function runSkillScript(input: {
56
+ skill_name: string;
57
+ script_name: string;
58
+ args?: string[];
59
+ }, io: ToolIO): Promise<ToolOutput>;
60
+ export {};
@@ -1,4 +1,4 @@
1
- import { WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource } from './WorkspaceFileAdapter';
1
+ import { RemoveOptions, WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource } from './WorkspaceFileAdapter';
2
2
  import { FsaDirectoryHandle } from './fsaTypes';
3
3
  /**
4
4
  * 基于用户授权的 DirectoryHandle 的工作区。只通过逐级 getDirectoryHandle / getFileHandle
@@ -14,4 +14,7 @@ export declare class FileSystemAccessAdapter implements WorkspaceFileAdapter {
14
14
  listEntries(path: string, signal?: AbortSignal): Promise<WorkspaceEntry[]>;
15
15
  readFile(path: string): Promise<Blob>;
16
16
  writeFile(path: string, source: WriteSource, options?: WriteOptions): Promise<void>;
17
+ createDirectory(path: string): Promise<void>;
18
+ remove(path: string, options?: RemoveOptions): Promise<void>;
19
+ move(from: string, to: string): Promise<void>;
17
20
  }
@@ -1,19 +1,38 @@
1
+ import { CommandRequest, CommandResult } from '../../builtinTools/command';
1
2
  import { WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource } from './WorkspaceFileAdapter';
2
- import { HostResponseMessage, HostWebView } from '../host/protocol';
3
+ import { HostCapability, HostResponseMessage, HostWebView } from '../host/protocol';
3
4
  /**
4
5
  * 把工作区原语转成宿主消息。页面看不到绝对路径,目录由宿主在授权后推送。
5
6
  */
6
7
  export declare class HostBridgeAdapter implements WorkspaceFileAdapter {
7
8
  private readonly view;
8
9
  displayName: string;
10
+ /** 宿主最近一次 workspace 消息声明的能力。 */
11
+ capabilities: ReadonlySet<HostCapability>;
12
+ /** 宿主随 sandbox-exec 声明的沙箱包版本和协议。 */
13
+ sandboxVersion?: string;
14
+ sandboxProtocol?: number;
9
15
  private seq;
10
16
  private readonly pending;
11
17
  constructor(view: HostWebView, displayName?: string);
18
+ setCapabilities(value: unknown, sandbox?: {
19
+ version?: unknown;
20
+ protocol?: unknown;
21
+ }): void;
22
+ /** 声明了 sandbox-exec 且协议版本与 SDK 一致时才把命令交给宿主。 */
23
+ get canExec(): boolean;
24
+ private requireCapability;
12
25
  settle(message: HostResponseMessage): void;
13
26
  private call;
14
27
  stat(path: string): Promise<WorkspaceEntry>;
15
28
  listEntries(path: string, signal?: AbortSignal): Promise<WorkspaceEntry[]>;
16
29
  readFile(path: string): Promise<Blob>;
30
+ createDirectory(path: string): Promise<void>;
31
+ remove(path: string, options?: {
32
+ recursive?: boolean;
33
+ }): Promise<void>;
34
+ move(from: string, to: string): Promise<void>;
35
+ exec(request: CommandRequest): Promise<CommandResult>;
17
36
  runPython(path: string, args: string[], timeoutMs: number, signal?: AbortSignal): Promise<{
18
37
  exitCode: number;
19
38
  timedOut: boolean;
@@ -1,4 +1,4 @@
1
- import { WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource } from './WorkspaceFileAdapter';
1
+ import { RemoveOptions, WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource } from './WorkspaceFileAdapter';
2
2
  /** 内存工作区:用于测试与契约基准,语义与 FileSystemAccessAdapter 一致。 */
3
3
  export declare class MemoryWorkspaceAdapter implements WorkspaceFileAdapter {
4
4
  readonly displayName: string;
@@ -15,4 +15,7 @@ export declare class MemoryWorkspaceAdapter implements WorkspaceFileAdapter {
15
15
  listEntries(path: string, signal?: AbortSignal): Promise<WorkspaceEntry[]>;
16
16
  readFile(path: string): Promise<Blob>;
17
17
  writeFile(path: string, source: WriteSource, options?: WriteOptions): Promise<void>;
18
+ createDirectory(path: string): Promise<void>;
19
+ remove(path: string, options?: RemoveOptions): Promise<void>;
20
+ move(from: string, to: string): Promise<void>;
18
21
  }
@@ -21,6 +21,20 @@ export interface WorkspaceFileAdapter {
21
21
  readFile(path: string): Promise<Blob>;
22
22
  /** 全部内容写完才提交;失败或取消时原文件保持不变,新建的文件不会残留。 */
23
23
  writeFile(path: string, source: WriteSource, options?: WriteOptions): Promise<void>;
24
+ /** 逐级创建目录,已存在时不报错。路径上有同名文件时抛 TypeMismatchError。 */
25
+ createDirectory?(path: string): Promise<void>;
26
+ /** 删除文件或目录。非空目录需要 recursive,否则抛 InvalidModificationError。不能删除根目录。 */
27
+ remove?(path: string, options?: RemoveOptions): Promise<void>;
28
+ /**
29
+ * 把 from 移到 to(to 是最终路径,不是目标目录)。to 的父目录必须存在。
30
+ * to 已是文件时覆盖;from 或 to 有一方是已存在的目录、或 to 在 from 之内时抛 InvalidModificationError。
31
+ */
32
+ move?(from: string, to: string): Promise<void>;
24
33
  }
34
+ export interface RemoveOptions {
35
+ recursive?: boolean;
36
+ }
37
+ /** from 与 to 都已规范化;to 等于 from 或在 from 之下。 */
38
+ export declare function isSameOrInside(from: string, to: string): boolean;
25
39
  export declare function domError(name: string, message?: string): DOMException;
26
40
  export declare function toChunks(source: WriteSource): AsyncIterable<Uint8Array>;
@@ -11,6 +11,8 @@ export interface FsaHandleBase {
11
11
  readonly name: string;
12
12
  queryPermission?(descriptor?: FsaPermissionDescriptor): Promise<PermissionState>;
13
13
  requestPermission?(descriptor?: FsaPermissionDescriptor): Promise<PermissionState>;
14
+ /** Chromium 部分版本支持;目录移动支持更晚。 */
15
+ move?(destination: FsaDirectoryHandle, name: string): Promise<void>;
14
16
  }
15
17
  export interface FsaFileHandle extends FsaHandleBase {
16
18
  readonly kind: 'file';
@@ -5,7 +5,8 @@ export type LocalFilesFunctionCode = (typeof LOCAL_FILES_FUNCTION_CODES)[number]
5
5
  * 平台上的内置工具插件。本地文件工具和 `run_python` 都在这一个插件里。
6
6
  * dev、test、prod、local 使用同一个 pluginCode。
7
7
  */
8
- export declare const BUILTIN_TOOLS_PLUGIN_CODE = "buildin_tools";
8
+ /** 平台插件编码。与内置工具 OpenAPI 的 pluginCode 一致。 */
9
+ export declare const BUILTIN_TOOLS_PLUGIN_CODE = "builtin_tools";
9
10
  export declare const BUILTIN_TOOLS_PLUGIN_CODES: Record<Env, string>;
10
11
  /** 与 `BUILTIN_TOOLS_PLUGIN_CODES` 相同。文件工具和脚本工具共用一个插件编码。 */
11
12
  export declare const LOCAL_FILES_PLUGIN_CODES: Record<Env, string>;
@@ -9,11 +9,22 @@ export interface HostWebView {
9
9
  data: unknown;
10
10
  }) => void): void;
11
11
  }
12
+ /**
13
+ * 宿主声明的能力。
14
+ * - `sandbox-exec`:命令交给 SDK 沙箱包执行,支持 `exec` 消息。
15
+ * - `fs-mutate`:支持 `mkdir`、`remove`、`move` 消息。
16
+ */
17
+ export type HostCapability = 'sandbox-exec' | 'fs-mutate';
18
+ /** SDK 支持的沙箱包协议版本。宿主声明的 sandboxProtocol 不同时不使用宿主沙箱。 */
19
+ export declare const SANDBOX_PROTOCOL = 1;
12
20
  export interface HostWorkspaceMessage {
13
21
  channel: string;
14
22
  type: 'workspace';
15
23
  granted?: boolean;
16
24
  displayName?: string;
25
+ capabilities?: HostCapability[];
26
+ sandboxVersion?: string;
27
+ sandboxProtocol?: number;
17
28
  }
18
29
  export interface HostResponseMessage {
19
30
  channel: string;
@@ -27,6 +38,8 @@ export interface HostResponseMessage {
27
38
  timedOut?: boolean;
28
39
  stdout?: string;
29
40
  stderr?: string;
41
+ /** shell 结束后的工作区相对目录。 */
42
+ cwd?: string;
30
43
  message?: string;
31
44
  }
32
45
  export declare function parseHostMessage(data: unknown): Record<string, unknown> | undefined;
@@ -2,7 +2,8 @@ export * from './constants';
2
2
  export * from './types';
3
3
  export { ToolCode, ToolError, toToolError } from './errors';
4
4
  export type { ToolErrorData, ToolErrorReason } from './errors';
5
- export { BUILTIN_TOOL_SCHEMAS, LOCAL_FILE_TOOL_SCHEMAS, LOCAL_PYTHON_TOOL_SCHEMA } from './schemas';
5
+ export { LOCAL_FILE_TOOL_SCHEMAS, LOCAL_PYTHON_TOOL_SCHEMA } from './schemas';
6
+ export { BUILTIN_TOOL_SCHEMAS } from '../builtinTools/schemas';
6
7
  export type { BuiltinToolSchema, JsonSchema, LocalFileToolSchema } from './schemas';
7
8
  export { createLocalFilesPlugin } from './createLocalFilesPlugin';
8
9
  export type { CreateLocalFilesPluginOptions, LocalFilesHandler, LocalFilesPluginTable, } from './createLocalFilesPlugin';
@@ -10,7 +11,7 @@ export { LocalWorkspace } from './workspace/LocalWorkspace';
10
11
  export type { LocalWorkspaceOptions } from './workspace/LocalWorkspace';
11
12
  export { createIndexedDbStore, createMemoryStore } from './workspace/handleStore';
12
13
  export type { KeyValueStore } from './workspace/handleStore';
13
- export type { WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource, } from './adapters/WorkspaceFileAdapter';
14
+ export type { RemoveOptions, WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource, } from './adapters/WorkspaceFileAdapter';
14
15
  export { FileSystemAccessAdapter } from './adapters/FileSystemAccessAdapter';
15
16
  export { MemoryWorkspaceAdapter } from './adapters/MemoryWorkspaceAdapter';
16
17
  export type { FsaDirectoryHandle, ShowDirectoryPicker } from './adapters/fsaTypes';
@@ -1,4 +1,4 @@
1
- import { LocalFilesFunctionCode, LOCAL_PYTHON_FUNCTION_CODE } from './constants';
1
+ import { LocalFilesFunctionCode } from './constants';
2
2
  export interface JsonSchema {
3
3
  type?: 'object' | 'string' | 'integer' | 'number' | 'boolean' | 'array';
4
4
  description?: string;
@@ -9,6 +9,7 @@ export interface JsonSchema {
9
9
  minimum?: number;
10
10
  maximum?: number;
11
11
  minLength?: number;
12
+ maxLength?: number;
12
13
  minItems?: number;
13
14
  maxItems?: number;
14
15
  oneOf?: JsonSchema[];
@@ -26,5 +27,3 @@ export interface LocalFileToolSchema extends BuiltinToolSchema {
26
27
  export declare const LOCAL_FILE_TOOL_SCHEMAS: Record<LocalFilesFunctionCode, LocalFileToolSchema>;
27
28
  /** run_python 的参数 Schema。与文件工具一起注册到同一个插件。 */
28
29
  export declare const LOCAL_PYTHON_TOOL_SCHEMA: BuiltinToolSchema;
29
- /** 文件工具和 run_python。平台上对应同一个插件。 */
30
- export declare const BUILTIN_TOOL_SCHEMAS: Record<LocalFilesFunctionCode | typeof LOCAL_PYTHON_FUNCTION_CODE, BuiltinToolSchema>;
@@ -82,6 +82,19 @@ export interface LocalFilesConfig {
82
82
  onApprovalRequired?: ApprovalHandler;
83
83
  /** 替换默认的会话文件上传/下载实现。 */
84
84
  transfer?: Partial<SessionFileTransfer>;
85
+ /** shell、run_file、run_skill_script 的执行方式。宿主沙箱由宿主能力声明决定,不在这里配置。 */
86
+ commandRuntime?: CommandRuntimeConfig;
87
+ }
88
+ export interface CommandRuntimeConfig {
89
+ /** 没有宿主沙箱时,在页面里解释 shell 命令、用 Pyodide 运行 Python。 */
90
+ browser?: {
91
+ /** 默认 true。设为 false 后,没有宿主沙箱时命令返回 501。 */
92
+ enabled?: boolean;
93
+ /** just-bash 浏览器构建(ES Module)的地址。默认使用公司 OBS 上与 SDK 匹配的版本。 */
94
+ bashModuleURL?: string;
95
+ /** Pyodide 资源目录,以 `/` 结尾。默认使用公司 OBS 上与 SDK 匹配的版本。 */
96
+ pyodideIndexURL?: string;
97
+ };
85
98
  }
86
99
  export interface PythonApprovalRequest {
87
100
  requestId: string;
@@ -260,7 +273,7 @@ export interface WorkspaceChangedEvent {
260
273
  export interface ToolEventBase {
261
274
  requestId: string;
262
275
  sessionId: string;
263
- functionCode: LocalFilesFunctionCode;
276
+ functionCode: string;
264
277
  path?: string;
265
278
  }
266
279
  export interface ToolProgressEvent extends ToolEventBase {
@@ -1,3 +1,4 @@
1
+ import { CommandRunner } from '../../builtinTools/command';
1
2
  import { WorkspaceFileAdapter } from '../adapters/WorkspaceFileAdapter';
2
3
  import { ShowDirectoryPicker } from '../adapters/fsaTypes';
3
4
  import { LocalFilesLimits } from '../constants';
@@ -15,6 +16,8 @@ export interface LocalWorkspaceOptions {
15
16
  /** 默认会话文件传输的 API 来源;config.transfer 中的方法优先。 */
16
17
  transfer?: SessionFileTransfer;
17
18
  fetch?: typeof fetch;
19
+ /** shell、run_file、run_skill_script 的执行器。未设置时依次尝试宿主沙箱、浏览器运行时。 */
20
+ commandRunner?: CommandRunner;
18
21
  }
19
22
  /**
20
23
  * 工作文件夹授权与运行状态。一个 BotClient 对应一个实例;UI 与纯 SDK 集成共用同一实例。
@@ -27,6 +30,12 @@ export declare class LocalWorkspace {
27
30
  readonly allowWorkspaceWideTextSearch: boolean;
28
31
  readonly transfer: SessionFileTransfer;
29
32
  readonly fetch: typeof fetch;
33
+ commandRunner?: CommandRunner;
34
+ readonly browserRuntime: {
35
+ enabled: boolean;
36
+ bashModuleURL?: string;
37
+ pyodideIndexURL?: string;
38
+ };
30
39
  private readonly store;
31
40
  private readonly picker?;
32
41
  private readonly event;
@@ -36,6 +45,7 @@ export declare class LocalWorkspace {
36
45
  private pendingHandle;
37
46
  private approvalHandler?;
38
47
  private activeCalls;
48
+ private commandRunning;
39
49
  private readonly inflight;
40
50
  private _ready;
41
51
  private stopWatching;
@@ -84,6 +94,8 @@ export declare class LocalWorkspace {
84
94
  getApprovalHandler(): ApprovalHandler | undefined;
85
95
  /** @internal 占用一个并发名额;已满时返回 null。 */
86
96
  acquireSlot(): (() => void) | null;
97
+ /** @internal 同一工作区同一时间只跑一个命令;已有命令在运行时返回 null。 */
98
+ acquireCommand(): (() => void) | null;
87
99
  /** @internal 登记进行中的调用,更换或断开工作区时统一中止。 */
88
100
  track(controller: AbortController): () => boolean;
89
101
  /** 中止所有进行中的调用(含等待确认的请求)。 */