modelrig 0.0.1 → 0.1.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.
Files changed (220) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +115 -8
  3. package/dist/adapters/anthropic.d.ts +46 -0
  4. package/dist/adapters/anthropic.d.ts.map +1 -0
  5. package/dist/adapters/anthropic.js +202 -0
  6. package/dist/adapters/deepseek.d.ts +41 -0
  7. package/dist/adapters/deepseek.d.ts.map +1 -0
  8. package/dist/adapters/deepseek.js +163 -0
  9. package/dist/adapters/gemini.d.ts +44 -0
  10. package/dist/adapters/gemini.d.ts.map +1 -0
  11. package/dist/adapters/gemini.js +222 -0
  12. package/dist/adapters/grok.d.ts +44 -0
  13. package/dist/adapters/grok.d.ts.map +1 -0
  14. package/dist/adapters/grok.js +168 -0
  15. package/dist/adapters/openai-compat.d.ts +74 -0
  16. package/dist/adapters/openai-compat.d.ts.map +1 -0
  17. package/dist/adapters/openai-compat.js +187 -0
  18. package/dist/adapters/openai.d.ts +49 -0
  19. package/dist/adapters/openai.d.ts.map +1 -0
  20. package/dist/adapters/openai.js +222 -0
  21. package/dist/bakeoff/engine.d.ts +52 -0
  22. package/dist/bakeoff/engine.d.ts.map +1 -0
  23. package/dist/bakeoff/engine.js +163 -0
  24. package/dist/bakeoff/replay.d.ts +52 -0
  25. package/dist/bakeoff/replay.d.ts.map +1 -0
  26. package/dist/bakeoff/replay.js +94 -0
  27. package/dist/bakeoff/samples.d.ts +62 -0
  28. package/dist/bakeoff/samples.d.ts.map +1 -0
  29. package/dist/bakeoff/samples.js +128 -0
  30. package/dist/bakeoff/stats.d.ts +13 -0
  31. package/dist/bakeoff/stats.d.ts.map +1 -0
  32. package/dist/bakeoff/stats.js +48 -0
  33. package/dist/bakeoff/types.d.ts +37 -0
  34. package/dist/bakeoff/types.d.ts.map +1 -0
  35. package/dist/bakeoff/types.js +10 -0
  36. package/dist/cli.d.ts +27 -0
  37. package/dist/cli.d.ts.map +1 -0
  38. package/dist/cli.js +572 -0
  39. package/dist/config.d.ts +104 -0
  40. package/dist/config.d.ts.map +1 -0
  41. package/dist/config.js +148 -0
  42. package/dist/feedback/coverage.d.ts +32 -0
  43. package/dist/feedback/coverage.d.ts.map +1 -0
  44. package/dist/feedback/coverage.js +95 -0
  45. package/dist/feedback/feedback.d.ts +35 -0
  46. package/dist/feedback/feedback.d.ts.map +1 -0
  47. package/dist/feedback/feedback.js +39 -0
  48. package/dist/index.d.ts +155 -0
  49. package/dist/index.d.ts.map +1 -0
  50. package/dist/index.js +448 -0
  51. package/dist/init/finder.d.ts +79 -0
  52. package/dist/init/finder.d.ts.map +1 -0
  53. package/dist/init/finder.js +297 -0
  54. package/dist/init/run.d.ts +99 -0
  55. package/dist/init/run.d.ts.map +1 -0
  56. package/dist/init/run.js +281 -0
  57. package/dist/init/signatures.d.ts +39 -0
  58. package/dist/init/signatures.d.ts.map +1 -0
  59. package/dist/init/signatures.js +116 -0
  60. package/dist/matrix/aggregate.d.ts +89 -0
  61. package/dist/matrix/aggregate.d.ts.map +1 -0
  62. package/dist/matrix/aggregate.js +186 -0
  63. package/dist/query/grammar.d.ts +35 -0
  64. package/dist/query/grammar.d.ts.map +1 -0
  65. package/dist/query/grammar.js +279 -0
  66. package/dist/query/run.d.ts +8 -0
  67. package/dist/query/run.d.ts.map +1 -0
  68. package/dist/query/run.js +21 -0
  69. package/dist/registry/build.d.ts +126 -0
  70. package/dist/registry/build.d.ts.map +1 -0
  71. package/dist/registry/build.js +192 -0
  72. package/dist/registry/call-notes.d.ts +11 -0
  73. package/dist/registry/call-notes.d.ts.map +1 -0
  74. package/dist/registry/call-notes.js +72 -0
  75. package/dist/registry/claims.d.ts +63 -0
  76. package/dist/registry/claims.d.ts.map +1 -0
  77. package/dist/registry/claims.js +107 -0
  78. package/dist/registry/facts.d.ts +32 -0
  79. package/dist/registry/facts.d.ts.map +1 -0
  80. package/dist/registry/facts.js +120 -0
  81. package/dist/registry/fingerprint.d.ts +20 -0
  82. package/dist/registry/fingerprint.d.ts.map +1 -0
  83. package/dist/registry/fingerprint.js +150 -0
  84. package/dist/registry/parity.d.ts +26 -0
  85. package/dist/registry/parity.d.ts.map +1 -0
  86. package/dist/registry/parity.js +41 -0
  87. package/dist/registry/pricing.d.ts +19 -0
  88. package/dist/registry/pricing.d.ts.map +1 -0
  89. package/dist/registry/pricing.js +69 -0
  90. package/dist/registry/rows.d.ts +16 -0
  91. package/dist/registry/rows.d.ts.map +1 -0
  92. package/dist/registry/rows.js +57 -0
  93. package/dist/registry/seed.d.ts +43 -0
  94. package/dist/registry/seed.d.ts.map +1 -0
  95. package/dist/registry/seed.js +97 -0
  96. package/dist/registry/select.d.ts +68 -0
  97. package/dist/registry/select.d.ts.map +1 -0
  98. package/dist/registry/select.js +141 -0
  99. package/dist/registry/staleness.d.ts +18 -0
  100. package/dist/registry/staleness.d.ts.map +1 -0
  101. package/dist/registry/staleness.js +39 -0
  102. package/dist/routes/draft.d.ts +83 -0
  103. package/dist/routes/draft.d.ts.map +1 -0
  104. package/dist/routes/draft.js +135 -0
  105. package/dist/routes/loader.d.ts +26 -0
  106. package/dist/routes/loader.d.ts.map +1 -0
  107. package/dist/routes/loader.js +436 -0
  108. package/dist/routes/manifest.d.ts +24 -0
  109. package/dist/routes/manifest.d.ts.map +1 -0
  110. package/dist/routes/manifest.js +118 -0
  111. package/dist/routes/serveability.d.ts +52 -0
  112. package/dist/routes/serveability.d.ts.map +1 -0
  113. package/dist/routes/serveability.js +73 -0
  114. package/dist/routes/template.d.ts +18 -0
  115. package/dist/routes/template.d.ts.map +1 -0
  116. package/dist/routes/template.js +94 -0
  117. package/dist/run/cost.d.ts +26 -0
  118. package/dist/run/cost.d.ts.map +1 -0
  119. package/dist/run/cost.js +41 -0
  120. package/dist/run/envelope.d.ts +21 -0
  121. package/dist/run/envelope.d.ts.map +1 -0
  122. package/dist/run/envelope.js +45 -0
  123. package/dist/run/grounding.d.ts +56 -0
  124. package/dist/run/grounding.d.ts.map +1 -0
  125. package/dist/run/grounding.js +89 -0
  126. package/dist/run/repair.d.ts +36 -0
  127. package/dist/run/repair.d.ts.map +1 -0
  128. package/dist/run/repair.js +61 -0
  129. package/dist/run/resolve.d.ts +26 -0
  130. package/dist/run/resolve.d.ts.map +1 -0
  131. package/dist/run/resolve.js +81 -0
  132. package/dist/run/retry.d.ts +19 -0
  133. package/dist/run/retry.d.ts.map +1 -0
  134. package/dist/run/retry.js +50 -0
  135. package/dist/run/run.d.ts +41 -0
  136. package/dist/run/run.d.ts.map +1 -0
  137. package/dist/run/run.js +0 -0
  138. package/dist/run/validate.d.ts +15 -0
  139. package/dist/run/validate.d.ts.map +1 -0
  140. package/dist/run/validate.js +56 -0
  141. package/dist/savings/emit.d.ts +25 -0
  142. package/dist/savings/emit.d.ts.map +1 -0
  143. package/dist/savings/emit.js +75 -0
  144. package/dist/savings/odometer.d.ts +32 -0
  145. package/dist/savings/odometer.d.ts.map +1 -0
  146. package/dist/savings/odometer.js +70 -0
  147. package/dist/savings/swap-execute.d.ts +44 -0
  148. package/dist/savings/swap-execute.d.ts.map +1 -0
  149. package/dist/savings/swap-execute.js +87 -0
  150. package/dist/savings/swaps-client.d.ts +41 -0
  151. package/dist/savings/swaps-client.d.ts.map +1 -0
  152. package/dist/savings/swaps-client.js +81 -0
  153. package/dist/telemetry/capture.d.ts +28 -0
  154. package/dist/telemetry/capture.d.ts.map +1 -0
  155. package/dist/telemetry/capture.js +74 -0
  156. package/dist/telemetry/exporter.d.ts +62 -0
  157. package/dist/telemetry/exporter.d.ts.map +1 -0
  158. package/dist/telemetry/exporter.js +233 -0
  159. package/dist/telemetry/ingest-protocol.d.ts +161 -0
  160. package/dist/telemetry/ingest-protocol.d.ts.map +1 -0
  161. package/dist/telemetry/ingest-protocol.js +163 -0
  162. package/dist/telemetry/sinks.d.ts +54 -0
  163. package/dist/telemetry/sinks.d.ts.map +1 -0
  164. package/dist/telemetry/sinks.js +89 -0
  165. package/dist/telemetry/store.d.ts +38 -0
  166. package/dist/telemetry/store.d.ts.map +1 -0
  167. package/dist/telemetry/store.js +332 -0
  168. package/dist/telemetry/supabase-exporter.d.ts +64 -0
  169. package/dist/telemetry/supabase-exporter.d.ts.map +1 -0
  170. package/dist/telemetry/supabase-exporter.js +211 -0
  171. package/dist/tenancy/api-key-format.d.ts +67 -0
  172. package/dist/tenancy/api-key-format.d.ts.map +1 -0
  173. package/dist/tenancy/api-key-format.js +91 -0
  174. package/dist/tenancy/constants.d.ts +23 -0
  175. package/dist/tenancy/constants.d.ts.map +1 -0
  176. package/dist/tenancy/constants.js +25 -0
  177. package/dist/tenancy/scrub.d.ts +47 -0
  178. package/dist/tenancy/scrub.d.ts.map +1 -0
  179. package/dist/tenancy/scrub.js +85 -0
  180. package/dist/types/failures-teaching.d.ts +56 -0
  181. package/dist/types/failures-teaching.d.ts.map +1 -0
  182. package/dist/types/failures-teaching.js +177 -0
  183. package/dist/types/failures.d.ts +27 -0
  184. package/dist/types/failures.d.ts.map +1 -0
  185. package/dist/types/failures.js +41 -0
  186. package/dist/types/provider.d.ts +79 -0
  187. package/dist/types/provider.d.ts.map +1 -0
  188. package/dist/types/provider.js +20 -0
  189. package/dist/types/route.d.ts +127 -0
  190. package/dist/types/route.d.ts.map +1 -0
  191. package/dist/types/route.js +6 -0
  192. package/dist/types/telemetry.d.ts +89 -0
  193. package/dist/types/telemetry.d.ts.map +1 -0
  194. package/dist/types/telemetry.js +6 -0
  195. package/dist/watch/budget.d.ts +19 -0
  196. package/dist/watch/budget.d.ts.map +1 -0
  197. package/dist/watch/budget.js +35 -0
  198. package/dist/watch/evaluate.d.ts +66 -0
  199. package/dist/watch/evaluate.d.ts.map +1 -0
  200. package/dist/watch/evaluate.js +94 -0
  201. package/dist/watch/proposals.d.ts +73 -0
  202. package/dist/watch/proposals.d.ts.map +1 -0
  203. package/dist/watch/proposals.js +169 -0
  204. package/dist/watch/run-record.d.ts +64 -0
  205. package/dist/watch/run-record.d.ts.map +1 -0
  206. package/dist/watch/run-record.js +86 -0
  207. package/dist/watch/run-reported.d.ts +20 -0
  208. package/dist/watch/run-reported.d.ts.map +1 -0
  209. package/dist/watch/run-reported.js +53 -0
  210. package/dist/watch/run.d.ts +40 -0
  211. package/dist/watch/run.d.ts.map +1 -0
  212. package/dist/watch/run.js +44 -0
  213. package/dist/watch/state-store.d.ts +48 -0
  214. package/dist/watch/state-store.d.ts.map +1 -0
  215. package/dist/watch/state-store.js +86 -0
  216. package/dist/watch/state.d.ts +21 -0
  217. package/dist/watch/state.d.ts.map +1 -0
  218. package/dist/watch/state.js +93 -0
  219. package/package.json +50 -14
  220. package/index.js +0 -3
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 ModelRig
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,12 +1,119 @@
1
- # ModelRig
1
+ # modelrig
2
2
 
