ai-sdk-ollama 4.6.2 → 4.6.4

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,25 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.6.4
4
+
5
+ ### Patch Changes
6
+
7
+ - fed4a15: Add `truncate` and `keep_alive` embedding model settings, forwarded to Ollama's `/api/embed`.
8
+
9
+ ## 4.6.3
10
+
11
+ ### Patch Changes
12
+
13
+ - c214c21: `generateText` and `streamText` keep the AI SDK's generics, so tool-specific options such as `experimental_toolCallers` type-check and `output` takes its type from your `Output`.
14
+
15
+ `usage` and `totalUsage` include synthesis and structured-output follow-up calls. In `streamText`, so do `text`, the `finish` part and `onEnd`/`onFinish`, and synthesis runs once, when you read the answer. `toUIMessageStream` and `toUIMessageStreamResponse` carry the answer, so `useChat` shows it.
16
+
17
+ With the default `stopWhen`, `toolChoice: 'required'` or a named tool applies to the first step and later steps use `auto`. Synthesis prompts carry each tool's input and output.
18
+
19
+ Decision models report a clear error for box questions and for questions without instructions.
20
+
21
+ `enableToolLogging` and `synthesisTimeout` are deprecated.
22
+
3
23
  ## 4.6.2
4
24
 
5
25
  ### Patch Changes
