///|
///|
/// Stable identifier for a single Run. Supplied by the host in the `Start`
/// input and carried through every state.
#derive(Eq, Hash, Debug)
pub(all) struct RunId {
value : String
}
///|
pub extend RunId with Eq::{not_equal, equal}
///|
pub extend RunId with Hash::{hash, hash_combine}
///|
pub extend RunId with Debug::{to_repr}
///|
pub fn RunId::checked(value : String) -> Result[RunId, String] {
if value == "" {
Err("RunId must be non-empty")
} else {
Ok({ value, })
}
}
///|
pub fn RunId::unchecked(value : String) -> RunId {
{ value, }
}
///|
pub fn RunId::to_string(self : RunId) -> String {
self.value
}
///|
pub extend RunId with Show::{output}
///|
pub impl Show for RunId with fn to_string(self : RunId) -> String {
"RunId(\{self.value})"
}
///|
/// Identifier for a single turn within a Run. A Run may contain multiple
/// turns (initial prompt + follow-ups); turns never outlive their Run.
/// follow_up allocates a new TurnId under the same RunId.
#derive(Eq, Hash, Debug)
pub(all) struct TurnId {
value : String
}
///|
pub extend TurnId with Eq::{not_equal, equal}
///|
pub extend TurnId with Hash::{hash, hash_combine}
///|
pub extend TurnId with Debug::{to_repr}
///|
pub fn TurnId::checked(value : String) -> Result[TurnId, String] {
if value == "" {
Err("TurnId must be non-empty")
} else {
Ok({ value, })
}
}
///|
pub fn TurnId::unchecked(value : String) -> TurnId {
{ value, }
}
///|
pub fn TurnId::to_string(self : TurnId) -> String {
self.value
}
///|
pub extend TurnId with Show::{output}
///|
pub impl Show for TurnId with fn to_string(self : TurnId) -> String {
self.value
}
///|
/// Stable identifier for a product session. The Kernel never opens or
/// materializes session storage; it carries this identity through effects,
/// journal entries, and committed event envelopes.
#derive(Eq, Hash, Debug)
pub(all) struct SessionId {
value : String
}
///|
pub extend SessionId with Eq::{not_equal, equal}
///|
pub extend SessionId with Hash::{hash, hash_combine}
///|
pub extend SessionId with Debug::{to_repr}
///|
pub fn SessionId::checked(value : String) -> Result[SessionId, String] {
if value == "" {
Err("SessionId must be non-empty")
} else {
Ok({ value, })
}
}
///|
pub fn SessionId::unchecked(value : String) -> SessionId {
{ value, }
}
///|
pub fn SessionId::to_string(self : SessionId) -> String {
self.value
}
///|
/// Identifier for a single declared Effect. Monotonic per Run. Each completion
/// input must correlate to a pending effect with this id; a mismatch is
/// `InvariantViolation::StaleCorrelation`.
#derive(Eq, Hash, Debug)
pub(all) struct EffectId {
value : Int32
}
///|
pub extend EffectId with Eq::{not_equal, equal}
///|
pub extend EffectId with Hash::{hash, hash_combine}
///|
pub extend EffectId with Debug::{to_repr}
///|
pub fn EffectId::first() -> EffectId {
{ value: 1, }
}
///|
pub fn EffectId::next(self : EffectId) -> EffectId {
{ value: @proof_identity.next_monotonic_id(self.value), }
}
///|
pub fn EffectId::to_int(self : EffectId) -> Int32 {
self.value
}
///|
pub extend EffectId with Show::{to_string, output}
///|
pub impl Show for EffectId with fn to_string(self : EffectId) -> String {
"EffectId(\{self.value})"
}
///|
#derive(Eq, Debug)
pub(all) struct CatalogVersion {
value : Int32
}
///|
pub extend CatalogVersion with Eq::{not_equal, equal}
///|
pub extend CatalogVersion with Debug::{to_repr}
///|
pub fn CatalogVersion::CatalogVersion(value : Int32) -> CatalogVersion {
{ value, }
}
///|
pub fn CatalogVersion::to_int(self : CatalogVersion) -> Int32 {
self.value
}
///|
pub extend CatalogVersion with Show::{to_string, output}
///|
pub impl Show for CatalogVersion with fn to_string(self : CatalogVersion) -> String {
"CatalogVersion(\{self.value})"
}
///|
/// Why a Run was cancelled.
#derive(Eq, Debug)
pub(all) enum CancelReason {
/// Host explicitly cancelled.
HostRequested(detail~ : String?)
/// Adapter/host observed the deadline.
DeadlineReached
}
///|
pub extend CancelReason with Eq::{not_equal, equal}
///|
pub extend CancelReason with Debug::{to_repr}
///|
fn detail_or_empty(detail : String?) -> String {
match detail {
Some(s) => s
None => ""
}
}
///|
pub extend CancelReason with Show::{to_string, output}
///|
pub impl Show for CancelReason with fn to_string(self : CancelReason) -> String {
match self {
HostRequested(detail~) => "HostRequested(\{detail_or_empty(detail)})"
DeadlineReached => "DeadlineReached"
}
}
///|
/// What an adapter reports after a `CancelOutstanding` effect. The reducer
/// never waits for this.
#derive(Eq, Debug)
pub(all) enum CancelDisposition {
/// Cancel signal propagated; execution may still be running.
Propagated
/// Cancellation completed and the executor confirms work has stopped.
/// This says nothing about rollback of side effects already performed.
Stopped
/// Cancel not propagated; only stops the reducer waiting.
NotPropagated
/// Effect already settled before cancel arrived.
AlreadySettled
}
///|
pub extend CancelDisposition with Eq::{not_equal, equal}
///|
pub extend CancelDisposition with Debug::{to_repr}
///|
pub extend CancelDisposition with Show::{to_string, output}
///|
pub impl Show for CancelDisposition with fn to_string(self : CancelDisposition) -> String {
match self {
Propagated => "Propagated"
Stopped => "Stopped"
NotPropagated => "NotPropagated"
AlreadySettled => "AlreadySettled"
}
}
///|
/// Invocation identity for a single model-side call (`ModelPort::chat` /
/// `ModelPort::compact`, and their `Runtime` correspondences). Constructed by
/// posoco at the effect-interpretation layer and passed down unchanged; ports
/// and hosts MUST treat it as read-only.
///
/// This is the canonical answer to "which session/run is this call serving":
/// adapters that key behaviour on session identity (continuity, telemetry,
/// cost attribution, per-session policy) read it from here instead of
/// smuggling it through messages or config.
///
/// Invariants:
/// - `session_id` / `run_id` always identify the Run that issued the call,
/// including `compact` (compact is host-driven but still scoped to a Run).
/// - `effect_id` is `Some` iff the call executes a reducer-allocated
/// `CallModel` effect; it is `None` for `compact`, which is not an effect.
/// Hosts that propagate cancellation key in-flight model calls by this id,
/// mirroring the tool side's `EffectContext.effect_id`.
/// - `pressure` is `Some` only where posoco has a reading worth sharing
/// (the compact path); ports treat it as advisory read-only input.
#derive(Eq, Debug)
pub(all) struct InvocationScope {
session_id : SessionId
run_id : RunId
effect_id : EffectId?
pressure : ContextPressure?
}
///|
pub extend InvocationScope with Eq::{not_equal, equal}
///|
pub extend InvocationScope with Debug::{to_repr}