@glodon-aiot/bot-client-sdk 3.26.0-alpha.21 → 3.26.0-alpha.24
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.
- package/dist/es/AgentSession.mjs +148 -129
- package/dist/es/Config.mjs +57 -53
- package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +47 -46
- package/dist/es/builtinTools/schemas.mjs +11 -11
- package/dist/es/localFiles/host/sandboxClient.mjs +237 -181
- package/dist/es/localFiles/workspace/LocalWorkspace.mjs +46 -39
- package/dist/es/localMcp/client.mjs +223 -0
- package/dist/es/localMcp/register.mjs +155 -0
- package/dist/es/localMcp/registry.mjs +39 -0
- package/dist/es/package.json.mjs +2 -2
- package/dist/lib/index.js +48 -43
- package/dist/src/AgentSession.d.ts +2 -0
- package/dist/src/localFiles/host/sandboxClient.d.ts +23 -0
- package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +5 -2
- package/dist/src/localMcp/client.d.ts +11 -0
- package/dist/src/localMcp/register.d.ts +32 -0
- package/dist/src/localMcp/registry.d.ts +26 -0
- package/package.json +2 -2
|
@@ -4,9 +4,11 @@ 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;
|
|
7
8
|
constructor(token: string, _id?: string, _data?: Partial<ISession>, lazyload?: boolean, application?: IApplication, client?: BotClient);
|
|
8
9
|
prepareConnection(): Promise<boolean>;
|
|
9
10
|
registerMcpFromClientConfig(): Promise<boolean>;
|
|
11
|
+
private registerLocalMcp;
|
|
10
12
|
addMcpServers(mcpServers: MCPConfig): Promise<boolean>;
|
|
11
13
|
listMcpServers(): Promise<MCPConfig>;
|
|
12
14
|
sendQuestion(questionBody: QuestionBody, configs: QuestionConfig): Promise<false | undefined>;
|
|
@@ -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;
|
|
@@ -51,7 +51,7 @@ export declare class LocalWorkspace {
|
|
|
51
51
|
private pendingHandle;
|
|
52
52
|
private approvalHandler?;
|
|
53
53
|
private activeCalls;
|
|
54
|
-
private
|
|
54
|
+
private activeCommands;
|
|
55
55
|
private readonly inflight;
|
|
56
56
|
private _ready;
|
|
57
57
|
private stopWatching;
|
|
@@ -113,7 +113,10 @@ export declare class LocalWorkspace {
|
|
|
113
113
|
getApprovalHandler(): ApprovalHandler | undefined;
|
|
114
114
|
/** @internal 占用一个并发名额;已满时返回 null。 */
|
|
115
115
|
acquireSlot(): (() => void) | null;
|
|
116
|
-
/**
|
|
116
|
+
/**
|
|
117
|
+
* 占用一个浏览器运行时的命令名额。本地沙箱在时页面不设上限,并发由沙箱的 exec.maxConcurrent 决定。
|
|
118
|
+
* 浏览器运行时一次只放一条。
|
|
119
|
+
*/
|
|
117
120
|
acquireCommand(): (() => void) | null;
|
|
118
121
|
/** @internal 登记进行中的调用,更换或断开工作区时统一中止。 */
|
|
119
122
|
track(controller: AbortController): () => boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
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;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { MCPConfig } from '../Config';
|
|
2
|
+
export interface ArrangeLocalMcp {
|
|
3
|
+
id?: string;
|
|
4
|
+
runtime?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface McpServerDetail {
|
|
7
|
+
code: string;
|
|
8
|
+
deployType?: string;
|
|
9
|
+
url?: string;
|
|
10
|
+
headers: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
interface SocketLike {
|
|
13
|
+
emit(event: string, data: unknown, ack?: (response: unknown) => void): void;
|
|
14
|
+
}
|
|
15
|
+
export declare function listedLocalMcps(arrange?: {
|
|
16
|
+
mcps?: ArrangeLocalMcp[];
|
|
17
|
+
} | null): ArrangeLocalMcp[];
|
|
18
|
+
export declare function detailMatchesInit(keys: string[] | null, id: string, code: string): boolean;
|
|
19
|
+
export declare function parseMcpDetail(body: unknown): McpServerDetail | null;
|
|
20
|
+
export declare function fetchMcpDetail(apiRoot: string, token: string, id: string, fetchImpl?: typeof fetch): Promise<McpServerDetail>;
|
|
21
|
+
export declare function registerLocalMcp(input: {
|
|
22
|
+
arrange?: {
|
|
23
|
+
mcps?: ArrangeLocalMcp[];
|
|
24
|
+
} | null;
|
|
25
|
+
initMcp?: MCPConfig | null;
|
|
26
|
+
apiRoot: string;
|
|
27
|
+
token: string;
|
|
28
|
+
socket?: SocketLike;
|
|
29
|
+
fetchImpl?: typeof fetch;
|
|
30
|
+
isCurrent?: () => boolean;
|
|
31
|
+
}): Promise<void>;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
/** 把本机 MCP 工具合并进插件表。业务插件里同编码的其它函数保留。 */
|
|
24
|
+
export declare function applyLocalMcpPlugins(plugins: AgentPluginMap): void;
|
|
25
|
+
export declare function resetLocalMcpTools(): void;
|
|
26
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glodon-aiot/bot-client-sdk",
|
|
3
|
-
"version": "3.26.0-alpha.
|
|
3
|
+
"version": "3.26.0-alpha.24",
|
|
4
4
|
"author": "glodoncv",
|
|
5
5
|
"description": "aiot bot client js sdk",
|
|
6
6
|
"type": "module",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"registry": "https://registry.npmjs.org/"
|
|
89
89
|
},
|
|
90
90
|
"dependencies": {
|
|
91
|
-
"@glodon-aiot/apis": "^3.26.0-alpha.
|
|
91
|
+
"@glodon-aiot/apis": "^3.26.0-alpha.24",
|
|
92
92
|
"axios": "0.24.0",
|
|
93
93
|
"buffer": "^6.0.3",
|
|
94
94
|
"dayjs": "^1.11.13",
|