@flop-labs/sdk 0.0.0-stage → 0.4.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 (617) hide show
  1. package/CHANGELOG.md +315 -0
  2. package/LICENSE +238 -0
  3. package/README.md +622 -2
  4. package/dist/a2a/agent-card.d.ts +56 -0
  5. package/dist/a2a/agent-card.d.ts.map +1 -0
  6. package/dist/a2a/agent-card.js +111 -0
  7. package/dist/a2a/agent-card.js.map +1 -0
  8. package/dist/a2a/index.d.ts +11 -0
  9. package/dist/a2a/index.d.ts.map +1 -0
  10. package/dist/a2a/index.js +11 -0
  11. package/dist/a2a/index.js.map +1 -0
  12. package/dist/a2a/task-lifecycle.d.ts +41 -0
  13. package/dist/a2a/task-lifecycle.d.ts.map +1 -0
  14. package/dist/a2a/task-lifecycle.js +60 -0
  15. package/dist/a2a/task-lifecycle.js.map +1 -0
  16. package/dist/a2a/types.d.ts +96 -0
  17. package/dist/a2a/types.d.ts.map +1 -0
  18. package/dist/a2a/types.js +23 -0
  19. package/dist/a2a/types.js.map +1 -0
  20. package/dist/a2a-cjs/agent-card.js +115 -0
  21. package/dist/a2a-cjs/agent-card.js.map +1 -0
  22. package/dist/a2a-cjs/index.js +21 -0
  23. package/dist/a2a-cjs/index.js.map +1 -0
  24. package/dist/a2a-cjs/package.json +1 -0
  25. package/dist/a2a-cjs/task-lifecycle.js +64 -0
  26. package/dist/a2a-cjs/task-lifecycle.js.map +1 -0
  27. package/dist/a2a-cjs/types.js +26 -0
  28. package/dist/a2a-cjs/types.js.map +1 -0
  29. package/dist/adaptor.d.ts +39 -0
  30. package/dist/adaptor.d.ts.map +1 -0
  31. package/dist/adaptor.js +130 -0
  32. package/dist/adaptor.js.map +1 -0
  33. package/dist/agent/errors.d.ts +95 -0
  34. package/dist/agent/errors.d.ts.map +1 -0
  35. package/dist/agent/errors.js +132 -0
  36. package/dist/agent/errors.js.map +1 -0
  37. package/dist/agent/task-delegation.d.ts +283 -0
  38. package/dist/agent/task-delegation.d.ts.map +1 -0
  39. package/dist/agent/task-delegation.js +444 -0
  40. package/dist/agent/task-delegation.js.map +1 -0
  41. package/dist/agent/types.d.ts +19 -0
  42. package/dist/agent/types.d.ts.map +1 -0
  43. package/dist/agent/types.js +7 -0
  44. package/dist/agent/types.js.map +1 -0
  45. package/dist/agent-wallet.d.ts +197 -0
  46. package/dist/agent-wallet.d.ts.map +1 -0
  47. package/dist/agent-wallet.js +408 -0
  48. package/dist/agent-wallet.js.map +1 -0
  49. package/dist/amhl.d.ts +61 -0
  50. package/dist/amhl.d.ts.map +1 -0
  51. package/dist/amhl.js +161 -0
  52. package/dist/amhl.js.map +1 -0
  53. package/dist/attestation.d.ts +126 -0
  54. package/dist/attestation.d.ts.map +1 -0
  55. package/dist/attestation.js +287 -0
  56. package/dist/attestation.js.map +1 -0
  57. package/dist/bip340-adaptor.d.ts +8 -0
  58. package/dist/bip340-adaptor.d.ts.map +1 -0
  59. package/dist/bip340-adaptor.js +129 -0
  60. package/dist/bip340-adaptor.js.map +1 -0
  61. package/dist/btc-relayer.d.ts +42 -0
  62. package/dist/btc-relayer.d.ts.map +1 -0
  63. package/dist/btc-relayer.js +40 -0
  64. package/dist/btc-relayer.js.map +1 -0
  65. package/dist/bundle/index.esm.js +2 -0
  66. package/dist/bundle/index.esm.js.map +1 -0
  67. package/dist/bundle/index.umd.cjs +2 -0
  68. package/dist/bundle/index.umd.cjs.map +1 -0
  69. package/dist/capability-claim-sink.d.ts +5 -0
  70. package/dist/capability-claim-sink.d.ts.map +1 -0
  71. package/dist/capability-claim-sink.js +6 -0
  72. package/dist/capability-claim-sink.js.map +1 -0
  73. package/dist/chain.d.ts +63 -0
  74. package/dist/chain.d.ts.map +1 -0
  75. package/dist/chain.js +100 -0
  76. package/dist/chain.js.map +1 -0
  77. package/dist/client.d.ts +356 -0
  78. package/dist/client.d.ts.map +1 -0
  79. package/dist/client.js +863 -0
  80. package/dist/client.js.map +1 -0
  81. package/dist/compute-channel/adaptor-settlement.d.ts +19 -0
  82. package/dist/compute-channel/adaptor-settlement.d.ts.map +1 -0
  83. package/dist/compute-channel/adaptor-settlement.js +40 -0
  84. package/dist/compute-channel/adaptor-settlement.js.map +1 -0
  85. package/dist/compute-channel/agent-client.d.ts +141 -0
  86. package/dist/compute-channel/agent-client.d.ts.map +1 -0
  87. package/dist/compute-channel/agent-client.js +265 -0
  88. package/dist/compute-channel/agent-client.js.map +1 -0
  89. package/dist/compute-channel/agent-driver.d.ts +59 -0
  90. package/dist/compute-channel/agent-driver.d.ts.map +1 -0
  91. package/dist/compute-channel/agent-driver.js +364 -0
  92. package/dist/compute-channel/agent-driver.js.map +1 -0
  93. package/dist/compute-channel/chain.d.ts +245 -0
  94. package/dist/compute-channel/chain.d.ts.map +1 -0
  95. package/dist/compute-channel/chain.js +490 -0
  96. package/dist/compute-channel/chain.js.map +1 -0
  97. package/dist/compute-channel/chat-render.d.ts +21 -0
  98. package/dist/compute-channel/chat-render.d.ts.map +1 -0
  99. package/dist/compute-channel/chat-render.js +87 -0
  100. package/dist/compute-channel/chat-render.js.map +1 -0
  101. package/dist/compute-channel/crypto.d.ts +19 -0
  102. package/dist/compute-channel/crypto.d.ts.map +1 -0
  103. package/dist/compute-channel/crypto.js +52 -0
  104. package/dist/compute-channel/crypto.js.map +1 -0
  105. package/dist/compute-channel/da.d.ts +111 -0
  106. package/dist/compute-channel/da.d.ts.map +1 -0
  107. package/dist/compute-channel/da.js +320 -0
  108. package/dist/compute-channel/da.js.map +1 -0
  109. package/dist/compute-channel/deepseek-v41.d.ts +56 -0
  110. package/dist/compute-channel/deepseek-v41.d.ts.map +1 -0
  111. package/dist/compute-channel/deepseek-v41.js +267 -0
  112. package/dist/compute-channel/deepseek-v41.js.map +1 -0
  113. package/dist/compute-channel/direct-session-chain.d.ts +3 -0
  114. package/dist/compute-channel/direct-session-chain.d.ts.map +1 -0
  115. package/dist/compute-channel/direct-session-chain.js +245 -0
  116. package/dist/compute-channel/direct-session-chain.js.map +1 -0
  117. package/dist/compute-channel/direct-session.d.ts +78 -0
  118. package/dist/compute-channel/direct-session.d.ts.map +1 -0
  119. package/dist/compute-channel/direct-session.js +208 -0
  120. package/dist/compute-channel/direct-session.js.map +1 -0
  121. package/dist/compute-channel/dispute.d.ts +103 -0
  122. package/dist/compute-channel/dispute.d.ts.map +1 -0
  123. package/dist/compute-channel/dispute.js +314 -0
  124. package/dist/compute-channel/dispute.js.map +1 -0
  125. package/dist/compute-channel/flop-meter.d.ts +96 -0
  126. package/dist/compute-channel/flop-meter.d.ts.map +1 -0
  127. package/dist/compute-channel/flop-meter.js +210 -0
  128. package/dist/compute-channel/flop-meter.js.map +1 -0
  129. package/dist/compute-channel/flop-submitter.d.ts +40 -0
  130. package/dist/compute-channel/flop-submitter.d.ts.map +1 -0
  131. package/dist/compute-channel/flop-submitter.js +134 -0
  132. package/dist/compute-channel/flop-submitter.js.map +1 -0
  133. package/dist/compute-channel/hybrid-candidate.d.ts +22 -0
  134. package/dist/compute-channel/hybrid-candidate.d.ts.map +1 -0
  135. package/dist/compute-channel/hybrid-candidate.js +155 -0
  136. package/dist/compute-channel/hybrid-candidate.js.map +1 -0
  137. package/dist/compute-channel/hybrid-metering.d.ts +36 -0
  138. package/dist/compute-channel/hybrid-metering.d.ts.map +1 -0
  139. package/dist/compute-channel/hybrid-metering.js +69 -0
  140. package/dist/compute-channel/hybrid-metering.js.map +1 -0
  141. package/dist/compute-channel/hybrid.d.ts +16 -0
  142. package/dist/compute-channel/hybrid.d.ts.map +1 -0
  143. package/dist/compute-channel/hybrid.js +98 -0
  144. package/dist/compute-channel/hybrid.js.map +1 -0
  145. package/dist/compute-channel/index.d.ts +47 -0
  146. package/dist/compute-channel/index.d.ts.map +1 -0
  147. package/dist/compute-channel/index.js +48 -0
  148. package/dist/compute-channel/index.js.map +1 -0
  149. package/dist/compute-channel/lane-producer.d.ts +92 -0
  150. package/dist/compute-channel/lane-producer.d.ts.map +1 -0
  151. package/dist/compute-channel/lane-producer.js +265 -0
  152. package/dist/compute-channel/lane-producer.js.map +1 -0
  153. package/dist/compute-channel/layered.d.ts +77 -0
  154. package/dist/compute-channel/layered.d.ts.map +1 -0
  155. package/dist/compute-channel/layered.js +220 -0
  156. package/dist/compute-channel/layered.js.map +1 -0
  157. package/dist/compute-channel/lineage.d.ts +19 -0
  158. package/dist/compute-channel/lineage.d.ts.map +1 -0
  159. package/dist/compute-channel/lineage.js +28 -0
  160. package/dist/compute-channel/lineage.js.map +1 -0
  161. package/dist/compute-channel/miner-host.d.ts +329 -0
  162. package/dist/compute-channel/miner-host.d.ts.map +1 -0
  163. package/dist/compute-channel/miner-host.js +880 -0
  164. package/dist/compute-channel/miner-host.js.map +1 -0
  165. package/dist/compute-channel/model-config.d.ts +87 -0
  166. package/dist/compute-channel/model-config.d.ts.map +1 -0
  167. package/dist/compute-channel/model-config.js +697 -0
  168. package/dist/compute-channel/model-config.js.map +1 -0
  169. package/dist/compute-channel/offers.d.ts +57 -0
  170. package/dist/compute-channel/offers.d.ts.map +1 -0
  171. package/dist/compute-channel/offers.js +182 -0
  172. package/dist/compute-channel/offers.js.map +1 -0
  173. package/dist/compute-channel/point-claim-sink.d.ts +5 -0
  174. package/dist/compute-channel/point-claim-sink.d.ts.map +1 -0
  175. package/dist/compute-channel/point-claim-sink.js +6 -0
  176. package/dist/compute-channel/point-claim-sink.js.map +1 -0
  177. package/dist/compute-channel/protocol.d.ts +243 -0
  178. package/dist/compute-channel/protocol.d.ts.map +1 -0
  179. package/dist/compute-channel/protocol.js +249 -0
  180. package/dist/compute-channel/protocol.js.map +1 -0
  181. package/dist/compute-channel/runtime-storage.d.ts +6 -0
  182. package/dist/compute-channel/runtime-storage.d.ts.map +1 -0
  183. package/dist/compute-channel/runtime-storage.js +11 -0
  184. package/dist/compute-channel/runtime-storage.js.map +1 -0
  185. package/dist/compute-channel/sampled-audit.d.ts +24 -0
  186. package/dist/compute-channel/sampled-audit.d.ts.map +1 -0
  187. package/dist/compute-channel/sampled-audit.js +97 -0
  188. package/dist/compute-channel/sampled-audit.js.map +1 -0
  189. package/dist/compute-channel/session-auth.d.ts +6 -0
  190. package/dist/compute-channel/session-auth.d.ts.map +1 -0
  191. package/dist/compute-channel/session-auth.js +23 -0
  192. package/dist/compute-channel/session-auth.js.map +1 -0
  193. package/dist/compute-channel/session-estimate.d.ts +103 -0
  194. package/dist/compute-channel/session-estimate.d.ts.map +1 -0
  195. package/dist/compute-channel/session-estimate.js +140 -0
  196. package/dist/compute-channel/session-estimate.js.map +1 -0
  197. package/dist/compute-channel/session-prior-bank.d.ts +61 -0
  198. package/dist/compute-channel/session-prior-bank.d.ts.map +1 -0
  199. package/dist/compute-channel/session-prior-bank.js +74 -0
  200. package/dist/compute-channel/session-prior-bank.js.map +1 -0
  201. package/dist/compute-channel/session-prior.d.ts +145 -0
  202. package/dist/compute-channel/session-prior.d.ts.map +1 -0
  203. package/dist/compute-channel/session-prior.js +325 -0
  204. package/dist/compute-channel/session-prior.js.map +1 -0
  205. package/dist/compute-channel/session-store.d.ts +51 -0
  206. package/dist/compute-channel/session-store.d.ts.map +1 -0
  207. package/dist/compute-channel/session-store.js +186 -0
  208. package/dist/compute-channel/session-store.js.map +1 -0
  209. package/dist/compute-channel/session.d.ts +120 -0
  210. package/dist/compute-channel/session.d.ts.map +1 -0
  211. package/dist/compute-channel/session.js +232 -0
  212. package/dist/compute-channel/session.js.map +1 -0
  213. package/dist/compute-channel/toploc-checker.d.ts +384 -0
  214. package/dist/compute-channel/toploc-checker.d.ts.map +1 -0
  215. package/dist/compute-channel/toploc-checker.js +794 -0
  216. package/dist/compute-channel/toploc-checker.js.map +1 -0
  217. package/dist/compute-channel/toploc-completion-rpc.d.ts +26 -0
  218. package/dist/compute-channel/toploc-completion-rpc.d.ts.map +1 -0
  219. package/dist/compute-channel/toploc-completion-rpc.js +391 -0
  220. package/dist/compute-channel/toploc-completion-rpc.js.map +1 -0
  221. package/dist/compute-channel/toploc-completion.d.ts +109 -0
  222. package/dist/compute-channel/toploc-completion.d.ts.map +1 -0
  223. package/dist/compute-channel/toploc-completion.js +301 -0
  224. package/dist/compute-channel/toploc-completion.js.map +1 -0
  225. package/dist/compute-channel/toploc-evidence.d.ts +185 -0
  226. package/dist/compute-channel/toploc-evidence.d.ts.map +1 -0
  227. package/dist/compute-channel/toploc-evidence.js +299 -0
  228. package/dist/compute-channel/toploc-evidence.js.map +1 -0
  229. package/dist/compute-channel/toploc-gumbel.d.ts +149 -0
  230. package/dist/compute-channel/toploc-gumbel.d.ts.map +1 -0
  231. package/dist/compute-channel/toploc-gumbel.js +245 -0
  232. package/dist/compute-channel/toploc-gumbel.js.map +1 -0
  233. package/dist/compute-channel/toploc.d.ts +63 -0
  234. package/dist/compute-channel/toploc.d.ts.map +1 -0
  235. package/dist/compute-channel/toploc.js +197 -0
  236. package/dist/compute-channel/toploc.js.map +1 -0
  237. package/dist/compute-channel/transcript.d.ts +127 -0
  238. package/dist/compute-channel/transcript.d.ts.map +1 -0
  239. package/dist/compute-channel/transcript.js +279 -0
  240. package/dist/compute-channel/transcript.js.map +1 -0
  241. package/dist/compute-channel/transport-http.d.ts +217 -0
  242. package/dist/compute-channel/transport-http.d.ts.map +1 -0
  243. package/dist/compute-channel/transport-http.js +625 -0
  244. package/dist/compute-channel/transport-http.js.map +1 -0
  245. package/dist/coordination.d.ts +341 -0
  246. package/dist/coordination.d.ts.map +1 -0
  247. package/dist/coordination.js +481 -0
  248. package/dist/coordination.js.map +1 -0
  249. package/dist/da-client.d.ts +124 -0
  250. package/dist/da-client.d.ts.map +1 -0
  251. package/dist/da-client.js +127 -0
  252. package/dist/da-client.js.map +1 -0
  253. package/dist/discovery/capabilities.d.ts +129 -0
  254. package/dist/discovery/capabilities.d.ts.map +1 -0
  255. package/dist/discovery/capabilities.js +398 -0
  256. package/dist/discovery/capabilities.js.map +1 -0
  257. package/dist/discovery/discovery-service.d.ts +476 -0
  258. package/dist/discovery/discovery-service.d.ts.map +1 -0
  259. package/dist/discovery/discovery-service.js +1005 -0
  260. package/dist/discovery/discovery-service.js.map +1 -0
  261. package/dist/discovery/examples.d.ts +50 -0
  262. package/dist/discovery/examples.d.ts.map +1 -0
  263. package/dist/discovery/examples.js +163 -0
  264. package/dist/discovery/examples.js.map +1 -0
  265. package/dist/discovery/fee-estimation.d.ts +550 -0
  266. package/dist/discovery/fee-estimation.d.ts.map +1 -0
  267. package/dist/discovery/fee-estimation.js +921 -0
  268. package/dist/discovery/fee-estimation.js.map +1 -0
  269. package/dist/discovery/index.d.ts +38 -0
  270. package/dist/discovery/index.d.ts.map +1 -0
  271. package/dist/discovery/index.js +32 -0
  272. package/dist/discovery/index.js.map +1 -0
  273. package/dist/discovery/metered-pricing.d.ts +100 -0
  274. package/dist/discovery/metered-pricing.d.ts.map +1 -0
  275. package/dist/discovery/metered-pricing.js +150 -0
  276. package/dist/discovery/metered-pricing.js.map +1 -0
  277. package/dist/discovery/priority.d.ts +16 -0
  278. package/dist/discovery/priority.d.ts.map +1 -0
  279. package/dist/discovery/priority.js +17 -0
  280. package/dist/discovery/priority.js.map +1 -0
  281. package/dist/discovery/scoring.d.ts +231 -0
  282. package/dist/discovery/scoring.d.ts.map +1 -0
  283. package/dist/discovery/scoring.js +354 -0
  284. package/dist/discovery/scoring.js.map +1 -0
  285. package/dist/ecdsa-adaptor.d.ts +72 -0
  286. package/dist/ecdsa-adaptor.d.ts.map +1 -0
  287. package/dist/ecdsa-adaptor.js +351 -0
  288. package/dist/ecdsa-adaptor.js.map +1 -0
  289. package/dist/errors.d.ts +98 -0
  290. package/dist/errors.d.ts.map +1 -0
  291. package/dist/errors.js +190 -0
  292. package/dist/errors.js.map +1 -0
  293. package/dist/escrow.d.ts +116 -0
  294. package/dist/escrow.d.ts.map +1 -0
  295. package/dist/escrow.js +172 -0
  296. package/dist/escrow.js.map +1 -0
  297. package/dist/evm-relayer.d.ts +12 -0
  298. package/dist/evm-relayer.d.ts.map +1 -0
  299. package/dist/evm-relayer.js +25 -0
  300. package/dist/evm-relayer.js.map +1 -0
  301. package/dist/experimental.d.ts +3 -0
  302. package/dist/experimental.d.ts.map +1 -0
  303. package/dist/experimental.js +3 -0
  304. package/dist/experimental.js.map +1 -0
  305. package/dist/faucet.d.ts +141 -0
  306. package/dist/faucet.d.ts.map +1 -0
  307. package/dist/faucet.js +312 -0
  308. package/dist/faucet.js.map +1 -0
  309. package/dist/finality-status.d.ts +21 -0
  310. package/dist/finality-status.d.ts.map +1 -0
  311. package/dist/finality-status.js +10 -0
  312. package/dist/finality-status.js.map +1 -0
  313. package/dist/generated-client/capabilities.d.ts +83 -0
  314. package/dist/generated-client/capabilities.d.ts.map +1 -0
  315. package/dist/generated-client/capabilities.js +87 -0
  316. package/dist/generated-client/capabilities.js.map +1 -0
  317. package/dist/generated-client/cli.d.ts +3 -0
  318. package/dist/generated-client/cli.d.ts.map +1 -0
  319. package/dist/generated-client/cli.js +33 -0
  320. package/dist/generated-client/cli.js.map +1 -0
  321. package/dist/generated-client/errors.d.ts +13 -0
  322. package/dist/generated-client/errors.d.ts.map +1 -0
  323. package/dist/generated-client/errors.js +23 -0
  324. package/dist/generated-client/errors.js.map +1 -0
  325. package/dist/generated-client/factory.d.ts +28 -0
  326. package/dist/generated-client/factory.d.ts.map +1 -0
  327. package/dist/generated-client/factory.js +182 -0
  328. package/dist/generated-client/factory.js.map +1 -0
  329. package/dist/generated-client/generator.d.ts +9 -0
  330. package/dist/generated-client/generator.d.ts.map +1 -0
  331. package/dist/generated-client/generator.js +80 -0
  332. package/dist/generated-client/generator.js.map +1 -0
  333. package/dist/generated-client/index.d.ts +11 -0
  334. package/dist/generated-client/index.d.ts.map +1 -0
  335. package/dist/generated-client/index.js +6 -0
  336. package/dist/generated-client/index.js.map +1 -0
  337. package/dist/generated-client/profile.d.ts +166 -0
  338. package/dist/generated-client/profile.d.ts.map +1 -0
  339. package/dist/generated-client/profile.js +158 -0
  340. package/dist/generated-client/profile.js.map +1 -0
  341. package/dist/generated-client/templates/agent-chat.d.ts +16 -0
  342. package/dist/generated-client/templates/agent-chat.d.ts.map +1 -0
  343. package/dist/generated-client/templates/agent-chat.js +12 -0
  344. package/dist/generated-client/templates/agent-chat.js.map +1 -0
  345. package/dist/generated-client/templates/index.d.ts +4 -0
  346. package/dist/generated-client/templates/index.d.ts.map +1 -0
  347. package/dist/generated-client/templates/index.js +4 -0
  348. package/dist/generated-client/templates/index.js.map +1 -0
  349. package/dist/generated-client/templates/miner-operator.d.ts +16 -0
  350. package/dist/generated-client/templates/miner-operator.d.ts.map +1 -0
  351. package/dist/generated-client/templates/miner-operator.js +12 -0
  352. package/dist/generated-client/templates/miner-operator.js.map +1 -0
  353. package/dist/generated-client/templates/model-publisher.d.ts +21 -0
  354. package/dist/generated-client/templates/model-publisher.d.ts.map +1 -0
  355. package/dist/generated-client/templates/model-publisher.js +13 -0
  356. package/dist/generated-client/templates/model-publisher.js.map +1 -0
  357. package/dist/hardware.d.ts +68 -0
  358. package/dist/hardware.d.ts.map +1 -0
  359. package/dist/hardware.js +222 -0
  360. package/dist/hardware.js.map +1 -0
  361. package/dist/index.d.ts +109 -0
  362. package/dist/index.d.ts.map +1 -0
  363. package/dist/index.js +140 -0
  364. package/dist/index.js.map +1 -0
  365. package/dist/model-loader/canonical.d.ts +79 -0
  366. package/dist/model-loader/canonical.d.ts.map +1 -0
  367. package/dist/model-loader/canonical.js +116 -0
  368. package/dist/model-loader/canonical.js.map +1 -0
  369. package/dist/model-loader/dir.d.ts +26 -0
  370. package/dist/model-loader/dir.d.ts.map +1 -0
  371. package/dist/model-loader/dir.js +109 -0
  372. package/dist/model-loader/dir.js.map +1 -0
  373. package/dist/model-loader/dmverity.d.ts +78 -0
  374. package/dist/model-loader/dmverity.d.ts.map +1 -0
  375. package/dist/model-loader/dmverity.js +141 -0
  376. package/dist/model-loader/dmverity.js.map +1 -0
  377. package/dist/model-loader/download-state.d.ts +24 -0
  378. package/dist/model-loader/download-state.d.ts.map +1 -0
  379. package/dist/model-loader/download-state.js +99 -0
  380. package/dist/model-loader/download-state.js.map +1 -0
  381. package/dist/model-loader/fetch.d.ts +51 -0
  382. package/dist/model-loader/fetch.d.ts.map +1 -0
  383. package/dist/model-loader/fetch.js +410 -0
  384. package/dist/model-loader/fetch.js.map +1 -0
  385. package/dist/model-loader/file-table.d.ts +38 -0
  386. package/dist/model-loader/file-table.d.ts.map +1 -0
  387. package/dist/model-loader/file-table.js +106 -0
  388. package/dist/model-loader/file-table.js.map +1 -0
  389. package/dist/model-loader/hf-preflight.d.ts +65 -0
  390. package/dist/model-loader/hf-preflight.d.ts.map +1 -0
  391. package/dist/model-loader/hf-preflight.js +179 -0
  392. package/dist/model-loader/hf-preflight.js.map +1 -0
  393. package/dist/model-loader/index.d.ts +27 -0
  394. package/dist/model-loader/index.d.ts.map +1 -0
  395. package/dist/model-loader/index.js +21 -0
  396. package/dist/model-loader/index.js.map +1 -0
  397. package/dist/model-loader/registry.d.ts +24 -0
  398. package/dist/model-loader/registry.d.ts.map +1 -0
  399. package/dist/model-loader/registry.js +105 -0
  400. package/dist/model-loader/registry.js.map +1 -0
  401. package/dist/model-loader/types.d.ts +101 -0
  402. package/dist/model-loader/types.d.ts.map +1 -0
  403. package/dist/model-loader/types.js +13 -0
  404. package/dist/model-loader/types.js.map +1 -0
  405. package/dist/model-loader/verify.d.ts +83 -0
  406. package/dist/model-loader/verify.d.ts.map +1 -0
  407. package/dist/model-loader/verify.js +138 -0
  408. package/dist/model-loader/verify.js.map +1 -0
  409. package/dist/model-qualification.d.ts +79 -0
  410. package/dist/model-qualification.d.ts.map +1 -0
  411. package/dist/model-qualification.js +135 -0
  412. package/dist/model-qualification.js.map +1 -0
  413. package/dist/near-relayer.d.ts +30 -0
  414. package/dist/near-relayer.d.ts.map +1 -0
  415. package/dist/near-relayer.js +81 -0
  416. package/dist/near-relayer.js.map +1 -0
  417. package/dist/paid-storage/bytes.d.ts +21 -0
  418. package/dist/paid-storage/bytes.d.ts.map +1 -0
  419. package/dist/paid-storage/bytes.js +71 -0
  420. package/dist/paid-storage/bytes.js.map +1 -0
  421. package/dist/paid-storage/chain.d.ts +20 -0
  422. package/dist/paid-storage/chain.d.ts.map +1 -0
  423. package/dist/paid-storage/chain.js +182 -0
  424. package/dist/paid-storage/chain.js.map +1 -0
  425. package/dist/paid-storage/client.d.ts +161 -0
  426. package/dist/paid-storage/client.d.ts.map +1 -0
  427. package/dist/paid-storage/client.js +1038 -0
  428. package/dist/paid-storage/client.js.map +1 -0
  429. package/dist/paid-storage/cloudflare.d.ts +4 -0
  430. package/dist/paid-storage/cloudflare.d.ts.map +1 -0
  431. package/dist/paid-storage/cloudflare.js +9 -0
  432. package/dist/paid-storage/cloudflare.js.map +1 -0
  433. package/dist/paid-storage/codec.d.ts +8 -0
  434. package/dist/paid-storage/codec.d.ts.map +1 -0
  435. package/dist/paid-storage/codec.js +92 -0
  436. package/dist/paid-storage/codec.js.map +1 -0
  437. package/dist/paid-storage/crypto.d.ts +27 -0
  438. package/dist/paid-storage/crypto.d.ts.map +1 -0
  439. package/dist/paid-storage/crypto.js +91 -0
  440. package/dist/paid-storage/crypto.js.map +1 -0
  441. package/dist/paid-storage/heads.d.ts +26 -0
  442. package/dist/paid-storage/heads.d.ts.map +1 -0
  443. package/dist/paid-storage/heads.js +208 -0
  444. package/dist/paid-storage/heads.js.map +1 -0
  445. package/dist/paid-storage/index.d.ts +14 -0
  446. package/dist/paid-storage/index.d.ts.map +1 -0
  447. package/dist/paid-storage/index.js +7 -0
  448. package/dist/paid-storage/index.js.map +1 -0
  449. package/dist/paid-storage/memory-wire.d.ts +85 -0
  450. package/dist/paid-storage/memory-wire.d.ts.map +1 -0
  451. package/dist/paid-storage/memory-wire.js +147 -0
  452. package/dist/paid-storage/memory-wire.js.map +1 -0
  453. package/dist/paid-storage/node-store.d.ts +9 -0
  454. package/dist/paid-storage/node-store.d.ts.map +1 -0
  455. package/dist/paid-storage/node-store.js +34 -0
  456. package/dist/paid-storage/node-store.js.map +1 -0
  457. package/dist/paid-storage/profile.d.ts +21 -0
  458. package/dist/paid-storage/profile.d.ts.map +1 -0
  459. package/dist/paid-storage/profile.js +22 -0
  460. package/dist/paid-storage/profile.js.map +1 -0
  461. package/dist/paid-storage/store.d.ts +18 -0
  462. package/dist/paid-storage/store.d.ts.map +1 -0
  463. package/dist/paid-storage/store.js +32 -0
  464. package/dist/paid-storage/store.js.map +1 -0
  465. package/dist/paid-storage/transport.d.ts +70 -0
  466. package/dist/paid-storage/transport.d.ts.map +1 -0
  467. package/dist/paid-storage/transport.js +140 -0
  468. package/dist/paid-storage/transport.js.map +1 -0
  469. package/dist/paid-storage/vouchers.d.ts +75 -0
  470. package/dist/paid-storage/vouchers.d.ts.map +1 -0
  471. package/dist/paid-storage/vouchers.js +239 -0
  472. package/dist/paid-storage/vouchers.js.map +1 -0
  473. package/dist/paid-storage-wire.d.ts +11 -0
  474. package/dist/paid-storage-wire.d.ts.map +1 -0
  475. package/dist/paid-storage-wire.js +184 -0
  476. package/dist/paid-storage-wire.js.map +1 -0
  477. package/dist/point-claims.d.ts +40 -0
  478. package/dist/point-claims.d.ts.map +1 -0
  479. package/dist/point-claims.js +98 -0
  480. package/dist/point-claims.js.map +1 -0
  481. package/dist/quickstart.d.ts +307 -0
  482. package/dist/quickstart.d.ts.map +1 -0
  483. package/dist/quickstart.js +536 -0
  484. package/dist/quickstart.js.map +1 -0
  485. package/dist/react/context.d.ts +10 -0
  486. package/dist/react/context.d.ts.map +1 -0
  487. package/dist/react/context.js +16 -0
  488. package/dist/react/context.js.map +1 -0
  489. package/dist/react/hooks.d.ts +206 -0
  490. package/dist/react/hooks.d.ts.map +1 -0
  491. package/dist/react/hooks.js +560 -0
  492. package/dist/react/hooks.js.map +1 -0
  493. package/dist/react/index.d.ts +4 -0
  494. package/dist/react/index.d.ts.map +1 -0
  495. package/dist/react/index.js +4 -0
  496. package/dist/react/index.js.map +1 -0
  497. package/dist/react/provider.d.ts +18 -0
  498. package/dist/react/provider.d.ts.map +1 -0
  499. package/dist/react/provider.js +17 -0
  500. package/dist/react/provider.js.map +1 -0
  501. package/dist/relayer.d.ts +122 -0
  502. package/dist/relayer.d.ts.map +1 -0
  503. package/dist/relayer.js +203 -0
  504. package/dist/relayer.js.map +1 -0
  505. package/dist/runtime-compatibility.d.ts +8 -0
  506. package/dist/runtime-compatibility.d.ts.map +1 -0
  507. package/dist/runtime-compatibility.js +20 -0
  508. package/dist/runtime-compatibility.js.map +1 -0
  509. package/dist/session-manager.d.ts +197 -0
  510. package/dist/session-manager.d.ts.map +1 -0
  511. package/dist/session-manager.js +429 -0
  512. package/dist/session-manager.js.map +1 -0
  513. package/dist/solana-ptlc.d.ts +64 -0
  514. package/dist/solana-ptlc.d.ts.map +1 -0
  515. package/dist/solana-ptlc.js +137 -0
  516. package/dist/solana-ptlc.js.map +1 -0
  517. package/dist/staking-client.d.ts +103 -0
  518. package/dist/staking-client.d.ts.map +1 -0
  519. package/dist/staking-client.js +308 -0
  520. package/dist/staking-client.js.map +1 -0
  521. package/dist/staking-types.d.ts +203 -0
  522. package/dist/staking-types.d.ts.map +1 -0
  523. package/dist/staking-types.js +16 -0
  524. package/dist/staking-types.js.map +1 -0
  525. package/dist/submit-tx.d.ts +14 -0
  526. package/dist/submit-tx.d.ts.map +1 -0
  527. package/dist/submit-tx.js +33 -0
  528. package/dist/submit-tx.js.map +1 -0
  529. package/dist/templates/index.d.ts +52 -0
  530. package/dist/templates/index.d.ts.map +1 -0
  531. package/dist/templates/index.js +123 -0
  532. package/dist/templates/index.js.map +1 -0
  533. package/dist/ton/index.d.ts +52 -0
  534. package/dist/ton/index.d.ts.map +1 -0
  535. package/dist/ton/index.js +163 -0
  536. package/dist/ton/index.js.map +1 -0
  537. package/dist/ton-relayer.d.ts +26 -0
  538. package/dist/ton-relayer.d.ts.map +1 -0
  539. package/dist/ton-relayer.js +22 -0
  540. package/dist/ton-relayer.js.map +1 -0
  541. package/dist/tracing.d.ts +48 -0
  542. package/dist/tracing.d.ts.map +1 -0
  543. package/dist/tracing.js +108 -0
  544. package/dist/tracing.js.map +1 -0
  545. package/dist/transaction-signer.d.ts +13 -0
  546. package/dist/transaction-signer.d.ts.map +1 -0
  547. package/dist/transaction-signer.js +13 -0
  548. package/dist/transaction-signer.js.map +1 -0
  549. package/dist/trust-root.d.ts +56 -0
  550. package/dist/trust-root.d.ts.map +1 -0
  551. package/dist/trust-root.js +28 -0
  552. package/dist/trust-root.js.map +1 -0
  553. package/dist/types.d.ts +201 -0
  554. package/dist/types.d.ts.map +1 -0
  555. package/dist/types.js +3 -0
  556. package/dist/types.js.map +1 -0
  557. package/dist/validator-staking-client.d.ts +87 -0
  558. package/dist/validator-staking-client.d.ts.map +1 -0
  559. package/dist/validator-staking-client.js +226 -0
  560. package/dist/validator-staking-client.js.map +1 -0
  561. package/dist/virtuals-acp.d.ts +149 -0
  562. package/dist/virtuals-acp.d.ts.map +1 -0
  563. package/dist/virtuals-acp.js +418 -0
  564. package/dist/virtuals-acp.js.map +1 -0
  565. package/dist/wallet-manager.d.ts +199 -0
  566. package/dist/wallet-manager.d.ts.map +1 -0
  567. package/dist/wallet-manager.js +425 -0
  568. package/dist/wallet-manager.js.map +1 -0
  569. package/dist/wallets/burner.d.ts +45 -0
  570. package/dist/wallets/burner.d.ts.map +1 -0
  571. package/dist/wallets/burner.js +58 -0
  572. package/dist/wallets/burner.js.map +1 -0
  573. package/dist/wallets/index.d.ts +26 -0
  574. package/dist/wallets/index.d.ts.map +1 -0
  575. package/dist/wallets/index.js +20 -0
  576. package/dist/wallets/index.js.map +1 -0
  577. package/dist/wallets/injected.d.ts +22 -0
  578. package/dist/wallets/injected.d.ts.map +1 -0
  579. package/dist/wallets/injected.js +45 -0
  580. package/dist/wallets/injected.js.map +1 -0
  581. package/dist/wallets/ledger.d.ts +76 -0
  582. package/dist/wallets/ledger.d.ts.map +1 -0
  583. package/dist/wallets/ledger.js +106 -0
  584. package/dist/wallets/ledger.js.map +1 -0
  585. package/dist/wallets/near.d.ts +69 -0
  586. package/dist/wallets/near.d.ts.map +1 -0
  587. package/dist/wallets/near.js +101 -0
  588. package/dist/wallets/near.js.map +1 -0
  589. package/dist/wallets/types.d.ts +42 -0
  590. package/dist/wallets/types.d.ts.map +1 -0
  591. package/dist/wallets/types.js +31 -0
  592. package/dist/wallets/types.js.map +1 -0
  593. package/dist/wallets/walletconnect.d.ts +38 -0
  594. package/dist/wallets/walletconnect.d.ts.map +1 -0
  595. package/dist/wallets/walletconnect.js +94 -0
  596. package/dist/wallets/walletconnect.js.map +1 -0
  597. package/dist/weak-subjectivity.d.ts +213 -0
  598. package/dist/weak-subjectivity.d.ts.map +1 -0
  599. package/dist/weak-subjectivity.js +389 -0
  600. package/dist/weak-subjectivity.js.map +1 -0
  601. package/dist/x402-types/channel-types.d.ts +78 -0
  602. package/dist/x402-types/channel-types.d.ts.map +1 -0
  603. package/dist/x402-types/channel-types.js +5 -0
  604. package/dist/x402-types/channel-types.js.map +1 -0
  605. package/dist/x402-types/exact-flop.d.ts +29 -0
  606. package/dist/x402-types/exact-flop.d.ts.map +1 -0
  607. package/dist/x402-types/exact-flop.js +64 -0
  608. package/dist/x402-types/exact-flop.js.map +1 -0
  609. package/dist/x402-types/index.d.ts +65 -0
  610. package/dist/x402-types/index.d.ts.map +1 -0
  611. package/dist/x402-types/index.js +26 -0
  612. package/dist/x402-types/index.js.map +1 -0
  613. package/dist/x402.d.ts +111 -0
  614. package/dist/x402.d.ts.map +1 -0
  615. package/dist/x402.js +206 -0
  616. package/dist/x402.js.map +1 -0
  617. package/package.json +165 -3
