wtfai 1.5.5 → 1.5.7
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/dist/iframe-bridge.js +25 -1
- package/dist/session.d.ts +50 -1
- package/dist/session.js +88 -0
- package/package.json +7 -7
package/dist/iframe-bridge.js
CHANGED
|
@@ -55,6 +55,24 @@ class IframeBridgeHost {
|
|
|
55
55
|
} else if ('uploadFile' === method) {
|
|
56
56
|
const [options] = params;
|
|
57
57
|
result = await this.session.uploadFileFromIframe(options);
|
|
58
|
+
} else if ('createRecord' === method) {
|
|
59
|
+
const [collection, data] = params;
|
|
60
|
+
result = await this.session.createRecord(collection, data);
|
|
61
|
+
} else if ('getRecord' === method) {
|
|
62
|
+
const [collection, id] = params;
|
|
63
|
+
result = await this.session.getRecord(collection, id);
|
|
64
|
+
} else if ('updateRecord' === method) {
|
|
65
|
+
const [collection, id, data] = params;
|
|
66
|
+
result = await this.session.updateRecord(collection, id, data);
|
|
67
|
+
} else if ('deleteRecord' === method) {
|
|
68
|
+
const [collection, id] = params;
|
|
69
|
+
result = await this.session.deleteRecord(collection, id);
|
|
70
|
+
} else if ('listRecords' === method) {
|
|
71
|
+
const [collection, options] = params;
|
|
72
|
+
result = await this.session.listRecords(collection, options);
|
|
73
|
+
} else if ('clearCollection' === method) {
|
|
74
|
+
const [collection] = params;
|
|
75
|
+
result = await this.session.clearCollection(collection);
|
|
58
76
|
} else {
|
|
59
77
|
const userMethods = this.session.getIframeMethods();
|
|
60
78
|
const fn = userMethods[method];
|
|
@@ -78,7 +96,13 @@ class IframeBridgeHost {
|
|
|
78
96
|
'hasMethod',
|
|
79
97
|
'executeWorkflow',
|
|
80
98
|
'uploadFile',
|
|
81
|
-
'updateSessionTitle'
|
|
99
|
+
'updateSessionTitle',
|
|
100
|
+
'createRecord',
|
|
101
|
+
'getRecord',
|
|
102
|
+
'updateRecord',
|
|
103
|
+
'deleteRecord',
|
|
104
|
+
'listRecords',
|
|
105
|
+
'clearCollection'
|
|
82
106
|
];
|
|
83
107
|
if (builtIns.includes(methodName)) return true;
|
|
84
108
|
const userMethods = this.session.getIframeMethods();
|
package/dist/session.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export declare class WorkflowSession {
|
|
|
16
16
|
private disposed;
|
|
17
17
|
constructor(workflowId: string, baseUrl: string, uploadService: UploadService, headers?: Record<string, string>, options?: SessionOptions);
|
|
18
18
|
private iframeMethods;
|
|
19
|
+
getWorkflowId(): string;
|
|
19
20
|
/**
|
|
20
21
|
* 注册可供 iframe 调用的自定义方法
|
|
21
22
|
*/
|
|
@@ -71,7 +72,55 @@ export declare class WorkflowSession {
|
|
|
71
72
|
*/
|
|
72
73
|
updateSessionTitle(title: string): Promise<void>;
|
|
73
74
|
/**
|
|
74
|
-
*
|
|
75
|
+
* 创建数据记录
|
|
76
|
+
* @param collection 集合名称
|
|
77
|
+
* @param data 数据内容
|
|
78
|
+
* @returns 新创建记录的 ID
|
|
79
|
+
*/
|
|
80
|
+
createRecord(collection: string, data: Record<string, unknown>): Promise<string>;
|
|
81
|
+
/**
|
|
82
|
+
* 获取数据记录
|
|
83
|
+
* @param collection 集合名称
|
|
84
|
+
* @param id 记录 ID
|
|
85
|
+
* @returns 记录数据,不存在时返回 null
|
|
86
|
+
*/
|
|
87
|
+
getRecord(collection: string, id: string): Promise<Record<string, unknown> | null>;
|
|
88
|
+
/**
|
|
89
|
+
* 更新数据记录
|
|
90
|
+
* @param collection 集合名称
|
|
91
|
+
* @param id 记录 ID
|
|
92
|
+
* @param data 新的数据内容
|
|
93
|
+
*/
|
|
94
|
+
updateRecord(collection: string, id: string, data: Record<string, unknown>): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* 删除数据记录
|
|
97
|
+
* @param collection 集合名称
|
|
98
|
+
* @param id 记录 ID
|
|
99
|
+
*/
|
|
100
|
+
deleteRecord(collection: string, id: string): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* 列表查询数据记录
|
|
103
|
+
* @param collection 集合名称
|
|
104
|
+
* @param options 分页选项
|
|
105
|
+
*/
|
|
106
|
+
listRecords(collection: string, options?: {
|
|
107
|
+
page?: number;
|
|
108
|
+
pageSize?: number;
|
|
109
|
+
}): Promise<{
|
|
110
|
+
records: Array<{
|
|
111
|
+
id: string;
|
|
112
|
+
data: Record<string, unknown>;
|
|
113
|
+
}>;
|
|
114
|
+
total: number;
|
|
115
|
+
}>;
|
|
116
|
+
/**
|
|
117
|
+
* 清空集合中的所有数据
|
|
118
|
+
* @param collection 集合名称
|
|
119
|
+
* @returns 被删除的记录数量
|
|
120
|
+
*/
|
|
121
|
+
clearCollection(collection: string): Promise<number>;
|
|
122
|
+
/**
|
|
123
|
+
* 执行指定的工作流(临时/嵌套执行),工作流需要使用消息生成组件来生成消息供收集
|
|
75
124
|
* 不会影响当前会话的状态(messages 等)
|
|
76
125
|
* @param workflowId 目标工作流 ID
|
|
77
126
|
* @param input 输入数据(与 send 方法一致)
|
package/dist/session.js
CHANGED
|
@@ -11,6 +11,9 @@ function _define_property(obj, key, value) {
|
|
|
11
11
|
return obj;
|
|
12
12
|
}
|
|
13
13
|
class WorkflowSession {
|
|
14
|
+
getWorkflowId() {
|
|
15
|
+
return this.workflowId;
|
|
16
|
+
}
|
|
14
17
|
registerIframeMethods(methods) {
|
|
15
18
|
this.assertNotDisposed();
|
|
16
19
|
this.iframeMethods = {
|
|
@@ -155,6 +158,90 @@ class WorkflowSession {
|
|
|
155
158
|
}, this.headers).catch(reject);
|
|
156
159
|
});
|
|
157
160
|
}
|
|
161
|
+
async createRecord(collection, data) {
|
|
162
|
+
this.assertNotDisposed();
|
|
163
|
+
if (!this.state.threadId) throw new Error('No active session (missing threadId)');
|
|
164
|
+
const response = await fetch(`${this.baseUrl}/workflows/${this.workflowId}/data/${encodeURIComponent(collection)}`, {
|
|
165
|
+
method: 'POST',
|
|
166
|
+
headers: {
|
|
167
|
+
'Content-Type': 'application/json',
|
|
168
|
+
...this.headers
|
|
169
|
+
},
|
|
170
|
+
body: JSON.stringify({
|
|
171
|
+
threadId: this.state.threadId,
|
|
172
|
+
data
|
|
173
|
+
})
|
|
174
|
+
});
|
|
175
|
+
if (!response.ok) throw new Error('Failed to create record');
|
|
176
|
+
const result = await response.json();
|
|
177
|
+
return result.id;
|
|
178
|
+
}
|
|
179
|
+
async getRecord(collection, id) {
|
|
180
|
+
this.assertNotDisposed();
|
|
181
|
+
if (!this.state.threadId) throw new Error('No active session (missing threadId)');
|
|
182
|
+
const url = new URL(`${this.baseUrl}/workflows/${this.workflowId}/data/${encodeURIComponent(collection)}/${encodeURIComponent(id)}`);
|
|
183
|
+
url.searchParams.set('threadId', this.state.threadId);
|
|
184
|
+
const response = await fetch(url.toString(), {
|
|
185
|
+
headers: this.headers
|
|
186
|
+
});
|
|
187
|
+
if (404 === response.status) return null;
|
|
188
|
+
if (!response.ok) throw new Error('Failed to get record');
|
|
189
|
+
const result = await response.json();
|
|
190
|
+
return result.data;
|
|
191
|
+
}
|
|
192
|
+
async updateRecord(collection, id, data) {
|
|
193
|
+
this.assertNotDisposed();
|
|
194
|
+
if (!this.state.threadId) throw new Error('No active session (missing threadId)');
|
|
195
|
+
const response = await fetch(`${this.baseUrl}/workflows/${this.workflowId}/data/${encodeURIComponent(collection)}/${encodeURIComponent(id)}`, {
|
|
196
|
+
method: 'PUT',
|
|
197
|
+
headers: {
|
|
198
|
+
'Content-Type': 'application/json',
|
|
199
|
+
...this.headers
|
|
200
|
+
},
|
|
201
|
+
body: JSON.stringify({
|
|
202
|
+
threadId: this.state.threadId,
|
|
203
|
+
data
|
|
204
|
+
})
|
|
205
|
+
});
|
|
206
|
+
if (!response.ok) throw new Error('Failed to update record');
|
|
207
|
+
}
|
|
208
|
+
async deleteRecord(collection, id) {
|
|
209
|
+
this.assertNotDisposed();
|
|
210
|
+
if (!this.state.threadId) throw new Error('No active session (missing threadId)');
|
|
211
|
+
const url = new URL(`${this.baseUrl}/workflows/${this.workflowId}/data/${encodeURIComponent(collection)}/${encodeURIComponent(id)}`);
|
|
212
|
+
url.searchParams.set('threadId', this.state.threadId);
|
|
213
|
+
const response = await fetch(url.toString(), {
|
|
214
|
+
method: 'DELETE',
|
|
215
|
+
headers: this.headers
|
|
216
|
+
});
|
|
217
|
+
if (!response.ok) throw new Error('Failed to delete record');
|
|
218
|
+
}
|
|
219
|
+
async listRecords(collection, options) {
|
|
220
|
+
this.assertNotDisposed();
|
|
221
|
+
if (!this.state.threadId) throw new Error('No active session (missing threadId)');
|
|
222
|
+
const url = new URL(`${this.baseUrl}/workflows/${this.workflowId}/data/${encodeURIComponent(collection)}`);
|
|
223
|
+
url.searchParams.set('threadId', this.state.threadId);
|
|
224
|
+
if (null == options ? void 0 : options.page) url.searchParams.set('page', String(options.page));
|
|
225
|
+
if (null == options ? void 0 : options.pageSize) url.searchParams.set('pageSize', String(options.pageSize));
|
|
226
|
+
const response = await fetch(url.toString(), {
|
|
227
|
+
headers: this.headers
|
|
228
|
+
});
|
|
229
|
+
if (!response.ok) throw new Error('Failed to list records');
|
|
230
|
+
return response.json();
|
|
231
|
+
}
|
|
232
|
+
async clearCollection(collection) {
|
|
233
|
+
this.assertNotDisposed();
|
|
234
|
+
if (!this.state.threadId) throw new Error('No active session (missing threadId)');
|
|
235
|
+
const url = new URL(`${this.baseUrl}/workflows/${this.workflowId}/data/${encodeURIComponent(collection)}`);
|
|
236
|
+
url.searchParams.set('threadId', this.state.threadId);
|
|
237
|
+
const response = await fetch(url.toString(), {
|
|
238
|
+
method: 'DELETE',
|
|
239
|
+
headers: this.headers
|
|
240
|
+
});
|
|
241
|
+
if (!response.ok) throw new Error('Failed to clear collection');
|
|
242
|
+
const result = await response.json();
|
|
243
|
+
return result.deleted;
|
|
244
|
+
}
|
|
158
245
|
async executeWorkflow(workflowId, input) {
|
|
159
246
|
this.assertNotDisposed();
|
|
160
247
|
const { parts: inputParts, ...rest } = input;
|
|
@@ -218,6 +305,7 @@ class WorkflowSession {
|
|
|
218
305
|
executeWorkflowSSE(`${this.baseUrl}/workflows/${workflowId}/execute`, {
|
|
219
306
|
input: executionInput,
|
|
220
307
|
threadId: tempThreadId,
|
|
308
|
+
hostWorkflowId: this.workflowId,
|
|
221
309
|
...rest
|
|
222
310
|
}, {
|
|
223
311
|
onNodeEnd: (data)=>{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wtfai",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
],
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@eslint/js": "^9.39.2",
|
|
17
|
-
"@rsbuild/plugin-react": "^1.4.
|
|
18
|
-
"@rslib/core": "^0.19.
|
|
19
|
-
"@types/react": "^19.2.
|
|
17
|
+
"@rsbuild/plugin-react": "^1.4.5",
|
|
18
|
+
"@rslib/core": "^0.19.5",
|
|
19
|
+
"@types/react": "^19.2.13",
|
|
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.
|
|
23
|
+
"globals": "^17.3.0",
|
|
24
24
|
"prettier": "^3.8.1",
|
|
25
25
|
"react": "^19.2.4",
|
|
26
26
|
"typescript": "^5.9.3",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"react-dom": ">=16.9.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@ant-design/x": "^2.2.
|
|
35
|
-
"@ant-design/x-markdown": "^2.2.
|
|
34
|
+
"@ant-design/x": "^2.2.2",
|
|
35
|
+
"@ant-design/x-markdown": "^2.2.2",
|
|
36
36
|
"@microsoft/fetch-event-source": "^2.0.1",
|
|
37
37
|
"clsx": "^2.1.1",
|
|
38
38
|
"compressorjs": "^1.2.1",
|