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

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 (60) hide show
  1. package/README.md +76 -105
  2. package/dist/es/AgentSession.mjs +32 -33
  3. package/dist/es/Config.mjs +85 -63
  4. package/dist/es/DialogSession.mjs +39 -40
  5. package/dist/es/Session.mjs +71 -63
  6. package/dist/es/index.mjs +48 -49
  7. package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +103 -193
  8. package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +77 -138
  9. package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +97 -132
  10. package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +28 -32
  11. package/dist/es/localFiles/constants.mjs +1 -1
  12. package/dist/es/localFiles/createLocalPythonPlugin.mjs +196 -0
  13. package/dist/es/localFiles/host/connectHostBridge.mjs +18 -22
  14. package/dist/es/localFiles/host/protocol.mjs +5 -6
  15. package/dist/es/localFiles/schemas.mjs +60 -45
  16. package/dist/es/localFiles/validate.mjs +37 -37
  17. package/dist/es/localFiles/workspace/LocalWorkspace.mjs +52 -71
  18. package/dist/es/package.json.mjs +29 -38
  19. package/dist/lib/index.js +9 -372
  20. package/dist/src/Config.d.ts +2 -2
  21. package/dist/src/Session.d.ts +4 -0
  22. package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +1 -4
  23. package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +1 -20
  24. package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +1 -4
  25. package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +0 -14
  26. package/dist/src/localFiles/adapters/fsaTypes.d.ts +0 -2
  27. package/dist/src/localFiles/constants.d.ts +1 -2
  28. package/dist/src/localFiles/host/protocol.d.ts +0 -13
  29. package/dist/src/localFiles/index.d.ts +2 -3
  30. package/dist/src/localFiles/schemas.d.ts +3 -2
  31. package/dist/src/localFiles/types.d.ts +1 -14
  32. package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +0 -12
  33. package/package.json +4 -13
  34. package/dist/es/builtinTools/browserRuntime/BrowserCommandRunner.mjs +0 -201
  35. package/dist/es/builtinTools/browserRuntime/PythonRunner.mjs +0 -356
  36. package/dist/es/builtinTools/browserRuntime/WorkspaceBashFs.mjs +0 -350
  37. package/dist/es/builtinTools/browserRuntime/assets.mjs +0 -9
  38. package/dist/es/builtinTools/browserRuntime/loadBash.mjs +0 -17
  39. package/dist/es/builtinTools/browserRuntime/pyodideRunner.py.mjs +0 -96
  40. package/dist/es/builtinTools/browserRuntime/pyodideWorker.mjs +0 -242
  41. package/dist/es/builtinTools/command.mjs +0 -56
  42. package/dist/es/builtinTools/constants.mjs +0 -10
  43. package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +0 -236
  44. package/dist/es/builtinTools/overview.mjs +0 -77
  45. package/dist/es/builtinTools/paths.mjs +0 -63
  46. package/dist/es/builtinTools/schemas.mjs +0 -216
  47. package/dist/es/builtinTools/tools.mjs +0 -471
  48. package/dist/src/builtinTools/browserRuntime/BrowserCommandRunner.d.ts +0 -26
  49. package/dist/src/builtinTools/browserRuntime/PythonRunner.d.ts +0 -67
  50. package/dist/src/builtinTools/browserRuntime/WorkspaceBashFs.d.ts +0 -51
  51. package/dist/src/builtinTools/browserRuntime/assets.d.ts +0 -13
  52. package/dist/src/builtinTools/browserRuntime/loadBash.d.ts +0 -3
  53. package/dist/src/builtinTools/browserRuntime/pyodideWorker.d.ts +0 -44
  54. package/dist/src/builtinTools/command.d.ts +0 -26
  55. package/dist/src/builtinTools/constants.d.ts +0 -17
  56. package/dist/src/builtinTools/createBuiltinToolsPlugin.d.ts +0 -11
  57. package/dist/src/builtinTools/overview.d.ts +0 -5
  58. package/dist/src/builtinTools/paths.d.ts +0 -15
  59. package/dist/src/builtinTools/schemas.d.ts +0 -3
  60. package/dist/src/builtinTools/tools.d.ts +0 -60
@@ -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,7 +53,7 @@ export declare function setActiveLocalWorkspace(workspace?: LocalWorkspace): voi
53
53
  export declare function getActiveLocalWorkspace(): LocalWorkspace | undefined;
