Skip to main content

cookie_agent_protocol/
producer.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use crate::{GoalId, InvocationId, ProducerId, SessionId};
5
6/// Stable identity used with session + idempotency key for durable deduplication.
7/// Plugin connection authorization is runtime-only; the engine derives `plugin`
8/// from the authenticated configured plugin name, never from send parameters.
9/// The transport supplies name + connection epoch for live authority separately;
10/// the epoch is never part of this durable owner or the deduplication key.
11/// GoalControl identifies engine-authored lifecycle steering, not a continuation
12/// reminder; its accepted messages survive goal-controller teardown.
13/// Agent identifies an in-tree agent mail sender; the session identity is
14/// engine-derived from the executing tool context, never from model arguments.
15/// The owner is durable and participates in `(session, owner, key)` dedup.
16#[derive(Clone, Debug, Deserialize, Eq, Hash, JsonSchema, PartialEq, Serialize)]
17#[serde(tag = "type", rename_all = "snake_case", deny_unknown_fields)]
18pub enum ProducerOwner {
19    Plugin { plugin: String },
20    Delegation { invocation_id: InvocationId },
21    Goal { goal_id: GoalId },
22    GoalControl { goal_id: GoalId },
23    Agent { session_id: SessionId },
24}
25
26/// Per-send mode. Queue remains accepted-but-deferred during an active run;
27/// steer joins the next safe request without interrupting an in-flight request.
28#[derive(Clone, Copy, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
29#[serde(rename_all = "snake_case")]
30pub enum ProducerDeliveryMode {
31    Steer,
32    Queue,
33}
34
35/// Read-only runtime record. Never persist or restore a registration ID.
36/// A fresh registration is required on each process start, even for retries.
37#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
38#[serde(deny_unknown_fields)]
39pub struct ProducerRegistration {
40    pub producer_id: ProducerId,
41    pub producer_owner: ProducerOwner,
42    pub session_id: SessionId,
43    pub age_ms: u64,
44}
45
46#[derive(Clone, Copy, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
47#[serde(rename_all = "snake_case")]
48pub enum PluginRecoveryStatus {
49    Starting,
50    Ready,
51    Failed,
52    Disabled,
53}
54
55/// Runtime startup readiness, not a durable producer record or recovery blob.
56/// Failed/disabled means external work is unknown, not that work is complete.
57#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
58#[serde(deny_unknown_fields)]
59pub struct PluginRecoveryState {
60    pub plugin: String,
61    pub status: PluginRecoveryStatus,
62}