Introduce a new /workflow command (#15854)

This subsumes the previous built-in prompt.

Release Notes:

- N/A
This commit is contained in:
Antonio Scandurra 2024-08-06 16:18:07 +02:00 committed by GitHub
parent 889a14a2c2
commit 411934bb61
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 85 additions and 50 deletions

View file

@ -1201,6 +1201,12 @@ impl PromptStore {
let mut txn = db_env.write_txn()?;
let metadata = db_env.create_database(&mut txn, Some("metadata.v2"))?;
let bodies = db_env.create_database(&mut txn, Some("bodies.v2"))?;
// Remove edit workflow prompt, as we decided to opt into it using
// a slash command instead.
metadata.delete(&mut txn, &PromptId::EditWorkflow).ok();
bodies.delete(&mut txn, &PromptId::EditWorkflow).ok();
txn.commit()?;
Self::upgrade_dbs(&db_env, metadata, bodies).log_err();
@ -1209,17 +1215,13 @@ impl PromptStore {
let metadata_cache = MetadataCache::from_db(metadata, &txn)?;
txn.commit()?;
let store = PromptStore {
Ok(PromptStore {
executor,
env: db_env,
metadata_cache: RwLock::new(metadata_cache),
metadata,
bodies,
};
store.save_built_in_prompts().log_err();
Ok(store)
})
}
})
}
@ -1425,49 +1427,6 @@ impl PromptStore {
})
}
fn save_built_in_prompts(&self) -> Result<()> {
self.save_built_in_prompt(
PromptId::EditWorkflow,
"Built-in: Editing Workflow",
"prompts/edit_workflow.md",
)?;
Ok(())
}
/// Write a built-in prompt to the database, preserving the value of the default field
/// if a prompt with this id already exists. This method blocks.
fn save_built_in_prompt(
&self,
id: PromptId,
title: impl Into<SharedString>,
body_path: &str,
) -> Result<()> {
let mut metadata_cache = self.metadata_cache.write();
let existing_metadata = metadata_cache.metadata_by_id.get(&id).cloned();
let prompt_metadata = PromptMetadata {
id,
title: Some(title.into()),
default: existing_metadata.map_or(true, |m| m.default),
saved_at: Utc::now(),
};
metadata_cache.insert(prompt_metadata.clone());
let db_connection = self.env.clone();
let bodies = self.bodies;
let metadata_db = self.metadata;
let mut txn = db_connection.write_txn()?;
metadata_db.put(&mut txn, &id, &prompt_metadata)?;
let body = String::from_utf8(Assets.load(body_path)?.unwrap().to_vec())?;
bodies.put(&mut txn, &id, &body)?;
txn.commit()?;
Ok(())
}
fn save_metadata(
&self,
id: PromptId,