@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
@@ -19,8 +19,30 @@ export interface WorkspaceFileAdapter {
19
19
  stat(path: string): Promise<WorkspaceEntry>;
20
20
  listEntries(path: string, signal?: AbortSignal): Promise<WorkspaceEntry[]>;
21
21
  readFile(path: string): Promise<Blob>;
22
+ /**
23
+ * 给页面标签的地址。实现方不得把文件字节读进页面。
24
+ * `release` 在地址不再使用时调用。
25
+ */
26
+ url?(path: string): Promise<{
27
+ url: string;
28
+ release: () => void;
29
+ }>;
22
30
  /** 全部内容写完才提交;失败或取消时原文件保持不变,新建的文件不会残留。 */
23
31
  writeFile(path: string, source: WriteSource, options?: WriteOptions): Promise<void>;
32
+ /** 逐级创建目录,已存在时不报错。路径上有同名文件时抛 TypeMismatchError。 */
33
+ createDirectory?(path: string): Promise<void>;
34
+ /** 删除文件或目录。非空目录需要 recursive,否则抛 InvalidModificationError。不能删除根目录。 */
35
+ remove?(path: string, options?: RemoveOptions): Promise<void>;
36
+ /**
37
+ * 把 from 移到 to(to 是最终路径,不是目标目录)。to 的父目录必须存在。
38
+ * to 已是文件时覆盖;from 或 to 有一方是已存在的目录、或 to 在 from 之内时抛 InvalidModificationError。
39
+ */
40
+ move?(from: string, to: string): Promise<void>;
24
41
  }
42
+ export interface RemoveOptions {
43
+ recursive?: boolean;
44
+ }
45
+ /** from 与 to 都已规范化;to 等于 from 或在 from 之下。 */
46
+ export declare function isSameOrInside(from: string, to: string): boolean;
25
47
  export declare function domError(name: string, message?: string): DOMException;
26
48
  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';
@@ -1,21 +1,11 @@
1
1
  import { Env } from '../Config';
2
2
  export declare const LOCAL_FILES_FUNCTION_CODES: readonly ["list_directory", "read_file", "stat_file", "search_files", "search_text", "apply_patch", "write_file", "upload_file", "download_file"];
3
3
  export type LocalFilesFunctionCode = (typeof LOCAL_FILES_FUNCTION_CODES)[number];
4
- /**
5
- * 平台上的内置工具插件。本地文件工具和 `run_python` 都在这一个插件里。
6
- * dev、test、prod、local 使用同一个 pluginCode。
7
- */
8
- export declare const BUILTIN_TOOLS_PLUGIN_CODE = "buildin_tools";
4
+ /** 平台插件编码。与内置工具 OpenAPI 的 pluginCode 一致。dev、test、prod、local 使用同一个 pluginCode。 */
5
+ export declare const BUILTIN_TOOLS_PLUGIN_CODE = "builtin_tools";
9
6
  export declare const BUILTIN_TOOLS_PLUGIN_CODES: Record<Env, string>;
10
- /** 与 `BUILTIN_TOOLS_PLUGIN_CODES` 相同。文件工具和脚本工具共用一个插件编码。 */
7
+ /** 与 `BUILTIN_TOOLS_PLUGIN_CODES` 相同。 */
11
8
  export declare const LOCAL_FILES_PLUGIN_CODES: Record<Env, string>;
12
- /** 本地 Python 脚本。与文件工具注册在同一个插件里。 */
13
- export declare const LOCAL_PYTHON_FUNCTION_CODE = "run_python";
14
- /** 与 `BUILTIN_TOOLS_PLUGIN_CODES` 相同。未单独配置时跟随文件工具的 pluginCode。 */
15
- export declare const LOCAL_PYTHON_PLUGIN_CODES: Record<Env, string>;
16
- export declare const PYTHON_DEFAULT_TIMEOUT_MS = 20000;
17
- export declare const PYTHON_MAX_TIMEOUT_MS = 120000;
18
- export declare const PYTHON_MAX_ARGS = 16;
19
9
  export declare const WORKSPACE_GRANT_ID = "current-workspace";
20
10
  export declare const KiB = 1024;
