fix(ai): stream usage events and accept free-form plan replies

Request stream_options.include_usage, emit usage SSE events for collect_usage,
propagate plan tokens through run, and treat unknown prose decisions as DONE.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-10-28 11:56:51 +08:00
1 parent 628e3b6e5d
commit 4018e9928a
4 files changed
+126 -17

No files matched your search

+9
View File
@@ -211,6 +211,10 @@ fn parse_sse_events(
{
accumulated.push_str(c);
}
// Preserve provider usage as a first-class event for llm.collect_usage.
if let Some(u) = v.get("usage").filter(|u| u.is_object()) {
events.push(json!({"type": "usage", "usage": u}));
}
}
events.push(json!({"type": "data", "data": data}));
}
@@ -365,6 +369,11 @@ fn chat_completions(args: &Value) -> Result<Value, String> {
}
if stream {
req_body.insert("stream".into(), Value::Bool(true));
// OpenAI / DeepSeek / compatible: final SSE chunk carries usage only when requested.
req_body.insert(
"stream_options".into(),
json!({ "include_usage": true }),
);
}
let body = Value::Object(req_body).to_string();
let auth = format!("{bearer}{api_key}");