@glodon-aiot/bot-client-sdk 3.26.0-alpha.9 → 3.27.0-alpha.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 (72) hide show
  1. package/README.md +246 -225
  2. package/dist/es/AgentSession.mjs +275 -197
  3. package/dist/es/BotClient.mjs +200 -123
  4. package/dist/es/Config.mjs +58 -68
  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/constants.mjs +12 -5
  11. package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +182 -160
  12. package/dist/es/builtinTools/paths.mjs +34 -27
  13. package/dist/es/builtinTools/platformSkills.mjs +248 -0
  14. package/dist/es/builtinTools/schemas.mjs +63 -18
  15. package/dist/es/builtinTools/tools.mjs +368 -244
  16. package/dist/es/index.mjs +62 -61
  17. package/dist/es/localFiles/adapters/FileSnapshotAdapter.mjs +160 -0
  18. package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +113 -131
  19. package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +60 -55
  20. package/dist/es/localFiles/constants.mjs +24 -28
  21. package/dist/es/localFiles/createLocalFilesPlugin.mjs +53 -52
  22. package/dist/es/localFiles/errors.mjs +44 -35
  23. package/dist/es/localFiles/host/connectHostBridge.mjs +20 -15
  24. package/dist/es/localFiles/host/protocol.mjs +27 -14
  25. package/dist/es/localFiles/host/sandboxClient.mjs +297 -127
  26. package/dist/es/localFiles/preview.mjs +33 -0
  27. package/dist/es/localFiles/schemas.mjs +22 -53
  28. package/dist/es/localFiles/workspace/LocalWorkspace.mjs +156 -89
  29. package/dist/es/localFiles/workspace/WorkspaceFiles.mjs +246 -0
  30. package/dist/es/localMcp/client.mjs +234 -0
  31. package/dist/es/localMcp/endpoints.mjs +94 -0
  32. package/dist/es/localMcp/register.mjs +207 -0
  33. package/dist/es/localMcp/registry.mjs +43 -0
  34. package/dist/es/package.json.mjs +29 -49
  35. package/dist/es/sessionUpload.mjs +49 -0
  36. package/dist/es/utils.mjs +24 -11
  37. package/dist/lib/index.js +48 -40
  38. package/dist/src/AgentSession.d.ts +13 -0
  39. package/dist/src/BotClient.d.ts +13 -1
  40. package/dist/src/Config.d.ts +14 -7
  41. package/dist/src/EventBus.d.ts +3 -0
  42. package/dist/src/Logger.d.ts +15 -8
  43. package/dist/src/PayloadTypes.d.ts +7 -0
  44. package/dist/src/Session.d.ts +19 -2
  45. package/dist/src/api/index.d.ts +2 -2
  46. package/dist/src/builtinTools/command.d.ts +7 -0
  47. package/dist/src/builtinTools/constants.d.ts +10 -2
  48. package/dist/src/builtinTools/paths.d.ts +3 -2
  49. package/dist/src/builtinTools/platformSkills.d.ts +92 -0
  50. package/dist/src/builtinTools/tools.d.ts +13 -0
  51. package/dist/src/constant.d.ts +1 -1
  52. package/dist/src/index.d.ts +2 -1
  53. package/dist/src/localFiles/adapters/FileSnapshotAdapter.d.ts +24 -0
  54. package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +7 -4
  55. package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +8 -0
  56. package/dist/src/localFiles/constants.d.ts +4 -13
  57. package/dist/src/localFiles/errors.d.ts +1 -1
  58. package/dist/src/localFiles/host/protocol.d.ts +14 -3
  59. package/dist/src/localFiles/host/sandboxClient.d.ts +50 -0
  60. package/dist/src/localFiles/index.d.ts +9 -5
  61. package/dist/src/localFiles/preview.d.ts +2 -0
  62. package/dist/src/localFiles/schemas.d.ts +0 -2
  63. package/dist/src/localFiles/types.d.ts +2 -22
  64. package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +25 -3
  65. package/dist/src/localFiles/workspace/WorkspaceFiles.d.ts +63 -0
  66. package/dist/src/localMcp/client.d.ts +15 -0
  67. package/dist/src/localMcp/endpoints.d.ts +19 -0
  68. package/dist/src/localMcp/register.d.ts +34 -0
  69. package/dist/src/localMcp/registry.d.ts +27 -0
  70. package/dist/src/sessionUpload.d.ts +14 -0
  71. package/dist/src/utils.d.ts +6 -0
  72. package/package.json +4 -24
