@openrouter/ai-sdk-provider 2.1.0 → 2.1.1

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.
@@ -4,6 +4,9 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
4
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
6
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __typeError = (msg) => {
8
+ throw TypeError(msg);
9
+ };
7
10
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
11
  var __spreadValues = (a, b) => {
9
12
  for (var prop in b || (b = {}))
@@ -29,6 +32,9 @@ var __objRest = (source, exclude) => {
29
32
  }
30
33
  return target;
31
34
  };
35
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
36
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
37
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
32
38
 
33
39
  // node_modules/.pnpm/@ai-sdk+provider@3.0.0/node_modules/@ai-sdk/provider/dist/index.mjs
34
40
  var marker = "vercel.ai.error";
@@ -2281,6 +2287,54 @@ function createFinishReason(unified, raw) {
2281
2287
  return { unified, raw };
2282
2288
  }
2283
2289
 
2290
+ // src/utils/reasoning-details-duplicate-tracker.ts
2291
+ var _seenKeys;
2292
+ var ReasoningDetailsDuplicateTracker = class {
2293
+ constructor() {
2294
+ __privateAdd(this, _seenKeys, /* @__PURE__ */ new Set());
2295
+ }
2296
+ /**
2297
+ * Attempts to track a detail.
2298
+ * Returns true if this is a NEW detail (not seen before and has valid key),
2299
+ * false if it was skipped (no valid key) or already seen (duplicate).
2300
+ */
2301
+ upsert(detail) {
2302
+ const key = this.getCanonicalKey(detail);
2303
+ if (key === null) {
2304
+ return false;
2305
+ }
2306
+ if (__privateGet(this, _seenKeys).has(key)) {
2307
+ return false;
2308
+ }
2309
+ __privateGet(this, _seenKeys).add(key);
2310
+ return true;
2311
+ }
2312
+ getCanonicalKey(detail) {
2313
+ switch (detail.type) {
2314
+ case "reasoning.summary" /* Summary */:
2315
+ return detail.summary;
2316
+ case "reasoning.encrypted" /* Encrypted */:
2317
+ if (detail.id) {
2318
+ return detail.id;
2319
+ }
2320
+ return detail.data;
2321
+ case "reasoning.text" /* Text */: {
2322
+ if (detail.text) {
2323
+ return detail.text;
2324
+ }
2325
+ if (detail.signature) {
2326
+ return detail.signature;
2327
+ }
2328
+ return null;
2329
+ }
2330
+ default: {
2331
+ return null;
2332
+ }
2333
+ }
2334
+ }
2335
+ };
2336
+ _seenKeys = new WeakMap();
2337
+
2284
2338
  // src/types/openrouter-chat-completions-input.ts
2285
2339
  var OPENROUTER_AUDIO_FORMATS = [
2286
2340
  "wav",
@@ -2412,6 +2466,7 @@ function getCacheControl(providerMetadata) {
2412
2466
  function convertToOpenRouterChatMessages(prompt) {
2413
2467
  var _a16, _b16, _c, _d, _e, _f, _g, _h;
2414
2468
  const messages = [];
2469
+ const reasoningDetailsTracker = new ReasoningDetailsDuplicateTracker();
2415
2470
  for (const { role, content, providerOptions } of prompt) {
2416
2471
  switch (role) {
2417
2472
  case "system": {
@@ -2554,7 +2609,17 @@ function convertToOpenRouterChatMessages(prompt) {
2554
2609
  const parsedProviderOptions = OpenRouterProviderOptionsSchema.safeParse(providerOptions);
2555
2610
  const messageReasoningDetails = parsedProviderOptions.success ? (_e = (_d = parsedProviderOptions.data) == null ? void 0 : _d.openrouter) == null ? void 0 : _e.reasoning_details : void 0;
2556
2611
  const messageAnnotations = parsedProviderOptions.success ? (_g = (_f = parsedProviderOptions.data) == null ? void 0 : _f.openrouter) == null ? void 0 : _g.annotations : void 0;
2557
- const finalReasoningDetails = messageReasoningDetails && Array.isArray(messageReasoningDetails) && messageReasoningDetails.length > 0 ? messageReasoningDetails : findFirstReasoningDetails(content);
2612
+ const candidateReasoningDetails = messageReasoningDetails && Array.isArray(messageReasoningDetails) && messageReasoningDetails.length > 0 ? messageReasoningDetails : findFirstReasoningDetails(content);
2613
+ let finalReasoningDetails;
2614
+ if (candidateReasoningDetails && candidateReasoningDetails.length > 0) {
2615
+ const uniqueDetails = [];
2616
+ for (const detail of candidateReasoningDetails) {
2617
+ if (reasoningDetailsTracker.upsert(detail)) {
2618
+ uniqueDetails.push(detail);
2619
+ }
2620
+ }
2621
+ finalReasoningDetails = uniqueDetails.length > 0 ? uniqueDetails : void 0;
2622
+ }
2558
2623
  messages.push({
2559
2624
  role: "assistant",
2560
2625
  content: text,