@glodon-aiot/bot-client-sdk 3.26.0-alpha.5 → 3.26.0-alpha.9
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 +20 -37
- package/dist/es/AgentSession.mjs +32 -33
- package/dist/es/DialogSession.mjs +39 -40
- package/dist/es/Session.mjs +71 -63
- package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +136 -128
- package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +102 -178
- package/dist/es/localFiles/host/connectHostBridge.mjs +38 -39
- package/dist/es/localFiles/host/protocol.mjs +1 -1
- package/dist/es/localFiles/host/sandboxClient.mjs +324 -0
- package/dist/es/localFiles/host/sandboxFrames.mjs +21 -0
- package/dist/es/package.json.mjs +2 -2
- package/dist/lib/index.js +43 -42
- package/dist/src/Session.d.ts +4 -0
- package/dist/src/builtinTools/command.d.ts +2 -0
- package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +14 -20
- package/dist/src/localFiles/host/protocol.d.ts +16 -22
- package/dist/src/localFiles/host/sandboxClient.d.ts +62 -0
- package/dist/src/localFiles/host/sandboxFrames.d.ts +9 -0
- package/package.json +2 -2
package/dist/src/Session.d.ts
CHANGED
|
@@ -164,6 +164,10 @@ export default abstract class Session {
|
|
|
164
164
|
delete(): Promise<string | false>;
|
|
165
165
|
activate(): Promise<unknown>;
|
|
166
166
|
inactivate(immediately?: boolean): boolean;
|
|
167
|
+
/**
|
|
168
|
+
* 会话标题摘要开关。应用详情返回布尔值时用该值,字段缺失时默认开启。
|
|
169
|
+
*/
|
|
170
|
+
protected resolveEnableTitleSummary(): boolean;
|
|
167
171
|
abstract prepareConnection(): Promise<boolean>;
|
|
168
172
|
abstract sendQuestion(params: QuestionBody, configs: QuestionConfig): any;
|
|
169
173
|
abstract stopAnswer(): any;
|
|
@@ -1,43 +1,37 @@
|
|
|
1
1
|
import { CommandRequest, CommandResult } from '../../builtinTools/command';
|
|
2
|
+
import { SandboxClient, SandboxNotice } from '../host/sandboxClient';
|
|
3
|
+
import { HostCapability, HostWebView } from '../host/protocol';
|
|
2
4
|
import { WorkspaceEntry, WorkspaceFileAdapter, WriteOptions, WriteSource } from './WorkspaceFileAdapter';
|
|
3
|
-
import { HostCapability, HostResponseMessage, HostWebView } from '../host/protocol';
|
|
4
5
|
/**
|
|
5
|
-
*
|
|
6
|
+
* 工作区原语走沙箱 WebSocket。页面只向宿主发 hello,不转发文件字节和命令输出。
|
|
6
7
|
*/
|
|
7
8
|
export declare class HostBridgeAdapter implements WorkspaceFileAdapter {
|
|
8
|
-
private readonly view;
|
|
9
9
|
displayName: string;
|
|
10
|
-
/** 宿主最近一次 workspace 消息声明的能力。 */
|
|
11
10
|
capabilities: ReadonlySet<HostCapability>;
|
|
12
|
-
/** 宿主随 sandbox-exec 声明的沙箱包版本和协议。 */
|
|
13
11
|
sandboxVersion?: string;
|
|
14
12
|
sandboxProtocol?: number;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
constructor(view: HostWebView, displayName?: string);
|
|
13
|
+
readonly sandbox: SandboxClient;
|
|
14
|
+
constructor(view: HostWebView, displayName?: string, sandbox?: SandboxClient);
|
|
18
15
|
setCapabilities(value: unknown, sandbox?: {
|
|
19
16
|
version?: unknown;
|
|
20
|
-
protocol?: unknown;
|
|
21
17
|
}): void;
|
|
22
|
-
|
|
18
|
+
applySandbox(notice?: SandboxNotice): void;
|
|
19
|
+
/** 沙箱已就绪且协议为 2 时,命令走直连。 */
|
|
23
20
|
get canExec(): boolean;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
private call;
|
|
21
|
+
get protocolMismatch(): boolean;
|
|
22
|
+
unavailableMessage(): string;
|
|
27
23
|
stat(path: string): Promise<WorkspaceEntry>;
|
|
28
24
|
listEntries(path: string, signal?: AbortSignal): Promise<WorkspaceEntry[]>;
|
|
29
|
-
readFile(path: string
|
|
25
|
+
readFile(path: string, window?: {
|
|
26
|
+
offset?: number;
|
|
27
|
+
maxBytes?: number;
|
|
28
|
+
}): Promise<Blob>;
|
|
30
29
|
createDirectory(path: string): Promise<void>;
|
|
31
30
|
remove(path: string, options?: {
|
|
32
31
|
recursive?: boolean;
|
|
33
32
|
}): Promise<void>;
|
|
34
33
|
move(from: string, to: string): Promise<void>;
|
|
35
34
|
exec(request: CommandRequest): Promise<CommandResult>;
|
|
36
|
-
runPython(path: string, args: string[], timeoutMs: number, signal?: AbortSignal): Promise<
|
|
37
|
-
exitCode: number;
|
|
38
|
-
timedOut: boolean;
|
|
39
|
-
stdout: string;
|
|
40
|
-
stderr: string;
|
|
41
|
-
}>;
|
|
35
|
+
runPython(path: string, args: string[], timeoutMs: number, signal?: AbortSignal): Promise<import('../host/sandboxClient').SandboxExecResult>;
|
|
42
36
|
writeFile(path: string, source: WriteSource, options?: WriteOptions): Promise<void>;
|
|
43
37
|
}
|
|
@@ -10,13 +10,23 @@ export interface HostWebView {
|
|
|
10
10
|
}) => void): void;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
* - `sandbox-exec
|
|
15
|
-
* - `fs-mutate
|
|
13
|
+
* 宿主声明的能力。文件和命令不经过宿主转发,能力只用于兼容旧的 workspace 消息。
|
|
14
|
+
* - `sandbox-exec`:宿主会启动沙箱进程。
|
|
15
|
+
* - `fs-mutate`:宿主允许改动工程文件。
|
|
16
16
|
*/
|
|
17
17
|
export type HostCapability = 'sandbox-exec' | 'fs-mutate';
|
|
18
|
-
/** SDK
|
|
19
|
-
export declare const SANDBOX_PROTOCOL =
|
|
18
|
+
/** SDK 直连沙箱使用的协议版本。 */
|
|
19
|
+
export declare const SANDBOX_PROTOCOL = 2;
|
|
20
|
+
export interface HostSandboxState {
|
|
21
|
+
state?: 'starting' | 'ready' | 'failed' | 'exited';
|
|
22
|
+
url?: string;
|
|
23
|
+
token?: string;
|
|
24
|
+
protocol?: number;
|
|
25
|
+
exitCode?: number;
|
|
26
|
+
detail?: string;
|
|
27
|
+
message?: string;
|
|
28
|
+
reason?: string;
|
|
29
|
+
}
|
|
20
30
|
export interface HostWorkspaceMessage {
|
|
21
31
|
channel: string;
|
|
22
32
|
type: 'workspace';
|
|
@@ -24,23 +34,7 @@ export interface HostWorkspaceMessage {
|
|
|
24
34
|
displayName?: string;
|
|
25
35
|
capabilities?: HostCapability[];
|
|
26
36
|
sandboxVersion?: string;
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
export interface HostResponseMessage {
|
|
30
|
-
channel: string;
|
|
31
|
-
id: string;
|
|
32
|
-
ok?: boolean;
|
|
33
|
-
name?: string;
|
|
34
|
-
entries?: unknown;
|
|
35
|
-
entry?: unknown;
|
|
36
|
-
contentBase64?: string;
|
|
37
|
-
exitCode?: number;
|
|
38
|
-
timedOut?: boolean;
|
|
39
|
-
stdout?: string;
|
|
40
|
-
stderr?: string;
|
|
41
|
-
/** shell 结束后的工作区相对目录。 */
|
|
42
|
-
cwd?: string;
|
|
43
|
-
message?: string;
|
|
37
|
+
sandbox?: HostSandboxState;
|
|
44
38
|
}
|
|
45
39
|
export declare function parseHostMessage(data: unknown): Record<string, unknown> | undefined;
|
|
46
40
|
export declare function getHostWebView(): HostWebView | undefined;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export interface SandboxNotice {
|
|
2
|
+
state?: 'starting' | 'ready' | 'failed' | 'exited';
|
|
3
|
+
url?: string;
|
|
4
|
+
token?: string;
|
|
5
|
+
protocol?: number;
|
|
6
|
+
exitCode?: number;
|
|
7
|
+
detail?: string;
|
|
8
|
+
message?: string;
|
|
9
|
+
reason?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface SandboxSocketLike {
|
|
12
|
+
readyState: number;
|
|
13
|
+
binaryType: string;
|
|
14
|
+
onopen: ((event?: unknown) => void) | null;
|
|
15
|
+
onmessage: ((event: {
|
|
16
|
+
data: unknown;
|
|
17
|
+
}) => void) | null;
|
|
18
|
+
onclose: ((event?: unknown) => void) | null;
|
|
19
|
+
onerror: ((event?: unknown) => void) | null;
|
|
20
|
+
send(data: string | Uint8Array): void;
|
|
21
|
+
close(): void;
|
|
22
|
+
}
|
|
23
|
+
export type SandboxOpener = (url: string) => SandboxSocketLike;
|
|
24
|
+
export interface SandboxExecResult {
|
|
25
|
+
exitCode: number;
|
|
26
|
+
timedOut: boolean;
|
|
27
|
+
stdout: string;
|
|
28
|
+
stderr: string;
|
|
29
|
+
cwd?: string;
|
|
30
|
+
}
|
|
31
|
+
/** 页面直连 127.0.0.1 上的沙箱。令牌只出现在认证帧里。 */
|
|
32
|
+
export declare class SandboxClient {
|
|
33
|
+
private readonly openSocket;
|
|
34
|
+
notice?: SandboxNotice;
|
|
35
|
+
private socket?;
|
|
36
|
+
private generation;
|
|
37
|
+
private authed;
|
|
38
|
+
private seq;
|
|
39
|
+
private readonly calls;
|
|
40
|
+
private outgoing;
|
|
41
|
+
constructor(openSocket?: SandboxOpener);
|
|
42
|
+
get ready(): boolean;
|
|
43
|
+
unavailableMessage(): string;
|
|
44
|
+
apply(notice?: SandboxNotice): void;
|
|
45
|
+
stat(path: string): Promise<Record<string, unknown>>;
|
|
46
|
+
list(path: string, signal?: AbortSignal): Promise<Record<string, unknown>>;
|
|
47
|
+
read(path: string, offset?: number, maxBytes?: number, signal?: AbortSignal): Promise<Uint8Array<ArrayBuffer>>;
|
|
48
|
+
write(path: string, bytes: Uint8Array, createDirectories: boolean, signal?: AbortSignal): Promise<void>;
|
|
49
|
+
mkdir(path: string): Promise<void>;
|
|
50
|
+
remove(path: string, recursive: boolean): Promise<void>;
|
|
51
|
+
move(from: string, to: string): Promise<void>;
|
|
52
|
+
exec(fields: Record<string, unknown>, signal?: AbortSignal, onOutput?: (stream: 'stdout' | 'stderr', text: string) => void): Promise<SandboxExecResult>;
|
|
53
|
+
private invoke;
|
|
54
|
+
private begin;
|
|
55
|
+
private next;
|
|
56
|
+
private send;
|
|
57
|
+
private connect;
|
|
58
|
+
private onFrame;
|
|
59
|
+
private push;
|
|
60
|
+
private failAll;
|
|
61
|
+
private stop;
|
|
62
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const MAX_BINARY_PAYLOAD: number;
|
|
2
|
+
export declare function encodeBinaryFrame(id: string, offset: number, eof: boolean, payload: Uint8Array): Uint8Array<ArrayBuffer>;
|
|
3
|
+
export declare function decodeBinaryFrame(data: Uint8Array): {
|
|
4
|
+
id: string;
|
|
5
|
+
offset: number;
|
|
6
|
+
eof: boolean;
|
|
7
|
+
payload: Uint8Array<ArrayBufferLike>;
|
|
8
|
+
};
|
|
9
|
+
export { MAX_BINARY_PAYLOAD };
|
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.9",
|
|
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.9",
|
|
92
92
|
"axios": "0.24.0",
|
|
93
93
|
"buffer": "^6.0.3",
|
|
94
94
|
"dayjs": "^1.11.13",
|