@openrouter/ai-sdk-provider 2.3.2 → 2.3.3
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.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +32 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -9
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +1 -0
- package/dist/internal/index.d.ts +1 -0
- package/dist/internal/index.js +31 -8
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +31 -8
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/internal/index.mjs
CHANGED
|
@@ -2148,11 +2148,13 @@ function isDefinedOrNotNull(value) {
|
|
|
2148
2148
|
var ReasoningFormat = /* @__PURE__ */ ((ReasoningFormat2) => {
|
|
2149
2149
|
ReasoningFormat2["Unknown"] = "unknown";
|
|
2150
2150
|
ReasoningFormat2["OpenAIResponsesV1"] = "openai-responses-v1";
|
|
2151
|
+
ReasoningFormat2["AzureOpenAIResponsesV1"] = "azure-openai-responses-v1";
|
|
2151
2152
|
ReasoningFormat2["XAIResponsesV1"] = "xai-responses-v1";
|
|
2152
2153
|
ReasoningFormat2["AnthropicClaudeV1"] = "anthropic-claude-v1";
|
|
2153
2154
|
ReasoningFormat2["GoogleGeminiV1"] = "google-gemini-v1";
|
|
2154
2155
|
return ReasoningFormat2;
|
|
2155
2156
|
})(ReasoningFormat || {});
|
|
2157
|
+
var DEFAULT_REASONING_FORMAT = "anthropic-claude-v1" /* AnthropicClaudeV1 */;
|
|
2156
2158
|
|
|
2157
2159
|
// src/schemas/reasoning-details.ts
|
|
2158
2160
|
var CommonReasoningDetailSchema = z.object({
|
|
@@ -2305,7 +2307,11 @@ var OpenRouterProviderMetadataSchema = z3.object({
|
|
|
2305
2307
|
}).catchall(z3.any());
|
|
2306
2308
|
var OpenRouterProviderOptionsSchema = z3.object({
|
|
2307
2309
|
openrouter: z3.object({
|
|
2308
|
-
|
|
2310
|
+
// Use ReasoningDetailArraySchema (with unknown fallback) instead of
|
|
2311
|
+
// z.array(ReasoningDetailUnionSchema) so that a single malformed entry
|
|
2312
|
+
// (e.g., a future format not yet in the enum) is individually dropped
|
|
2313
|
+
// rather than causing the entire array to fail parsing.
|
|
2314
|
+
reasoning_details: ReasoningDetailArraySchema.optional(),
|
|
2309
2315
|
annotations: z3.array(FileAnnotationSchema).optional()
|
|
2310
2316
|
}).optional()
|
|
2311
2317
|
}).optional();
|
|
@@ -2717,8 +2723,24 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
2717
2723
|
const candidateReasoningDetails = messageReasoningDetails && Array.isArray(messageReasoningDetails) && messageReasoningDetails.length > 0 ? messageReasoningDetails : findFirstReasoningDetails(content);
|
|
2718
2724
|
let finalReasoningDetails;
|
|
2719
2725
|
if (candidateReasoningDetails && candidateReasoningDetails.length > 0) {
|
|
2726
|
+
const validDetails = candidateReasoningDetails.filter((detail) => {
|
|
2727
|
+
var _a17;
|
|
2728
|
+
if (detail.type !== "reasoning.text" /* Text */) {
|
|
2729
|
+
return true;
|
|
2730
|
+
}
|
|
2731
|
+
const format = (_a17 = detail.format) != null ? _a17 : DEFAULT_REASONING_FORMAT;
|
|
2732
|
+
if (format !== "anthropic-claude-v1" /* AnthropicClaudeV1 */) {
|
|
2733
|
+
return true;
|
|
2734
|
+
}
|
|
2735
|
+
return !!detail.signature;
|
|
2736
|
+
});
|
|
2737
|
+
if (validDetails.length < candidateReasoningDetails.length) {
|
|
2738
|
+
console.warn(
|
|
2739
|
+
"[openrouter] Some reasoning_details entries were removed because they were missing signatures. See https://github.com/OpenRouterTeam/ai-sdk-provider/issues/423 for more details."
|
|
2740
|
+
);
|
|
2741
|
+
}
|
|
2720
2742
|
const uniqueDetails = [];
|
|
2721
|
-
for (const detail of
|
|
2743
|
+
for (const detail of validDetails) {
|
|
2722
2744
|
if (reasoningDetailsTracker.upsert(detail)) {
|
|
2723
2745
|
uniqueDetails.push(detail);
|
|
2724
2746
|
}
|
|
@@ -2888,13 +2910,14 @@ function filenameFromUrl(url) {
|
|
|
2888
2910
|
}
|
|
2889
2911
|
}
|
|
2890
2912
|
function findFirstReasoningDetails(content) {
|
|
2891
|
-
var _a16, _b16, _c;
|
|
2913
|
+
var _a16, _b16, _c, _d;
|
|
2892
2914
|
for (const part of content) {
|
|
2893
2915
|
if (part.type === "tool-call") {
|
|
2894
|
-
const
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2916
|
+
const parsed = OpenRouterProviderOptionsSchema.safeParse(
|
|
2917
|
+
part.providerOptions
|
|
2918
|
+
);
|
|
2919
|
+
if (parsed.success && ((_b16 = (_a16 = parsed.data) == null ? void 0 : _a16.openrouter) == null ? void 0 : _b16.reasoning_details) && parsed.data.openrouter.reasoning_details.length > 0) {
|
|
2920
|
+
return parsed.data.openrouter.reasoning_details;
|
|
2898
2921
|
}
|
|
2899
2922
|
}
|
|
2900
2923
|
}
|
|
@@ -2903,7 +2926,7 @@ function findFirstReasoningDetails(content) {
|
|
|
2903
2926
|
const parsed = OpenRouterProviderOptionsSchema.safeParse(
|
|
2904
2927
|
part.providerOptions
|
|
2905
2928
|
);
|
|
2906
|
-
if (parsed.success && ((
|
|
2929
|
+
if (parsed.success && ((_d = (_c = parsed.data) == null ? void 0 : _c.openrouter) == null ? void 0 : _d.reasoning_details) && parsed.data.openrouter.reasoning_details.length > 0) {
|
|
2907
2930
|
return parsed.data.openrouter.reasoning_details;
|
|
2908
2931
|
}
|
|
2909
2932
|
}
|