@glodon-aiot/bot-client-sdk 3.26.0-alpha.17 → 3.26.0-alpha.19
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 +58 -30
- package/dist/es/Session.mjs +35 -23
- package/dist/es/index.mjs +50 -46
- package/dist/es/localFiles/host/protocol.mjs +8 -7
- package/dist/es/localFiles/host/sandboxClient.mjs +19 -19
- package/dist/es/localFiles/workspace/LocalWorkspace.mjs +24 -18
- package/dist/es/localFiles/workspace/WorkspaceFiles.mjs +188 -0
- package/dist/es/package.json.mjs +2 -2
- package/dist/es/sessionUpload.mjs +49 -0
- package/dist/lib/index.js +43 -43
- package/dist/src/Session.d.ts +6 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/localFiles/host/protocol.d.ts +2 -0
- package/dist/src/localFiles/index.d.ts +3 -1
- package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +7 -1
- package/dist/src/localFiles/workspace/WorkspaceFiles.d.ts +54 -0
- package/dist/src/sessionUpload.d.ts +14 -0
- package/package.json +2 -2
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
|
|
@@ -176,6 +177,11 @@ export default abstract class Session {
|
|
|
176
177
|
abstract listMcpServers(): Promise<MCPConfig>;
|
|
177
178
|
get dataLoaded(): boolean;
|
|
178
179
|
get messagesLoading(): boolean;
|
|
180
|
+
/**
|
|
181
|
+
* 把文件上传到当前会话的对象存储,返回可访问的地址。
|
|
182
|
+
* 图片地址放进 send 的 imageContent。
|
|
183
|
+
*/
|
|
184
|
+
upload(file: File): Promise<SessionUploadResult>;
|
|
179
185
|
send(params: {
|
|
180
186
|
text?: string;
|
|
181
187
|
files?: any[];
|
package/dist/src/index.d.ts
CHANGED
|
@@ -3,5 +3,6 @@ export { configure, configuration, getRegisteredLocalFilesPluginCode, resolveLoc
|
|
|
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';
|
|
@@ -20,6 +20,8 @@ export interface HostBridge {
|
|
|
20
20
|
export type HostCapability = 'sandbox-exec' | 'fs-mutate';
|
|
21
21
|
/** SDK 直连沙箱使用的协议版本。 */
|
|
22
22
|
export declare const SANDBOX_PROTOCOL = 1;
|
|
23
|
+
/** 与 workspace-sandbox 的 MAX_FILE_BYTES 一致。只用于直连本地沙箱。 */
|
|
24
|
+
export declare const SANDBOX_MAX_FILE_BYTES: number;
|
|
23
25
|
export interface HostSandboxState {
|
|
24
26
|
state?: 'starting' | 'ready' | 'failed' | 'exited';
|
|
25
27
|
url?: string;
|
|
@@ -9,13 +9,15 @@ 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 { WorkspaceFiles, normalizeFilePath } from './workspace/WorkspaceFiles';
|
|
13
|
+
export type { WorkspaceFileInfo, WorkspaceReadOptions, WorkspaceWriteOptions, } from './workspace/WorkspaceFiles';
|
|
12
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
19
|
export type { FsaDirectoryHandle, ShowDirectoryPicker, } from './adapters/fsaTypes';
|
|
18
|
-
export { HOST_BRIDGE_GLOBAL, HOST_CHANNEL, registerHostBridge, } from './host/protocol';
|
|
20
|
+
export { HOST_BRIDGE_GLOBAL, HOST_CHANNEL, SANDBOX_MAX_FILE_BYTES, registerHostBridge, } from './host/protocol';
|
|
19
21
|
export type { HostBridge } from './host/protocol';
|
|
20
22
|
export { createDefaultSessionFileTransfer } from './transfer/SessionFileTransfer';
|
|
21
23
|
export type { ResolvedDownload, SessionFileTransfer, UploadProgress, } from './transfer/SessionFileTransfer';
|
|
@@ -7,6 +7,7 @@ import { SensitiveFilePolicy } from '../security/sensitiveFiles';
|
|
|
7
7
|
import { SessionFileTransfer } from '../transfer/SessionFileTransfer';
|
|
8
8
|
import { ApprovalHandler, LocalFilesConfig, LocalWorkspaceEventMap, LocalWorkspaceEventName, LocalWorkspaceStatus, WorkspaceHandshake } from '../types';
|
|
9
9
|
import { KeyValueStore } from './handleStore';
|
|
10
|
+
import { WorkspaceFiles } from './WorkspaceFiles';
|
|
10
11
|
export interface LocalWorkspaceOptions {
|
|
11
12
|
applicationId: string;
|
|
12
13
|
config?: LocalFilesConfig;
|
|
@@ -39,6 +40,8 @@ export declare class LocalWorkspace {
|
|
|
39
40
|
bashModuleURL?: string;
|
|
40
41
|
pyodideIndexURL?: string;
|
|
41
42
|
};
|
|
43
|
+
/** 接入方的文件操作入口。不要使用 `adapter`。 */
|
|
44
|
+
readonly files: WorkspaceFiles;
|
|
42
45
|
private readonly store;
|
|
43
46
|
private readonly picker?;
|
|
44
47
|
private readonly event;
|
|
@@ -64,7 +67,10 @@ export declare class LocalWorkspace {
|
|
|
64
67
|
get isSupported(): boolean;
|
|
65
68
|
/** 最近一次 restore() 完成前,工具调用会等待它。 */
|
|
66
69
|
get ready(): Promise<void>;
|
|
67
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* @internal 已授权时的磁盘后端,供内置工具使用。
|
|
72
|
+
* 接入方用 `files`:这里的路径必须已规范化,异常里也可能带系统路径。
|
|
73
|
+
*/
|
|
68
74
|
get adapter(): WorkspaceFileAdapter | null;
|
|
69
75
|
private get handleKey();
|
|
70
76
|
private get disclosureKey();
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
/**
|
|
35
|
+
* 接入方使用的工作区文件操作。路径校验、敏感文件拦截和错误文案都在这里完成。
|
|
36
|
+
* 写入、建目录、删除、移动成功后会通知目录树重读。
|
|
37
|
+
*/
|
|
38
|
+
export declare class WorkspaceFiles {
|
|
39
|
+
private readonly host;
|
|
40
|
+
constructor(host: WorkspaceFilesHost);
|
|
41
|
+
stat(path?: string): Promise<WorkspaceFileInfo>;
|
|
42
|
+
list(path?: string, options?: WorkspaceReadOptions): Promise<WorkspaceFileInfo[]>;
|
|
43
|
+
read(path: string): Promise<Blob>;
|
|
44
|
+
readText(path: string): Promise<string>;
|
|
45
|
+
write(path: string, source: WriteSource, options?: WorkspaceWriteOptions): Promise<void>;
|
|
46
|
+
append(path: string, source: string | Uint8Array, options?: WorkspaceReadOptions): Promise<void>;
|
|
47
|
+
mkdir(path: string): Promise<void>;
|
|
48
|
+
remove(path: string, options?: {
|
|
49
|
+
recursive?: boolean;
|
|
50
|
+
}): Promise<void>;
|
|
51
|
+
move(from: string, to: string): Promise<void>;
|
|
52
|
+
private assertAccess;
|
|
53
|
+
private run;
|
|
54
|
+
}
|
|
@@ -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 {};
|
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.19",
|
|
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.19",
|
|
92
92
|
"axios": "0.24.0",
|
|
93
93
|
"buffer": "^6.0.3",
|
|
94
94
|
"dayjs": "^1.11.13",
|