Class: WaveDispatch::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/wave_dispatch.rb

Overview

0.5.1 — payment hook: a Proc called once with the 402 challenge body (Hash) that returns the headers (Hash[String => String]) to retry the request with. Pair with ‘Client.wallet_hook(provider:, credentials:)` for the built-in CDP / Privy / Bridge factories, or build a Proc yourself.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(license = ENV["WAVE_LICENSE"], endpoint: "https://dispatch.wave.online", agents_endpoint: ENV["WAVE_AGENTS_ENDPOINT"] || "https://dispatch-agents.wave.online", payment_hook: nil) ⇒ Client

Returns a new instance of Client.



16
17
18
19
20
21
22
23
# File 'lib/wave_dispatch.rb', line 16

def initialize(license = ENV["WAVE_LICENSE"], endpoint: "https://dispatch.wave.online",
               agents_endpoint: ENV["WAVE_AGENTS_ENDPOINT"] || "https://dispatch-agents.wave.online",
               payment_hook: nil)
  @license = license
  @endpoint = endpoint
  @agents = agents_endpoint
  @payment_hook = payment_hook       # 0.5.1 — handles 402 inside the client
end

Class Method Details

.wallet_hook(provider:, credentials: {}) ⇒ Object

0.5.1 — build a payment_hook for a built-in provider. provider: :cdp | :privy | :bridge. credentials per provider: cdp: api_secret:, address:; privy: app_secret:, wallet_id:; bridge: source_wallet:, destination:. For custom wallets, build a Proc of your own that returns the header Hash you want set on the retry.



47
48
49
50
51
52
# File 'lib/wave_dispatch.rb', line 47

def self.wallet_hook(provider:, credentials: {})
  provider = provider.to_sym
  header = { cdp: "cdp-payment", privy: "privy-payment", bridge: "bridge-payment" }[provider]
  raise "dispatch.wallet_hook: unknown provider #{provider.inspect}" unless header
  ->(challenge) { { header => WaveDispatch.wallet_sign(provider, credentials, challenge) } }
end

Instance Method Details

#execute(prompt) ⇒ Object

Classify and run on the edge if your plan allows it.



29
# File 'lib/wave_dispatch.rb', line 29

def execute(prompt) = send_req(:post, @endpoint + "/", { prompt: prompt, execute: true })

#route(prompt) ⇒ Object

Classify a prompt (no execution) -> “probability”, “margin”, “forward”



26
# File 'lib/wave_dispatch.rb', line 26

def route(prompt) = send_req(:post, @endpoint + "/", { prompt: prompt })

#route_vector(vector) ⇒ Object

Classify a pre-computed 768-d embedding (matmul-only: cheapest + fastest).



32
# File 'lib/wave_dispatch.rb', line 32

def route_vector(vector) = send_req(:post, @endpoint + "/", { vector: vector })

#savingsObject

This license’s savings ledger (decisions, saved_usd, saved_pct, …). Requires a license.



35
# File 'lib/wave_dispatch.rb', line 35

def savings = send_req(:get, "#{@agents}/ledger/summary?license=#{lic}")

#subscribe(plan) ⇒ Object

Start/replace a programmatic subscription (plan: agent_starter | agent_pro | agent_scale).



41
# File 'lib/wave_dispatch.rb', line 41

def subscribe(plan) = send_req(:post, "#{@agents}/subscription/create", { license: @license, plan: plan })

#subscriptionObject

This license’s agent-subscription status.



38
# File 'lib/wave_dispatch.rb', line 38

def subscription = send_req(:get, "#{@agents}/subscription/status?license=#{lic}")