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/src/types.ts CHANGED
@@ -161,6 +161,16 @@ export interface ChatableXInitConfig {
161
161
  debug?: boolean;
162
162
  /** Timeout in ms for the handshake with Flutter (default: 10000) */
163
163
  timeout?: number;
164
+ /**
165
+ * Base URL of the ChatableX cloud API (auth-fc), e.g.
166
+ * `https://chatabl-fc-prod-xxxx.cn-hangzhou.fcapp.run`. Required for
167
+ * `sdk.cloud` to work. When omitted, the SDK best-effort asks the host via
168
+ * the `host.getApiBaseUrl` bridge call; if that is also unavailable, cloud
169
+ * calls reject with a clear error.
170
+ */
171
+ apiBaseUrl?: string;
172
+ /** Agent lock configuration — blocks user input during tool execution. */
173
+ agentLock?: AgentLockConfig;
164
174
  }
165
175
 
166
176
  // ---------------------------------------------------------------------------
@@ -251,6 +261,127 @@ export interface ChatableXAuth {
251
261
  refresh(): Promise<boolean>;
252
262
  }
253
263
 
264
+ // ---------------------------------------------------------------------------
265
+ // Cloud Storage
266
+ // ---------------------------------------------------------------------------
267
+
268
+ /** Binary payload accepted by `sdk.cloud.upload`. */
269
+ export type CloudUploadData = Blob | ArrayBuffer | ArrayBufferView | string;
270
+
271
+ export interface CloudUploadOptions {
272
+ /**
273
+ * MIME type to store the object as. Defaults to the `Blob.type` when a Blob
274
+ * is given, otherwise `application/octet-stream`. Must be one allowed by the
275
+ * server's content-type whitelist.
276
+ */
277
+ contentType?: string;
278
+ }
279
+
280
+ /** Result of a successful `sdk.cloud.upload`. */
281
+ export interface CloudUploadResult {
282
+ /** App-relative key (the same `fileKey` passed to `upload`). */
283
+ fileKey: string;
284
+ /** Fully-qualified OSS object key (`user-data/{user_id}/{app_id}/{fileKey}`). */
285
+ objectKey: string;
286
+ /** Bytes uploaded. */
287
+ size: number;
288
+ /** MIME type the object was stored as. */
289
+ contentType: string;
290
+ }
291
+
292
+ /** A single file in the user's cloud storage for this app. */
293
+ export interface CloudFileInfo {
294
+ fileKey: string;
295
+ size: number;
296
+ /** ISO-8601 timestamp. */
297
+ lastModified: string;
298
+ }
299
+
300
+ export interface CloudListOptions {
301
+ /** Restrict the listing to keys under this app-relative prefix. */
302
+ prefix?: string;
303
+ }
304
+
305
+ /** The user's storage usage / quota for the whole account. */
306
+ export interface CloudUsage {
307
+ usedBytes: number;
308
+ quotaBytes: number;
309
+ fileCount: number;
310
+ /** ISO-8601 timestamp of the last server-side reconciliation, if any. */
311
+ reconciledAt?: string;
312
+ }
313
+
314
+ /**
315
+ * Cloud storage for WebUI apps. Backed by auth-fc presigned OSS URLs; the
316
+ * app's `appId` (from `ChatableX.init`) is injected automatically so every key
317
+ * is namespaced to `{user}/{app}` and apps cannot reach into each other's data.
318
+ *
319
+ * Requires an authenticated session (`sdk.auth`) and a configured cloud API
320
+ * base URL (see `ChatableXInitConfig.apiBaseUrl`).
321
+ */
322
+ export interface ChatableXCloud {
323
+ /** Upload (overwrite) a file. Resolves once the bytes are stored in OSS. */
324
+ upload(fileKey: string, data: CloudUploadData, options?: CloudUploadOptions): Promise<CloudUploadResult>;
325
+ /** Download a file's bytes as a Blob. */
326
+ download(fileKey: string): Promise<Blob>;
327
+ /** Get a short-lived presigned GET URL (e.g. to feed an `<img src>`). */
328
+ getDownloadUrl(fileKey: string): Promise<string>;
329
+ /** List the current app's files for this user. */
330
+ list(options?: CloudListOptions): Promise<CloudFileInfo[]>;
331
+ /** Delete a file. Resolves even if the object did not exist. */
332
+ delete(fileKey: string): Promise<void>;
333
+ /** Read the account's storage usage / quota. */
334
+ usage(): Promise<CloudUsage>;
335
+ }
336
+
337
+ // ---------------------------------------------------------------------------
338
+ // Agent Lock
339
+ // ---------------------------------------------------------------------------
340
+
341
+ export interface AgentLockConfig {
342
+ /** Enable the agent lock feature (default: true). */
343
+ enabled?: boolean;
344
+ /**
345
+ * `"overlay"` — SDK renders a built-in transparent overlay (default).
346
+ * `"events-only"` — SDK only emits lock/unlock events; no overlay injected.
347
+ */
348
+ mode?: 'overlay' | 'events-only';
349
+ /** URL of the logo displayed in the overlay centre. Defaults to built-in Chatablex SVG. */
350
+ logoUrl?: string;
351
+ /** Message shown below the logo (default: "Agent 正在操作,请稍候…"). */
352
+ message?: string;
353
+ /** Show a cancel button on the overlay (default: true). */
354
+ allowCancel?: boolean;
355
+ /** Overlay background opacity, 0–1 (default: 0.3). */
356
+ opacity?: number;
357
+ /** Auto-unlock timeout in ms (default: 30000). 0 disables. */
358
+ timeout?: number;
359
+ /** Delay before actually removing the overlay after unlock, to avoid flicker between consecutive tools (default: 200ms). */
360
+ debounceUnlock?: number;
361
+ }
362
+
363
+ export type AgentLockEventType = 'lock' | 'unlock' | 'cancel' | 'timeout';
364
+
365
+ export interface AgentLockEventData {
366
+ requestId?: string;
367
+ timestamp: number;
368
+ }
369
+
370
+ export type AgentLockEventHandler = (data: AgentLockEventData) => void;
371
+
372
+ export interface ChatableXAgentLock {
373
+ /** Manually lock user interaction with an optional custom message / timeout. */
374
+ lock(opts?: { message?: string; timeout?: number }): void;
375
+ /** Manually unlock. Safe to call when already unlocked. */
376
+ unlock(): void;
377
+ /** Whether the overlay is currently active. */
378
+ isLocked(): boolean;
379
+ /** Subscribe to lock lifecycle events. Returns an unsubscribe function. */
380
+ on(event: AgentLockEventType, handler: AgentLockEventHandler): () => void;
381
+ /** Remove a previously registered handler. */
382
+ off(event: AgentLockEventType, handler: AgentLockEventHandler): void;
383
+ }
384
+
254
385
  export interface ChatableXSDK {
255
386
  ai: ChatableXAI;
256
387
  tools: ChatableXTools;
@@ -260,6 +391,8 @@ export interface ChatableXSDK {
260
391
  tool: ChatableXToolModule;
261
392
  platform: ChatableXPlatform;
262
393
  auth: ChatableXAuth;
394
+ cloud: ChatableXCloud;
395
+ agentLock: ChatableXAgentLock;
263
396
  }
264
397
 
265
398
  // ---------------------------------------------------------------------------