objectiveai_sdk/agent/
continuation.rs1use base64::Engine;
2use schemars::JsonSchema;
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
11#[serde(untagged)]
12#[schemars(rename = "agent.Continuation")]
13pub enum Continuation {
14 #[schemars(title = "Openrouter")]
15 Openrouter(super::openrouter::Continuation),
16 #[schemars(title = "ClaudeAgentSdk")]
17 ClaudeAgentSdk(super::claude_agent_sdk::Continuation),
18 #[schemars(title = "CodexSdk")]
19 CodexSdk(super::codex_sdk::Continuation),
20 #[schemars(title = "Mock")]
21 Mock(super::mock::Continuation),
22}
23
24impl From<super::openrouter::Continuation> for Continuation {
25 fn from(inner: super::openrouter::Continuation) -> Self {
26 Self::Openrouter(inner)
27 }
28}
29
30impl From<super::claude_agent_sdk::Continuation> for Continuation {
31 fn from(inner: super::claude_agent_sdk::Continuation) -> Self {
32 Self::ClaudeAgentSdk(inner)
33 }
34}
35
36impl From<super::codex_sdk::Continuation> for Continuation {
37 fn from(inner: super::codex_sdk::Continuation) -> Self {
38 Self::CodexSdk(inner)
39 }
40}
41
42impl From<super::mock::Continuation> for Continuation {
43 fn from(inner: super::mock::Continuation) -> Self {
44 Self::Mock(inner)
45 }
46}
47
48impl Continuation {
49 pub fn mcp_sessions(&self) -> &indexmap::IndexMap<String, String> {
51 match self {
52 Self::Openrouter(c) => &c.mcp_sessions,
53 Self::ClaudeAgentSdk(c) => &c.mcp_sessions,
54 Self::CodexSdk(c) => &c.mcp_sessions,
55 Self::Mock(c) => &c.mcp_sessions,
56 }
57 }
58
59 pub fn agent_instance_hierarchy(&self) -> &str {
64 match self {
65 Self::Openrouter(c) => c.agent_instance_hierarchy.as_str(),
66 Self::ClaudeAgentSdk(c) => c.agent_instance_hierarchy.as_str(),
67 Self::CodexSdk(c) => c.agent_instance_hierarchy.as_str(),
68 Self::Mock(c) => c.agent_instance_hierarchy.as_str(),
69 }
70 }
71
72 pub fn set_agent_instance_hierarchy(&mut self, id: String) {
76 match self {
77 Self::Openrouter(c) => c.agent_instance_hierarchy = id,
78 Self::ClaudeAgentSdk(c) => c.agent_instance_hierarchy = id,
79 Self::CodexSdk(c) => c.agent_instance_hierarchy = id,
80 Self::Mock(c) => c.agent_instance_hierarchy = id,
81 }
82 }
83
84 pub fn upstream(&self) -> super::Upstream {
86 match self {
87 Self::Openrouter(_) => super::Upstream::Openrouter,
88 Self::ClaudeAgentSdk(_) => super::Upstream::ClaudeAgentSdk,
89 Self::CodexSdk(_) => super::Upstream::CodexSdk,
90 Self::Mock(_) => super::Upstream::Mock,
91 }
92 }
93
94 pub fn to_string(&self) -> String {
96 let json = serde_json::to_string(self).unwrap();
97 base64::engine::general_purpose::STANDARD.encode(json)
98 }
99
100 pub fn try_from_string(s: &str) -> Option<Self> {
102 let json = base64::engine::general_purpose::STANDARD.decode(s).ok()?;
103 let continuation = serde_json::from_slice(&json).ok()?;
104 Some(continuation)
105 }
106}