54
54
  /** 当前已注册到 configuration.plugins 的内置文件工具编码;未注册时返回 undefined。 */
55
55
  export declare function getRegisteredLocalFilesPluginCode(): string | undefined;
56
- /** 当前已注册到 configuration.plugins 的脚本工具所在插件编码;未注册时返回 undefined。 */
56
+ /** 当前已注册到 configuration.plugins 的 run_python 所在插件编码;未注册时返回 undefined。 */
57
57
  export declare function getRegisteredLocalPythonPluginCode(): string | undefined;
58
58
  /** 显式配置优先,其次按 env 取默认值;都没有时返回 undefined。 */
59
59
  export declare function resolveLocalFilesPluginCode(config: LocalFilesConfig | undefined, env: string): string;
@@ -164,6 +164,10 @@ export default abstract class Session {
164
164
  delete(): Promise<string | false>;
165
165
  activate(): Promise<unknown>;
166
166
  inactivate(immediately?: boolean): boolean;
167
+ /**
168
+ * 会话标题摘要开关。应用详情返回布尔值时用该值,字段缺失时默认开启。
169
+ */
170
+ protected resolveEnableTitleSummary(): boolean;
167
171
  abstract prepareConnection(): Promise<boolean>;
168
172
  abstract sendQuestion(params: QuestionBody, configs: QuestionConfig): any;
169
173
  abstract stopAnswer(): any;
@@ -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,38 +1,19 @@
1
- import { CommandRequest, CommandResult } from '../../builtinTools/command';
2
1
  import { WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource } from './WorkspaceFileAdapter';
3
- import { HostCapability, HostResponseMessage, HostWebView } from '../host/protocol';
2
+ import { HostResponseMessage, HostWebView } from '../host/protocol';
4
3
  /**
5
4
  * 把工作区原语转成宿主消息。页面看不到绝对路径,目录由宿主在授权后推送。
6
5
  */
7
6
  export declare class HostBridgeAdapter implements WorkspaceFileAdapter {
8
7
  private readonly view;
9
8
  displayName: string;
10
- /** 宿主最近一次 workspace 消息声明的能力。 */
11
- capabilities: ReadonlySet<HostCapability>;
12
- /** 宿主随 sandbox-exec 声明的沙箱包版本和协议。 */
13
- sandboxVersion?: string;
14
- sandboxProtocol?: number;
15
9
  private seq;
16
10
  private readonly pending;
17
11
  constructor(view: HostWebView, displayName?: string);
18
- setCapabilities(value: unknown, sandbox?: {
19
- version?: unknown;
20
- protocol?: unknown;
21
- }): void;
22
- /** 声明了 sandbox-exec 且协议版本与 SDK 一致时才把命令交给宿主。 */
23
- get canExec(): boolean;
24
- private requireCapability;
25
12
  settle(message: HostResponseMessage): void;
26
13
  private call;
27
14
  stat(path: string): Promise<WorkspaceEntry>;
28
15
  listEntries(path: string, signal?: AbortSignal): Promise<WorkspaceEntry[]>;
29
16
  readFile(path: string): Promise<Blob>;
30
- createDirectory(path: string): Promise<void>;
31
- remove(path: string, options?: {
32
- recursive?: boolean;
33
- }): Promise<void>;
34
- move(from: string, to: string): Promise<void>;
35
- exec(request: CommandRequest): Promise<CommandResult>;
36
17
  runPython(path: string, args: string[], timeoutMs: number, signal?: AbortSignal): Promise<{
37
18
  exitCode: number;
38
19
  timedOut: boolean;
@@ -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
  }
@@ -21,20 +21,6 @@ export interface WorkspaceFileAdapter {
21
21
  readFile(path: string): Promise<Blob>;
22
22
  /** 全部内容写完才提交;失败或取消时原文件保持不变,新建的文件不会残留。 */
23
23
  writeFile(path: string, source: WriteSource, options?: WriteOptions): Promise<void>;
24
- /** 逐级创建目录,已存在时不报错。路径上有同名文件时抛 TypeMismatchError。 */
25
- createDirectory?(path: string): Promise<void>;
26
- /** 删除文件或目录。非空目录需要 recursive,否则抛 InvalidModificationError。不能删除根目录。 */
27
- remove?(path: string, options?: RemoveOptions): Promise<void>;
28
- /**
29
- * 把 from 移到 to(to 是最终路径,不是目标目录)。to 的父目录必须存在。
30
- * to 已是文件时覆盖;from 或 to 有一方是已存在的目录、或 to 在 from 之内时抛 InvalidModificationError。
31
- */
32
- move?(from: string, to: string): Promise<void>;
33
24
  }
34
- export interface RemoveOptions {
35
- recursive?: boolean;
36
- }
37
- /** from 与 to 都已规范化;to 等于 from 或在 from 之下。 */
38
- export declare function isSameOrInside(from: string, to: string): boolean;
39
25
  export declare function domError(name: string, message?: string): DOMException;
40
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';
@@ -5,8 +5,7 @@ export type LocalFilesFunctionCode = (typeof LOCAL_FILES_FUNCTION_CODES)[number]
5
5
  * 平台上的内置工具插件。本地文件工具和 `run_python` 都在这一个插件里。
6
6
  * dev、test、prod、local 使用同一个 pluginCode。
7
7
  */
8
- /** 平台插件编码。与内置工具 OpenAPI 的 pluginCode 一致。 */
9
- export declare const BUILTIN_TOOLS_PLUGIN_CODE = "builtin_tools";
8
+ export declare const BUILTIN_TOOLS_PLUGIN_CODE = "buildin_tools";
10
9
  export declare const BUILTIN_TOOLS_PLUGIN_CODES: Record<Env, string>;
11
10
  /** 与 `BUILTIN_TOOLS_PLUGIN_CODES` 相同。文件工具和脚本工具共用一个插件编码。 */
12
11
  export declare const LOCAL_FILES_PLUGIN_CODES: Record<Env, string>;
@@ -9,22 +9,11 @@ export interface HostWebView {
9
9
  data: unknown;
10
10
  }) => void): void;
