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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/README.md +572 -98
  2. package/dist/es/AgentSession.mjs +230 -165
  3. package/dist/es/BotClient.mjs +186 -136
  4. package/dist/es/Config.mjs +89 -26
  5. package/dist/es/Session.mjs +12 -0
  6. package/dist/es/api/index.mjs +42 -33
  7. package/dist/es/builtinTools/browserRuntime/BrowserCommandRunner.mjs +201 -0
  8. package/dist/es/builtinTools/browserRuntime/PythonRunner.mjs +356 -0
  9. package/dist/es/builtinTools/browserRuntime/WorkspaceBashFs.mjs +350 -0
  10. package/dist/es/builtinTools/browserRuntime/assets.mjs +9 -0
  11. package/dist/es/builtinTools/browserRuntime/loadBash.mjs +17 -0
  12. package/dist/es/builtinTools/browserRuntime/pyodideRunner.py.mjs +96 -0
  13. package/dist/es/builtinTools/browserRuntime/pyodideWorker.mjs +242 -0
  14. package/dist/es/builtinTools/command.mjs +56 -0
  15. package/dist/es/builtinTools/constants.mjs +10 -0
  16. package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +236 -0
  17. package/dist/es/builtinTools/overview.mjs +77 -0
  18. package/dist/es/builtinTools/paths.mjs +63 -0
  19. package/dist/es/builtinTools/schemas.mjs +216 -0
  20. package/dist/es/builtinTools/tools.mjs +471 -0
  21. package/dist/es/index.mjs +69 -9
  22. package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +264 -0
  23. package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +233 -0
  24. package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +197 -0
  25. package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +54 -0
  26. package/dist/es/localFiles/adapters/fsaTypes.mjs +9 -0
  27. package/dist/es/localFiles/constants.mjs +47 -0
  28. package/dist/es/localFiles/createLocalFilesPlugin.mjs +255 -0
  29. package/dist/es/localFiles/errors.mjs +57 -0
  30. package/dist/es/localFiles/host/connectHostBridge.mjs +54 -0
  31. package/dist/es/localFiles/host/protocol.mjs +27 -0
  32. package/dist/es/localFiles/limits.mjs +22 -0
  33. package/dist/es/localFiles/schemas.mjs +312 -0
  34. package/dist/es/localFiles/security/downloadUrlPolicy.mjs +39 -0
  35. package/dist/es/localFiles/security/glob.mjs +28 -0
  36. package/dist/es/localFiles/security/pathPolicy.mjs +59 -0
  37. package/dist/es/localFiles/security/sensitiveFiles.mjs +115 -0
  38. package/dist/es/localFiles/tools/readTools.mjs +333 -0
  39. package/dist/es/localFiles/tools/runtime.mjs +108 -0
  40. package/dist/es/localFiles/tools/transferTools.mjs +228 -0
  41. package/dist/es/localFiles/tools/writeTools.mjs +173 -0
  42. package/dist/es/localFiles/transfer/SessionFileTransfer.mjs +111 -0
  43. package/dist/es/localFiles/validate.mjs +66 -0
  44. package/dist/es/localFiles/workspace/LocalWorkspace.mjs +358 -0
  45. package/dist/es/localFiles/workspace/handleStore.mjs +79 -0
  46. package/dist/es/localFiles/workspace/watchDirectory.mjs +38 -0
  47. package/dist/es/package.json.mjs +38 -29
  48. package/dist/lib/index.js +373 -5
  49. package/dist/src/AgentSession.d.ts +9 -0
  50. package/dist/src/BotClient.d.ts +12 -2
  51. package/dist/src/Config.d.ts +22 -0
  52. package/dist/src/Session.d.ts +5 -1
  53. package/dist/src/api/index.d.ts +3 -1
  54. package/dist/src/builtinTools/browserRuntime/BrowserCommandRunner.d.ts +26 -0
  55. package/dist/src/builtinTools/browserRuntime/PythonRunner.d.ts +67 -0
  56. package/dist/src/builtinTools/browserRuntime/WorkspaceBashFs.d.ts +51 -0
  57. package/dist/src/builtinTools/browserRuntime/assets.d.ts +13 -0
  58. package/dist/src/builtinTools/browserRuntime/loadBash.d.ts +3 -0
  59. package/dist/src/builtinTools/browserRuntime/pyodideWorker.d.ts +44 -0
  60. package/dist/src/builtinTools/command.d.ts +26 -0
  61. package/dist/src/builtinTools/constants.d.ts +17 -0
  62. package/dist/src/builtinTools/createBuiltinToolsPlugin.d.ts +11 -0
  63. package/dist/src/builtinTools/overview.d.ts +5 -0
  64. package/dist/src/builtinTools/paths.d.ts +15 -0
  65. package/dist/src/builtinTools/schemas.d.ts +3 -0
  66. package/dist/src/builtinTools/tools.d.ts +60 -0
  67. package/dist/src/index.d.ts +4 -2
  68. package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +20 -0
  69. package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +43 -0
  70. package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +21 -0
  71. package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +40 -0
  72. package/dist/src/localFiles/adapters/fsaTypes.d.ts +41 -0
  73. package/dist/src/localFiles/constants.d.ts +51 -0
  74. package/dist/src/localFiles/createLocalFilesPlugin.d.ts +11 -0
  75. package/dist/src/localFiles/createLocalPythonPlugin.d.ts +12 -0
  76. package/dist/src/localFiles/errors.d.ts +34 -0
  77. package/dist/src/localFiles/host/connectHostBridge.d.ts +6 -0
  78. package/dist/src/localFiles/host/protocol.d.ts +46 -0
  79. package/dist/src/localFiles/index.d.ts +22 -0
  80. package/dist/src/localFiles/limits.d.ts +3 -0
  81. package/dist/src/localFiles/schemas.d.ts +29 -0
  82. package/dist/src/localFiles/security/downloadUrlPolicy.d.ts +4 -0
  83. package/dist/src/localFiles/security/glob.d.ts +3 -0
  84. package/dist/src/localFiles/security/pathPolicy.d.ts +14 -0
  85. package/dist/src/localFiles/security/sensitiveFiles.d.ts +23 -0
  86. package/dist/src/localFiles/tools/readTools.d.ts +7 -0
  87. package/dist/src/localFiles/tools/runtime.d.ts +43 -0
  88. package/dist/src/localFiles/tools/transferTools.d.ts +4 -0
  89. package/dist/src/localFiles/tools/writeTools.d.ts +4 -0
  90. package/dist/src/localFiles/transfer/SessionFileTransfer.d.ts +40 -0
  91. package/dist/src/localFiles/types.d.ts +319 -0
  92. package/dist/src/localFiles/validate.d.ts +2 -0
  93. package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +111 -0
  94. package/dist/src/localFiles/workspace/handleStore.d.ts +11 -0
  95. package/dist/src/localFiles/workspace/watchDirectory.d.ts +7 -0
  96. package/package.json +13 -4
