chatablex-web-sdk 1.0.31 → 1.0.34

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 CHANGED
@@ -34,6 +34,7 @@ Your WebUI runs inside a WebView. Many capabilities — native dialogs, file pic
34
34
  - [sdk.tools](#sdktools)
35
35
  - [sdk.platform](#sdkplatform)
36
36
  - [sdk.auth](#sdkauth)
37
+ - [sdk.cloud](#sdkcloud)
37
38
  - [Events Reference](#events-reference)
38
39
  - [Permissions](#permissions)
39
40
  - [Host Capability Matrix](#host-capability-matrix)
@@ -586,6 +587,65 @@ if (res.status === 401 && (await sdk.auth.refresh())) {
586
587
 
587
588
  ---
588
589
 
590
+ ### `sdk.cloud`
591
+
592
+ Unified cloud storage for **all** WebUI apps — keep user files saved across
593
+ devices without losing them. The SDK handles uploads, downloads, and retries;
594
+ you just call the methods. The `appId` (from `ChatableX.init`) is added
595
+ automatically, and each app's data is isolated so files never get mixed up.
596
+
597
+ > Requires: (1) the user is signed in (`sdk.auth`); (2) a configured cloud
598
+ > storage URL — pass `ChatableX.init({ apiBaseUrl })` (in a hosted environment
599
+ > ChatableX can also provide it automatically). Uploading is a **paid
600
+ > capability**: the user must purchase the corresponding tool before uploading,
601
+ > otherwise the upload is rejected.
602
+
603
+ | Method | Signature | Notes |
604
+ |--------|-----------|-------|
605
+ | `upload` | `(fileKey, data, opts?) => Promise<CloudUploadResult>` | Upload (overwrite). `data` accepts `Blob`/`ArrayBuffer`/`TypedArray`/`string`. |
606
+ | `download` | `(fileKey) => Promise<Blob>` | Download a file's bytes. |
607
+ | `getDownloadUrl` | `(fileKey) => Promise<string>` | Short-lived download URL (e.g. for `<img src>`). |
608
+ | `list` | `(opts?) => Promise<CloudFileInfo[]>` | List this app's files for the user; filter by `prefix`. |
609
+ | `delete` | `(fileKey) => Promise<void>` | Delete a file. |
610
+ | `usage` | `() => Promise<CloudUsage>` | Read the account's storage usage / quota. |
611
+
612
+ ```ts
613
+ const sdk = await ChatableX.init({
614
+ appId: 'math-studio',
615
+ apiBaseUrl: import.meta.env.VITE_CHATABLEX_API_BASE,
616
+ });
617
+
618
+ await sdk.cloud.upload('scenes/abc/scene.json.gz', blob, { contentType: 'application/gzip' });
619
+ const files = await sdk.cloud.list({ prefix: 'scenes/' });
620
+ const bytes = await sdk.cloud.download('scenes/abc/scene.json.gz');
621
+ await sdk.cloud.delete('scenes/abc/scene.json.gz');
622
+ const { usedBytes, quotaBytes } = await sdk.cloud.usage();
623
+ ```
624
+
625
+ **Error handling** (all `instanceof`-checkable, exported from the package root):
626
+
627
+ ```ts
628
+ import {
629
+ CloudAuthRequiredError, // not logged in
630
+ CloudSubscriptionRequiredError, // tool not purchased — prompt the user to buy it
631
+ CloudQuotaExceededError, // over storage quota; has usedBytes / quotaBytes
632
+ CloudError, // other cloud errors; has code
633
+ } from 'chatablex-web-sdk';
634
+ ```
635
+
636
+ **Behavior & guarantees**
637
+
638
+ - **Transparent auth.** Reuses `sdk.auth` internally; an expired session is
639
+ refreshed automatically and the request retried once. When the user is not
640
+ signed in it throws `CloudAuthRequiredError` and sends no request.
641
+ - **Data isolation.** Each user's and each app's data is isolated; apps and
642
+ users can never read each other's files.
643
+ - **Paid capability.** Uploading requires the user to have purchased the
644
+ corresponding tool; catch `CloudSubscriptionRequiredError` to drive a purchase
645
+ prompt.
646
+
647
+ ---
648
+
589
649
  ## Events Reference
590
650
 
591
651
  | Event | Payload | When fired |
@@ -630,6 +690,7 @@ SDK methods are thin RPC wrappers. Some host handlers are fully implemented; oth
630
690
  | `sdk.ui.updateState` | **Production** | Delegates to host |
631
691
  | `sdk.platform.openInBrowser` | **Production** | Auth handoff |
632
692
  | `sdk.auth.*` | **Production** | Hosted: reuses desktop login via `host.getAuthToken` (pre-refresh) |
693
+ | `sdk.cloud.*` | **Production** | Cloud file storage; needs `apiBaseUrl`, uploading requires purchasing the tool |
633
694
  | `sdk.ai.chat` | **Production** | Requires `ai_chat` + delegate |
634
695
  | `sdk.ai.getContext` | **Partial** | Returns minimal context |
635
696
  | `sdk.ai.chatStream` | **Partial** | Returns `{ streaming: true }`; tokens via events |
package/README.zh-CN.md CHANGED
@@ -34,6 +34,7 @@
34
34
  - [sdk.tools](#sdktools)
35
35
  - [sdk.platform](#sdkplatform)
36
36
  - [sdk.auth](#sdkauth)
37
+ - [sdk.cloud](#sdkcloud)
37
38
  - [事件参考](#事件参考)
38
39
  - [权限声明](#权限声明)
39
40
  - [宿主能力矩阵](#宿主能力矩阵)
@@ -585,6 +586,72 @@ if (res.status === 401 && (await sdk.auth.refresh())) {
585
586
 
586
587
  ---
587
588
 
589
+ ### `sdk.cloud`
590
+
591
+ 面向**所有** WebUI 应用的统一云存储,让用户文件跨设备保存、不丢失。上传、下载、
592
+ 重试等细节都由 SDK 处理,你只管调方法。`appId`(来自 `ChatableX.init`)会自动带上,
593
+ 每个应用的数据互相隔离,不会串。
594
+
595
+ > 需要:(1) 用户已登录(`sdk.auth`);(2) 已配置云存储服务地址——在
596
+ > `ChatableX.init({ apiBaseUrl })` 传入(宿主环境下也可由 ChatableX 自动提供)。
597
+ > 上传是**付费能力**:用户需购买对应工具后才能上传,未购买时上传会被拒绝。
598
+
599
+ | 方法 | 签名 | 说明 |
600
+ |------|------|------|
601
+ | `upload` | `(fileKey, data, opts?) => Promise<CloudUploadResult>` | 上传(覆盖写)。`data` 支持 `Blob`/`ArrayBuffer`/`TypedArray`/`string`。 |
602
+ | `download` | `(fileKey) => Promise<Blob>` | 下载文件字节。 |
603
+ | `getDownloadUrl` | `(fileKey) => Promise<string>` | 获取短期有效的下载链接(如喂给 `<img src>`)。 |
604
+ | `list` | `(opts?) => Promise<CloudFileInfo[]>` | 列出当前应用在该用户下的文件,可按 `prefix` 过滤。 |
605
+ | `delete` | `(fileKey) => Promise<void>` | 删除文件。 |
606
+ | `usage` | `() => Promise<CloudUsage>` | 读取账户存储用量/配额。 |
607
+
608
+ ```ts
609
+ const sdk = await ChatableX.init({
610
+ appId: 'math-studio',
611
+ apiBaseUrl: import.meta.env.VITE_CHATABLEX_API_BASE,
612
+ });
613
+
614
+ // 上传(app_id 自动注入,无需手动传)
615
+ await sdk.cloud.upload('scenes/abc/scene.json.gz', blob, { contentType: 'application/gzip' });
616
+
617
+ // 列表 / 下载 / 删除 / 用量
618
+ const files = await sdk.cloud.list({ prefix: 'scenes/' });
619
+ const bytes = await sdk.cloud.download('scenes/abc/scene.json.gz');
620
+ await sdk.cloud.delete('scenes/abc/scene.json.gz');
621
+ const { usedBytes, quotaBytes } = await sdk.cloud.usage();
622
+ ```
623
+
624
+ **错误处理**(均可 `instanceof` 判断,从包根导出):
625
+
626
+ ```ts
627
+ import {
628
+ CloudAuthRequiredError, // 未登录:提示登录 ChatableX
629
+ CloudSubscriptionRequiredError, // 未购买:引导用户购买工具
630
+ CloudQuotaExceededError, // 超出存储配额,含 usedBytes / quotaBytes
631
+ CloudError, // 其他云存储错误,含 code
632
+ } from 'chatablex-web-sdk';
633
+
634
+ try {
635
+ await sdk.cloud.upload('big.bin', buf);
636
+ } catch (e) {
637
+ if (e instanceof CloudSubscriptionRequiredError) {/* 弹出购买引导 */}
638
+ else if (e instanceof CloudQuotaExceededError) {/* 提示清理 / 升级,e.usedBytes/e.quotaBytes */}
639
+ else if (e instanceof CloudAuthRequiredError) {/* 提示登录 */}
640
+ else throw e;
641
+ }
642
+ ```
643
+
644
+ **行为与保证**
645
+
646
+ - **鉴权透明。** 内部复用 `sdk.auth`,登录态过期会自动刷新并重试一次;用户未登录
647
+ 时直接抛 `CloudAuthRequiredError`,不会发出无效请求。
648
+ - **数据隔离。** 每个用户、每个应用的数据互相隔离,应用之间、用户之间都不会读到
649
+ 对方的文件。
650
+ - **付费能力。** 上传需用户已购买对应工具;通过捕获
651
+ `CloudSubscriptionRequiredError` 引导用户购买。
652
+
653
+ ---
654
+
588
655
  ## 事件参考
589
656
 
590
657
  | 事件 | 载荷 | 触发时机 |
@@ -629,6 +696,7 @@ SDK 方法是薄 RPC 封装。部分宿主处理器已完整实现,部分返
629
696
  | `sdk.ui.updateState` | **生产可用** | 委托给宿主 |
630
697
  | `sdk.platform.openInBrowser` | **生产可用** | 鉴权传递 |
631
698
  | `sdk.auth.*` | **生产可用** | 宿主态:经 `host.getAuthToken` 复用桌面登录(下发前刷新) |
699
+ | `sdk.cloud.*` | **生产可用** | 云端文件存储;需配置 `apiBaseUrl`,上传需购买对应工具 |
632
700
  | `sdk.ai.chat` | **生产可用** | 需要 `ai_chat` + delegate |
633
701
  | `sdk.ai.getContext` | **部分实现** | 返回最小上下文 |
634
702
  | `sdk.ai.chatStream` | **部分实现** | 返回 `{ streaming: true }`;token 走事件 |
package/dist/index.d.mts CHANGED
@@ -119,6 +119,16 @@ interface ChatableXInitConfig {
119
119
  debug?: boolean;
120
120
  /** Timeout in ms for the handshake with Flutter (default: 10000) */
121
121
  timeout?: number;
122
+ /**
123
+ * Base URL of the ChatableX cloud API (auth-fc), e.g.
124
+ * `https://chatabl-fc-prod-xxxx.cn-hangzhou.fcapp.run`. Required for
125
+ * `sdk.cloud` to work. When omitted, the SDK best-effort asks the host via
126
+ * the `host.getApiBaseUrl` bridge call; if that is also unavailable, cloud
127
+ * calls reject with a clear error.
128
+ */
129
+ apiBaseUrl?: string;
130
+ /** Agent lock configuration — blocks user input during tool execution. */
131
+ agentLock?: AgentLockConfig;
122
132
  }
123
133
  interface ChatableXAI {
124
134
  chat(message: string, options?: ChatOptions): Promise<ChatResponse>;
@@ -191,6 +201,110 @@ interface ChatableXAuth {
191
201
  /** Force a token refresh via the host. Resolves `true` on success. */
192
202
  refresh(): Promise<boolean>;
193
203
  }
204
+ /** Binary payload accepted by `sdk.cloud.upload`. */
205
+ type CloudUploadData = Blob | ArrayBuffer | ArrayBufferView | string;
206
+ interface CloudUploadOptions {
207
+ /**
208
+ * MIME type to store the object as. Defaults to the `Blob.type` when a Blob
209
+ * is given, otherwise `application/octet-stream`. Must be one allowed by the
210
+ * server's content-type whitelist.
211
+ */
212
+ contentType?: string;
213
+ }
214
+ /** Result of a successful `sdk.cloud.upload`. */
215
+ interface CloudUploadResult {
216
+ /** App-relative key (the same `fileKey` passed to `upload`). */
217
+ fileKey: string;
218
+ /** Fully-qualified OSS object key (`user-data/{user_id}/{app_id}/{fileKey}`). */
219
+ objectKey: string;
220
+ /** Bytes uploaded. */
221
+ size: number;
222
+ /** MIME type the object was stored as. */
223
+ contentType: string;
224
+ }
225
+ /** A single file in the user's cloud storage for this app. */
226
+ interface CloudFileInfo {
227
+ fileKey: string;
228
+ size: number;
229
+ /** ISO-8601 timestamp. */
230
+ lastModified: string;
231
+ }
232
+ interface CloudListOptions {
233
+ /** Restrict the listing to keys under this app-relative prefix. */
234
+ prefix?: string;
235
+ }
236
+ /** The user's storage usage / quota for the whole account. */
237
+ interface CloudUsage {
238
+ usedBytes: number;
239
+ quotaBytes: number;
240
+ fileCount: number;
241
+ /** ISO-8601 timestamp of the last server-side reconciliation, if any. */
242
+ reconciledAt?: string;
243
+ }
244
+ /**
245
+ * Cloud storage for WebUI apps. Backed by auth-fc presigned OSS URLs; the
246
+ * app's `appId` (from `ChatableX.init`) is injected automatically so every key
247
+ * is namespaced to `{user}/{app}` and apps cannot reach into each other's data.
248
+ *
249
+ * Requires an authenticated session (`sdk.auth`) and a configured cloud API
250
+ * base URL (see `ChatableXInitConfig.apiBaseUrl`).
251
+ */
252
+ interface ChatableXCloud {
253
+ /** Upload (overwrite) a file. Resolves once the bytes are stored in OSS. */
254
+ upload(fileKey: string, data: CloudUploadData, options?: CloudUploadOptions): Promise<CloudUploadResult>;
255
+ /** Download a file's bytes as a Blob. */
256
+ download(fileKey: string): Promise<Blob>;
257
+ /** Get a short-lived presigned GET URL (e.g. to feed an `<img src>`). */
258
+ getDownloadUrl(fileKey: string): Promise<string>;
259
+ /** List the current app's files for this user. */
260
+ list(options?: CloudListOptions): Promise<CloudFileInfo[]>;
261
+ /** Delete a file. Resolves even if the object did not exist. */
262
+ delete(fileKey: string): Promise<void>;
263
+ /** Read the account's storage usage / quota. */
264
+ usage(): Promise<CloudUsage>;
265
+ }
266
+ interface AgentLockConfig {
267
+ /** Enable the agent lock feature (default: true). */
268
+ enabled?: boolean;
269
+ /**
270
+ * `"overlay"` — SDK renders a built-in transparent overlay (default).
271
+ * `"events-only"` — SDK only emits lock/unlock events; no overlay injected.
272
+ */
273
+ mode?: 'overlay' | 'events-only';
274
+ /** URL of the logo displayed in the overlay centre. Defaults to built-in Chatablex SVG. */
275
+ logoUrl?: string;
276
+ /** Message shown below the logo (default: "Agent 正在操作,请稍候…"). */
277
+ message?: string;
278
+ /** Show a cancel button on the overlay (default: true). */
279
+ allowCancel?: boolean;
280
+ /** Overlay background opacity, 0–1 (default: 0.3). */
281
+ opacity?: number;
282
+ /** Auto-unlock timeout in ms (default: 30000). 0 disables. */
283
+ timeout?: number;
284
+ /** Delay before actually removing the overlay after unlock, to avoid flicker between consecutive tools (default: 200ms). */
285
+ debounceUnlock?: number;
286
+ }
287
+ type AgentLockEventType = 'lock' | 'unlock' | 'cancel' | 'timeout';
288
+ interface AgentLockEventData {
289
+ requestId?: string;
290
+ timestamp: number;
291
+ }
292
+ type AgentLockEventHandler = (data: AgentLockEventData) => void;
293
+ interface ChatableXAgentLock {
294
+ /** Manually lock user interaction with an optional custom message / timeout. */
295
+ lock(opts?: {
296
+ message?: string;
297
+ timeout?: number;
298
+ }): void;
299
+ /** Manually unlock. Safe to call when already unlocked. */
300
+ unlock(): void;
301
+ /** Whether the overlay is currently active. */
302
+ isLocked(): boolean;
303
+ /** Subscribe to lock lifecycle events. Returns an unsubscribe function. */
304
+ on(event: AgentLockEventType, handler: AgentLockEventHandler): () => void;
305
+ /** Remove a previously registered handler. */
306
+ off(event: AgentLockEventType, handler: AgentLockEventHandler): void;
307
+ }
194
308
  interface ChatableXSDK {
195
309
  ai: ChatableXAI;
196
310
  tools: ChatableXTools;
@@ -200,6 +314,8 @@ interface ChatableXSDK {
200
314
  tool: ChatableXToolModule;
201
315
  platform: ChatableXPlatform;
202
316
  auth: ChatableXAuth;
317
+ cloud: ChatableXCloud;
318
+ agentLock: ChatableXAgentLock;
203
319
  }
204
320
  declare global {
205
321
  interface Window {
@@ -246,6 +362,33 @@ declare class Bridge {
246
362
  destroy(): void;
247
363
  }
248
364
 
365
+ /** Base error for all `sdk.cloud` failures. */
366
+ declare class CloudError extends Error {
367
+ /** Business code from auth-fc (or the HTTP status when none was returned). */
368
+ readonly code: number;
369
+ constructor(message: string, code: number);
370
+ }
371
+ /**
372
+ * Thrown when no authenticated session is available. The app should prompt the
373
+ * user to log in to ChatableX before retrying.
374
+ */
375
+ declare class CloudAuthRequiredError extends CloudError {
376
+ constructor(message?: string);
377
+ }
378
+ /**
379
+ * Thrown when the user lacks the entitlement (purchased tool / membership)
380
+ * required to write to cloud storage. Maps to auth-fc code `40302`.
381
+ */
382
+ declare class CloudSubscriptionRequiredError extends CloudError {
383
+ constructor(message?: string);
384
+ }
385
+ /** Thrown when the upload would exceed the user's storage quota (code `40301`). */
386
+ declare class CloudQuotaExceededError extends CloudError {
387
+ readonly usedBytes: number;
388
+ readonly quotaBytes: number;
389
+ constructor(usedBytes: number, quotaBytes: number, message?: string);
390
+ }
391
+
249
392
  /**
250
393
  * chatablex-web-sdk
251
394
  *
@@ -288,4 +431,4 @@ declare const ChatableX: {
288
431
  version: string;
289
432
  };
290
433
 
291
- export { type AiResponseEventData, type AuthTokenData, Bridge, type ChatOptions, type ChatResponse, ChatableX, type ChatableXAI, type ChatableXAuth, type ChatableXEvents, type ChatableXInitConfig, type ChatableXPlatform, type ChatableXSDK, type ChatableXStorage, type ChatableXToolModule, type ChatableXTools, type ChatableXUI, type CloseEventData, type EventCallbackMap, type EventType, type FilePickerOptions, type Message, type NotificationType, SDK_VERSION, type SessionContext, type StateUpdate, type StreamingContentEventData, type TabConfig, type ToolCall, type ToolExecuteHandler, type ToolExecutionEventData, type ToolInfo, type ToolParameter, type ToolResult, type Unsubscribe, type UserMessageEventData };
434
+ export { type AgentLockConfig, type AgentLockEventData, type AgentLockEventHandler, type AgentLockEventType, type AiResponseEventData, type AuthTokenData, Bridge, type ChatOptions, type ChatResponse, ChatableX, type ChatableXAI, type ChatableXAgentLock, type ChatableXAuth, type ChatableXCloud, type ChatableXEvents, type ChatableXInitConfig, type ChatableXPlatform, type ChatableXSDK, type ChatableXStorage, type ChatableXToolModule, type ChatableXTools, type ChatableXUI, type CloseEventData, CloudAuthRequiredError, CloudError, type CloudFileInfo, type CloudListOptions, CloudQuotaExceededError, CloudSubscriptionRequiredError, type CloudUploadData, type CloudUploadOptions, type CloudUploadResult, type CloudUsage, type EventCallbackMap, type EventType, type FilePickerOptions, type Message, type NotificationType, SDK_VERSION, type SessionContext, type StateUpdate, type StreamingContentEventData, type TabConfig, type ToolCall, type ToolExecuteHandler, type ToolExecutionEventData, type ToolInfo, type ToolParameter, type ToolResult, type Unsubscribe, type UserMessageEventData };
package/dist/index.d.ts CHANGED
@@ -119,6 +119,16 @@ interface ChatableXInitConfig {
119
119
  debug?: boolean;
120
120
  /** Timeout in ms for the handshake with Flutter (default: 10000) */
121
121
  timeout?: number;
122
+ /**
123
+ * Base URL of the ChatableX cloud API (auth-fc), e.g.
124
+ * `https://chatabl-fc-prod-xxxx.cn-hangzhou.fcapp.run`. Required for
125
+ * `sdk.cloud` to work. When omitted, the SDK best-effort asks the host via
126
+ * the `host.getApiBaseUrl` bridge call; if that is also unavailable, cloud
127
+ * calls reject with a clear error.
128
+ */
129
+ apiBaseUrl?: string;
130
+ /** Agent lock configuration — blocks user input during tool execution. */
131
+ agentLock?: AgentLockConfig;
122
132
  }
123
133
  interface ChatableXAI {
124
134
  chat(message: string, options?: ChatOptions): Promise<ChatResponse>;
@@ -191,6 +201,110 @@ interface ChatableXAuth {
191
201
  /** Force a token refresh via the host. Resolves `true` on success. */
192
202
  refresh(): Promise<boolean>;
193
203
  }
204
+ /** Binary payload accepted by `sdk.cloud.upload`. */
205
+ type CloudUploadData = Blob | ArrayBuffer | ArrayBufferView | string;
206
+ interface CloudUploadOptions {
207
+ /**
208
+ * MIME type to store the object as. Defaults to the `Blob.type` when a Blob
209
+ * is given, otherwise `application/octet-stream`. Must be one allowed by the
210
+ * server's content-type whitelist.
211
+ */
212
+ contentType?: string;
213
+ }
214
+ /** Result of a successful `sdk.cloud.upload`. */
215
+ interface CloudUploadResult {
216
+ /** App-relative key (the same `fileKey` passed to `upload`). */
217
+ fileKey: string;
218
+ /** Fully-qualified OSS object key (`user-data/{user_id}/{app_id}/{fileKey}`). */
219
+ objectKey: string;
220
+ /** Bytes uploaded. */
221
+ size: number;
222
+ /** MIME type the object was stored as. */
223
+ contentType: string;
224
+ }
225
+ /** A single file in the user's cloud storage for this app. */
226
+ interface CloudFileInfo {
227
+ fileKey: string;
228
+ size: number;
229
+ /** ISO-8601 timestamp. */
230
+ lastModified: string;
231
+ }
232
+ interface CloudListOptions {
233
+ /** Restrict the listing to keys under this app-relative prefix. */
234
+ prefix?: string;
235
+ }
236
+ /** The user's storage usage / quota for the whole account. */
237
+ interface CloudUsage {
238
+ usedBytes: number;
239
+ quotaBytes: number;
240
+ fileCount: number;
241
+ /** ISO-8601 timestamp of the last server-side reconciliation, if any. */
242
+ reconciledAt?: string;
243
+ }
244
+ /**
245
+ * Cloud storage for WebUI apps. Backed by auth-fc presigned OSS URLs; the
246
+ * app's `appId` (from `ChatableX.init`) is injected automatically so every key
247
+ * is namespaced to `{user}/{app}` and apps cannot reach into each other's data.
248
+ *
249
+ * Requires an authenticated session (`sdk.auth`) and a configured cloud API
250
+ * base URL (see `ChatableXInitConfig.apiBaseUrl`).
251
+ */
252
+ interface ChatableXCloud {
253
+ /** Upload (overwrite) a file. Resolves once the bytes are stored in OSS. */
254
+ upload(fileKey: string, data: CloudUploadData, options?: CloudUploadOptions): Promise<CloudUploadResult>;
255
+ /** Download a file's bytes as a Blob. */
256
+ download(fileKey: string): Promise<Blob>;
257
+ /** Get a short-lived presigned GET URL (e.g. to feed an `<img src>`). */
258
+ getDownloadUrl(fileKey: string): Promise<string>;
259
+ /** List the current app's files for this user. */
260
+ list(options?: CloudListOptions): Promise<CloudFileInfo[]>;
261
+ /** Delete a file. Resolves even if the object did not exist. */
262
+ delete(fileKey: string): Promise<void>;
263
+ /** Read the account's storage usage / quota. */
264
+ usage(): Promise<CloudUsage>;
265
+ }
266
+ interface AgentLockConfig {
267
+ /** Enable the agent lock feature (default: true). */
268
+ enabled?: boolean;
269
+ /**
270
+ * `"overlay"` — SDK renders a built-in transparent overlay (default).
271
+ * `"events-only"` — SDK only emits lock/unlock events; no overlay injected.
272
+ */
273
+ mode?: 'overlay' | 'events-only';
274
+ /** URL of the logo displayed in the overlay centre. Defaults to built-in Chatablex SVG. */
275
+ logoUrl?: string;
276
+ /** Message shown below the logo (default: "Agent 正在操作,请稍候…"). */
277
+ message?: string;
278
+ /** Show a cancel button on the overlay (default: true). */
279
+ allowCancel?: boolean;
280
+ /** Overlay background opacity, 0–1 (default: 0.3). */
281
+ opacity?: number;
282
+ /** Auto-unlock timeout in ms (default: 30000). 0 disables. */
283
+ timeout?: number;
284
+ /** Delay before actually removing the overlay after unlock, to avoid flicker between consecutive tools (default: 200ms). */
285
+ debounceUnlock?: number;
286
+ }
287
+ type AgentLockEventType = 'lock' | 'unlock' | 'cancel' | 'timeout';
288
+ interface AgentLockEventData {
289
+ requestId?: string;
290
+ timestamp: number;
291
+ }
292
+ type AgentLockEventHandler = (data: AgentLockEventData) => void;
293
+ interface ChatableXAgentLock {
294
+ /** Manually lock user interaction with an optional custom message / timeout. */
295
+ lock(opts?: {
296
+ message?: string;
297
+ timeout?: number;
298
+ }): void;
299
+ /** Manually unlock. Safe to call when already unlocked. */
300
+ unlock(): void;
301
+ /** Whether the overlay is currently active. */
302
+ isLocked(): boolean;
303
+ /** Subscribe to lock lifecycle events. Returns an unsubscribe function. */
304
+ on(event: AgentLockEventType, handler: AgentLockEventHandler): () => void;
305
+ /** Remove a previously registered handler. */
306
+ off(event: AgentLockEventType, handler: AgentLockEventHandler): void;
307
+ }
194
308
  interface ChatableXSDK {
195
309
  ai: ChatableXAI;
196
310
  tools: ChatableXTools;
@@ -200,6 +314,8 @@ interface ChatableXSDK {
200
314
  tool: ChatableXToolModule;
201
315
  platform: ChatableXPlatform;
202
316
  auth: ChatableXAuth;
317
+ cloud: ChatableXCloud;
318
+ agentLock: ChatableXAgentLock;
203
319
  }
204
320
  declare global {
205
321
  interface Window {
@@ -246,6 +362,33 @@ declare class Bridge {
246
362
  destroy(): void;
247
363
  }
248
364
 
365
+ /** Base error for all `sdk.cloud` failures. */
366
+ declare class CloudError extends Error {
367
+ /** Business code from auth-fc (or the HTTP status when none was returned). */
368
+ readonly code: number;
369
+ constructor(message: string, code: number);
370
+ }
371
+ /**
372
+ * Thrown when no authenticated session is available. The app should prompt the
373
+ * user to log in to ChatableX before retrying.
374
+ */
375
+ declare class CloudAuthRequiredError extends CloudError {
376
+ constructor(message?: string);
377
+ }
378
+ /**
379
+ * Thrown when the user lacks the entitlement (purchased tool / membership)
380
+ * required to write to cloud storage. Maps to auth-fc code `40302`.
381
+ */
382
+ declare class CloudSubscriptionRequiredError extends CloudError {
383
+ constructor(message?: string);
384
+ }
385
+ /** Thrown when the upload would exceed the user's storage quota (code `40301`). */
386
+ declare class CloudQuotaExceededError extends CloudError {
387
+ readonly usedBytes: number;
388
+ readonly quotaBytes: number;
389
+ constructor(usedBytes: number, quotaBytes: number, message?: string);
390
+ }
391
+
249
392
  /**
250
393
  * chatablex-web-sdk
251
394
  *
@@ -288,4 +431,4 @@ declare const ChatableX: {
288
431
  version: string;
289
432
  };
290
433
 
291
- export { type AiResponseEventData, type AuthTokenData, Bridge, type ChatOptions, type ChatResponse, ChatableX, type ChatableXAI, type ChatableXAuth, type ChatableXEvents, type ChatableXInitConfig, type ChatableXPlatform, type ChatableXSDK, type ChatableXStorage, type ChatableXToolModule, type ChatableXTools, type ChatableXUI, type CloseEventData, type EventCallbackMap, type EventType, type FilePickerOptions, type Message, type NotificationType, SDK_VERSION, type SessionContext, type StateUpdate, type StreamingContentEventData, type TabConfig, type ToolCall, type ToolExecuteHandler, type ToolExecutionEventData, type ToolInfo, type ToolParameter, type ToolResult, type Unsubscribe, type UserMessageEventData };
434
+ export { type AgentLockConfig, type AgentLockEventData, type AgentLockEventHandler, type AgentLockEventType, type AiResponseEventData, type AuthTokenData, Bridge, type ChatOptions, type ChatResponse, ChatableX, type ChatableXAI, type ChatableXAgentLock, type ChatableXAuth, type ChatableXCloud, type ChatableXEvents, type ChatableXInitConfig, type ChatableXPlatform, type ChatableXSDK, type ChatableXStorage, type ChatableXToolModule, type ChatableXTools, type ChatableXUI, type CloseEventData, CloudAuthRequiredError, CloudError, type CloudFileInfo, type CloudListOptions, CloudQuotaExceededError, CloudSubscriptionRequiredError, type CloudUploadData, type CloudUploadOptions, type CloudUploadResult, type CloudUsage, type EventCallbackMap, type EventType, type FilePickerOptions, type Message, type NotificationType, SDK_VERSION, type SessionContext, type StateUpdate, type StreamingContentEventData, type TabConfig, type ToolCall, type ToolExecuteHandler, type ToolExecutionEventData, type ToolInfo, type ToolParameter, type ToolResult, type Unsubscribe, type UserMessageEventData };