Rename conversations to contexts (#12724)
This just changes nomenclature within the codebase and should have no external effect. Release Notes: - N/A
This commit is contained in:
parent
70ce06cb95
commit
a0c0f1ebcd
8 changed files with 400 additions and 455 deletions
|
@ -545,7 +545,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"context": "ConversationEditor > Editor",
|
"context": "ContextEditor > Editor",
|
||||||
"bindings": {
|
"bindings": {
|
||||||
"ctrl-enter": "assistant::Assist",
|
"ctrl-enter": "assistant::Assist",
|
||||||
"ctrl-s": "workspace::Save",
|
"ctrl-s": "workspace::Save",
|
||||||
|
|
|
@ -228,7 +228,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"context": "ConversationEditor > Editor",
|
"context": "ContextEditor > Editor",
|
||||||
"bindings": {
|
"bindings": {
|
||||||
"cmd-enter": "assistant::Assist",
|
"cmd-enter": "assistant::Assist",
|
||||||
"cmd-s": "workspace::Save",
|
"cmd-s": "workspace::Save",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
pub mod assistant_panel;
|
pub mod assistant_panel;
|
||||||
pub mod assistant_settings;
|
pub mod assistant_settings;
|
||||||
mod completion_provider;
|
mod completion_provider;
|
||||||
mod conversation_store;
|
mod context_store;
|
||||||
mod inline_assistant;
|
mod inline_assistant;
|
||||||
mod model_selector;
|
mod model_selector;
|
||||||
mod prompt_library;
|
mod prompt_library;
|
||||||
|
@ -17,7 +17,7 @@ use assistant_slash_command::SlashCommandRegistry;
|
||||||
use client::{proto, Client};
|
use client::{proto, Client};
|
||||||
use command_palette_hooks::CommandPaletteFilter;
|
use command_palette_hooks::CommandPaletteFilter;
|
||||||
pub(crate) use completion_provider::*;
|
pub(crate) use completion_provider::*;
|
||||||
pub(crate) use conversation_store::*;
|
pub(crate) use context_store::*;
|
||||||
use gpui::{actions, AppContext, Global, SharedString, UpdateGlobal};
|
use gpui::{actions, AppContext, Global, SharedString, UpdateGlobal};
|
||||||
pub(crate) use inline_assistant::*;
|
pub(crate) use inline_assistant::*;
|
||||||
pub(crate) use model_selector::*;
|
pub(crate) use model_selector::*;
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -9,7 +9,7 @@ use regex::Regex;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{cmp::Reverse, ffi::OsStr, path::PathBuf, sync::Arc, time::Duration};
|
use std::{cmp::Reverse, ffi::OsStr, path::PathBuf, sync::Arc, time::Duration};
|
||||||
use ui::Context;
|
use ui::Context;
|
||||||
use util::{paths::CONVERSATIONS_DIR, ResultExt, TryFutureExt};
|
use util::{paths::CONTEXTS_DIR, ResultExt, TryFutureExt};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct SavedMessage {
|
pub struct SavedMessage {
|
||||||
|
@ -18,7 +18,7 @@ pub struct SavedMessage {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct SavedConversation {
|
pub struct SavedContext {
|
||||||
pub id: Option<String>,
|
pub id: Option<String>,
|
||||||
pub zed: String,
|
pub zed: String,
|
||||||
pub version: String,
|
pub version: String,
|
||||||
|
@ -28,12 +28,12 @@ pub struct SavedConversation {
|
||||||
pub summary: String,
|
pub summary: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SavedConversation {
|
impl SavedContext {
|
||||||
pub const VERSION: &'static str = "0.2.0";
|
pub const VERSION: &'static str = "0.2.0";
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
struct SavedConversationV0_1_0 {
|
struct SavedContextV0_1_0 {
|
||||||
id: Option<String>,
|
id: Option<String>,
|
||||||
zed: String,
|
zed: String,
|
||||||
version: String,
|
version: String,
|
||||||
|
@ -46,28 +46,26 @@ struct SavedConversationV0_1_0 {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct SavedConversationMetadata {
|
pub struct SavedContextMetadata {
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
pub mtime: chrono::DateTime<chrono::Local>,
|
pub mtime: chrono::DateTime<chrono::Local>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ConversationStore {
|
pub struct ContextStore {
|
||||||
conversations_metadata: Vec<SavedConversationMetadata>,
|
contexts_metadata: Vec<SavedContextMetadata>,
|
||||||
fs: Arc<dyn Fs>,
|
fs: Arc<dyn Fs>,
|
||||||
_watch_updates: Task<Option<()>>,
|
_watch_updates: Task<Option<()>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ConversationStore {
|
impl ContextStore {
|
||||||
pub fn new(fs: Arc<dyn Fs>, cx: &mut AppContext) -> Task<Result<Model<Self>>> {
|
pub fn new(fs: Arc<dyn Fs>, cx: &mut AppContext) -> Task<Result<Model<Self>>> {
|
||||||
cx.spawn(|mut cx| async move {
|
cx.spawn(|mut cx| async move {
|
||||||
const CONVERSATION_WATCH_DURATION: Duration = Duration::from_millis(100);
|
const CONTEXT_WATCH_DURATION: Duration = Duration::from_millis(100);
|
||||||
let (mut events, _) = fs
|
let (mut events, _) = fs.watch(&CONTEXTS_DIR, CONTEXT_WATCH_DURATION).await;
|
||||||
.watch(&CONVERSATIONS_DIR, CONVERSATION_WATCH_DURATION)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
let this = cx.new_model(|cx: &mut ModelContext<Self>| Self {
|
let this = cx.new_model(|cx: &mut ModelContext<Self>| Self {
|
||||||
conversations_metadata: Vec::new(),
|
contexts_metadata: Vec::new(),
|
||||||
fs,
|
fs,
|
||||||
_watch_updates: cx.spawn(|this, mut cx| {
|
_watch_updates: cx.spawn(|this, mut cx| {
|
||||||
async move {
|
async move {
|
||||||
|
@ -88,46 +86,41 @@ impl ConversationStore {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load(&self, path: PathBuf, cx: &AppContext) -> Task<Result<SavedConversation>> {
|
pub fn load(&self, path: PathBuf, cx: &AppContext) -> Task<Result<SavedContext>> {
|
||||||
let fs = self.fs.clone();
|
let fs = self.fs.clone();
|
||||||
cx.background_executor().spawn(async move {
|
cx.background_executor().spawn(async move {
|
||||||
let saved_conversation = fs.load(&path).await?;
|
let saved_context = fs.load(&path).await?;
|
||||||
let saved_conversation_json =
|
let saved_context_json = serde_json::from_str::<serde_json::Value>(&saved_context)?;
|
||||||
serde_json::from_str::<serde_json::Value>(&saved_conversation)?;
|
match saved_context_json
|
||||||
match saved_conversation_json
|
|
||||||
.get("version")
|
.get("version")
|
||||||
.ok_or_else(|| anyhow!("version not found"))?
|
.ok_or_else(|| anyhow!("version not found"))?
|
||||||
{
|
{
|
||||||
serde_json::Value::String(version) => match version.as_str() {
|
serde_json::Value::String(version) => match version.as_str() {
|
||||||
SavedConversation::VERSION => Ok(serde_json::from_value::<SavedConversation>(
|
SavedContext::VERSION => {
|
||||||
saved_conversation_json,
|
Ok(serde_json::from_value::<SavedContext>(saved_context_json)?)
|
||||||
)?),
|
}
|
||||||
"0.1.0" => {
|
"0.1.0" => {
|
||||||
let saved_conversation = serde_json::from_value::<SavedConversationV0_1_0>(
|
let saved_context =
|
||||||
saved_conversation_json,
|
serde_json::from_value::<SavedContextV0_1_0>(saved_context_json)?;
|
||||||
)?;
|
Ok(SavedContext {
|
||||||
Ok(SavedConversation {
|
id: saved_context.id,
|
||||||
id: saved_conversation.id,
|
zed: saved_context.zed,
|
||||||
zed: saved_conversation.zed,
|
version: saved_context.version,
|
||||||
version: saved_conversation.version,
|
text: saved_context.text,
|
||||||
text: saved_conversation.text,
|
messages: saved_context.messages,
|
||||||
messages: saved_conversation.messages,
|
message_metadata: saved_context.message_metadata,
|
||||||
message_metadata: saved_conversation.message_metadata,
|
summary: saved_context.summary,
|
||||||
summary: saved_conversation.summary,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
_ => Err(anyhow!(
|
_ => Err(anyhow!("unrecognized saved context version: {}", version)),
|
||||||
"unrecognized saved conversation version: {}",
|
|
||||||
version
|
|
||||||
)),
|
|
||||||
},
|
},
|
||||||
_ => Err(anyhow!("version not found on saved conversation")),
|
_ => Err(anyhow!("version not found on saved context")),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn search(&self, query: String, cx: &AppContext) -> Task<Vec<SavedConversationMetadata>> {
|
pub fn search(&self, query: String, cx: &AppContext) -> Task<Vec<SavedContextMetadata>> {
|
||||||
let metadata = self.conversations_metadata.clone();
|
let metadata = self.contexts_metadata.clone();
|
||||||
let executor = cx.background_executor().clone();
|
let executor = cx.background_executor().clone();
|
||||||
cx.background_executor().spawn(async move {
|
cx.background_executor().spawn(async move {
|
||||||
if query.is_empty() {
|
if query.is_empty() {
|
||||||
|
@ -159,10 +152,10 @@ impl ConversationStore {
|
||||||
fn reload(&mut self, cx: &mut ModelContext<Self>) -> Task<Result<()>> {
|
fn reload(&mut self, cx: &mut ModelContext<Self>) -> Task<Result<()>> {
|
||||||
let fs = self.fs.clone();
|
let fs = self.fs.clone();
|
||||||
cx.spawn(|this, mut cx| async move {
|
cx.spawn(|this, mut cx| async move {
|
||||||
fs.create_dir(&CONVERSATIONS_DIR).await?;
|
fs.create_dir(&CONTEXTS_DIR).await?;
|
||||||
|
|
||||||
let mut paths = fs.read_dir(&CONVERSATIONS_DIR).await?;
|
let mut paths = fs.read_dir(&CONTEXTS_DIR).await?;
|
||||||
let mut conversations = Vec::<SavedConversationMetadata>::new();
|
let mut contexts = Vec::<SavedContextMetadata>::new();
|
||||||
while let Some(path) = paths.next().await {
|
while let Some(path) = paths.next().await {
|
||||||
let path = path?;
|
let path = path?;
|
||||||
if path.extension() != Some(OsStr::new("json")) {
|
if path.extension() != Some(OsStr::new("json")) {
|
||||||
|
@ -178,13 +171,13 @@ impl ConversationStore {
|
||||||
.and_then(|name| name.to_str())
|
.and_then(|name| name.to_str())
|
||||||
.zip(metadata)
|
.zip(metadata)
|
||||||
{
|
{
|
||||||
// This is used to filter out conversations saved by the new assistant.
|
// This is used to filter out contexts saved by the new assistant.
|
||||||
if !re.is_match(file_name) {
|
if !re.is_match(file_name) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(title) = re.replace(file_name, "").lines().next() {
|
if let Some(title) = re.replace(file_name, "").lines().next() {
|
||||||
conversations.push(SavedConversationMetadata {
|
contexts.push(SavedContextMetadata {
|
||||||
title: title.to_string(),
|
title: title.to_string(),
|
||||||
path,
|
path,
|
||||||
mtime: metadata.mtime.into(),
|
mtime: metadata.mtime.into(),
|
||||||
|
@ -192,10 +185,10 @@ impl ConversationStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
conversations.sort_unstable_by_key(|conversation| Reverse(conversation.mtime));
|
contexts.sort_unstable_by_key(|context| Reverse(context.mtime));
|
||||||
|
|
||||||
this.update(&mut cx, |this, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
this.conversations_metadata = conversations;
|
this.contexts_metadata = contexts;
|
||||||
cx.notify();
|
cx.notify();
|
||||||
})
|
})
|
||||||
})
|
})
|
|
@ -66,7 +66,7 @@ impl InlineAssistant {
|
||||||
&mut self,
|
&mut self,
|
||||||
editor: &View<Editor>,
|
editor: &View<Editor>,
|
||||||
workspace: Option<WeakView<Workspace>>,
|
workspace: Option<WeakView<Workspace>>,
|
||||||
include_conversation: bool,
|
include_context: bool,
|
||||||
cx: &mut WindowContext,
|
cx: &mut WindowContext,
|
||||||
) {
|
) {
|
||||||
let selection = editor.read(cx).selections.newest_anchor().clone();
|
let selection = editor.read(cx).selections.newest_anchor().clone();
|
||||||
|
@ -144,7 +144,7 @@ impl InlineAssistant {
|
||||||
self.pending_assists.insert(
|
self.pending_assists.insert(
|
||||||
inline_assist_id,
|
inline_assist_id,
|
||||||
PendingInlineAssist {
|
PendingInlineAssist {
|
||||||
include_conversation,
|
include_context,
|
||||||
editor: editor.downgrade(),
|
editor: editor.downgrade(),
|
||||||
inline_assist_editor: Some((block_id, inline_assist_editor.clone())),
|
inline_assist_editor: Some((block_id, inline_assist_editor.clone())),
|
||||||
codegen: codegen.clone(),
|
codegen: codegen.clone(),
|
||||||
|
@ -375,11 +375,11 @@ impl InlineAssistant {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let conversation = if pending_assist.include_conversation {
|
let context = if pending_assist.include_context {
|
||||||
pending_assist.workspace.as_ref().and_then(|workspace| {
|
pending_assist.workspace.as_ref().and_then(|workspace| {
|
||||||
let workspace = workspace.upgrade()?.read(cx);
|
let workspace = workspace.upgrade()?.read(cx);
|
||||||
let assistant_panel = workspace.panel::<AssistantPanel>(cx)?;
|
let assistant_panel = workspace.panel::<AssistantPanel>(cx)?;
|
||||||
assistant_panel.read(cx).active_conversation(cx)
|
assistant_panel.read(cx).active_context(cx)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -461,8 +461,8 @@ impl InlineAssistant {
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut messages = Vec::new();
|
let mut messages = Vec::new();
|
||||||
if let Some(conversation) = conversation {
|
if let Some(context) = context {
|
||||||
let request = conversation.read(cx).to_completion_request(cx);
|
let request = context.read(cx).to_completion_request(cx);
|
||||||
messages = request.messages;
|
messages = request.messages;
|
||||||
}
|
}
|
||||||
let model = CompletionProvider::global(cx).model();
|
let model = CompletionProvider::global(cx).model();
|
||||||
|
@ -818,7 +818,7 @@ struct PendingInlineAssist {
|
||||||
codegen: Model<Codegen>,
|
codegen: Model<Codegen>,
|
||||||
_subscriptions: Vec<Subscription>,
|
_subscriptions: Vec<Subscription>,
|
||||||
workspace: Option<WeakView<Workspace>>,
|
workspace: Option<WeakView<Workspace>>,
|
||||||
include_conversation: bool,
|
include_context: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::assistant_panel::ConversationEditor;
|
use crate::assistant_panel::ContextEditor;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
pub use assistant_slash_command::{SlashCommand, SlashCommandOutput, SlashCommandRegistry};
|
pub use assistant_slash_command::{SlashCommand, SlashCommandOutput, SlashCommandRegistry};
|
||||||
use editor::{CompletionProvider, Editor};
|
use editor::{CompletionProvider, Editor};
|
||||||
|
@ -29,7 +29,7 @@ pub mod tabs_command;
|
||||||
pub(crate) struct SlashCommandCompletionProvider {
|
pub(crate) struct SlashCommandCompletionProvider {
|
||||||
commands: Arc<SlashCommandRegistry>,
|
commands: Arc<SlashCommandRegistry>,
|
||||||
cancel_flag: Mutex<Arc<AtomicBool>>,
|
cancel_flag: Mutex<Arc<AtomicBool>>,
|
||||||
editor: Option<WeakView<ConversationEditor>>,
|
editor: Option<WeakView<ContextEditor>>,
|
||||||
workspace: Option<WeakView<Workspace>>,
|
workspace: Option<WeakView<Workspace>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ pub(crate) struct SlashCommandLine {
|
||||||
impl SlashCommandCompletionProvider {
|
impl SlashCommandCompletionProvider {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
commands: Arc<SlashCommandRegistry>,
|
commands: Arc<SlashCommandRegistry>,
|
||||||
editor: Option<WeakView<ConversationEditor>>,
|
editor: Option<WeakView<ContextEditor>>,
|
||||||
workspace: Option<WeakView<Workspace>>,
|
workspace: Option<WeakView<Workspace>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
|
@ -21,7 +21,7 @@ lazy_static::lazy_static! {
|
||||||
} else {
|
} else {
|
||||||
HOME.join(".config").join("zed")
|
HOME.join(".config").join("zed")
|
||||||
};
|
};
|
||||||
pub static ref CONVERSATIONS_DIR: PathBuf = if cfg!(target_os = "macos") {
|
pub static ref CONTEXTS_DIR: PathBuf = if cfg!(target_os = "macos") {
|
||||||
CONFIG_DIR.join("conversations")
|
CONFIG_DIR.join("conversations")
|
||||||
} else {
|
} else {
|
||||||
SUPPORT_DIR.join("conversations")
|
SUPPORT_DIR.join("conversations")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue