Skip to main content

vv_agent/sdk/client/sessions/
base.rs

1use std::path::PathBuf;
2
3use crate::sdk::session::AgentSession;
4use crate::sdk::types::AgentDefinition;
5use crate::types::Metadata;
6
7use super::super::AgentSDKClient;
8use super::run::session_run_executor;
9
10pub fn create_agent_session(
11    client: &AgentSDKClient,
12    agent_name: impl Into<String>,
13    definition: AgentDefinition,
14) -> AgentSession {
15    create_agent_session_with_workspace(
16        client,
17        agent_name,
18        definition,
19        client.options.workspace.clone(),
20    )
21}
22
23pub fn create_agent_session_with_shared_state(
24    client: &AgentSDKClient,
25    agent_name: impl Into<String>,
26    definition: AgentDefinition,
27    shared_state: Metadata,
28) -> AgentSession {
29    create_agent_session_with_workspace_and_shared_state(
30        client,
31        agent_name,
32        definition,
33        client.options.workspace.clone(),
34        shared_state,
35    )
36}
37
38pub fn create_agent_session_with_workspace(
39    client: &AgentSDKClient,
40    agent_name: impl Into<String>,
41    definition: AgentDefinition,
42    workspace: impl Into<PathBuf>,
43) -> AgentSession {
44    create_agent_session_with_workspace_and_shared_state(
45        client,
46        agent_name,
47        definition,
48        workspace,
49        Metadata::new(),
50    )
51}
52
53pub fn create_agent_session_with_workspace_and_shared_state(
54    client: &AgentSDKClient,
55    agent_name: impl Into<String>,
56    definition: AgentDefinition,
57    workspace: impl Into<PathBuf>,
58    shared_state: Metadata,
59) -> AgentSession {
60    let definition = client.effective_definition(definition);
61    AgentSession::new_with_context_and_shared_state(
62        session_run_executor(client, &definition),
63        agent_name,
64        definition,
65        workspace,
66        shared_state,
67    )
68}
69
70pub fn create_agent_session_with_id(
71    client: &AgentSDKClient,
72    agent_name: impl Into<String>,
73    definition: AgentDefinition,
74    session_id: impl Into<String>,
75) -> AgentSession {
76    create_agent_session_with_id_and_workspace(
77        client,
78        agent_name,
79        definition,
80        session_id,
81        client.options.workspace.clone(),
82    )
83}
84
85pub fn create_agent_session_with_id_and_workspace(
86    client: &AgentSDKClient,
87    agent_name: impl Into<String>,
88    definition: AgentDefinition,
89    session_id: impl Into<String>,
90    workspace: impl Into<PathBuf>,
91) -> AgentSession {
92    create_agent_session_with_id_and_workspace_and_shared_state(
93        client,
94        agent_name,
95        definition,
96        session_id,
97        workspace,
98        Metadata::new(),
99    )
100}
101
102pub fn create_agent_session_with_id_and_workspace_and_shared_state(
103    client: &AgentSDKClient,
104    agent_name: impl Into<String>,
105    definition: AgentDefinition,
106    session_id: impl Into<String>,
107    workspace: impl Into<PathBuf>,
108    shared_state: Metadata,
109) -> AgentSession {
110    let definition = client.effective_definition(definition);
111    AgentSession::new_with_context_and_session_id_and_shared_state(
112        session_run_executor(client, &definition),
113        session_id,
114        agent_name,
115        definition,
116        workspace,
117        shared_state,
118    )
119}
120
121impl AgentSDKClient {
122    pub fn create_session(
123        &self,
124        agent_name: impl Into<String>,
125        definition: AgentDefinition,
126    ) -> AgentSession {
127        create_agent_session(self, agent_name, definition)
128    }
129
130    pub fn create_session_with_shared_state(
131        &self,
132        agent_name: impl Into<String>,
133        definition: AgentDefinition,
134        shared_state: Metadata,
135    ) -> AgentSession {
136        create_agent_session_with_shared_state(self, agent_name, definition, shared_state)
137    }
138
139    pub fn create_session_with_id(
140        &self,
141        agent_name: impl Into<String>,
142        definition: AgentDefinition,
143        session_id: impl Into<String>,
144    ) -> AgentSession {
145        create_agent_session_with_id(self, agent_name, definition, session_id)
146    }
147
148    pub fn create_session_with_workspace(
149        &self,
150        agent_name: impl Into<String>,
151        definition: AgentDefinition,
152        workspace: impl Into<PathBuf>,
153    ) -> AgentSession {
154        create_agent_session_with_workspace(self, agent_name, definition, workspace)
155    }
156
157    pub fn create_session_with_workspace_and_shared_state(
158        &self,
159        agent_name: impl Into<String>,
160        definition: AgentDefinition,
161        workspace: impl Into<PathBuf>,
162        shared_state: Metadata,
163    ) -> AgentSession {
164        create_agent_session_with_workspace_and_shared_state(
165            self,
166            agent_name,
167            definition,
168            workspace,
169            shared_state,
170        )
171    }
172
173    pub fn create_session_with_id_and_workspace(
174        &self,
175        agent_name: impl Into<String>,
176        definition: AgentDefinition,
177        session_id: impl Into<String>,
178        workspace: impl Into<PathBuf>,
179    ) -> AgentSession {
180        create_agent_session_with_id_and_workspace(
181            self, agent_name, definition, session_id, workspace,
182        )
183    }
184
185    pub fn create_session_with_id_workspace_and_shared_state(
186        &self,
187        agent_name: impl Into<String>,
188        definition: AgentDefinition,
189        session_id: impl Into<String>,
190        workspace: impl Into<PathBuf>,
191        shared_state: Metadata,
192    ) -> AgentSession {
193        create_agent_session_with_id_and_workspace_and_shared_state(
194            self,
195            agent_name,
196            definition,
197            session_id,
198            workspace,
199            shared_state,
200        )
201    }
202}