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

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 (75) hide show
  1. package/README.md +130 -179
  2. package/dist/es/BotClient.mjs +136 -154
  3. package/dist/es/Config.mjs +88 -51
  4. package/dist/es/Session.mjs +23 -35
  5. package/dist/es/index.mjs +64 -66
  6. package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +113 -185
  7. package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +137 -127
  8. package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +97 -132
  9. package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +28 -32
  10. package/dist/es/localFiles/constants.mjs +29 -24
  11. package/dist/es/localFiles/createLocalPythonPlugin.mjs +196 -0
  12. package/dist/es/localFiles/errors.mjs +19 -21
  13. package/dist/es/localFiles/host/connectHostBridge.mjs +34 -37
  14. package/dist/es/localFiles/host/protocol.mjs +13 -27
  15. package/dist/es/localFiles/schemas.mjs +86 -40
  16. package/dist/es/localFiles/validate.mjs +37 -37
  17. package/dist/es/localFiles/workspace/LocalWorkspace.mjs +87 -161
  18. package/dist/es/package.json.mjs +29 -38
  19. package/dist/lib/index.js +9 -373
  20. package/dist/src/Config.d.ts +7 -5
  21. package/dist/src/Session.d.ts +0 -6
  22. package/dist/src/index.d.ts +1 -2
  23. package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +1 -4
  24. package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +14 -30
  25. package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +1 -4
  26. package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +0 -22
  27. package/dist/src/localFiles/adapters/fsaTypes.d.ts +0 -2
  28. package/dist/src/localFiles/constants.d.ts +13 -3
  29. package/dist/src/localFiles/host/protocol.d.ts +16 -34
  30. package/dist/src/localFiles/index.d.ts +6 -11
  31. package/dist/src/localFiles/schemas.d.ts +5 -2
  32. package/dist/src/localFiles/types.d.ts +23 -16
  33. package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +1 -32
  34. package/package.json +4 -13
  35. package/dist/es/builtinTools/browserRuntime/BrowserCommandRunner.mjs +0 -201
  36. package/dist/es/builtinTools/browserRuntime/PythonRunner.mjs +0 -356
  37. package/dist/es/builtinTools/browserRuntime/WorkspaceBashFs.mjs +0 -350
  38. package/dist/es/builtinTools/browserRuntime/assets.mjs +0 -9
  39. package/dist/es/builtinTools/browserRuntime/loadBash.mjs +0 -17
  40. package/dist/es/builtinTools/browserRuntime/pyodideRunner.py.mjs +0 -96
  41. package/dist/es/builtinTools/browserRuntime/pyodideWorker.mjs +0 -242
  42. package/dist/es/builtinTools/command.mjs +0 -56
  43. package/dist/es/builtinTools/constants.mjs +0 -10
  44. package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +0 -261
  45. package/dist/es/builtinTools/overview.mjs +0 -77
  46. package/dist/es/builtinTools/paths.mjs +0 -69
  47. package/dist/es/builtinTools/platformSkills.mjs +0 -210
  48. package/dist/es/builtinTools/schemas.mjs +0 -216
  49. package/dist/es/builtinTools/tools.mjs +0 -494
  50. package/dist/es/localFiles/adapters/FileSnapshotAdapter.mjs +0 -160
  51. package/dist/es/localFiles/host/sandboxClient.mjs +0 -420
  52. package/dist/es/localFiles/host/sandboxFrames.mjs +0 -21
  53. package/dist/es/localFiles/preview.mjs +0 -33
  54. package/dist/es/localFiles/workspace/WorkspaceFiles.mjs +0 -246
  55. package/dist/es/sessionUpload.mjs +0 -49
  56. package/dist/src/builtinTools/browserRuntime/BrowserCommandRunner.d.ts +0 -26
  57. package/dist/src/builtinTools/browserRuntime/PythonRunner.d.ts +0 -67
  58. package/dist/src/builtinTools/browserRuntime/WorkspaceBashFs.d.ts +0 -51
  59. package/dist/src/builtinTools/browserRuntime/assets.d.ts +0 -13
  60. package/dist/src/builtinTools/browserRuntime/loadBash.d.ts +0 -3
  61. package/dist/src/builtinTools/browserRuntime/pyodideWorker.d.ts +0 -44
  62. package/dist/src/builtinTools/command.d.ts +0 -35
  63. package/dist/src/builtinTools/constants.d.ts +0 -17
  64. package/dist/src/builtinTools/createBuiltinToolsPlugin.d.ts +0 -11
  65. package/dist/src/builtinTools/overview.d.ts +0 -5
  66. package/dist/src/builtinTools/paths.d.ts +0 -16
  67. package/dist/src/builtinTools/platformSkills.d.ts +0 -67
  68. package/dist/src/builtinTools/schemas.d.ts +0 -3
  69. package/dist/src/builtinTools/tools.d.ts +0 -64
  70. package/dist/src/localFiles/adapters/FileSnapshotAdapter.d.ts +0 -24
  71. package/dist/src/localFiles/host/sandboxClient.d.ts +0 -81
  72. package/dist/src/localFiles/host/sandboxFrames.d.ts +0 -9
  73. package/dist/src/localFiles/preview.d.ts +0 -2
  74. package/dist/src/localFiles/workspace/WorkspaceFiles.d.ts +0 -63
  75. package/dist/src/sessionUpload.d.ts +0 -14
