@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/dist/index.mjs CHANGED
@@ -1320,6 +1320,7 @@ var OpenRouterChatLanguageModel = class {
1320
1320
  tools,
1321
1321
  toolChoice
1322
1322
  }) {
1323
+ var _a15;
1323
1324
  const baseArgs = __spreadValues(__spreadValues({
1324
1325
  // model id:
1325
1326
  model: this.modelId,
@@ -1347,9 +1348,18 @@ var OpenRouterChatLanguageModel = class {
1347
1348
  reasoning: this.settings.reasoning,
1348
1349
  usage: this.settings.usage
1349
1350
  }, this.config.extraBody), this.settings.extraBody);
1350
- if ((responseFormat == null ? void 0 : responseFormat.type) === "json") {
1351
+ if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
1351
1352
  return __spreadProps(__spreadValues({}, baseArgs), {
1352
- response_format: { type: "json_object" }
1353
+ response_format: {
1354
+ type: "json_schema",
1355
+ json_schema: __spreadValues({
1356
+ schema: responseFormat.schema,
1357
+ strict: true,
1358
+ name: (_a15 = responseFormat.name) != null ? _a15 : "response"
1359
+ }, responseFormat.description && {
1360
+ description: responseFormat.description
1361
+ })
1362
+ }
1353
1363
  });
1354
1364
  }
1355
1365
  if (tools && tools.length > 0) {
@@ -1595,21 +1605,6 @@ var OpenRouterChatLanguageModel = class {
1595
1605
  return;
1596
1606
  }
1597
1607
  const delta = choice.delta;
1598
- if (delta.content != null) {
1599
- if (!textStarted) {
1600
- textId = openrouterResponseId || generateId();
1601
- controller.enqueue({
1602
- type: "text-start",
1603
- id: textId
1604
- });
1605
- textStarted = true;
1606
- }
1607
- controller.enqueue({
1608
- type: "text-delta",
1609
- delta: delta.content,
1610
- id: textId || generateId()
1611
- });
1612
- }
1613
1608
  const emitReasoningChunk = (chunkText) => {
1614
1609
  if (!reasoningStarted) {
1615
1610
  reasoningId = openrouterResponseId || generateId();
@@ -1625,9 +1620,6 @@ var OpenRouterChatLanguageModel = class {
1625
1620
  id: reasoningId || generateId()
1626
1621
  });
1627
1622
  };
1628
- if (delta.reasoning != null) {
1629
- emitReasoningChunk(delta.reasoning);
1630
- }
1631
1623
  if (delta.reasoning_details && delta.reasoning_details.length > 0) {
1632
1624
  for (const detail of delta.reasoning_details) {
1633
1625
  switch (detail.type) {
@@ -1655,6 +1647,23 @@ var OpenRouterChatLanguageModel = class {
1655
1647
  }
1656
1648
  }
1657
1649
  }
1650
+ } else if (delta.reasoning != null) {
1651
+ emitReasoningChunk(delta.reasoning);
1652
+ }
1653
+ if (delta.content != null) {
1654
+ if (!textStarted) {
1655
+ textId = openrouterResponseId || generateId();
1656
+ controller.enqueue({
1657
+ type: "text-start",
1658
+ id: textId
1659
+ });
1660
+ textStarted = true;
1661
+ }
1662
+ controller.enqueue({
1663
+ type: "text-delta",
1664
+ delta: delta.content,
1665
+ id: textId || generateId()
1666
+ });
1658
1667
  }
1659
1668
  if (delta.tool_calls != null) {
1660
1669
  for (const toolCallDelta of delta.tool_calls) {
@@ -1754,7 +1763,7 @@ var OpenRouterChatLanguageModel = class {
1754
1763
  var _a16;
1755
1764
  if (finishReason === "tool-calls") {
1756
1765
  for (const toolCall of toolCalls) {
1757
- if (!toolCall.sent) {
1766
+ if (toolCall && !toolCall.sent) {
1758
1767
  controller.enqueue({
1759
1768
  type: "tool-call",
1760
1769
  toolCallId: (_a16 = toolCall.id) != null ? _a16 : generateId(),