Skip to content

Commit cc54e14

Browse files
committed
bugfix batch
1 parent 1037ef7 commit cc54e14

File tree

6 files changed

+47
-25
lines changed

6 files changed

+47
-25
lines changed

Cargo.lock

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ members = [
1818
]
1919

2020
[workspace.package]
21-
version = "0.3.13"
21+
version = "0.3.14"
2222
edition = "2021"
2323
license = "Apache-2.0 OR MIT"
2424
repository = "https://github.com/RightNow-AI/openfang"

crates/openfang-runtime/src/drivers/anthropic.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,13 @@ impl LlmDriver for AnthropicDriver {
415415
}
416416
}
417417
"content_block_delta" => {
418+
let block_idx = json["index"].as_u64().unwrap_or(0) as usize;
418419
let delta = &json["delta"];
419420
match delta["type"].as_str().unwrap_or("") {
420421
"text_delta" => {
421422
if let Some(text) = delta["text"].as_str() {
422423
if let Some(ContentBlockAccum::Text(ref mut t)) =
423-
blocks.last_mut()
424+
blocks.get_mut(block_idx)
424425
{
425426
t.push_str(text);
426427
}
@@ -436,7 +437,7 @@ impl LlmDriver for AnthropicDriver {
436437
if let Some(ContentBlockAccum::ToolUse {
437438
ref mut input_json,
438439
..
439-
}) = blocks.last_mut()
440+
}) = blocks.get_mut(block_idx)
440441
{
441442
input_json.push_str(partial);
442443
}
@@ -450,7 +451,7 @@ impl LlmDriver for AnthropicDriver {
450451
"thinking_delta" => {
451452
if let Some(thinking) = delta["thinking"].as_str() {
452453
if let Some(ContentBlockAccum::Thinking(ref mut t)) =
453-
blocks.last_mut()
454+
blocks.get_mut(block_idx)
454455
{
455456
t.push_str(thinking);
456457
}
@@ -460,11 +461,12 @@ impl LlmDriver for AnthropicDriver {
460461
}
461462
}
462463
"content_block_stop" => {
464+
let block_idx = json["index"].as_u64().unwrap_or(0) as usize;
463465
if let Some(ContentBlockAccum::ToolUse {
464466
id,
465467
name,
466468
input_json,
467-
}) = blocks.last()
469+
}) = blocks.get(block_idx)
468470
{
469471
let input: serde_json::Value =
470472
serde_json::from_str(input_json).unwrap_or_default();

crates/openfang-runtime/src/drivers/claude_code.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,17 @@ impl ClaudeCodeDriver {
8383
}
8484

8585
/// JSON output from `claude -p --output-format json`.
86+
///
87+
/// The CLI may return the response text in different fields depending on
88+
/// version: `result`, `content`, or `text`. We try all three.
8689
#[derive(Debug, Deserialize)]
8790
struct ClaudeJsonOutput {
8891
result: Option<String>,
8992
#[serde(default)]
93+
content: Option<String>,
94+
#[serde(default)]
95+
text: Option<String>,
96+
#[serde(default)]
9097
usage: Option<ClaudeUsage>,
9198
#[serde(default)]
9299
#[allow(dead_code)]
@@ -157,7 +164,10 @@ impl LlmDriver for ClaudeCodeDriver {
157164

158165
// Try JSON parse first
159166
if let Ok(parsed) = serde_json::from_str::<ClaudeJsonOutput>(&stdout) {
160-
let text = parsed.result.unwrap_or_default();
167+
let text = parsed.result
168+
.or(parsed.content)
169+
.or(parsed.text)
170+
.unwrap_or_default();
161171
let usage = parsed.usage.unwrap_or_default();
162172
return Ok(CompletionResponse {
163173
content: vec![ContentBlock::Text { text: text.clone() }],
@@ -195,7 +205,8 @@ impl LlmDriver for ClaudeCodeDriver {
195205
cmd.arg("-p")
196206
.arg(&prompt)
197207
.arg("--output-format")
198-
.arg("stream-json");
208+
.arg("stream-json")
209+
.arg("--verbose");
199210

200211
if let Some(ref model) = model_flag {
201212
cmd.arg("--model").arg(model);
@@ -232,7 +243,7 @@ impl LlmDriver for ClaudeCodeDriver {
232243
match serde_json::from_str::<ClaudeStreamEvent>(&line) {
233244
Ok(event) => {
234245
match event.r#type.as_str() {
235-
"content" | "text" => {
246+
"content" | "text" | "assistant" | "content_block_delta" => {
236247
if let Some(ref content) = event.content {
237248
full_text.push_str(content);
238249
let _ = tx

crates/openfang-runtime/src/model_catalog.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,18 @@ impl ModelCatalog {
169169
///
170170
/// Each entry maps a provider ID to a custom base URL.
171171
/// Unknown providers are silently skipped.
172+
/// Providers with explicit URL overrides are marked as configured since
173+
/// the user intentionally set them up (e.g. local proxies, custom endpoints).
172174
pub fn apply_url_overrides(&mut self, overrides: &HashMap<String, String>) {
173175
for (provider, url) in overrides {
174-
self.set_provider_url(provider, url);
176+
if self.set_provider_url(provider, url) {
177+
// Mark as configured so models from this provider show as available
178+
if let Some(p) = self.providers.iter_mut().find(|p| p.id == *provider) {
179+
if p.auth_status == AuthStatus::Missing {
180+
p.auth_status = AuthStatus::Configured;
181+
}
182+
}
183+
}
175184
}
176185
}
177186

crates/openfang-runtime/src/tool_runner.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn check_taint_shell_exec(command: &str) -> Option<String> {
4141
labels.insert(TaintLabel::ExternalNetwork);
4242
let tainted = TaintedValue::new(command, labels, "llm_tool_call");
4343
if let Err(violation) = tainted.check_sink(&TaintSink::shell_exec()) {
44-
warn!(command = &command[..command.len().min(80)], %violation, "Shell taint check failed");
44+
warn!(command = crate::str_utils::safe_truncate_str(command, 80), %violation, "Shell taint check failed");
4545
return Some(violation.to_string());
4646
}
4747
}
@@ -68,7 +68,7 @@ fn check_taint_net_fetch(url: &str) -> Option<String> {
6868
labels.insert(TaintLabel::Secret);
6969
let tainted = TaintedValue::new(url, labels, "llm_tool_call");
7070
if let Err(violation) = tainted.check_sink(&TaintSink::net_fetch()) {
71-
warn!(url = &url[..url.len().min(80)], %violation, "Net fetch taint check failed");
71+
warn!(url = crate::str_utils::safe_truncate_str(url, 80), %violation, "Net fetch taint check failed");
7272
return Some(violation.to_string());
7373
}
7474
}

0 commit comments

Comments
 (0)