@anyr/ai-sdk-provider 0.1.2 → 0.1.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/README.md CHANGED
@@ -65,6 +65,28 @@ for await (const chunk of textStream) {
65
65
  }
66
66
  ```
67
67
 
68
+ ### Reasoning models
69
+
70
+ Reasoning models (e.g. `deepseek/deepseek-r1`) return their thinking as a
71
+ separate stream — the provider surfaces it as the AI SDK's standard reasoning
72
+ parts, so `reasoning`/`reasoningText` and the full-stream `reasoning-*` parts
73
+ work out of the box.
74
+
75
+ ```ts
76
+ import { createAnyRouter } from "@anyr/ai-sdk-provider"
77
+ import { generateText } from "ai"
78
+
79
+ const anyrouter = createAnyRouter()
80
+
81
+ const { text, reasoningText } = await generateText({
82
+ model: anyrouter("deepseek/deepseek-r1"),
83
+ prompt: "How many r's are in strawberry?",
84
+ })
85
+
86
+ console.log(reasoningText) // the model's chain of thought
87
+ console.log(text) // the final answer
88
+ ```
89
+
68
90
  ### generateObject (structured output)
69
91
 
70
92
  ```ts
package/dist/index.js CHANGED
@@ -249,7 +249,21 @@ function emitResponseMetadata(chunk, state, fallbackModelId, controller) {
249
249
  modelId: chunk.model ?? fallbackModelId
250
250
  });
251
251
  }
