Skip to main content

vv_agent/sdk/client/
queries.rs

1use std::path::PathBuf;
2
3use super::super::session::AgentSessionRunRequest;
4use super::super::types::{query_text_from_run, AgentDefinition, AgentSDKOptions};
5use super::AgentSDKClient;
6
7impl AgentSDKClient {
8    pub fn query(&self, prompt: impl Into<String>) -> Result<String, String> {
9        self.query_with_require_completed(prompt, true)
10    }
11
12    pub fn query_with_require_completed(
13        &self,
14        prompt: impl Into<String>,
15        require_completed: bool,
16    ) -> Result<String, String> {
17        let run = self.run(prompt)?;
18        query_text_from_run(run, require_completed, "Agent query failed")
19    }
20
21    pub fn query_with_request(
22        &self,
23        request: AgentSessionRunRequest,
24        require_completed: bool,
25    ) -> Result<String, String> {
26        let run = self.run_with_request(request)?;
27        query_text_from_run(run, require_completed, "Agent query failed")
28    }
29
30    pub fn query_with_agent_request(
31        &self,
32        definition: AgentDefinition,
33        request: AgentSessionRunRequest,
34        require_completed: bool,
35    ) -> Result<String, String> {
36        let run = self.run_with_agent_request(definition, request)?;
37        query_text_from_run(run, require_completed, "Agent query failed")
38    }
39
40    pub fn query_agent(
41        &self,
42        agent_name: impl AsRef<str>,
43        prompt: impl Into<String>,
44    ) -> Result<String, String> {
45        self.query_agent_with_require_completed(agent_name, prompt, true)
46    }
47
48    pub fn query_agent_with_require_completed(
49        &self,
50        agent_name: impl AsRef<str>,
51        prompt: impl Into<String>,
52        require_completed: bool,
53    ) -> Result<String, String> {
54        let run = self.run_agent(agent_name, prompt)?;
55        query_text_from_run(run, require_completed, "Agent query failed")
56    }
57
58    pub fn query_agent_with_request(
59        &self,
60        agent_name: impl AsRef<str>,
61        request: AgentSessionRunRequest,
62        require_completed: bool,
63    ) -> Result<String, String> {
64        let run = self.run_agent_with_request(agent_name, request)?;
65        query_text_from_run(run, require_completed, "Agent query failed")
66    }
67
68    pub fn query_agent_in_workspace(
69        &self,
70        agent_name: impl AsRef<str>,
71        prompt: impl Into<String>,
72        workspace: impl Into<PathBuf>,
73    ) -> Result<String, String> {
74        self.query_agent_in_workspace_with_require_completed(agent_name, prompt, workspace, true)
75    }
76
77    pub fn query_agent_in_workspace_with_require_completed(
78        &self,
79        agent_name: impl AsRef<str>,
80        prompt: impl Into<String>,
81        workspace: impl Into<PathBuf>,
82        require_completed: bool,
83    ) -> Result<String, String> {
84        let run = self.run_agent_in_workspace(agent_name, prompt, workspace)?;
85        query_text_from_run(run, require_completed, "Agent query failed")
86    }
87
88    pub fn query_in_workspace(
89        &self,
90        prompt: impl Into<String>,
91        workspace: impl Into<PathBuf>,
92    ) -> Result<String, String> {
93        self.query_in_workspace_with_require_completed(prompt, workspace, true)
94    }
95
96    pub fn query_in_workspace_with_require_completed(
97        &self,
98        prompt: impl Into<String>,
99        workspace: impl Into<PathBuf>,
100        require_completed: bool,
101    ) -> Result<String, String> {
102        let run = self.run_in_workspace(prompt, workspace)?;
103        query_text_from_run(run, require_completed, "Agent query failed")
104    }
105}
106
107pub fn query(client: &AgentSDKClient, prompt: impl Into<String>) -> Result<String, String> {
108    client.query(prompt)
109}
110
111pub fn query_with_options_and_agent(
112    options: AgentSDKOptions,
113    definition: AgentDefinition,
114    prompt: impl Into<String>,
115) -> Result<String, String> {
116    query_with_options_and_agent_with_require_completed(options, definition, prompt, true)
117}
118
119pub fn query_with_options_and_agent_with_require_completed(
120    options: AgentSDKOptions,
121    definition: AgentDefinition,
122    prompt: impl Into<String>,
123    require_completed: bool,
124) -> Result<String, String> {
125    let run = AgentSDKClient::new(options).run_with_agent(definition, prompt)?;
126    query_text_from_run(run, require_completed, "Agent query failed")
127}
128
129pub fn query_with_options_and_agent_request(
130    options: AgentSDKOptions,
131    definition: AgentDefinition,
132    request: AgentSessionRunRequest,
133) -> Result<String, String> {
134    query_with_options_and_agent_request_with_require_completed(options, definition, request, true)
135}
136
137pub fn query_with_options_and_agent_request_with_require_completed(
138    options: AgentSDKOptions,
139    definition: AgentDefinition,
140    request: AgentSessionRunRequest,
141    require_completed: bool,
142) -> Result<String, String> {
143    let run = AgentSDKClient::new(options).run_with_agent_request(definition, request)?;
144    query_text_from_run(run, require_completed, "Agent query failed")
145}
146
147pub fn query_with_options_and_agent_in_workspace(
148    options: AgentSDKOptions,
149    definition: AgentDefinition,
150    prompt: impl Into<String>,
151    workspace: impl Into<PathBuf>,
152) -> Result<String, String> {
153    query_with_options_and_agent_in_workspace_with_require_completed(
154        options, definition, prompt, workspace, true,
155    )
156}
157
158pub fn query_with_options_and_agent_in_workspace_with_require_completed(
159    options: AgentSDKOptions,
160    definition: AgentDefinition,
161    prompt: impl Into<String>,
162    workspace: impl Into<PathBuf>,
163    require_completed: bool,
164) -> Result<String, String> {
165    let run =
166        AgentSDKClient::new(options).run_with_agent_in_workspace(definition, prompt, workspace)?;
167    query_text_from_run(run, require_completed, "Agent query failed")
168}