cookie_agent_engine/model_snapshots/
mod.rs1use std::sync::Arc;
8
9use cookie_agent_models::{
10 CompiledModelRuntime,
11 manifests::{ManifestError, build_manifest, frozen_binding},
12};
13use cookie_agent_protocol::{FrozenModelBinding, ModelSelection};
14
15use crate::EngineError;
16
17pub(crate) fn prepare_runtime_manifest(
18 runtime: &CompiledModelRuntime,
19) -> Result<Arc<cookie_agent_protocol::ModelSnapshotManifestV1>, EngineError> {
20 Ok(build_manifest(runtime.manifest_payload()?)?)
21}
22
23pub(crate) fn binding_for_selection(
24 manifest: &cookie_agent_protocol::ModelSnapshotManifestV1,
25 _runtime: &CompiledModelRuntime,
26 selection: &ModelSelection,
27) -> Result<FrozenModelBinding, EngineError> {
28 let blueprint = manifest
29 .payload
30 .blueprints
31 .iter()
32 .find(|blueprint| blueprint.selection.model == selection.model)
33 .ok_or(EngineError::NoRunnableModel)?;
34 if selection
35 .variant
36 .as_ref()
37 .is_some_and(|variant| !blueprint.variants.iter().any(|value| &value.id == variant))
38 {
39 return Err(EngineError::NoRunnableModel);
40 }
41 if cookie_agent_models::adapters::wire_adapter_for_protocol(blueprint.protocol_recipe.as_str())
42 .is_none()
43 {
44 return Err(EngineError::RuntimeCompileFailed);
45 }
46 frozen_binding(manifest.revision.clone(), blueprint, selection.clone())
47 .map_err(EngineError::from)
48}
49
50impl From<ManifestError> for EngineError {
51 fn from(error: ManifestError) -> Self {
52 Self::Manifest(error)
53 }
54}