@@ -3,12 +3,21 @@ import { MCPConfig } from './Config';
3
3
  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
+ private readonly inflightCalls;
6
7
  constructor(token: string, _id?: string, _data?: Partial<ISession>, lazyload?: boolean, application?: IApplication, client?: BotClient);
7
8
  prepareConnection(): Promise<boolean>;
8
9
  registerMcpFromClientConfig(): Promise<boolean>;
9
10
  addMcpServers(mcpServers: MCPConfig): Promise<boolean>;
10
11
  listMcpServers(): Promise<MCPConfig>;
11
12
  sendQuestion(questionBody: QuestionBody, configs: QuestionConfig): Promise<false | undefined>;
13
+ /**
14
+ * 调用客户端插件:传入第三个参数 context(旧插件可忽略),结果最多回传一次,
15
+ * 停止回答或调用被取消后不再回传。
16
+ */
17
+ private invokeClientPlugin;
18
+ private abortClientPluginCalls;
12
19
  stopAnswer(): void;
20
+ inactivate(immediately?: boolean): boolean;
21
+ destroy(): string;
13
22
  private convertKnowledgesToChatFormat;
14
23
  }
@@ -1,8 +1,9 @@
1
1
  import { default as Session } from './Session';
2
2
  import { BotClientConfig } from './Config';
3
- import { IApplication, IPrompt, ISession, ISessionPrompt, SessionQueryParams } from '@glodon-aiot/apis';
3
+ import { LocalWorkspace } from './localFiles/workspace/LocalWorkspace';
4
+ import { IApplication, IPrompt, ISession, ISessionArtifact, ISessionPrompt, SessionQueryParams } from '@glodon-aiot/apis';
4
5
  import { default as EventBus } from './EventBus';
