feat(coder): wire real thread grant token and proxy URL parsing for Coder inference

04cb84d364fb · AtlantisPleb · · parent 37b68bb88b1d

feat(coder): wire real thread grant token and proxy URL parsing for Coder inference

Deploy story

What this commit did to the running system — joined from the forge receipt chain, the part a commit page elsewhere cannot show.

Not deployed through the forge lane

No push, promotion, build, or deploy receipt references this commit (receipts are scanned over a bounded recent window). Changes shipped by full node replacement carry their proof in the release gate receipt instead.

Changed files

  • modified crates/openagents-cli/src/runtime.rs

Diff

1 file changed, +21 -18

crates/openagents-cli/src/runtime.rs modified +21 -18

@@ -60,6 +60,8 @@ impl Lane {

60 60
pub struct InferenceGrant {
61 61
    pub thread_id: String,
62 62
    pub token: String,
63
    pub proxy_url: String,
64
    pub model: String,
63 65
}
64 66
65 67
#[derive(Debug, Clone, Serialize, Deserialize)]

@@ -139,27 +141,34 @@ impl CoderRuntimeSession {

139 141
        let resp = self.http.post(&url)
140 142
            .headers(headers)
141 143
            .json(&serde_json::json!({
144
                "objective": "Coding assistant session",
142 145
                "lane": self.lane.model_name(),
143
                "agent_name": "openagents-coder-rust"
144 146
            }))
145 147
            .send()
146 148
            .await?;
147 149
148 150
        if resp.status().is_success() {
149 151
            let body: serde_json::Value = resp.json().await?;
150
            let thread_id = body.get("thread_id").or_else(|| body.get("id"))
151
                .and_then(|v| v.as_str())
152
                .unwrap_or("th_fallback")
153
                .to_string();
154
            let token = body.get("token").or_else(|| body.get("grant_token"))
155
                .and_then(|v| v.as_str())
156
                .unwrap_or("oat_fallback")
157
                .to_string();
158
            Ok(InferenceGrant { thread_id, token })
152
            let thread = body.get("thread").cloned().unwrap_or(serde_json::json!({}));
153
            let grant = body.get("grant").cloned().unwrap_or(serde_json::json!({}));
154
155
            let thread_id = thread.get("id").and_then(|v| v.as_str()).unwrap_or("th_active").to_string();
156
            let token = grant.get("token").and_then(|v| v.as_str()).unwrap_or("").to_string();
157
            let grant_url = grant.get("url").and_then(|v| v.as_str()).unwrap_or("https://openagents.com/api/inference/proxy").to_string();
158
            let model = grant.get("model").and_then(|v| v.as_str()).unwrap_or(self.lane.model_name()).to_string();
159
160
            Ok(InferenceGrant {
161
                thread_id,
162
                token,
163
                proxy_url: grant_url,
164
                model,
165
            })
159 166
        } else {
160 167
            Ok(InferenceGrant {
161 168
                thread_id: "th_local_fallback".to_string(),
162 169
                token: self.user_token.clone().unwrap_or_else(|| "oat_anon".to_string()),
170
                proxy_url: "https://openagents.com/api/inference/proxy".to_string(),
171
                model: self.lane.model_name().to_string(),
163 172
            })
164 173
        }
165 174
    }

@@ -194,14 +203,8 @@ impl CoderRuntimeSession {

194 203
        while max_steps > 0 {
195 204
            max_steps -= 1;
196 205
197
            let proxy_url = if self.api_base.ends_with("/api/v1") {
198
                self.api_base.replace("/api/v1", "/api/inference/proxy")
199
            } else {
200
                format!("{}/inference/proxy", self.api_base)
201
            };
202
203 206
            let req_body = serde_json::json!({
204
                "model": self.lane.model_name(),
207
                "model": grant.model,
205 208
                "messages": self.messages,
206 209
                "tools": tool_defs.iter().map(|t| serde_json::json!({
207 210
                    "type": "function",

@@ -218,7 +221,7 @@ impl CoderRuntimeSession {

218 221
            headers.insert(CONTENT_TYPE, HeaderValue::from_static("application/json"));
219 222
            headers.insert(AUTHORIZATION, HeaderValue::from_str(&format!("Bearer {}", grant.token))?);
220 223
221
            let resp = self.http.post(&proxy_url)
224
            let resp = self.http.post(&grant.proxy_url)
222 225
                .headers(headers)
223 226
                .json(&req_body)
224 227
                .send()

This page updates live while a promote is in flight · changelog