ai 4.0.0-canary.5 → 4.0.0-canary.6

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # ai
2
2
 
3
+ ## 4.0.0-canary.6
4
+
5
+ ### Major Changes
6
+
7
+ - b801982: chore (ai/core): remove init option from streamText result methods
8
+
9
+ ### Patch Changes
10
+
11
+ - f9bb30c: chore (ai): remove unnecessary dev dependencies
12
+
3
13
  ## 4.0.0-canary.5
4
14
 
5
15
  ### Major Changes
package/dist/index.d.mts CHANGED
@@ -1722,11 +1722,14 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>> {
1722
1722
  Writes data stream output to a Node.js response-like object.
1723
1723
 
1724
1724
  @param response A Node.js response-like object (ServerResponse).
1725
- @param options An object with an init property (ResponseInit) and a data property.
1726
- You can also pass in a ResponseInit directly (deprecated).
1725
+ @param options.status The status code.
1726
+ @param options.statusText The status text.
1727
+ @param options.headers The headers.
1728
+ @param options.data The stream data.
1729
+ @param options.getErrorMessage An optional function that converts an error to an error message.
1730
+ @param options.sendUsage Whether to send the usage information to the client. Defaults to true.
1727
1731
  */
1728
- pipeDataStreamToResponse(response: ServerResponse$1, options?: ResponseInit | {
1729
- init?: ResponseInit;
1732
+ pipeDataStreamToResponse(response: ServerResponse$1, options?: ResponseInit & {
1730
1733
  data?: StreamData;
1731
1734
  getErrorMessage?: (error: unknown) => string;
1732
1735
  sendUsage?: boolean;
@@ -1744,13 +1747,16 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>> {
1744
1747
  Converts the result to a streamed response object with a stream data part stream.
1745
1748
  It can be used with the `useChat` and `useCompletion` hooks.
1746
1749
 
1747
- @param options An object with an init property (ResponseInit) and a data property.
1748
- You can also pass in a ResponseInit directly (deprecated).
1750
+ @param options.status The status code.
1751
+ @param options.statusText The status text.
1752
+ @param options.headers The headers.
1753
+ @param options.data The stream data.
1754
+ @param options.getErrorMessage An optional function that converts an error to an error message.
1755
+ @param options.sendUsage Whether to send the usage information to the client. Defaults to true.
1749
1756
 
1750
1757
  @return A response object.
1751
1758
  */
1752
- toDataStreamResponse(options?: ResponseInit | {
1753
- init?: ResponseInit;
1759
+ toDataStreamResponse(options?: ResponseInit & {
1754
1760
  data?: StreamData;
1755
1761
  getErrorMessage?: (error: unknown) => string;
1756
1762
  sendUsage?: boolean;
package/dist/index.d.ts CHANGED
@@ -1722,11 +1722,14 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>> {
1722
1722
  Writes data stream output to a Node.js response-like object.
1723
1723
 
1724
1724
  @param response A Node.js response-like object (ServerResponse).
1725
- @param options An object with an init property (ResponseInit) and a data property.
1726
- You can also pass in a ResponseInit directly (deprecated).
1725
+ @param options.status The status code.
1726
+ @param options.statusText The status text.
1727
+ @param options.headers The headers.
1728
+ @param options.data The stream data.
1729
+ @param options.getErrorMessage An optional function that converts an error to an error message.
1730
+ @param options.sendUsage Whether to send the usage information to the client. Defaults to true.
1727
1731
  */
1728
- pipeDataStreamToResponse(response: ServerResponse$1, options?: ResponseInit | {
1729
- init?: ResponseInit;
1732
+ pipeDataStreamToResponse(response: ServerResponse$1, options?: ResponseInit & {
1730
1733
  data?: StreamData;
1731
1734
  getErrorMessage?: (error: unknown) => string;
1732
1735
  sendUsage?: boolean;
@@ -1744,13 +1747,16 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>> {
1744
1747
  Converts the result to a streamed response object with a stream data part stream.
1745
1748
  It can be used with the `useChat` and `useCompletion` hooks.
1746
1749
 
1747
- @param options An object with an init property (ResponseInit) and a data property.
1748
- You can also pass in a ResponseInit directly (deprecated).
1750
+ @param options.status The status code.
1751
+ @param options.statusText The status text.
1752
+ @param options.headers The headers.
1753
+ @param options.data The stream data.
1754
+ @param options.getErrorMessage An optional function that converts an error to an error message.
1755
+ @param options.sendUsage Whether to send the usage information to the client. Defaults to true.
1749
1756
 
1750
1757
  @return A response object.
1751
1758
  */
1752
- toDataStreamResponse(options?: ResponseInit | {
1753
- init?: ResponseInit;
1759
+ toDataStreamResponse(options?: ResponseInit & {
1754
1760
  data?: StreamData;
1755
1761
  getErrorMessage?: (error: unknown) => string;
1756
1762
  sendUsage?: boolean;
package/dist/index.js CHANGED
@@ -1555,19 +1555,18 @@ function calculateLanguageModelUsage(usage) {
1555
1555
  }
1556
1556
 
1557
1557
  // core/util/prepare-response-headers.ts
1558
- function prepareResponseHeaders(init, {
1558
+ function prepareResponseHeaders(headers, {
1559
1559
  contentType,
1560
1560
  dataStreamVersion
1561
1561
  }) {
1562
- var _a11;
1563
- const headers = new Headers((_a11 = init == null ? void 0 : init.headers) != null ? _a11 : {});
1564
- if (!headers.has("Content-Type")) {
1565
- headers.set("Content-Type", contentType);
1562
+ const responseHeaders = new Headers(headers != null ? headers : {});
1563
+ if (!responseHeaders.has("Content-Type")) {
1564
+ responseHeaders.set("Content-Type", contentType);
1566
1565
  }
1567
1566
  if (dataStreamVersion !== void 0) {
1568
- headers.set("X-Vercel-AI-Data-Stream", dataStreamVersion);
1567
+ responseHeaders.set("X-Vercel-AI-Data-Stream", dataStreamVersion);
1569
1568
  }
1570
- return headers;
1569
+ return responseHeaders;
1571
1570
  }
1572
1571
 
1573
1572
  // core/generate-object/inject-json-instruction.ts
@@ -2328,7 +2327,7 @@ var DefaultGenerateObjectResult = class {
2328
2327
  var _a11;
2329
2328
  return new Response(JSON.stringify(this.object), {
2330
2329
  status: (_a11 = init == null ? void 0 : init.status) != null ? _a11 : 200,
2331
- headers: prepareResponseHeaders(init, {
2330
+ headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
2332
2331
  contentType: "application/json; charset=utf-8"
2333
2332
  })
2334
2333
  });
@@ -2399,23 +2398,23 @@ function now() {
2399
2398
  }
2400
2399
 
2401
2400
  // core/util/prepare-outgoing-http-headers.ts
2402
- function prepareOutgoingHttpHeaders(init, {
2401
+ function prepareOutgoingHttpHeaders(headers, {
2403
2402
  contentType,
2404
2403
  dataStreamVersion
2405
2404
  }) {
2406
- const headers = {};
2407
- if ((init == null ? void 0 : init.headers) != null) {
2408
- for (const [key, value] of Object.entries(init.headers)) {
2409
- headers[key] = value;
2405
+ const outgoingHeaders = {};
2406
+ if (headers != null) {
2407
+ for (const [key, value] of Object.entries(headers)) {
2408
+ outgoingHeaders[key] = value;
2410
2409
  }
2411
2410
  }
2412
- if (headers["Content-Type"] == null) {
2413
- headers["Content-Type"] = contentType;
2411
+ if (outgoingHeaders["Content-Type"] == null) {
2412
+ outgoingHeaders["Content-Type"] = contentType;
2414
2413
  }
2415
2414
  if (dataStreamVersion !== void 0) {
2416
- headers["X-Vercel-AI-Data-Stream"] = dataStreamVersion;
2415
+ outgoingHeaders["X-Vercel-AI-Data-Stream"] = dataStreamVersion;
2417
2416
  }
2418
- return headers;
2417
+ return outgoingHeaders;
2419
2418
  }
2420
2419
 
2421
2420
  // core/util/write-to-server-response.ts
@@ -2930,7 +2929,7 @@ var DefaultStreamObjectResult = class {
2930
2929
  response,
2931
2930
  status: init == null ? void 0 : init.status,
2932
2931
  statusText: init == null ? void 0 : init.statusText,
2933
- headers: prepareOutgoingHttpHeaders(init, {
2932
+ headers: prepareOutgoingHttpHeaders(init == null ? void 0 : init.headers, {
2934
2933
  contentType: "text/plain; charset=utf-8"
2935
2934
  }),
2936
2935
  stream: this.textStream.pipeThrough(new TextEncoderStream())
@@ -2940,7 +2939,7 @@ var DefaultStreamObjectResult = class {
2940
2939
  var _a11;
2941
2940
  return new Response(this.textStream.pipeThrough(new TextEncoderStream()), {
2942
2941
  status: (_a11 = init == null ? void 0 : init.status) != null ? _a11 : 200,
2943
- headers: prepareResponseHeaders(init, {
2942
+ headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
2944
2943
  contentType: "text/plain; charset=utf-8"
2945
2944
  })
2946
2945
  });
@@ -4595,20 +4594,19 @@ var DefaultStreamTextResult = class {
4595
4594
  });
4596
4595
  return this.fullStream.pipeThrough(callbackTransformer).pipeThrough(streamPartsTransformer).pipeThrough(new TextEncoderStream());
4597
4596
  }
4598
- pipeDataStreamToResponse(response, options) {
4599
- const init = options == null ? void 0 : "init" in options ? options.init : {
4600
- headers: "headers" in options ? options.headers : void 0,
4601
- status: "status" in options ? options.status : void 0,
4602
- statusText: "statusText" in options ? options.statusText : void 0
4603
- };
4604
- const data = options == null ? void 0 : "data" in options ? options.data : void 0;
4605
- const getErrorMessage3 = options == null ? void 0 : "getErrorMessage" in options ? options.getErrorMessage : void 0;
4606
- const sendUsage = options == null ? void 0 : "sendUsage" in options ? options.sendUsage : void 0;
4597
+ pipeDataStreamToResponse(response, {
4598
+ status,
4599
+ statusText,
4600
+ headers,
4601
+ data,
4602
+ getErrorMessage: getErrorMessage3,
4603
+ sendUsage
4604
+ } = {}) {
4607
4605
  writeToServerResponse({
4608
4606
  response,
4609
- status: init == null ? void 0 : init.status,
4610
- statusText: init == null ? void 0 : init.statusText,
4611
- headers: prepareOutgoingHttpHeaders(init, {
4607
+ status,
4608
+ statusText,
4609
+ headers: prepareOutgoingHttpHeaders(headers, {
4612
4610
  contentType: "text/plain; charset=utf-8",
4613
4611
  dataStreamVersion: "v1"
4614
4612
  }),
@@ -4620,7 +4618,7 @@ var DefaultStreamTextResult = class {
4620
4618
  response,
4621
4619
  status: init == null ? void 0 : init.status,
4622
4620
  statusText: init == null ? void 0 : init.statusText,
4623
- headers: prepareOutgoingHttpHeaders(init, {
4621
+ headers: prepareOutgoingHttpHeaders(init == null ? void 0 : init.headers, {
4624
4622
  contentType: "text/plain; charset=utf-8"
4625
4623
  }),
4626
4624
  stream: this.textStream.pipeThrough(new TextEncoderStream())
@@ -4633,22 +4631,20 @@ var DefaultStreamTextResult = class {
4633
4631
  });
4634
4632
  return (options == null ? void 0 : options.data) ? mergeStreams(options == null ? void 0 : options.data.stream, stream) : stream;
4635
4633
  }
4636
- toDataStreamResponse(options) {
4637
- var _a11;
4638
- const init = options == null ? void 0 : "init" in options ? options.init : {
4639
- headers: "headers" in options ? options.headers : void 0,
4640
- status: "status" in options ? options.status : void 0,
4641
- statusText: "statusText" in options ? options.statusText : void 0
4642
- };
4643
- const data = options == null ? void 0 : "data" in options ? options.data : void 0;
4644
- const getErrorMessage3 = options == null ? void 0 : "getErrorMessage" in options ? options.getErrorMessage : void 0;
4645
- const sendUsage = options == null ? void 0 : "sendUsage" in options ? options.sendUsage : void 0;
4634
+ toDataStreamResponse({
4635
+ headers,
4636
+ status,
4637
+ statusText,
4638
+ data,
4639
+ getErrorMessage: getErrorMessage3,
4640
+ sendUsage
4641
+ } = {}) {
4646
4642
  return new Response(
4647
4643
  this.toDataStream({ data, getErrorMessage: getErrorMessage3, sendUsage }),
4648
4644
  {
4649
- status: (_a11 = init == null ? void 0 : init.status) != null ? _a11 : 200,
4650
- statusText: init == null ? void 0 : init.statusText,
4651
- headers: prepareResponseHeaders(init, {
4645
+ status,
4646
+ statusText,
4647
+ headers: prepareResponseHeaders(headers, {
4652
4648
  contentType: "text/plain; charset=utf-8",
4653
4649
  dataStreamVersion: "v1"
4654
4650
  })
@@ -4659,7 +4655,7 @@ var DefaultStreamTextResult = class {
4659
4655
  var _a11;
4660
4656
  return new Response(this.textStream.pipeThrough(new TextEncoderStream()), {
4661
4657
  status: (_a11 = init == null ? void 0 : init.status) != null ? _a11 : 200,
4662
- headers: prepareResponseHeaders(init, {
4658
+ headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
4663
4659
  contentType: "text/plain; charset=utf-8"
4664
4660
  })
4665
4661
  });
@@ -5097,7 +5093,7 @@ function toDataStreamResponse(stream, options) {
5097
5093
  return new Response(responseStream, {
5098
5094
  status: (_a11 = init == null ? void 0 : init.status) != null ? _a11 : 200,
5099
5095
  statusText: init == null ? void 0 : init.statusText,
5100
- headers: prepareResponseHeaders(init, {
5096
+ headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
5101
5097
  contentType: "text/plain; charset=utf-8",
5102
5098
  dataStreamVersion: "v1"
5103
5099
  })
@@ -5141,7 +5137,7 @@ function toDataStreamResponse2(stream, options = {}) {
5141
5137
  return new Response(responseStream, {
5142
5138
  status: (_a11 = init == null ? void 0 : init.status) != null ? _a11 : 200,
5143
5139
  statusText: init == null ? void 0 : init.statusText,
5144
- headers: prepareResponseHeaders(init, {
5140
+ headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
5145
5141
  contentType: "text/plain; charset=utf-8",
5146
5142
  dataStreamVersion: "v1"
5147
5143
  })