ai-sdk-ollama 4.6.1 → 4.6.2

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,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.6.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 518ddf1: Harden the stream for custom `OllamaClient` adapters whose iterator ends cleanly without the final `done` chunk: close any open text or reasoning block, emit an `error` part and end the stream with a `finish` part (reason `error`). The default client already throws in that case, so its streams still error as before.
8
+
3
9
  ## 4.6.1
4
10
 
5
11
  ### Patch Changes
@@ -1976,6 +1976,7 @@ function buildObjectGenerationResult(parameters) {
1976
1976
  }
1977
1977
 
1978
1978
  // src/models/chat-stream.ts
1979
+ var import_provider = require("@ai-sdk/provider");
1979
1980
  function createChunkTransformer({
1980
1981
  warnings,
1981
1982
  includeRawChunks
@@ -1984,6 +1985,7 @@ function createChunkTransformer({
1984
1985
  let textId;
1985
1986
  let reasoningId;
1986
1987
  let hasToolCalls = false;
1988
+ let finished = false;
1987
1989
  function endReasoning(controller) {
1988
1990
  if (reasoningId === void 0) {
1989
1991
  return;
@@ -2048,6 +2050,7 @@ function createChunkTransformer({
2048
2050
  emitReasoning(controller, thinking);
2049
2051
  }
2050
2052
  if (chunk.done) {
2053
+ finished = true;
2051
2054
  endReasoning(controller);
2052
2055
  if (hasContent) {
2053
2056
  emitText(controller, content);
@@ -2066,6 +2069,33 @@ function createChunkTransformer({
2066
2069
  if (hasContent) {
2067
2070
  emitText(controller, content);
2068
2071
  }
2072
+ },
2073
+ // Hardening for clients whose iterator ends cleanly without Ollama's
2074
+ // `done` chunk (a custom `OllamaClient` adapter). The default client throws
2075
+ // in that case, so the stream errors and this never runs. Close what is
2076
+ // open, report the early end as an error and still end the stream with a
2077
+ // finish part, so consumers do not wait on a part that never comes.
2078
+ flush(controller) {
2079
+ if (finished) {
2080
+ return;
2081
+ }
2082
+ if (!streamStarted) {
2083
+ controller.enqueue({ type: "stream-start", warnings });
2084
+ }
2085
+ endReasoning(controller);
2086
+ endText(controller);
2087
+ controller.enqueue({
2088
+ type: "error",
2089
+ error: new import_provider.InvalidResponseDataError({
2090
+ data: void 0,
2091
+ message: "Ollama stream ended without a done chunk."
2092
+ })
2093
+ });
2094
+ controller.enqueue({
2095
+ type: "finish",
2096
+ finishReason: { unified: "error", raw: void 0 },
2097
+ usage: aggregateUsage()
2098
+ });
2069
2099
  }
2070
2100
  });
2071
2101
  }
@@ -22811,7 +22841,7 @@ var OllamaSpeechModel = class {
22811
22841
  };
22812
22842
 
22813
22843
  // src/models/decision-model.ts
22814
- var import_provider = require("@ai-sdk/provider");
22844
+ var import_provider2 = require("@ai-sdk/provider");
22815
22845
  var isList = (input2) => Array.isArray(input2);
22816
22846
  var isText = (input2) => typeof input2 === "string";
22817
22847
  var toContent = (input2) => isList(input2) ? [...input2] : input2;
@@ -22826,7 +22856,7 @@ function toStateValue(part) {
22826
22856
  return part.value;
22827
22857
  }
22828
22858
  case "file": {
22829
- throw new import_provider.UnsupportedFunctionalityError({
22859
+ throw new import_provider2.UnsupportedFunctionalityError({
22830
22860
  functionality: "file parts in decision state"
22831
22861
  });
22832
22862
  }