wtfai 1.7.0 → 1.7.2
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 +12 -12
- package/dist/session.d.ts +8 -6
- package/dist/session.js +33 -24
- package/dist/types.d.ts +1 -0
- package/dist/upload.d.ts +4 -0
- package/dist/upload.js +19 -0
- package/package.json +1 -1
package/dist/iframe-bridge.js
CHANGED
|
@@ -35,15 +35,15 @@ class IframeBridgeHost {
|
|
|
35
35
|
const [targetMethod] = params;
|
|
36
36
|
result = this.hasMethod(targetMethod);
|
|
37
37
|
} else if ('saveData' === method) {
|
|
38
|
-
const [key, value] = params;
|
|
38
|
+
const [key, value, threadId] = params;
|
|
39
39
|
const safeKey = `iframe_data_${key}`;
|
|
40
40
|
await this.session.setWorkflowVariables({
|
|
41
41
|
[safeKey]: value
|
|
42
|
-
});
|
|
42
|
+
}, threadId);
|
|
43
43
|
result = true;
|
|
44
44
|
} else if ('loadData' === method) {
|
|
45
|
-
const [key] = params;
|
|
46
|
-
const variables = await this.session.getWorkflowVariables();
|
|
45
|
+
const [key, threadId] = params;
|
|
46
|
+
const variables = await this.session.getWorkflowVariables(threadId);
|
|
47
47
|
result = variables[`iframe_data_${key}`];
|
|
48
48
|
} else if ('executeWorkflow' === method) {
|
|
49
49
|
const [workflowId, input] = params;
|
|
@@ -62,20 +62,20 @@ class IframeBridgeHost {
|
|
|
62
62
|
const [collection, dataList, options] = params;
|
|
63
63
|
result = await this.session.createRecords(collection, dataList, options);
|
|
64
64
|
} else if ('getRecord' === method) {
|
|
65
|
-
const [collection, id] = params;
|
|
66
|
-
result = await this.session.getRecord(collection, id);
|
|
65
|
+
const [collection, id, threadId] = params;
|
|
66
|
+
result = await this.session.getRecord(collection, id, threadId);
|
|
67
67
|
} else if ('updateRecord' === method) {
|
|
68
|
-
const [collection, id, data] = params;
|
|
69
|
-
result = await this.session.updateRecord(collection, id, data);
|
|
68
|
+
const [collection, id, data, threadId] = params;
|
|
69
|
+
result = await this.session.updateRecord(collection, id, data, threadId);
|
|
70
70
|
} else if ('deleteRecord' === method) {
|
|
71
|
-
const [collection, id] = params;
|
|
72
|
-
result = await this.session.deleteRecord(collection, id);
|
|
71
|
+
const [collection, id, threadId] = params;
|
|
72
|
+
result = await this.session.deleteRecord(collection, id, threadId);
|
|
73
73
|
} else if ('listRecords' === method) {
|
|
74
74
|
const [collection, options] = params;
|
|
75
75
|
result = await this.session.listRecords(collection, options);
|
|
76
76
|
} else if ('clearCollection' === method) {
|
|
77
|
-
const [collection] = params;
|
|
78
|
-
result = await this.session.clearCollection(collection);
|
|
77
|
+
const [collection, threadId] = params;
|
|
78
|
+
result = await this.session.clearCollection(collection, threadId);
|
|
79
79
|
} else if ('fetch' === method) {
|
|
80
80
|
const [url, options] = params;
|
|
81
81
|
result = await this.session.fetch(url, options);
|
package/dist/session.d.ts
CHANGED
|
@@ -65,12 +65,12 @@ export declare class WorkflowSession {
|
|
|
65
65
|
* 恢复历史会话
|
|
66
66
|
*/
|
|
67
67
|
restore(): Promise<void>;
|
|
68
|
-
getWorkflowVariables(): Promise<Record<string, any>>;
|
|
68
|
+
getWorkflowVariables(threadId?: string): Promise<Record<string, any>>;
|
|
69
69
|
/**
|
|
70
70
|
* 更新会话状态(服务端变量)
|
|
71
71
|
* @param values 需要更新的变量键值对
|
|
72
72
|
*/
|
|
73
|
-
setWorkflowVariables(values: Record<string, unknown
|
|
73
|
+
setWorkflowVariables(values: Record<string, unknown>, threadId?: string): Promise<void>;
|
|
74
74
|
/**
|
|
75
75
|
* 更新会话标题
|
|
76
76
|
* @param title 新的标题
|
|
@@ -84,6 +84,7 @@ export declare class WorkflowSession {
|
|
|
84
84
|
*/
|
|
85
85
|
createRecord(collection: string, data: Record<string, unknown>, options?: {
|
|
86
86
|
entityId?: string;
|
|
87
|
+
threadId?: string;
|
|
87
88
|
}): Promise<string>;
|
|
88
89
|
/**
|
|
89
90
|
* 批量创建数据记录
|
|
@@ -93,6 +94,7 @@ export declare class WorkflowSession {
|
|
|
93
94
|
*/
|
|
94
95
|
createRecords(collection: string, dataList: Array<Record<string, unknown>>, options?: {
|
|
95
96
|
entityId?: string;
|
|
97
|
+
threadId?: string;
|
|
96
98
|
}): Promise<string[]>;
|
|
97
99
|
/**
|
|
98
100
|
* 获取数据记录
|
|
@@ -100,27 +102,27 @@ export declare class WorkflowSession {
|
|
|
100
102
|
* @param id 记录 ID
|
|
101
103
|
* @returns 记录数据,不存在时返回 null
|
|
102
104
|
*/
|
|
103
|
-
getRecord(collection: string, id: string): Promise<Record<string, unknown> | null>;
|
|
105
|
+
getRecord(collection: string, id: string, threadId?: string): Promise<Record<string, unknown> | null>;
|
|
104
106
|
/**
|
|
105
107
|
* 更新数据记录
|
|
106
108
|
* @param collection 集合名称
|
|
107
109
|
* @param id 记录 ID
|
|
108
110
|
* @param data 新的数据内容
|
|
109
111
|
*/
|
|
110
|
-
updateRecord(collection: string, id: string, data: Record<string, unknown
|
|
112
|
+
updateRecord(collection: string, id: string, data: Record<string, unknown>, threadId?: string): Promise<void>;
|
|
111
113
|
/**
|
|
112
114
|
* 删除数据记录
|
|
113
115
|
* @param collection 集合名称
|
|
114
116
|
* @param id 记录 ID
|
|
115
117
|
*/
|
|
116
|
-
deleteRecord(collection: string, id: string): Promise<void>;
|
|
118
|
+
deleteRecord(collection: string, id: string, threadId?: string): Promise<void>;
|
|
117
119
|
listRecords(collection: string, options?: ListRecordsOptions): Promise<ListRecordsResult>;
|
|
118
120
|
/**
|
|
119
121
|
* 清空集合中的所有数据
|
|
120
122
|
* @param collection 集合名称
|
|
121
123
|
* @returns 被删除的记录数量
|
|
122
124
|
*/
|
|
123
|
-
clearCollection(collection: string): Promise<number>;
|
|
125
|
+
clearCollection(collection: string, threadId?: string): Promise<number>;
|
|
124
126
|
/**
|
|
125
127
|
* 执行指定的工作流(临时/嵌套执行),工作流需要使用消息生成组件来生成消息供收集
|
|
126
128
|
* 不会影响当前会话的状态(messages 等)
|
package/dist/session.js
CHANGED
|
@@ -100,19 +100,21 @@ class WorkflowSession {
|
|
|
100
100
|
title: variables.sessionTitle
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
|
-
async getWorkflowVariables() {
|
|
103
|
+
async getWorkflowVariables(threadId) {
|
|
104
104
|
this.assertNotDisposed();
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
const finalThreadId = threadId || this.state.threadId;
|
|
106
|
+
if (!finalThreadId) throw new Error('No active session (missing threadId)');
|
|
107
|
+
const response = await fetch(`${this.baseUrl}/workflows/${this.workflowId}/state?threadId=${finalThreadId}`, {
|
|
107
108
|
headers: this.headers
|
|
108
109
|
});
|
|
109
110
|
if (!response.ok) throw new Error('Failed to get workflow variables');
|
|
110
111
|
const data = await response.json();
|
|
111
112
|
return data.variables || {};
|
|
112
113
|
}
|
|
113
|
-
async setWorkflowVariables(values) {
|
|
114
|
+
async setWorkflowVariables(values, threadId) {
|
|
114
115
|
this.assertNotDisposed();
|
|
115
|
-
|
|
116
|
+
const finalThreadId = threadId || this.state.threadId;
|
|
117
|
+
if (!finalThreadId) throw new Error('No active session (missing valid threadId)');
|
|
116
118
|
const response = await fetch(`${this.baseUrl}/workflows/${this.workflowId}/variables`, {
|
|
117
119
|
method: 'POST',
|
|
118
120
|
headers: {
|
|
@@ -120,7 +122,7 @@ class WorkflowSession {
|
|
|
120
122
|
...this.headers
|
|
121
123
|
},
|
|
122
124
|
body: JSON.stringify({
|
|
123
|
-
threadId:
|
|
125
|
+
threadId: finalThreadId,
|
|
124
126
|
values
|
|
125
127
|
})
|
|
126
128
|
});
|
|
@@ -163,7 +165,8 @@ class WorkflowSession {
|
|
|
163
165
|
}
|
|
164
166
|
async createRecord(collection, data, options = {}) {
|
|
165
167
|
this.assertNotDisposed();
|
|
166
|
-
|
|
168
|
+
const finalThreadId = options.threadId || this.state.threadId;
|
|
169
|
+
if (!finalThreadId) throw new Error('No active session (missing threadId)');
|
|
167
170
|
const response = await fetch(`${this.baseUrl}/workflows/${this.workflowId}/data/${encodeURIComponent(collection)}`, {
|
|
168
171
|
method: 'POST',
|
|
169
172
|
headers: {
|
|
@@ -171,7 +174,7 @@ class WorkflowSession {
|
|
|
171
174
|
...this.headers
|
|
172
175
|
},
|
|
173
176
|
body: JSON.stringify({
|
|
174
|
-
threadId:
|
|
177
|
+
threadId: finalThreadId,
|
|
175
178
|
data,
|
|
176
179
|
entityId: options.entityId
|
|
177
180
|
})
|
|
@@ -182,7 +185,8 @@ class WorkflowSession {
|
|
|
182
185
|
}
|
|
183
186
|
async createRecords(collection, dataList, options = {}) {
|
|
184
187
|
this.assertNotDisposed();
|
|
185
|
-
|
|
188
|
+
const finalThreadId = options.threadId || this.state.threadId;
|
|
189
|
+
if (!finalThreadId) throw new Error('No active session (missing threadId)');
|
|
186
190
|
const response = await fetch(`${this.baseUrl}/workflows/${this.workflowId}/data/${encodeURIComponent(collection)}/batch`, {
|
|
187
191
|
method: 'POST',
|
|
188
192
|
headers: {
|
|
@@ -190,7 +194,7 @@ class WorkflowSession {
|
|
|
190
194
|
...this.headers
|
|
191
195
|
},
|
|
192
196
|
body: JSON.stringify({
|
|
193
|
-
threadId:
|
|
197
|
+
threadId: finalThreadId,
|
|
194
198
|
dataList,
|
|
195
199
|
entityId: options.entityId
|
|
196
200
|
})
|
|
@@ -199,11 +203,12 @@ class WorkflowSession {
|
|
|
199
203
|
const result = await response.json();
|
|
200
204
|
return result.ids;
|
|
201
205
|
}
|
|
202
|
-
async getRecord(collection, id) {
|
|
206
|
+
async getRecord(collection, id, threadId) {
|
|
203
207
|
this.assertNotDisposed();
|
|
204
|
-
|
|
208
|
+
const finalThreadId = threadId || this.state.threadId;
|
|
209
|
+
if (!finalThreadId) throw new Error('No active session (missing threadId)');
|
|
205
210
|
const url = new URL(`${this.baseUrl}/workflows/${this.workflowId}/data/${encodeURIComponent(collection)}/${encodeURIComponent(id)}`);
|
|
206
|
-
url.searchParams.set('threadId',
|
|
211
|
+
url.searchParams.set('threadId', finalThreadId);
|
|
207
212
|
const response = await fetch(url.toString(), {
|
|
208
213
|
headers: this.headers
|
|
209
214
|
});
|
|
@@ -212,9 +217,10 @@ class WorkflowSession {
|
|
|
212
217
|
const result = await response.json();
|
|
213
218
|
return result.data;
|
|
214
219
|
}
|
|
215
|
-
async updateRecord(collection, id, data) {
|
|
220
|
+
async updateRecord(collection, id, data, threadId) {
|
|
216
221
|
this.assertNotDisposed();
|
|
217
|
-
|
|
222
|
+
const finalThreadId = threadId || this.state.threadId;
|
|
223
|
+
if (!finalThreadId) throw new Error('No active session (missing threadId)');
|
|
218
224
|
const response = await fetch(`${this.baseUrl}/workflows/${this.workflowId}/data/${encodeURIComponent(collection)}/${encodeURIComponent(id)}`, {
|
|
219
225
|
method: 'PUT',
|
|
220
226
|
headers: {
|
|
@@ -222,17 +228,18 @@ class WorkflowSession {
|
|
|
222
228
|
...this.headers
|
|
223
229
|
},
|
|
224
230
|
body: JSON.stringify({
|
|
225
|
-
threadId:
|
|
231
|
+
threadId: finalThreadId,
|
|
226
232
|
data
|
|
227
233
|
})
|
|
228
234
|
});
|
|
229
235
|
if (!response.ok) throw new Error('Failed to update record');
|
|
230
236
|
}
|
|
231
|
-
async deleteRecord(collection, id) {
|
|
237
|
+
async deleteRecord(collection, id, threadId) {
|
|
232
238
|
this.assertNotDisposed();
|
|
233
|
-
|
|
239
|
+
const finalThreadId = threadId || this.state.threadId;
|
|
240
|
+
if (!finalThreadId) throw new Error('No active session (missing threadId)');
|
|
234
241
|
const url = new URL(`${this.baseUrl}/workflows/${this.workflowId}/data/${encodeURIComponent(collection)}/${encodeURIComponent(id)}`);
|
|
235
|
-
url.searchParams.set('threadId',
|
|
242
|
+
url.searchParams.set('threadId', finalThreadId);
|
|
236
243
|
const response = await fetch(url.toString(), {
|
|
237
244
|
method: 'DELETE',
|
|
238
245
|
headers: this.headers
|
|
@@ -241,9 +248,10 @@ class WorkflowSession {
|
|
|
241
248
|
}
|
|
242
249
|
async listRecords(collection, options) {
|
|
243
250
|
this.assertNotDisposed();
|
|
244
|
-
|
|
251
|
+
const finalThreadId = (null == options ? void 0 : options.threadId) || this.state.threadId;
|
|
252
|
+
if (!finalThreadId) throw new Error('No active session (missing threadId)');
|
|
245
253
|
const url = new URL(`${this.baseUrl}/workflows/${this.workflowId}/data/${encodeURIComponent(collection)}`);
|
|
246
|
-
url.searchParams.set('threadId',
|
|
254
|
+
url.searchParams.set('threadId', finalThreadId);
|
|
247
255
|
Object.entries(options || {}).forEach(([key, value])=>{
|
|
248
256
|
if (void 0 !== value) url.searchParams.set(key, String(value));
|
|
249
257
|
});
|
|
@@ -253,11 +261,12 @@ class WorkflowSession {
|
|
|
253
261
|
if (!response.ok) throw new Error('Failed to list records');
|
|
254
262
|
return response.json();
|
|
255
263
|
}
|
|
256
|
-
async clearCollection(collection) {
|
|
264
|
+
async clearCollection(collection, threadId) {
|
|
257
265
|
this.assertNotDisposed();
|
|
258
|
-
|
|
266
|
+
const finalThreadId = threadId || this.state.threadId;
|
|
267
|
+
if (!finalThreadId) throw new Error('No active session (missing threadId)');
|
|
259
268
|
const url = new URL(`${this.baseUrl}/workflows/${this.workflowId}/data/${encodeURIComponent(collection)}`);
|
|
260
|
-
url.searchParams.set('threadId',
|
|
269
|
+
url.searchParams.set('threadId', finalThreadId);
|
|
261
270
|
const response = await fetch(url.toString(), {
|
|
262
271
|
method: 'DELETE',
|
|
263
272
|
headers: this.headers
|
package/dist/types.d.ts
CHANGED
package/dist/upload.d.ts
CHANGED
package/dist/upload.js
CHANGED
|
@@ -157,6 +157,25 @@ class UploadService {
|
|
|
157
157
|
...rest
|
|
158
158
|
});
|
|
159
159
|
}
|
|
160
|
+
async getSignedUrl(key, bucketTypeCode = 'private') {
|
|
161
|
+
const searchParams = new URLSearchParams({
|
|
162
|
+
key,
|
|
163
|
+
bucketType: bucketTypeCode
|
|
164
|
+
});
|
|
165
|
+
const res = await fetch(`${this.baseUrl}/workflows/signed-url?${searchParams.toString()}`, {
|
|
166
|
+
method: 'GET',
|
|
167
|
+
headers: {
|
|
168
|
+
'Content-Type': 'application/json',
|
|
169
|
+
...this.headers
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
if (!res.ok) {
|
|
173
|
+
const error = await res.json().catch(()=>({}));
|
|
174
|
+
throw new Error(error.message || '获取签名 URL 失败');
|
|
175
|
+
}
|
|
176
|
+
const data = await res.json();
|
|
177
|
+
return data;
|
|
178
|
+
}
|
|
160
179
|
constructor(baseUrl, headers = {}){
|
|
161
180
|
_define_property(this, "baseUrl", void 0);
|
|
162
181
|
_define_property(this, "headers", void 0);
|