252
+ function closeReasoning(state, controller) {
253
+ if (state.activeReasoningId !== null) {
254
+ controller.enqueue({ type: "reasoning-end", id: state.activeReasoningId });
255
+ state.activeReasoningId = null;
256
+ }
257
+ }
258
+ function emitReasoningDelta(content, state, controller) {
259
+ if (state.activeReasoningId === null) {
260
+ state.activeReasoningId = providerUtils.generateId();
261
+ controller.enqueue({ type: "reasoning-start", id: state.activeReasoningId });
262
+ }
263
+ controller.enqueue({ type: "reasoning-delta", id: state.activeReasoningId, delta: content });
264
+ }
252
265
  function emitTextDelta(content, state, controller) {
266
+ closeReasoning(state, controller);
253
267
  if (state.activeTextId === null) {
254
268
  state.activeTextId = providerUtils.generateId();
255
269
  controller.enqueue({ type: "text-start", id: state.activeTextId });
@@ -279,6 +293,7 @@ function emitToolCallDeltas(toolCalls, acc, controller) {
279
293
  }
280
294
  }
281
295
  function emitFinish(choice, chunk, state, acc, controller) {
296
+ closeReasoning(state, controller);
282
297
  if (state.activeTextId !== null) {
283
298
  controller.enqueue({ type: "text-end", id: state.activeTextId });
284
299
  state.activeTextId = null;
@@ -418,6 +433,9 @@ var AnyRouterChatLanguageModel = class {
418
433
  const choice = response.choices?.[0];
419
434
  const message = choice?.message;
420
435
  const content = [];
436
+ if (message?.reasoning_content) {
437
+ content.push({ type: "reasoning", text: message.reasoning_content });
438
+ }
421
439
  if (message?.content) {
422
440
  content.push({ type: "text", text: message.content });
423
441
  }
@@ -468,7 +486,11 @@ var AnyRouterChatLanguageModel = class {
468
486
  fetch: this.config.fetch
469
487
  });
470
488
  const toolCallAccumulator = {};
471
- const state = { activeTextId: null, metadataEmitted: false };
489
+ const state = {
490
+ activeTextId: null,
491
+ activeReasoningId: null,
492
+ metadataEmitted: false
493
+ };
472
494
  const selfModelId = this.modelId;
473
495
  const transformStream = new TransformStream({
474
496
  start(controller) {
@@ -484,6 +506,9 @@ var AnyRouterChatLanguageModel = class {
484
506
  emitResponseMetadata(chunk, state, selfModelId, controller);
485
507
  const delta = choice?.delta;
486
508
  if (delta) {
509
+ if (typeof delta.reasoning_content === "string" && delta.reasoning_content.length > 0) {
510
+ emitReasoningDelta(delta.reasoning_content, state, controller);
511
+ }
487
512
  if (typeof delta.content === "string" && delta.content.length > 0) {
488
513
  emitTextDelta(delta.content, state, controller);
489
514
  }
@@ -496,6 +521,7 @@ var AnyRouterChatLanguageModel = class {
496
521
  }
497
522
  },
498
523
  flush(controller) {
524
+ closeReasoning(state, controller);
499
525
  if (state.activeTextId !== null) {
500
526
  controller.enqueue({ type: "text-end", id: state.activeTextId });
501
527
  }
package/dist/index.mjs CHANGED
@@ -247,7 +247,21 @@ function emitResponseMetadata(chunk, state, fallbackModelId, controller) {
247
247
  modelId: chunk.model ?? fallbackModelId
248
248
  });
249
249
  }
250
+ function closeReasoning(state, controller) {
251
+ if (state.activeReasoningId !== null) {
252
+ controller.enqueue({ type: "reasoning-end", id: state.activeReasoningId });
253
+ state.activeReasoningId = null;
254
+ }
255
+ }
256
+ function emitReasoningDelta(content, state, controller) {
257
+ if (state.activeReasoningId === null) {
258
+ state.activeReasoningId = generateId();
259
+ controller.enqueue({ type: "reasoning-start", id: state.activeReasoningId });
260
+ }
261
+ controller.enqueue({ type: "reasoning-delta", id: state.activeReasoningId, delta: content });
262
+ }
250
263
  function emitTextDelta(content, state, controller) {
264
+ closeReasoning(state, controller);
251
265
  if (state.activeTextId === null) {
252
266
  state.activeTextId = generateId();
253
267
  controller.enqueue({ type: "text-start", id: state.activeTextId });
@@ -277,6 +291,7 @@ function emitToolCallDeltas(toolCalls, acc, controller) {
277
291
  }
278
292
  }
279
293
  function emitFinish(choice, chunk, state, acc, controller) {
294
+ closeReasoning(state, controller);
280
295
  if (state.activeTextId !== null) {
281
296
  controller.enqueue({ type: "text-end", id: state.activeTextId });
282
297
  state.activeTextId = null;
@@ -416,6 +431,9 @@ var AnyRouterChatLanguageModel = class {
416
431
  const choice = response.choices?.[0];
417
432
  const message = choice?.message;
418
433
  const content = [];
434
+ if (message?.reasoning_content) {
435
+ content.push({ type: "reasoning", text: message.reasoning_content });
436
+ }
419
437
  if (message?.content) {
420
438
  content.push({ type: "text", text: message.content });
421
439
  }
@@ -466,7 +484,11 @@ var AnyRouterChatLanguageModel = class {
466
484
  fetch: this.config.fetch
467
485
  });
468
486
  const toolCallAccumulator = {};
469
- const state = { activeTextId: null, metadataEmitted: false };
487
+ const state = {
488
+ activeTextId: null,
489
+ activeReasoningId: null,
490
+ metadataEmitted: false
491
+ };
470
492
  const selfModelId = this.modelId;
471
493
  const transformStream = new TransformStream({
472
494
  start(controller) {
@@ -482,6 +504,9 @@ var AnyRouterChatLanguageModel = class {
482
504
  emitResponseMetadata(chunk, state, selfModelId, controller);
483
505
  const delta = choice?.delta;
484
506
  if (delta) {
507
+ if (typeof delta.reasoning_content === "string" && delta.reasoning_content.length > 0) {
508
+ emitReasoningDelta(delta.reasoning_content, state, controller);
509
+ }
485
510
  if (typeof delta.content === "string" && delta.content.length > 0) {
486
511
  emitTextDelta(delta.content, state, controller);
487
512
  }
@@ -494,6 +519,7 @@ var AnyRouterChatLanguageModel = class {
494
519
  }
495
520
  },
496
521
  flush(controller) {
522
+ closeReasoning(state, controller);
497
523
  if (state.activeTextId !== null) {
498
524
  controller.enqueue({ type: "text-end", id: state.activeTextId });
499
525
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anyr/ai-sdk-provider",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "The AnyRouter provider for the Vercel AI SDK — call every AnyRouter model through `createAnyRouter`.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -61,15 +61,17 @@
61
61
  "access": "public"
62
62
  },
63
63
  "dependencies": {
64
- "@anyr/sdk": "^0.1.1",
65
- "@ai-sdk/provider": "^3.0.10",
66
- "@ai-sdk/provider-utils": "^4.0.0"
64
+ "@anyr/sdk": "^0.1.1"
67
65
  },
68
66
  "peerDependencies": {
69
- "ai": "^6.0.0",
67
+ "@ai-sdk/provider": "^3.0.10 || ^4.0.0-beta",
68
+ "@ai-sdk/provider-utils": "^4.0.0 || ^5.0.0-beta",
69
+ "ai": "^6.0.0 || ^7.0.0-beta",
70
70
  "zod": "^3.25.0 || ^4.0.0"
71
71
  },
72
72
  "devDependencies": {
73
+ "@ai-sdk/provider": "^3.0.10",
74
+ "@ai-sdk/provider-utils": "^4.0.0",
73
75
  "@types/node": "^24.0.0",
74
76
  "ai": "^6.0.159",
75
77
  "zod": "^4.4.3"