Skip to main content

vtcode_computer_use/
gate.rs

1//! Computer-use route admission and live-probe records.
2//!
3//! Admission is by declared native route (provider + protocol wire name): any
4//! model and any endpoint on a route the provider actually implements is
5//! admitted, so new models and custom proxies work without a gate change.
6//! Unknown routes stay denied before any network I/O.
7//!
8//! [`VERIFIED_MATRIX`] records tuples proven by live acceptance runs. It is
9//! advisory documentation of what was probed, not an admission list.
10
11use vtcode_commons::provider::Provider;
12
13/// Wire name of the OpenAI Responses `computer` tool. The provider codecs
14/// declare this constant rather than restating the string, so a wire-version
15/// bump cannot silently desynchronize declaration, gate, and parser.
16pub const OPENAI_COMPUTER_PROTOCOL: &str = "computer";
17/// Wire name of the Anthropic Messages computer toolset.
18pub const ANTHROPIC_COMPUTER_PROTOCOL: &str = "computer_toolset_20260801";
19
20/// Native computer-use routes implemented and contract-tested in `vtcode-llm`.
21///
22/// Both halves of a route are canonical here: provider identity comes from
23/// [`Provider`] and protocol wire names from the constants above. Providers
24/// re-export those constants as their `computer_use::PROTOCOL`, so this table
25/// is the single source of truth for route admission.
26pub const NATIVE_ROUTES: &[(Provider, &str)] = &[
27    (Provider::OpenAI, OPENAI_COMPUTER_PROTOCOL),
28    (Provider::Anthropic, ANTHROPIC_COMPUTER_PROTOCOL),
29];
30
31/// Whether a provider implements a native computer-use route. Model and
32/// endpoint are deliberately absent: every model on a declared route can
33/// drive a turn, including models released after this crate was built and
34/// requests sent through a custom base URL.
35#[must_use]
36pub fn native_route_supported(provider: Provider, protocol: &str) -> bool {
37    NATIVE_ROUTES.contains(&(provider, protocol))
38}
39
40/// One tuple proven by a live acceptance probe. Advisory only; see
41/// [`native_route_supported`] for admission.
42#[derive(Clone, Copy, Debug, PartialEq, Eq)]
43pub struct VerifiedTarget {
44    /// Provider key, e.g. `"anthropic"`.
45    pub provider: &'static str,
46    /// Exact model identifier.
47    pub model: &'static str,
48    /// Exact API endpoint the probe ran against.
49    pub endpoint: &'static str,
50    /// Native protocol version, e.g. `"computer_toolset_20260801"`.
51    pub protocol: &'static str,
52}
53
54/// Targets proven by live acceptance runs. Each entry records a probe that
55/// returned `computer_call` for the exact tuple; unknown tuples stay denied.
56pub const VERIFIED_MATRIX: &[VerifiedTarget] = &[
57    // Accepted 2026-11-19 by scripts/probe_openai_computer_use.py: P1
58    // declared tools=[{type:computer}] and received computer_call with a
59    // screenshot action; P2 replayed a real container screenshot
60    // statelessly (store=false, no previous_response_id) and the route
61    // continued with reasoning + computer_call. ~3k tokens on gpt-6-luna.
62    VerifiedTarget {
63        provider: "openai",
64        model: "gpt-6-luna",
65        endpoint: "https://api.openai.com/v1",
66        protocol: "computer",
67    },
68];
69
70/// Whether `matrix` admits an exact target match.
71#[must_use]
72pub fn verified_target(matrix: &[VerifiedTarget], provider: &str, model: &str, endpoint: &str, protocol: &str) -> bool {
73    matrix.iter().any(|target| {
74        target.provider == provider
75            && target.model == model
76            && target.endpoint == endpoint
77            && target.protocol == protocol
78    })
79}
80
81/// Whether [`VERIFIED_MATRIX`] recorded a probe for the target. Never used
82/// for admission: see [`native_route_supported`].
83#[must_use]
84pub fn verified_target_default(provider: &str, model: &str, endpoint: &str, protocol: &str) -> bool {
85    verified_target(VERIFIED_MATRIX, provider, model, endpoint, protocol)
86}
87
88#[cfg(test)]
89mod tests;