@dereekb/openrouter 14.7.0 → 14.9.0

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/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { filterUndefinedValues, mergeObjects, arrayToMap } from '@dereekb/util';
1
+ import { filterUndefinedValues, arrayToMap } from '@dereekb/util';
2
2
  import { callModel } from '@openrouter/sdk/funcs/call-model';
3
3
  export { callModel } from '@openrouter/sdk/funcs/call-model';
4
4
  import { responsesSend } from '@openrouter/sdk/funcs/responsesSend';
@@ -7,6 +7,8 @@ import { unsentResultsToAPIFormat } from '@openrouter/sdk/lib/conversation-state
7
7
  export { unsentResultsToAPIFormat } from '@openrouter/sdk/lib/conversation-state';
8
8
  import { embeddingsGenerate } from '@openrouter/sdk/funcs/embeddingsGenerate';
9
9
  export { embeddingsGenerate } from '@openrouter/sdk/funcs/embeddingsGenerate';
10
+ import { systemOneCreate } from '@openrouter/sdk/funcs/systemOneCreate';
11
+ export { systemOneCreate } from '@openrouter/sdk/funcs/systemOneCreate';
10
12
  import { generationsGetGeneration } from '@openrouter/sdk/funcs/generationsGetGeneration';
11
13
  export { generationsGetGeneration } from '@openrouter/sdk/funcs/generationsGetGeneration';
12
14
  import { generationsListGenerationContent } from '@openrouter/sdk/funcs/generationsListGenerationContent';
@@ -20,6 +22,8 @@ import { stepCountIs } from '@openrouter/sdk/lib/stop-conditions';
20
22
  export { finishReasonIs, hasToolCall, maxCost, maxTokensUsed, stepCountIs } from '@openrouter/sdk/lib/stop-conditions';
21
23
  import { isManualTool } from '@openrouter/sdk/lib/tool-types';
22
24
  export { ToolType, isManualTool } from '@openrouter/sdk/lib/tool-types';
25
+ import { o as isOpenRouterSystemOneModelId, F as readOpenRouterDecisionAnswers, k as OpenRouterDecisionAnswerFaultError, C as openRouterRunUsageFromDecisionsUsage, I as validateOpenRouterDecisionRequest, l as OpenRouterDecisionDeclarationError, G as splitOpenRouterDecisionModelConfig, v as openRouterDecisionRequestBody, q as mergeOpenRouterModelConfig } from './openrouter.decision.esm.js';
26
+ export { D as DEFAULT_OPENROUTER_PDF_PARSER_ENGINE, a as DEFAULT_OPENROUTER_SYSTEM_ONE_MODEL_ID, O as OPENROUTER_DECISION_CHOICE_OPTIONS_MAX, b as OPENROUTER_DECISION_CONFIDENCE_HIGH, c as OPENROUTER_DECISION_CONFIDENCE_MEDIUM, d as OPENROUTER_DECISION_DISTRIBUTION_SUM_TOLERANCE, e as OPENROUTER_DECISION_SCORE_LEVELS_MAX, f as OPENROUTER_DECISION_SCORE_LEVELS_MIN, g as OPENROUTER_JEV_1_13_MODEL_ID, h as OPENROUTER_JEV_LATEST_MODEL_ID, i as OPENROUTER_JEV_PREVIEW_MODEL_ID, j as OPENROUTER_SYSTEM_ONE_MODEL_NAMESPACE, m as asOpenRouterDecisionConfidenceBand, n as isBlankOpenRouterDecisionEntry, p as mapOpenRouterDecisionChoiceRows, r as openRouterChoiceQuestion, s as openRouterDecisionChoiceOptionNames, t as openRouterDecisionChoiceRanking, u as openRouterDecisionRequest, w as openRouterDecisionStatePaths, x as openRouterDecisionWireQuestion, y as openRouterFileParserPlugin, z as openRouterFileSearchTool, A as openRouterNoulQuestion, B as openRouterProviderPinnedTo, E as openRouterScoreQuestion, H as validateOpenRouterDecisionQuestions, J as validateOpenRouterModelConfig } from './openrouter.decision.esm.js';
23
27
 
