ai 4.0.0-canary.5 → 4.0.0-canary.7

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.mjs CHANGED
@@ -1490,28 +1490,30 @@ function standardizePrompt({
1490
1490
  }
1491
1491
 
1492
1492
  // core/types/usage.ts
1493
- function calculateLanguageModelUsage(usage) {
1493
+ function calculateLanguageModelUsage({
1494
+ promptTokens,
1495
+ completionTokens
1496
+ }) {
1494
1497
  return {
1495
- promptTokens: usage.promptTokens,
1496
- completionTokens: usage.completionTokens,
1497
- totalTokens: usage.promptTokens + usage.completionTokens
1498
+ promptTokens,
1499
+ completionTokens,
1500
+ totalTokens: promptTokens + completionTokens
1498
1501
  };
1499
1502
  }
1500
1503
 
1501
1504
  // core/util/prepare-response-headers.ts
1502
- function prepareResponseHeaders(init, {
1505
+ function prepareResponseHeaders(headers, {
1503
1506
  contentType,
1504
1507
  dataStreamVersion
1505
1508
  }) {
1506
- var _a11;
1507
- const headers = new Headers((_a11 = init == null ? void 0 : init.headers) != null ? _a11 : {});
1508
- if (!headers.has("Content-Type")) {
1509
- headers.set("Content-Type", contentType);
1509
+ const responseHeaders = new Headers(headers != null ? headers : {});
1510
+ if (!responseHeaders.has("Content-Type")) {
1511
+ responseHeaders.set("Content-Type", contentType);
1510
1512
  }
1511
1513
  if (dataStreamVersion !== void 0) {
1512
- headers.set("X-Vercel-AI-Data-Stream", dataStreamVersion);
1514
+ responseHeaders.set("X-Vercel-AI-Data-Stream", dataStreamVersion);
1513
1515
  }
1514
- return headers;
1516
+ return responseHeaders;
1515
1517
  }
1516
1518
 
1517
1519
  // core/generate-object/inject-json-instruction.ts
@@ -2277,7 +2279,7 @@ var DefaultGenerateObjectResult = class {
2277
2279
  var _a11;
2278
2280
  return new Response(JSON.stringify(this.object), {
2279
2281
  status: (_a11 = init == null ? void 0 : init.status) != null ? _a11 : 200,
2280
- headers: prepareResponseHeaders(init, {
2282
+ headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
2281
2283
  contentType: "application/json; charset=utf-8"
2282
2284
  })
2283
2285
  });
@@ -2351,23 +2353,23 @@ function now() {
2351
2353
  }
2352
2354
 
2353
2355
  // core/util/prepare-outgoing-http-headers.ts
2354
- function prepareOutgoingHttpHeaders(init, {
2356
+ function prepareOutgoingHttpHeaders(headers, {
2355
2357
  contentType,
2356
2358
  dataStreamVersion
2357
2359
  }) {
2358
- const headers = {};
2359
- if ((init == null ? void 0 : init.headers) != null) {
2360
- for (const [key, value] of Object.entries(init.headers)) {
2361
- headers[key] = value;
2360
+ const outgoingHeaders = {};
2361
+ if (headers != null) {
2362
+ for (const [key, value] of Object.entries(headers)) {
2363
+ outgoingHeaders[key] = value;
2362
2364
  }
2363
2365
  }
2364
- if (headers["Content-Type"] == null) {
2365
- headers["Content-Type"] = contentType;
2366
+ if (outgoingHeaders["Content-Type"] == null) {
2367
+ outgoingHeaders["Content-Type"] = contentType;
2366
2368
  }
2367
2369
  if (dataStreamVersion !== void 0) {
2368
- headers["X-Vercel-AI-Data-Stream"] = dataStreamVersion;
2370
+ outgoingHeaders["X-Vercel-AI-Data-Stream"] = dataStreamVersion;
2369
2371
  }
2370
- return headers;
2372
+ return outgoingHeaders;
2371
2373
  }
2372
2374
 
2373
2375
  // core/util/write-to-server-response.ts
@@ -2882,7 +2884,7 @@ var DefaultStreamObjectResult = class {
2882
2884
  response,
2883
2885
  status: init == null ? void 0 : init.status,
2884
2886
  statusText: init == null ? void 0 : init.statusText,
2885
- headers: prepareOutgoingHttpHeaders(init, {
2887
+ headers: prepareOutgoingHttpHeaders(init == null ? void 0 : init.headers, {
2886
2888
  contentType: "text/plain; charset=utf-8"
2887
2889
  }),
2888
2890
  stream: this.textStream.pipeThrough(new TextEncoderStream())
@@ -2892,7 +2894,7 @@ var DefaultStreamObjectResult = class {
2892
2894
  var _a11;
2893
2895
  return new Response(this.textStream.pipeThrough(new TextEncoderStream()), {
2894
2896
  status: (_a11 = init == null ? void 0 : init.status) != null ? _a11 : 200,
2895
- headers: prepareResponseHeaders(init, {
2897
+ headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
2896
2898
  contentType: "text/plain; charset=utf-8"
2897
2899
  })
2898
2900
  });
@@ -3116,8 +3118,7 @@ async function generateText({
3116
3118
  abortSignal,
3117
3119
  headers,
3118
3120
  maxSteps = 1,
3119
- experimental_continuationSteps,
3120
- experimental_continueSteps: continueSteps = experimental_continuationSteps != null ? experimental_continuationSteps : false,
3121
+ experimental_continueSteps: continueSteps = false,
3121
3122
  experimental_telemetry: telemetry,
3122
3123
  experimental_providerMetadata: providerMetadata,
3123
3124
  experimental_activeTools: activeTools,
@@ -3389,7 +3390,6 @@ async function generateText({
3389
3390
  messages: responseMessages
3390
3391
  },
3391
3392
  logprobs: currentModelResponse.logprobs,
3392
- responseMessages,
3393
3393
  steps,
3394
3394
  providerMetadata: currentModelResponse.providerMetadata
3395
3395
  });
@@ -3466,7 +3466,6 @@ var DefaultGenerateTextResult = class {
3466
3466
  this.warnings = options.warnings;
3467
3467
  this.request = options.request;
3468
3468
  this.response = options.response;
3469
- this.responseMessages = options.responseMessages;
3470
3469
  this.steps = options.steps;
3471
3470
  this.experimental_providerMetadata = options.providerMetadata;
3472
3471
  this.logprobs = options.logprobs;
@@ -4054,11 +4053,6 @@ var DefaultStreamTextResult = class {
4054
4053
  this.request = requestPromise;
4055
4054
  const { resolve: resolveResponse, promise: responsePromise } = createResolvablePromise();
4056
4055
  this.response = responsePromise;
4057
- const {
4058
- resolve: resolveResponseMessages,
4059
- promise: responseMessagesPromise
4060
- } = createResolvablePromise();
4061
- this.responseMessages = responseMessagesPromise;
4062
4056
  const {
4063
4057
  stream: stitchableStream,
4064
4058
  addStream,
@@ -4384,7 +4378,6 @@ var DefaultStreamTextResult = class {
4384
4378
  messages: responseMessages
4385
4379
  });
4386
4380
  resolveSteps(stepResults);
4387
- resolveResponseMessages(responseMessages);
4388
4381
  await (onFinish == null ? void 0 : onFinish({
4389
4382
  finishReason: stepFinishReason,
4390
4383
  logprobs: stepLogProbs,
@@ -4559,20 +4552,19 @@ var DefaultStreamTextResult = class {
4559
4552
  });
4560
4553
  return this.fullStream.pipeThrough(callbackTransformer).pipeThrough(streamPartsTransformer).pipeThrough(new TextEncoderStream());
4561
4554
  }
4562
- pipeDataStreamToResponse(response, options) {
4563
- const init = options == null ? void 0 : "init" in options ? options.init : {
4564
- headers: "headers" in options ? options.headers : void 0,
4565
- status: "status" in options ? options.status : void 0,
4566
- statusText: "statusText" in options ? options.statusText : void 0
4567
- };
4568
- const data = options == null ? void 0 : "data" in options ? options.data : void 0;
4569
- const getErrorMessage3 = options == null ? void 0 : "getErrorMessage" in options ? options.getErrorMessage : void 0;
4570
- const sendUsage = options == null ? void 0 : "sendUsage" in options ? options.sendUsage : void 0;
4555
+ pipeDataStreamToResponse(response, {
4556
+ status,
4557
+ statusText,
4558
+ headers,
4559
+ data,
4560
+ getErrorMessage: getErrorMessage3,
4561
+ sendUsage
4562
+ } = {}) {
4571
4563
  writeToServerResponse({
4572
4564
  response,
4573
- status: init == null ? void 0 : init.status,
4574
- statusText: init == null ? void 0 : init.statusText,
4575
- headers: prepareOutgoingHttpHeaders(init, {
4565
+ status,
4566
+ statusText,
4567
+ headers: prepareOutgoingHttpHeaders(headers, {
4576
4568
  contentType: "text/plain; charset=utf-8",
4577
4569
  dataStreamVersion: "v1"
4578
4570
  }),
@@ -4584,7 +4576,7 @@ var DefaultStreamTextResult = class {
4584
4576
  response,
4585
4577
  status: init == null ? void 0 : init.status,
4586
4578
  statusText: init == null ? void 0 : init.statusText,
4587
- headers: prepareOutgoingHttpHeaders(init, {
4579
+ headers: prepareOutgoingHttpHeaders(init == null ? void 0 : init.headers, {
4588
4580
  contentType: "text/plain; charset=utf-8"
4589
4581
  }),
4590
4582
  stream: this.textStream.pipeThrough(new TextEncoderStream())
@@ -4597,22 +4589,20 @@ var DefaultStreamTextResult = class {
4597
4589
  });
4598
4590
  return (options == null ? void 0 : options.data) ? mergeStreams(options == null ? void 0 : options.data.stream, stream) : stream;
4599
4591
  }
4600
- toDataStreamResponse(options) {
4601
- var _a11;
4602
- const init = options == null ? void 0 : "init" in options ? options.init : {
4603
- headers: "headers" in options ? options.headers : void 0,
4604
- status: "status" in options ? options.status : void 0,
4605
- statusText: "statusText" in options ? options.statusText : void 0
4606
- };
4607
- const data = options == null ? void 0 : "data" in options ? options.data : void 0;
4608
- const getErrorMessage3 = options == null ? void 0 : "getErrorMessage" in options ? options.getErrorMessage : void 0;
4609
- const sendUsage = options == null ? void 0 : "sendUsage" in options ? options.sendUsage : void 0;
4592
+ toDataStreamResponse({
4593
+ headers,
4594
+ status,
4595
+ statusText,
4596
+ data,
4597
+ getErrorMessage: getErrorMessage3,
4598
+ sendUsage
4599
+ } = {}) {
4610
4600
  return new Response(
4611
4601
  this.toDataStream({ data, getErrorMessage: getErrorMessage3, sendUsage }),
4612
4602
  {
4613
- status: (_a11 = init == null ? void 0 : init.status) != null ? _a11 : 200,
4614
- statusText: init == null ? void 0 : init.statusText,
4615
- headers: prepareResponseHeaders(init, {
4603
+ status,
4604
+ statusText,
4605
+ headers: prepareResponseHeaders(headers, {
4616
4606
  contentType: "text/plain; charset=utf-8",
4617
4607
  dataStreamVersion: "v1"
4618
4608
  })
@@ -4623,7 +4613,7 @@ var DefaultStreamTextResult = class {
4623
4613
  var _a11;
4624
4614
  return new Response(this.textStream.pipeThrough(new TextEncoderStream()), {
4625
4615
  status: (_a11 = init == null ? void 0 : init.status) != null ? _a11 : 200,
4626
- headers: prepareResponseHeaders(init, {
4616
+ headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
4627
4617
  contentType: "text/plain; charset=utf-8"
4628
4618
  })
4629
4619
  });
@@ -4727,15 +4717,11 @@ function experimental_createProviderRegistry(providers) {
4727
4717
  }
4728
4718
  return registry;
4729
4719
  }
4730
- var experimental_createModelRegistry = experimental_createProviderRegistry;
4731
4720
  var DefaultProviderRegistry = class {
4732
4721
  constructor() {
4733
4722
  this.providers = {};
4734
4723
  }
4735
- registerProvider({
4736
- id,
4737
- provider
4738
- }) {
4724
+ registerProvider({ id, provider }) {
4739
4725
  this.providers[id] = provider;
4740
4726
  }
4741
4727
  getProvider(id) {
@@ -4771,10 +4757,10 @@ var DefaultProviderRegistry = class {
4771
4757
  return model;
4772
4758
  }
4773
4759
  textEmbeddingModel(id) {
4774
- var _a11, _b, _c;
4760
+ var _a11;
4775
4761
  const [providerId, modelId] = this.splitId(id, "textEmbeddingModel");
4776
4762
  const provider = this.getProvider(providerId);
4777
- const model = (_c = (_a11 = provider.textEmbeddingModel) == null ? void 0 : _a11.call(provider, modelId)) != null ? _c : "textEmbedding" in provider ? (_b = provider.textEmbedding) == null ? void 0 : _b.call(provider, modelId) : void 0;
4763
+ const model = (_a11 = provider.textEmbeddingModel) == null ? void 0 : _a11.call(provider, modelId);
4778
4764
  if (model == null) {
4779
4765
  throw new NoSuchModelError4({
4780
4766
  modelId: id,
@@ -4886,8 +4872,6 @@ function AssistantResponse({ threadId, messageId }, process2) {
4886
4872
  );
4887
4873
  try {
4888
4874
  await process2({
4889
- threadId,
4890
- messageId,
4891
4875
  sendMessage,
4892
4876
  sendDataMessage,
4893
4877
  forwardStream
@@ -4910,12 +4894,10 @@ function AssistantResponse({ threadId, messageId }, process2) {
4910
4894
  }
4911
4895
  });
4912
4896
  }
4913
- var experimental_AssistantResponse = AssistantResponse;
4914
4897
 
4915
4898
  // streams/langchain-adapter.ts
4916
4899
  var langchain_adapter_exports = {};
4917
4900
  __export(langchain_adapter_exports, {
4918
- toAIStream: () => toAIStream,
4919
4901
  toDataStream: () => toDataStream,
4920
4902
  toDataStreamResponse: () => toDataStreamResponse
4921
4903
  });
@@ -5024,13 +5006,8 @@ function createStreamDataTransformer() {
5024
5006
  }
5025
5007
  });
5026
5008
  }
5027
- var experimental_StreamData = class extends StreamData {
5028
- };
5029
5009
 
5030
5010
  // streams/langchain-adapter.ts
5031
- function toAIStream(stream, callbacks) {
5032
- return toDataStream(stream, callbacks);
5033
- }
5034
5011
  function toDataStream(stream, callbacks) {
5035
5012
  return stream.pipeThrough(
5036
5013
  new TransformStream({
@@ -5063,7 +5040,7 @@ function toDataStreamResponse(stream, options) {
5063
5040
  return new Response(responseStream, {
5064
5041
  status: (_a11 = init == null ? void 0 : init.status) != null ? _a11 : 200,
5065
5042
  statusText: init == null ? void 0 : init.statusText,
5066
- headers: prepareResponseHeaders(init, {
5043
+ headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
5067
5044
  contentType: "text/plain; charset=utf-8",
5068
5045
  dataStreamVersion: "v1"
5069
5046
  })
@@ -5107,7 +5084,7 @@ function toDataStreamResponse2(stream, options = {}) {
5107
5084
  return new Response(responseStream, {
5108
5085
  status: (_a11 = init == null ? void 0 : init.status) != null ? _a11 : 200,
5109
5086
  statusText: init == null ? void 0 : init.statusText,
5110
- headers: prepareResponseHeaders(init, {
5087
+ headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
5111
5088
  contentType: "text/plain; charset=utf-8",
5112
5089
  dataStreamVersion: "v1"
5113
5090
  })
@@ -5155,9 +5132,6 @@ export {
5155
5132
  createStreamDataTransformer,
5156
5133
  embed,
5157
5134
  embedMany,
5158
- experimental_AssistantResponse,
5159
- experimental_StreamData,
5160
- experimental_createModelRegistry,
5161
5135
  experimental_createProviderRegistry,
5162
5136
  experimental_customProvider,
5163
5137
  experimental_wrapLanguageModel,