Skip to main content

github_copilot_sdk/generated/
rpc.rs

1//! Auto-generated typed JSON-RPC namespace — do not edit manually.
2//!
3//! Generated from `api.schema.json` by `scripts/codegen/rust.ts`. The
4//! [`ClientRpc`] and [`SessionRpc`] view structs let callers reach every
5//! protocol method through a typed namespace tree, so wire method names
6//! and request/response shapes live in exactly one place — this file.
7
8#![allow(missing_docs)]
9#![allow(clippy::too_many_arguments)]
10#![allow(deprecated)]
11#![allow(dead_code)]
12
13use super::api_types::{rpc_methods, *};
14use super::session_events::SessionMode;
15use crate::session::Session;
16use crate::{Client, Error};
17
18/// Typed view over the [`Client`]'s server-level RPC namespace.
19#[derive(Clone, Copy)]
20pub struct ClientRpc<'a> {
21    pub(crate) client: &'a Client,
22}
23
24impl<'a> ClientRpc<'a> {
25    /// `account.*` sub-namespace.
26    pub fn account(&self) -> ClientRpcAccount<'a> {
27        ClientRpcAccount {
28            client: self.client,
29        }
30    }
31
32    /// `agentRegistry.*` sub-namespace.
33    pub fn agent_registry(&self) -> ClientRpcAgentRegistry<'a> {
34        ClientRpcAgentRegistry {
35            client: self.client,
36        }
37    }
38
39    /// `agents.*` sub-namespace.
40    pub fn agents(&self) -> ClientRpcAgents<'a> {
41        ClientRpcAgents {
42            client: self.client,
43        }
44    }
45
46    /// `commands.*` sub-namespace.
47    pub fn commands(&self) -> ClientRpcCommands<'a> {
48        ClientRpcCommands {
49            client: self.client,
50        }
51    }
52
53    /// `extensions.*` sub-namespace.
54    pub fn extensions(&self) -> ClientRpcExtensions<'a> {
55        ClientRpcExtensions {
56            client: self.client,
57        }
58    }
59
60    /// `instructions.*` sub-namespace.
61    pub fn instructions(&self) -> ClientRpcInstructions<'a> {
62        ClientRpcInstructions {
63            client: self.client,
64        }
65    }
66
67    /// `llmInference.*` sub-namespace.
68    pub fn llm_inference(&self) -> ClientRpcLlmInference<'a> {
69        ClientRpcLlmInference {
70            client: self.client,
71        }
72    }
73
74    /// `managedSettings.*` sub-namespace.
75    pub fn managed_settings(&self) -> ClientRpcManagedSettings<'a> {
76        ClientRpcManagedSettings {
77            client: self.client,
78        }
79    }
80
81    /// `mcp.*` sub-namespace.
82    pub fn mcp(&self) -> ClientRpcMcp<'a> {
83        ClientRpcMcp {
84            client: self.client,
85        }
86    }
87
88    /// `models.*` sub-namespace.
89    pub fn models(&self) -> ClientRpcModels<'a> {
90        ClientRpcModels {
91            client: self.client,
92        }
93    }
94
95    /// `plugins.*` sub-namespace.
96    pub fn plugins(&self) -> ClientRpcPlugins<'a> {
97        ClientRpcPlugins {
98            client: self.client,
99        }
100    }
101
102    /// `runtime.*` sub-namespace.
103    pub fn runtime(&self) -> ClientRpcRuntime<'a> {
104        ClientRpcRuntime {
105            client: self.client,
106        }
107    }
108
109    /// `secrets.*` sub-namespace.
110    pub fn secrets(&self) -> ClientRpcSecrets<'a> {
111        ClientRpcSecrets {
112            client: self.client,
113        }
114    }
115
116    /// `sessionFs.*` sub-namespace.
117    pub fn session_fs(&self) -> ClientRpcSessionFs<'a> {
118        ClientRpcSessionFs {
119            client: self.client,
120        }
121    }
122
123    /// `sessions.*` sub-namespace.
124    pub fn sessions(&self) -> ClientRpcSessions<'a> {
125        ClientRpcSessions {
126            client: self.client,
127        }
128    }
129
130    /// `skills.*` sub-namespace.
131    pub fn skills(&self) -> ClientRpcSkills<'a> {
132        ClientRpcSkills {
133            client: self.client,
134        }
135    }
136
137    /// `tools.*` sub-namespace.
138    pub fn tools(&self) -> ClientRpcTools<'a> {
139        ClientRpcTools {
140            client: self.client,
141        }
142    }
143
144    /// `user.*` sub-namespace.
145    pub fn user(&self) -> ClientRpcUser<'a> {
146        ClientRpcUser {
147            client: self.client,
148        }
149    }
150
151    /// Checks server responsiveness and returns protocol information.
152    ///
153    /// Wire method: `ping`.
154    ///
155    /// # Parameters
156    ///
157    /// * `params` - Optional message to echo back to the caller.
158    ///
159    /// # Returns
160    ///
161    /// Server liveness response, including the echoed message, current server timestamp, and protocol version.
162    ///
163    /// <div class="warning">
164    ///
165    /// **Experimental.** This API is part of an experimental wire-protocol surface
166    /// and may change or be removed in future SDK or CLI releases. Pin both the
167    /// SDK and CLI versions if your code depends on it.
168    ///
169    /// </div>
170    pub async fn ping(&self, params: PingRequest) -> Result<PingResult, Error> {
171        let wire_params = serde_json::to_value(params)?;
172        let _value = self
173            .client
174            .call(rpc_methods::PING, Some(wire_params))
175            .await?;
176        Ok(serde_json::from_value(_value)?)
177    }
178
179    /// Performs the SDK server connection handshake and validates the optional connection token. Marked internal because this is JSON-RPC transport plumbing invoked automatically by an SDK client's own `connect()` wrapper, not a user-facing method. Stays internal as long as the SDK client owns the handshake; would only become public if the SDK ever exposed the raw schema surface to consumers without a connection wrapper.
180    ///
181    /// Wire method: `connect`.
182    ///
183    /// # Parameters
184    ///
185    /// * `params` - Parameters for the `server.connect` handshake: an optional connection token and optional connection-level opt-ins (e.g. GitHub telemetry forwarding).
186    ///
187    /// # Returns
188    ///
189    /// Handshake result reporting the server's protocol version and package version on success.
190    ///
191    /// <div class="warning">
192    ///
193    /// **Experimental.** This API is part of an experimental wire-protocol surface
194    /// and may change or be removed in future SDK or CLI releases. Pin both the
195    /// SDK and CLI versions if your code depends on it.
196    ///
197    /// </div>
198    pub(crate) async fn connect(&self, params: ConnectRequest) -> Result<ConnectResult, Error> {
199        let wire_params = serde_json::to_value(params)?;
200        let _value = self
201            .client
202            .call(rpc_methods::CONNECT, Some(wire_params))
203            .await?;
204        Ok(serde_json::from_value(_value)?)
205    }
206
207    /// Registers the calling SDK client as the per-entrypoint extension launch provider. Call before creating any sessions. When omitted, the runtime temporarily falls back to its built-in Node launcher for backward compatibility.
208    ///
209    /// Wire method: `registerExtensionLaunchProvider`.
210    ///
211    /// <div class="warning">
212    ///
213    /// **Experimental.** This API is part of an experimental wire-protocol surface
214    /// and may change or be removed in future SDK or CLI releases. Pin both the
215    /// SDK and CLI versions if your code depends on it.
216    ///
217    /// </div>
218    pub async fn register_extension_launch_provider(&self) -> Result<(), Error> {
219        let wire_params = serde_json::json!({});
220        let _value = self
221            .client
222            .call(
223                rpc_methods::REGISTEREXTENSIONLAUNCHPROVIDER,
224                Some(wire_params),
225            )
226            .await?;
227        Ok(())
228    }
229}
230
231/// `account.*` RPCs.
232#[derive(Clone, Copy)]
233pub struct ClientRpcAccount<'a> {
234    pub(crate) client: &'a Client,
235}
236
237impl<'a> ClientRpcAccount<'a> {
238    /// Gets Copilot quota usage for the authenticated user or supplied GitHub token.
239    ///
240    /// Wire method: `account.getQuota`.
241    ///
242    /// # Returns
243    ///
244    /// Quota usage snapshots for the resolved user, keyed by quota type.
245    ///
246    /// <div class="warning">
247    ///
248    /// **Experimental.** This API is part of an experimental wire-protocol surface
249    /// and may change or be removed in future SDK or CLI releases. Pin both the
250    /// SDK and CLI versions if your code depends on it.
251    ///
252    /// </div>
253    pub async fn get_quota(&self) -> Result<AccountGetQuotaResult, Error> {
254        let wire_params = serde_json::json!({});
255        let _value = self
256            .client
257            .call(rpc_methods::ACCOUNT_GETQUOTA, Some(wire_params))
258            .await?;
259        Ok(serde_json::from_value(_value)?)
260    }
261
262    /// Gets Copilot quota usage for the authenticated user or supplied GitHub token.
263    ///
264    /// Wire method: `account.getQuota`.
265    ///
266    /// # Parameters
267    ///
268    /// * `params` - Optional GitHub token used to look up quota for a specific user instead of the global auth context.
269    ///
270    /// # Returns
271    ///
272    /// Quota usage snapshots for the resolved user, keyed by quota type.
273    ///
274    /// <div class="warning">
275    ///
276    /// **Experimental.** This API is part of an experimental wire-protocol surface
277    /// and may change or be removed in future SDK or CLI releases. Pin both the
278    /// SDK and CLI versions if your code depends on it.
279    ///
280    /// </div>
281    pub async fn get_quota_with_params(
282        &self,
283        params: AccountGetQuotaRequest,
284    ) -> Result<AccountGetQuotaResult, Error> {
285        let wire_params = serde_json::to_value(params)?;
286        let _value = self
287            .client
288            .call(rpc_methods::ACCOUNT_GETQUOTA, Some(wire_params))
289            .await?;
290        Ok(serde_json::from_value(_value)?)
291    }
292
293    /// Gets the currently active authentication credentials from the global auth manager.
294    ///
295    /// Wire method: `account.getCurrentAuth`.
296    ///
297    /// # Returns
298    ///
299    /// Current authentication state
300    ///
301    /// <div class="warning">
302    ///
303    /// **Experimental.** This API is part of an experimental wire-protocol surface
304    /// and may change or be removed in future SDK or CLI releases. Pin both the
305    /// SDK and CLI versions if your code depends on it.
306    ///
307    /// </div>
308    pub async fn get_current_auth(&self) -> Result<AccountGetCurrentAuthResult, Error> {
309        let wire_params = serde_json::json!({});
310        let _value = self
311            .client
312            .call(rpc_methods::ACCOUNT_GETCURRENTAUTH, Some(wire_params))
313            .await?;
314        Ok(serde_json::from_value(_value)?)
315    }
316
317    /// Gets all authenticated users available for account switching.
318    ///
319    /// Wire method: `account.getAllUsers`.
320    ///
321    /// # Returns
322    ///
323    /// List of all authenticated users
324    ///
325    /// <div class="warning">
326    ///
327    /// **Experimental.** This API is part of an experimental wire-protocol surface
328    /// and may change or be removed in future SDK or CLI releases. Pin both the
329    /// SDK and CLI versions if your code depends on it.
330    ///
331    /// </div>
332    pub async fn get_all_users(&self) -> Result<AccountGetAllUsersResult, Error> {
333        let wire_params = serde_json::json!({});
334        let _value = self
335            .client
336            .call(rpc_methods::ACCOUNT_GETALLUSERS, Some(wire_params))
337            .await?;
338        Ok(serde_json::from_value(_value)?)
339    }
340
341    /// Stores authentication credentials after successful login (e.g., device code flow).
342    ///
343    /// Wire method: `account.login`.
344    ///
345    /// # Parameters
346    ///
347    /// * `params` - Credentials to store after successful authentication
348    ///
349    /// # Returns
350    ///
351    /// Result of a successful login; throws on failure
352    ///
353    /// <div class="warning">
354    ///
355    /// **Experimental.** This API is part of an experimental wire-protocol surface
356    /// and may change or be removed in future SDK or CLI releases. Pin both the
357    /// SDK and CLI versions if your code depends on it.
358    ///
359    /// </div>
360    pub async fn login(&self, params: AccountLoginRequest) -> Result<AccountLoginResult, Error> {
361        let wire_params = serde_json::to_value(params)?;
362        let _value = self
363            .client
364            .call(rpc_methods::ACCOUNT_LOGIN, Some(wire_params))
365            .await?;
366        Ok(serde_json::from_value(_value)?)
367    }
368
369    /// Removes user authentication from keychain and persisted state.
370    ///
371    /// Wire method: `account.logout`.
372    ///
373    /// # Parameters
374    ///
375    /// * `params` - User to log out
376    ///
377    /// # Returns
378    ///
379    /// Logout result indicating if more users remain
380    ///
381    /// <div class="warning">
382    ///
383    /// **Experimental.** This API is part of an experimental wire-protocol surface
384    /// and may change or be removed in future SDK or CLI releases. Pin both the
385    /// SDK and CLI versions if your code depends on it.
386    ///
387    /// </div>
388    pub async fn logout(&self, params: AccountLogoutRequest) -> Result<AccountLogoutResult, Error> {
389        let wire_params = serde_json::to_value(params)?;
390        let _value = self
391            .client
392            .call(rpc_methods::ACCOUNT_LOGOUT, Some(wire_params))
393            .await?;
394        Ok(serde_json::from_value(_value)?)
395    }
396}
397
398/// `agentRegistry.*` RPCs.
399#[derive(Clone, Copy)]
400pub struct ClientRpcAgentRegistry<'a> {
401    pub(crate) client: &'a Client,
402}
403
404impl<'a> ClientRpcAgentRegistry<'a> {
405    /// Spawns a managed-server child with the supplied configuration and returns a discriminated-union result. The caller (typically the CLI controller) is responsible for attaching to the spawned child and sending any follow-up prompt. When the controller-local spawn gate is closed the server returns JSON-RPC MethodNotFound.
406    ///
407    /// Wire method: `agentRegistry.spawn`.
408    ///
409    /// # Parameters
410    ///
411    /// * `params` - Inputs to spawn a managed-server child via the controller's spawn delegate.
412    ///
413    /// # Returns
414    ///
415    /// Outcome of an agentRegistry.spawn call.
416    ///
417    /// <div class="warning">
418    ///
419    /// **Experimental.** This API is part of an experimental wire-protocol surface
420    /// and may change or be removed in future SDK or CLI releases. Pin both the
421    /// SDK and CLI versions if your code depends on it.
422    ///
423    /// </div>
424    pub async fn spawn(
425        &self,
426        params: AgentRegistrySpawnRequest,
427    ) -> Result<AgentRegistrySpawnResult, Error> {
428        let wire_params = serde_json::to_value(params)?;
429        let _value = self
430            .client
431            .call(rpc_methods::AGENTREGISTRY_SPAWN, Some(wire_params))
432            .await?;
433        Ok(serde_json::from_value(_value)?)
434    }
435}
436
437/// `agents.*` RPCs.
438#[derive(Clone, Copy)]
439pub struct ClientRpcAgents<'a> {
440    pub(crate) client: &'a Client,
441}
442
443impl<'a> ClientRpcAgents<'a> {
444    /// Discovers custom agents across user, project, plugin, and remote sources.
445    ///
446    /// Wire method: `agents.discover`.
447    ///
448    /// # Parameters
449    ///
450    /// * `params` - Optional project paths to include in agent discovery.
451    ///
452    /// # Returns
453    ///
454    /// Agents discovered across user, project, plugin, and remote sources.
455    ///
456    /// <div class="warning">
457    ///
458    /// **Experimental.** This API is part of an experimental wire-protocol surface
459    /// and may change or be removed in future SDK or CLI releases. Pin both the
460    /// SDK and CLI versions if your code depends on it.
461    ///
462    /// </div>
463    pub async fn discover(&self, params: AgentsDiscoverRequest) -> Result<ServerAgentList, Error> {
464        let wire_params = serde_json::to_value(params)?;
465        let _value = self
466            .client
467            .call(rpc_methods::AGENTS_DISCOVER, Some(wire_params))
468            .await?;
469        Ok(serde_json::from_value(_value)?)
470    }
471
472    /// Returns the canonical directories where a client may create custom agents that the runtime will recognize, including ones that do not exist yet. Project directories become active once created.
473    ///
474    /// Wire method: `agents.getDiscoveryPaths`.
475    ///
476    /// # Parameters
477    ///
478    /// * `params` - Optional project paths to include when enumerating agent discovery directories.
479    ///
480    /// # Returns
481    ///
482    /// Canonical locations where custom agents can be created so the runtime will recognize them.
483    ///
484    /// <div class="warning">
485    ///
486    /// **Experimental.** This API is part of an experimental wire-protocol surface
487    /// and may change or be removed in future SDK or CLI releases. Pin both the
488    /// SDK and CLI versions if your code depends on it.
489    ///
490    /// </div>
491    pub async fn get_discovery_paths(
492        &self,
493        params: AgentsGetDiscoveryPathsRequest,
494    ) -> Result<AgentDiscoveryPathList, Error> {
495        let wire_params = serde_json::to_value(params)?;
496        let _value = self
497            .client
498            .call(rpc_methods::AGENTS_GETDISCOVERYPATHS, Some(wire_params))
499            .await?;
500        Ok(serde_json::from_value(_value)?)
501    }
502}
503
504/// `commands.*` RPCs.
505#[derive(Clone, Copy)]
506pub struct ClientRpcCommands<'a> {
507    pub(crate) client: &'a Client,
508}
509
510impl<'a> ClientRpcCommands<'a> {
511    /// Lists the well-known built-in slash commands that work as the first message in a new session (e.g. /plan, /env), without requiring an active session. Commands that depend on session state, authentication, or a synced session are omitted.
512    ///
513    /// Wire method: `commands.list`.
514    ///
515    /// # Returns
516    ///
517    /// Slash commands available in the session, after applying any include/exclude filters.
518    ///
519    /// <div class="warning">
520    ///
521    /// **Experimental.** This API is part of an experimental wire-protocol surface
522    /// and may change or be removed in future SDK or CLI releases. Pin both the
523    /// SDK and CLI versions if your code depends on it.
524    ///
525    /// </div>
526    pub async fn list(&self) -> Result<CommandList, Error> {
527        let wire_params = serde_json::json!({});
528        let _value = self
529            .client
530            .call(rpc_methods::COMMANDS_LIST, Some(wire_params))
531            .await?;
532        Ok(serde_json::from_value(_value)?)
533    }
534}
535
536/// `extensions.*` RPCs.
537#[derive(Clone, Copy)]
538pub struct ClientRpcExtensions<'a> {
539    pub(crate) client: &'a Client,
540}
541
542impl<'a> ClientRpcExtensions<'a> {
543    /// Discovers user and enabled installed-plugin extensions from persisted Copilot home state, including enablement preferences. Launch-scoped additional plugins are not included.
544    ///
545    /// Wire method: `extensions.discover`.
546    ///
547    /// # Returns
548    ///
549    /// Extensions discovered from persisted Copilot home state and their effective loading mode. Launch-scoped additional plugins are not included.
550    ///
551    /// <div class="warning">
552    ///
553    /// **Experimental.** This API is part of an experimental wire-protocol surface
554    /// and may change or be removed in future SDK or CLI releases. Pin both the
555    /// SDK and CLI versions if your code depends on it.
556    ///
557    /// </div>
558    pub async fn discover(&self) -> Result<DiscoveredExtensions, Error> {
559        let wire_params = serde_json::json!({});
560        let _value = self
561            .client
562            .call(rpc_methods::EXTENSIONS_DISCOVER, Some(wire_params))
563            .await?;
564        Ok(serde_json::from_value(_value)?)
565    }
566
567    /// Persistently enables extension IDs for future sessions. Active sessions are unchanged; use session.extensions.enable to update them.
568    ///
569    /// Wire method: `extensions.enable`.
570    ///
571    /// # Parameters
572    ///
573    /// * `params` - Source-qualified extension identifiers to persistently enable for future sessions.
574    ///
575    /// <div class="warning">
576    ///
577    /// **Experimental.** This API is part of an experimental wire-protocol surface
578    /// and may change or be removed in future SDK or CLI releases. Pin both the
579    /// SDK and CLI versions if your code depends on it.
580    ///
581    /// </div>
582    pub async fn enable(&self, params: DiscoveredExtensionsEnableRequest) -> Result<(), Error> {
583        let wire_params = serde_json::to_value(params)?;
584        let _value = self
585            .client
586            .call(rpc_methods::EXTENSIONS_ENABLE, Some(wire_params))
587            .await?;
588        Ok(())
589    }
590
591    /// Persistently disables extension IDs for future sessions. Active sessions are unchanged; use session.extensions.disable to update them.
592    ///
593    /// Wire method: `extensions.disable`.
594    ///
595    /// # Parameters
596    ///
597    /// * `params` - Source-qualified extension identifiers to persistently disable for future sessions.
598    ///
599    /// <div class="warning">
600    ///
601    /// **Experimental.** This API is part of an experimental wire-protocol surface
602    /// and may change or be removed in future SDK or CLI releases. Pin both the
603    /// SDK and CLI versions if your code depends on it.
604    ///
605    /// </div>
606    pub async fn disable(&self, params: DiscoveredExtensionsDisableRequest) -> Result<(), Error> {
607        let wire_params = serde_json::to_value(params)?;
608        let _value = self
609            .client
610            .call(rpc_methods::EXTENSIONS_DISABLE, Some(wire_params))
611            .await?;
612        Ok(())
613    }
614}
615
616/// `instructions.*` RPCs.
617#[derive(Clone, Copy)]
618pub struct ClientRpcInstructions<'a> {
619    pub(crate) client: &'a Client,
620}
621
622impl<'a> ClientRpcInstructions<'a> {
623    /// Discovers instruction sources across user, repository, and plugin sources.
624    ///
625    /// Wire method: `instructions.discover`.
626    ///
627    /// # Parameters
628    ///
629    /// * `params` - Optional project paths to include in instruction discovery.
630    ///
631    /// # Returns
632    ///
633    /// Instruction sources discovered across user, repository, and plugin sources.
634    ///
635    /// <div class="warning">
636    ///
637    /// **Experimental.** This API is part of an experimental wire-protocol surface
638    /// and may change or be removed in future SDK or CLI releases. Pin both the
639    /// SDK and CLI versions if your code depends on it.
640    ///
641    /// </div>
642    pub async fn discover(
643        &self,
644        params: InstructionsDiscoverRequest,
645    ) -> Result<ServerInstructionSourceList, Error> {
646        let wire_params = serde_json::to_value(params)?;
647        let _value = self
648            .client
649            .call(rpc_methods::INSTRUCTIONS_DISCOVER, Some(wire_params))
650            .await?;
651        Ok(serde_json::from_value(_value)?)
652    }
653
654    /// Returns the canonical files and directories where a client may create custom instructions that the runtime will recognize, including ones that do not exist yet. Repository targets become active once created.
655    ///
656    /// Wire method: `instructions.getDiscoveryPaths`.
657    ///
658    /// # Parameters
659    ///
660    /// * `params` - Optional project paths to include when enumerating instruction discovery targets.
661    ///
662    /// # Returns
663    ///
664    /// Canonical files and directories where custom instructions can be created so the runtime will recognize them.
665    ///
666    /// <div class="warning">
667    ///
668    /// **Experimental.** This API is part of an experimental wire-protocol surface
669    /// and may change or be removed in future SDK or CLI releases. Pin both the
670    /// SDK and CLI versions if your code depends on it.
671    ///
672    /// </div>
673    pub async fn get_discovery_paths(
674        &self,
675        params: InstructionsGetDiscoveryPathsRequest,
676    ) -> Result<InstructionDiscoveryPathList, Error> {
677        let wire_params = serde_json::to_value(params)?;
678        let _value = self
679            .client
680            .call(
681                rpc_methods::INSTRUCTIONS_GETDISCOVERYPATHS,
682                Some(wire_params),
683            )
684            .await?;
685        Ok(serde_json::from_value(_value)?)
686    }
687}
688
689/// `llmInference.*` RPCs.
690#[derive(Clone, Copy)]
691pub struct ClientRpcLlmInference<'a> {
692    pub(crate) client: &'a Client,
693}
694
695impl<'a> ClientRpcLlmInference<'a> {
696    /// Registers an SDK client as the LLM inference callback provider.
697    ///
698    /// Wire method: `llmInference.setProvider`.
699    ///
700    /// # Returns
701    ///
702    /// Indicates whether the calling client was registered as the LLM inference provider.
703    ///
704    /// <div class="warning">
705    ///
706    /// **Experimental.** This API is part of an experimental wire-protocol surface
707    /// and may change or be removed in future SDK or CLI releases. Pin both the
708    /// SDK and CLI versions if your code depends on it.
709    ///
710    /// </div>
711    pub async fn set_provider(&self) -> Result<LlmInferenceSetProviderResult, Error> {
712        let wire_params = serde_json::json!({});
713        let _value = self
714            .client
715            .call(rpc_methods::LLMINFERENCE_SETPROVIDER, Some(wire_params))
716            .await?;
717        Ok(serde_json::from_value(_value)?)
718    }
719
720    /// Delivers the response head (status + headers) for an in-flight request, correlated by the requestId the runtime supplied in httpRequestStart. Must be called exactly once per request before any httpResponseChunk frames.
721    ///
722    /// Wire method: `llmInference.httpResponseStart`.
723    ///
724    /// # Parameters
725    ///
726    /// * `params` - Response head.
727    ///
728    /// # Returns
729    ///
730    /// Whether the start frame was accepted.
731    ///
732    /// <div class="warning">
733    ///
734    /// **Experimental.** This API is part of an experimental wire-protocol surface
735    /// and may change or be removed in future SDK or CLI releases. Pin both the
736    /// SDK and CLI versions if your code depends on it.
737    ///
738    /// </div>
739    pub async fn http_response_start(
740        &self,
741        params: LlmInferenceHttpResponseStartRequest,
742    ) -> Result<LlmInferenceHttpResponseStartResult, Error> {
743        let wire_params = serde_json::to_value(params)?;
744        let _value = self
745            .client
746            .call(
747                rpc_methods::LLMINFERENCE_HTTPRESPONSESTART,
748                Some(wire_params),
749            )
750            .await?;
751        Ok(serde_json::from_value(_value)?)
752    }
753
754    /// Delivers a body byte range (or a terminal transport error) for an in-flight response, correlated by requestId. Set `end` true on the last chunk. When `error` is set the response terminates with a transport-level failure and the runtime raises an APIConnectionError.
755    ///
756    /// Wire method: `llmInference.httpResponseChunk`.
757    ///
758    /// # Parameters
759    ///
760    /// * `params` - A response body chunk or terminal error.
761    ///
762    /// # Returns
763    ///
764    /// Whether the chunk was accepted.
765    ///
766    /// <div class="warning">
767    ///
768    /// **Experimental.** This API is part of an experimental wire-protocol surface
769    /// and may change or be removed in future SDK or CLI releases. Pin both the
770    /// SDK and CLI versions if your code depends on it.
771    ///
772    /// </div>
773    pub async fn http_response_chunk(
774        &self,
775        params: LlmInferenceHttpResponseChunkRequest,
776    ) -> Result<LlmInferenceHttpResponseChunkResult, Error> {
777        let wire_params = serde_json::to_value(params)?;
778        let _value = self
779            .client
780            .call(
781                rpc_methods::LLMINFERENCE_HTTPRESPONSECHUNK,
782                Some(wire_params),
783            )
784            .await?;
785        Ok(serde_json::from_value(_value)?)
786    }
787}
788
789/// `managedSettings.*` RPCs.
790#[derive(Clone, Copy)]
791pub struct ClientRpcManagedSettings<'a> {
792    pub(crate) client: &'a Client,
793}
794
795impl<'a> ClientRpcManagedSettings<'a> {
796    /// Discovers device-managed settings from production MDM and managed-file sources, validates them against the runtime-owned managed-settings schema, and returns the canonical JSON without requiring a session.
797    ///
798    /// Wire method: `managedSettings.read`.
799    ///
800    /// # Returns
801    ///
802    /// Validated device-managed settings discovered before a session exists.
803    ///
804    /// <div class="warning">
805    ///
806    /// **Experimental.** This API is part of an experimental wire-protocol surface
807    /// and may change or be removed in future SDK or CLI releases. Pin both the
808    /// SDK and CLI versions if your code depends on it.
809    ///
810    /// </div>
811    pub async fn read(&self) -> Result<ManagedSettingsReadResult, Error> {
812        let wire_params = serde_json::json!({});
813        let _value = self
814            .client
815            .call(rpc_methods::MANAGEDSETTINGS_READ, Some(wire_params))
816            .await?;
817        Ok(serde_json::from_value(_value)?)
818    }
819}
820
821/// `mcp.*` RPCs.
822#[derive(Clone, Copy)]
823pub struct ClientRpcMcp<'a> {
824    pub(crate) client: &'a Client,
825}
826
827impl<'a> ClientRpcMcp<'a> {
828    /// `mcp.config.*` sub-namespace.
829    pub fn config(&self) -> ClientRpcMcpConfig<'a> {
830        ClientRpcMcpConfig {
831            client: self.client,
832        }
833    }
834
835    /// Discovers MCP servers from user, workspace, plugin, and builtin sources.
836    ///
837    /// Wire method: `mcp.discover`.
838    ///
839    /// # Parameters
840    ///
841    /// * `params` - Optional working directory used as context for MCP server discovery.
842    ///
843    /// # Returns
844    ///
845    /// MCP servers discovered from user, workspace, plugin, and built-in sources.
846    ///
847    /// <div class="warning">
848    ///
849    /// **Experimental.** This API is part of an experimental wire-protocol surface
850    /// and may change or be removed in future SDK or CLI releases. Pin both the
851    /// SDK and CLI versions if your code depends on it.
852    ///
853    /// </div>
854    pub async fn discover(&self, params: McpDiscoverRequest) -> Result<McpDiscoverResult, Error> {
855        let wire_params = serde_json::to_value(params)?;
856        let _value = self
857            .client
858            .call(rpc_methods::MCP_DISCOVER, Some(wire_params))
859            .await?;
860        Ok(serde_json::from_value(_value)?)
861    }
862}
863
864/// `mcp.config.*` RPCs.
865#[derive(Clone, Copy)]
866pub struct ClientRpcMcpConfig<'a> {
867    pub(crate) client: &'a Client,
868}
869
870impl<'a> ClientRpcMcpConfig<'a> {
871    /// Lists MCP servers from user configuration.
872    ///
873    /// Wire method: `mcp.config.list`.
874    ///
875    /// # Returns
876    ///
877    /// User-configured MCP servers, keyed by server name.
878    ///
879    /// <div class="warning">
880    ///
881    /// **Experimental.** This API is part of an experimental wire-protocol surface
882    /// and may change or be removed in future SDK or CLI releases. Pin both the
883    /// SDK and CLI versions if your code depends on it.
884    ///
885    /// </div>
886    pub async fn list(&self) -> Result<McpConfigList, Error> {
887        let wire_params = serde_json::json!({});
888        let _value = self
889            .client
890            .call(rpc_methods::MCP_CONFIG_LIST, Some(wire_params))
891            .await?;
892        Ok(serde_json::from_value(_value)?)
893    }
894
895    /// Adds an MCP server to user configuration.
896    ///
897    /// Wire method: `mcp.config.add`.
898    ///
899    /// # Parameters
900    ///
901    /// * `params` - MCP server name and configuration to add to user configuration.
902    ///
903    /// <div class="warning">
904    ///
905    /// **Experimental.** This API is part of an experimental wire-protocol surface
906    /// and may change or be removed in future SDK or CLI releases. Pin both the
907    /// SDK and CLI versions if your code depends on it.
908    ///
909    /// </div>
910    pub async fn add(&self, params: McpConfigAddRequest) -> Result<(), Error> {
911        let wire_params = serde_json::to_value(params)?;
912        let _value = self
913            .client
914            .call(rpc_methods::MCP_CONFIG_ADD, Some(wire_params))
915            .await?;
916        Ok(())
917    }
918
919    /// Updates an MCP server in user configuration.
920    ///
921    /// Wire method: `mcp.config.update`.
922    ///
923    /// # Parameters
924    ///
925    /// * `params` - MCP server name and replacement configuration to write to user configuration.
926    ///
927    /// <div class="warning">
928    ///
929    /// **Experimental.** This API is part of an experimental wire-protocol surface
930    /// and may change or be removed in future SDK or CLI releases. Pin both the
931    /// SDK and CLI versions if your code depends on it.
932    ///
933    /// </div>
934    pub async fn update(&self, params: McpConfigUpdateRequest) -> Result<(), Error> {
935        let wire_params = serde_json::to_value(params)?;
936        let _value = self
937            .client
938            .call(rpc_methods::MCP_CONFIG_UPDATE, Some(wire_params))
939            .await?;
940        Ok(())
941    }
942
943    /// Removes an MCP server from user configuration.
944    ///
945    /// Wire method: `mcp.config.remove`.
946    ///
947    /// # Parameters
948    ///
949    /// * `params` - MCP server name to remove from user configuration.
950    ///
951    /// <div class="warning">
952    ///
953    /// **Experimental.** This API is part of an experimental wire-protocol surface
954    /// and may change or be removed in future SDK or CLI releases. Pin both the
955    /// SDK and CLI versions if your code depends on it.
956    ///
957    /// </div>
958    pub async fn remove(&self, params: McpConfigRemoveRequest) -> Result<(), Error> {
959        let wire_params = serde_json::to_value(params)?;
960        let _value = self
961            .client
962            .call(rpc_methods::MCP_CONFIG_REMOVE, Some(wire_params))
963            .await?;
964        Ok(())
965    }
966
967    /// Enables MCP servers in user configuration for new sessions.
968    ///
969    /// Wire method: `mcp.config.enable`.
970    ///
971    /// # Parameters
972    ///
973    /// * `params` - MCP server names to enable for new sessions.
974    ///
975    /// <div class="warning">
976    ///
977    /// **Experimental.** This API is part of an experimental wire-protocol surface
978    /// and may change or be removed in future SDK or CLI releases. Pin both the
979    /// SDK and CLI versions if your code depends on it.
980    ///
981    /// </div>
982    pub async fn enable(&self, params: McpConfigEnableRequest) -> Result<(), Error> {
983        let wire_params = serde_json::to_value(params)?;
984        let _value = self
985            .client
986            .call(rpc_methods::MCP_CONFIG_ENABLE, Some(wire_params))
987            .await?;
988        Ok(())
989    }
990
991    /// Disables MCP servers in user configuration for new sessions.
992    ///
993    /// Wire method: `mcp.config.disable`.
994    ///
995    /// # Parameters
996    ///
997    /// * `params` - MCP server names to disable for new sessions.
998    ///
999    /// <div class="warning">
1000    ///
1001    /// **Experimental.** This API is part of an experimental wire-protocol surface
1002    /// and may change or be removed in future SDK or CLI releases. Pin both the
1003    /// SDK and CLI versions if your code depends on it.
1004    ///
1005    /// </div>
1006    pub async fn disable(&self, params: McpConfigDisableRequest) -> Result<(), Error> {
1007        let wire_params = serde_json::to_value(params)?;
1008        let _value = self
1009            .client
1010            .call(rpc_methods::MCP_CONFIG_DISABLE, Some(wire_params))
1011            .await?;
1012        Ok(())
1013    }
1014
1015    /// Drops this runtime process's in-memory MCP server-definition cache so the next MCP config read observes disk.
1016    ///
1017    /// Wire method: `mcp.config.reload`.
1018    ///
1019    /// <div class="warning">
1020    ///
1021    /// **Experimental.** This API is part of an experimental wire-protocol surface
1022    /// and may change or be removed in future SDK or CLI releases. Pin both the
1023    /// SDK and CLI versions if your code depends on it.
1024    ///
1025    /// </div>
1026    pub async fn reload(&self) -> Result<(), Error> {
1027        let wire_params = serde_json::json!({});
1028        let _value = self
1029            .client
1030            .call(rpc_methods::MCP_CONFIG_RELOAD, Some(wire_params))
1031            .await?;
1032        Ok(())
1033    }
1034}
1035
1036/// `models.*` RPCs.
1037#[derive(Clone, Copy)]
1038pub struct ClientRpcModels<'a> {
1039    pub(crate) client: &'a Client,
1040}
1041
1042impl<'a> ClientRpcModels<'a> {
1043    /// Lists Copilot models available to the authenticated user.
1044    ///
1045    /// Wire method: `models.list`.
1046    ///
1047    /// # Returns
1048    ///
1049    /// List of Copilot models available to the resolved user, including capabilities and billing metadata.
1050    ///
1051    /// <div class="warning">
1052    ///
1053    /// **Experimental.** This API is part of an experimental wire-protocol surface
1054    /// and may change or be removed in future SDK or CLI releases. Pin both the
1055    /// SDK and CLI versions if your code depends on it.
1056    ///
1057    /// </div>
1058    pub async fn list(&self) -> Result<ModelList, Error> {
1059        let wire_params = serde_json::json!({});
1060        let _value = self
1061            .client
1062            .call(rpc_methods::MODELS_LIST, Some(wire_params))
1063            .await?;
1064        Ok(serde_json::from_value(_value)?)
1065    }
1066
1067    /// Lists Copilot models available to the authenticated user.
1068    ///
1069    /// Wire method: `models.list`.
1070    ///
1071    /// # Parameters
1072    ///
1073    /// * `params` - Optional GitHub token used to list models for a specific user instead of the global auth context.
1074    ///
1075    /// # Returns
1076    ///
1077    /// List of Copilot models available to the resolved user, including capabilities and billing metadata.
1078    ///
1079    /// <div class="warning">
1080    ///
1081    /// **Experimental.** This API is part of an experimental wire-protocol surface
1082    /// and may change or be removed in future SDK or CLI releases. Pin both the
1083    /// SDK and CLI versions if your code depends on it.
1084    ///
1085    /// </div>
1086    pub async fn list_with_params(&self, params: ModelsListRequest) -> Result<ModelList, Error> {
1087        let wire_params = serde_json::to_value(params)?;
1088        let _value = self
1089            .client
1090            .call(rpc_methods::MODELS_LIST, Some(wire_params))
1091            .await?;
1092        Ok(serde_json::from_value(_value)?)
1093    }
1094
1095    /// Returns the running runtime's complete catalog of well-known built-in model IDs without authentication or network access.
1096    ///
1097    /// Wire method: `models.getBuiltInCatalog`.
1098    ///
1099    /// # Returns
1100    ///
1101    /// The running runtime's complete catalog of well-known built-in model IDs, including supported models and additional IDs with built-in metadata.
1102    ///
1103    /// <div class="warning">
1104    ///
1105    /// **Experimental.** This API is part of an experimental wire-protocol surface
1106    /// and may change or be removed in future SDK or CLI releases. Pin both the
1107    /// SDK and CLI versions if your code depends on it.
1108    ///
1109    /// </div>
1110    pub async fn get_built_in_catalog(&self) -> Result<BuiltInModelCatalog, Error> {
1111        let wire_params = serde_json::json!({});
1112        let _value = self
1113            .client
1114            .call(rpc_methods::MODELS_GETBUILTINCATALOG, Some(wire_params))
1115            .await?;
1116        Ok(serde_json::from_value(_value)?)
1117    }
1118}
1119
1120/// `plugins.*` RPCs.
1121#[derive(Clone, Copy)]
1122pub struct ClientRpcPlugins<'a> {
1123    pub(crate) client: &'a Client,
1124}
1125
1126impl<'a> ClientRpcPlugins<'a> {
1127    /// `plugins.marketplaces.*` sub-namespace.
1128    pub fn marketplaces(&self) -> ClientRpcPluginsMarketplaces<'a> {
1129        ClientRpcPluginsMarketplaces {
1130            client: self.client,
1131        }
1132    }
1133
1134    /// Lists plugins installed in user/global state.
1135    ///
1136    /// Wire method: `plugins.list`.
1137    ///
1138    /// # Returns
1139    ///
1140    /// Plugins installed in user/global state.
1141    ///
1142    /// <div class="warning">
1143    ///
1144    /// **Experimental.** This API is part of an experimental wire-protocol surface
1145    /// and may change or be removed in future SDK or CLI releases. Pin both the
1146    /// SDK and CLI versions if your code depends on it.
1147    ///
1148    /// </div>
1149    pub async fn list(&self) -> Result<PluginListResult, Error> {
1150        let wire_params = serde_json::json!({});
1151        let _value = self
1152            .client
1153            .call(rpc_methods::PLUGINS_LIST, Some(wire_params))
1154            .await?;
1155        Ok(serde_json::from_value(_value)?)
1156    }
1157
1158    /// Installs a plugin from a marketplace, GitHub repo, URL, or local path.
1159    ///
1160    /// Wire method: `plugins.install`.
1161    ///
1162    /// # Parameters
1163    ///
1164    /// * `params` - Plugin source and optional working directory for relative-path resolution.
1165    ///
1166    /// # Returns
1167    ///
1168    /// Result of installing a plugin.
1169    ///
1170    /// <div class="warning">
1171    ///
1172    /// **Experimental.** This API is part of an experimental wire-protocol surface
1173    /// and may change or be removed in future SDK or CLI releases. Pin both the
1174    /// SDK and CLI versions if your code depends on it.
1175    ///
1176    /// </div>
1177    pub async fn install(
1178        &self,
1179        params: PluginsInstallRequest,
1180    ) -> Result<PluginInstallResult, Error> {
1181        let wire_params = serde_json::to_value(params)?;
1182        let _value = self
1183            .client
1184            .call(rpc_methods::PLUGINS_INSTALL, Some(wire_params))
1185            .await?;
1186        Ok(serde_json::from_value(_value)?)
1187    }
1188
1189    /// Uninstalls an installed plugin.
1190    ///
1191    /// Wire method: `plugins.uninstall`.
1192    ///
1193    /// # Parameters
1194    ///
1195    /// * `params` - Name (or spec) of the plugin to uninstall.
1196    ///
1197    /// <div class="warning">
1198    ///
1199    /// **Experimental.** This API is part of an experimental wire-protocol surface
1200    /// and may change or be removed in future SDK or CLI releases. Pin both the
1201    /// SDK and CLI versions if your code depends on it.
1202    ///
1203    /// </div>
1204    pub async fn uninstall(&self, params: PluginsUninstallRequest) -> Result<(), Error> {
1205        let wire_params = serde_json::to_value(params)?;
1206        let _value = self
1207            .client
1208            .call(rpc_methods::PLUGINS_UNINSTALL, Some(wire_params))
1209            .await?;
1210        Ok(())
1211    }
1212
1213    /// Updates an installed plugin to its latest published version.
1214    ///
1215    /// Wire method: `plugins.update`.
1216    ///
1217    /// # Parameters
1218    ///
1219    /// * `params` - Name (or spec) of the plugin to update.
1220    ///
1221    /// # Returns
1222    ///
1223    /// Result of updating a single plugin.
1224    ///
1225    /// <div class="warning">
1226    ///
1227    /// **Experimental.** This API is part of an experimental wire-protocol surface
1228    /// and may change or be removed in future SDK or CLI releases. Pin both the
1229    /// SDK and CLI versions if your code depends on it.
1230    ///
1231    /// </div>
1232    pub async fn update(&self, params: PluginsUpdateRequest) -> Result<PluginUpdateResult, Error> {
1233        let wire_params = serde_json::to_value(params)?;
1234        let _value = self
1235            .client
1236            .call(rpc_methods::PLUGINS_UPDATE, Some(wire_params))
1237            .await?;
1238        Ok(serde_json::from_value(_value)?)
1239    }
1240
1241    /// Updates every installed plugin to its latest published version.
1242    ///
1243    /// Wire method: `plugins.updateAll`.
1244    ///
1245    /// # Returns
1246    ///
1247    /// Result of updating all installed plugins.
1248    ///
1249    /// <div class="warning">
1250    ///
1251    /// **Experimental.** This API is part of an experimental wire-protocol surface
1252    /// and may change or be removed in future SDK or CLI releases. Pin both the
1253    /// SDK and CLI versions if your code depends on it.
1254    ///
1255    /// </div>
1256    pub async fn update_all(&self) -> Result<PluginUpdateAllResult, Error> {
1257        let wire_params = serde_json::json!({});
1258        let _value = self
1259            .client
1260            .call(rpc_methods::PLUGINS_UPDATEALL, Some(wire_params))
1261            .await?;
1262        Ok(serde_json::from_value(_value)?)
1263    }
1264
1265    /// Enables installed plugins for new sessions.
1266    ///
1267    /// Wire method: `plugins.enable`.
1268    ///
1269    /// # Parameters
1270    ///
1271    /// * `params` - Plugin names (or specs) to enable.
1272    ///
1273    /// <div class="warning">
1274    ///
1275    /// **Experimental.** This API is part of an experimental wire-protocol surface
1276    /// and may change or be removed in future SDK or CLI releases. Pin both the
1277    /// SDK and CLI versions if your code depends on it.
1278    ///
1279    /// </div>
1280    pub async fn enable(&self, params: PluginsEnableRequest) -> Result<(), Error> {
1281        let wire_params = serde_json::to_value(params)?;
1282        let _value = self
1283            .client
1284            .call(rpc_methods::PLUGINS_ENABLE, Some(wire_params))
1285            .await?;
1286        Ok(())
1287    }
1288
1289    /// Disables installed plugins for new sessions.
1290    ///
1291    /// Wire method: `plugins.disable`.
1292    ///
1293    /// # Parameters
1294    ///
1295    /// * `params` - Plugin names (or specs) to disable.
1296    ///
1297    /// <div class="warning">
1298    ///
1299    /// **Experimental.** This API is part of an experimental wire-protocol surface
1300    /// and may change or be removed in future SDK or CLI releases. Pin both the
1301    /// SDK and CLI versions if your code depends on it.
1302    ///
1303    /// </div>
1304    pub async fn disable(&self, params: PluginsDisableRequest) -> Result<(), Error> {
1305        let wire_params = serde_json::to_value(params)?;
1306        let _value = self
1307            .client
1308            .call(rpc_methods::PLUGINS_DISABLE, Some(wire_params))
1309            .await?;
1310        Ok(())
1311    }
1312}
1313
1314/// `plugins.marketplaces.*` RPCs.
1315#[derive(Clone, Copy)]
1316pub struct ClientRpcPluginsMarketplaces<'a> {
1317    pub(crate) client: &'a Client,
1318}
1319
1320impl<'a> ClientRpcPluginsMarketplaces<'a> {
1321    /// Lists all registered marketplaces (defaults + user-added).
1322    ///
1323    /// Wire method: `plugins.marketplaces.list`.
1324    ///
1325    /// # Returns
1326    ///
1327    /// All registered marketplaces, including built-in defaults.
1328    ///
1329    /// <div class="warning">
1330    ///
1331    /// **Experimental.** This API is part of an experimental wire-protocol surface
1332    /// and may change or be removed in future SDK or CLI releases. Pin both the
1333    /// SDK and CLI versions if your code depends on it.
1334    ///
1335    /// </div>
1336    pub async fn list(&self) -> Result<MarketplaceListResult, Error> {
1337        let wire_params = serde_json::json!({});
1338        let _value = self
1339            .client
1340            .call(rpc_methods::PLUGINS_MARKETPLACES_LIST, Some(wire_params))
1341            .await?;
1342        Ok(serde_json::from_value(_value)?)
1343    }
1344
1345    /// Registers a new marketplace from a source (owner/repo, URL, or local path).
1346    ///
1347    /// Wire method: `plugins.marketplaces.add`.
1348    ///
1349    /// # Parameters
1350    ///
1351    /// * `params` - Marketplace source and optional working directory for relative-path resolution.
1352    ///
1353    /// # Returns
1354    ///
1355    /// Result of registering a new marketplace.
1356    ///
1357    /// <div class="warning">
1358    ///
1359    /// **Experimental.** This API is part of an experimental wire-protocol surface
1360    /// and may change or be removed in future SDK or CLI releases. Pin both the
1361    /// SDK and CLI versions if your code depends on it.
1362    ///
1363    /// </div>
1364    pub async fn add(
1365        &self,
1366        params: PluginsMarketplacesAddRequest,
1367    ) -> Result<MarketplaceAddResult, Error> {
1368        let wire_params = serde_json::to_value(params)?;
1369        let _value = self
1370            .client
1371            .call(rpc_methods::PLUGINS_MARKETPLACES_ADD, Some(wire_params))
1372            .await?;
1373        Ok(serde_json::from_value(_value)?)
1374    }
1375
1376    /// Removes a previously-registered marketplace. When the marketplace has dependent plugins and `force` is not set, the marketplace is left intact and the result lists the dependents so the caller can decide whether to retry with `force=true`.
1377    ///
1378    /// Wire method: `plugins.marketplaces.remove`.
1379    ///
1380    /// # Parameters
1381    ///
1382    /// * `params` - Name of the marketplace to remove and an optional force flag.
1383    ///
1384    /// # Returns
1385    ///
1386    /// Outcome of the remove attempt, including dependent-plugin info when applicable.
1387    ///
1388    /// <div class="warning">
1389    ///
1390    /// **Experimental.** This API is part of an experimental wire-protocol surface
1391    /// and may change or be removed in future SDK or CLI releases. Pin both the
1392    /// SDK and CLI versions if your code depends on it.
1393    ///
1394    /// </div>
1395    pub async fn remove(
1396        &self,
1397        params: PluginsMarketplacesRemoveRequest,
1398    ) -> Result<MarketplaceRemoveResult, Error> {
1399        let wire_params = serde_json::to_value(params)?;
1400        let _value = self
1401            .client
1402            .call(rpc_methods::PLUGINS_MARKETPLACES_REMOVE, Some(wire_params))
1403            .await?;
1404        Ok(serde_json::from_value(_value)?)
1405    }
1406
1407    /// Lists plugins advertised by a registered marketplace.
1408    ///
1409    /// Wire method: `plugins.marketplaces.browse`.
1410    ///
1411    /// # Parameters
1412    ///
1413    /// * `params` - Name of the marketplace whose plugin catalog to fetch.
1414    ///
1415    /// # Returns
1416    ///
1417    /// Plugins advertised by the marketplace.
1418    ///
1419    /// <div class="warning">
1420    ///
1421    /// **Experimental.** This API is part of an experimental wire-protocol surface
1422    /// and may change or be removed in future SDK or CLI releases. Pin both the
1423    /// SDK and CLI versions if your code depends on it.
1424    ///
1425    /// </div>
1426    pub async fn browse(
1427        &self,
1428        params: PluginsMarketplacesBrowseRequest,
1429    ) -> Result<MarketplaceBrowseResult, Error> {
1430        let wire_params = serde_json::to_value(params)?;
1431        let _value = self
1432            .client
1433            .call(rpc_methods::PLUGINS_MARKETPLACES_BROWSE, Some(wire_params))
1434            .await?;
1435        Ok(serde_json::from_value(_value)?)
1436    }
1437
1438    /// Re-fetches one or all registered marketplace catalogs.
1439    ///
1440    /// Wire method: `plugins.marketplaces.refresh`.
1441    ///
1442    /// # Returns
1443    ///
1444    /// Result of refreshing one or more marketplace catalogs.
1445    ///
1446    /// <div class="warning">
1447    ///
1448    /// **Experimental.** This API is part of an experimental wire-protocol surface
1449    /// and may change or be removed in future SDK or CLI releases. Pin both the
1450    /// SDK and CLI versions if your code depends on it.
1451    ///
1452    /// </div>
1453    pub async fn refresh(&self) -> Result<MarketplaceRefreshResult, Error> {
1454        let wire_params = serde_json::json!({});
1455        let _value = self
1456            .client
1457            .call(rpc_methods::PLUGINS_MARKETPLACES_REFRESH, Some(wire_params))
1458            .await?;
1459        Ok(serde_json::from_value(_value)?)
1460    }
1461
1462    /// Re-fetches one or all registered marketplace catalogs.
1463    ///
1464    /// Wire method: `plugins.marketplaces.refresh`.
1465    ///
1466    /// # Parameters
1467    ///
1468    /// * `params` - Optional marketplace name; omit to refresh all.
1469    ///
1470    /// # Returns
1471    ///
1472    /// Result of refreshing one or more marketplace catalogs.
1473    ///
1474    /// <div class="warning">
1475    ///
1476    /// **Experimental.** This API is part of an experimental wire-protocol surface
1477    /// and may change or be removed in future SDK or CLI releases. Pin both the
1478    /// SDK and CLI versions if your code depends on it.
1479    ///
1480    /// </div>
1481    pub async fn refresh_with_params(
1482        &self,
1483        params: PluginsMarketplacesRefreshRequest,
1484    ) -> Result<MarketplaceRefreshResult, Error> {
1485        let wire_params = serde_json::to_value(params)?;
1486        let _value = self
1487            .client
1488            .call(rpc_methods::PLUGINS_MARKETPLACES_REFRESH, Some(wire_params))
1489            .await?;
1490        Ok(serde_json::from_value(_value)?)
1491    }
1492}
1493
1494/// `runtime.*` RPCs.
1495#[derive(Clone, Copy)]
1496pub struct ClientRpcRuntime<'a> {
1497    pub(crate) client: &'a Client,
1498}
1499
1500impl<'a> ClientRpcRuntime<'a> {
1501    /// Gracefully shuts down an SDK-owned runtime. The response is sent only after cleanup completes; callers may then terminate the owned runtime process.
1502    ///
1503    /// Wire method: `runtime.shutdown`.
1504    ///
1505    /// <div class="warning">
1506    ///
1507    /// **Experimental.** This API is part of an experimental wire-protocol surface
1508    /// and may change or be removed in future SDK or CLI releases. Pin both the
1509    /// SDK and CLI versions if your code depends on it.
1510    ///
1511    /// </div>
1512    pub async fn shutdown(&self) -> Result<(), Error> {
1513        let wire_params = serde_json::json!({});
1514        let _value = self
1515            .client
1516            .call(rpc_methods::RUNTIME_SHUTDOWN, Some(wire_params))
1517            .await?;
1518        Ok(())
1519    }
1520}
1521
1522/// `secrets.*` RPCs.
1523#[derive(Clone, Copy)]
1524pub struct ClientRpcSecrets<'a> {
1525    pub(crate) client: &'a Client,
1526}
1527
1528impl<'a> ClientRpcSecrets<'a> {
1529    /// Registers secret values for redaction in session logs and exports. The SDK calls this to inject dynamically generated secret values (e.g., OIDC tokens).
1530    ///
1531    /// Wire method: `secrets.addFilterValues`.
1532    ///
1533    /// # Parameters
1534    ///
1535    /// * `params` - Secret values to add to the redaction filter.
1536    ///
1537    /// # Returns
1538    ///
1539    /// Confirmation that the secret values were registered.
1540    ///
1541    /// <div class="warning">
1542    ///
1543    /// **Experimental.** This API is part of an experimental wire-protocol surface
1544    /// and may change or be removed in future SDK or CLI releases. Pin both the
1545    /// SDK and CLI versions if your code depends on it.
1546    ///
1547    /// </div>
1548    pub async fn add_filter_values(
1549        &self,
1550        params: SecretsAddFilterValuesRequest,
1551    ) -> Result<SecretsAddFilterValuesResult, Error> {
1552        let wire_params = serde_json::to_value(params)?;
1553        let _value = self
1554            .client
1555            .call(rpc_methods::SECRETS_ADDFILTERVALUES, Some(wire_params))
1556            .await?;
1557        Ok(serde_json::from_value(_value)?)
1558    }
1559}
1560
1561/// `sessionFs.*` RPCs.
1562#[derive(Clone, Copy)]
1563pub struct ClientRpcSessionFs<'a> {
1564    pub(crate) client: &'a Client,
1565}
1566
1567impl<'a> ClientRpcSessionFs<'a> {
1568    /// Registers an SDK client as the session filesystem provider.
1569    ///
1570    /// Wire method: `sessionFs.setProvider`.
1571    ///
1572    /// # Parameters
1573    ///
1574    /// * `params` - Initial working directory, session-state path layout, and path conventions used to register the calling SDK client as the session filesystem provider.
1575    ///
1576    /// # Returns
1577    ///
1578    /// Indicates whether the calling client was registered as the session filesystem provider.
1579    ///
1580    /// <div class="warning">
1581    ///
1582    /// **Experimental.** This API is part of an experimental wire-protocol surface
1583    /// and may change or be removed in future SDK or CLI releases. Pin both the
1584    /// SDK and CLI versions if your code depends on it.
1585    ///
1586    /// </div>
1587    pub async fn set_provider(
1588        &self,
1589        params: SessionFsSetProviderRequest,
1590    ) -> Result<SessionFsSetProviderResult, Error> {
1591        let wire_params = serde_json::to_value(params)?;
1592        let _value = self
1593            .client
1594            .call(rpc_methods::SESSIONFS_SETPROVIDER, Some(wire_params))
1595            .await?;
1596        Ok(serde_json::from_value(_value)?)
1597    }
1598}
1599
1600/// `sessions.*` RPCs.
1601#[derive(Clone, Copy)]
1602pub struct ClientRpcSessions<'a> {
1603    pub(crate) client: &'a Client,
1604}
1605
1606impl<'a> ClientRpcSessions<'a> {
1607    /// Creates or resumes a local session and returns the opened session ID.
1608    ///
1609    /// Wire method: `sessions.open`.
1610    ///
1611    /// # Returns
1612    ///
1613    /// Result of opening a session.
1614    ///
1615    /// <div class="warning">
1616    ///
1617    /// **Experimental.** This API is part of an experimental wire-protocol surface
1618    /// and may change or be removed in future SDK or CLI releases. Pin both the
1619    /// SDK and CLI versions if your code depends on it.
1620    ///
1621    /// </div>
1622    pub async fn open(&self) -> Result<SessionOpenResult, Error> {
1623        let wire_params = serde_json::json!({});
1624        let _value = self
1625            .client
1626            .call(rpc_methods::SESSIONS_OPEN, Some(wire_params))
1627            .await?;
1628        Ok(serde_json::from_value(_value)?)
1629    }
1630
1631    /// Creates a new session by forking persisted history from an existing session.
1632    ///
1633    /// Wire method: `sessions.fork`.
1634    ///
1635    /// # Parameters
1636    ///
1637    /// * `params` - Source session identifier to fork from, optional event-ID boundary, and optional friendly name for the new session.
1638    ///
1639    /// # Returns
1640    ///
1641    /// Identifier and optional friendly name assigned to the newly forked session.
1642    ///
1643    /// <div class="warning">
1644    ///
1645    /// **Experimental.** This API is part of an experimental wire-protocol surface
1646    /// and may change or be removed in future SDK or CLI releases. Pin both the
1647    /// SDK and CLI versions if your code depends on it.
1648    ///
1649    /// </div>
1650    pub async fn fork(&self, params: SessionsForkRequest) -> Result<SessionsForkResult, Error> {
1651        let wire_params = serde_json::to_value(params)?;
1652        let _value = self
1653            .client
1654            .call(rpc_methods::SESSIONS_FORK, Some(wire_params))
1655            .await?;
1656        Ok(serde_json::from_value(_value)?)
1657    }
1658
1659    /// Connects to an existing remote session and exposes it as an SDK session.
1660    ///
1661    /// Wire method: `sessions.connect`.
1662    ///
1663    /// # Parameters
1664    ///
1665    /// * `params` - Remote session connection parameters.
1666    ///
1667    /// # Returns
1668    ///
1669    /// Remote session connection result.
1670    ///
1671    /// <div class="warning">
1672    ///
1673    /// **Experimental.** This API is part of an experimental wire-protocol surface
1674    /// and may change or be removed in future SDK or CLI releases. Pin both the
1675    /// SDK and CLI versions if your code depends on it.
1676    ///
1677    /// </div>
1678    pub async fn connect(
1679        &self,
1680        params: ConnectRemoteSessionParams,
1681    ) -> Result<RemoteSessionConnectionResult, Error> {
1682        let wire_params = serde_json::to_value(params)?;
1683        let _value = self
1684            .client
1685            .call(rpc_methods::SESSIONS_CONNECT, Some(wire_params))
1686            .await?;
1687        Ok(serde_json::from_value(_value)?)
1688    }
1689
1690    /// Lists sessions, optionally filtered by source and working-directory context. Returned entries are discriminated by `isRemote`: local entries carry only the lightweight `LocalSessionMetadataValue` shape; remote entries carry the full `RemoteSessionMetadataValue` shape (repository, PR number, taskType, etc.).
1691    ///
1692    /// Wire method: `sessions.list`.
1693    ///
1694    /// # Returns
1695    ///
1696    /// Sessions matching the filter, ordered most-recently-modified first.
1697    ///
1698    /// <div class="warning">
1699    ///
1700    /// **Experimental.** This API is part of an experimental wire-protocol surface
1701    /// and may change or be removed in future SDK or CLI releases. Pin both the
1702    /// SDK and CLI versions if your code depends on it.
1703    ///
1704    /// </div>
1705    pub async fn list(&self) -> Result<SessionList, Error> {
1706        let wire_params = serde_json::json!({});
1707        let _value = self
1708            .client
1709            .call(rpc_methods::SESSIONS_LIST, Some(wire_params))
1710            .await?;
1711        Ok(serde_json::from_value(_value)?)
1712    }
1713
1714    /// Lists sessions, optionally filtered by source and working-directory context. Returned entries are discriminated by `isRemote`: local entries carry only the lightweight `LocalSessionMetadataValue` shape; remote entries carry the full `RemoteSessionMetadataValue` shape (repository, PR number, taskType, etc.).
1715    ///
1716    /// Wire method: `sessions.list`.
1717    ///
1718    /// # Parameters
1719    ///
1720    /// * `params` - Optional source filter, metadata-load limit, and context filter applied to the returned sessions.
1721    ///
1722    /// # Returns
1723    ///
1724    /// Sessions matching the filter, ordered most-recently-modified first.
1725    ///
1726    /// <div class="warning">
1727    ///
1728    /// **Experimental.** This API is part of an experimental wire-protocol surface
1729    /// and may change or be removed in future SDK or CLI releases. Pin both the
1730    /// SDK and CLI versions if your code depends on it.
1731    ///
1732    /// </div>
1733    pub async fn list_with_params(
1734        &self,
1735        params: SessionsListRequest,
1736    ) -> Result<SessionList, Error> {
1737        let wire_params = serde_json::to_value(params)?;
1738        let _value = self
1739            .client
1740            .call(rpc_methods::SESSIONS_LIST, Some(wire_params))
1741            .await?;
1742        Ok(serde_json::from_value(_value)?)
1743    }
1744
1745    /// Reads lightweight persisted metadata for one local session without opening it.
1746    ///
1747    /// Wire method: `sessions.getMetadata`.
1748    ///
1749    /// # Parameters
1750    ///
1751    /// * `params` - Session ID whose persisted metadata should be read.
1752    ///
1753    /// # Returns
1754    ///
1755    /// Persisted local session metadata when the session exists.
1756    ///
1757    /// <div class="warning">
1758    ///
1759    /// **Experimental.** This API is part of an experimental wire-protocol surface
1760    /// and may change or be removed in future SDK or CLI releases. Pin both the
1761    /// SDK and CLI versions if your code depends on it.
1762    ///
1763    /// </div>
1764    pub(crate) async fn get_metadata(
1765        &self,
1766        params: SessionsGetMetadataRequest,
1767    ) -> Result<SessionsGetMetadataResult, Error> {
1768        let wire_params = serde_json::to_value(params)?;
1769        let _value = self
1770            .client
1771            .call(rpc_methods::SESSIONS_GETMETADATA, Some(wire_params))
1772            .await?;
1773        Ok(serde_json::from_value(_value)?)
1774    }
1775
1776    /// Lists recent local session IDs that contain user-visible history, omitting housekeeping-only sessions.
1777    ///
1778    /// Wire method: `sessions.listNonEmptySessionIds`.
1779    ///
1780    /// # Parameters
1781    ///
1782    /// * `params` - Limit for non-empty local session IDs.
1783    ///
1784    /// # Returns
1785    ///
1786    /// Recent local session IDs that contain user-visible history.
1787    ///
1788    /// <div class="warning">
1789    ///
1790    /// **Experimental.** This API is part of an experimental wire-protocol surface
1791    /// and may change or be removed in future SDK or CLI releases. Pin both the
1792    /// SDK and CLI versions if your code depends on it.
1793    ///
1794    /// </div>
1795    pub(crate) async fn list_non_empty_session_ids(
1796        &self,
1797        params: SessionsListNonEmptySessionIdsRequest,
1798    ) -> Result<SessionsListNonEmptySessionIdsResult, Error> {
1799        let wire_params = serde_json::to_value(params)?;
1800        let _value = self
1801            .client
1802            .call(
1803                rpc_methods::SESSIONS_LISTNONEMPTYSESSIONIDS,
1804                Some(wire_params),
1805            )
1806            .await?;
1807        Ok(serde_json::from_value(_value)?)
1808    }
1809
1810    /// Finds the local session bound to a GitHub task ID, if any.
1811    ///
1812    /// Wire method: `sessions.findByTaskId`.
1813    ///
1814    /// # Parameters
1815    ///
1816    /// * `params` - GitHub task ID to look up.
1817    ///
1818    /// # Returns
1819    ///
1820    /// ID of the local session bound to the given GitHub task, or omitted when none.
1821    ///
1822    /// <div class="warning">
1823    ///
1824    /// **Experimental.** This API is part of an experimental wire-protocol surface
1825    /// and may change or be removed in future SDK or CLI releases. Pin both the
1826    /// SDK and CLI versions if your code depends on it.
1827    ///
1828    /// </div>
1829    pub async fn find_by_task_id(
1830        &self,
1831        params: SessionsFindByTaskIDRequest,
1832    ) -> Result<SessionsFindByTaskIDResult, Error> {
1833        let wire_params = serde_json::to_value(params)?;
1834        let _value = self
1835            .client
1836            .call(rpc_methods::SESSIONS_FINDBYTASKID, Some(wire_params))
1837            .await?;
1838        Ok(serde_json::from_value(_value)?)
1839    }
1840
1841    /// Resolves a UUID prefix to a unique session ID, if exactly one session matches.
1842    ///
1843    /// Wire method: `sessions.findByPrefix`.
1844    ///
1845    /// # Parameters
1846    ///
1847    /// * `params` - UUID prefix to resolve to a unique session ID.
1848    ///
1849    /// # Returns
1850    ///
1851    /// Session ID matching the prefix, omitted when no unique match exists.
1852    ///
1853    /// <div class="warning">
1854    ///
1855    /// **Experimental.** This API is part of an experimental wire-protocol surface
1856    /// and may change or be removed in future SDK or CLI releases. Pin both the
1857    /// SDK and CLI versions if your code depends on it.
1858    ///
1859    /// </div>
1860    pub async fn find_by_prefix(
1861        &self,
1862        params: SessionsFindByPrefixRequest,
1863    ) -> Result<SessionsFindByPrefixResult, Error> {
1864        let wire_params = serde_json::to_value(params)?;
1865        let _value = self
1866            .client
1867            .call(rpc_methods::SESSIONS_FINDBYPREFIX, Some(wire_params))
1868            .await?;
1869        Ok(serde_json::from_value(_value)?)
1870    }
1871
1872    /// Returns the most-relevant prior session for a given working-directory context.
1873    ///
1874    /// Wire method: `sessions.getLastForContext`.
1875    ///
1876    /// # Parameters
1877    ///
1878    /// * `params` - Optional working-directory context used to score session relevance.
1879    ///
1880    /// # Returns
1881    ///
1882    /// Most-relevant session ID for the supplied context, or omitted when no sessions exist.
1883    ///
1884    /// <div class="warning">
1885    ///
1886    /// **Experimental.** This API is part of an experimental wire-protocol surface
1887    /// and may change or be removed in future SDK or CLI releases. Pin both the
1888    /// SDK and CLI versions if your code depends on it.
1889    ///
1890    /// </div>
1891    pub async fn get_last_for_context(
1892        &self,
1893        params: SessionsGetLastForContextRequest,
1894    ) -> Result<SessionsGetLastForContextResult, Error> {
1895        let wire_params = serde_json::to_value(params)?;
1896        let _value = self
1897            .client
1898            .call(rpc_methods::SESSIONS_GETLASTFORCONTEXT, Some(wire_params))
1899            .await?;
1900        Ok(serde_json::from_value(_value)?)
1901    }
1902
1903    /// Computes the absolute path to a session's persisted events.jsonl file. Internal: filesystem paths are only meaningful in-process (CLI and runtime share a filesystem). Currently used by the CLI's contribution-graph feature to read historical events directly. Remote SDK consumers must not depend on this; a proper event-query API would replace it if the contribution graph ever needed to work over the wire.
1904    ///
1905    /// Wire method: `sessions.getEventFilePath`.
1906    ///
1907    /// # Parameters
1908    ///
1909    /// * `params` - Session ID whose event-log file path to compute.
1910    ///
1911    /// # Returns
1912    ///
1913    /// Absolute path to the session's events.jsonl file on disk.
1914    ///
1915    /// <div class="warning">
1916    ///
1917    /// **Experimental.** This API is part of an experimental wire-protocol surface
1918    /// and may change or be removed in future SDK or CLI releases. Pin both the
1919    /// SDK and CLI versions if your code depends on it.
1920    ///
1921    /// </div>
1922    pub(crate) async fn get_event_file_path(
1923        &self,
1924        params: SessionsGetEventFilePathRequest,
1925    ) -> Result<SessionsGetEventFilePathResult, Error> {
1926        let wire_params = serde_json::to_value(params)?;
1927        let _value = self
1928            .client
1929            .call(rpc_methods::SESSIONS_GETEVENTFILEPATH, Some(wire_params))
1930            .await?;
1931        Ok(serde_json::from_value(_value)?)
1932    }
1933
1934    /// Returns the on-disk byte size of each session's workspace directory.
1935    ///
1936    /// Wire method: `sessions.getSizes`.
1937    ///
1938    /// # Returns
1939    ///
1940    /// Map of sessionId -> on-disk size in bytes for each session's workspace directory.
1941    ///
1942    /// <div class="warning">
1943    ///
1944    /// **Experimental.** This API is part of an experimental wire-protocol surface
1945    /// and may change or be removed in future SDK or CLI releases. Pin both the
1946    /// SDK and CLI versions if your code depends on it.
1947    ///
1948    /// </div>
1949    pub async fn get_sizes(&self) -> Result<SessionSizes, Error> {
1950        let wire_params = serde_json::json!({});
1951        let _value = self
1952            .client
1953            .call(rpc_methods::SESSIONS_GETSIZES, Some(wire_params))
1954            .await?;
1955        Ok(serde_json::from_value(_value)?)
1956    }
1957
1958    /// Returns the subset of the supplied session IDs that are currently held by another running process.
1959    ///
1960    /// Wire method: `sessions.checkInUse`.
1961    ///
1962    /// # Parameters
1963    ///
1964    /// * `params` - Session IDs to test for live in-use locks.
1965    ///
1966    /// # Returns
1967    ///
1968    /// Session IDs from the input set that are currently in use by another process.
1969    ///
1970    /// <div class="warning">
1971    ///
1972    /// **Experimental.** This API is part of an experimental wire-protocol surface
1973    /// and may change or be removed in future SDK or CLI releases. Pin both the
1974    /// SDK and CLI versions if your code depends on it.
1975    ///
1976    /// </div>
1977    pub async fn check_in_use(
1978        &self,
1979        params: SessionsCheckInUseRequest,
1980    ) -> Result<SessionsCheckInUseResult, Error> {
1981        let wire_params = serde_json::to_value(params)?;
1982        let _value = self
1983            .client
1984            .call(rpc_methods::SESSIONS_CHECKINUSE, Some(wire_params))
1985            .await?;
1986        Ok(serde_json::from_value(_value)?)
1987    }
1988
1989    /// Returns a session's persisted remote-steerable flag, if any has been recorded. Internal: this is CLI-specific book-keeping used by `--continue` / `--resume` to inherit the prior session's remote-steerable preference. SDK consumers that want similar behavior should manage their own persistence around start/stop calls rather than relying on this runtime-side flag.
1990    ///
1991    /// Wire method: `sessions.getPersistedRemoteSteerable`.
1992    ///
1993    /// # Parameters
1994    ///
1995    /// * `params` - Session ID to look up the persisted remote-steerable flag for.
1996    ///
1997    /// # Returns
1998    ///
1999    /// The session's persisted remote-steerable flag, or omitted when no value has been persisted.
2000    ///
2001    /// <div class="warning">
2002    ///
2003    /// **Experimental.** This API is part of an experimental wire-protocol surface
2004    /// and may change or be removed in future SDK or CLI releases. Pin both the
2005    /// SDK and CLI versions if your code depends on it.
2006    ///
2007    /// </div>
2008    pub(crate) async fn get_persisted_remote_steerable(
2009        &self,
2010        params: SessionsGetPersistedRemoteSteerableRequest,
2011    ) -> Result<SessionsGetPersistedRemoteSteerableResult, Error> {
2012        let wire_params = serde_json::to_value(params)?;
2013        let _value = self
2014            .client
2015            .call(
2016                rpc_methods::SESSIONS_GETPERSISTEDREMOTESTEERABLE,
2017                Some(wire_params),
2018            )
2019            .await?;
2020        Ok(serde_json::from_value(_value)?)
2021    }
2022
2023    /// Closes a session: emits shutdown, flushes pending events, releases the in-use lock, and disposes the active session.
2024    ///
2025    /// Wire method: `sessions.close`.
2026    ///
2027    /// # Parameters
2028    ///
2029    /// * `params` - Session ID to close.
2030    ///
2031    /// # Returns
2032    ///
2033    /// Closes a session: emits shutdown, flushes pending events to disk, releases the in-use lock, disposes the active session. Idempotent: succeeds even if the session is not currently active.
2034    ///
2035    /// <div class="warning">
2036    ///
2037    /// **Experimental.** This API is part of an experimental wire-protocol surface
2038    /// and may change or be removed in future SDK or CLI releases. Pin both the
2039    /// SDK and CLI versions if your code depends on it.
2040    ///
2041    /// </div>
2042    pub async fn close(&self, params: SessionsCloseRequest) -> Result<SessionsCloseResult, Error> {
2043        let wire_params = serde_json::to_value(params)?;
2044        let _value = self
2045            .client
2046            .call(rpc_methods::SESSIONS_CLOSE, Some(wire_params))
2047            .await?;
2048        Ok(serde_json::from_value(_value)?)
2049    }
2050
2051    /// Closes, deactivates, and deletes a set of sessions, returning the bytes freed per session.
2052    ///
2053    /// Wire method: `sessions.bulkDelete`.
2054    ///
2055    /// # Parameters
2056    ///
2057    /// * `params` - Session IDs to close, deactivate, and delete from disk.
2058    ///
2059    /// # Returns
2060    ///
2061    /// Map of sessionId -> bytes freed by removing the session's workspace directory.
2062    ///
2063    /// <div class="warning">
2064    ///
2065    /// **Experimental.** This API is part of an experimental wire-protocol surface
2066    /// and may change or be removed in future SDK or CLI releases. Pin both the
2067    /// SDK and CLI versions if your code depends on it.
2068    ///
2069    /// </div>
2070    pub async fn bulk_delete(
2071        &self,
2072        params: SessionsBulkDeleteRequest,
2073    ) -> Result<SessionBulkDeleteResult, Error> {
2074        let wire_params = serde_json::to_value(params)?;
2075        let _value = self
2076            .client
2077            .call(rpc_methods::SESSIONS_BULKDELETE, Some(wire_params))
2078            .await?;
2079        Ok(serde_json::from_value(_value)?)
2080    }
2081
2082    /// Deletes one local session from disk after running the same lifecycle hooks as the session manager.
2083    ///
2084    /// Wire method: `sessions.delete`.
2085    ///
2086    /// # Parameters
2087    ///
2088    /// * `params` - Session ID to delete from disk.
2089    ///
2090    /// <div class="warning">
2091    ///
2092    /// **Experimental.** This API is part of an experimental wire-protocol surface
2093    /// and may change or be removed in future SDK or CLI releases. Pin both the
2094    /// SDK and CLI versions if your code depends on it.
2095    ///
2096    /// </div>
2097    pub(crate) async fn delete(&self, params: SessionsDeleteRequest) -> Result<(), Error> {
2098        let wire_params = serde_json::to_value(params)?;
2099        let _value = self
2100            .client
2101            .call(rpc_methods::SESSIONS_DELETE, Some(wire_params))
2102            .await?;
2103        Ok(())
2104    }
2105
2106    /// Deletes sessions older than the given threshold, with optional dry-run and exclusion list.
2107    ///
2108    /// Wire method: `sessions.pruneOld`.
2109    ///
2110    /// # Parameters
2111    ///
2112    /// * `params` - Age threshold and optional flags controlling which old sessions are pruned (or simulated when dryRun is true).
2113    ///
2114    /// # Returns
2115    ///
2116    /// Outcome of the prune operation: deleted IDs, dry-run candidates, skipped IDs, total bytes freed, and the dry-run flag.
2117    ///
2118    /// <div class="warning">
2119    ///
2120    /// **Experimental.** This API is part of an experimental wire-protocol surface
2121    /// and may change or be removed in future SDK or CLI releases. Pin both the
2122    /// SDK and CLI versions if your code depends on it.
2123    ///
2124    /// </div>
2125    pub async fn prune_old(
2126        &self,
2127        params: SessionsPruneOldRequest,
2128    ) -> Result<SessionPruneResult, Error> {
2129        let wire_params = serde_json::to_value(params)?;
2130        let _value = self
2131            .client
2132            .call(rpc_methods::SESSIONS_PRUNEOLD, Some(wire_params))
2133            .await?;
2134        Ok(serde_json::from_value(_value)?)
2135    }
2136
2137    /// Flushes a session's pending events to disk.
2138    ///
2139    /// Wire method: `sessions.save`.
2140    ///
2141    /// # Parameters
2142    ///
2143    /// * `params` - Session ID whose pending events should be flushed to disk.
2144    ///
2145    /// # Returns
2146    ///
2147    /// Flush a session's pending events to disk. No-op when no writer exists for the session (e.g., already closed).
2148    ///
2149    /// <div class="warning">
2150    ///
2151    /// **Experimental.** This API is part of an experimental wire-protocol surface
2152    /// and may change or be removed in future SDK or CLI releases. Pin both the
2153    /// SDK and CLI versions if your code depends on it.
2154    ///
2155    /// </div>
2156    pub async fn save(&self, params: SessionsSaveRequest) -> Result<SessionsSaveResult, Error> {
2157        let wire_params = serde_json::to_value(params)?;
2158        let _value = self
2159            .client
2160            .call(rpc_methods::SESSIONS_SAVE, Some(wire_params))
2161            .await?;
2162        Ok(serde_json::from_value(_value)?)
2163    }
2164
2165    /// Releases the in-use lock held by this process for a session.
2166    ///
2167    /// Wire method: `sessions.releaseLock`.
2168    ///
2169    /// # Parameters
2170    ///
2171    /// * `params` - Session ID whose in-use lock should be released.
2172    ///
2173    /// # Returns
2174    ///
2175    /// Release the in-use lock held by this process for the given session. No-op when this process does not currently hold a lock for the session.
2176    ///
2177    /// <div class="warning">
2178    ///
2179    /// **Experimental.** This API is part of an experimental wire-protocol surface
2180    /// and may change or be removed in future SDK or CLI releases. Pin both the
2181    /// SDK and CLI versions if your code depends on it.
2182    ///
2183    /// </div>
2184    pub async fn release_lock(
2185        &self,
2186        params: SessionsReleaseLockRequest,
2187    ) -> Result<SessionsReleaseLockResult, Error> {
2188        let wire_params = serde_json::to_value(params)?;
2189        let _value = self
2190            .client
2191            .call(rpc_methods::SESSIONS_RELEASELOCK, Some(wire_params))
2192            .await?;
2193        Ok(serde_json::from_value(_value)?)
2194    }
2195
2196    /// Backfills missing summary and context fields on the supplied session metadata records.
2197    ///
2198    /// Wire method: `sessions.enrichMetadata`.
2199    ///
2200    /// # Parameters
2201    ///
2202    /// * `params` - Session metadata records to enrich with summary and context information.
2203    ///
2204    /// # Returns
2205    ///
2206    /// The enriched metadata records, with summary and context fields backfilled where available. Sessions confirmed empty and unnamed are omitted.
2207    ///
2208    /// <div class="warning">
2209    ///
2210    /// **Experimental.** This API is part of an experimental wire-protocol surface
2211    /// and may change or be removed in future SDK or CLI releases. Pin both the
2212    /// SDK and CLI versions if your code depends on it.
2213    ///
2214    /// </div>
2215    pub async fn enrich_metadata(
2216        &self,
2217        params: SessionsEnrichMetadataRequest,
2218    ) -> Result<SessionEnrichMetadataResult, Error> {
2219        let wire_params = serde_json::to_value(params)?;
2220        let _value = self
2221            .client
2222            .call(rpc_methods::SESSIONS_ENRICHMETADATA, Some(wire_params))
2223            .await?;
2224        Ok(serde_json::from_value(_value)?)
2225    }
2226
2227    /// Reloads user, plugin, and (optionally) repo hooks on the active session.
2228    ///
2229    /// Wire method: `sessions.reloadPluginHooks`.
2230    ///
2231    /// # Parameters
2232    ///
2233    /// * `params` - Active session ID and an optional flag for deferring repo-level hooks until folder trust.
2234    ///
2235    /// # Returns
2236    ///
2237    /// Reload all hooks (user, plugin, optionally repo) and apply them to the active session. Call after installing or removing plugins so their hooks take effect immediately. No-op when no active session matches the given sessionId.
2238    ///
2239    /// <div class="warning">
2240    ///
2241    /// **Experimental.** This API is part of an experimental wire-protocol surface
2242    /// and may change or be removed in future SDK or CLI releases. Pin both the
2243    /// SDK and CLI versions if your code depends on it.
2244    ///
2245    /// </div>
2246    pub async fn reload_plugin_hooks(
2247        &self,
2248        params: SessionsReloadPluginHooksRequest,
2249    ) -> Result<SessionsReloadPluginHooksResult, Error> {
2250        let wire_params = serde_json::to_value(params)?;
2251        let _value = self
2252            .client
2253            .call(rpc_methods::SESSIONS_RELOADPLUGINHOOKS, Some(wire_params))
2254            .await?;
2255        Ok(serde_json::from_value(_value)?)
2256    }
2257
2258    /// Loads previously-deferred repo-level hooks on the active session, returning queued startup prompts.
2259    ///
2260    /// Wire method: `sessions.loadDeferredRepoHooks`.
2261    ///
2262    /// # Parameters
2263    ///
2264    /// * `params` - Active session ID whose deferred repo-level hooks should be loaded.
2265    ///
2266    /// # Returns
2267    ///
2268    /// Queued repo-level startup prompts and the total hook command count after loading.
2269    ///
2270    /// <div class="warning">
2271    ///
2272    /// **Experimental.** This API is part of an experimental wire-protocol surface
2273    /// and may change or be removed in future SDK or CLI releases. Pin both the
2274    /// SDK and CLI versions if your code depends on it.
2275    ///
2276    /// </div>
2277    pub async fn load_deferred_repo_hooks(
2278        &self,
2279        params: SessionsLoadDeferredRepoHooksRequest,
2280    ) -> Result<SessionLoadDeferredRepoHooksResult, Error> {
2281        let wire_params = serde_json::to_value(params)?;
2282        let _value = self
2283            .client
2284            .call(
2285                rpc_methods::SESSIONS_LOADDEFERREDREPOHOOKS,
2286                Some(wire_params),
2287            )
2288            .await?;
2289        Ok(serde_json::from_value(_value)?)
2290    }
2291
2292    /// Replaces the manager-wide additional plugins registered with the session manager.
2293    ///
2294    /// Wire method: `sessions.setAdditionalPlugins`.
2295    ///
2296    /// # Parameters
2297    ///
2298    /// * `params` - Manager-wide additional plugins to register; replaces any previously-configured set.
2299    ///
2300    /// # Returns
2301    ///
2302    /// Replace the manager-wide additional plugins. New session creations and subsequent hook reloads see the new set; already-running sessions keep their existing hook installation until the next reload.
2303    ///
2304    /// <div class="warning">
2305    ///
2306    /// **Experimental.** This API is part of an experimental wire-protocol surface
2307    /// and may change or be removed in future SDK or CLI releases. Pin both the
2308    /// SDK and CLI versions if your code depends on it.
2309    ///
2310    /// </div>
2311    pub async fn set_additional_plugins(
2312        &self,
2313        params: SessionsSetAdditionalPluginsRequest,
2314    ) -> Result<SessionsSetAdditionalPluginsResult, Error> {
2315        let wire_params = serde_json::to_value(params)?;
2316        let _value = self
2317            .client
2318            .call(
2319                rpc_methods::SESSIONS_SETADDITIONALPLUGINS,
2320                Some(wire_params),
2321            )
2322            .await?;
2323        Ok(serde_json::from_value(_value)?)
2324    }
2325
2326    /// Gets the dynamic-context board entry count associated with a session, when available. Internal: this exists solely so CLI telemetry events (`rem_spawn_gate`, `rem_consolidation_complete`) can pair START / END board counts around the detached rem-agent spawn. "Dynamic context board" is a runtime-internal concept that is not part of the public SDK contract; the long-term plan is to relocate the telemetry emission into the runtime so this method can be deleted entirely.
2327    ///
2328    /// Wire method: `sessions.getBoardEntryCount`.
2329    ///
2330    /// # Parameters
2331    ///
2332    /// * `params` - Session ID whose board entry count should be returned.
2333    ///
2334    /// # Returns
2335    ///
2336    /// Dynamic-context board entry count, when available.
2337    ///
2338    /// <div class="warning">
2339    ///
2340    /// **Experimental.** This API is part of an experimental wire-protocol surface
2341    /// and may change or be removed in future SDK or CLI releases. Pin both the
2342    /// SDK and CLI versions if your code depends on it.
2343    ///
2344    /// </div>
2345    pub(crate) async fn get_board_entry_count(
2346        &self,
2347        params: SessionsGetBoardEntryCountRequest,
2348    ) -> Result<SessionsGetBoardEntryCountResult, Error> {
2349        let wire_params = serde_json::to_value(params)?;
2350        let _value = self
2351            .client
2352            .call(rpc_methods::SESSIONS_GETBOARDENTRYCOUNT, Some(wire_params))
2353            .await?;
2354        Ok(serde_json::from_value(_value)?)
2355    }
2356
2357    /// Attaches the runtime-managed remote-control singleton to a session, awaiting initial setup. If remote control is already attached to a different session, the singleton is transferred (preserving the underlying Mission Control connection). Returns the final status.
2358    ///
2359    /// Wire method: `sessions.startRemoteControl`.
2360    ///
2361    /// # Parameters
2362    ///
2363    /// * `params` - Parameters for attaching the remote-control singleton to a session.
2364    ///
2365    /// # Returns
2366    ///
2367    /// Wrapper for the singleton's current status.
2368    ///
2369    /// <div class="warning">
2370    ///
2371    /// **Experimental.** This API is part of an experimental wire-protocol surface
2372    /// and may change or be removed in future SDK or CLI releases. Pin both the
2373    /// SDK and CLI versions if your code depends on it.
2374    ///
2375    /// </div>
2376    pub async fn start_remote_control(
2377        &self,
2378        params: SessionsStartRemoteControlRequest,
2379    ) -> Result<RemoteControlStatusResult, Error> {
2380        let wire_params = serde_json::to_value(params)?;
2381        let _value = self
2382            .client
2383            .call(rpc_methods::SESSIONS_STARTREMOTECONTROL, Some(wire_params))
2384            .await?;
2385        Ok(serde_json::from_value(_value)?)
2386    }
2387
2388    /// Atomically rebinds the remote-control singleton to a different session, preserving the underlying Mission Control connection. When `expectedFromSessionId` is provided and does not match the singleton's current `attachedSessionId`, the transfer is rejected with `transferred: false` and the current status is returned unchanged.
2389    ///
2390    /// Wire method: `sessions.transferRemoteControl`.
2391    ///
2392    /// # Parameters
2393    ///
2394    /// * `params` - Parameters for atomically rebinding the remote-control singleton.
2395    ///
2396    /// # Returns
2397    ///
2398    /// Outcome of a transferRemoteControl call.
2399    ///
2400    /// <div class="warning">
2401    ///
2402    /// **Experimental.** This API is part of an experimental wire-protocol surface
2403    /// and may change or be removed in future SDK or CLI releases. Pin both the
2404    /// SDK and CLI versions if your code depends on it.
2405    ///
2406    /// </div>
2407    pub async fn transfer_remote_control(
2408        &self,
2409        params: SessionsTransferRemoteControlRequest,
2410    ) -> Result<RemoteControlTransferResult, Error> {
2411        let wire_params = serde_json::to_value(params)?;
2412        let _value = self
2413            .client
2414            .call(
2415                rpc_methods::SESSIONS_TRANSFERREMOTECONTROL,
2416                Some(wire_params),
2417            )
2418            .await?;
2419        Ok(serde_json::from_value(_value)?)
2420    }
2421
2422    /// Patches the steering state of the active remote-control singleton. When remote control is off, this is a no-op and the off status is returned. Today only `enabled: true` is actionable on the underlying exporter; passing `false` is reserved for future use.
2423    ///
2424    /// Wire method: `sessions.setRemoteControlSteering`.
2425    ///
2426    /// # Parameters
2427    ///
2428    /// * `params` - Patch for the singleton's steering state.
2429    ///
2430    /// # Returns
2431    ///
2432    /// Wrapper for the singleton's current status.
2433    ///
2434    /// <div class="warning">
2435    ///
2436    /// **Experimental.** This API is part of an experimental wire-protocol surface
2437    /// and may change or be removed in future SDK or CLI releases. Pin both the
2438    /// SDK and CLI versions if your code depends on it.
2439    ///
2440    /// </div>
2441    pub async fn set_remote_control_steering(
2442        &self,
2443        params: SessionsSetRemoteControlSteeringRequest,
2444    ) -> Result<RemoteControlStatusResult, Error> {
2445        let wire_params = serde_json::to_value(params)?;
2446        let _value = self
2447            .client
2448            .call(
2449                rpc_methods::SESSIONS_SETREMOTECONTROLSTEERING,
2450                Some(wire_params),
2451            )
2452            .await?;
2453        Ok(serde_json::from_value(_value)?)
2454    }
2455
2456    /// Stops the remote-control singleton. When `expectedSessionId` is provided and does not match the singleton's current `attachedSessionId`, the stop is rejected with `stopped: false` and the current status is returned unchanged (unless `force` is set, in which case the singleton is unconditionally torn down).
2457    ///
2458    /// Wire method: `sessions.stopRemoteControl`.
2459    ///
2460    /// # Returns
2461    ///
2462    /// Outcome of a stopRemoteControl call.
2463    ///
2464    /// <div class="warning">
2465    ///
2466    /// **Experimental.** This API is part of an experimental wire-protocol surface
2467    /// and may change or be removed in future SDK or CLI releases. Pin both the
2468    /// SDK and CLI versions if your code depends on it.
2469    ///
2470    /// </div>
2471    pub async fn stop_remote_control(&self) -> Result<RemoteControlStopResult, Error> {
2472        let wire_params = serde_json::json!({});
2473        let _value = self
2474            .client
2475            .call(rpc_methods::SESSIONS_STOPREMOTECONTROL, Some(wire_params))
2476            .await?;
2477        Ok(serde_json::from_value(_value)?)
2478    }
2479
2480    /// Stops the remote-control singleton. When `expectedSessionId` is provided and does not match the singleton's current `attachedSessionId`, the stop is rejected with `stopped: false` and the current status is returned unchanged (unless `force` is set, in which case the singleton is unconditionally torn down).
2481    ///
2482    /// Wire method: `sessions.stopRemoteControl`.
2483    ///
2484    /// # Parameters
2485    ///
2486    /// * `params` - Parameters for stopping the remote-control singleton.
2487    ///
2488    /// # Returns
2489    ///
2490    /// Outcome of a stopRemoteControl call.
2491    ///
2492    /// <div class="warning">
2493    ///
2494    /// **Experimental.** This API is part of an experimental wire-protocol surface
2495    /// and may change or be removed in future SDK or CLI releases. Pin both the
2496    /// SDK and CLI versions if your code depends on it.
2497    ///
2498    /// </div>
2499    pub async fn stop_remote_control_with_params(
2500        &self,
2501        params: SessionsStopRemoteControlRequest,
2502    ) -> Result<RemoteControlStopResult, Error> {
2503        let wire_params = serde_json::to_value(params)?;
2504        let _value = self
2505            .client
2506            .call(rpc_methods::SESSIONS_STOPREMOTECONTROL, Some(wire_params))
2507            .await?;
2508        Ok(serde_json::from_value(_value)?)
2509    }
2510
2511    /// Returns the current state of the remote-control singleton, including the attached session id and frontend URL when active.
2512    ///
2513    /// Wire method: `sessions.getRemoteControlStatus`.
2514    ///
2515    /// # Returns
2516    ///
2517    /// Wrapper for the singleton's current status.
2518    ///
2519    /// <div class="warning">
2520    ///
2521    /// **Experimental.** This API is part of an experimental wire-protocol surface
2522    /// and may change or be removed in future SDK or CLI releases. Pin both the
2523    /// SDK and CLI versions if your code depends on it.
2524    ///
2525    /// </div>
2526    pub async fn get_remote_control_status(&self) -> Result<RemoteControlStatusResult, Error> {
2527        let wire_params = serde_json::json!({});
2528        let _value = self
2529            .client
2530            .call(
2531                rpc_methods::SESSIONS_GETREMOTECONTROLSTATUS,
2532                Some(wire_params),
2533            )
2534            .await?;
2535        Ok(serde_json::from_value(_value)?)
2536    }
2537
2538    /// Registers extension-provided tools on the given session, gated by an optional `enabled` callback. Returns an opaque unsubscribe function the caller must invoke to deregister the tools when the extension is torn down. Marked internal because `loader`, `enabled`, and the returned `unsubscribe` are in-process handles that cannot cross the JSON-RPC boundary. Disappears once extension discovery / launch / tool registration are owned by the runtime: SDK consumers will pass pure config (search paths, disabled ids) via `SessionOptions` and the runtime will resolve, launch, register, and tear down extensions itself.
2539    ///
2540    /// Wire method: `sessions.registerExtensionToolsOnSession`.
2541    ///
2542    /// # Parameters
2543    ///
2544    /// * `params` - Params to attach an extension loader's tools to a session.
2545    ///
2546    /// # Returns
2547    ///
2548    /// Handle for releasing the extension tool registration.
2549    ///
2550    /// <div class="warning">
2551    ///
2552    /// **Experimental.** This API is part of an experimental wire-protocol surface
2553    /// and may change or be removed in future SDK or CLI releases. Pin both the
2554    /// SDK and CLI versions if your code depends on it.
2555    ///
2556    /// </div>
2557    pub(crate) async fn register_extension_tools_on_session(
2558        &self,
2559        params: RegisterExtensionToolsParams,
2560    ) -> Result<RegisterExtensionToolsResult, Error> {
2561        let wire_params = serde_json::to_value(params)?;
2562        let _value = self
2563            .client
2564            .call(
2565                rpc_methods::SESSIONS_REGISTEREXTENSIONTOOLSONSESSION,
2566                Some(wire_params),
2567            )
2568            .await?;
2569        Ok(serde_json::from_value(_value)?)
2570    }
2571
2572    /// Attaches (or detaches) an in-process ExtensionController delegate for the given session, used by shared-API surfaces that need to query or modify the session's extension state. Pass `controller: undefined` to detach. Marked internal because the controller is an in-process object that cannot cross the JSON-RPC boundary. Disappears alongside `registerExtensionToolsOnSession`: once the runtime owns extension management, the public surface exposes list/enable/disable/reload as dedicated RPCs served by the runtime.
2573    ///
2574    /// Wire method: `sessions.configureSessionExtensions`.
2575    ///
2576    /// # Parameters
2577    ///
2578    /// * `params` - Params to attach or detach an in-process ExtensionController delegate.
2579    ///
2580    /// <div class="warning">
2581    ///
2582    /// **Experimental.** This API is part of an experimental wire-protocol surface
2583    /// and may change or be removed in future SDK or CLI releases. Pin both the
2584    /// SDK and CLI versions if your code depends on it.
2585    ///
2586    /// </div>
2587    pub(crate) async fn configure_session_extensions(
2588        &self,
2589        params: ConfigureSessionExtensionsParams,
2590    ) -> Result<(), Error> {
2591        let wire_params = serde_json::to_value(params)?;
2592        let _value = self
2593            .client
2594            .call(
2595                rpc_methods::SESSIONS_CONFIGURESESSIONEXTENSIONS,
2596                Some(wire_params),
2597            )
2598            .await?;
2599        Ok(())
2600    }
2601}
2602
2603/// `skills.*` RPCs.
2604#[derive(Clone, Copy)]
2605pub struct ClientRpcSkills<'a> {
2606    pub(crate) client: &'a Client,
2607}
2608
2609impl<'a> ClientRpcSkills<'a> {
2610    /// `skills.config.*` sub-namespace.
2611    pub fn config(&self) -> ClientRpcSkillsConfig<'a> {
2612        ClientRpcSkillsConfig {
2613            client: self.client,
2614        }
2615    }
2616
2617    /// Discovers skills across global and project sources.
2618    ///
2619    /// Wire method: `skills.discover`.
2620    ///
2621    /// # Parameters
2622    ///
2623    /// * `params` - Optional project paths and additional skill directories to include in discovery.
2624    ///
2625    /// # Returns
2626    ///
2627    /// Skills discovered across global and project sources.
2628    ///
2629    /// <div class="warning">
2630    ///
2631    /// **Experimental.** This API is part of an experimental wire-protocol surface
2632    /// and may change or be removed in future SDK or CLI releases. Pin both the
2633    /// SDK and CLI versions if your code depends on it.
2634    ///
2635    /// </div>
2636    pub async fn discover(&self, params: SkillsDiscoverRequest) -> Result<ServerSkillList, Error> {
2637        let wire_params = serde_json::to_value(params)?;
2638        let _value = self
2639            .client
2640            .call(rpc_methods::SKILLS_DISCOVER, Some(wire_params))
2641            .await?;
2642        Ok(serde_json::from_value(_value)?)
2643    }
2644
2645    /// Returns the canonical directories where a client may create skills that the runtime will recognize, including ones that do not exist yet. Project directories become active once created.
2646    ///
2647    /// Wire method: `skills.getDiscoveryPaths`.
2648    ///
2649    /// # Parameters
2650    ///
2651    /// * `params` - Optional project paths to enumerate.
2652    ///
2653    /// # Returns
2654    ///
2655    /// Canonical locations where skills can be created so the runtime will recognize them.
2656    ///
2657    /// <div class="warning">
2658    ///
2659    /// **Experimental.** This API is part of an experimental wire-protocol surface
2660    /// and may change or be removed in future SDK or CLI releases. Pin both the
2661    /// SDK and CLI versions if your code depends on it.
2662    ///
2663    /// </div>
2664    pub async fn get_discovery_paths(
2665        &self,
2666        params: SkillsGetDiscoveryPathsRequest,
2667    ) -> Result<SkillDiscoveryPathList, Error> {
2668        let wire_params = serde_json::to_value(params)?;
2669        let _value = self
2670            .client
2671            .call(rpc_methods::SKILLS_GETDISCOVERYPATHS, Some(wire_params))
2672            .await?;
2673        Ok(serde_json::from_value(_value)?)
2674    }
2675}
2676
2677/// `skills.config.*` RPCs.
2678#[derive(Clone, Copy)]
2679pub struct ClientRpcSkillsConfig<'a> {
2680    pub(crate) client: &'a Client,
2681}
2682
2683impl<'a> ClientRpcSkillsConfig<'a> {
2684    /// Replaces the global list of disabled skills.
2685    ///
2686    /// Wire method: `skills.config.setDisabledSkills`.
2687    ///
2688    /// # Parameters
2689    ///
2690    /// * `params` - Skill names to mark as disabled in global configuration, replacing any previous list.
2691    ///
2692    /// <div class="warning">
2693    ///
2694    /// **Experimental.** This API is part of an experimental wire-protocol surface
2695    /// and may change or be removed in future SDK or CLI releases. Pin both the
2696    /// SDK and CLI versions if your code depends on it.
2697    ///
2698    /// </div>
2699    pub async fn set_disabled_skills(
2700        &self,
2701        params: SkillsConfigSetDisabledSkillsRequest,
2702    ) -> Result<(), Error> {
2703        let wire_params = serde_json::to_value(params)?;
2704        let _value = self
2705            .client
2706            .call(
2707                rpc_methods::SKILLS_CONFIG_SETDISABLEDSKILLS,
2708                Some(wire_params),
2709            )
2710            .await?;
2711        Ok(())
2712    }
2713}
2714
2715/// `tools.*` RPCs.
2716#[derive(Clone, Copy)]
2717pub struct ClientRpcTools<'a> {
2718    pub(crate) client: &'a Client,
2719}
2720
2721impl<'a> ClientRpcTools<'a> {
2722    /// Lists built-in tools available for a model.
2723    ///
2724    /// Wire method: `tools.list`.
2725    ///
2726    /// # Parameters
2727    ///
2728    /// * `params` - Optional model identifier whose tool overrides should be applied to the listing.
2729    ///
2730    /// # Returns
2731    ///
2732    /// Built-in tools available for the requested model, with their parameters and instructions.
2733    ///
2734    /// <div class="warning">
2735    ///
2736    /// **Experimental.** This API is part of an experimental wire-protocol surface
2737    /// and may change or be removed in future SDK or CLI releases. Pin both the
2738    /// SDK and CLI versions if your code depends on it.
2739    ///
2740    /// </div>
2741    pub async fn list(&self, params: ToolsListRequest) -> Result<ToolList, Error> {
2742        let wire_params = serde_json::to_value(params)?;
2743        let _value = self
2744            .client
2745            .call(rpc_methods::TOOLS_LIST, Some(wire_params))
2746            .await?;
2747        Ok(serde_json::from_value(_value)?)
2748    }
2749}
2750
2751/// `user.*` RPCs.
2752#[derive(Clone, Copy)]
2753pub struct ClientRpcUser<'a> {
2754    pub(crate) client: &'a Client,
2755}
2756
2757impl<'a> ClientRpcUser<'a> {
2758    /// `user.settings.*` sub-namespace.
2759    pub fn settings(&self) -> ClientRpcUserSettings<'a> {
2760        ClientRpcUserSettings {
2761            client: self.client,
2762        }
2763    }
2764}
2765
2766/// `user.settings.*` RPCs.
2767#[derive(Clone, Copy)]
2768pub struct ClientRpcUserSettings<'a> {
2769    pub(crate) client: &'a Client,
2770}
2771
2772impl<'a> ClientRpcUserSettings<'a> {
2773    /// Drops this runtime process's in-memory user settings cache so the next settings read observes disk.
2774    ///
2775    /// Wire method: `user.settings.reload`.
2776    ///
2777    /// <div class="warning">
2778    ///
2779    /// **Experimental.** This API is part of an experimental wire-protocol surface
2780    /// and may change or be removed in future SDK or CLI releases. Pin both the
2781    /// SDK and CLI versions if your code depends on it.
2782    ///
2783    /// </div>
2784    pub async fn reload(&self) -> Result<(), Error> {
2785        let wire_params = serde_json::json!({});
2786        let _value = self
2787            .client
2788            .call(rpc_methods::USER_SETTINGS_RELOAD, Some(wire_params))
2789            .await?;
2790        Ok(())
2791    }
2792
2793    /// Lists every known user setting (settings.json overlaid with the legacy config.json, config.json wins), each with its effective value, its default, and whether it is at the default — so settings the user has never set still appear with their default value. Does not include repository- or enterprise-managed overrides that the runtime layers on top at session time.
2794    ///
2795    /// Wire method: `user.settings.get`.
2796    ///
2797    /// # Returns
2798    ///
2799    /// Per-key metadata for every known user setting (settings.json overlaid with the legacy config.json, config.json wins), including settings left at their default. Excludes repository- and enterprise-managed overrides.
2800    ///
2801    /// <div class="warning">
2802    ///
2803    /// **Experimental.** This API is part of an experimental wire-protocol surface
2804    /// and may change or be removed in future SDK or CLI releases. Pin both the
2805    /// SDK and CLI versions if your code depends on it.
2806    ///
2807    /// </div>
2808    pub async fn get(&self) -> Result<UserSettingsGetResult, Error> {
2809        let wire_params = serde_json::json!({});
2810        let _value = self
2811            .client
2812            .call(rpc_methods::USER_SETTINGS_GET, Some(wire_params))
2813            .await?;
2814        Ok(serde_json::from_value(_value)?)
2815    }
2816
2817    /// Writes one or more user settings to settings.json, replacing each provided top-level key. A key whose value is null is removed. Returns the keys whose new value is shadowed by a legacy config.json entry (config.json wins on read), which the runtime leaves in place — such writes do not take effect until the legacy value is removed.
2818    ///
2819    /// Wire method: `user.settings.set`.
2820    ///
2821    /// # Parameters
2822    ///
2823    /// * `params` - Partial user settings to write to settings.json. Each top-level key is written individually, replacing the existing value; a key whose value is null is removed.
2824    ///
2825    /// # Returns
2826    ///
2827    /// Outcome of writing user settings.
2828    ///
2829    /// <div class="warning">
2830    ///
2831    /// **Experimental.** This API is part of an experimental wire-protocol surface
2832    /// and may change or be removed in future SDK or CLI releases. Pin both the
2833    /// SDK and CLI versions if your code depends on it.
2834    ///
2835    /// </div>
2836    pub async fn set(
2837        &self,
2838        params: UserSettingsSetRequest,
2839    ) -> Result<UserSettingsSetResult, Error> {
2840        let wire_params = serde_json::to_value(params)?;
2841        let _value = self
2842            .client
2843            .call(rpc_methods::USER_SETTINGS_SET, Some(wire_params))
2844            .await?;
2845        Ok(serde_json::from_value(_value)?)
2846    }
2847}
2848
2849/// Typed view over a [`Session`]'s RPC namespace.
2850#[derive(Clone, Copy)]
2851pub struct SessionRpc<'a> {
2852    pub(crate) session: &'a Session,
2853}
2854
2855impl<'a> SessionRpc<'a> {
2856    /// `session.agent.*` sub-namespace.
2857    pub fn agent(&self) -> SessionRpcAgent<'a> {
2858        SessionRpcAgent {
2859            session: self.session,
2860        }
2861    }
2862
2863    /// `session.canvas.*` sub-namespace.
2864    pub fn canvas(&self) -> SessionRpcCanvas<'a> {
2865        SessionRpcCanvas {
2866            session: self.session,
2867        }
2868    }
2869
2870    /// `session.commands.*` sub-namespace.
2871    pub fn commands(&self) -> SessionRpcCommands<'a> {
2872        SessionRpcCommands {
2873            session: self.session,
2874        }
2875    }
2876
2877    /// `session.completions.*` sub-namespace.
2878    pub fn completions(&self) -> SessionRpcCompletions<'a> {
2879        SessionRpcCompletions {
2880            session: self.session,
2881        }
2882    }
2883
2884    /// `session.contentExclusion.*` sub-namespace.
2885    pub fn content_exclusion(&self) -> SessionRpcContentExclusion<'a> {
2886        SessionRpcContentExclusion {
2887            session: self.session,
2888        }
2889    }
2890
2891    /// `session.debug.*` sub-namespace.
2892    pub fn debug(&self) -> SessionRpcDebug<'a> {
2893        SessionRpcDebug {
2894            session: self.session,
2895        }
2896    }
2897
2898    /// `session.eventLog.*` sub-namespace.
2899    pub fn event_log(&self) -> SessionRpcEventLog<'a> {
2900        SessionRpcEventLog {
2901            session: self.session,
2902        }
2903    }
2904
2905    /// `session.extensions.*` sub-namespace.
2906    pub fn extensions(&self) -> SessionRpcExtensions<'a> {
2907        SessionRpcExtensions {
2908            session: self.session,
2909        }
2910    }
2911
2912    /// `session.factory.*` sub-namespace.
2913    pub fn factory(&self) -> SessionRpcFactory<'a> {
2914        SessionRpcFactory {
2915            session: self.session,
2916        }
2917    }
2918
2919    /// `session.fleet.*` sub-namespace.
2920    pub fn fleet(&self) -> SessionRpcFleet<'a> {
2921        SessionRpcFleet {
2922            session: self.session,
2923        }
2924    }
2925
2926    /// `session.gitHubAuth.*` sub-namespace.
2927    pub fn git_hub_auth(&self) -> SessionRpcGitHubAuth<'a> {
2928        SessionRpcGitHubAuth {
2929            session: self.session,
2930        }
2931    }
2932
2933    /// `session.history.*` sub-namespace.
2934    pub fn history(&self) -> SessionRpcHistory<'a> {
2935        SessionRpcHistory {
2936            session: self.session,
2937        }
2938    }
2939
2940    /// `session.instructions.*` sub-namespace.
2941    pub fn instructions(&self) -> SessionRpcInstructions<'a> {
2942        SessionRpcInstructions {
2943            session: self.session,
2944        }
2945    }
2946
2947    /// `session.limitPrediction.*` sub-namespace.
2948    pub fn limit_prediction(&self) -> SessionRpcLimitPrediction<'a> {
2949        SessionRpcLimitPrediction {
2950            session: self.session,
2951        }
2952    }
2953
2954    /// `session.lsp.*` sub-namespace.
2955    pub fn lsp(&self) -> SessionRpcLsp<'a> {
2956        SessionRpcLsp {
2957            session: self.session,
2958        }
2959    }
2960
2961    /// `session.mcp.*` sub-namespace.
2962    pub fn mcp(&self) -> SessionRpcMcp<'a> {
2963        SessionRpcMcp {
2964            session: self.session,
2965        }
2966    }
2967
2968    /// `session.metadata.*` sub-namespace.
2969    pub fn metadata(&self) -> SessionRpcMetadata<'a> {
2970        SessionRpcMetadata {
2971            session: self.session,
2972        }
2973    }
2974
2975    /// `session.mode.*` sub-namespace.
2976    pub fn mode(&self) -> SessionRpcMode<'a> {
2977        SessionRpcMode {
2978            session: self.session,
2979        }
2980    }
2981
2982    /// `session.model.*` sub-namespace.
2983    pub fn model(&self) -> SessionRpcModel<'a> {
2984        SessionRpcModel {
2985            session: self.session,
2986        }
2987    }
2988
2989    /// `session.name.*` sub-namespace.
2990    pub fn name(&self) -> SessionRpcName<'a> {
2991        SessionRpcName {
2992            session: self.session,
2993        }
2994    }
2995
2996    /// `session.options.*` sub-namespace.
2997    pub fn options(&self) -> SessionRpcOptions<'a> {
2998        SessionRpcOptions {
2999            session: self.session,
3000        }
3001    }
3002
3003    /// `session.permissions.*` sub-namespace.
3004    pub fn permissions(&self) -> SessionRpcPermissions<'a> {
3005        SessionRpcPermissions {
3006            session: self.session,
3007        }
3008    }
3009
3010    /// `session.plan.*` sub-namespace.
3011    pub fn plan(&self) -> SessionRpcPlan<'a> {
3012        SessionRpcPlan {
3013            session: self.session,
3014        }
3015    }
3016
3017    /// `session.plugins.*` sub-namespace.
3018    pub fn plugins(&self) -> SessionRpcPlugins<'a> {
3019        SessionRpcPlugins {
3020            session: self.session,
3021        }
3022    }
3023
3024    /// `session.provider.*` sub-namespace.
3025    pub fn provider(&self) -> SessionRpcProvider<'a> {
3026        SessionRpcProvider {
3027            session: self.session,
3028        }
3029    }
3030
3031    /// `session.queue.*` sub-namespace.
3032    pub fn queue(&self) -> SessionRpcQueue<'a> {
3033        SessionRpcQueue {
3034            session: self.session,
3035        }
3036    }
3037
3038    /// `session.remote.*` sub-namespace.
3039    pub fn remote(&self) -> SessionRpcRemote<'a> {
3040        SessionRpcRemote {
3041            session: self.session,
3042        }
3043    }
3044
3045    /// `session.schedule.*` sub-namespace.
3046    pub fn schedule(&self) -> SessionRpcSchedule<'a> {
3047        SessionRpcSchedule {
3048            session: self.session,
3049        }
3050    }
3051
3052    /// `session.settings.*` sub-namespace.
3053    pub fn settings(&self) -> SessionRpcSettings<'a> {
3054        SessionRpcSettings {
3055            session: self.session,
3056        }
3057    }
3058
3059    /// `session.shell.*` sub-namespace.
3060    pub fn shell(&self) -> SessionRpcShell<'a> {
3061        SessionRpcShell {
3062            session: self.session,
3063        }
3064    }
3065
3066    /// `session.skills.*` sub-namespace.
3067    pub fn skills(&self) -> SessionRpcSkills<'a> {
3068        SessionRpcSkills {
3069            session: self.session,
3070        }
3071    }
3072
3073    /// `session.tasks.*` sub-namespace.
3074    pub fn tasks(&self) -> SessionRpcTasks<'a> {
3075        SessionRpcTasks {
3076            session: self.session,
3077        }
3078    }
3079
3080    /// `session.telemetry.*` sub-namespace.
3081    pub fn telemetry(&self) -> SessionRpcTelemetry<'a> {
3082        SessionRpcTelemetry {
3083            session: self.session,
3084        }
3085    }
3086
3087    /// `session.tools.*` sub-namespace.
3088    pub fn tools(&self) -> SessionRpcTools<'a> {
3089        SessionRpcTools {
3090            session: self.session,
3091        }
3092    }
3093
3094    /// `session.ui.*` sub-namespace.
3095    pub fn ui(&self) -> SessionRpcUi<'a> {
3096        SessionRpcUi {
3097            session: self.session,
3098        }
3099    }
3100
3101    /// `session.usage.*` sub-namespace.
3102    pub fn usage(&self) -> SessionRpcUsage<'a> {
3103        SessionRpcUsage {
3104            session: self.session,
3105        }
3106    }
3107
3108    /// `session.visibility.*` sub-namespace.
3109    pub fn visibility(&self) -> SessionRpcVisibility<'a> {
3110        SessionRpcVisibility {
3111            session: self.session,
3112        }
3113    }
3114
3115    /// `session.workspaces.*` sub-namespace.
3116    pub fn workspaces(&self) -> SessionRpcWorkspaces<'a> {
3117        SessionRpcWorkspaces {
3118            session: self.session,
3119        }
3120    }
3121
3122    /// Suspends the session while preserving persisted state for later resume.
3123    ///
3124    /// Wire method: `session.suspend`.
3125    ///
3126    /// <div class="warning">
3127    ///
3128    /// **Experimental.** This API is part of an experimental wire-protocol surface
3129    /// and may change or be removed in future SDK or CLI releases. Pin both the
3130    /// SDK and CLI versions if your code depends on it.
3131    ///
3132    /// </div>
3133    pub async fn suspend(&self) -> Result<(), Error> {
3134        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
3135        let _value = self
3136            .session
3137            .client()
3138            .call(rpc_methods::SESSION_SUSPEND, Some(wire_params))
3139            .await?;
3140        Ok(())
3141    }
3142
3143    /// Sends a user message to the session and returns its message ID.
3144    ///
3145    /// Wire method: `session.send`.
3146    ///
3147    /// # Parameters
3148    ///
3149    /// * `params` - Parameters for sending a user message to the session
3150    ///
3151    /// # Returns
3152    ///
3153    /// Result of sending a user message
3154    ///
3155    /// <div class="warning">
3156    ///
3157    /// **Experimental.** This API is part of an experimental wire-protocol surface
3158    /// and may change or be removed in future SDK or CLI releases. Pin both the
3159    /// SDK and CLI versions if your code depends on it.
3160    ///
3161    /// </div>
3162    pub async fn send(&self, params: SendRequest) -> Result<SendResult, Error> {
3163        let mut wire_params = serde_json::to_value(params)?;
3164        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3165        let _value = self
3166            .session
3167            .client()
3168            .call(rpc_methods::SESSION_SEND, Some(wire_params))
3169            .await?;
3170        Ok(serde_json::from_value(_value)?)
3171    }
3172
3173    /// Sends zero or more user messages to the session in a single turn and returns their message IDs. All provided messages are appended to the conversation in order, then exactly one agent turn runs over the resulting history. When the list is empty, one turn runs over the existing history with no new user message. Remote-backed (Mission Control) sessions do not support this method and will return an error.
3174    ///
3175    /// Wire method: `session.sendMessages`.
3176    ///
3177    /// # Parameters
3178    ///
3179    /// * `params` - Parameters for sending zero or more user messages to the session in a single turn. Remote-backed (Mission Control) sessions do not support this method and will return an error.
3180    ///
3181    /// # Returns
3182    ///
3183    /// Result of sending zero or more user messages
3184    ///
3185    /// <div class="warning">
3186    ///
3187    /// **Experimental.** This API is part of an experimental wire-protocol surface
3188    /// and may change or be removed in future SDK or CLI releases. Pin both the
3189    /// SDK and CLI versions if your code depends on it.
3190    ///
3191    /// </div>
3192    pub async fn send_messages(
3193        &self,
3194        params: SendMessagesRequest,
3195    ) -> Result<SendMessagesResult, Error> {
3196        let mut wire_params = serde_json::to_value(params)?;
3197        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3198        let _value = self
3199            .session
3200            .client()
3201            .call(rpc_methods::SESSION_SENDMESSAGES, Some(wire_params))
3202            .await?;
3203        Ok(serde_json::from_value(_value)?)
3204    }
3205
3206    /// Queues or sends an internal system notification to the session according to its passive policy.
3207    ///
3208    /// Wire method: `session.sendSystemNotification`.
3209    ///
3210    /// # Parameters
3211    ///
3212    /// * `params` - Internal request for sending a system notification.
3213    ///
3214    /// <div class="warning">
3215    ///
3216    /// **Experimental.** This API is part of an experimental wire-protocol surface
3217    /// and may change or be removed in future SDK or CLI releases. Pin both the
3218    /// SDK and CLI versions if your code depends on it.
3219    ///
3220    /// </div>
3221    pub(crate) async fn send_system_notification(
3222        &self,
3223        params: SendSystemNotificationRequest,
3224    ) -> Result<(), Error> {
3225        let mut wire_params = serde_json::to_value(params)?;
3226        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3227        let _value = self
3228            .session
3229            .client()
3230            .call(
3231                rpc_methods::SESSION_SENDSYSTEMNOTIFICATION,
3232                Some(wire_params),
3233            )
3234            .await?;
3235        Ok(())
3236    }
3237
3238    /// Aborts the current agent turn.
3239    ///
3240    /// Wire method: `session.abort`.
3241    ///
3242    /// # Parameters
3243    ///
3244    /// * `params` - Parameters for aborting the current turn
3245    ///
3246    /// # Returns
3247    ///
3248    /// Result of aborting the current turn
3249    ///
3250    /// <div class="warning">
3251    ///
3252    /// **Experimental.** This API is part of an experimental wire-protocol surface
3253    /// and may change or be removed in future SDK or CLI releases. Pin both the
3254    /// SDK and CLI versions if your code depends on it.
3255    ///
3256    /// </div>
3257    pub async fn abort(&self, params: AbortRequest) -> Result<AbortResult, Error> {
3258        let mut wire_params = serde_json::to_value(params)?;
3259        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3260        let _value = self
3261            .session
3262            .client()
3263            .call(rpc_methods::SESSION_ABORT, Some(wire_params))
3264            .await?;
3265        Ok(serde_json::from_value(_value)?)
3266    }
3267
3268    /// Interrupts the current main agent turn while leaving running background work (subagents, sidekicks, and promoted attached shells) alive. No-op when the main loop is not processing.
3269    ///
3270    /// Wire method: `session.interruptMainTurn`.
3271    ///
3272    /// # Parameters
3273    ///
3274    /// * `params` - Parameters for interrupting the main agent turn.
3275    ///
3276    /// # Returns
3277    ///
3278    /// Result of interrupting the main agent turn.
3279    ///
3280    /// <div class="warning">
3281    ///
3282    /// **Experimental.** This API is part of an experimental wire-protocol surface
3283    /// and may change or be removed in future SDK or CLI releases. Pin both the
3284    /// SDK and CLI versions if your code depends on it.
3285    ///
3286    /// </div>
3287    pub async fn interrupt_main_turn(
3288        &self,
3289        params: InterruptMainTurnRequest,
3290    ) -> Result<InterruptMainTurnResult, Error> {
3291        let mut wire_params = serde_json::to_value(params)?;
3292        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3293        let _value = self
3294            .session
3295            .client()
3296            .call(rpc_methods::SESSION_INTERRUPTMAINTURN, Some(wire_params))
3297            .await?;
3298        Ok(serde_json::from_value(_value)?)
3299    }
3300
3301    /// Cancels every running background agent (task-registry subagents plus sidekick agents) without interrupting the main agent loop. Promoted attached shells are left running.
3302    ///
3303    /// Wire method: `session.cancelAllBackgroundAgents`.
3304    ///
3305    /// # Returns
3306    ///
3307    /// The number of running background agents (task-registry agents) that were cancelled.
3308    ///
3309    /// <div class="warning">
3310    ///
3311    /// **Experimental.** This API is part of an experimental wire-protocol surface
3312    /// and may change or be removed in future SDK or CLI releases. Pin both the
3313    /// SDK and CLI versions if your code depends on it.
3314    ///
3315    /// </div>
3316    pub async fn cancel_all_background_agents(
3317        &self,
3318    ) -> Result<SessionCancelAllBackgroundAgentsResult, Error> {
3319        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
3320        let _value = self
3321            .session
3322            .client()
3323            .call(
3324                rpc_methods::SESSION_CANCELALLBACKGROUNDAGENTS,
3325                Some(wire_params),
3326            )
3327            .await?;
3328        Ok(serde_json::from_value(_value)?)
3329    }
3330
3331    /// Shuts down the session and persists its final state. Awaits any deferred sessionEnd hooks before resolving so user-supplied hook scripts complete before the runtime tears down.
3332    ///
3333    /// Wire method: `session.shutdown`.
3334    ///
3335    /// # Parameters
3336    ///
3337    /// * `params` - Parameters for shutting down the session
3338    ///
3339    /// <div class="warning">
3340    ///
3341    /// **Experimental.** This API is part of an experimental wire-protocol surface
3342    /// and may change or be removed in future SDK or CLI releases. Pin both the
3343    /// SDK and CLI versions if your code depends on it.
3344    ///
3345    /// </div>
3346    pub async fn shutdown(&self, params: ShutdownRequest) -> Result<(), Error> {
3347        let mut wire_params = serde_json::to_value(params)?;
3348        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3349        let _value = self
3350            .session
3351            .client()
3352            .call(rpc_methods::SESSION_SHUTDOWN, Some(wire_params))
3353            .await?;
3354        Ok(())
3355    }
3356
3357    /// Emits a user-visible session log event.
3358    ///
3359    /// Wire method: `session.log`.
3360    ///
3361    /// # Parameters
3362    ///
3363    /// * `params` - Message text, optional severity level, persistence flag, optional follow-up URL, and optional tip.
3364    ///
3365    /// # Returns
3366    ///
3367    /// Identifier of the session event that was emitted for the log message.
3368    ///
3369    /// <div class="warning">
3370    ///
3371    /// **Experimental.** This API is part of an experimental wire-protocol surface
3372    /// and may change or be removed in future SDK or CLI releases. Pin both the
3373    /// SDK and CLI versions if your code depends on it.
3374    ///
3375    /// </div>
3376    pub async fn log(&self, params: LogRequest) -> Result<LogResult, Error> {
3377        let mut wire_params = serde_json::to_value(params)?;
3378        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3379        let _value = self
3380            .session
3381            .client()
3382            .call(rpc_methods::SESSION_LOG, Some(wire_params))
3383            .await?;
3384        Ok(serde_json::from_value(_value)?)
3385    }
3386}
3387
3388/// `session.agent.*` RPCs.
3389#[derive(Clone, Copy)]
3390pub struct SessionRpcAgent<'a> {
3391    pub(crate) session: &'a Session,
3392}
3393
3394impl<'a> SessionRpcAgent<'a> {
3395    /// Lists agents available to the session. Defaults to custom agents only; pass includeBuiltInAgents to include the effective built-in agents.
3396    ///
3397    /// Wire method: `session.agent.list`.
3398    ///
3399    /// # Returns
3400    ///
3401    /// Agents available to the session.
3402    ///
3403    /// <div class="warning">
3404    ///
3405    /// **Experimental.** This API is part of an experimental wire-protocol surface
3406    /// and may change or be removed in future SDK or CLI releases. Pin both the
3407    /// SDK and CLI versions if your code depends on it.
3408    ///
3409    /// </div>
3410    pub async fn list(&self) -> Result<AgentList, Error> {
3411        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
3412        let _value = self
3413            .session
3414            .client()
3415            .call(rpc_methods::SESSION_AGENT_LIST, Some(wire_params))
3416            .await?;
3417        Ok(serde_json::from_value(_value)?)
3418    }
3419
3420    /// Lists agents available to the session. Defaults to custom agents only; pass includeBuiltInAgents to include the effective built-in agents.
3421    ///
3422    /// Wire method: `session.agent.list`.
3423    ///
3424    /// # Parameters
3425    ///
3426    /// * `params` - Controls whether built-in agents and authored prompt text are included.
3427    ///
3428    /// # Returns
3429    ///
3430    /// Agents available to the session.
3431    ///
3432    /// <div class="warning">
3433    ///
3434    /// **Experimental.** This API is part of an experimental wire-protocol surface
3435    /// and may change or be removed in future SDK or CLI releases. Pin both the
3436    /// SDK and CLI versions if your code depends on it.
3437    ///
3438    /// </div>
3439    pub async fn list_with_params(&self, params: AgentListRequest) -> Result<AgentList, Error> {
3440        let mut wire_params = serde_json::to_value(params)?;
3441        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3442        let _value = self
3443            .session
3444            .client()
3445            .call(rpc_methods::SESSION_AGENT_LIST, Some(wire_params))
3446            .await?;
3447        Ok(serde_json::from_value(_value)?)
3448    }
3449
3450    /// Sets an in-memory authored prompt override for an available agent. For built-in agents, this replaces only the static base prompt while preserving runtime-owned dynamic prompt composition and behavior. The special `general-purpose` agent is not overrideable. Overrides are not persisted; resumed and forked sessions start without them, so the host must re-apply them.
3451    ///
3452    /// Wire method: `session.agent.setPrompt`.
3453    ///
3454    /// # Parameters
3455    ///
3456    /// * `params` - An in-memory authored prompt override for an available agent.
3457    ///
3458    /// <div class="warning">
3459    ///
3460    /// **Experimental.** This API is part of an experimental wire-protocol surface
3461    /// and may change or be removed in future SDK or CLI releases. Pin both the
3462    /// SDK and CLI versions if your code depends on it.
3463    ///
3464    /// </div>
3465    pub async fn set_prompt(&self, params: AgentSetPromptRequest) -> Result<(), Error> {
3466        let mut wire_params = serde_json::to_value(params)?;
3467        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3468        let _value = self
3469            .session
3470            .client()
3471            .call(rpc_methods::SESSION_AGENT_SETPROMPT, Some(wire_params))
3472            .await?;
3473        Ok(())
3474    }
3475
3476    /// Gets the currently selected custom agent for the session.
3477    ///
3478    /// Wire method: `session.agent.getCurrent`.
3479    ///
3480    /// # Returns
3481    ///
3482    /// The currently selected custom agent, or null when using the default agent.
3483    ///
3484    /// <div class="warning">
3485    ///
3486    /// **Experimental.** This API is part of an experimental wire-protocol surface
3487    /// and may change or be removed in future SDK or CLI releases. Pin both the
3488    /// SDK and CLI versions if your code depends on it.
3489    ///
3490    /// </div>
3491    pub async fn get_current(&self) -> Result<AgentGetCurrentResult, Error> {
3492        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
3493        let _value = self
3494            .session
3495            .client()
3496            .call(rpc_methods::SESSION_AGENT_GETCURRENT, Some(wire_params))
3497            .await?;
3498        Ok(serde_json::from_value(_value)?)
3499    }
3500
3501    /// Selects a custom agent for subsequent turns in the session.
3502    ///
3503    /// Wire method: `session.agent.select`.
3504    ///
3505    /// # Parameters
3506    ///
3507    /// * `params` - Name of the custom agent to select for subsequent turns.
3508    ///
3509    /// # Returns
3510    ///
3511    /// The newly selected custom agent.
3512    ///
3513    /// <div class="warning">
3514    ///
3515    /// **Experimental.** This API is part of an experimental wire-protocol surface
3516    /// and may change or be removed in future SDK or CLI releases. Pin both the
3517    /// SDK and CLI versions if your code depends on it.
3518    ///
3519    /// </div>
3520    pub async fn select(&self, params: AgentSelectRequest) -> Result<AgentSelectResult, Error> {
3521        let mut wire_params = serde_json::to_value(params)?;
3522        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3523        let _value = self
3524            .session
3525            .client()
3526            .call(rpc_methods::SESSION_AGENT_SELECT, Some(wire_params))
3527            .await?;
3528        Ok(serde_json::from_value(_value)?)
3529    }
3530
3531    /// Clears the selected custom agent and returns the session to the default agent.
3532    ///
3533    /// Wire method: `session.agent.deselect`.
3534    ///
3535    /// <div class="warning">
3536    ///
3537    /// **Experimental.** This API is part of an experimental wire-protocol surface
3538    /// and may change or be removed in future SDK or CLI releases. Pin both the
3539    /// SDK and CLI versions if your code depends on it.
3540    ///
3541    /// </div>
3542    pub async fn deselect(&self) -> Result<(), Error> {
3543        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
3544        let _value = self
3545            .session
3546            .client()
3547            .call(rpc_methods::SESSION_AGENT_DESELECT, Some(wire_params))
3548            .await?;
3549        Ok(())
3550    }
3551
3552    /// Reloads custom agent definitions and returns the refreshed list.
3553    ///
3554    /// Wire method: `session.agent.reload`.
3555    ///
3556    /// # Returns
3557    ///
3558    /// Custom agents available to the session after reloading definitions from disk.
3559    ///
3560    /// <div class="warning">
3561    ///
3562    /// **Experimental.** This API is part of an experimental wire-protocol surface
3563    /// and may change or be removed in future SDK or CLI releases. Pin both the
3564    /// SDK and CLI versions if your code depends on it.
3565    ///
3566    /// </div>
3567    pub async fn reload(&self) -> Result<AgentReloadResult, Error> {
3568        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
3569        let _value = self
3570            .session
3571            .client()
3572            .call(rpc_methods::SESSION_AGENT_RELOAD, Some(wire_params))
3573            .await?;
3574        Ok(serde_json::from_value(_value)?)
3575    }
3576}
3577
3578/// `session.canvas.*` RPCs.
3579#[derive(Clone, Copy)]
3580pub struct SessionRpcCanvas<'a> {
3581    pub(crate) session: &'a Session,
3582}
3583
3584impl<'a> SessionRpcCanvas<'a> {
3585    /// `session.canvas.action.*` sub-namespace.
3586    pub fn action(&self) -> SessionRpcCanvasAction<'a> {
3587        SessionRpcCanvasAction {
3588            session: self.session,
3589        }
3590    }
3591
3592    /// Lists canvases declared for the session.
3593    ///
3594    /// Wire method: `session.canvas.list`.
3595    ///
3596    /// # Returns
3597    ///
3598    /// Declared canvases available in this session.
3599    ///
3600    /// <div class="warning">
3601    ///
3602    /// **Experimental.** This API is part of an experimental wire-protocol surface
3603    /// and may change or be removed in future SDK or CLI releases. Pin both the
3604    /// SDK and CLI versions if your code depends on it.
3605    ///
3606    /// </div>
3607    pub async fn list(&self) -> Result<CanvasList, Error> {
3608        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
3609        let _value = self
3610            .session
3611            .client()
3612            .call(rpc_methods::SESSION_CANVAS_LIST, Some(wire_params))
3613            .await?;
3614        Ok(serde_json::from_value(_value)?)
3615    }
3616
3617    /// Lists currently open canvas instances for the live session.
3618    ///
3619    /// Wire method: `session.canvas.listOpen`.
3620    ///
3621    /// # Returns
3622    ///
3623    /// Live open-canvas snapshot.
3624    ///
3625    /// <div class="warning">
3626    ///
3627    /// **Experimental.** This API is part of an experimental wire-protocol surface
3628    /// and may change or be removed in future SDK or CLI releases. Pin both the
3629    /// SDK and CLI versions if your code depends on it.
3630    ///
3631    /// </div>
3632    pub async fn list_open(&self) -> Result<CanvasListOpenResult, Error> {
3633        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
3634        let _value = self
3635            .session
3636            .client()
3637            .call(rpc_methods::SESSION_CANVAS_LISTOPEN, Some(wire_params))
3638            .await?;
3639        Ok(serde_json::from_value(_value)?)
3640    }
3641
3642    /// Opens or focuses a canvas instance.
3643    ///
3644    /// Wire method: `session.canvas.open`.
3645    ///
3646    /// # Parameters
3647    ///
3648    /// * `params` - Canvas open parameters.
3649    ///
3650    /// # Returns
3651    ///
3652    /// Open canvas instance snapshot.
3653    ///
3654    /// <div class="warning">
3655    ///
3656    /// **Experimental.** This API is part of an experimental wire-protocol surface
3657    /// and may change or be removed in future SDK or CLI releases. Pin both the
3658    /// SDK and CLI versions if your code depends on it.
3659    ///
3660    /// </div>
3661    pub async fn open(&self, params: CanvasOpenRequest) -> Result<OpenCanvasInstance, Error> {
3662        let mut wire_params = serde_json::to_value(params)?;
3663        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3664        let _value = self
3665            .session
3666            .client()
3667            .call(rpc_methods::SESSION_CANVAS_OPEN, Some(wire_params))
3668            .await?;
3669        Ok(serde_json::from_value(_value)?)
3670    }
3671
3672    /// Closes an open canvas instance.
3673    ///
3674    /// Wire method: `session.canvas.close`.
3675    ///
3676    /// # Parameters
3677    ///
3678    /// * `params` - Canvas close parameters.
3679    ///
3680    /// <div class="warning">
3681    ///
3682    /// **Experimental.** This API is part of an experimental wire-protocol surface
3683    /// and may change or be removed in future SDK or CLI releases. Pin both the
3684    /// SDK and CLI versions if your code depends on it.
3685    ///
3686    /// </div>
3687    pub async fn close(&self, params: CanvasCloseRequest) -> Result<(), Error> {
3688        let mut wire_params = serde_json::to_value(params)?;
3689        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3690        let _value = self
3691            .session
3692            .client()
3693            .call(rpc_methods::SESSION_CANVAS_CLOSE, Some(wire_params))
3694            .await?;
3695        Ok(())
3696    }
3697}
3698
3699/// `session.canvas.action.*` RPCs.
3700#[derive(Clone, Copy)]
3701pub struct SessionRpcCanvasAction<'a> {
3702    pub(crate) session: &'a Session,
3703}
3704
3705impl<'a> SessionRpcCanvasAction<'a> {
3706    /// Invokes an action on an open canvas instance.
3707    ///
3708    /// Wire method: `session.canvas.action.invoke`.
3709    ///
3710    /// # Parameters
3711    ///
3712    /// * `params` - Canvas action invocation parameters.
3713    ///
3714    /// # Returns
3715    ///
3716    /// Canvas action invocation result.
3717    ///
3718    /// <div class="warning">
3719    ///
3720    /// **Experimental.** This API is part of an experimental wire-protocol surface
3721    /// and may change or be removed in future SDK or CLI releases. Pin both the
3722    /// SDK and CLI versions if your code depends on it.
3723    ///
3724    /// </div>
3725    pub async fn invoke(
3726        &self,
3727        params: CanvasActionInvokeRequest,
3728    ) -> Result<CanvasActionInvokeResult, Error> {
3729        let mut wire_params = serde_json::to_value(params)?;
3730        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3731        let _value = self
3732            .session
3733            .client()
3734            .call(rpc_methods::SESSION_CANVAS_ACTION_INVOKE, Some(wire_params))
3735            .await?;
3736        Ok(serde_json::from_value(_value)?)
3737    }
3738}
3739
3740/// `session.commands.*` RPCs.
3741#[derive(Clone, Copy)]
3742pub struct SessionRpcCommands<'a> {
3743    pub(crate) session: &'a Session,
3744}
3745
3746impl<'a> SessionRpcCommands<'a> {
3747    /// Lists slash commands available in the session.
3748    ///
3749    /// Wire method: `session.commands.list`.
3750    ///
3751    /// # Returns
3752    ///
3753    /// Slash commands available in the session, after applying any include/exclude filters.
3754    ///
3755    /// <div class="warning">
3756    ///
3757    /// **Experimental.** This API is part of an experimental wire-protocol surface
3758    /// and may change or be removed in future SDK or CLI releases. Pin both the
3759    /// SDK and CLI versions if your code depends on it.
3760    ///
3761    /// </div>
3762    pub async fn list(&self) -> Result<CommandList, Error> {
3763        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
3764        let _value = self
3765            .session
3766            .client()
3767            .call(rpc_methods::SESSION_COMMANDS_LIST, Some(wire_params))
3768            .await?;
3769        Ok(serde_json::from_value(_value)?)
3770    }
3771
3772    /// Lists slash commands available in the session.
3773    ///
3774    /// Wire method: `session.commands.list`.
3775    ///
3776    /// # Parameters
3777    ///
3778    /// * `params` - Optional filters controlling which command sources to include in the listing.
3779    ///
3780    /// # Returns
3781    ///
3782    /// Slash commands available in the session, after applying any include/exclude filters.
3783    ///
3784    /// <div class="warning">
3785    ///
3786    /// **Experimental.** This API is part of an experimental wire-protocol surface
3787    /// and may change or be removed in future SDK or CLI releases. Pin both the
3788    /// SDK and CLI versions if your code depends on it.
3789    ///
3790    /// </div>
3791    pub async fn list_with_params(
3792        &self,
3793        params: CommandsListRequest,
3794    ) -> Result<CommandList, Error> {
3795        let mut wire_params = serde_json::to_value(params)?;
3796        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3797        let _value = self
3798            .session
3799            .client()
3800            .call(rpc_methods::SESSION_COMMANDS_LIST, Some(wire_params))
3801            .await?;
3802        Ok(serde_json::from_value(_value)?)
3803    }
3804
3805    /// Invokes a slash command in the session.
3806    ///
3807    /// Wire method: `session.commands.invoke`.
3808    ///
3809    /// # Parameters
3810    ///
3811    /// * `params` - Slash command name and optional raw input string to invoke.
3812    ///
3813    /// # Returns
3814    ///
3815    /// Result of invoking the slash command (text output, prompt to send to the agent, completion, or subcommand selection).
3816    ///
3817    /// <div class="warning">
3818    ///
3819    /// **Experimental.** This API is part of an experimental wire-protocol surface
3820    /// and may change or be removed in future SDK or CLI releases. Pin both the
3821    /// SDK and CLI versions if your code depends on it.
3822    ///
3823    /// </div>
3824    pub async fn invoke(
3825        &self,
3826        params: CommandsInvokeRequest,
3827    ) -> Result<SlashCommandInvocationResult, Error> {
3828        let mut wire_params = serde_json::to_value(params)?;
3829        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3830        let _value = self
3831            .session
3832            .client()
3833            .call(rpc_methods::SESSION_COMMANDS_INVOKE, Some(wire_params))
3834            .await?;
3835        Ok(serde_json::from_value(_value)?)
3836    }
3837
3838    /// Reports completion of a pending client-handled slash command.
3839    ///
3840    /// Wire method: `session.commands.handlePendingCommand`.
3841    ///
3842    /// # Parameters
3843    ///
3844    /// * `params` - Pending command request ID and an optional error if the client handler failed.
3845    ///
3846    /// # Returns
3847    ///
3848    /// Indicates whether the pending client-handled command was completed successfully.
3849    ///
3850    /// <div class="warning">
3851    ///
3852    /// **Experimental.** This API is part of an experimental wire-protocol surface
3853    /// and may change or be removed in future SDK or CLI releases. Pin both the
3854    /// SDK and CLI versions if your code depends on it.
3855    ///
3856    /// </div>
3857    pub async fn handle_pending_command(
3858        &self,
3859        params: CommandsHandlePendingCommandRequest,
3860    ) -> Result<CommandsHandlePendingCommandResult, Error> {
3861        let mut wire_params = serde_json::to_value(params)?;
3862        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3863        let _value = self
3864            .session
3865            .client()
3866            .call(
3867                rpc_methods::SESSION_COMMANDS_HANDLEPENDINGCOMMAND,
3868                Some(wire_params),
3869            )
3870            .await?;
3871        Ok(serde_json::from_value(_value)?)
3872    }
3873
3874    /// Executes a slash command synchronously and returns any error.
3875    ///
3876    /// Wire method: `session.commands.execute`.
3877    ///
3878    /// # Parameters
3879    ///
3880    /// * `params` - Slash command name and argument string to execute synchronously.
3881    ///
3882    /// # Returns
3883    ///
3884    /// Error message produced while executing the command, if any.
3885    ///
3886    /// <div class="warning">
3887    ///
3888    /// **Experimental.** This API is part of an experimental wire-protocol surface
3889    /// and may change or be removed in future SDK or CLI releases. Pin both the
3890    /// SDK and CLI versions if your code depends on it.
3891    ///
3892    /// </div>
3893    pub async fn execute(
3894        &self,
3895        params: ExecuteCommandParams,
3896    ) -> Result<ExecuteCommandResult, Error> {
3897        let mut wire_params = serde_json::to_value(params)?;
3898        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3899        let _value = self
3900            .session
3901            .client()
3902            .call(rpc_methods::SESSION_COMMANDS_EXECUTE, Some(wire_params))
3903            .await?;
3904        Ok(serde_json::from_value(_value)?)
3905    }
3906
3907    /// Enqueues a slash command for FIFO processing on the local session.
3908    ///
3909    /// Wire method: `session.commands.enqueue`.
3910    ///
3911    /// # Parameters
3912    ///
3913    /// * `params` - Slash-prefixed command string to enqueue for FIFO processing.
3914    ///
3915    /// # Returns
3916    ///
3917    /// Indicates whether the command was accepted into the local execution queue.
3918    ///
3919    /// <div class="warning">
3920    ///
3921    /// **Experimental.** This API is part of an experimental wire-protocol surface
3922    /// and may change or be removed in future SDK or CLI releases. Pin both the
3923    /// SDK and CLI versions if your code depends on it.
3924    ///
3925    /// </div>
3926    pub async fn enqueue(
3927        &self,
3928        params: EnqueueCommandParams,
3929    ) -> Result<EnqueueCommandResult, Error> {
3930        let mut wire_params = serde_json::to_value(params)?;
3931        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3932        let _value = self
3933            .session
3934            .client()
3935            .call(rpc_methods::SESSION_COMMANDS_ENQUEUE, Some(wire_params))
3936            .await?;
3937        Ok(serde_json::from_value(_value)?)
3938    }
3939
3940    /// Reports whether the host actually executed a queued command and whether to continue processing.
3941    ///
3942    /// Wire method: `session.commands.respondToQueuedCommand`.
3943    ///
3944    /// # Parameters
3945    ///
3946    /// * `params` - Queued-command request ID and the result indicating whether the host executed it (and whether to stop processing further queued commands).
3947    ///
3948    /// # Returns
3949    ///
3950    /// Indicates whether the queued-command response was matched to a pending request.
3951    ///
3952    /// <div class="warning">
3953    ///
3954    /// **Experimental.** This API is part of an experimental wire-protocol surface
3955    /// and may change or be removed in future SDK or CLI releases. Pin both the
3956    /// SDK and CLI versions if your code depends on it.
3957    ///
3958    /// </div>
3959    pub async fn respond_to_queued_command(
3960        &self,
3961        params: CommandsRespondToQueuedCommandRequest,
3962    ) -> Result<CommandsRespondToQueuedCommandResult, Error> {
3963        let mut wire_params = serde_json::to_value(params)?;
3964        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3965        let _value = self
3966            .session
3967            .client()
3968            .call(
3969                rpc_methods::SESSION_COMMANDS_RESPONDTOQUEUEDCOMMAND,
3970                Some(wire_params),
3971            )
3972            .await?;
3973        Ok(serde_json::from_value(_value)?)
3974    }
3975}
3976
3977/// `session.completions.*` RPCs.
3978#[derive(Clone, Copy)]
3979pub struct SessionRpcCompletions<'a> {
3980    pub(crate) session: &'a Session,
3981}
3982
3983impl<'a> SessionRpcCompletions<'a> {
3984    /// Gets the characters that should trigger host-driven completions for the session. Empty disables host-driven completions (e.g. local sessions, or a relay host that does not advertise them).
3985    ///
3986    /// Wire method: `session.completions.getTriggerCharacters`.
3987    ///
3988    /// # Returns
3989    ///
3990    /// Characters that, when typed in the composer, should trigger a `completions.request`. Empty when the session has no host-driven completions (e.g. local sessions, or a relay host that does not advertise `completionTriggerCharacters`).
3991    ///
3992    /// <div class="warning">
3993    ///
3994    /// **Experimental.** This API is part of an experimental wire-protocol surface
3995    /// and may change or be removed in future SDK or CLI releases. Pin both the
3996    /// SDK and CLI versions if your code depends on it.
3997    ///
3998    /// </div>
3999    pub async fn get_trigger_characters(
4000        &self,
4001    ) -> Result<CompletionsGetTriggerCharactersResult, Error> {
4002        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
4003        let _value = self
4004            .session
4005            .client()
4006            .call(
4007                rpc_methods::SESSION_COMPLETIONS_GETTRIGGERCHARACTERS,
4008                Some(wire_params),
4009            )
4010            .await?;
4011        Ok(serde_json::from_value(_value)?)
4012    }
4013
4014    /// Requests host-driven completion items for the current composer input. Returns an empty list when the host has no items or does not support completions.
4015    ///
4016    /// Wire method: `session.completions.request`.
4017    ///
4018    /// # Parameters
4019    ///
4020    /// * `params` - Request host-driven completions for the current composer input.
4021    ///
4022    /// # Returns
4023    ///
4024    /// Host-driven completion items for the current composer input. Empty when the host returns no items or does not support completions.
4025    ///
4026    /// <div class="warning">
4027    ///
4028    /// **Experimental.** This API is part of an experimental wire-protocol surface
4029    /// and may change or be removed in future SDK or CLI releases. Pin both the
4030    /// SDK and CLI versions if your code depends on it.
4031    ///
4032    /// </div>
4033    pub async fn request(
4034        &self,
4035        params: CompletionsRequestRequest,
4036    ) -> Result<CompletionsRequestResult, Error> {
4037        let mut wire_params = serde_json::to_value(params)?;
4038        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4039        let _value = self
4040            .session
4041            .client()
4042            .call(rpc_methods::SESSION_COMPLETIONS_REQUEST, Some(wire_params))
4043            .await?;
4044        Ok(serde_json::from_value(_value)?)
4045    }
4046}
4047
4048/// `session.contentExclusion.*` RPCs.
4049#[derive(Clone, Copy)]
4050pub struct SessionRpcContentExclusion<'a> {
4051    pub(crate) session: &'a Session,
4052}
4053
4054impl<'a> SessionRpcContentExclusion<'a> {
4055    /// Checks local file system absolute paths within the session working directory against its content-exclusion policy. Results preserve input order. Unsupported paths/filesystems and unavailable policy evaluation return available false, and callers must treat every requested path as excluded.
4056    ///
4057    /// Wire method: `session.contentExclusion.checkPaths`.
4058    ///
4059    /// # Parameters
4060    ///
4061    /// * `params` - Local file system absolute paths within the session working directory to check against its content-exclusion policy.
4062    ///
4063    /// # Returns
4064    ///
4065    /// Batch content-exclusion result. Callers must fail closed when policy evaluation is unavailable.
4066    ///
4067    /// <div class="warning">
4068    ///
4069    /// **Experimental.** This API is part of an experimental wire-protocol surface
4070    /// and may change or be removed in future SDK or CLI releases. Pin both the
4071    /// SDK and CLI versions if your code depends on it.
4072    ///
4073    /// </div>
4074    pub async fn check_paths(
4075        &self,
4076        params: ContentExclusionCheckPathsRequest,
4077    ) -> Result<ContentExclusionCheckPathsResult, Error> {
4078        let mut wire_params = serde_json::to_value(params)?;
4079        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4080        let _value = self
4081            .session
4082            .client()
4083            .call(
4084                rpc_methods::SESSION_CONTENTEXCLUSION_CHECKPATHS,
4085                Some(wire_params),
4086            )
4087            .await?;
4088        Ok(serde_json::from_value(_value)?)
4089    }
4090}
4091
4092/// `session.debug.*` RPCs.
4093#[derive(Clone, Copy)]
4094pub struct SessionRpcDebug<'a> {
4095    pub(crate) session: &'a Session,
4096}
4097
4098impl<'a> SessionRpcDebug<'a> {
4099    /// Collects a redacted session debug log bundle into a local archive or staging directory. The runtime includes session-owned logs by default and accepts caller-provided diagnostic entries so host applications can add their own files without changing this API shape.
4100    ///
4101    /// Wire method: `session.debug.collectLogs`.
4102    ///
4103    /// # Parameters
4104    ///
4105    /// * `params` - Options for collecting a redacted session debug bundle.
4106    ///
4107    /// # Returns
4108    ///
4109    /// Result of collecting a redacted debug bundle.
4110    ///
4111    /// <div class="warning">
4112    ///
4113    /// **Experimental.** This API is part of an experimental wire-protocol surface
4114    /// and may change or be removed in future SDK or CLI releases. Pin both the
4115    /// SDK and CLI versions if your code depends on it.
4116    ///
4117    /// </div>
4118    pub async fn collect_logs(
4119        &self,
4120        params: DebugCollectLogsRequest,
4121    ) -> Result<DebugCollectLogsResult, Error> {
4122        let mut wire_params = serde_json::to_value(params)?;
4123        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4124        let _value = self
4125            .session
4126            .client()
4127            .call(rpc_methods::SESSION_DEBUG_COLLECTLOGS, Some(wire_params))
4128            .await?;
4129        Ok(serde_json::from_value(_value)?)
4130    }
4131}
4132
4133/// `session.eventLog.*` RPCs.
4134#[derive(Clone, Copy)]
4135pub struct SessionRpcEventLog<'a> {
4136    pub(crate) session: &'a Session,
4137}
4138
4139impl<'a> SessionRpcEventLog<'a> {
4140    /// Reads a batch of session events from a cursor, optionally waiting for new events. Supports tail-first reads via `direction: backward`.
4141    ///
4142    /// Wire method: `session.eventLog.read`.
4143    ///
4144    /// # Parameters
4145    ///
4146    /// * `params` - Cursor, batch size, and optional long-poll/filter parameters for reading session events.
4147    ///
4148    /// # Returns
4149    ///
4150    /// Batch of session events returned by a read, with cursor and continuation metadata.
4151    ///
4152    /// <div class="warning">
4153    ///
4154    /// **Experimental.** This API is part of an experimental wire-protocol surface
4155    /// and may change or be removed in future SDK or CLI releases. Pin both the
4156    /// SDK and CLI versions if your code depends on it.
4157    ///
4158    /// </div>
4159    pub async fn read(&self, params: EventLogReadRequest) -> Result<EventsReadResult, Error> {
4160        let mut wire_params = serde_json::to_value(params)?;
4161        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4162        let _value = self
4163            .session
4164            .client()
4165            .call(rpc_methods::SESSION_EVENTLOG_READ, Some(wire_params))
4166            .await?;
4167        Ok(serde_json::from_value(_value)?)
4168    }
4169
4170    /// Returns a snapshot of the current tail cursor without consuming events.
4171    ///
4172    /// Wire method: `session.eventLog.tail`.
4173    ///
4174    /// # Returns
4175    ///
4176    /// Snapshot of the current tail cursor without returning any events. Use this when a consumer wants to subscribe to live events going forward without first paginating through the entire persisted history (which would happen if `read` were called without a cursor on a long-lived session).
4177    ///
4178    /// <div class="warning">
4179    ///
4180    /// **Experimental.** This API is part of an experimental wire-protocol surface
4181    /// and may change or be removed in future SDK or CLI releases. Pin both the
4182    /// SDK and CLI versions if your code depends on it.
4183    ///
4184    /// </div>
4185    pub async fn tail(&self) -> Result<EventLogTailResult, Error> {
4186        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
4187        let _value = self
4188            .session
4189            .client()
4190            .call(rpc_methods::SESSION_EVENTLOG_TAIL, Some(wire_params))
4191            .await?;
4192        Ok(serde_json::from_value(_value)?)
4193    }
4194
4195    /// Registers consumer interest in an event type for runtime gating purposes.
4196    ///
4197    /// Wire method: `session.eventLog.registerInterest`.
4198    ///
4199    /// # Parameters
4200    ///
4201    /// * `params` - Event type to register consumer interest for, used by runtime gating logic.
4202    ///
4203    /// # Returns
4204    ///
4205    /// Opaque handle representing an event-type interest registration.
4206    ///
4207    /// <div class="warning">
4208    ///
4209    /// **Experimental.** This API is part of an experimental wire-protocol surface
4210    /// and may change or be removed in future SDK or CLI releases. Pin both the
4211    /// SDK and CLI versions if your code depends on it.
4212    ///
4213    /// </div>
4214    pub async fn register_interest(
4215        &self,
4216        params: RegisterEventInterestParams,
4217    ) -> Result<RegisterEventInterestResult, Error> {
4218        let mut wire_params = serde_json::to_value(params)?;
4219        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4220        let _value = self
4221            .session
4222            .client()
4223            .call(
4224                rpc_methods::SESSION_EVENTLOG_REGISTERINTEREST,
4225                Some(wire_params),
4226            )
4227            .await?;
4228        Ok(serde_json::from_value(_value)?)
4229    }
4230
4231    /// Releases a consumer's previously-registered interest in an event type.
4232    ///
4233    /// Wire method: `session.eventLog.releaseInterest`.
4234    ///
4235    /// # Parameters
4236    ///
4237    /// * `params` - Opaque handle previously returned by `registerInterest` to release.
4238    ///
4239    /// # Returns
4240    ///
4241    /// Indicates whether the operation succeeded.
4242    ///
4243    /// <div class="warning">
4244    ///
4245    /// **Experimental.** This API is part of an experimental wire-protocol surface
4246    /// and may change or be removed in future SDK or CLI releases. Pin both the
4247    /// SDK and CLI versions if your code depends on it.
4248    ///
4249    /// </div>
4250    pub async fn release_interest(
4251        &self,
4252        params: ReleaseEventInterestParams,
4253    ) -> Result<EventLogReleaseInterestResult, Error> {
4254        let mut wire_params = serde_json::to_value(params)?;
4255        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4256        let _value = self
4257            .session
4258            .client()
4259            .call(
4260                rpc_methods::SESSION_EVENTLOG_RELEASEINTEREST,
4261                Some(wire_params),
4262            )
4263            .await?;
4264        Ok(serde_json::from_value(_value)?)
4265    }
4266}
4267
4268/// `session.extensions.*` RPCs.
4269#[derive(Clone, Copy)]
4270pub struct SessionRpcExtensions<'a> {
4271    pub(crate) session: &'a Session,
4272}
4273
4274impl<'a> SessionRpcExtensions<'a> {
4275    /// Lists extensions discovered for the session and their current status.
4276    ///
4277    /// Wire method: `session.extensions.list`.
4278    ///
4279    /// # Returns
4280    ///
4281    /// Extensions discovered for the session, with their current status.
4282    ///
4283    /// <div class="warning">
4284    ///
4285    /// **Experimental.** This API is part of an experimental wire-protocol surface
4286    /// and may change or be removed in future SDK or CLI releases. Pin both the
4287    /// SDK and CLI versions if your code depends on it.
4288    ///
4289    /// </div>
4290    pub async fn list(&self) -> Result<ExtensionList, Error> {
4291        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
4292        let _value = self
4293            .session
4294            .client()
4295            .call(rpc_methods::SESSION_EXTENSIONS_LIST, Some(wire_params))
4296            .await?;
4297        Ok(serde_json::from_value(_value)?)
4298    }
4299
4300    /// Enables an extension for the session.
4301    ///
4302    /// Wire method: `session.extensions.enable`.
4303    ///
4304    /// # Parameters
4305    ///
4306    /// * `params` - Source-qualified extension identifier to enable for the session.
4307    ///
4308    /// <div class="warning">
4309    ///
4310    /// **Experimental.** This API is part of an experimental wire-protocol surface
4311    /// and may change or be removed in future SDK or CLI releases. Pin both the
4312    /// SDK and CLI versions if your code depends on it.
4313    ///
4314    /// </div>
4315    pub async fn enable(&self, params: ExtensionsEnableRequest) -> Result<(), Error> {
4316        let mut wire_params = serde_json::to_value(params)?;
4317        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4318        let _value = self
4319            .session
4320            .client()
4321            .call(rpc_methods::SESSION_EXTENSIONS_ENABLE, Some(wire_params))
4322            .await?;
4323        Ok(())
4324    }
4325
4326    /// Disables an extension for the session.
4327    ///
4328    /// Wire method: `session.extensions.disable`.
4329    ///
4330    /// # Parameters
4331    ///
4332    /// * `params` - Source-qualified extension identifier to disable for the session.
4333    ///
4334    /// <div class="warning">
4335    ///
4336    /// **Experimental.** This API is part of an experimental wire-protocol surface
4337    /// and may change or be removed in future SDK or CLI releases. Pin both the
4338    /// SDK and CLI versions if your code depends on it.
4339    ///
4340    /// </div>
4341    pub async fn disable(&self, params: ExtensionsDisableRequest) -> Result<(), Error> {
4342        let mut wire_params = serde_json::to_value(params)?;
4343        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4344        let _value = self
4345            .session
4346            .client()
4347            .call(rpc_methods::SESSION_EXTENSIONS_DISABLE, Some(wire_params))
4348            .await?;
4349        Ok(())
4350    }
4351
4352    /// Reloads extension definitions and processes for the session.
4353    ///
4354    /// Wire method: `session.extensions.reload`.
4355    ///
4356    /// <div class="warning">
4357    ///
4358    /// **Experimental.** This API is part of an experimental wire-protocol surface
4359    /// and may change or be removed in future SDK or CLI releases. Pin both the
4360    /// SDK and CLI versions if your code depends on it.
4361    ///
4362    /// </div>
4363    pub async fn reload(&self) -> Result<(), Error> {
4364        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
4365        let _value = self
4366            .session
4367            .client()
4368            .call(rpc_methods::SESSION_EXTENSIONS_RELOAD, Some(wire_params))
4369            .await?;
4370        Ok(())
4371    }
4372
4373    /// Push attachments into the next user-message turn from an extension. The host should surface them as composer pills and forward them via the next session.send call. Callable only by extension-owned connections.
4374    ///
4375    /// Wire method: `session.extensions.sendAttachmentsToMessage`.
4376    ///
4377    /// # Parameters
4378    ///
4379    /// * `params` - Parameters for session.extensions.sendAttachmentsToMessage.
4380    ///
4381    /// <div class="warning">
4382    ///
4383    /// **Experimental.** This API is part of an experimental wire-protocol surface
4384    /// and may change or be removed in future SDK or CLI releases. Pin both the
4385    /// SDK and CLI versions if your code depends on it.
4386    ///
4387    /// </div>
4388    pub async fn send_attachments_to_message(
4389        &self,
4390        params: SendAttachmentsToMessageParams,
4391    ) -> Result<(), Error> {
4392        let mut wire_params = serde_json::to_value(params)?;
4393        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4394        let _value = self
4395            .session
4396            .client()
4397            .call(
4398                rpc_methods::SESSION_EXTENSIONS_SENDATTACHMENTSTOMESSAGE,
4399                Some(wire_params),
4400            )
4401            .await?;
4402        Ok(())
4403    }
4404}
4405
4406/// `session.factory.*` RPCs.
4407#[derive(Clone, Copy)]
4408pub struct SessionRpcFactory<'a> {
4409    pub(crate) session: &'a Session,
4410}
4411
4412impl<'a> SessionRpcFactory<'a> {
4413    /// `session.factory.journal.*` sub-namespace.
4414    pub fn journal(&self) -> SessionRpcFactoryJournal<'a> {
4415        SessionRpcFactoryJournal {
4416            session: self.session,
4417        }
4418    }
4419
4420    /// Runs a registered factory by name at the top level.
4421    ///
4422    /// Wire method: `session.factory.run`.
4423    ///
4424    /// # Parameters
4425    ///
4426    /// * `params` - Parameters for invoking a registered factory.
4427    ///
4428    /// # Returns
4429    ///
4430    /// Complete current or terminal factory run envelope.
4431    ///
4432    /// <div class="warning">
4433    ///
4434    /// **Experimental.** This API is part of an experimental wire-protocol surface
4435    /// and may change or be removed in future SDK or CLI releases. Pin both the
4436    /// SDK and CLI versions if your code depends on it.
4437    ///
4438    /// </div>
4439    pub async fn run(&self, params: FactoryRunRequest) -> Result<FactoryRunResult, Error> {
4440        let mut wire_params = serde_json::to_value(params)?;
4441        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4442        let _value = self
4443            .session
4444            .client()
4445            .call(rpc_methods::SESSION_FACTORY_RUN, Some(wire_params))
4446            .await?;
4447        Ok(serde_json::from_value(_value)?)
4448    }
4449
4450    /// Resumes a factory run using its persisted name, arguments, journal, and accounting.
4451    ///
4452    /// Wire method: `session.factory.resume`.
4453    ///
4454    /// # Parameters
4455    ///
4456    /// * `params` - Parameters for resuming a factory run from its persisted identity.
4457    ///
4458    /// # Returns
4459    ///
4460    /// Resolved persisted factory identity and resumed run envelope.
4461    ///
4462    /// <div class="warning">
4463    ///
4464    /// **Experimental.** This API is part of an experimental wire-protocol surface
4465    /// and may change or be removed in future SDK or CLI releases. Pin both the
4466    /// SDK and CLI versions if your code depends on it.
4467    ///
4468    /// </div>
4469    pub async fn resume(&self, params: FactoryResumeRequest) -> Result<FactoryResumeResult, Error> {
4470        let mut wire_params = serde_json::to_value(params)?;
4471        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4472        let _value = self
4473            .session
4474            .client()
4475            .call(rpc_methods::SESSION_FACTORY_RESUME, Some(wire_params))
4476            .await?;
4477        Ok(serde_json::from_value(_value)?)
4478    }
4479
4480    /// Gets the current or settled envelope for a factory run.
4481    ///
4482    /// Wire method: `session.factory.getRun`.
4483    ///
4484    /// # Parameters
4485    ///
4486    /// * `params` - Parameters for retrieving a factory run.
4487    ///
4488    /// # Returns
4489    ///
4490    /// Complete current or terminal factory run envelope.
4491    ///
4492    /// <div class="warning">
4493    ///
4494    /// **Experimental.** This API is part of an experimental wire-protocol surface
4495    /// and may change or be removed in future SDK or CLI releases. Pin both the
4496    /// SDK and CLI versions if your code depends on it.
4497    ///
4498    /// </div>
4499    pub async fn get_run(&self, params: FactoryGetRunRequest) -> Result<FactoryRunResult, Error> {
4500        let mut wire_params = serde_json::to_value(params)?;
4501        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4502        let _value = self
4503            .session
4504            .client()
4505            .call(rpc_methods::SESSION_FACTORY_GETRUN, Some(wire_params))
4506            .await?;
4507        Ok(serde_json::from_value(_value)?)
4508    }
4509
4510    /// Lists durable factory runs for this session in creation order.
4511    ///
4512    /// Wire method: `session.factory.listRuns`.
4513    ///
4514    /// # Parameters
4515    ///
4516    /// * `params` - Parameters for paging factory runs.
4517    ///
4518    /// # Returns
4519    ///
4520    /// A page of factory runs in durable creation order.
4521    ///
4522    /// <div class="warning">
4523    ///
4524    /// **Experimental.** This API is part of an experimental wire-protocol surface
4525    /// and may change or be removed in future SDK or CLI releases. Pin both the
4526    /// SDK and CLI versions if your code depends on it.
4527    ///
4528    /// </div>
4529    pub async fn list_runs(
4530        &self,
4531        params: FactoryListRunsRequest,
4532    ) -> Result<FactoryListRunsResult, Error> {
4533        let mut wire_params = serde_json::to_value(params)?;
4534        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4535        let _value = self
4536            .session
4537            .client()
4538            .call(rpc_methods::SESSION_FACTORY_LISTRUNS, Some(wire_params))
4539            .await?;
4540        Ok(serde_json::from_value(_value)?)
4541    }
4542
4543    /// Gets durable and live observability detail for one factory run.
4544    ///
4545    /// Wire method: `session.factory.getRunDetail`.
4546    ///
4547    /// # Parameters
4548    ///
4549    /// * `params` - Parameters for retrieving a factory run.
4550    ///
4551    /// # Returns
4552    ///
4553    /// Full factory run observability detail.
4554    ///
4555    /// <div class="warning">
4556    ///
4557    /// **Experimental.** This API is part of an experimental wire-protocol surface
4558    /// and may change or be removed in future SDK or CLI releases. Pin both the
4559    /// SDK and CLI versions if your code depends on it.
4560    ///
4561    /// </div>
4562    pub async fn get_run_detail(
4563        &self,
4564        params: FactoryGetRunRequest,
4565    ) -> Result<FactoryRunDetail, Error> {
4566        let mut wire_params = serde_json::to_value(params)?;
4567        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4568        let _value = self
4569            .session
4570            .client()
4571            .call(rpc_methods::SESSION_FACTORY_GETRUNDETAIL, Some(wire_params))
4572            .await?;
4573        Ok(serde_json::from_value(_value)?)
4574    }
4575
4576    /// Pages durable progress for one factory run.
4577    ///
4578    /// Wire method: `session.factory.getRunProgress`.
4579    ///
4580    /// # Parameters
4581    ///
4582    /// * `params` - Parameters for paging factory progress.
4583    ///
4584    /// # Returns
4585    ///
4586    /// A bidirectional page of factory progress.
4587    ///
4588    /// <div class="warning">
4589    ///
4590    /// **Experimental.** This API is part of an experimental wire-protocol surface
4591    /// and may change or be removed in future SDK or CLI releases. Pin both the
4592    /// SDK and CLI versions if your code depends on it.
4593    ///
4594    /// </div>
4595    pub async fn get_run_progress(
4596        &self,
4597        params: FactoryGetRunProgressRequest,
4598    ) -> Result<FactoryProgressPage, Error> {
4599        let mut wire_params = serde_json::to_value(params)?;
4600        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4601        let _value = self
4602            .session
4603            .client()
4604            .call(
4605                rpc_methods::SESSION_FACTORY_GETRUNPROGRESS,
4606                Some(wire_params),
4607            )
4608            .await?;
4609        Ok(serde_json::from_value(_value)?)
4610    }
4611
4612    /// Requests cancellation of a factory run and returns its run envelope.
4613    ///
4614    /// Wire method: `session.factory.cancel`.
4615    ///
4616    /// # Parameters
4617    ///
4618    /// * `params` - Parameters for cancelling a factory run.
4619    ///
4620    /// # Returns
4621    ///
4622    /// Complete current or terminal factory run envelope.
4623    ///
4624    /// <div class="warning">
4625    ///
4626    /// **Experimental.** This API is part of an experimental wire-protocol surface
4627    /// and may change or be removed in future SDK or CLI releases. Pin both the
4628    /// SDK and CLI versions if your code depends on it.
4629    ///
4630    /// </div>
4631    pub async fn cancel(&self, params: FactoryCancelRequest) -> Result<FactoryRunResult, Error> {
4632        let mut wire_params = serde_json::to_value(params)?;
4633        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4634        let _value = self
4635            .session
4636            .client()
4637            .call(rpc_methods::SESSION_FACTORY_CANCEL, Some(wire_params))
4638            .await?;
4639        Ok(serde_json::from_value(_value)?)
4640    }
4641
4642    /// Records a batch of ordered factory progress lines.
4643    ///
4644    /// Wire method: `session.factory.log`.
4645    ///
4646    /// # Parameters
4647    ///
4648    /// * `params` - Parameters for recording factory progress.
4649    ///
4650    /// # Returns
4651    ///
4652    /// Acknowledgement that a factory request was accepted.
4653    ///
4654    /// <div class="warning">
4655    ///
4656    /// **Experimental.** This API is part of an experimental wire-protocol surface
4657    /// and may change or be removed in future SDK or CLI releases. Pin both the
4658    /// SDK and CLI versions if your code depends on it.
4659    ///
4660    /// </div>
4661    pub async fn log(&self, params: FactoryLogRequest) -> Result<FactoryAckResult, Error> {
4662        let mut wire_params = serde_json::to_value(params)?;
4663        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4664        let _value = self
4665            .session
4666            .client()
4667            .call(rpc_methods::SESSION_FACTORY_LOG, Some(wire_params))
4668            .await?;
4669        Ok(serde_json::from_value(_value)?)
4670    }
4671
4672    /// Runs one factory-scoped subagent and returns its result.
4673    ///
4674    /// Wire method: `session.factory.agent`.
4675    ///
4676    /// # Parameters
4677    ///
4678    /// * `params` - Parameters for one factory-scoped subagent call.
4679    ///
4680    /// # Returns
4681    ///
4682    /// Result of one factory-scoped subagent call.
4683    ///
4684    /// <div class="warning">
4685    ///
4686    /// **Experimental.** This API is part of an experimental wire-protocol surface
4687    /// and may change or be removed in future SDK or CLI releases. Pin both the
4688    /// SDK and CLI versions if your code depends on it.
4689    ///
4690    /// </div>
4691    pub async fn agent(&self, params: FactoryAgentRequest) -> Result<FactoryAgentResult, Error> {
4692        let mut wire_params = serde_json::to_value(params)?;
4693        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4694        let _value = self
4695            .session
4696            .client()
4697            .call(rpc_methods::SESSION_FACTORY_AGENT, Some(wire_params))
4698            .await?;
4699        Ok(serde_json::from_value(_value)?)
4700    }
4701}
4702
4703/// `session.factory.journal.*` RPCs.
4704#[derive(Clone, Copy)]
4705pub struct SessionRpcFactoryJournal<'a> {
4706    pub(crate) session: &'a Session,
4707}
4708
4709impl<'a> SessionRpcFactoryJournal<'a> {
4710    /// Reads a memoized factory journal entry.
4711    ///
4712    /// Wire method: `session.factory.journal.get`.
4713    ///
4714    /// # Parameters
4715    ///
4716    /// * `params` - Parameters for reading a factory journal entry.
4717    ///
4718    /// # Returns
4719    ///
4720    /// Result of reading a factory journal entry.
4721    ///
4722    /// <div class="warning">
4723    ///
4724    /// **Experimental.** This API is part of an experimental wire-protocol surface
4725    /// and may change or be removed in future SDK or CLI releases. Pin both the
4726    /// SDK and CLI versions if your code depends on it.
4727    ///
4728    /// </div>
4729    pub async fn get(
4730        &self,
4731        params: FactoryJournalGetRequest,
4732    ) -> Result<FactoryJournalGetResult, Error> {
4733        let mut wire_params = serde_json::to_value(params)?;
4734        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4735        let _value = self
4736            .session
4737            .client()
4738            .call(rpc_methods::SESSION_FACTORY_JOURNAL_GET, Some(wire_params))
4739            .await?;
4740        Ok(serde_json::from_value(_value)?)
4741    }
4742
4743    /// Stores a memoized factory journal entry.
4744    ///
4745    /// Wire method: `session.factory.journal.put`.
4746    ///
4747    /// # Parameters
4748    ///
4749    /// * `params` - Parameters for storing a factory journal entry.
4750    ///
4751    /// # Returns
4752    ///
4753    /// Acknowledgement that a factory request was accepted.
4754    ///
4755    /// <div class="warning">
4756    ///
4757    /// **Experimental.** This API is part of an experimental wire-protocol surface
4758    /// and may change or be removed in future SDK or CLI releases. Pin both the
4759    /// SDK and CLI versions if your code depends on it.
4760    ///
4761    /// </div>
4762    pub async fn put(&self, params: FactoryJournalPutRequest) -> Result<FactoryAckResult, Error> {
4763        let mut wire_params = serde_json::to_value(params)?;
4764        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4765        let _value = self
4766            .session
4767            .client()
4768            .call(rpc_methods::SESSION_FACTORY_JOURNAL_PUT, Some(wire_params))
4769            .await?;
4770        Ok(serde_json::from_value(_value)?)
4771    }
4772}
4773
4774/// `session.fleet.*` RPCs.
4775#[derive(Clone, Copy)]
4776pub struct SessionRpcFleet<'a> {
4777    pub(crate) session: &'a Session,
4778}
4779
4780impl<'a> SessionRpcFleet<'a> {
4781    /// Starts fleet mode by submitting the fleet orchestration prompt to the session.
4782    ///
4783    /// Wire method: `session.fleet.start`.
4784    ///
4785    /// # Parameters
4786    ///
4787    /// * `params` - Optional user prompt to combine with the fleet orchestration instructions.
4788    ///
4789    /// # Returns
4790    ///
4791    /// Indicates whether fleet mode was successfully activated.
4792    ///
4793    /// <div class="warning">
4794    ///
4795    /// **Experimental.** This API is part of an experimental wire-protocol surface
4796    /// and may change or be removed in future SDK or CLI releases. Pin both the
4797    /// SDK and CLI versions if your code depends on it.
4798    ///
4799    /// </div>
4800    pub async fn start(&self, params: FleetStartRequest) -> Result<FleetStartResult, Error> {
4801        let mut wire_params = serde_json::to_value(params)?;
4802        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4803        let _value = self
4804            .session
4805            .client()
4806            .call(rpc_methods::SESSION_FLEET_START, Some(wire_params))
4807            .await?;
4808        Ok(serde_json::from_value(_value)?)
4809    }
4810}
4811
4812/// `session.gitHubAuth.*` RPCs.
4813#[derive(Clone, Copy)]
4814pub struct SessionRpcGitHubAuth<'a> {
4815    pub(crate) session: &'a Session,
4816}
4817
4818impl<'a> SessionRpcGitHubAuth<'a> {
4819    /// Gets authentication status and account metadata for the session.
4820    ///
4821    /// Wire method: `session.gitHubAuth.getStatus`.
4822    ///
4823    /// # Returns
4824    ///
4825    /// Authentication status and account metadata for the session.
4826    ///
4827    /// <div class="warning">
4828    ///
4829    /// **Experimental.** This API is part of an experimental wire-protocol surface
4830    /// and may change or be removed in future SDK or CLI releases. Pin both the
4831    /// SDK and CLI versions if your code depends on it.
4832    ///
4833    /// </div>
4834    pub async fn get_status(&self) -> Result<SessionAuthStatus, Error> {
4835        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
4836        let _value = self
4837            .session
4838            .client()
4839            .call(rpc_methods::SESSION_GITHUBAUTH_GETSTATUS, Some(wire_params))
4840            .await?;
4841        Ok(serde_json::from_value(_value)?)
4842    }
4843
4844    /// Updates the session's auth credentials used for outbound model and API requests.
4845    ///
4846    /// Wire method: `session.gitHubAuth.setCredentials`.
4847    ///
4848    /// # Parameters
4849    ///
4850    /// * `params` - New auth credentials to install on the session. Omit to leave credentials unchanged.
4851    ///
4852    /// # Returns
4853    ///
4854    /// Indicates whether the credential update succeeded.
4855    ///
4856    /// <div class="warning">
4857    ///
4858    /// **Experimental.** This API is part of an experimental wire-protocol surface
4859    /// and may change or be removed in future SDK or CLI releases. Pin both the
4860    /// SDK and CLI versions if your code depends on it.
4861    ///
4862    /// </div>
4863    pub async fn set_credentials(
4864        &self,
4865        params: SessionSetCredentialsParams,
4866    ) -> Result<SessionSetCredentialsResult, Error> {
4867        let mut wire_params = serde_json::to_value(params)?;
4868        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4869        let _value = self
4870            .session
4871            .client()
4872            .call(
4873                rpc_methods::SESSION_GITHUBAUTH_SETCREDENTIALS,
4874                Some(wire_params),
4875            )
4876            .await?;
4877        Ok(serde_json::from_value(_value)?)
4878    }
4879}
4880
4881/// `session.history.*` RPCs.
4882#[derive(Clone, Copy)]
4883pub struct SessionRpcHistory<'a> {
4884    pub(crate) session: &'a Session,
4885}
4886
4887impl<'a> SessionRpcHistory<'a> {
4888    /// Compacts the session history to reduce context usage.
4889    ///
4890    /// Wire method: `session.history.compact`.
4891    ///
4892    /// # Returns
4893    ///
4894    /// Compaction outcome with the number of tokens and messages removed, summary text, and the resulting context window breakdown.
4895    ///
4896    /// <div class="warning">
4897    ///
4898    /// **Experimental.** This API is part of an experimental wire-protocol surface
4899    /// and may change or be removed in future SDK or CLI releases. Pin both the
4900    /// SDK and CLI versions if your code depends on it.
4901    ///
4902    /// </div>
4903    pub async fn compact(&self) -> Result<HistoryCompactResult, Error> {
4904        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
4905        let _value = self
4906            .session
4907            .client()
4908            .call(rpc_methods::SESSION_HISTORY_COMPACT, Some(wire_params))
4909            .await?;
4910        Ok(serde_json::from_value(_value)?)
4911    }
4912
4913    /// Compacts the session history to reduce context usage.
4914    ///
4915    /// Wire method: `session.history.compact`.
4916    ///
4917    /// # Parameters
4918    ///
4919    /// * `params` - Optional compaction parameters.
4920    ///
4921    /// # Returns
4922    ///
4923    /// Compaction outcome with the number of tokens and messages removed, summary text, and the resulting context window breakdown.
4924    ///
4925    /// <div class="warning">
4926    ///
4927    /// **Experimental.** This API is part of an experimental wire-protocol surface
4928    /// and may change or be removed in future SDK or CLI releases. Pin both the
4929    /// SDK and CLI versions if your code depends on it.
4930    ///
4931    /// </div>
4932    pub async fn compact_with_params(
4933        &self,
4934        params: HistoryCompactRequest,
4935    ) -> Result<HistoryCompactResult, Error> {
4936        let mut wire_params = serde_json::to_value(params)?;
4937        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4938        let _value = self
4939            .session
4940            .client()
4941            .call(rpc_methods::SESSION_HISTORY_COMPACT, Some(wire_params))
4942            .await?;
4943        Ok(serde_json::from_value(_value)?)
4944    }
4945
4946    /// Truncates persisted session history to a specific event.
4947    ///
4948    /// Wire method: `session.history.truncate`.
4949    ///
4950    /// # Parameters
4951    ///
4952    /// * `params` - Identifier of the event to truncate to; this event and all later events are removed.
4953    ///
4954    /// # Returns
4955    ///
4956    /// Number of events that were removed by the truncation.
4957    ///
4958    /// <div class="warning">
4959    ///
4960    /// **Experimental.** This API is part of an experimental wire-protocol surface
4961    /// and may change or be removed in future SDK or CLI releases. Pin both the
4962    /// SDK and CLI versions if your code depends on it.
4963    ///
4964    /// </div>
4965    pub async fn truncate(
4966        &self,
4967        params: HistoryTruncateRequest,
4968    ) -> Result<HistoryTruncateResult, Error> {
4969        let mut wire_params = serde_json::to_value(params)?;
4970        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4971        let _value = self
4972            .session
4973            .client()
4974            .call(rpc_methods::SESSION_HISTORY_TRUNCATE, Some(wire_params))
4975            .await?;
4976        Ok(serde_json::from_value(_value)?)
4977    }
4978
4979    /// Lists the user turns that the session can rewind to. Never rejects for a busy session: rewind reads need the session's file-change captures to be settled, so a session that still holds active work answers with `unavailableReason: "session-busy"` and no points, which the caller can retry.
4980    ///
4981    /// Wire method: `session.history.listRewindPoints`.
4982    ///
4983    /// # Returns
4984    ///
4985    /// Rewind points and file-change-tracking availability for the session.
4986    ///
4987    /// <div class="warning">
4988    ///
4989    /// **Experimental.** This API is part of an experimental wire-protocol surface
4990    /// and may change or be removed in future SDK or CLI releases. Pin both the
4991    /// SDK and CLI versions if your code depends on it.
4992    ///
4993    /// </div>
4994    pub async fn list_rewind_points(&self) -> Result<HistoryListRewindPointsResult, Error> {
4995        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
4996        let _value = self
4997            .session
4998            .client()
4999            .call(
5000                rpc_methods::SESSION_HISTORY_LISTREWINDPOINTS,
5001                Some(wire_params),
5002            )
5003            .await?;
5004        Ok(serde_json::from_value(_value)?)
5005    }
5006
5007    /// Previews the files that a conversation-and-files rewind would restore.
5008    ///
5009    /// Wire method: `session.history.previewRewind`.
5010    ///
5011    /// # Parameters
5012    ///
5013    /// * `params` - Event boundary to preview for conversation-and-files rewind.
5014    ///
5015    /// # Returns
5016    ///
5017    /// Files and aggregate changes for a prospective rewind.
5018    ///
5019    /// <div class="warning">
5020    ///
5021    /// **Experimental.** This API is part of an experimental wire-protocol surface
5022    /// and may change or be removed in future SDK or CLI releases. Pin both the
5023    /// SDK and CLI versions if your code depends on it.
5024    ///
5025    /// </div>
5026    pub async fn preview_rewind(
5027        &self,
5028        params: HistoryPreviewRewindRequest,
5029    ) -> Result<HistoryPreviewRewindResult, Error> {
5030        let mut wire_params = serde_json::to_value(params)?;
5031        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5032        let _value = self
5033            .session
5034            .client()
5035            .call(
5036                rpc_methods::SESSION_HISTORY_PREVIEWREWIND,
5037                Some(wire_params),
5038            )
5039            .await?;
5040        Ok(serde_json::from_value(_value)?)
5041    }
5042
5043    /// Rewinds the session conversation, optionally restoring files changed by the discarded turns. Not crash-atomic: file restore and conversation truncation are separate stores, applied in that order, so a process crash between them can leave the workspace rewound while the conversation still contains the discarded turns. There is no recovery journal; re-running the same rewind is the recovery path for a crash before truncation lands, since file restore is idempotent (already-restored files are reported as skipped) and truncation is re-derived from the still-retained boundary event. After truncation lands that boundary no longer exists, so the same request is rejected; the only stage that can still be outstanding is snapshot pruning, whose failure leaves orphan snapshots the capture store tolerates. The reverse inconsistency cannot occur, because truncation is never applied before file restore succeeds.
5044    ///
5045    /// Wire method: `session.history.rewind`.
5046    ///
5047    /// # Parameters
5048    ///
5049    /// * `params` - Boundary and mode for rewinding session history.
5050    ///
5051    /// # Returns
5052    ///
5053    /// Structured outcome of a rewind request.
5054    ///
5055    /// <div class="warning">
5056    ///
5057    /// **Experimental.** This API is part of an experimental wire-protocol surface
5058    /// and may change or be removed in future SDK or CLI releases. Pin both the
5059    /// SDK and CLI versions if your code depends on it.
5060    ///
5061    /// </div>
5062    pub async fn rewind(&self, params: HistoryRewindRequest) -> Result<HistoryRewindResult, Error> {
5063        let mut wire_params = serde_json::to_value(params)?;
5064        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5065        let _value = self
5066            .session
5067            .client()
5068            .call(rpc_methods::SESSION_HISTORY_REWIND, Some(wire_params))
5069            .await?;
5070        Ok(serde_json::from_value(_value)?)
5071    }
5072
5073    /// Cancels any in-progress background compaction on a local session.
5074    ///
5075    /// Wire method: `session.history.cancelBackgroundCompaction`.
5076    ///
5077    /// # Returns
5078    ///
5079    /// Indicates whether an in-progress background compaction was cancelled.
5080    ///
5081    /// <div class="warning">
5082    ///
5083    /// **Experimental.** This API is part of an experimental wire-protocol surface
5084    /// and may change or be removed in future SDK or CLI releases. Pin both the
5085    /// SDK and CLI versions if your code depends on it.
5086    ///
5087    /// </div>
5088    pub async fn cancel_background_compaction(
5089        &self,
5090    ) -> Result<HistoryCancelBackgroundCompactionResult, Error> {
5091        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
5092        let _value = self
5093            .session
5094            .client()
5095            .call(
5096                rpc_methods::SESSION_HISTORY_CANCELBACKGROUNDCOMPACTION,
5097                Some(wire_params),
5098            )
5099            .await?;
5100        Ok(serde_json::from_value(_value)?)
5101    }
5102
5103    /// Aborts any in-progress manual compaction on a local session.
5104    ///
5105    /// Wire method: `session.history.abortManualCompaction`.
5106    ///
5107    /// # Returns
5108    ///
5109    /// Indicates whether an in-progress manual compaction was aborted.
5110    ///
5111    /// <div class="warning">
5112    ///
5113    /// **Experimental.** This API is part of an experimental wire-protocol surface
5114    /// and may change or be removed in future SDK or CLI releases. Pin both the
5115    /// SDK and CLI versions if your code depends on it.
5116    ///
5117    /// </div>
5118    pub async fn abort_manual_compaction(
5119        &self,
5120    ) -> Result<HistoryAbortManualCompactionResult, Error> {
5121        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
5122        let _value = self
5123            .session
5124            .client()
5125            .call(
5126                rpc_methods::SESSION_HISTORY_ABORTMANUALCOMPACTION,
5127                Some(wire_params),
5128            )
5129            .await?;
5130        Ok(serde_json::from_value(_value)?)
5131    }
5132
5133    /// Produces a markdown summary of the session's conversation context for hand-off scenarios.
5134    ///
5135    /// Wire method: `session.history.summarizeForHandoff`.
5136    ///
5137    /// # Returns
5138    ///
5139    /// Markdown summary of the conversation context (empty when not available).
5140    ///
5141    /// <div class="warning">
5142    ///
5143    /// **Experimental.** This API is part of an experimental wire-protocol surface
5144    /// and may change or be removed in future SDK or CLI releases. Pin both the
5145    /// SDK and CLI versions if your code depends on it.
5146    ///
5147    /// </div>
5148    pub async fn summarize_for_handoff(&self) -> Result<HistorySummarizeForHandoffResult, Error> {
5149        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
5150        let _value = self
5151            .session
5152            .client()
5153            .call(
5154                rpc_methods::SESSION_HISTORY_SUMMARIZEFORHANDOFF,
5155                Some(wire_params),
5156            )
5157            .await?;
5158        Ok(serde_json::from_value(_value)?)
5159    }
5160
5161    /// Clears the session's conversation history, keeping only system and developer messages, and seeds the fresh context window with a first user message. Must be called from inside a tool handler: the clear has to drop the results of the tool calls its wipe orphans, and it rejects when no tool call is in flight.
5162    ///
5163    /// Wire method: `session.history.clearContext`.
5164    ///
5165    /// # Parameters
5166    ///
5167    /// * `params` - Parameters for clearing the conversation and seeding the window that replaces it.
5168    ///
5169    /// # Returns
5170    ///
5171    /// What a successful clear removed. A clear that could not be applied rejects instead of reporting a count.
5172    ///
5173    /// <div class="warning">
5174    ///
5175    /// **Experimental.** This API is part of an experimental wire-protocol surface
5176    /// and may change or be removed in future SDK or CLI releases. Pin both the
5177    /// SDK and CLI versions if your code depends on it.
5178    ///
5179    /// </div>
5180    pub async fn clear_context(
5181        &self,
5182        params: HistoryClearContextRequest,
5183    ) -> Result<HistoryClearContextResult, Error> {
5184        let mut wire_params = serde_json::to_value(params)?;
5185        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5186        let _value = self
5187            .session
5188            .client()
5189            .call(rpc_methods::SESSION_HISTORY_CLEARCONTEXT, Some(wire_params))
5190            .await?;
5191        Ok(serde_json::from_value(_value)?)
5192    }
5193}
5194
5195/// `session.instructions.*` RPCs.
5196#[derive(Clone, Copy)]
5197pub struct SessionRpcInstructions<'a> {
5198    pub(crate) session: &'a Session,
5199}
5200
5201impl<'a> SessionRpcInstructions<'a> {
5202    /// Gets instruction sources loaded for the session.
5203    ///
5204    /// Wire method: `session.instructions.getSources`.
5205    ///
5206    /// # Returns
5207    ///
5208    /// Instruction sources loaded for the session, in merge order.
5209    ///
5210    /// <div class="warning">
5211    ///
5212    /// **Experimental.** This API is part of an experimental wire-protocol surface
5213    /// and may change or be removed in future SDK or CLI releases. Pin both the
5214    /// SDK and CLI versions if your code depends on it.
5215    ///
5216    /// </div>
5217    pub async fn get_sources(&self) -> Result<InstructionsGetSourcesResult, Error> {
5218        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
5219        let _value = self
5220            .session
5221            .client()
5222            .call(
5223                rpc_methods::SESSION_INSTRUCTIONS_GETSOURCES,
5224                Some(wire_params),
5225            )
5226            .await?;
5227        Ok(serde_json::from_value(_value)?)
5228    }
5229}
5230
5231/// `session.limitPrediction.*` RPCs.
5232#[derive(Clone, Copy)]
5233pub struct SessionRpcLimitPrediction<'a> {
5234    pub(crate) session: &'a Session,
5235}
5236
5237impl<'a> SessionRpcLimitPrediction<'a> {
5238    /// Predicts an AI-credit session limit for the session's resolved model. Returns an unavailable result instead of falling back when the current model is unresolved auto.
5239    ///
5240    /// Wire method: `session.limitPrediction.predict`.
5241    ///
5242    /// # Returns
5243    ///
5244    /// Prediction result. Available results include prediction details; unavailable results include an explicit reason.
5245    ///
5246    /// <div class="warning">
5247    ///
5248    /// **Experimental.** This API is part of an experimental wire-protocol surface
5249    /// and may change or be removed in future SDK or CLI releases. Pin both the
5250    /// SDK and CLI versions if your code depends on it.
5251    ///
5252    /// </div>
5253    pub async fn predict(&self) -> Result<SessionLimitPredictionResult, Error> {
5254        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
5255        let _value = self
5256            .session
5257            .client()
5258            .call(
5259                rpc_methods::SESSION_LIMITPREDICTION_PREDICT,
5260                Some(wire_params),
5261            )
5262            .await?;
5263        Ok(serde_json::from_value(_value)?)
5264    }
5265
5266    /// Predicts an AI-credit session limit for the session's resolved model. Returns an unavailable result instead of falling back when the current model is unresolved auto.
5267    ///
5268    /// Wire method: `session.limitPrediction.predict`.
5269    ///
5270    /// # Parameters
5271    ///
5272    /// * `params` - Parameters for predicting an AI-credit session limit. Omitting `modelId` uses the session's currently selected model.
5273    ///
5274    /// # Returns
5275    ///
5276    /// Prediction result. Available results include prediction details; unavailable results include an explicit reason.
5277    ///
5278    /// <div class="warning">
5279    ///
5280    /// **Experimental.** This API is part of an experimental wire-protocol surface
5281    /// and may change or be removed in future SDK or CLI releases. Pin both the
5282    /// SDK and CLI versions if your code depends on it.
5283    ///
5284    /// </div>
5285    pub async fn predict_with_params(
5286        &self,
5287        params: SessionLimitPredictionRequest,
5288    ) -> Result<SessionLimitPredictionResult, Error> {
5289        let mut wire_params = serde_json::to_value(params)?;
5290        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5291        let _value = self
5292            .session
5293            .client()
5294            .call(
5295                rpc_methods::SESSION_LIMITPREDICTION_PREDICT,
5296                Some(wire_params),
5297            )
5298            .await?;
5299        Ok(serde_json::from_value(_value)?)
5300    }
5301}
5302
5303/// `session.lsp.*` RPCs.
5304#[derive(Clone, Copy)]
5305pub struct SessionRpcLsp<'a> {
5306    pub(crate) session: &'a Session,
5307}
5308
5309impl<'a> SessionRpcLsp<'a> {
5310    /// Loads the merged LSP configuration set for the session's working directory.
5311    ///
5312    /// Wire method: `session.lsp.initialize`.
5313    ///
5314    /// # Parameters
5315    ///
5316    /// * `params` - Parameters for (re)loading the merged LSP configuration set.
5317    ///
5318    /// <div class="warning">
5319    ///
5320    /// **Experimental.** This API is part of an experimental wire-protocol surface
5321    /// and may change or be removed in future SDK or CLI releases. Pin both the
5322    /// SDK and CLI versions if your code depends on it.
5323    ///
5324    /// </div>
5325    pub async fn initialize(&self, params: LspInitializeRequest) -> Result<(), Error> {
5326        let mut wire_params = serde_json::to_value(params)?;
5327        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5328        let _value = self
5329            .session
5330            .client()
5331            .call(rpc_methods::SESSION_LSP_INITIALIZE, Some(wire_params))
5332            .await?;
5333        Ok(())
5334    }
5335}
5336
5337/// `session.mcp.*` RPCs.
5338#[derive(Clone, Copy)]
5339pub struct SessionRpcMcp<'a> {
5340    pub(crate) session: &'a Session,
5341}
5342
5343impl<'a> SessionRpcMcp<'a> {
5344    /// `session.mcp.apps.*` sub-namespace.
5345    pub fn apps(&self) -> SessionRpcMcpApps<'a> {
5346        SessionRpcMcpApps {
5347            session: self.session,
5348        }
5349    }
5350
5351    /// `session.mcp.headers.*` sub-namespace.
5352    pub fn headers(&self) -> SessionRpcMcpHeaders<'a> {
5353        SessionRpcMcpHeaders {
5354            session: self.session,
5355        }
5356    }
5357
5358    /// `session.mcp.oauth.*` sub-namespace.
5359    pub fn oauth(&self) -> SessionRpcMcpOauth<'a> {
5360        SessionRpcMcpOauth {
5361            session: self.session,
5362        }
5363    }
5364
5365    /// `session.mcp.resources.*` sub-namespace.
5366    pub fn resources(&self) -> SessionRpcMcpResources<'a> {
5367        SessionRpcMcpResources {
5368            session: self.session,
5369        }
5370    }
5371
5372    /// Lists MCP servers configured for the session, their connection status, and host-level state. The host-level state (disabled/filtered servers, failed/needs-auth/pending connections, mcp3p policy, full config) is empty/zero when no MCP host has been initialized for the session.
5373    ///
5374    /// Wire method: `session.mcp.list`.
5375    ///
5376    /// # Returns
5377    ///
5378    /// MCP servers configured for the session, with their connection status and host-level state.
5379    ///
5380    /// <div class="warning">
5381    ///
5382    /// **Experimental.** This API is part of an experimental wire-protocol surface
5383    /// and may change or be removed in future SDK or CLI releases. Pin both the
5384    /// SDK and CLI versions if your code depends on it.
5385    ///
5386    /// </div>
5387    pub async fn list(&self) -> Result<McpServerList, Error> {
5388        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
5389        let _value = self
5390            .session
5391            .client()
5392            .call(rpc_methods::SESSION_MCP_LIST, Some(wire_params))
5393            .await?;
5394        Ok(serde_json::from_value(_value)?)
5395    }
5396
5397    /// Lists the tools exposed by a connected MCP server on this session's host. This performs a live `tools/list` request. Tool UI metadata is returned independently of whether MCP Apps rendering is enabled for the session.
5398    ///
5399    /// Wire method: `session.mcp.listTools`.
5400    ///
5401    /// # Parameters
5402    ///
5403    /// * `params` - Server name whose tool list should be returned.
5404    ///
5405    /// # Returns
5406    ///
5407    /// Tools exposed by the connected MCP server. Throws when the server is not connected.
5408    ///
5409    /// <div class="warning">
5410    ///
5411    /// **Experimental.** This API is part of an experimental wire-protocol surface
5412    /// and may change or be removed in future SDK or CLI releases. Pin both the
5413    /// SDK and CLI versions if your code depends on it.
5414    ///
5415    /// </div>
5416    pub async fn list_tools(
5417        &self,
5418        params: McpListToolsRequest,
5419    ) -> Result<McpListToolsResult, Error> {
5420        let mut wire_params = serde_json::to_value(params)?;
5421        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5422        let _value = self
5423            .session
5424            .client()
5425            .call(rpc_methods::SESSION_MCP_LISTTOOLS, Some(wire_params))
5426            .await?;
5427        Ok(serde_json::from_value(_value)?)
5428    }
5429
5430    /// Enables an MCP server for the session.
5431    ///
5432    /// Wire method: `session.mcp.enable`.
5433    ///
5434    /// # Parameters
5435    ///
5436    /// * `params` - Name of the MCP server to enable for the session.
5437    ///
5438    /// <div class="warning">
5439    ///
5440    /// **Experimental.** This API is part of an experimental wire-protocol surface
5441    /// and may change or be removed in future SDK or CLI releases. Pin both the
5442    /// SDK and CLI versions if your code depends on it.
5443    ///
5444    /// </div>
5445    pub async fn enable(&self, params: McpEnableRequest) -> Result<(), Error> {
5446        let mut wire_params = serde_json::to_value(params)?;
5447        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5448        let _value = self
5449            .session
5450            .client()
5451            .call(rpc_methods::SESSION_MCP_ENABLE, Some(wire_params))
5452            .await?;
5453        Ok(())
5454    }
5455
5456    /// Disables an MCP server for the session.
5457    ///
5458    /// Wire method: `session.mcp.disable`.
5459    ///
5460    /// # Parameters
5461    ///
5462    /// * `params` - Name of the MCP server to disable for the session.
5463    ///
5464    /// <div class="warning">
5465    ///
5466    /// **Experimental.** This API is part of an experimental wire-protocol surface
5467    /// and may change or be removed in future SDK or CLI releases. Pin both the
5468    /// SDK and CLI versions if your code depends on it.
5469    ///
5470    /// </div>
5471    pub async fn disable(&self, params: McpDisableRequest) -> Result<(), Error> {
5472        let mut wire_params = serde_json::to_value(params)?;
5473        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5474        let _value = self
5475            .session
5476            .client()
5477            .call(rpc_methods::SESSION_MCP_DISABLE, Some(wire_params))
5478            .await?;
5479        Ok(())
5480    }
5481
5482    /// Reloads MCP server connections for the session.
5483    ///
5484    /// Wire method: `session.mcp.reload`.
5485    ///
5486    /// <div class="warning">
5487    ///
5488    /// **Experimental.** This API is part of an experimental wire-protocol surface
5489    /// and may change or be removed in future SDK or CLI releases. Pin both the
5490    /// SDK and CLI versions if your code depends on it.
5491    ///
5492    /// </div>
5493    pub async fn reload(&self) -> Result<(), Error> {
5494        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
5495        let _value = self
5496            .session
5497            .client()
5498            .call(rpc_methods::SESSION_MCP_RELOAD, Some(wire_params))
5499            .await?;
5500        Ok(())
5501    }
5502
5503    /// Reloads MCP server connections for the session with an explicit host-provided configuration.
5504    ///
5505    /// Wire method: `session.mcp.reloadWithConfig`.
5506    ///
5507    /// # Parameters
5508    ///
5509    /// * `params` - Opaque MCP reload configuration.
5510    ///
5511    /// # Returns
5512    ///
5513    /// MCP server startup filtering result.
5514    ///
5515    /// <div class="warning">
5516    ///
5517    /// **Experimental.** This API is part of an experimental wire-protocol surface
5518    /// and may change or be removed in future SDK or CLI releases. Pin both the
5519    /// SDK and CLI versions if your code depends on it.
5520    ///
5521    /// </div>
5522    pub(crate) async fn reload_with_config(
5523        &self,
5524        params: McpReloadWithConfigRequest,
5525    ) -> Result<McpStartServersResult, Error> {
5526        let mut wire_params = serde_json::to_value(params)?;
5527        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5528        let _value = self
5529            .session
5530            .client()
5531            .call(rpc_methods::SESSION_MCP_RELOADWITHCONFIG, Some(wire_params))
5532            .await?;
5533        Ok(serde_json::from_value(_value)?)
5534    }
5535
5536    /// Runs an MCP sampling inference on behalf of an MCP server.
5537    ///
5538    /// Wire method: `session.mcp.executeSampling`.
5539    ///
5540    /// # Parameters
5541    ///
5542    /// * `params` - Identifiers and raw MCP CreateMessageRequest params used to run a sampling inference.
5543    ///
5544    /// # Returns
5545    ///
5546    /// Outcome of an MCP sampling execution: success result, failure error, or cancellation.
5547    ///
5548    /// <div class="warning">
5549    ///
5550    /// **Experimental.** This API is part of an experimental wire-protocol surface
5551    /// and may change or be removed in future SDK or CLI releases. Pin both the
5552    /// SDK and CLI versions if your code depends on it.
5553    ///
5554    /// </div>
5555    pub async fn execute_sampling(
5556        &self,
5557        params: McpExecuteSamplingParams,
5558    ) -> Result<McpSamplingExecutionResult, Error> {
5559        let mut wire_params = serde_json::to_value(params)?;
5560        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5561        let _value = self
5562            .session
5563            .client()
5564            .call(rpc_methods::SESSION_MCP_EXECUTESAMPLING, Some(wire_params))
5565            .await?;
5566        Ok(serde_json::from_value(_value)?)
5567    }
5568
5569    /// Cancels an in-flight MCP sampling execution by request ID.
5570    ///
5571    /// Wire method: `session.mcp.cancelSamplingExecution`.
5572    ///
5573    /// # Parameters
5574    ///
5575    /// * `params` - The requestId previously passed to executeSampling that should be cancelled.
5576    ///
5577    /// # Returns
5578    ///
5579    /// Indicates whether an in-flight sampling execution with the given requestId was found and cancelled.
5580    ///
5581    /// <div class="warning">
5582    ///
5583    /// **Experimental.** This API is part of an experimental wire-protocol surface
5584    /// and may change or be removed in future SDK or CLI releases. Pin both the
5585    /// SDK and CLI versions if your code depends on it.
5586    ///
5587    /// </div>
5588    pub async fn cancel_sampling_execution(
5589        &self,
5590        params: McpCancelSamplingExecutionParams,
5591    ) -> Result<McpCancelSamplingExecutionResult, Error> {
5592        let mut wire_params = serde_json::to_value(params)?;
5593        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5594        let _value = self
5595            .session
5596            .client()
5597            .call(
5598                rpc_methods::SESSION_MCP_CANCELSAMPLINGEXECUTION,
5599                Some(wire_params),
5600            )
5601            .await?;
5602        Ok(serde_json::from_value(_value)?)
5603    }
5604
5605    /// Sets how environment-variable values supplied to MCP servers are resolved (direct or indirect).
5606    ///
5607    /// Wire method: `session.mcp.setEnvValueMode`.
5608    ///
5609    /// # Parameters
5610    ///
5611    /// * `params` - Mode controlling how MCP server env values are resolved (`direct` or `indirect`).
5612    ///
5613    /// # Returns
5614    ///
5615    /// Env-value mode recorded on the session after the update.
5616    ///
5617    /// <div class="warning">
5618    ///
5619    /// **Experimental.** This API is part of an experimental wire-protocol surface
5620    /// and may change or be removed in future SDK or CLI releases. Pin both the
5621    /// SDK and CLI versions if your code depends on it.
5622    ///
5623    /// </div>
5624    pub async fn set_env_value_mode(
5625        &self,
5626        params: McpSetEnvValueModeParams,
5627    ) -> Result<McpSetEnvValueModeResult, Error> {
5628        let mut wire_params = serde_json::to_value(params)?;
5629        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5630        let _value = self
5631            .session
5632            .client()
5633            .call(rpc_methods::SESSION_MCP_SETENVVALUEMODE, Some(wire_params))
5634            .await?;
5635        Ok(serde_json::from_value(_value)?)
5636    }
5637
5638    /// Removes the auto-managed `github` MCP server when present.
5639    ///
5640    /// Wire method: `session.mcp.removeGitHub`.
5641    ///
5642    /// # Returns
5643    ///
5644    /// Indicates whether the auto-managed `github` MCP server was removed (false when nothing to remove).
5645    ///
5646    /// <div class="warning">
5647    ///
5648    /// **Experimental.** This API is part of an experimental wire-protocol surface
5649    /// and may change or be removed in future SDK or CLI releases. Pin both the
5650    /// SDK and CLI versions if your code depends on it.
5651    ///
5652    /// </div>
5653    pub async fn remove_git_hub(&self) -> Result<McpRemoveGitHubResult, Error> {
5654        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
5655        let _value = self
5656            .session
5657            .client()
5658            .call(rpc_methods::SESSION_MCP_REMOVEGITHUB, Some(wire_params))
5659            .await?;
5660        Ok(serde_json::from_value(_value)?)
5661    }
5662
5663    /// Configures the built-in GitHub MCP server for the session's current auth context.
5664    ///
5665    /// Wire method: `session.mcp.configureGitHub`.
5666    ///
5667    /// # Parameters
5668    ///
5669    /// * `params` - Opaque auth info used to configure GitHub MCP.
5670    ///
5671    /// # Returns
5672    ///
5673    /// Result of configuring GitHub MCP.
5674    ///
5675    /// <div class="warning">
5676    ///
5677    /// **Experimental.** This API is part of an experimental wire-protocol surface
5678    /// and may change or be removed in future SDK or CLI releases. Pin both the
5679    /// SDK and CLI versions if your code depends on it.
5680    ///
5681    /// </div>
5682    pub(crate) async fn configure_git_hub(
5683        &self,
5684        params: McpConfigureGitHubRequest,
5685    ) -> Result<McpConfigureGitHubResult, Error> {
5686        let mut wire_params = serde_json::to_value(params)?;
5687        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5688        let _value = self
5689            .session
5690            .client()
5691            .call(rpc_methods::SESSION_MCP_CONFIGUREGITHUB, Some(wire_params))
5692            .await?;
5693        Ok(serde_json::from_value(_value)?)
5694    }
5695
5696    /// Starts an individual MCP server on the live session. Omit `config` for a config-free start-by-name of an already-configured server (reuses the server's already-registered configuration); supply `config` to start from a caller-supplied configuration. Session-scoped and ephemeral: the server is added to this session's running set only and is reaped when the session ends. Does NOT modify persistent user configuration (`mcp.config.*`), so it does not affect future sessions. The server surfaces through `session.mcp.list` and the `session.mcp_servers_loaded` / `session.mcp_server_status_changed` events like any other server.
5697    ///
5698    /// Wire method: `session.mcp.startServer`.
5699    ///
5700    /// # Parameters
5701    ///
5702    /// * `params` - Server name and optional configuration for an individual MCP server start. Omit `config` for a config-free start-by-name of an already-configured server.
5703    ///
5704    /// <div class="warning">
5705    ///
5706    /// **Experimental.** This API is part of an experimental wire-protocol surface
5707    /// and may change or be removed in future SDK or CLI releases. Pin both the
5708    /// SDK and CLI versions if your code depends on it.
5709    ///
5710    /// </div>
5711    pub async fn start_server(&self, params: McpStartServerRequest) -> Result<(), Error> {
5712        let mut wire_params = serde_json::to_value(params)?;
5713        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5714        let _value = self
5715            .session
5716            .client()
5717            .call(rpc_methods::SESSION_MCP_STARTSERVER, Some(wire_params))
5718            .await?;
5719        Ok(())
5720    }
5721
5722    /// Restarts an individual MCP server on the live session (stops then starts). Omit `config` for a config-free restart-by-name of an already-configured server; supply `config` to restart with a replacement configuration. Session-scoped and ephemeral: does NOT modify persistent user configuration (`mcp.config.*`).
5723    ///
5724    /// Wire method: `session.mcp.restartServer`.
5725    ///
5726    /// # Parameters
5727    ///
5728    /// * `params` - Server name and optional replacement configuration for an individual MCP server restart. Omit `config` for a config-free restart-by-name of an already-configured server.
5729    ///
5730    /// <div class="warning">
5731    ///
5732    /// **Experimental.** This API is part of an experimental wire-protocol surface
5733    /// and may change or be removed in future SDK or CLI releases. Pin both the
5734    /// SDK and CLI versions if your code depends on it.
5735    ///
5736    /// </div>
5737    pub async fn restart_server(&self, params: McpRestartServerRequest) -> Result<(), Error> {
5738        let mut wire_params = serde_json::to_value(params)?;
5739        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5740        let _value = self
5741            .session
5742            .client()
5743            .call(rpc_methods::SESSION_MCP_RESTARTSERVER, Some(wire_params))
5744            .await?;
5745        Ok(())
5746    }
5747
5748    /// Stops an individual MCP server on the session's host.
5749    ///
5750    /// Wire method: `session.mcp.stopServer`.
5751    ///
5752    /// # Parameters
5753    ///
5754    /// * `params` - Server name for an individual MCP server stop.
5755    ///
5756    /// <div class="warning">
5757    ///
5758    /// **Experimental.** This API is part of an experimental wire-protocol surface
5759    /// and may change or be removed in future SDK or CLI releases. Pin both the
5760    /// SDK and CLI versions if your code depends on it.
5761    ///
5762    /// </div>
5763    pub async fn stop_server(&self, params: McpStopServerRequest) -> Result<(), Error> {
5764        let mut wire_params = serde_json::to_value(params)?;
5765        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5766        let _value = self
5767            .session
5768            .client()
5769            .call(rpc_methods::SESSION_MCP_STOPSERVER, Some(wire_params))
5770            .await?;
5771        Ok(())
5772    }
5773
5774    /// Registers a pre-connected external MCP client (e.g. IDE) on the session's host. The caller retains lifecycle ownership of the client and transport. Marked internal because the `client` and `transport` arguments are in-process MCP SDK instances that cannot be serialized across the JSON-RPC boundary; once the CLI moves on top of the SDK, external clients will be expressed as transport configs the runtime can construct itself.
5775    ///
5776    /// Wire method: `session.mcp.registerExternalClient`.
5777    ///
5778    /// # Parameters
5779    ///
5780    /// * `params` - Registration parameters for an external MCP client.
5781    ///
5782    /// <div class="warning">
5783    ///
5784    /// **Experimental.** This API is part of an experimental wire-protocol surface
5785    /// and may change or be removed in future SDK or CLI releases. Pin both the
5786    /// SDK and CLI versions if your code depends on it.
5787    ///
5788    /// </div>
5789    pub(crate) async fn register_external_client(
5790        &self,
5791        params: McpRegisterExternalClientRequest,
5792    ) -> Result<(), Error> {
5793        let mut wire_params = serde_json::to_value(params)?;
5794        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5795        let _value = self
5796            .session
5797            .client()
5798            .call(
5799                rpc_methods::SESSION_MCP_REGISTEREXTERNALCLIENT,
5800                Some(wire_params),
5801            )
5802            .await?;
5803        Ok(())
5804    }
5805
5806    /// Unregisters a previously registered external MCP client by server name. Marked internal as the paired companion of `registerExternalClient`: only in-process callers that registered a client this way can meaningfully unregister it. Disappears alongside `registerExternalClient`: once external clients are described to the runtime as config rather than handed in as instances, lifecycle (including deregistration) is owned entirely by the runtime.
5807    ///
5808    /// Wire method: `session.mcp.unregisterExternalClient`.
5809    ///
5810    /// # Parameters
5811    ///
5812    /// * `params` - Server name identifying the external client to remove.
5813    ///
5814    /// <div class="warning">
5815    ///
5816    /// **Experimental.** This API is part of an experimental wire-protocol surface
5817    /// and may change or be removed in future SDK or CLI releases. Pin both the
5818    /// SDK and CLI versions if your code depends on it.
5819    ///
5820    /// </div>
5821    pub(crate) async fn unregister_external_client(
5822        &self,
5823        params: McpUnregisterExternalClientRequest,
5824    ) -> Result<(), Error> {
5825        let mut wire_params = serde_json::to_value(params)?;
5826        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5827        let _value = self
5828            .session
5829            .client()
5830            .call(
5831                rpc_methods::SESSION_MCP_UNREGISTEREXTERNALCLIENT,
5832                Some(wire_params),
5833            )
5834            .await?;
5835        Ok(())
5836    }
5837
5838    /// Checks whether a named MCP server is currently running on the session's host.
5839    ///
5840    /// Wire method: `session.mcp.isServerRunning`.
5841    ///
5842    /// # Parameters
5843    ///
5844    /// * `params` - Server name to check running status for.
5845    ///
5846    /// # Returns
5847    ///
5848    /// Whether the named MCP server is running.
5849    ///
5850    /// <div class="warning">
5851    ///
5852    /// **Experimental.** This API is part of an experimental wire-protocol surface
5853    /// and may change or be removed in future SDK or CLI releases. Pin both the
5854    /// SDK and CLI versions if your code depends on it.
5855    ///
5856    /// </div>
5857    pub async fn is_server_running(
5858        &self,
5859        params: McpIsServerRunningRequest,
5860    ) -> Result<McpIsServerRunningResult, Error> {
5861        let mut wire_params = serde_json::to_value(params)?;
5862        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5863        let _value = self
5864            .session
5865            .client()
5866            .call(rpc_methods::SESSION_MCP_ISSERVERRUNNING, Some(wire_params))
5867            .await?;
5868        Ok(serde_json::from_value(_value)?)
5869    }
5870}
5871
5872/// `session.mcp.apps.*` RPCs.
5873#[derive(Clone, Copy)]
5874pub struct SessionRpcMcpApps<'a> {
5875    pub(crate) session: &'a Session,
5876}
5877
5878impl<'a> SessionRpcMcpApps<'a> {
5879    /// Fetch an MCP resource (typically a `ui://` MCP App bundle, per SEP-1865) from a connected server. Requires the `mcp-apps` session capability.
5880    ///
5881    /// Wire method: `session.mcp.apps.readResource`.
5882    ///
5883    /// # Parameters
5884    ///
5885    /// * `params` - MCP server and resource URI to fetch.
5886    ///
5887    /// # Returns
5888    ///
5889    /// Resource contents returned by the MCP server.
5890    ///
5891    /// <div class="warning">
5892    ///
5893    /// **Experimental.** This API is part of an experimental wire-protocol surface
5894    /// and may change or be removed in future SDK or CLI releases. Pin both the
5895    /// SDK and CLI versions if your code depends on it.
5896    ///
5897    /// </div>
5898    pub async fn read_resource(
5899        &self,
5900        params: McpAppsReadResourceRequest,
5901    ) -> Result<McpAppsReadResourceResult, Error> {
5902        let mut wire_params = serde_json::to_value(params)?;
5903        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5904        let _value = self
5905            .session
5906            .client()
5907            .call(
5908                rpc_methods::SESSION_MCP_APPS_READRESOURCE,
5909                Some(wire_params),
5910            )
5911            .await?;
5912        Ok(serde_json::from_value(_value)?)
5913    }
5914
5915    /// List tools that an MCP App view is allowed to call (SEP-1865 visibility filter). Returns tools whose `_meta.ui.visibility` is unset (default `["model","app"]`) or includes `"app"`.
5916    ///
5917    /// Wire method: `session.mcp.apps.listTools`.
5918    ///
5919    /// # Parameters
5920    ///
5921    /// * `params` - MCP server to list app-callable tools for.
5922    ///
5923    /// # Returns
5924    ///
5925    /// App-callable tools from the named MCP server.
5926    ///
5927    /// <div class="warning">
5928    ///
5929    /// **Experimental.** This API is part of an experimental wire-protocol surface
5930    /// and may change or be removed in future SDK or CLI releases. Pin both the
5931    /// SDK and CLI versions if your code depends on it.
5932    ///
5933    /// </div>
5934    pub async fn list_tools(
5935        &self,
5936        params: McpAppsListToolsRequest,
5937    ) -> Result<McpAppsListToolsResult, Error> {
5938        let mut wire_params = serde_json::to_value(params)?;
5939        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5940        let _value = self
5941            .session
5942            .client()
5943            .call(rpc_methods::SESSION_MCP_APPS_LISTTOOLS, Some(wire_params))
5944            .await?;
5945        Ok(serde_json::from_value(_value)?)
5946    }
5947
5948    /// Call an MCP tool from an MCP App view (SEP-1865). Enforces the visibility check that prevents an app iframe from invoking model-only tools. Returns the standard MCP `CallToolResult`.
5949    ///
5950    /// Wire method: `session.mcp.apps.callTool`.
5951    ///
5952    /// # Parameters
5953    ///
5954    /// * `params` - MCP server, tool name, and arguments to invoke from an MCP App view.
5955    ///
5956    /// # Returns
5957    ///
5958    /// Standard MCP CallToolResult
5959    ///
5960    /// <div class="warning">
5961    ///
5962    /// **Experimental.** This API is part of an experimental wire-protocol surface
5963    /// and may change or be removed in future SDK or CLI releases. Pin both the
5964    /// SDK and CLI versions if your code depends on it.
5965    ///
5966    /// </div>
5967    pub async fn call_tool(
5968        &self,
5969        params: McpAppsCallToolRequest,
5970    ) -> Result<SessionMcpAppsCallToolResult, Error> {
5971        let mut wire_params = serde_json::to_value(params)?;
5972        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5973        let _value = self
5974            .session
5975            .client()
5976            .call(rpc_methods::SESSION_MCP_APPS_CALLTOOL, Some(wire_params))
5977            .await?;
5978        Ok(serde_json::from_value(_value)?)
5979    }
5980
5981    /// Replace the host context returned to MCP App guests on `ui/initialize`. Hosts use this to advertise theme, locale, or other metadata to the guest UI.
5982    ///
5983    /// Wire method: `session.mcp.apps.setHostContext`.
5984    ///
5985    /// # Parameters
5986    ///
5987    /// * `params` - Host context to advertise to MCP App guests.
5988    ///
5989    /// <div class="warning">
5990    ///
5991    /// **Experimental.** This API is part of an experimental wire-protocol surface
5992    /// and may change or be removed in future SDK or CLI releases. Pin both the
5993    /// SDK and CLI versions if your code depends on it.
5994    ///
5995    /// </div>
5996    pub async fn set_host_context(
5997        &self,
5998        params: McpAppsSetHostContextRequest,
5999    ) -> Result<(), Error> {
6000        let mut wire_params = serde_json::to_value(params)?;
6001        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
6002        let _value = self
6003            .session
6004            .client()
6005            .call(
6006                rpc_methods::SESSION_MCP_APPS_SETHOSTCONTEXT,
6007                Some(wire_params),
6008            )
6009            .await?;
6010        Ok(())
6011    }
6012
6013    /// Read the current host context advertised to MCP App guests.
6014    ///
6015    /// Wire method: `session.mcp.apps.getHostContext`.
6016    ///
6017    /// # Returns
6018    ///
6019    /// Current host context advertised to MCP App guests.
6020    ///
6021    /// <div class="warning">
6022    ///
6023    /// **Experimental.** This API is part of an experimental wire-protocol surface
6024    /// and may change or be removed in future SDK or CLI releases. Pin both the
6025    /// SDK and CLI versions if your code depends on it.
6026    ///
6027    /// </div>
6028    pub async fn get_host_context(&self) -> Result<McpAppsHostContext, Error> {
6029        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
6030        let _value = self
6031            .session
6032            .client()
6033            .call(
6034                rpc_methods::SESSION_MCP_APPS_GETHOSTCONTEXT,
6035                Some(wire_params),
6036            )
6037            .await?;
6038        Ok(serde_json::from_value(_value)?)
6039    }
6040
6041    /// Diagnose MCP Apps wiring for a specific MCP server. Reports the session capability, feature-flag state, advertised extension, and how many tools have `_meta.ui` populated.
6042    ///
6043    /// Wire method: `session.mcp.apps.diagnose`.
6044    ///
6045    /// # Parameters
6046    ///
6047    /// * `params` - MCP server to diagnose MCP Apps wiring for.
6048    ///
6049    /// # Returns
6050    ///
6051    /// Diagnostic snapshot of MCP Apps wiring for the named server.
6052    ///
6053    /// <div class="warning">
6054    ///
6055    /// **Experimental.** This API is part of an experimental wire-protocol surface
6056    /// and may change or be removed in future SDK or CLI releases. Pin both the
6057    /// SDK and CLI versions if your code depends on it.
6058    ///
6059    /// </div>
6060    pub async fn diagnose(
6061        &self,
6062        params: McpAppsDiagnoseRequest,
6063    ) -> Result<McpAppsDiagnoseResult, Error> {
6064        let mut wire_params = serde_json::to_value(params)?;
6065        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
6066        let _value = self
6067            .session
6068            .client()
6069            .call(rpc_methods::SESSION_MCP_APPS_DIAGNOSE, Some(wire_params))
6070            .await?;
6071        Ok(serde_json::from_value(_value)?)
6072    }
6073}
6074
6075/// `session.mcp.headers.*` RPCs.
6076#[derive(Clone, Copy)]
6077pub struct SessionRpcMcpHeaders<'a> {
6078    pub(crate) session: &'a Session,
6079}
6080
6081impl<'a> SessionRpcMcpHeaders<'a> {
6082    /// Responds to a pending MCP dynamic headers refresh request. Hosts that subscribe to `mcp.headers_refresh_required` use this to provide short-lived per-server headers or to indicate that no dynamic headers are available for this refresh.
6083    ///
6084    /// Wire method: `session.mcp.headers.handlePendingHeadersRefreshRequest`.
6085    ///
6086    /// # Parameters
6087    ///
6088    /// * `params` - MCP headers refresh request id and the host response.
6089    ///
6090    /// # Returns
6091    ///
6092    /// Indicates whether the pending MCP headers refresh response was accepted.
6093    ///
6094    /// <div class="warning">
6095    ///
6096    /// **Experimental.** This API is part of an experimental wire-protocol surface
6097    /// and may change or be removed in future SDK or CLI releases. Pin both the
6098    /// SDK and CLI versions if your code depends on it.
6099    ///
6100    /// </div>
6101    pub async fn handle_pending_headers_refresh_request(
6102        &self,
6103        params: McpHeadersHandlePendingHeadersRefreshRequestRequest,
6104    ) -> Result<McpHeadersHandlePendingHeadersRefreshRequestResult, Error> {
6105        let mut wire_params = serde_json::to_value(params)?;
6106        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
6107        let _value = self
6108            .session
6109            .client()
6110            .call(
6111                rpc_methods::SESSION_MCP_HEADERS_HANDLEPENDINGHEADERSREFRESHREQUEST,
6112                Some(wire_params),
6113            )
6114            .await?;
6115        Ok(serde_json::from_value(_value)?)
6116    }
6117}
6118
6119/// `session.mcp.oauth.*` RPCs.
6120#[derive(Clone, Copy)]
6121pub struct SessionRpcMcpOauth<'a> {
6122    pub(crate) session: &'a Session,
6123}
6124
6125impl<'a> SessionRpcMcpOauth<'a> {
6126    /// Resolves a pending MCP OAuth request with a host-provided token or cancellation. The pending request is emitted as mcp.oauth_required with the data necessary to authorize the request.
6127    ///
6128    /// Wire method: `session.mcp.oauth.handlePendingRequest`.
6129    ///
6130    /// # Parameters
6131    ///
6132    /// * `params` - Pending MCP OAuth request ID and host-provided token or cancellation response.
6133    ///
6134    /// # Returns
6135    ///
6136    /// Indicates whether the pending MCP OAuth response was accepted.
6137    ///
6138    /// <div class="warning">
6139    ///
6140    /// **Experimental.** This API is part of an experimental wire-protocol surface
6141    /// and may change or be removed in future SDK or CLI releases. Pin both the
6142    /// SDK and CLI versions if your code depends on it.
6143    ///
6144    /// </div>
6145    pub async fn handle_pending_request(
6146        &self,
6147        params: McpOauthHandlePendingRequest,
6148    ) -> Result<McpOauthHandlePendingResult, Error> {
6149        let mut wire_params = serde_json::to_value(params)?;
6150        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
6151        let _value = self
6152            .session
6153            .client()
6154            .call(
6155                rpc_methods::SESSION_MCP_OAUTH_HANDLEPENDINGREQUEST,
6156                Some(wire_params),
6157            )
6158            .await?;
6159        Ok(serde_json::from_value(_value)?)
6160    }
6161
6162    /// Notifies the session that MCP OAuth authentication succeeded and updated credentials were persisted, so cached tool definitions can be refreshed.
6163    ///
6164    /// Wire method: `session.mcp.oauth.authenticationStateChanged`.
6165    ///
6166    /// # Parameters
6167    ///
6168    /// * `params` - Identifies the MCP server whose persisted OAuth credentials were updated.
6169    ///
6170    /// <div class="warning">
6171    ///
6172    /// **Experimental.** This API is part of an experimental wire-protocol surface
6173    /// and may change or be removed in future SDK or CLI releases. Pin both the
6174    /// SDK and CLI versions if your code depends on it.
6175    ///
6176    /// </div>
6177    pub async fn authentication_state_changed(
6178        &self,
6179        params: McpOauthAuthenticationStateChangedRequest,
6180    ) -> Result<(), Error> {
6181        let mut wire_params = serde_json::to_value(params)?;
6182        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
6183        let _value = self
6184            .session
6185            .client()
6186            .call(
6187                rpc_methods::SESSION_MCP_OAUTH_AUTHENTICATIONSTATECHANGED,
6188                Some(wire_params),
6189            )
6190            .await?;
6191        Ok(())
6192    }
6193
6194    /// Starts OAuth authentication for a remote MCP server.
6195    ///
6196    /// Wire method: `session.mcp.oauth.login`.
6197    ///
6198    /// # Parameters
6199    ///
6200    /// * `params` - Remote MCP server name and optional overrides controlling reauthentication, OAuth client display name, callback success-page copy, and static OAuth client selection.
6201    ///
6202    /// # Returns
6203    ///
6204    /// OAuth authorization URL the caller should open, or empty when cached tokens already authenticated the server.
6205    ///
6206    /// <div class="warning">
6207    ///
6208    /// **Experimental.** This API is part of an experimental wire-protocol surface
6209    /// and may change or be removed in future SDK or CLI releases. Pin both the
6210    /// SDK and CLI versions if your code depends on it.
6211    ///
6212    /// </div>
6213    pub async fn login(&self, params: McpOauthLoginRequest) -> Result<McpOauthLoginResult, Error> {
6214        let mut wire_params = serde_json::to_value(params)?;
6215        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
6216        let _value = self
6217            .session
6218            .client()
6219            .call(rpc_methods::SESSION_MCP_OAUTH_LOGIN, Some(wire_params))
6220            .await?;
6221        Ok(serde_json::from_value(_value)?)
6222    }
6223
6224    /// Responds to a pending MCP OAuth authorization request by its request id.
6225    ///
6226    /// Wire method: `session.mcp.oauth.respond`.
6227    ///
6228    /// # Parameters
6229    ///
6230    /// * `params` - Pending MCP OAuth request id to respond to.
6231    ///
6232    /// # Returns
6233    ///
6234    /// Indicates whether the pending MCP OAuth response was accepted.
6235    ///
6236    /// <div class="warning">
6237    ///
6238    /// **Experimental.** This API is part of an experimental wire-protocol surface
6239    /// and may change or be removed in future SDK or CLI releases. Pin both the
6240    /// SDK and CLI versions if your code depends on it.
6241    ///
6242    /// </div>
6243    pub async fn respond(
6244        &self,
6245        params: McpOauthRespondRequest,
6246    ) -> Result<McpOauthRespondResult, Error> {
6247        let mut wire_params = serde_json::to_value(params)?;
6248        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
6249        let _value = self
6250            .session
6251            .client()
6252            .call(rpc_methods::SESSION_MCP_OAUTH_RESPOND, Some(wire_params))
6253            .await?;
6254        Ok(serde_json::from_value(_value)?)
6255    }
6256}
6257
6258/// `session.mcp.resources.*` RPCs.
6259#[derive(Clone, Copy)]
6260pub struct SessionRpcMcpResources<'a> {
6261    pub(crate) session: &'a Session,
6262}
6263
6264impl<'a> SessionRpcMcpResources<'a> {
6265    /// Fetch an MCP resource from a connected server by URI (proxies MCP `resources/read`).
6266    ///
6267    /// Wire method: `session.mcp.resources.read`.
6268    ///
6269    /// # Parameters
6270    ///
6271    /// * `params` - MCP server and resource URI to fetch.
6272    ///
6273    /// # Returns
6274    ///
6275    /// Resource contents returned by the MCP server.
6276    ///
6277    /// <div class="warning">
6278    ///
6279    /// **Experimental.** This API is part of an experimental wire-protocol surface
6280    /// and may change or be removed in future SDK or CLI releases. Pin both the
6281    /// SDK and CLI versions if your code depends on it.
6282    ///
6283    /// </div>
6284    pub async fn read(
6285        &self,
6286        params: McpResourcesReadRequest,
6287    ) -> Result<McpResourcesReadResult, Error> {
6288        let mut wire_params = serde_json::to_value(params)?;
6289        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
6290        let _value = self
6291            .session
6292            .client()
6293            .call(rpc_methods::SESSION_MCP_RESOURCES_READ, Some(wire_params))
6294            .await?;
6295        Ok(serde_json::from_value(_value)?)
6296    }
6297
6298    /// Enumerate one page of resources a connected MCP server exposes (proxies MCP `resources/list`). Pass `cursor` to continue from a prior result's `nextCursor`.
6299    ///
6300    /// Wire method: `session.mcp.resources.list`.
6301    ///
6302    /// # Parameters
6303    ///
6304    /// * `params` - MCP server whose resources to enumerate.
6305    ///
6306    /// # Returns
6307    ///
6308    /// One page of resources advertised by the named MCP server.
6309    ///
6310    /// <div class="warning">
6311    ///
6312    /// **Experimental.** This API is part of an experimental wire-protocol surface
6313    /// and may change or be removed in future SDK or CLI releases. Pin both the
6314    /// SDK and CLI versions if your code depends on it.
6315    ///
6316    /// </div>
6317    pub async fn list(
6318        &self,
6319        params: McpResourcesListRequest,
6320    ) -> Result<McpResourcesListResult, Error> {
6321        let mut wire_params = serde_json::to_value(params)?;
6322        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
6323        let _value = self
6324            .session
6325            .client()
6326            .call(rpc_methods::SESSION_MCP_RESOURCES_LIST, Some(wire_params))
6327            .await?;
6328        Ok(serde_json::from_value(_value)?)
6329    }
6330
6331    /// Enumerate one page of resource templates a connected MCP server exposes (proxies MCP `resources/templates/list`). Pass `cursor` to continue from a prior result's `nextCursor`.
6332    ///
6333    /// Wire method: `session.mcp.resources.listTemplates`.
6334    ///
6335    /// # Parameters
6336    ///
6337    /// * `params` - MCP server whose resource templates to enumerate.
6338    ///
6339    /// # Returns
6340    ///
6341    /// One page of resource templates advertised by the named MCP server.
6342    ///
6343    /// <div class="warning">
6344    ///
6345    /// **Experimental.** This API is part of an experimental wire-protocol surface
6346    /// and may change or be removed in future SDK or CLI releases. Pin both the
6347    /// SDK and CLI versions if your code depends on it.
6348    ///
6349    /// </div>
6350    pub async fn list_templates(
6351        &self,
6352        params: McpResourcesListTemplatesRequest,
6353    ) -> Result<McpResourcesListTemplatesResult, Error> {
6354        let mut wire_params = serde_json::to_value(params)?;
6355        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
6356        let _value = self
6357            .session
6358            .client()
6359            .call(
6360                rpc_methods::SESSION_MCP_RESOURCES_LISTTEMPLATES,
6361                Some(wire_params),
6362            )
6363            .await?;
6364        Ok(serde_json::from_value(_value)?)
6365    }
6366}
6367
6368/// `session.metadata.*` RPCs.
6369#[derive(Clone, Copy)]
6370pub struct SessionRpcMetadata<'a> {
6371    pub(crate) session: &'a Session,
6372}
6373
6374impl<'a> SessionRpcMetadata<'a> {
6375    /// Returns a snapshot of the session's identifying metadata, mode, agent, and remote info.
6376    ///
6377    /// Wire method: `session.metadata.snapshot`.
6378    ///
6379    /// # Returns
6380    ///
6381    /// Point-in-time snapshot of slow-changing session identifier and state fields
6382    ///
6383    /// <div class="warning">
6384    ///
6385    /// **Experimental.** This API is part of an experimental wire-protocol surface
6386    /// and may change or be removed in future SDK or CLI releases. Pin both the
6387    /// SDK and CLI versions if your code depends on it.
6388    ///
6389    /// </div>
6390    pub async fn snapshot(&self) -> Result<SessionMetadataSnapshot, Error> {
6391        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
6392        let _value = self
6393            .session
6394            .client()
6395            .call(rpc_methods::SESSION_METADATA_SNAPSHOT, Some(wire_params))
6396            .await?;
6397        Ok(serde_json::from_value(_value)?)
6398    }
6399
6400    /// Reports whether the local session is currently processing user/agent messages.
6401    ///
6402    /// Wire method: `session.metadata.isProcessing`.
6403    ///
6404    /// # Returns
6405    ///
6406    /// Indicates whether the local session is currently processing a turn or background continuation.
6407    ///
6408    /// <div class="warning">
6409    ///
6410    /// **Experimental.** This API is part of an experimental wire-protocol surface
6411    /// and may change or be removed in future SDK or CLI releases. Pin both the
6412    /// SDK and CLI versions if your code depends on it.
6413    ///
6414    /// </div>
6415    pub async fn is_processing(&self) -> Result<MetadataIsProcessingResult, Error> {
6416        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
6417        let _value = self
6418            .session
6419            .client()
6420            .call(
6421                rpc_methods::SESSION_METADATA_ISPROCESSING,
6422                Some(wire_params),
6423            )
6424            .await?;
6425        Ok(serde_json::from_value(_value)?)
6426    }
6427
6428    /// Returns a snapshot of activity flags for the session.
6429    ///
6430    /// Wire method: `session.metadata.activity`.
6431    ///
6432    /// # Returns
6433    ///
6434    /// Current activity flags for the session.
6435    ///
6436    /// <div class="warning">
6437    ///
6438    /// **Experimental.** This API is part of an experimental wire-protocol surface
6439    /// and may change or be removed in future SDK or CLI releases. Pin both the
6440    /// SDK and CLI versions if your code depends on it.
6441    ///
6442    /// </div>
6443    pub async fn activity(&self) -> Result<SessionActivity, Error> {
6444        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
6445        let _value = self
6446            .session
6447            .client()
6448            .call(rpc_methods::SESSION_METADATA_ACTIVITY, Some(wire_params))
6449            .await?;
6450        Ok(serde_json::from_value(_value)?)
6451    }
6452
6453    /// Returns the token breakdown for the session's current context window for a given model.
6454    ///
6455    /// Wire method: `session.metadata.contextInfo`.
6456    ///
6457    /// # Parameters
6458    ///
6459    /// * `params` - Model identifier and token limits used to compute the context-info breakdown.
6460    ///
6461    /// # Returns
6462    ///
6463    /// Token breakdown for the session's current context window, or null if uninitialized.
6464    ///
6465    /// <div class="warning">
6466    ///
6467    /// **Experimental.** This API is part of an experimental wire-protocol surface
6468    /// and may change or be removed in future SDK or CLI releases. Pin both the
6469    /// SDK and CLI versions if your code depends on it.
6470    ///
6471    /// </div>
6472    pub async fn context_info(
6473        &self,
6474        params: MetadataContextInfoRequest,
6475    ) -> Result<MetadataContextInfoResult, Error> {
6476        let mut wire_params = serde_json::to_value(params)?;
6477        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
6478        let _value = self
6479            .session
6480            .client()
6481            .call(rpc_methods::SESSION_METADATA_CONTEXTINFO, Some(wire_params))
6482            .await?;
6483        Ok(serde_json::from_value(_value)?)
6484    }
6485
6486    /// Returns the experimental per-source attribution breakdown of the session's current context window as a flat list of entries (skills, subagents, MCP servers, built-in tools, plugin rollups, system/tool-definition costs, with nesting via parentId), plus the successful compaction count. The heaviest individual messages are available separately via `metadata.getContextHeaviestMessages`. Returns null until the session has initialized its system prompt and tool metadata.
6487    ///
6488    /// Wire method: `session.metadata.getContextAttribution`.
6489    ///
6490    /// # Returns
6491    ///
6492    /// Per-source attribution breakdown for the session's current context window, or null if uninitialized.
6493    ///
6494    /// <div class="warning">
6495    ///
6496    /// **Experimental.** This API is part of an experimental wire-protocol surface
6497    /// and may change or be removed in future SDK or CLI releases. Pin both the
6498    /// SDK and CLI versions if your code depends on it.
6499    ///
6500    /// </div>
6501    pub async fn get_context_attribution(&self) -> Result<MetadataContextAttributionResult, Error> {
6502        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
6503        let _value = self
6504            .session
6505            .client()
6506            .call(
6507                rpc_methods::SESSION_METADATA_GETCONTEXTATTRIBUTION,
6508                Some(wire_params),
6509            )
6510            .await?;
6511        Ok(serde_json::from_value(_value)?)
6512    }
6513
6514    /// Returns the largest individual messages currently in the session's context window, most-expensive first. Companion to `metadata.getContextAttribution`. Returns an empty list until the session has initialized.
6515    ///
6516    /// Wire method: `session.metadata.getContextHeaviestMessages`.
6517    ///
6518    /// # Parameters
6519    ///
6520    /// * `params` - Parameters for the heaviest-messages query.
6521    ///
6522    /// # Returns
6523    ///
6524    /// The heaviest individual messages in the session's context window, most-expensive first.
6525    ///
6526    /// <div class="warning">
6527    ///
6528    /// **Experimental.** This API is part of an experimental wire-protocol surface
6529    /// and may change or be removed in future SDK or CLI releases. Pin both the
6530    /// SDK and CLI versions if your code depends on it.
6531    ///
6532    /// </div>
6533    pub async fn get_context_heaviest_messages(
6534        &self,
6535        params: MetadataContextHeaviestMessagesRequest,
6536    ) -> Result<MetadataContextHeaviestMessagesResult, Error> {
6537        let mut wire_params = serde_json::to_value(params)?;
6538        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
6539        let _value = self
6540            .session
6541            .client()
6542            .call(
6543                rpc_methods::SESSION_METADATA_GETCONTEXTHEAVIESTMESSAGES,
6544                Some(wire_params),
6545            )
6546            .await?;
6547        Ok(serde_json::from_value(_value)?)
6548    }
6549
6550    /// Records a working-directory/git context change and emits a `session.context_changed` event. For a local session, a report whose `cwd` diverges from the session's current working directory is ignored (the call still succeeds but records nothing and emits no event): a local session's working directory is authoritative and is moved via `metadata.setWorkingDirectory` (or an SDK `session.resume` that supplies a `workingDirectory`), not by this method.
6551    ///
6552    /// Wire method: `session.metadata.recordContextChange`.
6553    ///
6554    /// # Parameters
6555    ///
6556    /// * `params` - Updated working-directory/git context to record on the session.
6557    ///
6558    /// # Returns
6559    ///
6560    /// Notify the session that its working directory context has changed. Emits a `session.context_changed` event so consumers (telemetry, OTel tracker, ACP, the timeline UI) can react. Use this when the host has detected a cwd/branch/repo change outside the session's normal lifecycle (e.g., after a shell command in interactive mode). For a local session, a report whose `cwd` diverges from the session's current working directory is ignored (the call still succeeds but records nothing and emits no event); move a local session's working directory via `metadata.setWorkingDirectory` instead.
6561    ///
6562    /// <div class="warning">
6563    ///
6564    /// **Experimental.** This API is part of an experimental wire-protocol surface
6565    /// and may change or be removed in future SDK or CLI releases. Pin both the
6566    /// SDK and CLI versions if your code depends on it.
6567    ///
6568    /// </div>
6569    pub async fn record_context_change(
6570        &self,
6571        params: MetadataRecordContextChangeRequest,
6572    ) -> Result<MetadataRecordContextChangeResult, Error> {
6573        let mut wire_params = serde_json::to_value(params)?;
6574        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
6575        let _value = self
6576            .session
6577            .client()
6578            .call(
6579                rpc_methods::SESSION_METADATA_RECORDCONTEXTCHANGE,
6580                Some(wire_params),
6581            )
6582            .await?;
6583        Ok(serde_json::from_value(_value)?)
6584    }
6585
6586    /// Updates the session's working directory. For local sessions the target is validated first (an absolute path that exists on disk) and the permission primary directory is re-based; a rejected validation fails the call before any session state changes.
6587    ///
6588    /// Wire method: `session.metadata.setWorkingDirectory`.
6589    ///
6590    /// # Parameters
6591    ///
6592    /// * `params` - Absolute path to set as the session's new working directory. For local sessions the path must be absolute and exist on disk: it is validated before any session state changes, and a failing validation rejects the call with nothing mutated, persisted, or emitted. Remote sessions record the path as-is.
6593    ///
6594    /// # Returns
6595    ///
6596    /// Update the session's working directory. Used by the host when the user explicitly changes cwd (e.g., the `/cd` slash command). The host is responsible for any related side-effects (file index, etc.); it does NOT change the process working directory (a session's cwd is per-session, not process-global). For local sessions the runtime validates the target first (an absolute path that exists on disk) and re-bases the permission primary directory; a rejected validation fails the call before anything is mutated, persisted, or emitted. Location-scoped permission rules are then re-keyed to the new directory (best-effort). Remote sessions only record the path.
6597    ///
6598    /// <div class="warning">
6599    ///
6600    /// **Experimental.** This API is part of an experimental wire-protocol surface
6601    /// and may change or be removed in future SDK or CLI releases. Pin both the
6602    /// SDK and CLI versions if your code depends on it.
6603    ///
6604    /// </div>
6605    pub async fn set_working_directory(
6606        &self,
6607        params: MetadataSetWorkingDirectoryRequest,
6608    ) -> Result<MetadataSetWorkingDirectoryResult, Error> {
6609        let mut wire_params = serde_json::to_value(params)?;
6610        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
6611        let _value = self
6612            .session
6613            .client()
6614            .call(
6615                rpc_methods::SESSION_METADATA_SETWORKINGDIRECTORY,
6616                Some(wire_params),
6617            )
6618            .await?;
6619        Ok(serde_json::from_value(_value)?)
6620    }
6621
6622    /// Re-tokenizes the session's existing messages against a model and returns aggregate token totals.
6623    ///
6624    /// Wire method: `session.metadata.recomputeContextTokens`.
6625    ///
6626    /// # Parameters
6627    ///
6628    /// * `params` - Model identifier to use when re-tokenizing the session's existing messages.
6629    ///
6630    /// # Returns
6631    ///
6632    /// Re-tokenize the session's existing messages against `modelId` and return the token totals. Useful for hosts that want an initial estimate of context usage on session resume, before the next agent turn fires `session.context_info_changed` events. Returns zeros for an empty session.
6633    ///
6634    /// <div class="warning">
6635    ///
6636    /// **Experimental.** This API is part of an experimental wire-protocol surface
6637    /// and may change or be removed in future SDK or CLI releases. Pin both the
6638    /// SDK and CLI versions if your code depends on it.
6639    ///
6640    /// </div>
6641    pub async fn recompute_context_tokens(
6642        &self,
6643        params: MetadataRecomputeContextTokensRequest,
6644    ) -> Result<MetadataRecomputeContextTokensResult, Error> {
6645        let mut wire_params = serde_json::to_value(params)?;
6646        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
6647        let _value = self
6648            .session
6649            .client()
6650            .call(
6651                rpc_methods::SESSION_METADATA_RECOMPUTECONTEXTTOKENS,
6652                Some(wire_params),
6653            )
6654            .await?;
6655        Ok(serde_json::from_value(_value)?)
6656    }
6657}
6658
6659/// `session.mode.*` RPCs.
6660#[derive(Clone, Copy)]
6661pub struct SessionRpcMode<'a> {
6662    pub(crate) session: &'a Session,
6663}
6664
6665impl<'a> SessionRpcMode<'a> {
6666    /// Gets the current agent interaction mode.
6667    ///
6668    /// Wire method: `session.mode.get`.
6669    ///
6670    /// # Returns
6671    ///
6672    /// The session mode the agent is operating in
6673    ///
6674    /// <div class="warning">
6675    ///
6676    /// **Experimental.** This API is part of an experimental wire-protocol surface
6677    /// and may change or be removed in future SDK or CLI releases. Pin both the
6678    /// SDK and CLI versions if your code depends on it.
6679    ///
6680    /// </div>
6681    pub async fn get(&self) -> Result<SessionMode, Error> {
6682        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
6683        let _value = self
6684            .session
6685            .client()
6686            .call(rpc_methods::SESSION_MODE_GET, Some(wire_params))
6687            .await?;
6688        Ok(serde_json::from_value(_value)?)
6689    }
6690
6691    /// Sets the current agent interaction mode.
6692    ///
6693    /// Wire method: `session.mode.set`.
6694    ///
6695    /// # Parameters
6696    ///
6697    /// * `params` - Agent interaction mode to apply to the session.
6698    ///
6699    /// <div class="warning">
6700    ///
6701    /// **Experimental.** This API is part of an experimental wire-protocol surface
6702    /// and may change or be removed in future SDK or CLI releases. Pin both the
6703    /// SDK and CLI versions if your code depends on it.
6704    ///
6705    /// </div>
6706    pub async fn set(&self, params: ModeSetRequest) -> Result<(), Error> {
6707        let mut wire_params = serde_json::to_value(params)?;
6708        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
6709        let _value = self
6710            .session
6711            .client()
6712            .call(rpc_methods::SESSION_MODE_SET, Some(wire_params))
6713            .await?;
6714        Ok(())
6715    }
6716}
6717
6718/// `session.model.*` RPCs.
6719#[derive(Clone, Copy)]
6720pub struct SessionRpcModel<'a> {
6721    pub(crate) session: &'a Session,
6722}
6723
6724impl<'a> SessionRpcModel<'a> {
6725    /// Gets the currently selected model for the session.
6726    ///
6727    /// Wire method: `session.model.getCurrent`.
6728    ///
6729    /// # Returns
6730    ///
6731    /// The currently selected model, reasoning effort, and context tier for the session. The context tier reflects `Session.getContextTier()`, restored from the session journal on resume.
6732    ///
6733    /// <div class="warning">
6734    ///
6735    /// **Experimental.** This API is part of an experimental wire-protocol surface
6736    /// and may change or be removed in future SDK or CLI releases. Pin both the
6737    /// SDK and CLI versions if your code depends on it.
6738    ///
6739    /// </div>
6740    pub async fn get_current(&self) -> Result<CurrentModel, Error> {
6741        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
6742        let _value = self
6743            .session
6744            .client()
6745            .call(rpc_methods::SESSION_MODEL_GETCURRENT, Some(wire_params))
6746            .await?;
6747        Ok(serde_json::from_value(_value)?)
6748    }
6749
6750    /// Switches the session to a model and optional reasoning configuration.
6751    ///
6752    /// Wire method: `session.model.switchTo`.
6753    ///
6754    /// # Parameters
6755    ///
6756    /// * `params` - Target model identifier and optional reasoning effort, summary, capability overrides, and context tier.
6757    ///
6758    /// # Returns
6759    ///
6760    /// The model identifier active on the session after the switch.
6761    ///
6762    /// <div class="warning">
6763    ///
6764    /// **Experimental.** This API is part of an experimental wire-protocol surface
6765    /// and may change or be removed in future SDK or CLI releases. Pin both the
6766    /// SDK and CLI versions if your code depends on it.
6767    ///
6768    /// </div>
6769    pub async fn switch_to(
6770        &self,
6771        params: ModelSwitchToRequest,
6772    ) -> Result<ModelSwitchToResult, Error> {
6773        let mut wire_params = serde_json::to_value(params)?;
6774        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
6775        let _value = self
6776            .session
6777            .client()
6778            .call(rpc_methods::SESSION_MODEL_SWITCHTO, Some(wire_params))
6779            .await?;
6780        Ok(serde_json::from_value(_value)?)
6781    }
6782
6783    /// Updates the session's reasoning effort without changing the selected model.
6784    ///
6785    /// Wire method: `session.model.setReasoningEffort`.
6786    ///
6787    /// # Parameters
6788    ///
6789    /// * `params` - Reasoning effort level to apply to the currently selected model.
6790    ///
6791    /// # Returns
6792    ///
6793    /// Update the session's reasoning effort without changing the selected model. Use `switchTo` instead when you also need to change the model. The runtime stores the effort on the session and applies it to subsequent turns.
6794    ///
6795    /// <div class="warning">
6796    ///
6797    /// **Experimental.** This API is part of an experimental wire-protocol surface
6798    /// and may change or be removed in future SDK or CLI releases. Pin both the
6799    /// SDK and CLI versions if your code depends on it.
6800    ///
6801    /// </div>
6802    pub async fn set_reasoning_effort(
6803        &self,
6804        params: ModelSetReasoningEffortRequest,
6805    ) -> Result<ModelSetReasoningEffortResult, Error> {
6806        let mut wire_params = serde_json::to_value(params)?;
6807        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
6808        let _value = self
6809            .session
6810            .client()
6811            .call(
6812                rpc_methods::SESSION_MODEL_SETREASONINGEFFORT,
6813                Some(wire_params),
6814            )
6815            .await?;
6816        Ok(serde_json::from_value(_value)?)
6817    }
6818
6819    /// Lists models available to this session using its own auth and integration context. Connected hosts (CLI TUI, GitHub App) should call this through the session client so remote sessions return the remote CLI's available models rather than the caller's.
6820    ///
6821    /// Wire method: `session.model.list`.
6822    ///
6823    /// # Returns
6824    ///
6825    /// The list of models available to this session.
6826    ///
6827    /// <div class="warning">
6828    ///
6829    /// **Experimental.** This API is part of an experimental wire-protocol surface
6830    /// and may change or be removed in future SDK or CLI releases. Pin both the
6831    /// SDK and CLI versions if your code depends on it.
6832    ///
6833    /// </div>
6834    pub async fn list(&self) -> Result<SessionModelList, Error> {
6835        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
6836        let _value = self
6837            .session
6838            .client()
6839            .call(rpc_methods::SESSION_MODEL_LIST, Some(wire_params))
6840            .await?;
6841        Ok(serde_json::from_value(_value)?)
6842    }
6843
6844    /// Lists models available to this session using its own auth and integration context. Connected hosts (CLI TUI, GitHub App) should call this through the session client so remote sessions return the remote CLI's available models rather than the caller's.
6845    ///
6846    /// Wire method: `session.model.list`.
6847    ///
6848    /// # Parameters
6849    ///
6850    /// * `params` - Optional listing options.
6851    ///
6852    /// # Returns
6853    ///
6854    /// The list of models available to this session.
6855    ///
6856    /// <div class="warning">
6857    ///
6858    /// **Experimental.** This API is part of an experimental wire-protocol surface
6859    /// and may change or be removed in future SDK or CLI releases. Pin both the
6860    /// SDK and CLI versions if your code depends on it.
6861    ///
6862    /// </div>
6863    pub async fn list_with_params(
6864        &self,
6865        params: ModelListRequest,
6866    ) -> Result<SessionModelList, Error> {
6867        let mut wire_params = serde_json::to_value(params)?;
6868        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
6869        let _value = self
6870            .session
6871            .client()
6872            .call(rpc_methods::SESSION_MODEL_LIST, Some(wire_params))
6873            .await?;
6874        Ok(serde_json::from_value(_value)?)
6875    }
6876}
6877
6878/// `session.name.*` RPCs.
6879#[derive(Clone, Copy)]
6880pub struct SessionRpcName<'a> {
6881    pub(crate) session: &'a Session,
6882}
6883
6884impl<'a> SessionRpcName<'a> {
6885    /// Gets the session's friendly name.
6886    ///
6887    /// Wire method: `session.name.get`.
6888    ///
6889    /// # Returns
6890    ///
6891    /// The session's friendly name, or null when not yet set.
6892    ///
6893    /// <div class="warning">
6894    ///
6895    /// **Experimental.** This API is part of an experimental wire-protocol surface
6896    /// and may change or be removed in future SDK or CLI releases. Pin both the
6897    /// SDK and CLI versions if your code depends on it.
6898    ///
6899    /// </div>
6900    pub async fn get(&self) -> Result<NameGetResult, Error> {
6901        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
6902        let _value = self
6903            .session
6904            .client()
6905            .call(rpc_methods::SESSION_NAME_GET, Some(wire_params))
6906            .await?;
6907        Ok(serde_json::from_value(_value)?)
6908    }
6909
6910    /// Sets the session's friendly name.
6911    ///
6912    /// Wire method: `session.name.set`.
6913    ///
6914    /// # Parameters
6915    ///
6916    /// * `params` - New friendly name to apply to the session.
6917    ///
6918    /// <div class="warning">
6919    ///
6920    /// **Experimental.** This API is part of an experimental wire-protocol surface
6921    /// and may change or be removed in future SDK or CLI releases. Pin both the
6922    /// SDK and CLI versions if your code depends on it.
6923    ///
6924    /// </div>
6925    pub async fn set(&self, params: NameSetRequest) -> Result<(), Error> {
6926        let mut wire_params = serde_json::to_value(params)?;
6927        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
6928        let _value = self
6929            .session
6930            .client()
6931            .call(rpc_methods::SESSION_NAME_SET, Some(wire_params))
6932            .await?;
6933        Ok(())
6934    }
6935
6936    /// Persists an auto-generated session summary as the session's name when no user-set name exists.
6937    ///
6938    /// Wire method: `session.name.setAuto`.
6939    ///
6940    /// # Parameters
6941    ///
6942    /// * `params` - Auto-generated session summary to apply as the session's name when no user-set name exists.
6943    ///
6944    /// # Returns
6945    ///
6946    /// Indicates whether the auto-generated summary was applied as the session's name.
6947    ///
6948    /// <div class="warning">
6949    ///
6950    /// **Experimental.** This API is part of an experimental wire-protocol surface
6951    /// and may change or be removed in future SDK or CLI releases. Pin both the
6952    /// SDK and CLI versions if your code depends on it.
6953    ///
6954    /// </div>
6955    pub async fn set_auto(&self, params: NameSetAutoRequest) -> Result<NameSetAutoResult, Error> {
6956        let mut wire_params = serde_json::to_value(params)?;
6957        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
6958        let _value = self
6959            .session
6960            .client()
6961            .call(rpc_methods::SESSION_NAME_SETAUTO, Some(wire_params))
6962            .await?;
6963        Ok(serde_json::from_value(_value)?)
6964    }
6965}
6966
6967/// `session.options.*` RPCs.
6968#[derive(Clone, Copy)]
6969pub struct SessionRpcOptions<'a> {
6970    pub(crate) session: &'a Session,
6971}
6972
6973impl<'a> SessionRpcOptions<'a> {
6974    /// Patches the genuinely-mutable subset of session options.
6975    ///
6976    /// Wire method: `session.options.update`.
6977    ///
6978    /// # Parameters
6979    ///
6980    /// * `params` - Patch of mutable session options to apply to the running session.
6981    ///
6982    /// # Returns
6983    ///
6984    /// Indicates whether the session options patch was applied successfully.
6985    ///
6986    /// <div class="warning">
6987    ///
6988    /// **Experimental.** This API is part of an experimental wire-protocol surface
6989    /// and may change or be removed in future SDK or CLI releases. Pin both the
6990    /// SDK and CLI versions if your code depends on it.
6991    ///
6992    /// </div>
6993    pub async fn update(
6994        &self,
6995        params: SessionUpdateOptionsParams,
6996    ) -> Result<SessionUpdateOptionsResult, Error> {
6997        let mut wire_params = serde_json::to_value(params)?;
6998        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
6999        let _value = self
7000            .session
7001            .client()
7002            .call(rpc_methods::SESSION_OPTIONS_UPDATE, Some(wire_params))
7003            .await?;
7004        Ok(serde_json::from_value(_value)?)
7005    }
7006}
7007
7008/// `session.permissions.*` RPCs.
7009#[derive(Clone, Copy)]
7010pub struct SessionRpcPermissions<'a> {
7011    pub(crate) session: &'a Session,
7012}
7013
7014impl<'a> SessionRpcPermissions<'a> {
7015    /// `session.permissions.folderTrust.*` sub-namespace.
7016    pub fn folder_trust(&self) -> SessionRpcPermissionsFolderTrust<'a> {
7017        SessionRpcPermissionsFolderTrust {
7018            session: self.session,
7019        }
7020    }
7021
7022    /// `session.permissions.locations.*` sub-namespace.
7023    pub fn locations(&self) -> SessionRpcPermissionsLocations<'a> {
7024        SessionRpcPermissionsLocations {
7025            session: self.session,
7026        }
7027    }
7028
7029    /// `session.permissions.paths.*` sub-namespace.
7030    pub fn paths(&self) -> SessionRpcPermissionsPaths<'a> {
7031        SessionRpcPermissionsPaths {
7032            session: self.session,
7033        }
7034    }
7035
7036    /// `session.permissions.urls.*` sub-namespace.
7037    pub fn urls(&self) -> SessionRpcPermissionsUrls<'a> {
7038        SessionRpcPermissionsUrls {
7039            session: self.session,
7040        }
7041    }
7042
7043    /// Replaces selected permission policy fields (rules, paths, URLs, exclusions, allow-all flags) on the session.
7044    ///
7045    /// Wire method: `session.permissions.configure`.
7046    ///
7047    /// # Parameters
7048    ///
7049    /// * `params` - Patch of permission policy fields to apply (omit a field to leave it unchanged).
7050    ///
7051    /// # Returns
7052    ///
7053    /// Indicates whether the operation succeeded.
7054    ///
7055    /// <div class="warning">
7056    ///
7057    /// **Experimental.** This API is part of an experimental wire-protocol surface
7058    /// and may change or be removed in future SDK or CLI releases. Pin both the
7059    /// SDK and CLI versions if your code depends on it.
7060    ///
7061    /// </div>
7062    pub async fn configure(
7063        &self,
7064        params: PermissionsConfigureParams,
7065    ) -> Result<PermissionsConfigureResult, Error> {
7066        let mut wire_params = serde_json::to_value(params)?;
7067        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
7068        let _value = self
7069            .session
7070            .client()
7071            .call(
7072                rpc_methods::SESSION_PERMISSIONS_CONFIGURE,
7073                Some(wire_params),
7074            )
7075            .await?;
7076        Ok(serde_json::from_value(_value)?)
7077    }
7078
7079    /// Provides a decision for a pending tool permission request.
7080    ///
7081    /// Wire method: `session.permissions.handlePendingPermissionRequest`.
7082    ///
7083    /// # Parameters
7084    ///
7085    /// * `params` - Pending permission request ID and the decision to apply (approve/reject and scope).
7086    ///
7087    /// # Returns
7088    ///
7089    /// Indicates whether the permission decision was applied; false when the request was already resolved.
7090    ///
7091    /// <div class="warning">
7092    ///
7093    /// **Experimental.** This API is part of an experimental wire-protocol surface
7094    /// and may change or be removed in future SDK or CLI releases. Pin both the
7095    /// SDK and CLI versions if your code depends on it.
7096    ///
7097    /// </div>
7098    pub async fn handle_pending_permission_request(
7099        &self,
7100        params: PermissionDecisionRequest,
7101    ) -> Result<PermissionRequestResult, Error> {
7102        let mut wire_params = serde_json::to_value(params)?;
7103        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
7104        let _value = self
7105            .session
7106            .client()
7107            .call(
7108                rpc_methods::SESSION_PERMISSIONS_HANDLEPENDINGPERMISSIONREQUEST,
7109                Some(wire_params),
7110            )
7111            .await?;
7112        Ok(serde_json::from_value(_value)?)
7113    }
7114
7115    /// Reconstructs the set of pending tool permission requests from the session's event history.
7116    ///
7117    /// Wire method: `session.permissions.pendingRequests`.
7118    ///
7119    /// # Returns
7120    ///
7121    /// List of pending permission requests reconstructed from event history.
7122    ///
7123    /// <div class="warning">
7124    ///
7125    /// **Experimental.** This API is part of an experimental wire-protocol surface
7126    /// and may change or be removed in future SDK or CLI releases. Pin both the
7127    /// SDK and CLI versions if your code depends on it.
7128    ///
7129    /// </div>
7130    pub async fn pending_requests(&self) -> Result<PendingPermissionRequestList, Error> {
7131        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
7132        let _value = self
7133            .session
7134            .client()
7135            .call(
7136                rpc_methods::SESSION_PERMISSIONS_PENDINGREQUESTS,
7137                Some(wire_params),
7138            )
7139            .await?;
7140        Ok(serde_json::from_value(_value)?)
7141    }
7142
7143    /// Enables or disables automatic approval of tool permission requests for the session.
7144    ///
7145    /// Wire method: `session.permissions.setApproveAll`.
7146    ///
7147    /// # Parameters
7148    ///
7149    /// * `params` - Allow-all toggle for tool permission requests, with an optional telemetry source.
7150    ///
7151    /// # Returns
7152    ///
7153    /// Indicates whether the operation succeeded.
7154    ///
7155    /// <div class="warning">
7156    ///
7157    /// **Experimental.** This API is part of an experimental wire-protocol surface
7158    /// and may change or be removed in future SDK or CLI releases. Pin both the
7159    /// SDK and CLI versions if your code depends on it.
7160    ///
7161    /// </div>
7162    pub async fn set_approve_all(
7163        &self,
7164        params: PermissionsSetApproveAllRequest,
7165    ) -> Result<PermissionsSetApproveAllResult, Error> {
7166        let mut wire_params = serde_json::to_value(params)?;
7167        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
7168        let _value = self
7169            .session
7170            .client()
7171            .call(
7172                rpc_methods::SESSION_PERMISSIONS_SETAPPROVEALL,
7173                Some(wire_params),
7174            )
7175            .await?;
7176        Ok(serde_json::from_value(_value)?)
7177    }
7178
7179    /// Sets the allow-all permission mode for the session. Used by attach-mode clients (e.g. LocalRpcSession's `/allow-all` forwarder) to flip the target session's permission state. The `on` mode swaps in unrestricted path and URL managers and emits `session.permissions_changed` on transition; the `auto` mode keeps normal prompt paths active while attaching LLM safety recommendations. The result returns the authoritative post-mutation state so callers can update their local mirrors without racing the `session.permissions_changed` notification on the same wire.
7180    ///
7181    /// Wire method: `session.permissions.setAllowAll`.
7182    ///
7183    /// # Parameters
7184    ///
7185    /// * `params` - Allow-all mode to apply for the session.
7186    ///
7187    /// # Returns
7188    ///
7189    /// Indicates whether the operation succeeded and reports the post-mutation state.
7190    ///
7191    /// <div class="warning">
7192    ///
7193    /// **Experimental.** This API is part of an experimental wire-protocol surface
7194    /// and may change or be removed in future SDK or CLI releases. Pin both the
7195    /// SDK and CLI versions if your code depends on it.
7196    ///
7197    /// </div>
7198    pub async fn set_allow_all(
7199        &self,
7200        params: PermissionsSetAllowAllRequest,
7201    ) -> Result<AllowAllPermissionSetResult, Error> {
7202        let mut wire_params = serde_json::to_value(params)?;
7203        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
7204        let _value = self
7205            .session
7206            .client()
7207            .call(
7208                rpc_methods::SESSION_PERMISSIONS_SETALLOWALL,
7209                Some(wire_params),
7210            )
7211            .await?;
7212        Ok(serde_json::from_value(_value)?)
7213    }
7214
7215    /// Returns the current allow-all permission mode for the session.
7216    ///
7217    /// Wire method: `session.permissions.getAllowAll`.
7218    ///
7219    /// # Returns
7220    ///
7221    /// Current allow-all permission mode.
7222    ///
7223    /// <div class="warning">
7224    ///
7225    /// **Experimental.** This API is part of an experimental wire-protocol surface
7226    /// and may change or be removed in future SDK or CLI releases. Pin both the
7227    /// SDK and CLI versions if your code depends on it.
7228    ///
7229    /// </div>
7230    pub async fn get_allow_all(&self) -> Result<AllowAllPermissionState, Error> {
7231        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
7232        let _value = self
7233            .session
7234            .client()
7235            .call(
7236                rpc_methods::SESSION_PERMISSIONS_GETALLOWALL,
7237                Some(wire_params),
7238            )
7239            .await?;
7240        Ok(serde_json::from_value(_value)?)
7241    }
7242
7243    /// Adds or removes session-scoped or location-scoped permission rules.
7244    ///
7245    /// Wire method: `session.permissions.modifyRules`.
7246    ///
7247    /// # Parameters
7248    ///
7249    /// * `params` - Scope and add/remove instructions for modifying session- or location-scoped permission rules.
7250    ///
7251    /// # Returns
7252    ///
7253    /// Indicates whether the operation succeeded.
7254    ///
7255    /// <div class="warning">
7256    ///
7257    /// **Experimental.** This API is part of an experimental wire-protocol surface
7258    /// and may change or be removed in future SDK or CLI releases. Pin both the
7259    /// SDK and CLI versions if your code depends on it.
7260    ///
7261    /// </div>
7262    pub async fn modify_rules(
7263        &self,
7264        params: PermissionsModifyRulesParams,
7265    ) -> Result<PermissionsModifyRulesResult, Error> {
7266        let mut wire_params = serde_json::to_value(params)?;
7267        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
7268        let _value = self
7269            .session
7270            .client()
7271            .call(
7272                rpc_methods::SESSION_PERMISSIONS_MODIFYRULES,
7273                Some(wire_params),
7274            )
7275            .await?;
7276        Ok(serde_json::from_value(_value)?)
7277    }
7278
7279    /// Sets whether the client wants permission prompts bridged into session events.
7280    ///
7281    /// Wire method: `session.permissions.setRequired`.
7282    ///
7283    /// # Parameters
7284    ///
7285    /// * `params` - Toggles whether permission prompts should be bridged into session events for this client.
7286    ///
7287    /// # Returns
7288    ///
7289    /// Indicates whether the operation succeeded.
7290    ///
7291    /// <div class="warning">
7292    ///
7293    /// **Experimental.** This API is part of an experimental wire-protocol surface
7294    /// and may change or be removed in future SDK or CLI releases. Pin both the
7295    /// SDK and CLI versions if your code depends on it.
7296    ///
7297    /// </div>
7298    pub async fn set_required(
7299        &self,
7300        params: PermissionsSetRequiredRequest,
7301    ) -> Result<PermissionsSetRequiredResult, Error> {
7302        let mut wire_params = serde_json::to_value(params)?;
7303        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
7304        let _value = self
7305            .session
7306            .client()
7307            .call(
7308                rpc_methods::SESSION_PERMISSIONS_SETREQUIRED,
7309                Some(wire_params),
7310            )
7311            .await?;
7312        Ok(serde_json::from_value(_value)?)
7313    }
7314
7315    /// Clears session-scoped tool permission approvals.
7316    ///
7317    /// Wire method: `session.permissions.resetSessionApprovals`.
7318    ///
7319    /// # Parameters
7320    ///
7321    /// * `params` - Clears session-scoped tool permission approvals, and optionally the location-scoped ones.
7322    ///
7323    /// # Returns
7324    ///
7325    /// Indicates whether the operation succeeded.
7326    ///
7327    /// <div class="warning">
7328    ///
7329    /// **Experimental.** This API is part of an experimental wire-protocol surface
7330    /// and may change or be removed in future SDK or CLI releases. Pin both the
7331    /// SDK and CLI versions if your code depends on it.
7332    ///
7333    /// </div>
7334    pub async fn reset_session_approvals(
7335        &self,
7336        params: PermissionsResetSessionApprovalsRequest,
7337    ) -> Result<PermissionsResetSessionApprovalsResult, Error> {
7338        let mut wire_params = serde_json::to_value(params)?;
7339        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
7340        let _value = self
7341            .session
7342            .client()
7343            .call(
7344                rpc_methods::SESSION_PERMISSIONS_RESETSESSIONAPPROVALS,
7345                Some(wire_params),
7346            )
7347            .await?;
7348        Ok(serde_json::from_value(_value)?)
7349    }
7350
7351    /// Notifies the runtime that a permission prompt UI has been shown to the user.
7352    ///
7353    /// Wire method: `session.permissions.notifyPromptShown`.
7354    ///
7355    /// # Parameters
7356    ///
7357    /// * `params` - Notification payload describing the permission prompt that the client just rendered.
7358    ///
7359    /// # Returns
7360    ///
7361    /// Indicates whether the operation succeeded.
7362    ///
7363    /// <div class="warning">
7364    ///
7365    /// **Experimental.** This API is part of an experimental wire-protocol surface
7366    /// and may change or be removed in future SDK or CLI releases. Pin both the
7367    /// SDK and CLI versions if your code depends on it.
7368    ///
7369    /// </div>
7370    pub async fn notify_prompt_shown(
7371        &self,
7372        params: PermissionPromptShownNotification,
7373    ) -> Result<PermissionsNotifyPromptShownResult, Error> {
7374        let mut wire_params = serde_json::to_value(params)?;
7375        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
7376        let _value = self
7377            .session
7378            .client()
7379            .call(
7380                rpc_methods::SESSION_PERMISSIONS_NOTIFYPROMPTSHOWN,
7381                Some(wire_params),
7382            )
7383            .await?;
7384        Ok(serde_json::from_value(_value)?)
7385    }
7386}
7387
7388/// `session.permissions.folderTrust.*` RPCs.
7389#[derive(Clone, Copy)]
7390pub struct SessionRpcPermissionsFolderTrust<'a> {
7391    pub(crate) session: &'a Session,
7392}
7393
7394impl<'a> SessionRpcPermissionsFolderTrust<'a> {
7395    /// Reports whether a folder is trusted according to the user's folder trust state.
7396    ///
7397    /// Wire method: `session.permissions.folderTrust.isTrusted`.
7398    ///
7399    /// # Parameters
7400    ///
7401    /// * `params` - Folder path to check for trust.
7402    ///
7403    /// # Returns
7404    ///
7405    /// Folder trust check result.
7406    ///
7407    /// <div class="warning">
7408    ///
7409    /// **Experimental.** This API is part of an experimental wire-protocol surface
7410    /// and may change or be removed in future SDK or CLI releases. Pin both the
7411    /// SDK and CLI versions if your code depends on it.
7412    ///
7413    /// </div>
7414    pub async fn is_trusted(
7415        &self,
7416        params: FolderTrustCheckParams,
7417    ) -> Result<FolderTrustCheckResult, Error> {
7418        let mut wire_params = serde_json::to_value(params)?;
7419        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
7420        let _value = self
7421            .session
7422            .client()
7423            .call(
7424                rpc_methods::SESSION_PERMISSIONS_FOLDERTRUST_ISTRUSTED,
7425                Some(wire_params),
7426            )
7427            .await?;
7428        Ok(serde_json::from_value(_value)?)
7429    }
7430
7431    /// Adds a folder to the user's trusted folders list.
7432    ///
7433    /// Wire method: `session.permissions.folderTrust.addTrusted`.
7434    ///
7435    /// # Parameters
7436    ///
7437    /// * `params` - Folder path to add to trusted folders.
7438    ///
7439    /// # Returns
7440    ///
7441    /// Indicates whether the operation succeeded.
7442    ///
7443    /// <div class="warning">
7444    ///
7445    /// **Experimental.** This API is part of an experimental wire-protocol surface
7446    /// and may change or be removed in future SDK or CLI releases. Pin both the
7447    /// SDK and CLI versions if your code depends on it.
7448    ///
7449    /// </div>
7450    pub async fn add_trusted(
7451        &self,
7452        params: FolderTrustAddParams,
7453    ) -> Result<PermissionsFolderTrustAddTrustedResult, Error> {
7454        let mut wire_params = serde_json::to_value(params)?;
7455        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
7456        let _value = self
7457            .session
7458            .client()
7459            .call(
7460                rpc_methods::SESSION_PERMISSIONS_FOLDERTRUST_ADDTRUSTED,
7461                Some(wire_params),
7462            )
7463            .await?;
7464        Ok(serde_json::from_value(_value)?)
7465    }
7466}
7467
7468/// `session.permissions.locations.*` RPCs.
7469#[derive(Clone, Copy)]
7470pub struct SessionRpcPermissionsLocations<'a> {
7471    pub(crate) session: &'a Session,
7472}
7473
7474impl<'a> SessionRpcPermissionsLocations<'a> {
7475    /// Resolves the permission location key and type for a working directory.
7476    ///
7477    /// Wire method: `session.permissions.locations.resolve`.
7478    ///
7479    /// # Parameters
7480    ///
7481    /// * `params` - Working directory to resolve into a location-permissions key.
7482    ///
7483    /// # Returns
7484    ///
7485    /// Resolved location-permissions key and type.
7486    ///
7487    /// <div class="warning">
7488    ///
7489    /// **Experimental.** This API is part of an experimental wire-protocol surface
7490    /// and may change or be removed in future SDK or CLI releases. Pin both the
7491    /// SDK and CLI versions if your code depends on it.
7492    ///
7493    /// </div>
7494    pub async fn resolve(
7495        &self,
7496        params: PermissionLocationResolveParams,
7497    ) -> Result<PermissionLocationResolveResult, Error> {
7498        let mut wire_params = serde_json::to_value(params)?;
7499        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
7500        let _value = self
7501            .session
7502            .client()
7503            .call(
7504                rpc_methods::SESSION_PERMISSIONS_LOCATIONS_RESOLVE,
7505                Some(wire_params),
7506            )
7507            .await?;
7508        Ok(serde_json::from_value(_value)?)
7509    }
7510
7511    /// Applies persisted location-scoped tool approvals and allowed directories for a working directory to this session's permission service.
7512    ///
7513    /// Wire method: `session.permissions.locations.apply`.
7514    ///
7515    /// # Parameters
7516    ///
7517    /// * `params` - Working directory to load persisted location permissions for.
7518    ///
7519    /// # Returns
7520    ///
7521    /// Summary of persisted location permissions applied to the session.
7522    ///
7523    /// <div class="warning">
7524    ///
7525    /// **Experimental.** This API is part of an experimental wire-protocol surface
7526    /// and may change or be removed in future SDK or CLI releases. Pin both the
7527    /// SDK and CLI versions if your code depends on it.
7528    ///
7529    /// </div>
7530    pub async fn apply(
7531        &self,
7532        params: PermissionLocationApplyParams,
7533    ) -> Result<PermissionLocationApplyResult, Error> {
7534        let mut wire_params = serde_json::to_value(params)?;
7535        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
7536        let _value = self
7537            .session
7538            .client()
7539            .call(
7540                rpc_methods::SESSION_PERMISSIONS_LOCATIONS_APPLY,
7541                Some(wire_params),
7542            )
7543            .await?;
7544        Ok(serde_json::from_value(_value)?)
7545    }
7546
7547    /// Persists a tool approval for a permission location and applies its rules to this session's live permission service.
7548    ///
7549    /// Wire method: `session.permissions.locations.addToolApproval`.
7550    ///
7551    /// # Parameters
7552    ///
7553    /// * `params` - Location-scoped tool approval to persist.
7554    ///
7555    /// # Returns
7556    ///
7557    /// Indicates whether the operation succeeded.
7558    ///
7559    /// <div class="warning">
7560    ///
7561    /// **Experimental.** This API is part of an experimental wire-protocol surface
7562    /// and may change or be removed in future SDK or CLI releases. Pin both the
7563    /// SDK and CLI versions if your code depends on it.
7564    ///
7565    /// </div>
7566    pub async fn add_tool_approval(
7567        &self,
7568        params: PermissionLocationAddToolApprovalParams,
7569    ) -> Result<PermissionsLocationsAddToolApprovalResult, Error> {
7570        let mut wire_params = serde_json::to_value(params)?;
7571        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
7572        let _value = self
7573            .session
7574            .client()
7575            .call(
7576                rpc_methods::SESSION_PERMISSIONS_LOCATIONS_ADDTOOLAPPROVAL,
7577                Some(wire_params),
7578            )
7579            .await?;
7580        Ok(serde_json::from_value(_value)?)
7581    }
7582}
7583
7584/// `session.permissions.paths.*` RPCs.
7585#[derive(Clone, Copy)]
7586pub struct SessionRpcPermissionsPaths<'a> {
7587    pub(crate) session: &'a Session,
7588}
7589
7590impl<'a> SessionRpcPermissionsPaths<'a> {
7591    /// Returns the session's allowed directories and primary working directory.
7592    ///
7593    /// Wire method: `session.permissions.paths.list`.
7594    ///
7595    /// # Returns
7596    ///
7597    /// Snapshot of the session's allow-listed directories and primary working directory.
7598    ///
7599    /// <div class="warning">
7600    ///
7601    /// **Experimental.** This API is part of an experimental wire-protocol surface
7602    /// and may change or be removed in future SDK or CLI releases. Pin both the
7603    /// SDK and CLI versions if your code depends on it.
7604    ///
7605    /// </div>
7606    pub async fn list(&self) -> Result<PermissionPathsList, Error> {
7607        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
7608        let _value = self
7609            .session
7610            .client()
7611            .call(
7612                rpc_methods::SESSION_PERMISSIONS_PATHS_LIST,
7613                Some(wire_params),
7614            )
7615            .await?;
7616        Ok(serde_json::from_value(_value)?)
7617    }
7618
7619    /// Adds a directory to the session's allow-list.
7620    ///
7621    /// Wire method: `session.permissions.paths.add`.
7622    ///
7623    /// # Parameters
7624    ///
7625    /// * `params` - Directory path to add to the session's allowed directories.
7626    ///
7627    /// # Returns
7628    ///
7629    /// Indicates whether the operation succeeded.
7630    ///
7631    /// <div class="warning">
7632    ///
7633    /// **Experimental.** This API is part of an experimental wire-protocol surface
7634    /// and may change or be removed in future SDK or CLI releases. Pin both the
7635    /// SDK and CLI versions if your code depends on it.
7636    ///
7637    /// </div>
7638    pub async fn add(
7639        &self,
7640        params: PermissionPathsAddParams,
7641    ) -> Result<PermissionsPathsAddResult, Error> {
7642        let mut wire_params = serde_json::to_value(params)?;
7643        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
7644        let _value = self
7645            .session
7646            .client()
7647            .call(
7648                rpc_methods::SESSION_PERMISSIONS_PATHS_ADD,
7649                Some(wire_params),
7650            )
7651            .await?;
7652        Ok(serde_json::from_value(_value)?)
7653    }
7654
7655    /// Updates the session's primary working directory used by the permission policy.
7656    ///
7657    /// Wire method: `session.permissions.paths.updatePrimary`.
7658    ///
7659    /// # Parameters
7660    ///
7661    /// * `params` - Directory path to set as the session's new primary working directory.
7662    ///
7663    /// # Returns
7664    ///
7665    /// Indicates whether the operation succeeded.
7666    ///
7667    /// <div class="warning">
7668    ///
7669    /// **Experimental.** This API is part of an experimental wire-protocol surface
7670    /// and may change or be removed in future SDK or CLI releases. Pin both the
7671    /// SDK and CLI versions if your code depends on it.
7672    ///
7673    /// </div>
7674    pub async fn update_primary(
7675        &self,
7676        params: PermissionPathsUpdatePrimaryParams,
7677    ) -> Result<PermissionsPathsUpdatePrimaryResult, Error> {
7678        let mut wire_params = serde_json::to_value(params)?;
7679        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
7680        let _value = self
7681            .session
7682            .client()
7683            .call(
7684                rpc_methods::SESSION_PERMISSIONS_PATHS_UPDATEPRIMARY,
7685                Some(wire_params),
7686            )
7687            .await?;
7688        Ok(serde_json::from_value(_value)?)
7689    }
7690
7691    /// Reports whether a path falls within any of the session's allowed directories.
7692    ///
7693    /// Wire method: `session.permissions.paths.isPathWithinAllowedDirectories`.
7694    ///
7695    /// # Parameters
7696    ///
7697    /// * `params` - Path to evaluate against the session's allowed directories.
7698    ///
7699    /// # Returns
7700    ///
7701    /// Indicates whether the supplied path is within the session's allowed directories.
7702    ///
7703    /// <div class="warning">
7704    ///
7705    /// **Experimental.** This API is part of an experimental wire-protocol surface
7706    /// and may change or be removed in future SDK or CLI releases. Pin both the
7707    /// SDK and CLI versions if your code depends on it.
7708    ///
7709    /// </div>
7710    pub async fn is_path_within_allowed_directories(
7711        &self,
7712        params: PermissionPathsAllowedCheckParams,
7713    ) -> Result<PermissionPathsAllowedCheckResult, Error> {
7714        let mut wire_params = serde_json::to_value(params)?;
7715        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
7716        let _value = self
7717            .session
7718            .client()
7719            .call(
7720                rpc_methods::SESSION_PERMISSIONS_PATHS_ISPATHWITHINALLOWEDDIRECTORIES,
7721                Some(wire_params),
7722            )
7723            .await?;
7724        Ok(serde_json::from_value(_value)?)
7725    }
7726
7727    /// Reports whether a path falls within the session's workspace (primary) directory.
7728    ///
7729    /// Wire method: `session.permissions.paths.isPathWithinWorkspace`.
7730    ///
7731    /// # Parameters
7732    ///
7733    /// * `params` - Path to evaluate against the session's workspace (primary) directory.
7734    ///
7735    /// # Returns
7736    ///
7737    /// Indicates whether the supplied path is within the session's workspace directory.
7738    ///
7739    /// <div class="warning">
7740    ///
7741    /// **Experimental.** This API is part of an experimental wire-protocol surface
7742    /// and may change or be removed in future SDK or CLI releases. Pin both the
7743    /// SDK and CLI versions if your code depends on it.
7744    ///
7745    /// </div>
7746    pub async fn is_path_within_workspace(
7747        &self,
7748        params: PermissionPathsWorkspaceCheckParams,
7749    ) -> Result<PermissionPathsWorkspaceCheckResult, Error> {
7750        let mut wire_params = serde_json::to_value(params)?;
7751        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
7752        let _value = self
7753            .session
7754            .client()
7755            .call(
7756                rpc_methods::SESSION_PERMISSIONS_PATHS_ISPATHWITHINWORKSPACE,
7757                Some(wire_params),
7758            )
7759            .await?;
7760        Ok(serde_json::from_value(_value)?)
7761    }
7762}
7763
7764/// `session.permissions.urls.*` RPCs.
7765#[derive(Clone, Copy)]
7766pub struct SessionRpcPermissionsUrls<'a> {
7767    pub(crate) session: &'a Session,
7768}
7769
7770impl<'a> SessionRpcPermissionsUrls<'a> {
7771    /// Toggles the runtime's URL-permission policy between unrestricted and restricted modes.
7772    ///
7773    /// Wire method: `session.permissions.urls.setUnrestrictedMode`.
7774    ///
7775    /// # Parameters
7776    ///
7777    /// * `params` - Whether the URL-permission policy should run in unrestricted mode.
7778    ///
7779    /// # Returns
7780    ///
7781    /// Indicates whether the operation succeeded.
7782    ///
7783    /// <div class="warning">
7784    ///
7785    /// **Experimental.** This API is part of an experimental wire-protocol surface
7786    /// and may change or be removed in future SDK or CLI releases. Pin both the
7787    /// SDK and CLI versions if your code depends on it.
7788    ///
7789    /// </div>
7790    pub async fn set_unrestricted_mode(
7791        &self,
7792        params: PermissionUrlsSetUnrestrictedModeParams,
7793    ) -> Result<PermissionsUrlsSetUnrestrictedModeResult, Error> {
7794        let mut wire_params = serde_json::to_value(params)?;
7795        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
7796        let _value = self
7797            .session
7798            .client()
7799            .call(
7800                rpc_methods::SESSION_PERMISSIONS_URLS_SETUNRESTRICTEDMODE,
7801                Some(wire_params),
7802            )
7803            .await?;
7804        Ok(serde_json::from_value(_value)?)
7805    }
7806}
7807
7808/// `session.plan.*` RPCs.
7809#[derive(Clone, Copy)]
7810pub struct SessionRpcPlan<'a> {
7811    pub(crate) session: &'a Session,
7812}
7813
7814impl<'a> SessionRpcPlan<'a> {
7815    /// Reads the session plan file from the workspace.
7816    ///
7817    /// Wire method: `session.plan.read`.
7818    ///
7819    /// # Returns
7820    ///
7821    /// Existence, contents, and resolved path of the session plan file.
7822    ///
7823    /// <div class="warning">
7824    ///
7825    /// **Experimental.** This API is part of an experimental wire-protocol surface
7826    /// and may change or be removed in future SDK or CLI releases. Pin both the
7827    /// SDK and CLI versions if your code depends on it.
7828    ///
7829    /// </div>
7830    pub async fn read(&self) -> Result<PlanReadResult, Error> {
7831        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
7832        let _value = self
7833            .session
7834            .client()
7835            .call(rpc_methods::SESSION_PLAN_READ, Some(wire_params))
7836            .await?;
7837        Ok(serde_json::from_value(_value)?)
7838    }
7839
7840    /// Writes new content to the session plan file.
7841    ///
7842    /// Wire method: `session.plan.update`.
7843    ///
7844    /// # Parameters
7845    ///
7846    /// * `params` - Replacement contents to write to the session plan file.
7847    ///
7848    /// <div class="warning">
7849    ///
7850    /// **Experimental.** This API is part of an experimental wire-protocol surface
7851    /// and may change or be removed in future SDK or CLI releases. Pin both the
7852    /// SDK and CLI versions if your code depends on it.
7853    ///
7854    /// </div>
7855    pub async fn update(&self, params: PlanUpdateRequest) -> Result<(), Error> {
7856        let mut wire_params = serde_json::to_value(params)?;
7857        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
7858        let _value = self
7859            .session
7860            .client()
7861            .call(rpc_methods::SESSION_PLAN_UPDATE, Some(wire_params))
7862            .await?;
7863        Ok(())
7864    }
7865
7866    /// Deletes the session plan file from the workspace.
7867    ///
7868    /// Wire method: `session.plan.delete`.
7869    ///
7870    /// <div class="warning">
7871    ///
7872    /// **Experimental.** This API is part of an experimental wire-protocol surface
7873    /// and may change or be removed in future SDK or CLI releases. Pin both the
7874    /// SDK and CLI versions if your code depends on it.
7875    ///
7876    /// </div>
7877    pub async fn delete(&self) -> Result<(), Error> {
7878        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
7879        let _value = self
7880            .session
7881            .client()
7882            .call(rpc_methods::SESSION_PLAN_DELETE, Some(wire_params))
7883            .await?;
7884        Ok(())
7885    }
7886
7887    /// Reads todo rows from the session SQL database for plan rendering.
7888    ///
7889    /// Wire method: `session.plan.readSqlTodos`.
7890    ///
7891    /// # Returns
7892    ///
7893    /// Todo rows read from the session SQL database. Empty when no session database is available.
7894    ///
7895    /// <div class="warning">
7896    ///
7897    /// **Experimental.** This API is part of an experimental wire-protocol surface
7898    /// and may change or be removed in future SDK or CLI releases. Pin both the
7899    /// SDK and CLI versions if your code depends on it.
7900    ///
7901    /// </div>
7902    pub async fn read_sql_todos(&self) -> Result<PlanReadSqlTodosResult, Error> {
7903        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
7904        let _value = self
7905            .session
7906            .client()
7907            .call(rpc_methods::SESSION_PLAN_READSQLTODOS, Some(wire_params))
7908            .await?;
7909        Ok(serde_json::from_value(_value)?)
7910    }
7911
7912    /// Reads todo rows AND dependency edges from the session SQL database for structured progress UI. Same defensive behavior as readSqlTodos — returns empty arrays when the database, tables, or columns aren't available. Clients should call this on session start and after every `session.todos_changed` event to refresh structured-UI rendering.
7913    ///
7914    /// Wire method: `session.plan.readSqlTodosWithDependencies`.
7915    ///
7916    /// # Returns
7917    ///
7918    /// Todo rows + dependency edges read from the session SQL database.
7919    ///
7920    /// <div class="warning">
7921    ///
7922    /// **Experimental.** This API is part of an experimental wire-protocol surface
7923    /// and may change or be removed in future SDK or CLI releases. Pin both the
7924    /// SDK and CLI versions if your code depends on it.
7925    ///
7926    /// </div>
7927    pub async fn read_sql_todos_with_dependencies(
7928        &self,
7929    ) -> Result<PlanReadSqlTodosWithDependenciesResult, Error> {
7930        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
7931        let _value = self
7932            .session
7933            .client()
7934            .call(
7935                rpc_methods::SESSION_PLAN_READSQLTODOSWITHDEPENDENCIES,
7936                Some(wire_params),
7937            )
7938            .await?;
7939        Ok(serde_json::from_value(_value)?)
7940    }
7941}
7942
7943/// `session.plugins.*` RPCs.
7944#[derive(Clone, Copy)]
7945pub struct SessionRpcPlugins<'a> {
7946    pub(crate) session: &'a Session,
7947}
7948
7949impl<'a> SessionRpcPlugins<'a> {
7950    /// Lists plugins installed for the session.
7951    ///
7952    /// Wire method: `session.plugins.list`.
7953    ///
7954    /// # Returns
7955    ///
7956    /// Plugins installed for the session, with their enabled state and version metadata.
7957    ///
7958    /// <div class="warning">
7959    ///
7960    /// **Experimental.** This API is part of an experimental wire-protocol surface
7961    /// and may change or be removed in future SDK or CLI releases. Pin both the
7962    /// SDK and CLI versions if your code depends on it.
7963    ///
7964    /// </div>
7965    pub async fn list(&self) -> Result<PluginList, Error> {
7966        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
7967        let _value = self
7968            .session
7969            .client()
7970            .call(rpc_methods::SESSION_PLUGINS_LIST, Some(wire_params))
7971            .await?;
7972        Ok(serde_json::from_value(_value)?)
7973    }
7974
7975    /// Reloads the session's plugin set, refreshing MCP servers, custom agents, hooks, and skills cache so SDK-driven changes via `server.plugins.*` take effect immediately.
7976    ///
7977    /// Wire method: `session.plugins.reload`.
7978    ///
7979    /// <div class="warning">
7980    ///
7981    /// **Experimental.** This API is part of an experimental wire-protocol surface
7982    /// and may change or be removed in future SDK or CLI releases. Pin both the
7983    /// SDK and CLI versions if your code depends on it.
7984    ///
7985    /// </div>
7986    pub async fn reload(&self) -> Result<(), Error> {
7987        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
7988        let _value = self
7989            .session
7990            .client()
7991            .call(rpc_methods::SESSION_PLUGINS_RELOAD, Some(wire_params))
7992            .await?;
7993        Ok(())
7994    }
7995
7996    /// Reloads the session's plugin set, refreshing MCP servers, custom agents, hooks, and skills cache so SDK-driven changes via `server.plugins.*` take effect immediately.
7997    ///
7998    /// Wire method: `session.plugins.reload`.
7999    ///
8000    /// # Parameters
8001    ///
8002    /// * `params` - Optional flags controlling which side effects the reload performs.
8003    ///
8004    /// <div class="warning">
8005    ///
8006    /// **Experimental.** This API is part of an experimental wire-protocol surface
8007    /// and may change or be removed in future SDK or CLI releases. Pin both the
8008    /// SDK and CLI versions if your code depends on it.
8009    ///
8010    /// </div>
8011    pub async fn reload_with_params(&self, params: PluginsReloadRequest) -> Result<(), Error> {
8012        let mut wire_params = serde_json::to_value(params)?;
8013        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
8014        let _value = self
8015            .session
8016            .client()
8017            .call(rpc_methods::SESSION_PLUGINS_RELOAD, Some(wire_params))
8018            .await?;
8019        Ok(())
8020    }
8021}
8022
8023/// `session.provider.*` RPCs.
8024#[derive(Clone, Copy)]
8025pub struct SessionRpcProvider<'a> {
8026    pub(crate) session: &'a Session,
8027}
8028
8029impl<'a> SessionRpcProvider<'a> {
8030    /// Returns the provider endpoint and credentials the session is currently configured to talk to, so the caller can make inference calls directly against the same backend the session uses.
8031    ///
8032    /// Wire method: `session.provider.getEndpoint`.
8033    ///
8034    /// # Returns
8035    ///
8036    /// A snapshot of the provider endpoint the session is currently configured to talk to.
8037    ///
8038    /// <div class="warning">
8039    ///
8040    /// **Experimental.** This API is part of an experimental wire-protocol surface
8041    /// and may change or be removed in future SDK or CLI releases. Pin both the
8042    /// SDK and CLI versions if your code depends on it.
8043    ///
8044    /// </div>
8045    pub async fn get_endpoint(&self) -> Result<ProviderEndpoint, Error> {
8046        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
8047        let _value = self
8048            .session
8049            .client()
8050            .call(rpc_methods::SESSION_PROVIDER_GETENDPOINT, Some(wire_params))
8051            .await?;
8052        Ok(serde_json::from_value(_value)?)
8053    }
8054
8055    /// Returns the provider endpoint and credentials the session is currently configured to talk to, so the caller can make inference calls directly against the same backend the session uses.
8056    ///
8057    /// Wire method: `session.provider.getEndpoint`.
8058    ///
8059    /// # Parameters
8060    ///
8061    /// * `params` - Optional model identifier to scope the endpoint snapshot to.
8062    ///
8063    /// # Returns
8064    ///
8065    /// A snapshot of the provider endpoint the session is currently configured to talk to.
8066    ///
8067    /// <div class="warning">
8068    ///
8069    /// **Experimental.** This API is part of an experimental wire-protocol surface
8070    /// and may change or be removed in future SDK or CLI releases. Pin both the
8071    /// SDK and CLI versions if your code depends on it.
8072    ///
8073    /// </div>
8074    pub async fn get_endpoint_with_params(
8075        &self,
8076        params: ProviderGetEndpointRequest,
8077    ) -> Result<ProviderEndpoint, Error> {
8078        let mut wire_params = serde_json::to_value(params)?;
8079        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
8080        let _value = self
8081            .session
8082            .client()
8083            .call(rpc_methods::SESSION_PROVIDER_GETENDPOINT, Some(wire_params))
8084            .await?;
8085        Ok(serde_json::from_value(_value)?)
8086    }
8087
8088    /// Adds BYOK providers and/or models to the session's registry at runtime, extending the additive registry built from the session's `providers`/`models` options. Both fields are optional, so a call may add providers only, models only, or both. Within a single call providers are registered before models, so a model may reference a provider added in the same call; across calls a model may reference any provider already registered (from session creation or a prior add). A model whose referenced provider is not registered by the end of the call is rejected. Newly added models become selectable via `model.list` / `model.switchTo` and are inherited by sub-agents spawned afterwards.
8089    ///
8090    /// Wire method: `session.provider.add`.
8091    ///
8092    /// # Parameters
8093    ///
8094    /// * `params` - BYOK providers and/or models to add to the session's registry at runtime. Both fields are optional; provide providers, models, or both.
8095    ///
8096    /// # Returns
8097    ///
8098    /// The selectable model entries synthesized for the models added by this call.
8099    ///
8100    /// <div class="warning">
8101    ///
8102    /// **Experimental.** This API is part of an experimental wire-protocol surface
8103    /// and may change or be removed in future SDK or CLI releases. Pin both the
8104    /// SDK and CLI versions if your code depends on it.
8105    ///
8106    /// </div>
8107    pub async fn add(&self, params: ProviderAddRequest) -> Result<ProviderAddResult, Error> {
8108        let mut wire_params = serde_json::to_value(params)?;
8109        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
8110        let _value = self
8111            .session
8112            .client()
8113            .call(rpc_methods::SESSION_PROVIDER_ADD, Some(wire_params))
8114            .await?;
8115        Ok(serde_json::from_value(_value)?)
8116    }
8117}
8118
8119/// `session.queue.*` RPCs.
8120#[derive(Clone, Copy)]
8121pub struct SessionRpcQueue<'a> {
8122    pub(crate) session: &'a Session,
8123}
8124
8125impl<'a> SessionRpcQueue<'a> {
8126    /// Returns the local session's pending user-facing queued items and steering messages.
8127    ///
8128    /// Wire method: `session.queue.pendingItems`.
8129    ///
8130    /// # Returns
8131    ///
8132    /// Snapshot of the session's pending queued items and immediate-steering messages.
8133    ///
8134    /// <div class="warning">
8135    ///
8136    /// **Experimental.** This API is part of an experimental wire-protocol surface
8137    /// and may change or be removed in future SDK or CLI releases. Pin both the
8138    /// SDK and CLI versions if your code depends on it.
8139    ///
8140    /// </div>
8141    pub async fn pending_items(&self) -> Result<QueuePendingItemsResult, Error> {
8142        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
8143        let _value = self
8144            .session
8145            .client()
8146            .call(rpc_methods::SESSION_QUEUE_PENDINGITEMS, Some(wire_params))
8147            .await?;
8148        Ok(serde_json::from_value(_value)?)
8149    }
8150
8151    /// Returns the internal native queue snapshot for in-process session orchestration.
8152    ///
8153    /// Wire method: `session.queue.snapshot`.
8154    ///
8155    /// # Returns
8156    ///
8157    /// Internal snapshot of native queue state for local session orchestration.
8158    ///
8159    /// <div class="warning">
8160    ///
8161    /// **Experimental.** This API is part of an experimental wire-protocol surface
8162    /// and may change or be removed in future SDK or CLI releases. Pin both the
8163    /// SDK and CLI versions if your code depends on it.
8164    ///
8165    /// </div>
8166    pub(crate) async fn snapshot(&self) -> Result<QueueSnapshotResult, Error> {
8167        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
8168        let _value = self
8169            .session
8170            .client()
8171            .call(rpc_methods::SESSION_QUEUE_SNAPSHOT, Some(wire_params))
8172            .await?;
8173        Ok(serde_json::from_value(_value)?)
8174    }
8175
8176    /// Moves an addressable queued item to a public visible position.
8177    ///
8178    /// Wire method: `session.queue.moveItem`.
8179    ///
8180    /// # Parameters
8181    ///
8182    /// * `params` - Parameters for moving a queued item by stable id.
8183    ///
8184    /// # Returns
8185    ///
8186    /// Result of moving a queued item.
8187    ///
8188    /// <div class="warning">
8189    ///
8190    /// **Experimental.** This API is part of an experimental wire-protocol surface
8191    /// and may change or be removed in future SDK or CLI releases. Pin both the
8192    /// SDK and CLI versions if your code depends on it.
8193    ///
8194    /// </div>
8195    pub async fn move_item(
8196        &self,
8197        params: QueueMoveItemRequest,
8198    ) -> Result<QueueMoveItemResult, Error> {
8199        let mut wire_params = serde_json::to_value(params)?;
8200        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
8201        let _value = self
8202            .session
8203            .client()
8204            .call(rpc_methods::SESSION_QUEUE_MOVEITEM, Some(wire_params))
8205            .await?;
8206        Ok(serde_json::from_value(_value)?)
8207    }
8208
8209    /// Inserts a new queued message at a public visible position.
8210    ///
8211    /// Wire method: `session.queue.insertAt`.
8212    ///
8213    /// # Parameters
8214    ///
8215    /// * `params` - Parameters for inserting a queued message at a public visible position.
8216    ///
8217    /// # Returns
8218    ///
8219    /// Result of inserting a queued message.
8220    ///
8221    /// <div class="warning">
8222    ///
8223    /// **Experimental.** This API is part of an experimental wire-protocol surface
8224    /// and may change or be removed in future SDK or CLI releases. Pin both the
8225    /// SDK and CLI versions if your code depends on it.
8226    ///
8227    /// </div>
8228    pub async fn insert_at(
8229        &self,
8230        params: QueueInsertAtRequest,
8231    ) -> Result<QueueInsertAtResult, Error> {
8232        let mut wire_params = serde_json::to_value(params)?;
8233        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
8234        let _value = self
8235            .session
8236            .client()
8237            .call(rpc_methods::SESSION_QUEUE_INSERTAT, Some(wire_params))
8238            .await?;
8239        Ok(serde_json::from_value(_value)?)
8240    }
8241
8242    /// Removes an addressable queued item by its stable id.
8243    ///
8244    /// Wire method: `session.queue.removeAt`.
8245    ///
8246    /// # Parameters
8247    ///
8248    /// * `params` - Parameters for removing a queued item by stable id.
8249    ///
8250    /// # Returns
8251    ///
8252    /// Result of removing a queued item.
8253    ///
8254    /// <div class="warning">
8255    ///
8256    /// **Experimental.** This API is part of an experimental wire-protocol surface
8257    /// and may change or be removed in future SDK or CLI releases. Pin both the
8258    /// SDK and CLI versions if your code depends on it.
8259    ///
8260    /// </div>
8261    pub async fn remove_at(
8262        &self,
8263        params: QueueRemoveAtRequest,
8264    ) -> Result<QueueRemoveAtResult, Error> {
8265        let mut wire_params = serde_json::to_value(params)?;
8266        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
8267        let _value = self
8268            .session
8269            .client()
8270            .call(rpc_methods::SESSION_QUEUE_REMOVEAT, Some(wire_params))
8271            .await?;
8272        Ok(serde_json::from_value(_value)?)
8273    }
8274
8275    /// Updates the text of an addressable single-message queue item.
8276    ///
8277    /// Wire method: `session.queue.updateText`.
8278    ///
8279    /// # Parameters
8280    ///
8281    /// * `params` - Parameters for editing a single queued message.
8282    ///
8283    /// # Returns
8284    ///
8285    /// Result of editing a queued message.
8286    ///
8287    /// <div class="warning">
8288    ///
8289    /// **Experimental.** This API is part of an experimental wire-protocol surface
8290    /// and may change or be removed in future SDK or CLI releases. Pin both the
8291    /// SDK and CLI versions if your code depends on it.
8292    ///
8293    /// </div>
8294    pub async fn update_text(
8295        &self,
8296        params: QueueUpdateTextRequest,
8297    ) -> Result<QueueUpdateTextResult, Error> {
8298        let mut wire_params = serde_json::to_value(params)?;
8299        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
8300        let _value = self
8301            .session
8302            .client()
8303            .call(rpc_methods::SESSION_QUEUE_UPDATETEXT, Some(wire_params))
8304            .await?;
8305        Ok(serde_json::from_value(_value)?)
8306    }
8307
8308    /// Duplicates an addressable queued item immediately after its source.
8309    ///
8310    /// Wire method: `session.queue.duplicateAt`.
8311    ///
8312    /// # Parameters
8313    ///
8314    /// * `params` - Parameters for duplicating a queued item.
8315    ///
8316    /// # Returns
8317    ///
8318    /// Result of duplicating a queued item.
8319    ///
8320    /// <div class="warning">
8321    ///
8322    /// **Experimental.** This API is part of an experimental wire-protocol surface
8323    /// and may change or be removed in future SDK or CLI releases. Pin both the
8324    /// SDK and CLI versions if your code depends on it.
8325    ///
8326    /// </div>
8327    pub async fn duplicate_at(
8328        &self,
8329        params: QueueDuplicateAtRequest,
8330    ) -> Result<QueueDuplicateAtResult, Error> {
8331        let mut wire_params = serde_json::to_value(params)?;
8332        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
8333        let _value = self
8334            .session
8335            .client()
8336            .call(rpc_methods::SESSION_QUEUE_DUPLICATEAT, Some(wire_params))
8337            .await?;
8338        Ok(serde_json::from_value(_value)?)
8339    }
8340
8341    /// Acquires or releases the queued-lane drain pause.
8342    ///
8343    /// Wire method: `session.queue.setDrainPaused`.
8344    ///
8345    /// # Parameters
8346    ///
8347    /// * `params` - Parameters for acquiring or releasing the queued-lane drain pause. Acquisition is exclusive and non-idempotent: `paused: true` against an already-paused session fails with `queue_already_paused`. The pause is never released automatically — it is not tied to the caller's lifetime, so a client that exits without sending `paused: false` leaves the lane frozen. Release is unowned: `paused: false` clears the pause for any caller, including one that never acquired it.
8348    ///
8349    /// <div class="warning">
8350    ///
8351    /// **Experimental.** This API is part of an experimental wire-protocol surface
8352    /// and may change or be removed in future SDK or CLI releases. Pin both the
8353    /// SDK and CLI versions if your code depends on it.
8354    ///
8355    /// </div>
8356    pub async fn set_drain_paused(&self, params: QueueSetDrainPausedRequest) -> Result<(), Error> {
8357        let mut wire_params = serde_json::to_value(params)?;
8358        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
8359        let _value = self
8360            .session
8361            .client()
8362            .call(rpc_methods::SESSION_QUEUE_SETDRAINPAUSED, Some(wire_params))
8363            .await?;
8364        Ok(())
8365    }
8366
8367    /// Moves an addressable queued message into the live turn's steering lane.
8368    ///
8369    /// Wire method: `session.queue.sendNow`.
8370    ///
8371    /// # Parameters
8372    ///
8373    /// * `params` - Parameters for steering a queued message into a live turn.
8374    ///
8375    /// # Returns
8376    ///
8377    /// Result of trying to steer a queued message into a live turn.
8378    ///
8379    /// <div class="warning">
8380    ///
8381    /// **Experimental.** This API is part of an experimental wire-protocol surface
8382    /// and may change or be removed in future SDK or CLI releases. Pin both the
8383    /// SDK and CLI versions if your code depends on it.
8384    ///
8385    /// </div>
8386    pub async fn send_now(&self, params: QueueSendNowRequest) -> Result<QueueSendNowResult, Error> {
8387        let mut wire_params = serde_json::to_value(params)?;
8388        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
8389        let _value = self
8390            .session
8391            .client()
8392            .call(rpc_methods::SESSION_QUEUE_SENDNOW, Some(wire_params))
8393            .await?;
8394        Ok(serde_json::from_value(_value)?)
8395    }
8396
8397    /// Reports whether the local session has native queued work pending.
8398    ///
8399    /// Wire method: `session.queue.hasPending`.
8400    ///
8401    /// # Returns
8402    ///
8403    /// Whether the native queue has pending work.
8404    ///
8405    /// <div class="warning">
8406    ///
8407    /// **Experimental.** This API is part of an experimental wire-protocol surface
8408    /// and may change or be removed in future SDK or CLI releases. Pin both the
8409    /// SDK and CLI versions if your code depends on it.
8410    ///
8411    /// </div>
8412    pub(crate) async fn has_pending(&self) -> Result<QueueHasPendingResult, Error> {
8413        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
8414        let _value = self
8415            .session
8416            .client()
8417            .call(rpc_methods::SESSION_QUEUE_HASPENDING, Some(wire_params))
8418            .await?;
8419        Ok(serde_json::from_value(_value)?)
8420    }
8421
8422    /// Begins a native deferred-idle drain when background work has quiesced.
8423    ///
8424    /// Wire method: `session.queue.beginDeferredIdleDrain`.
8425    ///
8426    /// # Parameters
8427    ///
8428    /// * `params` - Inputs for starting a deferred-idle drain.
8429    ///
8430    /// # Returns
8431    ///
8432    /// Whether a deferred-idle drain should run.
8433    ///
8434    /// <div class="warning">
8435    ///
8436    /// **Experimental.** This API is part of an experimental wire-protocol surface
8437    /// and may change or be removed in future SDK or CLI releases. Pin both the
8438    /// SDK and CLI versions if your code depends on it.
8439    ///
8440    /// </div>
8441    pub(crate) async fn begin_deferred_idle_drain(
8442        &self,
8443        params: QueueBeginDeferredIdleDrainRequest,
8444    ) -> Result<QueueBeginDeferredIdleDrainResult, Error> {
8445        let mut wire_params = serde_json::to_value(params)?;
8446        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
8447        let _value = self
8448            .session
8449            .client()
8450            .call(
8451                rpc_methods::SESSION_QUEUE_BEGINDEFERREDIDLEDRAIN,
8452                Some(wire_params),
8453            )
8454            .await?;
8455        Ok(serde_json::from_value(_value)?)
8456    }
8457
8458    /// Finishes a native deferred-idle drain and reports whether to drain queue work or emit idle.
8459    ///
8460    /// Wire method: `session.queue.finishDeferredIdleDrain`.
8461    ///
8462    /// # Parameters
8463    ///
8464    /// * `params` - Inputs for completing a deferred-idle drain.
8465    ///
8466    /// # Returns
8467    ///
8468    /// Action selected by the native deferred-idle drain.
8469    ///
8470    /// <div class="warning">
8471    ///
8472    /// **Experimental.** This API is part of an experimental wire-protocol surface
8473    /// and may change or be removed in future SDK or CLI releases. Pin both the
8474    /// SDK and CLI versions if your code depends on it.
8475    ///
8476    /// </div>
8477    pub(crate) async fn finish_deferred_idle_drain(
8478        &self,
8479        params: QueueFinishDeferredIdleDrainRequest,
8480    ) -> Result<QueueFinishDeferredIdleDrainResult, Error> {
8481        let mut wire_params = serde_json::to_value(params)?;
8482        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
8483        let _value = self
8484            .session
8485            .client()
8486            .call(
8487                rpc_methods::SESSION_QUEUE_FINISHDEFERREDIDLEDRAIN,
8488                Some(wire_params),
8489            )
8490            .await?;
8491        Ok(serde_json::from_value(_value)?)
8492    }
8493
8494    /// Marks session.idle as deferred by native background work state.
8495    ///
8496    /// Wire method: `session.queue.deferSessionIdle`.
8497    ///
8498    /// # Parameters
8499    ///
8500    /// * `params` - Inputs for marking session.idle deferred in native state.
8501    ///
8502    /// <div class="warning">
8503    ///
8504    /// **Experimental.** This API is part of an experimental wire-protocol surface
8505    /// and may change or be removed in future SDK or CLI releases. Pin both the
8506    /// SDK and CLI versions if your code depends on it.
8507    ///
8508    /// </div>
8509    pub(crate) async fn defer_session_idle(
8510        &self,
8511        params: QueueDeferSessionIdleRequest,
8512    ) -> Result<(), Error> {
8513        let mut wire_params = serde_json::to_value(params)?;
8514        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
8515        let _value = self
8516            .session
8517            .client()
8518            .call(
8519                rpc_methods::SESSION_QUEUE_DEFERSESSIONIDLE,
8520                Some(wire_params),
8521            )
8522            .await?;
8523        Ok(())
8524    }
8525
8526    /// Removes the most recently queued user-facing item (LIFO).
8527    ///
8528    /// Wire method: `session.queue.removeMostRecent`.
8529    ///
8530    /// # Returns
8531    ///
8532    /// Indicates whether a user-facing pending item was removed.
8533    ///
8534    /// <div class="warning">
8535    ///
8536    /// **Experimental.** This API is part of an experimental wire-protocol surface
8537    /// and may change or be removed in future SDK or CLI releases. Pin both the
8538    /// SDK and CLI versions if your code depends on it.
8539    ///
8540    /// </div>
8541    pub async fn remove_most_recent(&self) -> Result<QueueRemoveMostRecentResult, Error> {
8542        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
8543        let _value = self
8544            .session
8545            .client()
8546            .call(
8547                rpc_methods::SESSION_QUEUE_REMOVEMOSTRECENT,
8548                Some(wire_params),
8549            )
8550            .await?;
8551        Ok(serde_json::from_value(_value)?)
8552    }
8553
8554    /// Clears all pending queued items on the local session.
8555    ///
8556    /// Wire method: `session.queue.clear`.
8557    ///
8558    /// <div class="warning">
8559    ///
8560    /// **Experimental.** This API is part of an experimental wire-protocol surface
8561    /// and may change or be removed in future SDK or CLI releases. Pin both the
8562    /// SDK and CLI versions if your code depends on it.
8563    ///
8564    /// </div>
8565    pub async fn clear(&self) -> Result<(), Error> {
8566        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
8567        let _value = self
8568            .session
8569            .client()
8570            .call(rpc_methods::SESSION_QUEUE_CLEAR, Some(wire_params))
8571            .await?;
8572        Ok(())
8573    }
8574
8575    /// Consumes queued native system notifications matching an internal filter.
8576    ///
8577    /// Wire method: `session.queue.consumeSystemNotifications`.
8578    ///
8579    /// # Parameters
8580    ///
8581    /// * `params` - Internal filter for consuming queued system notifications.
8582    ///
8583    /// # Returns
8584    ///
8585    /// Indicates whether a user-facing pending item was removed.
8586    ///
8587    /// <div class="warning">
8588    ///
8589    /// **Experimental.** This API is part of an experimental wire-protocol surface
8590    /// and may change or be removed in future SDK or CLI releases. Pin both the
8591    /// SDK and CLI versions if your code depends on it.
8592    ///
8593    /// </div>
8594    pub(crate) async fn consume_system_notifications(
8595        &self,
8596        params: QueueConsumeSystemNotificationsRequest,
8597    ) -> Result<QueueRemoveMostRecentResult, Error> {
8598        let mut wire_params = serde_json::to_value(params)?;
8599        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
8600        let _value = self
8601            .session
8602            .client()
8603            .call(
8604                rpc_methods::SESSION_QUEUE_CONSUMESYSTEMNOTIFICATIONS,
8605                Some(wire_params),
8606            )
8607            .await?;
8608        Ok(serde_json::from_value(_value)?)
8609    }
8610
8611    /// Enqueues the internal resume-pending wake item when orphan handling needs a follow-up turn.
8612    ///
8613    /// Wire method: `session.queue.enqueueResumePending`.
8614    ///
8615    /// # Returns
8616    ///
8617    /// Result of enqueueing the resume-pending wake item.
8618    ///
8619    /// <div class="warning">
8620    ///
8621    /// **Experimental.** This API is part of an experimental wire-protocol surface
8622    /// and may change or be removed in future SDK or CLI releases. Pin both the
8623    /// SDK and CLI versions if your code depends on it.
8624    ///
8625    /// </div>
8626    pub(crate) async fn enqueue_resume_pending(
8627        &self,
8628    ) -> Result<QueueEnqueueResumePendingResult, Error> {
8629        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
8630        let _value = self
8631            .session
8632            .client()
8633            .call(
8634                rpc_methods::SESSION_QUEUE_ENQUEUERESUMEPENDING,
8635                Some(wire_params),
8636            )
8637            .await?;
8638        Ok(serde_json::from_value(_value)?)
8639    }
8640
8641    /// Drains the native local-session work queue for in-process session orchestration.
8642    ///
8643    /// Wire method: `session.queue.process`.
8644    ///
8645    /// <div class="warning">
8646    ///
8647    /// **Experimental.** This API is part of an experimental wire-protocol surface
8648    /// and may change or be removed in future SDK or CLI releases. Pin both the
8649    /// SDK and CLI versions if your code depends on it.
8650    ///
8651    /// </div>
8652    pub(crate) async fn process(&self) -> Result<(), Error> {
8653        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
8654        let _value = self
8655            .session
8656            .client()
8657            .call(rpc_methods::SESSION_QUEUE_PROCESS, Some(wire_params))
8658            .await?;
8659        Ok(())
8660    }
8661}
8662
8663/// `session.remote.*` RPCs.
8664#[derive(Clone, Copy)]
8665pub struct SessionRpcRemote<'a> {
8666    pub(crate) session: &'a Session,
8667}
8668
8669impl<'a> SessionRpcRemote<'a> {
8670    /// Enables remote session export or steering.
8671    ///
8672    /// Wire method: `session.remote.enable`.
8673    ///
8674    /// # Parameters
8675    ///
8676    /// * `params` - Optional remote session mode ("off", "export", or "on"); defaults to enabling both export and remote steering.
8677    ///
8678    /// # Returns
8679    ///
8680    /// GitHub URL for the session and a flag indicating whether remote steering is enabled.
8681    ///
8682    /// <div class="warning">
8683    ///
8684    /// **Experimental.** This API is part of an experimental wire-protocol surface
8685    /// and may change or be removed in future SDK or CLI releases. Pin both the
8686    /// SDK and CLI versions if your code depends on it.
8687    ///
8688    /// </div>
8689    pub async fn enable(&self, params: RemoteEnableRequest) -> Result<RemoteEnableResult, Error> {
8690        let mut wire_params = serde_json::to_value(params)?;
8691        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
8692        let _value = self
8693            .session
8694            .client()
8695            .call(rpc_methods::SESSION_REMOTE_ENABLE, Some(wire_params))
8696            .await?;
8697        Ok(serde_json::from_value(_value)?)
8698    }
8699
8700    /// Disables remote session export and steering.
8701    ///
8702    /// Wire method: `session.remote.disable`.
8703    ///
8704    /// <div class="warning">
8705    ///
8706    /// **Experimental.** This API is part of an experimental wire-protocol surface
8707    /// and may change or be removed in future SDK or CLI releases. Pin both the
8708    /// SDK and CLI versions if your code depends on it.
8709    ///
8710    /// </div>
8711    pub async fn disable(&self) -> Result<(), Error> {
8712        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
8713        let _value = self
8714            .session
8715            .client()
8716            .call(rpc_methods::SESSION_REMOTE_DISABLE, Some(wire_params))
8717            .await?;
8718        Ok(())
8719    }
8720
8721    /// Persists a remote-steerability change emitted by the host as a session event.
8722    ///
8723    /// Wire method: `session.remote.notifySteerableChanged`.
8724    ///
8725    /// # Parameters
8726    ///
8727    /// * `params` - New remote-steerability state to persist as a `session.remote_steerable_changed` event.
8728    ///
8729    /// # Returns
8730    ///
8731    /// Persist a steerability change as a `session.remote_steerable_changed` event. Used by the host (CLI / SDK consumer) when it has just finished enabling or disabling steering on a remote exporter that the runtime does not directly own.
8732    ///
8733    /// <div class="warning">
8734    ///
8735    /// **Experimental.** This API is part of an experimental wire-protocol surface
8736    /// and may change or be removed in future SDK or CLI releases. Pin both the
8737    /// SDK and CLI versions if your code depends on it.
8738    ///
8739    /// </div>
8740    pub async fn notify_steerable_changed(
8741        &self,
8742        params: RemoteNotifySteerableChangedRequest,
8743    ) -> Result<RemoteNotifySteerableChangedResult, Error> {
8744        let mut wire_params = serde_json::to_value(params)?;
8745        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
8746        let _value = self
8747            .session
8748            .client()
8749            .call(
8750                rpc_methods::SESSION_REMOTE_NOTIFYSTEERABLECHANGED,
8751                Some(wire_params),
8752            )
8753            .await?;
8754        Ok(serde_json::from_value(_value)?)
8755    }
8756}
8757
8758/// `session.schedule.*` RPCs.
8759#[derive(Clone, Copy)]
8760pub struct SessionRpcSchedule<'a> {
8761    pub(crate) session: &'a Session,
8762}
8763
8764impl<'a> SessionRpcSchedule<'a> {
8765    /// Lists the session's currently active scheduled prompts.
8766    ///
8767    /// Wire method: `session.schedule.list`.
8768    ///
8769    /// # Returns
8770    ///
8771    /// Snapshot of the currently active recurring prompts for this session.
8772    ///
8773    /// <div class="warning">
8774    ///
8775    /// **Experimental.** This API is part of an experimental wire-protocol surface
8776    /// and may change or be removed in future SDK or CLI releases. Pin both the
8777    /// SDK and CLI versions if your code depends on it.
8778    ///
8779    /// </div>
8780    pub async fn list(&self) -> Result<ScheduleList, Error> {
8781        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
8782        let _value = self
8783            .session
8784            .client()
8785            .call(rpc_methods::SESSION_SCHEDULE_LIST, Some(wire_params))
8786            .await?;
8787        Ok(serde_json::from_value(_value)?)
8788    }
8789
8790    /// Hydrates the native schedule registry from persisted session events.
8791    ///
8792    /// Wire method: `session.schedule.hydrate`.
8793    ///
8794    /// <div class="warning">
8795    ///
8796    /// **Experimental.** This API is part of an experimental wire-protocol surface
8797    /// and may change or be removed in future SDK or CLI releases. Pin both the
8798    /// SDK and CLI versions if your code depends on it.
8799    ///
8800    /// </div>
8801    pub(crate) async fn hydrate(&self) -> Result<(), Error> {
8802        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
8803        let _value = self
8804            .session
8805            .client()
8806            .call(rpc_methods::SESSION_SCHEDULE_HYDRATE, Some(wire_params))
8807            .await?;
8808        Ok(())
8809    }
8810
8811    /// Reports whether the session has an active self-paced scheduled prompt.
8812    ///
8813    /// Wire method: `session.schedule.hasSelfPaced`.
8814    ///
8815    /// # Returns
8816    ///
8817    /// Whether the session currently has an active self-paced schedule.
8818    ///
8819    /// <div class="warning">
8820    ///
8821    /// **Experimental.** This API is part of an experimental wire-protocol surface
8822    /// and may change or be removed in future SDK or CLI releases. Pin both the
8823    /// SDK and CLI versions if your code depends on it.
8824    ///
8825    /// </div>
8826    pub(crate) async fn has_self_paced(&self) -> Result<ScheduleHasSelfPacedResult, Error> {
8827        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
8828        let _value = self
8829            .session
8830            .client()
8831            .call(
8832                rpc_methods::SESSION_SCHEDULE_HASSELFPACED,
8833                Some(wire_params),
8834            )
8835            .await?;
8836        Ok(serde_json::from_value(_value)?)
8837    }
8838
8839    /// Registers a relative-interval scheduled prompt.
8840    ///
8841    /// Wire method: `session.schedule.add`.
8842    ///
8843    /// # Parameters
8844    ///
8845    /// * `params` - Register a relative-interval scheduled prompt.
8846    ///
8847    /// # Returns
8848    ///
8849    /// Result of registering or re-arming a scheduled prompt.
8850    ///
8851    /// <div class="warning">
8852    ///
8853    /// **Experimental.** This API is part of an experimental wire-protocol surface
8854    /// and may change or be removed in future SDK or CLI releases. Pin both the
8855    /// SDK and CLI versions if your code depends on it.
8856    ///
8857    /// </div>
8858    pub(crate) async fn add(&self, params: ScheduleAddRequest) -> Result<ScheduleAddResult, Error> {
8859        let mut wire_params = serde_json::to_value(params)?;
8860        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
8861        let _value = self
8862            .session
8863            .client()
8864            .call(rpc_methods::SESSION_SCHEDULE_ADD, Some(wire_params))
8865            .await?;
8866        Ok(serde_json::from_value(_value)?)
8867    }
8868
8869    /// Registers a recurring cron scheduled prompt.
8870    ///
8871    /// Wire method: `session.schedule.addCron`.
8872    ///
8873    /// # Parameters
8874    ///
8875    /// * `params` - Register a cron scheduled prompt.
8876    ///
8877    /// # Returns
8878    ///
8879    /// Result of registering or re-arming a scheduled prompt.
8880    ///
8881    /// <div class="warning">
8882    ///
8883    /// **Experimental.** This API is part of an experimental wire-protocol surface
8884    /// and may change or be removed in future SDK or CLI releases. Pin both the
8885    /// SDK and CLI versions if your code depends on it.
8886    ///
8887    /// </div>
8888    pub(crate) async fn add_cron(
8889        &self,
8890        params: ScheduleAddCronRequest,
8891    ) -> Result<ScheduleAddResult, Error> {
8892        let mut wire_params = serde_json::to_value(params)?;
8893        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
8894        let _value = self
8895            .session
8896            .client()
8897            .call(rpc_methods::SESSION_SCHEDULE_ADDCRON, Some(wire_params))
8898            .await?;
8899        Ok(serde_json::from_value(_value)?)
8900    }
8901
8902    /// Registers an absolute-time scheduled prompt.
8903    ///
8904    /// Wire method: `session.schedule.addAt`.
8905    ///
8906    /// # Parameters
8907    ///
8908    /// * `params` - Register an absolute-time scheduled prompt.
8909    ///
8910    /// # Returns
8911    ///
8912    /// Result of registering or re-arming a scheduled prompt.
8913    ///
8914    /// <div class="warning">
8915    ///
8916    /// **Experimental.** This API is part of an experimental wire-protocol surface
8917    /// and may change or be removed in future SDK or CLI releases. Pin both the
8918    /// SDK and CLI versions if your code depends on it.
8919    ///
8920    /// </div>
8921    pub(crate) async fn add_at(
8922        &self,
8923        params: ScheduleAddAtRequest,
8924    ) -> Result<ScheduleAddResult, Error> {
8925        let mut wire_params = serde_json::to_value(params)?;
8926        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
8927        let _value = self
8928            .session
8929            .client()
8930            .call(rpc_methods::SESSION_SCHEDULE_ADDAT, Some(wire_params))
8931            .await?;
8932        Ok(serde_json::from_value(_value)?)
8933    }
8934
8935    /// Registers a self-paced scheduled prompt.
8936    ///
8937    /// Wire method: `session.schedule.addSelfPaced`.
8938    ///
8939    /// # Parameters
8940    ///
8941    /// * `params` - Register a self-paced scheduled prompt.
8942    ///
8943    /// # Returns
8944    ///
8945    /// Result of registering or re-arming a scheduled prompt.
8946    ///
8947    /// <div class="warning">
8948    ///
8949    /// **Experimental.** This API is part of an experimental wire-protocol surface
8950    /// and may change or be removed in future SDK or CLI releases. Pin both the
8951    /// SDK and CLI versions if your code depends on it.
8952    ///
8953    /// </div>
8954    pub(crate) async fn add_self_paced(
8955        &self,
8956        params: ScheduleAddSelfPacedRequest,
8957    ) -> Result<ScheduleAddResult, Error> {
8958        let mut wire_params = serde_json::to_value(params)?;
8959        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
8960        let _value = self
8961            .session
8962            .client()
8963            .call(
8964                rpc_methods::SESSION_SCHEDULE_ADDSELFPACED,
8965                Some(wire_params),
8966            )
8967            .await?;
8968        Ok(serde_json::from_value(_value)?)
8969    }
8970
8971    /// Re-arms an active self-paced scheduled prompt.
8972    ///
8973    /// Wire method: `session.schedule.rearmSelfPaced`.
8974    ///
8975    /// # Parameters
8976    ///
8977    /// * `params` - Re-arm a self-paced scheduled prompt.
8978    ///
8979    /// # Returns
8980    ///
8981    /// Result of registering or re-arming a scheduled prompt.
8982    ///
8983    /// <div class="warning">
8984    ///
8985    /// **Experimental.** This API is part of an experimental wire-protocol surface
8986    /// and may change or be removed in future SDK or CLI releases. Pin both the
8987    /// SDK and CLI versions if your code depends on it.
8988    ///
8989    /// </div>
8990    pub(crate) async fn rearm_self_paced(
8991        &self,
8992        params: ScheduleRearmSelfPacedRequest,
8993    ) -> Result<ScheduleAddResult, Error> {
8994        let mut wire_params = serde_json::to_value(params)?;
8995        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
8996        let _value = self
8997            .session
8998            .client()
8999            .call(
9000                rpc_methods::SESSION_SCHEDULE_REARMSELFPACED,
9001                Some(wire_params),
9002            )
9003            .await?;
9004        Ok(serde_json::from_value(_value)?)
9005    }
9006
9007    /// Removes a scheduled prompt by id.
9008    ///
9009    /// Wire method: `session.schedule.stop`.
9010    ///
9011    /// # Parameters
9012    ///
9013    /// * `params` - Identifier of the scheduled prompt to remove.
9014    ///
9015    /// # Returns
9016    ///
9017    /// Remove a scheduled prompt by id. The result entry is omitted if the id was unknown.
9018    ///
9019    /// <div class="warning">
9020    ///
9021    /// **Experimental.** This API is part of an experimental wire-protocol surface
9022    /// and may change or be removed in future SDK or CLI releases. Pin both the
9023    /// SDK and CLI versions if your code depends on it.
9024    ///
9025    /// </div>
9026    pub async fn stop(&self, params: ScheduleStopRequest) -> Result<ScheduleStopResult, Error> {
9027        let mut wire_params = serde_json::to_value(params)?;
9028        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
9029        let _value = self
9030            .session
9031            .client()
9032            .call(rpc_methods::SESSION_SCHEDULE_STOP, Some(wire_params))
9033            .await?;
9034        Ok(serde_json::from_value(_value)?)
9035    }
9036}
9037
9038/// `session.settings.*` RPCs.
9039#[derive(Clone, Copy)]
9040pub struct SessionRpcSettings<'a> {
9041    pub(crate) session: &'a Session,
9042}
9043
9044impl<'a> SessionRpcSettings<'a> {
9045    /// Returns a redacted snapshot of session runtime settings, with secrets and raw feature flags excluded. Internal: the runtime settings shape is a runtime-internal surface and is deliberately kept out of the public SDK, because consumers should not depend on the runtime's internal settings layout. It remains callable in-process and is expected to be reworked as the runtime internals are consolidated.
9046    ///
9047    /// Wire method: `session.settings.snapshot`.
9048    ///
9049    /// # Returns
9050    ///
9051    /// Redacted, serializable view of session runtime settings for SDK boundary consumers. Secrets and raw feature flags are intentionally excluded.
9052    ///
9053    /// <div class="warning">
9054    ///
9055    /// **Experimental.** This API is part of an experimental wire-protocol surface
9056    /// and may change or be removed in future SDK or CLI releases. Pin both the
9057    /// SDK and CLI versions if your code depends on it.
9058    ///
9059    /// </div>
9060    pub(crate) async fn snapshot(&self) -> Result<SessionSettingsSnapshot, Error> {
9061        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
9062        let _value = self
9063            .session
9064            .client()
9065            .call(rpc_methods::SESSION_SETTINGS_SNAPSHOT, Some(wire_params))
9066            .await?;
9067        Ok(serde_json::from_value(_value)?)
9068    }
9069
9070    /// Evaluates a named Rust-owned settings predicate without exposing raw feature flags. Internal: the raw feature-flag names and composition are runtime-internal, so this predicate-evaluation helper is kept out of the public SDK surface and is callable in-process only.
9071    ///
9072    /// Wire method: `session.settings.evaluatePredicate`.
9073    ///
9074    /// # Parameters
9075    ///
9076    /// * `params` - Named Rust-owned settings predicate to evaluate for this session.
9077    ///
9078    /// # Returns
9079    ///
9080    /// Result of evaluating a Rust-owned settings predicate.
9081    ///
9082    /// <div class="warning">
9083    ///
9084    /// **Experimental.** This API is part of an experimental wire-protocol surface
9085    /// and may change or be removed in future SDK or CLI releases. Pin both the
9086    /// SDK and CLI versions if your code depends on it.
9087    ///
9088    /// </div>
9089    pub(crate) async fn evaluate_predicate(
9090        &self,
9091        params: SessionSettingsEvaluatePredicateRequest,
9092    ) -> Result<SessionSettingsEvaluatePredicateResult, Error> {
9093        let mut wire_params = serde_json::to_value(params)?;
9094        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
9095        let _value = self
9096            .session
9097            .client()
9098            .call(
9099                rpc_methods::SESSION_SETTINGS_EVALUATEPREDICATE,
9100                Some(wire_params),
9101            )
9102            .await?;
9103        Ok(serde_json::from_value(_value)?)
9104    }
9105}
9106
9107/// `session.shell.*` RPCs.
9108#[derive(Clone, Copy)]
9109pub struct SessionRpcShell<'a> {
9110    pub(crate) session: &'a Session,
9111}
9112
9113impl<'a> SessionRpcShell<'a> {
9114    /// Starts a shell command and streams output through session notifications. The command runs as the leader of its own process group (POSIX) or in a dedicated job object (Windows), so a forced termination — via "shell.kill", the request timeout, or session disposal — signals that whole group/job rather than only the direct child. Two gaps are worth planning for: a command that exits on its own does not trigger that teardown, and on POSIX a descendant that moves itself into a new session or process group (for example via "setsid") leaves the signalled group, so either can leave a background process running.
9115    ///
9116    /// Wire method: `session.shell.exec`.
9117    ///
9118    /// # Parameters
9119    ///
9120    /// * `params` - Shell command to run, with optional working directory and timeout in milliseconds.
9121    ///
9122    /// # Returns
9123    ///
9124    /// Identifier of the spawned process, used to correlate streamed output and exit notifications.
9125    ///
9126    /// <div class="warning">
9127    ///
9128    /// **Experimental.** This API is part of an experimental wire-protocol surface
9129    /// and may change or be removed in future SDK or CLI releases. Pin both the
9130    /// SDK and CLI versions if your code depends on it.
9131    ///
9132    /// </div>
9133    pub async fn exec(&self, params: ShellExecRequest) -> Result<ShellExecResult, Error> {
9134        let mut wire_params = serde_json::to_value(params)?;
9135        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
9136        let _value = self
9137            .session
9138            .client()
9139            .call(rpc_methods::SESSION_SHELL_EXEC, Some(wire_params))
9140            .await?;
9141        Ok(serde_json::from_value(_value)?)
9142    }
9143
9144    /// Sends a signal to a shell process previously started via "shell.exec". The signal targets the command's whole process group (POSIX) or job object (Windows), so descendants still in that group are signalled too, not just the direct child. On POSIX a descendant that moved itself into a new session or process group (for example via "setsid") is no longer in the signalled group and survives.
9145    ///
9146    /// Wire method: `session.shell.kill`.
9147    ///
9148    /// # Parameters
9149    ///
9150    /// * `params` - Identifier of a process previously returned by "shell.exec" and the signal to send.
9151    ///
9152    /// # Returns
9153    ///
9154    /// Indicates whether the signal was delivered; false if the process was unknown or already exited.
9155    ///
9156    /// <div class="warning">
9157    ///
9158    /// **Experimental.** This API is part of an experimental wire-protocol surface
9159    /// and may change or be removed in future SDK or CLI releases. Pin both the
9160    /// SDK and CLI versions if your code depends on it.
9161    ///
9162    /// </div>
9163    pub async fn kill(&self, params: ShellKillRequest) -> Result<ShellKillResult, Error> {
9164        let mut wire_params = serde_json::to_value(params)?;
9165        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
9166        let _value = self
9167            .session
9168            .client()
9169            .call(rpc_methods::SESSION_SHELL_KILL, Some(wire_params))
9170            .await?;
9171        Ok(serde_json::from_value(_value)?)
9172    }
9173
9174    /// Executes a user-requested shell command through the session runtime.
9175    ///
9176    /// Wire method: `session.shell.executeUserRequested`.
9177    ///
9178    /// # Parameters
9179    ///
9180    /// * `params` - User-requested shell command and cancellation handle.
9181    ///
9182    /// # Returns
9183    ///
9184    /// Result of a user-requested shell command.
9185    ///
9186    /// <div class="warning">
9187    ///
9188    /// **Experimental.** This API is part of an experimental wire-protocol surface
9189    /// and may change or be removed in future SDK or CLI releases. Pin both the
9190    /// SDK and CLI versions if your code depends on it.
9191    ///
9192    /// </div>
9193    pub async fn execute_user_requested(
9194        &self,
9195        params: ShellExecuteUserRequestedRequest,
9196    ) -> Result<UserRequestedShellCommandResult, Error> {
9197        let mut wire_params = serde_json::to_value(params)?;
9198        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
9199        let _value = self
9200            .session
9201            .client()
9202            .call(
9203                rpc_methods::SESSION_SHELL_EXECUTEUSERREQUESTED,
9204                Some(wire_params),
9205            )
9206            .await?;
9207        Ok(serde_json::from_value(_value)?)
9208    }
9209
9210    /// Cancels a user-requested shell command by request ID.
9211    ///
9212    /// Wire method: `session.shell.cancelUserRequested`.
9213    ///
9214    /// # Parameters
9215    ///
9216    /// * `params` - User-requested shell execution cancellation handle.
9217    ///
9218    /// # Returns
9219    ///
9220    /// Cancellation result for a user-requested shell command.
9221    ///
9222    /// <div class="warning">
9223    ///
9224    /// **Experimental.** This API is part of an experimental wire-protocol surface
9225    /// and may change or be removed in future SDK or CLI releases. Pin both the
9226    /// SDK and CLI versions if your code depends on it.
9227    ///
9228    /// </div>
9229    pub async fn cancel_user_requested(
9230        &self,
9231        params: ShellCancelUserRequestedRequest,
9232    ) -> Result<CancelUserRequestedShellCommandResult, Error> {
9233        let mut wire_params = serde_json::to_value(params)?;
9234        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
9235        let _value = self
9236            .session
9237            .client()
9238            .call(
9239                rpc_methods::SESSION_SHELL_CANCELUSERREQUESTED,
9240                Some(wire_params),
9241            )
9242            .await?;
9243        Ok(serde_json::from_value(_value)?)
9244    }
9245}
9246
9247/// `session.skills.*` RPCs.
9248#[derive(Clone, Copy)]
9249pub struct SessionRpcSkills<'a> {
9250    pub(crate) session: &'a Session,
9251}
9252
9253impl<'a> SessionRpcSkills<'a> {
9254    /// Lists skills available to the session.
9255    ///
9256    /// Wire method: `session.skills.list`.
9257    ///
9258    /// # Returns
9259    ///
9260    /// Skills available to the session, with their enabled state.
9261    ///
9262    /// <div class="warning">
9263    ///
9264    /// **Experimental.** This API is part of an experimental wire-protocol surface
9265    /// and may change or be removed in future SDK or CLI releases. Pin both the
9266    /// SDK and CLI versions if your code depends on it.
9267    ///
9268    /// </div>
9269    pub async fn list(&self) -> Result<SkillList, Error> {
9270        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
9271        let _value = self
9272            .session
9273            .client()
9274            .call(rpc_methods::SESSION_SKILLS_LIST, Some(wire_params))
9275            .await?;
9276        Ok(serde_json::from_value(_value)?)
9277    }
9278
9279    /// Returns the skills that have been invoked during this session.
9280    ///
9281    /// Wire method: `session.skills.getInvoked`.
9282    ///
9283    /// # Returns
9284    ///
9285    /// Skills invoked during this session, ordered by invocation time (most recent last).
9286    ///
9287    /// <div class="warning">
9288    ///
9289    /// **Experimental.** This API is part of an experimental wire-protocol surface
9290    /// and may change or be removed in future SDK or CLI releases. Pin both the
9291    /// SDK and CLI versions if your code depends on it.
9292    ///
9293    /// </div>
9294    pub async fn get_invoked(&self) -> Result<SkillsGetInvokedResult, Error> {
9295        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
9296        let _value = self
9297            .session
9298            .client()
9299            .call(rpc_methods::SESSION_SKILLS_GETINVOKED, Some(wire_params))
9300            .await?;
9301        Ok(serde_json::from_value(_value)?)
9302    }
9303
9304    /// Enables a skill for the session.
9305    ///
9306    /// Wire method: `session.skills.enable`.
9307    ///
9308    /// # Parameters
9309    ///
9310    /// * `params` - Name of the skill to enable for the session.
9311    ///
9312    /// <div class="warning">
9313    ///
9314    /// **Experimental.** This API is part of an experimental wire-protocol surface
9315    /// and may change or be removed in future SDK or CLI releases. Pin both the
9316    /// SDK and CLI versions if your code depends on it.
9317    ///
9318    /// </div>
9319    pub async fn enable(&self, params: SkillsEnableRequest) -> Result<(), Error> {
9320        let mut wire_params = serde_json::to_value(params)?;
9321        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
9322        let _value = self
9323            .session
9324            .client()
9325            .call(rpc_methods::SESSION_SKILLS_ENABLE, Some(wire_params))
9326            .await?;
9327        Ok(())
9328    }
9329
9330    /// Disables a skill for the session.
9331    ///
9332    /// Wire method: `session.skills.disable`.
9333    ///
9334    /// # Parameters
9335    ///
9336    /// * `params` - Name of the skill to disable for the session.
9337    ///
9338    /// <div class="warning">
9339    ///
9340    /// **Experimental.** This API is part of an experimental wire-protocol surface
9341    /// and may change or be removed in future SDK or CLI releases. Pin both the
9342    /// SDK and CLI versions if your code depends on it.
9343    ///
9344    /// </div>
9345    pub async fn disable(&self, params: SkillsDisableRequest) -> Result<(), Error> {
9346        let mut wire_params = serde_json::to_value(params)?;
9347        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
9348        let _value = self
9349            .session
9350            .client()
9351            .call(rpc_methods::SESSION_SKILLS_DISABLE, Some(wire_params))
9352            .await?;
9353        Ok(())
9354    }
9355
9356    /// Reloads skill definitions for the session.
9357    ///
9358    /// Wire method: `session.skills.reload`.
9359    ///
9360    /// # Returns
9361    ///
9362    /// Diagnostics from reloading skill definitions, with warnings and errors as separate lists.
9363    ///
9364    /// <div class="warning">
9365    ///
9366    /// **Experimental.** This API is part of an experimental wire-protocol surface
9367    /// and may change or be removed in future SDK or CLI releases. Pin both the
9368    /// SDK and CLI versions if your code depends on it.
9369    ///
9370    /// </div>
9371    pub async fn reload(&self) -> Result<SkillsLoadDiagnostics, Error> {
9372        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
9373        let _value = self
9374            .session
9375            .client()
9376            .call(rpc_methods::SESSION_SKILLS_RELOAD, Some(wire_params))
9377            .await?;
9378        Ok(serde_json::from_value(_value)?)
9379    }
9380
9381    /// Ensures the session's skill definitions have been loaded from disk.
9382    ///
9383    /// Wire method: `session.skills.ensureLoaded`.
9384    ///
9385    /// <div class="warning">
9386    ///
9387    /// **Experimental.** This API is part of an experimental wire-protocol surface
9388    /// and may change or be removed in future SDK or CLI releases. Pin both the
9389    /// SDK and CLI versions if your code depends on it.
9390    ///
9391    /// </div>
9392    pub async fn ensure_loaded(&self) -> Result<(), Error> {
9393        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
9394        let _value = self
9395            .session
9396            .client()
9397            .call(rpc_methods::SESSION_SKILLS_ENSURELOADED, Some(wire_params))
9398            .await?;
9399        Ok(())
9400    }
9401}
9402
9403/// `session.tasks.*` RPCs.
9404#[derive(Clone, Copy)]
9405pub struct SessionRpcTasks<'a> {
9406    pub(crate) session: &'a Session,
9407}
9408
9409impl<'a> SessionRpcTasks<'a> {
9410    /// Starts a background agent task in the session.
9411    ///
9412    /// Wire method: `session.tasks.startAgent`.
9413    ///
9414    /// # Parameters
9415    ///
9416    /// * `params` - Agent type, prompt, name, and optional description and model override for the new task.
9417    ///
9418    /// # Returns
9419    ///
9420    /// Identifier assigned to the newly started background agent task.
9421    ///
9422    /// <div class="warning">
9423    ///
9424    /// **Experimental.** This API is part of an experimental wire-protocol surface
9425    /// and may change or be removed in future SDK or CLI releases. Pin both the
9426    /// SDK and CLI versions if your code depends on it.
9427    ///
9428    /// </div>
9429    pub async fn start_agent(
9430        &self,
9431        params: TasksStartAgentRequest,
9432    ) -> Result<TasksStartAgentResult, Error> {
9433        let mut wire_params = serde_json::to_value(params)?;
9434        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
9435        let _value = self
9436            .session
9437            .client()
9438            .call(rpc_methods::SESSION_TASKS_STARTAGENT, Some(wire_params))
9439            .await?;
9440        Ok(serde_json::from_value(_value)?)
9441    }
9442
9443    /// Lists background tasks tracked by the session.
9444    ///
9445    /// Wire method: `session.tasks.list`.
9446    ///
9447    /// # Returns
9448    ///
9449    /// Background tasks currently tracked by the session.
9450    ///
9451    /// <div class="warning">
9452    ///
9453    /// **Experimental.** This API is part of an experimental wire-protocol surface
9454    /// and may change or be removed in future SDK or CLI releases. Pin both the
9455    /// SDK and CLI versions if your code depends on it.
9456    ///
9457    /// </div>
9458    pub async fn list(&self) -> Result<TaskList, Error> {
9459        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
9460        let _value = self
9461            .session
9462            .client()
9463            .call(rpc_methods::SESSION_TASKS_LIST, Some(wire_params))
9464            .await?;
9465        Ok(serde_json::from_value(_value)?)
9466    }
9467
9468    /// Refreshes metadata for any detached background shells the runtime knows about.
9469    ///
9470    /// Wire method: `session.tasks.refresh`.
9471    ///
9472    /// # Returns
9473    ///
9474    /// Refresh metadata for any detached background shells the runtime knows about. Use after a long pause to pick up exit/output state for shells running outside the agent loop.
9475    ///
9476    /// <div class="warning">
9477    ///
9478    /// **Experimental.** This API is part of an experimental wire-protocol surface
9479    /// and may change or be removed in future SDK or CLI releases. Pin both the
9480    /// SDK and CLI versions if your code depends on it.
9481    ///
9482    /// </div>
9483    pub async fn refresh(&self) -> Result<TasksRefreshResult, Error> {
9484        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
9485        let _value = self
9486            .session
9487            .client()
9488            .call(rpc_methods::SESSION_TASKS_REFRESH, Some(wire_params))
9489            .await?;
9490        Ok(serde_json::from_value(_value)?)
9491    }
9492
9493    /// Waits for all in-flight background tasks and any follow-up turns to settle.
9494    ///
9495    /// Wire method: `session.tasks.waitForPending`.
9496    ///
9497    /// # Returns
9498    ///
9499    /// Wait until all in-flight background tasks (agents + shells) and any follow-up turns scheduled by their completions have settled. Returns when the runtime is fully drained or after an internal timeout (default 10 minutes; configurable via COPILOT_TASK_WAIT_TIMEOUT_SECONDS).
9500    ///
9501    /// <div class="warning">
9502    ///
9503    /// **Experimental.** This API is part of an experimental wire-protocol surface
9504    /// and may change or be removed in future SDK or CLI releases. Pin both the
9505    /// SDK and CLI versions if your code depends on it.
9506    ///
9507    /// </div>
9508    pub async fn wait_for_pending(&self) -> Result<TasksWaitForPendingResult, Error> {
9509        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
9510        let _value = self
9511            .session
9512            .client()
9513            .call(rpc_methods::SESSION_TASKS_WAITFORPENDING, Some(wire_params))
9514            .await?;
9515        Ok(serde_json::from_value(_value)?)
9516    }
9517
9518    /// Returns progress information for a background task by ID.
9519    ///
9520    /// Wire method: `session.tasks.getProgress`.
9521    ///
9522    /// # Parameters
9523    ///
9524    /// * `params` - Identifier of the background task to fetch progress for.
9525    ///
9526    /// # Returns
9527    ///
9528    /// Progress information for the task, or null when no task with that ID is tracked.
9529    ///
9530    /// <div class="warning">
9531    ///
9532    /// **Experimental.** This API is part of an experimental wire-protocol surface
9533    /// and may change or be removed in future SDK or CLI releases. Pin both the
9534    /// SDK and CLI versions if your code depends on it.
9535    ///
9536    /// </div>
9537    pub async fn get_progress(
9538        &self,
9539        params: TasksGetProgressRequest,
9540    ) -> Result<TasksGetProgressResult, Error> {
9541        let mut wire_params = serde_json::to_value(params)?;
9542        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
9543        let _value = self
9544            .session
9545            .client()
9546            .call(rpc_methods::SESSION_TASKS_GETPROGRESS, Some(wire_params))
9547            .await?;
9548        Ok(serde_json::from_value(_value)?)
9549    }
9550
9551    /// Returns the first sync-waiting task that can currently be promoted to background mode.
9552    ///
9553    /// Wire method: `session.tasks.getCurrentPromotable`.
9554    ///
9555    /// # Returns
9556    ///
9557    /// The first sync-waiting task that can currently be promoted to background mode.
9558    ///
9559    /// <div class="warning">
9560    ///
9561    /// **Experimental.** This API is part of an experimental wire-protocol surface
9562    /// and may change or be removed in future SDK or CLI releases. Pin both the
9563    /// SDK and CLI versions if your code depends on it.
9564    ///
9565    /// </div>
9566    pub async fn get_current_promotable(&self) -> Result<TasksGetCurrentPromotableResult, Error> {
9567        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
9568        let _value = self
9569            .session
9570            .client()
9571            .call(
9572                rpc_methods::SESSION_TASKS_GETCURRENTPROMOTABLE,
9573                Some(wire_params),
9574            )
9575            .await?;
9576        Ok(serde_json::from_value(_value)?)
9577    }
9578
9579    /// Promotes an eligible synchronously-waited task so it continues running in the background.
9580    ///
9581    /// Wire method: `session.tasks.promoteToBackground`.
9582    ///
9583    /// # Parameters
9584    ///
9585    /// * `params` - Identifier of the task to promote to background mode.
9586    ///
9587    /// # Returns
9588    ///
9589    /// Indicates whether the task was successfully promoted to background mode.
9590    ///
9591    /// <div class="warning">
9592    ///
9593    /// **Experimental.** This API is part of an experimental wire-protocol surface
9594    /// and may change or be removed in future SDK or CLI releases. Pin both the
9595    /// SDK and CLI versions if your code depends on it.
9596    ///
9597    /// </div>
9598    pub async fn promote_to_background(
9599        &self,
9600        params: TasksPromoteToBackgroundRequest,
9601    ) -> Result<TasksPromoteToBackgroundResult, Error> {
9602        let mut wire_params = serde_json::to_value(params)?;
9603        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
9604        let _value = self
9605            .session
9606            .client()
9607            .call(
9608                rpc_methods::SESSION_TASKS_PROMOTETOBACKGROUND,
9609                Some(wire_params),
9610            )
9611            .await?;
9612        Ok(serde_json::from_value(_value)?)
9613    }
9614
9615    /// Atomically promotes the first promotable sync-waiting task to background mode and returns it.
9616    ///
9617    /// Wire method: `session.tasks.promoteCurrentToBackground`.
9618    ///
9619    /// # Returns
9620    ///
9621    /// The promoted task as it now exists in background mode, omitted if no promotable task was waiting.
9622    ///
9623    /// <div class="warning">
9624    ///
9625    /// **Experimental.** This API is part of an experimental wire-protocol surface
9626    /// and may change or be removed in future SDK or CLI releases. Pin both the
9627    /// SDK and CLI versions if your code depends on it.
9628    ///
9629    /// </div>
9630    pub async fn promote_current_to_background(
9631        &self,
9632    ) -> Result<TasksPromoteCurrentToBackgroundResult, Error> {
9633        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
9634        let _value = self
9635            .session
9636            .client()
9637            .call(
9638                rpc_methods::SESSION_TASKS_PROMOTECURRENTTOBACKGROUND,
9639                Some(wire_params),
9640            )
9641            .await?;
9642        Ok(serde_json::from_value(_value)?)
9643    }
9644
9645    /// Cancels a background task.
9646    ///
9647    /// Wire method: `session.tasks.cancel`.
9648    ///
9649    /// # Parameters
9650    ///
9651    /// * `params` - Identifier of the background task to cancel.
9652    ///
9653    /// # Returns
9654    ///
9655    /// Indicates whether the background task was successfully cancelled.
9656    ///
9657    /// <div class="warning">
9658    ///
9659    /// **Experimental.** This API is part of an experimental wire-protocol surface
9660    /// and may change or be removed in future SDK or CLI releases. Pin both the
9661    /// SDK and CLI versions if your code depends on it.
9662    ///
9663    /// </div>
9664    pub async fn cancel(&self, params: TasksCancelRequest) -> Result<TasksCancelResult, Error> {
9665        let mut wire_params = serde_json::to_value(params)?;
9666        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
9667        let _value = self
9668            .session
9669            .client()
9670            .call(rpc_methods::SESSION_TASKS_CANCEL, Some(wire_params))
9671            .await?;
9672        Ok(serde_json::from_value(_value)?)
9673    }
9674
9675    /// Removes a completed or cancelled background task from tracking.
9676    ///
9677    /// Wire method: `session.tasks.remove`.
9678    ///
9679    /// # Parameters
9680    ///
9681    /// * `params` - Identifier of the completed or cancelled task to remove from tracking.
9682    ///
9683    /// # Returns
9684    ///
9685    /// Indicates whether the task was removed. False when the task does not exist or is still running/idle.
9686    ///
9687    /// <div class="warning">
9688    ///
9689    /// **Experimental.** This API is part of an experimental wire-protocol surface
9690    /// and may change or be removed in future SDK or CLI releases. Pin both the
9691    /// SDK and CLI versions if your code depends on it.
9692    ///
9693    /// </div>
9694    pub async fn remove(&self, params: TasksRemoveRequest) -> Result<TasksRemoveResult, Error> {
9695        let mut wire_params = serde_json::to_value(params)?;
9696        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
9697        let _value = self
9698            .session
9699            .client()
9700            .call(rpc_methods::SESSION_TASKS_REMOVE, Some(wire_params))
9701            .await?;
9702        Ok(serde_json::from_value(_value)?)
9703    }
9704
9705    /// Sends a message to a background agent task.
9706    ///
9707    /// Wire method: `session.tasks.sendMessage`.
9708    ///
9709    /// # Parameters
9710    ///
9711    /// * `params` - Identifier of the target agent task, message content, and optional sender agent ID.
9712    ///
9713    /// # Returns
9714    ///
9715    /// Indicates whether the message was delivered, with an error message when delivery failed.
9716    ///
9717    /// <div class="warning">
9718    ///
9719    /// **Experimental.** This API is part of an experimental wire-protocol surface
9720    /// and may change or be removed in future SDK or CLI releases. Pin both the
9721    /// SDK and CLI versions if your code depends on it.
9722    ///
9723    /// </div>
9724    pub async fn send_message(
9725        &self,
9726        params: TasksSendMessageRequest,
9727    ) -> Result<TasksSendMessageResult, Error> {
9728        let mut wire_params = serde_json::to_value(params)?;
9729        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
9730        let _value = self
9731            .session
9732            .client()
9733            .call(rpc_methods::SESSION_TASKS_SENDMESSAGE, Some(wire_params))
9734            .await?;
9735        Ok(serde_json::from_value(_value)?)
9736    }
9737}
9738
9739/// `session.telemetry.*` RPCs.
9740#[derive(Clone, Copy)]
9741pub struct SessionRpcTelemetry<'a> {
9742    pub(crate) session: &'a Session,
9743}
9744
9745impl<'a> SessionRpcTelemetry<'a> {
9746    /// Gets the telemetry engagement ID currently associated with the session, when available.
9747    ///
9748    /// Wire method: `session.telemetry.getEngagementId`.
9749    ///
9750    /// # Returns
9751    ///
9752    /// Telemetry engagement ID for the session, when available.
9753    ///
9754    /// <div class="warning">
9755    ///
9756    /// **Experimental.** This API is part of an experimental wire-protocol surface
9757    /// and may change or be removed in future SDK or CLI releases. Pin both the
9758    /// SDK and CLI versions if your code depends on it.
9759    ///
9760    /// </div>
9761    pub async fn get_engagement_id(&self) -> Result<SessionTelemetryEngagement, Error> {
9762        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
9763        let _value = self
9764            .session
9765            .client()
9766            .call(
9767                rpc_methods::SESSION_TELEMETRY_GETENGAGEMENTID,
9768                Some(wire_params),
9769            )
9770            .await?;
9771        Ok(serde_json::from_value(_value)?)
9772    }
9773
9774    /// Sets feature override key/value pairs to attach to subsequent telemetry events for the session.
9775    ///
9776    /// Wire method: `session.telemetry.setFeatureOverrides`.
9777    ///
9778    /// # Parameters
9779    ///
9780    /// * `params` - Feature override key/value pairs to attach to subsequent telemetry events from this session.
9781    ///
9782    /// <div class="warning">
9783    ///
9784    /// **Experimental.** This API is part of an experimental wire-protocol surface
9785    /// and may change or be removed in future SDK or CLI releases. Pin both the
9786    /// SDK and CLI versions if your code depends on it.
9787    ///
9788    /// </div>
9789    pub async fn set_feature_overrides(
9790        &self,
9791        params: TelemetrySetFeatureOverridesRequest,
9792    ) -> Result<(), Error> {
9793        let mut wire_params = serde_json::to_value(params)?;
9794        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
9795        let _value = self
9796            .session
9797            .client()
9798            .call(
9799                rpc_methods::SESSION_TELEMETRY_SETFEATUREOVERRIDES,
9800                Some(wire_params),
9801            )
9802            .await?;
9803        Ok(())
9804    }
9805}
9806
9807/// `session.tools.*` RPCs.
9808#[derive(Clone, Copy)]
9809pub struct SessionRpcTools<'a> {
9810    pub(crate) session: &'a Session,
9811}
9812
9813impl<'a> SessionRpcTools<'a> {
9814    /// Provides the result for a pending external tool call.
9815    ///
9816    /// Wire method: `session.tools.handlePendingToolCall`.
9817    ///
9818    /// # Parameters
9819    ///
9820    /// * `params` - Pending external tool call request ID, with the tool result or an error describing why it failed.
9821    ///
9822    /// # Returns
9823    ///
9824    /// Indicates whether the external tool call result was handled successfully.
9825    ///
9826    /// <div class="warning">
9827    ///
9828    /// **Experimental.** This API is part of an experimental wire-protocol surface
9829    /// and may change or be removed in future SDK or CLI releases. Pin both the
9830    /// SDK and CLI versions if your code depends on it.
9831    ///
9832    /// </div>
9833    pub async fn handle_pending_tool_call(
9834        &self,
9835        params: HandlePendingToolCallRequest,
9836    ) -> Result<HandlePendingToolCallResult, Error> {
9837        let mut wire_params = serde_json::to_value(params)?;
9838        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
9839        let _value = self
9840            .session
9841            .client()
9842            .call(
9843                rpc_methods::SESSION_TOOLS_HANDLEPENDINGTOOLCALL,
9844                Some(wire_params),
9845            )
9846            .await?;
9847        Ok(serde_json::from_value(_value)?)
9848    }
9849
9850    /// Resolves, builds, and validates the runtime tool list for the session.
9851    ///
9852    /// Wire method: `session.tools.initializeAndValidate`.
9853    ///
9854    /// # Returns
9855    ///
9856    /// Resolve, build, and validate the runtime tool list for this session. Subagent sessions and consumer flows that need an initialized tool set before `send` invoke this. Default base-class implementation is a no-op for sessions that don't support tool validation.
9857    ///
9858    /// <div class="warning">
9859    ///
9860    /// **Experimental.** This API is part of an experimental wire-protocol surface
9861    /// and may change or be removed in future SDK or CLI releases. Pin both the
9862    /// SDK and CLI versions if your code depends on it.
9863    ///
9864    /// </div>
9865    pub async fn initialize_and_validate(&self) -> Result<ToolsInitializeAndValidateResult, Error> {
9866        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
9867        let _value = self
9868            .session
9869            .client()
9870            .call(
9871                rpc_methods::SESSION_TOOLS_INITIALIZEANDVALIDATE,
9872                Some(wire_params),
9873            )
9874            .await?;
9875        Ok(serde_json::from_value(_value)?)
9876    }
9877
9878    /// Returns lightweight metadata for the session's currently initialized tools.
9879    ///
9880    /// Wire method: `session.tools.getCurrentMetadata`.
9881    ///
9882    /// # Returns
9883    ///
9884    /// Current lightweight tool metadata snapshot for the session.
9885    ///
9886    /// <div class="warning">
9887    ///
9888    /// **Experimental.** This API is part of an experimental wire-protocol surface
9889    /// and may change or be removed in future SDK or CLI releases. Pin both the
9890    /// SDK and CLI versions if your code depends on it.
9891    ///
9892    /// </div>
9893    pub async fn get_current_metadata(&self) -> Result<ToolsGetCurrentMetadataResult, Error> {
9894        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
9895        let _value = self
9896            .session
9897            .client()
9898            .call(
9899                rpc_methods::SESSION_TOOLS_GETCURRENTMETADATA,
9900                Some(wire_params),
9901            )
9902            .await?;
9903        Ok(serde_json::from_value(_value)?)
9904    }
9905
9906    /// Updates the current session's live subagent settings after user settings change. The persisted user settings remain the source of truth for future sessions.
9907    ///
9908    /// Wire method: `session.tools.updateSubagentSettings`.
9909    ///
9910    /// # Parameters
9911    ///
9912    /// * `params` - Subagent settings to apply to the current session
9913    ///
9914    /// # Returns
9915    ///
9916    /// Empty result after applying subagent settings
9917    ///
9918    /// <div class="warning">
9919    ///
9920    /// **Experimental.** This API is part of an experimental wire-protocol surface
9921    /// and may change or be removed in future SDK or CLI releases. Pin both the
9922    /// SDK and CLI versions if your code depends on it.
9923    ///
9924    /// </div>
9925    pub async fn update_subagent_settings(
9926        &self,
9927        params: UpdateSubagentSettingsRequest,
9928    ) -> Result<ToolsUpdateSubagentSettingsResult, Error> {
9929        let mut wire_params = serde_json::to_value(params)?;
9930        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
9931        let _value = self
9932            .session
9933            .client()
9934            .call(
9935                rpc_methods::SESSION_TOOLS_UPDATESUBAGENTSETTINGS,
9936                Some(wire_params),
9937            )
9938            .await?;
9939        Ok(serde_json::from_value(_value)?)
9940    }
9941}
9942
9943/// `session.ui.*` RPCs.
9944#[derive(Clone, Copy)]
9945pub struct SessionRpcUi<'a> {
9946    pub(crate) session: &'a Session,
9947}
9948
9949impl<'a> SessionRpcUi<'a> {
9950    /// Runs a transient no-tools model query against the current conversation context.
9951    ///
9952    /// Wire method: `session.ui.ephemeralQuery`.
9953    ///
9954    /// # Parameters
9955    ///
9956    /// * `params` - Transient question to answer without adding it to conversation history.
9957    ///
9958    /// # Returns
9959    ///
9960    /// Transient answer generated from current conversation context.
9961    ///
9962    /// <div class="warning">
9963    ///
9964    /// **Experimental.** This API is part of an experimental wire-protocol surface
9965    /// and may change or be removed in future SDK or CLI releases. Pin both the
9966    /// SDK and CLI versions if your code depends on it.
9967    ///
9968    /// </div>
9969    pub async fn ephemeral_query(
9970        &self,
9971        params: UIEphemeralQueryRequest,
9972    ) -> Result<UIEphemeralQueryResult, Error> {
9973        let mut wire_params = serde_json::to_value(params)?;
9974        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
9975        let _value = self
9976            .session
9977            .client()
9978            .call(rpc_methods::SESSION_UI_EPHEMERALQUERY, Some(wire_params))
9979            .await?;
9980        Ok(serde_json::from_value(_value)?)
9981    }
9982
9983    /// Requests structured input from a UI-capable client.
9984    ///
9985    /// Wire method: `session.ui.elicitation`.
9986    ///
9987    /// # Parameters
9988    ///
9989    /// * `params` - Prompt message and JSON schema describing the form fields to elicit from the user.
9990    ///
9991    /// # Returns
9992    ///
9993    /// The elicitation response (accept with form values, decline, or cancel)
9994    ///
9995    /// <div class="warning">
9996    ///
9997    /// **Experimental.** This API is part of an experimental wire-protocol surface
9998    /// and may change or be removed in future SDK or CLI releases. Pin both the
9999    /// SDK and CLI versions if your code depends on it.
10000    ///
10001    /// </div>
10002    pub async fn elicitation(
10003        &self,
10004        params: UIElicitationRequest,
10005    ) -> Result<UIElicitationResponse, Error> {
10006        let mut wire_params = serde_json::to_value(params)?;
10007        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
10008        let _value = self
10009            .session
10010            .client()
10011            .call(rpc_methods::SESSION_UI_ELICITATION, Some(wire_params))
10012            .await?;
10013        Ok(serde_json::from_value(_value)?)
10014    }
10015
10016    /// Provides the user response for a pending elicitation request.
10017    ///
10018    /// Wire method: `session.ui.handlePendingElicitation`.
10019    ///
10020    /// # Parameters
10021    ///
10022    /// * `params` - Pending elicitation request ID and the user's response (accept/decline/cancel + form values).
10023    ///
10024    /// # Returns
10025    ///
10026    /// Indicates whether the elicitation response was accepted; false if it was already resolved by another client.
10027    ///
10028    /// <div class="warning">
10029    ///
10030    /// **Experimental.** This API is part of an experimental wire-protocol surface
10031    /// and may change or be removed in future SDK or CLI releases. Pin both the
10032    /// SDK and CLI versions if your code depends on it.
10033    ///
10034    /// </div>
10035    pub async fn handle_pending_elicitation(
10036        &self,
10037        params: UIHandlePendingElicitationRequest,
10038    ) -> Result<UIElicitationResult, Error> {
10039        let mut wire_params = serde_json::to_value(params)?;
10040        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
10041        let _value = self
10042            .session
10043            .client()
10044            .call(
10045                rpc_methods::SESSION_UI_HANDLEPENDINGELICITATION,
10046                Some(wire_params),
10047            )
10048            .await?;
10049        Ok(serde_json::from_value(_value)?)
10050    }
10051
10052    /// Resolves a pending `user_input.requested` event with the user's response.
10053    ///
10054    /// Wire method: `session.ui.handlePendingUserInput`.
10055    ///
10056    /// # Parameters
10057    ///
10058    /// * `params` - Request ID of a pending `user_input.requested` event and the user's response.
10059    ///
10060    /// # Returns
10061    ///
10062    /// Indicates whether the pending UI request was resolved by this call.
10063    ///
10064    /// <div class="warning">
10065    ///
10066    /// **Experimental.** This API is part of an experimental wire-protocol surface
10067    /// and may change or be removed in future SDK or CLI releases. Pin both the
10068    /// SDK and CLI versions if your code depends on it.
10069    ///
10070    /// </div>
10071    pub async fn handle_pending_user_input(
10072        &self,
10073        params: UIHandlePendingUserInputRequest,
10074    ) -> Result<UIHandlePendingResult, Error> {
10075        let mut wire_params = serde_json::to_value(params)?;
10076        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
10077        let _value = self
10078            .session
10079            .client()
10080            .call(
10081                rpc_methods::SESSION_UI_HANDLEPENDINGUSERINPUT,
10082                Some(wire_params),
10083            )
10084            .await?;
10085        Ok(serde_json::from_value(_value)?)
10086    }
10087
10088    /// Resolves a pending `sampling.requested` event with a sampling result, or rejects it.
10089    ///
10090    /// Wire method: `session.ui.handlePendingSampling`.
10091    ///
10092    /// # Parameters
10093    ///
10094    /// * `params` - Request ID of a pending `sampling.requested` event and an optional sampling result payload (omit to reject).
10095    ///
10096    /// # Returns
10097    ///
10098    /// Indicates whether the pending UI request was resolved by this call.
10099    ///
10100    /// <div class="warning">
10101    ///
10102    /// **Experimental.** This API is part of an experimental wire-protocol surface
10103    /// and may change or be removed in future SDK or CLI releases. Pin both the
10104    /// SDK and CLI versions if your code depends on it.
10105    ///
10106    /// </div>
10107    pub async fn handle_pending_sampling(
10108        &self,
10109        params: UIHandlePendingSamplingRequest,
10110    ) -> Result<UIHandlePendingResult, Error> {
10111        let mut wire_params = serde_json::to_value(params)?;
10112        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
10113        let _value = self
10114            .session
10115            .client()
10116            .call(
10117                rpc_methods::SESSION_UI_HANDLEPENDINGSAMPLING,
10118                Some(wire_params),
10119            )
10120            .await?;
10121        Ok(serde_json::from_value(_value)?)
10122    }
10123
10124    /// Resolves a pending `auto_mode_switch.requested` event with the user's accept/decline decision.
10125    ///
10126    /// Wire method: `session.ui.handlePendingAutoModeSwitch`.
10127    ///
10128    /// # Parameters
10129    ///
10130    /// * `params` - Request ID of a pending `auto_mode_switch.requested` event and the user's response.
10131    ///
10132    /// # Returns
10133    ///
10134    /// Indicates whether the pending UI request was resolved by this call.
10135    ///
10136    /// <div class="warning">
10137    ///
10138    /// **Experimental.** This API is part of an experimental wire-protocol surface
10139    /// and may change or be removed in future SDK or CLI releases. Pin both the
10140    /// SDK and CLI versions if your code depends on it.
10141    ///
10142    /// </div>
10143    pub async fn handle_pending_auto_mode_switch(
10144        &self,
10145        params: UIHandlePendingAutoModeSwitchRequest,
10146    ) -> Result<UIHandlePendingResult, Error> {
10147        let mut wire_params = serde_json::to_value(params)?;
10148        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
10149        let _value = self
10150            .session
10151            .client()
10152            .call(
10153                rpc_methods::SESSION_UI_HANDLEPENDINGAUTOMODESWITCH,
10154                Some(wire_params),
10155            )
10156            .await?;
10157        Ok(serde_json::from_value(_value)?)
10158    }
10159
10160    /// Resolves a pending `session_limits_exhausted.requested` event with the user's selected limit action.
10161    ///
10162    /// Wire method: `session.ui.handlePendingSessionLimitsExhausted`.
10163    ///
10164    /// # Parameters
10165    ///
10166    /// * `params` - Request ID of a pending `session_limits_exhausted.requested` event and the user's selected limit action.
10167    ///
10168    /// # Returns
10169    ///
10170    /// Indicates whether the pending UI request was resolved by this call.
10171    ///
10172    /// <div class="warning">
10173    ///
10174    /// **Experimental.** This API is part of an experimental wire-protocol surface
10175    /// and may change or be removed in future SDK or CLI releases. Pin both the
10176    /// SDK and CLI versions if your code depends on it.
10177    ///
10178    /// </div>
10179    pub async fn handle_pending_session_limits_exhausted(
10180        &self,
10181        params: UIHandlePendingSessionLimitsExhaustedRequest,
10182    ) -> Result<UIHandlePendingResult, Error> {
10183        let mut wire_params = serde_json::to_value(params)?;
10184        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
10185        let _value = self
10186            .session
10187            .client()
10188            .call(
10189                rpc_methods::SESSION_UI_HANDLEPENDINGSESSIONLIMITSEXHAUSTED,
10190                Some(wire_params),
10191            )
10192            .await?;
10193        Ok(serde_json::from_value(_value)?)
10194    }
10195
10196    /// Resolves a pending `exit_plan_mode.requested` event with the user's response.
10197    ///
10198    /// Wire method: `session.ui.handlePendingExitPlanMode`.
10199    ///
10200    /// # Parameters
10201    ///
10202    /// * `params` - Request ID of a pending `exit_plan_mode.requested` event and the user's response.
10203    ///
10204    /// # Returns
10205    ///
10206    /// Indicates whether the pending UI request was resolved by this call.
10207    ///
10208    /// <div class="warning">
10209    ///
10210    /// **Experimental.** This API is part of an experimental wire-protocol surface
10211    /// and may change or be removed in future SDK or CLI releases. Pin both the
10212    /// SDK and CLI versions if your code depends on it.
10213    ///
10214    /// </div>
10215    pub async fn handle_pending_exit_plan_mode(
10216        &self,
10217        params: UIHandlePendingExitPlanModeRequest,
10218    ) -> Result<UIHandlePendingResult, Error> {
10219        let mut wire_params = serde_json::to_value(params)?;
10220        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
10221        let _value = self
10222            .session
10223            .client()
10224            .call(
10225                rpc_methods::SESSION_UI_HANDLEPENDINGEXITPLANMODE,
10226                Some(wire_params),
10227            )
10228            .await?;
10229        Ok(serde_json::from_value(_value)?)
10230    }
10231
10232    /// Registers an in-process handler for auto-mode-switch requests so the server bridge skips dispatch.
10233    ///
10234    /// Wire method: `session.ui.registerDirectAutoModeSwitchHandler`.
10235    ///
10236    /// # Returns
10237    ///
10238    /// Register an in-process handler for `auto_mode_switch.requested` events. The caller still attaches the actual listener via the standard event-subscription mechanism; this registration solely tells the server bridge to skip its own dispatch (so a remote client doesn't race the in-process handler for the same requestId).
10239    ///
10240    /// <div class="warning">
10241    ///
10242    /// **Experimental.** This API is part of an experimental wire-protocol surface
10243    /// and may change or be removed in future SDK or CLI releases. Pin both the
10244    /// SDK and CLI versions if your code depends on it.
10245    ///
10246    /// </div>
10247    pub async fn register_direct_auto_mode_switch_handler(
10248        &self,
10249    ) -> Result<UIRegisterDirectAutoModeSwitchHandlerResult, Error> {
10250        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
10251        let _value = self
10252            .session
10253            .client()
10254            .call(
10255                rpc_methods::SESSION_UI_REGISTERDIRECTAUTOMODESWITCHHANDLER,
10256                Some(wire_params),
10257            )
10258            .await?;
10259        Ok(serde_json::from_value(_value)?)
10260    }
10261
10262    /// Unregisters a previously-registered in-process auto-mode-switch handler by its opaque handle.
10263    ///
10264    /// Wire method: `session.ui.unregisterDirectAutoModeSwitchHandler`.
10265    ///
10266    /// # Parameters
10267    ///
10268    /// * `params` - Opaque handle previously returned by `registerDirectAutoModeSwitchHandler` to release.
10269    ///
10270    /// # Returns
10271    ///
10272    /// Indicates whether the handle was active and the registration count was decremented.
10273    ///
10274    /// <div class="warning">
10275    ///
10276    /// **Experimental.** This API is part of an experimental wire-protocol surface
10277    /// and may change or be removed in future SDK or CLI releases. Pin both the
10278    /// SDK and CLI versions if your code depends on it.
10279    ///
10280    /// </div>
10281    pub async fn unregister_direct_auto_mode_switch_handler(
10282        &self,
10283        params: UIUnregisterDirectAutoModeSwitchHandlerRequest,
10284    ) -> Result<UIUnregisterDirectAutoModeSwitchHandlerResult, Error> {
10285        let mut wire_params = serde_json::to_value(params)?;
10286        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
10287        let _value = self
10288            .session
10289            .client()
10290            .call(
10291                rpc_methods::SESSION_UI_UNREGISTERDIRECTAUTOMODESWITCHHANDLER,
10292                Some(wire_params),
10293            )
10294            .await?;
10295        Ok(serde_json::from_value(_value)?)
10296    }
10297}
10298
10299/// `session.usage.*` RPCs.
10300#[derive(Clone, Copy)]
10301pub struct SessionRpcUsage<'a> {
10302    pub(crate) session: &'a Session,
10303}
10304
10305impl<'a> SessionRpcUsage<'a> {
10306    /// Gets accumulated usage metrics for the session.
10307    ///
10308    /// Wire method: `session.usage.getMetrics`.
10309    ///
10310    /// # Returns
10311    ///
10312    /// Accumulated session usage metrics, including premium request cost, token counts, model breakdown, and code-change totals.
10313    ///
10314    /// <div class="warning">
10315    ///
10316    /// **Experimental.** This API is part of an experimental wire-protocol surface
10317    /// and may change or be removed in future SDK or CLI releases. Pin both the
10318    /// SDK and CLI versions if your code depends on it.
10319    ///
10320    /// </div>
10321    pub async fn get_metrics(&self) -> Result<UsageGetMetricsResult, Error> {
10322        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
10323        let _value = self
10324            .session
10325            .client()
10326            .call(rpc_methods::SESSION_USAGE_GETMETRICS, Some(wire_params))
10327            .await?;
10328        Ok(serde_json::from_value(_value)?)
10329    }
10330}
10331
10332/// `session.visibility.*` RPCs.
10333#[derive(Clone, Copy)]
10334pub struct SessionRpcVisibility<'a> {
10335    pub(crate) session: &'a Session,
10336}
10337
10338impl<'a> SessionRpcVisibility<'a> {
10339    /// Returns the session's current Mission Control sharing status and shareable GitHub URL. Reflects whether the synced session is visible to repository readers ("repo") or restricted to its creator and collaborators ("unshared").
10340    ///
10341    /// Wire method: `session.visibility.get`.
10342    ///
10343    /// # Returns
10344    ///
10345    /// Current sharing status and shareable GitHub URL for a session.
10346    ///
10347    /// <div class="warning">
10348    ///
10349    /// **Experimental.** This API is part of an experimental wire-protocol surface
10350    /// and may change or be removed in future SDK or CLI releases. Pin both the
10351    /// SDK and CLI versions if your code depends on it.
10352    ///
10353    /// </div>
10354    pub async fn get(&self) -> Result<VisibilityGetResult, Error> {
10355        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
10356        let _value = self
10357            .session
10358            .client()
10359            .call(rpc_methods::SESSION_VISIBILITY_GET, Some(wire_params))
10360            .await?;
10361        Ok(serde_json::from_value(_value)?)
10362    }
10363
10364    /// Sets the session's Mission Control sharing status, controlling whether the synced session is visible to repository readers. Returns the effective status and shareable GitHub URL after the change.
10365    ///
10366    /// Wire method: `session.visibility.set`.
10367    ///
10368    /// # Parameters
10369    ///
10370    /// * `params` - Desired sharing status for the session.
10371    ///
10372    /// # Returns
10373    ///
10374    /// Effective sharing status and shareable GitHub URL after updating session visibility.
10375    ///
10376    /// <div class="warning">
10377    ///
10378    /// **Experimental.** This API is part of an experimental wire-protocol surface
10379    /// and may change or be removed in future SDK or CLI releases. Pin both the
10380    /// SDK and CLI versions if your code depends on it.
10381    ///
10382    /// </div>
10383    pub async fn set(&self, params: VisibilitySetRequest) -> Result<VisibilitySetResult, Error> {
10384        let mut wire_params = serde_json::to_value(params)?;
10385        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
10386        let _value = self
10387            .session
10388            .client()
10389            .call(rpc_methods::SESSION_VISIBILITY_SET, Some(wire_params))
10390            .await?;
10391        Ok(serde_json::from_value(_value)?)
10392    }
10393}
10394
10395/// `session.workspaces.*` RPCs.
10396#[derive(Clone, Copy)]
10397pub struct SessionRpcWorkspaces<'a> {
10398    pub(crate) session: &'a Session,
10399}
10400
10401impl<'a> SessionRpcWorkspaces<'a> {
10402    /// Gets current workspace metadata for the session.
10403    ///
10404    /// Wire method: `session.workspaces.getWorkspace`.
10405    ///
10406    /// # Returns
10407    ///
10408    /// Current workspace metadata for the session, including its absolute filesystem path when available.
10409    ///
10410    /// <div class="warning">
10411    ///
10412    /// **Experimental.** This API is part of an experimental wire-protocol surface
10413    /// and may change or be removed in future SDK or CLI releases. Pin both the
10414    /// SDK and CLI versions if your code depends on it.
10415    ///
10416    /// </div>
10417    pub async fn get_workspace(&self) -> Result<WorkspacesGetWorkspaceResult, Error> {
10418        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
10419        let _value = self
10420            .session
10421            .client()
10422            .call(
10423                rpc_methods::SESSION_WORKSPACES_GETWORKSPACE,
10424                Some(wire_params),
10425            )
10426            .await?;
10427        Ok(serde_json::from_value(_value)?)
10428    }
10429
10430    /// Updates workspace metadata for a local session and returns the refreshed workspace.
10431    ///
10432    /// Wire method: `session.workspaces.updateMetadata`.
10433    ///
10434    /// # Parameters
10435    ///
10436    /// * `params` - Workspace metadata fields to update.
10437    ///
10438    /// # Returns
10439    ///
10440    /// Current workspace metadata for the session, including its absolute filesystem path when available.
10441    ///
10442    /// <div class="warning">
10443    ///
10444    /// **Experimental.** This API is part of an experimental wire-protocol surface
10445    /// and may change or be removed in future SDK or CLI releases. Pin both the
10446    /// SDK and CLI versions if your code depends on it.
10447    ///
10448    /// </div>
10449    pub async fn update_metadata(
10450        &self,
10451        params: WorkspacesUpdateMetadataRequest,
10452    ) -> Result<WorkspacesGetWorkspaceResult, Error> {
10453        let mut wire_params = serde_json::to_value(params)?;
10454        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
10455        let _value = self
10456            .session
10457            .client()
10458            .call(
10459                rpc_methods::SESSION_WORKSPACES_UPDATEMETADATA,
10460                Some(wire_params),
10461            )
10462            .await?;
10463        Ok(serde_json::from_value(_value)?)
10464    }
10465
10466    /// Ensures a local session workspace exists and returns it.
10467    ///
10468    /// Wire method: `session.workspaces.ensure`.
10469    ///
10470    /// # Parameters
10471    ///
10472    /// * `params` - Optional session context used when creating a local workspace.
10473    ///
10474    /// # Returns
10475    ///
10476    /// Current workspace metadata for the session, including its absolute filesystem path when available.
10477    ///
10478    /// <div class="warning">
10479    ///
10480    /// **Experimental.** This API is part of an experimental wire-protocol surface
10481    /// and may change or be removed in future SDK or CLI releases. Pin both the
10482    /// SDK and CLI versions if your code depends on it.
10483    ///
10484    /// </div>
10485    pub async fn ensure(
10486        &self,
10487        params: WorkspacesEnsureRequest,
10488    ) -> Result<WorkspacesGetWorkspaceResult, Error> {
10489        let mut wire_params = serde_json::to_value(params)?;
10490        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
10491        let _value = self
10492            .session
10493            .client()
10494            .call(rpc_methods::SESSION_WORKSPACES_ENSURE, Some(wire_params))
10495            .await?;
10496        Ok(serde_json::from_value(_value)?)
10497    }
10498
10499    /// Lists files stored in the session workspace files directory.
10500    ///
10501    /// Wire method: `session.workspaces.listFiles`.
10502    ///
10503    /// # Returns
10504    ///
10505    /// Relative paths of files stored in the session workspace files directory.
10506    ///
10507    /// <div class="warning">
10508    ///
10509    /// **Experimental.** This API is part of an experimental wire-protocol surface
10510    /// and may change or be removed in future SDK or CLI releases. Pin both the
10511    /// SDK and CLI versions if your code depends on it.
10512    ///
10513    /// </div>
10514    pub async fn list_files(&self) -> Result<WorkspacesListFilesResult, Error> {
10515        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
10516        let _value = self
10517            .session
10518            .client()
10519            .call(rpc_methods::SESSION_WORKSPACES_LISTFILES, Some(wire_params))
10520            .await?;
10521        Ok(serde_json::from_value(_value)?)
10522    }
10523
10524    /// Reads a file from the session workspace files directory.
10525    ///
10526    /// Wire method: `session.workspaces.readFile`.
10527    ///
10528    /// # Parameters
10529    ///
10530    /// * `params` - Relative path of the workspace file to read.
10531    ///
10532    /// # Returns
10533    ///
10534    /// Contents of the requested workspace file as a UTF-8 string.
10535    ///
10536    /// <div class="warning">
10537    ///
10538    /// **Experimental.** This API is part of an experimental wire-protocol surface
10539    /// and may change or be removed in future SDK or CLI releases. Pin both the
10540    /// SDK and CLI versions if your code depends on it.
10541    ///
10542    /// </div>
10543    pub async fn read_file(
10544        &self,
10545        params: WorkspacesReadFileRequest,
10546    ) -> Result<WorkspacesReadFileResult, Error> {
10547        let mut wire_params = serde_json::to_value(params)?;
10548        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
10549        let _value = self
10550            .session
10551            .client()
10552            .call(rpc_methods::SESSION_WORKSPACES_READFILE, Some(wire_params))
10553            .await?;
10554        Ok(serde_json::from_value(_value)?)
10555    }
10556
10557    /// Creates or overwrites a file in the session workspace files directory.
10558    ///
10559    /// Wire method: `session.workspaces.createFile`.
10560    ///
10561    /// # Parameters
10562    ///
10563    /// * `params` - Relative path and UTF-8 content for the workspace file to create or overwrite.
10564    ///
10565    /// <div class="warning">
10566    ///
10567    /// **Experimental.** This API is part of an experimental wire-protocol surface
10568    /// and may change or be removed in future SDK or CLI releases. Pin both the
10569    /// SDK and CLI versions if your code depends on it.
10570    ///
10571    /// </div>
10572    pub async fn create_file(&self, params: WorkspacesCreateFileRequest) -> Result<(), Error> {
10573        let mut wire_params = serde_json::to_value(params)?;
10574        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
10575        let _value = self
10576            .session
10577            .client()
10578            .call(
10579                rpc_methods::SESSION_WORKSPACES_CREATEFILE,
10580                Some(wire_params),
10581            )
10582            .await?;
10583        Ok(())
10584    }
10585
10586    /// Lists workspace checkpoints in chronological order.
10587    ///
10588    /// Wire method: `session.workspaces.listCheckpoints`.
10589    ///
10590    /// # Returns
10591    ///
10592    /// Workspace checkpoints in chronological order; empty when the workspace is not enabled.
10593    ///
10594    /// <div class="warning">
10595    ///
10596    /// **Experimental.** This API is part of an experimental wire-protocol surface
10597    /// and may change or be removed in future SDK or CLI releases. Pin both the
10598    /// SDK and CLI versions if your code depends on it.
10599    ///
10600    /// </div>
10601    pub async fn list_checkpoints(&self) -> Result<WorkspacesListCheckpointsResult, Error> {
10602        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
10603        let _value = self
10604            .session
10605            .client()
10606            .call(
10607                rpc_methods::SESSION_WORKSPACES_LISTCHECKPOINTS,
10608                Some(wire_params),
10609            )
10610            .await?;
10611        Ok(serde_json::from_value(_value)?)
10612    }
10613
10614    /// Reads the content of a workspace checkpoint by number.
10615    ///
10616    /// Wire method: `session.workspaces.readCheckpoint`.
10617    ///
10618    /// # Parameters
10619    ///
10620    /// * `params` - Checkpoint number to read.
10621    ///
10622    /// # Returns
10623    ///
10624    /// Checkpoint content as a UTF-8 string, or null when the checkpoint or workspace is missing.
10625    ///
10626    /// <div class="warning">
10627    ///
10628    /// **Experimental.** This API is part of an experimental wire-protocol surface
10629    /// and may change or be removed in future SDK or CLI releases. Pin both the
10630    /// SDK and CLI versions if your code depends on it.
10631    ///
10632    /// </div>
10633    pub async fn read_checkpoint(
10634        &self,
10635        params: WorkspacesReadCheckpointRequest,
10636    ) -> Result<WorkspacesReadCheckpointResult, Error> {
10637        let mut wire_params = serde_json::to_value(params)?;
10638        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
10639        let _value = self
10640            .session
10641            .client()
10642            .call(
10643                rpc_methods::SESSION_WORKSPACES_READCHECKPOINT,
10644                Some(wire_params),
10645            )
10646            .await?;
10647        Ok(serde_json::from_value(_value)?)
10648    }
10649
10650    /// Adds a compaction summary checkpoint to the local session workspace.
10651    ///
10652    /// Wire method: `session.workspaces.addSummary`.
10653    ///
10654    /// # Parameters
10655    ///
10656    /// * `params` - Compaction summary checkpoint to persist.
10657    ///
10658    /// # Returns
10659    ///
10660    /// Persisted summary metadata and refreshed workspace metadata.
10661    ///
10662    /// <div class="warning">
10663    ///
10664    /// **Experimental.** This API is part of an experimental wire-protocol surface
10665    /// and may change or be removed in future SDK or CLI releases. Pin both the
10666    /// SDK and CLI versions if your code depends on it.
10667    ///
10668    /// </div>
10669    pub async fn add_summary(
10670        &self,
10671        params: WorkspacesAddSummaryRequest,
10672    ) -> Result<WorkspacesAddSummaryResult, Error> {
10673        let mut wire_params = serde_json::to_value(params)?;
10674        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
10675        let _value = self
10676            .session
10677            .client()
10678            .call(
10679                rpc_methods::SESSION_WORKSPACES_ADDSUMMARY,
10680                Some(wire_params),
10681            )
10682            .await?;
10683        Ok(serde_json::from_value(_value)?)
10684    }
10685
10686    /// Truncates local workspace compaction summaries after a rollback.
10687    ///
10688    /// Wire method: `session.workspaces.truncateSummaries`.
10689    ///
10690    /// # Parameters
10691    ///
10692    /// * `params` - Rollback point for local workspace summaries.
10693    ///
10694    /// # Returns
10695    ///
10696    /// Current workspace metadata for the session, including its absolute filesystem path when available.
10697    ///
10698    /// <div class="warning">
10699    ///
10700    /// **Experimental.** This API is part of an experimental wire-protocol surface
10701    /// and may change or be removed in future SDK or CLI releases. Pin both the
10702    /// SDK and CLI versions if your code depends on it.
10703    ///
10704    /// </div>
10705    pub async fn truncate_summaries(
10706        &self,
10707        params: WorkspacesTruncateSummariesRequest,
10708    ) -> Result<WorkspacesGetWorkspaceResult, Error> {
10709        let mut wire_params = serde_json::to_value(params)?;
10710        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
10711        let _value = self
10712            .session
10713            .client()
10714            .call(
10715                rpc_methods::SESSION_WORKSPACES_TRUNCATESUMMARIES,
10716                Some(wire_params),
10717            )
10718            .await?;
10719        Ok(serde_json::from_value(_value)?)
10720    }
10721
10722    /// Reads the autopilot objective state file from the local session workspace.
10723    ///
10724    /// Wire method: `session.workspaces.readAutopilotObjective`.
10725    ///
10726    /// # Returns
10727    ///
10728    /// Autopilot objective file content, or null when missing.
10729    ///
10730    /// <div class="warning">
10731    ///
10732    /// **Experimental.** This API is part of an experimental wire-protocol surface
10733    /// and may change or be removed in future SDK or CLI releases. Pin both the
10734    /// SDK and CLI versions if your code depends on it.
10735    ///
10736    /// </div>
10737    pub async fn read_autopilot_objective(
10738        &self,
10739    ) -> Result<WorkspacesReadAutopilotObjectiveResult, Error> {
10740        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
10741        let _value = self
10742            .session
10743            .client()
10744            .call(
10745                rpc_methods::SESSION_WORKSPACES_READAUTOPILOTOBJECTIVE,
10746                Some(wire_params),
10747            )
10748            .await?;
10749        Ok(serde_json::from_value(_value)?)
10750    }
10751
10752    /// Writes the autopilot objective state file in the local session workspace.
10753    ///
10754    /// Wire method: `session.workspaces.writeAutopilotObjective`.
10755    ///
10756    /// # Parameters
10757    ///
10758    /// * `params` - Autopilot objective file content to persist.
10759    ///
10760    /// # Returns
10761    ///
10762    /// Result of writing the autopilot objective file.
10763    ///
10764    /// <div class="warning">
10765    ///
10766    /// **Experimental.** This API is part of an experimental wire-protocol surface
10767    /// and may change or be removed in future SDK or CLI releases. Pin both the
10768    /// SDK and CLI versions if your code depends on it.
10769    ///
10770    /// </div>
10771    pub async fn write_autopilot_objective(
10772        &self,
10773        params: WorkspacesWriteAutopilotObjectiveRequest,
10774    ) -> Result<WorkspacesWriteAutopilotObjectiveResult, Error> {
10775        let mut wire_params = serde_json::to_value(params)?;
10776        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
10777        let _value = self
10778            .session
10779            .client()
10780            .call(
10781                rpc_methods::SESSION_WORKSPACES_WRITEAUTOPILOTOBJECTIVE,
10782                Some(wire_params),
10783            )
10784            .await?;
10785        Ok(serde_json::from_value(_value)?)
10786    }
10787
10788    /// Deletes the autopilot objective state file from the local session workspace.
10789    ///
10790    /// Wire method: `session.workspaces.deleteAutopilotObjective`.
10791    ///
10792    /// # Returns
10793    ///
10794    /// Result of deleting the autopilot objective file.
10795    ///
10796    /// <div class="warning">
10797    ///
10798    /// **Experimental.** This API is part of an experimental wire-protocol surface
10799    /// and may change or be removed in future SDK or CLI releases. Pin both the
10800    /// SDK and CLI versions if your code depends on it.
10801    ///
10802    /// </div>
10803    pub async fn delete_autopilot_objective(
10804        &self,
10805    ) -> Result<WorkspacesDeleteAutopilotObjectiveResult, Error> {
10806        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
10807        let _value = self
10808            .session
10809            .client()
10810            .call(
10811                rpc_methods::SESSION_WORKSPACES_DELETEAUTOPILOTOBJECTIVE,
10812                Some(wire_params),
10813            )
10814            .await?;
10815        Ok(serde_json::from_value(_value)?)
10816    }
10817
10818    /// Checks whether the local session workspace has an autopilot objective state file.
10819    ///
10820    /// Wire method: `session.workspaces.autopilotObjectiveExists`.
10821    ///
10822    /// # Returns
10823    ///
10824    /// Whether the autopilot objective file exists.
10825    ///
10826    /// <div class="warning">
10827    ///
10828    /// **Experimental.** This API is part of an experimental wire-protocol surface
10829    /// and may change or be removed in future SDK or CLI releases. Pin both the
10830    /// SDK and CLI versions if your code depends on it.
10831    ///
10832    /// </div>
10833    pub async fn autopilot_objective_exists(
10834        &self,
10835    ) -> Result<WorkspacesAutopilotObjectiveExistsResult, Error> {
10836        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
10837        let _value = self
10838            .session
10839            .client()
10840            .call(
10841                rpc_methods::SESSION_WORKSPACES_AUTOPILOTOBJECTIVEEXISTS,
10842                Some(wire_params),
10843            )
10844            .await?;
10845        Ok(serde_json::from_value(_value)?)
10846    }
10847
10848    /// Saves pasted content as a UTF-8 file in the session workspace.
10849    ///
10850    /// Wire method: `session.workspaces.saveLargePaste`.
10851    ///
10852    /// # Parameters
10853    ///
10854    /// * `params` - Pasted content to save as a UTF-8 file in the session workspace.
10855    ///
10856    /// # Returns
10857    ///
10858    /// Descriptor for the saved paste file, or null when the workspace is unavailable.
10859    ///
10860    /// <div class="warning">
10861    ///
10862    /// **Experimental.** This API is part of an experimental wire-protocol surface
10863    /// and may change or be removed in future SDK or CLI releases. Pin both the
10864    /// SDK and CLI versions if your code depends on it.
10865    ///
10866    /// </div>
10867    pub async fn save_large_paste(
10868        &self,
10869        params: WorkspacesSaveLargePasteRequest,
10870    ) -> Result<WorkspacesSaveLargePasteResult, Error> {
10871        let mut wire_params = serde_json::to_value(params)?;
10872        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
10873        let _value = self
10874            .session
10875            .client()
10876            .call(
10877                rpc_methods::SESSION_WORKSPACES_SAVELARGEPASTE,
10878                Some(wire_params),
10879            )
10880            .await?;
10881        Ok(serde_json::from_value(_value)?)
10882    }
10883
10884    /// Computes a diff for the session workspace. Never rejects for a busy session: a `session`-mode diff that cannot read the session's file-change captures falls back to an unstaged git diff with `isFallback: true` and reports why in `unavailableReason`.
10885    ///
10886    /// Wire method: `session.workspaces.diff`.
10887    ///
10888    /// # Parameters
10889    ///
10890    /// * `params` - Parameters for computing a workspace diff.
10891    ///
10892    /// # Returns
10893    ///
10894    /// Workspace diff result for the requested mode.
10895    ///
10896    /// <div class="warning">
10897    ///
10898    /// **Experimental.** This API is part of an experimental wire-protocol surface
10899    /// and may change or be removed in future SDK or CLI releases. Pin both the
10900    /// SDK and CLI versions if your code depends on it.
10901    ///
10902    /// </div>
10903    pub async fn diff(&self, params: WorkspacesDiffRequest) -> Result<WorkspaceDiffResult, Error> {
10904        let mut wire_params = serde_json::to_value(params)?;
10905        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
10906        let _value = self
10907            .session
10908            .client()
10909            .call(rpc_methods::SESSION_WORKSPACES_DIFF, Some(wire_params))
10910            .await?;
10911        Ok(serde_json::from_value(_value)?)
10912    }
10913}