11
11
  }
12
- /**
13
- * 宿主声明的能力。
14
- * - `sandbox-exec`:命令交给 SDK 沙箱包执行,支持 `exec` 消息。
15
- * - `fs-mutate`:支持 `mkdir`、`remove`、`move` 消息。
16
- */
17
- export type HostCapability = 'sandbox-exec' | 'fs-mutate';
18
- /** SDK 支持的沙箱包协议版本。宿主声明的 sandboxProtocol 不同时不使用宿主沙箱。 */
19
- export declare const SANDBOX_PROTOCOL = 1;
20
12
  export interface HostWorkspaceMessage {
21
13
  channel: string;
22
14
  type: 'workspace';
23
15
  granted?: boolean;
24
16
  displayName?: string;
25
- capabilities?: HostCapability[];
26
- sandboxVersion?: string;
27
- sandboxProtocol?: number;
28
17
  }
29
18
  export interface HostResponseMessage {
30
19
  channel: string;
@@ -38,8 +27,6 @@ export interface HostResponseMessage {
38
27
  timedOut?: boolean;
39
28
  stdout?: string;
40
29
  stderr?: string;
41
- /** shell 结束后的工作区相对目录。 */
42
- cwd?: string;
43
30
  message?: string;
44
31
  }
45
32
  export declare function parseHostMessage(data: unknown): Record<string, unknown> | undefined;
@@ -2,8 +2,7 @@ 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, LOCAL_PYTHON_TOOL_SCHEMA } from './schemas';
6
- export { BUILTIN_TOOL_SCHEMAS } from '../builtinTools/schemas';
5
+ export { BUILTIN_TOOL_SCHEMAS, LOCAL_FILE_TOOL_SCHEMAS, LOCAL_PYTHON_TOOL_SCHEMA } from './schemas';
7
6
  export type { BuiltinToolSchema, JsonSchema, LocalFileToolSchema } from './schemas';
8
7
  export { createLocalFilesPlugin } from './createLocalFilesPlugin';
9
8
  export type { CreateLocalFilesPluginOptions, LocalFilesHandler, LocalFilesPluginTable, } from './createLocalFilesPlugin';
@@ -11,7 +10,7 @@ export { LocalWorkspace } from './workspace/LocalWorkspace';
11
10
  export type { LocalWorkspaceOptions } from './workspace/LocalWorkspace';
