@glodon-aiot/bot-client-sdk 3.26.0-alpha.23 → 3.26.0-alpha.26

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 (83) hide show
  1. package/README.md +180 -130
  2. package/dist/es/AgentSession.mjs +148 -129
  3. package/dist/es/BotClient.mjs +154 -136
  4. package/dist/es/Config.mjs +56 -89
  5. package/dist/es/Session.mjs +35 -23
  6. package/dist/es/builtinTools/browserRuntime/BrowserCommandRunner.mjs +201 -0
  7. package/dist/es/builtinTools/browserRuntime/PythonRunner.mjs +356 -0
  8. package/dist/es/builtinTools/browserRuntime/WorkspaceBashFs.mjs +350 -0
  9. package/dist/es/builtinTools/browserRuntime/assets.mjs +9 -0
  10. package/dist/es/builtinTools/browserRuntime/loadBash.mjs +17 -0
  11. package/dist/es/builtinTools/browserRuntime/pyodideRunner.py.mjs +96 -0
  12. package/dist/es/builtinTools/browserRuntime/pyodideWorker.mjs +242 -0
  13. package/dist/es/builtinTools/command.mjs +56 -0
  14. package/dist/es/builtinTools/constants.mjs +10 -0
  15. package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +262 -0
  16. package/dist/es/builtinTools/overview.mjs +77 -0
  17. package/dist/es/builtinTools/paths.mjs +69 -0
  18. package/dist/es/builtinTools/platformSkills.mjs +210 -0
  19. package/dist/es/builtinTools/schemas.mjs +216 -0
  20. package/dist/es/builtinTools/tools.mjs +494 -0
  21. package/dist/es/index.mjs +66 -64
  22. package/dist/es/localFiles/adapters/FileSnapshotAdapter.mjs +160 -0
  23. package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +185 -113
  24. package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +127 -137
  25. package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +132 -97
  26. package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +32 -28
  27. package/dist/es/localFiles/constants.mjs +24 -29
  28. package/dist/es/localFiles/errors.mjs +21 -19
  29. package/dist/es/localFiles/host/connectHostBridge.mjs +37 -34
  30. package/dist/es/localFiles/host/protocol.mjs +27 -13
  31. package/dist/es/localFiles/host/sandboxClient.mjs +476 -0
  32. package/dist/es/localFiles/host/sandboxFrames.mjs +21 -0
  33. package/dist/es/localFiles/preview.mjs +33 -0
  34. package/dist/es/localFiles/schemas.mjs +40 -86
  35. package/dist/es/localFiles/validate.mjs +37 -37
  36. package/dist/es/localFiles/workspace/LocalWorkspace.mjs +167 -86
  37. package/dist/es/localFiles/workspace/WorkspaceFiles.mjs +246 -0
  38. package/dist/es/localMcp/client.mjs +223 -0
  39. package/dist/es/localMcp/register.mjs +155 -0
  40. package/dist/es/localMcp/registry.mjs +39 -0
  41. package/dist/es/package.json.mjs +38 -29
  42. package/dist/es/sessionUpload.mjs +49 -0
  43. package/dist/lib/index.js +379 -10
  44. package/dist/src/AgentSession.d.ts +2 -0
  45. package/dist/src/Config.d.ts +5 -7
  46. package/dist/src/Session.d.ts +6 -0
  47. package/dist/src/builtinTools/browserRuntime/BrowserCommandRunner.d.ts +26 -0
  48. package/dist/src/builtinTools/browserRuntime/PythonRunner.d.ts +67 -0
  49. package/dist/src/builtinTools/browserRuntime/WorkspaceBashFs.d.ts +51 -0
  50. package/dist/src/builtinTools/browserRuntime/assets.d.ts +13 -0
  51. package/dist/src/builtinTools/browserRuntime/loadBash.d.ts +3 -0
  52. package/dist/src/builtinTools/browserRuntime/pyodideWorker.d.ts +44 -0
  53. package/dist/src/builtinTools/command.d.ts +35 -0
  54. package/dist/src/builtinTools/constants.d.ts +17 -0
  55. package/dist/src/builtinTools/createBuiltinToolsPlugin.d.ts +11 -0
  56. package/dist/src/builtinTools/overview.d.ts +5 -0
  57. package/dist/src/builtinTools/paths.d.ts +16 -0
  58. package/dist/src/builtinTools/platformSkills.d.ts +67 -0
  59. package/dist/src/builtinTools/schemas.d.ts +3 -0
  60. package/dist/src/builtinTools/tools.d.ts +64 -0
  61. package/dist/src/index.d.ts +2 -1
  62. package/dist/src/localFiles/adapters/FileSnapshotAdapter.d.ts +24 -0
  63. package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +4 -1
  64. package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +30 -14
  65. package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +4 -1
  66. package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +22 -0
  67. package/dist/src/localFiles/adapters/fsaTypes.d.ts +2 -0
  68. package/dist/src/localFiles/constants.d.ts +3 -13
  69. package/dist/src/localFiles/host/protocol.d.ts +34 -16
  70. package/dist/src/localFiles/host/sandboxClient.d.ts +104 -0
  71. package/dist/src/localFiles/host/sandboxFrames.d.ts +9 -0
  72. package/dist/src/localFiles/index.d.ts +11 -6
  73. package/dist/src/localFiles/preview.d.ts +2 -0
  74. package/dist/src/localFiles/schemas.d.ts +2 -5
  75. package/dist/src/localFiles/types.d.ts +16 -23
  76. package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +35 -1
  77. package/dist/src/localFiles/workspace/WorkspaceFiles.d.ts +63 -0
  78. package/dist/src/localMcp/client.d.ts +11 -0
  79. package/dist/src/localMcp/register.d.ts +32 -0
  80. package/dist/src/localMcp/registry.d.ts +26 -0
  81. package/dist/src/sessionUpload.d.ts +14 -0
  82. package/package.json +13 -4
  83. package/dist/es/localFiles/createLocalPythonPlugin.mjs +0 -196
