wtfai 1.6.9 → 1.7.0

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.
@@ -76,6 +76,9 @@ class IframeBridgeHost {
76
76
  } else if ('clearCollection' === method) {
77
77
  const [collection] = params;
78
78
  result = await this.session.clearCollection(collection);
79
+ } else if ('fetch' === method) {
80
+ const [url, options] = params;
81
+ result = await this.session.fetch(url, options);
79
82
  } else {
80
83
  const userMethods = this.session.getIframeMethods();
81
84
  const fn = userMethods[method];
@@ -107,7 +110,8 @@ class IframeBridgeHost {
107
110
  'updateRecord',
108
111
  'deleteRecord',
109
112
  'listRecords',
110
- 'clearCollection'
113
+ 'clearCollection',
114
+ 'fetch'
111
115
  ];
112
116
  if (builtIns.includes(methodName)) return true;
113
117
  const userMethods = this.session.getIframeMethods();
package/dist/session.d.ts CHANGED
@@ -129,6 +129,12 @@ export declare class WorkflowSession {
129
129
  * @returns 执行结果的所有消息
130
130
  */
131
131
  executeWorkflow(workflowId: string, input: SendInput): Promise<SimpleMessage[]>;
132
+ /**
133
+ * 通用的 fetch 方法,支持调用后端 API
134
+ * @param url 请求地址,如果是相对路径则会自动拼接 baseUrl
135
+ * @param options 请求配置
136
+ */
137
+ fetch(url: string, options?: RequestInit): Promise<any>;
132
138
  /**
133
139
  * 发送消息执行工作流
134
140
  */
package/dist/session.js CHANGED
@@ -346,6 +346,22 @@ class WorkflowSession {
346
346
  }, this.headers).catch(reject);
347
347
  });
348
348
  }
349
+ async fetch(url, options = {}) {
350
+ this.assertNotDisposed();
351
+ const fullUrl = url.startsWith('http') ? url : `${this.baseUrl}${url}`;
352
+ const response = await fetch(fullUrl, {
353
+ ...options,
354
+ headers: {
355
+ ...this.headers,
356
+ ...options.headers
357
+ }
358
+ });
359
+ if (!response.ok) {
360
+ const errorData = await response.json().catch(()=>({}));
361
+ throw new Error(errorData.message || errorData.error || `Fetch failed with status ${response.status}`);
362
+ }
363
+ return response.json();
364
+ }
349
365
  async send({ parts: inputParts, ...rest }) {
350
366
  this.assertNotDisposed();
351
367
  if (this.state.isExecuting) throw new Error('工作流正在执行中');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wtfai",
3
- "version": "1.6.9",
3
+ "version": "1.7.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {