meerkat_runtime/
ingress_types.rs1use meerkat_core::lifecycle::RuntimeExecutionKind;
10use meerkat_core::lifecycle::run_primitive::{
11 ConversationAppend, ConversationContextAppend, PeerResponseTerminalApplyIntent,
12 RunApplyBoundary,
13};
14use meerkat_core::types::HandlingMode;
15use serde::{Deserialize, Serialize};
16
17use crate::identifiers::{InputKind, KindId};
18
19#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
24pub struct ContentShape(InputKind);
25
26impl ContentShape {
27 pub const fn from_kind(kind: InputKind) -> Self {
28 Self(kind)
29 }
30
31 pub const fn from_kind_id(kind_id: KindId) -> Self {
32 Self(kind_id.kind())
33 }
34
35 pub const fn kind(self) -> InputKind {
36 self.0
37 }
38
39 pub fn as_str(self) -> &'static str {
40 self.0.as_str()
41 }
42}
43
44impl From<InputKind> for ContentShape {
45 fn from(kind: InputKind) -> Self {
46 Self::from_kind(kind)
47 }
48}
49
50impl From<KindId> for ContentShape {
51 fn from(kind_id: KindId) -> Self {
52 Self::from_kind_id(kind_id)
53 }
54}
55
56impl std::fmt::Display for ContentShape {
57 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
58 f.write_str(self.as_str())
59 }
60}
61
62#[derive(Debug, Clone, PartialEq, Eq, Hash)]
64pub struct ReservationKey(pub String);
65
66#[derive(Debug, Clone, PartialEq, Eq, Hash)]
68pub struct RequestId(pub String);
69
70#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
77pub struct RuntimeInputSemantics {
78 pub(crate) boundary: RunApplyBoundary,
79 pub(crate) execution_kind: RuntimeExecutionKind,
80 pub(crate) execution_handling_mode: Option<HandlingMode>,
81 pub(crate) peer_response_terminal_apply_intent: Option<PeerResponseTerminalApplyIntent>,
82 #[serde(default)]
87 pub(crate) live_interrupt_required: bool,
88}
89
90#[derive(Debug, Clone, Default, PartialEq)]
99pub struct RuntimeInputProjection {
100 pub append: Option<ConversationAppend>,
101 pub additional_appends: Vec<ConversationAppend>,
102 pub context_append: Option<ConversationContextAppend>,
103 pub peer_response_terminal: Option<meerkat_core::PeerResponseTerminalFact>,
109}
110
111impl RuntimeInputSemantics {
112 pub fn try_from_generated_admission(
113 input: &crate::input::Input,
114 runtime_idle: bool,
115 ) -> Result<Self, String> {
116 crate::policy_table::generated_admission_projection_for_input(input, runtime_idle)
117 .map(|projection| projection.runtime_semantics)
118 }
119
120 pub fn boundary(&self) -> RunApplyBoundary {
121 self.boundary
122 }
123
124 pub fn execution_kind(&self) -> RuntimeExecutionKind {
125 self.execution_kind
126 }
127
128 pub fn peer_response_terminal_apply_intent(&self) -> Option<PeerResponseTerminalApplyIntent> {
129 self.peer_response_terminal_apply_intent
130 }
131}
132
133#[cfg(test)]
134mod tests {
135 use super::*;
136
137 #[test]
138 fn terminal_peer_response_keeps_content_turn_execution_kind() {
139 let semantics = crate::policy_table::generated_admission_projection_for_kind(
140 KindId::new(InputKind::PeerResponseTerminal),
141 false,
142 )
143 .expect("generated admission projection")
144 .runtime_semantics;
145
146 assert_eq!(semantics.boundary, RunApplyBoundary::RunStart);
147 assert_eq!(semantics.execution_kind, RuntimeExecutionKind::ContentTurn);
148 assert_eq!(semantics.execution_handling_mode, None);
149 assert_eq!(
150 semantics.peer_response_terminal_apply_intent,
151 Some(PeerResponseTerminalApplyIntent::AppendContextAndRun)
152 );
153 }
154
155 #[test]
156 fn continuation_is_the_only_resume_pending_execution_kind() {
157 let semantics = crate::policy_table::generated_admission_projection_for_kind(
158 KindId::new(InputKind::Continuation),
159 false,
160 )
161 .expect("generated admission projection")
162 .runtime_semantics;
163
164 assert_eq!(semantics.boundary, RunApplyBoundary::RunCheckpoint);
165 assert_eq!(
166 semantics.execution_kind,
167 RuntimeExecutionKind::ResumePending
168 );
169 assert_eq!(semantics.execution_handling_mode, None);
170 assert_eq!(semantics.peer_response_terminal_apply_intent, None);
171 }
172
173 #[test]
174 fn admitted_content_shape_is_closed_to_input_kind_contract() {
175 let shapes = [
176 (InputKind::Prompt, "prompt"),
177 (InputKind::PeerMessage, "peer_message"),
178 (InputKind::PeerRequest, "peer_request"),
179 (InputKind::PeerResponseProgress, "peer_response_progress"),
180 (InputKind::PeerResponseTerminal, "peer_response_terminal"),
181 (InputKind::FlowStep, "flow_step"),
182 (InputKind::ExternalEvent, "external_event"),
183 (InputKind::Continuation, "continuation"),
184 (InputKind::Operation, "operation"),
185 ];
186
187 for (kind, label) in shapes {
188 let shape = ContentShape::from_kind(kind);
189 assert_eq!(shape.kind(), kind);
190 assert_eq!(shape.as_str(), label);
191 assert_eq!(shape.to_string(), label);
192 }
193 }
194
195 #[test]
196 fn admitted_content_shape_source_has_no_string_newtype_contract() {
197 let source = std::fs::read_to_string(
198 std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
199 .join("src")
200 .join("ingress_types.rs"),
201 )
202 .expect("read ingress types source");
203
204 let forbidden = ["pub struct ContentShape", "(pub String)"].concat();
205 assert!(
206 !source.contains(&forbidden),
207 "runtime admitted-input ContentShape must not be a public arbitrary string newtype"
208 );
209 }
210}