@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.
package/dist/index.js CHANGED
@@ -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/index.ts
60
66
  var index_exports = {};
@@ -2349,6 +2355,54 @@ function createFinishReason(unified, raw) {
2349
2355
  return { unified, raw };
2350
2356
  }
2351
2357
 
2358
+ // src/utils/reasoning-details-duplicate-tracker.ts
2359
+ var _seenKeys;
2360
+ var ReasoningDetailsDuplicateTracker = class {
2361
+ constructor() {
2362
+ __privateAdd(this, _seenKeys, /* @__PURE__ */ new Set());
2363
+ }
2364
+ /**
2365
+ * Attempts to track a detail.
2366
+ * Returns true if this is a NEW detail (not seen before and has valid key),
2367
+ * false if it was skipped (no valid key) or already seen (duplicate).
2368
+ */
2369
+ upsert(detail) {
2370
+ const key = this.getCanonicalKey(detail);
2371
+ if (key === null) {
2372
+ return false;
2373
+ }
2374
+ if (__privateGet(this, _seenKeys).has(key)) {
2375
+ return false;
2376
+ }
2377
+ __privateGet(this, _seenKeys).add(key);
2378
+ return true;
2379
+ }
2380
+ getCanonicalKey(detail) {
2381
+ switch (detail.type) {
2382
+ case "reasoning.summary" /* Summary */:
2383
+ return detail.summary;
2384
+ case "reasoning.encrypted" /* Encrypted */:
2385
+ if (detail.id) {
2386
+ return detail.id;
2387
+ }
2388
+ return detail.data;
2389
+ case "reasoning.text" /* Text */: {
2390
+ if (detail.text) {
2391
+ return detail.text;
2392
+ }
2393
+ if (detail.signature) {
2394
+ return detail.signature;
2395
+ }
2396
+ return null;
2397
+ }
2398
+ default: {
2399
+ return null;
2400
+ }
2401
+ }
2402
+ }
2403
+ };
2404
+ _seenKeys = new WeakMap();
2405
+
2352
2406
  // src/types/openrouter-chat-completions-input.ts
2353
2407
  var OPENROUTER_AUDIO_FORMATS = [
2354
2408
  "wav",
@@ -2480,6 +2534,7 @@ function getCacheControl(providerMetadata) {
2480
2534
  function convertToOpenRouterChatMessages(prompt) {
2481
2535
  var _a16, _b16, _c, _d, _e, _f, _g, _h;
2482
2536
  const messages = [];
2537
+ const reasoningDetailsTracker = new ReasoningDetailsDuplicateTracker();
2483
2538
  for (const { role, content, providerOptions } of prompt) {
2484
2539
  switch (role) {
2485
2540
  case "system": {
@@ -2622,7 +2677,17 @@ function convertToOpenRouterChatMessages(prompt) {
2622
2677
  const parsedProviderOptions = OpenRouterProviderOptionsSchema.safeParse(providerOptions);
2623
2678
  const messageReasoningDetails = parsedProviderOptions.success ? (_e = (_d = parsedProviderOptions.data) == null ? void 0 : _d.openrouter) == null ? void 0 : _e.reasoning_details : void 0;
2624
2679
  const messageAnnotations = parsedProviderOptions.success ? (_g = (_f = parsedProviderOptions.data) == null ? void 0 : _f.openrouter) == null ? void 0 : _g.annotations : void 0;
2625
- const finalReasoningDetails = messageReasoningDetails && Array.isArray(messageReasoningDetails) && messageReasoningDetails.length > 0 ? messageReasoningDetails : findFirstReasoningDetails(content);
2680
+ const candidateReasoningDetails = messageReasoningDetails && Array.isArray(messageReasoningDetails) && messageReasoningDetails.length > 0 ? messageReasoningDetails : findFirstReasoningDetails(content);
2681
+ let finalReasoningDetails;
2682
+ if (candidateReasoningDetails && candidateReasoningDetails.length > 0) {
2683
+ const uniqueDetails = [];
2684
+ for (const detail of candidateReasoningDetails) {
2685
+ if (reasoningDetailsTracker.upsert(detail)) {
2686
+ uniqueDetails.push(detail);
2687
+ }
2688
+ }
2689
+ finalReasoningDetails = uniqueDetails.length > 0 ? uniqueDetails : void 0;
2690
+ }
2626
2691
  messages.push({
2627
2692
  role: "assistant",
2628
2693
  content: text,
@@ -4440,7 +4505,7 @@ function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
4440
4505
  }
4441
4506
 
4442
4507
  // src/version.ts
4443
- var VERSION2 = false ? "0.0.0-test" : "2.1.0";
4508
+ var VERSION2 = false ? "0.0.0-test" : "2.1.1";
4444
4509
 
4445
4510
  // src/provider.ts
4446
4511
  function createOpenRouter(options = {}) {