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

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 (99) hide show
  1. package/README.md +284 -254
  2. package/dist/es/AgentSession.mjs +267 -197
  3. package/dist/es/BotClient.mjs +200 -123
  4. package/dist/es/Config.mjs +55 -88
  5. package/dist/es/DialogSession.mjs +123 -118
  6. package/dist/es/EventBus.mjs +38 -34
  7. package/dist/es/Logger.mjs +19 -21
  8. package/dist/es/Session.mjs +338 -284
  9. package/dist/es/api/index.mjs +31 -30
  10. package/dist/es/builtinTools/browserRuntime/BrowserCommandRunner.mjs +201 -0
  11. package/dist/es/builtinTools/browserRuntime/PythonRunner.mjs +356 -0
  12. package/dist/es/builtinTools/browserRuntime/WorkspaceBashFs.mjs +350 -0
  13. package/dist/es/builtinTools/browserRuntime/assets.mjs +9 -0
  14. package/dist/es/builtinTools/browserRuntime/loadBash.mjs +17 -0
  15. package/dist/es/builtinTools/browserRuntime/pyodideRunner.py.mjs +96 -0
  16. package/dist/es/builtinTools/browserRuntime/pyodideWorker.mjs +242 -0
  17. package/dist/es/builtinTools/command.mjs +56 -0
  18. package/dist/es/builtinTools/constants.mjs +17 -0
  19. package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +266 -0
  20. package/dist/es/builtinTools/overview.mjs +77 -0
  21. package/dist/es/builtinTools/paths.mjs +70 -0
  22. package/dist/es/builtinTools/platformSkills.mjs +248 -0
  23. package/dist/es/builtinTools/schemas.mjs +261 -0
  24. package/dist/es/builtinTools/tools.mjs +595 -0
  25. package/dist/es/index.mjs +66 -64
  26. package/dist/es/localFiles/adapters/FileSnapshotAdapter.mjs +160 -0
  27. package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +185 -113
  28. package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +127 -137
  29. package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +132 -97
  30. package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +32 -28
  31. package/dist/es/localFiles/constants.mjs +24 -28
  32. package/dist/es/localFiles/createLocalFilesPlugin.mjs +53 -52
  33. package/dist/es/localFiles/errors.mjs +44 -35
  34. package/dist/es/localFiles/host/connectHostBridge.mjs +43 -35
  35. package/dist/es/localFiles/host/protocol.mjs +27 -13
  36. package/dist/es/localFiles/host/sandboxClient.mjs +494 -0
  37. package/dist/es/localFiles/host/sandboxFrames.mjs +21 -0
  38. package/dist/es/localFiles/preview.mjs +33 -0
  39. package/dist/es/localFiles/schemas.mjs +40 -86
  40. package/dist/es/localFiles/validate.mjs +37 -37
  41. package/dist/es/localFiles/workspace/LocalWorkspace.mjs +176 -90
  42. package/dist/es/localFiles/workspace/WorkspaceFiles.mjs +246 -0
  43. package/dist/es/localMcp/client.mjs +234 -0
  44. package/dist/es/localMcp/endpoints.mjs +94 -0
  45. package/dist/es/localMcp/register.mjs +207 -0
  46. package/dist/es/localMcp/registry.mjs +43 -0
  47. package/dist/es/package.json.mjs +49 -60
  48. package/dist/es/sessionUpload.mjs +49 -0
  49. package/dist/es/utils.mjs +24 -11
  50. package/dist/lib/index.js +382 -10
  51. package/dist/src/AgentSession.d.ts +13 -0
  52. package/dist/src/BotClient.d.ts +13 -1
  53. package/dist/src/Config.d.ts +7 -8
  54. package/dist/src/EventBus.d.ts +3 -0
  55. package/dist/src/Logger.d.ts +15 -8
  56. package/dist/src/PayloadTypes.d.ts +2 -0
  57. package/dist/src/Session.d.ts +19 -2
  58. package/dist/src/api/index.d.ts +2 -2
  59. package/dist/src/builtinTools/browserRuntime/BrowserCommandRunner.d.ts +26 -0
  60. package/dist/src/builtinTools/browserRuntime/PythonRunner.d.ts +67 -0
  61. package/dist/src/builtinTools/browserRuntime/WorkspaceBashFs.d.ts +51 -0
  62. package/dist/src/builtinTools/browserRuntime/assets.d.ts +13 -0
  63. package/dist/src/builtinTools/browserRuntime/loadBash.d.ts +3 -0
  64. package/dist/src/builtinTools/browserRuntime/pyodideWorker.d.ts +44 -0
  65. package/dist/src/builtinTools/command.d.ts +35 -0
  66. package/dist/src/builtinTools/constants.d.ts +25 -0
  67. package/dist/src/builtinTools/createBuiltinToolsPlugin.d.ts +11 -0
  68. package/dist/src/builtinTools/overview.d.ts +5 -0
  69. package/dist/src/builtinTools/paths.d.ts +16 -0
  70. package/dist/src/builtinTools/platformSkills.d.ts +92 -0
  71. package/dist/src/builtinTools/schemas.d.ts +3 -0
  72. package/dist/src/builtinTools/tools.d.ts +73 -0
  73. package/dist/src/constant.d.ts +1 -1
  74. package/dist/src/index.d.ts +2 -1
  75. package/dist/src/localFiles/adapters/FileSnapshotAdapter.d.ts +24 -0
  76. package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +4 -1
  77. package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +30 -14
  78. package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +4 -1
  79. package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +22 -0
  80. package/dist/src/localFiles/adapters/fsaTypes.d.ts +2 -0
  81. package/dist/src/localFiles/constants.d.ts +5 -13
  82. package/dist/src/localFiles/errors.d.ts +1 -1
  83. package/dist/src/localFiles/host/protocol.d.ts +34 -16
  84. package/dist/src/localFiles/host/sandboxClient.d.ts +112 -0
  85. package/dist/src/localFiles/host/sandboxFrames.d.ts +9 -0
  86. package/dist/src/localFiles/index.d.ts +11 -6
  87. package/dist/src/localFiles/preview.d.ts +2 -0
  88. package/dist/src/localFiles/schemas.d.ts +2 -5
  89. package/dist/src/localFiles/types.d.ts +16 -23
  90. package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +35 -1
  91. package/dist/src/localFiles/workspace/WorkspaceFiles.d.ts +63 -0
  92. package/dist/src/localMcp/client.d.ts +15 -0
  93. package/dist/src/localMcp/endpoints.d.ts +19 -0
  94. package/dist/src/localMcp/register.d.ts +34 -0
  95. package/dist/src/localMcp/registry.d.ts +27 -0
  96. package/dist/src/sessionUpload.d.ts +14 -0
  97. package/dist/src/utils.d.ts +6 -0
  98. package/package.json +13 -24
  99. package/dist/es/localFiles/createLocalPythonPlugin.mjs +0 -196
