diff --git a/epiphany-core/Cargo.toml b/epiphany-core/Cargo.toml index 97d67f1a..5c0510e7 100644 --- a/epiphany-core/Cargo.toml +++ b/epiphany-core/Cargo.toml @@ -17,6 +17,7 @@ cultcache-rs = { path = "../vendor/cultcache-rs" } cultmesh-rs = { path = "../vendor/cultmesh-rs" } cultnet-rs = { path = "../vendor/cultnet-rs" } epiphany-openai-adapter = { path = "../epiphany-openai-adapter" } +epiphany-model-adapter = { path = "../epiphany-model-adapter" } epiphany-state-model = { path = "../epiphany-state-model" } ignore = "0.4.23" postgres = "0.19" diff --git a/epiphany-core/src/bin/epiphany-repo-birth-runner.rs b/epiphany-core/src/bin/epiphany-repo-birth-runner.rs index f8aab18b..e7aecf64 100644 --- a/epiphany-core/src/bin/epiphany-repo-birth-runner.rs +++ b/epiphany-core/src/bin/epiphany-repo-birth-runner.rs @@ -145,7 +145,7 @@ fn run(args: Args) -> Result { let prompt_path = execution_dir.join("prompt.md"); let schema_path = execution_dir.join("output-schema.json"); let result_path = execution_dir.join("result.json"); - let request_path = execution_dir.join("openai-request.json"); + let request_path = execution_dir.join("model-request.json"); let runtime_summary_path = execution_dir.join("model-runtime-summary.json"); let stdout_path = execution_dir.join("executor.stdout.log"); let stderr_path = execution_dir.join("executor.stderr.log"); @@ -333,9 +333,10 @@ fn run_openai_runtime_specialist( Utc::now().timestamp_millis() ); let request = json!({ - "schema_id": "epiphany.openai_model_request.v0", + "schema_id": "epiphany.model_request.v0", "request_id": request_id, "conversation_id": format!("repo-birth-{}", sanitize(kind)), + "provider": args.model_provider.clone(), "model": model, "instructions": format!( "{prompt}\n\nReturn only a single JSON object matching this output schema. No Markdown, no commentary.\n\n```json\n{schema_text}\n```" diff --git a/epiphany-core/src/runtime_spine.rs b/epiphany-core/src/runtime_spine.rs index a9b980aa..a3997a47 100644 --- a/epiphany-core/src/runtime_spine.rs +++ b/epiphany-core/src/runtime_spine.rs @@ -71,6 +71,10 @@ use cultnet_rs::CultNetWireContract; use cultnet_rs::builtin_schema_registry; use cultnet_rs::encode_cultnet_message_to_vec; use cultnet_rs::encode_frame; +use epiphany_model_adapter::EpiphanyModelAdapterStatus; +use epiphany_model_adapter::EpiphanyModelReceipt; +use epiphany_model_adapter::EpiphanyModelRequest; +use epiphany_model_adapter::EpiphanyModelStreamEvent; use epiphany_openai_adapter::EpiphanyOpenAiAdapterStatus; use epiphany_openai_adapter::EpiphanyOpenAiModelReceipt; use epiphany_openai_adapter::EpiphanyOpenAiModelRequest; @@ -98,6 +102,10 @@ pub const OPENAI_ADAPTER_STATUS_TYPE: &str = "epiphany.openai_adapter_status.v0" pub const OPENAI_MODEL_REQUEST_TYPE: &str = "epiphany.openai_model_request.v0"; pub const OPENAI_MODEL_STREAM_EVENT_TYPE: &str = "epiphany.openai_model_stream_event.v0"; pub const OPENAI_MODEL_RECEIPT_TYPE: &str = "epiphany.openai_model_receipt.v0"; +pub const MODEL_ADAPTER_STATUS_TYPE: &str = "epiphany.model_adapter_status.v0"; +pub const MODEL_REQUEST_TYPE: &str = "epiphany.model_request.v0"; +pub const MODEL_STREAM_EVENT_TYPE: &str = "epiphany.model_stream_event.v0"; +pub const MODEL_RECEIPT_TYPE: &str = "epiphany.model_receipt.v0"; pub const SURFACE_SCENE_TYPE: &str = "epiphany.surface.scene"; pub const SURFACE_FRESHNESS_TYPE: &str = "epiphany.surface.freshness"; pub const SURFACE_CONTEXT_TYPE: &str = "epiphany.surface.context"; @@ -127,6 +135,10 @@ pub const OPENAI_ADAPTER_STATUS_SCHEMA_VERSION: &str = "epiphany.openai_adapter_ pub const OPENAI_MODEL_REQUEST_SCHEMA_VERSION: &str = "epiphany.openai_model_request.v0"; pub const OPENAI_MODEL_STREAM_EVENT_SCHEMA_VERSION: &str = "epiphany.openai_model_stream_event.v0"; pub const OPENAI_MODEL_RECEIPT_SCHEMA_VERSION: &str = "epiphany.openai_model_receipt.v0"; +pub const MODEL_ADAPTER_STATUS_SCHEMA_VERSION: &str = "epiphany.model_adapter_status.v0"; +pub const MODEL_REQUEST_SCHEMA_VERSION: &str = "epiphany.model_request.v0"; +pub const MODEL_STREAM_EVENT_SCHEMA_VERSION: &str = "epiphany.model_stream_event.v0"; +pub const MODEL_RECEIPT_SCHEMA_VERSION: &str = "epiphany.model_receipt.v0"; pub const SCENE_SURFACE_SCHEMA_VERSION: &str = "epiphany.scene_surface.v0"; pub const FRESHNESS_SURFACE_SCHEMA_VERSION: &str = "epiphany.freshness_surface.v0"; pub const CONTEXT_SURFACE_SCHEMA_VERSION: &str = "epiphany.context_surface.v0"; @@ -627,6 +639,10 @@ pub fn runtime_spine_cache(store_path: impl AsRef) -> Result { cache.register_entry_type::()?; cache.register_entry_type::()?; cache.register_entry_type::()?; + cache.register_entry_type::()?; + cache.register_entry_type::()?; + cache.register_entry_type::()?; + cache.register_entry_type::()?; cache.add_generic_backing_store(SingleFileMessagePackBackingStore::new( store_path.to_path_buf(), )); @@ -2030,6 +2046,52 @@ fn epiphany_mutation_contracts() -> Vec { vec![], vec!["Runtime events are append-only projections for inspection."], ), + mutation_contract( + MODEL_ADAPTER_STATUS_TYPE, + MODEL_ADAPTER_STATUS_SCHEMA_VERSION, + vec![CultNetDocumentOperation::Snapshot], + CultNetMutationAuthority::ReadOnly, + vec![], + vec![], + vec![ + "Model adapter status is provider-neutral; OpenAI/Codex is one current provider behind this boundary.", + ], + ), + mutation_contract( + MODEL_REQUEST_TYPE, + MODEL_REQUEST_SCHEMA_VERSION, + vec![ + CultNetDocumentOperation::IntentSubmit, + CultNetDocumentOperation::ReceiptWatch, + ], + CultNetMutationAuthority::Coordinator, + vec![MODEL_REQUEST_TYPE], + vec![MODEL_STREAM_EVENT_TYPE, MODEL_RECEIPT_TYPE], + vec![ + "Model turns enter through typed provider-neutral Epiphany request documents and return typed stream events/receipts.", + "Provider adapters may authenticate and transport; they must not own Epiphany state, prompt authority, or scheduling.", + ], + ), + mutation_contract( + MODEL_STREAM_EVENT_TYPE, + MODEL_STREAM_EVENT_SCHEMA_VERSION, + vec![CultNetDocumentOperation::ReceiptWatch], + CultNetMutationAuthority::ReadOnly, + vec![], + vec![], + vec!["Model stream events are receipts from a typed model request."], + ), + mutation_contract( + MODEL_RECEIPT_TYPE, + MODEL_RECEIPT_SCHEMA_VERSION, + vec![CultNetDocumentOperation::ReceiptWatch], + CultNetMutationAuthority::ReadOnly, + vec![], + vec![], + vec![ + "Terminal model receipts carry provider response id, usage, and transport evidence.", + ], + ), mutation_contract( OPENAI_ADAPTER_STATUS_TYPE, OPENAI_ADAPTER_STATUS_SCHEMA_VERSION, @@ -2038,22 +2100,18 @@ fn epiphany_mutation_contracts() -> Vec { vec![], vec![], vec![ - "OpenAI adapter status is a typed document; it is not a Codex app-server status blob.", + "OpenAI adapter status is provider-specific evidence behind the model adapter boundary.", ], ), mutation_contract( OPENAI_MODEL_REQUEST_TYPE, OPENAI_MODEL_REQUEST_SCHEMA_VERSION, - vec![ - CultNetDocumentOperation::IntentSubmit, - CultNetDocumentOperation::ReceiptWatch, - ], - CultNetMutationAuthority::Coordinator, - vec![OPENAI_MODEL_REQUEST_TYPE], + vec![CultNetDocumentOperation::Snapshot], + CultNetMutationAuthority::ReadOnly, + vec![], vec![OPENAI_MODEL_STREAM_EVENT_TYPE, OPENAI_MODEL_RECEIPT_TYPE], vec![ - "Model turns enter through typed Epiphany request documents and return typed stream events/receipts.", - "The Codex spine may authenticate and transport; it must not own Epiphany state or scheduling.", + "OpenAI model requests are adapter projection evidence, not the provider-neutral request authority.", ], ), mutation_contract( @@ -2063,7 +2121,9 @@ fn epiphany_mutation_contracts() -> Vec { CultNetMutationAuthority::ReadOnly, vec![], vec![], - vec!["OpenAI stream events are receipts from a typed model request."], + vec![ + "OpenAI stream events are provider-specific receipts mirrored from model stream events.", + ], ), mutation_contract( OPENAI_MODEL_RECEIPT_TYPE, @@ -2072,7 +2132,9 @@ fn epiphany_mutation_contracts() -> Vec { CultNetMutationAuthority::ReadOnly, vec![], vec![], - vec!["Terminal model receipts carry response id, usage, and transport evidence."], + vec![ + "OpenAI terminal receipts are provider-specific evidence behind the model receipt.", + ], ), mutation_contract( AGENT_MEMORY_TYPE, @@ -3029,22 +3091,31 @@ mod tests { .iter() .any(|item| item == "epiphany.repo_birth_runner.v0")) ); - let openai_contract = contracts + let model_contract = contracts .iter() - .find(|contract| contract.document_type == OPENAI_MODEL_REQUEST_TYPE) - .expect("OpenAI adapter should advertise typed model request contract"); + .find(|contract| contract.document_type == MODEL_REQUEST_TYPE) + .expect("model adapter should advertise provider-neutral request contract"); assert_eq!( - openai_contract.authority, + model_contract.authority, CultNetMutationAuthority::Coordinator ); assert!( - openai_contract + model_contract .receipt_document_types .as_ref() - .is_some_and(|items| items - .iter() - .any(|item| item == OPENAI_MODEL_RECEIPT_TYPE)) + .is_some_and(|items| items.iter().any(|item| item == MODEL_RECEIPT_TYPE)) ); + let openai_contract = contracts + .iter() + .find(|contract| contract.document_type == OPENAI_MODEL_REQUEST_TYPE) + .expect("OpenAI adapter should advertise typed provider evidence contract"); + assert_eq!( + openai_contract.authority, + CultNetMutationAuthority::ReadOnly + ); + assert!(openai_contract.notes.as_ref().is_some_and(|notes| { + notes.iter().any(|note| note.contains("adapter projection")) + })); let memory_graph_contract = contracts .iter() .find(|contract| contract.document_type == MEMORY_GRAPH_TYPE) @@ -3099,6 +3170,14 @@ mod tests { schema.document_type.as_deref() == Some("epiphany.swarm_control_receipt.v0") && schema.schema_version.as_deref() == Some("epiphany.swarm_control_receipt.v0") })); + assert!(schemas.iter().any(|schema| { + schema.document_type.as_deref() == Some(MODEL_REQUEST_TYPE) + && schema.schema_version.as_deref() == Some(MODEL_REQUEST_SCHEMA_VERSION) + })); + assert!(schemas.iter().any(|schema| { + schema.document_type.as_deref() == Some(MODEL_RECEIPT_TYPE) + && schema.schema_version.as_deref() == Some(MODEL_RECEIPT_SCHEMA_VERSION) + })); let receipt_schema_path = epiphany_schema_root().join("epiphany.swarm-control-receipt.schema.json"); let receipt_schema: serde_json::Value = diff --git a/epiphany-model-adapter/Cargo.lock b/epiphany-model-adapter/Cargo.lock new file mode 100644 index 00000000..89e2fca7 --- /dev/null +++ b/epiphany-model-adapter/Cargo.lock @@ -0,0 +1,737 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anyhow" +version = "1.0.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" + +[[package]] +name = "autocfg" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" + +[[package]] +name = "bitflags" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" + +[[package]] +name = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + +[[package]] +name = "cc" +version = "1.2.62" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1dce859f0832a7d088c4f1119888ab94ef4b5d6795d1ce05afb7fe159d79f98" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "chrono" +version = "0.4.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-traits", + "serde", + "wasm-bindgen", + "windows-link", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cultcache-rs" +version = "0.1.0" +dependencies = [ + "anyhow", + "chrono", + "cultcache-rs-derive", + "fs2", + "rmp-serde", + "serde", + "serde_bytes", + "serde_json", + "uuid", +] + +[[package]] +name = "cultcache-rs-derive" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "epiphany-model-adapter" +version = "0.1.0" +dependencies = [ + "cultcache-rs", + "serde", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "fs2" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "slab", +] + +[[package]] +name = "getrandom" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "wasip2", + "wasip3", +] + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash", +] + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "iana-time-zone" +version = "0.1.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + +[[package]] +name = "indexmap" +version = "2.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" +dependencies = [ + "equivalent", + "hashbrown 0.17.1", + "serde", + "serde_core", +] + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "js-sys" +version = "0.3.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "142bc4740e452c1e57ade0cbc129f139c9093e354346f0872ef985f4f5cf5f11" +dependencies = [ + "cfg-if", + "futures-util", + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + +[[package]] +name = "libc" +version = "0.2.186" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" + +[[package]] +name = "log" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616ec5685824bcc94416c6d4a7a446eea774a31efd7062c8480ba6fd06d7a6e5" + +[[package]] +name = "memchr" +version = "2.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b947ae49db0d222b1dbc6b113ce7248a3fc3a6ca21b696717bfc000ba4484d8" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "rmp" +version = "0.8.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ba8be72d372b2c9b35542551678538b562e7cf86c3315773cae48dfbfe7790c" +dependencies = [ + "num-traits", +] + +[[package]] +name = "rmp-serde" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f81bee8c8ef9b577d1681a70ebbc962c232461e397b22c208c43c04b67a155" +dependencies = [ + "rmp", + "serde", +] + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_bytes" +version = "0.11.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5d440709e79d88e51ac01c4b72fc6cb7314017bb7da9eeff678aa94c10e3ea8" +dependencies = [ + "serde", + "serde_core", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.150" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "uuid" +version = "1.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd74a9687298c6858e9b88ec8935ec45d22e8fd5e6394fa1bd4e99a87789c76" +dependencies = [ + "getrandom", + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "wasip2" +version = "1.0.3+wasi-0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20064672db26d7cdc89c7798c48a0fdfac8213434a1186e5ef29fd560ae223d6" +dependencies = [ + "wit-bindgen 0.57.1", +] + +[[package]] +name = "wasip3" +version = "0.4.0+wasi-0.3.0-rc-2026-01-06" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" +dependencies = [ + "wit-bindgen 0.51.0", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.122" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed04576f974d2b2fba0f38c51dbc5518011e38c36bf1143164be765528fd409" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.122" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "916151b09da36bd82f6615cbf3a419e2f0ba23a03c6160e8e92eb6bd4aa1dec6" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.122" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "299047362ccbfce148b67ab7e73349f77748e00c8296f9542adfad2ad82c5c5e" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.122" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a929b2c61f11ba3e9bc35b50c1f25cb38e0e892c0c231ae2b8cf78d5dad4437" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "wasm-encoder" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" +dependencies = [ + "anyhow", + "indexmap", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +dependencies = [ + "bitflags", + "hashbrown 0.15.5", + "indexmap", + "semver", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" +dependencies = [ + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen" +version = "0.57.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" + +[[package]] +name = "wit-bindgen-core" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/epiphany-model-adapter/Cargo.toml b/epiphany-model-adapter/Cargo.toml new file mode 100644 index 00000000..f1a9badf --- /dev/null +++ b/epiphany-model-adapter/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "epiphany-model-adapter" +version = "0.1.0" +edition = "2024" +publish = false +license-file = "../LICENSE" + +[lib] +name = "epiphany_model_adapter" +path = "src/lib.rs" + +[dependencies] +cultcache-rs = { path = "../vendor/cultcache-rs" } +serde = { version = "1", features = ["derive"] } diff --git a/epiphany-model-adapter/src/lib.rs b/epiphany-model-adapter/src/lib.rs new file mode 100644 index 00000000..881bdfb7 --- /dev/null +++ b/epiphany-model-adapter/src/lib.rs @@ -0,0 +1,168 @@ +use cultcache_rs::DatabaseEntry; +use serde::Deserialize; +use serde::Serialize; + +pub const MODEL_ADAPTER_REQUEST_SCHEMA_ID: &str = "epiphany.model_request.v0"; +pub const MODEL_ADAPTER_EVENT_SCHEMA_ID: &str = "epiphany.model_stream_event.v0"; +pub const MODEL_ADAPTER_RECEIPT_SCHEMA_ID: &str = "epiphany.model_receipt.v0"; +pub const MODEL_ADAPTER_STATUS_SCHEMA_ID: &str = "epiphany.model_adapter_status.v0"; + +#[derive(Debug, Clone, PartialEq, Eq, DatabaseEntry)] +#[cultcache( + type = "epiphany.model_adapter_status.v0", + schema = "EpiphanyModelAdapterStatus" +)] +pub struct EpiphanyModelAdapterStatus { + #[cultcache(key = 0)] + pub schema_id: String, + #[cultcache(key = 1)] + pub adapter_id: String, + #[cultcache(key = 2)] + pub provider: String, + #[cultcache(key = 3, default)] + pub default_model: Option, + #[cultcache(key = 4)] + pub streaming_supported: bool, + #[cultcache(key = 5)] + pub provider_transport_attached: bool, +} + +#[derive(Debug, Clone, PartialEq, DatabaseEntry)] +#[cultcache(type = "epiphany.model_request.v0", schema = "EpiphanyModelRequest")] +pub struct EpiphanyModelRequest { + #[cultcache(key = 0)] + pub schema_id: String, + #[cultcache(key = 1)] + pub request_id: String, + #[cultcache(key = 2)] + pub conversation_id: String, + #[cultcache(key = 3)] + pub provider: String, + #[cultcache(key = 4)] + pub model: String, + #[cultcache(key = 5)] + pub instructions: String, + #[cultcache(key = 6, default)] + pub input: Vec, + #[cultcache(key = 7, default)] + pub reasoning_effort: Option, + #[cultcache(key = 8, default)] + pub reasoning_summary: Option, + #[cultcache(key = 9, default)] + pub service_tier: Option, + #[cultcache(key = 10, default)] + pub output_contract_id: Option, +} + +impl EpiphanyModelRequest { + pub fn new( + request_id: impl Into, + conversation_id: impl Into, + provider: impl Into, + model: impl Into, + instructions: impl Into, + ) -> Self { + Self { + schema_id: MODEL_ADAPTER_REQUEST_SCHEMA_ID.to_string(), + request_id: request_id.into(), + conversation_id: conversation_id.into(), + provider: provider.into(), + model: model.into(), + instructions: instructions.into(), + input: Vec::new(), + reasoning_effort: None, + reasoning_summary: None, + service_tier: None, + output_contract_id: None, + } + } +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub enum EpiphanyModelInputItem { + UserText { text: String }, + AssistantText { text: String }, + ToolResult { call_id: String, output: String }, +} + +#[derive(Debug, Clone, PartialEq, DatabaseEntry)] +#[cultcache( + type = "epiphany.model_stream_event.v0", + schema = "EpiphanyModelStreamEvent" +)] +pub struct EpiphanyModelStreamEvent { + #[cultcache(key = 0)] + pub schema_id: String, + #[cultcache(key = 1)] + pub request_id: String, + #[cultcache(key = 2)] + pub provider: String, + #[cultcache(key = 3)] + pub sequence: u64, + #[cultcache(key = 4)] + pub payload: EpiphanyModelStreamPayload, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub enum EpiphanyModelStreamPayload { + TextDelta { + text: String, + }, + ReasoningDelta { + text: String, + }, + ToolCall { + call_id: String, + name: String, + arguments: String, + }, + Completed { + receipt: EpiphanyModelReceipt, + }, + Failed { + message: String, + }, +} + +#[derive(Debug, Clone, PartialEq, Eq, DatabaseEntry)] +#[cultcache(type = "epiphany.model_receipt.v0", schema = "EpiphanyModelReceipt")] +pub struct EpiphanyModelReceipt { + #[cultcache(key = 0)] + pub schema_id: String, + #[cultcache(key = 1)] + pub request_id: String, + #[cultcache(key = 2)] + pub provider: String, + #[cultcache(key = 3)] + pub model: String, + #[cultcache(key = 4, default)] + pub provider_response_id: Option, + #[cultcache(key = 5, default)] + pub input_tokens: Option, + #[cultcache(key = 6, default)] + pub output_tokens: Option, + #[cultcache(key = 7, default)] + pub reasoning_output_tokens: Option, + #[cultcache(key = 8, default)] + pub transport: Option, +} + +impl EpiphanyModelReceipt { + pub fn new( + request_id: impl Into, + provider: impl Into, + model: impl Into, + ) -> Self { + Self { + schema_id: MODEL_ADAPTER_RECEIPT_SCHEMA_ID.to_string(), + request_id: request_id.into(), + provider: provider.into(), + model: model.into(), + provider_response_id: None, + input_tokens: None, + output_tokens: None, + reasoning_output_tokens: None, + transport: None, + } + } +} diff --git a/epiphany-openai-runtime/Cargo.toml b/epiphany-openai-runtime/Cargo.toml index ad9b8a58..9c5379e1 100644 --- a/epiphany-openai-runtime/Cargo.toml +++ b/epiphany-openai-runtime/Cargo.toml @@ -13,6 +13,7 @@ path = "src/lib.rs" anyhow = "1" chrono = "0.4.44" epiphany-core = { path = "../epiphany-core" } +epiphany-model-adapter = { path = "../epiphany-model-adapter" } epiphany-openai-adapter = { path = "../epiphany-openai-adapter" } epiphany-openai-codex-spine = { path = "../epiphany-openai-codex-spine" } rmp-serde = "1" diff --git a/epiphany-openai-runtime/src/bin/epiphany-openai-runtime.rs b/epiphany-openai-runtime/src/bin/epiphany-openai-runtime.rs index 11018974..d0ae4286 100644 --- a/epiphany-openai-runtime/src/bin/epiphany-openai-runtime.rs +++ b/epiphany-openai-runtime/src/bin/epiphany-openai-runtime.rs @@ -5,7 +5,8 @@ use std::path::PathBuf; use anyhow::Context; use anyhow::Result; use anyhow::anyhow; -use epiphany_openai_adapter::EpiphanyOpenAiInputItem; +use epiphany_model_adapter::EpiphanyModelInputItem; +use epiphany_model_adapter::EpiphanyModelRequest; use epiphany_openai_adapter::EpiphanyOpenAiModelReceipt; use epiphany_openai_adapter::EpiphanyOpenAiModelRequest; use epiphany_openai_adapter::EpiphanyOpenAiStreamEvent; @@ -13,11 +14,12 @@ use epiphany_openai_adapter::EpiphanyOpenAiStreamPayload; use epiphany_openai_runtime::EpiphanyOpenAiRuntimeOptions; use epiphany_openai_runtime::EpiphanyWorkerRuntimeOptions; use epiphany_openai_runtime::OPENAI_RUNTIME_ROLE; -use epiphany_openai_runtime::assistant_text_from_openai_events; +use epiphany_openai_runtime::assistant_text_from_model_events; use epiphany_openai_runtime::default_codex_home; use epiphany_openai_runtime::default_options; use epiphany_openai_runtime::ensure_openai_runtime_ready; use epiphany_openai_runtime::record_openai_events; +use epiphany_openai_runtime::run_model_turn; use epiphany_openai_runtime::run_openai_model_turn; use epiphany_openai_runtime::run_worker_launch; use serde_json::json; @@ -36,16 +38,27 @@ async fn main() -> Result<()> { require_supported_provider(&options.provider)?; let request_text = fs::read_to_string(&options.request_path) .with_context(|| format!("failed to read {}", options.request_path.display()))?; - let request: EpiphanyOpenAiModelRequest = serde_json::from_str(&request_text) - .with_context(|| format!("failed to parse {}", options.request_path.display()))?; let output_last_message_path = options.output_last_message_path.clone(); - let runtime_options = options.into_runtime_options(&request); - let summary = run_openai_model_turn(runtime_options.clone(), request.clone()).await?; + let (request_id, runtime_options, summary) = + if let Ok(request) = serde_json::from_str::(&request_text) { + let runtime_options = options.clone().into_runtime_options_for_model(&request); + let summary = + run_model_turn(&options.provider, runtime_options.clone(), request.clone()) + .await?; + (request.request_id, runtime_options, summary) + } else { + let request: EpiphanyOpenAiModelRequest = serde_json::from_str(&request_text) + .with_context(|| { + format!("failed to parse {}", options.request_path.display()) + })?; + let runtime_options = options.into_runtime_options(&request); + let summary = + run_openai_model_turn(runtime_options.clone(), request.clone()).await?; + (request.request_id, runtime_options, summary) + }; if let Some(path) = output_last_message_path { - let text = assistant_text_from_openai_events( - &runtime_options.store_path, - &request.request_id, - )?; + let text = + assistant_text_from_model_events(&runtime_options.store_path, &request_id)?; fs::write(&path, text) .with_context(|| format!("failed to write {}", path.display()))?; } @@ -57,6 +70,7 @@ async fn main() -> Result<()> { let summary = run_worker_launch(EpiphanyWorkerRuntimeOptions { store_path: options.store_path, codex_home: options.codex_home, + provider: options.provider, job_id: options.job_id, model: options.model, }) @@ -66,17 +80,23 @@ async fn main() -> Result<()> { "smoke" => { let options = parse_smoke_options(args.collect())?; require_supported_provider(&options.provider)?; - let mut request = EpiphanyOpenAiModelRequest::new( + let mut request = EpiphanyModelRequest::new( "smoke-request", "smoke-conversation", + &options.provider, "gpt-5.4", "Answer with one sentence.", ); - request.input.push(EpiphanyOpenAiInputItem::UserText { + request.input.push(EpiphanyModelInputItem::UserText { text: "smoke".to_string(), }); - let runtime_options = - default_options(options.store_path.clone(), options.codex_home, &request); + let openai_request = + epiphany_openai_runtime::openai_request_from_model_request(&request); + let runtime_options = default_options( + options.store_path.clone(), + options.codex_home, + &openai_request, + ); ensure_openai_runtime_ready(&runtime_options)?; epiphany_core::ensure_runtime_session( &runtime_options.store_path, @@ -99,7 +119,11 @@ async fn main() -> Result<()> { artifact_refs: Vec::new(), }, )?; - epiphany_openai_runtime::store_openai_request(&runtime_options.store_path, &request)?; + epiphany_openai_runtime::store_model_request(&runtime_options.store_path, &request)?; + epiphany_openai_runtime::store_openai_request( + &runtime_options.store_path, + &openai_request, + )?; let mut receipt = EpiphanyOpenAiModelReceipt::new(&request.request_id, &request.model); receipt.response_id = Some("smoke-response".to_string()); receipt.transport = Some("smoke_no_network".to_string()); @@ -112,7 +136,7 @@ async fn main() -> Result<()> { let summary = record_openai_events( &runtime_options.store_path, &runtime_options, - &request, + &openai_request, &events, )?; print_json(&json!({ @@ -125,6 +149,7 @@ async fn main() -> Result<()> { Ok(()) } +#[derive(Clone)] struct ModelTurnCliOptions { provider: String, store_path: PathBuf, @@ -138,6 +163,14 @@ struct ModelTurnCliOptions { } impl ModelTurnCliOptions { + fn into_runtime_options_for_model( + self, + request: &EpiphanyModelRequest, + ) -> EpiphanyOpenAiRuntimeOptions { + let openai_request = epiphany_openai_runtime::openai_request_from_model_request(request); + self.into_runtime_options(&openai_request) + } + fn into_runtime_options( self, request: &EpiphanyOpenAiModelRequest, diff --git a/epiphany-openai-runtime/src/lib.rs b/epiphany-openai-runtime/src/lib.rs index cf4279ce..9d2c613f 100644 --- a/epiphany-openai-runtime/src/lib.rs +++ b/epiphany-openai-runtime/src/lib.rs @@ -23,6 +23,11 @@ use epiphany_core::put_runtime_reorient_worker_result; use epiphany_core::put_runtime_role_worker_result; use epiphany_core::runtime_spine_cache; use epiphany_core::runtime_spine_status; +use epiphany_model_adapter::EpiphanyModelInputItem; +use epiphany_model_adapter::EpiphanyModelReceipt; +use epiphany_model_adapter::EpiphanyModelRequest; +use epiphany_model_adapter::EpiphanyModelStreamEvent; +use epiphany_model_adapter::EpiphanyModelStreamPayload; use epiphany_openai_adapter::EpiphanyOpenAiAdapterStatus; use epiphany_openai_adapter::EpiphanyOpenAiInputItem; use epiphany_openai_adapter::EpiphanyOpenAiModelRequest; @@ -36,6 +41,7 @@ use serde::de::DeserializeOwned; pub const OPENAI_RUNTIME_ROLE: &str = "openai-model-adapter"; pub const OPENAI_RUNTIME_SOURCE: &str = "epiphany-openai-runtime"; +pub const DEFAULT_MODEL_PROVIDER: &str = "openai-codex"; #[derive(Debug, Clone, PartialEq, Eq)] pub struct EpiphanyOpenAiRuntimeOptions { @@ -65,6 +71,7 @@ pub struct EpiphanyOpenAiRuntimeRunSummary { pub struct EpiphanyWorkerRuntimeOptions { pub store_path: PathBuf, pub codex_home: PathBuf, + pub provider: String, pub job_id: String, pub model: String, } @@ -90,6 +97,11 @@ pub async fn run_openai_model_turn( let auth_manager = auth_manager(options.codex_home.clone()); let status = status_from_auth_manager(&auth_manager, options.default_model.clone(), true).await; store_openai_status(&options.store_path, &status)?; + store_model_status(&options.store_path, &status, DEFAULT_MODEL_PROVIDER)?; + store_model_request( + &options.store_path, + &model_request_from_openai_request(DEFAULT_MODEL_PROVIDER, &request), + )?; store_openai_request(&options.store_path, &request)?; ensure_runtime_session( &options.store_path, @@ -142,11 +154,32 @@ pub async fn run_openai_model_turn( record_openai_events(&options.store_path, &options, &request, &events) } +pub async fn run_model_turn( + provider: &str, + options: EpiphanyOpenAiRuntimeOptions, + request: EpiphanyModelRequest, +) -> Result { + require_openai_provider(provider)?; + if !provider_matches_request(provider, &request.provider) { + return Err(anyhow!( + "model request provider {:?} does not match selected provider {:?}", + request.provider, + provider + )); + } + let store_path = options.store_path.clone(); + let summary = + run_openai_model_turn(options, openai_request_from_model_request(&request)).await?; + store_model_request(&store_path, &request)?; + Ok(summary) +} + pub async fn run_worker_launch( options: EpiphanyWorkerRuntimeOptions, ) -> Result { let launch_request = load_worker_launch_request(&options.store_path, &options.job_id)?; - let model_request = build_worker_model_request(&launch_request, &options.model)?; + let model_request = + build_worker_model_request(&launch_request, &options.provider, &options.model)?; let openai_options = EpiphanyOpenAiRuntimeOptions { store_path: options.store_path.clone(), codex_home: options.codex_home, @@ -160,10 +193,14 @@ pub async fn run_worker_launch( .to_string(), default_model: Some(options.model), }; - let openai_summary = - run_openai_model_turn(openai_options.clone(), model_request.clone()).await?; + let openai_summary = run_model_turn( + &options.provider, + openai_options.clone(), + model_request.clone(), + ) + .await?; let assistant_text = - assistant_text_from_openai_events(&openai_options.store_path, &model_request.request_id)?; + assistant_text_from_model_events(&openai_options.store_path, &model_request.request_id)?; let worker_result = complete_worker_job_from_assistant_text( &openai_options.store_path, &launch_request, @@ -195,7 +232,17 @@ pub fn record_openai_events( { let mut cache = runtime_spine_cache(store_path)?; cache.pull_all_backing_stores()?; + let model_request = model_request_from_openai_request(DEFAULT_MODEL_PROVIDER, request); + cache.put(model_request_key(&model_request.request_id), &model_request)?; for event in events { + let model_event = model_event_from_openai_event(DEFAULT_MODEL_PROVIDER, event); + cache.put( + model_event_key(&model_event.request_id, model_event.sequence), + &model_event, + )?; + if let EpiphanyModelStreamPayload::Completed { receipt } = &model_event.payload { + cache.put(model_receipt_key(&receipt.request_id), receipt)?; + } let key = openai_event_key(&event.request_id, event.sequence); cache.put(key, event)?; match &event.payload { @@ -292,8 +339,9 @@ pub fn load_worker_launch_request( pub fn build_worker_model_request( launch_request: &EpiphanyRuntimeWorkerLaunchRequest, + provider: &str, model: &str, -) -> Result { +) -> Result { let launch_document = launch_request.launch_document()?; let request_id = format!( "worker-{}-{}", @@ -302,13 +350,14 @@ pub fn build_worker_model_request( ); let launch_document_text = serde_json::to_string_pretty(&launch_document) .context("failed to render worker launch document for model input")?; - let mut request = EpiphanyOpenAiModelRequest::new( + let mut request = EpiphanyModelRequest::new( request_id, format!("worker-{}", launch_request.binding_id), + provider, model.to_string(), worker_instructions(launch_request, &launch_document), ); - request.input.push(EpiphanyOpenAiInputItem::UserText { + request.input.push(EpiphanyModelInputItem::UserText { text: format!( "Execute this Epiphany worker launch document.\n\n```json\n{launch_document_text}\n```" ), @@ -439,6 +488,35 @@ pub fn store_openai_request( Ok(()) } +pub fn store_model_status( + store_path: impl AsRef, + status: &EpiphanyOpenAiAdapterStatus, + provider: &str, +) -> Result<()> { + let mut cache = runtime_spine_cache(store_path)?; + cache.pull_all_backing_stores()?; + let status = epiphany_model_adapter::EpiphanyModelAdapterStatus { + schema_id: epiphany_model_adapter::MODEL_ADAPTER_STATUS_SCHEMA_ID.to_string(), + adapter_id: status.adapter_id.clone(), + provider: provider.to_string(), + default_model: status.default_model.clone(), + streaming_supported: true, + provider_transport_attached: status.codex_transport_attached, + }; + cache.put(status.adapter_id.clone(), &status)?; + Ok(()) +} + +pub fn store_model_request( + store_path: impl AsRef, + request: &EpiphanyModelRequest, +) -> Result<()> { + let mut cache = runtime_spine_cache(store_path)?; + cache.pull_all_backing_stores()?; + cache.put(model_request_key(&request.request_id), request)?; + Ok(()) +} + pub fn assistant_text_from_openai_events( store_path: impl AsRef, request_id: &str, @@ -461,6 +539,28 @@ pub fn assistant_text_from_openai_events( Ok(text) } +pub fn assistant_text_from_model_events( + store_path: impl AsRef, + request_id: &str, +) -> Result { + let mut cache = runtime_spine_cache(store_path)?; + cache.pull_all_backing_stores()?; + let mut events = cache + .get_all::()? + .into_iter() + .filter(|event| event.request_id == request_id) + .collect::>(); + events.sort_by_key(|event| event.sequence); + + let mut text = String::new(); + for event in events { + if let EpiphanyModelStreamPayload::TextDelta { text: delta } = event.payload { + text.push_str(&delta); + } + } + Ok(text) +} + pub fn default_options( store_path: PathBuf, codex_home: PathBuf, @@ -486,6 +586,18 @@ pub fn openai_receipt_key(request_id: &str) -> String { request_id.to_string() } +pub fn model_request_key(request_id: &str) -> String { + request_id.to_string() +} + +pub fn model_event_key(request_id: &str, sequence: u64) -> String { + format!("{request_id}:{sequence:08}") +} + +pub fn model_receipt_key(request_id: &str) -> String { + request_id.to_string() +} + fn openai_event_type(event: &EpiphanyOpenAiStreamEvent) -> &'static str { match event.payload { EpiphanyOpenAiStreamPayload::TextDelta { .. } => "openai.model_turn.text_delta", @@ -527,6 +639,151 @@ fn openai_event_summary(event: &EpiphanyOpenAiStreamEvent) -> String { } } +pub fn model_request_from_openai_request( + provider: &str, + request: &EpiphanyOpenAiModelRequest, +) -> EpiphanyModelRequest { + EpiphanyModelRequest { + schema_id: epiphany_model_adapter::MODEL_ADAPTER_REQUEST_SCHEMA_ID.to_string(), + request_id: request.request_id.clone(), + conversation_id: request.conversation_id.clone(), + provider: provider.to_string(), + model: request.model.clone(), + instructions: request.instructions.clone(), + input: request + .input + .iter() + .map(model_input_from_openai_input) + .collect(), + reasoning_effort: request.reasoning_effort.clone(), + reasoning_summary: request.reasoning_summary.clone(), + service_tier: request.service_tier.clone(), + output_contract_id: request.output_contract_id.clone(), + } +} + +pub fn openai_request_from_model_request( + request: &EpiphanyModelRequest, +) -> EpiphanyOpenAiModelRequest { + EpiphanyOpenAiModelRequest { + schema_id: epiphany_openai_adapter::OPENAI_ADAPTER_REQUEST_SCHEMA_ID.to_string(), + request_id: request.request_id.clone(), + conversation_id: request.conversation_id.clone(), + model: request.model.clone(), + instructions: request.instructions.clone(), + input: request + .input + .iter() + .map(openai_input_from_model_input) + .collect(), + reasoning_effort: request.reasoning_effort.clone(), + reasoning_summary: request.reasoning_summary.clone(), + service_tier: request.service_tier.clone(), + output_contract_id: request.output_contract_id.clone(), + } +} + +fn model_input_from_openai_input(input: &EpiphanyOpenAiInputItem) -> EpiphanyModelInputItem { + match input { + EpiphanyOpenAiInputItem::UserText { text } => { + EpiphanyModelInputItem::UserText { text: text.clone() } + } + EpiphanyOpenAiInputItem::AssistantText { text } => { + EpiphanyModelInputItem::AssistantText { text: text.clone() } + } + EpiphanyOpenAiInputItem::ToolResult { call_id, output } => { + EpiphanyModelInputItem::ToolResult { + call_id: call_id.clone(), + output: output.clone(), + } + } + } +} + +fn openai_input_from_model_input(input: &EpiphanyModelInputItem) -> EpiphanyOpenAiInputItem { + match input { + EpiphanyModelInputItem::UserText { text } => { + EpiphanyOpenAiInputItem::UserText { text: text.clone() } + } + EpiphanyModelInputItem::AssistantText { text } => { + EpiphanyOpenAiInputItem::AssistantText { text: text.clone() } + } + EpiphanyModelInputItem::ToolResult { call_id, output } => { + EpiphanyOpenAiInputItem::ToolResult { + call_id: call_id.clone(), + output: output.clone(), + } + } + } +} + +pub fn model_event_from_openai_event( + provider: &str, + event: &EpiphanyOpenAiStreamEvent, +) -> EpiphanyModelStreamEvent { + EpiphanyModelStreamEvent { + schema_id: epiphany_model_adapter::MODEL_ADAPTER_EVENT_SCHEMA_ID.to_string(), + request_id: event.request_id.clone(), + provider: provider.to_string(), + sequence: event.sequence, + payload: match &event.payload { + EpiphanyOpenAiStreamPayload::TextDelta { text } => { + EpiphanyModelStreamPayload::TextDelta { text: text.clone() } + } + EpiphanyOpenAiStreamPayload::ReasoningDelta { text } => { + EpiphanyModelStreamPayload::ReasoningDelta { text: text.clone() } + } + EpiphanyOpenAiStreamPayload::ToolCall { + call_id, + name, + arguments, + } => EpiphanyModelStreamPayload::ToolCall { + call_id: call_id.clone(), + name: name.clone(), + arguments: arguments.clone(), + }, + EpiphanyOpenAiStreamPayload::Completed { receipt } => { + EpiphanyModelStreamPayload::Completed { + receipt: model_receipt_from_openai_receipt(provider, receipt), + } + } + EpiphanyOpenAiStreamPayload::Failed { message } => EpiphanyModelStreamPayload::Failed { + message: message.clone(), + }, + }, + } +} + +pub fn model_receipt_from_openai_receipt( + provider: &str, + receipt: &epiphany_openai_adapter::EpiphanyOpenAiModelReceipt, +) -> EpiphanyModelReceipt { + EpiphanyModelReceipt { + schema_id: epiphany_model_adapter::MODEL_ADAPTER_RECEIPT_SCHEMA_ID.to_string(), + request_id: receipt.request_id.clone(), + provider: provider.to_string(), + model: receipt.model.clone(), + provider_response_id: receipt.response_id.clone(), + input_tokens: receipt.input_tokens, + output_tokens: receipt.output_tokens, + reasoning_output_tokens: receipt.reasoning_output_tokens, + transport: receipt.transport.clone(), + } +} + +fn require_openai_provider(provider: &str) -> Result<()> { + if matches!(provider, "openai-codex" | "openai") { + return Ok(()); + } + Err(anyhow!( + "unsupported model runtime provider {provider:?}; current providers: openai-codex" + )) +} + +fn provider_matches_request(selected: &str, requested: &str) -> bool { + selected == requested || (selected == "openai" && requested == DEFAULT_MODEL_PROVIDER) +} + fn worker_instructions( launch_request: &EpiphanyRuntimeWorkerLaunchRequest, launch_document: &EpiphanyWorkerLaunchDocument, @@ -849,8 +1106,16 @@ mod tests { assert_eq!(summary.verdict, "pass"); assert_eq!(assistant_text_from_openai_events(&store, "req-1")?, ""); + assert_eq!(assistant_text_from_model_events(&store, "req-1")?, ""); let mut cache = runtime_spine_cache(&store)?; cache.pull_all_backing_stores()?; + assert!(cache.get::("req-1")?.is_some()); + assert!( + cache + .get::("req-1:00000000")? + .is_some() + ); + assert!(cache.get::("req-1")?.is_some()); assert!(cache.get::("req-1")?.is_some()); assert!( cache @@ -916,7 +1181,8 @@ mod tests { }, )?; let launch_request = load_worker_launch_request(&store, "worker-job-1")?; - let model_request = build_worker_model_request(&launch_request, "gpt-5.4")?; + let model_request = + build_worker_model_request(&launch_request, DEFAULT_MODEL_PROVIDER, "gpt-5.4")?; assert_eq!( model_request.output_contract_id.as_deref(), Some(epiphany_core::ROLE_WORKER_OUTPUT_CONTRACT_ID) diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 70f26841..1ba2832d 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -37,7 +37,7 @@ remembers doctrine; the branch remembers the blade. - Local operator runs now write typed CultMesh intent/receipt documents to `.epiphany-run/cultmesh/operator-runs.ccmp` through `epiphany-operator-run`. The wrapper writes intent before acting and a completion receipt after success; this is the local consent/trace rail, not a hidden scheduler queue. - Status-mode local runs now also write a native CultMesh operator snapshot to `.epiphany-run/cultmesh/operator-snapshots.ccmp` through `epiphany-operator-snapshot`. That snapshot distills the operator-safe MVP status artifact into typed fields such as thread id, state status, coordinator action, CRRC action, reorient action, available actions, and artifact refs; it does not preserve the raw JSON status blob as internal state. - `epiphany-mvp-status --source native` is the current provider-neutral status boundary. It projects scene, pressure, jobs, roles, planning, reorient, CRRC, and coordinator status from native core surfaces and returns provider/runtime worker results as `backendMissing` placeholders instead of asking Codex for model-worker state. Keep future pluggable model-provider work behind launch/result/runtime documents; do not let provider choice leak into status, prompt authority, scheduler policy, or durable `EpiphanyThreadState`. -- `epiphany-model-runtime` is the current provider-neutral executable boundary. It is built by the `epiphany-openai-runtime` crate for now and accepts `--provider openai-codex`; the old `epiphany-openai-runtime` binary, `--openai-runtime-bin`, and `openai-runtime` executor name survive only as compatibility aliases. Coordinator run mode, local wrapper run mode, and repo birth runner should call `--model-runtime-bin` plus `--model-provider`. Next provider work should replace OpenAI-named request/event/receipt documents with provider-neutral model documents and keep OpenAI/Codex as one adapter projection behind that boundary. +- `epiphany-model-runtime` is the current provider-neutral executable boundary. It is built by the `epiphany-openai-runtime` crate for now and accepts `--provider openai-codex`; the old `epiphany-openai-runtime` binary, `--openai-runtime-bin`, and `openai-runtime` executor name survive only as compatibility aliases. Coordinator run mode, local wrapper run mode, and repo birth runner should call `--model-runtime-bin` plus `--model-provider`. The typed request/event/receipt contract is now provider-neutral in `epiphany-model-adapter` as `epiphany.model_request.v0`, `epiphany.model_stream_event.v0`, `epiphany.model_receipt.v0`, and `epiphany.model_adapter_status.v0`; OpenAI/Codex documents are adapter evidence behind that boundary, not scheduler/status/state authority. - The active foundation directive is now `notes/codex-starvation-and-cultnet-liberation-plan.md`. The previous Codex app-server control-plane rebuild made Epiphany less rotten inside Codex, but that is not the destination. Epiphany must become a native CultCache/CultMesh/CultNet runtime while remaining an honest modified Codex-derived backend for subscription auth/model use. Codex should remain relatively vanilla and keep doing Codex things, including useful app-server and streaming bridge affordances, but it must not own Epiphany state, processes, prompts, scheduler decisions, or policy. The bridge handles interop; Codex and Epiphany do not get to rummage around in each other's organs. - `notes/epiphany-cultmesh-dreaming-roadmap.md` is the new concrete design for distributed Epiphany dreaming. The invariant is hard: private state stays local; public dreams are separately authored typed documents distributed through CultMesh/CultNet; foreign dreams are thought weather until a reviewed local adoption receipt digests them. The first code slice should be dream schemas plus a local CultMesh-backed store, not public fanout. - CultMesh is now the preferred Rust abstraction for that local store work. The compile-time Rust substrate is repo-contained: `vendor/cultcache-rs`, `vendor/cultnet-rs`, and `vendor/cultmesh-rs`. The old `E:\Projects\CultLib\crates\*` dependency body is dead in this checkout and must not be revived by accident. Vendored CultCache reads/writes `cultcache.store.v1`, so `state/ledgers.msgpack` and `epiphany-state status` are aligned again. The first integrations are deliberately small: status, Verse policy, global room policy, organ contract policy, native operator status, native operator snapshots, and local operator run intent/receipt round-trip through CultMesh. Use `cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-cultmesh-smoke`, `cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-cultmesh-status -- smoke --store .\.epiphany-smoke\cultmesh\operator-status.ccmp --runtime-id epiphany-cultmesh-status-smoke`, `cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-operator-snapshot -- smoke --store .\.epiphany-smoke\cultmesh\operator-snapshots.ccmp --runtime-id epiphany-operator-snapshot-smoke --snapshot-id smoke-status`, and `cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-operator-run -- smoke --store .\.epiphany-smoke\cultmesh\operator-runs.ccmp --runtime-id epiphany-operator-run-smoke --run-id smoke-run` for the focused proofs. Future local dream/status/Verse work should start from CultMesh, not raw CultNet, unless the task is polishing the CultMesh internals themselves. Preserve the three Verse tiers: `epiphany-internal` for private sub-agent typed state, `gamecult-local` for trusted LAN/Yggdrasil-tunnel GameCult sharing, and `epiphany-global` for untrusted public dreams plus topic-specific threaded public rooms for Face posts. diff --git a/schemas/cultnet/epiphany.model-adapter-status.schema.json b/schemas/cultnet/epiphany.model-adapter-status.schema.json new file mode 100644 index 00000000..7c8a9dbc --- /dev/null +++ b/schemas/cultnet/epiphany.model-adapter-status.schema.json @@ -0,0 +1,16 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://gamecult.dev/epiphany/cultnet/epiphany.model-adapter-status.schema.json", + "title": "Epiphany Model Adapter Status", + "type": "object", + "required": ["schema_id", "adapter_id", "provider", "streaming_supported", "provider_transport_attached"], + "properties": { + "schema_id": { "const": "epiphany.model_adapter_status.v0" }, + "adapter_id": { "type": "string" }, + "provider": { "type": "string" }, + "default_model": { "type": ["string", "null"] }, + "streaming_supported": { "type": "boolean" }, + "provider_transport_attached": { "type": "boolean" } + }, + "additionalProperties": false +} diff --git a/schemas/cultnet/epiphany.model-receipt.schema.json b/schemas/cultnet/epiphany.model-receipt.schema.json new file mode 100644 index 00000000..314f1094 --- /dev/null +++ b/schemas/cultnet/epiphany.model-receipt.schema.json @@ -0,0 +1,19 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://gamecult.dev/epiphany/cultnet/epiphany.model-receipt.schema.json", + "title": "Epiphany Model Receipt", + "type": "object", + "required": ["schema_id", "request_id", "provider", "model"], + "properties": { + "schema_id": { "const": "epiphany.model_receipt.v0" }, + "request_id": { "type": "string" }, + "provider": { "type": "string" }, + "model": { "type": "string" }, + "provider_response_id": { "type": ["string", "null"] }, + "input_tokens": { "type": ["integer", "null"], "minimum": 0 }, + "output_tokens": { "type": ["integer", "null"], "minimum": 0 }, + "reasoning_output_tokens": { "type": ["integer", "null"], "minimum": 0 }, + "transport": { "type": ["string", "null"] } + }, + "additionalProperties": false +} diff --git a/schemas/cultnet/epiphany.model-request.schema.json b/schemas/cultnet/epiphany.model-request.schema.json new file mode 100644 index 00000000..ebd1a697 --- /dev/null +++ b/schemas/cultnet/epiphany.model-request.schema.json @@ -0,0 +1,72 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://gamecult.dev/epiphany/cultnet/epiphany.model-request.schema.json", + "title": "Epiphany Model Request", + "type": "object", + "required": ["schema_id", "request_id", "conversation_id", "provider", "model", "instructions", "input"], + "properties": { + "schema_id": { "const": "epiphany.model_request.v0" }, + "request_id": { "type": "string" }, + "conversation_id": { "type": "string" }, + "provider": { "type": "string" }, + "model": { "type": "string" }, + "instructions": { "type": "string" }, + "input": { + "type": "array", + "items": { "$ref": "#/$defs/input_item" } + }, + "reasoning_effort": { "type": ["string", "null"] }, + "reasoning_summary": { "type": ["string", "null"] }, + "service_tier": { "type": ["string", "null"] }, + "output_contract_id": { "type": ["string", "null"] } + }, + "additionalProperties": false, + "$defs": { + "input_item": { + "oneOf": [ + { + "type": "object", + "required": ["UserText"], + "properties": { + "UserText": { + "type": "object", + "required": ["text"], + "properties": { "text": { "type": "string" } }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": ["AssistantText"], + "properties": { + "AssistantText": { + "type": "object", + "required": ["text"], + "properties": { "text": { "type": "string" } }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": ["ToolResult"], + "properties": { + "ToolResult": { + "type": "object", + "required": ["call_id", "output"], + "properties": { + "call_id": { "type": "string" }, + "output": { "type": "string" } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + ] + } + } +} diff --git a/schemas/cultnet/epiphany.model-stream-event.schema.json b/schemas/cultnet/epiphany.model-stream-event.schema.json new file mode 100644 index 00000000..0ab9e1b5 --- /dev/null +++ b/schemas/cultnet/epiphany.model-stream-event.schema.json @@ -0,0 +1,94 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://gamecult.dev/epiphany/cultnet/epiphany.model-stream-event.schema.json", + "title": "Epiphany Model Stream Event", + "type": "object", + "required": ["schema_id", "request_id", "provider", "sequence", "payload"], + "properties": { + "schema_id": { "const": "epiphany.model_stream_event.v0" }, + "request_id": { "type": "string" }, + "provider": { "type": "string" }, + "sequence": { "type": "integer", "minimum": 0 }, + "payload": { + "oneOf": [ + { "$ref": "#/$defs/text_delta" }, + { "$ref": "#/$defs/reasoning_delta" }, + { "$ref": "#/$defs/tool_call" }, + { "$ref": "#/$defs/completed" }, + { "$ref": "#/$defs/failed" } + ] + } + }, + "additionalProperties": false, + "$defs": { + "text_delta": { + "type": "object", + "required": ["TextDelta"], + "properties": { + "TextDelta": { + "type": "object", + "required": ["text"], + "properties": { "text": { "type": "string" } }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + "reasoning_delta": { + "type": "object", + "required": ["ReasoningDelta"], + "properties": { + "ReasoningDelta": { + "type": "object", + "required": ["text"], + "properties": { "text": { "type": "string" } }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + "tool_call": { + "type": "object", + "required": ["ToolCall"], + "properties": { + "ToolCall": { + "type": "object", + "required": ["call_id", "name", "arguments"], + "properties": { + "call_id": { "type": "string" }, + "name": { "type": "string" }, + "arguments": { "type": "string" } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + "completed": { + "type": "object", + "required": ["Completed"], + "properties": { + "Completed": { + "type": "object", + "required": ["receipt"], + "properties": { "receipt": { "$ref": "epiphany.model-receipt.schema.json" } }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + "failed": { + "type": "object", + "required": ["Failed"], + "properties": { + "Failed": { + "type": "object", + "required": ["message"], + "properties": { "message": { "type": "string" } }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + } +} diff --git a/schemas/cultnet/index.json b/schemas/cultnet/index.json index abd7a9b9..591a0d66 100644 --- a/schemas/cultnet/index.json +++ b/schemas/cultnet/index.json @@ -56,6 +56,50 @@ "title": "Epiphany Runtime Event", "path": "epiphany.runtime.event.schema.json" }, + { + "schemaId": "https://gamecult.dev/epiphany/cultnet/epiphany.model-adapter-status.schema.json", + "kind": "document_payload", + "wireContracts": [ + "cultnet.schema.v0" + ], + "schemaVersion": "epiphany.model_adapter_status.v0", + "documentType": "epiphany.model_adapter_status.v0", + "title": "Epiphany Model Adapter Status", + "path": "epiphany.model-adapter-status.schema.json" + }, + { + "schemaId": "https://gamecult.dev/epiphany/cultnet/epiphany.model-request.schema.json", + "kind": "document_payload", + "wireContracts": [ + "cultnet.schema.v0" + ], + "schemaVersion": "epiphany.model_request.v0", + "documentType": "epiphany.model_request.v0", + "title": "Epiphany Model Request", + "path": "epiphany.model-request.schema.json" + }, + { + "schemaId": "https://gamecult.dev/epiphany/cultnet/epiphany.model-stream-event.schema.json", + "kind": "document_payload", + "wireContracts": [ + "cultnet.schema.v0" + ], + "schemaVersion": "epiphany.model_stream_event.v0", + "documentType": "epiphany.model_stream_event.v0", + "title": "Epiphany Model Stream Event", + "path": "epiphany.model-stream-event.schema.json" + }, + { + "schemaId": "https://gamecult.dev/epiphany/cultnet/epiphany.model-receipt.schema.json", + "kind": "document_payload", + "wireContracts": [ + "cultnet.schema.v0" + ], + "schemaVersion": "epiphany.model_receipt.v0", + "documentType": "epiphany.model_receipt.v0", + "title": "Epiphany Model Receipt", + "path": "epiphany.model-receipt.schema.json" + }, { "schemaId": "https://gamecult.dev/epiphany/cultnet/epiphany.openai-adapter-status.schema.json", "kind": "document_payload", diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index 5673dd09..9dc70718 100644 Binary files a/state/ledgers.msgpack and b/state/ledgers.msgpack differ diff --git a/state/map.yaml b/state/map.yaml index 93fea753..353eea6b 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -515,4 +515,14 @@ current_status: uses typed OpenAI request/event/receipt documents through the Codex auth reliquary. It does move provider selection out of scheduler/status/state surfaces and into one runtime executable boundary. - next_action: Continue Codex starvation and CultNet liberation by moving coordinator plan/run outputs into typed CultNet receipts and by replacing OpenAI-specific request/event/receipt document names with provider-neutral model request/event/receipt documents plus OpenAI/Codex adapter projection behind the runtime boundary. + The provider-neutral model document seam is now landed: + `epiphany-model-adapter` owns `epiphany.model_request.v0`, + `epiphany.model_stream_event.v0`, `epiphany.model_receipt.v0`, and + `epiphany.model_adapter_status.v0`; runtime-spine advertises those as the + coordinator/model contract; and OpenAI request/event/receipt/status + documents are read-only adapter evidence behind that boundary. The current + `epiphany-model-runtime` still executes through the Codex/OpenAI provider, + but model turns and worker launches now enter through provider-neutral + requests, store provider-neutral events/receipts, and mirror OpenAI docs + only as transport proof. + next_action: Continue Codex starvation and CultNet liberation by moving coordinator plan/run outputs into typed CultNet receipts, then make the next provider adapter implement the `epiphany.model_*` contract without teaching scheduler/status/state surfaces provider-specific law.