ai 6.0.91 → 6.0.93

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.
@@ -153,7 +153,7 @@ var import_provider_utils2 = require("@ai-sdk/provider-utils");
153
153
  var import_provider_utils3 = require("@ai-sdk/provider-utils");
154
154
 
155
155
  // src/version.ts
156
- var VERSION = true ? "6.0.91" : "0.0.0-test";
156
+ var VERSION = true ? "6.0.93" : "0.0.0-test";
157
157
 
158
158
  // src/util/download/download.ts
159
159
  var download = async ({
@@ -132,7 +132,7 @@ import {
132
132
  } from "@ai-sdk/provider-utils";
133
133
 
134
134
  // src/version.ts
135
- var VERSION = true ? "6.0.91" : "0.0.0-test";
135
+ var VERSION = true ? "6.0.93" : "0.0.0-test";
136
136
 
137
137
  // src/util/download/download.ts
138
138
  var download = async ({
@@ -71,6 +71,7 @@ The open-source community has created the following providers:
71
71
  - [Voyage AI Provider](/providers/community-providers/voyage-ai) (`voyage-ai-provider`)
72
72
  - [Mem0 Provider](/providers/community-providers/mem0) (`@mem0/vercel-ai-provider`)
73
73
  - [Letta Provider](/providers/community-providers/letta) (`@letta-ai/vercel-ai-sdk-provider`)
74
+ - [Hindsight Provider](/providers/community-providers/hindsight) (`@vectorize-io/hindsight-ai-sdk`)
74
75
  - [Supermemory Provider](/providers/community-providers/supermemory) (`@supermemory/tools`)
75
76
  - [Spark Provider](/providers/community-providers/spark) (`spark-ai-provider`)
76
77
  - [AnthropicVertex Provider](/providers/community-providers/anthropic-vertex-ai) (`anthropic-vertex-ai`)
@@ -331,13 +331,14 @@ export async function POST(request: Request) {
331
331
 
332
332
  ### Track Step Progress
333
333
 
334
- Use `onStepFinish` to track each step's progress, including token usage:
334
+ Use `onStepFinish` to track each step's progress, including token usage.
335
+ The callback receives a `stepNumber` (zero-based) to identify which step just completed:
335
336
 
336
337
  ```ts
337
338
  const result = await myAgent.generate({
338
339
  prompt: 'Research and summarize the latest AI trends',
339
- onStepFinish: async ({ usage, finishReason, toolCalls }) => {
340
- console.log('Step completed:', {
340
+ onStepFinish: async ({ stepNumber, usage, finishReason, toolCalls }) => {
341
+ console.log(`Step ${stepNumber} completed:`, {
341
342
  inputTokens: usage.inputTokens,
342
343
  outputTokens: usage.outputTokens,
343
344
  finishReason,
@@ -352,18 +353,18 @@ You can also define `onStepFinish` in the constructor for agent-wide tracking. W
352
353
  ```ts
353
354
  const agent = new ToolLoopAgent({
354
355
  model: __MODEL__,
355
- onStepFinish: async ({ usage }) => {
356
+ onStepFinish: async ({ stepNumber, usage }) => {
356
357
  // Agent-wide logging
357
- console.log('Agent step:', usage.totalTokens);
358
+ console.log(`Agent step ${stepNumber}:`, usage.totalTokens);
358
359
  },
359
360
  });
360
361
 
361
362
  // Method-level callback runs after constructor callback
362
363
  const result = await agent.generate({
363
364
  prompt: 'Hello',
364
- onStepFinish: async ({ usage }) => {
365
+ onStepFinish: async ({ stepNumber, usage }) => {
365
366
  // Per-call tracking (e.g., for billing)
366
- await trackUsage(usage);
367
+ await trackUsage(stepNumber, usage);
367
368
  },
368
369
  });
369
370
  ```
@@ -175,6 +175,39 @@ Supermemory works with any AI SDK provider. The tools give the model `addMemory`
175
175
 
176
176
  See the [Supermemory provider documentation](/providers/community-providers/supermemory) for full setup and configuration.
177
177
 
178
+ ### Hindsight
179
+
180
+ [Hindsight](/providers/community-providers/hindsight) provides agents with persistent memory through five tools: `retain`, `recall`, `reflect`, `getMentalModel`, and `getDocument`. It can be self-hosted with Docker or used as a cloud service.
181
+
182
+ ```bash
183
+ pnpm add @vectorize-io/hindsight-ai-sdk @vectorize-io/hindsight-client
184
+ ```
185
+
186
+ ```ts
187
+ __PROVIDER_IMPORT__;
188
+ import { HindsightClient } from '@vectorize-io/hindsight-client';
189
+ import { createHindsightTools } from '@vectorize-io/hindsight-ai-sdk';
190
+ import { ToolLoopAgent, stepCountIs } from 'ai';
191
+ import { openai } from '@ai-sdk/openai';
192
+
193
+ const client = new HindsightClient({ baseUrl: process.env.HINDSIGHT_API_URL });
194
+
195
+ const agent = new ToolLoopAgent({
196
+ model: __MODEL__,
197
+ tools: createHindsightTools({ client, bankId: 'user-123' }),
198
+ stopWhen: stepCountIs(10),
199
+ instructions: 'You are a helpful assistant with long-term memory.',
200
+ });
201
+
202
+ const result = await agent.generate({
203
+ prompt: 'Remember that my favorite editor is Neovim',
204
+ });
205
+ ```
206
+
207
+ The `bankId` identifies the memory store and is typically a user ID. In multi-user apps, call `createHindsightTools` inside your request handler so each request gets the right bank. Hindsight works with any AI SDK provider.
208
+
209
+ See the [Hindsight provider documentation](/providers/community-providers/hindsight) for full setup and configuration.
210
+
178
211
  **When to use memory providers**: these providers are a good fit when you want memory without building any storage infrastructure. The tradeoff is that the provider controls memory behavior, so you have less visibility into what gets stored and how it is retrieved. You also take on a dependency on an external service.
179
212
 
180
213
  ## Custom Tool
@@ -105,6 +105,60 @@ const result = await generateText({
105
105
  });
106
106
  ```
107
107
 
108
+ ### Lifecycle callbacks (experimental)
109
+
110
+ <Note type="warning">
111
+ Experimental callbacks are subject to breaking changes in incremental package
112
+ releases.
113
+ </Note>
114
+
115
+ `generateText` provides several experimental lifecycle callbacks that let you hook into different phases of the generation process.
116
+ These are useful for logging, observability, debugging, and custom telemetry.
117
+ Errors thrown inside these callbacks are silently caught and do not break the generation flow.
118
+
119
+ ```tsx
120
+ import { generateText } from 'ai';
121
+ __PROVIDER_IMPORT__;
122
+
123
+ const result = await generateText({
124
+ model: __MODEL__,
125
+ prompt: 'What is the weather in San Francisco?',
126
+ tools: {
127
+ // ... your tools
128
+ },
129
+
130
+ experimental_onStart({ model, settings, functionId }) {
131
+ console.log('Generation started', { model, functionId });
132
+ },
133
+
134
+ experimental_onStepStart({ stepNumber, model, promptMessages }) {
135
+ console.log(`Step ${stepNumber} starting`, { model: model.modelId });
136
+ },
137
+
138
+ experimental_onToolCallStart({ toolName, toolCallId, input }) {
139
+ console.log(`Tool call starting: ${toolName}`, { toolCallId });
140
+ },
141
+
142
+ experimental_onToolCallFinish({ toolName, durationMs, error }) {
143
+ console.log(`Tool call finished: ${toolName} (${durationMs}ms)`, {
144
+ success: !error,
145
+ });
146
+ },
147
+
148
+ onStepFinish({ stepNumber, finishReason, usage }) {
149
+ console.log(`Step ${stepNumber} finished`, { finishReason, usage });
150
+ },
151
+ });
152
+ ```
153
+
154
+ The available lifecycle callbacks are:
155
+
156
+ - **`experimental_onStart`**: Called once when the `generateText` operation begins, before any LLM calls. Receives model info, prompt, settings, and telemetry metadata.
157
+ - **`experimental_onStepStart`**: Called before each step (LLM call). Receives the step number, model, prompt messages being sent, tools, and prior steps.
158
+ - **`experimental_onToolCallStart`**: Called right before a tool's `execute` function runs. Receives the tool name, call ID, and input.
159
+ - **`experimental_onToolCallFinish`**: Called right after a tool's `execute` function completes or errors. Receives the tool name, call ID, input, output (or undefined on error), error (or undefined on success), and `durationMs`.
160
+ - **`onStepFinish`**: Called after each step finishes. Now also includes `stepNumber` (zero-based index of the completed step).
161
+
108
162
  ## `streamText`
109
163
 
110
164
  Depending on your model and prompt, it can take a large language model (LLM) up to a minute to finish generating its response. This delay can be unacceptable for interactive use cases such as chatbots or real-time applications, where users expect immediate responses.
@@ -304,17 +304,59 @@ is triggered when a step is finished,
304
304
  i.e. all text deltas, tool calls, and tool results for the step are available.
305
305
  When you have multiple steps, the callback is triggered for each step.
306
306
 
307
- ```tsx highlight="5-7"
307
+ The callback receives a `stepNumber` (zero-based) to identify which step just completed:
308
+
309
+ ```tsx highlight="5-8"
308
310
  import { generateText } from 'ai';
309
311
 
310
312
  const result = await generateText({
311
313
  // ...
312
- onStepFinish({ text, toolCalls, toolResults, finishReason, usage }) {
314
+ onStepFinish({
315
+ stepNumber,
316
+ text,
317
+ toolCalls,
318
+ toolResults,
319
+ finishReason,
320
+ usage,
321
+ }) {
322
+ console.log(`Step ${stepNumber} finished (${finishReason})`);
313
323
  // your own logic, e.g. for saving the chat history or recording usage
314
324
  },
315
325
  });
316
326
  ```
317
327
 
328
+ ### Tool execution lifecycle callbacks
329
+
330
+ You can use `experimental_onToolCallStart` and `experimental_onToolCallFinish` to observe tool execution.
331
+ These callbacks are called right before and after each tool's `execute` function, giving you
332
+ visibility into tool execution timing, inputs, outputs, and errors:
333
+
334
+ ```tsx highlight="5-14"
335
+ import { generateText } from 'ai';
336
+
337
+ const result = await generateText({
338
+ // ... model, tools, prompt
339
+ experimental_onToolCallStart({ toolName, toolCallId, input }) {
340
+ console.log(`Calling tool: ${toolName}`, { toolCallId, input });
341
+ },
342
+ experimental_onToolCallFinish({
343
+ toolName,
344
+ toolCallId,
345
+ output,
346
+ error,
347
+ durationMs,
348
+ }) {
349
+ if (error) {
350
+ console.error(`Tool ${toolName} failed after ${durationMs}ms:`, error);
351
+ } else {
352
+ console.log(`Tool ${toolName} completed in ${durationMs}ms`, { output });
353
+ }
354
+ },
355
+ });
356
+ ```
357
+
358
+ Errors thrown inside these callbacks are silently caught and do not break the generation flow.
359
+
318
360
  ### `prepareStep` callback
319
361
 
320
362
  The `prepareStep` callback is called before a step is started.