5
- export type ClientEventName = 'ready' | 'application:loaded';
6
+ export type ClientEventName = 'ready' | 'application:loaded' | 'error';
6
7
  export interface SDKConfig {
7
8
  analytics: {
8
9
  enabled: boolean;
@@ -25,8 +26,13 @@ export default class BotClient {
25
26
  private _ready?;
26
27
  private _questionContextMaxLength?;
27
28
  private _promptVariables?;
29
+ private _localWorkspace?;
30
+ private _disconnectHost?;
28
31
  constructor(_token: string, //AIoT resource token
29
32
  configs: BotClientConfig, lazyload?: boolean, sdkConfigs?: SDKConfig);
33
+ private setupLocalWorkspace;
34
+ /** 启用 builtinPlugins.localFiles 后可用;UI 与纯 SDK 集成共用此实例。 */
35
+ get localWorkspace(): LocalWorkspace | undefined;
30
36
  private checkReady;
31
37
  get ready(): boolean | undefined;
32
38
  private set ready(value);
@@ -44,6 +50,10 @@ export default class BotClient {
44
50
  get activeSession(): string;
45
51
  set activeSession(sessionId: string);
46
52
  private createSession;
53
+ /**
54
+ * 获取会话产出物。不传 sessionId 时取当前活跃会话。没有产出物时返回空数组。
55
+ */
56
+ getArtifacts(sessionId?: string): Promise<ISessionArtifact[]>;
47
57
  getSessions(queryParams?: SessionQueryParams): Promise<Session[]>;
48
58
  loadSession(sessionId?: string, sessionParams?: Partial<ISession & {
49
59
  promptVariables?: ISessionPrompt[];
@@ -1,3 +1,5 @@
1
+ import { BuiltinPluginsConfig, LocalFilesConfig, LocalPythonConfig } from './localFiles/types';
2
+ import { LocalWorkspace } from './localFiles/workspace/LocalWorkspace';
1
3
  export interface McpServer {
2
4
  type: 'sse';
3
5
  url: string;
@@ -17,6 +19,8 @@ export interface BotClientConfig {
17
19
  loadRelatedQuesions?: boolean;
18
20
  mcp?: MCPConfig;
19
21
  stream?: boolean;
22
+ /** SDK 内置插件。文件、命令和技能工具注册到同一个 pluginCode。 */
23
+ builtinPlugins?: BuiltinPluginsConfig;
20
24
  }
21
25
  export interface AgentPluginRegistor {
22
26
  [key: string]: Function;
@@ -36,11 +40,29 @@ export declare let configuration: {
36
40
  env: string;
37
41
  apiRoot: string;
38
42
  applicationId: string;
43
+ /** 最终生效的插件表 = 业务插件 + 内置插件,由 configure() 计算,不要直接修改。 */
39
44
  plugins: AgentPluginMap;
45
+ /** 集成方传入的原始 plugins。 */
46
+ businessPlugins: AgentPluginMap;
47
+ builtinPlugins: BuiltinPluginsConfig | undefined;
40
48
  mcp: (MCPConfig | undefined);
41
49
  loadRelatedQuesions: boolean;
42
50
  stream: boolean;
43
51
  };
52
+ export declare function setActiveLocalWorkspace(workspace?: LocalWorkspace): void;
53
+ export declare function getActiveLocalWorkspace(): LocalWorkspace | undefined;
54
+ /** 当前已注册到 configuration.plugins 的内置文件工具编码;未注册时返回 undefined。 */
55
+ export declare function getRegisteredLocalFilesPluginCode(): string | undefined;
56
+ /** 当前已注册到 configuration.plugins 的脚本工具所在插件编码;未注册时返回 undefined。 */
57
+ export declare function getRegisteredLocalPythonPluginCode(): string | undefined;
58
+ /** 显式配置优先,其次按 env 取默认值;都没有时返回 undefined。 */
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;
62
+ /**
63
+ * 重新计算 configuration.plugins,返回本次新出现的问题(相同问题只报告一次)。
64
+ */
65
+ export declare function refreshBuiltinPlugins(): Error[];
44
66
  /**
45
67
  * 配置SDK,可以在SDK被使用前被调用,该方法被调用后将改变是否debug模式、是否测试环境等基本配置
46
68
  * @param param {debug?: boolean; env?: 'dev' | 'test' | 'prod';}
@@ -1,4 +1,4 @@
1
- import { ChatMessageRole, IApplication, IChatMessage, ICommentParam, ISession, ISessionPrompt, CVForceApi, ChatHistoryParams, IKnowledge } from '@glodon-aiot/apis';
1
+ import { ChatMessageRole, IApplication, IChatMessage, ICommentParam, ISession, ISessionArtifact, ISessionPrompt, CVForceApi, ChatHistoryParams, IKnowledge } from '@glodon-aiot/apis';
2
2
  import { MCPConfig } from './Config';
3
3
  import { Socket } from 'socket.io-client';
4
4
  import { default as EventBus } from './EventBus';
@@ -212,6 +212,10 @@ export default abstract class Session {
212
212
  * @param params - 评论参数,包含评论相关的信息,如消息 ID 等
213
213
  * @returns 返回调用 API 提交评论后的响应结果
214
214
  */
215
+ /**
216
+ * 获取当前会话的产出物。没有产出物时返回空数组。
217
+ */
218
+ getArtifacts(): Promise<ISessionArtifact[]>;
215
219
  postMessageComment(params: ICommentParam): Promise<string>;
216
220
  /**
217
221
  * 清除当前会话的上下文信息
@@ -1,2 +1,4 @@
1
- import { CVForceApi } from '@glodon-aiot/apis';
1
+ import { AIShopApi, CVForceApi } from '@glodon-aiot/apis';
2
2
  export declare function getCVForceService(apiBase: string, token: string, errorHandler: (status: number, message: string) => void): CVForceApi;
3
+ /** 平台文件上传与查询,base 为 `${apiRoot}/aishop`。 */
4
+ export declare function getAIShopService(apiBase: string, token: string, errorHandler: (status: number, message: string) => void): AIShopApi;
@@ -0,0 +1,26 @@
1
+ import { WorkspaceFileAdapter } from '../../localFiles/adapters/WorkspaceFileAdapter';
2
+ import { SensitiveFilePolicy } from '../../localFiles/security/sensitiveFiles';
3
+ import { CommandRequest, CommandResult, CommandRunner } from '../command';
4
+ import { WorkerLike } from './PythonRunner';
5
+ export declare const NO_NODE_MESSAGE = "\u5F53\u524D\u73AF\u5883\u6CA1\u6709 Node\uFF0C\u8BF7\u6539\u7528 python3 \u6216 shell \u547D\u4EE4\u3002\n";
6
+ export interface BrowserCommandRunnerOptions {
7
+ adapter: WorkspaceFileAdapter;
8
+ sensitive: SensitiveFilePolicy;
9
+ /** just-bash 浏览器构建的地址,默认 DEFAULT_BASH_MODULE_URL。 */
10
+ moduleURL?: string;
11
+ /** Pyodide 目录,默认 DEFAULT_PYODIDE_INDEX_URL。 */
12
+ pyodideIndexURL?: string;
13
+ createWorker?: (source: string) => WorkerLike;
14
+ }
15
+ /**
16
+ * 纯网页里的命令执行器:just-bash 解释 shell,文件读写落到当前工作区。
17
+ * 每条命令新建一个 shell,只有文件和 cwd 跨命令保留。
18
+ */
19
+ export declare class BrowserCommandRunner implements CommandRunner {
20
+ private readonly options;
21
+ private readonly python;
22
+ constructor(options: BrowserCommandRunnerOptions);
23
+ private load;
24
+ private create;
25
+ exec(request: CommandRequest): Promise<CommandResult>;
26
+ }
@@ -0,0 +1,67 @@
1
+ import { WorkspaceFileAdapter } from '../../localFiles/adapters/WorkspaceFileAdapter';
2
+ import { SensitiveFilePolicy } from '../../localFiles/security/sensitiveFiles';
3
+ export declare const NO_PIP_MESSAGE: string;
4
+ export declare const MAX_SYNC_FILE_BYTES: number;
5
+ export declare const MAX_SYNC_TOTAL_BYTES: number;
6
+ /** 把 shell 或工具传来的目录换成 Pyodide 里的工作区路径。 */
7
+ export declare function toMount(cwd: string): string;
8
+ /** Worker 的最小接口,测试里用 Node 的 worker_threads 实现。 */
9
+ export interface WorkerLike {
10
+ onmessage: ((event: {
11
+ data: unknown;
12
+ }) => void) | null;
13
+ onerror: ((event: unknown) => void) | null;
14
+ postMessage(message: unknown, transfer?: Transferable[]): void;
15
+ terminate(): void;
16
+ }
17
+ export interface PythonRunnerOptions {
18
+ adapter: WorkspaceFileAdapter;
19
+ sensitive: SensitiveFilePolicy;
20
+ /** Pyodide 目录,以 `/` 结尾,默认 DEFAULT_PYODIDE_INDEX_URL。 */
21
+ indexURL?: string;
22
+ createWorker?: (source: string) => WorkerLike;
23
+ }
24
+ export interface PythonRequest {
25
+ /** `python3` 后面的参数。 */
26
+ args: string[];
27
+ /** shell 里的目录。`.` 或 `/workspace` 表示工作区根。 */
28
+ cwd: string;
29
+ stdin?: Uint8Array;
30
+ signal?: AbortSignal;
31
+ }
32
+ export interface PythonResult {
33
+ exitCode: number;
34
+ stdout: string;
35
+ stderr: string;
36
+ }
37
+ type Invocation = {
38
+ mode: 'c' | 'm' | 'file';
39
+ target: string;
40
+ argv: string[];
41
+ stdin: Uint8Array;
42
+ };
43
+ /** 按 python3 命令行解析参数;不需要启动解释器的情况直接给出结果。 */
44
+ export declare function parsePythonArgs(args: string[], cwd: string, stdin: Uint8Array): Invocation | PythonResult;
45
+ /**
46
+ * 浏览器里的 python3:Pyodide 跑在专用 Worker 里,执行前把工作区文件快照同步进去,执行后把改动写回。
47
+ * 同一时间只跑一个请求;超时或取消时终止 Worker,下次重新创建。
48
+ */
49
+ export declare class PythonRunner {
50
+ private readonly options;
51
+ private state?;
52
+ private queue;
53
+ private nextId;
54
+ constructor(options: PythonRunnerOptions);
55
+ private get indexURL();
56
+ private loadError;
57
+ private dispose;
58
+ private spawn;
59
+ run(request: PythonRequest): Promise<PythonResult>;
60
+ private runNow;
61
+ /** 执行前把整个工作区读进 Pyodide。 */
62
+ private collect;
63
+ private exists;
64
+ /** 把 Python 里的改动写回工作区,返回是否有写回失败。 */
65
+ private writeBack;
66
+ }
67
+ export {};
@@ -0,0 +1,51 @@
1
+ import { BufferEncoding, CpOptions, FileContent, FsStat, IFileSystem, MkdirOptions, RmOptions } from 'just-bash/browser';
2
+ import { WorkspaceFileAdapter } from '../../localFiles/adapters/WorkspaceFileAdapter';
3
+ import { SensitiveFilePolicy } from '../../localFiles/security/sensitiveFiles';
4
+ type EncodingOption = {
5
+ encoding?: BufferEncoding | null;
6
+ } | BufferEncoding | undefined;
7
+ interface DirentEntry {
8
+ name: string;
9
+ isFile: boolean;
10
+ isDirectory: boolean;
11
+ isSymbolicLink: boolean;
12
+ }
13
+ /**
14
+ * 把工作区挂到 just-bash 的一个目录。root 为空表示整个工作区。
15
+ * 收到的路径相对挂载点,以 `/` 开头。
16
+ */
17
+ export declare class WorkspaceBashFs implements IFileSystem {
18
+ private readonly adapter;
19
+ private readonly root;
20
+ private readonly sensitive;
21
+ constructor(adapter: WorkspaceFileAdapter, root: string, sensitive: SensitiveFilePolicy);
22
+ private relative;
23
+ private shown;
24
+ private isRoot;
25
+ private guard;
26
+ private mapError;
27
+ private entry;
28
+ private ensureRoot;
29
+ readFileBuffer(path: string): Promise<Uint8Array>;
30
+ readFile(path: string, options?: EncodingOption): Promise<string>;
31
+ writeFile(path: string, content: FileContent, options?: EncodingOption): Promise<void>;
32
+ appendFile(path: string, content: FileContent, options?: EncodingOption): Promise<void>;
33
+ exists(path: string): Promise<boolean>;
34
+ stat(path: string): Promise<FsStat>;
35
+ lstat(path: string): Promise<FsStat>;
36
+ mkdir(path: string, options?: MkdirOptions): Promise<void>;
37
+ readdirWithFileTypes(path: string): Promise<DirentEntry[]>;
38
+ readdir(path: string): Promise<string[]>;
39
+ rm(path: string, options?: RmOptions): Promise<void>;
40
+ cp(src: string, dest: string, options?: CpOptions): Promise<void>;
41
+ mv(src: string, dest: string): Promise<void>;
42
+ resolvePath(base: string, path: string): string;
43
+ getAllPaths(): string[];
44
+ chmod(path: string): Promise<void>;
45
+ symlink(_target: string, linkPath: string): Promise<void>;
46
+ link(_existingPath: string, newPath: string): Promise<void>;
47
+ readlink(path: string): Promise<string>;
48
+ realpath(path: string): Promise<string>;
49
+ utimes(path: string): Promise<void>;
50
+ }
51
+ export {};
@@ -0,0 +1,13 @@
1
+ /** 公司 OBS 上的前端依赖目录,按 `<包名>/<版本>/` 存放。 */
2
+ export declare const CDN_LIBS_ROOT = "https://cv-cdn.obs.cn-north-4.myhuaweicloud.com/glodon/libs/";
3
+ /** 必须与 package.json 里 just-bash 的版本一致;升级时先上传新版本目录。 */
4
+ export declare const JUST_BASH_VERSION = "3.6.0";
5
+ export declare const DEFAULT_BASH_MODULE_URL = "https://cv-cdn.obs.cn-north-4.myhuaweicloud.com/glodon/libs/just-bash/3.6.0/just-bash.mjs";
6
+ /** 必须与 package.json 里 pyodide 的版本一致;升级时先上传新版本目录。 */
7
+ export declare const PYODIDE_VERSION = "314.0.7";
8
+ export declare const DEFAULT_PYODIDE_INDEX_URL = "https://cv-cdn.obs.cn-north-4.myhuaweicloud.com/glodon/libs/pyodide/314.0.7/";
9
+ /**
10
+ * 浏览器里可以 import 的第三方包,构建脚本按它们的依赖闭包上传 wheel 并改写 pyodide-lock.json。
11
+ * 调整后需要重新构建并上传新的 Pyodide 目录。
12
+ */
13
+ export declare const PYODIDE_PACKAGES: string[];
@@ -0,0 +1,3 @@
1
+ export type BashModule = typeof import('just-bash/browser');
2
+ /** 第一次执行命令时才从 url 加载 just-bash,不进首屏。加载失败后下次重试。 */
3
+ export declare function loadBash(url: string): Promise<BashModule>;
@@ -0,0 +1,44 @@
1
+ /** Emscripten 的 ErrnoError 不是 Error,只带 errno 和 code。 */
2
+ declare function describe(error: any): any;
3
+ declare function networkDenied(url: any): TypeError;
4
+ /** 只放行 indexURL 下的资源(Pyodide 自身和白名单 wheel),其余请求一律拒绝。 */
5
+ declare function guardNetwork(indexURL: any): void;
6
+ declare function collector(): {
7
+ write(bytes: any): void;
8
+ finish(): string;
9
+ };
10
+ declare function init({ indexURL, packages, runner }: {
11
+ indexURL: any;
12
+ packages: any;
13
+ runner: any;
14
+ }): Promise<void>;
15
+ declare function dirname(path: any): any;
16
+ /** 主脚本、`-c` 代码,以及主脚本目录和 cwd 下的 .py 文件里出现的 import。 */
17
+ declare function sourcesToScan({ files, cwd, mode, target }: {
18
+ files: any;
19
+ cwd: any;
20
+ mode: any;
21
+ target: any;
22
+ }): any[];
23
+ declare function loadPackages(sources: any, stderr: any): Promise<void>;
24
+ declare function lstat(path: any): any;
25
+ declare function removeTree(path: any): void;
26
+ declare function walk(path: any, files: any, dirs: any): void;
27
+ declare function sameBytes(a: any, b: any): boolean;
28
+ declare function execute(message: any): Promise<{
29
+ exitCode: any;
30
+ stdout: string;
31
+ stderr: string;
32
+ written: {
33
+ path: any;
34
+ data: any;
35
+ }[];
36
+ removed: any[];
37
+ createdDirs: any[];
38
+ removedDirs: string[];
39
+ }>;
40
+ declare const ROOTS: string[];
41
+ declare const OUTPUT_LIMIT: number;
42
+ declare let pyodide: null;
43
+ declare let runPython: null;
44
+ declare let sink: null;
@@ -0,0 +1,26 @@
1
+ /** 在工作区里执行命令。由端侧宿主沙箱、浏览器运行时或测试注入实现。 */
2
+ export interface CommandRequest {
3
+ /** shell 命令。与 argv 二选一。 */
4
+ command?: string;
5
+ /** 直接执行的程序和参数,不经过 shell。 */
6
+ argv?: string[];
7
+ /** 工作区相对目录。`.` 表示工作区根。 */
8
+ cwd: string;
9
+ timeoutMs?: number;
10
+ signal?: AbortSignal;
11
+ }
12
+ export interface CommandResult {
13
+ exitCode: number;
14
+ stdout: string;
15
+ stderr: string;
16
+ /** 命令结束后的工作区相对目录。shell 用来保留上次停留的目录。 */
17
+ cwd?: string;
18
+ }
19
+ export interface CommandRunner {
20
+ exec(request: CommandRequest): Promise<CommandResult>;
21
+ }
22
+ /** stdout、stderr 各自返回给模型的字符上限。 */
23
+ export declare const MAX_COMMAND_OUTPUT_CHARS = 16000;
24
+ export declare const OUTPUT_TRUNCATED_NOTE = "\n\u2026\u8F93\u51FA\u5DF2\u622A\u65AD";
25
+ export declare function limitOutput(text: string): string;
26
+ export declare function withOutputLimit(runner: CommandRunner): CommandRunner;
@@ -0,0 +1,17 @@
1
+ export declare const BUILTIN_FUNCTION_CODES: readonly ["shell", "read_file", "write_file", "append_file", "run_file", "edit_file", "grep", "find", "load_skill", "read_skill_resource", "run_skill_script"];
2
+ export type BuiltinFunctionCode = (typeof BUILTIN_FUNCTION_CODES)[number];
3
+ /** 单次 read_file 按原文返回的上限。超出后结构化文本改为概览。 */
4
+ export declare const MAX_READ_BYTES = 81920;
5
+ /** write_file 单次覆盖写入的 UTF-8 字节上限。 */
6
+ export declare const MAX_WRITE_BYTES = 81920;
7
+ export declare const MAX_COMMAND_CHARS = 20000;
8
+ /** shell 一开始停在工作区根目录。 */
9
+ export declare const SHELL_CWD = ".";
10
+ /**
11
+ * 浏览器 shell 把工作区挂在这里。命令里的工作区绝对路径会改写到这个前缀,
12
+ * 输出再换回以 / 开头的工作区路径。
13
+ */
14
+ export declare const WORKSPACE_MOUNT = "/workspace";
15
+ /** 技能目录在工作区根下。 */
16
+ export declare const SKILLS_DIR = "skills";
17
+ export declare const RUNNABLE_EXTENSIONS: readonly [".py", ".sh", ".js"];
@@ -0,0 +1,11 @@
1
+ import { LocalWorkspace } from '../localFiles/workspace/LocalWorkspace';
2
+ import { ClientPluginCallback, ToolContext } from '../localFiles/types';
3
+ import { BuiltinFunctionCode } from './constants';
4
+ export type BuiltinHandler = (params: unknown, callback: ClientPluginCallback, context?: Partial<ToolContext>) => void;
5
+ export type BuiltinPluginTable = Record<string, Record<BuiltinFunctionCode, BuiltinHandler>>;
6
+ export interface CreateBuiltinToolsPluginOptions {
7
+ pluginCode: string;
8
+ workspace: LocalWorkspace;
9
+ }
10
+ /** 组装内置工具插件:`{ [pluginCode]: { shell, read_file, ... } }`。 */
11
+ export declare function createBuiltinToolsPlugin({ pluginCode, workspace, }: CreateBuiltinToolsPluginOptions): BuiltinPluginTable;
@@ -0,0 +1,5 @@
1
+ export declare function isStructuredPath(path: string): boolean;
2
+ export declare function structureOverview(path: string, text: string): string;
3
+ export declare function extensionOf(path: string): string;
4
+ export declare function isImagePath(path: string): boolean;
5
+ export declare function isPdf(path: string, bytes?: Uint8Array): boolean;
@@ -0,0 +1,15 @@
1
+ export declare const SYNTHETIC_DIRS: readonly ["input", "output", "uploads", "tmp"];
2
+ export declare const SYNTHETIC_DIR_MESSAGE = "\u4E0D\u8981\u4F7F\u7528 input\u3001output\u3001uploads\u3001tmp\uFF0C\u4E5F\u4E0D\u8981\u65B0\u5EFA\u8FD9\u4E9B\u76EE\u5F55\u3002\u8BF7\u628A\u6587\u4EF6\u76F4\u63A5\u653E\u5728\u5DE5\u4F5C\u533A\u5DF2\u6709\u4F4D\u7F6E\u6216\u6839\u76EE\u5F55\u3002";
3
+ export declare function mentionsSyntheticDir(text: string): boolean;
4
+ export declare function isSyntheticCwd(cwd: string): boolean;
5
+ /**
6
+ * 把工作区内绝对路径转成相对工作区根的路径。`/` 表示工作区根。
7
+ * 拒绝相对路径、盘符和 .. 。
8
+ */
9
+ export declare function resolveWorkspacePath(input: string): string;
10
+ export declare function resolveFilePath(input: string): string;
11
+ export declare function resolveRunPath(input: string): string;
12
+ export declare function toVirtualPath(relative: string): string;
13
+ /** shell 回传的目录必须仍在工作区内。`.` 表示工作区根。 */
14
+ export declare function isSafeCwd(cwd: string): boolean;
15
+ export declare function skillRelative(skillName: string, relativeName: string): string;
@@ -0,0 +1,3 @@
1
+ import { BuiltinToolSchema } from '../localFiles/schemas';
2
+ import { BuiltinFunctionCode } from './constants';
3
+ export declare const BUILTIN_TOOL_SCHEMAS: Record<BuiltinFunctionCode, BuiltinToolSchema>;
@@ -0,0 +1,60 @@
1
+ import { WorkspaceFileAdapter } from '../localFiles/adapters/WorkspaceFileAdapter';
2
+ import { CommandRunner } from './command';
3
+ export interface ToolIO {
4
+ adapter: WorkspaceFileAdapter;
5
+ runner?: CommandRunner;
6
+ signal?: AbortSignal;
7
+ timeoutMs: number;
8
+ shellCwd: {
9
+ cwd: string;
10
+ };
11
+ }
12
+ interface ToolOutput {
13
+ data: Record<string, unknown>;
14
+ truncated?: boolean;
15
+ }
16
+ export declare function readFile(input: {
17
+ path: string;
18
+ start_line?: number;
19
+ end_line?: number;
20
+ }, io: ToolIO): Promise<ToolOutput>;
21
+ export declare function writeFile(input: {
22
+ path: string;
23
+ content: string;
24
+ }, io: ToolIO): Promise<ToolOutput>;
25
+ export declare function appendFile(input: {
26
+ path: string;
27
+ content: string;
28
+ }, io: ToolIO): Promise<ToolOutput>;
29
+ export declare function editFile(input: {
30
+ path: string;
31
+ old_text: string;
32
+ new_text: string;
33
+ }, io: ToolIO): Promise<ToolOutput>;
34
+ export declare function grep(input: {
35
+ path: string;
36
+ pattern: string;
37
+ }, io: ToolIO): Promise<ToolOutput>;
38
+ export declare function find(input: {
39
+ path: string;
40
+ name: string;
41
+ }, io: ToolIO): Promise<ToolOutput>;
42
+ export declare function runFile(input: {
43
+ path: string;
44
+ }, io: ToolIO): Promise<ToolOutput>;
45
+ export declare function shell(input: {
46
+ command: string;
47
+ }, io: ToolIO): Promise<ToolOutput>;
48
+ export declare function loadSkill(input: {
49
+ skill_name: string;
50
+ }, io: ToolIO): Promise<ToolOutput>;
51
+ export declare function readSkillResource(input: {
52
+ skill_name: string;
53
+ resource_name: string;
54
+ }, io: ToolIO): Promise<ToolOutput>;
55
+ export declare function runSkillScript(input: {
56
+ skill_name: string;
57
+ script_name: string;
58
+ args?: string[];
59
+ }, io: ToolIO): Promise<ToolOutput>;
60
+ export {};
@@ -1,5 +1,7 @@
1
- export type { AgentPluginRegistor, AgentPluginMap, MCPConfig, McpServer } from './Config';
2
- export { configure, configuration } from './Config';
1
+ export type { AgentPluginRegistor, AgentPluginMap, BotClientConfig, MCPConfig, McpServer } from './Config';
2
+ export { configure, configuration, getRegisteredLocalFilesPluginCode, getRegisteredLocalPythonPluginCode, resolveLocalFilesPluginCode, } from './Config';
3
+ export type { ISessionArtifact } from '@glodon-aiot/apis';
3
4
  export { default as BotClient } from './BotClient';
4
5
  export { default as Session } from './Session';
5
6
  export { default as AgentPlugin } from './AgentPlugin';
7
+ export * from './localFiles';
@@ -0,0 +1,20 @@
1
+ import { RemoveOptions, WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource } from './WorkspaceFileAdapter';
2
+ import { FsaDirectoryHandle } from './fsaTypes';
3
+ /**
4
+ * 基于用户授权的 DirectoryHandle 的工作区。只通过逐级 getDirectoryHandle / getFileHandle
5
+ * 访问子树,不使用任何绝对路径。FSA 不暴露符号链接目标,链接的处理以浏览器行为为准。
6
+ */
7
+ export declare class FileSystemAccessAdapter implements WorkspaceFileAdapter {
8
+ private readonly root;
9
+ constructor(root: FsaDirectoryHandle);
10
+ get displayName(): string;
11
+ private resolveDirectory;
12
+ private resolveFile;
13
+ stat(path: string): Promise<WorkspaceEntry>;
14
+ listEntries(path: string, signal?: AbortSignal): Promise<WorkspaceEntry[]>;
15
+ readFile(path: string): Promise<Blob>;
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
+ }
@@ -0,0 +1,43 @@
1
+ import { CommandRequest, CommandResult } from '../../builtinTools/command';
2
+ import { WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource } from './WorkspaceFileAdapter';
3
+ import { HostCapability, HostResponseMessage, HostWebView } from '../host/protocol';
4
+ /**
5
+ * 把工作区原语转成宿主消息。页面看不到绝对路径,目录由宿主在授权后推送。
6
+ */
7
+ export declare class HostBridgeAdapter implements WorkspaceFileAdapter {
8
+ private readonly view;
9
+ displayName: string;
10
+ /** 宿主最近一次 workspace 消息声明的能力。 */
11
+ capabilities: ReadonlySet<HostCapability>;
12
+ /** 宿主随 sandbox-exec 声明的沙箱包版本和协议。 */
13
+ sandboxVersion?: string;
14
+ sandboxProtocol?: number;
15
+ private seq;
16
+ private readonly pending;
17
+ constructor(view: HostWebView, displayName?: string);
18
+ setCapabilities(value: unknown, sandbox?: {
19
+ version?: unknown;
20
+ protocol?: unknown;
21
+ }): void;
22
+ /** 声明了 sandbox-exec 且协议版本与 SDK 一致时才把命令交给宿主。 */
23
+ get canExec(): boolean;
24
+ private requireCapability;
25
+ settle(message: HostResponseMessage): void;
26
+ private call;
27
+ stat(path: string): Promise<WorkspaceEntry>;
28
+ listEntries(path: string, signal?: AbortSignal): Promise<WorkspaceEntry[]>;
29
+ readFile(path: string): Promise<Blob>;
30
+ createDirectory(path: string): Promise<void>;
31
+ remove(path: string, options?: {
32
+ recursive?: boolean;
33
+ }): Promise<void>;
34
+ move(from: string, to: string): Promise<void>;
35
+ exec(request: CommandRequest): Promise<CommandResult>;
36
+ runPython(path: string, args: string[], timeoutMs: number, signal?: AbortSignal): Promise<{
37
+ exitCode: number;
38
+ timedOut: boolean;
39
+ stdout: string;
40
+ stderr: string;
41
+ }>;
42
+ writeFile(path: string, source: WriteSource, options?: WriteOptions): Promise<void>;
43
+ }
@@ -0,0 +1,21 @@
1
+ import { RemoveOptions, WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource } from './WorkspaceFileAdapter';
2
+ /** 内存工作区:用于测试与契约基准,语义与 FileSystemAccessAdapter 一致。 */
3
+ export declare class MemoryWorkspaceAdapter implements WorkspaceFileAdapter {
4
+ readonly displayName: string;
5
+ private root;
6
+ constructor(files?: Record<string, string | Uint8Array>, displayName?: string);
7
+ /**
8
+ * 直接写入文件(含中间目录),用于构造测试数据或模拟外部修改。
9
+ * 以 `/` 结尾的路径表示创建空目录。
10
+ */
11
+ seed(path: string, content?: string | Uint8Array, lastModified?: number): void;
12
+ private resolveDirectory;
13
+ private resolveNode;
14
+ stat(path: string): Promise<WorkspaceEntry>;
15
+ listEntries(path: string, signal?: AbortSignal): Promise<WorkspaceEntry[]>;
16
+ readFile(path: string): Promise<Blob>;
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
+ }
@@ -0,0 +1,40 @@
1
+ export interface WorkspaceEntry {
2
+ name: string;
3
+ kind: 'file' | 'directory';
4
+ size?: number;
5
+ lastModified?: number;
6
+ }
7
+ export type WriteSource = string | Uint8Array | AsyncIterable<Uint8Array>;
8
+ export interface WriteOptions {
9
+ createDirectories?: boolean;
10
+ signal?: AbortSignal;
11
+ }
12
+ /**
13
+ * 工作区磁盘原语。路径均为已规范化的工作区相对路径,根目录为空字符串。
14
+ * 失败时抛出与 FSA 同名的 DOMException(NotFoundError、TypeMismatchError 等),
15
+ * 由工具层统一映射为错误码,保证不同后端语义一致。
16
+ */
17
+ export interface WorkspaceFileAdapter {
18
+ readonly displayName: string;
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
+ /** 逐级创建目录,已存在时不报错。路径上有同名文件时抛 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
+ }
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
+ export declare function domError(name: string, message?: string): DOMException;
40
+ export declare function toChunks(source: WriteSource): AsyncIterable<Uint8Array>;