pub struct BenchRunsClient { /* private fields */ }Expand description
Operations keyed on a global bench_runs.id. These endpoints live under
/bench-runs/{id}/... and don’t need a project scope (the server resolves
the owning project from the run row). Obtained via client.bench_runs().
Implementations§
Source§impl BenchRunsClient
impl BenchRunsClient
Sourcepub async fn get(&self, run_id: i64) -> Result<Option<BenchRun>>
pub async fn get(&self, run_id: i64) -> Result<Option<BenchRun>>
GET /bench-runs/{id} — 404 → Ok(None).
Sourcepub async fn delete(&self, run_id: i64) -> Result<()>
pub async fn delete(&self, run_id: i64) -> Result<()>
DELETE /bench-runs/{id} — returns () (server emits 204 No Content).
Cancels the run first (best-effort) before dropping the row.
Sourcepub async fn list_results(&self, run_id: i64) -> Result<Vec<BenchResult>>
pub async fn list_results(&self, run_id: i64) -> Result<Vec<BenchResult>>
GET /bench-runs/{id}/results. 404 → empty list.
Sourcepub async fn subscribe_run_events(
&self,
run_id: i64,
) -> Result<(UnboundedReceiver<BenchRunEvent>, EventSubscription)>
pub async fn subscribe_run_events( &self, run_id: i64, ) -> Result<(UnboundedReceiver<BenchRunEvent>, EventSubscription)>
Subscribe to a bench run’s live result stream over SSE
(GET /bench-runs/{id}/events, Accept: text/event-stream).
Returns a receiver of typed BenchRunEvents plus an
EventSubscription handle that cancels the background listener
on drop. The server emits a BenchRunEvent::Result per recorded
case, a BenchRunEvent::Lagged if the broadcast subscriber falls
behind, and a final BenchRunEvent::Terminal carrying the run’s
terminal status — after which the channel closes.
This awaits the SSE subscription being live on the server before
returning, so a non-2xx (e.g. 403 on a project the token can’t
read, or the run id not resolving to a project) surfaces here
rather than as a silently-empty stream. Reuses the crate’s shared
SSE byte-deframer and field parser (the same machinery behind
events().event_stream / executions().run_stream).
Mirrors the TS SDK’s subscribeRunEvents; the terminal frame is
surfaced as a typed variant so Rust callers can detect
end-of-stream without a side channel. Drop the returned
EventSubscription (or let it fall out of scope) to unsubscribe.
let (mut rx, _sub) = client.bench_runs().subscribe_run_events(42).await?;
while let Some(evt) = rx.recv().await {
match evt {
BenchRunEvent::Result(r) => println!("case {} → {}", r.case_id, r.status),
BenchRunEvent::Lagged { dropped } => eprintln!("dropped {dropped}"),
BenchRunEvent::Terminal { status } => {
println!("run ended: {status}");
break;
}
}
}Sourcepub async fn cancel(&self, run_id: i64) -> Result<BenchRun>
pub async fn cancel(&self, run_id: i64) -> Result<BenchRun>
POST /bench-runs/{id}/cancel. Flips the cancel token; in-flight cases
complete naturally. Returns the run row as it stands.
Sourcepub async fn tag_session(
&self,
run_id: i64,
mcp_session_id: &str,
) -> Result<BenchRunTagSessionResponse>
pub async fn tag_session( &self, run_id: i64, mcp_session_id: &str, ) -> Result<BenchRunTagSessionResponse>
PATCH /bench-runs/{id}/tag-session — attribute the run to an MCP
session id so the coordinator’s finalize step posts the cost into
mcp_session_cost.
Sourcepub async fn promote_execution(
&self,
execution_id: &str,
req: &PromoteExecutionRequest,
) -> Result<BenchCase>
pub async fn promote_execution( &self, execution_id: &str, req: &PromoteExecutionRequest, ) -> Result<BenchCase>
POST /executions/{exec_id}/promote-to-case — promote a completed
execution into a bench case, with optional edits overlay.
This is run-scoped only in the loose sense: it lives on /executions
rather than /bench-runs, but it’s the natural counterpart to the
“promote-from-execution” flow on the bench surface and doesn’t need a
project_id (the server resolves the owning project from the source
execution).
Sourcepub async fn compare(&self, run_a: i64, run_b: i64) -> Result<CompareReport>
pub async fn compare(&self, run_a: i64, run_b: i64) -> Result<CompareReport>
GET /bench-runs/{a}/compare/{b} — diff two runs of the same bench.
Sourcepub async fn get_case(&self, case_id: &str) -> Result<Value>
pub async fn get_case(&self, case_id: &str) -> Result<Value>
GET /executions/{case_id} — fetch a single case (cases are
executions rows with kind='case'). Returned as Value for
compatibility with the MCP tool, which doesn’t trust the row to
always type-check as BenchCase (legacy promoted-execution rows can
have null kind on older servers).
Sourcepub async fn patch_case(
&self,
case_id: &str,
req: &PatchBenchCaseRequest,
) -> Result<BenchCase>
pub async fn patch_case( &self, case_id: &str, req: &PatchBenchCaseRequest, ) -> Result<BenchCase>
PATCH /cases/{id} — sparse update.
Sourcepub async fn delete_case(&self, case_id: &str) -> Result<()>
pub async fn delete_case(&self, case_id: &str) -> Result<()>
DELETE /cases/{id}. The server emits a {"deleted": true} JSON body;
we discard it and return ().
Sourcepub async fn bench_by_id(&self, bench_id: i64) -> Result<Option<Value>>
pub async fn bench_by_id(&self, bench_id: i64) -> Result<Option<Value>>
GET /benches/{id} — fast bench-by-id lookup. Returns the bench
row joined with the owning project_id + script_name so the
caller can chain into list_cases / list_runs without an N+1
project walk. 404 → Ok(None).
Sourcepub async fn mcp_session_cost(&self, session_id: &str) -> Result<Value>
pub async fn mcp_session_cost(&self, session_id: &str) -> Result<Value>
GET /mcp-sessions/{id}/cost — aggregated cost for an MCP
session. Returns {session_id, total_cost_usd, breakdown}.
Lets the MCP server (and any other client) read accumulated
cost via HTTP rather than querying the mcp_session_cost
table directly.
Trait Implementations§
Source§impl Clone for BenchRunsClient
impl Clone for BenchRunsClient
Source§fn clone(&self) -> BenchRunsClient
fn clone(&self) -> BenchRunsClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more