@metagptx/web-sdk 0.0.39 → 0.0.40

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.
Files changed (2) hide show
  1. package/README.md +63 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -384,6 +384,69 @@ const response = await client.apiCall.invoke({
384
384
  });
385
385
  ```
386
386
 
387
+ #### Stream Response Type (Browser Only)
388
+
389
+ When making API calls in a browser environment with `responseType: 'stream'`, the SDK automatically uses the native `fetch` API instead of axios to handle streaming responses more efficiently. This avoids potential performance issues with axios interceptors when processing streaming data.
390
+
391
+ **Behavior:**
392
+ - **Browser environment** + `responseType: 'stream'`: Uses `fetch` API
393
+ - **Non-browser environment** or other `responseType` values: Uses axios (default behavior)
394
+
395
+ **Automatic Configuration:**
396
+ When using `fetch` for streaming:
397
+ - Automatically includes `Authorization` header from `localStorage.token` (if available)
398
+ - Automatically includes `Content-Type: application/json` header
399
+ - Automatically includes `App-Host` header with current origin
400
+ - Automatically handles `baseURL` from axios instance configuration
401
+ - Merges custom headers from `options.headers`
402
+ - Automatically serializes request body for POST/PUT/PATCH methods
403
+
404
+ **Return Value:**
405
+ - When using `fetch` (stream responseType in browser): Returns a native `Response` object
406
+ - When using axios (default): Returns an `AxiosResponse` object
407
+
408
+ **Example - Streaming Response:**
409
+ ```typescript
410
+ // Stream response in browser - returns Response object
411
+ const response = await client.apiCall.invoke({
412
+ url: '/api/v1/files/download',
413
+ method: 'GET',
414
+ options: {
415
+ responseType: 'stream',
416
+ },
417
+ });
418
+
419
+ // Access the ReadableStream from response.body
420
+ const reader = response.body?.getReader();
421
+ if (reader) {
422
+ while (true) {
423
+ const { done, value } = await reader.read();
424
+ if (done) break;
425
+ // Process chunk: value is a Uint8Array
426
+ console.log('Received chunk:', value);
427
+ }
428
+ }
429
+
430
+ // Or convert to blob
431
+ const blob = await response.blob();
432
+ const url = URL.createObjectURL(blob);
433
+ ```
434
+
435
+ **Example - Regular Response (uses axios):**
436
+ ```typescript
437
+ // Regular response - returns AxiosResponse object
438
+ const response = await client.apiCall.invoke({
439
+ url: '/api/v1/custom/endpoint',
440
+ method: 'GET',
441
+ // responseType defaults to 'json' or undefined
442
+ });
443
+
444
+ // Access data via response.data (axios format)
445
+ console.log(response.data);
446
+ ```
447
+
448
+ **Note:** In non-browser environments (e.g., Node.js), even with `responseType: 'stream'`, the SDK will use axios to maintain consistency across environments.
449
+
387
450
  ---
388
451
 
389
452
  ### Integrations Module
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@metagptx/web-sdk",
3
3
  "type": "module",
4
- "version": "0.0.39",
4
+ "version": "0.0.40",
5
5
  "packageManager": "pnpm@10.15.0+sha512.486ebc259d3e999a4e8691ce03b5cac4a71cbeca39372a9b762cb500cfdf0873e2cb16abe3d951b1ee2cf012503f027b98b6584e4df22524e0c7450d9ec7aa7b",
6
6
  "description": "TypeScript SDK for interacting with FuncSea API",
7
7
  "author": "MetaGPTX",