@@ -1,4 +1,4 @@
1
- import { BuiltinPluginsConfig, LocalFilesConfig } from './localFiles/types';
1
+ import { BuiltinPluginsConfig, LocalFilesConfig, LocalPythonConfig } 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 内置插件。文件、命令和技能工具注册到同一个 pluginCode。 */
22
+ /** SDK 内置插件:本地文件工具和 run_python,注册到同一个 pluginCode。 */
23
23
  builtinPlugins?: BuiltinPluginsConfig;
24
24
  }
25
25
  export interface AgentPluginRegistor {
@@ -53,8 +53,12 @@ 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;
56
58
  /** 显式配置优先,其次按 env 取默认值;都没有时返回 undefined。 */
57
59
  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;
58
62
  /**
59
63
  * 重新计算 configuration.plugins,返回本次新出现的问题(相同问题只报告一次)。
60
64
  */
@@ -63,6 +67,4 @@ export declare function refreshBuiltinPlugins(): Error[];
63
67
  * 配置SDK,可以在SDK被使用前被调用,该方法被调用后将改变是否debug模式、是否测试环境等基本配置
64
68
  * @param param {debug?: boolean; env?: 'dev' | 'test' | 'prod';}
65
69
  */
66
- export declare function configure(param?: BotClientConfig, options?: {
67
- refreshBuiltinPlugins?: boolean;
68
- }): void;
70
+ export declare function configure(param?: BotClientConfig): void;
@@ -4,7 +4,6 @@ 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';
8
7
  export declare enum NetOpen {
9
8
  enable = 1,
10
9
  disable = 2
@@ -177,11 +176,6 @@ export default abstract class Session {
177
176
  abstract listMcpServers(): Promise<MCPConfig>;
178
177
  get dataLoaded(): boolean;
179
178
  get messagesLoading(): boolean;
180
- /**
181
- * 把文件上传到当前会话的对象存储,返回可访问的地址。
182
- * 图片地址放进 send 的 imageContent。
183
- */
184
- upload(file: File): Promise<SessionUploadResult>;
185
179
  send(params: {
186
180
  text?: string;
187
181
  files?: any[];
@@ -1,8 +1,7 @@
1
1
  export type { AgentPluginRegistor, AgentPluginMap, BotClientConfig, MCPConfig, McpServer } from './Config';
2
- export { configure, configuration, getRegisteredLocalFilesPluginCode, resolveLocalFilesPluginCode, } from './Config';
2
+ export { configure, configuration, getRegisteredLocalFilesPluginCode, getRegisteredLocalPythonPluginCode, 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';
7
6
  export { default as AgentPlugin } from './AgentPlugin';
8
7
  export * from './localFiles';
@@ -1,4 +1,4 @@
1
- import { RemoveOptions, WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource } from './WorkspaceFileAdapter';
1
+ import { WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource } from './WorkspaceFileAdapter';
2
2
  import { FsaDirectoryHandle } from './fsaTypes';
3
3
  /**
4
4
  * 基于用户授权的 DirectoryHandle 的工作区。只通过逐级 getDirectoryHandle / getFileHandle
@@ -14,7 +14,4 @@ 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>;
20
17
  }
@@ -1,40 +1,24 @@
1
- import { CommandRequest, CommandResult } from '../../builtinTools/command';
2
- import { SandboxClient, SandboxNotice } from '../host/sandboxClient';
3
- import { HostCapability, HostBridge } from '../host/protocol';
4
1
  import { WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource } from './WorkspaceFileAdapter';
2
+ import { HostResponseMessage, HostWebView } from '../host/protocol';
5
3
  /**
6
- * 工作区原语走沙箱 WebSocket。页面只向宿主发 hello,不转发文件字节和命令输出。
4
+ * 把工作区原语转成宿主消息。页面看不到绝对路径,目录由宿主在授权后推送。
7
5
  */
8
6
  export declare class HostBridgeAdapter implements WorkspaceFileAdapter {
7
+ private readonly view;
9
8
  displayName: string;
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;
9
+ private seq;
10
+ private readonly pending;
11
+ constructor(view: HostWebView, displayName?: string);
12
+ settle(message: HostResponseMessage): void;
13
+ private call;
23
14
  stat(path: string): Promise<WorkspaceEntry>;
24
15
  listEntries(path: string, signal?: AbortSignal): Promise<WorkspaceEntry[]>;
25
- url(path: string): Promise<{
26
- url: string;
27
- release: () => void;
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;
28
22
  }>;
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>;
39
23
  writeFile(path: string, source: WriteSource, options?: WriteOptions): Promise<void>;
40
24
  }
@@ -1,4 +1,4 @@
1
- import { RemoveOptions, WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource } from './WorkspaceFileAdapter';
1
+ import { WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource } from './WorkspaceFileAdapter';
2
2
  /** 内存工作区:用于测试与契约基准,语义与 FileSystemAccessAdapter 一致。 */
3
3
  export declare class MemoryWorkspaceAdapter implements WorkspaceFileAdapter {
4
4
  readonly displayName: string;
@@ -15,7 +15,4 @@ 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>;
21
18
  }
@@ -19,30 +19,8 @@ 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
- }>;
30
22
  /** 全部内容写完才提交;失败或取消时原文件保持不变,新建的文件不会残留。 */
31
23
  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>;
41
24
  }
42
- export interface RemoveOptions {
43
- recursive?: boolean;
44
- }
45
- /** from 与 to 都已规范化;to 等于 from 或在 from 之下。 */
46
- export declare function isSameOrInside(from: string, to: string): boolean;
47
25
  export declare function domError(name: string, message?: string): DOMException;
48
26
  export declare function toChunks(source: WriteSource): AsyncIterable<Uint8Array>;
@@ -11,8 +11,6 @@ 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>;
16
14
  }
17
15
  export interface FsaFileHandle extends FsaHandleBase {
18
16
  readonly kind: 'file';
@@ -1,11 +1,21 @@
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
- /** 平台插件编码。与内置工具 OpenAPI 的 pluginCode 一致。dev、test、prod、local 使用同一个 pluginCode。 */
5
- export declare const BUILTIN_TOOLS_PLUGIN_CODE = "builtin_tools";
4
+ /**
5
+ * 平台上的内置工具插件。本地文件工具和 `run_python` 都在这一个插件里。
6
+ * dev、test、prod、local 使用同一个 pluginCode。
7
+ */
8
+ export declare const BUILTIN_TOOLS_PLUGIN_CODE = "buildin_tools";
6
9
  export declare const BUILTIN_TOOLS_PLUGIN_CODES: Record<Env, string>;
7
- /** 与 `BUILTIN_TOOLS_PLUGIN_CODES` 相同。 */
10
+ /** 与 `BUILTIN_TOOLS_PLUGIN_CODES` 相同。文件工具和脚本工具共用一个插件编码。 */
8
11
  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;
9
19
  export declare const WORKSPACE_GRANT_ID = "current-workspace";
10
20
  export declare const KiB = 1024;
11
21
  export declare const MiB: number;
@@ -1,9 +1,6 @@
1
1
  /** 宿主与页面之间的通道名。根目录只由宿主设置,消息里不能带绝对路径。 */
2
2
  export declare const HOST_CHANNEL = "glodon-workspace";
3
- /** 宿主在页面脚本运行前挂上的消息桥。不对应某一种 WebView 或浏览器内核。 */
4
- export declare const HOST_BRIDGE_GLOBAL = "__glodonHostBridge";
5
- /** 页面与宿主之间的双向消息桥。消息正文是普通 JSON。 */
6
- export interface HostBridge {
3
+ export interface HostWebView {
7
4
  postMessage(message: unknown): void;
8
5
  addEventListener(type: 'message', listener: (event: {
9
6
  data: unknown;
@@ -12,40 +9,25 @@ export interface HostBridge {
12
9
  data: unknown;
13
10
  }) => void): void;
14
11
  }
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
- }
35
12
  export interface HostWorkspaceMessage {
36
13
  channel: string;
37
14
  type: 'workspace';
38
15
  granted?: boolean;
39
16
  displayName?: string;
40
- capabilities?: HostCapability[];
41
- sandboxVersion?: string;
42
- sandbox?: HostSandboxState;
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;
43
31
  }
44
32
  export declare function parseHostMessage(data: unknown): Record<string, unknown> | undefined;
45
- /** 挂上当前页面的宿主消息桥。传入空值时移除。 */
46
- export declare function registerHostBridge(bridge?: HostBridge): void;
47
- /**
48
- * 优先使用宿主注册的消息桥。没有注册时,接受已经具备同样三个方法的 `chrome.webview`,
49
- * 让自带该对象的嵌入环境不必再包一层。
50
- */
51
- export declare function getHostBridge(): HostBridge | undefined;
33
+ export declare function getHostWebView(): HostWebView | undefined;
@@ -2,25 +2,20 @@ 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 { LOCAL_FILE_TOOL_SCHEMAS } from './schemas';
6
- export { BUILTIN_TOOL_SCHEMAS } from '../builtinTools/schemas';
7
- export type { BuiltinToolSchema, JsonSchema, LocalFileToolSchema, } from './schemas';
5
+ export { BUILTIN_TOOL_SCHEMAS, LOCAL_FILE_TOOL_SCHEMAS, LOCAL_PYTHON_TOOL_SCHEMA } from './schemas';
6
+ export type { BuiltinToolSchema, JsonSchema, LocalFileToolSchema } from './schemas';
8
7
  export { createLocalFilesPlugin } from './createLocalFilesPlugin';
9
8
  export type { CreateLocalFilesPluginOptions, LocalFilesHandler, LocalFilesPluginTable, } from './createLocalFilesPlugin';
10
9
  export { LocalWorkspace } from './workspace/LocalWorkspace';
11
10
  export type { LocalWorkspaceOptions } from './workspace/LocalWorkspace';
12
- export { WorkspaceFiles, normalizeFilePath } from './workspace/WorkspaceFiles';
13
- export type { WorkspaceFileInfo, WorkspaceReadOptions, WorkspaceWriteOptions, } from './workspace/WorkspaceFiles';
14
- export { createIndexedDbStore, createMemoryStore, } from './workspace/handleStore';
11
+ export { createIndexedDbStore, createMemoryStore } from './workspace/handleStore';
15
12
  export type { KeyValueStore } from './workspace/handleStore';
16
- export type { RemoveOptions, WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource, } from './adapters/WorkspaceFileAdapter';
13
+ export type { WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource, } from './adapters/WorkspaceFileAdapter';
17
14
  export { FileSystemAccessAdapter } from './adapters/FileSystemAccessAdapter';
18
15
  export { MemoryWorkspaceAdapter } from './adapters/MemoryWorkspaceAdapter';
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';
16
+ export type { FsaDirectoryHandle, ShowDirectoryPicker } from './adapters/fsaTypes';
22
17
  export { createDefaultSessionFileTransfer } from './transfer/SessionFileTransfer';
23
18
  export type { ResolvedDownload, SessionFileTransfer, UploadProgress, } from './transfer/SessionFileTransfer';
24
19
  export { getDownloadUrlAllowlist, isDownloadUrlAllowed, } from './security/downloadUrlPolicy';
25
20
  export { SDK_SENSITIVE_BASELINE } from './security/sensitiveFiles';
26
- export type { SensitiveRule, SensitiveRuleInput, } from './security/sensitiveFiles';
21
+ export type { SensitiveRule, SensitiveRuleInput } from './security/sensitiveFiles';
@@ -1,4 +1,4 @@
1
- import { LocalFilesFunctionCode } from './constants';
1
+ import { LocalFilesFunctionCode, LOCAL_PYTHON_FUNCTION_CODE } from './constants';
2
2
  export interface JsonSchema {
3
3
  type?: 'object' | 'string' | 'integer' | 'number' | 'boolean' | 'array';
4
4
  description?: string;
@@ -9,7 +9,6 @@ export interface JsonSchema {
9
9
  minimum?: number;
10
10
  maximum?: number;
11
11
  minLength?: number;
12
- maxLength?: number;
13
12
  minItems?: number;
14
13
  maxItems?: number;
15
14
  oneOf?: JsonSchema[];
@@ -25,3 +24,7 @@ export interface LocalFileToolSchema extends BuiltinToolSchema {
25
24
  }
26
25
  /** 9 个工具的参数 Schema,同时作为平台注册时的草案。 */
27
26
  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`:目录由宿主消息桥推送,页面不弹选择框。
66
+ * `host-bridge`:目录由宿主通过 `chrome.webview` 设置,页面不弹选择框。
67
67
  */
68
68
  backend?: 'file-system-access' | 'host-bridge';
69
69
  /**
70
- * 平台上的内置工具插件编码。
70
+ * 平台上的内置工具插件编码。文件工具和 run_python 使用同一个编码。
71
71
  * 未配置时按 env 取 BUILTIN_TOOLS_PLUGIN_CODES。
72
72
  */
73
73
  pluginCode?: string;
@@ -82,22 +82,29 @@ 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
+ }
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;
98
104
  }
99
105
  export interface BuiltinPluginsConfig {
100
106
  localFiles?: LocalFilesConfig;
107
+ localPython?: LocalPythonConfig;
101
108
  }
102
109
  export interface WorkspaceGrantInput {
103
110
  grantId: string;
@@ -253,7 +260,7 @@ export interface WorkspaceChangedEvent {
253
260
  export interface ToolEventBase {
254
261
  requestId: string;
255
262
  sessionId: string;
256
- functionCode: string;
263
+ functionCode: LocalFilesFunctionCode;
257
264
  path?: string;
258
265
  }
259
266
  export interface ToolProgressEvent extends ToolEventBase {
@@ -1,5 +1,3 @@
1
- import { CommandRunner } from '../../builtinTools/command';
2
- import { PlatformSkillSync } from '../../builtinTools/platformSkills';
3
1
  import { WorkspaceFileAdapter } from '../adapters/WorkspaceFileAdapter';
4
2
  import { ShowDirectoryPicker } from '../adapters/fsaTypes';
5
3
  import { LocalFilesLimits } from '../constants';
@@ -7,7 +5,6 @@ import { SensitiveFilePolicy } from '../security/sensitiveFiles';
7
5
  import { SessionFileTransfer } from '../transfer/SessionFileTransfer';
8
6
  import { ApprovalHandler, LocalFilesConfig, LocalWorkspaceEventMap, LocalWorkspaceEventName, LocalWorkspaceStatus, WorkspaceHandshake } from '../types';
9
7
  import { KeyValueStore } from './handleStore';
10
- import { WorkspaceFiles } from './WorkspaceFiles';
11
8
  export interface LocalWorkspaceOptions {
12
9
  applicationId: string;
13
10
  config?: LocalFilesConfig;
@@ -18,8 +15,6 @@ export interface LocalWorkspaceOptions {
18
15
  /** 默认会话文件传输的 API 来源;config.transfer 中的方法优先。 */
19
16
  transfer?: SessionFileTransfer;
20
17
  fetch?: typeof fetch;
21
- /** shell、run_file、run_skill_script 的执行器。未设置时依次尝试宿主沙箱、浏览器运行时。 */
22
- commandRunner?: CommandRunner;
23
18
  }
24
19
  /**
25
20
  * 工作文件夹授权与运行状态。一个 BotClient 对应一个实例;UI 与纯 SDK 集成共用同一实例。
@@ -32,16 +27,6 @@ export declare class LocalWorkspace {
32
27
  readonly allowWorkspaceWideTextSearch: boolean;
33
28
  readonly transfer: SessionFileTransfer;
34
29
  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;
45
30
  private readonly store;
46
31
  private readonly picker?;
47
32
  private readonly event;
@@ -51,15 +36,12 @@ export declare class LocalWorkspace {
51
36
  private pendingHandle;
52
37
  private approvalHandler?;
53
38
  private activeCalls;
54
- private commandRunning;
55
39
  private readonly inflight;
56
40
  private _ready;
57
41
  private stopWatching;
58
42
  private readonly pendingChangePaths;
59
43
  private changeTimer;
60
44
  private refreshAllVisible;
61
- /** 选择、关闭会推进它。进行中的 restore 若发现已经变了,就不再覆盖当前目录。 */
62
- private epoch;
63
45
  constructor(options: LocalWorkspaceOptions);
64
46
  get status(): LocalWorkspaceStatus;
65
47
  /** 当前(或待恢复的)文件夹名,不含绝对路径。 */
@@ -67,15 +49,11 @@ export declare class LocalWorkspace {
67
49
  get isSupported(): boolean;
68
50
  /** 最近一次 restore() 完成前,工具调用会等待它。 */
69
51
  get ready(): Promise<void>;
70
- /**
71
- * @internal 已授权时的磁盘后端,供内置工具使用。
72
- * 接入方用 `files`:这里的路径必须已规范化,异常里也可能带系统路径。
73
- */
52
+ /** @internal 已授权时可用的 Adapter。 */
74
53
  get adapter(): WorkspaceFileAdapter | null;
75
54
  private get handleKey();
76
55
  private get disclosureKey();
77
56
  private setStatus;
78
- private replaceAdapter;
79
57
  private attachHandle;
80
58
  /**
81
59
  * 弹出目录选择框。必须在用户点击事件中调用。
@@ -85,17 +63,10 @@ export declare class LocalWorkspace {
85
63
  /** 读取上次的目录句柄并检查权限,不弹窗。 */
86
64
  restore(): Promise<void>;
87
65
  private doRestore;
88
- /** queryPermission 仍可能是 prompt,但选择框留下的句柄其实列得出目录。 */
89
- private canList;
90
66
  /** 对已保存的目录重新申请权限。必须在用户点击事件中调用。 */
91
67
  requestPermission(): Promise<boolean>;
92
68
  /** 断开工作区并删除持久化句柄。状态立即变为未授权,存储删除在其后完成。 */
93
69
  clear(): Promise<void>;
94
- /**
95
- * 用文件列表挂上工作区。路径来自 webkitRelativePath,选完就能列出层级。
96
- * 写入只留在内存里,不会出现在用户磁盘上。需要落盘时用 pick()。
97
- */
98
- attachFileSnapshot(files: Iterable<File>, displayName?: string): void;
99
70
  /** 直接挂载一个 Adapter(测试或自定义后端),视为已授权。 */
100
71
  attachAdapter(adapter: WorkspaceFileAdapter, displayName?: string): void;
101
72
  /**
@@ -113,8 +84,6 @@ export declare class LocalWorkspace {
113
84
  getApprovalHandler(): ApprovalHandler | undefined;
114
85
  /** @internal 占用一个并发名额;已满时返回 null。 */
115
86
  acquireSlot(): (() => void) | null;
116
- /** @internal 同一工作区同一时间只跑一个命令;已有命令在运行时返回 null。 */
117
- acquireCommand(): (() => void) | null;
118
87
  /** @internal 登记进行中的调用,更换或断开工作区时统一中止。 */
119
88
  track(controller: AbortController): () => boolean;
120
89
  /** 中止所有进行中的调用(含等待确认的请求)。 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glodon-aiot/bot-client-sdk",
3
- "version": "3.26.0-alpha.20",
3
+ "version": "3.26.0-alpha.23",
4
4
  "author": "glodoncv",
5
5
  "description": "aiot bot client js sdk",
6
6
  "type": "module",
@@ -36,13 +36,7 @@
36
36
  "preview": "vite preview",
37
37
  "check": "yarn prettier --check .",
38
38
  "write": "yarn prettier --write .",
39
- "lint": "eslint --ext .tsx,.ts --fix ./example -c .eslintrc.js",
40
- "build:just-bash": "node scripts/build-just-bash.mjs",
41
- "upload:just-bash": "node scripts/build-just-bash.mjs && node scripts/upload-cdn-libs.cjs just-bash",
42
- "build:pyodide": "node scripts/build-pyodide.mjs",
43
- "upload:pyodide": "node scripts/build-pyodide.mjs && node scripts/upload-cdn-libs.cjs pyodide",
44
- "test": "vitest run",
45
- "test:watch": "vitest"
39
+ "lint": "eslint --ext .tsx,.ts --fix ./example -c .eslintrc.js"
46
40
  },
47
41
  "devDependencies": {
48
42
  "@babel/core": "^7.20.12",
@@ -66,10 +60,8 @@
66
60
  "express": "4",
67
61
  "http-proxy-middleware": "^3.0.0",
68
62
  "identity-obj-proxy": "^3.0.0",
69
- "just-bash": "3.6.0",
70
63
  "npm-run-all": "^4.1.5",
71
64
  "prettier": "2.7.1",
72
- "pyodide": "314.0.7",
73
65
  "rollup-plugin-visualizer": "^6.0.1",
74
66
  "socket.io": "^4.7.5",
75
67
  "ts-node": "^10.9.2",
@@ -77,8 +69,7 @@
77
69
  "vite": "^4.1.1",
78
70
  "vite-plugin-dts": "^4.3.0",
79
71
  "vite-plugin-externalize-deps": "^0.9.0",
80
- "vite-tsconfig-paths": "^5.1.4",
81
- "vitest": "^0.34.6"
72
+ "vite-tsconfig-paths": "^5.1.4"
82
73
  },
83
74
  "lint-staged": {
84
75
  "*.{js,css,md,jsx,less,ts,tsx,json}": "prettier --write"
@@ -88,7 +79,7 @@
88
79
  "registry": "https://registry.npmjs.org/"
89
80
  },
90
81
  "dependencies": {
91
- "@glodon-aiot/apis": "^3.26.0-alpha.20",
82
+ "@glodon-aiot/apis": "^3.26.0-alpha.23",
92
83
  "axios": "0.24.0",
93
84
  "buffer": "^6.0.3",
94
85
  "dayjs": "^1.11.13",