ai-sdk-ollama 3.8.1 → 3.8.3
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 +12 -0
- package/dist/index.browser.cjs +50 -15
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +4 -36
- package/dist/index.browser.d.ts +4 -36
- package/dist/index.browser.js +50 -15
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +50 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -36
- package/dist/index.d.ts +4 -36
- package/dist/index.js +50 -15
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 3.8.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 6019088: Updated AI SDK to 6.0.154
|
|
8
|
+
|
|
9
|
+
## 3.8.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 92ca938: Fix TypeScript 6.0 build failure caused by deprecated baseUrl option in tsup DTS generation
|
|
14
|
+
|
|
3
15
|
## 3.8.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.browser.cjs
CHANGED
|
@@ -17228,7 +17228,6 @@ async function streamText(options) {
|
|
|
17228
17228
|
}
|
|
17229
17229
|
const streamResult = await (0, import_ai4.streamText)({
|
|
17230
17230
|
...streamTextOptions,
|
|
17231
|
-
// Only set stopWhen default if user didn't provide one and tools are enabled
|
|
17232
17231
|
stopWhen: streamTextOptions.stopWhen ?? (hasTools ? (0, import_ai4.stepCountIs)(5) : void 0)
|
|
17233
17232
|
});
|
|
17234
17233
|
const state = {
|
|
@@ -17240,11 +17239,13 @@ async function streamText(options) {
|
|
|
17240
17239
|
};
|
|
17241
17240
|
let synthesisApplied = false;
|
|
17242
17241
|
let synthesisInProgress = false;
|
|
17243
|
-
const generateSynthesis = async () => {
|
|
17242
|
+
const generateSynthesis = async (toolCallsOverride, toolResultsOverride) => {
|
|
17244
17243
|
if (synthesisApplied || synthesisInProgress) {
|
|
17245
17244
|
return "";
|
|
17246
17245
|
}
|
|
17247
|
-
|
|
17246
|
+
const toolCalls = toolCallsOverride ?? state.toolCalls;
|
|
17247
|
+
const toolResults = toolResultsOverride ?? state.toolResults;
|
|
17248
|
+
if (toolCalls.length === 0) {
|
|
17248
17249
|
return "";
|
|
17249
17250
|
}
|
|
17250
17251
|
if (state.textContent.length >= minStreamLength) {
|
|
@@ -17252,7 +17253,7 @@ async function streamText(options) {
|
|
|
17252
17253
|
}
|
|
17253
17254
|
synthesisInProgress = true;
|
|
17254
17255
|
try {
|
|
17255
|
-
const toolContext =
|
|
17256
|
+
const toolContext = toolResults.map((tr) => {
|
|
17256
17257
|
return `${tr.toolName}: ${JSON.stringify(tr.output)}`;
|
|
17257
17258
|
}).join("\n") || "";
|
|
17258
17259
|
const originalPromptText = typeof options.prompt === "string" ? options.prompt : options.messages?.at(-1)?.content || "the user question";
|
|
@@ -17317,20 +17318,55 @@ Based on the tool results above, please provide a comprehensive response to the
|
|
|
17317
17318
|
}
|
|
17318
17319
|
return false;
|
|
17319
17320
|
};
|
|
17320
|
-
const
|
|
17321
|
+
const applySynthesisFromSteps = async () => {
|
|
17321
17322
|
if (synthesisApplied || controllerClosed) return;
|
|
17322
|
-
|
|
17323
|
-
|
|
17324
|
-
|
|
17325
|
-
|
|
17323
|
+
try {
|
|
17324
|
+
const steps = await streamResult.steps;
|
|
17325
|
+
const allToolCalls = [];
|
|
17326
|
+
const allToolResults = [];
|
|
17327
|
+
if (steps) {
|
|
17328
|
+
for (const step of steps) {
|
|
17329
|
+
if (step.toolCalls) {
|
|
17330
|
+
for (const tc of step.toolCalls) {
|
|
17331
|
+
allToolCalls.push({
|
|
17332
|
+
toolCallId: tc.toolCallId,
|
|
17333
|
+
toolName: tc.toolName,
|
|
17334
|
+
input: tc.input
|
|
17335
|
+
});
|
|
17336
|
+
}
|
|
17337
|
+
}
|
|
17338
|
+
if (step.toolResults) {
|
|
17339
|
+
for (const tr of step.toolResults) {
|
|
17340
|
+
allToolResults.push({
|
|
17341
|
+
toolCallId: tr.toolCallId,
|
|
17342
|
+
toolName: tr.toolName,
|
|
17343
|
+
output: tr.output
|
|
17344
|
+
});
|
|
17345
|
+
}
|
|
17346
|
+
}
|
|
17347
|
+
}
|
|
17326
17348
|
}
|
|
17349
|
+
if (allToolCalls.length > 0 && state.textContent.length < minStreamLength) {
|
|
17350
|
+
const synthesisText = await generateSynthesis(
|
|
17351
|
+
allToolCalls,
|
|
17352
|
+
allToolResults
|
|
17353
|
+
);
|
|
17354
|
+
if (synthesisText && !controllerClosed) {
|
|
17355
|
+
const chunkSize = 20;
|
|
17356
|
+
for (let i = 0; i < synthesisText.length; i += chunkSize) {
|
|
17357
|
+
if (!safeEnqueue(synthesisText.slice(i, i + chunkSize)))
|
|
17358
|
+
break;
|
|
17359
|
+
}
|
|
17360
|
+
}
|
|
17361
|
+
}
|
|
17362
|
+
} catch {
|
|
17327
17363
|
}
|
|
17328
17364
|
};
|
|
17329
17365
|
const resetTimeout = () => {
|
|
17330
17366
|
if (streamTimeout) clearTimeout(streamTimeout);
|
|
17331
17367
|
streamTimeout = setTimeout(async () => {
|
|
17332
17368
|
if (!streamComplete && !synthesisApplied && !controllerClosed) {
|
|
17333
|
-
await
|
|
17369
|
+
await applySynthesisFromSteps();
|
|
17334
17370
|
}
|
|
17335
17371
|
safeClose();
|
|
17336
17372
|
}, synthesisTimeout);
|
|
@@ -17345,7 +17381,7 @@ Based on the tool results above, please provide a comprehensive response to the
|
|
|
17345
17381
|
if (streamTimeout) clearTimeout(streamTimeout);
|
|
17346
17382
|
state.hasFinished = true;
|
|
17347
17383
|
if (!synthesisApplied && !controllerClosed) {
|
|
17348
|
-
await
|
|
17384
|
+
await applySynthesisFromSteps();
|
|
17349
17385
|
}
|
|
17350
17386
|
safeClose();
|
|
17351
17387
|
break;
|
|
@@ -17369,7 +17405,7 @@ Based on the tool results above, please provide a comprehensive response to the
|
|
|
17369
17405
|
return new ReadableStream({
|
|
17370
17406
|
async start(controller) {
|
|
17371
17407
|
let controllerClosed = false;
|
|
17372
|
-
let
|
|
17408
|
+
let hasSeenMeaningfulText = false;
|
|
17373
17409
|
let currentTextId = null;
|
|
17374
17410
|
const safeClose = () => {
|
|
17375
17411
|
if (!controllerClosed) {
|
|
@@ -17419,7 +17455,7 @@ Based on the tool results above, please provide a comprehensive response to the
|
|
|
17419
17455
|
output: tr.output
|
|
17420
17456
|
}));
|
|
17421
17457
|
}
|
|
17422
|
-
if (state.toolCalls.length > 0 && state.textContent.length < minStreamLength && !
|
|
17458
|
+
if (state.toolCalls.length > 0 && state.textContent.length < minStreamLength && !hasSeenMeaningfulText) {
|
|
17423
17459
|
const synthesisText = await generateSynthesis();
|
|
17424
17460
|
if (synthesisText && synthesisText.length > 0) {
|
|
17425
17461
|
currentTextId = crypto.randomUUID();
|
|
@@ -17455,12 +17491,12 @@ Based on the tool results above, please provide a comprehensive response to the
|
|
|
17455
17491
|
switch (part.type) {
|
|
17456
17492
|
case "text-delta":
|
|
17457
17493
|
case "text-delta-text": {
|
|
17458
|
-
hasSeenText = true;
|
|
17459
17494
|
const delta = typeof part.delta === "string" ? part.delta : "";
|
|
17460
17495
|
const text = typeof part.text === "string" ? part.text : "";
|
|
17461
17496
|
const textDelta = delta || text;
|
|
17462
17497
|
if (textDelta) {
|
|
17463
17498
|
state.textContent += textDelta;
|
|
17499
|
+
hasSeenMeaningfulText = true;
|
|
17464
17500
|
}
|
|
17465
17501
|
if (!currentTextId && typeof part.id === "string") {
|
|
17466
17502
|
currentTextId = part.id;
|
|
@@ -17468,7 +17504,6 @@ Based on the tool results above, please provide a comprehensive response to the
|
|
|
17468
17504
|
break;
|
|
17469
17505
|
}
|
|
17470
17506
|
case "text-start": {
|
|
17471
|
-
hasSeenText = true;
|
|
17472
17507
|
if (typeof part.id === "string") {
|
|
17473
17508
|
currentTextId = part.id;
|
|
17474
17509
|
}
|