@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.
@@ -9,6 +9,9 @@ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
9
  var __getProtoOf = Object.getPrototypeOf;
10
10
  var __hasOwnProp = Object.prototype.hasOwnProperty;
11
11
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __typeError = (msg) => {
13
+ throw TypeError(msg);
14
+ };
12
15
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
16
  var __spreadValues = (a, b) => {
14
17
  for (var prop in b || (b = {}))
@@ -55,6 +58,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
55
58
  mod
56
59
  ));
57
60
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
61
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
62
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
63
+ 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);
58
64
 
59
65
  // src/internal/index.ts
60
66
  var index_exports = {};
@@ -2315,6 +2321,54 @@ function createFinishReason(unified, raw) {
2315
2321
  return { unified, raw };
2316
2322
  }
2317
2323
 
2324
+ // src/utils/reasoning-details-duplicate-tracker.ts
2325
+ var _seenKeys;
2326
+ var ReasoningDetailsDuplicateTracker = class {
2327
+ constructor() {
2328
+ __privateAdd(this, _seenKeys, /* @__PURE__ */ new Set());
2329
+ }
2330
+ /**
2331
+ * Attempts to track a detail.
2332
+ * Returns true if this is a NEW detail (not seen before and has valid key),
2333
+ * false if it was skipped (no valid key) or already seen (duplicate).
2334
+ */
2335
+ upsert(detail) {
2336
+ const key = this.getCanonicalKey(detail);
2337
+ if (key === null) {
2338
+ return false;
2339
+ }
2340
+ if (__privateGet(this, _seenKeys).has(key)) {
2341
+ return false;
2342
+ }
2343
+ __privateGet(this, _seenKeys).add(key);
2344
+ return true;
2345
+ }
2346
+ getCanonicalKey(detail) {
2347
+ switch (detail.type) {
2348
+ case "reasoning.summary" /* Summary */:
2349
+ return detail.summary;
2350
+ case "reasoning.encrypted" /* Encrypted */:
2351
+ if (detail.id) {
2352
+ return detail.id;
2353
+ }
2354
+ return detail.data;
2355
+ case "reasoning.text" /* Text */: {
2356
+ if (detail.text) {
2357
+ return detail.text;
2358
+ }
2359
+ if (detail.signature) {
2360
+ return detail.signature;
2361
+ }
2362
+ return null;
2363
+ }
2364
+ default: {
2365
+ return null;
2366
+ }
2367
+ }
2368
+ }
2369
+ };
2370
+ _seenKeys = new WeakMap();
2371
+
2318
2372
  // src/types/openrouter-chat-completions-input.ts
2319
2373
  var OPENROUTER_AUDIO_FORMATS = [
2320
2374
  "wav",
@@ -2446,6 +2500,7 @@ function getCacheControl(providerMetadata) {
2446
2500
  function convertToOpenRouterChatMessages(prompt) {
2447
2501
  var _a16, _b16, _c, _d, _e, _f, _g, _h;
2448
2502
  const messages = [];
2503
+ const reasoningDetailsTracker = new ReasoningDetailsDuplicateTracker();
2449
2504
  for (const { role, content, providerOptions } of prompt) {
2450
2505
  switch (role) {
2451
2506
  case "system": {
@@ -2588,7 +2643,17 @@ function convertToOpenRouterChatMessages(prompt) {
2588
2643
  const parsedProviderOptions = OpenRouterProviderOptionsSchema.safeParse(providerOptions);
2589
2644
  const messageReasoningDetails = parsedProviderOptions.success ? (_e = (_d = parsedProviderOptions.data) == null ? void 0 : _d.openrouter) == null ? void 0 : _e.reasoning_details : void 0;
2590
2645
  const messageAnnotations = parsedProviderOptions.success ? (_g = (_f = parsedProviderOptions.data) == null ? void 0 : _f.openrouter) == null ? void 0 : _g.annotations : void 0;
2591
- const finalReasoningDetails = messageReasoningDetails && Array.isArray(messageReasoningDetails) && messageReasoningDetails.length > 0 ? messageReasoningDetails : findFirstReasoningDetails(content);
2646
+ const candidateReasoningDetails = messageReasoningDetails && Array.isArray(messageReasoningDetails) && messageReasoningDetails.length > 0 ? messageReasoningDetails : findFirstReasoningDetails(content);
2647
+ let finalReasoningDetails;
2648
+ if (candidateReasoningDetails && candidateReasoningDetails.length > 0) {
2649
+ const uniqueDetails = [];
2650
+ for (const detail of candidateReasoningDetails) {
2651
+ if (reasoningDetailsTracker.upsert(detail)) {
2652
+ uniqueDetails.push(detail);
2653
+ }
2654
+ }
2655
+ finalReasoningDetails = uniqueDetails.length > 0 ? uniqueDetails : void 0;
2656
+ }
2592
2657
  messages.push({
2593
2658
  role: "assistant",
2594
2659
  content: text,