24
28
  function _array_like_to_array$1(arr, len) {
25
29
  if (len == null || len > arr.length) len = arr.length;
@@ -29,7 +33,11 @@ function _array_like_to_array$1(arr, len) {
29
33
  function _array_without_holes$1(arr) {
30
34
  if (Array.isArray(arr)) return _array_like_to_array$1(arr);
31
35
  }
32
- function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
36
+ function _assert_this_initialized(self) {
37
+ if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
38
+ return self;
39
+ }
40
+ function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
33
41
  try {
34
42
  var info = gen[key](arg);
35
43
  var value = info.value;
@@ -40,21 +48,44 @@ function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
40
48
  if (info.done) resolve(value);
41
49
  else Promise.resolve(value).then(_next, _throw);
42
50
  }
43
- function _async_to_generator$2(fn) {
51
+ function _async_to_generator$3(fn) {
44
52
  return function() {
45
53
  var self = this, args = arguments;
46
54
  return new Promise(function(resolve, reject) {
47
55
  var gen = fn.apply(self, args);
48
56
  function _next(value) {
49
- asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
57
+ asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
50
58
  }
51
59
  function _throw(err) {
52
- asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
60
+ asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
53
61
  }
54
62
  _next(undefined);
55
63
  });
56
64
  };
57
65
  }
66
+ function _call_super(_this, derived, args) {
67
+ derived = _get_prototype_of(derived);
68
+ return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
69
+ }
70
+ function _class_call_check(instance, Constructor) {
71
+ if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
72
+ }
73
+ function _construct(Parent, args, Class) {
74
+ if (_is_native_reflect_construct()) _construct = Reflect.construct;
75
+ else {
76
+ _construct = function construct(Parent, args, Class) {
77
+ var a = [
78
+ null
79
+ ];
80
+ a.push.apply(a, args);
81
+ var Constructor = Function.bind.apply(Parent, a);
82
+ var instance = new Constructor();
83
+ if (Class) _set_prototype_of(instance, Class.prototype);
84
+ return instance;
85
+ };
86
+ }
87
+ return _construct.apply(null, arguments);
88
+ }
58
89
  function _define_property$2(obj, key, value) {
59
90
  if (key in obj) {
60
91
  Object.defineProperty(obj, key, {
@@ -66,6 +97,36 @@ function _define_property$2(obj, key, value) {
66
97
  } else obj[key] = value;
67
98
  return obj;
68
99
  }
100
+ function _get_prototype_of(o) {
101
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
102
+ return o.__proto__ || Object.getPrototypeOf(o);
103
+ };
104
+ return _get_prototype_of(o);
105
+ }
106
+ function _inherits(subClass, superClass) {
107
+ if (typeof superClass !== "function" && superClass !== null) {
108
+ throw new TypeError("Super expression must either be null or a function");
109
+ }
110
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
111
+ constructor: {
112
+ value: subClass,
113
+ writable: true,
114
+ configurable: true
115
+ }
116
+ });
117
+ if (superClass) _set_prototype_of(subClass, superClass);
118
+ }
119
+ function _is_native_function(fn) {
120
+ return Function.toString.call(fn).indexOf("[native code]") !== -1;
121
+ }
122
+ function _is_native_reflect_construct() {
123
+ try {
124
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
125
+ } catch (_) {}
126
+ return (_is_native_reflect_construct = function() {
127
+ return !!result;
128
+ })();
129
+ }
69
130
  function _iterable_to_array$1(iter) {
70
131
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
71
132
  return Array.from(iter);
@@ -143,10 +204,21 @@ function _object_without_properties_loose$1(source, excluded) {
143
204
  }
144
205
  return target;
145
206
  }
207
+ function _possible_constructor_return(self, call) {
208
+ if (call && (_type_of(call) === "object" || typeof call === "function")) return call;
209
+ return _assert_this_initialized(self);
210
+ }
211
+ function _set_prototype_of(o, p) {
212
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
213
+ o.__proto__ = p;
214
+ return o;
215
+ };
216
+ return _set_prototype_of(o, p);
217
+ }
146
218
  function _to_consumable_array$1(arr) {
147
219
  return _array_without_holes$1(arr) || _iterable_to_array$1(arr) || _unsupported_iterable_to_array$1(arr) || _non_iterable_spread$1();
148
220
  }
149
- function _ts_generator$2(thisArg, body) {
221
+ function _ts_generator$3(thisArg, body) {
150
222
  var f, y, t, _ = {
151
223
  label: 0,
152
224
  sent: function() {
@@ -257,6 +329,30 @@ function _unsupported_iterable_to_array$1(o, minLen) {
257
329
  if (n === "Map" || n === "Set") return Array.from(n);
258
330
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$1(o, minLen);
259
331
  }
332
+ function _wrap_native_super(Class) {
333
+ var _cache = typeof Map === "function" ? new Map() : undefined;
334
+ _wrap_native_super = function(Class) {
335
+ if (Class === null || !_is_native_function(Class)) return Class;
336
+ if (typeof Class !== "function") throw new TypeError("Super expression must either be null or a function");
337
+ if (typeof _cache !== "undefined") {
338
+ if (_cache.has(Class)) return _cache.get(Class);
339
+ _cache.set(Class, Wrapper);
340
+ }
341
+ function Wrapper() {
342
+ return _construct(Class, arguments, _get_prototype_of(this).constructor);
343
+ }
344
+ Wrapper.prototype = Object.create(Class.prototype, {
345
+ constructor: {
346
+ value: Wrapper,
347
+ enumerable: false,
348
+ writable: true,
349
+ configurable: true
350
+ }
351
+ });
352
+ return _set_prototype_of(Wrapper, Class);
353
+ };
354
+ return _wrap_native_super(Class);
355
+ }
260
356
  /**
261
357
  * Splits a model config into request parameters and execution controls.
262
358
  *
@@ -296,15 +392,63 @@ function _unsupported_iterable_to_array$1(o, minLen) {
296
392
  var tools = config === null || config === void 0 ? void 0 : config.tools;
297
393
  return Array.isArray(tools) ? tools : [];
298
394
  }
395
+ /**
396
+ * Raised when a request naming a System One model is sent down the completion arm.
397
+ *
398
+ * Its own error type rather than a generic one because the fix is specific and mechanical — the call
399
+ * goes to `openRouterDecision` — and an error a reader can act on without opening the source is worth
400
+ * a named class.
401
+ */ var OpenRouterSystemOneModelOnCompletionArmError = /*#__PURE__*/ function(Error1) {
402
+ _inherits(OpenRouterSystemOneModelOnCompletionArmError, Error1);
403
+ function OpenRouterSystemOneModelOnCompletionArmError(model) {
404
+ _class_call_check(this, OpenRouterSystemOneModelOnCompletionArmError);
405
+ var _this;
406
+ _this = _call_super(this, OpenRouterSystemOneModelOnCompletionArmError, [
407
+ "`".concat(model, "` is a System One model. It answers only `POST /systemone` and cannot serve a completion — build an `OpenRouterDecisionRequest` and call `openRouterDecision` instead of `callModelForOpenRouterRequest`.")
408
+ ]), _define_property$2(_this, "model", void 0);
409
+ _this.name = 'OpenRouterSystemOneModelOnCompletionArmError';
410
+ _this.model = model;
411
+ return _this;
412
+ }
413
+ return OpenRouterSystemOneModelOnCompletionArmError;
414
+ }(_wrap_native_super(Error));
415
+ /**
416
+ * Refuses a config whose model cannot serve a completion.
417
+ *
418
+ * Asserted rather than assumed, for the same reason {@link sendOpenRouterResponsesRequest} asserts its
419
+ * response is not an event stream: the alternative failure is unreadable. A Jev slug on `/responses`
420
+ * comes back as a provider-level error naming neither the model class nor the route that would have
421
+ * served it, from inside a sweep, on a request whose config was accepted when it was written.
422
+ *
423
+ * @param config - The merged model config.
424
+ * @throws {OpenRouterSystemOneModelOnCompletionArmError} When the config names a System One model.
425
+ */ function assertOpenRouterCompletionModel(config) {
426
+ var _ref;
427
+ var model = [
428
+ config === null || config === void 0 ? void 0 : config.model
429
+ ].concat(_to_consumable_array$1((_ref = config === null || config === void 0 ? void 0 : config.models) !== null && _ref !== void 0 ? _ref : [])).filter(Boolean).find(function(x) {
430
+ return isOpenRouterSystemOneModelId(x);
431
+ });
432
+ if (model != null) {
433
+ throw new OpenRouterSystemOneModelOnCompletionArmError(model);
434
+ }
435
+ }
299
436
  /**
300
437
  * Converts a built request into the `/responses` request body.
301
438
  *
302
439
  * This is the whole wire body minus the SDK-only keys (`tools`/`state`/`stopWhen` on the `callModel`
303
440
  * path), so both dispatch paths assemble the request the same way and cannot drift.
304
441
  *
442
+ * It is also where a System One model is refused, because it is the ONE point every dispatch path
443
+ * converges on — `openRouterCallModelInput`, `sendOpenRouterResponsesRequest` and
444
+ * `openRouterModelResultForRequest` all build their body here — so no route to the completion arm can
445
+ * be added later that quietly skips the check.
446
+ *
305
447
  * @param request - The built request.
306
448
  * @returns The request body, in the SDK's camelCase request surface.
449
+ * @throws {OpenRouterSystemOneModelOnCompletionArmError} When the config names a System One model.
307
450
  */ function openRouterResponsesRequestBody(request) {
451
+ assertOpenRouterCompletionModel(request.config);
308
452
  var requestConfig = splitOpenRouterModelConfig(request.config).requestConfig;
309
453
  return filterUndefinedValues(_object_spread_props$1(_object_spread$2({}, requestConfig), {
310
454
  input: request.input,
@@ -388,9 +532,9 @@ function _unsupported_iterable_to_array$1(o, minLen) {
388
532
  * @returns The response.
389
533
  * @throws {Error} When the request fails, or when a streaming response comes back for a non-streaming request.
390
534
  */ function sendOpenRouterResponsesRequest(params) {
391
- return _async_to_generator$2(function() {
535
+ return _async_to_generator$3(function() {
392
536
  var client, request, options, requestTimeoutMs, responsesRequest, result;
393
- return _ts_generator$2(this, function(_state) {
537
+ return _ts_generator$3(this, function(_state) {
394
538
  switch(_state.label){
395
539
  case 0:
396
540
  client = params.client, request = params.request, options = params.options;
@@ -479,9 +623,9 @@ function _unsupported_iterable_to_array$1(o, minLen) {
479
623
  * @param params - The client, request, tools, state, and options.
480
624
  * @returns The normalized call result.
481
625
  */ function callModelForOpenRouterRequest(params) {
482
- return _async_to_generator$2(function() {
626
+ return _async_to_generator$3(function() {
483
627
  var _ref, _params_tools, needsClientToolLoop, sendDirect, response, _tmp;
484
- return _ts_generator$2(this, function(_state) {
628
+ return _ts_generator$3(this, function(_state) {
485
629
  switch(_state.label){
486
630
  case 0:
487
631
  // Client tools and a `StateAccessor` both live on `ModelResult`, so a run using either needs the loop
@@ -639,6 +783,32 @@ function _unsupported_iterable_to_array$1(o, minLen) {
639
783
  return result;
640
784
  }
641
785
 
786
+ function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
787
+ try {
788
+ var info = gen[key](arg);
789
+ var value = info.value;
790
+ } catch (error) {
791
+ reject(error);
792
+ return;
793
+ }
794
+ if (info.done) resolve(value);
795
+ else Promise.resolve(value).then(_next, _throw);
796
+ }
797
+ function _async_to_generator$2(fn) {
798
+ return function() {
799
+ var self = this, args = arguments;
800
+ return new Promise(function(resolve, reject) {
801
+ var gen = fn.apply(self, args);
802
+ function _next(value) {
803
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
804
+ }
805
+ function _throw(err) {
806
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
807
+ }
808
+ _next(undefined);
809
+ });
810
+ };
811
+ }
642
812
  function _define_property$1(obj, key, value) {
643
813
  if (key in obj) {
644
814
  Object.defineProperty(obj, key, {
@@ -665,138 +835,167 @@ function _object_spread$1(target) {
665
835
  }
666
836
  return target;
667
837
  }
668
- /**
669
- * Builds a hosted `file_search` tool entry with the field names the SDK actually forwards.
670
- *
671
- * @param vectorStoreIds - The `vs_…` ids to search.
672
- * @param maxNumResults - Optional cap on returned chunks.
673
- * @returns The hosted tool entry.
674
- *
675
- * @__NO_SIDE_EFFECTS__
676
- */ function openRouterFileSearchTool(vectorStoreIds, maxNumResults) {
677
- return _object_spread$1({
678
- type: 'file_search',
679
- vectorStoreIds: vectorStoreIds
680
- }, maxNumResults == null ? undefined : {
681
- maxNumResults: maxNumResults
682
- });
683
- }
684
- /**
685
- * The default PDF parser engine this package pins.
686
- *
687
- * Pinned because the alternative is silent: with no engine named, OpenRouter downgrades any model it
688
- * believes lacks native file support to `mistral-ocr`, inheriting its 8-image cap and per-page billing with
689
- * no error — which on a multi-page document quietly truncates content.
690
- *
691
- * `native` rather than the equally-free `pdf-text` because it fails LOUDLY. It requires a model with
692
- * native file input and 400s on one without, where `pdf-text` would hand a scanned PDF to the model as
693
- * empty text and let it answer ungrounded. A caller on a text-only model wants
694
- * `openRouterFileParserPlugin('pdf-text')` — see {@link OpenRouterPdfParserEngine}.
695
- */ var DEFAULT_OPENROUTER_PDF_PARSER_ENGINE = 'native';
696
- /**
697
- * The `file-parser` plugin entry with the PDF engine pinned.
698
- *
699
- * @param engine - Engine to pin. Defaults to {@link DEFAULT_OPENROUTER_PDF_PARSER_ENGINE}.
700
- * @returns The plugin config entry.
701
- *
702
- * @__NO_SIDE_EFFECTS__
703
- */ function openRouterFileParserPlugin() {
704
- var engine = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : DEFAULT_OPENROUTER_PDF_PARSER_ENGINE;
705
- return {
706
- id: 'file-parser',
707
- pdf: {
708
- engine: engine
838
+ function _ts_generator$2(thisArg, body) {
839
+ var f, y, t, _ = {
840
+ label: 0,
841
+ sent: function() {
842
+ if (t[0] & 1) throw t[1];
843
+ return t[1];
844
+ },
845
+ trys: [],
846
+ ops: []
847
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
848
+ return d(g, "next", {
849
+ value: verb(0)
850
+ }), d(g, "throw", {
851
+ value: verb(1)
852
+ }), d(g, "return", {
853
+ value: verb(2)
854
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
855
+ value: function() {
856
+ return this;
709
857
  }
710
- };
711
- }
712
- /**
713
- * A provider config that pins routing to a single provider with fallbacks off and parameter support
714
- * required — the configuration that makes a BYOK request actually reach the intended upstream with
715
- * every parameter intact.
716
- *
717
- * @param provider - The provider slug to pin to (e.g. `openai`).
718
- * @returns The provider routing config.
719
- *
720
- * @__NO_SIDE_EFFECTS__
721
- */ function openRouterProviderPinnedTo(provider) {
722
- return {
723
- only: [
724
- provider
725
- ],
726
- allowFallbacks: false,
727
- requireParameters: true
728
- };
858
+ }), g;
859
+ function verb(n) {
860
+ return function(v) {
861
+ return step([
862
+ n,
863
+ v
864
+ ]);
865
+ };
866
+ }
867
+ function step(op) {
868
+ if (f) throw new TypeError("Generator is already executing.");
869
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
870
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
871
+ if (y = 0, t) op = [
872
+ op[0] & 2,
873
+ t.value
874
+ ];
875
+ switch(op[0]){
876
+ case 0:
877
+ case 1:
878
+ t = op;
879
+ break;
880
+ case 4:
881
+ _.label++;
882
+ return {
883
+ value: op[1],
884
+ done: false
885
+ };
886
+ case 5:
887
+ _.label++;
888
+ y = op[1];
889
+ op = [
890
+ 0
891
+ ];
892
+ continue;
893
+ case 7:
894
+ op = _.ops.pop();
895
+ _.trys.pop();
896
+ continue;
897
+ default:
898
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
899
+ _ = 0;
900
+ continue;
901
+ }
902
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
903
+ _.label = op[1];
904
+ break;
905
+ }
906
+ if (op[0] === 6 && _.label < t[1]) {
907
+ _.label = t[1];
908
+ t = op;
909
+ break;
910
+ }
911
+ if (t && _.label < t[2]) {
912
+ _.label = t[2];
913
+ _.ops.push(op);
914
+ break;
915
+ }
916
+ if (t[2]) _.ops.pop();
917
+ _.trys.pop();
918
+ continue;
919
+ }
920
+ op = body.call(thisArg, _);
921
+ } catch (e) {
922
+ op = [
923
+ 6,
924
+ e
925
+ ];
926
+ y = 0;
927
+ } finally{
928
+ f = t = 0;
929
+ }
930
+ if (op[0] & 5) throw op[1];
931
+ return {
932
+ value: op[0] ? op[1] : void 0,
933
+ done: true
934
+ };
935
+ }
729
936
  }
730
937
  /**
731
- * Merges model configs left-to-right, so the last input wins.
732
- *
733
- * Merging is SHALLOW by key: an override that supplies `provider` replaces the whole provider object
734
- * rather than merging into it. That is the behaviour a caller wants — a half-overridden `provider`
735
- * (say, `only` from the override and `allowFallbacks` from the version) is a configuration nobody
736
- * wrote down and nobody can reason about.
938
+ * Asks a decision and returns its answers.
737
939
  *
738
- * `undefined` values do not overwrite; an explicit `null` does (it is how a caller clears a value
739
- * the version set).
940
+ * The request is validated first, so a model that cannot serve a decision is refused HERE rather than by
941
+ * the route — the mirror of the refusal `callModelForOpenRouterRequest` makes for a System One model on
942
+ * the completion arm. Which surface a request belongs to is a property of the request, not a choice the
943
+ * caller makes at the call site.
740
944
  *
741
- * @param configs - Configs to merge, lowest priority first.
742
- * @returns The merged config.
743
- */ function mergeOpenRouterModelConfig(configs) {
744
- return mergeObjects(configs);
745
- }
746
- /**
747
- * Validates a merged model config, catching the misconfigurations that fail silently at runtime
748
- * rather than loudly.
749
- *
750
- * @param config - The merged config to check.
751
- * @returns The validation result.
752
- */ function validateOpenRouterModelConfig(config) {
753
- var errors = [];
754
- var warnings = [];
755
- if (config == null) {
756
- errors.push('No model config was provided.');
757
- } else {
758
- var _ref;
759
- var _config_models, _config_text, _config_plugins, _fileParser_pdf, _config_tools, _config_tools1, _config_provider, _config_provider_only, _config_provider1;
760
- if (!config.model && !((_config_models = config.models) === null || _config_models === void 0 ? void 0 : _config_models.length)) {
761
- errors.push('No `model` (or `models` fallback chain) was specified.');
762
- }
763
- var format = (_config_text = config.text) === null || _config_text === void 0 ? void 0 : _config_text.format;
764
- if ((format === null || format === void 0 ? void 0 : format.type) === 'json_schema') {
765
- if (!format.name) {
766
- errors.push('A `json_schema` text format requires a `name`.');
767
- }
768
- if (!format.schema) {
769
- errors.push('A `json_schema` text format requires a `schema`.');
945
+ * @param params - The client, request, and options.
946
+ * @returns The normalized decision result.
947
+ * @throws {OpenRouterDecisionDeclarationError} When the request cannot be asked as declared.
948
+ * @throws {OpenRouterDecisionAnswerFaultError} When the reply did not answer the declared questions.
949
+ */ function openRouterDecision(params) {
950
+ return _async_to_generator$2(function() {
951
+ var _response_answers, client, request, options, validation, requestTimeoutMs, decisionsRequest, result, response, read;
952
+ return _ts_generator$2(this, function(_state) {
953
+ switch(_state.label){
954
+ case 0:
955
+ client = params.client, request = params.request, options = params.options;
956
+ validation = validateOpenRouterDecisionRequest(request);
957
+ if (!validation.valid) {
958
+ throw new OpenRouterDecisionDeclarationError(validation.errors);
959
+ }
960
+ requestTimeoutMs = splitOpenRouterDecisionModelConfig(request.config).requestTimeoutMs;
961
+ decisionsRequest = openRouterDecisionRequestBody(request);
962
+ return [
963
+ 4,
964
+ systemOneCreate(client, {
965
+ decisionsRequest: decisionsRequest
966
+ }, _object_spread$1({}, options, requestTimeoutMs == null ? undefined : {
967
+ timeoutMs: requestTimeoutMs
968
+ }))
969
+ ];
970
+ case 1:
971
+ result = _state.sent();
972
+ if (!result.ok) {
973
+ throw result.error;
974
+ }
975
+ response = result.value;
976
+ read = readOpenRouterDecisionAnswers({
977
+ questions: request.questions,
978
+ raw: (_response_answers = response.answers) !== null && _response_answers !== void 0 ? _response_answers : {}
979
+ });
980
+ if (read.faults != null) {
981
+ throw new OpenRouterDecisionAnswerFaultError(read.faults);
982
+ }
983
+ return [
984
+ 2,
985
+ {
986
+ answers: read.answers,
987
+ model: response.model,
988
+ provider: response.provider,
989
+ generationIds: response.id ? [
990
+ response.id
991
+ ] : [],
992
+ usage: openRouterRunUsageFromDecisionsUsage(response.usage),
993
+ response: response
994
+ }
995
+ ];
770
996
  }
771
- }
772
- var fileParser = (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.find(function(x) {
773
- return x.id === 'file-parser';
774
- });
775
- if (fileParser != null && !((_fileParser_pdf = fileParser.pdf) === null || _fileParser_pdf === void 0 ? void 0 : _fileParser_pdf.engine)) {
776
- warnings.push('The `file-parser` plugin has no pinned `pdf.engine`; OpenRouter will silently fall back to `mistral-ocr` (8-image cap, per-page billing) on any model it believes lacks native file support.');
777
- }
778
- var hasHostedTools = ((_ref = (_config_tools = config.tools) === null || _config_tools === void 0 ? void 0 : _config_tools.length) !== null && _ref !== void 0 ? _ref : 0) > 0;
779
- var fileSearchWithoutStores = (_config_tools1 = config.tools) === null || _config_tools1 === void 0 ? void 0 : _config_tools1.some(function(x) {
780
- return x.type === 'file_search' && !Array.isArray(x['vectorStoreIds']);
781
997
  });
782
- if (fileSearchWithoutStores) {
783
- // The SDK drops an unrecognized field (a `vector_store_ids` authored in wire case, say) during
784
- // outbound serialization, leaving a tool that searches nothing and a model that answers ungrounded
785
- // with no error at all. That is exactly the failure worth refusing to publish.
786
- errors.push('A `file_search` hosted tool requires a `vectorStoreIds` array. Note the CAMELCASE — the SDK drops the wire-cased `vector_store_ids`, leaving a tool that searches nothing.');
787
- }
788
- if (hasHostedTools && ((_config_provider = config.provider) === null || _config_provider === void 0 ? void 0 : _config_provider.requireParameters) !== true) {
789
- warnings.push('Hosted tools were requested without `provider.requireParameters: true`; a provider that does not support them receives only the parameters it supports and ignores the rest, returning an ungrounded answer with no error.');
790
- }
791
- if (((_config_provider1 = config.provider) === null || _config_provider1 === void 0 ? void 0 : (_config_provider_only = _config_provider1.only) === null || _config_provider_only === void 0 ? void 0 : _config_provider_only.length) && config.provider.allowFallbacks !== false) {
792
- warnings.push('`provider.only` was set without `provider.allowFallbacks: false`, so routing can still leave the pinned provider.');
793
- }
794
- }
795
- return {
796
- valid: errors.length === 0,
797
- errors: errors,
798
- warnings: warnings
799
- };
998
+ })();
800
999
  }
801
1000
 
802
1001
  function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
@@ -1755,4 +1954,4 @@ function _unsupported_iterable_to_array(o, minLen) {
1755
1954
  }));
1756
1955
  }
1757
1956
 
1758
- export { DEFAULT_OPENROUTER_PDF_PARSER_ENGINE, OPENROUTER_CALL_MODEL_HEADER, callModelForOpenRouterRequest, isOpenRouterStateAwaitingDeferredTools, mergeOpenRouterModelConfig, openRouterCallModelInput, openRouterCallResultFromResponse, openRouterDecodeBase64, openRouterEmbeddingVector, openRouterEmbeddings, openRouterFileAnnotationMessage, openRouterFileAnnotationText, openRouterFileParserPlugin, openRouterFileSearchTool, openRouterFunctionCallOutputItems, openRouterGeneration, openRouterGenerationContent, openRouterHostedTools, openRouterInputFileDataPart, openRouterInputFilePartsForAttachedFiles, openRouterInputFileUrlPart, openRouterInputImagePart, openRouterInputMessages, openRouterInputTextPart, openRouterMessagesWithFreshFileAttachments, openRouterMessagesWithoutFileAttachmentData, openRouterModelResultForRequest, openRouterOutputTextFromResponse, openRouterPendingDeferredToolCallFromParsedCall, openRouterPendingDeferredToolCalls, openRouterPromptRequest, openRouterProviderPinnedTo, openRouterResolvedDeferredToolResults, openRouterResponsesRequestBody, openRouterRunErrorFromResponseError, openRouterRunUsageFromResponseUsage, openRouterUnparsedAttachedFiles, parseOpenRouterJsonOutput, sendOpenRouterResponsesRequest, splitOpenRouterModelConfig, validateOpenRouterModelConfig };
1957
+ export { OPENROUTER_CALL_MODEL_HEADER, OpenRouterDecisionAnswerFaultError, OpenRouterDecisionDeclarationError, OpenRouterSystemOneModelOnCompletionArmError, callModelForOpenRouterRequest, isOpenRouterStateAwaitingDeferredTools, isOpenRouterSystemOneModelId, mergeOpenRouterModelConfig, openRouterCallModelInput, openRouterCallResultFromResponse, openRouterDecision, openRouterDecisionRequestBody, openRouterDecodeBase64, openRouterEmbeddingVector, openRouterEmbeddings, openRouterFileAnnotationMessage, openRouterFileAnnotationText, openRouterFunctionCallOutputItems, openRouterGeneration, openRouterGenerationContent, openRouterHostedTools, openRouterInputFileDataPart, openRouterInputFilePartsForAttachedFiles, openRouterInputFileUrlPart, openRouterInputImagePart, openRouterInputMessages, openRouterInputTextPart, openRouterMessagesWithFreshFileAttachments, openRouterMessagesWithoutFileAttachmentData, openRouterModelResultForRequest, openRouterOutputTextFromResponse, openRouterPendingDeferredToolCallFromParsedCall, openRouterPendingDeferredToolCalls, openRouterPromptRequest, openRouterResolvedDeferredToolResults, openRouterResponsesRequestBody, openRouterRunErrorFromResponseError, openRouterRunUsageFromDecisionsUsage, openRouterRunUsageFromResponseUsage, openRouterUnparsedAttachedFiles, parseOpenRouterJsonOutput, readOpenRouterDecisionAnswers, sendOpenRouterResponsesRequest, splitOpenRouterDecisionModelConfig, splitOpenRouterModelConfig, validateOpenRouterDecisionRequest };