@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.
- package/README.md +246 -225
- package/dist/es/AgentSession.mjs +275 -197
- package/dist/es/BotClient.mjs +200 -123
- package/dist/es/Config.mjs +58 -68
- package/dist/es/DialogSession.mjs +123 -118
- package/dist/es/EventBus.mjs +38 -34
- package/dist/es/Logger.mjs +19 -21
- package/dist/es/Session.mjs +338 -284
- package/dist/es/api/index.mjs +31 -30
- package/dist/es/builtinTools/constants.mjs +12 -5
- package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +182 -160
- package/dist/es/builtinTools/paths.mjs +34 -27
- package/dist/es/builtinTools/platformSkills.mjs +248 -0
- package/dist/es/builtinTools/schemas.mjs +63 -18
- package/dist/es/builtinTools/tools.mjs +368 -244
- package/dist/es/index.mjs +62 -61
- package/dist/es/localFiles/adapters/FileSnapshotAdapter.mjs +160 -0
- package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +113 -131
- package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +60 -55
- package/dist/es/localFiles/constants.mjs +24 -28
- package/dist/es/localFiles/createLocalFilesPlugin.mjs +53 -52
- package/dist/es/localFiles/errors.mjs +44 -35
- package/dist/es/localFiles/host/connectHostBridge.mjs +20 -15
- package/dist/es/localFiles/host/protocol.mjs +27 -14
- package/dist/es/localFiles/host/sandboxClient.mjs +297 -127
- package/dist/es/localFiles/preview.mjs +33 -0
- package/dist/es/localFiles/schemas.mjs +22 -53
- package/dist/es/localFiles/workspace/LocalWorkspace.mjs +156 -89
- package/dist/es/localFiles/workspace/WorkspaceFiles.mjs +246 -0
- package/dist/es/localMcp/client.mjs +234 -0
- package/dist/es/localMcp/endpoints.mjs +94 -0
- package/dist/es/localMcp/register.mjs +207 -0
- package/dist/es/localMcp/registry.mjs +43 -0
- package/dist/es/package.json.mjs +29 -49
- package/dist/es/sessionUpload.mjs +49 -0
- package/dist/es/utils.mjs +24 -11
- package/dist/lib/index.js +48 -40
- package/dist/src/AgentSession.d.ts +13 -0
- package/dist/src/BotClient.d.ts +13 -1
- package/dist/src/Config.d.ts +14 -7
- package/dist/src/EventBus.d.ts +3 -0
- package/dist/src/Logger.d.ts +15 -8
- package/dist/src/PayloadTypes.d.ts +7 -0
- package/dist/src/Session.d.ts +19 -2
- package/dist/src/api/index.d.ts +2 -2
- package/dist/src/builtinTools/command.d.ts +7 -0
- package/dist/src/builtinTools/constants.d.ts +10 -2
- package/dist/src/builtinTools/paths.d.ts +3 -2
- package/dist/src/builtinTools/platformSkills.d.ts +92 -0
- package/dist/src/builtinTools/tools.d.ts +13 -0
- package/dist/src/constant.d.ts +1 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/localFiles/adapters/FileSnapshotAdapter.d.ts +24 -0
- package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +7 -4
- package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +8 -0
- package/dist/src/localFiles/constants.d.ts +4 -13
- package/dist/src/localFiles/errors.d.ts +1 -1
- package/dist/src/localFiles/host/protocol.d.ts +14 -3
- package/dist/src/localFiles/host/sandboxClient.d.ts +50 -0
- package/dist/src/localFiles/index.d.ts +9 -5
- package/dist/src/localFiles/preview.d.ts +2 -0
- package/dist/src/localFiles/schemas.d.ts +0 -2
- package/dist/src/localFiles/types.d.ts +2 -22
- package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +25 -3
- package/dist/src/localFiles/workspace/WorkspaceFiles.d.ts +63 -0
- package/dist/src/localMcp/client.d.ts +15 -0
- package/dist/src/localMcp/endpoints.d.ts +19 -0
- package/dist/src/localMcp/register.d.ts +34 -0
- package/dist/src/localMcp/registry.d.ts +27 -0
- package/dist/src/sessionUpload.d.ts +14 -0
- package/dist/src/utils.d.ts +6 -0
- package/package.json +4 -24
|
@@ -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;
|
package/dist/src/BotClient.d.ts
CHANGED
|
@@ -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
|
}
|
package/dist/src/Config.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BuiltinPluginsConfig, LocalFilesConfig
|
|
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,6 +19,13 @@ export interface BotClientConfig {
|
|
|
19
19
|
loadRelatedQuesions?: boolean;
|
|
20
20
|
mcp?: MCPConfig;
|
|
21
21
|
stream?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* 应用编排版本。Agent 建连时写入 WebSocket query 的 `appVersion`。
|
|
24
|
+
* `draft`:草稿;`v1` / `v2` / `vx`:指定版本,大小写不敏感;`latest`:始终最新。
|
|
25
|
+
* 不传或空白时 SDK 默认传 `latest`。其他值原样传递,由服务端改用最新版本。
|
|
26
|
+
* ready 带回的版本与请求不一致时,SDK 输出告警,连接仍然成功。
|
|
27
|
+
*/
|
|
28
|
+
appVersion?: string;
|
|
22
29
|
/** SDK 内置插件。文件、命令和技能工具注册到同一个 pluginCode。 */
|
|
23
30
|
builtinPlugins?: BuiltinPluginsConfig;
|
|
24
31
|
}
|
|
@@ -48,23 +55,23 @@ export declare let configuration: {
|
|
|
48
55
|
mcp: (MCPConfig | undefined);
|
|
49
56
|
loadRelatedQuesions: boolean;
|
|
50
57
|
stream: boolean;
|
|
58
|
+
appVersion: string;
|
|
51
59
|
};
|
|
52
60
|
export declare function setActiveLocalWorkspace(workspace?: LocalWorkspace): void;
|
|
53
61
|
export declare function getActiveLocalWorkspace(): LocalWorkspace | undefined;
|
|
54
62
|
/** 当前已注册到 configuration.plugins 的内置文件工具编码;未注册时返回 undefined。 */
|
|
55
63
|
export declare function getRegisteredLocalFilesPluginCode(): string | undefined;
|
|
56
|
-
/** 当前已注册到 configuration.plugins 的脚本工具所在插件编码;未注册时返回 undefined。 */
|
|
57
|
-
export declare function getRegisteredLocalPythonPluginCode(): string | undefined;
|
|
58
64
|
/** 显式配置优先,其次按 env 取默认值;都没有时返回 undefined。 */
|
|
59
65
|
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
66
|
/**
|
|
63
67
|
* 重新计算 configuration.plugins,返回本次新出现的问题(相同问题只报告一次)。
|
|
64
68
|
*/
|
|
65
69
|
export declare function refreshBuiltinPlugins(): Error[];
|
|
66
70
|
/**
|
|
67
|
-
* 配置SDK,可以在SDK被使用前被调用,该方法被调用后将改变是否debug
|
|
71
|
+
* 配置SDK,可以在SDK被使用前被调用,该方法被调用后将改变是否debug模式、是否测试环境等基本配置。
|
|
72
|
+
* debug 为 true 时才输出调试日志;非 debug 只输出调用方无法从返回值或事件感知的失败。
|
|
68
73
|
* @param param {debug?: boolean; env?: 'dev' | 'test' | 'prod';}
|
|
69
74
|
*/
|
|
70
|
-
export declare function configure(param?: BotClientConfig
|
|
75
|
+
export declare function configure(param?: BotClientConfig, options?: {
|
|
76
|
+
refreshBuiltinPlugins?: boolean;
|
|
77
|
+
}): void;
|
package/dist/src/EventBus.d.ts
CHANGED
|
@@ -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
|
};
|
package/dist/src/Logger.d.ts
CHANGED
|
@@ -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
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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,10 +14,16 @@ 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;
|
|
19
21
|
userMode: UserMode;
|
|
22
|
+
/**
|
|
23
|
+
* 服务端实际生效的应用编排版本。
|
|
24
|
+
* 请求值无效时服务端改为最新版本,此字段与建连传入的 `appVersion` 不一致。
|
|
25
|
+
*/
|
|
26
|
+
appVersion?: string;
|
|
20
27
|
}
|
|
21
28
|
export interface PluginFunctionBasic {
|
|
22
29
|
pluginName: string;
|
package/dist/src/Session.d.ts
CHANGED
|
@@ -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
|
-
|
|
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[];
|
package/dist/src/api/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { AIShopApi, CVForceApi } from '@glodon-aiot/apis';
|
|
2
|
-
export declare function getCVForceService(apiBase: string,
|
|
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,
|
|
4
|
+
export declare function getAIShopService(apiBase: string, getToken: () => string, errorHandler: (status: number, message: string) => void): AIShopApi;
|
|
@@ -10,6 +10,13 @@ export interface CommandRequest {
|
|
|
10
10
|
signal?: AbortSignal;
|
|
11
11
|
/** 命令还在跑时收到的一块 stdout 或 stderr。 */
|
|
12
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
|
+
};
|
|
13
20
|
}
|
|
14
21
|
export interface CommandResult {
|
|
15
22
|
exitCode: number;
|
|
@@ -1,4 +1,4 @@
|
|
|
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"];
|
|
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
2
|
export type BuiltinFunctionCode = (typeof BUILTIN_FUNCTION_CODES)[number];
|
|
3
3
|
/** 单次 read_file 按原文返回的上限。超出后结构化文本改为概览。 */
|
|
4
4
|
export declare const MAX_READ_BYTES = 81920;
|
|
@@ -14,4 +14,12 @@ export declare const SHELL_CWD = ".";
|
|
|
14
14
|
export declare const WORKSPACE_MOUNT = "/workspace";
|
|
15
15
|
/** 技能目录在工作区根下。 */
|
|
16
16
|
export declare const SKILLS_DIR = "skills";
|
|
17
|
-
|
|
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
|
+
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export declare const SYNTHETIC_DIRS: readonly ["input", "output", "uploads", "tmp"];
|
|
2
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;
|
|
3
4
|
export declare function mentionsSyntheticDir(text: string): boolean;
|
|
4
5
|
export declare function isSyntheticCwd(cwd: string): boolean;
|
|
5
6
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
7
|
+
* 把工作区路径转成相对工作区根的路径。
|
|
8
|
+
* `/说明.md` 与 `说明.md`、`notes/a.md` 都相对工作区根。拒绝盘符、反斜杠和 `..`。
|
|
8
9
|
*/
|
|
9
10
|
export declare function resolveWorkspacePath(input: string): string;
|
|
10
11
|
export declare function resolveFilePath(input: 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
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { WorkspaceFileAdapter } from '../localFiles/adapters/WorkspaceFileAdapter';
|
|
2
2
|
import { CommandRunner } from './command';
|
|
3
|
+
import { PlatformSkillSync } from './platformSkills';
|
|
3
4
|
export interface ToolIO {
|
|
4
5
|
adapter: WorkspaceFileAdapter;
|
|
5
6
|
runner?: CommandRunner;
|
|
@@ -8,6 +9,9 @@ export interface ToolIO {
|
|
|
8
9
|
shellCwd: {
|
|
9
10
|
cwd: string;
|
|
10
11
|
};
|
|
12
|
+
skills?: PlatformSkillSync;
|
|
13
|
+
/** 只接注入的执行器或已就绪的宿主沙箱,不接浏览器运行时。 */
|
|
14
|
+
skillRunner?: CommandRunner;
|
|
11
15
|
}
|
|
12
16
|
interface ToolOutput {
|
|
13
17
|
data: Record<string, unknown>;
|
|
@@ -48,6 +52,15 @@ export declare function shell(input: {
|
|
|
48
52
|
export declare function loadSkill(input: {
|
|
49
53
|
skill_name: string;
|
|
50
54
|
}, io: ToolIO): Promise<ToolOutput>;
|
|
55
|
+
export declare function listSkillFiles(input: {
|
|
56
|
+
skill_name: string;
|
|
57
|
+
path?: string;
|
|
58
|
+
}, io: ToolIO): Promise<ToolOutput>;
|
|
59
|
+
export declare function grepSkill(input: {
|
|
60
|
+
skill_name: string;
|
|
61
|
+
pattern: string;
|
|
62
|
+
path?: string;
|
|
63
|
+
}, io: ToolIO): Promise<ToolOutput>;
|
|
51
64
|
export declare function readSkillResource(input: {
|
|
52
65
|
skill_name: string;
|
|
53
66
|
resource_name: string;
|
package/dist/src/constant.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const SYSTEM_PROMPT_TITLE = "\u89D2\u8272\u8BBE\u5B9A";
|
|
2
|
-
export declare const SYSTEM_PROMPT_PLACEHOLDER = "\u5B9A\u4E49AI\u626E\u6F14\u7684\u89D2\u8272\u4E0E\u56DE\u590D\u903B\u8F91\uFF0C\u793A\u4F8B\uFF1A\n\n# \u89D2\u8272\n\u4F60\u662F\u4E00\u4F4D\u8D44\u6DF1\u7684\u5EFA\u7B51\u9886\u57DF\u77E5\u8BC6\u4E13\u5BB6\uFF0C\u4E13\u4E3A\u5EFA\u7B51\u884C\u4E1A\u4ECE\u4E1A\u8005\u63D0\u4F9B\u4E13\u4E1A\u3001\u51C6\u786E\u7684\u667A\u80FD\u95EE\u7B54\u670D\u52A1\u3002\n\n# \u4EFB\u52A1\n- \u5F53\u7528\u6237\u63D0\u51FA\u5EFA\u7B51\u9886\u57DF\u76F8\u5173\u95EE\u9898\u65F6\uFF0C\u8BF7\u6839\u636E\u4F60\u638C\u63E1\u7684\u77E5\u8BC6\u56DE\u7B54\uFF1B\
|
|
2
|
+
export declare const SYSTEM_PROMPT_PLACEHOLDER = "\u5B9A\u4E49AI\u626E\u6F14\u7684\u89D2\u8272\u4E0E\u56DE\u590D\u903B\u8F91\uFF0C\u793A\u4F8B\uFF1A\n\n# \u89D2\u8272\n\u4F60\u662F\u4E00\u4F4D\u8D44\u6DF1\u7684\u5EFA\u7B51\u9886\u57DF\u77E5\u8BC6\u4E13\u5BB6\uFF0C\u4E13\u4E3A\u5EFA\u7B51\u884C\u4E1A\u4ECE\u4E1A\u8005\u63D0\u4F9B\u4E13\u4E1A\u3001\u51C6\u786E\u7684\u667A\u80FD\u95EE\u7B54\u670D\u52A1\u3002\n\n# \u4EFB\u52A1\n- \u5F53\u7528\u6237\u63D0\u51FA\u5EFA\u7B51\u9886\u57DF\u76F8\u5173\u95EE\u9898\u65F6\uFF0C\u8BF7\u6839\u636E\u4F60\u638C\u63E1\u7684\u77E5\u8BC6\u56DE\u7B54\uFF1B\n- \u5982\u679C\u77E5\u8BC6\u4E0D\u5C5E\u4E8E\u5EFA\u7B51\u884C\u4E1A\u6216\u8D85\u51FA\u4F60\u7684\u77E5\u8BC6\u8303\u56F4\uFF0C\u8BF7\u56DE\u7B54\u201C\u6211\u8FD8\u6CA1\u6709\u5B66\u4F1A\u8FD9\u4E2A\u95EE\u9898\u201D\u3002\n\n# \u9650\u5236\uFF1A\n- \u53EA\u56DE\u7B54\u4E0E\u5EFA\u7B51\u9886\u57DF\u76F8\u5173\u7684\u95EE\u9898\uFF0C\u62D2\u7EDD\u56DE\u7B54\u5176\u4ED6\u4E0D\u76F8\u5173\u8BDD\u9898\uFF1B\n- \u56DE\u7B54\u9700\u7B80\u6D01\u660E\u4E86\uFF0C\u786E\u4FDD\u4E13\u4E1A\u6027\u548C\u51C6\u786E\u6027\u3002";
|
|
3
3
|
export declare const SYSTEM_PROMPT_TOOLTIP: string[];
|
|
4
4
|
export declare const DEFAULT_SYSTEM_VARIABLE: {
|
|
5
5
|
key: string;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export type { AgentPluginRegistor, AgentPluginMap, BotClientConfig, MCPConfig, McpServer } from './Config';
|
|
2
|
-
export { configure, configuration, getRegisteredLocalFilesPluginCode,
|
|
2
|
+
export { configure, configuration, getRegisteredLocalFilesPluginCode, resolveLocalFilesPluginCode, } from './Config';
|
|
3
3
|
export type { ISessionArtifact } from '@glodon-aiot/apis';
|
|
4
4
|
export { default as BotClient } from './BotClient';
|
|
5
5
|
export { default as Session } from './Session';
|
|
6
|
+
export type { SessionUploadResult } from './sessionUpload';
|
|
6
7
|
export { default as AgentPlugin } from './AgentPlugin';
|
|
7
8
|
export * from './localFiles';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource } from './WorkspaceFileAdapter';
|
|
2
|
+
export interface SnapshotFileInput {
|
|
3
|
+
name: string;
|
|
4
|
+
webkitRelativePath?: string;
|
|
5
|
+
lastModified?: number;
|
|
6
|
+
blob: Blob;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* 用一次目录选择拿到的文件列表画出目录树。
|
|
10
|
+
* 浏览器取消或无法返回目录句柄时,仍然能按相对路径列出文件夹结构。
|
|
11
|
+
*/
|
|
12
|
+
export declare class FileSnapshotAdapter implements WorkspaceFileAdapter {
|
|
13
|
+
readonly displayName: string;
|
|
14
|
+
private readonly root;
|
|
15
|
+
constructor(files: Iterable<SnapshotFileInput>, displayName: string);
|
|
16
|
+
private writeNode;
|
|
17
|
+
private resolveDirectory;
|
|
18
|
+
private resolveNode;
|
|
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
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CommandRequest, CommandResult } from '../../builtinTools/command';
|
|
2
2
|
import { SandboxClient, SandboxNotice } from '../host/sandboxClient';
|
|
3
|
-
import { HostCapability,
|
|
3
|
+
import { HostCapability, HostBridge } from '../host/protocol';
|
|
4
4
|
import { WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource } from './WorkspaceFileAdapter';
|
|
5
5
|
/**
|
|
6
6
|
* 工作区原语走沙箱 WebSocket。页面只向宿主发 hello,不转发文件字节和命令输出。
|
|
@@ -11,17 +11,21 @@ export declare class HostBridgeAdapter implements WorkspaceFileAdapter {
|
|
|
11
11
|
sandboxVersion?: string;
|
|
12
12
|
sandboxProtocol?: number;
|
|
13
13
|
readonly sandbox: SandboxClient;
|
|
14
|
-
constructor(view:
|
|
14
|
+
constructor(view: HostBridge, displayName?: string, sandbox?: SandboxClient);
|
|
15
15
|
setCapabilities(value: unknown, sandbox?: {
|
|
16
16
|
version?: unknown;
|
|
17
17
|
}): void;
|
|
18
18
|
applySandbox(notice?: SandboxNotice): void;
|
|
19
|
-
/** 沙箱已就绪且协议为
|
|
19
|
+
/** 沙箱已就绪且协议为 1 时,命令走直连。 */
|
|
20
20
|
get canExec(): boolean;
|
|
21
21
|
get protocolMismatch(): boolean;
|
|
22
22
|
unavailableMessage(): string;
|
|
23
23
|
stat(path: string): Promise<WorkspaceEntry>;
|
|
24
24
|
listEntries(path: string, signal?: AbortSignal): Promise<WorkspaceEntry[]>;
|
|
25
|
+
url(path: string): Promise<{
|
|
26
|
+
url: string;
|
|
27
|
+
release: () => void;
|
|
28
|
+
}>;
|
|
25
29
|
readFile(path: string, window?: {
|
|
26
30
|
offset?: number;
|
|
27
31
|
maxBytes?: number;
|
|
@@ -32,6 +36,5 @@ export declare class HostBridgeAdapter implements WorkspaceFileAdapter {
|
|
|
32
36
|
}): Promise<void>;
|
|
33
37
|
move(from: string, to: string): Promise<void>;
|
|
34
38
|
exec(request: CommandRequest): Promise<CommandResult>;
|
|
35
|
-
runPython(path: string, args: string[], timeoutMs: number, signal?: AbortSignal): Promise<import('../host/sandboxClient').SandboxExecResult>;
|
|
36
39
|
writeFile(path: string, source: WriteSource, options?: WriteOptions): Promise<void>;
|
|
37
40
|
}
|
|
@@ -19,6 +19,14 @@ export interface WorkspaceFileAdapter {
|
|
|
19
19
|
stat(path: string): Promise<WorkspaceEntry>;
|
|
20
20
|
listEntries(path: string, signal?: AbortSignal): Promise<WorkspaceEntry[]>;
|
|
21
21
|
readFile(path: string): Promise<Blob>;
|
|
22
|
+
/**
|
|
23
|
+
* 给页面标签的地址。实现方不得把文件字节读进页面。
|
|
24
|
+
* `release` 在地址不再使用时调用。
|
|
25
|
+
*/
|
|
26
|
+
url?(path: string): Promise<{
|
|
27
|
+
url: string;
|
|
28
|
+
release: () => void;
|
|
29
|
+
}>;
|
|
22
30
|
/** 全部内容写完才提交;失败或取消时原文件保持不变,新建的文件不会残留。 */
|
|
23
31
|
writeFile(path: string, source: WriteSource, options?: WriteOptions): Promise<void>;
|
|
24
32
|
/** 逐级创建目录,已存在时不报错。路径上有同名文件时抛 TypeMismatchError。 */
|
|
@@ -1,22 +1,11 @@
|
|
|
1
1
|
import { Env } from '../Config';
|
|
2
2
|
export declare const LOCAL_FILES_FUNCTION_CODES: readonly ["list_directory", "read_file", "stat_file", "search_files", "search_text", "apply_patch", "write_file", "upload_file", "download_file"];
|
|
3
3
|
export type LocalFilesFunctionCode = (typeof LOCAL_FILES_FUNCTION_CODES)[number];
|
|
4
|
-
/**
|
|
5
|
-
* 平台上的内置工具插件。本地文件工具和 `run_python` 都在这一个插件里。
|
|
6
|
-
* dev、test、prod、local 使用同一个 pluginCode。
|
|
7
|
-
*/
|
|
8
|
-
/** 平台插件编码。与内置工具 OpenAPI 的 pluginCode 一致。 */
|
|
4
|
+
/** 平台插件编码。与内置工具 OpenAPI 的 pluginCode 一致。dev、test、prod、local 使用同一个 pluginCode。 */
|
|
9
5
|
export declare const BUILTIN_TOOLS_PLUGIN_CODE = "builtin_tools";
|
|
10
6
|
export declare const BUILTIN_TOOLS_PLUGIN_CODES: Record<Env, string>;
|
|
11
|
-
/** 与 `BUILTIN_TOOLS_PLUGIN_CODES`
|
|
7
|
+
/** 与 `BUILTIN_TOOLS_PLUGIN_CODES` 相同。 */
|
|
12
8
|
export declare const LOCAL_FILES_PLUGIN_CODES: Record<Env, string>;
|
|
13
|
-
/** 本地 Python 脚本。与文件工具注册在同一个插件里。 */
|
|
14
|
-
export declare const LOCAL_PYTHON_FUNCTION_CODE = "run_python";
|
|
15
|
-
/** 与 `BUILTIN_TOOLS_PLUGIN_CODES` 相同。未单独配置时跟随文件工具的 pluginCode。 */
|
|
16
|
-
export declare const LOCAL_PYTHON_PLUGIN_CODES: Record<Env, string>;
|
|
17
|
-
export declare const PYTHON_DEFAULT_TIMEOUT_MS = 20000;
|
|
18
|
-
export declare const PYTHON_MAX_TIMEOUT_MS = 120000;
|
|
19
|
-
export declare const PYTHON_MAX_ARGS = 16;
|
|
20
9
|
export declare const WORKSPACE_GRANT_ID = "current-workspace";
|
|
21
10
|
export declare const KiB = 1024;
|
|
22
11
|
export declare const MiB: number;
|
|
@@ -29,6 +18,8 @@ export interface LocalFilesLimits {
|
|
|
29
18
|
maxConcurrentRequests: number;
|
|
30
19
|
maxTransferBytes: number;
|
|
31
20
|
toolTimeoutMs: number;
|
|
21
|
+
/** shell、run_file、run_skill_script。安装依赖和图纸脚本单独放宽,不跟读文件共用。 */
|
|
22
|
+
commandTimeoutMs: number;
|
|
32
23
|
searchTimeoutMs: number;
|
|
33
24
|
transferTimeoutMs: number;
|
|
34
25
|
approvalTimeoutMs: number;
|
|
@@ -29,6 +29,6 @@ export declare function cancelledError(): ToolError;
|
|
|
29
29
|
export declare function throwIfAborted(signal?: AbortSignal): void;
|
|
30
30
|
/**
|
|
31
31
|
* 把任意异常转换为可回传给平台的 ToolError。
|
|
32
|
-
* FSA 抛出的 DOMException
|
|
32
|
+
* FSA 抛出的 DOMException 可能带有系统路径等信息,因此按 name 映射为固定文案。
|
|
33
33
|
*/
|
|
34
34
|
export declare function toToolError(error: unknown): ToolError;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/** 宿主与页面之间的通道名。根目录只由宿主设置,消息里不能带绝对路径。 */
|
|
2
2
|
export declare const HOST_CHANNEL = "glodon-workspace";
|
|
3
|
-
|
|
3
|
+
/** 宿主在页面脚本运行前挂上的消息桥。不对应某一种 WebView 或浏览器内核。 */
|
|
4
|
+
export declare const HOST_BRIDGE_GLOBAL = "__glodonHostBridge";
|
|
5
|
+
/** 页面与宿主之间的双向消息桥。消息正文是普通 JSON。 */
|
|
6
|
+
export interface HostBridge {
|
|
4
7
|
postMessage(message: unknown): void;
|
|
5
8
|
addEventListener(type: 'message', listener: (event: {
|
|
6
9
|
data: unknown;
|
|
@@ -16,7 +19,9 @@ export interface HostWebView {
|
|
|
16
19
|
*/
|
|
17
20
|
export type HostCapability = 'sandbox-exec' | 'fs-mutate';
|
|
18
21
|
/** SDK 直连沙箱使用的协议版本。 */
|
|
19
|
-
export declare const SANDBOX_PROTOCOL =
|
|
22
|
+
export declare const SANDBOX_PROTOCOL = 1;
|
|
23
|
+
/** 与 workspace-sandbox 的 MAX_FILE_BYTES 一致。只用于直连本地沙箱。 */
|
|
24
|
+
export declare const SANDBOX_MAX_FILE_BYTES: number;
|
|
20
25
|
export interface HostSandboxState {
|
|
21
26
|
state?: 'starting' | 'ready' | 'failed' | 'exited';
|
|
22
27
|
url?: string;
|
|
@@ -37,4 +42,10 @@ export interface HostWorkspaceMessage {
|
|
|
37
42
|
sandbox?: HostSandboxState;
|
|
38
43
|
}
|
|
39
44
|
export declare function parseHostMessage(data: unknown): Record<string, unknown> | undefined;
|
|
40
|
-
|
|
45
|
+
/** 挂上当前页面的宿主消息桥。传入空值时移除。 */
|
|
46
|
+
export declare function registerHostBridge(bridge?: HostBridge): void;
|
|
47
|
+
/**
|
|
48
|
+
* 优先使用宿主注册的消息桥。没有注册时,接受已经具备同样三个方法的 `chrome.webview`,
|
|
49
|
+
* 让自带该对象的嵌入环境不必再包一层。
|
|
50
|
+
*/
|
|
51
|
+
export declare function getHostBridge(): HostBridge | undefined;
|