ai 4.1.55 → 4.1.57
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 +13 -0
- package/dist/index.d.mts +20 -1
- package/dist/index.d.ts +20 -1
- package/dist/index.js +152 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +150 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
@@ -5994,6 +5994,62 @@ var DefaultStreamTextResult = class {
|
|
5994
5994
|
}
|
5995
5995
|
};
|
5996
5996
|
|
5997
|
+
// core/util/merge-objects.ts
|
5998
|
+
function mergeObjects(target, source) {
|
5999
|
+
if (target === void 0 && source === void 0) {
|
6000
|
+
return void 0;
|
6001
|
+
}
|
6002
|
+
if (target === void 0) {
|
6003
|
+
return source;
|
6004
|
+
}
|
6005
|
+
if (source === void 0) {
|
6006
|
+
return target;
|
6007
|
+
}
|
6008
|
+
const result = { ...target };
|
6009
|
+
for (const key in source) {
|
6010
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
6011
|
+
const sourceValue = source[key];
|
6012
|
+
if (sourceValue === void 0)
|
6013
|
+
continue;
|
6014
|
+
const targetValue = key in target ? target[key] : void 0;
|
6015
|
+
const isSourceObject = sourceValue !== null && typeof sourceValue === "object" && !Array.isArray(sourceValue) && !(sourceValue instanceof Date) && !(sourceValue instanceof RegExp);
|
6016
|
+
const isTargetObject = targetValue !== null && targetValue !== void 0 && typeof targetValue === "object" && !Array.isArray(targetValue) && !(targetValue instanceof Date) && !(targetValue instanceof RegExp);
|
6017
|
+
if (isSourceObject && isTargetObject) {
|
6018
|
+
result[key] = mergeObjects(
|
6019
|
+
targetValue,
|
6020
|
+
sourceValue
|
6021
|
+
);
|
6022
|
+
} else {
|
6023
|
+
result[key] = sourceValue;
|
6024
|
+
}
|
6025
|
+
}
|
6026
|
+
}
|
6027
|
+
return result;
|
6028
|
+
}
|
6029
|
+
|
6030
|
+
// core/middleware/default-settings-middleware.ts
|
6031
|
+
function defaultSettingsMiddleware({
|
6032
|
+
settings
|
6033
|
+
}) {
|
6034
|
+
return {
|
6035
|
+
middlewareVersion: "v1",
|
6036
|
+
transformParams: async ({ params }) => {
|
6037
|
+
var _a17;
|
6038
|
+
return {
|
6039
|
+
...settings,
|
6040
|
+
...params,
|
6041
|
+
providerMetadata: mergeObjects(
|
6042
|
+
settings.providerMetadata,
|
6043
|
+
params.providerMetadata
|
6044
|
+
),
|
6045
|
+
// special case for temperature 0
|
6046
|
+
// TODO remove when temperature defaults to undefined
|
6047
|
+
temperature: params.temperature === 0 || params.temperature == null ? (_a17 = settings.temperature) != null ? _a17 : 0 : params.temperature
|
6048
|
+
};
|
6049
|
+
}
|
6050
|
+
};
|
6051
|
+
}
|
6052
|
+
|
5997
6053
|
// core/util/get-potential-start-index.ts
|
5998
6054
|
function getPotentialStartIndex(text2, searchedText) {
|
5999
6055
|
if (searchedText.length === 0) {
|
@@ -6104,6 +6160,89 @@ function extractReasoningMiddleware({
|
|
6104
6160
|
};
|
6105
6161
|
}
|
6106
6162
|
|
6163
|
+
// core/middleware/simulate-streaming-middleware.ts
|
6164
|
+
function simulateStreamingMiddleware() {
|
6165
|
+
return {
|
6166
|
+
middlewareVersion: "v1",
|
6167
|
+
wrapStream: async ({ doGenerate }) => {
|
6168
|
+
const result = await doGenerate();
|
6169
|
+
const simulatedStream = new ReadableStream({
|
6170
|
+
start(controller) {
|
6171
|
+
controller.enqueue({ type: "response-metadata", ...result.response });
|
6172
|
+
if (result.reasoning) {
|
6173
|
+
if (typeof result.reasoning === "string") {
|
6174
|
+
controller.enqueue({
|
6175
|
+
type: "reasoning",
|
6176
|
+
textDelta: result.reasoning
|
6177
|
+
});
|
6178
|
+
} else {
|
6179
|
+
for (const reasoning of result.reasoning) {
|
6180
|
+
switch (reasoning.type) {
|
6181
|
+
case "text": {
|
6182
|
+
controller.enqueue({
|
6183
|
+
type: "reasoning",
|
6184
|
+
textDelta: reasoning.text
|
6185
|
+
});
|
6186
|
+
if (reasoning.signature != null) {
|
6187
|
+
controller.enqueue({
|
6188
|
+
type: "reasoning-signature",
|
6189
|
+
signature: reasoning.signature
|
6190
|
+
});
|
6191
|
+
}
|
6192
|
+
break;
|
6193
|
+
}
|
6194
|
+
case "redacted": {
|
6195
|
+
controller.enqueue({
|
6196
|
+
type: "redacted-reasoning",
|
6197
|
+
data: reasoning.data
|
6198
|
+
});
|
6199
|
+
break;
|
6200
|
+
}
|
6201
|
+
}
|
6202
|
+
}
|
6203
|
+
}
|
6204
|
+
}
|
6205
|
+
if (result.text) {
|
6206
|
+
controller.enqueue({
|
6207
|
+
type: "text-delta",
|
6208
|
+
textDelta: result.text
|
6209
|
+
});
|
6210
|
+
}
|
6211
|
+
if (result.toolCalls) {
|
6212
|
+
for (const toolCall of result.toolCalls) {
|
6213
|
+
controller.enqueue({
|
6214
|
+
type: "tool-call-delta",
|
6215
|
+
toolCallType: "function",
|
6216
|
+
toolCallId: toolCall.toolCallId,
|
6217
|
+
toolName: toolCall.toolName,
|
6218
|
+
argsTextDelta: toolCall.args
|
6219
|
+
});
|
6220
|
+
controller.enqueue({
|
6221
|
+
type: "tool-call",
|
6222
|
+
...toolCall
|
6223
|
+
});
|
6224
|
+
}
|
6225
|
+
}
|
6226
|
+
controller.enqueue({
|
6227
|
+
type: "finish",
|
6228
|
+
finishReason: result.finishReason,
|
6229
|
+
usage: result.usage,
|
6230
|
+
logprobs: result.logprobs,
|
6231
|
+
providerMetadata: result.providerMetadata
|
6232
|
+
});
|
6233
|
+
controller.close();
|
6234
|
+
}
|
6235
|
+
});
|
6236
|
+
return {
|
6237
|
+
stream: simulatedStream,
|
6238
|
+
rawCall: result.rawCall,
|
6239
|
+
rawResponse: result.rawResponse,
|
6240
|
+
warnings: result.warnings
|
6241
|
+
};
|
6242
|
+
}
|
6243
|
+
};
|
6244
|
+
}
|
6245
|
+
|
6107
6246
|
// core/middleware/wrap-language-model.ts
|
6108
6247
|
var wrapLanguageModel = ({
|
6109
6248
|
model,
|
@@ -6139,12 +6278,19 @@ var doWrap = ({
|
|
6139
6278
|
async doGenerate(params) {
|
6140
6279
|
const transformedParams = await doTransform({ params, type: "generate" });
|
6141
6280
|
const doGenerate = async () => model.doGenerate(transformedParams);
|
6142
|
-
|
6281
|
+
const doStream = async () => model.doStream(transformedParams);
|
6282
|
+
return wrapGenerate ? wrapGenerate({
|
6283
|
+
doGenerate,
|
6284
|
+
doStream,
|
6285
|
+
params: transformedParams,
|
6286
|
+
model
|
6287
|
+
}) : doGenerate();
|
6143
6288
|
},
|
6144
6289
|
async doStream(params) {
|
6145
6290
|
const transformedParams = await doTransform({ params, type: "stream" });
|
6291
|
+
const doGenerate = async () => model.doGenerate(transformedParams);
|
6146
6292
|
const doStream = async () => model.doStream(transformedParams);
|
6147
|
-
return wrapStream ? wrapStream({ doStream, params: transformedParams, model }) : doStream();
|
6293
|
+
return wrapStream ? wrapStream({ doGenerate, doStream, params: transformedParams, model }) : doStream();
|
6148
6294
|
}
|
6149
6295
|
};
|
6150
6296
|
};
|
@@ -7632,6 +7778,7 @@ export {
|
|
7632
7778
|
createDataStreamResponse,
|
7633
7779
|
createIdGenerator5 as createIdGenerator,
|
7634
7780
|
customProvider,
|
7781
|
+
defaultSettingsMiddleware,
|
7635
7782
|
embed,
|
7636
7783
|
embedMany,
|
7637
7784
|
createMCPClient as experimental_createMCPClient,
|
@@ -7652,6 +7799,7 @@ export {
|
|
7652
7799
|
processDataStream,
|
7653
7800
|
processTextStream,
|
7654
7801
|
simulateReadableStream,
|
7802
|
+
simulateStreamingMiddleware,
|
7655
7803
|
smoothStream,
|
7656
7804
|
streamObject,
|
7657
7805
|
streamText,
|