feat(worker): answer traces stored from the question on and filled in as the answer is made
A trace is now kept the moment the request arrives (at the time it was asked, ms -1), its steps are stored as the engine adds each one, and it ends with the answer. Traces a killed run left unfinished are closed at start. The 대화 screen reads a trace still being made as pending. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -215,11 +215,13 @@ pub fn query(path: &Path, bot: Option<&str>, q: &Query) -> Result<Value, String>
|
||||
let (id, ts): (i64, f64) = (r.get(0)?, r.get(1)?);
|
||||
let user: String = r.get(4)?;
|
||||
let steps: String = r.get(8)?;
|
||||
let ms: i64 = r.get(7)?;
|
||||
Ok(((ts, 1, id), json!({
|
||||
"key": format!("t{id}"), "type": "thought", "at": ts, "via": r.get::<_, String>(2)?,
|
||||
"channel": r.get::<_, Option<String>>(3)?,
|
||||
"who": {"id": user.clone(), "name": name_of(&user)},
|
||||
"question": r.get::<_, String>(5)?, "answer": r.get::<_, String>(6)?, "ms": r.get::<_, i64>(7)?,
|
||||
"question": r.get::<_, String>(5)?, "answer": r.get::<_, String>(6)?, "ms": ms.max(0),
|
||||
"pending": ms < 0,
|
||||
"steps": serde_json::from_str::<Value>(&steps).unwrap_or(json!([])),
|
||||
})))
|
||||
}).map_err(err)?;
|
||||
@@ -384,6 +386,21 @@ mod tests {
|
||||
assert!(Cursor::of(&json!({"at": 1.0, "key": "x1"})).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_trace_still_being_made_reads_as_pending_with_its_steps_so_far() {
|
||||
let (path, c) = db("pending");
|
||||
rec(&c, 10.0, "voice", "vc", "1", "Alice", None, "서울 날씨 어때");
|
||||
c.execute("INSERT INTO traces(ts, via, channel_id, user_id, question, answer, ms, steps) VALUES (?,?,?,?,?,?,?,?)",
|
||||
rusqlite::params![10.5, "voice", "vc", "1", "서울 날씨 어때", "", -1, r#"[{"kind":"tools","names":["getWeather"]}]"#])
|
||||
.unwrap();
|
||||
let v = query(&path, None, &Query::default()).unwrap();
|
||||
let t = &v["items"][1];
|
||||
assert_eq!((t["type"].as_str(), t["pending"].as_bool()), (Some("thought"), Some(true)));
|
||||
assert_eq!(t["steps"][0]["names"], json!(["getWeather"]));
|
||||
let done = query(&sample("pending-done"), None, &Query::default()).unwrap();
|
||||
assert_eq!(done["items"][1]["pending"], false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_bot_id_comes_from_its_token() {
|
||||
assert_eq!(bot_id_of_token("MTIzNDU2Nzg5MDEyMzQ1Njc4.GxYzAb.abcdef").as_deref(), Some("123456789012345678"));
|
||||
|
||||
Reference in New Issue
Block a user