aboutsummaryrefslogtreecommitdiffstats
path: root/src/provider.rs
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-19 11:30:47 +0100
committersalmonik <salmonik@tuta.io>2026-11-19 11:30:47 +0100
commit4d5b584e39cf90a4afaab8af46be2f69dcd914b6 (patch)
tree567bd18d2c7ea52129aaca6d3af0e8e8e0e84802 /src/provider.rs
parentdocs: refresh KNOWN-ISSUES for 0.11.0; note the yolo git gate (diff)
downloadagent686-4d5b584e39cf90a4afaab8af46be2f69dcd914b6.tar.gz
agent686-4d5b584e39cf90a4afaab8af46be2f69dcd914b6.zip
0.12.0: provider is a type + URL, plus a config file
- --provider opencode|openai-compatible; opencode keeps the session header, openai-compatible needs a base URL and sends none - config file at ~/.config/agent686/config.toml (provider, url, model, flags) - fix the doubled-dash --provider help message
Diffstat (limited to 'src/provider.rs')
-rw-r--r--src/provider.rs37
1 files changed, 20 insertions, 17 deletions
diff --git a/src/provider.rs b/src/provider.rs
index c03dea2..b5dca62 100644
--- a/src/provider.rs
+++ b/src/provider.rs
@@ -256,17 +256,18 @@ pub fn chat_with(
256 return Err(Error::Aborted); 256 return Err(Error::Aborted);
257 } 257 }
258 258
259 let sent = agent 259 let mut request = agent
260 .post(&cfg.endpoint()) 260 .post(&cfg.endpoint())
261 .header("Content-Type", "application/json") 261 .header("Content-Type", "application/json")
262 .header("Accept", "text/event-stream") 262 .header("Accept", "text/event-stream")
263 .header("Authorization", format!("Bearer {}", cfg.api_key)) 263 .header("Authorization", format!("Bearer {}", cfg.api_key))
264 .header("User-Agent", concat!("agent686/", env!("CARGO_PKG_VERSION"))) 264 .header("User-Agent", concat!("agent686/", env!("CARGO_PKG_VERSION")));
265 // Required by OpenCode Go: stable per conversation, used for 265 // OpenCode requires a stable per-conversation id for routing and
266 // routing and prompt caching. Without it the gateway answers 266 // prompt caching; a plain OpenAI-compatible endpoint must not get it.
267 // 400 MissingSessionID. 267 if cfg.provider.needs_session_header() {
268 .header("x-opencode-session", &cfg.session) 268 request = request.header("x-opencode-session", &cfg.session);
269 .send(bytes.clone()); 269 }
270 let sent = request.send(bytes.clone());
270 271
271 let mut response = match sent { 272 let mut response = match sent {
272 Ok(response) => response, 273 Ok(response) => response,
@@ -570,14 +571,15 @@ struct FunctionDelta {
570pub fn summarize(cfg: &Config, messages: &[Value]) -> Result<String, Error> { 571pub fn summarize(cfg: &Config, messages: &[Value]) -> Result<String, Error> {
571 let body = serde_json::json!({ "model": cfg.model, "messages": messages, "stream": false }); 572 let body = serde_json::json!({ "model": cfg.model, "messages": messages, "stream": false });
572 let bytes = serde_json::to_vec(&body).map_err(|e| Error::Transport(e.to_string()))?; 573 let bytes = serde_json::to_vec(&body).map_err(|e| Error::Transport(e.to_string()))?;
573 let mut response = agent(cfg.system_ca) 574 let mut request = agent(cfg.system_ca)
574 .post(&cfg.endpoint()) 575 .post(&cfg.endpoint())
575 .header("Content-Type", "application/json") 576 .header("Content-Type", "application/json")
576 .header("Authorization", format!("Bearer {}", cfg.api_key)) 577 .header("Authorization", format!("Bearer {}", cfg.api_key))
577 .header("User-Agent", concat!("agent686/", env!("CARGO_PKG_VERSION"))) 578 .header("User-Agent", concat!("agent686/", env!("CARGO_PKG_VERSION")));
578 .header("x-opencode-session", &cfg.session) 579 if cfg.provider.needs_session_header() {
579 .send(bytes) 580 request = request.header("x-opencode-session", &cfg.session);
580 .map_err(|e| Error::Transport(e.to_string()))?; 581 }
582 let mut response = request.send(bytes).map_err(|e| Error::Transport(e.to_string()))?;
581 583
582 let status = response.status().as_u16(); 584 let status = response.status().as_u16();
583 let text = response 585 let text = response
@@ -605,13 +607,14 @@ pub fn models(cfg: &Config) -> Result<Vec<String>, Error> {
605 let agent = agent(cfg.system_ca); 607 let agent = agent(cfg.system_ca);
606 608
607 let url = format!("{}/models", cfg.base_url.trim_end_matches('/')); 609 let url = format!("{}/models", cfg.base_url.trim_end_matches('/'));
608 let mut response = agent 610 let mut request = agent
609 .get(&url) 611 .get(&url)
610 .header("Authorization", format!("Bearer {}", cfg.api_key)) 612 .header("Authorization", format!("Bearer {}", cfg.api_key))
611 .header("User-Agent", concat!("agent686/", env!("CARGO_PKG_VERSION"))) 613 .header("User-Agent", concat!("agent686/", env!("CARGO_PKG_VERSION")));
612 .header("x-opencode-session", &cfg.session) 614 if cfg.provider.needs_session_header() {
613 .call() 615 request = request.header("x-opencode-session", &cfg.session);
614 .map_err(|e| Error::Transport(e.to_string()))?; 616 }
617 let mut response = request.call().map_err(|e| Error::Transport(e.to_string()))?;
615 618
616 let status = response.status().as_u16(); 619 let status = response.status().as_u16();
617 let body = response 620 let body = response