3
- **The capability-aware AI gateway. Rig it. Prove it. Sell it.**
3
+ **A capability-aware AI gateway.** You declare a route — the shape of the
4
+ answer you need and the set of models allowed to serve it — and ModelRig picks
5
+ a model that can, validates what comes back, retries the right way when it
6
+ doesn't, and records every attempt. Routes are code, failures are typed, and
7
+ cost is capped by an envelope you set.
4
8
 
5
- This package name is reserved for ModelRig — probes of what every model can
6
- actually do, routes that call a task (not a model), and rails to meter and
7
- sell AI endpoints.
9
+ - Node **≥ 20**
10
+ - Works standalone with just a provider key. The hosted console, bake-offs, and
11
+ the model registry are an optional upgrade — see [Signing up](#what-you-get-by-signing-up).
8
12
 
9
- Full release coming soon.
13
+ ## Install
10
14
 
11
- - Website: [modelrig.ai](https://modelrig.ai)
12
- - Docs: [modelrig.dev](https://modelrig.dev)
15
+ ```bash
16
+ npm i modelrig
17
+ ```
18
+
19
+ > **Native dependency.** ModelRig writes one telemetry row to a local SQLite
20
+ > file before each run returns, so a run never blocks on the network. That
21
+ > buffer is `better-sqlite3`, a native module — prebuilt binaries cover
22
+ > macOS and Linux on x64/arm64 (nearly everyone); an unusual platform will
23
+ > compile it at install time and needs a C++ toolchain. Node ≥ 20 is assumed.
24
+
25
+ ## Quickstart
26
+
27
+ This runs with **only a provider key** — no account, no signup.
28
+
29
+ **1. Set a provider key** (any one your route allows):
30
+
31
+ ```bash
32
+ export GEMINI_API_KEY=... # or OPENAI_API_KEY, ANTHROPIC_API_KEY, …
33
+ ```
34
+
35
+ **2. Define a route** at `modelrig/routes/research.growth_scenarios.yaml`:
36
+
37
+ ```yaml
38
+ route: research.growth_scenarios
39
+ version: 1
40
+ schema: ./schemas/growth_scenarios.schema.json # JSON Schema for the output
41
+ candidates: # THE candidate set — nothing else can serve
42
+ - provider: gemini
43
+ model: gemini-3.1-pro-preview
44
+ - provider: openai
45
+ model: gpt-5.4-mini
46
+ require: [schema_conformant]
47
+ prefer: [cost]
48
+ prompt:
49
+ system: ./prompts/growth_scenarios.system.md # {{var}} + {{#if capability.X}} blocks
50
+ variables: [ticker, financials, priorSteps]
51
+ policy:
52
+ retries: { content_invalid: 2, network: 4, capacity_shed: 3 }
53
+ timeout_ms: 300000
54
+ tier: flex
55
+ json: native
56
+ ```
57
+
58
+ **3. Call it:**
59
+
60
+ ```ts
61
+ import { createRig, loadConfigFromEnv } from "modelrig";
62
+
63
+ const rig = createRig(loadConfigFromEnv()); // keys from GEMINI_API_KEY etc.
64
+ const result = await rig.run("research.growth_scenarios", {
65
+ input: { ticker, financials, priorSteps }, // template variables
66
+ tags: { run_id, step: "growth_scenarios", ticker },
67
+ budget: { envelope: run_id }, // hard-stop cost envelope
68
+ });
69
+ // result.output — schema-validated JSON (ajv), regardless of serving model
70
+ // result.meta — servedCandidate, tokens (in/out/cached), cost, tiers,
71
+ // validation status, attempts by failure class
72
+ rig.close();
73
+ ```
74
+
75
+ Every attempt is recorded in a local SQLite file (`.modelrig/telemetry.db`)
76
+ tagged with your `tags`. Failures are typed —
77
+ `RigFailureError.failure.class` is one of `content_invalid`, `capacity_shed`,
78
+ `network`, `refusal`, `cache_invalid`, `timeout`, `budget_exhausted`,
79
+ `invariant_violation` — with a separate retry budget per class, so a flaky
80
+ network never spends your content-validation retries.
81
+
82
+ ## CLI
83
+
84
+ The package ships a `modelrig` binary:
85
+
86
+ ```bash
87
+ npx modelrig init # scan a repo for provider call sites, scaffold routes
88
+ npx modelrig bakeoff # compare candidates on recorded inputs
89
+ npx modelrig watch # keep the pricing/capability registry current
90
+ npx modelrig swap # propose + actuate a candidate-set change (git-tracked)
91
+ npx modelrig samples # inspect recorded telemetry samples
92
+ ```
93
+
94
+ `npx modelrig serve` (a thin HTTP wrapper over `rig.run`) lives in a separate
95
+ package, `modelrig-server`; the CLI tells you so if it isn't installed.
96
+
97
+ ## What you get by signing up
98
+
99
+ The gateway above is complete on its own. An account at
100
+ [app.modelrig.ai](https://app.modelrig.ai) adds, as an upgrade — never a gate
101
+ on the quickstart:
102
+
103
+ - a **console** for telemetry, cost, and route health across your runs,
104
+ - **bake-offs** and a maintained **model registry** (pricing + capabilities),
105
+ - **hosted telemetry ingest** — set `MODELRIG_API_KEY=rig_sk_…` and the
106
+ exporter posts to the hosted API instead of writing only local SQLite.
107
+
108
+ ## Honest limits
109
+
110
+ - **Prepaid balances and managed billing are not built yet.** This release is
111
+ the gateway and the self-host lane; the hosted control plane has one customer.
112
+ - **`0.x` means the shape may still move.** Route and config contracts are
113
+ stable enough to build on, not frozen.
114
+ - **`modelrig serve` needs the `modelrig-server` package** — it is not bundled
115
+ here.
116
+
117
+ ## License
118
+
119
+ Apache-2.0. See [LICENSE](./LICENSE).
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Anthropic ProviderAdapter — provider expansion 2026-08-02. Messages API
3
+ * via @anthropic-ai/sdk with streaming. Structured output is a FORCED TOOL
4
+ * CALL: the route schema becomes the single tool's input_schema and
5
+ * tool_choice pins it, so the accumulated input_json_delta stream IS the
6
+ * JSON output (Anthropic's recommended structured-output pattern; the run
7
+ * loop still ajv-validates like every provider). Prompt caching is explicit
8
+ * cache_control on Anthropic and is NOT wired yet — all cache capability
9
+ * flags stay false until it is.
10
+ */
11
+ import type { CapabilityFlag, ProviderAdapter } from "../types/provider";
12
+ import type { ClassifiedFailure, ShapingInput } from "./gemini";
13
+ export interface AnthropicAdapterConfig {
14
+ readonly apiKey: string;
15
+ }
16
+ /** True when a 400 says the schema cannot compile for strict mode —
17
+ * downgrade to advisory, do NOT surface as a failure. */
18
+ export declare function isStrictSchemaRejection(message: string): boolean;
19
+ export declare function anthropicSupports(feature: CapabilityFlag, _model: string): boolean;
20
+ export declare function classifyAnthropicFailure(message: string): ClassifiedFailure;
21
+ interface AnthropicTool {
22
+ readonly name: string;
23
+ readonly description: string;
24
+ readonly input_schema: object;
25
+ /** Constrained decoding (structured-outputs beta). */
26
+ readonly strict?: true;
27
+ }
28
+ export interface AnthropicShapedParams {
29
+ readonly model: string;
30
+ readonly max_tokens: number;
31
+ readonly system?: string;
32
+ readonly messages: ReadonlyArray<{
33
+ readonly role: "user";
34
+ readonly content: string;
35
+ }>;
36
+ readonly stream: true;
37
+ readonly tools?: readonly AnthropicTool[];
38
+ readonly tool_choice?: {
39
+ readonly type: "tool";
40
+ readonly name: string;
41
+ };
42
+ }
43
+ export declare function buildAnthropicParams(model: string, req: ShapingInput, strict?: boolean): AnthropicShapedParams;
44
+ export declare function createAnthropicAdapter(config: AnthropicAdapterConfig): ProviderAdapter;
45
+ export {};
46
+ //# sourceMappingURL=anthropic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/adapters/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAIV,cAAc,EACd,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAEhE,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AASD;yDACyD;AACzD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAEhE;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAalF;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,iBAAiB,CAwB3E;AAED,UAAU,aAAa;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,sDAAsD;IACtD,QAAQ,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC;CACxB;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACtF,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;IAC1C,QAAQ,CAAC,WAAW,CAAC,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CACzE;AAED,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,YAAY,EACjB,MAAM,UAAQ,GACb,qBAAqB,CAqBvB;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,sBAAsB,GAAG,eAAe,CAgJtF"}
@@ -0,0 +1,202 @@
1
+ "use strict";
2
+ /**
3
+ * Anthropic ProviderAdapter — provider expansion 2026-08-02. Messages API
4
+ * via @anthropic-ai/sdk with streaming. Structured output is a FORCED TOOL
5
+ * CALL: the route schema becomes the single tool's input_schema and
6
+ * tool_choice pins it, so the accumulated input_json_delta stream IS the
7
+ * JSON output (Anthropic's recommended structured-output pattern; the run
8
+ * loop still ajv-validates like every provider). Prompt caching is explicit
9
+ * cache_control on Anthropic and is NOT wired yet — all cache capability
10
+ * flags stay false until it is.
11
+ */
12
+ var __importDefault = (this && this.__importDefault) || function (mod) {
13
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.isStrictSchemaRejection = isStrictSchemaRejection;
17
+ exports.anthropicSupports = anthropicSupports;
18
+ exports.classifyAnthropicFailure = classifyAnthropicFailure;
19
+ exports.buildAnthropicParams = buildAnthropicParams;
20
+ exports.createAnthropicAdapter = createAnthropicAdapter;
21
+ const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
22
+ const DEFAULT_MAX_TOKENS = 32000;
23
+ const OUTPUT_TOOL_NAME = "route_output";
24
+ /** Strict tool use (constrained decoding) — public beta. Schemas that
25
+ * exceed Anthropic's compile limits (e.g. >16 union-typed parameters) are
26
+ * rejected with a 400; the call() path downgrades to advisory mode then. */
27
+ const STRUCTURED_OUTPUTS_BETA = "structured-outputs-2025-11-13";
28
+ /** True when a 400 says the schema cannot compile for strict mode —
29
+ * downgrade to advisory, do NOT surface as a failure. */
30
+ function isStrictSchemaRejection(message) {
31
+ return /union|exponential compilation|does not support strict|strict.*not supported/i.test(message);
32
+ }
33
+ function anthropicSupports(feature, _model) {
34
+ switch (feature) {
35
+ case "structured_native": // forced tool call with the route schema
36
+ case "json_mode":
37
+ return true;
38
+ case "grounded_native": // web-search tool exists but is not wired
39
+ case "context_cache_explicit": // cache_control not wired yet
40
+ case "prompt_cache_key":
41
+ case "prefix_cache_implicit":
42
+ case "tier_flex":
43
+ case "trace_visible": // extended thinking not enabled by this adapter
44
+ return false;
45
+ }
46
+ }
47
+ function classifyAnthropicFailure(message) {
48
+ const msg = message.toLowerCase();
49
+ if (/\b429\b|rate limit|rate_limit/.test(msg))
50
+ return { cls: "capacity_shed" };
51
+ if (/\b529\b|overloaded|\b50[023]\b|service unavailable/.test(msg)) {
52
+ return { cls: "capacity_shed" };
53
+ }
54
+ if (/timeout|etimedout|abort/.test(msg))
55
+ return { cls: "timeout" };
56
+ if (/econnreset|econnrefused|enotfound|fetch failed|network/.test(msg))
57
+ return { cls: "network" };
58
+ if (/\b401\b|authentication|x-api-key|api key/.test(msg)) {
59
+ // F2: non-retryable — a dead key never burns backoff retries.
60
+ return { cls: "config_auth", fixHint: "check the Anthropic API key configured for this rig" };
61
+ }
62
+ if (/credit|spending limit|insufficient_quota|billing/.test(msg)) {
63
+ // Account-level hard stop — retrying burns nothing but time (learned
64
+ // from the 2026-08-03 xAI credit exhaustion mid-bake-off).
65
+ return { cls: "config_auth", fixHint: "the Anthropic account is out of credits or over its spending limit" };
66
+ }
67
+ if (/not_found|not found|does not exist/.test(msg)) {
68
+ return {
69
+ cls: "network",
70
+ fixHint: "the candidate model was not found — fix the model id in the route's candidate list",
71
+ };
72
+ }
73
+ return { cls: "network" };
74
+ }
75
+ function buildAnthropicParams(model, req, strict = false) {
76
+ return {
77
+ model,
78
+ max_tokens: req.maxOutputTokens ?? DEFAULT_MAX_TOKENS,
79
+ ...(req.systemPrompt !== "" ? { system: req.systemPrompt } : {}),
80
+ messages: [{ role: "user", content: req.userPrompt }],
81
+ stream: true,
82
+ ...(req.outputSchema !== null
83
+ ? {
84
+ tools: [
85
+ {
86
+ name: OUTPUT_TOOL_NAME,
87
+ description: "Emit the structured output for this route.",
88
+ input_schema: req.outputSchema,
89
+ ...(strict ? { strict: true } : {}),
90
+ },
91
+ ],
92
+ tool_choice: { type: "tool", name: OUTPUT_TOOL_NAME },
93
+ }
94
+ : {}),
95
+ };
96
+ }
97
+ function createAnthropicAdapter(config) {
98
+ return {
99
+ id: "anthropic",
100
+ supports: anthropicSupports,
101
+ async call(req) {
102
+ const model = req.candidate.model;
103
+ // F1: post-stream failures still billed tokens — attach usage.
104
+ const fail = (cls, message, fixHint, usage) => ({
105
+ ok: false,
106
+ failure: {
107
+ class: cls,
108
+ message,
109
+ provider: "anthropic",
110
+ model,
111
+ ...(fixHint !== undefined ? { fixHint } : {}),
112
+ },
113
+ ...(usage !== undefined ? { usage } : {}),
114
+ });
115
+ const wantJson = req.outputSchema !== null;
116
+ try {
117
+ const client = new sdk_1.default({ apiKey: config.apiKey, timeout: req.timeoutMs });
118
+ // Strict-first (constrained decoding, structured-outputs beta): the
119
+ // strongest available rung. Schemas over Anthropic's compile limits
120
+ // (e.g. >16 union-typed parameters — hit live by earnings_5c on
121
+ // 2026-08-03) get an immediate 400; downgrade to advisory mode and
122
+ // let the run loop's ajv validation arbitrate, like every provider.
123
+ let stream;
124
+ if (wantJson) {
125
+ try {
126
+ stream = await client.messages.create(buildAnthropicParams(model, req, true), { headers: { "anthropic-beta": STRUCTURED_OUTPUTS_BETA } });
127
+ }
128
+ catch (strictError) {
129
+ const message = strictError instanceof Error ? strictError.message : String(strictError);
130
+ if (!isStrictSchemaRejection(message))
131
+ throw strictError;
132
+ stream = await client.messages.create(buildAnthropicParams(model, req));
133
+ }
134
+ }
135
+ else {
136
+ stream = await client.messages.create(buildAnthropicParams(model, req));
137
+ }
138
+ const events = stream;
139
+ let text = "";
140
+ let promptTokens = 0;
141
+ let completionTokens = 0;
142
+ let cachedTokens = 0;
143
+ let stopReason = null;
144
+ for await (const event of events) {
145
+ if (event.type === "message_start" && event.message?.usage !== undefined) {
146
+ promptTokens = event.message.usage.input_tokens ?? 0;
147
+ cachedTokens = event.message.usage.cache_read_input_tokens ?? 0;
148
+ }
149
+ else if (event.type === "content_block_delta") {
150
+ // Schema path: the forced tool's input_json_delta IS the output.
151
+ // Plain path: text deltas. Never mix the two buffers.
152
+ if (wantJson && event.delta?.type === "input_json_delta" && event.delta.partial_json) {
153
+ text += event.delta.partial_json;
154
+ }
155
+ else if (!wantJson && event.delta?.type === "text_delta" && event.delta.text) {
156
+ text += event.delta.text;
157
+ }
158
+ }
159
+ else if (event.type === "message_delta") {
160
+ if (event.usage?.output_tokens !== undefined) {
161
+ completionTokens = event.usage.output_tokens;
162
+ }
163
+ if (event.delta?.stop_reason)
164
+ stopReason = event.delta.stop_reason;
165
+ }
166
+ }
167
+ // Anthropic has no service tiers on this path — served is standard.
168
+ const usage = {
169
+ tokensIn: promptTokens,
170
+ tokensOut: completionTokens,
171
+ tokensCached: cachedTokens,
172
+ servedTier: "standard",
173
+ };
174
+ if (stopReason === "refusal") {
175
+ return fail("refusal", "Anthropic refused this request (stop_reason=refusal)", undefined, usage);
176
+ }
177
+ if (text.trim().length === 0) {
178
+ return fail("content_invalid", `empty response from Anthropic (stop_reason=${stopReason ?? "none"})`, undefined, usage);
179
+ }
180
+ if (stopReason === "max_tokens" && wantJson) {
181
+ return fail("content_invalid", "Anthropic structured output truncated (stop_reason=max_tokens)", "raise maxOutputTokens for this route", usage);
182
+ }
183
+ return { ok: true, text, usage };
184
+ }
185
+ catch (error) {
186
+ const message = error instanceof Error ? error.message : String(error);
187
+ const { cls, fixHint } = classifyAnthropicFailure(message);
188
+ return {
189
+ ok: false,
190
+ failure: {
191
+ class: cls,
192
+ message,
193
+ provider: "anthropic",
194
+ model,
195
+ cause: error,
196
+ ...(fixHint !== undefined ? { fixHint } : {}),
197
+ },
198
+ };
199
+ }
200
+ },
201
+ };
202
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * DeepSeek ProviderAdapter — plan step 5 (sanctioned cut if C1 date at risk).
3
+ * Transformation logic ported from apps/api/src/services/deepseek-provider.ts:
4
+ * OpenAI-compatible API at api.deepseek.com, json_object forcing (DeepSeek has
5
+ * NO native strict json_schema — the run loop's json_mode path injects the
6
+ * schema-coached prompt; this adapter receives it already coached),
7
+ * prompt_cache_hit_tokens accounting, reasoning_content excluded from the
8
+ * JSON buffer (only delta.content is accumulated).
9
+ * NOT ported: logging, pricing tables, env reads, the analyst-persona prompt.
10
+ *
11
+ * Portions may be derived from LiteLLM (https://github.com/BerriAI/litellm),
12
+ * Copyright (c) 2023 Berri AI, MIT License — retain this notice if LiteLLM's
13
+ * deepseek transformation logic is consulted during the port.
14
+ */
15
+ import type { CapabilityFlag, ProviderAdapter } from "../types/provider";
16
+ import type { ClassifiedFailure, ShapingInput } from "./gemini";
17
+ export interface DeepSeekAdapterConfig {
18
+ readonly apiKey: string;
19
+ }
20
+ export declare function deepseekSupports(feature: CapabilityFlag, model: string): boolean;
21
+ export declare function classifyDeepSeekFailure(message: string): ClassifiedFailure;
22
+ interface ChatMessage {
23
+ readonly role: "system" | "user";
24
+ readonly content: string;
25
+ }
26
+ export interface DeepSeekShapedParams {
27
+ readonly model: string;
28
+ readonly max_tokens: number;
29
+ readonly messages: readonly ChatMessage[];
30
+ readonly stream: true;
31
+ readonly stream_options: {
32
+ readonly include_usage: true;
33
+ };
34
+ readonly response_format?: {
35
+ readonly type: "json_object";
36
+ };
37
+ }
38
+ export declare function buildDeepSeekParams(model: string, req: ShapingInput): DeepSeekShapedParams;
39
+ export declare function createDeepSeekAdapter(config: DeepSeekAdapterConfig): ProviderAdapter;
40
+ export {};
41
+ //# sourceMappingURL=deepseek.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deepseek.d.ts","sourceRoot":"","sources":["../../src/adapters/deepseek.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EAIV,cAAc,EACd,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAEhE,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAKD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAMhF;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,iBAAiB,CAiB1E;AAED,UAAU,WAAW;IACnB,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,SAAS,WAAW,EAAE,CAAC;IAC1C,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC;IACtB,QAAQ,CAAC,cAAc,EAAE;QAAE,QAAQ,CAAC,aAAa,EAAE,IAAI,CAAA;KAAE,CAAC;IAC1D,QAAQ,CAAC,eAAe,CAAC,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAA;KAAE,CAAC;CAC7D;AAOD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,GAAG,oBAAoB,CAkB1F;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,qBAAqB,GAAG,eAAe,CAkHpF"}