@openrouter/ai-sdk-provider 1.0.0-beta.5 → 1.0.0-beta.7

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
@@ -1,6 +1,6 @@
1
1
  # OpenRouter Provider for Vercel AI SDK
2
2
 
3
- The [OpenRouter](https://openrouter.ai/) provider for the [Vercel AI SDK](https://sdk.vercel.ai/docs) gives access to over 300 large language model on the OpenRouter chat and completion APIs.
3
+ The [OpenRouter](https://openrouter.ai/) provider for the [Vercel AI SDK](https://sdk.vercel.ai/docs) gives access to over 300 large language models on the OpenRouter chat and completion APIs.
4
4
 
5
5
  ## Setup
6
6
 
@@ -126,7 +126,7 @@ await streamText({
126
126
  {
127
127
  role: 'system',
128
128
  content:
129
- 'You are a podcast summary assistant. You are detail oriented and critical about the content.',
129
+ 'You are a podcast summary assistant. You are detail-oriented and critical about the content.',
130
130
  },
131
131
  {
132
132
  role: 'user',
package/dist/index.d.mts CHANGED
@@ -21,7 +21,7 @@ type OpenRouterChatSettings = {
21
21
  /**
22
22
  Return the log probabilities of the tokens. Including logprobs will increase
23
23
  the response size and can slow down response times. However, it can
24
- be useful to better understand how the model is behaving.
24
+ be useful to understand better how the model is behaving.
25
25
 
26
26
  Setting to true will return the log probabilities of the tokens that
27
27
  were generated.
@@ -277,7 +277,7 @@ declare class OpenRouter {
277
277
  */
278
278
  readonly baseURL: string;
279
279
  /**
280
- API key that is being send using the `Authorization` header.
280
+ API key that is being sent using the `Authorization` header.
281
281
  It defaults to the `OPENROUTER_API_KEY` environment variable.
282
282
  */
283
283
  readonly apiKey?: string;
package/dist/index.d.ts CHANGED
@@ -21,7 +21,7 @@ type OpenRouterChatSettings = {
21
21
  /**
22
22
  Return the log probabilities of the tokens. Including logprobs will increase
23
23
  the response size and can slow down response times. However, it can
24
- be useful to better understand how the model is behaving.
24
+ be useful to understand better how the model is behaving.
25
25
 
26
26
  Setting to true will return the log probabilities of the tokens that
27
27
  were generated.
@@ -277,7 +277,7 @@ declare class OpenRouter {
277
277
  */
278
278
  readonly baseURL: string;
279
279
  /**
280
- API key that is being send using the `Authorization` header.
280
+ API key that is being sent using the `Authorization` header.
281
281
  It defaults to the `OPENROUTER_API_KEY` environment variable.
282
282
  */
283
283
  readonly apiKey?: string;
package/dist/index.js CHANGED
@@ -1355,6 +1355,7 @@ var OpenRouterChatLanguageModel = class {
1355
1355
  tools,
1356
1356
  toolChoice
1357
1357
  }) {
1358
+ var _a15;
1358
1359
  const baseArgs = __spreadValues(__spreadValues({
1359
1360
  // model id:
1360
1361
  model: this.modelId,
@@ -1382,9 +1383,18 @@ var OpenRouterChatLanguageModel = class {
1382
1383
  reasoning: this.settings.reasoning,
1383
1384
  usage: this.settings.usage
1384
1385
  }, this.config.extraBody), this.settings.extraBody);
1385
- if ((responseFormat == null ? void 0 : responseFormat.type) === "json") {
1386
+ if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
1386
1387
  return __spreadProps(__spreadValues({}, baseArgs), {
1387
- response_format: { type: "json_object" }
1388
+ response_format: {
1389
+ type: "json_schema",
1390
+ json_schema: __spreadValues({
1391
+ schema: responseFormat.schema,
1392
+ strict: true,
1393
+ name: (_a15 = responseFormat.name) != null ? _a15 : "response"
1394
+ }, responseFormat.description && {
1395
+ description: responseFormat.description
1396
+ })
1397
+ }
1388
1398
  });
1389
1399
  }
1390
1400
  if (tools && tools.length > 0) {
@@ -1630,21 +1640,6 @@ var OpenRouterChatLanguageModel = class {
1630
1640
  return;
1631
1641
  }
1632
1642
  const delta = choice.delta;
1633
- if (delta.content != null) {
1634
- if (!textStarted) {
1635
- textId = openrouterResponseId || generateId();
1636
- controller.enqueue({
1637
- type: "text-start",
1638
- id: textId
1639
- });
1640
- textStarted = true;
1641
- }
1642
- controller.enqueue({
1643
- type: "text-delta",
1644
- delta: delta.content,
1645
- id: textId || generateId()
1646
- });
1647
- }
1648
1643
  const emitReasoningChunk = (chunkText) => {
1649
1644
  if (!reasoningStarted) {
1650
1645
  reasoningId = openrouterResponseId || generateId();
@@ -1660,9 +1655,6 @@ var OpenRouterChatLanguageModel = class {
1660
1655
  id: reasoningId || generateId()
1661
1656
  });
1662
1657
  };
1663
- if (delta.reasoning != null) {
1664
- emitReasoningChunk(delta.reasoning);
1665
- }
1666
1658
  if (delta.reasoning_details && delta.reasoning_details.length > 0) {
1667
1659
  for (const detail of delta.reasoning_details) {
1668
1660
  switch (detail.type) {
@@ -1690,6 +1682,23 @@ var OpenRouterChatLanguageModel = class {
1690
1682
  }
1691
1683
  }
1692
1684
  }
1685
+ } else if (delta.reasoning != null) {
1686
+ emitReasoningChunk(delta.reasoning);
1687
+ }
1688
+ if (delta.content != null) {
1689
+ if (!textStarted) {
1690
+ textId = openrouterResponseId || generateId();
1691
+ controller.enqueue({
1692
+ type: "text-start",
1693
+ id: textId
1694
+ });
1695
+ textStarted = true;
1696
+ }
1697
+ controller.enqueue({
1698
+ type: "text-delta",
1699
+ delta: delta.content,
1700
+ id: textId || generateId()
1701
+ });
1693
1702
  }
1694
1703
  if (delta.tool_calls != null) {
1695
1704
  for (const toolCallDelta of delta.tool_calls) {
@@ -1789,7 +1798,7 @@ var OpenRouterChatLanguageModel = class {
1789
1798
  var _a16;
1790
1799
  if (finishReason === "tool-calls") {
1791
1800
  for (const toolCall of toolCalls) {
1792
- if (!toolCall.sent) {
1801
+ if (toolCall && !toolCall.sent) {
1793
1802
  controller.enqueue({
1794
1803
  type: "tool-call",
1795
1804
  toolCallId: (_a16 = toolCall.id) != null ? _a16 : generateId(),