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