@@ -4,9 +4,11 @@ import { default as Session, QuestionBody, QuestionConfig } from './Session';
4
4
  import { default as BotClient } from './BotClient';
5
5
  export default class AgentSession extends Session {
6
6
  private readonly inflightCalls;
7
+ private localMcpTicket;
7
8
  constructor(token: string, _id?: string, _data?: Partial<ISession>, lazyload?: boolean, application?: IApplication, client?: BotClient);
8
9
  prepareConnection(): Promise<boolean>;
9
10
  registerMcpFromClientConfig(): Promise<boolean>;
11
+ private registerLocalMcp;
10
12
  addMcpServers(mcpServers: MCPConfig): Promise<boolean>;
11
13
  listMcpServers(): Promise<MCPConfig>;
12
14
  sendQuestion(questionBody: QuestionBody, configs: QuestionConfig): Promise<false | undefined>;
@@ -1,4 +1,4 @@
1
- import { BuiltinPluginsConfig, LocalFilesConfig, LocalPythonConfig } from './localFiles/types';
1
+ import { BuiltinPluginsConfig, LocalFilesConfig } from './localFiles/types';
2
2
  import { LocalWorkspace } from './localFiles/workspace/LocalWorkspace';
3
3
  export interface McpServer {
4
4
  type: 'sse';
@@ -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,12 +53,8 @@ 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。 */
57
- export declare function getRegisteredLocalPythonPluginCode(): string | undefined;
58
56
  /** 显式配置优先,其次按 env 取默认值;都没有时返回 undefined。 */
59
57
  export declare function resolveLocalFilesPluginCode(config: LocalFilesConfig | undefined, env: string): string;
60
- /** 显式配置优先,其次跟随文件工具编码,最后按 env 取默认值。 */
61
- export declare function resolveLocalPythonPluginCode(config: LocalPythonConfig | undefined, env: string, filesPluginCode?: string): string;
62
58
  /**
63
59
  * 重新计算 configuration.plugins,返回本次新出现的问题(相同问题只报告一次)。
64
60
  */
@@ -67,4 +63,6 @@ export declare function refreshBuiltinPlugins(): Error[];
67
63
  * 配置SDK,可以在SDK被使用前被调用,该方法被调用后将改变是否debug模式、是否测试环境等基本配置
68
64
  * @param param {debug?: boolean; env?: 'dev' | 'test' | 'prod';}
69
65
  */
70
- export declare function configure(param?: BotClientConfig): void;
66
+ export declare function configure(param?: BotClientConfig, options?: {
67
+ refreshBuiltinPlugins?: boolean;
68
+ }): void;
@@ -4,6 +4,7 @@ import { Socket } from 'socket.io-client';
4
4
  import { default as EventBus } from './EventBus';
5
5
  import { ActionPayload, PluginFunctionBasic, Thought } from './PayloadTypes';
6
6
  import { default as BotClient } from './BotClient';
7
+ import { SessionUploadResult } from './sessionUpload';
7
8
  export declare enum NetOpen {
8
9
  enable = 1,
9
10
  disable = 2
@@ -176,6 +177,11 @@ export default abstract class Session {
176
177
  abstract listMcpServers(): Promise<MCPConfig>;
177
178
  get dataLoaded(): boolean;
178
179
  get messagesLoading(): boolean;
180
+ /**
181
+ * 把文件上传到当前会话的对象存储,返回可访问的地址。
182
+ * 图片地址放进 send 的 imageContent。
183
+ */
184
+ upload(file: File): Promise<SessionUploadResult>;
179
185
  send(params: {
180
186
  text?: string;
181
187
  files?: any[];
@@ -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,35 @@
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
+ /** 命令还在跑时收到的一块 stdout 或 stderr。 */
12
+ onOutput?: (stream: 'stdout' | 'stderr', text: string) => void;
13
+ /** 只在 run_skill_script 中设置。沙箱据此只读挂载该版本目录。 */
14
+ skill?: {
15
+ applicationId: string;
16
+ skillId: string;
17
+ version: number;
18
+ name: string;
19
+ };
20
+ }
21
+ export interface CommandResult {
22
+ exitCode: number;
23
+ stdout: string;
24
+ stderr: string;
25
+ /** 命令结束后的工作区相对目录。shell 用来保留上次停留的目录。 */
26
+ cwd?: string;
27
+ }
28
+ export interface CommandRunner {
29
+ exec(request: CommandRequest): Promise<CommandResult>;
30
+ }
31
+ /** stdout、stderr 各自返回给模型的字符上限。 */
32
+ export declare const MAX_COMMAND_OUTPUT_CHARS = 16000;
33
+ export declare const OUTPUT_TRUNCATED_NOTE = "\n\u2026\u8F93\u51FA\u5DF2\u622A\u65AD";
34
+ export declare function limitOutput(text: string): string;
35
+ 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,16 @@
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 mentionsSkillDir(text: string): boolean;
4
+ export declare function mentionsSyntheticDir(text: string): boolean;
5
+ export declare function isSyntheticCwd(cwd: string): boolean;
6
+ /**
7
+ * 把工作区内绝对路径转成相对工作区根的路径。`/` 表示工作区根。
8
+ * 拒绝相对路径、盘符和 .. 。
9
+ */
10
+ export declare function resolveWorkspacePath(input: string): string;
11
+ export declare function resolveFilePath(input: string): string;
12
+ export declare function resolveRunPath(input: string): string;
13
+ export declare function toVirtualPath(relative: string): string;
14
+ /** shell 回传的目录必须仍在工作区内。`.` 表示工作区根。 */
15
+ export declare function isSafeCwd(cwd: string): boolean;
16
+ export declare function skillRelative(skillName: string, relativeName: string): string;
@@ -0,0 +1,67 @@
1
+ export interface ArrangeSkillInput {
2
+ skillId?: string;
3
+ name?: string;
4
+ displayName?: string;
5
+ description?: string;
6
+ version?: number;
7
+ }
8
+ export interface SkillRecord {
9
+ skillId: string;
10
+ name: string;
11
+ version: number;
12
+ }
13
+ export interface SkillSandbox {
14
+ ready: boolean;
15
+ unavailableMessage(): string;
16
+ skillStatus(applicationId: string, signal?: AbortSignal): Promise<unknown>;
17
+ skillRead(applicationId: string, skillId: string, version: number, path: string, signal?: AbortSignal): Promise<Uint8Array>;
18
+ installSkill(fields: {
19
+ applicationId: string;
20
+ skillId: string;
21
+ version: number;
22
+ name: string;
23
+ }, bytes: Uint8Array, signal?: AbortSignal): Promise<void>;
24
+ skillPrune(applicationId: string, keep: Array<{
25
+ skillId: string;
26
+ version: number;
27
+ }>, busy: Array<{
28
+ skillId: string;
29
+ version: number;
30
+ }>, signal?: AbortSignal): Promise<void>;
31
+ }
32
+ /** 缺省、空数组和非数组都当成没有技能。 */
33
+ export declare function listedSkills(arrange?: {
34
+ skills?: ArrangeSkillInput[];
35
+ } | null): ArrangeSkillInput[];
36
+ export declare class PlatformSkillSync {
37
+ private readonly options;
38
+ private readonly inflight;
39
+ private readonly busy;
40
+ constructor(options: {
41
+ applicationId: () => string;
42
+ getToken: () => string;
43
+ getSkills: () => ArrangeSkillInput[];
44
+ apiRoot: () => string;
45
+ getSandbox: () => SkillSandbox | undefined;
46
+ fetch?: typeof fetch;
47
+ });
48
+ /** 进入会话时调用。不阻塞历史,也不改沙箱就绪。 */
49
+ sync(): Promise<void | undefined>;
50
+ read(name: string, relative: string, signal?: AbortSignal): Promise<Uint8Array<ArrayBufferLike>>;
51
+ target(name: string, signal?: AbortSignal): Promise<{
52
+ applicationId: string;
53
+ skillId: string;
54
+ version: number;
55
+ name: string;
56
+ }>;
57
+ track(skillId: string, version: number): () => void;
58
+ private requireSandbox;
59
+ private prepare;
60
+ private bound;
61
+ private reconcile;
62
+ private ensure;
63
+ private installIfNeeded;
64
+ private alreadyInstalled;
65
+ private prune;
66
+ private waitReady;
67
+ }
@@ -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,64 @@
1
+ import { WorkspaceFileAdapter } from '../localFiles/adapters/WorkspaceFileAdapter';
2
+ import { CommandRunner } from './command';
3
+ import { PlatformSkillSync } from './platformSkills';
4
+ export interface ToolIO {
5
+ adapter: WorkspaceFileAdapter;
6
+ runner?: CommandRunner;
7
+ signal?: AbortSignal;
8
+ timeoutMs: number;
9
+ shellCwd: {
10
+ cwd: string;
11
+ };
12
+ skills?: PlatformSkillSync;
13
+ /** 只接注入的执行器或已就绪的宿主沙箱,不接浏览器运行时。 */
14
+ skillRunner?: CommandRunner;
15
+ }
16
+ interface ToolOutput {
17
+ data: Record<string, unknown>;
18
+ truncated?: boolean;
19
+ }
20
+ export declare function readFile(input: {
21
+ path: string;
22
+ start_line?: number;
23
+ end_line?: number;
24
+ }, io: ToolIO): Promise<ToolOutput>;
25
+ export declare function writeFile(input: {
26
+ path: string;
27
+ content: string;
28
+ }, io: ToolIO): Promise<ToolOutput>;
29
+ export declare function appendFile(input: {
30
+ path: string;
31
+ content: string;
32
+ }, io: ToolIO): Promise<ToolOutput>;
33
+ export declare function editFile(input: {
34
+ path: string;
35
+ old_text: string;
36
+ new_text: string;
37
+ }, io: ToolIO): Promise<ToolOutput>;
38
+ export declare function grep(input: {
39
+ path: string;
40
+ pattern: string;
41
+ }, io: ToolIO): Promise<ToolOutput>;
42
+ export declare function find(input: {
43
+ path: string;
44
+ name: string;
45
+ }, io: ToolIO): Promise<ToolOutput>;
46
+ export declare function runFile(input: {
47
+ path: string;
48
+ }, io: ToolIO): Promise<ToolOutput>;
49
+ export declare function shell(input: {
50
+ command: string;
51
+ }, io: ToolIO): Promise<ToolOutput>;
52
+ export declare function loadSkill(input: {
53
+ skill_name: string;
54
+ }, io: ToolIO): Promise<ToolOutput>;
55
+ export declare function readSkillResource(input: {
56
+ skill_name: string;
57
+ resource_name: string;
58
+ }, io: ToolIO): Promise<ToolOutput>;
59
+ export declare function runSkillScript(input: {
60
+ skill_name: string;
61
+ script_name: string;
62
+ args?: string[];
63
+ }, io: ToolIO): Promise<ToolOutput>;
64
+ export {};
@@ -1,7 +1,8 @@
1
1
  export type { AgentPluginRegistor, AgentPluginMap, BotClientConfig, MCPConfig, McpServer } from './Config';
2
- export { configure, configuration, getRegisteredLocalFilesPluginCode, getRegisteredLocalPythonPluginCode, resolveLocalFilesPluginCode, } from './Config';
2
+ export { configure, configuration, getRegisteredLocalFilesPluginCode, resolveLocalFilesPluginCode, } from './Config';
3
3
  export type { ISessionArtifact } from '@glodon-aiot/apis';
4
4
  export { default as BotClient } from './BotClient';
5
5
  export { default as Session } from './Session';
6
+ export type { SessionUploadResult } from './sessionUpload';
6
7
  export { default as AgentPlugin } from './AgentPlugin';
7
8
  export * from './localFiles';
@@ -0,0 +1,24 @@
1
+ import { WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource } from './WorkspaceFileAdapter';
2
+ export interface SnapshotFileInput {
3
+ name: string;
4
+ webkitRelativePath?: string;
5
+ lastModified?: number;
6
+ blob: Blob;
7
+ }
8
+ /**
9
+ * 用一次目录选择拿到的文件列表画出目录树。
10
+ * 浏览器取消或无法返回目录句柄时,仍然能按相对路径列出文件夹结构。
11
+ */
12
+ export declare class FileSnapshotAdapter implements WorkspaceFileAdapter {
13
+ readonly displayName: string;
14
+ private readonly root;
15
+ constructor(files: Iterable<SnapshotFileInput>, displayName: string);
16
+ private writeNode;
17
+ private resolveDirectory;
18
+ private resolveNode;
19
+ stat(path: string): Promise<WorkspaceEntry>;
20
+ listEntries(path: string, signal?: AbortSignal): Promise<WorkspaceEntry[]>;
21
+ readFile(path: string): Promise<Blob>;
22
+ /** 只更新内存中的快照,不会写回用户磁盘。 */
23
+ writeFile(path: string, source: WriteSource, options?: WriteOptions): Promise<void>;
24
+ }
@@ -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,24 +1,40 @@
1
+ import { CommandRequest, CommandResult } from '../../builtinTools/command';
2
+ import { SandboxClient, SandboxNotice } from '../host/sandboxClient';
3
+ import { HostCapability, HostBridge } from '../host/protocol';
1
4
  import { WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource } from './WorkspaceFileAdapter';
2
- import { HostResponseMessage, HostWebView } from '../host/protocol';
3
5
  /**
4
- * 把工作区原语转成宿主消息。页面看不到绝对路径,目录由宿主在授权后推送。
6
+ * 工作区原语走沙箱 WebSocket。页面只向宿主发 hello,不转发文件字节和命令输出。
5
7
  */
6
8
  export declare class HostBridgeAdapter implements WorkspaceFileAdapter {
7
- private readonly view;
8
9
  displayName: string;
9
- private seq;
10
- private readonly pending;
11
- constructor(view: HostWebView, displayName?: string);
12
- settle(message: HostResponseMessage): void;
13
- private call;
10
+ capabilities: ReadonlySet<HostCapability>;
11
+ sandboxVersion?: string;
12
+ sandboxProtocol?: number;
13
+ readonly sandbox: SandboxClient;
14
+ constructor(view: HostBridge, displayName?: string, sandbox?: SandboxClient);
15
+ setCapabilities(value: unknown, sandbox?: {
16
+ version?: unknown;
17
+ }): void;
18
+ applySandbox(notice?: SandboxNotice): void;
19
+ /** 沙箱已就绪且协议为 1 时,命令走直连。 */
20
+ get canExec(): boolean;
21
+ get protocolMismatch(): boolean;
22
+ unavailableMessage(): string;
14
23
  stat(path: string): Promise<WorkspaceEntry>;
15
24
  listEntries(path: string, signal?: AbortSignal): Promise<WorkspaceEntry[]>;
16
- readFile(path: string): Promise<Blob>;
17
- runPython(path: string, args: string[], timeoutMs: number, signal?: AbortSignal): Promise<{
18
- exitCode: number;
19
- timedOut: boolean;
20
- stdout: string;
21
- stderr: string;
25
+ url(path: string): Promise<{
26
+ url: string;
27
+ release: () => void;
22
28
  }>;
29
+ readFile(path: string, window?: {
30
+ offset?: number;
31
+ maxBytes?: number;
32
+ }): Promise<Blob>;
33
+ createDirectory(path: string): Promise<void>;
34
+ remove(path: string, options?: {
35
+ recursive?: boolean;
36
+ }): Promise<void>;
37
+ move(from: string, to: string): Promise<void>;
38
+ exec(request: CommandRequest): Promise<CommandResult>;
23
39
  writeFile(path: string, source: WriteSource, options?: WriteOptions): Promise<void>;
24
40
  }
@@ -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
  }