@@ -0,0 +1,1005 @@
1
+ /**
2
+ * Model Discovery Service for FLOP Network
3
+ *
4
+ * This module provides the main discovery service for finding and selecting
5
+ * models based on capabilities, quality, cost, and availability.
6
+ *
7
+ * @module discovery/discovery-service
8
+ * @see docs/research/r0009-agent-onboarding-recommendations.md section 2
9
+ */
10
+ import { inferCapabilityFromPrompt, createEmptyProfile, } from './capabilities.js';
11
+ import { ModelScorer, BENCHMARK_CAPABILITY_MAP, estimateCapabilitiesFromBenchmarks, inferModelSize, estimateCostFromSize, } from './scoring.js';
12
+ import { FeeEstimationError, createFeeEstimator, } from './fee-estimation.js';
13
+ import { meteredPricing, readMeteringChainParams } from './metered-pricing.js';
14
+ // ── Default Implementations ───────────────────────────────────────────────
15
+ /**
16
+ * On-chain model registry implementation.
17
+ *
18
+ * This implementation properly maps the model-registry pallet's storage format
19
+ * to the SDK's ModelInfo format.
20
+ */
21
+ export class OnChainModelRegistry {
22
+ api;
23
+ constructor(api) {
24
+ this.api = api;
25
+ }
26
+ async listModels() {
27
+ const models = [];
28
+ try {
29
+ // Check if model-registry pallet exists
30
+ if (this.api.query.modelRegistry) {
31
+ const entries = await this.api.query.modelRegistry.models.entries();
32
+ for (const [key, value] of entries) {
33
+ if (value.isSome) {
34
+ const modelData = value.unwrap().toJSON();
35
+ models.push(this.palletEntryToModelInfo(modelData));
36
+ }
37
+ }
38
+ }
39
+ }
40
+ catch (error) {
41
+ console.warn('Failed to query on-chain model registry:', error);
42
+ }
43
+ return models;
44
+ }
45
+ async getModel(hash) {
46
+ try {
47
+ if (this.api.query.modelRegistry) {
48
+ const result = await this.api.query.modelRegistry.models(hash);
49
+ if (result.isSome) {
50
+ return this.palletEntryToModelInfo(result.unwrap().toJSON());
51
+ }
52
+ }
53
+ }
54
+ catch (error) {
55
+ console.warn(`Failed to get model ${hash}:`, error);
56
+ }
57
+ return null;
58
+ }
59
+ async getModelByName(name) {
60
+ const models = await this.listModels();
61
+ return models.find(m => m.name.toLowerCase() === name.toLowerCase()) ?? null;
62
+ }
63
+ async findByCapability(capability) {
64
+ const models = await this.listModels();
65
+ return models.filter(m => {
66
+ const score = m.capabilities.get(capability);
67
+ return score !== undefined && score > 0;
68
+ });
69
+ }
70
+ /**
71
+ * Convert a byte array (BoundedVec<u8>) to a string.
72
+ */
73
+ bytesToString(bytes) {
74
+ if (!bytes)
75
+ return '';
76
+ return String.fromCharCode(...bytes);
77
+ }
78
+ /**
79
+ * Convert capability string from pallet to SDK ModelCapability.
80
+ * The pallet uses enum variants like 'TextGeneration', SDK uses snake_case.
81
+ */
82
+ palletCapabilityToSdk(palletCap) {
83
+ // Map pallet PascalCase enum to SDK snake_case
84
+ const mapping = {
85
+ 'TextGeneration': 'text_generation',
86
+ 'Translation': 'translation',
87
+ 'Summarization': 'summarization',
88
+ 'QuestionAnswering': 'question_answering',
89
+ 'CodeGeneration': 'code_generation',
90
+ 'CodeReview': 'code_review',
91
+ 'MathematicalReasoning': 'mathematical_reasoning',
92
+ 'LogicalReasoning': 'logical_reasoning',
93
+ 'Planning': 'planning',
94
+ 'ImageGeneration': 'image_generation',
95
+ 'ImageUnderstanding': 'image_understanding',
96
+ 'AudioGeneration': 'audio_generation',
97
+ 'VideoUnderstanding': 'video_understanding',
98
+ 'Embeddings': 'embeddings',
99
+ 'FunctionCalling': 'function_calling',
100
+ 'StructuredOutput': 'structured_output',
101
+ };
102
+ return mapping[palletCap] ?? 'text_generation';
103
+ }
104
+ /**
105
+ * Derive capability quality scores from benchmark scores.
106
+ *
107
+ * Uses benchmark-to-capability mapping from scoring.ts to estimate
108
+ * quality scores for each capability based on benchmark performance.
109
+ */
110
+ deriveCapabilityScores(taskTypes, benchmarkScores) {
111
+ const capabilities = new Map();
112
+ // First, mark all supported capabilities from taskTypes with a base score
113
+ for (const taskType of taskTypes) {
114
+ const cap = this.palletCapabilityToSdk(taskType);
115
+ capabilities.set(cap, 50); // Base score for supported capability
116
+ }
117
+ // Then, derive quality scores from benchmarks
118
+ for (const benchmark of benchmarkScores) {
119
+ const benchName = this.bytesToString(benchmark.benchmarkName).toLowerCase();
120
+ const score = benchmark.score;
121
+ // Map benchmark to capabilities
122
+ const benchCaps = BENCHMARK_CAPABILITY_MAP[benchName];
123
+ if (benchCaps) {
124
+ for (const cap of benchCaps) {
125
+ // Update score if higher, or average if multiple benchmarks
126
+ const existing = capabilities.get(cap);
127
+ if (existing !== undefined) {
128
+ // Average with existing score
129
+ capabilities.set(cap, Math.round((existing + score) / 2));
130
+ }
131
+ else {
132
+ capabilities.set(cap, score);
133
+ }
134
+ }
135
+ }
136
+ }
137
+ return capabilities;
138
+ }
139
+ /**
140
+ * Convert pallet model registry entry to SDK ModelInfo.
141
+ */
142
+ palletEntryToModelInfo(entry) {
143
+ // Convert byte arrays to strings
144
+ const name = this.bytesToString(entry.modelName);
145
+ const version = this.bytesToString(entry.version);
146
+ // Derive capabilities from taskTypes and benchmarkScores
147
+ const capabilities = this.deriveCapabilityScores(entry.taskTypes, entry.benchmarkScores);
148
+ // Infer model size from paramsBillion
149
+ const parameterCount = entry.paramsBillion;
150
+ const size = inferModelSize(parameterCount);
151
+ // Context window and max output tokens are not stored in the pallet
152
+ // Use reasonable defaults based on model size
153
+ const contextWindowDefaults = {
154
+ small: 4096,
155
+ medium: 8192,
156
+ large: 32768,
157
+ xlarge: 128000,
158
+ };
159
+ const maxOutputDefaults = {
160
+ small: 2048,
161
+ medium: 4096,
162
+ large: 8192,
163
+ xlarge: 16384,
164
+ };
165
+ // Check for function_calling and structured_output in capabilities
166
+ const supportsFunctionCalling = capabilities.has('function_calling') &&
167
+ (capabilities.get('function_calling') ?? 0) > 0;
168
+ const supportsStructuredOutput = capabilities.has('structured_output') &&
169
+ (capabilities.get('structured_output') ?? 0) > 0;
170
+ return {
171
+ hash: entry.modelHash,
172
+ name,
173
+ size,
174
+ parameterCount,
175
+ contextWindow: contextWindowDefaults[size],
176
+ maxOutputTokens: maxOutputDefaults[size],
177
+ capabilities,
178
+ supportsStreaming: true, // Most models support streaming by default
179
+ supportsFunctionCalling,
180
+ supportsStructuredOutput,
181
+ version,
182
+ provider: entry.publisher, // Use publisher as provider
183
+ };
184
+ }
185
+ }
186
+ /**
187
+ * Off-chain benchmark provider implementation.
188
+ */
189
+ export class OffChainBenchmarkProvider {
190
+ endpoint;
191
+ cache = new Map();
192
+ constructor(endpoint) {
193
+ this.endpoint = endpoint;
194
+ }
195
+ async getBenchmarks(modelId) {
196
+ // Check cache first
197
+ const cached = this.cache.get(modelId);
198
+ if (cached)
199
+ return cached;
200
+ // Fetch from endpoint if available
201
+ if (this.endpoint) {
202
+ try {
203
+ const response = await fetch(`${this.endpoint}/benchmarks/${modelId}`);
204
+ if (response.ok) {
205
+ const data = await response.json();
206
+ this.cache.set(modelId, data.benchmarks);
207
+ return data.benchmarks;
208
+ }
209
+ }
210
+ catch (error) {
211
+ console.warn(`Failed to fetch benchmarks for ${modelId}:`, error);
212
+ }
213
+ }
214
+ return [];
215
+ }
216
+ async getBenchmarksBatch(modelIds) {
217
+ const results = new Map();
218
+ await Promise.all(modelIds.map(async (id) => {
219
+ results.set(id, await this.getBenchmarks(id));
220
+ }));
221
+ return results;
222
+ }
223
+ }
224
+ /**
225
+ * On-chain availability provider implementation.
226
+ */
227
+ export class OnChainAvailabilityProvider {
228
+ api;
229
+ constructor(api) {
230
+ this.api = api;
231
+ }
232
+ async getAvailability(modelId) {
233
+ const defaultAvailability = {
234
+ modelId,
235
+ warmMiners: 0,
236
+ totalMiners: 0,
237
+ avgLatencyBlocks: 30,
238
+ estimatedQueueBlocks: 0,
239
+ loadPercentage: 0,
240
+ };
241
+ try {
242
+ // Check if miner-registry pallet exists
243
+ if (this.api.query.minerRegistry) {
244
+ // Query miners with this model loaded
245
+ const miners = await this.api.query.minerRegistry.minersByModel(modelId);
246
+ if (miners) {
247
+ const minerArray = Array.isArray(miners) ? miners : miners.toJSON();
248
+ const warmMiners = minerArray.length;
249
+ return {
250
+ modelId,
251
+ warmMiners,
252
+ totalMiners: warmMiners,
253
+ avgLatencyBlocks: warmMiners > 0 ? 20 : 60,
254
+ estimatedQueueBlocks: Math.max(0, 10 - warmMiners),
255
+ loadPercentage: warmMiners > 5 ? 30 : 70,
256
+ };
257
+ }
258
+ }
259
+ }
260
+ catch (error) {
261
+ console.warn(`Failed to get availability for ${modelId}:`, error);
262
+ }
263
+ return defaultAvailability;
264
+ }
265
+ async getAvailabilityBatch(modelIds) {
266
+ const results = new Map();
267
+ await Promise.all(modelIds.map(async (id) => {
268
+ results.set(id, await this.getAvailability(id));
269
+ }));
270
+ return results;
271
+ }
272
+ }
273
+ // ── Main Discovery Service ─────────────────────────────────────────────────
274
+ /**
275
+ * Model Discovery Service for finding and selecting models.
276
+ *
277
+ * @example
278
+ * ```ts
279
+ * const discovery = new DiscoveryService({ api });
280
+ *
281
+ * // Discover models by capability
282
+ * const result = await discovery.discover({
283
+ * capability: 'code_generation',
284
+ * maxCost: 5.0,
285
+ * minQuality: 80,
286
+ * });
287
+ *
288
+ * console.log(result.topPick);
289
+ * ```
290
+ */
291
+ export class ModelDiscoveryService {
292
+ api;
293
+ registry;
294
+ benchmarkProvider;
295
+ availabilityProvider;
296
+ meteringProvider;
297
+ scorer;
298
+ feeEstimator;
299
+ cache = new Map();
300
+ cacheTTL;
301
+ enableCache;
302
+ minWarmMiners;
303
+ defaultMaxCost;
304
+ modelCache = new Map();
305
+ profileCache = new Map();
306
+ constructor(options = {}) {
307
+ this.api = options.api;
308
+ this.cacheTTL = options.cacheTTL ?? 300_000; // 5 minutes
309
+ this.enableCache = options.enableCache ?? true;
310
+ this.minWarmMiners = options.minWarmMiners ?? 1;
311
+ this.defaultMaxCost = options.defaultMaxCost ?? 10;
312
+ this.scorer = new ModelScorer(options.weights);
313
+ this.feeEstimator = createFeeEstimator(this.api);
314
+ // Initialize providers
315
+ if (this.api) {
316
+ this.registry = new OnChainModelRegistry(this.api);
317
+ this.availabilityProvider = new OnChainAvailabilityProvider(this.api);
318
+ }
319
+ else {
320
+ // Use default/fallback implementations
321
+ this.registry = new InMemoryModelRegistry();
322
+ this.availabilityProvider = new InMemoryAvailabilityProvider();
323
+ }
324
+ this.benchmarkProvider = new OffChainBenchmarkProvider(options.benchmarkEndpoint);
325
+ }
326
+ /**
327
+ * Set custom model registry.
328
+ */
329
+ setRegistry(registry) {
330
+ this.registry = registry;
331
+ }
332
+ /**
333
+ * Set custom benchmark provider.
334
+ */
335
+ setBenchmarkProvider(provider) {
336
+ this.benchmarkProvider = provider;
337
+ }
338
+ /**
339
+ * Set custom availability provider.
340
+ */
341
+ setAvailabilityProvider(provider) {
342
+ this.availabilityProvider = provider;
343
+ }
344
+ /**
345
+ * Set the metering source provider {@link meteringByModel} reads.
346
+ */
347
+ setMeteringProvider(provider) {
348
+ this.meteringProvider = provider;
349
+ }
350
+ /**
351
+ * Metered pricing for discovered models, for `FeeEstimator.selectWithinBudget` and the other
352
+ * budget paths. Chain constants come from the service's `api`, everything else from the metering
353
+ * provider. A model whose pricing cannot be built is withdrawn with the reason, never given a
354
+ * default; a budget decision rejects a candidate without metering, so pass `models` on.
355
+ *
356
+ * @example
357
+ * ```ts
358
+ * discovery.setMeteringProvider(provider);
359
+ * const result = await discovery.discover({ capability: 'text_generation' });
360
+ * const priced = await discovery.meteringByModel(result.models);
361
+ * const selection = await new FeeEstimator().selectWithinBudget({
362
+ * models: priced.models,
363
+ * meteringByModel: priced.meteringByModel,
364
+ * maxBudget: 100,
365
+ * inputTokens: 1000,
366
+ * outputTokens: 500,
367
+ * });
368
+ * ```
369
+ */
370
+ async meteringByModel(models) {
371
+ if (!this.api)
372
+ throw new DiscoveryError('metered pricing reads runtime constants and needs an api', 'NO_API');
373
+ if (!this.meteringProvider) {
374
+ throw new DiscoveryError('metered pricing needs a metering provider (setMeteringProvider)', 'NO_METERING_PROVIDER');
375
+ }
376
+ const provider = this.meteringProvider;
377
+ const chain = readMeteringChainParams(this.api);
378
+ const now = Date.now();
379
+ const built = await Promise.all(models.map(async (model) => {
380
+ try {
381
+ const sources = await provider.getMeteringSources(model.hash);
382
+ return { model, metering: meteredPricing({ ...sources, modelHash: model.hash, chain, now }) };
383
+ }
384
+ catch (error) {
385
+ return { model, reason: error instanceof Error ? error.message : String(error) };
386
+ }
387
+ }));
388
+ const result = { models: [], meteringByModel: new Map(), withdrawn: [] };
389
+ for (const entry of built) {
390
+ if ('metering' in entry) {
391
+ result.models.push(entry.model);
392
+ result.meteringByModel.set(entry.model.hash, entry.metering);
393
+ }
394
+ else {
395
+ result.withdrawn.push({ hash: entry.model.hash, reason: entry.reason });
396
+ }
397
+ }
398
+ return result;
399
+ }
400
+ /**
401
+ * Discover models by capability.
402
+ *
403
+ * @example
404
+ * ```ts
405
+ * const result = await discovery.discover({
406
+ * capability: 'code_generation',
407
+ * maxCost: 5.0,
408
+ * minQuality: 80,
409
+ * limit: 10,
410
+ * });
411
+ *
412
+ * result.models.forEach(model => {
413
+ * console.log(`${model.name}: ${model.matchScore}% match`);
414
+ * });
415
+ * ```
416
+ */
417
+ async discover(request) {
418
+ const startTime = Date.now();
419
+ // Check cache
420
+ const cacheKey = JSON.stringify(request);
421
+ if (this.enableCache) {
422
+ const cached = this.cache.get(cacheKey);
423
+ if (cached && Date.now() - cached.timestamp < this.cacheTTL) {
424
+ return {
425
+ ...cached.data,
426
+ fromCache: true,
427
+ };
428
+ }
429
+ }
430
+ // 1. Get all models from registry
431
+ const allModels = await this.registry.listModels();
432
+ let totalConsidered = allModels.length;
433
+ // 2. Filter by capability
434
+ const candidates = allModels.filter(model => {
435
+ const capScore = model.capabilities.get(request.capability);
436
+ return capScore !== undefined && capScore > 0;
437
+ });
438
+ // 3. Get profiles, costs, and availability for candidates
439
+ const [profiles, availability, benchmarks] = await Promise.all([
440
+ this.getProfiles(candidates),
441
+ this.getAvailability(candidates),
442
+ this.getBenchmarks(candidates),
443
+ ]);
444
+ // 4. Score each model
445
+ const scoredModels = [];
446
+ for (const model of candidates) {
447
+ const profile = profiles.get(model.hash) ?? createEmptyProfile(model.hash, model.name);
448
+ const avail = availability.get(model.hash) ?? this.getDefaultAvailability(model.hash);
449
+ const bench = benchmarks.get(model.hash) ?? [];
450
+ // Update profile with benchmarks if available
451
+ if (bench.length > 0) {
452
+ const benchCaps = estimateCapabilitiesFromBenchmarks(bench);
453
+ for (const [cap, score] of benchCaps) {
454
+ if (!model.capabilities.has(cap)) {
455
+ model.capabilities.set(cap, score);
456
+ }
457
+ }
458
+ }
459
+ // Estimate cost from model size
460
+ const cost = {
461
+ modelId: model.hash,
462
+ costPer1kTokens: estimateCostFromSize(model.size) / 10,
463
+ minCostPerTask: estimateCostFromSize(model.size) / 5,
464
+ estimatedCost: estimateCostFromSize(model.size),
465
+ dynamicPricing: false,
466
+ };
467
+ // Score the model
468
+ const scored = this.scorer.scoreModel(model, profile, cost, avail, request);
469
+ scoredModels.push(scored);
470
+ }
471
+ // 5. Apply preferences
472
+ const withPreferences = this.scorer.applyPreferences(scoredModels, request.preferModels);
473
+ // 6. Filter by constraints
474
+ const filtered = this.scorer.filterModels(withPreferences, request);
475
+ // 7. Rank by score
476
+ const ranked = this.scorer.rankModels(filtered);
477
+ // 8. Limit results
478
+ const limit = request.limit ?? 5;
479
+ const limited = ranked.slice(0, limit);
480
+ // Build result
481
+ const result = {
482
+ models: limited,
483
+ request,
484
+ duration: Date.now() - startTime,
485
+ fromCache: false,
486
+ totalConsidered,
487
+ topPick: limited[0],
488
+ };
489
+ // Cache result
490
+ if (this.enableCache) {
491
+ this.cache.set(cacheKey, {
492
+ data: result,
493
+ timestamp: Date.now(),
494
+ });
495
+ }
496
+ return result;
497
+ }
498
+ /**
499
+ * Get the best model for a capability.
500
+ *
501
+ * @example
502
+ * ```ts
503
+ * const best = await discovery.getBestModel('code_generation');
504
+ * console.log(best.name); // 'llama-3-70b-instruct'
505
+ * ```
506
+ */
507
+ async getBestModel(capability, maxCost) {
508
+ const result = await this.discover({
509
+ capability,
510
+ maxCost: maxCost ?? this.defaultMaxCost,
511
+ limit: 1,
512
+ });
513
+ if (result.models.length === 0) {
514
+ throw new DiscoveryError(`No models available for capability: ${capability}`, 'NO_MODELS_FOUND');
515
+ }
516
+ return result.models[0];
517
+ }
518
+ /**
519
+ * Auto-select model based on prompt classification.
520
+ *
521
+ * @example
522
+ * ```ts
523
+ * const model = await discovery.autoSelect({
524
+ * prompt: 'Write a Python function to sort a list',
525
+ * maxCost: 5.0,
526
+ * });
527
+ *
528
+ * console.log(`Selected ${model.name} for code generation`);
529
+ * ```
530
+ */
531
+ async autoSelect(options) {
532
+ // 1. Classify prompt to detect capability
533
+ const capability = inferCapabilityFromPrompt(options.prompt);
534
+ // 2. Discover models
535
+ const result = await this.discover({
536
+ capability,
537
+ maxCost: options.maxCost,
538
+ maxLatency: options.maxLatency,
539
+ preferredSize: options.preferredSize,
540
+ excludeModels: options.excludeModels,
541
+ limit: 3,
542
+ });
543
+ // 3. Return best match
544
+ if (result.models.length === 0) {
545
+ // Fallback to general-purpose model
546
+ const fallback = await this.discover({
547
+ capability: 'text_generation',
548
+ maxCost: options.maxCost,
549
+ maxLatency: options.maxLatency,
550
+ limit: 1,
551
+ });
552
+ if (fallback.models.length === 0) {
553
+ throw new DiscoveryError('No models available for auto-selection', 'NO_MODELS_FOUND');
554
+ }
555
+ return fallback.models[0];
556
+ }
557
+ return result.models[0];
558
+ }
559
+ /**
560
+ * Auto-select model with fee estimation preview.
561
+ *
562
+ * Returns both the selected model and a detailed fee estimate,
563
+ * allowing agents to understand costs before submission.
564
+ *
565
+ * @example
566
+ * ```ts
567
+ * const selection = await discovery.autoSelectWithFeeEstimate({
568
+ * prompt: 'Write a Python function',
569
+ * maxBudget: 5.0, // needs inputTokens, outputTokens and meteringByModel
570
+ * inputTokens: 1000,
571
+ * outputTokens: 500,
572
+ * meteringByModel,
573
+ * });
574
+ *
575
+ * console.log(`Model: ${selection.model.name}`);
576
+ * console.log(`Fee: ${selection.fee.estimatedFee} FLOP`);
577
+ * console.log(`Breakdown:`, selection.fee.breakdown);
578
+ * ```
579
+ */
580
+ async autoSelectWithFeeEstimate(options) {
581
+ // 1. If budget specified, do full budget-aware selection
582
+ if (options.maxBudget !== undefined) {
583
+ // No maxCost: the size-based discovery estimate is not what settlement charges, so the
584
+ // metered comparison below applies the budget.
585
+ const result = await this.discover({
586
+ capability: inferCapabilityFromPrompt(options.prompt),
587
+ limit: 10,
588
+ });
589
+ const budgetSelection = await this.feeEstimator.selectWithinBudget({
590
+ models: meteredCandidates(result.models, options.meteringByModel),
591
+ maxBudget: options.maxBudget,
592
+ prompt: options.prompt,
593
+ pricingMode: options.pricingMode,
594
+ preferBestValue: options.preferBestValue,
595
+ inputTokens: options.inputTokens,
596
+ outputTokens: options.outputTokens,
597
+ meteringByModel: options.meteringByModel,
598
+ });
599
+ return {
600
+ model: budgetSelection.selectedModel,
601
+ fee: budgetSelection.estimatedFee,
602
+ selectedModel: budgetSelection.selectedModel,
603
+ estimatedFee: budgetSelection.estimatedFee,
604
+ alternatives: budgetSelection.alternatives,
605
+ outOfBudget: budgetSelection.outOfBudget,
606
+ reason: budgetSelection.reason,
607
+ tradeoffScore: budgetSelection.tradeoffScore,
608
+ };
609
+ }
610
+ // 2. Auto-select using existing method
611
+ const model = await this.autoSelect(options);
612
+ // 3. Get fee estimate for selected model
613
+ const fee = await this.feeEstimator.estimateFee({
614
+ prompt: options.prompt,
615
+ model: model,
616
+ modelSize: model.size,
617
+ pricingMode: options.pricingMode ?? 'standard',
618
+ inputTokens: options.inputTokens,
619
+ outputTokens: options.outputTokens,
620
+ metering: options.meteringByModel?.get(model.hash),
621
+ });
622
+ // 4. Return model with fee estimate
623
+ return {
624
+ model,
625
+ fee,
626
+ selectedModel: model,
627
+ estimatedFee: fee,
628
+ alternatives: [],
629
+ outOfBudget: [],
630
+ reason: `Auto-selected ${model.name} for ${inferCapabilityFromPrompt(options.prompt)}`,
631
+ tradeoffScore: model.qualityScore / fee.estimatedFee,
632
+ };
633
+ }
634
+ /**
635
+ * Select best model within budget with full fee awareness.
636
+ *
637
+ * @example
638
+ * ```ts
639
+ * const selection = await discovery.selectWithBudget({
640
+ * prompt: 'Write Python code',
641
+ * maxBudget: 5.0,
642
+ * capability: 'code_generation',
643
+ * inputTokens: 1000,
644
+ * outputTokens: 500,
645
+ * meteringByModel, // from meteringByModel(models)
646
+ * });
647
+ *
648
+ * console.log(`Selected: ${selection.selectedModel.name}`);
649
+ * console.log(`Fee: ${selection.estimatedFee.estimatedFee} FLOP`);
650
+ * console.log(`Alternatives: ${selection.alternatives.length} within budget`);
651
+ * ```
652
+ */
653
+ async selectWithBudget(options) {
654
+ // 1. Infer capability if not provided
655
+ const capability = options.capability ?? inferCapabilityFromPrompt(options.prompt ?? '');
656
+ // 2. Discover models for capability; the metered comparison applies the budget, not maxCost
657
+ const result = await this.discover({
658
+ capability,
659
+ minQuality: options.minQuality,
660
+ limit: 15,
661
+ });
662
+ // 3. Use fee estimator for budget-aware selection
663
+ return this.feeEstimator.selectWithinBudget({
664
+ models: meteredCandidates(result.models, options.meteringByModel),
665
+ maxBudget: options.maxBudget,
666
+ prompt: options.prompt,
667
+ pricingMode: options.pricingMode,
668
+ minQuality: options.minQuality,
669
+ preferBestValue: options.preferBestValue,
670
+ inputTokens: options.inputTokens,
671
+ outputTokens: options.outputTokens,
672
+ meteringByModel: options.meteringByModel,
673
+ });
674
+ }
675
+ /**
676
+ * Get fee estimate for a specific model and prompt.
677
+ *
678
+ * @example
679
+ * ```ts
680
+ * const fee = await discovery.getFeeEstimate('llama-3-70b', 'Write code');
681
+ * console.log(`Estimated cost: ${fee.estimatedFee} FLOP`);
682
+ * ```
683
+ */
684
+ async getFeeEstimate(model, prompt, options) {
685
+ const modelInfo = typeof model === 'string'
686
+ ? await this.getModel(model)
687
+ : null;
688
+ return this.feeEstimator.estimateFee({
689
+ prompt,
690
+ model: typeof model === 'string' ? model : model,
691
+ modelSize: modelInfo?.size ?? (typeof model !== 'string' ? model.size : 'medium'),
692
+ ...options,
693
+ });
694
+ }
695
+ /**
696
+ * Compare fee estimates across pricing modes.
697
+ */
698
+ async compareFeeModes(prompt, modelSize = 'medium') {
699
+ return this.feeEstimator.comparePricingModes({ prompt, modelSize });
700
+ }
701
+ /**
702
+ * Get network congestion info for fee estimation.
703
+ */
704
+ async getNetworkCongestion() {
705
+ return this.feeEstimator.getNetworkCongestion();
706
+ }
707
+ /**
708
+ * Get models by name or hash.
709
+ */
710
+ async getModel(identifier) {
711
+ // Check cache
712
+ const cached = this.modelCache.get(identifier);
713
+ if (cached)
714
+ return cached;
715
+ // Try by hash first
716
+ const byHash = await this.registry.getModel(identifier);
717
+ if (byHash) {
718
+ this.modelCache.set(identifier, byHash);
719
+ return byHash;
720
+ }
721
+ // Try by name
722
+ const byName = await this.registry.getModelByName(identifier);
723
+ if (byName) {
724
+ this.modelCache.set(identifier, byName);
725
+ return byName;
726
+ }
727
+ return null;
728
+ }
729
+ /**
730
+ * Check if a model supports a capability.
731
+ */
732
+ async supportsCapability(modelId, capability, minScore = 50) {
733
+ const model = await this.getModel(modelId);
734
+ if (!model)
735
+ return false;
736
+ const score = model.capabilities.get(capability);
737
+ return score !== undefined && score >= minScore;
738
+ }
739
+ /**
740
+ * Clear all caches.
741
+ */
742
+ clearCache() {
743
+ this.cache.clear();
744
+ this.modelCache.clear();
745
+ this.profileCache.clear();
746
+ }
747
+ // ── Private Helpers ─────────────────────────────────────────────────────
748
+ async getProfiles(models) {
749
+ const profiles = new Map();
750
+ // Get benchmarks for all models
751
+ const modelIds = models.map(m => m.hash);
752
+ const benchmarks = await this.benchmarkProvider.getBenchmarksBatch(modelIds);
753
+ for (const model of models) {
754
+ const bench = benchmarks.get(model.hash) ?? [];
755
+ // Create profile from model capabilities and benchmarks
756
+ const primaryCapability = this.getPrimaryCapability(model);
757
+ const secondaryCapabilities = new Map();
758
+ for (const [cap, score] of model.capabilities) {
759
+ if (cap !== primaryCapability && score > 0) {
760
+ secondaryCapabilities.set(cap, score);
761
+ }
762
+ }
763
+ const profile = {
764
+ modelId: model.hash,
765
+ modelName: model.name,
766
+ primaryCapability,
767
+ secondaryCapabilities,
768
+ qualityScore: model.capabilities.get(primaryCapability) ?? 50,
769
+ benchmarks: bench,
770
+ lastUpdated: new Date().toISOString(),
771
+ source: 'estimated',
772
+ };
773
+ profiles.set(model.hash, profile);
774
+ }
775
+ return profiles;
776
+ }
777
+ async getAvailability(models) {
778
+ const modelIds = models.map(m => m.hash);
779
+ return this.availabilityProvider.getAvailabilityBatch(modelIds);
780
+ }
781
+ async getBenchmarks(models) {
782
+ const modelIds = models.map(m => m.hash);
783
+ return this.benchmarkProvider.getBenchmarksBatch(modelIds);
784
+ }
785
+ getPrimaryCapability(model) {
786
+ let maxScore = 0;
787
+ let primary = 'text_generation';
788
+ for (const [cap, score] of model.capabilities) {
789
+ if (score > maxScore) {
790
+ maxScore = score;
791
+ primary = cap;
792
+ }
793
+ }
794
+ return primary;
795
+ }
796
+ getDefaultAvailability(modelId) {
797
+ return {
798
+ modelId,
799
+ warmMiners: 0,
800
+ totalMiners: 0,
801
+ avgLatencyBlocks: 30,
802
+ estimatedQueueBlocks: 5,
803
+ loadPercentage: 50,
804
+ };
805
+ }
806
+ }
807
+ // ── Fallback Implementations ──────────────────────────────────────────────
808
+ /**
809
+ * In-memory model registry for testing/development.
810
+ */
811
+ export class InMemoryModelRegistry {
812
+ models = new Map();
813
+ constructor(initialModels) {
814
+ if (initialModels) {
815
+ for (const model of initialModels) {
816
+ this.models.set(model.hash, model);
817
+ }
818
+ }
819
+ }
820
+ addModel(model) {
821
+ this.models.set(model.hash, model);
822
+ }
823
+ async listModels() {
824
+ return Array.from(this.models.values());
825
+ }
826
+ async getModel(hash) {
827
+ return this.models.get(hash) ?? null;
828
+ }
829
+ async getModelByName(name) {
830
+ for (const model of this.models.values()) {
831
+ if (model.name.toLowerCase() === name.toLowerCase()) {
832
+ return model;
833
+ }
834
+ }
835
+ return null;
836
+ }
837
+ async findByCapability(capability) {
838
+ const result = [];
839
+ for (const model of this.models.values()) {
840
+ const score = model.capabilities.get(capability);
841
+ if (score !== undefined && score > 0) {
842
+ result.push(model);
843
+ }
844
+ }
845
+ return result;
846
+ }
847
+ }
848
+ /**
849
+ * In-memory availability provider for testing/development.
850
+ */
851
+ export class InMemoryAvailabilityProvider {
852
+ availability = new Map();
853
+ constructor(initialAvailability) {
854
+ if (initialAvailability) {
855
+ this.availability = initialAvailability;
856
+ }
857
+ }
858
+ setAvailability(modelId, availability) {
859
+ this.availability.set(modelId, availability);
860
+ }
861
+ async getAvailability(modelId) {
862
+ return this.availability.get(modelId) ?? {
863
+ modelId,
864
+ warmMiners: 0,
865
+ totalMiners: 0,
866
+ avgLatencyBlocks: 30,
867
+ estimatedQueueBlocks: 5,
868
+ loadPercentage: 50,
869
+ };
870
+ }
871
+ async getAvailabilityBatch(modelIds) {
872
+ const results = new Map();
873
+ for (const id of modelIds) {
874
+ results.set(id, await this.getAvailability(id));
875
+ }
876
+ return results;
877
+ }
878
+ }
879
+ /**
880
+ * Budget candidates: with a metering map, only the models it prices at a live price (a withdrawn
881
+ * model, or one whose price has expired, cannot be held to a budget); without one, all of them, so
882
+ * `selectWithinBudget` fails closed.
883
+ */
884
+ function meteredCandidates(models, meteringByModel) {
885
+ if (!meteringByModel)
886
+ return models;
887
+ const now = Date.now();
888
+ const priced = models.filter((model) => {
889
+ const metering = meteringByModel.get(model.hash);
890
+ return metering !== undefined && (metering.expiresAtMs === undefined || now < metering.expiresAtMs);
891
+ });
892
+ if (models.length > 0 && priced.length === 0) {
893
+ throw new FeeEstimationError('No discovered model has live metered pricing', 'METERING_REQUIRED');
894
+ }
895
+ return priced;
896
+ }
897
+ // ── Errors ────────────────────────────────────────────────────────────────
898
+ /**
899
+ * Discovery error types.
900
+ */
901
+ export class DiscoveryError extends Error {
902
+ code;
903
+ details;
904
+ constructor(message, code, details) {
905
+ super(message);
906
+ this.code = code;
907
+ this.details = details;
908
+ this.name = 'DiscoveryError';
909
+ }
910
+ }
911
+ // ── Convenience Functions ──────────────────────────────────────────────────
912
+ /**
913
+ * Create a discovery service with default configuration.
914
+ */
915
+ export function createDiscoveryService(api, options) {
916
+ return new ModelDiscoveryService({ api, ...options });
917
+ }
918
+ /**
919
+ * Quick discovery helper for one-off queries.
920
+ */
921
+ export async function discoverModels(capability, options) {
922
+ const service = createDiscoveryService(options?.api);
923
+ const result = await service.discover({
924
+ capability,
925
+ maxCost: options?.maxCost,
926
+ minQuality: options?.minQuality,
927
+ limit: options?.limit,
928
+ });
929
+ return result.models;
930
+ }
931
+ /**
932
+ * Quick auto-select helper for one-off queries.
933
+ */
934
+ export async function autoSelectModel(prompt, options) {
935
+ const service = createDiscoveryService(options?.api);
936
+ return service.autoSelect({
937
+ prompt,
938
+ maxCost: options?.maxCost,
939
+ });
940
+ }
941
+ /**
942
+ * Auto-select model with full fee estimation.
943
+ *
944
+ * Discovers models matching the prompt, estimates fees for each,
945
+ * and returns the best model with detailed cost breakdown.
946
+ *
947
+ * @example
948
+ * ```ts
949
+ * const result = await autoSelectWithFeeEstimate({
950
+ * prompt: 'Write Python code',
951
+ * maxBudget: 10,
952
+ * pricingMode: 'standard',
953
+ * });
954
+ * console.log(`Selected: ${result.selectedModel.name}`);
955
+ * console.log(`Fee: ${result.estimatedFee.estimatedFee} FLOP`);
956
+ * ```
957
+ */
958
+ export async function autoSelectWithFeeEstimate(options) {
959
+ const service = createDiscoveryService(options.api);
960
+ return service.autoSelectWithFeeEstimate({
961
+ prompt: options.prompt,
962
+ maxBudget: options.maxBudget,
963
+ pricingMode: options.pricingMode,
964
+ preferBestValue: options.preferBestValue,
965
+ inputTokens: options.inputTokens,
966
+ outputTokens: options.outputTokens,
967
+ meteringByModel: options.meteringByModel,
968
+ });
969
+ }
970
+ /**
971
+ * Select best model within a budget constraint.
972
+ *
973
+ * @example
974
+ * ```ts
975
+ * const selection = await selectWithBudget({
976
+ * prompt: 'Translate this text',
977
+ * maxBudget: 5.0,
978
+ * capability: 'text_generation',
979
+ * });
980
+ * console.log(`Best value: ${selection.selectedModel.name}`);
981
+ * console.log(`Fee: ${selection.estimatedFee.estimatedFee} FLOP`);
982
+ * ```
983
+ */
984
+ export async function selectWithBudget(options) {
985
+ const estimator = createFeeEstimator(options.api);
986
+ // Discover or use provided models
987
+ const service = createDiscoveryService(options.api);
988
+ const result = options.capability
989
+ ? await service.discover({ capability: options.capability })
990
+ : await service.discover({
991
+ capability: inferCapabilityFromPrompt(options.prompt ?? ''),
992
+ });
993
+ return estimator.selectWithinBudget({
994
+ models: meteredCandidates(result.models, options.meteringByModel),
995
+ maxBudget: options.maxBudget,
996
+ prompt: options.prompt,
997
+ pricingMode: options.pricingMode,
998
+ minQuality: options.minQuality,
999
+ preferBestValue: options.preferBestValue,
1000
+ inputTokens: options.inputTokens,
1001
+ outputTokens: options.outputTokens,
1002
+ meteringByModel: options.meteringByModel,
1003
+ });
1004
+ }
1005
+ //# sourceMappingURL=discovery-service.js.map