12
11
  export { createIndexedDbStore, createMemoryStore } from './workspace/handleStore';
13
12
  export type { KeyValueStore } from './workspace/handleStore';
14
- export type { RemoveOptions, WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource, } from './adapters/WorkspaceFileAdapter';
13
+ export type { WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource, } from './adapters/WorkspaceFileAdapter';
15
14
  export { FileSystemAccessAdapter } from './adapters/FileSystemAccessAdapter';
16
15
  export { MemoryWorkspaceAdapter } from './adapters/MemoryWorkspaceAdapter';
17
16
  export type { FsaDirectoryHandle, ShowDirectoryPicker } from './adapters/fsaTypes';
@@ -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[];
@@ -27,3 +26,5 @@ export interface LocalFileToolSchema extends BuiltinToolSchema {
27
26
  export declare const LOCAL_FILE_TOOL_SCHEMAS: Record<LocalFilesFunctionCode, LocalFileToolSchema>;
28
27
  /** run_python 的参数 Schema。与文件工具一起注册到同一个插件。 */
29
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>;
@@ -82,19 +82,6 @@ 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
- };
98
85
  }
99
86
  export interface PythonApprovalRequest {
100
87
  requestId: string;
@@ -273,7 +260,7 @@ export interface WorkspaceChangedEvent {
273
260
  export interface ToolEventBase {
274
261
  requestId: string;
275
262
  sessionId: string;
276
- functionCode: string;
263
+ functionCode: LocalFilesFunctionCode;
277
264
  path?: string;
278
265
  }
279
266
  export interface ToolProgressEvent extends ToolEventBase {
@@ -1,4 +1,3 @@
1
- import { CommandRunner } from '../../builtinTools/command';
2
1
  import { WorkspaceFileAdapter } from '../adapters/WorkspaceFileAdapter';
3
2
  import { ShowDirectoryPicker } from '../adapters/fsaTypes';
4
3
  import { LocalFilesLimits } from '../constants';
@@ -16,8 +15,6 @@ export interface LocalWorkspaceOptions {
16
15
  /** 默认会话文件传输的 API 来源;config.transfer 中的方法优先。 */
17
16
  transfer?: SessionFileTransfer;
18
17
  fetch?: typeof fetch;
19
- /** shell、run_file、run_skill_script 的执行器。未设置时依次尝试宿主沙箱、浏览器运行时。 */
20
- commandRunner?: CommandRunner;
21
18
  }
22
19
  /**
23
20
  * 工作文件夹授权与运行状态。一个 BotClient 对应一个实例;UI 与纯 SDK 集成共用同一实例。
@@ -30,12 +27,6 @@ export declare class LocalWorkspace {
30
27
  readonly allowWorkspaceWideTextSearch: boolean;
31
28
  readonly transfer: SessionFileTransfer;
32
29
  readonly fetch: typeof fetch;
33
- commandRunner?: CommandRunner;
34
- readonly browserRuntime: {
35
- enabled: boolean;
36
- bashModuleURL?: string;
37
- pyodideIndexURL?: string;
38
- };
39
30
  private readonly store;
40
31
  private readonly picker?;
41
32
  private readonly event;
@@ -45,7 +36,6 @@ export declare class LocalWorkspace {
45
36
  private pendingHandle;
46
37
  private approvalHandler?;
47
38
  private activeCalls;
48
- private commandRunning;
49
39
  private readonly inflight;
50
40
  private _ready;
51
41
  private stopWatching;
@@ -94,8 +84,6 @@ export declare class LocalWorkspace {
94
84
  getApprovalHandler(): ApprovalHandler | undefined;
95
85
  /** @internal 占用一个并发名额;已满时返回 null。 */
96
86
  acquireSlot(): (() => void) | null;
97
- /** @internal 同一工作区同一时间只跑一个命令;已有命令在运行时返回 null。 */
98
- acquireCommand(): (() => void) | null;
99
87
  /** @internal 登记进行中的调用,更换或断开工作区时统一中止。 */
100
88
  track(controller: AbortController): () => boolean;
101
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.5",
3
+ "version": "3.26.0-alpha.8",
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.5",
82
+ "@glodon-aiot/apis": "^3.26.0-alpha.8",
92
83
  "axios": "0.24.0",
93
84
  "buffer": "^6.0.3",
94
85
  "dayjs": "^1.11.13",
@@ -1,201 +0,0 @@
1
- var k = Object.defineProperty;
2
- var U = (r, t, e) => t in r ? k(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
- var A = (r, t, e) => (U(r, typeof t != "symbol" ? t + "" : t, e), e);
4
- var E = (r, t, e) => new Promise((n, i) => {
5
- var l = (s) => {
6
- try {
7
- a(e.next(s));
8
- } catch (o) {
9
- i(o);
10
- }
11
- }, c = (s) => {
12
- try {
13
- a(e.throw(s));
14
- } catch (o) {
15
- i(o);
16
- }
17
- }, a = (s) => s.done ? n(s.value) : Promise.resolve(s.value).then(l, c);
18
- a((e = e.apply(r, t)).next());
19
- });
20
- import { domError as y } from "../../localFiles/adapters/WorkspaceFileAdapter.mjs";
21
- import { ToolError as x, ToolCode as W } from "../../localFiles/errors.mjs";
22
- import { WORKSPACE_MOUNT as d } from "../constants.mjs";
23
- import { isSyntheticCwd as L, mentionsSyntheticDir as O, SYNTHETIC_DIR_MESSAGE as T } from "../paths.mjs";
24
- import { DEFAULT_BASH_MODULE_URL as B } from "./assets.mjs";
25
- import { loadBash as F } from "./loadBash.mjs";
26
- import { PythonRunner as M, NO_PIP_MESSAGE as R } from "./PythonRunner.mjs";
27
- import { WorkspaceBashFs as N } from "./WorkspaceBashFs.mjs";
28
- const D = `当前环境没有 Node,请改用 python3 或 shell 命令。
29
- `, I = /* @__PURE__ */ new Set(["writeFile", "appendFile", "mkdir", "rm", "cp", "mv", "chmod", "symlink", "link", "utimes", "createExclusive"]), P = "dev|bin|usr|proc|etc|System|Library|private|var|opt|sbin|tmp|Applications|Volumes|cores|net|home", G = new RegExp(`(^|[\\s'"=(;|&<>\`:])/(?!${P}(?=$|[/\\s'"\`;|&)<>:]))(?!/)`, "g");
30
- function H(r) {
31
- let t = !1;
32
- return {
33
- fs: new Proxy(r, {
34
- get(n, i, l) {
35
- const c = Reflect.get(n, i, l);
36
- return typeof c != "function" ? c : (...a) => {
37
- var o;
38
- const s = String((o = a[0]) != null ? o : "");
39
- if (t && I.has(String(i)) && !s.startsWith("/dev/"))
40
- throw Object.assign(new Error(`EROFS: 只能写入工作区下的路径, open '${s}'`), {
41
- code: "EROFS"
42
- });
43
- return c.apply(n, a);
44
- };
45
- }
46
- }),
47
- lock: () => t = !0
48
- };
49
- }
50
- function j(r) {
51
- return r instanceof Uint8Array ? r : Uint8Array.from(String(r != null ? r : ""), (t) => t.charCodeAt(0) & 255);
52
- }
53
- function K(r) {
54
- return r instanceof DOMException && r.name === "AbortError";
55
- }
56
- function V(r) {
57
- if (!r)
58
- return;
59
- if (r === d)
60
- return ".";
61
- if (!r.startsWith(`${d}/`))
62
- return;
63
- const t = r.slice(d.length + 1).replace(/\/+$/, "");
64
- if (!t)
65
- return ".";
66
- const e = t.split("/");
67
- if (!e.some((n) => !n || n === "." || n === ".."))
68
- return e.join("/");
69
- }
70
- function _(r) {
71
- return !r || r === "." ? d : r === d || r.startsWith(`${d}/`) ? r : `${d}/${r.replace(/^\/+/, "")}`;
72
- }
73
- function Y(r) {
74
- return r.replace(G, (t, e) => `${e}${d}/`);
75
- }
76
- function C(r) {
77
- return r.replace(/\/workspace(?![\p{L}\p{N}_.\-])/gu, (t, e, n) => n[e + t.length] === "/" ? "" : "/");
78
- }
79
- class nt {
80
- constructor(t) {
81
- A(this, "python");
82
- this.options = t, this.python = new M({
83
- adapter: t.adapter,
84
- sensitive: t.sensitive,
85
- indexURL: t.pyodideIndexURL,
86
- createWorker: t.createWorker
87
- });
88
- }
89
- load() {
90
- return E(this, null, function* () {
91
- const t = this.options.moduleURL || B;
92
- try {
93
- return yield F(t);
94
- } catch (e) {
95
- throw new x(W.NotImplemented, `命令运行时加载失败,请确认页面能访问 ${t}(CSP 需在 script-src 放行该地址)。`);
96
- }
97
- });
98
- }
99
- create(t, e, n, i) {
100
- const {
101
- adapter: l,
102
- sensitive: c
103
- } = this.options, a = H(new t.InMemoryFs()), s = new t.MountableFs({
104
- base: a.fs
105
- });
106
- s.mount(d, new N(l, "", c));
107
- const o = (m, u, p) => t.defineCommand(m, () => E(this, null, function* () {
108
- return {
109
- stdout: "",
110
- stderr: u,
111
- exitCode: p
112
- };
113
- })), h = (m) => t.defineCommand(m, (u, p) => E(this, null, function* () {
114
- var w;
115
- try {
116
- return yield this.python.run({
117
- args: u,
118
- cwd: p.cwd,
119
- stdin: j(p.stdin),
120
- signal: n
121
- });
122
- } catch (f) {
123
- return f instanceof x || K(f) ? ((w = i.fatal) != null || (i.fatal = f), {
124
- stdout: "",
125
- stderr: "",
126
- exitCode: 1
127
- }) : {
128
- stdout: "",
129
- stderr: `${m}: ${f instanceof Error ? f.message : String(f)}
130
- `,
131
- exitCode: 1
132
- };
133
- }
134
- })), g = new t.Bash({
135
- fs: s,
136
- cwd: e,
137
- env: {
138
- HOME: "/tmp",
139
- LANG: "C.UTF-8"
140
- },
141
- customCommands: [o("node", D, 127), o("pip", R, 1), o("pip3", R, 1), h("python3"), h("python")],
142
- // 默认开启时会在执行期间替换页面的 setTimeout、Function 等全局对象,影响宿主页面。
143
- defenseInDepth: !1
144
- });
145
- return a.lock(), g;
146
- }
147
- exec(t) {
148
- return E(this, null, function* () {
149
- var h, g, m, u, p, w, f, b, v;
150
- if (L(t.cwd) || O((h = t.command) != null ? h : "") || O((m = (g = t.argv) == null ? void 0 : g[1]) != null ? m : ""))
151
- return {
152
- exitCode: 1,
153
- stdout: "",
154
- stderr: `${T}
155
- `
156
- };
157
- const e = yield this.load();
158
- if ((u = t.signal) != null && u.aborted)
159
- throw y("AbortError");
160
- const n = _(t.cwd), i = {}, l = this.create(e, n, t.signal, i), [c, a, ...s] = (p = t.argv) != null ? p : [];
161
- let o;
162
- try {
163
- o = t.argv ? yield l.exec(c, {
164
- cwd: n,
165
- signal: t.signal,
166
- args: [_(a), ...s]
167
- }) : yield l.exec(Y((w = t.command) != null ? w : ""), {
168
- cwd: n,
169
- signal: t.signal,
170
- rawScript: !0
171
- });
172
- } catch (S) {
173
- if (i.fatal)
174
- throw i.fatal;
175
- if ((f = t.signal) != null && f.aborted)
176
- throw y("AbortError");
177
- const $ = S instanceof Error ? S.message : String(S);
178
- return {
179
- exitCode: 1,
180
- stdout: "",
181
- stderr: `bash: ${C($)}
182
- `
183
- };
184
- }
185
- if (i.fatal)
186
- throw i.fatal;
187
- if ((b = t.signal) != null && b.aborted)
188
- throw y("AbortError");
189
- return {
190
- exitCode: o.exitCode,
191
- stdout: C(o.stdout),
192
- stderr: C(o.stderr),
193
- cwd: V((v = o.env) == null ? void 0 : v.PWD)
194
- };
195
- });
196
- }
197
- }
198
- export {
199
- nt as BrowserCommandRunner,
200
- D as NO_NODE_MESSAGE
201
- };