wtfai 1.5.7 → 1.5.8

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,7 +34,7 @@ const client = new Wtfai({
34
34
  const session = client.createSession('workflow-id')
35
35
 
36
36
  // 3. 发送消息
37
- await session.send({ content: '你好' })
37
+ await session.send({ parts: [{ type: 'text', text: '你好' }] })
38
38
  ```
39
39
 
40
40
  ## API 文档
@@ -442,6 +442,128 @@ const url = await IframeBridge.uploadFile(file, {
442
442
 
443
443
  ---
444
444
 
445
+ ### Session Data CRUD API
446
+
447
+ 用于会话级数据的持久化存储,与 `saveData/loadData` 不同,这是一套完整的 CRUD 接口,支持集合(Collection)概念,适合存储结构化数据。
448
+
449
+ > **与 saveData/loadData 的区别**:
450
+ > - `saveData/loadData` 存储在工作流 state 中(适合简单 key-value)
451
+ > - Session Data API 存储在独立数据表中(适合结构化数据、列表数据)
452
+
453
+ #### `IframeBridge.createRecord(collection, data)`
454
+
455
+ 在指定集合中创建一条记录。
456
+
457
+ ```javascript
458
+ const id = await IframeBridge.createRecord('notes', {
459
+ title: 'My Note',
460
+ content: 'Hello World',
461
+ createdAt: Date.now()
462
+ });
463
+ console.log('创建成功, ID:', id);
464
+ ```
465
+
466
+ #### `IframeBridge.getRecord(collection, id)`
467
+
468
+ 获取单条记录。
469
+
470
+ ```javascript
471
+ const data = await IframeBridge.getRecord('notes', id);
472
+ if (data) {
473
+ console.log('记录内容:', data.title, data.content);
474
+ } else {
475
+ console.log('记录不存在');
476
+ }
477
+ ```
478
+
479
+ #### `IframeBridge.updateRecord(collection, id, data)`
480
+
481
+ 更新记录(完整替换)。
482
+
483
+ ```javascript
484
+ await IframeBridge.updateRecord('notes', id, {
485
+ title: 'Updated Title',
486
+ content: 'New content',
487
+ updatedAt: Date.now()
488
+ });
489
+ ```
490
+
491
+ #### `IframeBridge.deleteRecord(collection, id)`
492
+
493
+ 删除单条记录。
494
+
495
+ ```javascript
496
+ await IframeBridge.deleteRecord('notes', id);
497
+ ```
498
+
499
+ #### `IframeBridge.listRecords(collection, options?)`
500
+
501
+ 分页查询集合中的记录。
502
+
503
+ ```javascript
504
+ const result = await IframeBridge.listRecords('notes', {
505
+ page: 1,
506
+ pageSize: 10
507
+ });
508
+ console.log(`共 ${result.total} 条记录`);
509
+ result.records.forEach(r => {
510
+ console.log(r.id, r.data.title);
511
+ });
512
+ ```
513
+
514
+ #### `IframeBridge.clearCollection(collection)`
515
+
516
+ 清空集合中的所有记录。
517
+
518
+ ```javascript
519
+ const count = await IframeBridge.clearCollection('notes');
520
+ console.log(`已删除 ${count} 条记录`);
521
+ ```
522
+
523
+ **使用场景**:
524
+ - 待办事项列表
525
+ - 用户收藏/历史记录
526
+ - 表单草稿
527
+ - 游戏存档
528
+
529
+ ---
530
+
531
+ ## HTTP API
532
+
533
+ 以下 API 可直接通过 HTTP 调用,无需使用 SDK。
534
+
535
+ ### 中断工作流执行
536
+
537
+ 中断正在运行的工作流。工作流会返回 `error` 事件携带中断原因后关闭连接。
538
+
539
+ **请求**
540
+
541
+ ```http
542
+ POST /workflows/:workflowId/interrupt
543
+ Content-Type: application/json
544
+
545
+ {
546
+ "threadId": "会话ID",
547
+ "reason": "中断原因"
548
+ }
549
+ ```
550
+
551
+ **响应**
552
+
553
+ ```json
554
+ {
555
+ "success": true,
556
+ "local": true // true=本地实例中断, false=通过集群广播
557
+ }
558
+ ```
559
+
560
+ **说明**:
561
+ - 支持集群模式,会通过 Redis Pub/Sub 广播中断信号到所有实例
562
+ - 工作流被中断后会触发 `error` 事件,`message` 为传入的 `reason`
563
+ - 如果找不到对应的执行会话,返回 404
564
+
565
+ ---
566
+
445
567
  ### UploadService
446
568
 
447
569
  文件上传服务(通过 `client.upload` 访问)。
@@ -52,7 +52,8 @@ class IframeBridgeHost {
52
52
  const [title] = params;
53
53
  await this.session.updateSessionTitle(title);
54
54
  result = true;
55
- } else if ('uploadFile' === method) {
55
+ } else if ('getSessionId' === method) result = this.session.getState().threadId;
56
+ else if ('uploadFile' === method) {
56
57
  const [options] = params;
57
58
  result = await this.session.uploadFileFromIframe(options);
58
59
  } else if ('createRecord' === method) {
@@ -97,6 +98,7 @@ class IframeBridgeHost {
97
98
  'executeWorkflow',
98
99
  'uploadFile',
99
100
  'updateSessionTitle',
101
+ 'getSessionId',
100
102
  'createRecord',
101
103
  'getRecord',
102
104
  'updateRecord',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wtfai",
3
- "version": "1.5.7",
3
+ "version": "1.5.8",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -13,18 +13,18 @@
13
13
  "dist"
14
14
  ],
15
15
  "devDependencies": {
16
- "@eslint/js": "^9.39.2",
16
+ "@eslint/js": "^9.39.3",
17
17
  "@rsbuild/plugin-react": "^1.4.5",
18
- "@rslib/core": "^0.19.5",
19
- "@types/react": "^19.2.13",
20
- "eslint": "^9.39.2",
18
+ "@rslib/core": "^0.19.6",
19
+ "@types/react": "^19.2.14",
20
+ "eslint": "^9.39.3",
21
21
  "eslint-config-prettier": "^10.1.8",
22
22
  "eslint-plugin-prettier": "^5.5.5",
23
23
  "globals": "^17.3.0",
24
24
  "prettier": "^3.8.1",
25
25
  "react": "^19.2.4",
26
26
  "typescript": "^5.9.3",
27
- "typescript-eslint": "^8.54.0"
27
+ "typescript-eslint": "^8.56.1"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "react": ">=16.9.0",