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/CHANGELOG.md +24 -0
- package/dist/index.d.mts +50 -168
- package/dist/index.d.ts +50 -168
- package/dist/index.js +55 -84
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +55 -81
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -7
- package/rsc/dist/index.d.ts +18 -18
- package/rsc/dist/rsc-server.d.mts +18 -18
- package/rsc/dist/rsc-server.mjs +7 -4
- package/rsc/dist/rsc-server.mjs.map +1 -1
package/dist/index.js
CHANGED
@@ -50,9 +50,6 @@ __export(streams_exports, {
|
|
50
50
|
createStreamDataTransformer: () => createStreamDataTransformer,
|
51
51
|
embed: () => embed,
|
52
52
|
embedMany: () => embedMany,
|
53
|
-
experimental_AssistantResponse: () => experimental_AssistantResponse,
|
54
|
-
experimental_StreamData: () => experimental_StreamData,
|
55
|
-
experimental_createModelRegistry: () => experimental_createModelRegistry,
|
56
53
|
experimental_createProviderRegistry: () => experimental_createProviderRegistry,
|
57
54
|
experimental_customProvider: () => experimental_customProvider,
|
58
55
|
experimental_wrapLanguageModel: () => experimental_wrapLanguageModel,
|
@@ -1546,28 +1543,30 @@ function standardizePrompt({
|
|
1546
1543
|
}
|
1547
1544
|
|
1548
1545
|
// core/types/usage.ts
|
1549
|
-
function calculateLanguageModelUsage(
|
1546
|
+
function calculateLanguageModelUsage({
|
1547
|
+
promptTokens,
|
1548
|
+
completionTokens
|
1549
|
+
}) {
|
1550
1550
|
return {
|
1551
|
-
promptTokens
|
1552
|
-
completionTokens
|
1553
|
-
totalTokens:
|
1551
|
+
promptTokens,
|
1552
|
+
completionTokens,
|
1553
|
+
totalTokens: promptTokens + completionTokens
|
1554
1554
|
};
|
1555
1555
|
}
|
1556
1556
|
|
1557
1557
|
// core/util/prepare-response-headers.ts
|
1558
|
-
function prepareResponseHeaders(
|
1558
|
+
function prepareResponseHeaders(headers, {
|
1559
1559
|
contentType,
|
1560
1560
|
dataStreamVersion
|
1561
1561
|
}) {
|
1562
|
-
|
1563
|
-
|
1564
|
-
|
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
|
-
|
1567
|
+
responseHeaders.set("X-Vercel-AI-Data-Stream", dataStreamVersion);
|
1569
1568
|
}
|
1570
|
-
return
|
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(
|
2401
|
+
function prepareOutgoingHttpHeaders(headers, {
|
2403
2402
|
contentType,
|
2404
2403
|
dataStreamVersion
|
2405
2404
|
}) {
|
2406
|
-
const
|
2407
|
-
if (
|
2408
|
-
for (const [key, value] of Object.entries(
|
2409
|
-
|
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 (
|
2413
|
-
|
2411
|
+
if (outgoingHeaders["Content-Type"] == null) {
|
2412
|
+
outgoingHeaders["Content-Type"] = contentType;
|
2414
2413
|
}
|
2415
2414
|
if (dataStreamVersion !== void 0) {
|
2416
|
-
|
2415
|
+
outgoingHeaders["X-Vercel-AI-Data-Stream"] = dataStreamVersion;
|
2417
2416
|
}
|
2418
|
-
return
|
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
|
});
|
@@ -3152,8 +3151,7 @@ async function generateText({
|
|
3152
3151
|
abortSignal,
|
3153
3152
|
headers,
|
3154
3153
|
maxSteps = 1,
|
3155
|
-
|
3156
|
-
experimental_continueSteps: continueSteps = experimental_continuationSteps != null ? experimental_continuationSteps : false,
|
3154
|
+
experimental_continueSteps: continueSteps = false,
|
3157
3155
|
experimental_telemetry: telemetry,
|
3158
3156
|
experimental_providerMetadata: providerMetadata,
|
3159
3157
|
experimental_activeTools: activeTools,
|
@@ -3425,7 +3423,6 @@ async function generateText({
|
|
3425
3423
|
messages: responseMessages
|
3426
3424
|
},
|
3427
3425
|
logprobs: currentModelResponse.logprobs,
|
3428
|
-
responseMessages,
|
3429
3426
|
steps,
|
3430
3427
|
providerMetadata: currentModelResponse.providerMetadata
|
3431
3428
|
});
|
@@ -3502,7 +3499,6 @@ var DefaultGenerateTextResult = class {
|
|
3502
3499
|
this.warnings = options.warnings;
|
3503
3500
|
this.request = options.request;
|
3504
3501
|
this.response = options.response;
|
3505
|
-
this.responseMessages = options.responseMessages;
|
3506
3502
|
this.steps = options.steps;
|
3507
3503
|
this.experimental_providerMetadata = options.providerMetadata;
|
3508
3504
|
this.logprobs = options.logprobs;
|
@@ -4090,11 +4086,6 @@ var DefaultStreamTextResult = class {
|
|
4090
4086
|
this.request = requestPromise;
|
4091
4087
|
const { resolve: resolveResponse, promise: responsePromise } = createResolvablePromise();
|
4092
4088
|
this.response = responsePromise;
|
4093
|
-
const {
|
4094
|
-
resolve: resolveResponseMessages,
|
4095
|
-
promise: responseMessagesPromise
|
4096
|
-
} = createResolvablePromise();
|
4097
|
-
this.responseMessages = responseMessagesPromise;
|
4098
4089
|
const {
|
4099
4090
|
stream: stitchableStream,
|
4100
4091
|
addStream,
|
@@ -4420,7 +4411,6 @@ var DefaultStreamTextResult = class {
|
|
4420
4411
|
messages: responseMessages
|
4421
4412
|
});
|
4422
4413
|
resolveSteps(stepResults);
|
4423
|
-
resolveResponseMessages(responseMessages);
|
4424
4414
|
await (onFinish == null ? void 0 : onFinish({
|
4425
4415
|
finishReason: stepFinishReason,
|
4426
4416
|
logprobs: stepLogProbs,
|
@@ -4595,20 +4585,19 @@ var DefaultStreamTextResult = class {
|
|
4595
4585
|
});
|
4596
4586
|
return this.fullStream.pipeThrough(callbackTransformer).pipeThrough(streamPartsTransformer).pipeThrough(new TextEncoderStream());
|
4597
4587
|
}
|
4598
|
-
pipeDataStreamToResponse(response,
|
4599
|
-
|
4600
|
-
|
4601
|
-
|
4602
|
-
|
4603
|
-
|
4604
|
-
|
4605
|
-
|
4606
|
-
const sendUsage = options == null ? void 0 : "sendUsage" in options ? options.sendUsage : void 0;
|
4588
|
+
pipeDataStreamToResponse(response, {
|
4589
|
+
status,
|
4590
|
+
statusText,
|
4591
|
+
headers,
|
4592
|
+
data,
|
4593
|
+
getErrorMessage: getErrorMessage3,
|
4594
|
+
sendUsage
|
4595
|
+
} = {}) {
|
4607
4596
|
writeToServerResponse({
|
4608
4597
|
response,
|
4609
|
-
status
|
4610
|
-
statusText
|
4611
|
-
headers: prepareOutgoingHttpHeaders(
|
4598
|
+
status,
|
4599
|
+
statusText,
|
4600
|
+
headers: prepareOutgoingHttpHeaders(headers, {
|
4612
4601
|
contentType: "text/plain; charset=utf-8",
|
4613
4602
|
dataStreamVersion: "v1"
|
4614
4603
|
}),
|
@@ -4620,7 +4609,7 @@ var DefaultStreamTextResult = class {
|
|
4620
4609
|
response,
|
4621
4610
|
status: init == null ? void 0 : init.status,
|
4622
4611
|
statusText: init == null ? void 0 : init.statusText,
|
4623
|
-
headers: prepareOutgoingHttpHeaders(init, {
|
4612
|
+
headers: prepareOutgoingHttpHeaders(init == null ? void 0 : init.headers, {
|
4624
4613
|
contentType: "text/plain; charset=utf-8"
|
4625
4614
|
}),
|
4626
4615
|
stream: this.textStream.pipeThrough(new TextEncoderStream())
|
@@ -4633,22 +4622,20 @@ var DefaultStreamTextResult = class {
|
|
4633
4622
|
});
|
4634
4623
|
return (options == null ? void 0 : options.data) ? mergeStreams(options == null ? void 0 : options.data.stream, stream) : stream;
|
4635
4624
|
}
|
4636
|
-
toDataStreamResponse(
|
4637
|
-
|
4638
|
-
|
4639
|
-
|
4640
|
-
|
4641
|
-
|
4642
|
-
|
4643
|
-
|
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;
|
4625
|
+
toDataStreamResponse({
|
4626
|
+
headers,
|
4627
|
+
status,
|
4628
|
+
statusText,
|
4629
|
+
data,
|
4630
|
+
getErrorMessage: getErrorMessage3,
|
4631
|
+
sendUsage
|
4632
|
+
} = {}) {
|
4646
4633
|
return new Response(
|
4647
4634
|
this.toDataStream({ data, getErrorMessage: getErrorMessage3, sendUsage }),
|
4648
4635
|
{
|
4649
|
-
status
|
4650
|
-
statusText
|
4651
|
-
headers: prepareResponseHeaders(
|
4636
|
+
status,
|
4637
|
+
statusText,
|
4638
|
+
headers: prepareResponseHeaders(headers, {
|
4652
4639
|
contentType: "text/plain; charset=utf-8",
|
4653
4640
|
dataStreamVersion: "v1"
|
4654
4641
|
})
|
@@ -4659,7 +4646,7 @@ var DefaultStreamTextResult = class {
|
|
4659
4646
|
var _a11;
|
4660
4647
|
return new Response(this.textStream.pipeThrough(new TextEncoderStream()), {
|
4661
4648
|
status: (_a11 = init == null ? void 0 : init.status) != null ? _a11 : 200,
|
4662
|
-
headers: prepareResponseHeaders(init, {
|
4649
|
+
headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
|
4663
4650
|
contentType: "text/plain; charset=utf-8"
|
4664
4651
|
})
|
4665
4652
|
});
|
@@ -4763,15 +4750,11 @@ function experimental_createProviderRegistry(providers) {
|
|
4763
4750
|
}
|
4764
4751
|
return registry;
|
4765
4752
|
}
|
4766
|
-
var experimental_createModelRegistry = experimental_createProviderRegistry;
|
4767
4753
|
var DefaultProviderRegistry = class {
|
4768
4754
|
constructor() {
|
4769
4755
|
this.providers = {};
|
4770
4756
|
}
|
4771
|
-
registerProvider({
|
4772
|
-
id,
|
4773
|
-
provider
|
4774
|
-
}) {
|
4757
|
+
registerProvider({ id, provider }) {
|
4775
4758
|
this.providers[id] = provider;
|
4776
4759
|
}
|
4777
4760
|
getProvider(id) {
|
@@ -4807,10 +4790,10 @@ var DefaultProviderRegistry = class {
|
|
4807
4790
|
return model;
|
4808
4791
|
}
|
4809
4792
|
textEmbeddingModel(id) {
|
4810
|
-
var _a11
|
4793
|
+
var _a11;
|
4811
4794
|
const [providerId, modelId] = this.splitId(id, "textEmbeddingModel");
|
4812
4795
|
const provider = this.getProvider(providerId);
|
4813
|
-
const model = (
|
4796
|
+
const model = (_a11 = provider.textEmbeddingModel) == null ? void 0 : _a11.call(provider, modelId);
|
4814
4797
|
if (model == null) {
|
4815
4798
|
throw new import_provider16.NoSuchModelError({
|
4816
4799
|
modelId: id,
|
@@ -4920,8 +4903,6 @@ function AssistantResponse({ threadId, messageId }, process2) {
|
|
4920
4903
|
);
|
4921
4904
|
try {
|
4922
4905
|
await process2({
|
4923
|
-
threadId,
|
4924
|
-
messageId,
|
4925
4906
|
sendMessage,
|
4926
4907
|
sendDataMessage,
|
4927
4908
|
forwardStream
|
@@ -4944,12 +4925,10 @@ function AssistantResponse({ threadId, messageId }, process2) {
|
|
4944
4925
|
}
|
4945
4926
|
});
|
4946
4927
|
}
|
4947
|
-
var experimental_AssistantResponse = AssistantResponse;
|
4948
4928
|
|
4949
4929
|
// streams/langchain-adapter.ts
|
4950
4930
|
var langchain_adapter_exports = {};
|
4951
4931
|
__export(langchain_adapter_exports, {
|
4952
|
-
toAIStream: () => toAIStream,
|
4953
4932
|
toDataStream: () => toDataStream,
|
4954
4933
|
toDataStreamResponse: () => toDataStreamResponse
|
4955
4934
|
});
|
@@ -5058,13 +5037,8 @@ function createStreamDataTransformer() {
|
|
5058
5037
|
}
|
5059
5038
|
});
|
5060
5039
|
}
|
5061
|
-
var experimental_StreamData = class extends StreamData {
|
5062
|
-
};
|
5063
5040
|
|
5064
5041
|
// streams/langchain-adapter.ts
|
5065
|
-
function toAIStream(stream, callbacks) {
|
5066
|
-
return toDataStream(stream, callbacks);
|
5067
|
-
}
|
5068
5042
|
function toDataStream(stream, callbacks) {
|
5069
5043
|
return stream.pipeThrough(
|
5070
5044
|
new TransformStream({
|
@@ -5097,7 +5071,7 @@ function toDataStreamResponse(stream, options) {
|
|
5097
5071
|
return new Response(responseStream, {
|
5098
5072
|
status: (_a11 = init == null ? void 0 : init.status) != null ? _a11 : 200,
|
5099
5073
|
statusText: init == null ? void 0 : init.statusText,
|
5100
|
-
headers: prepareResponseHeaders(init, {
|
5074
|
+
headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
|
5101
5075
|
contentType: "text/plain; charset=utf-8",
|
5102
5076
|
dataStreamVersion: "v1"
|
5103
5077
|
})
|
@@ -5141,7 +5115,7 @@ function toDataStreamResponse2(stream, options = {}) {
|
|
5141
5115
|
return new Response(responseStream, {
|
5142
5116
|
status: (_a11 = init == null ? void 0 : init.status) != null ? _a11 : 200,
|
5143
5117
|
statusText: init == null ? void 0 : init.statusText,
|
5144
|
-
headers: prepareResponseHeaders(init, {
|
5118
|
+
headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
|
5145
5119
|
contentType: "text/plain; charset=utf-8",
|
5146
5120
|
dataStreamVersion: "v1"
|
5147
5121
|
})
|
@@ -5190,9 +5164,6 @@ function trimStartOfStream() {
|
|
5190
5164
|
createStreamDataTransformer,
|
5191
5165
|
embed,
|
5192
5166
|
embedMany,
|
5193
|
-
experimental_AssistantResponse,
|
5194
|
-
experimental_StreamData,
|
5195
|
-
experimental_createModelRegistry,
|
5196
5167
|
experimental_createProviderRegistry,
|
5197
5168
|
experimental_customProvider,
|
5198
5169
|
experimental_wrapLanguageModel,
|