feat(ai): send editor selection to the AI as bound context
This commit is contained in:
1 parent
d939959341
commit
e1b182c326
29 files changed
+1430
-54
No files matched your search
@@ -630,6 +630,14 @@ pub struct AiChatMessage {
|
||||
/// actionable after the conversation itself is rebound (#9902).
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub source_binding: Option<AiChatSourceBinding>,
|
||||
/// Footprint of a turn that carried a context selection (#10058): the
|
||||
/// selection text is session-only (up to 12 000 chars, and conversation
|
||||
/// records are synced), so only the fact that one existed is persisted, and
|
||||
/// a reloaded transcript can still tell the model the content is gone
|
||||
/// instead of showing an empty turn. Absent on records written before the
|
||||
/// field existed.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub selections_omitted: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
|
||||
@@ -9518,6 +9518,7 @@ mod tests {
|
||||
failed: None,
|
||||
covered_messages: None,
|
||||
source_binding: None,
|
||||
selections_omitted: None,
|
||||
}],
|
||||
queued_input: None,
|
||||
created_at: updated_at.to_string(),
|
||||
@@ -9838,6 +9839,29 @@ mod tests {
|
||||
let _ = std::fs::remove_file(path);
|
||||
}
|
||||
|
||||
// #10058: a turn that carried a context selection keeps only a footprint in
|
||||
// storage — the selection text is session-only. The record must round-trip
|
||||
// that boolean, and a record written before the field existed must load.
|
||||
#[tokio::test]
|
||||
async fn ai_conversation_roundtrips_selection_omitted_footprint() {
|
||||
let path = temp_db_path("ai-conversation-selection-footprint");
|
||||
let storage = crate::persistence::test_storage::open(&path).await.unwrap();
|
||||
|
||||
let mut conversation = ai_conversation("selection-conv", "0000");
|
||||
conversation.messages[0].selections_omitted = Some(true);
|
||||
storage.save_ai_conversation(&conversation).await.unwrap();
|
||||
|
||||
let loaded = storage.load_ai_conversations().await.unwrap();
|
||||
assert_eq!(loaded[0].messages[0].selections_omitted, Some(true));
|
||||
// No selection text is stored alongside it, only the flag.
|
||||
assert!(loaded[0].messages[0].mentions.is_none());
|
||||
|
||||
let legacy: AiChatMessage = serde_json::from_str(r#"{"role":"user","content":"old turn"}"#).unwrap();
|
||||
assert!(legacy.selections_omitted.is_none());
|
||||
|
||||
let _ = std::fs::remove_file(path);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn ai_conversation_upgrades_legacy_schema_and_binds_a_unique_connection() {
|
||||
let path = temp_db_path("ai-conversation-legacy-binding");
|
||||
|
||||
Reference in new issue
Block a user