agentmux_srv/server/
jekt_entry.rs1use std::sync::Arc;
12
13use super::AppState;
14use crate::backend::reactive::types::{InjectionRequest, InjectionResponse};
15use crate::backend::storage::store::Store;
16
17pub(super) fn bus_inject_request(
20 state: &AppState,
21 from: &str,
22 target: &str,
23 message: &str,
24 priority: Option<String>,
25 audit_source_uid: String,
26) -> InjectionRequest {
27 let mut req = InjectionRequest {
28 target_agent: target.to_string(),
29 message: message.to_string(),
30 source_agent: Some(from.to_string()),
31 priority,
32 delivery_tier: Some("host".to_string()),
33 audit_source_uid,
34 ..Default::default()
35 };
36 prepare_host_entry(state, &mut req);
37 req
38}
39
40pub(super) fn prepare_host_entry(state: &AppState, req: &mut InjectionRequest) {
45 super::reactive::verify_jekt_signature(state, req);
46 super::reactive::resolve_transcript_request_tier_fields(&state.mstore, req);
47}
48
49pub(super) fn bus_fallback_allowed(req: &InjectionRequest, resp: &InjectionResponse) -> bool {
54 let not_found = resp.error.as_deref().is_some_and(|e| e.contains("not found"));
55 not_found && !req.is_transcript_request
56}
57
58pub(crate) fn inject_from_bridge(mut req: InjectionRequest, raw_text: &str) -> InjectionResponse {
63 resolve_bridge_fields(crate::backend::identity_spawn::row_store(), &mut req, raw_text);
64 crate::backend::reactive::handler::get_global_handler().inject_message(req)
65}
66
67pub(crate) fn resolve_bridge_fields(store: Option<&Arc<Store>>, req: &mut InjectionRequest, raw_text: &str) {
71 let enveloped = std::mem::replace(&mut req.message, raw_text.to_string());
72 resolve_with_store(store, req);
73 req.message = enveloped;
74}
75
76pub(crate) fn resolve_with_store(store: Option<&Arc<Store>>, req: &mut InjectionRequest) {
81 match store {
82 Some(store) => super::reactive::resolve_transcript_request_tier_fields(store, req),
83 None => {
84 if crate::backend::reactive::transcript_request::parse_transcript_request(&req.message).is_some() {
85 req.is_transcript_request = true;
86 req.transcript_request_escalate_forced = true;
87 }
88 }
89 }
90}
91
92#[cfg(test)]
93#[path = "tests/jekt_entry_tests.rs"]
94mod tests;