21
11
  export declare const MiB: number;
@@ -1,6 +1,9 @@
1
1
  /** 宿主与页面之间的通道名。根目录只由宿主设置,消息里不能带绝对路径。 */
2
2
  export declare const HOST_CHANNEL = "glodon-workspace";
3
- export interface HostWebView {
3
+ /** 宿主在页面脚本运行前挂上的消息桥。不对应某一种 WebView 或浏览器内核。 */
4
+ export declare const HOST_BRIDGE_GLOBAL = "__glodonHostBridge";
5
+ /** 页面与宿主之间的双向消息桥。消息正文是普通 JSON。 */
6
+ export interface HostBridge {
4
7
  postMessage(message: unknown): void;
5
8
  addEventListener(type: 'message', listener: (event: {
6
9
  data: unknown;
@@ -9,25 +12,40 @@ export interface HostWebView {
9
12
  data: unknown;
10
13
  }) => void): void;
11
14
  }
15
+ /**
16
+ * 宿主声明的能力。文件和命令不经过宿主转发,能力只用于兼容旧的 workspace 消息。
17
+ * - `sandbox-exec`:宿主会启动沙箱进程。
18
+ * - `fs-mutate`:宿主允许改动工程文件。
19
+ */
20
+ export type HostCapability = 'sandbox-exec' | 'fs-mutate';
21
+ /** SDK 直连沙箱使用的协议版本。 */
22
+ export declare const SANDBOX_PROTOCOL = 1;
23
+ /** 与 workspace-sandbox 的 MAX_FILE_BYTES 一致。只用于直连本地沙箱。 */
24
+ export declare const SANDBOX_MAX_FILE_BYTES: number;
25
+ export interface HostSandboxState {
26
+ state?: 'starting' | 'ready' | 'failed' | 'exited';
27
+ url?: string;
28
+ token?: string;
29
+ protocol?: number;
30
+ exitCode?: number;
31
+ detail?: string;
32
+ message?: string;
33
+ reason?: string;
34
+ }
12
35
  export interface HostWorkspaceMessage {
13
36
  channel: string;
14
37
  type: 'workspace';
15
38
  granted?: boolean;
16
39
  displayName?: string;
17
- }
18
- export interface HostResponseMessage {
19
- channel: string;
20
- id: string;
21
- ok?: boolean;
22
- name?: string;
23
- entries?: unknown;
24
- entry?: unknown;
25
- contentBase64?: string;
26
- exitCode?: number;
27
- timedOut?: boolean;
28
- stdout?: string;
29
- stderr?: string;
30
- message?: string;
40
+ capabilities?: HostCapability[];
41
+ sandboxVersion?: string;
42
+ sandbox?: HostSandboxState;
31
43
  }
32
44
  export declare function parseHostMessage(data: unknown): Record<string, unknown> | undefined;
33
- export declare function getHostWebView(): HostWebView | undefined;
45
+ /** 挂上当前页面的宿主消息桥。传入空值时移除。 */
46
+ export declare function registerHostBridge(bridge?: HostBridge): void;
47
+ /**
48
+ * 优先使用宿主注册的消息桥。没有注册时,接受已经具备同样三个方法的 `chrome.webview`,
49
+ * 让自带该对象的嵌入环境不必再包一层。
50
+ */
51
+ export declare function getHostBridge(): HostBridge | undefined;
@@ -0,0 +1,104 @@
1
+ export interface SandboxNotice {
2
+ state?: 'starting' | 'ready' | 'failed' | 'exited';
3
+ url?: string;
4
+ token?: string;
5
+ protocol?: number;
6
+ exitCode?: number;
7
+ detail?: string;
8
+ message?: string;
9
+ reason?: string;
10
+ }
11
+ export interface SandboxSocketLike {
12
+ readyState: number;
13
+ binaryType: string;
14
+ onopen: ((event?: unknown) => void) | null;
15
+ onmessage: ((event: {
16
+ data: unknown;
17
+ }) => void) | null;
18
+ onclose: ((event?: unknown) => void) | null;
19
+ onerror: ((event?: unknown) => void) | null;
20
+ send(data: string | Uint8Array): void;
21
+ close(): void;
22
+ }
23
+ export type SandboxOpener = (url: string) => SandboxSocketLike;
24
+ export interface SandboxExecResult {
25
+ exitCode: number;
26
+ timedOut: boolean;
27
+ stdout: string;
28
+ stderr: string;
29
+ cwd?: string;
30
+ /** 宿主网络策略拒绝的 host:port,只在 allowlist 模式下出现。 */
31
+ denied?: string[];
32
+ }
33
+ /** 宿主给沙箱的网络策略摘要。页面只能读,不能改。 */
34
+ export interface SandboxPolicySummary {
35
+ revision: number;
36
+ network: {
37
+ mode: 'off' | 'allowlist' | 'open';
38
+ allow: string[];
39
+ };
40
+ packages: {
41
+ python: {
42
+ enabled: boolean;
43
+ };
44
+ };
45
+ /** 宿主允许同时运行的命令数。旧沙箱不发这个字段。 */
46
+ exec?: {
47
+ maxConcurrent: number;
48
+ };
49
+ }
50
+ /** 旧沙箱不发策略时按断网处理。 */
51
+ export declare const OFFLINE_POLICY: SandboxPolicySummary;
52
+ /** 页面直连 127.0.0.1 上的沙箱。令牌只出现在认证帧里。 */
53
+ export declare class SandboxClient {
54
+ private readonly openSocket;
55
+ notice?: SandboxNotice;
56
+ /** 沙箱最近一次告知的网络策略。 */
57
+ policy: SandboxPolicySummary;
58
+ private socket?;
59
+ private generation;
60
+ private authed;
61
+ private seq;
62
+ private readonly calls;
63
+ private outgoing;
64
+ constructor(openSocket?: SandboxOpener);
65
+ get ready(): boolean;
66
+ unavailableMessage(): string;
67
+ apply(notice?: SandboxNotice): void;
68
+ /** `ws://127.0.0.1:port` 的主机和端口,文件地址拼在它前面。 */
69
+ httpOrigin(): string;
70
+ stat(path: string): Promise<Record<string, unknown>>;
71
+ url(path: string): Promise<string>;
72
+ releaseUrl(ticket: string): Promise<void>;
73
+ list(path: string, signal?: AbortSignal): Promise<Record<string, unknown>>;
74
+ read(path: string, offset?: number, maxBytes?: number, signal?: AbortSignal): Promise<Uint8Array<ArrayBuffer>>;
75
+ write(path: string, bytes: Uint8Array, createDirectories: boolean, signal?: AbortSignal): Promise<void>;
76
+ skillStatus(applicationId: string, signal?: AbortSignal): Promise<any[]>;
77
+ skillRead(applicationId: string, skillId: string, version: number, path: string, signal?: AbortSignal): Promise<Uint8Array<ArrayBuffer>>;
78
+ installSkill(fields: {
79
+ applicationId: string;
80
+ skillId: string;
81
+ version: number;
82
+ name: string;
83
+ }, bytes: Uint8Array, signal?: AbortSignal): Promise<void>;
84
+ skillPrune(applicationId: string, keep: Array<{
85
+ skillId: string;
86
+ version: number;
87
+ }>, busy: Array<{
88
+ skillId: string;
89
+ version: number;
90
+ }>, signal?: AbortSignal): Promise<void>;
91
+ mkdir(path: string): Promise<void>;
92
+ remove(path: string, recursive: boolean): Promise<void>;
93
+ move(from: string, to: string): Promise<void>;
94
+ exec(fields: Record<string, unknown>, signal?: AbortSignal, onOutput?: (stream: 'stdout' | 'stderr', text: string) => void): Promise<SandboxExecResult>;
95
+ private invoke;
96
+ private begin;
97
+ private next;
98
+ private send;
99
+ private connect;
100
+ private onFrame;
101
+ private push;
102
+ private failAll;
103
+ private stop;
104
+ }
@@ -0,0 +1,9 @@
1
+ declare const MAX_BINARY_PAYLOAD: number;
2
+ export declare function encodeBinaryFrame(id: string, offset: number, eof: boolean, payload: Uint8Array): Uint8Array<ArrayBuffer>;
3
+ export declare function decodeBinaryFrame(data: Uint8Array): {
4
+ id: string;
5
+ offset: number;
6
+ eof: boolean;
7
+ payload: Uint8Array<ArrayBufferLike>;
8
+ };
9
+ export { MAX_BINARY_PAYLOAD };
@@ -2,20 +2,25 @@ 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';
6
- export type { BuiltinToolSchema, JsonSchema, LocalFileToolSchema } from './schemas';
5
+ export { LOCAL_FILE_TOOL_SCHEMAS } from './schemas';
6
+ export { BUILTIN_TOOL_SCHEMAS } from '../builtinTools/schemas';
7
+ export type { BuiltinToolSchema, JsonSchema, LocalFileToolSchema, } from './schemas';
7
8
  export { createLocalFilesPlugin } from './createLocalFilesPlugin';
8
9
  export type { CreateLocalFilesPluginOptions, LocalFilesHandler, LocalFilesPluginTable, } from './createLocalFilesPlugin';
9
10
  export { LocalWorkspace } from './workspace/LocalWorkspace';
10
11
  export type { LocalWorkspaceOptions } from './workspace/LocalWorkspace';
11
- export { createIndexedDbStore, createMemoryStore } from './workspace/handleStore';
12
+ export { WorkspaceFiles, normalizeFilePath } from './workspace/WorkspaceFiles';
13
+ export type { WorkspaceFileInfo, WorkspaceReadOptions, WorkspaceWriteOptions, } from './workspace/WorkspaceFiles';
14
+ export { createIndexedDbStore, createMemoryStore, } from './workspace/handleStore';
12
15
  export type { KeyValueStore } from './workspace/handleStore';
13
- export type { WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource, } from './adapters/WorkspaceFileAdapter';
16
+ export type { RemoveOptions, WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource, } from './adapters/WorkspaceFileAdapter';
14
17
  export { FileSystemAccessAdapter } from './adapters/FileSystemAccessAdapter';
15
18
  export { MemoryWorkspaceAdapter } from './adapters/MemoryWorkspaceAdapter';
16
- export type { FsaDirectoryHandle, ShowDirectoryPicker } from './adapters/fsaTypes';
19
+ export type { FsaDirectoryHandle, ShowDirectoryPicker, } from './adapters/fsaTypes';
20
+ export { HOST_BRIDGE_GLOBAL, HOST_CHANNEL, SANDBOX_MAX_FILE_BYTES, registerHostBridge, } from './host/protocol';
21
+ export type { HostBridge } from './host/protocol';
17
22
  export { createDefaultSessionFileTransfer } from './transfer/SessionFileTransfer';
18
23
  export type { ResolvedDownload, SessionFileTransfer, UploadProgress, } from './transfer/SessionFileTransfer';
19
24
  export { getDownloadUrlAllowlist, isDownloadUrlAllowed, } from './security/downloadUrlPolicy';
20
25
  export { SDK_SENSITIVE_BASELINE } from './security/sensitiveFiles';
21
- export type { SensitiveRule, SensitiveRuleInput } from './security/sensitiveFiles';
26
+ export type { SensitiveRule, SensitiveRuleInput, } from './security/sensitiveFiles';
@@ -0,0 +1,2 @@
1
+ export declare const PREVIEW_TYPE_MESSAGE = "\u53EA\u80FD\u9884\u89C8\u56FE\u7247\u3001\u97F3\u89C6\u9891\u548C PDF\u3002";
2
+ export declare function mediaTypeOf(path: string): string | undefined;
@@ -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[];
@@ -24,7 +25,3 @@ export interface LocalFileToolSchema extends BuiltinToolSchema {
24
25
  }
25
26
  /** 9 个工具的参数 Schema,同时作为平台注册时的草案。 */
26
27
  export declare const LOCAL_FILE_TOOL_SCHEMAS: Record<LocalFilesFunctionCode, LocalFileToolSchema>;
27
- /** run_python 的参数 Schema。与文件工具一起注册到同一个插件。 */
28
- 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>;
@@ -63,11 +63,11 @@ export interface LocalFilesConfig {
63
63
  enabled?: boolean;
64
64
  /**
65
65
  * `file-system-access`:网页里由用户选择目录。
66
- * `host-bridge`:目录由宿主通过 `chrome.webview` 设置,页面不弹选择框。
66
+ * `host-bridge`:目录由宿主消息桥推送,页面不弹选择框。
67
67
  */
68
68
  backend?: 'file-system-access' | 'host-bridge';
69
69
  /**
70
- * 平台上的内置工具插件编码。文件工具和 run_python 使用同一个编码。
70
+ * 平台上的内置工具插件编码。
71
71
  * 未配置时按 env 取 BUILTIN_TOOLS_PLUGIN_CODES。
72
72
  */
73
73
  pluginCode?: string;
@@ -82,29 +82,22 @@ export interface LocalFilesConfig {
82
82
  onApprovalRequired?: ApprovalHandler;
83
83
  /** 替换默认的会话文件上传/下载实现。 */
84
84
  transfer?: Partial<SessionFileTransfer>;
85
- }
86
- export interface PythonApprovalRequest {
87
- requestId: string;
88
- sessionId: string;
89
- path: string;
90
- args: string[];
91
- workspaceName: string;
92
- signal: AbortSignal;
93
- }
94
- export type PythonApprovalHandler = (request: PythonApprovalRequest) => boolean | Promise<boolean>;
95
- export interface LocalPythonConfig {
96
- enabled?: boolean;
97
- /**
98
- * 平台上的内置工具插件编码,须与文件工具相同。
99
- * 未配置时跟随 localFiles.pluginCode,再按 env 取 BUILTIN_TOOLS_PLUGIN_CODES。
100
- */
101
- pluginCode?: string;
102
- /** 运行脚本前的确认。与文件写入确认分开;未配置时一律拒绝。 */
103
- onApprovalRequired?: PythonApprovalHandler;
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
+ };
104
98
  }
105
99
  export interface BuiltinPluginsConfig {
106
100
  localFiles?: LocalFilesConfig;
107
- localPython?: LocalPythonConfig;
108
101
  }
109
102
  export interface WorkspaceGrantInput {
110
103
  grantId: string;
@@ -260,7 +253,7 @@ export interface WorkspaceChangedEvent {
260
253
  export interface ToolEventBase {
261
254
  requestId: string;
262
255
  sessionId: string;
263
- functionCode: LocalFilesFunctionCode;
256
+ functionCode: string;
264
257
  path?: string;
265
258
  }
266
259
  export interface ToolProgressEvent extends ToolEventBase {
@@ -1,3 +1,5 @@
1
+ import { CommandRunner } from '../../builtinTools/command';
2
+ import { PlatformSkillSync } from '../../builtinTools/platformSkills';
1
3
  import { WorkspaceFileAdapter } from '../adapters/WorkspaceFileAdapter';
2
4
  import { ShowDirectoryPicker } from '../adapters/fsaTypes';
3
5
  import { LocalFilesLimits } from '../constants';
@@ -5,6 +7,7 @@ import { SensitiveFilePolicy } from '../security/sensitiveFiles';
5
7
  import { SessionFileTransfer } from '../transfer/SessionFileTransfer';
6
8
  import { ApprovalHandler, LocalFilesConfig, LocalWorkspaceEventMap, LocalWorkspaceEventName, LocalWorkspaceStatus, WorkspaceHandshake } from '../types';
7
9
  import { KeyValueStore } from './handleStore';
10
+ import { WorkspaceFiles } from './WorkspaceFiles';
8
11
  export interface LocalWorkspaceOptions {
9
12
  applicationId: string;
10
13
  config?: LocalFilesConfig;
@@ -15,6 +18,8 @@ export interface LocalWorkspaceOptions {
15
18
  /** 默认会话文件传输的 API 来源;config.transfer 中的方法优先。 */
16
19
  transfer?: SessionFileTransfer;
17
20
  fetch?: typeof fetch;
21
+ /** shell、run_file、run_skill_script 的执行器。未设置时依次尝试宿主沙箱、浏览器运行时。 */
22
+ commandRunner?: CommandRunner;
18
23
  }
19
24
  /**
20
25
  * 工作文件夹授权与运行状态。一个 BotClient 对应一个实例;UI 与纯 SDK 集成共用同一实例。
@@ -27,6 +32,16 @@ export declare class LocalWorkspace {
27
32
  readonly allowWorkspaceWideTextSearch: boolean;
28
33
  readonly transfer: SessionFileTransfer;
29
34
  readonly fetch: typeof fetch;
35
+ commandRunner?: CommandRunner;
36
+ /** 平台技能同步。由 BotClient 在启用本地工作区后挂上。 */
37
+ platformSkills?: PlatformSkillSync;
38
+ readonly browserRuntime: {
39
+ enabled: boolean;
40
+ bashModuleURL?: string;
41
+ pyodideIndexURL?: string;
42
+ };
43
+ /** 接入方的文件操作入口。不要使用 `adapter`。 */
44
+ readonly files: WorkspaceFiles;
30
45
  private readonly store;
31
46
  private readonly picker?;
32
47
  private readonly event;
@@ -36,12 +51,15 @@ export declare class LocalWorkspace {
36
51
  private pendingHandle;
37
52
  private approvalHandler?;
38
53
  private activeCalls;
54
+ private activeCommands;
39
55
  private readonly inflight;
40
56
  private _ready;
41
57
  private stopWatching;
42
58
  private readonly pendingChangePaths;
43
59
  private changeTimer;
44
60
  private refreshAllVisible;
61
+ /** 选择、关闭会推进它。进行中的 restore 若发现已经变了,就不再覆盖当前目录。 */
62
+ private epoch;
45
63
  constructor(options: LocalWorkspaceOptions);
46
64
  get status(): LocalWorkspaceStatus;
47
65
  /** 当前(或待恢复的)文件夹名,不含绝对路径。 */
@@ -49,11 +67,15 @@ export declare class LocalWorkspace {
49
67
  get isSupported(): boolean;
50
68
  /** 最近一次 restore() 完成前,工具调用会等待它。 */
51
69
  get ready(): Promise<void>;
52
- /** @internal 已授权时可用的 Adapter。 */
70
+ /**
71
+ * @internal 已授权时的磁盘后端,供内置工具使用。
72
+ * 接入方用 `files`:这里的路径必须已规范化,异常里也可能带系统路径。
73
+ */
53
74
  get adapter(): WorkspaceFileAdapter | null;
54
75
  private get handleKey();
55
76
  private get disclosureKey();
56
77
  private setStatus;
78
+ private replaceAdapter;
57
79
  private attachHandle;
58
80
  /**
59
81
  * 弹出目录选择框。必须在用户点击事件中调用。
@@ -63,10 +85,17 @@ export declare class LocalWorkspace {
63
85
  /** 读取上次的目录句柄并检查权限,不弹窗。 */
64
86
  restore(): Promise<void>;
65
87
  private doRestore;
88
+ /** queryPermission 仍可能是 prompt,但选择框留下的句柄其实列得出目录。 */
89
+ private canList;
66
90
  /** 对已保存的目录重新申请权限。必须在用户点击事件中调用。 */
67
91
  requestPermission(): Promise<boolean>;
68
92
  /** 断开工作区并删除持久化句柄。状态立即变为未授权,存储删除在其后完成。 */
69
93
  clear(): Promise<void>;
94
+ /**
95
+ * 用文件列表挂上工作区。路径来自 webkitRelativePath,选完就能列出层级。
96
+ * 写入只留在内存里,不会出现在用户磁盘上。需要落盘时用 pick()。
97
+ */
98
+ attachFileSnapshot(files: Iterable<File>, displayName?: string): void;
70
99
  /** 直接挂载一个 Adapter(测试或自定义后端),视为已授权。 */
71
100
  attachAdapter(adapter: WorkspaceFileAdapter, displayName?: string): void;
72
101
  /**
@@ -84,6 +113,11 @@ export declare class LocalWorkspace {
84
113
  getApprovalHandler(): ApprovalHandler | undefined;
85
114
  /** @internal 占用一个并发名额;已满时返回 null。 */
86
115
  acquireSlot(): (() => void) | null;
116
+ /**
117
+ * 占用一个浏览器运行时的命令名额。本地沙箱在时页面不设上限,并发由沙箱的 exec.maxConcurrent 决定。
118
+ * 浏览器运行时一次只放一条。
119
+ */
120
+ acquireCommand(): (() => void) | null;
87
121
  /** @internal 登记进行中的调用,更换或断开工作区时统一中止。 */
88
122
  track(controller: AbortController): () => boolean;
89
123
  /** 中止所有进行中的调用(含等待确认的请求)。 */
@@ -0,0 +1,63 @@
1
+ import { WorkspaceFileAdapter, WriteSource } from '../adapters/WorkspaceFileAdapter';
2
+ import { SensitiveFilePolicy } from '../security/sensitiveFiles';
3
+ /**
4
+ * `files` 能调用的工作区能力。适配器仍由 SDK 持有,不交给接入方。
5
+ */
6
+ export interface WorkspaceFilesHost {
7
+ readonly adapter: WorkspaceFileAdapter | null;
8
+ readonly sensitive: SensitiveFilePolicy;
9
+ notifyFilesChanged(paths?: readonly string[]): void;
10
+ handlePermissionLost(): Promise<void>;
11
+ }
12
+ export interface WorkspaceFileInfo {
13
+ name: string;
14
+ /** 相对工作区根的路径。根目录本身是空字符串。 */
15
+ path: string;
16
+ kind: 'file' | 'directory';
17
+ size?: number;
18
+ lastModified?: number;
19
+ /** 命中敏感文件规则时为 true。列表和 stat 仍返回该条目,读和写会被拒绝。 */
20
+ sensitive: boolean;
21
+ }
22
+ export interface WorkspaceReadOptions {
23
+ signal?: AbortSignal;
24
+ }
25
+ export interface WorkspaceWriteOptions extends WorkspaceReadOptions {
26
+ /** 默认 true:父目录不存在时逐级创建。 */
27
+ createDirectories?: boolean;
28
+ }
29
+ /**
30
+ * 接受工作区相对路径(`notes/a.md`)或以 `/` 开头的工作区路径(`/notes/a.md`)。
31
+ * 根目录在 allowRoot 时返回空字符串。
32
+ */
33
+ export declare function normalizeFilePath(input: unknown, allowRoot: boolean): string;
34
+ export declare class WorkspaceFiles {
35
+ private readonly host;
36
+ private readonly previews;
37
+ private readonly previewByPath;
38
+ constructor(host: WorkspaceFilesHost);
39
+ stat(path?: string): Promise<WorkspaceFileInfo>;
40
+ list(path?: string, options?: WorkspaceReadOptions): Promise<WorkspaceFileInfo[]>;
41
+ /**
42
+ * 给 `<img>`、`<video>`、`<audio>` 的地址。浏览器自己拉字节,调用方拿不到文件内容。
43
+ * 同一路径在大小和修改时间没变时返回同一个地址,并增加引用。用完调用 `releaseUrl`。
44
+ */
45
+ url(path: string): Promise<string>;
46
+ /** 页面不再显示这个地址时调用。引用归零后,blob 地址会撤销,沙箱票据会作废。 */
47
+ releaseUrl(url: string): void;
48
+ /** 工作区断开时释放还没归还的地址。 */
49
+ releaseAllUrls(): void;
50
+ read(path: string): Promise<Blob>;
51
+ readText(path: string): Promise<string>;
52
+ write(path: string, source: WriteSource, options?: WorkspaceWriteOptions): Promise<void>;
53
+ append(path: string, source: string | Uint8Array, options?: WorkspaceReadOptions): Promise<void>;
54
+ mkdir(path: string): Promise<void>;
55
+ remove(path: string, options?: {
56
+ recursive?: boolean;
57
+ }): Promise<void>;
58
+ move(from: string, to: string): Promise<void>;
59
+ private openPreview;
60
+ private dropPreview;
61
+ private assertAccess;
62
+ private run;
63
+ }
@@ -0,0 +1,11 @@
1
+ import { LocalMcpBinding } from './registry';
2
+ export interface McpToolSchema {
3
+ name: string;
4
+ description: string;
5
+ inputSchema: object;
6
+ }
7
+ export declare function parseMcpBody(text: string): Record<string, unknown>;
8
+ export declare function mcpToolText(result: unknown): string;
9
+ export declare function listMcpTools(binding: LocalMcpBinding, fetchImpl?: typeof fetch): Promise<McpToolSchema[]>;
10
+ export declare function callMcpTool(binding: LocalMcpBinding, name: string, args: unknown, signal?: AbortSignal, fetchImpl?: typeof fetch): Promise<string>;
11
+ export declare function resetMcpSessions(): void;
@@ -0,0 +1,32 @@
1
+ import { MCPConfig } from '../Config';
2
+ export interface ArrangeLocalMcp {
3
+ id?: string;
4
+ runtime?: string;
5
+ }
6
+ export interface McpServerDetail {
7
+ code: string;
8
+ deployType?: string;
9
+ url?: string;
10
+ headers: Record<string, string>;
11
+ }
12
+ interface SocketLike {
13
+ emit(event: string, data: unknown, ack?: (response: unknown) => void): void;
14
+ }
15
+ export declare function listedLocalMcps(arrange?: {
16
+ mcps?: ArrangeLocalMcp[];
17
+ } | null): ArrangeLocalMcp[];
18
+ export declare function detailMatchesInit(keys: string[] | null, id: string, code: string): boolean;
19
+ export declare function parseMcpDetail(body: unknown): McpServerDetail | null;
20
+ export declare function fetchMcpDetail(apiRoot: string, token: string, id: string, fetchImpl?: typeof fetch): Promise<McpServerDetail>;
21
+ export declare function registerLocalMcp(input: {
22
+ arrange?: {
23
+ mcps?: ArrangeLocalMcp[];
24
+ } | null;
25
+ initMcp?: MCPConfig | null;
26
+ apiRoot: string;
27
+ token: string;
28
+ socket?: SocketLike;
29
+ fetchImpl?: typeof fetch;
30
+ isCurrent?: () => boolean;
31
+ }): Promise<void>;
32
+ export {};
@@ -0,0 +1,26 @@
1
+ import { AgentPluginMap } from '../Config';
2
+ export declare const MCP_PLUGIN_CODE = "MCP";
3
+ export interface LocalMcpBinding {
4
+ code: string;
5
+ url: string;
6
+ headers: Record<string, string>;
7
+ }
8
+ export interface LocalMcpAck {
9
+ code: number;
10
+ message: string;
11
+ data?: string;
12
+ }
13
+ type LocalMcpHandler = (args: unknown, callback: (result: LocalMcpAck) => void, context?: {
14
+ signal?: AbortSignal;
15
+ }) => void;
16
+ export declare function rememberLocalMcpTool(name: string, binding: LocalMcpBinding, handler: LocalMcpHandler): void;
17
+ export declare function replaceLocalMcpTools(tools: {
18
+ name: string;
19
+ binding: LocalMcpBinding;
20
+ handler: LocalMcpHandler;
21
+ }[]): void;
22
+ export declare function localMcpBinding(name: string): LocalMcpBinding | undefined;
23
+ /** 把本机 MCP 工具合并进插件表。业务插件里同编码的其它函数保留。 */
24
+ export declare function applyLocalMcpPlugins(plugins: AgentPluginMap): void;
25
+ export declare function resetLocalMcpTools(): void;
26
+ export {};
@@ -0,0 +1,14 @@
1
+ import { CVForceApi } from '@glodon-aiot/apis';
2
+ /** 上传到当前会话对象存储后的结果。url 可放进 send 的 imageContent,或写进问题正文。 */
3
+ export interface SessionUploadResult {
4
+ url: string;
5
+ name: string;
6
+ size: number;
7
+ }
8
+ type UploadApi = Pick<CVForceApi, 'postUploadTicket' | 'uploadMinioFile'>;
9
+ /**
10
+ * 把文件上传到会话的对象存储。图片、表格和其他附件走同一条凭证。
11
+ * 存储名用新的 id,只保留安全的扩展名。
12
+ */
13
+ export declare function uploadSessionFile(api: UploadApi, sessionId: string, file: File): Promise<SessionUploadResult>;
14
+ export {};