wtfai 1.5.6 → 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 +48 -0
- package/dist/session.js +84 -0
- package/package.json +3 -3
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
|
@@ -71,6 +71,54 @@ export declare class WorkflowSession {
|
|
|
71
71
|
* @param title 新的标题
|
|
72
72
|
*/
|
|
73
73
|
updateSessionTitle(title: string): Promise<void>;
|
|
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>;
|
|
74
122
|
/**
|
|
75
123
|
* 执行指定的工作流(临时/嵌套执行),工作流需要使用消息生成组件来生成消息供收集
|
|
76
124
|
* 不会影响当前会话的状态(messages 等)
|
package/dist/session.js
CHANGED
|
@@ -158,6 +158,90 @@ class WorkflowSession {
|
|
|
158
158
|
}, this.headers).catch(reject);
|
|
159
159
|
});
|
|
160
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
|
+
}
|
|
161
245
|
async executeWorkflow(workflowId, input) {
|
|
162
246
|
this.assertNotDisposed();
|
|
163
247
|
const { parts: inputParts, ...rest } = input;
|
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
|
".": {
|
|
@@ -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",
|