package/README.md CHANGED
@@ -368,6 +368,14 @@ const result = await generateText({
368
368
  console.log(result.text); // "15 + 27 equals 42. Using the math tool, I calculated..."
369
369
  ```
370
370
 
371
+ When a run ends on tool results with no answer, the wrapper makes one more model call, without tools, to write it:
372
+
373
+ - `usage`, `totalUsage` and `text` include that call, as do the `finish` part and `onEnd`/`onFinish` of `streamText`.
374
+ - `streamText` runs it once, when you read `textStream`, `stream`, `fullStream` or `text`. `toUIMessageStream`, `toUIMessageStreamResponse`, `toTextStreamResponse` and the `pipe` methods carry the answer too. Reading `usage` or calling `consumeStream` alone doesn't start it.
375
+ - With the default `stopWhen`, `toolChoice: 'required'` or a named tool applies to the first step, and later steps use `auto` so the model can answer in text.
376
+
377
+ `streamText` takes `enhancedOptions: { enableStreamingSynthesis, minStreamLength }`, which default to `true` and `10`.
378
+
371
379
  ### Combining Tools with Structured Output
372
380
 
373
381
  The `enableToolsWithStructuredOutput` option allows you to use both tool calling and structured output together:
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * generateText - Enhanced generateText with Ollama-specific reliability
3
3
  *
4
- * This wrapper provides response synthesis and enhanced tool calling reliability
5
- * that addresses the core Ollama limitation: tools execute but no final text is generated.
4
+ * When a run ends on tool results with no answer, one more model call writes it.
6
5
  */
7
- import { generateText as _generateText } from 'ai';
6
+ import type { Context } from '@ai-sdk/provider-utils';
7
+ import { generateText as _generateText, type GenerateTextResult, type OutputInterface, type ToolSet } from 'ai';
8
8
  /**
9
9
  * Enhanced options for Ollama-specific reliability features
10
10
  */
@@ -31,13 +31,10 @@ export interface EnhancedOptions {
31
31
  /**
32
32
  * EXPERIMENTAL: Enable tool calling with structured output (output)
33
33
  *
34
- * The official AI SDK doesn't support combining toolChoice: 'required' with output.
35
34
  * When enabled, this uses a two-phase approach:
36
35
  * 1. Execute tools first (without output)
37
36
  * 2. Generate structured output with tool results injected as context
38
37
  *
39
- * This is NOT standard AI SDK behavior - only enable if you need both features together.
40
- *
41
38
  * @default false
42
39
  */
43
40
  enableToolsWithStructuredOutput?: boolean;
@@ -45,7 +42,7 @@ export interface EnhancedOptions {
45
42
  /**
46
43
  * Enhanced generateText options that extend the official AI SDK options
47
44
  */
48
- export type GenerateTextOptions = Parameters<typeof _generateText>[0] & {
45
+ export type GenerateTextOptions<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends OutputInterface = OutputInterface> = Parameters<typeof _generateText<TOOLS, RUNTIME_CONTEXT, OUTPUT>>[0] & {
49
46
  /**
50
47
  * Enhanced options for Ollama-specific reliability features
51
48
  */
@@ -59,5 +56,6 @@ export type GenerateTextOptions = Parameters<typeof _generateText>[0] & {
59
56
  *
60
57
  * Type parameters are inferred from the options, preserving AI SDK's type inference.
61
58
  */
59
+ export declare function generateText<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends OutputInterface = OutputInterface<string, string>>(options: GenerateTextOptions<TOOLS, RUNTIME_CONTEXT, OUTPUT>): Promise<GenerateTextResult<ToolSet, RUNTIME_CONTEXT, OUTPUT>>;
62
60
  export declare function generateText(options: GenerateTextOptions): Promise<Awaited<ReturnType<typeof _generateText>>>;
63
61
  //# sourceMappingURL=generate-text.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate-text.d.ts","sourceRoot":"","sources":["../../src/functions/generate-text.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,IAAI,aAAa,EAAe,MAAM,IAAI,CAAC;AAsBhE;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B;;;;;;;;;;;OAWG;IACH,+BAA+B,CAAC,EAAE,OAAO,CAAC;CAC3C;AAED;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC,GAAG;IACtE;;OAEG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAyNpD"}
1
+ {"version":3,"file":"generate-text.d.ts","sourceRoot":"","sources":["../../src/functions/generate-text.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;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- type AIStreamTextOptions = Parameters<typeof _streamText>[0];
3
- export type StreamTextOptions = AIStreamTextOptions & {
1
+ import type { Context } from '@ai-sdk/provider-utils';
2
+ import { streamText as _streamText, type OutputInterface, type StreamTextResult, type ToolSet } from 'ai';
3
+ type AIStreamTextOptions<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context, OUTPUT extends OutputInterface> = Parameters<typeof _streamText<TOOLS, RUNTIME_CONTEXT, OUTPUT>>[0];
4
+ export type StreamTextOptions<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends OutputInterface = OutputInterface> = AIStreamTextOptions<TOOLS, RUNTIME_CONTEXT, OUTPUT> & {
4
5
  enhancedOptions?: {
5
6
  /**
6
- * @default true
7
+ * @deprecated Has no effect.
7
8
  */
8
9
  enableToolLogging?: boolean;
9
10
  /**
@@ -15,11 +16,12 @@ export type StreamTextOptions = AIStreamTextOptions & {
15
16
  */
16
17
  minStreamLength?: number;
17
18
  /**
18
- * @default 3000
19
+ * @deprecated Has no effect: synthesis needs the finished stream.
19
20
  */
20
21
  synthesisTimeout?: number;
21
22
  };
22
23
  };
24
+ export declare function streamText<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends OutputInterface = OutputInterface<string, string, never>>(options: StreamTextOptions<TOOLS, RUNTIME_CONTEXT, OUTPUT>): Promise<StreamTextResult<ToolSet, RUNTIME_CONTEXT, OUTPUT>>;
23
25
  export declare function streamText(options: StreamTextOptions): Promise<Awaited<ReturnType<typeof _streamText>>>;
24
26
  export {};
25
27
  //# sourceMappingURL=stream-text.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stream-text.d.ts","sourceRoot":"","sources":["../../src/functions/stream-text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,WAAW,EAAe,MAAM,IAAI,CAAC;AAG5D,KAAK,mBAAmB,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CA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CAAC,EAAE,MAAM,CAAC;QACzB;;WAEG;QACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;KAC3B,CAAC;CACH,CAAC;AAEF,wBAAsB,UAAU,CAC9B,KAAK,SAAS,OAAO,EACrB,eAAe,SAAS,OAAO,GAAG,OAAO,EACzC,MAAM,SAAS,eAAe,GAAG,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAEvE,OAAO,EAAE,iBAAiB,CAAC,KAAK,EAAE,eAAe,EAAE,MAAM,CAAC,GACzD,OAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,eAAe,EAAE,MAAM,CAAC,CAAC,CAAC;AAG/D,wBAAsB,UAAU,CAC9B,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Synthesis: when a run ends with tool results but no answer, one more model
3
+ * call writes the answer from those results. This is the policy that
4
+ * `generateText` and `streamText` share.
5
+ */
6
+ import type { ModelMessage, ToolChoice, ToolSet } from 'ai';
7
+ export declare const DEFAULT_SYNTHESIS_PROMPT = "Based on the tool results above, please provide a comprehensive response to the original question.";
8
+ interface FinishedStep {
9
+ toolCalls: unknown[];
10
+ toolResults: Array<{
11
+ toolName: string;
12
+ input?: unknown;
13
+ output?: unknown;
14
+ }>;
15
+ }
16
+ export declare function forcesTool(toolChoice?: ToolChoice<ToolSet>): boolean;
17
+ /**
18
+ * A forced tool applies to every step, so a step that answers in text would
19
+ * fail. With only our default `stopWhen`, force the first step alone.
20
+ */
21
+ export declare function prepareStepFor<PREPARE_STEP>(options: {
22
+ toolChoice?: ToolChoice<ToolSet>;
23
+ stopWhen?: unknown;
24
+ prepareStep?: PREPARE_STEP;
25
+ }): (({ stepNumber }: {
26
+ stepNumber: number;
27
+ }) => {
28
+ toolChoice?: undefined;
29
+ } | {
30
+ toolChoice: 'auto';
31
+ }) | NonNullable<PREPARE_STEP> | undefined;
32
+ export declare function needsSynthesis({ steps, text, minLength, toolChoice, }: {
33
+ steps: FinishedStep[];
34
+ text: string;
35
+ minLength: number;
36
+ toolChoice?: ToolChoice<ToolSet>;
37
+ }): boolean;
38
+ /** Options for the synthesis call: the caller's, without anything tool-related. */
39
+ export declare function buildSynthesisOptions<OPTIONS extends {
40
+ tools?: unknown;
41
+ toolChoice?: unknown;
42
+ prepareStep?: (options: never) => unknown;
43
+ prompt?: string | ModelMessage[];
44
+ messages?: ModelMessage[];
45
+ }>(options: OPTIONS, steps: FinishedStep[], instruction: string): (Omit<OPTIONS, "messages" | "prepareStep" | "prompt" | "toolChoice" | "tools"> & {
46
+ prepareStep?: ((options: never) => Promise<unknown>) | undefined;
47
+ messages: ModelMessage[];
48
+ }) | (Omit<OPTIONS, "messages" | "prepareStep" | "prompt" | "toolChoice" | "tools"> & {
49
+ prepareStep?: ((options: never) => Promise<unknown>) | undefined;
50
+ prompt: string;
51
+ });
52
+ export {};
53
+ //# sourceMappingURL=synthesis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"synthesis.d.ts","sourceRoot":"","sources":["../../src/functions/synthesis.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAG5D,eAAO,MAAM,wBAAwB,uGACiE,CAAC;AAEvG,UAAU,YAAY;IACpB,SAAS,EAAE,OAAO,EAAE,CAAC;IACrB,WAAW,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;CAC7E;AAED,wBAAgB,UAAU,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,OAAO,CAEpE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,YAAY,EAAE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