@@ -27,11 +27,34 @@ export interface SandboxExecResult {
27
27
  stdout: string;
28
28
  stderr: string;
29
29
  cwd?: string;
30
+ /** 宿主网络策略拒绝的 host:port,只在 allowlist 模式下出现。 */
31
+ denied?: string[];
30
32
  }
33
+ /** 宿主给沙箱的网络策略摘要。页面只能读,不能改。 */
34
+ export interface SandboxPolicySummary {
35
+ revision: number;
36
+ network: {
37
+ mode: 'off' | 'allowlist' | 'open';
38
+ allow: string[];
39
+ };
40
+ packages: {
41
+ python: {
42
+ enabled: boolean;
43
+ };
44
+ };
45
+ /** 宿主允许同时运行的命令数。旧沙箱不发这个字段。 */
46
+ exec?: {
47
+ maxConcurrent: number;
48
+ };
49
+ }
50
+ /** 旧沙箱不发策略时按断网处理。 */
51
+ export declare const OFFLINE_POLICY: SandboxPolicySummary;
31
52
  /** 页面直连 127.0.0.1 上的沙箱。令牌只出现在认证帧里。 */
32
53
  export declare class SandboxClient {
33
54
  private readonly openSocket;
34
55
  notice?: SandboxNotice;
56
+ /** 沙箱最近一次告知的网络策略。 */
57
+ policy: SandboxPolicySummary;
35
58
  private socket?;
36
59
  private generation;
37
60
  private authed;
@@ -42,15 +65,42 @@ export declare class SandboxClient {
42
65
  get ready(): boolean;
43
66
  unavailableMessage(): string;
44
67
  apply(notice?: SandboxNotice): void;
68
+ /** `ws://127.0.0.1:port` 的主机和端口,文件地址拼在它前面。 */
69
+ httpOrigin(): string;
45
70
  stat(path: string): Promise<Record<string, unknown>>;
71
+ url(path: string): Promise<string>;
72
+ releaseUrl(ticket: string): Promise<void>;
46
73
  list(path: string, signal?: AbortSignal): Promise<Record<string, unknown>>;
47
74
  read(path: string, offset?: number, maxBytes?: number, signal?: AbortSignal): Promise<Uint8Array<ArrayBuffer>>;
48
75
  write(path: string, bytes: Uint8Array, createDirectories: boolean, signal?: AbortSignal): Promise<void>;
76
+ skillStatus(applicationId: string, signal?: AbortSignal): Promise<any[]>;
77
+ skillRead(applicationId: string, skillId: string, version: number, path: string, signal?: AbortSignal): Promise<Uint8Array<ArrayBuffer>>;
78
+ skillList(applicationId: string, skillId: string, version: number, path: string, signal?: AbortSignal): Promise<string>;
79
+ skillGrep(applicationId: string, skillId: string, version: number, path: string, pattern: string, signal?: AbortSignal): Promise<string>;
80
+ installSkill(fields: {
81
+ applicationId: string;
82
+ skillId: string;
83
+ version: number;
84
+ name: string;
85
+ }, bytes: Uint8Array, signal?: AbortSignal): Promise<void>;
86
+ skillPrune(applicationId: string, keep: Array<{
87
+ skillId: string;
88
+ version: number;
89
+ }>, busy: Array<{
90
+ skillId: string;
91
+ version: number;
92
+ }>, signal?: AbortSignal): Promise<void>;
49
93
  mkdir(path: string): Promise<void>;
50
94
  remove(path: string, recursive: boolean): Promise<void>;
51
95
  move(from: string, to: string): Promise<void>;
52
96
  exec(fields: Record<string, unknown>, signal?: AbortSignal, onOutput?: (stream: 'stdout' | 'stderr', text: string) => void): Promise<SandboxExecResult>;
53
97
  private invoke;
98
+ /**
99
+ * 沙箱轮到这次上传时先回 offset 为 0 的 ack,之后每个 ack 再发下一片。
100
+ * 排队期间不发数据,沙箱不用替排队的请求存分片。
101
+ */
102
+ private upload;
103
+ /** 取消时通知沙箱:命令会被结束,还在排队的文件请求会被移出队列。 */
54
104
  private begin;
55
105
  private next;
56
106
  private send;
@@ -2,21 +2,25 @@ export * from './constants';
2
2
  export * from './types';
3
3
  export { ToolCode, ToolError, toToolError } from './errors';
4
4
  export type { ToolErrorData, ToolErrorReason } from './errors';
5
- export { LOCAL_FILE_TOOL_SCHEMAS, LOCAL_PYTHON_TOOL_SCHEMA } from './schemas';
5
+ export { LOCAL_FILE_TOOL_SCHEMAS } from './schemas';
6
6
  export { BUILTIN_TOOL_SCHEMAS } from '../builtinTools/schemas';
7
- export type { BuiltinToolSchema, JsonSchema, LocalFileToolSchema } from './schemas';
7
+ export type { BuiltinToolSchema, JsonSchema, LocalFileToolSchema, } from './schemas';
8
8
  export { createLocalFilesPlugin } from './createLocalFilesPlugin';
9
9
  export type { CreateLocalFilesPluginOptions, LocalFilesHandler, LocalFilesPluginTable, } from './createLocalFilesPlugin';
10
10
  export { LocalWorkspace } from './workspace/LocalWorkspace';
11
11
  export type { LocalWorkspaceOptions } from './workspace/LocalWorkspace';
12
- export { createIndexedDbStore, createMemoryStore } from './workspace/handleStore';
12
+ export { WorkspaceFiles, normalizeFilePath } from './workspace/WorkspaceFiles';
13
+ export type { WorkspaceFileInfo, WorkspaceReadOptions, WorkspaceWriteOptions, } from './workspace/WorkspaceFiles';
14
+ export { createIndexedDbStore, createMemoryStore, } from './workspace/handleStore';
13
15
  export type { KeyValueStore } from './workspace/handleStore';
14
16
  export type { RemoveOptions, WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource, } from './adapters/WorkspaceFileAdapter';
15
17
  export { FileSystemAccessAdapter } from './adapters/FileSystemAccessAdapter';
16
18
  export { MemoryWorkspaceAdapter } from './adapters/MemoryWorkspaceAdapter';
17
- export type { FsaDirectoryHandle, ShowDirectoryPicker } from './adapters/fsaTypes';
19
+ export type { FsaDirectoryHandle, ShowDirectoryPicker, } from './adapters/fsaTypes';
20
+ export { HOST_BRIDGE_GLOBAL, HOST_CHANNEL, SANDBOX_MAX_FILE_BYTES, registerHostBridge, } from './host/protocol';
21
+ export type { HostBridge } from './host/protocol';
18
22
  export { createDefaultSessionFileTransfer } from './transfer/SessionFileTransfer';
19
23
  export type { ResolvedDownload, SessionFileTransfer, UploadProgress, } from './transfer/SessionFileTransfer';
20
24
  export { getDownloadUrlAllowlist, isDownloadUrlAllowed, } from './security/downloadUrlPolicy';
21
25
  export { SDK_SENSITIVE_BASELINE } from './security/sensitiveFiles';
22
- export type { SensitiveRule, SensitiveRuleInput } from './security/sensitiveFiles';
26
+ export type { SensitiveRule, SensitiveRuleInput, } from './security/sensitiveFiles';
@@ -0,0 +1,2 @@
1
+ export declare const PREVIEW_TYPE_MESSAGE = "\u53EA\u80FD\u9884\u89C8\u56FE\u7247\u3001\u97F3\u89C6\u9891\u548C PDF\u3002";
2
+ export declare function mediaTypeOf(path: string): string | undefined;
@@ -25,5 +25,3 @@ export interface LocalFileToolSchema extends BuiltinToolSchema {
25
25
  }
26
26
  /** 9 个工具的参数 Schema,同时作为平台注册时的草案。 */
27
27
  export declare const LOCAL_FILE_TOOL_SCHEMAS: Record<LocalFilesFunctionCode, LocalFileToolSchema>;
28
- /** run_python 的参数 Schema。与文件工具一起注册到同一个插件。 */
29
- export declare const LOCAL_PYTHON_TOOL_SCHEMA: BuiltinToolSchema;
@@ -63,11 +63,11 @@ export interface LocalFilesConfig {
63
63
  enabled?: boolean;
64
64
  /**
65
65
  * `file-system-access`:网页里由用户选择目录。
66
- * `host-bridge`:目录由宿主通过 `chrome.webview` 设置,页面不弹选择框。
66
+ * `host-bridge`:目录由宿主消息桥推送,页面不弹选择框。
67
67
  */
68
68
  backend?: 'file-system-access' | 'host-bridge';
69
69
  /**
70
- * 平台上的内置工具插件编码。文件工具和 run_python 使用同一个编码。
70
+ * 平台上的内置工具插件编码。
71
71
  * 未配置时按 env 取 BUILTIN_TOOLS_PLUGIN_CODES。
72
72
  */
73
73
  pluginCode?: string;
@@ -96,28 +96,8 @@ export interface CommandRuntimeConfig {
96
96
  pyodideIndexURL?: string;
97
97
  };
98
98
  }
99
- export interface PythonApprovalRequest {
100
- requestId: string;
101
- sessionId: string;
102
- path: string;
103
- args: string[];
104
- workspaceName: string;
105
- signal: AbortSignal;
106
- }
107
- export type PythonApprovalHandler = (request: PythonApprovalRequest) => boolean | Promise<boolean>;
108
- export interface LocalPythonConfig {
109
- enabled?: boolean;
110
- /**
111
- * 平台上的内置工具插件编码,须与文件工具相同。
112
- * 未配置时跟随 localFiles.pluginCode,再按 env 取 BUILTIN_TOOLS_PLUGIN_CODES。
113
- */
114
- pluginCode?: string;
115
- /** 运行脚本前的确认。与文件写入确认分开;未配置时一律拒绝。 */
116
- onApprovalRequired?: PythonApprovalHandler;
117
- }
118
99
  export interface BuiltinPluginsConfig {
119
100
  localFiles?: LocalFilesConfig;
120
- localPython?: LocalPythonConfig;
121
101
  }
122
102
  export interface WorkspaceGrantInput {
123
103
  grantId: string;
@@ -1,4 +1,5 @@
1
1
  import { CommandRunner } from '../../builtinTools/command';
2
+ import { PlatformSkillSync } from '../../builtinTools/platformSkills';
2
3
  import { WorkspaceFileAdapter } from '../adapters/WorkspaceFileAdapter';
3
4
  import { ShowDirectoryPicker } from '../adapters/fsaTypes';
4
5
  import { LocalFilesLimits } from '../constants';
@@ -6,6 +7,7 @@ import { SensitiveFilePolicy } from '../security/sensitiveFiles';
6
7
  import { SessionFileTransfer } from '../transfer/SessionFileTransfer';
7
8
  import { ApprovalHandler, LocalFilesConfig, LocalWorkspaceEventMap, LocalWorkspaceEventName, LocalWorkspaceStatus, WorkspaceHandshake } from '../types';
8
9
  import { KeyValueStore } from './handleStore';
10
+ import { WorkspaceFiles } from './WorkspaceFiles';
9
11
  export interface LocalWorkspaceOptions {
10
12
  applicationId: string;
11
13
  config?: LocalFilesConfig;
@@ -31,11 +33,15 @@ export declare class LocalWorkspace {
31
33
  readonly transfer: SessionFileTransfer;
32
34
  readonly fetch: typeof fetch;
33
35
  commandRunner?: CommandRunner;
36
+ /** 平台技能同步。由 BotClient 在启用本地工作区后挂上。 */
37
+ platformSkills?: PlatformSkillSync;
34
38
  readonly browserRuntime: {
35
39
  enabled: boolean;
36
40
  bashModuleURL?: string;
37
41
  pyodideIndexURL?: string;
38
42
  };
43
+ /** 接入方的文件操作入口。不要使用 `adapter`。 */
44
+ readonly files: WorkspaceFiles;
39
45
  private readonly store;
40
46
  private readonly picker?;
41
47
  private readonly event;
@@ -45,13 +51,15 @@ export declare class LocalWorkspace {
45
51
  private pendingHandle;
46
52
  private approvalHandler?;
47
53
  private activeCalls;
48
- private commandRunning;
54
+ private activeCommands;
49
55
  private readonly inflight;
50
56
  private _ready;
51
57
  private stopWatching;
52
58
  private readonly pendingChangePaths;
53
59
  private changeTimer;
54
60
  private refreshAllVisible;
61
+ /** 选择、关闭会推进它。进行中的 restore 若发现已经变了,就不再覆盖当前目录。 */
62
+ private epoch;
55
63
  constructor(options: LocalWorkspaceOptions);
56
64
  get status(): LocalWorkspaceStatus;
57
65
  /** 当前(或待恢复的)文件夹名,不含绝对路径。 */
@@ -59,11 +67,15 @@ export declare class LocalWorkspace {
59
67
  get isSupported(): boolean;
60
68
  /** 最近一次 restore() 完成前,工具调用会等待它。 */
61
69
  get ready(): Promise<void>;
62
- /** @internal 已授权时可用的 Adapter。 */
70
+ /**
71
+ * @internal 已授权时的磁盘后端,供内置工具使用。
72
+ * 接入方用 `files`:这里的路径必须已规范化,异常里也可能带系统路径。
73
+ */
63
74
  get adapter(): WorkspaceFileAdapter | null;
64
75
  private get handleKey();
65
76
  private get disclosureKey();
66
77
  private setStatus;
78
+ private replaceAdapter;
67
79
  private attachHandle;
68
80
  /**
69
81
  * 弹出目录选择框。必须在用户点击事件中调用。
@@ -73,10 +85,17 @@ export declare class LocalWorkspace {
73
85
  /** 读取上次的目录句柄并检查权限,不弹窗。 */
74
86
  restore(): Promise<void>;
75
87
  private doRestore;
88
+ /** queryPermission 仍可能是 prompt,但选择框留下的句柄其实列得出目录。 */
89
+ private canList;
76
90
  /** 对已保存的目录重新申请权限。必须在用户点击事件中调用。 */
77
91
  requestPermission(): Promise<boolean>;
78
92
  /** 断开工作区并删除持久化句柄。状态立即变为未授权,存储删除在其后完成。 */
79
93
  clear(): Promise<void>;
94
+ /**
95
+ * 用文件列表挂上工作区。路径来自 webkitRelativePath,选完就能列出层级。
96
+ * 写入只留在内存里,不会出现在用户磁盘上。需要落盘时用 pick()。
97
+ */
98
+ attachFileSnapshot(files: Iterable<File>, displayName?: string): void;
80
99
  /** 直接挂载一个 Adapter(测试或自定义后端),视为已授权。 */
81
100
  attachAdapter(adapter: WorkspaceFileAdapter, displayName?: string): void;
82
101
  /**
@@ -94,7 +113,10 @@ export declare class LocalWorkspace {
94
113
  getApprovalHandler(): ApprovalHandler | undefined;
95
114
  /** @internal 占用一个并发名额;已满时返回 null。 */
96
115
  acquireSlot(): (() => void) | null;
97
- /** @internal 同一工作区同一时间只跑一个命令;已有命令在运行时返回 null。 */
116
+ /**
117
+ * 占用一个浏览器运行时的命令名额。本地沙箱在时页面不设上限,并发由沙箱的 exec.maxConcurrent 决定。
118
+ * 浏览器运行时一次只放一条。
119
+ */
98
120
  acquireCommand(): (() => void) | null;
99
121
  /** @internal 登记进行中的调用,更换或断开工作区时统一中止。 */
100
122
  track(controller: AbortController): () => boolean;
@@ -0,0 +1,63 @@
1
+ import { WorkspaceFileAdapter, WriteSource } from '../adapters/WorkspaceFileAdapter';
2
+ import { SensitiveFilePolicy } from '../security/sensitiveFiles';
3
+ /**
4
+ * `files` 能调用的工作区能力。适配器仍由 SDK 持有,不交给接入方。
5
+ */
6
+ export interface WorkspaceFilesHost {
7
+ readonly adapter: WorkspaceFileAdapter | null;
8
+ readonly sensitive: SensitiveFilePolicy;
9
+ notifyFilesChanged(paths?: readonly string[]): void;
10
+ handlePermissionLost(): Promise<void>;
11
+ }
12
+ export interface WorkspaceFileInfo {
13
+ name: string;
14
+ /** 相对工作区根的路径。根目录本身是空字符串。 */
15
+ path: string;
16
+ kind: 'file' | 'directory';
17
+ size?: number;
18
+ lastModified?: number;
19
+ /** 命中敏感文件规则时为 true。列表和 stat 仍返回该条目,读和写会被拒绝。 */
20
+ sensitive: boolean;
21
+ }
22
+ export interface WorkspaceReadOptions {
23
+ signal?: AbortSignal;
24
+ }
25
+ export interface WorkspaceWriteOptions extends WorkspaceReadOptions {
26
+ /** 默认 true:父目录不存在时逐级创建。 */
27
+ createDirectories?: boolean;
28
+ }
29
+ /**
30
+ * 接受工作区相对路径(`notes/a.md`)或以 `/` 开头的工作区路径(`/notes/a.md`)。
31
+ * 根目录在 allowRoot 时返回空字符串。
32
+ */
33
+ export declare function normalizeFilePath(input: unknown, allowRoot: boolean): string;
34
+ export declare class WorkspaceFiles {
35
+ private readonly host;
36
+ private readonly previews;
37
+ private readonly previewByPath;
38
+ constructor(host: WorkspaceFilesHost);
39
+ stat(path?: string): Promise<WorkspaceFileInfo>;
40
+ list(path?: string, options?: WorkspaceReadOptions): Promise<WorkspaceFileInfo[]>;
41
+ /**
42
+ * 给 `<img>`、`<video>`、`<audio>` 的地址。浏览器自己拉字节,调用方拿不到文件内容。
43
+ * 同一路径在大小和修改时间没变时返回同一个地址,并增加引用。用完调用 `releaseUrl`。
44
+ */
45
+ url(path: string): Promise<string>;
46
+ /** 页面不再显示这个地址时调用。引用归零后,blob 地址会撤销,沙箱票据会作废。 */
47
+ releaseUrl(url: string): void;
48
+ /** 工作区断开时释放还没归还的地址。 */
49
+ releaseAllUrls(): void;
50
+ read(path: string): Promise<Blob>;
51
+ readText(path: string): Promise<string>;
52
+ write(path: string, source: WriteSource, options?: WorkspaceWriteOptions): Promise<void>;
53
+ append(path: string, source: string | Uint8Array, options?: WorkspaceReadOptions): Promise<void>;
54
+ mkdir(path: string): Promise<void>;
55
+ remove(path: string, options?: {
56
+ recursive?: boolean;
57
+ }): Promise<void>;
58
+ move(from: string, to: string): Promise<void>;
59
+ private openPreview;
60
+ private dropPreview;
61
+ private assertAccess;
62
+ private run;
63
+ }
@@ -0,0 +1,15 @@
1
+ import { LocalMcpBinding } from './registry';
2
+ export interface McpToolSchema {
3
+ name: string;
4
+ description: string;
5
+ inputSchema: object;
6
+ }
7
+ export declare function parseMcpBody(text: string): Record<string, unknown>;
8
+ export declare function mcpToolText(result: unknown): string;
9
+ export declare function listMcpTools(binding: LocalMcpBinding, fetchImpl?: typeof fetch): Promise<McpToolSchema[]>;
10
+ export declare function callMcpTool(binding: LocalMcpBinding, name: string, args: unknown, signal?: AbortSignal, fetchImpl?: typeof fetch): Promise<string>;
11
+ export declare function resetMcpSessions(): void;
12
+ /** 地址或 Header 已变化的连接不再复用。仍在使用的绑定保留会话。 */
13
+ export declare function retainMcpSessions(bindings: LocalMcpBinding[]): void;
14
+ /** 过期注册创建的会话如果已经不在当前工具表里,就丢掉。 */
15
+ export declare function dropUnusedMcpSession(binding: LocalMcpBinding, live: LocalMcpBinding[]): void;
@@ -0,0 +1,19 @@
1
+ export interface LocalMcpEndpoint {
2
+ id: string;
3
+ code?: string;
4
+ url: string;
5
+ token?: string;
6
+ }
7
+ export interface LocalMcpEndpointState {
8
+ revision?: number;
9
+ servers: LocalMcpEndpoint[];
10
+ }
11
+ export declare function currentLocalMcpEndpoints(): LocalMcpEndpointState;
12
+ export declare function subscribeLocalMcpEndpoints(listener: () => void): () => boolean;
13
+ /** 只接受显式端口的宿主回环 HTTP 地址。 */
14
+ export declare function loopbackMcpUrl(value: string): string | undefined;
15
+ /** 接受更新的完整快照。返回是否替换了当前状态。 */
16
+ export declare function applyLocalMcpSnapshot(message: Record<string, unknown>): boolean;
17
+ /** 监听宿主推送的本地 MCP 地址。没有工程目录授权也可以接收。 */
18
+ export declare function connectLocalMcpBridge(): () => void;
19
+ export declare function resetLocalMcpEndpoints(): void;
@@ -0,0 +1,34 @@
1
+ import { MCPConfig } from '../Config';
2
+ import { LocalMcpEndpoint } from './endpoints';
3
+ export interface ArrangeLocalMcp {
4
+ id?: string;
5
+ runtime?: string;
6
+ }
7
+ export interface McpServerDetail {
8
+ code: string;
9
+ deployType?: string;
10
+ url?: string;
11
+ headers: Record<string, string>;
12
+ }
13
+ interface SocketLike {
14
+ emit(event: string, data: unknown, ack?: (response: unknown) => void): void;
15
+ }
16
+ export declare function listedLocalMcps(arrange?: {
17
+ mcps?: ArrangeLocalMcp[];
18
+ } | null): ArrangeLocalMcp[];
19
+ export declare function detailMatchesInit(keys: string[] | null, id: string, code: string): boolean;
20
+ export declare function parseMcpDetail(body: unknown): McpServerDetail | null;
21
+ export declare function fetchMcpDetail(apiRoot: string, token: string, id: string, fetchImpl?: typeof fetch): Promise<McpServerDetail>;
22
+ export declare function headersForEndpoint(headers: Record<string, string>, endpoint?: LocalMcpEndpoint): Record<string, string>;
23
+ export declare function registerLocalMcp(input: {
24
+ arrange?: {
25
+ mcps?: ArrangeLocalMcp[];
26
+ } | null;
27
+ initMcp?: MCPConfig | null;
28
+ apiRoot: string;
29
+ token: string;
30
+ socket?: SocketLike;
31
+ fetchImpl?: typeof fetch;
32
+ isCurrent?: () => boolean;
33
+ }): Promise<void>;
34
+ export {};
@@ -0,0 +1,27 @@
1
+ import { AgentPluginMap } from '../Config';
2
+ export declare const MCP_PLUGIN_CODE = "MCP";
3
+ export interface LocalMcpBinding {
4
+ code: string;
5
+ url: string;
6
+ headers: Record<string, string>;
7
+ }
8
+ export interface LocalMcpAck {
9
+ code: number;
10
+ message: string;
11
+ data?: string;
12
+ }
13
+ type LocalMcpHandler = (args: unknown, callback: (result: LocalMcpAck) => void, context?: {
14
+ signal?: AbortSignal;
15
+ }) => void;
16
+ export declare function rememberLocalMcpTool(name: string, binding: LocalMcpBinding, handler: LocalMcpHandler): void;
17
+ export declare function replaceLocalMcpTools(tools: {
18
+ name: string;
19
+ binding: LocalMcpBinding;
20
+ handler: LocalMcpHandler;
21
+ }[]): void;
22
+ export declare function localMcpBinding(name: string): LocalMcpBinding | undefined;
23
+ export declare function localMcpBindings(): LocalMcpBinding[];
24
+ /** 把本机 MCP 工具合并进插件表。业务插件里同编码的其它函数保留。 */
25
+ export declare function applyLocalMcpPlugins(plugins: AgentPluginMap): void;
26
+ export declare function resetLocalMcpTools(): void;
27
+ export {};
@@ -0,0 +1,14 @@
1
+ import { CVForceApi } from '@glodon-aiot/apis';
2
+ /** 上传到当前会话对象存储后的结果。url 可放进 send 的 imageContent,或写进问题正文。 */
3
+ export interface SessionUploadResult {
4
+ url: string;
5
+ name: string;
6
+ size: number;
7
+ }
8
+ type UploadApi = Pick<CVForceApi, 'postUploadTicket' | 'uploadMinioFile'>;
9
+ /**
10
+ * 把文件上传到会话的对象存储。图片、表格和其他附件走同一条凭证。
11
+ * 存储名用新的 id,只保留安全的扩展名。
12
+ */
13
+ export declare function uploadSessionFile(api: UploadApi, sessionId: string, file: File): Promise<SessionUploadResult>;
14
+ export {};
@@ -1,5 +1,11 @@
1
1
  export declare const parseJWT: (token: string) => any;
2
2
  export declare const isExpired: (token: string) => boolean;
3
+ /**
4
+ * 两张 resource token 的业务载荷是否相同。
5
+ * 只比 rid、ten、ext、label;exp / iat / sid 等可不同。
6
+ * 缺少的字段按 undefined 比较。
7
+ */
8
+ export declare const sameResourceTokenPayload: (a: string, b: string) => boolean;
3
9
  export declare const removeNewlines: (str: string) => string;
4
10
  export declare const removeLeadingAndTrailingBackslashes: (str: string) => string;
5
11
  export interface RelatedQuestionAppConfig {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glodon-aiot/bot-client-sdk",
3
- "version": "3.26.0-alpha.9",
3
+ "version": "3.27.0-alpha.0",
4
4
  "author": "glodoncv",
5
5
  "description": "aiot bot client js sdk",
6
6
  "type": "module",
@@ -27,21 +27,18 @@
27
27
  "license": "MIT",
28
28
  "scripts": {
29
29
  "watch": "yarn build --watch",
30
- "example": "node ./example/server.js",
31
- "dev": "npm-run-all -p watch example",
32
- "start": "vite",
33
30
  "build": "tsc && vite build --mode prod && yarn build:cdn",
34
31
  "build:npm": "tsc && vite build --mode prod",
35
32
  "build:cdn": "tsc && vite build --mode prod --config ./vite.config.cdn.ts",
36
- "preview": "vite preview",
37
33
  "check": "yarn prettier --check .",
38
34
  "write": "yarn prettier --write .",
39
- "lint": "eslint --ext .tsx,.ts --fix ./example -c .eslintrc.js",
35
+ "lint": "eslint --ext .ts src -c .eslintrc.cjs",
40
36
  "build:just-bash": "node scripts/build-just-bash.mjs",
41
37
  "upload:just-bash": "node scripts/build-just-bash.mjs && node scripts/upload-cdn-libs.cjs just-bash",
42
38
  "build:pyodide": "node scripts/build-pyodide.mjs",
43
39
  "upload:pyodide": "node scripts/build-pyodide.mjs && node scripts/upload-cdn-libs.cjs pyodide",
44
40
  "test": "vitest run",
41
+ "test:e2e": "vitest run -c vitest.e2e.config.ts",
45
42
  "test:watch": "vitest"
46
43
  },
47
44
  "devDependencies": {
@@ -50,34 +47,18 @@
50
47
  "@commitlint/config-conventional": "^17.0.3",
51
48
  "@rollup/plugin-babel": "^6.0.4",
52
49
  "@rollup/plugin-typescript": "^11.1.6",
53
- "@types/express": "^4",
54
- "@types/identity-obj-proxy": "^3",
55
50
  "@typescript-eslint/eslint-plugin": "^5.35.1",
56
51
  "@typescript-eslint/parser": "^5.35.1",
57
- "babel-loader": "^8.3.0",
58
52
  "eslint": "^8.0.1",
59
53
  "eslint-config-prettier": "^8.5.0",
60
- "eslint-config-standard-with-typescript": "^22.0.0",
61
- "eslint-plugin-import": "^2.25.2",
62
- "eslint-plugin-n": "^15.0.0",
63
- "eslint-plugin-promise": "^6.0.0",
64
- "eslint-plugin-react": "^7.31.0",
65
- "eslint-plugin-storybook": "^0.6.10",
66
- "express": "4",
67
- "http-proxy-middleware": "^3.0.0",
68
- "identity-obj-proxy": "^3.0.0",
69
54
  "just-bash": "3.6.0",
70
- "npm-run-all": "^4.1.5",
71
55
  "prettier": "2.7.1",
72
56
  "pyodide": "314.0.7",
73
- "rollup-plugin-visualizer": "^6.0.1",
74
57
  "socket.io": "^4.7.5",
75
- "ts-node": "^10.9.2",
76
58
  "typescript": "*",
77
59
  "vite": "^4.1.1",
78
60
  "vite-plugin-dts": "^4.3.0",
79
61
  "vite-plugin-externalize-deps": "^0.9.0",
80
- "vite-tsconfig-paths": "^5.1.4",
81
62
  "vitest": "^0.34.6"
82
63
  },
83
64
  "lint-staged": {
@@ -88,9 +69,8 @@
88
69
  "registry": "https://registry.npmjs.org/"
89
70
  },
90
71
  "dependencies": {
91
- "@glodon-aiot/apis": "^3.26.0-alpha.9",
72
+ "@glodon-aiot/apis": "^3.27.0-alpha.0",
92
73
  "axios": "0.24.0",
93
- "buffer": "^6.0.3",
94
74
  "dayjs": "^1.11.13",
95
75
  "js-base64": "^3.7.7",
96
76
  "socket.io-client": "^4.7.5",