Preserve pi-ai catalog metadata for configured models
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
//! Fresh reads of provider keys and cached models.dev metadata for the host harness.
|
||||
use deno_core::OpState;
|
||||
//! Fresh reads of provider configuration and keys for the host harness.
|
||||
use sausage_vfs::{Layer, Open};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{collections::BTreeMap, sync::Arc};
|
||||
@@ -33,29 +32,3 @@ impl Config {
|
||||
.map_err(|error| anyhow::anyhow!("Cannot read {PATH}: {error}"))
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct CatalogCache(pub std::path::PathBuf);
|
||||
#[deno_core::op2]
|
||||
#[serde]
|
||||
pub(super) async fn op_model_catalog(
|
||||
state: std::rc::Rc<std::cell::RefCell<OpState>>,
|
||||
#[serde] updated: Option<serde_json::Value>,
|
||||
) -> Result<serde_json::Value, deno_error::JsErrorBox> {
|
||||
let path = state.borrow().borrow::<CatalogCache>().0.clone();
|
||||
let result = async {
|
||||
if let Some(value) = updated {
|
||||
tokio::fs::write(&path, serde_json::to_vec(&value)?).await?;
|
||||
return Ok::<_, anyhow::Error>(value);
|
||||
}
|
||||
let bytes = match tokio::fs::read(&path).await {
|
||||
Ok(bytes) => bytes,
|
||||
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {
|
||||
include_bytes!("../../js/models-dev.json").to_vec()
|
||||
}
|
||||
Err(error) => return Err(error.into()),
|
||||
};
|
||||
Ok(serde_json::from_slice(&bytes)?)
|
||||
}
|
||||
.await;
|
||||
result.map_err(|error| deno_error::JsErrorBox::generic(error.to_string()))
|
||||
}
|
||||
|
||||
@@ -85,7 +85,6 @@ deno_core::extension!(
|
||||
op_sql,
|
||||
credentials::op_credential_requests,
|
||||
credentials::op_model_providers,
|
||||
config::op_model_catalog,
|
||||
credentials::op_credential_next,
|
||||
environment::op_file,
|
||||
environment::op_exec,
|
||||
@@ -175,10 +174,6 @@ pub async fn run_module_with_input(
|
||||
})),
|
||||
..Default::default()
|
||||
});
|
||||
runtime
|
||||
.op_state()
|
||||
.borrow_mut()
|
||||
.put(config::CatalogCache(world.host_dir.join("models-dev.json")));
|
||||
runtime.op_state().borrow_mut().put(loader);
|
||||
runtime
|
||||
.op_state()
|
||||
|
||||
Reference in New Issue
Block a user