wtfai 1.5.2 → 1.5.4

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
@@ -256,6 +256,15 @@ await session.restore()
256
256
  // 会将历史消息写入 state,可通过 getState 获取
257
257
  ```
258
258
 
259
+ ##### `updateSessionTitle(title: string)`
260
+
261
+ 更新会话标题(手动修改)。
262
+
263
+ ```typescript
264
+ await session.updateSessionTitle('新的会话标题')
265
+ // 会更新服务端变量,并触发 title 事件
266
+ ```
267
+
259
268
  ##### `getState()`
260
269
 
261
270
  获取当前状态快照。
@@ -395,6 +404,14 @@ const result = await IframeBridge.executeWorkflow('target-workflow-id', {
395
404
  console.log(result); // 执行产生的所有消息
396
405
  ```
397
406
 
407
+ #### `IframeBridge.updateSessionTitle(title)`
408
+
409
+ 更新当前会话的标题。
410
+
411
+ ```javascript
412
+ await IframeBridge.updateSessionTitle('新的标题');
413
+ ```
414
+
398
415
  #### `IframeBridge.uploadFile(file, options?)`
399
416
 
400
417
  上传文件到云存储,返回 CDN URL。
@@ -48,6 +48,10 @@ class IframeBridgeHost {
48
48
  } else if ('executeWorkflow' === method) {
49
49
  const [workflowId, input] = params;
50
50
  result = await this.session.executeWorkflow(workflowId, input);
51
+ } else if ('updateSessionTitle' === method) {
52
+ const [title] = params;
53
+ await this.session.updateSessionTitle(title);
54
+ result = true;
51
55
  } else if ('uploadFile' === method) {
52
56
  const [options] = params;
53
57
  result = await this.session.uploadFileFromIframe(options);
@@ -73,7 +77,8 @@ class IframeBridgeHost {
73
77
  'loadData',
74
78
  'hasMethod',
75
79
  'executeWorkflow',
76
- 'uploadFile'
80
+ 'uploadFile',
81
+ 'updateSessionTitle'
77
82
  ];
78
83
  if (builtIns.includes(methodName)) return true;
79
84
  const userMethods = this.session.getIframeMethods();
package/dist/session.d.ts CHANGED
@@ -59,15 +59,17 @@ export declare class WorkflowSession {
59
59
  * 恢复历史会话
60
60
  */
61
61
  restore(): Promise<void>;
62
- /**
63
- * 获取工作流变量
64
- */
65
62
  getWorkflowVariables(): Promise<Record<string, any>>;
66
63
  /**
67
64
  * 更新会话状态(服务端变量)
68
65
  * @param values 需要更新的变量键值对
69
66
  */
70
67
  setWorkflowVariables(values: Record<string, unknown>): Promise<void>;
68
+ /**
69
+ * 更新会话标题
70
+ * @param title 新的标题
71
+ */
72
+ updateSessionTitle(title: string): Promise<void>;
71
73
  /**
72
74
  * 执行指定的工作流(临时/嵌套执行)
73
75
  * 不会影响当前会话的状态(messages 等)
package/dist/session.js CHANGED
@@ -88,8 +88,10 @@ class WorkflowSession {
88
88
  });
89
89
  if (!response.ok) throw new Error('获取工作流状态失败');
90
90
  const data = await response.json();
91
+ const variables = data.variables || {};
91
92
  this.updateState({
92
- messages: data.messages
93
+ messages: data.messages,
94
+ title: variables.sessionTitle
93
95
  });
94
96
  }
95
97
  async getWorkflowVariables() {
@@ -104,7 +106,7 @@ class WorkflowSession {
104
106
  }
105
107
  async setWorkflowVariables(values) {
106
108
  this.assertNotDisposed();
107
- if (!this.state.threadId || this.state.threadId.startsWith('tmp_')) throw new Error('No active session (missing valid threadId)');
109
+ if (!this.state.threadId) throw new Error('No active session (missing valid threadId)');
108
110
  const response = await fetch(`${this.baseUrl}/workflows/${this.workflowId}/variables`, {
109
111
  method: 'POST',
110
112
  headers: {
@@ -118,6 +120,41 @@ class WorkflowSession {
118
120
  });
119
121
  if (!response.ok) throw new Error('Failed to update state');
120
122
  }
123
+ async updateSessionTitle(title) {
124
+ this.assertNotDisposed();
125
+ if (!this.state.threadId) throw new Error('No active session (missing valid threadId)');
126
+ const executionInput = {
127
+ messages: [],
128
+ variables: {
129
+ sessionTitle: title
130
+ }
131
+ };
132
+ return new Promise((resolve, reject)=>{
133
+ executeWorkflowSSE(`${this.baseUrl}/workflows/${this.workflowId}/execute`, {
134
+ input: executionInput,
135
+ threadId: this.state.threadId,
136
+ mode: 'title_update'
137
+ }, {
138
+ onTitle: (data)=>{
139
+ this.updateState({
140
+ title: data.ti
141
+ });
142
+ this.emit('title', {
143
+ title: data.ti
144
+ });
145
+ },
146
+ onComplete: ()=>{
147
+ this.updateState({
148
+ title
149
+ });
150
+ resolve();
151
+ },
152
+ onError: (err)=>{
153
+ reject(new Error(err.message));
154
+ }
155
+ }, this.headers).catch(reject);
156
+ });
157
+ }
121
158
  async executeWorkflow(workflowId, input) {
122
159
  this.assertNotDisposed();
123
160
  const { parts: inputParts, ...rest } = input;
@@ -280,6 +317,9 @@ class WorkflowSession {
280
317
  this.updateState({
281
318
  threadId: data.t
282
319
  });
320
+ if (data.ti) this.updateState({
321
+ title: data.ti
322
+ });
283
323
  this.emit('start', {
284
324
  threadId: data.t,
285
325
  ...data.ti && {
@@ -355,6 +395,9 @@ class WorkflowSession {
355
395
  });
356
396
  },
357
397
  onTitle: (data)=>{
398
+ this.updateState({
399
+ title: data.ti
400
+ });
358
401
  this.emit('title', {
359
402
  title: data.ti
360
403
  });
package/dist/types.d.ts CHANGED
@@ -168,6 +168,8 @@ export interface SessionState {
168
168
  isExecuting: boolean;
169
169
  /** 当前执行节点 ID */
170
170
  currentNodeId?: string;
171
+ /** 会话标题 */
172
+ title?: string;
171
173
  }
172
174
  /**
173
175
  * 工作流基本信息
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wtfai",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -16,23 +16,23 @@
16
16
  "@eslint/js": "^9.39.2",
17
17
  "@rsbuild/plugin-react": "^1.4.3",
18
18
  "@rslib/core": "^0.19.3",
19
- "@types/react": "^19.2.9",
19
+ "@types/react": "^19.2.10",
20
20
  "eslint": "^9.39.2",
21
21
  "eslint-config-prettier": "^10.1.8",
22
22
  "eslint-plugin-prettier": "^5.5.5",
23
- "globals": "^17.1.0",
23
+ "globals": "^17.2.0",
24
24
  "prettier": "^3.8.1",
25
- "react": "^19.2.3",
25
+ "react": "^19.2.4",
26
26
  "typescript": "^5.9.3",
27
- "typescript-eslint": "^8.53.1"
27
+ "typescript-eslint": "^8.54.0"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "react": ">=16.9.0",
31
31
  "react-dom": ">=16.9.0"
32
32
  },
33
33
  "dependencies": {
34
- "@ant-design/x": "^2.1.3",
35
- "@ant-design/x-markdown": "^2.1.3",
34
+ "@ant-design/x": "^2.2.0",
35
+ "@ant-design/x-markdown": "^2.2.0",
36
36
  "@microsoft/fetch-event-source": "^2.0.1",
37
37
  "clsx": "^2.1.1",
38
38
  "compressorjs": "^1.2.1",