ai 3.2.1 → 3.2.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/index.d.mts CHANGED
@@ -525,6 +525,11 @@ declare class GenerateObjectResult<T> {
525
525
  };
526
526
  logprobs: LogProbs | undefined;
527
527
  });
528
+ /**
529
+ Converts the object to a JSON response.
530
+ The response will have a status code of 200 and a content type of `application/json; charset=utf-8`.
531
+ */
532
+ toJsonResponse(init?: ResponseInit): Response;
528
533
  }
529
534
  /**
530
535
  * @deprecated Use `generateObject` instead.
@@ -709,6 +714,7 @@ declare class StreamObjectResult<T> {
709
714
  }): void;
710
715
  /**
711
716
  Creates a simple text stream response.
717
+ The response has a `Content-Type` header set to `text/plain; charset=utf-8`.
712
718
  Each text delta is encoded as UTF-8 and sent as a separate chunk.
713
719
  Non-text-delta events are ignored.
714
720
 
package/dist/index.d.ts CHANGED
@@ -525,6 +525,11 @@ declare class GenerateObjectResult<T> {
525
525
  };
526
526
  logprobs: LogProbs | undefined;
527
527
  });
528
+ /**
529
+ Converts the object to a JSON response.
530
+ The response will have a status code of 200 and a content type of `application/json; charset=utf-8`.
531
+ */
532
+ toJsonResponse(init?: ResponseInit): Response;
528
533
  }
529
534
  /**
530
535
  * @deprecated Use `generateObject` instead.
@@ -709,6 +714,7 @@ declare class StreamObjectResult<T> {
709
714
  }): void;
710
715
  /**
711
716
  Creates a simple text stream response.
717
+ The response has a `Content-Type` header set to `text/plain; charset=utf-8`.
712
718
  Each text delta is encoded as UTF-8 and sent as a separate chunk.
713
719
  Non-text-delta events are ignored.
714
720
 
package/dist/index.js CHANGED
@@ -623,6 +623,16 @@ function injectJsonSchemaIntoSystem({
623
623
  ].filter((line) => line != null).join("\n");
624
624
  }
625
625
 
626
+ // core/util/prepare-response-headers.ts
627
+ function prepareResponseHeaders(init, { contentType }) {
628
+ var _a;
629
+ const headers = new Headers((_a = init == null ? void 0 : init.headers) != null ? _a : {});
630
+ if (!headers.has("Content-Type")) {
631
+ headers.set("Content-Type", contentType);
632
+ }
633
+ return headers;
634
+ }
635
+
626
636
  // core/generate-object/generate-object.ts
627
637
  async function generateObject({
628
638
  model,
@@ -765,6 +775,19 @@ var GenerateObjectResult = class {
765
775
  this.rawResponse = options.rawResponse;
766
776
  this.logprobs = options.logprobs;
767
777
  }
778
+ /**
779
+ Converts the object to a JSON response.
780
+ The response will have a status code of 200 and a content type of `application/json; charset=utf-8`.
781
+ */
782
+ toJsonResponse(init) {
783
+ var _a;
784
+ return new Response(JSON.stringify(this.object), {
785
+ status: (_a = init == null ? void 0 : init.status) != null ? _a : 200,
786
+ headers: prepareResponseHeaders(init, {
787
+ contentType: "application/json; charset=utf-8"
788
+ })
789
+ });
790
+ }
768
791
  };
769
792
  var experimental_generateObject = generateObject;
770
793
 
@@ -789,16 +812,6 @@ function createAsyncIterableStream(source, transformer) {
789
812
  return transformedStream;
790
813
  }
791
814
 
792
- // core/util/prepare-response-headers.ts
793
- function prepareResponseHeaders(init, { contentType }) {
794
- var _a;
795
- const headers = new Headers((_a = init == null ? void 0 : init.headers) != null ? _a : {});
796
- if (!headers.has("Content-Type")) {
797
- headers.set("Content-Type", contentType);
798
- }
799
- return headers;
800
- }
801
-
802
815
  // core/generate-object/stream-object.ts
803
816
  async function streamObject({
804
817
  model,
@@ -1124,6 +1137,7 @@ var StreamObjectResult = class {
1124
1137
  }
1125
1138
  /**
1126
1139
  Creates a simple text stream response.
1140
+ The response has a `Content-Type` header set to `text/plain; charset=utf-8`.
1127
1141
  Each text delta is encoded as UTF-8 and sent as a separate chunk.
1128
1142
  Non-text-delta events are ignored.
1129
1143