@@ -4,18 +4,31 @@ import { default as Session, QuestionBody, QuestionConfig } from './Session';
4
4
  import { default as BotClient } from './BotClient';
5
5
  export default class AgentSession extends Session {
6
6
  private readonly inflightCalls;
7
+ private localMcpTicket;
8
+ private stopLocalMcpUpdates?;
9
+ /** 已发出 `update`、尚未收到结果;下一条 ready / ack 按换票结果处理,不拆连接。 */
10
+ private pendingTokenUpdate;
7
11
  constructor(token: string, _id?: string, _data?: Partial<ISession>, lazyload?: boolean, application?: IApplication, client?: BotClient);
8
12
  prepareConnection(): Promise<boolean>;
9
13
  registerMcpFromClientConfig(): Promise<boolean>;
14
+ private registerLocalMcp;
10
15
  addMcpServers(mcpServers: MCPConfig): Promise<boolean>;
11
16
  listMcpServers(): Promise<MCPConfig>;
12
17
  sendQuestion(questionBody: QuestionBody, configs: QuestionConfig): Promise<false | undefined>;
18
+ private emitQuestion;
13
19
  /**
14
20
  * 调用客户端插件:传入第三个参数 context(旧插件可忽略),结果最多回传一次,
15
21
  * 停止回答或调用被取消后不再回传。
16
22
  */
17
23
  private invokeClientPlugin;
18
24
  private abortClientPluginCalls;
25
+ /**
26
+ * 长连接静默换票:发 `update`,body 为 `{ resourceToken }`(无 Bearer,与建连一致)。
27
+ * 结果走 ack 或下一条 `ready`;失败只报错,不拆连接(服务端仍用旧 token)。
28
+ * 断线期间不发 `update`,只更新重连握手用的 token。
29
+ */
30
+ updateSocketResourceToken(resourceToken: string): void;
31
+ private handleResourceTokenUpdateResult;
19
32
  stopAnswer(): void;
20
33
  inactivate(immediately?: boolean): boolean;
21
34
  destroy(): string;
@@ -3,7 +3,7 @@ import { BotClientConfig } from './Config';
3
3
  import { LocalWorkspace } from './localFiles/workspace/LocalWorkspace';
4
4
  import { IApplication, IPrompt, ISession, ISessionArtifact, ISessionPrompt, SessionQueryParams } from '@glodon-aiot/apis';
5
5
  import { default as EventBus } from './EventBus';
6
- export type ClientEventName = 'ready' | 'application:loaded' | 'error';
6
+ export type ClientEventName = 'ready' | 'application:loaded' | 'sessions:updated' | 'error';
7
7
  export interface SDKConfig {
8
8
  analytics: {
9
9
  enabled: boolean;
@@ -28,8 +28,11 @@ export default class BotClient {
28
28
  private _promptVariables?;
29
29
  private _localWorkspace?;
30
30
  private _disconnectHost?;
31
+ /** 后进入的会话作废尚未返回的编排刷新。 */
32
+ private arrangeSkillEpoch;
31
33
  constructor(_token: string, //AIoT resource token
32
34
  configs: BotClientConfig, lazyload?: boolean, sdkConfigs?: SDKConfig);
35
+ private logReady;
33
36
  private setupLocalWorkspace;
34
37
  /** 启用 builtinPlugins.localFiles 后可用;UI 与纯 SDK 集成共用此实例。 */
35
38
  get localWorkspace(): LocalWorkspace | undefined;
@@ -44,6 +47,11 @@ export default class BotClient {
44
47
  private loadApplication;
45
48
  private getService;
46
49
  get token(): string;
50
+ /**
51
+ * 更新 resource token。
52
+ * rid / ten / ext / label 都相同时只换票,不卸会话;
53
+ * 任一不同时沿用原逻辑(ready 置 false,应用 id 变则重载并 clean)。
54
+ */
47
55
  set token(v: string);
48
56
  get applicationId(): string;
49
57
  get application(): IApplication | null;
@@ -55,6 +63,8 @@ export default class BotClient {
55
63
  */
56
64
  getArtifacts(sessionId?: string): Promise<ISessionArtifact[]>;
57
65
  getSessions(queryParams?: SessionQueryParams): Promise<Session[]>;
66
+ /** 只更新 arrange[0].skills。查询失败时保留内存中的名单,会话仍可进入。 */
67
+ private refreshArrangeSkills;
58
68
  loadSession(sessionId?: string, sessionParams?: Partial<ISession & {
59
69
  promptVariables?: ISessionPrompt[];
60
70
  }>): Promise<Session>;
@@ -65,4 +75,6 @@ export default class BotClient {
65
75
  removeEventListener(eventName: ClientEventName, callback: any): void;
66
76
  removeSession(session: string | Session, deleteFromRemote?: boolean): Promise<void>;
67
77
  clean(): void;
78
+ /** 同 payload 换票后,让已连接的 Agent 会话向服务端发 `update`。 */
79
+ private notifySessionsResourceToken;
68
80
  }
@@ -1,4 +1,4 @@
1
- import { BuiltinPluginsConfig, LocalFilesConfig, LocalPythonConfig } from './localFiles/types';
1
+ import { BuiltinPluginsConfig, LocalFilesConfig } from './localFiles/types';
2
2
  import { LocalWorkspace } from './localFiles/workspace/LocalWorkspace';
3
3
  export interface McpServer {
4
4
  type: 'sse';
@@ -19,7 +19,7 @@ export interface BotClientConfig {
19
19
  loadRelatedQuesions?: boolean;
20
20
  mcp?: MCPConfig;
21
21
  stream?: boolean;
22
- /** SDK 内置插件:本地文件工具和 run_python,注册到同一个 pluginCode。 */
22
+ /** SDK 内置插件。文件、命令和技能工具注册到同一个 pluginCode。 */
23
23
  builtinPlugins?: BuiltinPluginsConfig;
24
24
  }
25
25
  export interface AgentPluginRegistor {
@@ -53,18 +53,17 @@ export declare function setActiveLocalWorkspace(workspace?: LocalWorkspace): voi
53
53
  export declare function getActiveLocalWorkspace(): LocalWorkspace | undefined;
54
54
  /** 当前已注册到 configuration.plugins 的内置文件工具编码;未注册时返回 undefined。 */
55
55
  export declare function getRegisteredLocalFilesPluginCode(): string | undefined;
56
- /** 当前已注册到 configuration.plugins 的 run_python 所在插件编码;未注册时返回 undefined。 */
57
- export declare function getRegisteredLocalPythonPluginCode(): string | undefined;
58
56
  /** 显式配置优先,其次按 env 取默认值;都没有时返回 undefined。 */
59
57
  export declare function resolveLocalFilesPluginCode(config: LocalFilesConfig | undefined, env: string): string;
60
- /** 显式配置优先,其次跟随文件工具编码,最后按 env 取默认值。 */
61
- export declare function resolveLocalPythonPluginCode(config: LocalPythonConfig | undefined, env: string, filesPluginCode?: string): string;
62
58
  /**
63
59
  * 重新计算 configuration.plugins,返回本次新出现的问题(相同问题只报告一次)。
64
60
  */
65
61
  export declare function refreshBuiltinPlugins(): Error[];
66
62
  /**
67
- * 配置SDK,可以在SDK被使用前被调用,该方法被调用后将改变是否debug模式、是否测试环境等基本配置
63
+ * 配置SDK,可以在SDK被使用前被调用,该方法被调用后将改变是否debug模式、是否测试环境等基本配置。
64
+ * debug 为 true 时才输出调试日志;非 debug 只输出调用方无法从返回值或事件感知的失败。
68
65
  * @param param {debug?: boolean; env?: 'dev' | 'test' | 'prod';}
69
66
  */
70
- export declare function configure(param?: BotClientConfig): void;
67
+ export declare function configure(param?: BotClientConfig, options?: {
68
+ refreshBuiltinPlugins?: boolean;
69
+ }): void;
@@ -9,8 +9,11 @@ interface SingleEventListener {
9
9
  once: true;
10
10
  }
11
11
  export default class EventBus {
12
+ private disableLog;
12
13
  private eventListenerMap;
14
+ /** disableLog 只关掉这一条总线;日志本身仍受 debug 模式控制。 */
13
15
  constructor(disableLog?: boolean);
16
+ private trace;
14
17
  getEventListenerMap(): {
15
18
  [key: string]: (SingleEventListener | EventListener)[];
16
19
  };
@@ -1,12 +1,19 @@
1
+ /**
2
+ * SDK 内部日志。
3
+ *
4
+ * log / info / warn / error 只在 debug 模式输出(`configure({ debug: true })`)。
5
+ * 业务失败应通过返回值、异常或事件交给调用方,不依赖控制台。
6
+ *
7
+ * report 在非 debug 下也会输出,只用于异常被吞掉、调用方无法从返回值或事件得知的失败。
8
+ */
1
9
  export default class Logger {
2
10
  private prefix;
3
- private open;
4
11
  static debug: boolean;
5
- constructor(prefix: string, open?: boolean);
6
- disable(): void;
7
- enable(): void;
8
- log(...rest: any[]): void;
9
- info(...rest: any[]): void;
10
- error(...rest: any[]): void;
11
- warn(...rest: any[]): void;
12
+ constructor(prefix: string);
13
+ log(...rest: unknown[]): void;
14
+ info(...rest: unknown[]): void;
15
+ warn(...rest: unknown[]): void;
16
+ error(...rest: unknown[]): void;
17
+ /** 非 debug 也会输出。调用方无法感知的失败才用这个。 */
18
+ report(...rest: unknown[]): void;
12
19
  }
@@ -4,6 +4,7 @@ export declare enum UserMode {
4
4
  }
5
5
  export interface ReadyEventPayload {
6
6
  /**
7
+ * init 与长连接 `update` 换票共用。
7
8
  * 错误码如下:
8
9
  * 200: 成功
9
10
  * 11903: 密钥失效
@@ -13,6 +14,7 @@ export interface ReadyEventPayload {
13
14
  * 11913: 获取应用编排数据失败
14
15
  * 11914: 获取大模型服务失败, 请检查
15
16
  * 11924: 用户无此应用权限
17
+ * `update` 失败时服务端不生效新 token,仍用建连时的 token。
16
18
  */
17
19
  code: number;
18
20
  message: string;
@@ -4,6 +4,7 @@ import { Socket } from 'socket.io-client';
4
4
  import { default as EventBus } from './EventBus';
5
5
  import { ActionPayload, PluginFunctionBasic, Thought } from './PayloadTypes';
6
6
  import { default as BotClient } from './BotClient';
7
+ import { SessionUploadResult } from './sessionUpload';
7
8
  export declare enum NetOpen {
8
9
  enable = 1,
9
10
  disable = 2
@@ -25,7 +26,7 @@ export interface QuestionConfig {
25
26
  oldMessageId?: string;
26
27
  }
27
28
  type ActionPayloadBasic = ActionPayload<PluginFunctionBasic & Thought>;
28
- export type SessionEventName = 'init' | 'ready' | 'activated' | 'inactivated' | 'frozen' | 'data:loading' | 'data:loaded' | 'data:updating' | 'data:updated' | 'data:updated:promptVariables' | 'data:updated:knowledges' | 'data:creating' | 'data:created' | 'data:deleting' | 'data:deleted' | 'socket:connect' | 'socket:disconnect' | 'error' | 'destroy' | 'history:loading' | 'history:loaded' | 'history:moreloading' | 'history:moreloaded' | 'history:add' | 'message:new' | 'message:updated' | 'message:action' | 'message:content' | 'message:reference' | 'message:relatedQuesion:loading' | 'message:relatedQuesion:loaded' | 'message:comment' | 'message:error' | 'answer:finish';
29
+ export type SessionEventName = 'init' | 'ready' | 'activated' | 'inactivated' | 'frozen' | 'data:loading' | 'data:loaded' | 'data:updating' | 'data:updated' | 'data:updated:promptVariables' | 'data:updated:knowledges' | 'data:creating' | 'data:created' | 'data:deleting' | 'data:deleted' | 'socket:connect' | 'socket:disconnect' | 'error' | 'destroy' | 'history:loading' | 'history:loaded' | 'history:moreloading' | 'history:moreloaded' | 'history:add' | 'message:new' | 'message:updated' | 'message:action' | 'message:content' | 'message:remove' | 'message:reference' | 'message:relatedQuesion:loading' | 'message:relatedQuesion:loaded' | 'message:comment' | 'message:error' | 'answer:finish';
29
30
  export declare enum SessionErrors {
30
31
  DataRequestFailed = "data request error",
31
32
  SocketConnectionFailed = "socket error",
@@ -67,7 +68,9 @@ export default abstract class Session {
67
68
  cvforceApi: CVForceApi;
68
69
  socket: Socket | null;
69
70
  protected _promptVariables: ISessionPrompt[];
70
- protected active: boolean;
71
+ private _sessionActive;
72
+ /** 是否为当前正在使用的会话。 */
73
+ get active(): boolean;
71
74
  protected activing: boolean;
72
75
  protected _stopAnswer: boolean;
73
76
  private _dataLoading;
@@ -106,6 +109,15 @@ export default abstract class Session {
106
109
  * @returns 如果设置成功,返回最终的网络访问开关状态;若不满足设置条件,则提前返回 undefined
107
110
  */
108
111
  setNetOpen(v: boolean): Promise<boolean | undefined>;
112
+ /**
113
+ * 发请求用的 token。有 BotClient 时跟它同步,便于同 payload 静默换票。
114
+ */
115
+ protected get requestToken(): string;
116
+ /**
117
+ * 同 payload 静默换票时通知长连接。
118
+ * Agent 发 socket `update`;Dialog / 无连接默认空操作(HTTP 已现读 requestToken)。
119
+ */
120
+ updateSocketResourceToken(_resourceToken: string): void;
109
121
  private getService;
110
122
  addEventListener(eventName: SessionEventName, callback: any, once?: boolean): void;
111
123
  removeEventListener(eventName: SessionEventName, callback: any): void;
@@ -176,6 +188,11 @@ export default abstract class Session {
176
188
  abstract listMcpServers(): Promise<MCPConfig>;
177
189
  get dataLoaded(): boolean;
178
190
  get messagesLoading(): boolean;
191
+ /**
192
+ * 把文件上传到当前会话的对象存储,返回可访问的地址。
193
+ * 图片地址放进 send 的 imageContent。
194
+ */
195
+ upload(file: File): Promise<SessionUploadResult>;
179
196
  send(params: {
180
197
  text?: string;
181
198
  files?: any[];
@@ -1,4 +1,4 @@
1
1
  import { AIShopApi, CVForceApi } from '@glodon-aiot/apis';
2
- export declare function getCVForceService(apiBase: string, token: string, errorHandler: (status: number, message: string) => void): CVForceApi;
2
+ export declare function getCVForceService(apiBase: string, getToken: () => string, errorHandler: (status: number, message: string) => void): CVForceApi;
3
3
  /** 平台文件上传与查询,base 为 `${apiRoot}/aishop`。 */
4
- export declare function getAIShopService(apiBase: string, token: string, errorHandler: (status: number, message: string) => void): AIShopApi;
4
+ export declare function getAIShopService(apiBase: string, getToken: () => 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,35 @@
1
+ /** 在工作区里执行命令。由端侧宿主沙箱、浏览器运行时或测试注入实现。 */
2
+ export interface CommandRequest {
3
+ /** shell 命令。与 argv 二选一。 */
4
+ command?: string;
5
+ /** 直接执行的程序和参数,不经过 shell。 */
6
+ argv?: string[];
7
+ /** 工作区相对目录。`.` 表示工作区根。 */
8
+ cwd: string;
9
+ timeoutMs?: number;
10
+ signal?: AbortSignal;
11
+ /** 命令还在跑时收到的一块 stdout 或 stderr。 */
12
+ onOutput?: (stream: 'stdout' | 'stderr', text: string) => void;
13
+ /** 只在 run_skill_script 中设置。沙箱据此只读挂载该版本目录。 */
14
+ skill?: {
15
+ applicationId: string;
16
+ skillId: string;
17
+ version: number;
18
+ name: string;
19
+ };
20
+ }
21
+ export interface CommandResult {
22
+ exitCode: number;
23
+ stdout: string;
24
+ stderr: string;
25
+ /** 命令结束后的工作区相对目录。shell 用来保留上次停留的目录。 */
26
+ cwd?: string;
27
+ }
28
+ export interface CommandRunner {
29
+ exec(request: CommandRequest): Promise<CommandResult>;
30
+ }
31
+ /** stdout、stderr 各自返回给模型的字符上限。 */
32
+ export declare const MAX_COMMAND_OUTPUT_CHARS = 16000;
33
+ export declare const OUTPUT_TRUNCATED_NOTE = "\n\u2026\u8F93\u51FA\u5DF2\u622A\u65AD";
34
+ export declare function limitOutput(text: string): string;
35
+ export declare function withOutputLimit(runner: CommandRunner): CommandRunner;
@@ -0,0 +1,25 @@
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", "list_skill_files", "grep_skill", "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
+ /** 脚本后缀到解释器。Node 的 .js / .mjs / .cjs 都交给 node。 */
18
+ export declare const SCRIPT_PROGRAMS: {
19
+ readonly '.py': "python3";
20
+ readonly '.sh': "sh";
21
+ readonly '.bash': "sh";
22
+ readonly '.js': "node";
23
+ readonly '.mjs': "node";
24
+ readonly '.cjs': "node";
25
+ };
@@ -0,0 +1,11 @@
1
+ import { LocalWorkspace } from '../localFiles/workspace/LocalWorkspace';
2
+ import { ClientPluginCallback, ToolContext } from '../localFiles/types';
3
+ import { BuiltinFunctionCode } from './constants';
4
+ export type BuiltinHandler = (params: unknown, callback: ClientPluginCallback, context?: Partial<ToolContext>) => void;
5
+ export type BuiltinPluginTable = Record<string, Record<BuiltinFunctionCode, BuiltinHandler>>;
6
+ export interface CreateBuiltinToolsPluginOptions {
7
+ pluginCode: string;
8
+ workspace: LocalWorkspace;
9
+ }
10
+ /** 组装内置工具插件:`{ [pluginCode]: { shell, read_file, ... } }`。 */
11
+ export declare function createBuiltinToolsPlugin({ pluginCode, workspace, }: CreateBuiltinToolsPluginOptions): BuiltinPluginTable;
@@ -0,0 +1,5 @@
1
+ export declare function isStructuredPath(path: string): boolean;
2
+ export declare function structureOverview(path: string, text: string): string;
3
+ export declare function extensionOf(path: string): string;
4
+ export declare function isImagePath(path: string): boolean;
5
+ export declare function isPdf(path: string, bytes?: Uint8Array): boolean;
@@ -0,0 +1,16 @@
1
+ export declare const SYNTHETIC_DIRS: readonly ["input", "output", "uploads", "tmp"];
2
+ export declare const SYNTHETIC_DIR_MESSAGE = "\u4E0D\u8981\u4F7F\u7528 input\u3001output\u3001uploads\u3001tmp\uFF0C\u4E5F\u4E0D\u8981\u65B0\u5EFA\u8FD9\u4E9B\u76EE\u5F55\u3002\u8BF7\u628A\u6587\u4EF6\u76F4\u63A5\u653E\u5728\u5DE5\u4F5C\u533A\u5DF2\u6709\u4F4D\u7F6E\u6216\u6839\u76EE\u5F55\u3002";
3
+ export declare function mentionsSkillDir(text: string): boolean;
4
+ export declare function mentionsSyntheticDir(text: string): boolean;
5
+ export declare function isSyntheticCwd(cwd: string): boolean;
6
+ /**
7
+ * 把工作区路径转成相对工作区根的路径。
8
+ * `/说明.md` 与 `说明.md`、`notes/a.md` 都相对工作区根。拒绝盘符、反斜杠和 `..`。
9
+ */
10
+ export declare function resolveWorkspacePath(input: string): string;
11
+ export declare function resolveFilePath(input: string): string;
12
+ export declare function resolveRunPath(input: string): string;
13
+ export declare function toVirtualPath(relative: string): string;
14
+ /** shell 回传的目录必须仍在工作区内。`.` 表示工作区根。 */
15
+ export declare function isSafeCwd(cwd: string): boolean;
16
+ export declare function skillRelative(skillName: string, relativeName: string): string;
@@ -0,0 +1,92 @@
1
+ export interface ArrangeSkillInput {
2
+ skillId?: string;
3
+ name?: string;
4
+ displayName?: string;
5
+ description?: string;
6
+ version?: number;
7
+ }
8
+ export interface SkillRecord {
9
+ skillId: string;
10
+ name: string;
11
+ version: number;
12
+ }
13
+ export interface SkillSandbox {
14
+ ready: boolean;
15
+ unavailableMessage(): string;
16
+ skillStatus(applicationId: string, signal?: AbortSignal): Promise<unknown>;
17
+ skillRead(applicationId: string, skillId: string, version: number, path: string, signal?: AbortSignal): Promise<Uint8Array>;
18
+ skillList(applicationId: string, skillId: string, version: number, path: string, signal?: AbortSignal): Promise<string>;
19
+ skillGrep(applicationId: string, skillId: string, version: number, path: string, pattern: string, signal?: AbortSignal): Promise<string>;
20
+ installSkill(fields: {
21
+ applicationId: string;
22
+ skillId: string;
23
+ version: number;
24
+ name: string;
25
+ }, bytes: Uint8Array, signal?: AbortSignal): Promise<void>;
26
+ skillPrune(applicationId: string, keep: Array<{
27
+ skillId: string;
28
+ version: number;
29
+ }>, busy: Array<{
30
+ skillId: string;
31
+ version: number;
32
+ }>, signal?: AbortSignal): Promise<void>;
33
+ }
34
+ /** 缺省、空数组和非数组都当成没有技能。 */
35
+ export declare function listedSkills(arrange?: {
36
+ skills?: ArrangeSkillInput[];
37
+ } | null): ArrangeSkillInput[];
38
+ /** 只替换 skills。响应里没有 arrange[0] 时保持原名单。 */
39
+ export declare function assignArrangeSkills(current: {
40
+ skills?: ArrangeSkillInput[];
41
+ }, latest: {
42
+ skills?: ArrangeSkillInput[];
43
+ } | undefined): void;
44
+ /**
45
+ * 进入会话前重新读取编排技能。调用方在返回后再 sync,这样对账用的是新名单。
46
+ * stillCurrent 为假时丢弃这次响应,避免慢请求盖住后一次进入会话的结果。
47
+ */
48
+ export declare function pullArrangeSkills(input: {
49
+ arrange: {
50
+ skills?: ArrangeSkillInput[];
51
+ } | undefined;
52
+ fetchApplication: () => Promise<{
53
+ arrange?: Array<{
54
+ skills?: ArrangeSkillInput[];
55
+ } | undefined>;
56
+ } | null | undefined>;
57
+ stillCurrent?: () => boolean;
58
+ }): Promise<void>;
59
+ export declare class PlatformSkillSync {
60
+ private readonly options;
61
+ private readonly inflight;
62
+ private readonly busy;
63
+ constructor(options: {
64
+ applicationId: () => string;
65
+ getToken: () => string;
66
+ getSkills: () => ArrangeSkillInput[];
67
+ apiRoot: () => string;
68
+ getSandbox: () => SkillSandbox | undefined;
69
+ fetch?: typeof fetch;
70
+ });
71
+ /** 进入会话时调用。不阻塞历史,也不改沙箱就绪。 */
72
+ sync(): Promise<void>;
73
+ read(name: string, relative: string, signal?: AbortSignal): Promise<Uint8Array<ArrayBufferLike>>;
74
+ list(name: string, relative: string, signal?: AbortSignal): Promise<string>;
75
+ grep(name: string, pattern: string, relative: string, signal?: AbortSignal): Promise<string>;
76
+ target(name: string, signal?: AbortSignal): Promise<{
77
+ applicationId: string;
78
+ skillId: string;
79
+ version: number;
80
+ name: string;
81
+ }>;
82
+ track(skillId: string, version: number): () => void;
83
+ private requireSandbox;
84
+ private prepare;
85
+ private bound;
86
+ private reconcile;
87
+ private ensure;
88
+ private installIfNeeded;
89
+ private alreadyInstalled;
90
+ private prune;
91
+ private waitReady;
92
+ }
@@ -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>;